Subversion Repositories SvarDOS

Rev

Rev 1988 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1988 Rev 1997
Line 222... Line 222...
222
  }
222
  }
223
  return(res);
223
  return(res);
224
}
224
}
225
 
225
 
226
 
226
 
-
 
227
static unsigned char _dos_getkey_noecho(void);
-
 
228
#pragma aux _dos_getkey_noecho = \
-
 
229
"mov ax, 0x0c08" /* clear input buffer and execute getchar (INT 21h,AH=8) */  \
-
 
230
"int 0x21"                                                                    \
-
 
231
"test al, al"    /* if AL == 0 then this is an extended character */          \
-
 
232
"jnz GOTCHAR"                                                                 \
-
 
233
"mov ah, 0x08"   /* read again to flush extended char from input buffer */    \
-
 
234
"int 0x21"                                                                    \
-
 
235
"xor al, al"     /* all extended chars are ignored */                         \
-
 
236
"GOTCHAR:"       /* received key is in AL now */                              \
-
 
237
modify [ah]                                                                   \
-
 
238
value [al]
-
 
239
 
-
 
240
 
227
/* print s string and wait for a single key press from stdin. accepts only
241
/* print s string and wait for a single key press from stdin. accepts only
228
 * key presses defined in the c ASCIIZ string. returns offset of pressed key
242
 * key presses defined in the c ASCIIZ string. returns offset of pressed key
229
 * in string. keys in c MUST BE UPPERCASE! */
243
 * in string. keys in c MUST BE UPPERCASE! ENTER chooses the FIRST choice */
230
unsigned short askchoice(const char *s, const char *c) {
244
unsigned short askchoice(const char *s, const char *c) {
231
  unsigned short res;
245
  unsigned short res;
232
  char cstr[2] = {0,0};
246
  char cstr[2] = {0,0};
233
  char key = 0;
247
  char key = 0;
234
 
248
 
235
  AGAIN:
-
 
236
  output(s);
249
  output(s);
237
  output(" ");
250
  output(" ");
238
  output("(");
251
  output("(");
239
  for (res = 0; c[res] != 0; res++) {
252
  for (res = 0; c[res] != 0; res++) {
240
    if (res != 0) output("/");
253
    if (res != 0) output("/");
241
    cstr[0] = c[res];
254
    cstr[0] = c[res];
242
    output(cstr);
255
    output(cstr);
243
  }
256
  }
244
  output(") ");
257
  output(") ");
245
 
258
 
246
  _asm {
259
  AGAIN:
247
    push ax
-
 
248
    push dx
-
 
249
 
-
 
250
    mov ax, 0x0c01 /* clear input buffer and execute getchar (INT 21h,AH=1) */
-
 
251
    int 0x21
-
 
252
    /* if AL == 0 then this is an extended character */
-
 
253
    test al, al
260
  key = _dos_getkey_noecho();
254
    jnz GOTCHAR
-
 
255
    mov ah, 0x08   /* read again to flush extended char from input buffer */
261
  if (key == '\r') key = c[0]; /* ENTER is synonym for the first key */
256
    int 0x21
-
 
257
    xor al, al     /* all extended chars are ignored */
-
 
258
    GOTCHAR:       /* received key is in AL now */
-
 
259
    mov [key], al  /* save key */
-
 
260
 
-
 
261
    /* print a cr/lf */
-
 
262
    mov ah, 0x02
-
 
263
    mov dl, 0x0D
-
 
264
    int 0x21
-
 
265
    mov dl, 0x0A
-
 
266
    int 0x21
-
 
267
 
-
 
268
    pop dx
-
 
269
    pop ax
-
 
270
  }
-
 
271
 
262
 
272
  /* ucase() result */
263
  /* ucase() result */
273
  if ((key >= 'a') && (key <= 'z')) key -= ('a' - 'A');
264
  if ((key >= 'a') && (key <= 'z')) key -= ('a' - 'A');
274
 
265
 
275
  /* is there a match? */
266
  /* is there a match? */
276
  for (res = 0; c[res] != 0; res++) if (c[res] == key) return(res);
267
  for (res = 0; c[res] != 0; res++) {
-
 
268
    if (c[res] == key) {
-
 
269
      cstr[0] = key;
-
 
270
      output(cstr);
-
 
271
      output("\r\n");
-
 
272
      return(res);
-
 
273
    }
-
 
274
  }
277
 
275
 
278
  goto AGAIN;
276
  goto AGAIN;
279
}
277
}
280
 
278
 
281
 
279