home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / tptools.zip / ALLINST.ZIP / SINST.ASM < prev    next >
Assembly Source File  |  1987-12-21  |  12KB  |  300 lines

  1.  
  2. ;       SINST.ASM
  3. ;       Editor Toolbox 4.0
  4. ;       Copyright (c) 1985, 87 by Borland International, Inc.
  5. ;
  6. ;       Fast screen writing routines for Editor Toolbox installation programs
  7.  
  8.  
  9. DATA    SEGMENT BYTE PUBLIC
  10.  
  11.         EXTRN   ScreenAdr:WORD,PhyScrCols:WORD  ;Pascal variables
  12.         EXTRN   RetraceMode:BYTE
  13.  
  14. DATA    ENDS
  15.  
  16. CODE    SEGMENT BYTE PUBLIC
  17.  
  18.         ASSUME  CS:CODE,DS:DATA
  19.  
  20.         PUBLIC  EdFastWrite,EdChangeAttribute
  21.         PUBLIC  EdMoveFromScreen,EdMoveToScreen
  22.         PUBLIC  EdSetCursor
  23.  
  24. ;******************************************************
  25.  
  26. ;calculate Offset in video memory.
  27. ;On entry, AX has Row, DI has Column
  28. ;On exit, ES has ScreenAdr, DI has offset
  29.  
  30. CalcOffset      PROC NEAR
  31.  
  32.         DEC     AX                      ;Row to 0..24 range
  33.         MOV     CX,PhyScrCols           ;CX = Rows per column
  34.         MUL     CX                      ;AX = Row * PhyScrCols
  35.         DEC     DI                      ;Column to 0..79 range
  36.         ADD     DI,AX                   ;DI = (Row * PhyScrCols) + Col
  37.         SHL     DI,1                    ;Account for attribute bytes
  38.         MOV     ES,ScreenAdr            ;ES:DI points to ScreenAdr:Row,Col
  39.         RET                             ;Return
  40.  
  41. CalcOffset      ENDP
  42.  
  43. ;******************************************************
  44.  
  45. ;procedure EdFastWrite(St : String; Row, Col, Attr : Integer);
  46.  
  47. ;Write St at Row,Col in Attr (video attribute) without snow
  48.  
  49. FWAttr          EQU     BYTE PTR [BP+6]
  50. FWCol           EQU     WORD PTR [BP+8]
  51. FWRow           EQU     WORD PTR [BP+10]
  52. FWSt            EQU     DWORD PTR [BP+12]
  53.  
  54. EdFastWrite     PROC FAR
  55.  
  56.         PUSH    BP                      ;Save BP
  57.         MOV     BP,SP                   ;Set up stack frame
  58.         PUSH    DS                      ;Save DS
  59.         MOV     AX,FWRow                ;AX = Row
  60.         MOV     DI,FWCol                ;DI = Column
  61.         CALL    CalcOffset              ;Call routine to calculate offset
  62.         MOV     CL,RetraceMode          ;Grab this before changing DS
  63.         LDS     SI,FWSt                 ;DS:SI points to St[0]
  64.         CLD                             ;Set direction to forward
  65.         XOR     AX,AX                   ;AX = 0
  66.         LODSB                           ;AX = Length(St); DS:SI -> St[1]
  67.         XCHG    AX,CX                   ;CX = Length; AL = Wait
  68.         JCXZ    FWExit                  ;If string empty, exit
  69.         MOV     AH,FWAttr               ;AH = Attribute
  70.         RCR     AL,1                    ;If RetraceMode is False...
  71.         JNC     FWMono                  ; use "FWMono" routine
  72.         MOV     DX,03DAh                ;Point DX to CGA status port
  73. FWGetNext:
  74.         LODSB                           ;Load next character into AL
  75.                                         ; AH already has Attr
  76.         MOV     BX,AX                   ;Store video word in BX
  77.         CLI                             ;No interrupts now
  78. FWWaitNoH:
  79.         IN      AL,DX                   ;Get 6845 status
  80.         TEST    AL,8                    ;Vertical retrace in progress?
  81.         JNZ     FWStore                 ;If so, go
  82.         RCR     AL,1                    ;Else, wait for end of
  83.         JC      FWWaitNoH               ; horizontal retrace
  84. FWWaitH:
  85.         IN      AL,DX                   ;Get 6845 status again
  86.         RCR     AL,1                    ;Wait for horizontal
  87.         JNC     FWWaitH                 ; retrace
  88. FWStore:
  89.         MOV     AX,BX                   ;Move word back to AX...
  90.         STOSW                           ; and then to screen
  91.         STI                             ;Allow interrupts!
  92.         LOOP    FWGetNext               ;Get next character
  93.         JMP     FWExit                  ;Done
  94. FWMono:
  95.         LODSB                           ;Load next character into AL
  96.                                         ; AH already has Attr
  97.         STOSW                           ;Move video word into place
  98.         LOOP    FWMono                  ;Get next character
  99. FWExit:
  100.         POP    Z  
  101. BININST        ;Restore DS
  102.         MOV     SP,BP                   ;Restore SP
  103.         POP     BP                      ;Restore BP
  104.         RET     10                      ;Remove parameters and return
  105.  
  106. EdFastWrite     ENDP
  107.  
  108. ;******************************************************
  109.  
  110. ;procedure EdChangeAttribute(Number : Integer; Row, Col, Attr : Integer);
  111.  
  112. ;Change Number video attributes to Attr starting at Row,Col
  113.  
  114. CAAttr          EQU     BYTE PTR [BP+6]
  115. CACol           EQU     WORD PTR [BP+8]
  116. CARow           EQU     WORD PTR [BP+10]
  117. CANumber        EQU     WORD PTR [BP+12]
  118.  
  119. EdChangeAttribute       PROC FAR
  120.  
  121.         PUSH    BP                      ;Save BP
  122.         MOV     BP,SP                   ;Set up stack frame
  123.         MOV     AX,CARow                ;AX = Row
  124.         MOV     DI,CACol                ;DI = Column
  125.         CALL    CalcOffset              ;Call routine to calculate offset
  126.         INC     DI                      ;Skip character
  127.         MOV     AL,CAAttr               ;AL = Attribute
  128.         CLD                             ;Set direction to forward
  129.         MOV     CX,CANumber             ;CX = Number to change
  130.         JCXZ    CAExit                  ;If zero, exit
  131.         CMP     RetraceMode,1           ;Get wait state
  132.         JNE     CANoWait                ;If RetraceMode is False
  133.                                         ; use CANoWait routine
  134.         MOV     AH,AL                   ;Store attribute in AH
  135.         MOV     DX,03DAh                ;Point DX to CGA status port
  136. CAGetNext:
  137.         CLI                             ;No interrupts now
  138. CAWaitNoH:
  139.         IN      AL,DX                   ;Get 6845 status
  140.         TEST    AL,8                    ;Check for vert. retrace
  141.         JNZ     CAGo                    ;In progress? Go
  142.         RCR     AL,1                    ;Wait for end of horizontal
  143.         JC      CAWaitNoH               ; retrace
  144. CAWaitH:
  145.         IN      AL,DX                   ;Get 6845 status again
  146.         RCR     AL,1                    ;Wait for horizontal
  147.         JNC     CAWaitH                 ; retrace
  148. CAGo:
  149.         MOV     AL,AH                   ;Move Attr back to AL...
  150.         STOSB                           ; and then to screen
  151.         STI                             ;Allow interrupts
  152.         INC     DI                      ;Skip characters
  153.         LOOP    CAGetNext               ;Look for next opportunity
  154.         JMP     CAExit                  ;Done
  155. CANoWait:
  156.         STOSB                           ;Change the attribute
  157.         INC     DI                      ;Skip characters
  158.         LOOP    CANoWait                ;Get next character
  159. CAExit:                                 ;Next instruction
  160.         MOV     SP,BP                   ;Restore SP
  161.         POP     BP                      ;Restore BP
  162.         RET     8                       ;Remove parameters and return
  163.  
  164. EdChangeAttribute       ENDP
  165.  
  166. ;******************************************************
  167.  
  168. ;procedure EdMoveFromScreen(var Source, Dest; Length : Integer);
  169.  
  170. ;Move Length words from Source (video memory) to Dest without snow
  171.  
  172. MFLength        EQU     WORD PTR [BP+6]
  173. MFDest          EQU     DWORD PTR [BP+8]
  174. MFSource        EQU     DWORD PTR [BP+12]
  175.  
  176. EdMoveFromScreen        PROC FAR
  177.  
  178.         PUSH    BP                      ;Save BP
  179.         MOV     BP,SP                   ;Set up stack frame
  180.         MOV     BX,DS                   ;Save DS in BX
  181.         MOV     AL,RetraceMode          ;Grab before changing DS
  182.         LES     DI,MFDest               ;ES:DI points to Dest
  183.         LDS     SI,MFSource             ;DS:SI points to Source
  184.         MOV     CX,MFLength             ;CX = Length
  185.         CLD                             ;Set direction to forward
  186.         RCR     AL,1                    ;Check RetraceMode
  187.         JNC     MFNoWait                ;False? Use MFNoWait routine
  188.         MOV     DX,03DAh                ;Point DX to CGA status port
  189. MFNext:
  190.         CLI                             ;No interrupts now
  191. MFWaitNoH:
  192.         IN      AL,DX                   ;Get 6845 status
  193.         TEST    AL,8                    ;Check for vertical retrace
  194.         JNZ     MFGo                    ;In progress? go
  195.         RCR     AL,1                    ;Wait for end of horizontal
  196.         JC      MFWaitNoH               ; retrace
  197. MFWaitH:
  198.         IN      AL,DX                   ;Get 6845 status again
  199.         RCR     AL,1                    ;Wait for horizontal
  200.         JNC     MFWaitH                 ; retrace
  201. MFGo:
  202.         LODSW                           ;Load next video word into AX
  203.         STI                             ;Allow interrupts
  204.         STOSW                           ;Store video word in Dest
  205.         LOOP    MFNext                  ;Get next video word
  206.         JMP     MFExit                  ;All Done
  207. MFNoWait:
  208.         REP     MOVSW                   ;That's it!
  209. MFExit:
  210.         MOV     DS,BX                   ;Restore DS
  211.         MOV     SP,BP                   ;Restore SP
  212.         POP     BP                      ;Restore BP
  213.         RET     10                      ;Remove parameters and return
  214.  
  215. EdMoveFromScreen        ENDP
  216.  
  217. ;******************************************************
  218.  
  219. ;procedure EdMoveToScreen(var Source, Dest; Length : Integer);
  220.  
  221. ;Move Length words from Source to Dest (video memory) without snow
  222.  
  223. MTLength        EQU     WORD PTR [BP+6]
  224. MTDest          EQU     DWORD PTR [BP+8]
  225. MTSource        EQU     DWORD PTR [BP+12]
  226.  
  227. EdMoveToScreen          PROC FAR
  228.  
  229.         PUSH    BP                      ;Save BP
  230.         MOV     BP,SP                   ;Set up stack frame
  231.         PUSH    DS                      ;Save DS
  232.         MOV     AL,RetraceMode          ;Grab before changing DS
  233.         LES     DI,MTDest               ;ES:DI points to Dest
  234.         LDS     SI,MTSource             ;DS:SI points to Source
  235.         MOV     CX,MTLength             ;CX = Length
  236.         CLD                             ;Set direction to forward
  237.         RCR     AL,1                    ;Check RetraceMode
  238.         JNC     MTNoWait                ;False? Use MTNoWait routine
  239.         MOV     DX,03DAh                ;Point DX to CGA status port
  240. MTGetNext:
  241.         LODSW                           ;Load next video word into AX
  242.         MOV     BX,AX                   ;Store video word in BX
  243.         CLI                             ;No interrupts now
  244. MTWaitNoH:
  245.         IN      AL,DX                   ;Get 6845 status
  246.         TEST    AL,8                    ;Check for vertical retrace
  247.         JNZ     MTGo                    ;In progress? Go
  248.         RCR     AL,1                    ;Wait for end of horizontal
  249.         JC      MTWaitNoH               ; retrace
  250. MTWaitH:
  251.         IN      AL,DX                   ;Get 6845 status again
  252.         RCR     AL,1                    ;Wait for horizontal
  253.         JNC     MTWaitH                 ; retrace
  254. MTGo:
  255.         MOV     AX,BX                   ;Move word back to AX...
  256.         STOSW                           ; and then to screen
  257.         STI                             ;Allow interrupts
  258.         LOOP    MTGetNext               ;Get next video word
  259.         JMP     MTExit                  ;All done
  260. MTNoWait:
  261.         REP     MOVSW                   ;That's all!
  262. MTExit:
  263.         POP     DS                      ;Restore DS
  264.         MOV     SP,BP                   ;Restore SP
  265.         POP     BP                      ;Restore BP
  266.         RET     10                      ;Remove parameters and return
  267.  
  268. EdMoveToScreen          ENDP
  269.  
  270. ;******************************************************
  271.  
  272. ;procedure EdSetCursor(ScanLines : Word);
  273.  
  274. ;Set the scan lines of the hardware cursor
  275.  
  276. ScanLines       EQU     WORD PTR [BP+6]
  277.  
  278. EdSetCursor     PROC FAR
  279.  
  280.         PUSH    BP                      ;Save BP
  281.         MOV     BP,SP                   ;Set up stack frame
  282.  
  283.         PUSH    BP                      ;Protect BP
  284.         MOV     CX,ScanLines
  285.         MOV     AH,1
  286.         INT     10H
  287.         POP     BP
  288.  
  289.         MOV     SP,BP                   ;Restore SP
  290.         POP     BP                      ;Restore BP
  291.         RET     2                       ;Remove parameters and return
  292.  
  293. EdSetCursor     ENDP
  294.  
  295.  
  296.  
  297. CODE    ENDS
  298.  
  299.         END
  300.