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

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