home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0000 - 0009 / ibm0000-0009 / ibm0003.tar / ibm0003 / TPOWER53.ZIP / TPASM.ARC / TPFAST.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-07-10  |  11.1 KB  |  391 lines

  1. ;******************************************************
  2. ;           TPFAST.ASM 5.07
  3. ;          Fast screen writing routines
  4. ;     Copyright (c) TurboPower Software 1987.
  5. ; Portions copyright (c) Sunny Hill Software 1985, 1986
  6. ;     and used under license to    TurboPower Software
  7. ;         All rights reserved.
  8. ;******************************************************
  9.  
  10.     INCLUDE    TPCOMMON.ASM
  11.  
  12. ;******************************************************    Data
  13.  
  14. DATA    SEGMENT    BYTE PUBLIC
  15.  
  16.     ;Pascal    variables
  17.  
  18.     EXTRN    DirectVideo : BYTE        ;If false, use BIOS
  19.     EXTRN    WindMin    : WORD            ;Min. XY coordinates
  20.     EXTRN    WindMax    : WORD            ;Max. XY coordinates
  21.     EXTRN    CurrentPage : BYTE        ;Current video page
  22.     EXTRN    CurrentMode : BYTE        ;Current video mode
  23.     EXTRN    InTextMode : BYTE        ;False if in graphics mode
  24.     EXTRN    TextAttr : BYTE            ;Current video attribute
  25.     EXTRN    NormalAttr : BYTE        ;Attribute for NormVideo
  26.     EXTRN    CheckSnow : BYTE        ;If true, check    for retrace
  27.     EXTRN    VideoSegment : WORD        ;Segment of Video Memory
  28.     EXTRN    VirtualSegment : WORD        ;Segment of Video Memory--alt
  29.     EXTRN    VirtualWidth : BYTE        ;Current width of virtual display
  30.  
  31. DATA    ENDS
  32.  
  33. ;******************************************************    Code
  34.  
  35. CODE    SEGMENT    BYTE PUBLIC
  36.  
  37.     ASSUME    CS:CODE, DS:DATA
  38.  
  39.     PUBLIC    CalcOffset
  40.     PUBLIC    FastWrite, FastWriteWindow, FastRead, FastReadWindow
  41.     PUBLIC    ReadAttribute, ReadAttributeWindow
  42.     PUBLIC    ChangeAttribute, ChangeAttributeWindow,    MoveScreen
  43.  
  44.     EXTRN    MapColor : FAR            ;Pascal    routine
  45.  
  46. ;******************************************************    CalcOffset
  47.  
  48. ;calculate Offset in video memory.
  49. ;On entry, AX has Row, DI has Column
  50. ;On exit, CX and ES have VideoSegment, DI has offset,
  51. ; and DL = 1 if    snow checking is needed
  52.  
  53. CalcOffset    PROC NEAR
  54.  
  55.     DEC    AX            ;Row to    0..24 range
  56.     MOV    CX, WP VirtualWidth    ;CX = Rows per column
  57.     MUL    CX            ;AX = Row * VirtualWidth
  58.     DEC    DI            ;Column    to 0..79 range
  59.     ADD    DI,AX            ;DI = (Row * VirtualWidth) + Col
  60.     SHL    DI,1            ;Account for attribute bytes
  61.     MOV    CX,VirtualSegment    ;CX = VirtualSegment
  62.     MOV    ES,CX            ;ES:DI points to VideoSegment:Row,Col
  63.     CLD                ;Set direction to forward
  64.     MOV    DL,CheckSnow        ;Get snow check    into DL
  65.     CMP    DL,True            ;Is it set?
  66.     JNE    CalcExit        ;Exit if not
  67.     CMP    CH,0B8h            ;Writing to CGA    memory?
  68.     JE    CalcExit        ;Exit if so
  69.     SetZero    DL            ;Otherwise turn    snow checking off
  70. CalcExit:
  71.     RET                ;Return
  72.  
  73. CalcOffset    ENDP
  74.  
  75. ;******************************************************    FastWriteWindow
  76.  
  77. ;procedure FastWriteWindow(S : string; Row, Col, Attr :    Byte);
  78. ;Write a string    using window-relative coordinates.
  79.  
  80. FWAttr        EQU    BYTE PTR SS:[BX+4]
  81. FWCol        EQU    BYTE PTR SS:[BX+6]
  82. FWRow        EQU    BYTE PTR SS:[BX+8]
  83. FWSt        EQU    DWORD PTR SS:[BX+10]
  84.  
  85. FastWriteWindow    PROC FAR
  86.  
  87.     StackFrame
  88.     MOV    AL,FWAttr        ;Load Attribute    into AL
  89.     PUSH    AX            ;PUSH parameter    onto stack
  90.     CALL    MapColor        ;Call color mapping routine
  91.     StackFrame            ;Set up    stack frame again
  92.     MOV    FWAttr,AL        ;Reload    Attr with mapped attribute
  93.     MOV    AL,FWRow        ;AL = Row
  94.     ADD    AL,WindMin.YLow        ;Adjust    for current window
  95.     MOV    FWRow,AL        ;Reload    Row
  96.     MOV    AL,FWCol        ;AL = Col
  97.     ADD    AL,WindMin.XLow        ;Adjust    for current window
  98.     MOV    FWCol,AL        ;Reload    Col
  99.  
  100.     ;Let FastWrite do the rest
  101.  
  102. FastWriteWindow    ENDP
  103.  
  104. ;******************************************************    FastWrite
  105.  
  106. ;procedure FastWrite(St    : String; Row, Col, Attr : Byte);
  107. ;Write St at Row,Col in    Attr (video attribute) without snow
  108.  
  109. FastWrite     PROC FAR
  110.  
  111.     StackFrame
  112.     PUSH    DS            ;Save DS
  113.     SetZero    AH            ;AH = 0
  114.     MOV    AL,FWRow        ;AX = Row
  115.     SetZero    CH            ;CH = 0
  116.     MOV    CL,FWCol        ;CX = Column
  117.     MOV    DI,CX            ;DI = Column
  118.     CALL    CalcOffset        ;Call routine to calculate offset
  119.     GetDSPtr    FWSt        ;DS:SI points to St[0]
  120.     SetZero    CX            ;CX = 0
  121.     LODSB                ;AL = Length(St); DS:SI    -> St[1]
  122.     MOV    CL,AL            ;CX = Length
  123.     JCXZ    FWExit            ;If string empty, exit
  124.     MOV    AH,FWAttr        ;AH = Attribute
  125.     SHR    DL,1            ;If snow checking is off...
  126.     JNC    FWNoWait        ; use FWNoWait routine
  127.     MOV    DX,03DAh        ;Point DX to CGA status    port
  128. FWGetNext:
  129.     LODSB                ;Load next character into AL
  130.                     ; AH already has Attr
  131.     MOV    BX,AX            ;Store video word in BX
  132.     WaitForRetrace            ;Wait for an opportunity to write
  133.     WordToCGA    BX        ;Move the word
  134.     LOOP    FWGetNext        ;Get next character
  135.     JMP    SHORT FWExit        ;Done
  136. FWNoWait:
  137.     LODSB                ;Load next character into AL
  138.                     ; AH already has Attr
  139.     STOSW                ;Move video word into place
  140.     LOOP    FWNoWait        ;Get next character
  141. FWExit:
  142.     POP    DS            ;Restore DS
  143.     RET    10
  144.  
  145. FastWrite    ENDP
  146.  
  147. ;******************************************************    ReadAttributeWindow
  148.  
  149. ;procedure ReadAttributeWindow(Number, Row, Col    : Byte;    var St : string);
  150. ;Read Number attributes    from the screen    into St    starting at Row,Col
  151.  
  152. ReadAttributeWindow    PROC FAR
  153.  
  154.     MOV    SI,1            ;Read attributes
  155.     JMP    SHORT FastReadWindowPrim
  156.  
  157. ReadAttributeWindow    ENDP
  158.  
  159. ;******************************************************    FastReadWindow
  160.  
  161. ;procedure FastReadWindow(Number, Row, Col : Byte; var St : string);
  162. ;Read Number bytes from    the screen into    St starting at Row,Col without snow
  163.  
  164. FRSt    EQU    DWORD PTR SS:[BX+4]
  165. FRCol    EQU    BYTE PTR SS:[BX+8]
  166. FRRow    EQU    BYTE PTR SS:[BX+10]
  167. FRNum    EQU    BYTE PTR SS:[BX+12]
  168.  
  169. FastReadWindow    PROC FAR
  170.  
  171.     SetZero    SI            ;Read characters
  172.  
  173. FastReadWindowPrim:
  174.  
  175.     StackFrame
  176.     MOV    AL,FRRow        ;AL = Row
  177.     ADD    AL,WindMin.YLow        ;Adjust    for current window
  178.     MOV    FRRow,AL        ;Reload    Row
  179.     MOV    AL,FRCol        ;AL = Col
  180.     ADD    AL,WindMin.XLow        ;Adjust    for current window
  181.     MOV    FRCol,AL        ;Reload    Col
  182.     JMP    SHORT FastReadPrim    ;Let FastRead do the rest
  183.  
  184. FastReadWindow    ENDP
  185.  
  186. ;******************************************************    ReadAttribute
  187.  
  188. ;procedure ReadAttribute(Number, Row, Col : Byte; var St : string);
  189. ;Read Number attributes    from the screen    into St    starting at Row,Col
  190.  
  191. ReadAttribute    PROC FAR
  192.  
  193.     MOV    SI,1            ;Read attributes
  194.     JMP    SHORT FastReadPrim
  195.  
  196. ReadAttribute    ENDP
  197.  
  198. ;******************************************************    FastRead
  199.  
  200. ;procedure FastRead(Number, Row, Col : Byte; var St : string);
  201. ;Read Number characters    from the screen    into St    starting at Row,Col
  202.  
  203. FastRead      PROC FAR
  204.  
  205.     SetZero    SI            ;Read characters
  206.  
  207. FastReadPrim:
  208.  
  209.     StackFrame
  210.     PUSH    DS            ;Save DS
  211.     SetZero    AH            ;AH = 0
  212.     MOV    AL,FRRow        ;AX = Row
  213.     SetZero    CH            ;CH = 0
  214.     MOV    CL,FRCol        ;CX = Column
  215.     MOV    DI,CX            ;DI = Column
  216.     CALL    CalcOffset        ;Call routine to calculate offset
  217.     ADD    DI,SI            ;adjust    for attributes if necessary
  218.     MOV    DS,CX            ;CX still has VideoSegment
  219.     MOV    SI,DI            ;DS:SI points to VideoSegment:Row,Col
  220.     GetPtr    FRSt            ;ES:DI points to St[0]
  221.     SetZero    AH            ;AH = 0
  222.     MOV    AL,FRNum        ;AX = number of    bytes to read
  223.     STOSB                ;Set length byte
  224.     MOV    CX,AX            ;CX = Length
  225.     JCXZ    FRExit            ;If string empty, exit
  226.     SHR    DL,1            ;If snow checking is off...
  227.     JNC    FRNoWait        ; use FWNoWait routine
  228.     MOV    DX,03DAh        ;Point DX to CGA status    port
  229. FRGetNext:
  230.     WaitForRetrace            ;Wait for an opportunity
  231.     LODSB                ;Load next char    into AX
  232.     STI                ;Allow interrupts
  233.     STOSB                ;Store the character in    St
  234.     INC    SI            ;Skip attribute
  235.     LOOP    FRGetNext        ;Get next character
  236.     JMP    SHORT FRExit        ;Done
  237. FRNoWait:
  238.     LODSW                ;Load next word    into AX
  239.     STOSB                ;Move character    into St
  240.     LOOP    FRNoWait        ;Get next character
  241. FRExit:
  242.     POP    DS            ;Restore DS
  243.     RET    10
  244.  
  245. FastRead      ENDP
  246.  
  247. ;******************************************************    ChangeAttributeWindow
  248.  
  249. ;procedure ChangeAttributeWindow(Number    : Word;    Row, Col, Attr : Byte);
  250. ;Change    Number video attributes    to Attr    starting at Row,Col
  251.  
  252. CAAttr        EQU    BYTE PTR SS:[BX+4]
  253. CACol        EQU    BYTE PTR SS:[BX+6]
  254. CARow        EQU    BYTE PTR SS:[BX+8]
  255. CANumber    EQU    WORD PTR SS:[BX+10]
  256.  
  257. ChangeAttributeWindow    PROC FAR
  258.  
  259.     StackFrame
  260.     MOV    AL,CAAttr        ;Load Attribute    into AL
  261.     PUSH    AX            ;PUSH parameter    onto stack
  262.     CALL    MapColor        ;Call color mapping routine
  263.     StackFrame            ;Set up    stack frame again
  264.     MOV    CAAttr,AL        ;Reload    Attr with mapped attribute
  265.     MOV    AL,CARow        ;AL = Row
  266.     ADD    AL,WindMin.YLow        ;Adjust    for current window
  267.     MOV    CARow,AL        ;Reload    Row
  268.     MOV    AL,CACol        ;AL = Col
  269.     ADD    AL,WindMin.XLow        ;Adjust    for current window
  270.     MOV    CACol,AL        ;Reload    Col
  271.  
  272.     ;let ChangeAttribute do    the rest
  273.  
  274. ChangeAttributeWindow    ENDP
  275.  
  276. ;******************************************************    ChangeAttribute
  277.  
  278. ;procedure ChangeAttribute(Number : Word; Row, Col, Attr : Byte);
  279. ;Change    Number video attributes    to Attr    starting at Row,Col
  280.  
  281. ChangeAttribute          PROC FAR
  282.  
  283.     StackFrame
  284.     SetZero    AH            ;AH = 0
  285.     MOV    AL,CARow        ;AX = Row
  286.     SetZero    CH            ;CH = 0
  287.     MOV    CL,CACol        ;CX = Column
  288.     MOV    DI,CX            ;DI = Column
  289.     CALL    CalcOffset        ;Call routine to calculate offset
  290.     INC    DI            ;Skip character
  291.     MOV    AL,CAAttr        ;AL = Attribute
  292.     MOV    CX,CANumber        ;CX = Number to    change
  293.     JCXZ    CAExit            ;If zero, exit
  294.     SHR    DL,1            ;If snow checking is off...
  295.     JNC    CANoWait        ; use CANoWait routine
  296.     MOV    AH,AL            ;Store attribute in AH
  297.     MOV    DX,03DAh        ;Point DX to CGA status    port
  298. CAGetNext:
  299.     WaitForRetrace            ;Wait for an opportunity to write
  300.     MOV    AL,AH            ;Move Attr back    to AL...
  301.     STOSB                ; and then to screen
  302.     STI                ;Allow interrupts
  303.     INC    DI            ;Skip characters
  304.     LOOP    CAGetNext        ;Look for next opportunity
  305.     JMP    SHORT CAExit        ;Done
  306. CANoWait:
  307.     STOSB                ;Change    the attribute
  308.     INC    DI            ;Skip characters
  309.     LOOP    CANoWait        ;Get next character
  310. CAExit:
  311.     RET    8
  312.  
  313. ChangeAttribute          ENDP
  314.  
  315. ;******************************************************    MoveScreen
  316.  
  317. ;procedure MoveScreen(var Source, Dest;    Length : Word);
  318. ;Move Length words from    Source to Dest without snow
  319.  
  320. MLength        EQU    WORD PTR SS:[BX+4]
  321. MDest        EQU    DWORD PTR SS:[BX+6]
  322. MSource        EQU    DWORD PTR SS:[BX+10]
  323.  
  324. MoveScreen    PROC FAR
  325.  
  326.     StackFrame
  327.     PUSH    DS            ;Save DS
  328.     SetZero    AH            ;AH = 0
  329.     MOV    AL,CheckSnow        ;Grab before changing DS
  330.     GetPtr        MDest        ;ES:DI points to Dest
  331.     GetDSPtr    MSource        ;DS:SI points to Source
  332.     MOV    CX,MLength        ;CX = Length
  333.     JCXZ    MSExit            ;Exit if CX = 0
  334.     CLD                ;Assume    forward
  335.     MOV    BX,DS            ;BX = DS
  336.     MOV    DX,ES            ;DX = ES
  337.     CMP    DX,BX            ;Same segment?
  338.     MOV    BL,0            ;Clear same-segment flag
  339.     JNE    MSForward        ;If not, go forward
  340.     INC    BL            ;Set same-segment flag
  341.     CMP    SI,DI            ;Check for potential overlap
  342.     JAE    MSForward        ;Go forward if Source at higher    offset
  343.  
  344.     STD                ;Go backwards
  345.     DEC    CX            ;CX = Number of    words to add to    SI/DI
  346.     ADD    DI,CX            ;Point DI to end of Dest area
  347.     ADD    DI,CX
  348.     ADD    SI,CX            ;Point SI to end of Source area
  349.     ADD    SI,CX
  350.     INC    CX            ;Reset CX
  351.     INC    AH            ;Flag to indicate we're going backward
  352.  
  353. MSForward:
  354.     SHR    AL,1            ;Snow checking on?
  355.     JNC    MSNoWait        ;Skip the rest of this if not
  356.     CMP    BH,0B8h            ;See if    we're reading from CGA memory
  357.     JE    MSGetNext        ;If so,    wait for retrace
  358.     CMP    DH,0B8h            ;Check segment in ES, too
  359.     JNE    MSNoWait        ;Not writing to    CGA
  360. MSGetNext:
  361.     MOV    DX,03DAh        ;Point DX to CGA status    port
  362.  
  363. IF SuppressAllSnow
  364.     OR    AH,AH            ;Going forward?
  365.     JZ    MSgo            ;If so,    continue
  366.     INC    SI            ;Else, point SI/DI to last byte, rather
  367.     INC    DI            ; than the last    word
  368. ELSE
  369.     ;see if    we can use a faster algorithm
  370.     OR    BL,BL            ;is same-segment flag set?
  371.     JNZ    MSgo            ;if so,    use WordMoveNoSnow algorithm
  372.     FastMoveNoSnow            ;else, use faster algorithm
  373.     JMP    SHORT MSExit
  374. ENDIF
  375.  
  376. MSgo:
  377.     WordMoveNoSnow            ;Move CX words,    preventing snow
  378.     JMP    SHORT MSExit        ;All done
  379. MSNoWait:
  380.     REP    MOVSW            ;That's all!
  381. MSExit:
  382.     CLD                ;Reset direction flag
  383.     POP    DS            ;Restore DS
  384.     RET    10
  385.  
  386. MoveScreen    ENDP
  387.  
  388. CODE    ENDS
  389.  
  390.     END
  391.