home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / DIVERSEN / PCXK53 / VGA.ASM < prev    next >
Assembly Source File  |  1994-11-16  |  9KB  |  244 lines

  1. ; ------------------------------------
  2. ; Module for PCX.PAS and PCX.CPP
  3. ; Copyright (c) 1994 by Peter Donnelly
  4. ; ------------------------------------
  5.  
  6. ; To compile for Pascal, put "/dpascal" on the TASM command line. 
  7.  
  8. ; To compile for C++, change the .MODEL definition to match your program's 
  9. ; memory model. Then run TASM with the "/mx" switch on the command line.
  10.  
  11. IFDEF PASCAL
  12. .MODEL TPASCAL
  13. ELSE
  14. .MODEL LARGE, C                    ; can be COMPACT, LARGE, or HUGE
  15. ENDIF
  16.  
  17. .DATA 
  18.         extrn DataLength: word
  19.         extrn Scratch: dword
  20.         extrn Plane: word
  21.         extrn VideoOffs: word
  22.         extrn VideoSeg: word
  23.         extrn Margin: word
  24.         extrn ScreenWidth: word
  25.         extrn LineEnd: word
  26.         extrn RepeatCount: byte
  27.         extrn ColumnCount: word
  28.     extrn BytesPerLine: word
  29. .CODE 
  30.     PUBLIC  Decode16
  31.     PUBLIC  Decode256
  32.         LOCALS
  33.  
  34. ; ----------------------------- 16-COLOR FILES ---------------------------      
  35.  
  36. Decode16 PROC
  37.  
  38. ; Main use of registers:
  39.  
  40. ;   AL   data byte to be written to video
  41. ;   AH   data bytes per scan line
  42. ;   BX   end of input buffer
  43. ;   CL   number of times data byte is to be written
  44. ;   DL   current column in scan line
  45. ;   ES   output segment
  46. ;   DI   index into output buffer
  47. ;   SI   index into input buffer
  48. ;   BP   current color plane
  49.  
  50. push    si                        ; save C register variables
  51. push    di                        ; ditto
  52. push    bp
  53.  
  54. ; The first section is initialization done on each run through the
  55. ;  input buffer.
  56.  
  57. @@startproc:
  58. mov     bp, Plane                 ; plane in BP
  59. mov     di, VideoOffs             ; index into video segment
  60. mov     ah, byte ptr BytesPerLine ; line length in AH
  61. mov     dx, ColumnCount           ; column counter
  62. mov     bx, DataLength            ; no. of bytes to read
  63. xor     cx, cx                    ; clean up CX for loop counter
  64. mov     cl, RepeatCount           ; count in CX
  65. les     si, Scratch               ; index into input buffer in SI
  66.   ; ES  not significant here - we don't use LDS because we want to
  67.   ; preserve DS
  68.   ; We have to adjust datalength for comparison with SI. Pascal pointers
  69.   ; are normalized, but the offset can still be 0 or 8.
  70. mov     es, VideoSeg              ; video display segment
  71. add     bx, si
  72. cld                               ; clear DF for stosb
  73. cmp     cl, 0                     ; was last byte a count?
  74. jne     @@multi_data              ; yes, so next is data
  75. jmp short @@getbyte               ; no, so find out what next is
  76.  
  77. ; The data in the .PCX file is organized by color plane, by line; that is,
  78. ; all the data for plane 0 for line 1, then for plane 1, line 1, etc.
  79. ; Writing the data to display memory is just a matter of masking out the
  80. ; other planes while one plane is being written to. This is done with the
  81. ; map mask register in the sequencer. All the other weird and wonderful
  82. ; registers in the EGA/VGA do just fine with their default settings, thank
  83. ; goodness.
  84.  
  85. @@writebyte:
  86. stosb                             ; AL into ES:DI, inc DI
  87. inc     dl                        ; increment column
  88. cmp     dl, ah                    ; reached end of scanline?
  89. je      @@doneline                ; yes
  90. loop    @@writebyte               ; no, do another
  91. jmp short @@getbyte               ;   or get more data
  92. @@doneline:
  93. shl     bp, 1                     ; shift to next plane
  94. cmp     bp, 8                     ; done 4 planes?
  95. jle     @@setindex                ; no
  96. mov     bp, 1                     ; yes, reset plane to 1
  97. add     di, Margin                ; skip to start of next scanline
  98. mov     dx, ScreenWidth
  99. add     LineEnd, dx
  100. jmp short @@setplane
  101. @@setindex:
  102. sub     di, dx                    ; reset index to start of same line
  103. @@setplane:
  104. push    ax                        ; save AX
  105. cli                               ; no interrupts
  106. mov     ax, bp                    ; plane is 1, 2, 4, or 8
  107. mov     dx, 3C5h                  ; sequencer data register
  108. out     dx, al                    ; mask out 3 planes
  109. sti                               ; enable interrupts
  110. pop     ax                        ; restore AX
  111. xor     dx, dx                    ; reset column count
  112. loop    @@writebyte               ; do it again, or fetch more data
  113.  
  114. ; --- Loop through input buffer
  115.  
  116. ; Here's how the data compression system works. Each byte is either image
  117. ; data or a count byte that tells how often the next byte is to be
  118. ; repeated. The byte is image data if it follows a count byte, or if
  119. ; either of the top 2 bits is clear. Otherwise it is a count byte, with
  120. ; the count derived from the lower 6 bits.
  121.  
  122. @@getbyte:                        ; last byte was not a count
  123. cmp     si, bx                    ; end of input buffer?
  124. je      @@exit                    ; yes, quit
  125. push    ds                        ; save program data
  126. push    si
  127. lds     si, Scratch               ; input segment into DS
  128. pop     si
  129. lodsb                             ; get a byte from DS:SI into AL, increment SI
  130. pop     ds                        ; restore program data
  131. cmp     al, 192                   ; test high bits
  132. jb      @@one_data                ; not set, it's data to be written once
  133.  ; It's a count byte:
  134. xor     al, 192                   ; get count from 6 low bits
  135. mov     cl, al                    ; store repeat count
  136. cmp     si, bx                    ; end of input buffer?
  137. je      @@exit                    ; yes, quit
  138. @@multi_data:
  139. push    ds                        ; save program data
  140. push    si
  141. lds     si, Scratch               ; segment of input buffer into DS
  142. pop     si
  143. lodsb                             ; get a byte from DS:SI into AL, increment SI
  144. pop     ds                        ; restore program data
  145. jmp     @@writebyte               ; write it CL times
  146. @@one_data:
  147. mov     cl, 1                     ; write byte once
  148. jmp     @@writebyte
  149.  
  150. ; --- Finished with buffer ---
  151.  
  152. @@exit:
  153. mov     Plane, bp                 ; save status for next run thru buffer
  154. mov     RepeatCount, cl
  155. mov     ColumnCount, dx
  156. mov     VideoOffs, di
  157. pop     bp
  158. pop     di                        ; restore any C register variables
  159. pop     si
  160. ret
  161.  
  162. Decode16 ENDP
  163.  
  164. ; ------------------------- 256-COLOR VGA FILES ---------------------------
  165.  
  166. Decode256 PROC
  167.  
  168. ; Main use of registers:
  169.  
  170. ;  AL   data byte to be written to video
  171. ;  BX   end of input buffer
  172. ;  CL   number of times data byte is to be written
  173. ;  DX   temporary storage of EndOfLine
  174. ;  ES   segment of output buffer
  175. ;  DI   index into output buffer
  176. ;  SI   index into input buffer
  177.  
  178. push    si                        ; save C register variables
  179. push    di                        ; ditto
  180. push    bp
  181.  
  182. les     si, Scratch               ; index into input buffer in SI
  183.   ; ES  not used here - we don't use LDS because we want to preserve DS
  184. mov     bx, DataLength            ; end of input buffer
  185. add     bx, si                    ; adjust datalength - SI may not be 0
  186. mov     es, VideoSeg              ; base address of output window
  187. mov     di, VideoOffs             ; index into window
  188. xor     cx, cx                    ; clean up loop counter 
  189. mov     cl, RepeatCount           ; restore count from last byte 
  190. cld                               ; clear DF 
  191. cmp     cl, 0                     ; was last byte a count?
  192. jne     @@multi_data              ; yes, so next is data 
  193.  
  194. ; --- Loop through input buffer --- 
  195.  
  196. @@getbyte:                        ; last byte was not a count 
  197. cmp     di, LineEnd               ; reached end of line? 
  198. jb      @@NoLineEnd               ; no 
  199. add     di, Margin
  200. mov     dx, ScreenWidth
  201. add     LineEnd, dx
  202. @@NoLineEnd:
  203. cmp     si, bx                    ; end of input buffer? 
  204. je      @@exit                    ; yes, quit
  205. push    ds                        ; save Pascal's data segment 
  206. push    si                        ; Get segment of input buffer into DS
  207. lds     si, Scratch               ;   while preserving SI 
  208. pop     si
  209. lodsb                             ; get byte from DS:SI into AL, increment SI 
  210. pop     ds                        ; restore program data 
  211. cmp     al, 192                   ; test high bits 
  212. jb      @@one_data                ; not set, not a count 
  213. ; It's a count byte 
  214. xor     al, 192                   ; get count from 6 low bits 
  215. mov     cl, al                    ; store repeat count 
  216. cmp     si, bx                    ; end of input buffer? 
  217. je      @@exit                    ; yes, quit
  218. @@multi_data:
  219. push    ds                        ; save program data
  220. push    si
  221. lds     si, Scratch
  222. pop     si
  223. lodsb                             ; get byte from DS:SI into AL, increment SI 
  224. pop     ds                        ; restore program data 
  225. rep     stosb                     ; write byte CX times
  226. jmp     @@getbyte
  227. @@one_data:
  228. stosb                             ; byte into video 
  229. jmp     @@getbyte
  230.  
  231. ; --- Finished with buffer 
  232. @@exit:
  233. mov     VideoOffs, di             ; save status for next run thru buffer 
  234. mov     RepeatCount, cl
  235. pop     bp
  236. pop     di                        ; restore any C register variables
  237. pop     si
  238. ret
  239.  
  240. Decode256 ENDP
  241.  
  242. END
  243.  
  244.