-
Notifications
You must be signed in to change notification settings - Fork 2
/
r_aclip68k.s
558 lines (491 loc) · 11.2 KB
/
r_aclip68k.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
**
** Quake for AMIGA
** r_aclip.c assembler implementations by Frank Wille <[email protected]>
**
INCLUDE "quakedef68k.i"
XREF _r_refdef
XDEF _R_Alias_clip_left
XDEF _R_Alias_clip_right
XDEF _R_Alias_clip_top
XDEF _R_Alias_clip_bottom
XDEF _R_AliasClip
ALIAS_LEFT_CLIP = 1
ALIAS_TOP_CLIP = 2
ALIAS_RIGHT_CLIP = 4
ALIAS_BOTTOM_CLIP = 8
fpu
******************************************************************************
*
* void _R_Alias_clip_left (finalvert_t *pfv0, finalvert_t *pfv1,
* finalvert_t *out)
*
******************************************************************************
cnop 0,4
_R_Alias_clip_left
***** stackframe
rsreset
.fpuregs rs.x 2
.intregs rs.l 5
rs.l 1
.pfv0 rs.l 1
.pfv1 rs.l 1
.out rs.l 1
movem.l d2-d4/a2/a3,-(sp)
fmovem.x fp2/fp3,-(sp)
move.l .pfv0(sp),a0
move.l .pfv1(sp),a1
move.l .out(sp),a2
lea _r_refdef,a3
fmove.s #0.5,fp2
move.l (a0)+,d2
move.l (a0)+,d3
move.l (a1)+,d0
move.l (a1)+,d1
move.l REFDEF_ALIASVRECT+VRECT_X(a3),d4
cmp.l d1,d3
blt.b .cont
sub.l d2,d4
fmove.l d4,fp0
fmove fp0,fp3
fadd fp2,fp3
move.l d0,d4
sub.l d2,d4
fmove.l d4,fp1
fdiv fp1,fp0
fmove.l fp3,d0
add.l d2,d0
move.l d0,(a2)+
moveq #5-1,d2
bra.b .entry
.loop
move.l (a0)+,d3
move.l (a1)+,d1
.entry
sub.l d3,d1
fmove.l d1,fp1
fmul fp0,fp1
fadd fp2,fp1
fmove.l fp1,d1
add.l d3,d1
move.l d1,(a2)+
dbra d2,.loop
bra.b .exit
.cont
sub.l d0,d4
fmove.l d4,fp0
fmove fp0,fp3
fadd fp2,fp3
move.l d2,d4
sub.l d0,d4
fmove.l d4,fp1
fdiv fp1,fp0
fmove.l fp3,d2
add.l d0,d2
move.l d2,(a2)+
moveq #5-1,d2
bra.b .entry2
.loop2
move.l (a0)+,d3
move.l (a1)+,d1
.entry2
sub.l d1,d3
fmove.l d3,fp1
fmul fp0,fp1
fadd fp2,fp1
fmove.l fp1,d3
add.l d1,d3
move.l d3,(a2)+
dbra d2,.loop2
.exit
fmovem.x (sp)+,fp2/fp3
movem.l (sp)+,d2-d4/a2/a3
rts
******************************************************************************
*
* void _R_Alias_clip_right (finalvert_t *pfv0, finalvert_t *pfv1,
* finalvert_t *out)
*
******************************************************************************
cnop 0,4
_R_Alias_clip_right
***** stackframe
rsreset
.fpuregs rs.x 2
.intregs rs.l 5
rs.l 1
.pfv0 rs.l 1
.pfv1 rs.l 1
.out rs.l 1
movem.l d2-d4/a2/a3,-(sp)
fmovem.x fp2/fp3,-(sp)
move.l .pfv0(sp),a0
move.l .pfv1(sp),a1
move.l .out(sp),a2
lea _r_refdef,a3
fmove.s #0.5,fp2
move.l (a0)+,d2
move.l (a0)+,d3
move.l (a1)+,d0
move.l (a1)+,d1
move.l REFDEF_ALIASVRECTRIGHT(a3),d4
cmp.l d1,d3
blt.b .cont
sub.l d2,d4
fmove.l d4,fp0
fmove fp0,fp3
fadd fp2,fp3
move.l d0,d4
sub.l d2,d4
fmove.l d4,fp1
fdiv fp1,fp0
fmove.l fp3,d0
add.l d2,d0
move.l d0,(a2)+
moveq #5-1,d2
bra.b .entry
.loop
move.l (a0)+,d3
move.l (a1)+,d1
.entry
sub.l d3,d1
fmove.l d1,fp1
fmul fp0,fp1
fadd fp2,fp1
fmove.l fp1,d1
add.l d3,d1
move.l d1,(a2)+
dbra d2,.loop
bra.b .exit
.cont
sub.l d0,d4
fmove.l d4,fp0
fmove fp0,fp3
fadd fp2,fp3
move.l d2,d4
sub.l d0,d4
fmove.l d4,fp1
fdiv fp1,fp0
fmove.l fp3,d2
add.l d0,d2
move.l d2,(a2)+
moveq #5-1,d2
bra.b .entry2
.loop2
move.l (a0)+,d3
move.l (a1)+,d1
.entry2
sub.l d1,d3
fmove.l d3,fp1
fmul fp0,fp1
fadd fp2,fp1
fmove.l fp1,d3
add.l d1,d3
move.l d3,(a2)+
dbra d2,.loop2
.exit
fmovem.x (sp)+,fp2/fp3
movem.l (sp)+,d2-d4/a2/a3
rts
******************************************************************************
*
* void _R_Alias_clip_top (finalvert_t *pfv0, finalvert_t *pfv1,
* finalvert_t *out)
*
******************************************************************************
cnop 0,4
_R_Alias_clip_top
***** stackframe
rsreset
.fpuregs rs.x 2
.intregs rs.l 5
rs.l 1
.pfv0 rs.l 1
.pfv1 rs.l 1
.out rs.l 1
movem.l d2-d4/a2/a3,-(sp)
fmovem.x fp2/fp3,-(sp)
move.l .pfv0(sp),a0
move.l .pfv1(sp),a1
move.l .out(sp),a2
lea _r_refdef,a3
fmove.s #0.5,fp2
move.l (a0)+,d2
move.l (a0)+,d3
move.l (a1)+,d0
move.l (a1)+,d1
move.l REFDEF_ALIASVRECT+VRECT_Y(a3),d4
cmp.l d1,d3
blt.b .cont
sub.l d3,d4
fmove.l d4,fp0
fmove fp0,fp3
fadd fp2,fp3
move.l d1,d4
sub.l d3,d4
fmove.l d4,fp1
fdiv fp1,fp0
fmove.l fp3,d1
add.l d3,d1
move.l d1,(a2)+
moveq #5-1,d3
bra.b .entry
.loop
move.l (a0)+,d2
move.l (a1)+,d0
.entry
sub.l d2,d0
fmove.l d0,fp1
fmul fp0,fp1
fadd fp2,fp1
fmove.l fp1,d0
add.l d2,d0
move.l d0,(a2)+
dbra d3,.loop
bra.b .exit
.cont
sub.l d1,d4
fmove.l d4,fp0
fmove fp0,fp3
fadd fp2,fp3
move.l d3,d4
sub.l d1,d4
fmove.l d4,fp1
fdiv fp1,fp0
fmove.l fp3,d3
add.l d1,d3
move.l d3,(a2)+
moveq #5-1,d3
bra.b .entry2
.loop2
move.l (a0)+,d2
move.l (a1)+,d0
.entry2
sub.l d0,d2
fmove.l d2,fp1
fmul fp0,fp1
fadd fp2,fp1
fmove.l fp1,d2
add.l d0,d2
move.l d2,(a2)+
dbra d3,.loop2
.exit
move.l -24(a2),d0
move.l -20(a2),-24(a2)
move.l d0,-20(a2)
fmovem.x (sp)+,fp2/fp3
movem.l (sp)+,d2-d4/a2/a3
rts
******************************************************************************
*
* void _R_Alias_clip_bottom (finalvert_t *pfv0, finalvert_t *pfv1,
* finalvert_t *out)
*
******************************************************************************
cnop 0,4
_R_Alias_clip_bottom
***** stackframe
rsreset
.fpuregs rs.x 2
.intregs rs.l 5
rs.l 1
.pfv0 rs.l 1
.pfv1 rs.l 1
.out rs.l 1
movem.l d2-d4/a2/a3,-(sp)
fmovem.x fp2/fp3,-(sp)
move.l .pfv0(sp),a0
move.l .pfv1(sp),a1
move.l .out(sp),a2
lea _r_refdef,a3
fmove.s #0.5,fp2
move.l (a0)+,d2
move.l (a0)+,d3
move.l (a1)+,d0
move.l (a1)+,d1
move.l REFDEF_ALIASVRECTBOTTOM(a3),d4
cmp.l d1,d3
blt.b .cont
sub.l d3,d4
fmove.l d4,fp0
fmove fp0,fp3
fadd fp2,fp3
move.l d1,d4
sub.l d3,d4
fmove.l d4,fp1
fdiv fp1,fp0
fmove.l fp3,d1
add.l d3,d1
move.l d1,(a2)+
moveq #5-1,d3
bra.b .entry
.loop
move.l (a0)+,d2
move.l (a1)+,d0
.entry
sub.l d2,d0
fmove.l d0,fp1
fmul fp0,fp1
fadd fp2,fp1
fmove.l fp1,d0
add.l d2,d0
move.l d0,(a2)+
dbra d3,.loop
bra.b .exit
.cont
sub.l d1,d4
fmove.l d4,fp0
fmove fp0,fp3
fadd fp2,fp3
move.l d3,d4
sub.l d1,d4
fmove.l d4,fp1
fdiv fp1,fp0
fmove.l fp3,d3
add.l d1,d3
move.l d3,(a2)+
moveq #5-1,d3
bra.b .entry2
.loop2
move.l (a0)+,d2
move.l (a1)+,d0
.entry2
sub.l d0,d2
fmove.l d2,fp1
fmul fp0,fp1
fadd fp2,fp1
fmove.l fp1,d2
add.l d0,d2
move.l d2,(a2)+
dbra d3,.loop2
.exit
move.l -24(a2),d0
move.l -20(a2),-24(a2)
move.l d0,-20(a2)
fmovem.x (sp)+,fp2/fp3
movem.l (sp)+,d2-d4/a2/a3
rts
******************************************************************************
*
* int _R_AliasClip (finalvert_t *in, finalvert_t *out, int flag,
* int count, void(*clip)(...)
*
******************************************************************************
cnop 0,4
_R_AliasClip
***** stackframe
rsreset
.intregs rs.l 11
rs.l 1
.in rs.l 1
.out rs.l 1
.flag rs.l 1
.count rs.l 1
.clip rs.l 1
movem.l d2-d7/a2-a6,-(sp)
move.l .in(sp),a2
move.l .out(sp),a3
move.l .flag(sp),d2
move.l .count(sp),d3
move.l .clip(sp),a4
* j = count-1;
* k = 0;
* for (i=0 ; i<count ; j = i, i++)
* {
move.l d3,d5
subq.l #1,d5
bmi.w .skip
move.l d5,d0 ;j = count-1
asl.l #FV_SIZEOF_EXP,d0
lea 0(a2,d0.l),a6 ;a6 = in[j]
lea _r_refdef,a5
move.l REFDEF_ALIASVRECT+VRECT_X(a5),d3
move.l REFDEF_ALIASVRECT+VRECT_Y(a5),d4
move.l REFDEF_ALIASVRECTRIGHT(a5),d6
move.l REFDEF_ALIASVRECTBOTTOM(a5),d7
move.l a2,a5
* oldflags = in[j].flags & flag;
* flags = in[i].flags & flag;
* if (flags && oldflags)
* continue;
.loop
move.l FV_FLAGS(a6),d0
and.l d2,d0 ;oldflags = in[j].flags & flag
move.l FV_FLAGS(a2),d1
and.l d2,d1 ;flags = in[i].flags & flag
beq.b .do
tst.l d0
bne.w .next
.do
* if (oldflags ^ flags)
* {
* clip (&in[j], &in[i], &out[k]);
* out[k].flags = 0;
* if (out[k].v[0] < r_refdef.aliasvrect.x)
* out[k].flags |= ALIAS_LEFT_CLIP;
* if (out[k].v[1] < r_refdef.aliasvrect.y)
* out[k].flags |= ALIAS_TOP_CLIP;
* if (out[k].v[0] > r_refdef.aliasvrectright)
* out[k].flags |= ALIAS_RIGHT_CLIP;
* if (out[k].v[1] > r_refdef.aliasvrectbottom)
* out[k].flags |= ALIAS_BOTTOM_CLIP;
* k++;
* }
eor.l d1,d0 ;if (oldflags ^ flags)
beq.b .cont
move.l d1,-(sp)
move.l a3,-(sp)
move.l a2,-(sp)
move.l a6,-(sp)
jsr (a4) ;clip (&in[j], &in[i], &out[k])
add #12,sp
moveq #0,d1 ;out[k].flags = 0
move.l (a3),d0 ;if (out[k].v[0] < ...
cmp.l d3,d0
bge.b .1
or.l #ALIAS_LEFT_CLIP,d1 ;out[k].flags |= ALIAS_LEFT_CLIP
.1
cmp.l d6,d0 ;if (out[k].v[0] > ...
ble.b .2
or.l #ALIAS_RIGHT_CLIP,d1 ;out[k].flags |= ALIAS_RIGHT_CLIP
.2
move.l 4(a3),d0 ;if (out[k].v[1] < ...
cmp.l d4,d0
bge.b .3
or.l #ALIAS_TOP_CLIP,d1 ;out[k].flags |= ALIAS_TOP_CLIP
.3
cmp.l d7,d0 ;if (out[k].v[1] > ...
ble.b .4
or.l #ALIAS_BOTTOM_CLIP,d1 ;out[k].flags |= ALIAS_BOTTOM_CLIP
.4
move.l d1,FV_FLAGS(a3)
lea FV_SIZEOF(a3),a3 ;k++
move.l (sp)+,d1
* if (!flags)
* {
* out[k] = in[i];
* k++;
* }
.cont
tst.l d1 ;if (!flags)
bne.b .next
move.l (a2)+,(a3)+ ;out[k] = in[i]
move.l (a2)+,(a3)+
move.l (a2)+,(a3)+
move.l (a2)+,(a3)+
move.l (a2)+,(a3)+
move.l (a2)+,(a3)+
move.l (a2)+,(a3)+
addq #4,a3
sub #28,a2
.next
move.l a5,a6
lea FV_SIZEOF(a5),a5
lea FV_SIZEOF(a2),a2
dbra d5,.loop
* return k;
.skip
move.l a3,d0
sub.l .out(sp),d0
asr.l #FV_SIZEOF_EXP,d0
movem.l (sp)+,d2-d7/a2-a6
rts