home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l351 / 1.ddi / EXAMPLES / KEYS2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-26  |  1.7 KB  |  59 lines

  1. /* 
  2. KEYS.C -- demonstrate use of BIOS data area in 286|DOS-Extender
  3. */
  4.  
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <conio.h>
  8.  
  9. /*
  10.     Microsoft Visual C++ - 
  11.     We use based variables, which are perfect for mapped selectors
  12.     in 286|DOS-Extender, and much nicer to work with than either
  13.     the MAKEP() or MK_FP() macros.  Notice that 0x40 is a _very_
  14.     special case.  All DPMI servers arrange that selector 0x40
  15.     maps the memory at 0040:000.  In other words, for this selector
  16.     only, protected-mode addresses are the same as real-mode addresses.
  17. */
  18. _segment bios = 0x40;
  19. #define TICKS()             (*((unsigned long _based(bios) *) 0x6C))
  20. #define KB_STAT             (*((unsigned char _based(bios) *) 0x17))
  21. #define KB_HEAD             (*((unsigned short _based(bios) *) 0x1A))
  22. #define KB_TAIL             (*((unsigned short _based(bios) *) 0x1C))
  23.  
  24. #define KB_HIT()            (KB_HEAD != KB_TAIL)
  25. #define CTRL()              (KB_STAT & 4)
  26. #define ALT()               (KB_STAT & 8)
  27.  
  28. #define ESC                 0x1B
  29.  
  30. void fail(char *s, unsigned ret)
  31. {
  32.     printf("%s ret=%04X (%u)\n", s, ret, ret);
  33.     exit(ret);
  34. }
  35.  
  36. main()
  37. {
  38.     int done = 0;
  39.     int c;
  40.     
  41.  
  42.     /* Note: Ctrl-Esc probably not a good choice: used by Windows too! */
  43.     puts("Press keys; Ctrl-Esc to quit");
  44.     while (! done)
  45.         if (KB_HIT())
  46.         {
  47.             c = getch();
  48.             printf("TIME=%-8lX ST=%02X CHAR=%02X ", TICKS(), KB_STAT, c);
  49.             if (c == 0)
  50.                 printf("%02X", getch());  /* extended character */
  51.             printf("\n");
  52.             if ((c == ESC) && CTRL()) /* Ctrl-ESC */ 
  53.                 break;
  54.     }
  55.     
  56.     puts("bye");
  57.     return 0;
  58. }
  59.