home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / tttsrc51.zip / FASTTTT5.ASM < prev    next >
Assembly Source File  |  1993-03-08  |  11KB  |  249 lines

  1. ;                  Copyright 1991 TechnoJock Software, Inc. 
  2. ;                             All Rights Reserved           
  3. ;                            Restricted by License          
  4.  
  5. ;                                 FastTTT5.ASM 
  6.  
  7. ;                                  Version 5.1
  8.  
  9. %Title "TTT Toolkit screen writing and memory moving routines"
  10.  
  11. ;       IDEAL
  12.  
  13. SEGMENT DATA byte public
  14.  
  15.         EXTRN   SnowProne : BYTE
  16.  
  17. ENDS DATA
  18.  
  19.  
  20. SEGMENT CODE byte public
  21.  
  22.         ASSUME  CS:CODE, DS:DATA
  23.  
  24.         PUBLIC  AsmWrite, AsmPWrite, AsmAttr
  25.  
  26. ;  |||||||||||||||||||||||||||||||
  27. ;  |     A d j u s t E S D I     |
  28. ;  |||||||||||||||||||||||||||||||
  29.  
  30. ;   Local routine that computes the offset from the top left of
  31. ;   the screen. You must set ES:DI to point to start of screen 
  32. ;   before calling.
  33.  
  34. AdjustESDI      PROC NEAR
  35.  
  36.         XOR     DX,DX                   ;set DX to 0
  37.         MOV     CL,DL                   ;CL = 0
  38.         MOV     BH,DL                   ;BH = 0
  39.         MOV     AH,DL                   ;AH = 0
  40.         DEC     CH                      ;set CH to number of full rows
  41.         MUL     CH                      ;AX <- CH * AL  i.e. rows * width
  42.         SHL     AX,1                    ;*2 for char and attr
  43.         ADD     DI,AX                   ;add rows*width*2 to DI 
  44.         DEC     BX                      ;decrease cols by 1
  45.         SHL     BX,1                    ;multiply cols by 2
  46.         ADD     DI,BX                   ;add cols to DI
  47.         XOR     AX,AX                   ;set AX to zero
  48.         RET                             ;Return
  49.  
  50. AdjustESDI      ENDP
  51.  
  52. ;||||||||||||||||||||||||||||
  53. ;|     A S M w r i t e      |
  54. ;||||||||||||||||||||||||||||
  55.  
  56. ;  Turbo passed parameters
  57.  
  58. AWSt            EQU     DWORD PTR [BP+6]
  59. AWAttr          EQU     BYTE PTR [BP+10]
  60. AWRow           EQU     BYTE PTR [BP+12]
  61. AWCol           EQU     BYTE PTR [BP+14]
  62. AWWidth         EQU     BYTE PTR [BP+16]
  63. AWScreenStart   EQU     DWORD PTR [BP+18]
  64.  
  65. AsmWrite       PROC FAR
  66.  
  67.         PUSH    BP                      ;Save BP
  68.         MOV     BP,SP                   ;Set up stack frame
  69.         PUSH    DS                      ;Save DS
  70.         MOV     CH,AWRow                ;CH = Row
  71.         MOV     BL,AWCol                ;BL = Column
  72.         MOV     AL,AWWidth              ;AL = screen width
  73.         LES     DI,AWScreenStart        ;Set up ES:DI to start of screen
  74.         CALL    AdjustESDI              ;move ES:DI to X,Y coord for write
  75.         MOV     CL,SnowProne            ;Need to wait?
  76.         LDS     SI,AWSt                 ;DS:SI points to St[0]
  77.         CLD                             ;Set SI inc. direction to forward
  78.         LODSB                           ;AX = Length(St); DS:SI -> St[1]
  79.         XCHG    AX,CX                   ;CX = Length; AL = WaitForRetrace
  80.         JCXZ    AWExit                  ;exit if CX = 0, i.e. string empty
  81.         MOV     AH,AWAttr               ;AH = display attribute
  82.         RCR     AL,1                    ;If WaitForRetrace is False...
  83.         JNC     AWMono                  ; use "AWMono" routine
  84.         MOV     DX,03DAh                ;Point DX to CGA status port
  85. AWGetNext:
  86.         LODSB                           ;Load next character into AL
  87.         MOV     BX,AX                   ;Store video word in BX
  88.         CLI                             ;hold interrupts
  89. AWWaitNoH:
  90.         IN      AL,DX                   ;get retrace situation
  91.         TEST    AL,8                    ;retracing?
  92.         JNZ     AWStore                 ;If so, go
  93.         RCR     AL,1                    ;Else, wait for end of
  94.         JC      AWWaitNoH               ; horizontal retrace
  95. AWWaitH:
  96.         IN      AL,DX                   ;get retrace situation
  97.         RCR     AL,1                    ;Wait for horizontal
  98.         JNC     AWWaitH                 ; retrace
  99. AWStore:
  100.         MOV     AX,BX                   ;Move word back to AX...
  101.         STOSW                           ; and then to screen
  102.         STI                             ;OK to interrupt now
  103.         LOOP    AWGetNext               ;Get next character
  104.         JMP     AWExit                  ;wind up
  105. AWMono:
  106.         LODSB                           ;Load next character into AL
  107.         STOSW                           ;Move video word into place
  108.         LOOP    AWMono                  ;Get next character
  109. AWExit:
  110.         POP     DS                      ;clean up and go home
  111.         MOV     SP,BP                   ;
  112.         POP     BP                      ;
  113.         RET     16                      ;16 bytes for passed paremeters 
  114.                                         ;(minimum is 2 bytes per param)
  115.  
  116. AsmWrite       ENDP
  117.  
  118. ;||||||||||||||||||||||||||||||
  119. ;|     A S M P w r i t e      |
  120. ;||||||||||||||||||||||||||||||
  121.  
  122. ;  Turbo passed parameters
  123.  
  124. PWSt            EQU     DWORD PTR [BP+6]
  125. PWRow           EQU     BYTE PTR [BP+10]
  126. PWCol           EQU     BYTE PTR [BP+12]
  127. PWWidth         EQU     BYTE PTR [BP+14]
  128. PWScreenStart   EQU     DWORD PTR [BP+16]
  129.  
  130. AsmPWrite      PROC FAR
  131.  
  132.         PUSH    BP                      ;Save BP
  133.         MOV     BP,SP                   ;Set up stack frame
  134.         PUSH    DS                      ;Save DS
  135.         MOV     CH,PWRow                ;CH = Row
  136.         MOV     BL,PWCol                ;BL = Column
  137.         MOV     AL,PWWidth              ;AL = screen width
  138.         LES     DI,PWScreenStart        ;Set up ES:DI to start of screen
  139.         CALL    AdjustESDI              ;move ES:DI to X,Y coord for write
  140.         MOV     CL,Snowprone            ;Need to wait?               
  141.         LDS     SI,PWSt                 ;DS:SI points to St[0]
  142.         CLD                             ;Set direction to forward
  143.         LODSB                           ;AX = Length(St); DS:SI -> St[1]
  144.         XCHG    AX,CX                   ;CX = Length; AL = Wait
  145.         JCXZ    PWExit                  ;exit if string empty
  146.         RCR     AL,1                    ;If WaitForRetrace is False...
  147.         JNC     PWNoWait                ; use PWNoWait routine
  148.         MOV     DX,03DAh                ;Point DX to CGA status port
  149. PWGetNext:
  150.         LODSB                           ;Load next character into AL
  151.         MOV     AH,AL                   ;Store char in AH
  152.         CLI                             ;hold interrupts
  153. PWWaitNoH:
  154.         IN      AL,DX                   ; get retrace situation
  155.         TEST    AL,8                    ;Check for vertical retrace
  156.         JNZ     PWStore                 ; In progress? go
  157.         RCR     AL,1                    ;Else, wait for end of
  158.         JC      PWWaitNoH               ; horizontal retrace
  159. PWWaitH:
  160.         IN      AL,DX                   ;Get 6845 status again
  161.         RCR     AL,1                    ;Wait for horizontal
  162.         JNC     PWWaitH                 ; retrace
  163. PWStore:
  164.         MOV     AL,AH                   ;Move char back to AL...
  165.         STOSB                           ; and then to screen
  166.         STI                             ;OK to interrupt now
  167.         INC     DI                      ;Skip attribute bytes
  168.         LOOP    PWGetNext               ;Get next character
  169.         JMP     PWExit                  ;Done
  170. PWNoWait:
  171.         MOVSB                           ;Move character to screen
  172.         INC     DI                      ;Skip attribute bytes
  173.         LOOP    PWNoWait                ;Get next character
  174. PWExit:
  175.         POP     DS                      ;Clean up and go home
  176.         MOV     SP,BP                   ;
  177.         POP     BP                      ;
  178.         RET     14                      ;
  179.  
  180. AsmPWrite      ENDP
  181.  
  182. ;||||||||||||||||||||||||||
  183. ;|     A S M a t t r      |
  184. ;||||||||||||||||||||||||||
  185.  
  186. ;  Turbo passed parameters
  187.  
  188. ANumber        EQU     WORD PTR [BP+6]
  189. AAttr          EQU     BYTE PTR [BP+8]
  190. ARow           EQU     BYTE PTR [BP+10]
  191. ACol           EQU     BYTE PTR [BP+12]
  192. PWWidth        EQU     BYTE PTR [BP+14]
  193. PWScreenStart  EQU     DWORD PTR [BP+16]
  194.  
  195.  
  196. ASMattr PROC FAR
  197.  
  198.         PUSH    BP                      ;Save BP
  199.         MOV     BP,SP                   ;Set up stack frame
  200.         MOV     CH,PWRow                ;CH = Row
  201.         MOV     BL,PWCol                ;BL = Column
  202.         MOV     AL,PWWidth              ;AL = screen width
  203.         LES     DI,PWScreenStart        ;Set up ES:DI to start of screen
  204.         CALL    AdjustESDI              ;move ES:DI to X,Y coord for write
  205.         INC     DI                      ;Skip character
  206.         CLD                             ;Set direction to forward
  207.         MOV     CX,ANumber              ;CX = Number to change
  208.         JCXZ    AExit                   ;If zero, exit
  209.         MOV     AL,AAttr                ;AL = Attribute
  210.         CMP     SnowProne,1             ;Get wait state
  211.         JNE     ANoWait                 ;If WaitForRetrace is False
  212.                                         ; use ANoWait routine
  213.         MOV     AH,AL                   ;Store attribute in AH
  214.         MOV     DX,03DAh                ;Point DX to CGA status port
  215. AGetNext:
  216.         CLI                             ;No interrupts now
  217. AWaitNoH:
  218.         IN      AL,DX                   ;get retrace situation
  219.         TEST    AL,8                    ;check for vertical retrace
  220.         JNZ     AGo                     ;In progress? Go
  221.         RCR     AL,1                    ;Wait for end of horizontal
  222.         JC      AWaitNoH                ; retrace
  223. AWaitH:
  224.         IN      AL,DX                   ; get retrace situation
  225.         RCR     AL,1                    ;Wait for horizontal
  226.         JNC     AWaitH                  ; retrace
  227. AGo:
  228.         MOV     AL,AH                   ;Move Attr back to AL...
  229.         STOSB                           ; and then to screen
  230.         STI                             ;Allow interrupts
  231.         INC     DI                      ;Skip characters
  232.         LOOP    AGetNext                ;Look for next opportunity
  233.         JMP     AExit                   ;Done
  234. ANoWait:
  235.         STOSB                           ;Change the attribute
  236.         INC     DI                      ;Skip characters
  237.         LOOP    ANoWait                 ;Get next character
  238. AExit:                                  
  239.         MOV     SP,BP                   ;Clean up and go home
  240.         POP     BP                      ;
  241.         RET     14                      ;
  242.  
  243. AsmAttr ENDP
  244.  
  245.  
  246. ENDS    CODE
  247.  
  248.         END
  249.