home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TTT405.ZIP / FASTTTT.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-11-26  |  11.0 KB  |  277 lines

  1.  
  2. ;       TechnoJocks Turbo Toolkit v4.0
  3. ;       Display Routines : included in UNIT FastTTT
  4. ;       Copyright (c) R. D. Ainsbury 1986, 1987
  5. ;
  6. ;       Credits : Marshall Brain (the Fastwrite inventor)
  7. ;                 Brian Foley    (the Fastwrite optimizer)
  8.  
  9. ;****************************************************** Equates
  10.  
  11.         Mono    = 0
  12.         CGA     = 1
  13.         EGA     = 2
  14.         MCGA    = 3
  15.         VGA     = 4
  16.  
  17. ;****************************************************** Data
  18.  
  19. DATA    SEGMENT BYTE PUBLIC
  20.  
  21.         EXTRN   BaseOfScreen : WORD     ;Pascal variables
  22.         EXTRN   WaitForRetrace : BYTE
  23.  
  24.         CurrentMode     DB      ?       ;local variables
  25.         Display         DB      ?
  26.  
  27. DATA    ENDS
  28.  
  29. ;****************************************************** Code
  30.  
  31. CODE    SEGMENT BYTE PUBLIC
  32.  
  33.         ASSUME  CS:CODE,DS:DATA
  34.  
  35.         PUBLIC  FastWrite, PlainWrite
  36.         PUBLIC  CurrentDisplay, CurrentVideoMode
  37. ;****************************************************** CalcOffset
  38.  
  39. ;Calculates offset in video memory corresponding to Row,Column
  40. ;On entry, CH has Row, BX has Column (both 1-based)
  41. ;On exit, ES:DI points to proper address in video memory, AX = 0
  42.  
  43. CalcOffset      PROC NEAR
  44.  
  45.         XOR     AX,AX                   ;AX = 0
  46.         MOV     CL,AL                   ;CL = 0
  47.         MOV     BH,AL                   ;BH = 0
  48.         DEC     CH                      ;Row (in CH) to 0..24 range
  49.         SHR     CX,1                    ;CX = Row * 128
  50.         MOV     DI,CX                   ;Store in DI
  51.         SHR     DI,1                    ;DI = Row * 64
  52.         SHR     DI,1                    ;DI = Row * 32
  53.         ADD     DI,CX                   ;DI = (Row * 160)
  54.         DEC     BX                      ;Col (in BX) to 0..79 range
  55.         SHL     BX,1                    ;Account for attribute bytes
  56.         ADD     DI,BX                   ;DI = (Row * 160) + (Col * 2)
  57.         MOV     ES,BaseOfScreen         ;ES:DI points to BaseOfScreen:Row,Col
  58.         RET                             ;Return
  59.  
  60. CalcOffset      ENDP
  61.  
  62. ;****************************************************** FastWrite
  63.  
  64. ;procedure FastWrite(Col, Row, Attr:byte; St : String);
  65. ;Fast write string St to screen in color Attr at coords Col, Row
  66.  
  67. ;equates for parameters:
  68. FWSt            EQU     DWORD PTR [BP+6]
  69. FWAttr          EQU     BYTE PTR [BP+10]
  70. FWRow           EQU     BYTE PTR [BP+12]
  71. FWCol           EQU     BYTE PTR [BP+14]
  72.  
  73. FastWrite       PROC FAR
  74.  
  75.         PUSH    BP                      ;Save BP
  76.         MOV     BP,SP                   ;Set up stack frame
  77.         PUSH    DS                      ;Save DS
  78.         MOV     CH,FWRow                ;CH = Row
  79.         MOV     BL,FWCol                ;BL = Column
  80.         CALL    CalcOffset              ;Call routine to calculate offset
  81.         MOV     CL,WaitForRetrace       ;Grab this before changing DS
  82.         LDS     SI,FWSt                 ;DS:SI points to St[0]
  83.         CLD                             ;Set direction to forward
  84.         LODSB                           ;AX = Length(St); DS:SI -> St[1]
  85.         XCHG    AX,CX                   ;CX = Length; AL = WaitForRetrace
  86.         JCXZ    FWExit                  ;If string empty, exit
  87.         MOV     AH,FWAttr               ;AH = Attribute
  88.         RCR     AL,1                    ;If WaitForRetrace is False...
  89.         JNC     FWMono                  ; use "FWMono" routine
  90.         MOV     DX,03DAh                ;Point DX to CGA status port
  91. FWGetNext:
  92.         LODSB                           ;Load next character into AL
  93.                                         ; AH already has Attr
  94.         MOV     BX,AX                   ;Store video word in BX
  95.         CLI                             ;No interrupts now
  96. FWWaitNoH:
  97.         IN      AL,DX                   ;Get 6845 status
  98.         TEST    AL,8                    ;Vertical retrace in progress?
  99.         JNZ     FWStore                 ;If so, go
  100.         RCR     AL,1                    ;Else, wait for end of
  101.         JC      FWWaitNoH               ; horizontal retrace
  102. FWWaitH:
  103.         IN      AL,DX                   ;Get 6845 status again
  104.         RCR     AL,1                    ;Wait for horizontal
  105.         JNC     FWWaitH                 ; retrace
  106. FWStore:
  107.         MOV     AX,BX                   ;Move word back to AX...
  108.         STOSW                           ; and then to screen
  109.         STI                             ;Allow interrupts!
  110.         LOOP    FWGetNext               ;Get next character
  111.         JMP     FWExit                  ;Done
  112. FWMono:
  113.         LODSB                           ;Load next character into AL
  114.                                         ; AH already has Attr
  115.         STOSW                           ;Move video word into place
  116.         LOOP    FWMono                  ;Get next character
  117. FWExit:
  118.         POP     DS                      ;Restore DS
  119.         MOV     SP,BP                   ;Restore SP
  120.         POP     BP                      ;Restore BP
  121.         RET     10                      ;Remove parameters and return
  122.  
  123. FastWrite       ENDP
  124.  
  125. ;****************************************************** PlainWrite
  126.  
  127. ;procedure PlainWrite(Col, Row:byte; St : String);
  128. ;Megafast write string St to the screen at coords Col,Row
  129.  
  130. ;equates for parameters:
  131. PWSt            EQU     DWORD PTR [BP+6]
  132. PWRow           EQU     BYTE PTR [BP+10]
  133. PWCol           EQU     BYTE PTR [BP+12]
  134.  
  135. PlainWrite      PROC FAR
  136.  
  137.         PUSH    BP                      ;Save BP
  138.         MOV     BP,SP                   ;Set up stack frame
  139.         PUSH    DS                      ;Save DS
  140.         MOV     CH,PWRow                ;CH = Row
  141.         MOV     BL,PWCol                ;BL = Column
  142.         CALL    CalcOffset              ;Call routine to calculate offset
  143.         MOV     CL,WaitForRetrace       ;Grab this before changing DS
  144.         LDS     SI,PWSt                 ;DS:SI points to St[0]
  145.         CLD                             ;Set direction to forward
  146.         LODSB                           ;AX = Length(St); DS:SI -> St[1]
  147.         XCHG    AX,CX                   ;CX = Length; AL = Wait
  148.         JCXZ    PWExit                  ;If string empty, exit
  149.         RCR     AL,1                    ;If WaitForRetrace is False...
  150.         JNC     PWNoWait                ; use PWNoWait routine
  151.         MOV     DX,03DAh                ;Point DX to CGA status port
  152. PWGetNext:
  153.         LODSB                           ;Load next character into AL
  154.         MOV     AH,AL                   ;Store char in AH
  155.         CLI                             ;No interrupts now
  156. PWWaitNoH:
  157.         IN      AL,DX                   ;Get 6845 status
  158.         TEST    AL,8                    ;Check for vertical retrace
  159.         JNZ     PWStore                 ; In progress? go
  160.         RCR     AL,1                    ;Else, wait for end of
  161.         JC      PWWaitNoH               ; horizontal retrace
  162. PWWaitH:
  163.         IN      AL,DX                   ;Get 6845 status again
  164.         RCR     AL,1                    ;Wait for horizontal
  165.         JNC     PWWaitH                 ; retrace
  166. PWStore:
  167.         MOV     AL,AH                   ;Move char back to AL...
  168.         STOSB                           ; and then to screen
  169.         STI                             ;Allow interrupts
  170.         INC     DI                      ;Skip attribute bytes
  171.         LOOP    PWGetNext               ;Get next character
  172.         JMP     PWExit                  ;Done
  173. PWNoWait:
  174.         MOVSB                           ;Move character to screen
  175.         INC     DI                      ;Skip attribute bytes
  176.         LOOP    PWNoWait                ;Get next character
  177. PWExit:
  178.         POP     DS                      ;Restore DS
  179.         MOV     SP,BP                   ;Restore SP
  180.         POP     BP                      ;Restore BP
  181.         RET     8                       ;Remove parameters and return
  182.  
  183. PlainWrite      ENDP
  184.  
  185. ;****************************************************** CurrentModePrim
  186.  
  187. ;Returns current video mode in AL
  188.  
  189. CurrentModePrim PROC NEAR
  190.  
  191.         MOV     AH,0Fh                  ;Get video mode function
  192.         INT     10h                     ;Call BIOS
  193.         MOV     CurrentMode,AL          ;Save it
  194.         RET                             ;Return
  195.  
  196. CurrentModePrim ENDP
  197.  
  198. ;****************************************************** CurrentDisplay
  199.  
  200. ;function CurrentDisplay : DisplayType;
  201. ;Returns type of the currently active display.
  202.  
  203. JunkValue       = 0FFFFh
  204.  
  205. CurrentDisplay  PROC FAR
  206.  
  207.         ;get the current video mode
  208.         CALL     CurrentModePrim        ;Call primitive routine
  209.  
  210.         ;test for VGA
  211.         MOV     Display,VGA             ;Assume VGA
  212.         MOV     CX,JunkValue            ;Load CX with junk value
  213.         MOV     AX,1C00h                ;Save/Restore video state
  214.         INT     10h
  215.         CMP     AL,1Ch                  ;AL = $1C signals valid call
  216.         JE      CDexit                  ;Adapter type known
  217.  
  218.         ;test for MCGA
  219.         MOV     Display,MCGA            ;Assume MCGA
  220.         MOV     BL,32h                  ;Choose Enable
  221.         MOV     AX,1200h                ;Enable/Disable video addressing
  222.         INT     10h
  223.         CMP     AL,12h                  ;AL = $12 signals valid call
  224.         JE      CDexit                  ;Adapter type known
  225.  
  226.         ;test for EGA
  227.         MOV     Display,EGA             ;Assume EGA
  228.         MOV     BX,0FF10h               ;Return EGA information
  229.         MOV     CX,JunkValue            ;Load CX with junk value
  230.         MOV     AX,1200h                ;Alternate function select
  231.         INT     10h
  232.         XOR     AL,AL                   ;AL = 0
  233.         CMP     CX,JunkValue            ;CX unchanged?
  234.         JE      CDplain                 ;If so, not an EGA
  235.         CMP     BH,1                    ;BH should be 0 or 1
  236.         JA      CDplain                 ;Mono or CGA if it isn't
  237.  
  238.         ;See if EGA is the active display
  239.         CMP     BH,1                    ;mono display?
  240.         JE      CDegaMono               ;If so, use mono check
  241.         CMP     CurrentMode,7           ;In mono mode?
  242.         JE      CDplain                 ;If so, we're not on the EGA
  243.         JMP     SHORT CDexit            ;else, it's an EGA
  244.  
  245. CDegaMono:
  246.         CMP     CurrentMode,7           ;Current mode = 7?
  247.         JNE     CDplain                 ;Exit if not
  248.  
  249. CDexit:
  250.         MOV     AL,Display              ;set return value
  251.         RET                             ;Return
  252.  
  253. CDplain:
  254.         MOV     Display,CGA             ;Assume CGA
  255.         CMP     CurrentMode,7           ;Mono mode
  256.         JNE     CDexit                  ;Done if not
  257.         MOV     Display,Mono            ;Else, Mono
  258.         JMP     SHORT CDexit            ;Done
  259.  
  260. CurrentDisplay  ENDP
  261.  
  262. ;****************************************************** CurrentVideoMode
  263.  
  264. ;function CurrentVideoMode : Byte;
  265. ;Returns current video mode in AL
  266.  
  267. CurrentVideoMode        PROC FAR
  268.  
  269.         CALL     CurrentModePrim        ;Call primitive routine
  270.         RET                             ;Return
  271.  
  272. CurrentVideoMode        ENDP
  273.  
  274. CODE    ENDS
  275.  
  276.         END
  277.