Subversion Repositories SvarDOS

Rev

Rev 388 | Rev 396 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 388 Rev 392
Line 92... Line 92...
92
    mov [res], ax
92
    mov [res], ax
93
    DONE:
93
    DONE:
94
  }
94
  }
95
  return(res);
95
  return(res);
96
}
96
}
-
 
97
 
-
 
98
 
-
 
99
/* print s string and wait for a single key press from stdin. accepts only
-
 
100
 * key presses defined in the c ASCIIZ string. returns offset of pressed key
-
 
101
 * in string. keys in c MUST BE UPPERCASE! */
-
 
102
unsigned short askchoice(const char *s, const char *c) {
-
 
103
  unsigned short res;
-
 
104
  char key = 0;
-
 
105
 
-
 
106
  AGAIN:
-
 
107
  output(s);
-
 
108
  output(" ");
-
 
109
 
-
 
110
  _asm {
-
 
111
    push ax
-
 
112
    push dx
-
 
113
 
-
 
114
    mov ax, 0x0c01 /* clear input buffer and execute getchar (INT 21h,AH=1) */
-
 
115
    int 0x21
-
 
116
    /* if AL == 0 then this is an extended character */
-
 
117
    test al, al
-
 
118
    jnz GOTCHAR
-
 
119
    mov ah, 0x08   /* read again to flush extended char from input buffer */
-
 
120
    int 0x21
-
 
121
    xor al, al     /* all extended chars are ignored */
-
 
122
    GOTCHAR:       /* received key is in AL now */
-
 
123
    mov [key], al  /* save key */
-
 
124
 
-
 
125
    /* print a cr/lf */
-
 
126
    mov ah, 0x02
-
 
127
    mov dl, 0x0D
-
 
128
    int 0x21
-
 
129
    mov dl, 0x0A
-
 
130
    int 0x21
-
 
131
 
-
 
132
    pop dx
-
 
133
    pop ax
-
 
134
  }
-
 
135
 
-
 
136
  /* ucase() result */
-
 
137
  if ((key >= 'a') && (key <= 'z')) key -= ('a' - 'A');
-
 
138
 
-
 
139
  /* is there a match? */
-
 
140
  for (res = 0; c[res] != 0; res++) if (c[res] == key) return(res);
-
 
141
 
-
 
142
  goto AGAIN;
-
 
143
}
-
 
144
 
-
 
145
 
-
 
146
/* converts a path to its canonic representation */
-
 
147
void file_truename(const char *src, char *dst) {
-
 
148
  _asm {
-
 
149
    mov ah, 0x60  /* query truename, DS:SI=src, ES:DI=dst */
-
 
150
    push ds
-
 
151
    pop es
-
 
152
    mov si, src
-
 
153
    mov di, dst
-
 
154
    int 0x21
-
 
155
  }
-
 
156
}
-
 
157
 
-
 
158
 
-
 
159
/* returns DOS attributes of file, or -1 on error */
-
 
160
int file_getattr(const char *fname) {
-
 
161
  int res = -1;
-
 
162
  _asm {
-
 
163
    mov ax, 0x4300  /* query file attributes, fname at DS:DX */
-
 
164
    mov dx, fname
-
 
165
    int 0x21        /* CX=attributes if CF=0, otherwise AX=errno */
-
 
166
    jc DONE
-
 
167
    mov [res], cx
-
 
168
    DONE:
-
 
169
  }
-
 
170
  return(res);
-
 
171
}