home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / IBMLIB / KB_DRIVE.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-09-25  |  2.6 KB  |  128 lines

  1. ;
  2. ;  kb_drive.asm
  3. ;
  4. ;  Purpose: Keyboard primitives.
  5. ;
  6. ;  Blackstar C Function Libarary
  7. ;  (c) Copyright 1985,1989 Sterling Castle Software
  8. ;
  9.  
  10.     include model
  11.     include blackstr.mac
  12.  
  13.  
  14.     ;---------------------------------------------
  15.     ; the interrupt and codes for the interface.
  16.     ;--------------------------------------------
  17.     keyboard        equ     16h     ;interrupt 16 to deal with keyboard
  18.     video           equ     10h     ;interrupt for screen
  19.     cicode          equ     0       ;code for reading keyboard character
  20.     cstscode        equ     1       ;code for keyboard status
  21.     readch          equ     08      ;read character
  22.  
  23.     dseg    'DATA'
  24.     unchar          dw      0       ;un-keyed character
  25.     enddseg
  26.  
  27.  
  28.     cseg    kb_getc_
  29.  
  30. ;-----------------
  31. ;    kb_getc_                   get the next keyboard character.
  32. ;-----------------              
  33. ;                               Usage:  character = kb_getc_();
  34. ;
  35. ;                               int kb_getc(void);
  36.  
  37.     public  kb_getc_
  38.  
  39. kb_getc_ proc
  40.     prolog
  41.  
  42.     ifdef   Large_data
  43.     mov     ax,seg dgroup
  44.     mov     ds,ax
  45.     endif
  46.  
  47.     mov     ax,unchar       ;see if character was un_key
  48.     cmp     ax,0
  49.     je      key_c1
  50.     mov     unchar,0        ;kill un_key character
  51.     jmp     key_x           ;and done
  52. key_c1:
  53.     mov     ah,cicode       ;ask for a keyboard character
  54.     int     keyboard
  55. key_x:
  56.  
  57.     ifdef    asm_386
  58.     movsx    eax,ax
  59.     endif
  60.  
  61.     epilog
  62. kb_getc_ endp
  63.  
  64.  
  65. ;--------------------
  66. ;       kb_hit_                 return 255 if any available. otherwise
  67. ;--------------------           return zero.
  68. ;
  69. ;                               Usage:  character = kb_hit_();
  70. ;
  71. ;                               int kb_hit_(void);
  72.  
  73.     public  kb_hit_
  74.  
  75. kb_hit_ proc                    ;return status code if any available
  76.     prolog
  77.  
  78.     ifdef   Large_data
  79.     mov     ax,seg dgroup
  80.     mov     ds,ax
  81.     endif
  82.  
  83.     mov     ah,cstscode
  84.     int     keyboard
  85.     mov     ax,unchar       ;get previously un-keyed char
  86.     jz      hit_x
  87.     mov     ax,255          ;character available flag
  88.  
  89. hit_x:  
  90.     ifdef    asm_386
  91.     movsx    eax,ax
  92.     endif
  93.  
  94.     epilog
  95. kb_hit_ endp
  96.  
  97.  
  98. ;------------------
  99. ;       kb_ungetc_              put back character for next input
  100. ;------------------
  101. ;                               Usage:  kb_ungetc_(c);
  102. ;
  103. ;                               int kb_ungetc(char c);
  104.  
  105.     public  kb_ungetc_
  106.  
  107. kb_ungetc_ proc
  108.     parms<<c,byte>>
  109.     prolog
  110.  
  111.     ifdef   Large_data
  112.     mov     ax,seg dgroup
  113.     mov     ds,ax
  114.     endif
  115.  
  116.     mov     al,c            ;get character to un_key
  117.     mov     unchar,ax       ;save it
  118.  
  119.     ifdef    asm_386
  120.     movsx    eax,ax
  121.     endif
  122.  
  123.     epilog
  124. kb_ungetc_ endp
  125.  
  126.     endcseg kb_getc_
  127.     end
  128.