home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / teseract / source / tsint16.asm < prev    next >
Encoding:
Assembly Source File  |  1988-10-02  |  6.7 KB  |  232 lines

  1. IFNDEF TP4
  2.         PAGE 60,132
  3. ;----------------------------------------------------------------------------
  4. SUBTTL  TesSeRact Revision Level 1
  5. ;-----------------------------------------------------------------------------
  6. ;   TesSeRact(tm) -- A Library of Routines for Creating Ram-Resident (TSR)
  7. ;                    programs for the IBM PC and compatible Personal
  8. ;                    Computers.
  9. ;
  10. ;The software, documentation and source code are: 
  11. ;       Copyright (C) 1986, 1987, 1988 Tesseract Development Team
  12. ;       All Rights Reserved 
  13. ;       c/o Chip Rabinowitz
  14. ;       Innovative Data Concepts
  15. ;       2084 Woodlawn Avenue
  16. ;       Glenside, PA 19038
  17. ;       1-215-884-3373
  18. ;
  19. ;-----------------------------------------------------------------------------
  20. ;   This product supports the TesSeRact Standard for Ram-Resident Program 
  21. ;   Communication.  For information about TesSeRact, contact the TesSeRact 
  22. ;   Development Team at:
  23. ;       Compuserve:    70731,20
  24. ;       MCIMAIL:       315-5415
  25. ;   This MCIMAIL Account has been provided to the TesSeRact Development
  26. ;   Team by Borland International, Inc.  The TesSeRact Development Team
  27. ;   is in no way associated with Borland International, Inc.
  28. ;-----------------------------------------------------------------------------
  29.  
  30. INCLUDE TESS.INC
  31. IFDEF   ALLPUBLIC
  32. INCLUDE tsint16.pub     ;public definitions (uses Periscope PUBLIC.COM /E)
  33. ENDIF
  34.  
  35. .MODEL small
  36. .CODE
  37.  
  38. EXTRN _TESSKEYSTAT:near
  39.  
  40. EXTRN TESS_GLOBALS:byte
  41.  
  42. PUBLIC newint16, _TESSSTUFFKEYS
  43.  
  44. ENDIF
  45.  
  46. BUFFER_TAIL     equ     1ch
  47. BUFFER_HEAD     equ     1ah
  48. BUFFER_START    equ     80h
  49. BUFFER_END      equ     82h
  50.  
  51.  
  52. _TESSSTUFFKEYS proc near
  53. ;
  54. ;       on entry, AX contains ASCII/SCAN CODE pair to stuff
  55. ;       on exit, AX contains FFFF if keyboard is full, else
  56. ;           AX is 0
  57. ;       DI contains the stuffing speed.  If DI is zero, then a keystroke
  58. ;           is only placed into the buffer if the buffer is empty!
  59. ;           
  60. ;
  61.         ASSUMENODS
  62.  
  63.         push    es
  64.         push    si
  65.         push    bx
  66.  
  67.         pushf
  68.         cli
  69.  
  70.         push    ax
  71.         xor     ax,ax
  72.         mov     ax,40h
  73.         mov     es,ax
  74.         pop     ax
  75.  
  76.         mov     bx,es:[BUFFER_TAIL]     ;get tail of kbd buffer
  77.         mov     si,bx                   ;save it for later
  78.  
  79.         or      di,di                   ;if SLOW speed, then ....
  80.         jnz     not_slow
  81.  
  82.         cmp     bx,es:[BUFFER_HEAD]     ;if head=tail then
  83.         jne     bad_stuff               ;buffer is empty and
  84.                                         ;we can continue
  85. not_slow:
  86.         inc     bx
  87.         inc     bx                      ;advance to next position
  88.         cmp     bx,es:[BUFFER_END]      ;check for warap-around
  89.         jne     no_wrap
  90.  
  91.         mov     bx,es:[BUFFER_START]    ;start from beginning again
  92. no_wrap:
  93.         cmp     bx,es:[BUFFER_HEAD]     ;is the buffer full?
  94.         je      bad_stuff               ;yep -- return right away!
  95.  
  96.         mov     es:[si],ax              ;store the character
  97.         mov     es:[BUFFER_TAIL],bx     ;move the tail pointer up
  98.         xor     ax,ax
  99.         jmp     short stuff_out
  100.  
  101. bad_stuff:
  102.         xor     ax,ax
  103.         dec     ax
  104. stuff_out:
  105.         POPFF
  106.         pop     bx
  107.         pop     si
  108.         pop     es
  109.         ret
  110.  
  111. _TESSSTUFFKEYS endp
  112.  
  113.  
  114. newint16 PROC FAR
  115.  
  116.         ASSUMENODS
  117.  
  118. ; ..lf -- we may have to go thru here and check for flag modifications 
  119. ; ..cr - yep -- we're blowing the flags -- fix ASAP
  120. ;
  121. start_again:                    ; ..lf
  122.         or      BPTR [SOFTINTFLAGS],ININT16 ;indicate our int16 is active
  123.  
  124.         cmp     ax,55ffh                ;is it msword?
  125.         je      check_word              ;yes!!
  126.  
  127.         test    ah,10h                  ;check for new bios function ..lf
  128.         jz      gobios16                ;if zero, then have char request.
  129.  
  130.         mov     BPTR [NEWKBDFLAG],10h   ;say new_bios function involved
  131.         and     ah,0EFh                 ;just clear out the one bit
  132.                                         ;force test w/o new_bios flag
  133.  
  134. gobios16:
  135.         cmp     ah,00                   ;if char request,
  136.         je      func00                  ;loop for character
  137.         cmp     ah,01                   ;if character availability test
  138.         je      func01                  ;go check for char
  139.  
  140. bios16:
  141.         and     BPTR [SOFTINTFLAGS],NOT ININT16 ;say our 16 deactivated
  142.         or      ah,BPTR [NEWKBDFLAG]
  143.         mov     BPTR [NEWKBDFLAG],00    ;clear the enyucked flag
  144.         jmp     DPTR [OLDINT16]
  145.  
  146.  
  147. check_word:
  148.         cmp     bx,4
  149.         jne     bios16
  150.  
  151.         or      cx,cx
  152.         jz      start_word
  153.         mov     BPTR [INWORD4],0
  154.         jmp     bios16
  155.  
  156. start_word:
  157.         mov     BPTR [INWORD4],1
  158.         jmp     bios16
  159.  
  160.  
  161. ; -- USER REQUEST FOR KEYBOARD STATUS / KEY AVAILABILITY 
  162.  
  163. func01:
  164.         push    ds                      ;save regs, set our Dseg
  165.         push    cs
  166.         pop     ds
  167.  
  168.         ASSUMEDS
  169.  
  170. func01A:
  171.         call    _TESSKEYSTAT            ;look at key buffer
  172.         pushf                           ;save return flags
  173.  
  174. fret01:                                 ;return INT 16h information
  175.         mov     BPTR [NEWKBDFLAG],0     ;clear any "new bios" conditions ..lf
  176.         and     BPTR [SOFTINTFLAGS],NOT ININT16 ;Say INT16 is done
  177.         POPFF                           ;return bios int 16 status flags 
  178.  
  179.         pop     ds
  180.  
  181.         ASSUMENODS
  182.  
  183.         push    ax                      ;save return value
  184.  
  185.         pushf
  186.         pop     ax                      ;get FLAGS to AX
  187.         push    bp
  188.  
  189.         mov     bp,sp
  190.  
  191.         or      ax,200h         ;make sure INTs are enabled (on stack)
  192.  
  193.         mov     [bp+8],ax
  194.  
  195.         pop     bp
  196.         pop     ax              ;get return value back
  197.  
  198.         iret                    ;return (flags modified in place)
  199.  
  200. ; -- REQUEST TO READ/WAIT FOR  KEY FROM KEYBOARD
  201.  
  202. func00:
  203.         push    ds
  204.         push    cs
  205.         pop     ds
  206.  
  207.         ASSUMEDS
  208.  
  209. func00A:
  210.         call    _TESSKEYSTAT            ;Read & wait until key available
  211.         jz      func00A                 ;loop 'till key from keyboard or TSR
  212.  
  213.  
  214.         pushf                           ;simulate INT 16
  215.  
  216.         mov     ah,0                    ;get the waiting key
  217.         or      ah,BPTR [NEWKBDFLAG]    ;re-insert new_bios flags ..lf
  218.  
  219.  
  220.         call    DPTR [OLDINT16] ;do bios read 
  221.  
  222. out_16A:
  223.         pushf                           ;save return flags
  224.                                         ;stack now holds FLAGS,SI,DI,IP,DS,CS,FLAGS
  225.         jmp     fret01                  ;restore and return
  226.  
  227. newint16 endp
  228.  
  229. ENDIT
  230.