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

  1. ;******************************************************
  2. ;           TPFLEX.ASM 5.07
  3. ;          Flexible fast write routine
  4. ;     Copyright (c) TurboPower Software 1988.
  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    WindMin    : WORD            ;Min. XY coordinates
  19.     EXTRN    WindMax    : WORD            ;Max. XY coordinates
  20.  
  21. DATA    ENDS
  22.  
  23. ;******************************************************    Code
  24.  
  25. CODE    SEGMENT    BYTE PUBLIC
  26.  
  27.     ASSUME    CS:CODE, DS:DATA
  28.  
  29.     PUBLIC    FlexWrite, FlexWriteWindow
  30.  
  31.     EXTRN    CalcOffset : NEAR        ;in TPFAST.OBJ
  32.  
  33.     EXTRN    MapColor : FAR            ;Pascal    routine
  34.  
  35. ;******************************************************    FlexWriteWindow
  36.  
  37. ;procedure FlexWriteWindow(S : string; Row, Col    : Byte;    var FAttrs : FlexAttrs);
  38. ;Write a string    flexibly using window-relative coordinates.
  39.  
  40. FWWCol    EQU    BYTE PTR SS:[BX+8]
  41. FWWRow    EQU    BYTE PTR SS:[BX+10]
  42. FWWSt    EQU    DWORD PTR SS:[BX+12]
  43.  
  44. FlexWriteWindow    PROC FAR
  45.  
  46.     StackFrame
  47.     MOV    AL,FWWRow        ;AL = Row
  48.     ADD    AL,WindMin.YLow        ;Adjust    for current window
  49.     MOV    FWWRow,AL        ;Reload    Row
  50.     MOV    AL,FWWCol        ;AL = Col
  51.     ADD    AL,WindMin.XLow        ;Adjust    for current window
  52.     MOV    FWWCol,AL        ;Reload    Col
  53.  
  54.     ;Let FlexWrite do the rest
  55.  
  56. FlexWriteWindow    ENDP
  57.  
  58. ;******************************************************    FlexWrite
  59.  
  60. ;procedure FlexWrite(St    : String; Row, Col : Byte; var FAttrs :    FlexAttrs);
  61. ;Write St at Row,Col with flexible color handling
  62.  
  63. FWSt    EQU    DWORD PTR [BP+14]
  64. FWRow    EQU    BYTE PTR [BP+12]
  65. FWCol    EQU    BYTE PTR [BP+10]
  66. FWAttrs    EQU    DWORD PTR [BP+6]
  67. ;return    address    is at BP+2
  68. ;old BP    is at BP+0
  69. SaveDS    EQU    WORD PTR [BP-2]
  70. Attrs    EQU    BYTE PTR [BP-6]
  71.  
  72. FlexWrite    PROC FAR
  73.  
  74.     StackFrameBP
  75.     PUSH    DS            ;Save DS
  76.     SUB    SP,4            ;make room for locals
  77.     CLD                ;go forward
  78.  
  79.     LDS    SI,FWAttrs        ;DS:SI => FAttrs
  80.     PUSH    SS            ;ES:DI => Attrs
  81.     POP    ES
  82.     LEA    DI,Attrs
  83.     MOVSW                ;make a    local copy of the attributes
  84.     MOVSW
  85.     MOV    DS,SaveDS        ;restore DS
  86.  
  87.     SetZero    AH            ;AH = 0
  88.     MOV    AL,FWRow        ;AX = Row
  89.     SetZero    CH            ;CH = 0
  90.     MOV    CL,FWCol        ;CX = Column
  91.     MOV    DI,CX            ;DI = Column
  92.     CALL    CalcOffset        ;Call routine to calculate offset
  93.  
  94.     GetDSPtr FWSt            ;DS:SI points to St[0]
  95.     SetZero    CH            ;CH = 0
  96.     LODSB                ;AL = Length(St); DS:SI    -> St[1]
  97.     MOV    CL,AL            ;CX = Length
  98.     JCXZ    FWExit            ;If string empty, exit
  99.  
  100.     MOV    AH,Attrs        ;get the default attribute into    AH
  101.     SetZero    AL            ;AL = 0
  102.     PUSH    AX            ;push the pair onto the    stack
  103.  
  104.     MOV    DH,03h            ;DH = 3
  105.     CMP    DL,CH            ;If snow checking is on...
  106.     JE    FWGetNext
  107.     MOV    DL,0DAh            ;Point DX to CGA status    port (03DAh)
  108.  
  109. FWGetNext:
  110.     LODSB                ;Load next character into AL
  111.     CMP    AL,DH            ;is it in range    ^A..^C?
  112.     JA    NotSpecial
  113.     OR    AL,AL
  114.     JZ    NotSpecial
  115.  
  116.     POP    BX            ;get current char/attr pair off    stack
  117.     OR    BL,BL            ;is the    character 0?
  118.     JZ    NewAttr            ;if so,    this is    a new attribute
  119.     CMP    BL,AL            ;is it the same    as the current one?
  120.     JNE    NewAttr            ;if not, this is a new attribute
  121.     POP    AX            ;else get previous char/attr into AX
  122.     OR    AL,AL            ;is the    character 0?
  123.     JNZ    NotZero
  124.     PUSH    AX            ;if so,    push the pair back on the stack
  125. NotZero:
  126.     LOOP    FWGetNext        ;and get next character
  127.     JMP    SHORT FWExit
  128.  
  129. NewAttr:
  130.     PUSH    BX            ;put the current pair back on stack
  131.     MOV    AH,AL            ;save the special character in AH
  132.     LEA    BX,Attrs        ;SS:BX points to Attrs
  133.     XLAT    BYTE PTR SS:[0]        ;translate the attribute
  134.     XCHG    AH,AL            ;get the attr into AH, char into AL
  135.     PUSH    AX            ;push the char/attr onto the stack
  136.     LOOP    FWGetNext        ;and get next character
  137.     JMP    SHORT FWExit
  138.  
  139. NotSpecial:
  140.     OR    DL,DL            ;is DL set up for retrace checking?
  141.     JNZ    FWWait            ;if so,    use special routine
  142.     STOSW                ;else, move video word into place
  143.     LOOP    FWGetNext        ;and get next character
  144.     JMP    SHORT FWExit
  145.  
  146. FWWait:
  147.     MOV    BX,AX            ;Store video word in BX
  148.     WaitForRetrace            ;Wait for an opportunity to write
  149.     WordToCGA    BX        ;Move the word
  150.     LOOP    FWGetNext        ;Get next character
  151.  
  152. FWExit:
  153.     MOV    DS,SaveDS        ;Restore DS
  154.     ExitCode 12
  155.  
  156. FlexWrite    ENDP
  157.  
  158. CODE    ENDS
  159.  
  160.     END
  161.