home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / tot4.zip / TOTFAST.ASM < prev    next >
Assembly Source File  |  1991-02-11  |  15KB  |  354 lines

  1. ;                  Copyright 1991 TechnoJock Software, Inc. 
  2. ;                             All Rights Reserved           
  3. ;                            Restricted by License          
  4.  
  5. ;                                 FastTOP.ASM 
  6.  
  7. ;                               Version Alpha 2
  8.  
  9. %Title "TOT 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.         PUBLIC  ASMMoveFromScreen, ASMMoveToScreen
  26.  
  27. ;  |||||||||||||||||||||||||||||||
  28. ;  |     A d j u s t E S D I     |
  29. ;  |||||||||||||||||||||||||||||||
  30.  
  31. ;   Local routine that computes the offset from the top left of
  32. ;   the screen. You must set ES:DI to point to start of screen 
  33. ;   before calling.
  34.  
  35. AdjustESDI      PROC NEAR
  36.  
  37.         XOR     DX,DX                   ;set DX to 0
  38.         MOV     CL,DL                   ;CL = 0
  39.         MOV     BH,DL                   ;BH = 0
  40.         MOV     AH,DL                   ;AH = 0
  41.         DEC     CH                      ;set CH to number of full rows
  42.         MUL     CH                      ;AX <- CH * AL  i.e. rows * width
  43.         SHL     AX,1                    ;*2 for char and attr
  44.         ADD     DI,AX                   ;add rows*width*2 to DI 
  45.         DEC     BX                      ;decrease cols by 1
  46.         SHL     BX,1                    ;multiply cols by 2
  47.         ADD     DI,BX                   ;add cols to DI
  48.         XOR     AX,AX                   ;set AX to zero
  49.         RET                             ;Return
  50.  
  51. AdjustESDI      ENDP
  52.  
  53. ;||||||||||||||||||||||||||||
  54. ;|     A S M w r i t e      |
  55. ;||||||||||||||||||||||||||||
  56.  
  57. ;  Turbo passed parameters
  58.  
  59. AWSt            EQU     DWORD PTR [BP+6]
  60. AWAttr          EQU     BYTE PTR [BP+10]
  61. AWRow           EQU     BYTE PTR [BP+12]
  62. AWCol           EQU     BYTE PTR [BP+14]
  63. AWWidth         EQU     BYTE PTR [BP+16]
  64. AWScreenStart   EQU     DWORD PTR [BP+18]
  65.  
  66. AsmWrite       PROC FAR
  67.  
  68.         PUSH    BP                      ;Save BP
  69.         MOV     BP,SP                   ;Set up stack frame
  70.         PUSH    DS                      ;Save DS
  71.         MOV     CH,AWRow                ;CH = Row
  72.         MOV     BL,AWCol                ;BL = Column
  73.         MOV     AL,AWWidth              ;AL = screen width
  74.         LES     DI,AWScreenStart        ;Set up ES:DI to start of screen
  75.         CALL    AdjustESDI              ;move ES:DI to X,Y coord for write
  76.         MOV     CL,SnowProne            ;Need to wait?
  77.         LDS     SI,AWSt                 ;DS:SI points to St[0]
  78.         CLD                             ;Set SI inc. direction to forward
  79.         LODSB                           ;AX = Length(St); DS:SI -> St[1]
  80.         XCHG    AX,CX                   ;CX = Length; AL = WaitForRetrace
  81.         JCXZ    AWExit                  ;exit if CX = 0, i.e. string empty
  82.         MOV     AH,AWAttr               ;AH = display attribute
  83.         RCR     AL,1                    ;If WaitForRetrace is False...
  84.         JNC     AWMono                  ; use "AWMono" routine
  85.         MOV     DX,03DAh                ;Point DX to CGA status port
  86. AWGetNext:
  87.         LODSB                           ;Load next character into AL
  88.         MOV     BX,AX                   ;Store video word in BX
  89.         CLI                             ;hold interrupts
  90. AWWaitNoH:
  91.         IN      AL,DX                   ;get retrace situation
  92.         TEST    AL,8                    ;retracing?
  93.         JNZ     AWStore                 ;If so, go
  94.         RCR     AL,1                    ;Else, wait for end of
  95.         JC      AWWaitNoH               ; horizontal retrace
  96. AWWaitH:
  97.         IN      AL,DX                   ;get retrace situation
  98.         RCR     AL,1                    ;Wait for horizontal
  99.         JNC     AWWaitH                 ; retrace
  100. AWStore:
  101.         MOV     AX,BX                   ;Move word back to AX...
  102.         STOSW                           ; and then to screen
  103.         STI                             ;OK to interrupt now
  104.         LOOP    AWGetNext               ;Get next character
  105.         JMP     AWExit                  ;wind up
  106. AWMono:
  107.         LODSB                           ;Load next character into AL
  108.         STOSW                           ;Move video word into place
  109.         LOOP    AWMono                  ;Get next character
  110. AWExit:
  111.         POP     DS                      ;clean up and go home
  112.         MOV     SP,BP                   ;
  113.         POP     BP                      ;
  114.         RET     16                      ;16 bytes for passed paremeters 
  115.                                         ;(minimum is 2 bytes per param)
  116.  
  117. AsmWrite       ENDP
  118.  
  119. ;||||||||||||||||||||||||||||||
  120. ;|     A S M P w r i t e      |
  121. ;||||||||||||||||||||||||||||||
  122.  
  123. ;  Turbo passed parameters
  124.  
  125. PWSt            EQU     DWORD PTR [BP+6]
  126. PWRow           EQU     BYTE PTR [BP+10]
  127. PWCol           EQU     BYTE PTR [BP+12]
  128. PWWidth         EQU     BYTE PTR [BP+14]
  129. PWScreenStart   EQU     DWORD PTR [BP+16]
  130.  
  131. AsmPWrite      PROC FAR
  132.  
  133.         PUSH    BP                      ;Save BP
  134.         MOV     BP,SP                   ;Set up stack frame
  135.         PUSH    DS                      ;Save DS
  136.         MOV     CH,PWRow                ;CH = Row
  137.         MOV     BL,PWCol                ;BL = Column
  138.         MOV     AL,PWWidth              ;AL = screen width
  139.         LES     DI,PWScreenStart        ;Set up ES:DI to start of screen
  140.         CALL    AdjustESDI              ;move ES:DI to X,Y coord for write
  141.         MOV     CL,Snowprone            ;Need to wait?               
  142.         LDS     SI,PWSt                 ;DS:SI points to St[0]
  143.         CLD                             ;Set direction to forward
  144.         LODSB                           ;AX = Length(St); DS:SI -> St[1]
  145.         XCHG    AX,CX                   ;CX = Length; AL = Wait
  146.         JCXZ    PWExit                  ;exit if string empty
  147.         RCR     AL,1                    ;If WaitForRetrace is False...
  148.         JNC     PWNoWait                ; use PWNoWait routine
  149.         MOV     DX,03DAh                ;Point DX to CGA status port
  150. PWGetNext:
  151.         LODSB                           ;Load next character into AL
  152.         MOV     AH,AL                   ;Store char in AH
  153.         CLI                             ;hold interrupts
  154. PWWaitNoH:
  155.         IN      AL,DX                   ; get retrace situation
  156.         TEST    AL,8                    ;Check for vertical retrace
  157.         JNZ     PWStore                 ; In progress? go
  158.         RCR     AL,1                    ;Else, wait for end of
  159.         JC      PWWaitNoH               ; horizontal retrace
  160. PWWaitH:
  161.         IN      AL,DX                   ;Get 6845 status again
  162.         RCR     AL,1                    ;Wait for horizontal
  163.         JNC     PWWaitH                 ; retrace
  164. PWStore:
  165.         MOV     AL,AH                   ;Move char back to AL...
  166.         STOSB                           ; and then to screen
  167.         STI                             ;OK to interrupt now
  168.         INC     DI                      ;Skip attribute bytes
  169.         LOOP    PWGetNext               ;Get next character
  170.         JMP     PWExit                  ;Done
  171. PWNoWait:
  172.         MOVSB                           ;Move character to screen
  173.         INC     DI                      ;Skip attribute bytes
  174.         LOOP    PWNoWait                ;Get next character
  175. PWExit:
  176.         POP     DS                      ;Clean up and go home
  177.         MOV     SP,BP                   ;
  178.         POP     BP                      ;
  179.         RET     14                      ;
  180.  
  181. AsmPWrite      ENDP
  182.  
  183. ;||||||||||||||||||||||||||
  184. ;|     A S M a t t r      |
  185. ;||||||||||||||||||||||||||
  186.  
  187. ;  Turbo passed parameters
  188.  
  189. ANumber        EQU     WORD PTR [BP+6]
  190. AAttr          EQU     BYTE PTR [BP+8]
  191. ARow           EQU     BYTE PTR [BP+10]
  192. ACol           EQU     BYTE PTR [BP+12]
  193. PWWidth        EQU     BYTE PTR [BP+14]
  194. PWScreenStart  EQU     DWORD PTR [BP+16]
  195.  
  196.  
  197. ASMattr PROC FAR
  198.  
  199.         PUSH    BP                      ;Save BP
  200.         MOV     BP,SP                   ;Set up stack frame
  201.         MOV     CH,PWRow                ;CH = Row
  202.         MOV     BL,PWCol                ;BL = Column
  203.         MOV     AL,PWWidth              ;AL = screen width
  204.         LES     DI,PWScreenStart        ;Set up ES:DI to start of screen
  205.         CALL    AdjustESDI              ;move ES:DI to X,Y coord for write
  206.         INC     DI                      ;Skip character
  207.         CLD                             ;Set direction to forward
  208.         MOV     CX,ANumber              ;CX = Number to change
  209.         JCXZ    AExit                   ;If zero, exit
  210.         MOV     AL,AAttr                ;AL = Attribute
  211.         CMP     SnowProne,1             ;Get wait state
  212.         JNE     ANoWait                 ;If WaitForRetrace is False
  213.                                         ; use ANoWait routine
  214.         MOV     AH,AL                   ;Store attribute in AH
  215.         MOV     DX,03DAh                ;Point DX to CGA status port
  216. AGetNext:
  217.         CLI                             ;No interrupts now
  218. AWaitNoH:
  219.         IN      AL,DX                   ;get retrace situation
  220.         TEST    AL,8                    ;check for vertical retrace
  221.         JNZ     AGo                     ;In progress? Go
  222.         RCR     AL,1                    ;Wait for end of horizontal
  223.         JC      AWaitNoH                ; retrace
  224. AWaitH:
  225.         IN      AL,DX                   ; get retrace situation
  226.         RCR     AL,1                    ;Wait for horizontal
  227.         JNC     AWaitH                  ; retrace
  228. AGo:
  229.         MOV     AL,AH                   ;Move Attr back to AL...
  230.         STOSB                           ; and then to screen
  231.         STI                             ;Allow interrupts
  232.         INC     DI                      ;Skip characters
  233.         LOOP    AGetNext                ;Look for next opportunity
  234.         JMP     AExit                   ;Done
  235. ANoWait:
  236.         STOSB                           ;Change the attribute
  237.         INC     DI                      ;Skip characters
  238.         LOOP    ANoWait                 ;Get next character
  239. AExit:                                  
  240.         MOV     SP,BP                   ;Clean up and go home
  241.         POP     BP                      ;
  242.         RET     14                      ;
  243.  
  244. AsmAttr ENDP
  245.  
  246.  
  247. ;||||||||||||||||||||||||||||||||||||||||||||||
  248. ;|     A S M M o v e F r o m S c r e e n      |
  249. ;||||||||||||||||||||||||||||||||||||||||||||||
  250.  
  251. ;  Turbo passed parameters
  252.  
  253. MFLength        EQU     WORD PTR [BP+6]
  254. MFDest          EQU     DWORD PTR [BP+8]
  255. MFSource        EQU     DWORD PTR [BP+12]
  256.  
  257. ASMMoveFromScreen  PROC FAR
  258.  
  259.         PUSH    BP                      ;Save BP
  260.         MOV     BP,SP                   ;Set up stack frame
  261.         MOV     BX,DS                   ;Save DS in BX
  262.         MOV     AL,Snowprone            ;Grab before changing DS
  263.         LES     DI,MFDest               ;ES:DI points to Dest
  264.         LDS     SI,MFSource             ;DS:SI points to Source
  265.         MOV     CX,MFLength             ;CX = Length
  266.         CLD                             ;Set direction to forward
  267.         RCR     AL,1                    ;Check WaitForRetrace
  268.         JNC     MFNoWait                ;False? Use MFNoWait routine
  269.         MOV     DX,03DAh                ;Point DX to CGA status port
  270. MFNext:
  271.         CLI                             ;No interrupts now
  272. MFWaitNoH:
  273.         IN      AL,DX                   ;Get 6845 status
  274.         TEST    AL,8                    ;Check for vertical retrace
  275.         JNZ     MFGo                    ;In progress? go
  276.         RCR     AL,1                    ;Wait for end of horizontal
  277.         JC      MFWaitNoH               ; retrace
  278. MFWaitH:
  279.         IN      AL,DX                   ;Get 6845 status again
  280.         RCR     AL,1                    ;Wait for horizontal
  281.         JNC     MFWaitH                 ; retrace
  282. MFGo:
  283.         LODSW                           ;Load next video word into AX
  284.         STI                             ;Allow interrupts
  285.         STOSW                           ;Store video word in Dest
  286.         LOOP    MFNext                  ;Get next video word
  287.         JMP     MFExit                  ;All Done
  288. MFNoWait:
  289.         REP     MOVSW                   ;That's it!
  290. MFExit:
  291.         MOV     DS,BX                   ;Restore DS
  292.         MOV     SP,BP                   ;Restore SP
  293.         POP     BP                      ;Restore BP
  294.         RET     10                      ;Remove parameters and return
  295.  
  296. ASMMoveFromScreen  ENDP
  297.  
  298. ;|||||||||||||||||||||||||||||||||||||||||||
  299. ;|     A S M M o v e T o  S c r e e n      |
  300. ;|||||||||||||||||||||||||||||||||||||||||||
  301.  
  302. ;  Turbo passed parameters
  303.  
  304. MTLength        EQU     WORD PTR [BP+6]
  305. MTDest          EQU     DWORD PTR [BP+8]
  306. MTSource        EQU     DWORD PTR [BP+12]
  307.  
  308. ASMMoveToScreen    PROC FAR
  309.  
  310.         PUSH    BP                      ;Save BP
  311.         MOV     BP,SP                   ;Set up stack frame
  312.         PUSH    DS                      ;Save DS
  313.         MOV     AL,SnowProne            ;Grab before changing DS
  314.         LES     DI,MTDest               ;ES:DI points to Dest
  315.         LDS     SI,MTSource             ;DS:SI points to Source
  316.         MOV     CX,MTLength             ;CX = Length
  317.         CLD                             ;Set direction to forward
  318.         RCR     AL,1                    ;Check WaitForRetrace
  319.         JNC     MTNoWait                ;False? Use MTNoWait routine
  320.         MOV     DX,03DAh                ;Point DX to CGA status port
  321. MTGetNext:
  322.         LODSW                           ;Load next video word into AX
  323.         MOV     BX,AX                   ;Store video word in BX
  324.         CLI                             ;No interrupts now
  325. MTWaitNoH:
  326.         IN      AL,DX                   ;Get 6845 status
  327.         TEST    AL,8                    ;Check for vertical retrace
  328.         JNZ     MTGo                    ;In progress? Go
  329.         RCR     AL,1                    ;Wait for end of horizontal
  330.         JC      MTWaitNoH               ; retrace
  331. MTWaitH:
  332.         IN      AL,DX                   ;Get 6845 status again
  333.         RCR     AL,1                    ;Wait for horizontal
  334.         JNC     MTWaitH                 ; retrace
  335. MTGo:
  336.         MOV     AX,BX                   ;Move word back to AX...
  337.         STOSW                           ; and then to screen
  338.         STI                             ;Allow interrupts
  339.         LOOP    MTGetNext               ;Get next video word
  340.         JMP     MTExit                  ;All done
  341. MTNoWait:
  342.         REP     MOVSW                   ;That's all!
  343. MTExit:
  344.         POP     DS                      ;Restore DS
  345.         MOV     SP,BP                   ;Restore SP
  346.         POP     BP                      ;Restore BP
  347.         RET     10                      ;Remove parameters and return
  348.  
  349. ASMMoveToScreen    ENDP
  350.  
  351. ENDS    CODE
  352.  
  353.         END
  354.