home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / ttt2.zip / FASTTTT5.ASM < prev    next >
Assembly Source File  |  1989-01-31  |  14KB  |  306 lines

  1. ;{--------------------------------------------------------------------------}
  2. ;{                         TechnoJock's Turbo Toolkit                       }
  3. ;{                                                                          }
  4. ;{                              Version   5.00                              }
  5. ;{                                                                          }
  6. ;{                                                                          }
  7. ;{              Copyright 1986, 1989 TechnoJock Software, Inc.              }
  8. ;{                           All Rights Reserved                            }
  9. ;{                          Restricted by License                           }
  10. ;{--------------------------------------------------------------------------}
  11. ;                     {--------------------------------}                                       
  12. ;                     {       OBJ:   FastTTT5          }
  13. ;                     {--------------------------------}
  14. ;
  15. ;
  16.  
  17. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  18. ;+                                                                +
  19. ;+          This asm file contains 3 pascal procedures for        +
  20. ;+          linking with TTT version 5.0. The procedures are:     +
  21. ;+                                                                +
  22. ;+                  Fastwrite(X,Y,A,String)                       +
  23. ;+                  PlainWrite(X,Y,String)                        +
  24. ;+                  Attribute(X,Y,X,HowMany)                      +
  25. ;+                                                                + 
  26. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  27.  
  28.  
  29.  
  30. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  31. ;+                                                                +
  32. ;+    The main pascal unit includes three global variables. The   +
  33. ;+    VSeg and Vofs indicate the active screen buffer - this may  +
  34. ;+    or may not be the visible screen buffer so "snow" checking  +
  35. ;+    is always performed.                                        +
  36. ;+                                                                +
  37. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  38.  
  39. DATA    SEGMENT BYTE PUBLIC
  40.  
  41.         EXTRN   VSeg : WORD     
  42.      EXTRN   Vofs : WORD
  43.         EXTRN   SnowProne : BYTE
  44.  
  45. DATA    ENDS
  46.  
  47.  
  48. CODE    SEGMENT BYTE PUBLIC
  49.  
  50.         ASSUME  CS:CODE,DS:DATA
  51.  
  52.         PUBLIC  FastWrite, PlainWrite, Attribute
  53.  
  54. ;++++++++++++++++++++++++++++++++++++
  55. ;+     C A L M E M P O I N T E R    +
  56. ;++++++++++++++++++++++++++++++++++++
  57.  
  58. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  59. ;+                                                                +
  60. ;+    CALCMEMPOINTER is a local procedure that is called by       +
  61. ;+    Fastwrite, PlainWrite and Attribute. It places the segment  +
  62. ;+    and offset of the first attribute, in ES:DI ready for an    +
  63. ;+    LDS. Vseg and Vofs point to the first attribute of the      +
  64. ;+    screen, the final location is computed by adding Row*160    +
  65. ;+    (80 attribs and 80 chars per row) and then adding 2*Col.    +
  66. ;+    The passed Row and Column are decremented by one to fit     +
  67. ;+    with DOS's 0..79, 0..24 coordinate system.                  + 
  68. ;+                                                                +
  69. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  70.  
  71.  
  72. Calcmempointer      PROC NEAR
  73.  
  74.         XOR     AX,AX                   ;AX = 0
  75.         MOV     CL,AL                   ;CL = 0
  76.         MOV     BH,AL                   ;BH = 0
  77.         DEC     CH                      ;convert to DOS 0..24 coords
  78.         SHR     CX,1                    ;CX = Row * 128
  79.         MOV     DI,CX                   ;Store in DI
  80.         SHR     DI,1                    ;DI = Row * 64
  81.         SHR     DI,1                    ;DI = Row * 32
  82.         ADD     DI,CX                   ;DI = (Row * 160)
  83.         DEC     BX                      ;convert to DOS 0..79 coords
  84.         SHL     BX,1                    ;Account for attribute bytes
  85.         ADD     DI,BX                   ;DI = (Row * 160) + (Col * 2)
  86.     ADD     DI,Vofs                 ;Add base address
  87.         MOV     ES,Vseg                 ;ES:DI points to first Row,Col attribute
  88.         RET                             ;Return
  89.  
  90. Calcmempointer      ENDP
  91.  
  92.  
  93. ;++++++++++++++++++++++++++++
  94. ;+     F A S T W R I T E    +
  95. ;++++++++++++++++++++++++++++
  96.  
  97. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  98. ;+                                                                  +
  99. ;+   Why fastwrite. Normal BIOS services are too slow writing       +
  100. ;+   to the screen. Even Turbo  write procs are not as fast as      +
  101. ;+   we need - especially on snow-prone systems.                    +
  102. ;+                                                                  +
  103. ;+   Basic Process:    Save stack state                             +
  104. ;+                     Repeat                                       +         
  105. ;+                        Set ES:DI with target memory address      +
  106. ;+                        Load source with LODSB                    +
  107. ;+                        Check for vertical retrace if necessary   +    
  108. ;+                           and store the character in target      +
  109. ;+                           with STOSW                             +
  110. ;+                     Until no more chracters                      +
  111. ;+                                                                  +
  112. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  113.  
  114. ;  Turbo passed parameters
  115.  
  116. FWSt            EQU     DWORD PTR [BP+6]
  117. FWAttr          EQU     BYTE PTR [BP+10]
  118. FWRow           EQU     BYTE PTR [BP+12]
  119. FWCol           EQU     BYTE PTR [BP+14]
  120.  
  121. FastWrite       PROC FAR
  122.  
  123.         PUSH    BP                      ;Save BP
  124.         MOV     BP,SP                   ;Set up stack frame
  125.         PUSH    DS                      ;Save DS
  126.         MOV     CH,FWRow                ;CH = Row
  127.         MOV     BL,FWCol                ;BL = Column
  128.         CALL    Calcmempointer          ;Set up ES:DI for LDS
  129.         MOV     CL,SnowProne            ;Need to wait?
  130.         LDS     SI,FWSt                 ;DS:SI points to St[0]
  131.         CLD                             ;Set direction to forward
  132.         LODSB                           ;AX = Length(St); DS:SI -> St[1]
  133.         XCHG    AX,CX                   ;CX = Length; AL = WaitForRetrace
  134.         JCXZ    FWExit                  ;exit if string empty
  135.         MOV     AH,FWAttr               ;AH = display attribute
  136.         RCR     AL,1                    ;If WaitForRetrace is False...
  137.         JNC     FWMono                  ; use "FWMono" routine
  138.         MOV     DX,03DAh                ;Point DX to CGA status port
  139. FWGetNext:
  140.         LODSB                           ;Load next character into AL
  141.         MOV     BX,AX                   ;Store video word in BX
  142.         CLI                             ;hold interrupts
  143. FWWaitNoH:
  144.         IN      AL,DX                   ;get retrace situation
  145.         TEST    AL,8                    ;retracing?
  146.         JNZ     FWStore                 ;If so, go
  147.         RCR     AL,1                    ;Else, wait for end of
  148.         JC      FWWaitNoH               ; horizontal retrace
  149. FWWaitH:
  150.         IN      AL,DX                   ;get retrace situation
  151.         RCR     AL,1                    ;Wait for horizontal
  152.         JNC     FWWaitH                 ; retrace
  153. FWStore:
  154.         MOV     AX,BX                   ;Move word back to AX...
  155.         STOSW                           ; and then to screen
  156.         STI                             ;OK to interrupt now
  157.         LOOP    FWGetNext               ;Get next character
  158.         JMP     FWExit                  ;wind up
  159. FWMono:
  160.         LODSB                           ;Load next character into AL
  161.         STOSW                           ;Move video word into place
  162.         LOOP    FWMono                  ;Get next character
  163. FWExit:
  164.         POP     DS                      ;clean up and go home
  165.         MOV     SP,BP                   ;
  166.         POP     BP                      ;
  167.         RET     10                      ;
  168.  
  169. FastWrite       ENDP
  170.  
  171.  
  172. ;+++++++++++++++++++++++++++++++
  173. ;+     P L A I N W R I T E     +
  174. ;+++++++++++++++++++++++++++++++
  175.  
  176. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  177. ;+                                                                  +
  178. ;+   Uses same concept as Fastwrite but doesn't affect current      +
  179. ;+   display attribute.                                             +
  180. ;+                                                                  +
  181. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  182.  
  183. ;  Turbo passed parameters
  184.  
  185. PWSt            EQU     DWORD PTR [BP+6]
  186. PWRow           EQU     BYTE PTR [BP+10]
  187. PWCol           EQU     BYTE PTR [BP+12]
  188.  
  189. PlainWrite      PROC FAR
  190.  
  191.         PUSH    BP                      ;Save BP
  192.         MOV     BP,SP                   ;Set up stack frame
  193.         PUSH    DS                      ;Save DS
  194.         MOV     CH,PWRow                ;CH = Row
  195.         MOV     BL,PWCol                ;BL = Column
  196.         CALL    Calcmempointer          ;Set up ES:DI for LDS
  197.         MOV     CL,Snowprone            ;Need to wait?               
  198.         LDS     SI,PWSt                 ;DS:SI points to St[0]
  199.         CLD                             ;Set direction to forward
  200.         LODSB                           ;AX = Length(St); DS:SI -> St[1]
  201.         XCHG    AX,CX                   ;CX = Length; AL = Wait
  202.         JCXZ    PWExit                  ;exit if string empty
  203.         RCR     AL,1                    ;If WaitForRetrace is False...
  204.         JNC     PWNoWait                ; use PWNoWait routine
  205.         MOV     DX,03DAh                ;Point DX to CGA status port
  206. PWGetNext:
  207.         LODSB                           ;Load next character into AL
  208.         MOV     AH,AL                   ;Store char in AH
  209.         CLI                             ;hold interrupts
  210. PWWaitNoH:
  211.         IN      AL,DX                   ; get retrace situation
  212.         TEST    AL,8                    ;Check for vertical retrace
  213.         JNZ     PWStore                 ; In progress? go
  214.         RCR     AL,1                    ;Else, wait for end of
  215.         JC      PWWaitNoH               ; horizontal retrace
  216. PWWaitH:
  217.         IN      AL,DX                   ;Get 6845 status again
  218.         RCR     AL,1                    ;Wait for horizontal
  219.         JNC     PWWaitH                 ; retrace
  220. PWStore:
  221.         MOV     AL,AH                   ;Move char back to AL...
  222.         STOSB                           ; and then to screen
  223.         STI                             ;OK to interrupt now
  224.         INC     DI                      ;Skip attribute bytes
  225.         LOOP    PWGetNext               ;Get next character
  226.         JMP     PWExit                  ;Done
  227. PWNoWait:
  228.         MOVSB                           ;Move character to screen
  229.         INC     DI                      ;Skip attribute bytes
  230.         LOOP    PWNoWait                ;Get next character
  231. PWExit:
  232.         POP     DS                      ;Clean up and go home
  233.         MOV     SP,BP                   ;
  234.         POP     BP                      ;
  235.         RET     8                       ;
  236.  
  237. PlainWrite      ENDP
  238.  
  239. ;+++++++++++++++++++++++++++++++
  240. ;+     A T T R I B U T E       +
  241. ;+++++++++++++++++++++++++++++++
  242.  
  243. ;++++++++++++++++++++++++++++++++++++++
  244. ;+                                    +
  245. ;+   Changes the display attribute    +
  246. ;+                                    +
  247. ;++++++++++++++++++++++++++++++++++++++
  248.  
  249. ;  Turbo passed parameters
  250.  
  251. ANumber        EQU     WORD PTR [BP+6]
  252. AAttr          EQU     BYTE PTR [BP+8]
  253. ARow           EQU     BYTE PTR [BP+10]
  254. ACol           EQU     BYTE PTR [BP+12]
  255.  
  256. Attribute PROC FAR
  257.  
  258.         PUSH    BP                      ;Save BP
  259.         MOV     BP,SP                   ;Set up stack frame
  260.         MOV     CH,ARow                 ;CH = Row
  261.         MOV     BL,ACol                 ;BL = Column
  262.         CALL    Calcmempointer          ;Call routine to calculate offset
  263.         INC     DI                      ;Skip character
  264.         CLD                             ;Set direction to forward
  265.         MOV     CX,ANumber              ;CX = Number to change
  266.         JCXZ    AExit                   ;If zero, exit
  267.         MOV     AL,AAttr                ;AL = Attribute
  268.         CMP     SnowProne,1             ;Get wait state
  269.         JNE     ANoWait                 ;If WaitForRetrace is False
  270.                                         ; use ANoWait routine
  271.         MOV     AH,AL                   ;Store attribute in AH
  272.         MOV     DX,03DAh                ;Point DX to CGA status port
  273. AGetNext:
  274.         CLI                             ;No interrupts now
  275. AWaitNoH:
  276.         IN      AL,DX                   ;get retrace situation
  277.         TEST    AL,8                    ;check for vertical retrace
  278.         JNZ     AGo                     ;In progress? Go
  279.         RCR     AL,1                    ;Wait for end of horizontal
  280.         JC      AWaitNoH                ; retrace
  281. AWaitH:
  282.         IN      AL,DX                   ; get retrace situation
  283.         RCR     AL,1                    ;Wait for horizontal
  284.         JNC     AWaitH                  ; retrace
  285. AGo:
  286.         MOV     AL,AH                   ;Move Attr back to AL...
  287.         STOSB                           ; and then to screen
  288.         STI                             ;Allow interrupts
  289.         INC     DI                      ;Skip characters
  290.         LOOP    AGetNext                ;Look for next opportunity
  291.         JMP     AExit                   ;Done
  292. ANoWait:
  293.         STOSB                           ;Change the attribute
  294.         INC     DI                      ;Skip characters
  295.         LOOP    ANoWait                 ;Get next character
  296. AExit:                                  ;
  297.         MOV     SP,BP                   ;Clean up and go home
  298.         POP     BP                      ;
  299.         RET     8                       ;
  300.  
  301. Attribute ENDP
  302.  
  303. CODE    ENDS
  304.  
  305.         END
  306.