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

  1. ;******************************************************
  2. ;           TPPACK.ASM 5.07
  3. ;        Screen packing/unpacking routines
  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. ;******************************************************    Equates
  13.  
  14. ;structure of a    PackedWindow --    DO NOT CHANGE!!
  15.  
  16. WSize        EQU    (WORD PTR 0)    ;size of packed    window
  17. TopRow        EQU    (BYTE PTR 2)    ;coordinates for top left
  18. TopCol        EQU    (BYTE PTR 3)    ; corner of window
  19. Rows        EQU    (BYTE PTR 4)    ;height    of window
  20. Cols        EQU    (BYTE PTR 5)    ;width of window
  21. AStart        EQU    (WORD PTR 6)    ;index to start    of attributes section
  22. CDelta        EQU    (WORD PTR 8)    ;# of bytes to first PackRec --    chars
  23. ADelta        EQU    (WORD PTR 10)    ;# of bytes to first PackRec --    attrs
  24. Contents    EQU    (BYTE PTR 12)    ;the contents of the packed screen
  25.  
  26. ;structure of a    PackRec    -- DO NOT CHANGE!!
  27.  
  28. Link        EQU    (WORD PTR 0)
  29. FillVal        EQU    (BYTE PTR 2)
  30. FillCnt        EQU    (WORD PTR 3)
  31. PackRecSize    =    5
  32.  
  33. ;******************************************************    Data
  34.  
  35. DATA    SEGMENT    BYTE PUBLIC
  36.  
  37.     ;Pascal    variables
  38.  
  39.     EXTRN    VirtualWidth : BYTE        ;Current width of screen
  40.     EXTRN    CheckSnow : BYTE        ;If true, check    for retrace
  41.     EXTRN    VirtualSegment : WORD        ;Segment of screen
  42.  
  43. DATA    ENDS
  44.  
  45. ;******************************************************    Code
  46.  
  47. CODE    SEGMENT    BYTE PUBLIC
  48.  
  49.     ASSUME    CS:CODE, DS:DATA
  50.  
  51.     PUBLIC    PackPrim, DispPackedWindow
  52.  
  53. ;******************************************************    GetWaitState
  54.  
  55. GetWaitState    PROC NEAR
  56.  
  57.     MOV    AX,VirtualSegment    ;AX = VirtualSegment
  58.     MOV    AL,CheckSnow        ;Get snow check    flag into AL
  59.     OR    AL,AL            ;Is it set?
  60.     JZ    WaitExit        ;Exit if not
  61.     CMP    AH,0B8h            ;Reading/writing CGA memory?
  62.     JE    WaitExit        ;Exit if so
  63.     SetZero    AL            ;Otherwise turn    snow checking off
  64. WaitExit:
  65.     RET
  66.  
  67. GetWaitState    ENDP
  68.  
  69. ;******************************************************    PackPrim
  70.  
  71. ;function PackPrim(Height, Width : Byte;
  72. ;           DstSeg, DstOfs, SrcOfs : Word;
  73. ;           var Delta : Word) : Word;
  74. ;Primitive routine to pack a window. Called once for the characters and
  75. ; once for the attributes
  76.  
  77. ;--------------    params -----------------
  78. PDheight    EQU    BYTE PTR [BP+16]
  79. PDwidth        EQU    BYTE PTR [BP+14]
  80. PDseg        EQU    WORD PTR [BP+12]
  81. PDofs        EQU    WORD PTR [BP+10]
  82. PSofs        EQU    WORD PTR [BP+8]
  83. Delta        EQU    DWORD PTR [BP+4]
  84. ;--------------    locals -----------------
  85. LastLink    EQU    WORD PTR [BP-2]
  86. PRdelta        EQU    WORD PTR [BP-4]
  87. Count        EQU    WORD PTR [BP-6]
  88. Pwords1        EQU    WORD PTR [BP-8]
  89. Ldelta        EQU    WORD PTR [BP-10]
  90. LocalSnow1    EQU    BYTE PTR [BP-11]
  91.  
  92. PackPrim    PROC NEAR
  93.  
  94.     StackFrameBP
  95.     SUB    SP,11                ;make room for locals
  96.     PUSH    DS
  97.     CLD                    ;go forward
  98.  
  99.     MOV    AX,WP VirtualWidth        ;calculate words to next row
  100.     SHL    AX,1
  101.     MOV    Pwords1,AX
  102.  
  103.     MOV    Count,1                ;initialize other locals
  104.     MOV    PRdelta,0
  105.     MOV    LastLink,-1
  106.  
  107.     CALL    GetWaitState            ;Set local snow    checking flag
  108.     MOV    LocalSnow1,AL
  109.  
  110.     MOV    DS,VirtualSegment        ;DS:SI => start    of window
  111.     MOV    SI,PSofs
  112.     MOV    ES,PDseg            ;ES:DI => start    of packed screen
  113.     MOV    DI,PDofs
  114.     PUSH    DI                ;save starting offset
  115.  
  116.     OR    AL,AL                ;snow checking on?
  117.     JZ    GetFirst
  118.     MOV    DX,03DAh            ;Point DX to CGA status    port
  119.     WaitForRetrace                ;wait for opportunity
  120. GetFirst:
  121.     MOV    AH,[SI]                ;AH has    last byte -- no    NOT AH!
  122.     STI                    ;interrupts on
  123.  
  124.     MOV    CL,PDheight            ;load outer loop counter
  125.     SetZero    CH
  126.  
  127. OuterLoop1:
  128.     PUSH    CX                ;save outer loop counter
  129.     MOV    CL,PDwidth            ;load inner loop counter
  130.     SetZero    CH
  131.     PUSH    SI                ;save source index
  132.  
  133. InnerLoop1:
  134.     CMP    LocalSnow1,False        ;Need to wait for retrace?
  135.     JE    NoWait                ;if not, go ahead
  136.     WaitForRetrace                ;Else, wait for    an opportunity
  137. NoWait:    LODSB                    ;Read the next byte
  138.     STI                    ;Allow interrupts
  139.     INC    SI                ;skip the odd byte
  140.     NOT    AL                ;flip the bits
  141.  
  142.     STOSB                    ;plug it in
  143.     INC    PRdelta                ;distance between PackRec's
  144.     CMP    AL,AH                ;a repeated byte?
  145.     JNE    NoRepeat
  146.  
  147.     INC    Count                ;increment repeat counter
  148.     LOOP    InnerLoop1            ;repeat    inner loop
  149.     JMP    SHORT EndInner1
  150.  
  151. NoRepeat:
  152.     CMP    Count,PackRecSize        ;is pattern long enough?
  153.     JBE    EndRepeat            ;if not, no PackRec
  154.     MOV    BX,Count            ;Dec(PRdelta, Count+1)
  155.     INC    BX
  156.     SUB    PRdelta,BX
  157.     MOV    BX,LastLink            ;BX = LastLink
  158.     PUSH    PRdelta                ;Put PRdelta on    stack
  159.     CMP    BX,-1                ;Is it -1?
  160.     JNE    FixLastPackRec1
  161.     POP    LDelta                ;if so,    LDelta = PRdelta
  162.     JMP    SHORT MakePackRec
  163.  
  164. FixLastPackRec1:
  165.     POP    ES:[BX]                ;else, ES:LastLink = PRdelta
  166.  
  167. MakePackRec:
  168.     MOV    BX,Count            ;BX has    Count
  169.     SUB    DI,BX                ;DI = DI-Succ(Count)
  170.     DEC    DI
  171.     MOV    LastLink,DI            ;save offset in    LastLink
  172.     INC    DI                ;skip the link for now
  173.     INC    DI
  174.     XCHG    AH,AL                ;get last value    into AL
  175.     STOSB                    ;store it as the FillVal
  176.     XCHG    AH,AL                ;switch    AH and AL back
  177.     XCHG    AX,BX                ;switch    AX and BX
  178.     STOSW                    ;store the FillCnt
  179.     MOV    AX,BX                ;get old AX back from BX
  180.     MOV    PRdelta,1            ;reset distance
  181.     STOSB                    ;append    new char after PackRec
  182.  
  183. EndRepeat:
  184.     MOV    AH,AL                ;save last value
  185.     MOV    Count,1                ;repeat    count =    1
  186.     LOOP    InnerLoop1            ;repeat    inner loop
  187.  
  188. EndInner1:
  189.     POP    SI                ;restore source    index
  190.     ADD    SI,Pwords1            ;advance to next row
  191.     POP    CX                ;restore outer loop counter
  192.     LOOP    OuterLoop1            ;repeat    outer loop
  193.  
  194.     ;fill in the previous link
  195.  
  196.     MOV    CX,PRdelta            ;CX = PRdelta
  197.     MOV    BX,Count            ;BX = Count
  198.     CMP    BX,PackRecSize            ;will we need a    PackRec?
  199.     JBE    DeltaOK                ;if not, don't adjust delta
  200.     SUB    CX,BX                ;else, CX = PRdelta-Count
  201.  
  202. DeltaOK:
  203.     CMP    LastLink,-1            ;have we had a PackRec?
  204.     JNE    FixLastPackRec2
  205.     MOV    Ldelta,CX            ;if not, Ldelta    = PRdelta
  206.     JMP    SHORT PackRecCheck
  207.  
  208. FixLastPackRec2:
  209.     MOV    SI,LastLink            ;store PRdelta in the last
  210.     MOV    ES:[SI],CX            ; unfinished PackRec
  211.  
  212. PackRecCheck:
  213.     CMP    BX,PackRecSize            ;do we need a final PackRec?
  214.     JBE    PPdone
  215.  
  216.     SUB    DI,BX                ;back up dest index
  217.     MOV    CL,AH                ;save last value in CL
  218.     XOR    AX,AX                ;link is 0
  219.     STOSW
  220.     MOV    AL,CL                ;store FillVal
  221.     STOSB
  222.     MOV    AX,BX                ;store repeat count
  223.     STOSW
  224.  
  225. PPdone:
  226.     MOV    BX,DI                ;save current dest. offset
  227.     LES    DI,Delta            ;set Delta
  228.     MOV    AX,Ldelta
  229.     STOSW
  230.  
  231.     POP    AX                ;recover starting offset
  232.     SUB    BX,AX                ;calculate difference...
  233.     MOV    AX,BX                ; and return in    AX
  234.  
  235.     POP    DS                ;restore DS
  236.     ExitCode 14                ;clean up stack    and return
  237.  
  238. PackPrim    ENDP
  239.  
  240. ;******************************************************    DispPackedWindow
  241.  
  242. ;procedure DispPackedWindow(PWP    : PackedWindowPtr);
  243. ;Display the packed window pointed to by PWP.
  244.  
  245. ;--------------    params -----------------
  246. PWP        EQU    DWORD PTR [BP+6]
  247. ;--------------    locals -----------------
  248. NextRecA    EQU    WORD PTR [BP-2]
  249. NextRecC    EQU    WORD PTR [BP-4]
  250. FillCntC    EQU    WORD PTR [BP-6]
  251. FillCntA    EQU    WORD PTR [BP-8]
  252. PWords2        EQU    WORD PTR [BP-10]
  253. LCols        EQU    WORD PTR [BP-12]
  254. LocalSnow2    EQU    BYTE PTR [BP-13]
  255.  
  256. DispPackedWindow    PROC FAR
  257.  
  258.     StackFrameBP                ;set up    stack frame
  259.     SUB    SP,13                ;make room for locals
  260.     PUSH    DS                ;save DS
  261.     CLD                    ;go forward
  262.  
  263.     MOV    AL,VirtualWidth            ;calculate words to next row
  264.     SetZero    AH
  265.     SHL    AX,1
  266.     MOV    Pwords2,AX
  267.     CALL    GetWaitState            ;Set local snow    checking flag
  268.     MOV    LocalSnow2,AL
  269.  
  270.     ;get fields in window record into local    storage
  271.     LES    BX,PWP                ;ES:DI = PWP
  272.     SetZero    AH                ;LCols = # of columns
  273.     MOV    AL,ES:[BX].Cols
  274.     MOV    LCols,AX
  275.     MOV    CL,ES:[BX].Rows            ;CX has    outer loop counter
  276.     SetZero    CH                ; (number of rows)
  277.     MOV    AX,ES:[BX].CDelta        ;# of bytes to first PackRec
  278.     MOV    NextRecC,AX            ; (characters)
  279.     MOV    AX,ES:[BX].ADelta        ;# of bytes to first PackRec
  280.     MOV    NextRecA,AX            ; (attributes)
  281.  
  282.     SetZero    AH                ;calculate starting
  283.     MOV    AL,ES:[BX].TopCol        ;offset    on screen (in DI)
  284.     MOV    DI,AX
  285.     DEC    DI
  286.     SHL    DI,1
  287.     MOV    AL,ES:[BX].TopRow
  288.     DEC    AX
  289.     MUL    PWords2
  290.     ADD    DI,AX
  291.  
  292.     LEA    SI,ES:[BX].Contents        ;SI = offset of    characters
  293.     MOV    BX,ES:[BX].AStart        ;BX has    offset to attributes
  294.     DEC    BX                ;array is 1-based
  295.     ADD    BX,SI
  296.  
  297.     MOV    AX,ES                ;AX = ES
  298.     MOV    ES,VirtualSegment        ;ES = VirtualSegment
  299.     MOV    DS,AX                ;DS = AX
  300.  
  301.     SetZero    AX                ;initialize fill counters to 0
  302.     MOV    FillCntA,AX
  303.     MOV    FillCntC,AX
  304.  
  305. OuterLoop2:
  306.     PUSH    CX                ;save outer loop counter
  307.     MOV    CX,LCols            ;load inner loop counter
  308.     PUSH    DI                ;save dest index
  309.  
  310. InnerLoop2:
  311.     ;get next character
  312.     CMP    FillCntC,0            ;still filling?
  313.     JE    NotFillingC
  314.     DEC    FillCntC            ;yes, decrement    counter
  315.     JMP    SHORT NextAttr
  316.  
  317. NotFillingC:
  318.     CMP    NextRecC,0            ;see if    this is    a PackRec
  319.     JNE    NotAPackRecC
  320.     MOV    DX,[SI]                ;NextRecC = Link
  321.     MOV    NextRecC,DX
  322.     INC    SI                ;skip over the link
  323.     INC    SI
  324.     LODSB                    ;AL has    FillVal
  325.     NOT    AL                ;flip the bits
  326.     MOV    DX,[SI]                ;FillCntC = FillCnt-1
  327.     DEC    DX
  328.     MOV    FillCntC,DX
  329.     INC    SI                ;skip over the FillCnt
  330.     INC    SI
  331.     JMP    SHORT NextAttr
  332.  
  333. NotAPackRecC:
  334.     LODSB                    ;get next character
  335.     NOT    AL                ;flip the bits
  336.     DEC    NextRecC            ;decrement counter
  337.  
  338.     ;get next attribute
  339. NextAttr:
  340.     CMP    FillCntA,0            ;still filling?
  341.     JE    NotFillingA
  342.     DEC    FillCntA            ;yes, decrement    counter
  343.     JMP    SHORT StoreWord
  344.  
  345. NotFillingA:
  346.     CMP    NextRecA,0            ;see if    this is    a PackRec
  347.     JNE    NotAPackRecA
  348.     MOV    DX,[BX]                ;NextRecC = Link
  349.     MOV    NextRecA,DX
  350.     INC    BX                ;skip over the Link
  351.     INC    BX
  352.     MOV    AH,[BX]                ;AH has    FillVal
  353.     NOT    AH                ;flip the bits
  354.     INC    BX                ;skip over the FillVal
  355.     MOV    DX,[BX]                ;FillCntA = FillCnt-1
  356.     DEC    DX
  357.     MOV    FillCntA,DX
  358.     INC    BX                ;skip over the FillCnt
  359.     INC    BX
  360.     JMP    SHORT StoreWord
  361.  
  362. NotAPackRecA:
  363.     MOV    AH,[BX]                ;get next attribute
  364.     NOT    AH                ;flip the bits
  365.     INC    BX
  366.     DEC    NextRecA            ;decrement counter
  367.  
  368. StoreWord:
  369.     PUSH    BX                ;save BX
  370.     CMP    LocalSnow2,False        ;do we need to wait?
  371.     JE    Go                ;if not, go ahead
  372.     MOV    DX,03DAh            ;Point DX to CGA status    port
  373.     MOV    BX,AX                ;save AX in BX
  374.     WaitForRetrace                ;wait for an opportunity
  375.     MOV    AX,BX                ;restore AX
  376. Go:    STOSW                    ;store the pair
  377.     STI                    ;Allow interrupts
  378.     POP    BX                ;restore BX
  379.     LOOP    InnerLoop2            ;repeat    inner loop
  380.  
  381.     POP    DI                ;restore dest index
  382.     ADD    DI,Pwords2            ;advance to next row
  383.     POP    CX                ;restore outer loop counter
  384.     DEC    CX                ;decrement counter
  385.     JCXZ    DPWdone                ;done?
  386.     JMP    OuterLoop2            ;repeat    outer loop
  387.  
  388. DPWdone:
  389.     POP    DS                ;restore DS
  390.     ExitCode 4
  391.  
  392. DispPackedWindow    ENDP
  393.  
  394. CODE    ENDS
  395.  
  396.     END
  397.