home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / PROGJRN / PJ_5_6.ARC / CAPSLOCK.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-08-07  |  6.8 KB  |  204 lines

  1. ;--------------------------------------------------------------------
  2. ;   Code For "The Case of the Invisible CapsLock" by Tom Swan
  3. ;        Page 24, Volume 5.5, Programmer's Journal
  4. ;--------------------------------------------------------------------
  5. ;
  6. ;  PURPOSE      : CapsLock Cursor Display program (TSR)
  7. ;
  8. ;  SYSTEM       : IBM PC-DOS
  9. ;
  10. ;  LANGUAGE     : Microsoft Macro Assembler (MASM)
  11. ;
  12. ;  AUTHOR       : (C) 1987 by Tom Swan, Swan Software, P.O. Box
  13. ;                 206, Lititz, PA 17543 
  14. ;
  15. ;--------------------------------------------------------------------
  16. ;----- Equates
  17.  
  18. cr              equ     13              ;ASCII carriage return
  19. lf              equ     10              ;ASCII line feed
  20. caps            equ     040h            ;CapsLock kbflag bit
  21. monochrome      equ     7               ;Monochrome video mode
  22. last8x8mode     equ     0eh             ;If <=, assume 8x8 chars
  23. fatStart14      equ     7               ;14-line cursor fat
  24. thinStart14     equ     11              ; and thin start/end lines
  25. endLine14       equ     12
  26. fatStart8       equ     3               ;8-line cursor fat
  27. thinStart8      equ     6               ; and thin start/end lines
  28. endLine8        equ     7
  29.  
  30.  
  31. BIOSDATA        SEGMENT AT 40H
  32.  
  33. kbflag          equ     017h            ;Keyboard flag offset
  34. crtmode         equ     049h            ;Current video mode
  35. BIOSDATA        ENDS
  36.  
  37.  
  38. ;----- Start of Program
  39.  
  40. CSEG            SEGMENT byte
  41.                 ASSUME  cs:CSEG,ds:CSEG,ss:CSEG,es:CSEG
  42.                 ORG     100h            ;com file entry point
  43.  
  44. CapsLock:       jmp     short init      ;jump to initialize program
  45.  
  46.  
  47. èpage;----------------------------------------------------------
  48. ; INT9
  49. ;----------------------------------------------------------
  50. ; Purpose       -- Trap keyboard interrupt #9 on every
  51. ;                   keypress.  Set cursor according to
  52. ;                   current CapsLock/NumLock settings
  53. ;                   then continue with normal interrupt.
  54. ;
  55. ; Called by     -- Keyboard hardware interrupt (#9)
  56. ;
  57. ; Calls         -- Jumps to pre-installation code
  58. ;                  Does not call DOS
  59. ;
  60. ; Arguments     -- none
  61. ;
  62. ; Registers     -- none changed
  63. ;----------------------------------------------------------
  64.  
  65.         ASSUME  cs:CSEG, ds:BIOSDATA
  66.  
  67. oldcaps db      0               ;last known capslock setting
  68. int9    PROC    near
  69.  
  70.         pushf                   ; save flags & registers
  71.         push    ax
  72.         push    cx
  73.         push    ds
  74.  
  75.         mov     ax,BIOSDATA     ;set dsregister to
  76.         mov     ds,ax           ; BIOS data segment
  77.         mov     ah,byte ptr [ds:kbflag]         ;get keyboard flag
  78.         and     ah,caps         ;isolate capslock bit
  79.         cmp     ah,byte ptr [cs:oldcaps]        ;compare old setting
  80.         je      exit            ;exit if not changed
  81.         mov     byte ptr[cs:oldcaps],ah         ;save new setting
  82.         mov     al,byte ptr [ds:crtmode]        ;get video mode
  83.         cmp     al,monochrome   ;if monochrome
  84.         je      line14          ; then use 14-line cursor settings
  85.         cmp     al,last8x8mode  ;else if less than this
  86.         jle     line8           ; then use 8-line cursor settings
  87.  
  88. line14:
  89.         mov     al,fatStart14   ; 14-line cursors
  90.         mov     ch,thinStart14
  91.         mov     cl,endLine14
  92.         jmp     short change
  93.  
  94. line8:
  95.         mov     al,fatStart8    ; 8-line cursors
  96.         mov     ch,thinStart8
  97.         mov     cl,endLine8
  98.  
  99.  
  100. ;----- Change cursor style.  At this point, ah=capslock bit,
  101. ;      al=fat start line, ch=thin startline, cl=end line 
  102. èchange:
  103.         or      ah,ah           ;test capslock setting
  104.         jz      nocaps          ;jump if key is off (thin style)
  105.         mov     ch,al           ;else switch to fat style
  106.  
  107. nocaps:
  108.         mov     ah,1            ;select cursor style
  109.         int     10h             
  110. ;execute BIOS video I/O interrupt
  111.  
  112. exit:
  113.         pop     ds              ;restore registers & flags
  114.         pop     cx
  115.         pop     ax
  116.         popf
  117.  
  118.  
  119. ;----- The following reserves space fora far jump instruction,
  120. ;      filled in by the initialization code.  This lets the program
  121. ;      continue to the original address that handled this interrupt
  122. ;      before installing the TSR code.
  123.  
  124.         db      0eah    ;ea=far jump hex code
  125.  
  126. address:
  127.         dd      0       ;32-bit jump address (unitialized)
  128.  
  129. int9    ENDP            ;end of procedure
  130.  
  131.  
  132. page
  133. ;----------------------------------------------------------
  134. ; INIT
  135. ;----------------------------------------------------------
  136. ; Purpose       -- Initialize interrupt trap, terminate
  137. ;                   program and stay resident.  All code
  138. ;                   from this point on is NOT saved
  139. ;                   in memory.  Everything before stays.
  140. ;
  141. ; Called by     -- Main program (via jmp)
  142. ;
  143. ; Calls         -- DOS
  144. ;----------------------------------------------------------
  145.  
  146.         ASSUME  cs:CSEG,ds:CSEG
  147.  
  148. init    PROC    near
  149.         mov     dx,offset id    ;print program id
  150.         mov     ah,9
  151.         int     21h
  152.  
  153.  
  154. ;----- Get vector to current interrupt #9 routine
  155.  
  156.         mov     ax,3509h        ;ah=35 
  157. è(get vector)
  158.                                 ;al=09 
  159. (vector number)
  160.         int     21h             ;set es:bx to current vector
  161.  
  162.  
  163. ;----- Insert vector as far jump address at end of resident code
  164.  
  165. init1:  mov     word ptr address,bx     ;set far jmp offset address
  166.         mov     word ptr address+2,es   ;set far jmp segment address
  167.  
  168. ;----- Change interrupt vector to the new TSR routine.
  169.  
  170.         mov     dx,offset int9  ;dx=address of routine
  171.         mov     ax,2509h        ;ah=25(set vector)
  172.                                 
  173. ;al=09(vector number)
  174.         int     21h             ;set interrupt 9 vector
  175.  
  176.  
  177. ;----- Make sure capslock bit is off.
  178.  
  179.         ASSUME  ds:BIOSDATA
  180.  
  181.         push    ds
  182.         mov     ax,BIOSDATA
  183.         mov     ds,ax           ;address BIOS data segment
  184.         and     byte ptr [ds:kbflag],not caps   ; turn off caps
  185.         pop     ds
  186.  
  187.         ASSUME  ds:CSEG
  188.  
  189.  
  190. ;----- Terminate and stay resident (TSR).
  191.  
  192.         mov     dx,offset init  ;dx = first available address
  193.         int     27h             ;terminate, stay resident
  194. init    ENDP                    ;end ofprocedure
  195.  
  196.  
  197. ;----- Program variables.
  198.  
  199. id      db      cr,lf, 'CapsLock Cursor Display Program'
  200.         db      cr,lf, '(C) 1987 by TomSwan'
  201.         db      cr,lf, 'Swan Software, PO Box 206, Lititz PA  17543'
  202.         db      cr,lf, '$'
  203.  
  204. CSEG    ends                    ;end ofsegment
  205.         end     CapsLock        ;end of program
  206.  
  207.