/[projet1]/public/oric/routines/rasterization/linebench/buffer.s
Defence Force logotype

Contents of /public/oric/routines/rasterization/linebench/buffer.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 224 - (show annotations)
Tue Feb 2 20:17:28 2010 UTC (10 years, 3 months ago) by dbug
File size: 5370 byte(s)
Moved the rasterization effects to a new public folder
1
2
3 .zero
4
5 ; *= tmp1
6
7 e .dsb 2 ; Error decision factor (slope) 2 bytes in zero page
8 i .dsb 1 ; Number of pixels to draw (iteration counter) 1 byte in zp
9 dx .dsb 1 ; Width
10 dy .dsb 1 ; Height
11 _CurrentPixelX .dsb 1
12 _CurrentPixelY .dsb 1
13 _OtherPixelX .dsb 1
14 _OtherPixelY .dsb 1
15
16 .text
17
18 .dsb 256-(*&255)
19
20
21 ;
22 ; This code is used when the things are moving faster
23 ; horizontally than vertically
24 ;
25 ; dx<dy
26 ;
27 draw_nearly_horizontal
28 .(
29 ; here we have DY in Y, and the OPCODE in A
30 sta _outer_patch ; Write a (dex / nop / inx) instruction
31
32 ;
33 ; Initialize counter to dx+1
34 ;
35 ldx dx
36 inx
37 stx i
38
39 ; Initialise e=dy*2-dx
40 lda dy
41 asl
42 sta _path_e_dy_0+1 ; dy
43 sta e
44 lda #0
45 rol
46 sta _path_e_dy_1+1 ; dy+1
47 sta 1+e
48
49 sec
50 lda e
51 sbc dx
52 sta e
53 lda 1+e
54 sbc #0
55 sta 1+e
56
57 ; Compute dx*2
58 lda dx
59 asl
60 sta _path_e_dx_0+1 ;dx
61 lda #0
62 rol
63 sta _path_e_dx_1+1 ;dx+1
64
65 ;
66 ; Draw loop
67 ;
68 ldx _CurrentPixelX
69 ldy _TableDiv6,x
70 sec
71 outer_loop
72 lda _TableBit6Reverse,x ; 4
73 eor (tmp0),y ; 5
74 sta (tmp0),y ; 6
75
76 lda 1+e
77 bmi end_inner_loop
78
79 ; e=e-2*dx
80 ;sec
81 lda e
82 _path_e_dx_0
83 sbc #0
84 sta e
85 lda 1+e
86 _path_e_dx_1
87 sbc #0
88 sta 1+e
89
90 ; Update screen adress
91 ;clc ; 2
92 lda tmp0+0 ; 3
93 adc #40 ; 2
94 sta tmp0+0 ; 3
95 bcc skip ; 2 (+1 if taken)
96 inc tmp0+1 ; 5
97 skip
98 ; ------------------Min=13 Max=17
99
100
101 end_inner_loop
102
103 _outer_patch
104 inx
105 ldy _TableDiv6,x
106
107 ; e=e+2*dy
108 clc
109 lda e
110 _path_e_dy_0
111 adc #0
112 sta e
113 lda 1+e
114 _path_e_dy_1
115 adc #0
116 sta 1+e
117
118 dec i
119 bne outer_loop
120 rts
121 .)
122
123
124
125
126 _DrawLine
127 ;jmp _DrawLine
128 ;
129 ; Compute deltas and signs
130 ;
131
132 ; Test Y value
133 .(
134 sec
135 lda _CurrentPixelY
136 sbc _OtherPixelY
137 sta dy
138 beq end
139 bcc cur_smaller
140
141 cur_bigger ; y1>y2
142 ; Swap X and Y
143 ; So we always draw from top to bottom
144 lda _CurrentPixelY
145 ldx _OtherPixelY
146 sta _OtherPixelY
147 stx _CurrentPixelY
148
149 lda _CurrentPixelX
150 ldx _OtherPixelX
151 sta _OtherPixelX
152 stx _CurrentPixelX
153
154 jmp end
155
156 cur_smaller ; y1<y2
157 ; Absolute value
158 eor #$ff
159 adc #1
160 sta dy
161 end
162 .)
163
164 ;
165 ; Initialise screen pointer
166 ;
167 ldy _CurrentPixelY
168 lda _HiresAddrLow,y ; 4
169 sta tmp0+0 ; 3
170 lda _HiresAddrHigh,y ; 4
171 sta tmp0+1 ; 3 => Total 14 cycles
172
173 ; Test X value
174 .(
175 sec
176 lda _CurrentPixelX
177 sbc _OtherPixelX
178 sta dx
179 beq draw_totaly_vertical
180 bcc cur_smaller
181
182 cur_bigger ; x1>x2
183 lda #$ca ; 0 DEC
184 bne end
185
186 cur_smaller ; x1<x2
187 ; Absolute value
188 eor #$ff
189 adc #1
190 sta dx
191
192 lda #$e8 ; 2 INC
193 end
194 .)
195
196 ; Compute slope and call the specialized code for mostly horizontal or vertical lines
197 ldy dy
198 beq draw_totaly_horizontal
199 cpy dx
200 bcs draw_nearly_vertical
201 jmp draw_nearly_horizontal
202
203 draw_totaly_horizontal
204 .(
205 ; here we have DY in Y, and the OPCODE in A
206 sta _outer_patch ; Write a (dex / nop / inx) instruction
207
208 ;
209 ; Initialize counter to dx+1
210 ;
211 ldx dx
212 inx
213 stx i
214
215
216 ldx _CurrentPixelX
217
218 ;
219 ; Draw loop
220 ;
221 outer_loop
222 ldy _TableDiv6,x
223 lda _TableBit6Reverse,x ; 4
224 eor (tmp0),y ; 5
225 sta (tmp0),y ; 6
226
227 _outer_patch
228 inx
229
230 dec i
231 bne outer_loop
232 rts
233 .)
234
235 draw_totaly_vertical
236 .(
237 ldx _CurrentPixelX
238 ldy _TableDiv6,x
239 lda _TableBit6Reverse,x ; 4
240 sta _mask_patch+1
241
242 ldx dy
243 inx
244
245 clc ; 2
246 loop
247 _mask_patch
248 lda #0 ; 2
249 eor (tmp0),y ; 5
250 sta (tmp0),y ; 6 => total = 13 cycles
251
252 ; Update screen adress
253 lda tmp0+0 ; 3
254 adc #40 ; 2
255 sta tmp0+0 ; 3
256 bcc skip ; 2 (+1 if taken)
257 inc tmp0+1 ; 5
258 clc ; 2
259 skip
260 ; ------------------Min=13 Max=17
261
262 dex
263 bne loop
264 rts
265 .)
266
267 ;.dsb 256-(*&255)
268
269 ;
270 ; This code is used when the things are moving faster
271 ; vertically than horizontally
272 ;
273 ; dy>dx
274 ;
275 draw_nearly_vertical
276 ;jmp draw_nearly_vertical
277 .(
278 ; here we have DY in Y, and the OPCODE in A
279 sta _inner_patch ; Write a (dex / nop / inx) instruction
280 ; just increment en store to know the number of iterations
281 iny
282 sty i
283
284
285 ; Compute dx*2
286 lda dy
287 asl
288 sta _path_e_dx_0+1 ;dx
289 lda #0
290 rol
291 sta _path_e_dx_1+1 ;dx+1
292
293
294 ; Normaly we should have swapped DX and DY, but instead just swap in the usage is more efficient
295 ; Initialise e
296 lda dx
297 asl
298 sta _path_e_dy_0+1 ; dy
299 sta e
300 lda #0
301 rol
302 sta _path_e_dy_1+1 ; dy+1
303 sta 1+e
304
305 ldx _CurrentPixelX
306 ldy _TableDiv6,x
307
308 sec
309 lda e
310 sbc dy
311 sta e
312 lda 1+e
313 sbc #0
314 sta 1+e
315 bmi end_inner_loop2 ; n=1 ?
316
317 ;
318 ; Draw loop
319 ;
320 outer_loop
321 lda _TableBit6Reverse,x ; 4
322 eor (tmp0),y ; 5
323 sta (tmp0),y ; 6
324 ; --------------------------=15
325
326 _inner_patch
327 inx
328
329 ldy _TableDiv6,x
330
331 ; e=e-2*dx
332 sec
333 lda e
334 _path_e_dx_0
335 sbc #0
336 sta e
337 lda 1+e
338 _path_e_dx_1
339 sbc #0
340 sta 1+e
341
342 end_inner_loop
343
344 dec i
345 beq done
346
347 .(
348 ; Update screen adress
349 ;clc ; 2
350 lda tmp0+0 ; 3
351 adc #40 ; 2
352 sta tmp0+0 ; 3
353 bcc skip ; 2 (+1 if taken)
354 inc tmp0+1 ; 5
355 clc
356 skip
357 ; ------------------Min=13 Max=17
358 .)
359
360 ; e=e+2*dy
361 lda e
362 _path_e_dy_0
363 adc #0
364 sta e
365 lda 1+e
366 _path_e_dy_1
367 adc #0
368 sta 1+e
369 bpl outer_loop
370
371 end_inner_loop2
372 lda _TableBit6Reverse,x ; 4
373 eor (tmp0),y ; 5
374 sta (tmp0),y ; 6
375 ; --------------------------=15
376
377 bne end_inner_loop
378
379 done
380 rts
381 .)
382
383

  ViewVC Help
Powered by ViewVC 1.1.26