home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / dtx9101 / tricks / ansi / txansi.asm < prev    next >
Encoding:
Assembly Source File  |  1991-10-11  |  44.6 KB  |  1,582 lines

  1. ;* ------------------------------------------------------- *
  2. ;*                     TXANSI.ASM                          *
  3. ;*              DOS-Toolbox ANSI-Treiber                   *
  4. ;* ------------------------------------------------------- *
  5. ;*  Erzeugen:   MASM    txansi ;                           *
  6. ;*              LINK    txansi                             *
  7. ;*  oder                                                   *
  8. ;*              TASM    txansi                             *
  9. ;*              TLINK   txansi                             *
  10. ;*  und                                                    *
  11. ;*              EXE2BIN txansi.exe txansi.sys              *
  12. ;*              DEL     txansi.exe                         *
  13. ;* ------------------------------------------------------- *
  14.  
  15. CODE   SEGMENT BYTE PUBLIC 'CODE'
  16. ASSUME CS:CODE,DS:CODE,ES:NOTHING,SS:NOTHING
  17.  
  18. ; -------------------------------------
  19. ; Constants
  20.  
  21. MaxCmd          EQU    0Ch
  22. ScrSegMono      EQU    0B000h
  23. ScrSegColor     EQU    0B800h
  24. TRUE            EQU    01h
  25. FALSE           EQU    00h
  26.  
  27. ; -------------------------------------
  28. ; Characters
  29.  
  30. quote           EQU    22h
  31. CR              EQU    0Dh
  32. LF              EQU    0Ah
  33. BEL             EQU    07h
  34. BS              EQU    08h
  35. ESC             EQU    1Bh
  36.  
  37. ; -------------------------------------
  38.  
  39.   ORG            00h
  40.  
  41. ; ----------------------------------------------------------
  42. ; Header
  43.  
  44.                 DD     -1              ; Next Driver
  45.  
  46.                 DW     0C013h          ; Attribute
  47.  
  48.                 DW     Offset Strategy
  49.                 DW     Offset Interrupt
  50.  
  51.                 DB     "CON     "      ; Driver Name
  52.  
  53.  
  54. ; ----------------------------------------------------------
  55. ; Dispatch_Table
  56.  
  57. Dispatch        DW     Offset Init
  58.                 DW     Offset Exit_01    ; MediaCheck
  59.                 DW     Offset Exit_01    ; BuildBPB
  60.                 DW     Offset Exit_Error ; IOCTL_Read
  61.                 DW     Offset Read
  62.                 DW     Offset NdRead
  63.                 DW     Offset Exit_01    ; InpStat
  64.                 DW     Offset InpFlush
  65.                 DW     Offset Write
  66.                 DW     Offset Write      ; WriteVfy
  67.                 DW     Offset Exit_01    ; OutStat
  68.                 DW     Offset OutFlush
  69.                 DW     Offset Exit_01    ; IOCTL_Write
  70.  
  71. DevHdr          DW     ?                 ; Offset
  72.                 DW     ?                 ; Segment
  73.  
  74. ; ----------------------------------------------------------
  75.  
  76. Strategy PROC FAR
  77.  
  78.                 MOV  Word Ptr CS:[DevHdr+00h],BX
  79.                 MOV  Word Ptr CS:[DevHdr+02h],ES
  80.                 RETF
  81.  
  82. Strategy ENDP
  83.  
  84. ; ----------------------------------------------------------
  85.  
  86. Interrupt PROC FAR
  87.  
  88.                 PUSH   SI              ; save Registers
  89.                 PUSH   AX
  90.                 PUSH   CX
  91.                 PUSH   DX
  92.                 PUSH   DI
  93.                 PUSH   DS
  94.                 PUSH   ES
  95.                 PUSH   BX
  96.                 LEA    SI, Dispatch
  97.                 LDS    BX, DWord Ptr CS:[DevHdr]
  98.                 MOV    CX,[BX+12h]
  99.                 MOV    AL,[BX+02h]     ; Cmd_Code
  100.                 CMP    AL, MaxCmd
  101.                 JA     Exit_Error      ; invalid Code
  102.  
  103.                 CBW                    ; Cmd_Code  -> AX
  104.                 ADD    SI,AX           ; Func_Code -> SI
  105.                 ADD    SI,AX           ; * 2
  106.                 LES    DI,[BX+0Eh]     ; Buffer
  107.                 MOV    AX,CS
  108.                 MOV    DS,AX           ; DS := CS
  109.  
  110.                 JMP    Word Ptr [SI]   ; Jump Function
  111.  
  112. ; ----------------------------------------------------------
  113.  
  114. Exit_03:        MOV    AH,03h          ; Status := 3
  115.                 JMP    Short Drv_Exit
  116.  
  117. Exit_Error:     MOV    AL,03h          ; Status := 3
  118.                 MOV    AH,81h
  119.                 STC
  120.                 JMP    Short Drv_Exit
  121.  
  122. Exit_01:        MOV    AH,01h          ; Status := 1
  123.  
  124. Drv_Exit:       LDS    BX, DWord Ptr CS:[DevHdr]
  125.  
  126.                 MOV    [BX+03h],AX     ; Return Status
  127.                 POP    BX              ; restore Registers
  128.                 POP    ES
  129.                 POP    DS
  130.                 POP    DI
  131.                 POP    DX
  132.                 POP    CX
  133.                 POP    AX
  134.                 POP    SI
  135.                 RETF
  136.  
  137. Interrupt ENDP
  138.  
  139. ; ----------------------------------------------------------
  140.  
  141. ANSI_Seq_Len    DB     00h
  142. ANSI_Seq_Buf    DB     10 DUP(00h)
  143.  
  144. ESC_Flag        DW     0001h
  145. Buffer          DB     255 DUP(00h)
  146. Buf_End         DB     00h
  147. Sentinel        DW     0000h
  148. Nd_Read         DB     FALSE
  149. ANSI_End        DW     0000h
  150. StrPtr          DW     0000h
  151. Key_Index       DW     0093h
  152. Sav_Index       DW     0001h
  153. StrLen          DW     0000h
  154. Rst_Index       DW     0001h
  155. IdxLen          DW     0000h
  156.  
  157. ; ----------------------------------------------------------
  158.  
  159. Read PROC NEAR
  160.  
  161.                 MOV    Byte Ptr DS:[Nd_Read], FALSE
  162.                 JCXZ   Read_Exit       ; if (CX == 0)
  163.  
  164. Read_1:         PUSH   DI
  165.                 PUSH   ES
  166.                 PUSH   DS
  167.                 POP    ES              ; ES := DS
  168.                 CALL   Store_ANSI      ; Store ANSI Sequence
  169.                 POP    ES
  170.                 POP    DI
  171.                 STOSB                  ; AL -> ES:DI
  172.                 LOOP   Read_1
  173.  
  174. Read_Exit:      JMP    Exit_01
  175.  
  176. Read ENDP
  177.  
  178. ; ----------------------------------------------------------
  179.  
  180. Store_ANSI PROC NEAR
  181.  
  182.                 XOR    AX,AX           ; AX = 0
  183.                 CALL   Concat_ANSI     ; Concat ANSI String
  184.                 OR     AL,AL           ; if (AL == 0)
  185.                 JZ     Store_ANSI_1    ; Kbd -> ANSI Buffer
  186.  
  187.                 RET
  188.  
  189. Store_ANSI_1:   INT    16h             ; Read Key
  190.                 CALL   Copy_ANSI       ; AL -> ANSI Buffer
  191.                 RET
  192.  
  193. Store_ANSI ENDP
  194.  
  195. ; ----------------------------------------------------------
  196.  
  197. NdRead PROC NEAR
  198.  
  199.                 PUSH   ES
  200.                 PUSH   DS
  201.                 POP    ES              ; ES = DS
  202.  
  203.                 MOV    Byte Ptr DS:[Nd_Read], TRUE
  204.  
  205.                 XOR    AX,AX           ; AX = 0
  206.                 CALL   Concat_ANSI     ; Concat ANSI String
  207.                 OR     AL,AL
  208.                 JNZ    NdRead_1        ; if (AL != 0)
  209.  
  210.                 MOV    AH,01h
  211.                 INT    16h             ; Check Key
  212.                 JZ     NdRead_2        ; if (no_char)
  213.  
  214.                                        ; char waiting ->
  215.                 CALL   Copy_ANSI       ; AL -> ANSI Buffer
  216.  
  217. NdRead_1:       LDS    BX, DWord Ptr CS:[DevHdr]
  218.                 MOV    [BX+0Dh],AL     ; AL -> DevHdr + 0Dh
  219.                 POP    ES
  220.                 JMP    Exit_01         ; Return Status = 1
  221.  
  222. NdRead_2:       POP    ES
  223.                 JMP    Exit_03         ; Return Status = 3
  224.  
  225. NdRead ENDP
  226.  
  227. ; ----------------------------------------------------------
  228.  
  229. Concat_ANSI PROC NEAR
  230.  
  231.                 MOV    SI, Word Ptr DS:[Sav_Index]
  232.                 CMP    SI, Word Ptr DS:[StrLen]
  233.                 JG     Concat_ANSI_1
  234.  
  235.                 LODSB                  ; DS:SI -> AL
  236.                 CMP    Byte Ptr DS:[Nd_Read], FALSE
  237.                 JZ     Concat_ANSI_2
  238.  
  239.                 RET
  240.  
  241. Concat_ANSI_2:  MOV    Word Ptr DS:[Sav_Index],SI
  242.                 RET
  243.  
  244. Concat_ANSI_1:  MOV    SI,Word Ptr DS:[Rst_Index]
  245.                 CMP    SI,Word Ptr DS:[IdxLen]
  246.                 JG     Concat_ANSI_3
  247.  
  248.                 LODSB                  ; DS:SI -> AL
  249.                 CMP    Byte Ptr DS:[Nd_Read], FALSE
  250.                 JZ     Concat_ANSI_4
  251.  
  252.                 RET
  253.  
  254. Concat_ANSI_4:  MOV    Word Ptr DS:[Rst_Index],SI
  255.                 RET
  256.  
  257. Concat_ANSI_3:  CMP    Byte Ptr DS:[ANSI_Seq_Len],00h
  258.                 JNZ    Concat_ANSI_5
  259.  
  260.                 RET
  261.  
  262. Concat_ANSI_5:  MOV    AL, Byte Ptr DS:[ANSI_Seq_Len]
  263.                 CMP    Byte Ptr DS:[Nd_Read], FALSE
  264.                 JZ     Concat_ANSI_6
  265.  
  266.                 RET
  267.  
  268. Concat_ANSI_6:  MOV    Byte Ptr DS:[ANSI_Seq_Len],00h
  269.                 RET
  270.  
  271. Concat_ANSI ENDP
  272.  
  273. ; ----------------------------------------------------------
  274.  
  275. Copy_ANSI PROC NEAR
  276.  
  277.                 LEA    SI, Word Ptr DS:[Buffer]
  278.  
  279. Copy_ANSI_1:    MOV    Word Ptr DS:[Sentinel], 0003h
  280.                 CMP    Word Ptr [SI],+00h
  281.                 JZ     Copy_ANSI_4     ; Buffer empty
  282.  
  283.                 CMP    AL,[SI+02h]
  284.                 JNZ    Copy_ANSI_3
  285.  
  286.                 OR     AL,AL
  287.                 JNZ    Copy_ANSI_2     ; if (AL != 0)
  288.  
  289.                 MOV    Word Ptr DS:[Sentinel],0004h
  290.                 CMP    AH,[SI+03h]
  291.                 JZ     Copy_ANSI_2
  292.  
  293. Copy_ANSI_3:    ADD    SI,[SI]
  294.                 JMP    Short Copy_ANSI_1
  295.  
  296. Copy_ANSI_2:    CMP    Byte Ptr DS:[Nd_Read], FALSE
  297.                 JZ     Copy_ANSI_5
  298.  
  299.                 ADD    SI,Word Ptr DS:[Sentinel]
  300.                 MOV    AL,[SI]
  301.                 RET
  302.  
  303. Copy_ANSI_5:    MOV    DI,SI
  304.                 ADD    DI,[SI]
  305.                 DEC    DI
  306.                 MOV    Word Ptr DS:[IdxLen],DI
  307.                 ADD    SI, Word Ptr DS:[Sentinel]
  308.                 MOV    AL,[SI]
  309.                 INC    SI
  310.                 MOV    Word Ptr DS:[Rst_Index],SI
  311.                 RET
  312.  
  313. Copy_ANSI_4:    OR     AL,AL
  314.                 JZ     Copy_ANSI_6     ; if (AL == 0)
  315.  
  316.                 RET
  317.  
  318. Copy_ANSI_6:    CMP    Byte Ptr DS:[Nd_Read], FALSE
  319.                 JZ     Copy_ANSI_7
  320.  
  321.                 RET
  322.  
  323. Copy_ANSI_7:    MOV    Byte Ptr DS:[ANSI_Seq_Len], AH
  324.                 RET
  325.  
  326. Copy_ANSI ENDP
  327.  
  328. ; ----------------------------------------------------------
  329.  
  330. InpFlush PROC NEAR
  331.  
  332.                 ; Reset variables
  333.  
  334.                 MOV    Byte Ptr DS:[ANSI_Seq_Len],   00h
  335.                 MOV    Word Ptr DS:[Sav_Index],    0001h
  336.                 MOV    Word Ptr DS:[StrLen],       0000h
  337.                 MOV    Word Ptr DS:[Rst_Index],    0001h
  338.                 MOV    Word Ptr DS:[IdxLen],       0000h
  339.  
  340.                 ; Flush Kbd Buffer
  341.  
  342. InpFlush_1:     MOV    AH,01h
  343.                 INT    16h             ; Check Key
  344.                 JZ     InpFlush_2      ; if (no_char)
  345.  
  346.                 XOR    AH,AH
  347.                 INT    16h             ; Read Key
  348.                 JMP    Short InpFlush_1
  349.  
  350. InpFlush_2:     JMP    Exit_01         ; Return Status = 1
  351.  
  352. InpFlush ENDP
  353.  
  354. ; ----------------------------------------------------------
  355.  
  356. Write PROC NEAR
  357.  
  358.                 JCXZ   Write_Exit      ; if (CX == 0)
  359.  
  360.                 MOV    SI,DI
  361.  
  362. Write_2:        MOV    BX,ES
  363.                 MOV    DS,BX           ; DS := ES
  364.                 LODSB                  ; DS:SI -> AL
  365.                 PUSH   CX
  366.                 PUSH   SI
  367.                 PUSH   ES
  368.                 MOV    BX,CS
  369.                 MOV    DS,BX           ; DS := CS
  370.                 MOV    ES,BX           ; ES := CS
  371.                 CALL   ANSI            ; Main Parsing Loop
  372.                 POP    ES
  373.                 POP    SI
  374.                 POP    CX
  375.                 LOOP   Write_2
  376.  
  377. Write_Exit:     JMP    Exit_01         ; Return Status = 1
  378.  
  379. Write ENDP
  380.  
  381. ; ----------------------------------------------------------
  382.  
  383. OutFlush PROC NEAR
  384.  
  385.                 CALL   Flush           ; Set Variables
  386.                 JMP    Exit_01         ; Return Status = 1
  387.  
  388. OutFlush ENDP
  389.  
  390. ; ----------------------------------------------------------
  391. ; New Interrupt 29  (Quick Screen Output)
  392.  
  393. QuickScreen PROC NEAR
  394.  
  395.                 STI
  396.                 PUSH   AX
  397.                 PUSH   BX
  398.                 PUSH   CX
  399.                 PUSH   DX
  400.                 PUSH   SI
  401.                 PUSH   DI
  402.                 PUSH   DS
  403.                 PUSH   ES
  404.  
  405.                 MOV    BX,CS
  406.                 MOV    DS,BX           ; DS := CS
  407.                 MOV    ES,BX           ; ES := CS
  408.                 CALL   ANSI            ; Main Parsing Loop
  409.  
  410.                 POP    ES
  411.                 POP    DS
  412.                 POP    DI
  413.                 POP    SI
  414.                 POP    DX
  415.                 POP    CX
  416.                 POP    BX
  417.                 POP    AX
  418.                 IRET
  419.  
  420. QuickScreen ENDP
  421.  
  422. ; ----------------------------------------------------------
  423.  
  424. CursorPos       DW     0000h
  425. ScreenPage      DB     00h
  426. TextAttr        DB     07h             ; black/white
  427. Row             DB     00h
  428. Column          DB     00h
  429. MaxColumn       DB     4Fh             ; = 79d
  430. MaxRow          DB     18h             ; = 24d
  431. Monochrome      DB     FALSE
  432. CharFlag        DB     FALSE
  433. NumFlag         DB     FALSE
  434.  
  435. KeyTable        DB     "A"
  436.                 DW     Offset MoveCursor
  437.                 DW     Offset CurUp         ; Cursor up
  438.  
  439.                 DB     "B"
  440.                 DW     Offset MoveCursor
  441.                 DW     Offset CurDown       ; Cursor down
  442.  
  443.                 DB     "C"
  444.                 DW     Offset MoveCursor
  445.                 DW     Offset CurRight      ; Cursor right
  446.  
  447.                 DB     "D"
  448.                 DW     Offset MoveCursor
  449.                 DW     Offset CurLeft       ; Cursor left
  450.  
  451.                 DB     "H"
  452.                 DW     Offset MoveCursor_0  ; Move Cursor:
  453.                 DW     Offset GoXY          ; GotoXY
  454.  
  455.                 DB     "f"
  456.                 DW     Offset MoveCursor_0  ; Move Cursor:
  457.                 DW     Offset GoXY          ; GotoXY
  458.  
  459.                 DB     "u"
  460.                 DW     Offset MoveCursor_0  ; Move Cursor:
  461.                 DW     Offset StoreCurPos   ; Store CurPos
  462.  
  463.                 DB     "s"
  464.                 DW     Offset RestCurPos    ; Restore CurPos
  465.                 DW     0000h
  466.  
  467.                 DB     "J"
  468.                 DW     Offset ClrScreen
  469.                 DW     0000h
  470.  
  471.                 DB     "k"
  472.                 DW     Offset ClrEoL
  473.                 DW     0000h
  474.  
  475.                 DB     "K"
  476.                 DW     Offset ClrEoL
  477.                 DW     0000h
  478.  
  479.                 DB     "m"
  480.                 DW     Offset GraphParms
  481.                 DW     0000h
  482.  
  483.                 DB     "h"
  484.                 DW     Offset ScreenParms
  485.                 DW     0000h
  486.  
  487.                 DB     "l"
  488.                 DW     Offset ScreenParms2
  489.                 DW     0000h
  490.  
  491.                 DB     "n"
  492.                 DW     Offset WhereXY
  493.                 DW     0000h
  494.  
  495.                 DB     "c"
  496.                 DW     Offset Color
  497.                 DW     0000h
  498.  
  499.                 DB     "p"
  500.                 DW     Offset Params
  501.                 DW     0000h
  502.  
  503.                 DB     00h             ; End of Table
  504.  
  505. ; ----------------------------------------------------------
  506.  
  507. ANSI PROC NEAR
  508.  
  509.                 CMP    Word Ptr DS:[ESC_Flag],+01h
  510.                 JZ     ANSI_1
  511.                 JB     ANSI_2
  512.                 JMP    ANSI_3
  513.  
  514. ANSI_2:         JMP    ANSI_18
  515.  
  516. ANSI_1:         CMP    AL, ESC
  517.                 JA     ANSI_4
  518.  
  519.                 JNZ    PutChar
  520.  
  521.                 MOV    Word Ptr DS:[ESC_Flag],0000h
  522.                 MOV    Byte Ptr DS:[CharFlag],00h
  523.                 RET
  524.  
  525. PutChar:        CMP    AL, CR
  526.                 JNZ    ANSI_6
  527.  
  528.                 MOV    Byte Ptr DS:[Column],00h
  529.  
  530. ANSI_6:         CMP    AL, BEL
  531.                 JNZ    ANSI_7
  532.  
  533.                 CALL   Beep
  534.                 RET
  535.  
  536. ANSI_7:         MOV    AH, 0Eh
  537.                 MOV    BL, Byte Ptr DS:[TextAttr]
  538.                 INT    10h             ; Write TTY Char
  539.                 RET
  540.  
  541. ANSI_4:         XOR    BX,BX
  542.                 MOV    ES,BX           ; ES := 0
  543.                 MOV    AH, Byte Ptr ES:[0449h]
  544.  
  545.                        ; 0040h:0049h -> CrtMode
  546.  
  547.                 CMP    AH,07h
  548.                 JZ     ANSI_8          ; if (CrtMode == 7)
  549.  
  550.                 CMP    AH,03h
  551.                 JBE    ANSI_9          ; if (CrtMode <= 3)
  552.  
  553.                 JMP    Short ANSI_7    ; Write TTY (AL)
  554.  
  555. ANSI_8:         MOV    Byte Ptr CS:[Monochrome], TRUE
  556.  
  557. ANSI_9:         MOV    BL, Byte Ptr ES:[0462h]
  558.  
  559.                        ; 0040h:0062h -> ActPage
  560.  
  561.                 MOV    Byte Ptr DS:[ScreenPage], BL
  562.                 SHL    BL,1
  563.                 ADD    BX,0450h
  564.                 MOV    DX,ES:[BX]
  565.  
  566.                 MOV    CX, Word Ptr ES:[044Ah]
  567.  
  568.                        ; 0040h:004Ah -> Columns
  569.  
  570.                 DEC    CX
  571.                 MOV    Byte Ptr DS:[MaxColumn],CL
  572.                 MOV    Byte Ptr DS:[MaxRow],18h
  573.  
  574.                 MOV    BL, Byte Ptr ES:[0484h]
  575.  
  576.                        ; 0040h:0084h -> Rows
  577.  
  578.                 OR     BL,BL
  579.                 JZ     ANSI_10         ; if (BL == 0)
  580.  
  581.                 MOV    Byte Ptr CS:[Monochrome], TRUE
  582.                 MOV    Byte Ptr DS:[MaxRow],BL
  583.  
  584. ANSI_10:        CMP    Byte Ptr DS:[Column],01h
  585.                 JNZ    ANSI_11
  586.  
  587.                 RET
  588.  
  589. ANSI_11:        MOV    AH,Byte Ptr DS:[TextAttr]
  590.                 MOV    BH,Byte Ptr DS:[ScreenPage]
  591.                 PUSH   ES
  592.                 PUSH   DX
  593.                 MOV    CX, AX
  594.                 CALL   NormColumns
  595.                 MOV    DX, Word Ptr ES:[0463h]
  596.  
  597.                        ; 0040h:0063h -> Video Base
  598.  
  599.                 ADD    DX,+06h         ; Crt Status
  600.  
  601.                 MOV    AX, ScrSegColor
  602.                 CMP    Byte Ptr ES:[0449h],07h
  603.  
  604.                        ; 0040h:0049h -> CrtMode
  605.  
  606.                 JNZ    ANSI_12
  607.  
  608.                 MOV    AX, ScrSegMono
  609.  
  610. ANSI_12:        MOV    ES,AX           ; ES = ScreenSeg
  611.                 CMP    Byte Ptr DS:[Monochrome], TRUE
  612.                 JZ     ANSI_13
  613.  
  614.                        ; Wait for horizontal retrace
  615.  
  616. ANSI_14:        IN     AL,DX           ; Port_IN:VideoBase + 6
  617.                                        ; ( Status )
  618.                 ROR    AL,1
  619.                 JB     ANSI_14         ; if (Bit_0)
  620.  
  621.                 CLI
  622.  
  623. ANSI_15:        IN     AL,DX           ; Port_IN:VideoBase + 6
  624.                                        ; ( Status )
  625.                 ROR    AL,1
  626.                 JNB    ANSI_15         ; if !(Bit_0)
  627.  
  628. ANSI_13:        MOV    AX,CX
  629.                 STOSW                  ; AX -> ES:DI
  630.                 STI
  631.                 POP    DX
  632.                 POP    ES
  633.                 INC    DL
  634.                 CMP    DL,Byte Ptr DS:[MaxColumn]
  635.                 JBE    ANSI_16
  636.  
  637.                 CMP    Byte Ptr DS:[Row],01h
  638.                 JNZ    ANSI_17         ; Bottom of screen
  639.  
  640.                 MOV    Byte Ptr DS:[Column],01h
  641.                 RET
  642.  
  643. ANSI_17:        XOR    DL,DL           ; DL = 0
  644.                 INC    DH
  645.                 CMP    DH, Byte Ptr DS:[MaxRow]
  646.                 JBE    ANSI_16
  647.  
  648.                                        ; if (Row > MaxRows)
  649.                 MOV    AH,06h          ; Scroll Up
  650.                 CALL   Scroll
  651.  
  652.                 XOR    DL,DL           ; DL = 0
  653.                 MOV    DH,Byte Ptr DS:[MaxRow]
  654.  
  655. ANSI_16:        MOV    AL,Byte Ptr DS:[ScreenPage]
  656.                 CBW                    ; WORD(ScrPage)
  657.                 SHL    AX,1            ; ScrPage * 2
  658.                 ADD    AX,0450h
  659.                 MOV    DI,AX
  660.                 MOV    ES:[DI],DX
  661.                 CALL   NormColumns
  662.                 SHR    DI,1
  663.                 MOV    CX,DI
  664.                 MOV    AH,0Eh
  665.                 MOV    DI,DX           ; Save DX
  666.                 CALL   OutVideo
  667.                 MOV    DX,DI           ; Restore DX
  668.                 RET
  669.  
  670. ANSI_18:        CALL   Flush
  671.                 CMP    AL,5Bh
  672.                 JZ     ANSI_19         ; if ( AL == "[" )
  673.  
  674.                 CMP    AL,5Ah
  675.                 JNZ    ANSI_20         ; if ( AL != "Z" )
  676.  
  677.                 CALL   Color
  678.                 JMP    Flush
  679.  
  680. ANSI_20:        CMP    AL,37h
  681.                 JNZ    ANSI_21         ; if ( AL != "7" )
  682.  
  683.                 CALL   RestCurPos      ; Restore CurPos
  684.                 JMP    Flush
  685.  
  686. ANSI_21:        CMP    AL,38h
  687.                 JNZ    ANSI_22         ; if ( AL != "8" )
  688.  
  689.                 CALL   StoreCurPos     ; Store CurPos
  690.                 CALL   ANSI_16
  691.                 JMP    Flush
  692.  
  693. ANSI_22:        CMP    AL,44h
  694.                 JNZ    ANSI_23         ; if ( AL != "D" )
  695.  
  696.                 MOV    AH,06h
  697.                 JMP    Short ANSI_24
  698.  
  699. ANSI_23:        CMP    AL,4Dh
  700.                 JNZ    ANSI_25         ; if ( AL != "M" )
  701.  
  702.                 MOV    AH,07h
  703.  
  704. ANSI_24:        MOV    DH, Byte Ptr DS:[MaxRow]
  705.                 DEC    DH
  706.                 CALL   Scroll_1
  707.                 JMP    Flush
  708.  
  709. ANSI_25:        JMP    Put_And_Flush
  710.  
  711. ANSI_19:        MOV    Word Ptr DS:[ESC_Flag],0002h
  712.                 RET
  713.  
  714. ANSI_3:         CMP    AL,3Fh
  715.                 JZ     ANSI_27         ; if ( AL == "?" )
  716.  
  717.                 CMP    AL,3Dh
  718.                 JZ     ANSI_27         ; if ( AL == "=" )
  719.  
  720.                 CMP    AL,3Bh
  721.                 JZ     ANSI_27         ; if ( AL == ";" )
  722.  
  723.                 CMP    AL,30h
  724.                 JB     ANSI_28         ; if ( AL < "0" )
  725.  
  726.                 CMP    AL,39h
  727.                 JBE    ANSI_27         ; if ( AL <= "9" )
  728.  
  729. ANSI_28:        CMP    AL, quote
  730.                 JZ     ANSI_29         ; if ( AL == '"' )
  731.  
  732.                 TEST   Byte Ptr DS:[CharFlag], TRUE
  733.                 JNZ    ANSI_27
  734.  
  735.                 JMP    Short ANSI_31
  736.  
  737. ANSI_29:        XOR    Byte Ptr DS:[CharFlag], 01h
  738.  
  739. ANSI_27:        CMP    Word Ptr DS:[ANSI_End], Offset Buf_End
  740.                 JNB    ANSI_30
  741.  
  742.                 MOV    DI, Word Ptr DS:[ANSI_End]
  743.                 MOV    [DI],AL
  744.                 INC    Word Ptr DS:[ANSI_End]
  745.                 RET
  746.  
  747. ANSI_30:        JMP    Short EmitParms
  748.  
  749.                 NOP
  750.  
  751. ANSI_31:        MOV    Word Ptr DS:[ESC_Flag], 0001h
  752.                 DEC    Word Ptr DS:[ANSI_End]
  753.  
  754.                 MOV    DI, Offset KeyTable - 5
  755.  
  756. ANSI_32:        ADD    DI,+05h
  757.                 CMP    Byte Ptr [DI],00h
  758.                                        ; Proceed table
  759.                                        ; until key = 00h
  760.                 JNZ    ANSI_33
  761.  
  762.                 JMP    Short EmitParms
  763.  
  764.                 NOP
  765.  
  766. ANSI_33:        CMP    AL,[DI]         ; table key
  767.                 JNZ    ANSI_32         ; try next
  768.  
  769.                                        ; table key found:
  770.                 MOV    SI, Word Ptr DS:[Key_Index]
  771.                 MOV    Word Ptr DS:[StrPtr], SI
  772.  
  773.                 CALL   Word Ptr [DI+01h]
  774.                                        ; first table proc
  775.                 RET
  776.  
  777. ANSI ENDP
  778.  
  779. ; ----------------------------------------------------------
  780.  
  781. Parse PROC NEAR
  782.  
  783.                 MOV    Byte Ptr DS:[NumFlag], FALSE
  784.                 XOR    AX, AX          ; AX = 0
  785.                 PUSH   DI              ; save table key
  786.  
  787. Parse_1:        MOV    DI, Word Ptr DS:[StrPtr]
  788.                 CMP    DI, Word Ptr DS:[ANSI_End]
  789.                 JG     Parse_2
  790.  
  791.                 CMP    Byte Ptr [DI], "="
  792.                 JZ     Parse_3
  793.  
  794.                 CMP    Byte Ptr [DI], "?"
  795.                 JZ     Parse_3
  796.  
  797.                 CMP    Byte Ptr [DI], ";"
  798.                 JZ     Parse_4
  799.  
  800.                 MOV    CL,0Ah
  801.                 MUL    CL              ; AX := CL * 10
  802.                 SUB    Byte Ptr [DI], "0"
  803.                 ADD    AL,[DI]
  804.                 MOV    Byte Ptr DS:[NumFlag], TRUE
  805.  
  806. Parse_3:        INC    Word Ptr DS:[StrPtr]
  807.                 JMP    Short Parse_1
  808.  
  809. Parse_4:        INC    Word Ptr DS:[StrPtr]
  810.  
  811. Parse_2:        MOV    CX,AX
  812.                 POP    DI              ; restore table key
  813.                 RET
  814.  
  815. Parse ENDP
  816.  
  817. ; ----------------------------------------------------------
  818.  
  819. EmitParms PROC NEAR
  820.  
  821.                 PUSH   AX
  822.                 MOV    AL, "["
  823.                 CALL   PutChar
  824.                 MOV    DI, Word Ptr DS:[Key_Index]
  825.  
  826. EmitParms_1:    CMP    DI, Word Ptr DS:[ANSI_End]
  827.                 JA     EmitParms_2
  828.  
  829.                 MOV    AL,[DI]
  830.                 CALL   PutChar
  831.                 INC    DI
  832.                 JMP    Short EmitParms_1
  833.  
  834. EmitParms_2:    POP    AX
  835.  
  836. Put_And_Flush:  CALL   PutChar
  837.  
  838. Flush:          MOV    Word Ptr DS:[ESC_Flag],0001h
  839.                 MOV    SI, Word Ptr DS:[Key_Index]
  840.                 MOV    Word Ptr DS:[ANSI_End],SI
  841.                 MOV    Word Ptr DS:[StrPtr],SI
  842.                 RET
  843.  
  844. EmitParms ENDP
  845.  
  846. ; ----------------------------------------------------------
  847. ; Scroll
  848.  
  849. Scroll PROC NEAR
  850.  
  851.                 MOV    DH, Byte Ptr DS:[MaxRow]
  852.  
  853. Scroll_1:       MOV    DL, Byte Ptr DS:[MaxColumn]
  854.                 MOV    AL,01h          ; # lines
  855.                 MOV    BH, Byte Ptr DS:[TextAttr]
  856.                 XOR    CX,CX
  857.                 PUSH   BP
  858.                 INT    10h             ; Scroll
  859.                 POP    BP
  860.                 RET
  861.  
  862. Scroll ENDP
  863.  
  864. ; ----------------------------------------------------------
  865.  
  866. MoveCursor PROC NEAR
  867.  
  868.                  MOV   AH,03h
  869.                  MOV   BH, Byte Ptr DS:[ScreenPage]
  870.                  INT   10h             ; Get Cursor Position
  871.                                        ; CX = CurSize
  872.                                        ; DX = CursPos
  873.  
  874. MoveCursor_0:    CALL  Parse
  875.                  OR    CX,CX
  876.                  JNZ   MoveCursor_1    ; if (CX != 0)
  877.  
  878.                  MOV   CX,0001h        ; CurMovement
  879.  
  880. MoveCursor_1:    CALL  Word Ptr [DI+03h]
  881.                                        ; follow Procedure
  882.                                        ; DH = Row
  883.                                        ; DL = Column
  884.                  MOV   AH,02h
  885.                  MOV   BH, Byte Ptr DS:[ScreenPage]
  886.                  INT   10h             ; Set Cursor Position
  887.                  RET
  888.  
  889. MoveCursor ENDP
  890.  
  891. ; ----------------------------------------------------------
  892.  
  893. CurUp PROC NEAR
  894.  
  895.                 OR     DH,DH
  896.                 JZ     CurUp_1
  897.  
  898.                 DEC    DH
  899.                 LOOP   CurUp
  900.  
  901. CurUp_1:        RET
  902.  
  903. CurUp ENDP
  904.  
  905. ; ----------------------------------------------------------
  906.  
  907. CurDown PROC NEAR
  908.  
  909.                 CMP    DH, Byte Ptr DS:[MaxRow]
  910.                 JZ     CurDown_1
  911.  
  912.                 INC    DH
  913.                 LOOP   CurDown
  914.  
  915. CurDown_1:      RET
  916.  
  917. CurDown ENDP
  918.  
  919. ; ----------------------------------------------------------
  920.  
  921. CurRight PROC NEAR
  922.  
  923.                 CMP    DL, Byte Ptr DS:[MaxColumn]
  924.                 JNB    CurRight_1
  925.  
  926.                 INC    DL
  927.                 LOOP   CurRight
  928.  
  929. CurRight_1:     RET
  930.  
  931. CurRight ENDP
  932.  
  933. ; ----------------------------------------------------------
  934.  
  935. CurLeft PROC NEAR
  936.  
  937.                 OR     DL,DL
  938.                 JZ     CurLeft_1
  939.  
  940.                 DEC    DL
  941.                 LOOP   CurLeft
  942.  
  943. CurLeft_1:      RET
  944.  
  945. CurLeft ENDP
  946.  
  947. ; ----------------------------------------------------------
  948.  
  949. GoXY PROC NEAR
  950.  
  951.                 MOV    DH,CL
  952.                 CALL   Parse
  953.                 OR     CL,CL
  954.                 JNZ    GoXY_1
  955.  
  956.                 MOV    CL,01h
  957.  
  958. GoXY_1:         MOV    DL,CL
  959.                 SUB    DX,0101h
  960.                 RET
  961.  
  962. GoXY ENDP
  963.  
  964. ; ----------------------------------------------------------
  965.  
  966. StoreCurPos PROC NEAR
  967.  
  968.                 MOV    DX, Word Ptr DS:[CursorPos]
  969.                 RET
  970.  
  971. StoreCurPos ENDP
  972.  
  973. ; ----------------------------------------------------------
  974.  
  975. RestCurPos PROC NEAR
  976.  
  977.                 MOV    AH,03h
  978.                 MOV    BH, Byte Ptr DS:[ScreenPage]
  979.                 INT    10h             ; Get Cursor Position
  980.                 MOV    Word Ptr DS:[CursorPos],DX
  981.                 RET
  982.  
  983. RestCurPos ENDP
  984.  
  985. ; ----------------------------------------------------------
  986.  
  987. ClrScreen PROC NEAR
  988.  
  989.                 CALL   Parse
  990.  
  991.                 PUSH   CX
  992.                 MOV    AH,03h
  993.                 MOV    BH, Byte Ptr DS:[ScreenPage]
  994.                 INT    10h             ; Get Cursor Position
  995.                 MOV    AL, Byte Ptr DS:[MaxColumn]
  996.                 INC    AL
  997.                 MOV    CX,DX           ; CX := CursPos
  998.                 MUL    CH              ; AX := AL * CH
  999.                 XOR    CH,CH
  1000.                 ADD    AX,CX           ; AX := AX + Row
  1001.                 POP    CX
  1002.  
  1003.                 PUSH   DX              ; CursPos
  1004.                 OR     CX,CX
  1005.                 JNZ    ClrScreen_1     ; if ( CX != 0 )
  1006.  
  1007.                 PUSH   AX
  1008.                 XOR    AX,AX           ; AX = 0
  1009.                 MOV    AL, Byte Ptr DS:[MaxRow]
  1010.                 MOV    CL, Byte Ptr DS:[MaxColumn]
  1011.                 INC    CL
  1012.                 MUL    CL              ; AX := AL * CL
  1013.                 MOV    CX,AX
  1014.                 POP    AX
  1015.  
  1016.                 SUB    CX,AX
  1017.                 JMP    Short WriteBlank
  1018.  
  1019. ClrScreen_1:    CMP    CX,+01h
  1020.                 JNZ    ClrScreen_2     ; if ( CX != 1 )
  1021.  
  1022.                 MOV    CX,AX
  1023.                 XOR    DX,DX           ; CursPos = 0
  1024.                 MOV    AH,02h
  1025.                 MOV    BH, Byte Ptr DS:[ScreenPage]
  1026.                 INT    10h             ; Set Cursor Position
  1027.                 JMP    Short WriteBlank
  1028.  
  1029. ClrScreen_2:    POP    DX
  1030.                 XOR    DX,DX           ; DX = 0
  1031.                 PUSH   DX
  1032.                 MOV    DH,Byte Ptr DS:[MaxRow]
  1033.                 MOV    DL,Byte Ptr DS:[MaxColumn]
  1034.                 XOR    CX,CX           ; CX = 0
  1035.                 MOV    BH,Byte Ptr DS:[TextAttr]
  1036.                 MOV    AX,0600h
  1037.                 JMP    Short ClrScreen_3
  1038.  
  1039. WriteBlank:     MOV    AX,0A20h
  1040.                 MOV    BH,Byte Ptr DS:[ScreenPage]
  1041.  
  1042. ClrScreen_3:    INT    10h             ; Write Char
  1043.                 POP    DX
  1044.                 MOV    AH,02h
  1045.                 MOV    BH,Byte Ptr DS:[ScreenPage]
  1046.                 INT    10h             ; Set Cursor Position
  1047.                 RET
  1048.  
  1049. ClrScreen ENDP
  1050.  
  1051. ; ----------------------------------------------------------
  1052.  
  1053. ClrEoL PROC NEAR
  1054.  
  1055.                 CALL   Parse
  1056.                 PUSH   CX
  1057.                 MOV    AH,03h
  1058.                 MOV    BH,Byte Ptr DS:[ScreenPage]
  1059.                 INT    10h             ; Get Cursor Position
  1060.                 POP    CX
  1061.                 PUSH   DX
  1062.                 MOV    CX,DX
  1063.                 MOV    DL,Byte Ptr DS:[MaxColumn]
  1064.  
  1065.                 MOV    AX,0600h
  1066.                 MOV    BH,Byte Ptr DS:[TextAttr]
  1067.                 INT    10h             ; Scroll Up
  1068.                 POP    DX              ; Cursor Position
  1069.                 MOV    AH,02h
  1070.                 MOV    BH,Byte Ptr DS:[ScreenPage]
  1071.                 INT    10h             ; Set Cursor Position
  1072.                 RET
  1073.  
  1074. ClrEoL ENDP
  1075.  
  1076. ; ----------------------------------------------------------
  1077.  
  1078. ColorTable      DW     Offset SetAttr
  1079.                 DB     07h             ; Black/White
  1080.  
  1081.                 DW     Offset Or_Attr
  1082.                 DB     08h             ; DarkGrey
  1083.  
  1084.                 DW     0FFFFh
  1085.                 DB     0FFh            ; not implemented
  1086.  
  1087.                 DW     0FFFFh
  1088.                 DB     0FFh            ; not implemented
  1089.  
  1090.                 DW     Offset Or_Attr
  1091.                 DB     01h             ; Blue
  1092.  
  1093.                 DW     Offset Or_Attr
  1094.                 DB     80h             ; Blink
  1095.  
  1096.                 DW     0FFFFh
  1097.                 DB     0FFh            ; not implemented
  1098.  
  1099.                 DW     Offset SetAttr
  1100.                 DB     70h             ; LightGrey/Black
  1101.  
  1102.                 DW     Offset SetAttr
  1103.                 DB     00h             ; Black/Black
  1104.  
  1105.                 DW     0FFFFh
  1106.                 DB     0FFh            ; not implemented
  1107.  
  1108.                 DW     Offset Background
  1109.                 DB     00h             ; Black
  1110.  
  1111.                 DW     Offset Background
  1112.                 DB     04h             ; Red
  1113.  
  1114.                 DW     Offset Background
  1115.                 DB     02h             ; Green
  1116.  
  1117.                 DW     Offset Background
  1118.                 DB     0Eh             ; Yellow
  1119.  
  1120.                 DW     Offset Background
  1121.                 DB     01h             ; Blue
  1122.  
  1123.                 DW     Offset Background
  1124.                 DB     05h             ; Magenta
  1125.  
  1126.                 DW     Offset Background
  1127.                 DB     03h             ; Cyan
  1128.  
  1129.                 DW     Offset Background
  1130.                 DB     07h             ; LightGray
  1131.  
  1132.                 DW     0FFFFh
  1133.                 DB     0FFh            ; not implemented
  1134.  
  1135.                 DW     0FFFFh
  1136.                 DB     0FFh            ; not implemented
  1137.  
  1138.                 DW     Offset Foreground
  1139.                 DB     00h             ; Black
  1140.  
  1141.                 DW     Offset Foreground
  1142.                 DB     40h             ; Red
  1143.  
  1144.                 DW     Offset Foreground
  1145.                 DB     20h             ; Green
  1146.  
  1147.                 DW     Offset Foreground
  1148.                 DB     60h             ; Brown
  1149.  
  1150.                 DW     Offset Foreground
  1151.                 DB     10h             ; Blue
  1152.  
  1153.                 DW     Offset Foreground
  1154.                 DB     50h             ; Magenta
  1155.  
  1156.                 DW     Offset Foreground
  1157.                 DB     30h             ; Cyan
  1158.  
  1159.                 DW     Offset Foreground
  1160.                 DB     70h             ; LightGray
  1161.  
  1162. ; ----------------------------------------------------------
  1163.  
  1164. GraphParms PROC NEAR
  1165.  
  1166.                 CALL   Parse
  1167.                 CMP    Byte Ptr DS:[NumFlag],00h
  1168.                 JZ     GraphParms_1    ; Exit
  1169.  
  1170.                 CMP    CL, 2Fh         ; Color Table entries
  1171.                 JG     GraphParms
  1172.  
  1173.                 CMP    CL,00h
  1174.                 JB     GraphParms
  1175.  
  1176.                 CMP    CL,0Ah
  1177.                 JB     GraphParms_2
  1178.  
  1179.                 SUB    CL,14h
  1180.  
  1181. GraphParms_2:   MOV    AL,CL           ; AL = Attr_Function
  1182.                 XOR    AH,AH
  1183.                 MOV    BL,03h
  1184.                 MUL    BL              ; AX := AL * 3
  1185.                 LEA    DI, Word Ptr DS:[ColorTable]
  1186.                 ADD    DI,AX
  1187.  
  1188.                 CMP    Byte Ptr [DI],0FFh
  1189.                 JZ     GraphParms
  1190.  
  1191.                 MOV    BL, Byte Ptr DS:[TextAttr]
  1192.  
  1193.                 CALL   Word Ptr [DI]   ; Call Function
  1194.  
  1195.                 JMP    Short GraphParms
  1196.  
  1197. GraphParms_1:   RET
  1198.  
  1199. GraphParms ENDP
  1200.  
  1201. ; ----------------------------------------------------------
  1202.  
  1203. SetAttr PROC NEAR
  1204.  
  1205.                 MOV    BL,[DI+02h]
  1206.                 MOV    Byte Ptr DS:[TextAttr],BL
  1207.                 RET
  1208.  
  1209. SetAttr ENDP
  1210.  
  1211. ; ----------------------------------------------------------
  1212.  
  1213. Or_Attr PROC NEAR
  1214.  
  1215.                 OR     BL,[DI+02h]
  1216.                 MOV    Byte Ptr DS:[TextAttr],BL
  1217.                 RET
  1218.  
  1219. Or_Attr ENDP
  1220.  
  1221. ; ----------------------------------------------------------
  1222.  
  1223. Background  PROC NEAR
  1224.  
  1225.                 AND       BL,0F0h
  1226.                 OR        BL,[DI+02h]
  1227.                 MOV       Byte Ptr DS:[TextAttr],BL
  1228.                 RET
  1229.  
  1230. Background  ENDP
  1231.  
  1232. ; ----------------------------------------------------------
  1233.  
  1234. Foreground PROC NEAR
  1235.  
  1236.                 AND    BL,0Fh
  1237.                 OR     BL,[DI+02h]
  1238.                 MOV    Byte Ptr DS:[TextAttr],BL
  1239.                 RET
  1240.  
  1241. Foreground ENDP
  1242.  
  1243. ; ----------------------------------------------------------
  1244.  
  1245. ScreenParms PROC NEAR
  1246.  
  1247.                 XOR    DL,DL           ; DL := 0
  1248.                 JMP    Short ScreenParms_1
  1249.  
  1250.                 NOP
  1251.  
  1252. ScreenParms2:   MOV    DL,01h
  1253.  
  1254. ScreenParms_1:  CALL   Parse
  1255.                 CMP    CX,+07h
  1256.                 JG     ScreenParms_2
  1257.  
  1258.                 JB     ScreenParms_3
  1259.  
  1260.                 MOV    Byte Ptr DS:[Row],DL
  1261.                 RET
  1262.  
  1263. ScreenParms_3:  CMP    CX,+00h
  1264.                 JB     ScreenParms_2
  1265.  
  1266.                 XOR    AH,AH
  1267.                 MOV    AL,CL
  1268.                 INT    10h             ; Set_Vid_Mode
  1269.  
  1270. ScreenParms_2:  RET
  1271.  
  1272. ScreenParms ENDP
  1273.  
  1274. ; ----------------------------------------------------------
  1275.  
  1276. ANSI_Str_1      DB     1Bh, "[0n"
  1277.  
  1278. ANSI_Str_2      DB     1Bh, "[;R"
  1279.  
  1280. ANSI_Str_3      DB     1Bh, "[?1;0c"
  1281.  
  1282. ; ----------------------------------------------------------
  1283.  
  1284. WhereXY PROC NEAR
  1285.  
  1286.                 CALL   Parse
  1287.                 LEA    DI, Word Ptr DS:[ANSI_Seq_Buf]
  1288.                 LEA    SI, Word Ptr DS:[ANSI_Str_2]
  1289.                 MOV    Word Ptr DS:[Sav_Index],DI
  1290.                 CMP    CX,+05h
  1291.                 JNZ    WhereXY_1
  1292.  
  1293.                 LEA    SI, Word Ptr DS:[ANSI_Str_1]
  1294.                 MOV    CX,0004h
  1295.                 CALL   Copy
  1296.                 JMP    Short WhereXY_2
  1297.  
  1298. WhereXY_1:      MOV    CX,0002h
  1299.                 CALL   Copy
  1300.  
  1301.                 MOV    AH,03h
  1302.                 MOV    BH, Byte Ptr DS:[ScreenPage]
  1303.                 INT    10h             ; Get Cursor Position
  1304.                 ADD    DX,0101h
  1305.                 MOV    AL,DH           ; AL := Row
  1306.                 CALL   NormCurPos
  1307.  
  1308.                 MOV    CX,0001h
  1309.                 CALL   Copy
  1310.  
  1311.                 MOV    AL,DL           ; AL := Col
  1312.                 CALL   NormCurPos
  1313.  
  1314.                 MOV    CX,0001h
  1315.                 CALL   Copy
  1316.  
  1317. WhereXY_2:      DEC    DI
  1318.                 MOV    Word Ptr DS:[StrLen],DI
  1319.                 RET
  1320.  
  1321. WhereXY ENDP
  1322.  
  1323. ; ----------------------------------------------------------
  1324.  
  1325. Copy   PROC NEAR
  1326.  
  1327.                 MOVSB                  ; DS:SI -> ES:DI
  1328.                 LOOP   Copy            ; CX Bytes
  1329.  
  1330.                 RET
  1331.  
  1332. Copy   ENDP
  1333.  
  1334. ; ----------------------------------------------------------
  1335.  
  1336. NormCurPos PROC NEAR
  1337.  
  1338.                 XOR    AH,AH
  1339.                 MOV    CL,0Ah
  1340.                 DIV    CL              ; AX := AX / CL
  1341.                                        ; AL = DIV
  1342.                                        ; AH = MOD
  1343.                 OR     AX,3030h        ; + "0"
  1344.                 STOSB                  ; AL -> ES:DI
  1345.                 XCHG   AH, AL
  1346.                 STOSB                  ; AL -> ES:DI
  1347.                 RET
  1348.  
  1349. NormCurPos ENDP
  1350.  
  1351. ; ----------------------------------------------------------
  1352.  
  1353. Color PROC NEAR
  1354.  
  1355.                 LEA    SI, Word Ptr DS:[ANSI_Str_3]
  1356.                 LEA    DI, Word Ptr DS:[ANSI_Seq_Buf]
  1357.                 MOV    Word Ptr DS:[Sav_Index],DI
  1358.                 MOV    CX,0007h
  1359.                 CALL   Copy
  1360.                 JMP    Short WhereXY_2
  1361.  
  1362. Params:         PUSH   ES
  1363.                 PUSH   DS
  1364.                 POP    ES              ; ES := DS
  1365.                 MOV    DI, Word Ptr DS:[Key_Index]
  1366.                 SUB    DI,+02h
  1367.                 MOV    SI, Word Ptr DS:[Key_Index]
  1368.  
  1369.                        ; string in quotes -> ES:DI
  1370.  
  1371. Params_1:       CMP    SI, Word Ptr DS:[ANSI_End]
  1372.                 JG     Params_2
  1373.  
  1374.                 CMP    Byte Ptr [SI], quote
  1375.                 JZ     Params_3
  1376.  
  1377.                 MOV    Word Ptr DS:[StrPtr],SI
  1378.                 CALL   Parse
  1379.                 MOV    SI, Word Ptr DS:[StrPtr]
  1380.                 STOSB                  ; AL -> ES:DI
  1381.                 JMP    Short Params_1
  1382.  
  1383. Params_3:       INC    SI
  1384. Params_4:       MOVSB                  ; AL -> DS:SI
  1385.                 CMP    Byte Ptr [SI], quote
  1386.                 JNZ    Params_4
  1387.  
  1388.                 INC    SI
  1389.                 INC    SI
  1390.                 JMP    Short Params_1
  1391.  
  1392. Params_2:       MOV    Word Ptr [DI],0000h
  1393.                 ADD    DI,+04h
  1394.                 MOV    SI,DI
  1395.                 XCHG   DI, Word Ptr DS:[Key_Index]
  1396.                 SUB    SI,DI
  1397.                 SUB    DI,+04h
  1398.                 MOV    [DI],SI
  1399.                 POP    ES
  1400.                 RET
  1401.  
  1402. Color ENDP
  1403.  
  1404. ; ----------------------------------------------------------
  1405.  
  1406. NormColumns PROC NEAR
  1407.  
  1408.                 MOV    AL,BH
  1409.                 CBW                    ; AX := WORD(BH)
  1410.                 OR     AX,AX
  1411.                 JZ     NormColumns_1
  1412.  
  1413. NormColumns_1:  MOV    DI,AX           ; DI := WORD(BH)
  1414.                 MOV    BX,DX
  1415.                 MOV    AL,DH
  1416.                 MUL    Byte Ptr ES:[044Ah]
  1417.                                        ; 0040h:004Ah -> Cols
  1418.                 XOR    BH,BH
  1419.                 ADD    AX,BX
  1420.                 SHL    AX,1
  1421.                 ADD    DI,AX
  1422.                 RET
  1423.  
  1424. NormColumns ENDP
  1425.  
  1426. ; ----------------------------------------------------------
  1427.  
  1428. OutVideo PROC NEAR
  1429.  
  1430.                 MOV    DX, Word Ptr ES:[0463h]
  1431.                                        ; 0040h:0063h -> VideoBase
  1432.                 MOV    AL,AH
  1433.                 OUT    DX,AL           ; Port_OUT:VideoBase
  1434.                 MOV    AL,CH
  1435.                 INC    DX
  1436.                 OUT    DX,AL           ; Port_OUT:VideoBase+1
  1437.                 DEC    DX
  1438.                 INC    AH
  1439.                 MOV    AL,AH
  1440.                 OUT    DX,AL           ; Port_OUT:VideoBase
  1441.                 MOV    AL,CL
  1442.                 INC    DX
  1443.                 OUT    DX,AL           ; Port_OUT:VideoBase+1
  1444.                 RET
  1445.  
  1446. OutVideo ENDP
  1447.  
  1448. ; ----------------------------------------------------------
  1449.  
  1450. Beep PROC NEAR
  1451.  
  1452.                 PUSH   AX
  1453.                 PUSH   DX
  1454.                 PUSH   ES
  1455.                 MOV    AL,0B6h
  1456.                 MOV    DX,0043h
  1457.                 OUT    DX,AL           ; Port_OUT:Timer+4
  1458.                 DEC    DX
  1459.                 MOV    AX,0960h
  1460.                 JMP    Short Beep_1
  1461.  
  1462. Beep_1:         OUT    DX,AL           ; Port_OUT:Timer+3
  1463.                 XCHG   AH,AL
  1464.                 JMP    Short Beep_2
  1465.  
  1466. Beep_2:         OUT    DX,AL           ; Port_OUT:Timer+3
  1467.                 MOV    DX,0061h
  1468.                 JMP    Short Beep_3
  1469.  
  1470. Beep_3:         IN     AL,DX           ; Port_IN:Keyb+1
  1471.                 PUSH   AX
  1472.                 OR     AL,03h
  1473.                 JMP    Short Beep_4
  1474.  
  1475. Beep_4:         OUT    DX,AL           ; Port_OUT:Keyb+1
  1476.  
  1477.                 MOV    AX,0040h
  1478.                 MOV    ES,AX           ; ES := BIOS
  1479.                 MOV    BX, Word Ptr ES:[006Ch]
  1480.  
  1481.                        ; 0040h:006Ch -> Timer Count
  1482.  
  1483.                 MOV    CX,0FFFFh
  1484.                 MOV    AX,BX
  1485.                 ADD    AX,0001h
  1486.  
  1487. Beep_5:         MOV    AX, Word Ptr ES:[006Ch]
  1488.  
  1489.                        ; 0040h:006Ch -> Timer Count
  1490.  
  1491.                 SUB    AX,BX
  1492.                 CMP    AX,0001h
  1493.                 JG     Beep_6
  1494.  
  1495.                 LOOP   Beep_5
  1496.  
  1497. Beep_6:         POP    AX
  1498.                 AND    AL,0FCh
  1499.                 OUT    DX,AL           ; Port_OUT:Keyb+1
  1500.                 POP    ES
  1501.                 POP    DX
  1502.                 POP    AX
  1503.                 RET
  1504.  
  1505. Beep ENDP
  1506.  
  1507. ; ----------------------------------------------------------
  1508.  
  1509. Message   DB     0Dh, 0Ah, "   ╔════════════════════════════════════════╗"
  1510.           DB     0Dh, 0Ah, "   ║ DOS-toolbox: DAS PROGRAMMIERER-MAGAZIN ║▒"
  1511.           DB     0Dh, 0Ah, "   ╟────────────────────────────────────────╢▒"
  1512.           DB     0Dh, 0Ah, "   ║           ANSI Driver V 1.01           ║▒"
  1513.           DB     0Dh, 0Ah, "   ║                                        ║▒"
  1514.           DB     0Dh, 0Ah, "   ║  (c) 1991 DMV - Daten & Medien Verlag  ║▒"
  1515.           DB     0Dh, 0Ah, "   ║  ────────────────────────────────────  ║▒"
  1516.           DB     0Dh, 0Ah, "   ║          Redaktion DOS-toolbox         ║▒"
  1517.           DB     0Dh, 0Ah, "   ║              Postfach 250              ║▒"
  1518.           DB     0Dh, 0Ah, "   ║             3440  Eschwege             ║▒"
  1519.           DB     0Dh, 0Ah, "   ║            Tel.: 05651-809-0           ║▒"
  1520.           DB     0Dh, 0Ah, "   ║                                        ║▒"
  1521.           DB     0Dh, 0Ah, "   ╚════════════════════════════════════════╝▒"
  1522.           DB     0Dh, 0Ah, "    ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒"
  1523.           DB     0Dh, 0Ah
  1524.           DB     0Dh, 0Ah, 00h
  1525.  
  1526. ; ----------------------------------------------------------
  1527.  
  1528. PrintMsg PROC NEAR
  1529.  
  1530.                 MOV    AH, 0Eh         ; Write TTY
  1531.                 MOV    BH, Byte Ptr DS:[ScreenPage]
  1532.                 MOV    SI, Offset Message
  1533.                 MOV    CX, 0001h
  1534.  
  1535. PrintMsg_1:     MOV    AL, Byte Ptr CS:[SI]
  1536.                 CMP    AL, 00h
  1537.                 JZ     PrintMsg_Exit
  1538.  
  1539.                 INT    10h
  1540.                 INC    SI
  1541.                 JMP    PrintMsg_1
  1542.  
  1543. PrintMsg_Exit:  RET
  1544.  
  1545. PrintMsg ENDP
  1546.  
  1547. ; ----------------------------------------------------------
  1548.  
  1549. Init PROC NEAR
  1550.  
  1551.                 LDS    BX, DWord Ptr DS:[DevHdr]
  1552.                 MOV    Word Ptr [BX+0Eh], Offset Message
  1553.  
  1554.                        ; Länge des residenten Teils.
  1555.                        ; "Offset EndDrv" wäre an sich richtig,
  1556.                        ; aber der Initialisierungsteil wird
  1557.                        ; nie wieder gebraucht. So sparen wir
  1558.                        ; noch ein paar Bytes im Speicher.
  1559.  
  1560.                 MOV    [BX+10h],CS
  1561.                 XOR    BX,BX
  1562.                 MOV    DS,BX           ; DS := 0
  1563.                 MOV    BX,00A4h        ; Int 29
  1564.                 MOV    Word Ptr [BX], Offset QuickScreen
  1565.                 MOV    [BX+02h],CS
  1566.  
  1567.                 CALL   PrintMsg
  1568.  
  1569.                 JMP    Exit_01
  1570.  
  1571. Init ENDP
  1572.  
  1573. ; ----------------------------------------------------------
  1574.  
  1575. EndDrv:                ; Mark the next free byte
  1576.  
  1577. CODE  ENDS
  1578.       END
  1579.  
  1580. ;* ------------------------------------------------------- *
  1581. ;*                  Ende von TXANSI.ASM                    *
  1582.