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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 253 - (show annotations)
Sat Feb 6 15:41:16 2010 UTC (9 years, 10 months ago) by thrust26
File size: 6688 byte(s)
simple optimizations, 579 now
1 ; History of timings...
2 ;649
3 ;614 (replacing the update of tmp0)
4 ;607
5 ;588
6 ;583 after alignment
7 ;579
8
9 .zero
10
11 ; *= tmp1
12
13 ;e .dsb 2 ; Error decision factor (slope) 2 bytes in zero page
14 ;i .dsb 1 ; Number of pixels to draw (iteration counter) 1 byte in zp
15 ;dx .dsb 1 ; Width
16 ;dy .dsb 1 ; Height
17 ;_CurrentPixelX .dsb 1
18 ;_CurrentPixelY .dsb 1
19 ;_OtherPixelX .dsb 1
20 ;_OtherPixelY .dsb 1
21
22 save_a .dsb 1
23 save_y .dsb 1
24
25 .text
26
27 .dsb 256-(*&255)
28
29 ; nop $ea
30 ; inx $e8 11101000
31 ; dex $ca 11001010
32 ; iny $c8 11001000
33 ; dey $88 10001000
34
35
36
37 draw_totaly_vertical_8
38 .(
39 ldx _CurrentPixelX
40 ldy _TableDiv6,x
41 lda _TableBit6Reverse,x ; 4
42 sta _mask_patch+1
43
44 ldx dy
45 inx
46
47 clc ; 2
48 loop
49 _mask_patch
50 lda #0 ; 2
51 eor (tmp0),y ; 5
52 sta (tmp0),y ; 6 => total = 13 cycles
53
54 ; Update screen adress
55 .(
56 lda tmp0+0 ; 3
57 adc #40 ; 2
58 sta tmp0+0 ; 3
59 bcc skip ; 2 (+1 if taken)
60 inc tmp0+1 ; 5
61 clc ; 2
62 skip
63 .)
64 ; ------------------Min=13 Max=17
65
66 dex
67 bne loop
68 rts
69 .)
70
71
72
73 ;
74 ; Expects the following variables to be set when called:
75 ; _CurrentPixelX
76 ; _CurrentPixelY
77 ; _OtherPixelX
78 ; _OtherPixelY
79 ;
80 _DrawLine8
81 ;
82 ; Compute deltas and signs
83 ;
84
85 ; Test Y value
86 .(
87 sec
88 lda _CurrentPixelY
89 sbc _OtherPixelY
90 beq end
91 bcc cur_smaller
92
93 cur_bigger ; y1>y2
94 ; Swap X and Y
95 ; So we always draw from top to bottom
96 ldy _CurrentPixelY
97 ldx _OtherPixelY
98 sty _OtherPixelY
99 stx _CurrentPixelY
100
101 ldy _CurrentPixelX
102 ldx _OtherPixelX
103 sty _OtherPixelX
104 stx _CurrentPixelX
105
106 jmp end
107
108 cur_smaller ; y1<y2
109 ; Absolute value
110 eor #$ff
111 adc #1
112 end
113 sta dy
114 .)
115
116 ;
117 ; Initialise screen pointer
118 ;
119 ldy _CurrentPixelY
120 lda _HiresAddrLow,y ; 4
121 sta tmp0+0 ; 3
122 lda _HiresAddrHigh,y ; 4
123 sta tmp0+1 ; 3 => Total 14 cycles
124
125 ; Test X value
126 .(
127 sec
128 lda _CurrentPixelX
129 sbc _OtherPixelX
130 sta dx
131 beq draw_totaly_vertical_8
132 bcc cur_smaller
133
134 cur_bigger ; x1>x2
135 lda #$ca ; dex
136 bne end
137
138 cur_smaller ; x1<x2
139 ; Absolute value
140 eor #$ff
141 adc #1
142 sta dx
143
144 lda #$e8 ; inx
145 end
146 .)
147
148 jmp alignIt
149
150 .dsb 256-(*&255)
151
152 alignIt
153 ; Compute slope and call the specialized code for mostly horizontal or vertical lines
154 ldy dy
155 beq draw_totaly_horizontal_8
156 cpy dx
157 bcs draw_nearly_vertical_8
158
159 draw_nearly_horizontal_8
160 .(
161 ; here we have DY in Y, and the OPCODE in A
162 sta __auto_stepx ; Write a (dex / nop / inx) instruction
163 cmp #$ca ; dex?
164 bne skipDex
165 dey ; adjust for carry being set in loop
166 skipDex
167 sty __auto_ady+1
168
169 lda dx
170 sta __auto_dx+1
171
172 lda _OtherPixelX
173 sta __auto_cpx+1
174
175 ldx _CurrentPixelX ;Plotting coordinates
176 ldy _CurrentPixelY ;in X and Y
177
178 lda dy
179 lsr
180 eor #$ff
181 ; clc
182
183 loopX
184 sta save_a ; 3 = 3
185 loopY
186 ; Draw the pixel
187 __auto_div6
188 ldy _TableDiv6,x ; 4
189 __auto_bit6
190 lda _TableBit6Reverse,x ; 4
191 eor (tmp0),y ; 5*
192 sta (tmp0),y ; 6*= 19
193
194 __auto_cpx
195 cpx #00 ; 2 At the endpoint yet?
196 beq exitLoop ; 2/3
197 __auto_stepx
198 inx ; 2 Step in x
199 lda save_a ; 3
200 __auto_ady
201 adc #00 ; 2 +DY
202 bcc loopX ; 2/3=13/14
203 ; Time to step in y
204 __auto_dx
205 sbc #00 ; 2 -DX
206 sta save_a ; 3 = 5
207
208 ; Set the new screen adress
209 lda tmp0+0 ; 3
210 adc #40 ; 2
211 sta tmp0+0 ; 3
212 bcc loopY ; 2/3=10/11 ~84 taken
213 inc tmp0+1 ; 5
214 bcs loopY ; 3 = 8
215 ; average: 12.12
216
217 exitLoop
218 rts
219 ; Timings:
220 ; x++/y : 36
221 ; x++/y++: 49.12
222 ; average: 42.56
223 .)
224
225 draw_totaly_horizontal_8
226 .(
227 ; here we have DY in Y, and the OPCODE in A
228 sta _outer_patch ; Write a (dex / nop / inx) instruction
229
230 ldx _OtherPixelX
231 sta __auto_cpx+1
232
233 ldx _CurrentPixelX
234
235 ;
236 ; Draw loop
237 ;
238 outer_loop
239 ldy _TableDiv6,x
240 lda _TableBit6Reverse,x ; 4
241 eor (tmp0),y ; 5
242 sta (tmp0),y ; 6
243
244 _outer_patch
245 inx
246
247 __auto_cpx
248 cpx #00 ; At the endpoint yet?
249 bne outer_loop
250 rts
251 .)
252
253
254 ;
255 ; This code is used when the things are moving faster
256 ; vertically than horizontally
257 ;
258 ; dy>dx
259 ;
260 draw_nearly_vertical_8
261 .(
262 ; here we have DY in Y, and the OPCODE in A
263 sta __auto_stepx ; Write a (dex / nop / inx) instruction
264 sty __auto_dy+1
265
266 lda dx
267 sta __auto_adx+1
268
269 lda _OtherPixelY
270 sta __auto_cpy+1
271
272 ldx _CurrentPixelX ; Plotting coordinates
273 ldy _CurrentPixelY ; in X and Y
274
275 lda dx
276 lsr
277 eor #$ff ; -DX/2
278 ; clc
279
280 loop
281 ; Draw the pixel
282 sty save_y ; 3
283 ldy _TableDiv6,x ; 4
284 lda _TableBit6Reverse,x ; 4
285 eor (tmp0),y ; 5*
286 sta (tmp0),y ; 6*
287 lda save_a ; 3
288 ldy save_y ; 3 = 28
289
290 __auto_cpy
291 cpy #00 ; 2 At the endpoint yet?
292 beq exitLoop ; 2/3
293
294 iny ; 2 Step in y
295 __auto_adx
296 adc #00 ; 2 +DX
297 bcc skipX ; 2/3=10/11 ~50% taken
298 ; Time to step in x
299 __auto_stepx
300 inx ; 2 Step in x
301 __auto_dy
302 sbc #00 ; 2 = 4 -DY
303 skipX
304 ; Set the new screen adress
305 sta save_a ; 3 = 3
306
307 ; Update screen adress
308 lda tmp0+0 ; 3
309 adc #40 ; 2
310 sta tmp0+0 ; 3
311 bcc loop ; 2/3 ~84% taken
312 inc tmp0+1 ; 5
313 bcs loop ; 3
314 ; = 12.12 average
315
316 ; x ,y++: 54.12
317 ; x++,y++: 57.12
318 ; average: 55.62
319 exitLoop
320 rts
321 .)

  ViewVC Help
Powered by ViewVC 1.1.26