home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT11 / TSR00.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  7.6 KB  |  193 lines

  1. ;************************************************************************
  2. ;  Program TSR00 ( Chapter 11 )
  3. ;                                                                       *
  4. ;  TSR-program for output of the hot key codes in line 1
  5. ;
  6. ;  Execution by pressing:  Shift (R) + hot key (1-9)    
  7. ;
  8. ;  Author: A.I.SOPIN  VGU,  Voronezh  1992                Version 1.0   *
  9. ;
  10. ;  Interrupt INT 09h is used                                             
  11. ;                                                                       *
  12. ;************************************************************************
  13. NAME     TSR00
  14. ;  Saving the registers to be used
  15. PUSHR    MACRO  REGLST
  16.      IFB    <REGLST>
  17.      push   ax
  18.      push   bx
  19.      push   cx
  20.      push   dx
  21.      push   si
  22.      push   di
  23.      push   ds
  24.      push   es
  25.      push   bp
  26.      ENDIF
  27.      IRP    REG,<REGLST>
  28.      push   REG
  29.      ENDM
  30.      ENDM
  31. ;  Restoring the registers been used
  32. POPR     MACRO  REGLST
  33.      IFB    <REGLST>
  34.      pop    bp
  35.      pop    es
  36.      pop    ds
  37.      pop    di
  38.      pop    si
  39.      pop    dx
  40.      pop    cx
  41.      pop    bx
  42.      pop    ax
  43.      ENDIF
  44.      IRP    REG,<REGLST>
  45.      pop    REG
  46.      ENDM
  47.      ENDM
  48. ;----------------------------------------------------------
  49. CODE     SEGMENT 'CODE'
  50.      ASSUME CS:CODE,DS:CODE,ES:CODE
  51. ;----------------------------------------------------------
  52. OLD09H   LABEL  DWORD                   ;  old vector INT 09h address
  53. OFF09H   DW     0                       ;  offset of standart INT 09h 
  54. SEG09H   DW     0                       ;  segment address of INT 09h
  55. TXT0     DB     ' Shift + '
  56. KeyCode db      'X'
  57. TXT0E   db      ' keystroke has been pressed !!!    '
  58. CursCX  dw      ?
  59. CursDX  dw      ?
  60. PRES     DW     1234                    ;  signature  of program's presence
  61. ;----------------------------------------------------------
  62. ;  New handler of interrupt INT 09h
  63. ;  
  64. ;  Key combinations: Shift (R) + 1 - 9 are treated
  65. ;
  66. ;  On pressing them the text output to the cursor position is performed
  67. ;
  68. ;----------------------------------------------------------
  69. INT09H   PROC   FAR                  ;  ne interrupt INT 09h handler
  70.      cli                         ;  disable interrupts
  71.      PUSHR                       ;
  72.      mov    ax,40h               ;  keyboard data
  73.      mov    ES,ax                ; segment address for BIOS
  74.      mov    ch,ES:[17h]          ; state of register keys
  75.      in     al,60h               ;  obtain  the scan code
  76. ;  Testing for hot key being pressed (keys Shift + 1- 9)
  77.      and    ch,01h               ;  clearing of unnecessary flags
  78.      cmp    ch,01h               ;  previous Shift ?
  79.      jne    RET09                ;
  80.      sub    al,1                 ;  transform ASCII into a number
  81.      jng    RET09                ;  key  <  F1    
  82.      cmp    al,9                 ;
  83.      jg     RET09                ;  key >  F9
  84. ;  Editing the code of a hot key
  85.      or     al,30h               ;  obtain ASCII-code
  86.      mov    CS:KeyCode,al        ;  pass the code of a key
  87. ;  Hot key output and delay for 1.5 seconds
  88.      mov    ax,cs                ;
  89.      mov    ds,ax                ;  data segment in code segmen
  90.      mov    ah,0Fh               ;  function 0Fh - get video mode
  91.      int    10h                  ; BIOS video service call
  92.      mov    ah,03h
  93.      int    10h                  ; BIOS video service call
  94.      mov    CursCX,cx
  95.      mov    CursDX,dx
  96.      mov    bl,0
  97.      mov    cx,LengthOf TXT0+LengthOf TXT0E
  98.      mov    ah,0Eh
  99.      lea    si,0
  100. OutMsg:  mov    al,TXT0[si]
  101.     int     10h                  ; BIOS video service call
  102.     inc     si
  103.     loop    OutMsg   
  104.      mov    cx,25                ;  delay for  1.5 seconds
  105.      Call   DELAY                ;  generation of delay
  106.      mov    ah,02h
  107.      mov    cx,CursCX
  108.      mov    dx,CursDX
  109.      int    10h                  ; BIOS video service call
  110.      pushf                       ;  flag register for IRET (from INT 09h)
  111.      Call   CS:OLD09H            ;  call the old handler for INT 09h
  112.      mov    cx,LengthOf TXT0+LengthOf TXT0E
  113.      mov    al,' '
  114.      mov    ah,0Ah
  115.      int    10h
  116. ;  Restoring the screen after the text output
  117.     mov     ax,40h
  118.     mov     ES,ax               ;  ES points to BIOS data segment
  119.     mov     al,ES:[1Ah]         ;  address of keyboard buffer head
  120.     mov     ES:[1Ch],al         ;  clear buffer (tail ptr = head ptr)
  121.     jmp     ExHand
  122. ;  Restoring the registers and exit
  123. RET09:   pushf                       ;  flag register for IRET (from INT 09h)
  124.      Call   CS:OLD09H            ;  call the old handler for INT 09h
  125. ExHand:  POPR                        ;  restore the registers
  126.      sti                         ;  enable interrupts
  127.      IRET                        ;  exit from the interrupt handling
  128. INT09H   ENDP
  129. ;-----------------------------------------------------------
  130. ;
  131. ;  Procedure for the delay generation
  132. ;  
  133. ;  CX  - time of delay (in       1/18 sec) 
  134. ;
  135. ;-----------------------------------------------------------
  136. DELAY   PROC    NEAR
  137.     PUSHR   <ax,dx,es>
  138.     mov     ax,40h               ;
  139.     mov     ES,ax                ;  segment address of BIOS area
  140.     sti                          ;  enable interrupts
  141. T0:     mov     dx,ES:[6Ch]          ;  initial time (in ticks)
  142. T1:     cmp     dx,ES:[6Ch]          ;  has time passed ?
  143.     je      T1                   ;  no !!!
  144.     loop    T0                   ;
  145.     POPR    <es,dx,ax>
  146.     RETN
  147. DELAY   ENDP
  148. ;----------------------------------------------------------
  149. ;
  150. ;  Program for the initial loading of the TSR-part of TSR00
  151. ;
  152. ;----------------------------------------------------------
  153. ;  Checking for the presence of the TSR00 driver been loaded before 
  154. INSTALL:mov     ax,3509h          ;  read address of the current INT 09h vector
  155.     int     21h               ;  ES:BX  - address of the vector been read
  156.     mov     ax,cs             ;
  157.     mov     ds,ax             ;  data segment in code segment
  158.     mov     ax,CS:[bx-2]      ;  driver presence indicator
  159.     cmp     ax,CS:PRES        ;  is driver already in memory ?
  160.     jne     Modvec            ;  no, load th TSR-part
  161. ;  Output of message about the program loaded and exit
  162.     lea     dx,LOAD1          ;  address of message
  163.     mov     ah,9              ;  code for text output function
  164.     int     21h               ;  output the driver-been-loaded-message
  165.     mov     ax,4C01h          ;  Return Code
  166.     int     21h               ;  Return to  MS-DOS
  167. ;----------------------------------------------------------
  168. ;  Modification of the keyboard interrupt INT 09h vector
  169. Modvec: mov     ax,3509h          ;  read address of current vector INT 09h
  170.     int     21h               ;  ES:BX  -address of the vector been read
  171.     mov     CS:OFF09H,bx      ;  pass the address of the  old vector
  172.     mov     CS:SEG09H,es      ;  pass the old segment address
  173.     lea     dx,INT09H         ;  DS:DX -address of the new vector
  174.     mov     ax,2509h          ;  introduce a new interrupt INT 09h vector
  175.     int     21h               ;
  176. ;  Loading of the TSR-part of the program
  177.     lea     dx,LOAD0          ;  message address
  178.     mov     ah,9              ;  text output function code
  179.     int     21h               ;  output the driver-been-loaded-message
  180.     lea     dx,INSTALL        ;  the length of the TSR-part
  181.     mov     cl,4              ;  4 shifts to the right (to divide by 16)
  182.     shr     dx,cl             ;  the length of the TSR-part in paragraphs
  183.     add     dx,20             ;  16  paragraphs for  PSP + 4
  184.     mov     ax,3100h          ;  terminate-stay -resident
  185.     int     21h               ;  KEEP
  186. ;----------------------------------------------------------
  187. LOAD0   DB      10,13,'*** The TSR00 program  is loaded *** ',13,10
  188.     DB      10,13,' To activate press:   '
  189.     DB      10,13,'   Shift (R)  +  numeric key (1-9) $ ',13,10
  190. LOAD1   DB      10,13,' The TSR00 program had been loaded $ ',13,10
  191. CODE    ENDS
  192.     END     INSTALL
  193.