home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 123.img / TASM.ZIP / UNCRUNCH.ASM < prev    next >
Assembly Source File  |  1987-10-20  |  8KB  |  188 lines

  1. ;This is the flash display routine used to display crunched TheDraw image
  2. ;files.  It uses a custom protocol for reproducing a 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 routine you call the procedure with the ImageData pointed to
  23. ;by the DS:SI register pair and the display address pointed to by the ES:DI
  24. ;register pair.  The length of the ImageData must be in the CX register.
  25. ;All used registers are stored on the stack and restored after use.
  26. ;
  27. ;Assume we have a ImageData file of a 40 character by 10 line block.  Also
  28. ;the following defintions.  ie:
  29. ;
  30. ;
  31. ;     ;TheDraw Crunched Asm...etc...Length=467
  32. ;     ImageData  DB      ...list of image bytes here...
  33. ;
  34. ;                MOV     SI,offset ImageData
  35. ;                MOV     AX,0B800H
  36. ;                MOV     ES,AX
  37. ;                MOV     DI,34*2 + 5*160-162
  38. ;                MOV     CX,467
  39. ;                CALL    UNCRUNCH
  40. ;
  41. ;It is assumed DS points to the segment ImageData resides in.  The above
  42. ;Sets up the ES:DI pair to point to position (34,5) on a color graphics
  43. ;screen (monochrome users, replace the 0B800H with 0B000H), calculated
  44. ;as an offset from the start of the screen.
  45. ;
  46. ;The value of 467 used is the length of the array as indicated by the title
  47. ;block provided by TheDraw.
  48. ;
  49. ;UnCrunch remembers the horizontal (X) starting position when it goes down
  50. ;to the next line.  This allows you to display the ImageData block correctly
  51. ;at any position on the screen.   ie:
  52. ;
  53. ;  +-------------------------------------------------+
  54. ;  |                                                 |
  55. ;  |                                                 | <- Pretend this
  56. ;  |                                                 |    is the video
  57. ;  |           ┌─────────────────────┐               |    display.
  58. ;  |           │█████████████████████│               |
  59. ;  |           │█████████████████████│               |
  60. ;  |           │██ ImageData block ██│               |
  61. ;  |           │█████████████████████│               |
  62. ;  |           │█████████████████████│               |
  63. ;  |           │█████████████████████│               |
  64. ;  |           └─────────────────────┘               |
  65. ;  |                                                 |
  66. ;  |                                                 |
  67. ;  |                                                 |
  68. ;  +-------------------------------------------------+
  69. ;
  70. ;
  71. ;The ImageData block could just as well have been display in the upper-left
  72. ;corner of the screen with:
  73. ;                MOV     SI,offset ImageData
  74. ;                MOV     AX,0B800H
  75. ;                MOV     ES,AX
  76. ;                MOV     DI,1*2 + 1*160-162
  77. ;                MOV     CX,467
  78. ;                CALL    UNCRUNCH
  79. ;
  80. ;Notice the offset address changed to the coordinates (1,1).
  81. ;
  82. ;To display the block in the lower-right corner you would change the MOV DI,
  83. ;statement to:
  84. ;                MOV     DI,40*2 + 15*160-162
  85. ;
  86. ;The block is 40 characters wide by 10 lines deep.  Therefore to display
  87. ;such a large block, we must display the block at coordinate (40,15);
  88. ;
  89. ;
  90. ;Obviously I have been attempting to describe this procedure by use of
  91. ;examples.  This was done because I felt it to be the easiest and clearest
  92. ;way explaining the procedure.  It was designed to be as simple as possible,
  93. ;however for some people the best way to learn it is to experiment.  Try
  94. ;creating a program using the above example information.  Use TheDraw to
  95. ;make a 40 by 10 block (or any size) to experiment with.  Good luck.  If
  96. ;you can devise a better way of explaining this, please share your labors
  97. ;with me.   Others will surely benifit.   Thanks!
  98. ;
  99.  
  100.  
  101. UNCRUNCH PROC NEAR
  102. ;
  103. ;Parameters Required:
  104. ;  DS:SI  ImageData source pointer.
  105. ;  ES:DI  Display address pointer.
  106. ;  CX     Length of ImageData source data.
  107. ;
  108.        PUSH    SI                      ;Save registers.
  109.        PUSH    DI
  110.        PUSH    AX
  111.        PUSH    CX
  112.        PUSH    DX
  113.  
  114.        MOV     DX,DI                   ;Save X coordinate for later.
  115.        XOR     AX,AX                   ;Set Current attributes.
  116.  
  117. LOOPA: LODSB                           ;Get next character.
  118.        CMP     AL,27                   ;Does user want to toggle the blink
  119.        JNZ     ForeGround              ;attibute?
  120.        XOR     AH,128                  ;Done.
  121.        JMP     Short Next
  122.  
  123. ForeGround:
  124.        CMP     AL,16                   ;If less than 16, then change the
  125.        JNC     BackGround              ;foreground color.  Otherwise jump.
  126.        AND     AH,70H                  ;Strip off old foreground.
  127.        OR      AH,AL
  128.        JMP     Short Next
  129.  
  130. BackGround:
  131.        CMP     AL,24                   ;If less than 24, then change the
  132.        JZ      NextLine                ;background color.  If exactly 24,
  133.        JNC     MultiOutput             ;then jump down to next line.
  134.        SUB     AL,16                   ;Otherwise jump to multiple output
  135.        ADD     AL,AL                   ;routines.
  136.        ADD     AL,AL
  137.        ADD     AL,AL
  138.        ADD     AL,AL
  139.        AND     AH,7FH                  ;Strip off old background.
  140.        OR      AH,AL
  141.        JMP     Short Next
  142.  
  143. NextLine:
  144.        ADD     DX,160                  ;If equal to 24,
  145.        MOV     DI,DX                   ;then jump down to
  146.        JMP     Short Next              ;the next line.
  147.  
  148. MultiOutput:
  149.        CMP     AL,25                   ;If equal to 25,
  150.        JNZ     NotMultiSpaces          ;then using the
  151.        LODSB                           ;following code as
  152.        PUSH    CX                      ;a count, output
  153.        XOR     CH,CH                   ;said number of
  154.        MOV     CL,AL                   ;spaces.
  155.        MOV     AL,32
  156.        JMP     StartOutput             ;Use below loop.
  157.  
  158. NotMultiSpaces:
  159.        CMP     AL,26                   ;If equal to 26, then using
  160.        JNZ     NormalLetter            ;the following two codes, display
  161.        LODSB                           ;<x> number of <y> characters.
  162.        DEC     CX                      ;Adjust main counter.
  163.        PUSH    CX                      ;Display as many of
  164.        XOR     CH,CH                   ;whatever the user
  165.        MOV     CL,AL                   ;wants.
  166.        LODSB                           ;Get character.
  167.  
  168. StartOutput:
  169.        JCXZ    Stop                    ;Abort if already at zilch.
  170. LOOPB: STOSW
  171.        LOOP    LOOPB
  172. Stop:  POP     CX
  173.        DEC     CX                      ;Adjust main counter.
  174.  
  175. NormalLetter:
  176.        STOSW                           ;Save screen letter.
  177.  
  178. Next:  JCXZ    Done                    ;Get next, unless CX
  179.        LOOP    LOOPA                   ;has already one to zero.
  180.  
  181. Done:  POP     DX                      ;Restore registers.
  182.        POP     CX
  183.        POP     AX
  184.        POP     DI
  185.        POP     SI
  186.        RET
  187.  
  188. UNCRUNCH ENDP