home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / teseract / source / tsint8.asm < prev    next >
Encoding:
Assembly Source File  |  1988-10-02  |  10.8 KB  |  409 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.  
  31. INCLUDE TESS.INC
  32. IFDEF   ALLPUBLIC
  33. INCLUDE tsint8.pub
  34. ENDIF
  35.  
  36. .MODEL small
  37.  
  38. .CODE
  39.  
  40. EXTRN _TESSDOPOPUP:near
  41. EXTRN TESSBEEP:FAR
  42. EXTRN _TESSSTUFFKEYS:near
  43.  
  44. EXTRN TESS_GLOBALS:byte
  45. EXTRN TESS_USERPARMS:byte
  46.  
  47. PUBLIC newint8, _TESSSTOREKEYS, _TESSCLEARKEYS
  48.  
  49. ENDIF
  50.  
  51. KbdCount        dw      0
  52. StuffSpeed      db      0
  53. StuffCount      dw      0
  54.  
  55. KBDBEGIN        equ     $
  56.  
  57. KbdBuffer       dw      80 dup(?)
  58.  
  59. KBDEND          equ     $-2
  60.  
  61. MAXKBDSIZE      equ     (KBDEND - KBDBEGIN) / 2
  62.  
  63. KbdHead         dw      KBDBEGIN
  64. KbdTail         dw      KBDBEGIN
  65.  
  66. wait8   db      8
  67. KbdCleared      db      0
  68.  
  69. _TESSCLEARKEYS proc near
  70.  
  71.         ASSUMEDS
  72.  
  73.         push    ax
  74.  
  75.         xor     ax,ax
  76.         mov     KbdCount,ax             ;say no more keys are waiting
  77.         mov     ax,offset KBDBEGIN      ;reset buffer pointers
  78.         mov     KbdHead,ax
  79.         mov     KbdTail,ax
  80.  
  81.         mov     KbdCleared,18           ;flag value
  82.  
  83.         pop     ax
  84.  
  85.         ret
  86. _TESSCLEARKEYS endp
  87.  
  88. _TESSSTOREKEYS proc near
  89. ;
  90. ;       on entry, es:di points to buffer, SI contains number of 
  91. ;           chars to stuff, dl has speed, dh = 0 to stuff words, 1
  92. ;           to stuff just chars
  93. ;
  94. ;
  95.         ASSUMENODS
  96.  
  97.         push    ds
  98.  
  99.         push    cs
  100.         pop     ds
  101.  
  102.         ASSUMEDS
  103.  
  104.  
  105.         mov     al,KbdCleared           ;did we get a ^C?
  106.         or      al,al
  107.         jnz     clear_buffer            ;yep ... signal on return
  108.  
  109.         or      si,si                   ;if no chars, just exit
  110.         jz      not_enough_room
  111.  
  112.         cli
  113.  
  114.         mov     ax,MAXKBDSIZE
  115.         sub     ax,[KbdCount]           ;how many are already there?
  116.  
  117.         cmp     ax,si                   ;is there room?
  118.         jbe     not_enough_room
  119.  
  120.         mov     cx,si
  121.  
  122.         mov     StuffSpeed,dl
  123. store_them:
  124.         mov     bx,[KbdTail]            ;load pointer
  125.  
  126.         or      dh,dh
  127.         jz      store_both
  128.  
  129.         mov     al,es:[di]              ;store the ascii code
  130.         xor     ah,ah
  131.         cmp     al,0dh                  ;is it a CR
  132.         jne     done_fetch
  133.  
  134.         mov     ah,1ch                  ;yep, add scan code
  135.         jmp     short done_fetch
  136.  
  137. store_both:
  138.         mov     ax,es:[di]              ;load the word
  139.         inc     di
  140. done_fetch:
  141.         inc     di
  142.         mov     [bx],ax                 ;store it in buffer
  143.  
  144.         inc     bx                      ;advance buffer, and wrap if needed
  145.         inc     bx
  146.         cmp     bx,offset KBDEND
  147.         jne     dont_wrap1
  148.  
  149.         mov     bx,offset KBDBEGIN
  150.  
  151. dont_wrap1:
  152.         mov     [KbdTail],bx            ;save end of buffer away
  153.         inc     [KbdCount]
  154.  
  155.         loop    store_them
  156.  
  157.         xor     ax,ax
  158.         jmp     short store_out
  159.  
  160. clear_buffer:
  161.         mov     ax,0f0f0h               ;signal ^C
  162.         mov     KbdCleared,0
  163.         jmp     short store_out
  164. not_enough_room:
  165.         xor     ax,ax
  166.         dec     ax
  167. store_out:
  168.         sti
  169.         pop     ds
  170.         ret
  171.  
  172. _TESSSTOREKEYS endp
  173.  
  174. ;---------------------------------------------------------------------;
  175. ;     Interrupt 8 pops an application over a running program          ;
  176. ;---------------------------------------------------------------------;
  177. newint8 proc far
  178.  
  179.         ASSUMENODS
  180.  
  181. ; IF TIMER CODE IS STILL BUSY, GO DIRECTLY TO BIOS TIMER CODE
  182.  
  183.         push    ds
  184.  
  185.         pushf
  186.  
  187.         push    cs
  188.         pop     ds                      ;recover our Datasegment address
  189.  
  190.         ASSUMEDS
  191.  
  192.         mov     BPTR [WASINT8],1
  193.  
  194. ;---------------------------------------------------------------------;
  195. ;       NOTE:  We don't want to be releasing a TSR from inside an INT8
  196. ;       popup routine!
  197. ;---------------------------------------------------------------------;
  198. ;       test    WPTR [STATUS],TSRRELEASED
  199. ;       jnz     dorel8
  200.  
  201.         test    WPTR [STATUS],TSRENABLED
  202.         jz      do_old8
  203.  
  204. dorel8:
  205.         test    BPTR [SOFTINTFLAGS],ININT08     ;See if recursion has taken place
  206.         jz      start_new_int8          ;If not continue with new int 8
  207. do_old8:
  208.         POPFF
  209.         pop     ds
  210.  
  211.         ASSUMENODS
  212.  
  213.         jmp     DPTR [OLDINT8]  ;Jump to original int 8
  214.  
  215. start_new_int8:
  216.  
  217.         ASSUMEDS
  218.  
  219.         POPFF
  220.         or      BPTR [SOFTINTFLAGS],ININT08     ;Set the int 8 active flag
  221.  
  222.         push    dx
  223.         push    cx                      ;save regs
  224.         push    bx
  225.         push    ax
  226.         push    di
  227.  
  228. ;  call the original Timer interrupt to avoid timer tick misses
  229.  
  230.         pushf                           ;simulate interrupt ...
  231.         call DPTR [OLDINT8]             ;do the original
  232.  
  233.         sti                             ;make sure INTs are ON!!
  234. Start_8:
  235.  
  236.         mov     al,KbdCleared
  237.         or      al,al
  238.         jz      checkword
  239.  
  240.         dec     [KbdCleared]
  241.  
  242. checkword:
  243.         mov     al,BPTR [WORD4DELAY]
  244.         or      al,al
  245.         jz      noword
  246.  
  247.         dec     BPTR [WORD4DELAY]
  248.         jnz     noword
  249.  
  250.         or      WPTR [STATUS],HOTKEYON
  251. noword:
  252.         mov     ax,WPTR [STATUS]
  253.         test    ax,POPUPSET
  254.         jz      again_8_2
  255.         test    ax,HOTKEYON
  256.         jz      again_8_2
  257.         test    ax,TSRACTIVE+INT28ACTIVE        ;are we already running?
  258.         jnz     again_8_2
  259.  
  260. wait_8:
  261.         call    Checkstatus_8
  262.  
  263.         jnz     end_8
  264.  
  265.         call    _TESSDOPOPUP
  266.  
  267. reset_8:
  268.         mov     wait8,8
  269.         jmp     short again_8_2
  270. end_8:
  271.         dec     wait8
  272.         jnz     again_8_2
  273.  
  274.         test    WPTR [STATUS],TSRRELEASED
  275.         jnz     reset_8
  276.         and     WPTR [STATUS],NOT HOTKEYON
  277.  
  278. IFDEF TP4
  279. IFNDEF ASMCOM
  280.         call    FAR PTR TESSBEEP
  281. ELSE
  282.         call    TESSBEEP
  283. ENDIF
  284. ELSE
  285.         call    TESSBEEP
  286. ENDIF
  287.  
  288.         jmp     short reset_8
  289.  
  290. again_8_2:
  291.         mov     ax,[KbdCount]
  292.         or      ax,ax
  293.         jz      no_keys
  294.  
  295.         mov     al,StuffSpeed
  296.         xor     ah,ah                   ;store speed
  297.         mov     di,ax                   ; in DI register
  298.  
  299.         mov     bx,[KbdHead]
  300.         mov     ax,[bx]
  301.  
  302.         call    _TESSSTUFFKEYS
  303.         cmp     ax,-1
  304.         je      no_keys                 ;no room in BIOS buffer -- try again!
  305.  
  306.         inc     bx
  307.         inc     bx
  308.         cmp     bx,offset KBDEND
  309.         jne     dont_wrap
  310.  
  311.         mov     bx,offset KBDBEGIN
  312.  
  313. dont_wrap:
  314.         mov     [KbdHead],bx
  315.         dec     [KbdCount]
  316.         inc     [StuffCount]
  317.  
  318.         mov     ax,di                   ;recover speed
  319.         or      al,al                   ;slow speed
  320.         jz      no_keys
  321.  
  322.         dec     al
  323.         jnz     again_8_2
  324.  
  325.         cmp     StuffCount,4
  326.         jne     again_8_2
  327.  
  328. no_keys:
  329.         xor     ax,ax
  330.         mov     StuffCount,ax
  331.  
  332.         and     BPTR [SOFTINTFLAGS], NOT ININT08 ;Clear the INT08 active flag
  333.  
  334.         ASSUMENODS
  335.  
  336.         pop     di
  337.         pop     ax                           ;get back registers
  338.         pop     bx
  339.         pop     cx
  340.         pop     dx
  341.  
  342. exit_8:
  343.         pop     ds
  344.         iret
  345.  
  346. newint8 endp
  347.  
  348. ; --------------------------------------------------------------------;
  349. ;   Check for occurance of non INT 8 interrupts in progress           ;
  350. ; --------------------------------------------------------------------;
  351. ;  Returns al containing In Service Register except Int 8 flag
  352. Checkstatus_8 proc    near      ;See if any interrupts are being serviced
  353.  
  354.         ASSUMEDS
  355.  
  356.         push    ds                      ;check if dos critical error in effect
  357.         push    si
  358.         push    DX
  359.         mov     DX,OCW3_8259            ;Address of 8259 OCW3
  360. ;;
  361. ;;      NOTE:  Leaving in the next two lines to read Port 20 and OR it with
  362. ;;              the appropriate mask for hte 8259 causes a nasty and subtle
  363. ;;              bug conflicting with the MS-MOUSE version 6.0 driver.  
  364. ;;              changing to a MOV AL,0bh fixes the problem, and still gets
  365. ;;              the 8259 programmed to the appropriate state.
  366. ;;
  367. ;       in      al,dx
  368. ;       or      AL,000001011b           ;Set the In-Service Reg. read
  369. ;;
  370. ;;      this is correct
  371. ;;
  372.         mov     AL,000001011b           ;Set the In-Service Reg. read
  373.                                         ;bits IRR=1 and ISR=1
  374.         out     DX,AL                   ;Tell 8259 to OUT ISR on next read
  375.         nop                             ;let the 8259 settle down
  376.         nop
  377.         nop
  378. status_8259_2:
  379.         in      AL,DX                   ;Get the ISR (clear int 8)
  380.         and     al,0FEh                 ;Set zero flag if no active interrupts
  381.         pop     DX
  382.  
  383.         lds     si,DPTR [DOSCRITERR]    ;zero says dos is interruptable
  384.  
  385.     ASSUMENODS
  386.  
  387.         or      al,[si]                 ;NOT zero says dos is in a critical state
  388.         lds     si,DPTR [INDOSFLAG]     ;add in second status byte
  389.         or      al,[si]
  390.         or      al,BPTR [INTFLAGS]              ;any flags says we're busy
  391.  
  392.         ; -- check to see if a print screen is in progress              ;v0.51
  393. BiosExtraSegment equ 50h                ;Bios extra data area           ;v0.51
  394. PrintScreenFlag  equ 00h                ;offset of PrintScreen flag     ;v0.51
  395.                                                                         ;v0.51
  396.         ASSUMENODS
  397.         mov     si,BiosExtraSegment     ;Checkout the PrintScrn flag    ;v0.51
  398.         mov     ds,si                   ;1=inprogress, -1=print error   ;v0.51
  399.         or      al,ds:PrintScreenFlag                                   ;v0.51
  400.  
  401.         pop     si
  402.         pop     ds
  403.         ret
  404. Checkstatus_8 endp
  405.  
  406. ENDIT
  407.