home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 94.img / THEDRAW.ZIP / UNCRUNCH.ASM < prev    next >
Assembly Source File  |  1989-11-01  |  8KB  |  197 lines

  1. ;THEDRAW IMAGE UNCRUNCHING ROUTINE
  2. ;-----------------------------------------------------------------------------
  3. ;Compatible with MASM (Microsoft) and TASM v1.0 (Borland).  Minor format
  4. ;changes may be required for other assemblers.
  5. ;-----------------------------------------------------------------------------
  6. ;
  7. ;This is the flash display routine used to display crunched TheDraw image
  8. ;files.  It uses a custom protocol for reproducing an image with any
  9. ;possible color combinations.  The control codes below 32 are reserved
  10. ;for this function.  The following data structure shows the format of a
  11. ;sequence.  Not all operations use the optional bytes <x> or <y>..
  12. ;
  13. ;Data Structure:  <current byte>[<x>[<y>]]
  14. ;
  15. ;   0..15 = New Foreground Color
  16. ;  16..23 = New Background Color
  17. ;      24 = Go down to next line, return to same horizontal position as when
  18. ;           routine was started (akin to a c/r).
  19. ;      25 = Displays <x> number of spaces.
  20. ;      26 = Displays <x> number of <y>.  Also used to display ANY characters
  21. ;           below #32.  This function is the only way to do this although it
  22. ;           uses three bytes.  Otherwise the code would be interpreted as
  23. ;           another command.
  24. ;      27 = Toggles on/off the foreground attribute blink flag.
  25. ;
  26. ;----------------------------------------------------------------------------
  27. ;
  28. ;To use this uncrunch routine, call the procedure with the DS:SI register
  29. ;pair pointing to the TheDraw output listing, the ES:DI register pair
  30. ;pointing to the destination display address, and the length of the image
  31. ;data in the CX register.  All modified registers are restored upon exiting.
  32. ;
  33. ;Assume an output file of a 40 character by 10 line block.  The label
  34. ;'IMAGEDATA' has been added for referencing purposes. ie:
  35. ;
  36. ;
  37. ;     ;TheDraw Assembler Crunched Screen Image
  38. ;     IMAGEDATA_WIDTH EQU 40
  39. ;     IMAGEDATA_DEPTH EQU 10
  40. ;     IMAGEDATA_LENGTH EQU 467
  41. ;     IMAGEDATA LABEL BYTE
  42. ;                DB      ...list of image bytes here...
  43. ;
  44. ;
  45. ;The following assembly language code could then be used to display the
  46. ;40x10 block on the screen with:
  47. ;
  48. ;                MOV     SI,offset IMAGEDATA
  49. ;                MOV     AX,0B800h
  50. ;                MOV     ES,AX
  51. ;                MOV     DI,34*2 + 5*160-162
  52. ;                MOV     CX,IMAGEDATA_LENGTH
  53. ;                CALL    UNCRUNCH
  54. ;
  55. ;The data segment (DS register) is assumed to point at the segment ImageData
  56. ;resides in.   The ES:DI register pair points at position (34,5) on the color
  57. ;graphics adapter screen, calculated as an offset from the start of the screen.
  58. ;Monochrome card users, replace the 0B800h with 0B000h.
  59. ;
  60. ;UnCrunch remembers the original horizontal (X) starting position when it
  61. ;goes down to the next line.  This permits a block to be displayed correctly
  62. ;anywhere on the screen.   ie:
  63. ;
  64. ;  +-------------------------------------------------+
  65. ;  |                                                 |
  66. ;  |                                                 | <- Assume this
  67. ;  |                                                 |    is the video
  68. ;  |           ┌─────────────────────┐               |    display.
  69. ;  |           │█████████████████████│               |
  70. ;  |           │█████████████████████│               |
  71. ;  |           │██ ImageData block ██│               |
  72. ;  |           │█████████████████████│               |
  73. ;  |           │█████████████████████│               |
  74. ;  |           │█████████████████████│               |
  75. ;  |           └─────────────────────┘               |
  76. ;  |                                                 |
  77. ;  |                                                 |
  78. ;  |                                                 |
  79. ;  +-------------------------------------------------+
  80. ;
  81. ;
  82. ;The ImageData block could just as easily been displayed in the upper-left
  83. ;corner of the screen with:
  84. ;                MOV     SI,offset IMAGEDATA
  85. ;                MOV     AX,0B800H
  86. ;                MOV     ES,AX
  87. ;                MOV     DI,1*2 + 1*160-162
  88. ;                MOV     CX,IMAGEDATA_LENGTH
  89. ;                CALL    UNCRUNCH
  90. ;
  91. ;Notice the offset address changed to the coordinates (1,1).  To display
  92. ;the block in the lower-right corner you would change the DI assignment to:
  93. ;
  94. ;                MOV     DI,40*2 + 15*160-162
  95. ;
  96. ;The block is 40 characters wide by 10 lines deep.  Therefore to display
  97. ;such a large block, we must display the block at coordinates (40,15);
  98. ;
  99. ;
  100. ;Obviously the documentation here attempts to describe the procedure by use
  101. ;of examples.  This was felt to be the clearest way of explaining it.  The
  102. ;routine was designed to make using it easy; however, for some people the
  103. ;best way to learn it is to experiment.  Try creating a program using the
  104. ;above example information.  Use TheDraw to make a 40 by 10 block (or any
  105. ;size) to experiment with.  Good luck.
  106. ;
  107.  
  108.  
  109. UNCRUNCH PROC NEAR
  110. ;
  111. ;Parameters Required:
  112. ;  DS:SI  Crunched image source pointer.
  113. ;  ES:DI  Display address pointer.
  114. ;  CX     Length of ImageData source data.
  115. ;
  116.        PUSH    SI                      ;Save registers.
  117.        PUSH    DI
  118.        PUSH    AX
  119.        PUSH    CX
  120.        PUSH    DX
  121.  
  122.        MOV     DX,DI                   ;Save X coordinate for later.
  123.        XOR     AX,AX                   ;Set Current attributes.
  124.        CLD
  125.  
  126. LOOPA: LODSB                           ;Get next character.
  127.        CMP     AL,27                   ;Does user want to toggle the blink
  128.        JNZ     ForeGround              ;attibute?
  129.        XOR     AH,128                  ;Done.
  130.        JMP     Short Next
  131.  
  132. ForeGround:
  133.        CMP     AL,16                   ;If less than 16, then change the
  134.        JNC     BackGround              ;foreground color.  Otherwise jump.
  135.        AND     AH,70H                  ;Strip off old foreground.
  136.        OR      AH,AL
  137.        JMP     Short Next
  138.  
  139. BackGround:
  140.        CMP     AL,24                   ;If less than 24, then change the
  141.        JZ      NextLine                ;background color.  If exactly 24,
  142.        JNC     MultiOutput             ;then jump down to next line.
  143.        SUB     AL,16                   ;Otherwise jump to multiple output
  144.        ADD     AL,AL                   ;routines.
  145.        ADD     AL,AL
  146.        ADD     AL,AL
  147.        ADD     AL,AL
  148.        AND     AH,8FH                  ;Strip off old background.
  149.        OR      AH,AL
  150.        JMP     Short Next
  151.  
  152. NextLine:
  153.        ADD     DX,160                  ;If equal to 24,
  154.        MOV     DI,DX                   ;then jump down to
  155.        JMP     Short Next              ;the next line.
  156.  
  157. MultiOutput:
  158.        CMP     AL,25                   ;If equal to 25,
  159.        JNZ     NotMultiSpaces          ;then use the
  160.        LODSB                           ;following code as
  161.        PUSH    CX                      ;a count and output
  162.        XOR     CH,CH                   ;said number of
  163.        MOV     CL,AL                   ;spaces.
  164.        MOV     AL,32
  165.        JMP     Short StartOutput       ;Use below loop.
  166.  
  167. NotMultiSpaces:
  168.        CMP     AL,26                   ;If equal to 26, then using
  169.        JNZ     NormalLetter            ;the following two codes, display
  170.        LODSB                           ;<x> number of <y> characters.
  171.        DEC     CX                      ;Adjust main counter.
  172.        PUSH    CX                      ;Display as many of
  173.        XOR     CH,CH                   ;whatever the user
  174.        MOV     CL,AL                   ;wants.
  175.        LODSB                           ;Get character.
  176.  
  177. StartOutput:
  178.        JCXZ    Stop                    ;Abort if already at zilch.
  179. LOOPB: STOSW
  180.        LOOP    LOOPB
  181. Stop:  POP     CX
  182.        DEC     CX                      ;Adjust main counter.
  183.  
  184. NormalLetter:
  185.        STOSW                           ;Save screen letter.
  186.  
  187. Next:  JCXZ    Done                    ;Get next, unless CX
  188.        LOOP    LOOPA                   ;has already gone to zero.
  189.  
  190. Done:  POP     DX                      ;Restore registers.
  191.        POP     CX
  192.        POP     AX
  193.        POP     DI
  194.        POP     SI
  195.        RET
  196.  
  197. UNCRUNCH ENDP