home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / open / tdraw320.lzh / UNCRUNCH.ASM < prev    next >
Assembly Source File  |  1989-04-04  |  8KB  |  191 lines

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