home *** CD-ROM | disk | FTP | other *** search
/ ftp.update.uu.se / ftp.update.uu.se.2014.03.zip / ftp.update.uu.se / pub / rainbow / msdos / decus / RB140 / grlib03a.arj / GETKEY.ASM < prev    next >
Assembly Source File  |  1988-12-08  |  3KB  |  184 lines

  1. PAGE ,132
  2. TITLE GETKEY.ASM
  3. ;UPDATE HISTORY
  4. ;==============
  5. ; 3-dec-1984     convert from c to assembler
  6.  
  7. include asmc.h
  8. include asmk.h
  9.  
  10.     public    CAPITAL
  11.     public    INKEY
  12.     public    GETKEY
  13.     extrn    KBD16:near, KBDIN:near
  14. ; convert character to uppercase if lower case */
  15. ;  if('a'<=c && c<='z')c+=('A'-'a');
  16. ;  return c;
  17. ucase    PROC    NEAR
  18.     push    BP
  19.     mov    BP,SP
  20.     mov    AL,+4[BP]
  21.     cbw
  22.     cmp    AX,97
  23.     jl    ucasex
  24.     mov    AL,+4[BP]
  25.     cbw
  26.     cmp    AX,122
  27.     jg    ucasex
  28.     mov    AX,-32
  29.     push    AX
  30.     pop    DX
  31.     mov    AL,+4[BP]
  32.     cbw
  33.     add    AX,DX
  34.     mov    +4[BP],AL
  35. ucasex:
  36.     mov    AL,+4[BP]
  37.     cbw
  38.     mov    SP,BP
  39.     pop    BP
  40.     ret
  41. ucase    ENDP
  42.  
  43.  
  44. ;******************************************************
  45. ;convert non-function key to upper case               *
  46. ;capital(key_pressed)                                 *
  47. ;unsigned int key_pressed;                            *
  48. ;******************************************************
  49.     PROCDEF CAPITAL
  50.     push    BP
  51.     mov    BP,SP
  52.  
  53. ;    if ( !FUNKEY(key_pressed) )
  54.     mov    AX,+4[BP]
  55.     and    AX,256
  56.     or    AX,AX
  57.     je    .012
  58.     mov    AX,1
  59.     jmp    SHORT .014
  60. .012:            ;11
  61.     xor    AX,AX
  62. .014:            ;11
  63.     or    AX,AX
  64.     je    .01A
  65.     jmp    SHORT .027
  66.  
  67. ;    return(toupper(key_pressed));
  68. .01A:            ;11
  69.     push    WORD PTR +4[BP]
  70.     call    ucase
  71.     add    SP,2
  72.  
  73.     mov    SP,BP
  74.     pop    BP
  75.     ret
  76.  
  77. ;     else
  78. ;    return(key_pressed);
  79. .027:            ;13
  80.     mov    AX,+4[BP]
  81.     mov    SP,BP
  82.     pop    BP
  83.     ret
  84.     PROCEND CAPITAL
  85.  
  86. ;******************************************************
  87. ;wait for a key to be pressed and return it to caller *
  88. ; inkey()                                             *
  89. ;******************************************************
  90.  
  91.  
  92. INKEY    PROC    NEAR
  93. .032:            ;19
  94.     push    BP
  95.     mov    BP,SP
  96.     sub    SP,2
  97.  
  98. ;    while ((key = getkey()) == 0);
  99. .038:            ;22
  100.     call    GETKEY
  101.     mov    -2[BP],AX
  102.     cmp    AX,0
  103.     jne    .045
  104.     jmp    SHORT .038
  105.  
  106. ;    return(key);
  107. .045:            ;22
  108.     mov    AX,-2[BP]
  109.     mov    SP,BP
  110.     pop    BP
  111.     ret
  112. INKEY    ENDP
  113.  
  114. ;***********************************************************
  115. ;see if a key was pressed and return 16-bit char to caller *
  116. ;if function key, bit 0x0100 = 1                           *
  117. ;           else, bit 0x0100 = 0                           *
  118. ;return 0 if no key pressed                                *
  119. ;getkey()                                                  *
  120. ;***********************************************************
  121. ;    };
  122. ;}
  123. GETKEY    PROC    NEAR
  124. .04C:            ;27
  125.     push    BP
  126.     mov    BP,SP
  127.     sub    SP,6
  128.  
  129. ;    j = kbd16(&i);
  130.     lea    SI,-6[BP]
  131.     push    SI
  132.     call    KBD16
  133.     add    SP,2
  134.  
  135. ;    while (j == LEV2) {            /* lose L2 chars */
  136. ;    j = kbdin(k);
  137. ;    j = kbd16(&i);
  138.     mov    -4[BP],AX
  139. .05F:            ;31
  140.     cmp    WORD PTR -4[BP],1
  141.     jne    .081
  142.     push    WORD PTR -2[BP]
  143.     call    KBDIN
  144.     add    SP,2
  145.     mov    -4[BP],AX
  146.     lea    SI,-6[BP]
  147.     push    SI
  148.     call    KBD16
  149.     add    SP,2
  150.     mov    -4[BP],AX
  151.     jmp    SHORT .05F
  152.  
  153. ;    if (j == AKEY) return(i & FUNCTION ? i & FUNMASK : i & 0xFF);
  154. .081:            ;34
  155.     cmp    WORD PTR -4[BP],-1
  156.     jne    .0A4
  157.     mov    AX,-6[BP]
  158.     and    AX,256
  159.     or    AX,AX
  160.     je    .09A
  161.     mov    AX,-6[BP]
  162.     and    AX,319
  163.     jmp    SHORT .0A0
  164. .09A:            ;35
  165.     mov    AX,-6[BP]
  166.     and    AX,255
  167. .0A0:            ;35
  168.     mov    SP,BP
  169.     pop    BP
  170.     ret
  171.  
  172. ;    return(0);
  173. .0A4:            ;36
  174.     xor    AX,AX
  175.     mov    SP,BP
  176.     pop    BP
  177.     ret
  178. GETKEY    ENDP
  179.  
  180.  
  181. include epilogue.h
  182.     END
  183. 
  184.