home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / asm_kit / case.asm < prev    next >
Assembly Source File  |  1985-05-11  |  8KB  |  184 lines

  1.  
  2. COMMENT^ *** CASE.COM *** Last Rev. 10/08/83 *** Vincent T. Bly ***
  3.  -------------------------------------------------------------------
  4. |                                    |
  5. | PURPOSE:  Provide a resident utility to aid assembly language     |
  6. |        programmers who wish to write their source code in        |
  7. |        ALL CAPS and their comments in lower case.            |
  8. |                                    |
  9. | FUNCTION: Change the cursor shape to indicate the present state   |
  10. |        of the "Caps Lock" key (block cursor for caps lock and  |
  11. |        underline cursor for upper/lower case).            |
  12. |        Shift to upper/lower case for comments whenever the ";" |
  13. |        key is pressed.                        |
  14. |        Shift to caps lock for source code whenever the "Enter" |
  15. |        key is pressed.                        |
  16. |        Toggle the ";"/"Enter" case switching off or on when-   |
  17. |        ever both shift keys are pressed simultaneously.        |
  18. |                                    |
  19. | TO USE:   From DOS, type CASE and press the "Enter" key.          |
  20. |                                    |
  21. | NOTES:    This version works with either the color graphics or    |
  22. |        monochrome card.  The DOS utilities (DIR, DEBUG, etc.)  |
  23. |        do not turn off the cursor during printing.  If you     |
  24. |        find the effect with the block cursor objectionable,    |
  25. |        you can temporarily turn off the case switching by        |
  26. |        pressing both shift keys simultaneously or you can        |
  27. |        change the DWs defining the cursor shapes.            |
  28. |                                    |
  29.  -------------------------------------------------------------------^
  30.  
  31. INTERRUPTS    SEGMENT AT 00H    ;*********** Interrupt vector table **
  32.         ORG    09H*4
  33. KB_INT        LABEL    DWORD        ; keyboard hardware interrupt
  34.         ORG    16H*4
  35. KEYBRD_INT    LABEL    DWORD        ; keyboard software interrupt
  36. INTERRUPTS    ENDS
  37.  
  38. BIOS_DATA    SEGMENT AT 40H    ;*********** BIOS data segment *******
  39.         ORG    10H
  40. EQUIP_FLAG    LABEL    WORD        ; bits 4 & 5 indicate CRT board type
  41.         ORG    17H
  42. KYBD_FLAG    LABEL    BYTE        ; primary keyboard status flag
  43.         ORG    63H
  44. ADDR_6845    LABEL    WORD        ; port address of 6845 index register
  45. BIOS_DATA    ENDS
  46.  
  47. CSEG        SEGMENT
  48.         ORG    100H        ; necessary for a .COM file
  49.         ASSUME    CS:CSEG
  50. START:        JMP    INITIALIZE    ; jump to initilization routine
  51. CAP_CURSOR_C    DW    0006H        ; caps lock cursor type (color board)
  52. CAP_CURSOR_M    DW    000BH        ;     as above, for monochrome board
  53. LOW_CURSOR_C    DW    0607H        ; upper/lower case cursor type (color)
  54. LOW_CURSOR_M    DW    0B0CH        ;     as above, for monochrome board
  55. ROM_KEY_INT    DD            ; ROM keyb'rd hardware interrupt addr.
  56. ROM_KYBD_IO    DD            ; ROM keyb'rd software interrupt addr.
  57. CASE_FLAG    DB    0FFH        ; case switching flag (FF=on, 00=off)
  58. OLD_KYF     DB    040H        ; old value of KYBD_FLAG
  59.  
  60.  
  61.  
  62. ;===========================================================================;
  63. @HARD_KYBD_INT    PROC    FAR            ; Keyboard hardware interrupts  ;
  64.         ASSUME CS:CSEG,DS:BIOS_DATA ; (09H) are re-vectored to here ;
  65.         STI                ;-------------------------------;
  66.         PUSHF            ; set-up to call like an interrupt
  67.         CALL    ROM_KEY_INT    ; call ROM BIOS, but return here
  68.         PUSH    AX        ; save regs
  69.         PUSH    DS
  70.         MOV    AX,BIOS_DATA    ; point DS to BIOS data seg
  71.         MOV    DS,AX
  72.         MOV    AL,[KYBD_FLAG]    ; get BIOS keyboard status flag
  73.         CMP    AL,CS:[OLD_KYF] ; has status flag changed?
  74.         JE    GO_BACK     ; if not, go back
  75.         MOV    CS:[OLD_KYF],AL ; refresh old status flag value
  76.         CALL    SET_CURSOR    ; go set proper cursor type
  77.         AND    AL,3        ; mask all but shift keys
  78.         CMP    AL,3        ; check for both shift keys down
  79.         JNE    GO_BACK     ; if not both shifts, skip toggle
  80.         MOV    AL,CS:[CASE_FLAG] ; get case switch flag
  81.         NOT    AL        ; toggle flag
  82.         MOV    CS:[CASE_FLAG],AL ; replace flag
  83. GO_BACK:    POP    DS
  84.         POP    AX
  85.         IRET            ; back to program
  86. @HARD_KYBD_INT    ENDP
  87.  
  88. ;============================================================================;
  89. SET_CURSOR    PROC    NEAR    ; Set cursor for uppr/lowr case or caps lock ;
  90.         ASSUME    CS:CSEG,DS:BIOS_DATA ;-------------------------------;
  91.         PUSH    AX        ; save regs
  92.         PUSH    BX
  93.         PUSH    DX
  94.         LEA    BX,LOW_CURSOR_C ; load upper/lower case cursor
  95.         TEST    AL,40H        ; is caps lock on?
  96.         JZ    CHK_BOARD    ; if not, go check board type
  97.         LEA    BX,CAP_CURSOR_C ; load caps lock cursor
  98. CHK_BOARD:    MOV    AX,EQUIP_FLAG    ; get equipment flag
  99.         AND    AX,30H        ; isolate CRT board type bits
  100.         CMP    AX,30H        ; is it monochrome board?
  101.         JNE    CG_SET        ; if not, skip ahead
  102.         ADD    BX,2        ; bump BX to mono cursor type
  103. CG_SET:     MOV    BX,CS:[BX]    ; get proper cursor into BX
  104.         MOV    DX,ADDR_6845    ; point to 6845 index reg
  105.         MOV    AL,10D        ; point to cursor start reg
  106.         OUT    DX,AL        ; select cursor start reg
  107.         INC    DX        ;     point to 6845 data reg
  108.         MOV    AL,BH        ;     data into AL
  109.         OUT    DX,AL        ;     data to cursor start reg
  110.         DEC    DX        ; point to 6845 index reg
  111.         MOV    AL,11D        ; point to cursor end reg
  112.         OUT    DX,AL        ; select cursor end reg
  113.         INC    DX        ;     point to 6845 data reg
  114.         MOV    AL,BL        ;     next data into AL
  115.         OUT    DX,AL        ;     data to cursor end reg
  116.         POP    DX        ; restore regs
  117.         POP    BX
  118.         POP    AX
  119.         RET
  120. SET_CURSOR    ENDP
  121.  
  122.  
  123. ;============================================================================;
  124. @SOFT_KYBD_INT    PROC    FAR             ; Keyboard software interrupts  ;
  125.         ASSUME    CS:CSEG,DS:BIOS_DATA ; (16H) are re-vectored to here ;
  126.         STI                 ;-------------------------------;
  127.         OR    AH,AH        ; is it wait for keyboard input?
  128.         JZ    THIS_ROUTINE    ; if so, do this routine
  129.         JMP    ROM_KYBD_IO    ; else go to ROM & back to caller
  130. THIS_ROUTINE:    PUSHF            ; set-up to CALL like an interrupt
  131.         CALL    ROM_KYBD_IO    ; call ROM BIOS, but return here
  132.         PUSH    AX        ; save caller's registers
  133.         PUSH    DS        ;    "
  134.         TEST    CS:[CASE_FLAG],1 ; is case switching flag on?
  135.         JZ    BACK_TO_CALLER    ; if case flag off, skip the rest
  136.         CMP    AL,";"          ; is the character a semicolon?
  137.         JE    CAPS_OFF    ; if so, go turn caps lock off
  138.         CMP    AL,0DH        ; is the character a carriage return?
  139.         JE    CAPS_ON     ; if so, go turn caps lock on
  140. BACK_TO_CALLER: POP    DS        ; restore caller's registers
  141.         POP    AX        ;    "
  142.         IRET            ; return to the caller
  143. ;--- Toggle caps lock for ";" or "Enter" ----------------------------------
  144. CAPS_ON:    STC            ; set carry to indicate caps on
  145. CAPS_OFF:    MOV    AX,BIOS_DATA    ; point to BIOS data segment
  146.         MOV    DS,AX
  147.         MOV    AL,[KYBD_FLAG]    ; get keyboard state flag
  148.         JC    SET_ON        ; if caps should be set on, skip ahead
  149.         AND    AL,NOT 40H    ; turn off caps lock
  150.         JMP    REPLACE_FLAG
  151. SET_ON:     OR    AL,40H        ; turn caps lock on
  152. REPLACE_FLAG:    MOV    [KYBD_FLAG],AL    ; replace keyboard state flag
  153.         CALL    SET_CURSOR    ; go set proper cursor type
  154.         JMP    BACK_TO_CALLER
  155. @SOFT_KYBD_INT    ENDP
  156.  
  157. ;============================================================================;
  158. INITIALIZE    PROC    NEAR              ; Re-vector keyb'rd interrupts ;
  159.         ASSUME    CS:CSEG,DS:INTERRUPTS ;------------------------------;
  160.         MOV    AX,INTERRUPTS    ; point to interrupt vector segment
  161.         MOV    DS,AX
  162. ;--- Set intercept for software keyboard interrupt -------------------------
  163.         MOV    AX,KEYBRD_INT    ; save old keyboard interrupt vector
  164.         MOV    ROM_KYBD_IO,AX
  165.         MOV    AX,KEYBRD_INT[2]
  166.         MOV    ROM_KYBD_IO[2],AX
  167.         MOV    AX,OFFSET @SOFT_KYBD_INT ; reset keyboard interrupt
  168.         MOV    KEYBRD_INT,AX    ; vector to point to this routine
  169.         MOV    KEYBRD_INT[2],CS
  170. ;--- Set intercept for hardware keyboard interrupt -------------------------
  171.         MOV    AX,KB_INT    ; save old keyboard interrupt vector
  172.         MOV    ROM_KEY_INT,AX
  173.         MOV    AX,KB_INT[2]
  174.         MOV    ROM_KEY_INT[2],AX
  175.         MOV    AX,OFFSET @HARD_KYBD_INT ; reset keyboard interrupt
  176.         MOV    KB_INT,AX    ; vector to point to this routine
  177.         MOV    KB_INT[2],CS
  178.         MOV    DX,OFFSET INITIALIZE ; point to end of resident code
  179.         INT    27H        ; terminate but stay resident
  180. INITIALIZE    ENDP
  181.  
  182. CSEG        ENDS
  183.         END    START
  184.