1 ;-----------------------------------------------------------------------
\r
4 ; This module contains only the compiler and sizeof routines --
\r
5 ; use the plotter from XCBITMAP.
\r
7 ;-----------------------------------------------------------------------
\r
10 include xcomppbm.inc
\r
12 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
\r
15 ; I only changed five instructions, instead of rewriting this
\r
16 ; for PBMs. So it is amazingly inefficient. But, what the hell,
\r
17 ; It's only a game :).
\r
20 ; accessory macros to save typing (what else?)
\r
22 mov byte ptr es:[di],&arg&
\r
27 mov word ptr es:[di],&arg&
\r
31 ; opcodes emitted by _x_compile_pbm
\r
32 ROL_AL equ 0c0d0h ; rol al
\r
33 SHORT_STORE_8 equ 044c6h ; mov [si]+disp8, imm8
\r
34 STORE_8 equ 084c6h ; mov [si]+disp16, imm8
\r
35 SHORT_STORE_16 equ 044c7h ; mov [si]+disp8, imm16
\r
36 STORE_16 equ 084c7h ; mov [si]+disp16, imm16
\r
37 ADC_SI_IMMED equ 0d683h ; adc si,imm8
\r
38 OUT_AL equ 0eeh ; out dx,al
\r
39 RETURN equ 0cbh ; ret
\r
45 ColumnMask db 011h,022h,044h,088h
\r
52 ARG logical_width:word,bitmap:dword,output:dword
\r
53 LOCAL bwidth,scanx,scany,outputx,outputy,column,set_column,input_size:word=LocalStk
\r
55 mov bp, sp ; caller's stack frame
\r
56 sub sp,LocalStk ; local space
\r
61 mov word ptr [scanx],0
\r
62 mov word ptr [scany],0
\r
63 mov word ptr [outputx],0
\r
64 mov word ptr [outputy],0
\r
65 mov word ptr [column],0
\r
66 mov word ptr [set_column],0
\r
68 lds si,[bitmap] ; 32-bit pointer to source bitmap
\r
70 les di,[output] ; 32-bit pointer to destination stream
\r
72 lodsb ; load width byte
\r
73 xor ah, ah ; convert to word
\r
74 mov [bwidth], ax ; save for future reference
\r
75 mov bl, al ; copy width byte to bl
\r
76 lodsb ; load height byte -- already a word since ah=0
\r
77 mul bl ; mult height word by width byte
\r
78 mov [input_size], ax; to get pixel total
\r
81 mov bx, [scanx] ; position in original bitmap
\r
84 mov al, [si+bx] ; get pixel
\r
85 or al, al ; skip empty pixels
\r
90 mov dx, [set_column]
\r
94 Emitw ROL_AL ; emit code to move to new column
\r
102 Emitb OUT_AL ; emit code to set VGA mask for new column
\r
103 mov [set_column], dx
\r
105 mov dx, [outputy] ; calculate output position
\r
109 inc word ptr [scanx]
\r
110 mov cx, [scanx] ; within four pixels of right edge?
\r
114 inc word ptr [outputx]
\r
115 mov ah, [si+bx+1] ; get second pixel
\r
119 cmp dx, 127 ; can we use shorter form?
\r
123 Emitw SHORT_STORE_8
\r
124 Emitb dl ; 8-bit position in output
\r
128 Emitw dx ; position in output
\r
131 jmp short @@Advance
\r
137 Emitw SHORT_STORE_16
\r
138 Emitb dl ; 8-bit position in output
\r
139 jmp @@EmitTwoPixels
\r
142 Emitw dx ; position in output
\r
147 inc word ptr [outputx]
\r
153 add dx, [logical_width]
\r
156 cmp cx, [input_size]
\r
158 inc word ptr [column]
\r
161 je @@Exit ; Column 4: there is no column 4.
\r
162 xor cx, cx ; scany and outputy are 0 again for
\r
163 mov dx, cx ; the new column
\r
164 add si, [input_size]
\r
169 mov word ptr [outputx], 0
\r
177 sub ax,word ptr [output] ; size of generated code
\r
186 _x_compile_pbm endp
\r
189 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
\r
195 _x_sizeof_cpbm proc
\r
196 ARG logical_width:word,bitmap:dword
\r
197 LOCAL bwidth,scanx,scany,outputx,outputy,column,set_column,input_size:word=LocalStk
\r
199 mov bp, sp ; caller's stack frame
\r
200 sub sp,LocalStk ; local space
\r
205 mov word ptr [scanx], 0
\r
206 mov word ptr [scany], 0
\r
207 mov word ptr [outputx], 0
\r
208 mov word ptr [outputy], 0
\r
209 mov word ptr [column], 0
\r
210 mov word ptr [set_column], 0
\r
212 lds si,[bitmap] ; 32-bit pointer to source bitmap
\r
214 mov di, 1 ; initial size is just the size of the far RET
\r
216 lodsb ; load width byte
\r
217 xor ah, ah ; convert to word
\r
218 mov [bwidth], ax ; save for future reference
\r
219 mov bl, al ; copy width byte to bl
\r
220 lodsb ; load height byte -- already a word since ah=0
\r
221 mul bl ; mult height word by width byte
\r
222 mov [input_size], ax; to get pixel total
\r
225 mov bx, [scanx] ; position in original bitmap
\r
228 mov al, [si+bx] ; get pixel
\r
229 or al, al ; skip empty pixels
\r
234 mov dx, [set_column]
\r
238 add di, 5 ; size of code to move to new column
\r
243 inc di ; size of code to set VGA mask
\r
244 mov [set_column], dx
\r
246 mov dx, [outputy] ; calculate output position
\r
250 inc word ptr [scanx]
\r
251 mov cx, [scanx] ; within four pixels of right edge?
\r
255 inc word ptr [outputx]
\r
256 mov ah,[si+bx+1] ; get second pixel
\r
260 cmp dx, 127 ; can we use shorter form?
\r
264 add di, 4 ; size of 8-bit position in output plus one pixel
\r
267 add di, 5 ; size of position in output plus one pixels
\r
269 jmp short @@Advance
\r
275 add di, 5 ; size of 8-bit position in output plus two pixels
\r
276 jmp @@EmitTwoPixels
\r
278 add di, 6 ; size of 16-bit position in output plus two pixels
\r
282 inc word ptr [outputx]
\r
288 add dx, [logical_width]
\r
291 cmp cx, [input_size]
\r
293 inc word ptr [column]
\r
296 je @@Exit ; Column 4: there is no column 4.
\r
297 xor cx,cx ; scany and outputy are 0 again for
\r
298 mov dx,cx ; the new column
\r
299 add si, [input_size]
\r
304 mov word ptr [outputx], ax
\r
310 mov ax, di ; size of generated code
\r
319 _x_sizeof_cpbm endp
\r