-
Notifications
You must be signed in to change notification settings - Fork 0
/
yarc.js
1241 lines (1095 loc) · 20.2 KB
/
yarc.js
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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;-*-Asm-*-
GPU
include <js/macro/help.mac>
include <js/macro/joypad1.mac>
include <js/symbols/blit_eq.js>
include <js/symbols/jagregeq.js>
include <js/symbols/joypad.js>
UNREG SP,SP.a,LR,LR.a
DEBUG:: EQU 0
MOD:: EQU 1
JITTER EQU 1
;; return values
_MS_PER_FRAME equ 0
_VBLS_PER_FRAME equ 4
_HEIGHT equ 8
_X_POS equ 12
_Y_POS equ 16
_ANGLE equ 20
_Z equ 24
screen0:: equ $00080000
screen1:: equ $000a0000
parameter equ $f03ff0
FP_BITS equ 12
;; canvas
rez_x:: equ 320 ; 160/192/256/320
rez_y equ 200
IF rez_x = 320
BLIT_WID EQU BLIT_WID320
ENDIF
IF rez_x = 256
BLIT_WID EQU BLIT_WID256
ENDIF
IF rez_x = 192
BLIT_WID EQU BLIT_WID192
ENDIF
IF rez_x = 160
BLIT_WID EQU BLIT_WID160
ENDIF
;; global registers
IRQ_SP.a REG 31
IRQ_RTS.a REG 30
IRQ_FLAGADDR.a REG 29
IRQ_FLAG.a REG 28
obl1.a reg 27
obl0.a reg 26
obl_size.a reg 25
LR.a reg 24
SP.a reg 23
IRQScratch4.a REG 4
IRQScratch3.a REG 3
IRQScratch2.a REG 2
IRQScratch1.a REG 1
IRQScratch0.a REG 0
IRQ_SP REG 31
VBLFlag REG 22
IRQ_RTS REG 30 ; only for VJ needed
IRQ_FLAGADDR REG 29
LR REG 24
SP REG 23
tmp2 reg 2
tmp1 reg 1
tmp0 reg 0
IRQ_STACK EQU $f03020
MACRO WAITBLITTER
.\wait@
load (blitter+$38),tmp0
shrq #1,tmp0
jr cc,.\wait@
nop
ENDM
run $f03000
GPUstart::
load (IRQ_FLAGADDR.a),IRQ_FLAG.a
movei #cpu_irq,IRQScratch0.a
bset #9+0,IRQ_FLAG.a
load (IRQ_SP.a),IRQ_RTS.a
jump (IRQScratch0.a)
bclr #3,IRQ_FLAG.a
org $f03010
movei #init,r0
jump (r0)
nop
org $f03020
timer::
load (IRQ_FLAGADDR.a),IRQ_FLAG.a
movei #timer_irq,IRQScratch0.a
bset #9+2,IRQ_FLAG.a
load (IRQ_SP.a),IRQ_RTS.a
jump (IRQScratch0.a)
bclr #3,IRQ_FLAG.a
org $f03030
op::
load (IRQ_FLAGADDR.a),IRQ_FLAG.a
movei #op_irq,IRQScratch0.a
bset #9+3,IRQ_FLAG.a
load (IRQ_SP.a),IRQ_RTS.a
jump (IRQScratch0.a)
bclr #3,IRQ_FLAG.a
org $f03050
op_irq::
move obl0.a,IRQScratch0.a
movei #$1000,IRQScratch1.a
move obl_size.a,IRQScratch3.a
.l loadp (IRQScratch0.a),IRQScratch2.a
addqt #8,IRQScratch0.a
subq #1,IRQScratch3.a
storep IRQScratch2.a,(IRQScratch1.a)
jr ne,.l
addq #8,IRQScratch1.a
moveq #1,IRQScratch0.a
moveta IRQScratch0.a,VBLFlag
moveq #_VBLS_PER_FRAME,IRQScratch0.a
load (IRQScratch0.a),IRQScratch1.a
addq #1,IRQScratch1.a
store IRQScratch1.a,(IRQScratch0.a)
movei #$f00026,IRQScratch1.a
jr irq_return
storew IRQScratch1.a,(IRQScratch1.a) ; resume OP
timer_irq::
nop
irq_return
addqt #2,IRQ_RTS.a
moveta IRQ_RTS.a,IRQ_RTS ; only for VJ needed
movefa IRQ_SP,IRQ_SP.a
store IRQ_FLAG.a,(IRQ_FLAGADDR.a)
jump (IRQ_RTS.a)
nop
cpu_irq:
moveq #1,IRQScratch0.a
moveta IRQScratch0.a,VBLFlag
jr irq_return
nop
;;; ------------------------------------------------------------
init::
movei #$f02100,IRQ_FLAGADDR
moveta IRQ_FLAGADDR,IRQ_FLAGADDR.a
movei #1<<14|%11111<<9,r0 ; clear all ints, REGPAGE = 1
store r0,(IRQ_FLAGADDR)
nop
nop
movei #IRQ_STACK,IRQ_SP
moveta IRQ_SP,IRQ_SP.a
movei #gpu_stack+4*4,SP
;; get OP lists from 68k
movei #parameter,r15
load (r15),r0
moveta r0,obl0.a
load (r15+4),r0
moveta r0,obl1.a
load (r15+8),r0
moveta r0,obl_size.a
movei #1<<14|%11111<<9|%01000<<4,r0
store r0,(IRQ_FLAGADDR)
nop
nop
;;; -----------------------------------------------------------------------
blitter reg 14
sinptr reg 15
currScreen.a REG 99
BG.a REG 99
LOOP.a REG 99
pit.a reg 99
time.a reg 99
alpha.a reg 99
beta.a reg 99
delta.a reg 99
z_pos.a reg 99
jitcounter.a reg 99
object.a reg 99
cur_object.a reg 99
dots.a reg 99
faces.a reg 99
position.a reg 99
obj_swap.a reg 99
scene_flag.a reg 99
finish.a reg 99
main::
movei #sintab,sinptr
move sinptr,r14
moveq #16,r1
shlq #3+2,r1
movei #127,r2
moveq #0,r3
singen:
subq #2,r2
move r3,r0
IF FP_BITS <> 12
shrq #12-FP_BITS,r0
ENDIF
store r0,(r14)
neg r0
add r2,r3
store r0,(r14+r1)
jr ne,singen
addqt #4,r14
movei #sintab+256*4,r14
bset #6+2,r3
cosingen:
subq #4,r3
load (sinptr+r3),r2
jr ne,cosingen
store r2,(r14+r3)
movei #$f02200,blitter
movei #200<<16|320,tmp0
//-> moveq #0,tmp0
store tmp0,(blitter+_BLIT_A1_CLIP)
moveq #0,tmp0
store tmp0,(blitter+_BLIT_A1_STEP)
store tmp0,(blitter+_BLIT_A1_FSTEP)
movei #$f00058,r0
moveta r0,BG.a
movei #$8800,r1
storew r1,(r0)
movei #screen1,r0
moveta r0,currScreen.a
;--------------------
;- Init ms-Timer
movei #$f00050,r0
movei #(26591-1)<<16|($ffff),r1
store r1,(r0) ; Start timer
addq #2,r0
moveta r0,pit.a
moveq #0,r0
moveta r0,delta.a
moveta r0,beta.a
moveta r0,alpha.a
//-> moveq #1,r0
moveta r0,scene_flag.a
moveq #2,r0
moveta r0,finish.a
movei #1400,r0
moveta r0,z_pos.a
movei #200,r0
moveta r0,jitcounter.a
moveq #1,r0
moveta r0,obj_swap.a
movei #cube,r15
moveta r15,object.a
load (r15),r0
moveta r0,dots.a
load (r15+4),r0
moveta r0,faces.a
load (r15+8),r0
moveta r0,position.a
move PC,r0
addq #6,r0
moveta r0,LOOP.a
loop:
IF DEBUG = 1
movefa BG.a,r0
moveq #0,r1
storew r1,(r0)
moveq #3,tmp0
movei #$f02114,tmp1
store tmp0,(tmp1) ; wakeup 68k
ENDIF
xor VBLFlag,VBLFlag
waitStart:
jr eq,waitStart ; wait for VBL
cmpq #0,VBLFlag
movefa pit.a,r0
loadw (r0),r0
moveta r0,time.a
IF DEBUG = 1
movefa BG.a,r0
movei #$88ff,r1
storew r1,(r0)
ENDIF
movefa finish.a,r0
cmpq #0,r0
movei #100,r0
jr mi,.no_plus
movefa z_pos.a,r1
cmp r0,r1
jr mi,.no_diinc
nop
jr .no_diinc
subq #8,r1
.no_plus
addq #2,r1
.no_diinc:
moveta r1,z_pos.a
;;; ------------------------------
;;; CLS
;;; ------------------------------
moveq #0,tmp0
store tmp0,(blitter+_BLIT_PATD)
store tmp0,(blitter+_BLIT_PATD+4)
store tmp0,(blitter+$40)
store tmp0,(blitter+$44)
bset #8,tmp0 ; = $200
store tmp0,(blitter+$70) ; int inc
movei #BLIT_PITCH1|BLIT_PIXEL16|BLIT_WID|BLIT_XADDPHR,tmp0
movefa currScreen.a,tmp1
store tmp0,(blitter+_BLIT_A1_FLAGS)
store tmp1,(blitter) ;_BLIT_A1_BASE
moveq #0,tmp1
movei #(1<<16)|(rez_y*rez_x),tmp0
store tmp1,(blitter+_BLIT_A1_PIXEL)
movei #B_PATDSEL|B_GOURD,tmp1
store tmp0,(blitter+_BLIT_COUNT)
store tmp1,(blitter+_BLIT_CMD)
macro subang
movefa \0,r0
subq #\1,r0
and \2,r0
moveta r0,\0
endm
macro addang
movefa \0,r0
addq #\1,r0
and \2,r0
moveta r0,\0
endm
.loop
movefa object.a,r0
movei #doScene,r1
BL (r1)
movefa scene_flag.a,r0
cmpq #0,r0
movei #.skip,r1
jump pl,(r1)
nop
movei #diamant,r0
movei #doScene,r1
BL (r1)
movei #ball,r0
movei #doScene,r1
BL (r1)
.skip
movefa object.a,r0
movei #.nojit,r4
movefa jitcounter.a,r2
movei #-110,r3
subq #1,r2
movefa dots.a,r0
moveta r2,jitcounter.a
jump pl,(r4)
load (r0),r1
cmp r3,r2
addqt #4,r0
jr eq,.nojit1
moveq #3,r2
.jit
//-> IF JITTER = 1
//-> load (r0),r3
//-> xor r2,r3
//-> subq #1,r1
//-> store r3,(r0)
//-> jr ne,.jit
//-> addq #4,r0
//-> ENDIF
jump (r4)
.nojit1
nop
movefa obj_swap.a,r0
neg r3
subq #1,r0
moveta r0,obj_swap.a
jump pl,(r4)
moveta r3,jitcounter.a
moveta r3,jitcounter.a
addq #1,r0
movefa object.a,r1
moveta r0,obj_swap.a
movefa scene_flag.a,r0
addq #16,r1
addq #1,r0
movei #last_object,r3
moveta r0,scene_flag.a
jr eq,.xxx
cmp r1,r3
jr ne,.nojit
moveta r1,object.a
movei #-2,r1
moveta r1,scene_flag.a
movefa finish.a,r0
subq #1,r0
moveta r0,finish.a
.xxx
movei #cube,r1
moveta r1,object.a
.nojit
;;; ------------------------------
;;; move
JOYPAD1 3
movei #LastJoy,r0
load (r0),r0
cmpq #0,r0
movei #255<<2,r1
jr ne,.norot
nop
addang alpha.a,4,r1
//-> addang beta.a,4,r1
addang delta.a,4,r1
.norot
;;; ------------------------------
;;; time
movefa pit.a,tmp0
movefa time.a,r1
loadw (tmp0),tmp0
sub tmp0,r1
moveq #_MS_PER_FRAME,tmp0
store r1,(tmp0)
;;; ------------------------------
movei #ball2_pos,r4
movei #diamant2_pos,r5
movei #diamant+8,r3
movefa scene_flag.a,r0
movei #cube+8,r1
cmpq #0,r0
movei #ball+8,r2
jr pl,.noscene
nop
movei #cube2_pos,r0
store r0,(r1)
store r4,(r2)
store r5,(r3)
subq #8,r1
moveta r1,object.a
.noscene
;;; ------------------------------
;;; swap
movefa obl0.a,tmp0
movefa obl1.a,r1
moveta tmp0,obl1.a
moveta r1,obl0.a
movei #screen0^screen1,r1
movefa currScreen.a,r2
movefa LOOP.a,tmp0
xor r1,r2
jump (tmp0)
moveta r2,currScreen.a
;;; ----------------------------------------
;;; doCube(r0 = color, r14 = object)
;;;
;;; Total registers used: r0-r19
doScene::
PUSH LR
moveta r0,cur_object.a
movefa jitcounter.a,r2
cmpq #0,r2
movei #.nojit0,r2
IF JITTER = 1
echo "JITTER on"
jump pl,(r2)
nop
movei #255<<2,r1
subang alpha.a,32,r1
subang beta.a,32,r1
subang delta.a,32,r1
movei #doCube,r1
movei #$8000,r0
BL (r1)
movei #255<<2,r1
addang alpha.a,16,r1
addang beta.a,16,r1
addang delta.a,16,r1
movei #doCube,r1
movei #$0f00,r0
BL (r1)
movei #255<<2,r1
addang alpha.a,16,r1
addang beta.a,16,r1
addang delta.a,16,r1
ENDIF
.nojit0
movei #$f000,r0
movei #doCube,r1
BL (r1)
RTS
doCube::
PUSH LR
PUSH r0
movefa cur_object.a,r14
load (r14),r0
moveta r0,dots.a
load (r14+4),r0
moveta r0,faces.a
load (r14+8),r0
moveta r0,position.a
movei #rotate,r0
BL (r0)
movei #projection,r0
BL (r0)
POP r0
movei #draw_cube,r1
BL (r1)
RTS
;;; ----------------------------------------
;;; rotation
;;;
;;; Register usage: r0-r19
;;;
rotate::
a reg 0!
b reg 1!
c reg 2!
d reg 3
e reg 4
f reg 5
acfbe reg 6
aebcf reg 7
bceaf reg 8
bface reg 9
dot_cnt reg 10
movei #1<<(FP_BITS-1),r20
movei #sintab,sinptr
movei #sintab+64*4,r14
movefa alpha.a,a
movefa alpha.a,b
movefa beta.a,c
movefa beta.a,d
movefa delta.a,e
movefa delta.a,f
load (sinptr+a),a ; sin a
load (r14+b),b ; cos a
load (sinptr+c),c ; sin b
load (r14+d),d ; cos b
load (sinptr+e),e ; sin d
load (r14+f),f ; cos d
move a,acfbe
imult c,acfbe
add r20,acfbe
sharq #FP_BITS,acfbe
imult f,acfbe
move b,r7
imult e,r7
add r7,acfbe
move b,r8
move a,aebcf
neg r8
imult e,aebcf
imult c,r8
add r20,r8
sharq #FP_BITS,r8
imult f,r8
add r8,aebcf
move b,bceaf
imult c,bceaf
add r20,bceaf
sharq #FP_BITS,bceaf
imult e,bceaf
move f,r9
imult a,r9
add r9,bceaf
neg a
move f,r10
move a,bface
imult b,r10
imult c,bface
add r20,bface
sharq #FP_BITS,bface
imult e,bface
add r10,bface
imult d,b
imult d,a
neg e
imult d,f
imult e,d
add r20,acfbe
add r20,aebcf
add r20,bceaf
add r20,bface
add r20,a
add r20,b
add r20,f
add r20,d
sharq #FP_BITS,acfbe
sharq #FP_BITS,aebcf
sharq #FP_BITS,bceaf
sharq #FP_BITS,bface
sharq #FP_BITS,a
sharq #FP_BITS,b
sharq #FP_BITS,f
sharq #FP_BITS,d
UNREG e
movefa position.a,r14
movefa z_pos.a,r12
load (r14),r17
load (r14+4),r18
load (r14+8),r19
add r12,r19
movefa dots.a,r14
movei #rdots,r15
load (r14),r10
addq #4,r14
move pc,r21
.rot
load (r14),r11
load (r14+4),r12
load (r14+8),r13
addq #12,r14
imultn f,r11
imacn d,r12
imacn c,r13
resmac r16
imultn acfbe,r11
imacn bface,r12
imacn a,r13
resmac r4
imultn aebcf,r11
imacn bceaf,r12
imacn b,r13
resmac r11
add r20,r16
add r20,r4
add r20,r11
sharq #FP_BITS,r16
sharq #FP_BITS,r4
add r17,r16
sharq #FP_BITS,r11
store r16,(r15)
add r19,r11
add r18,r4
store r11,(r15+8)
subq #3,r10
store r4,(r15+4)
jump ne,(r21)
addqt #12,r15
jump (LR)
nop
unreg a,b,c,d,f,acfbe,aebcf,bceaf,bface,dot_cnt
;;; ----------------------------------------
;;; projection
;;; ----------------------------------------
x reg 0!
y reg 1!
z reg 2!
sign reg 3
x_center reg 4
di reg 5
cnt reg 6
PROJ reg 7
projection::
movefa dots.a,cnt
movei #.proj,PROJ
load (cnt),cnt
movei #rdots,r14
movei #pxy,r15
movei #160,x_center
movei #1<<(FP_BITS-1),r8
movei #col,r9
.proj
load (r14+8),z
moveq #1,sign
abs z
movei #100<<FP_BITS,di
jr cc,.pos_z
div z,di ; 120*256/z
subq #2,sign
.pos_z
//-> shlq #2,z
movei #255,x
sub z,x
sat8 x
store x,(r9)
addq #4,r9
load (r14),x
or x,x
movei #100,r2
load (r14+4),y
or y,y
addq #12,r14
imult sign,di ; get sign back
imult di,x
imult di,y
add r8,x
add r8,y
sharq #FP_BITS,x
sharq #FP_BITS,y
add x_center,x
sub y,r2
store x,(r15)
subq #3,cnt
store r2,(r15+4)
jump ne,(PROJ)
addqt #8,r15
jump (LR)
nop
UNREG x,y,z,sign,di,cnt,PROJ,x_center
;;; ----------------------------------------
;;; Draw cube
;;;
POLY reg 21
DRAW reg 20
FACES reg 19
fcnt reg 18
y0 reg 4
x0 reg 3
color reg 2! ; re-use tmp2
y1 reg 1!
x1 reg 0!
draw_cube::
PUSH LR
PUSH r0
movei #draw,DRAW
movefa faces.a,FACES
movei #$f02200,blitter
load (FACES),fcnt
movei #poly,POLY
addq #4,FACES
.loop
load (FACES),r0
load (SP),r1
BL (POLY)
subq #1,fcnt
jr ne,.loop
addq #4,FACES
addq #4,SP
RTS
UNREG x0,y0,x1,y1,color
;;; ----------------------------------------
;;; poly(vertice_list, color)
;;;
;;; Register usage: r0-r16
;;;
p0 REG 5
p1 reg 6
p2 reg 7
poly::
move r0,r13
move r1,r12
move r0,p0
shlq #6,r0
shrq #26,p0
move r0,p1
shlq #3,p0
shrq #26,p1
shlq #6,r0
shlq #3,p1
move r0,p2
shrq #26,p2
shlq #3,p2
movei #pxy,r15
load (r15+p1),r1
move r1,r2
load (r15+p0),r0
sub r0,r1 ; p1.x - p0.x
load (r15+p2),r0
sub r0,r2 ; p1.x - p2.x
addq #4,r15
load (r15+p2),r0
load (r15+p1),r3
sub r3,r0 ; p2.y - p1.y
load (r15+p0),r4
sub r4,r3 ; p1.y - p0.y
imult r1,r0
imult r2,r3
movefa jitcounter.a,r2
cmpq #0,r2
moveq #3,r11
IF JITTER = 1
jr mi,.nohide
ENDIF
add r3,r0
jump pl,(LR)
.nohide
move LR,r16
and r13,r11 ; count
addq #3,r11
movei #col,r17
UNREG p0,p1,p2
.loop
move r13,r3
shrq #26,r3
shlq #6,r13
shlq #3,r3
move r13,r0
move r3,r5
shrq #26,r0
shrq #1,r5
add r17,r5
load (r15+r3),r4
shlq #3,r0
subq #4,r3
move r0,r6
load (r15+r3),r3
shrq #1,r6
add r17,r6
load (r15+r0),r1
subq #4,r0
load (r5),r5
//-> move r12,r2
load (r15+r0),r0
load (r6),r6
add r5,r6
shrq #1,r6
move r6,r2
or r12,r2
BL (DRAW)
movei #.loop,r2
subq #1,r11
jump ne,(r2)
nop
jump (r16)
nop
;;; ----------------------------------------
;;; draw
;;;
;;; Register usage: r0-r10, r14
;;;
;;; r4 - y0
;;; r3 - x0
;;; r2 - color
;;; r1 - y1
;;; r0 - x1
draw::
dx reg 10
dy reg 9
m reg 8
cnt reg 7
dir_x reg 6
step_y reg 5
a1inc reg 4
;;; -- parameter
y0 reg 4!
x0 reg 3
color reg 2!
y1 reg 1!
x1 reg 0!
.pos1
move y1,dy
move x1,dx
sub y0,dy
sub x0,dx
moveq #1,dir_x
jr pl,.noswap0
moveq #1,step_y
move x1,x0
move y1,y0
neg step_y
.noswap0
abs dy
jr cc,.pos
abs dx
neg step_y
.pos
cmpq #0,dy
jr ne,.yno0
cmp dy,dx
moveq #0,step_y
.yno0
move dx,cnt
jr ne,.not_diag
move dy,m
;; dx = dy
moveq #0,m
moveq #0,dir_x
shlq #16,step_y
jr .diagonal
addqt #1,step_y ; => becomes A1_INC
.not_diag
jr cc,.no_swap
shlq #16,m
shlq #16,dx
move dy,cnt
move dx,m
subq #2,dir_x ; swap x_inc 1 => y_inc 1
.no_swap
div cnt,m
.diagonal
shlq #16,y0
movei #$80008000,tmp1 ; start in the middle of the 1st pixel
or x0,y0
WAITBLITTER
store color,(blitter+_BLIT_PATD)
store color,(blitter+_BLIT_PATD+4) ;VJ
movei #BLIT_PITCH1|BLIT_PIXEL16|BLIT_WID|BLIT_XADDINC,tmp0
movefa currScreen.a,color
store tmp0,(blitter+_BLIT_A1_FLAGS)
store color,(blitter) ;_BLIT_A1_BASE
cmpq #0,dir_x
store y0,(blitter+_BLIT_A1_PIXEL)
jr eq,.cont_dia
store tmp1,(blitter+_BLIT_A1_FPIXEL)
jr mi,.xstep