-
Notifications
You must be signed in to change notification settings - Fork 2
/
voxel.asm
1318 lines (1090 loc) · 30.8 KB
/
voxel.asm
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
;TODO: -
VOXEL_DEPTHS = 64
VOXEL_WIDTH = 160
VOXEL_HEIGHT = 100
VOXEL_PLANESIZE = VOXEL_WIDTH*VOXEL_HEIGHT/4
VOXEL_NUMFRAMES = 1200
include "../framework/hardware.i"
include "../framework/framework.i"
include "../launcher/timings.asm"
ifnd _DEMO
include "../framework/parttester.asm"
endc // _DEMO
section "voxel_code",code
entrypoint:
move.l a6,fw_jumptable
;detect aga
clr.w voxel_isaga
moveq #0,d1
move.w $dff004,d0
and.w #$6f00,d0 ; 0110111100000000
cmp.w #$2200,d0 ; 0010001000000000
beq.b .aga
cmp.w #$2300,d0 ; 0010001100000000
.aga:
seq d1
tst.w d1
beq.b .noaga
move.w #$6a00,voxel_agafix ;if we have aga, we need to set a correct ham6 mode.
;the "ham7" needed for the dma-hack, doesnt work here.
move.w #1,voxel_isaga
.noaga:
bsr.w voxel_init
bsr.w voxel_step
bsr.w voxel_doframe
bsr.w voxel_step
bsr.w voxel_doframe
bsr.w voxel_step
bsr.w voxel_doframe
lea voxel_coppersprites,a0
move.l fw_jumptable,a6
jsr CLEARSPRITES(a6)
lea voxel_coppersprites,a0
move.l #voxel_sprite,d0
move.w d0,$06(a0)
swap d0
move.w d0,$02(a0)
move.w #TIME_VOXEL_START,d0
move.l fw_jumptable,a6
jsr WAITFORFRAME(a6)
move.l #voxel_copperlist,a0
move.l #voxel_irq,a1
move.l fw_jumptable,a6
jsr SETCOPPER(a6)
move.w #$8020,$dff096 ;copper, bitplane & sprite dma
bsr.w voxel_setpal
clr.w $dff1a2 ;sprite color
voxel_main:
;move.w #$0008,$dff180
bsr.w voxel_doframe
;move.w #$000,$dff180
;bsr.w vsync
;move.w voxel_time(pc),d0
;add.w d0,d0
;clr.w voxel_time
;lea voxel_timetab,a0
;move.w (a0,d0.w),$dff180
btst #$06,$bfe001
beq.b voxel_end
cmpi.w #VOXEL_NUMFRAMES,voxel_fadeframe
blt.b voxel_main
voxel_end:
move.l fw_jumptable,a6
jsr SETBASECOPPER(a6)
move.w #$0020,$dff096 ;turn off sprite dma
rts
cnop 0,4
fw_jumptable:
dc.l 0
voxel_timetab:
dc.w $0000,$0fff,$0f00,$00ff,$0f0f,$00f0,$000f,$0ff0
;--------------------------------------------------------------------
voxel_init:
lea voxel_sintab,a0 ;tablica sinusów
lea $280(a0),a1
move.l a1,a2
lea $500(a0),a3
move.w #$9f,d7 ;159 razy
.sl0:
move.w (a0)+,d0
move.w d0,-(a1)
neg.w d0 ;Subtracts the destination operand from zero
move.w d0,(a2)+
move.w d0,-(a3)
dbra d7,.sl0 ;decrements Di.w and branches to Addr
lea voxel_sintab,a0
lea $500(a0),a1
move.w #$27f,d7
.sl1:
move.w (a0)+,(a1)+
dbra d7,.sl1
move.l fw_jumptable,a6
jsr VSYNC(a6)
bsr.w voxel_initcopper
bsr.w voxel_initmask
bsr.w voxel_inittexture
bsr.w voxel_initpersptab
bsr.w voxel_initoffsets
bsr.w voxel_initshadetab
rts ;Pops the program counter value from the stack.
;--------------------------------------------------------------------
VOXEL_SKYCOL = $06ae
VOXEL_SKYCOLHAM = $7bf0
cnop 0,2
voxel_isaga:
dc.w 0
voxel_setpal:
clr.w $dff106
lea $dff180,a0
clr.w (a0)+
move.w #VOXEL_SKYCOL,(a0)+
tst.w voxel_isaga
beq.b .skip
move.w #$0200,$dff106
lea $dff180,a0
clr.w (a0)+
clr.w (a0)+
.skip:
rts
;--------------------------------------------------------------------
cnop 0,4
voxel_copperbpl:
dc.l 0
voxel_agafix:
dc.w $7a00
voxel_initcopper:
lea voxel_copperstretch,a0
;move.l #$720ffffe,d0
move.l #$1a0ffffe,d0
move.w #44-1,d7
.l0:
move.l d0,(a0)+
move.l #$01001200,(a0)+
addi.l #$01000000,d0
move.l d0,(a0)+
move.l #$01000200,(a0)+
addi.l #$01000000,d0
dbra d7,.l0
move.l a0,voxel_copperbpl
move.l #$00e40000,(a0)+ ;8 real bitplane pointers
move.l #$00e60000,(a0)+
move.l #$00e80000,(a0)+
move.l #$00ea0000,(a0)+
move.l #$00ec0000,(a0)+
move.l #$00ee0000,(a0)+
move.l #$00f00000,(a0)+
move.l #$00f20000,(a0)+
move.l #$00f40000,(a0)+
move.l #$00f60000,(a0)+
move.l #$00f80000,(a0)+
move.l #$00fa0000,(a0)+
move.l #$00fc0000,(a0)+
move.l #$00fe0000,(a0)+
move.l #$00e00000,(a0)+
move.l #$00e20000,(a0)+
move.l #$01080000,(a0)+
move.l #$010a0000,(a0)+ ;modulos
move.w #VOXEL_HEIGHT-1,d7
.l1:
move.l d0,(a0)+
move.w #$0100,(a0)+
move.w voxel_agafix(pc),(a0)+
addi.l #$01000000,d0
move.l d0,(a0)+
move.l #$01000200,(a0)+
addi.l #$01000000,d0
cmpi.l #$000ffffe,d0
bne.b .skipwrap
move.l #$ffdffffe,(a0)+
.skipwrap:
dbra d7,.l1
move.l #$01000200,(a0)+ ;turn off bitplanes
move.l #$fffffffe,(a0)+ ;end of copperlist
rts
;--------------------------------------------------------------------
voxel_initmask:
lea voxel_mask,a0
lea VOXEL_PLANESIZE(a0),a1
lea VOXEL_PLANESIZE(a1),a2
move.w #VOXEL_PLANESIZE/4-1,d7
.l0:
move.l #$77777777,(a0)+ ;rgbb
move.l #$cccccccc,(a1)+ ;rgbb
move.l #$00000000,(a2)+ ;rgbb
dbra d7,.l0
rts
;--------------------------------------------------------------------
voxel_inittexture:
lea voxel_textureheights+$10000,a0
lea voxel_textureheights,a1
lea voxel_textureheights+$20000,a2
move.w #$7fff,d7
.l0:
move.b (a0)+,(a2)+
move.b (a1)+,(a2)+
move.b (a0)+,(a2)+
move.b (a1)+,(a2)+
dbra d7,.l0
lea voxel_textureheights+$20000,a0
lea voxel_textureheights,a1
move.w #$7fff,d7
.l1:
move.l (a0)+,(a1)+
dbra d7,.l1
rts
;--------------------------------------------------------------------
MACRO<VOXEL_CALCSHADE>
move.w d0,d1
move.w d0,d2
move.w d0,d3
move.w d0,d4
andi.w #$0800,d1
andi.w #$0400,d2
andi.w #$0200,d3
andi.w #$0100,d4
lsl.w #4,d1 ;$0800->$8000
lsl.w #1,d2 ;$0400->$0800
lsr.w #2,d3 ;$0200->$0080
lsr.w #5,d4 ;$0100->$0008
or.w d2,d1
or.w d3,d1
or.w d4,d1 ;$8888
move.w d0,d2
move.w d0,d3
move.w d0,d4
move.w d0,d5
andi.w #$0080,d2
andi.w #$0040,d3
andi.w #$0020,d4
andi.w #$0010,d5
lsl.w #7,d2 ;$0080->$4000
lsl.w #4,d3 ;$0040->$0400
lsl.w #1,d4 ;$0020->$0040
lsr.w #2,d5 ;$0010->$0004
or.w d3,d2
or.w d4,d2
or.w d5,d2 ;$4444
move.w d0,d3
move.w d0,d4
move.w d0,d5
move.w d0,d6
andi.w #$0008,d3
andi.w #$0004,d4
andi.w #$0002,d5
andi.w #$0001,d6
lsl.w #8,d3
lsl.w #2,d3 ;$0008->$2000
lsl.w #7,d4 ;$0004->$0200
lsl.w #4,d5 ;$0002->$0020
lsl.w #1,d6 ;$0001->$0002
or.w d4,d3
or.w d5,d3
or.w d6,d3 ;$2222
move.w d3,d4
lsr.w #1,d4
or.w d4,d3 ;$3333
move.w d1,d0 ;$8888
or.w d2,d0 ;$cccc
or.w d3,d0 ;$ffff
ENDM
voxel_initshadetab:
lea voxel_shadetab,a0
move.l #voxel_shadetab,d0
andi.l #$ffff0000,d0
addi.l #$00010000,d0
move.l d0,voxel_shadetabpoi
lea voxel_shadetabsrc,a0
move.l d0,a1
move.w #16*128-1,d7
.l0:
move.w (a0)+,d0
VOXEL_CALCSHADE
move.w d0,(a1)+
dbra d7,.l0
move.w #VOXEL_SKYCOLHAM,d0
move.w #16*128-1,d7
.l1:
move.w d0,(a1)+
dbra d7,.l1
rts
;--------------------------------------------------------------------
voxel_initpersptab:
lea voxel_persptabpacked,a0
lea voxel_persptab,a1
moveq #128-1,d7
.l1:
move.l (a0)+,d1
move.l (a0)+,d0
sub.l d0,d1
asr.l #7,d1
move.w #99,d4
moveq #128-1,d6
.l0:
move.l d0,d2
swap d2
tst.w d2
bpl.b .cliptop
moveq #0,d2
.cliptop:
cmp.w d4,d2
blt.b .clipbottom
move.w d4,d2
.clipbottom:
move.w d2,d3
add.w d3,d3
add.w d3,d3
add.w d2,d3
lsl.w #5,d3 ;mulu #160
move.w d3,(a1)
adda.w #256,a1
add.l d1,d0
dbra d6,.l0
suba.w #256*128-2,a1
dbra d7,.l1
rts
;--------------------------------------------------------------------
voxel_initoffsets:
lea voxel_offsets,a0
lea voxel_offsets+64*480,a1
lea voxel_offsetstmp,a2
move.w #64*480-1,d7
.l0:
move.b (a0)+,d0
move.b (a1)+,d1
lsl.w #8,d1
move.b d0,d1
add.w d1,d1
move.w d1,(a2)+
dbra d7,.l0
lea voxel_offsetstmp,a0
lea voxel_offsets,a1
move.w #64*480/2-1,d7
.l1:
move.l (a0)+,(a1)+
dbra d7,.l1
rts
;--------------------------------------------------------------------
voxel_doframe:
bsr.w voxel_clear
bsr.w voxel_c2p
bsr.w voxel_fill
bsr.w voxel_draw
bsr.w voxel_updatefade
move.l fw_jumptable(pc),a6
jsr BLTWAIT(a6)
bsr.w voxel_page
rts
;--------------------------------------------------------------------
voxel_clear:
move.l voxel_backbuffers+4,a0
move.l fw_jumptable,a6
jsr BLTWAIT(a6)
lea BLTBASE,a6
move.w #$ffff,BLTAFWM(a6)
move.w #$ffff,BLTALWM(a6)
clr.w BLTADAT(a6)
clr.w BLTBDAT(a6)
clr.w BLTCDAT(a6)
clr.w BLTCMOD(a6)
clr.w BLTDMOD(a6)
move.l a0,BLTDPTR(a6)
move.l #$01f00000,BLTCON0(a6)
move.w #VOXEL_HEIGHT*128+VOXEL_WIDTH/4,BLTSIZE(a6)
rts
;--------------------------------------------------------------------
; 5120 = 160 * 32
voxel_step:
move.w voxel_moveframe(pc),d0 ;pobierz PC do d0 = 0
addi.w #2,d0 ;dodaj 2
cmpi.w #1280*4,d0 ;odejmij od 5120
blt.b .wrap0 ;jeżeli nie skończyliśmy to pomiń krok
moveq #0,d0
.wrap0:
move.w d0,voxel_moveframe ; zapisz pozycję w voxel_moveframe
lsr.w #2,d0 ; podziel przez 4
andi.w #$ffe,d0 ; AND 111111111110
lea voxel_sintab,a0 ;Loads the effective address into the specified address register
move.w (a0,d0.w),d1 ;pobierz wartość z odpowiedniej pozycji tablicy sinusów do d1
muls.w #12/4,d1 ; pomnóż wartość przez 3
move.l d1,voxel_movespeed ; zapisz jako obecna prędkość
move.w voxel_rotframe(pc),d0 ;pobierz wartość rotacji
addq #4,d0 ;dodaj 4
cmpi.w #1280*4,d0 ;odejmij od 5120
blt.b .wrap01 ;pomin jeżeli mniejsze
subi.w #1280*4,d0 ;jeżeli skończyliśmy to odejmij 5120
.wrap01:
move.w d0,voxel_rotframe ; zapisz rotację w voxel_rotframe
lsr.w #2,d0 ; podziel przez 4
andi.w #$ffe,d0 ; AND 111111111110
move.w (a0,d0.w),d1 ;pobierz wartość z odpowiedniej pozycji tablicy sinusów do d1
muls.w #10*8/4,d1 ;pomnóż przez 20
swap d1 ;przesuń wartość do górnego rejestru / pomnóż przez 256
move.w d1,voxel_rotystep ;zapisz w voxel_rotystep
move.w voxel_roty(pc),d0 ;pobierz roty
add.w voxel_rotystep(pc),d0 ;dodaj tory step
bpl.b .wrap1 ;pomiń jeżeli większe od 0
addi.w #640*8,d0 ;dodaj
.wrap1:
cmpi.w #640*8,d0 ;odejmij 5120
blt.b .wrap2 ;pomin jeżeli mniejsze
subi.w #640*8,d0 ;zapętl do wartości 5120
.wrap2:
move.w d0,voxel_roty ;zapisz do voxel_roty
lsr.w #3,d0 ;podziel przez 8
addi.w #20,d0 ;dodaj
move.w d0,d1 ;zapisz w d1
add.w d0,d0 ; x2
add.w d1,d0 ; +1
add.w d0,d0 ;fast mulu.w #6 ; x2
asr.w #3,d0 ; przesuń o 3 bity, ale raczej podziel przez 8 jeżeli wartość mniejsze ż 32k
cmpi.w #480,d0 ;sprawdź czy większe od
blt.b .bla ;pomin jeżeli mniejsze
subi.w #480,d0 ;zapętl do wartości 480
.bla:
ext.l d0 ;zamień na long
lsl.l #7,d0 ;pomnóż przez 128
move.l d0,voxel_offsetoffset ;zapisz voxel_offsetoffset
move.w voxel_roty(pc),d0 ;pobierz voxel_roty
lsr.w #3,d0 ;podziel przez 8
add.w d0,d0 ;x 2
lea voxel_sintab+80*2,a1 ;ustaw adres sin
lea voxel_sintab+240*2,a2 ;ustaw adres sin
move.l voxel_offsetx(pc),d3
move.l voxel_offsety(pc),d4
move.w (a1,d0.w),d1
move.w (a2,d0.w),d2
ext.l d1 ;zamień na long
ext.l d2 ;zamień na long
move.l d1,d5
move.l d2,d6
move.l d5,voxel_dirx ;zapisz voxel_dirx
move.l d6,voxel_diry ;zapisz voxel_diry
move.l voxel_movespeed(pc),d1 ;zapisz jako prędkość
moveq #0,d2
add.l d1,d3
add.l d2,d4
move.l d3,voxel_offsetx ;zapisz voxel_offsetx
move.l d4,voxel_offsety ;zapisz voxel_offsety
rts ;wróć
;--------------------------------------------------------------------
; 1 - krok głębokości ?
; 2 - voxel_offset
; 3 - mgła?
MACRO<VOXEL_PIXEL1>
adda.w (a0)+,a3
move.w (a3),d1
move.b d1,d0
clr.b d1
move.w \1*2(a2,d1.w),d4
cmp.w d4,d5
ble.w .skip\@+\2
move.l d0,a1
move.w (a1),d1
eor.w d1,d3
move.w d3,(a6,d5.w)
.skip\@:
if \3>0
add.w d2,d0
endc
ENDM
; 1 - krok głębokości ?
; 2 - voxel_offset
; 3 - mgła?
MACRO<VOXEL_PIXEL2>
adda.w (a0)+,a3
move.w (a3),d3
move.b d3,d0
clr.b d3
move.w \1*2(a2,d3.w),d5
cmp.w d5,d4
ble.w .skip\@+\2
move.l d0,a1
move.w (a1),d3
eor.w d3,d1
move.w d1,(a6,d4.w)
.skip\@:
if \3>0
add.w d2,d0
endc
ENDM
MACRO<VOXEL_DOSKY>
eor.w #VOXEL_SKYCOLHAM,\2
move.w \2,(a6,\3.w)
ENDM
;--------------------------------------------------------------------
cnop 0,2
voxel_fadeframe:
dc.w 0
voxel_fadetab:
dc.w $0000,$0001,$0112,$0123,$0234,$0235,$0346,$0357
dc.w $0357,$0468,$0479,$057a,$058b,$069c,$069d,$06ae
voxel_updatefade:
move.w voxel_fadeframe(pc),d0
cmpi.w #64,d0
bgt.b .fadeout
lsr.w #2,d0
cmpi.w #$0f,d0
blt.b .wrap0
moveq #$0f,d0
.wrap0:
eori.w #$0f,d0
lsl.w #8,d0
ext.l d0
move.l d0,voxel_fadeoff
rts
.fadeout:
sub.w #VOXEL_NUMFRAMES-32,d0
neg.w d0
bpl.b .bla
moveq #0,d0
.bla:
.dofade:
lsr.w #2,d0
cmpi.w #$0f,d0
blt.b .wrap1
moveq #$0f,d0
.wrap1:
eori.w #$0f,d0
move.w d0,d1
addq #1,d0
lsl.w #8,d0
ext.l d0
move.l d0,voxel_fadeoff
add.w d1,d1
lea voxel_fadetab,a0
move.w (a0,d1.w),d0
clr.w $dff106
move.w d0,$dff180
move.w d0,$dff1a2
tst.w voxel_isaga
beq.b .skip
move.w #$0200,$dff106
clr.w $dff180
clr.w $dff1a2
.skip:
rts
;--------------------------------------------------------------------
cnop 0,4
voxel_campoi:
dc.l 0
voxel_movespeed:
dc.l $8000*8
voxel_persptabpoi:
dc.l 0
voxel_offsetx:
dc.l 160*65536
voxel_offsety:
dc.l 32*65536
voxel_dirx:
dc.l 0
voxel_diry:
dc.l 0
voxel_camheight:
dc.w 0
voxel_roty:
dc.w 0*1
voxel_rotystep:
dc.w 4
voxel_moveframe:
dc.w 0 ;Define constant. The DC directive places the specified data or string within the instruction stream.
voxel_rotframe:
dc.w 0
voxel_fadeoff:
dc.l 128*2*16
voxel_offsetoffset:
dc.l 0
voxel_scrambletab:
dc.w $00,$02,$04,$06
dc.w $08,$0a,$0c,$0e
dc.w $10,$12,$14,$16
dc.w $18,$1a,$1c,$1e
dc.w $20,$22,$24,$26
dc.w $28,$2a,$2c,$2e
dc.w $30,$32,$34,$36
dc.w $38,$3a,$3c,$3e
dc.w $40,$42,$44,$46
dc.w $48,$4a,$4c,$4e
dc.w $50,$52,$54,$56
dc.w $58,$5a,$5c,$5e
dc.w $60,$62,$64,$66
dc.w $68,$6a,$6c,$6e
dc.w $70,$72,$74,$76
dc.w $78,$7a,$7c,$7e
dc.w $80,$82,$84,$86
dc.w $88,$8a,$8c,$8e
dc.w $90,$92,$94,$96
dc.w $98,$9a,$9c,$9e
voxel_shadetabpoi:
dc.l 0
;*********************************************************************************
voxel_draw:
move.l voxel_offsetoffset(pc),d0 ;d0 -
lea voxel_offsets,a0 ;a0 -
adda.l d0,a0
move.l voxel_offsetx(pc),d3 ;d3 - offset x
move.l voxel_offsety(pc),d4 ;d4 - offset y
move.l voxel_dirx(pc),d5 ;d5 - dir x
move.l voxel_diry(pc),d6 ;d6 - dir y
;wylliczenie adresu w pamięci ( x + y * 256 ) * 2
;moveq #0,d4
move.l #12*65536,d4
swap d3 ;d3 * 64k
swap d4 ;d4 * 64k
andi.w #$ff,d3
andi.l #$ff,d4
lsl.w #8,d4 ;*256
move.b d3,d4
add.l d4,d4
lea voxel_textureheights+256*512,a3 ;
adda.l d4,a3 ;d4 - dodaj odczytaną wysokość
move.l a3,voxel_campoi
lsl.l #5,d5 ;dir x * 32
lsl.l #5,d6 ;dir y * 32
move.l voxel_offsetx(pc),d3
move.l voxel_offsety(pc),d4
;moveq #0,d4
move.l #12*65536,d4
add.l d5,d3 ;do pozycji x dodaj obrót x
add.l d6,d4 ;do pozycji y dodaj obrót y
moveq #0,d5 ;w d5 zapisz 0
moveq #0,d6 ;w d6 zapisz 0
swap d3 ;d3 * 64k
swap d4 ;d4 * 64k
andi.w #$ff,d3
andi.l #$ff,d4
lsl.w #8,d4 ;*256
move.b d3,d4
add.l d4,d4
lea voxel_textureheights+256*512,a3
adda.l d4,a3 ;dodaj odczytaną wysokość
move.w #$3f00,d0 ;d0 - 00111111 - 16128
sub.w (a3),d0 ;d0 - odejmij wysokość
;clr.b 1(a3)
;move.b #$3e,1(a3)
;andi.w #$3f00,d0
;inercja zmiany wysokości kamery?
move.w voxel_camheight(pc),d1 ;d1 - wysokośc kamery
add.w d1,d1
add.w voxel_camheight(pc),d1 ;d1 * 3
add.w d0,d1 ;odejmij d0 od d1 - czyli wysokość terenu od wysokości kamery
lsr.w #2,d1 ;d1 / 4
move.w d1,voxel_camheight ;zapisz do voxel_camheight
lea voxel_persptab,a2 ;odczytaj perspektywę
andi.w #$ff00,d1 ;użyj górnej części wysokości kamery
adda.w d1,a2 ;zapisz do perspektywy???
move.l a2,voxel_persptabpoi ;oraz tabpoi ???
move.w $7e(a2),d2 ;d2 - odczytaj wartość z tab persp
ext.l d2 ;Extends a byte in a data register to a word
divu.w #160,d2 ;Divides the unsigned destination operand - podziel przez 160
not.w d2 ;Calculates the ones complement of the destination operand
addi.w #94,d2 ;Adds the immediate data to the destination operand - dodaj 94
add.w d2,d2 ;*2
lea voxel_scrambletab+VOXEL_WIDTH/2*2,a4 ;wczytaj scramble z pozycji odpowiaadającej szerokości czyli 160
adda.w d6,a4 ;dodaj 0 ???
lea voxel_blitbuf,a5 ;32*34 = 1088
move.l #voxel_offsetsend,d6 ;move ??? to d6
move.w #VOXEL_WIDTH/2-7,d7 ;d7 - 80-7=73
.l0:
tst.w (a5) ;Compares the operand with zero - ;32*34 = 1088 (440)
beq.b .skipblit ;we are finished with blits - if blitbuf = 0
lea BLTBASE,a1
.bltwait1:
btst #$0e,2(a1) ;sprawdź czy bliter jest 0000 1110
bne.b .skipblit ;if blitter is busy, skip blit for this run and try on next (branch if not equal)
;jeżeli bliter jest wolny to go ustaw
move.w (a5)+,BLTADAT(a1)
move.l (a5)+,BLTBPTR(a1)
move.l (a5)+,BLTCPTR(a1)
move.l (a5)+,BLTDPTR(a1)
move.l (a5)+,BLTCON0(a1)
move.w (a5)+,BLTBMOD(a1)
move.w (a5)+,BLTSIZE(a1)
.skipblit:
move.l voxel_persptabpoi(pc),a2
move.l voxel_campoi(pc),a3
move.l voxel_backbuffers+0,a6
adda.w -(a4),a6
move.w #$100,d2
moveq #0,d3
move.w #(VOXEL_HEIGHT-2)*VOXEL_WIDTH,d5
move.l voxel_shadetabpoi(pc),d0
add.l voxel_fadeoff(pc),d0
voxel_offset = .voxel_code2-.voxel_code1
.voxel_code1: ;64 naprzemienne wywołania
VOXEL_PIXEL1 $00, voxel_offset, 0
VOXEL_PIXEL2 $01, voxel_offset, 0
VOXEL_PIXEL1 $02, voxel_offset, 0
VOXEL_PIXEL2 $03, voxel_offset, 0
VOXEL_PIXEL1 $04, voxel_offset, 0
VOXEL_PIXEL2 $05, voxel_offset, 0
VOXEL_PIXEL1 $06, voxel_offset, 0
VOXEL_PIXEL2 $07, voxel_offset, 0
VOXEL_PIXEL1 $08, voxel_offset, 0
VOXEL_PIXEL2 $09, voxel_offset, 0
VOXEL_PIXEL1 $0a, voxel_offset, 0
VOXEL_PIXEL2 $0b, voxel_offset, 0
VOXEL_PIXEL1 $0c, voxel_offset, 0
VOXEL_PIXEL2 $0d, voxel_offset, 0
VOXEL_PIXEL1 $0e, voxel_offset, 0
VOXEL_PIXEL2 $0f, voxel_offset, 0
VOXEL_PIXEL1 $10, voxel_offset, 0
VOXEL_PIXEL2 $11, voxel_offset, 0
VOXEL_PIXEL1 $12, voxel_offset, 0
VOXEL_PIXEL2 $13, voxel_offset, 0
VOXEL_PIXEL1 $14, voxel_offset, 0
VOXEL_PIXEL2 $15, voxel_offset, 0
VOXEL_PIXEL1 $16, voxel_offset, 0
VOXEL_PIXEL2 $17, voxel_offset, 0
VOXEL_PIXEL1 $18, voxel_offset, 0
VOXEL_PIXEL2 $19, voxel_offset, 0
VOXEL_PIXEL1 $1a, voxel_offset, 0
VOXEL_PIXEL2 $1b, voxel_offset, 0
VOXEL_PIXEL1 $1c, voxel_offset, 0
VOXEL_PIXEL2 $1d, voxel_offset, 0
VOXEL_PIXEL1 $1e, voxel_offset, 0
VOXEL_PIXEL2 $1f, voxel_offset, 0
VOXEL_PIXEL1 $20, voxel_offset, 0
VOXEL_PIXEL2 $21, voxel_offset, 0
VOXEL_PIXEL1 $22, voxel_offset, 0
VOXEL_PIXEL2 $23, voxel_offset, 0
VOXEL_PIXEL1 $24, voxel_offset, 0
VOXEL_PIXEL2 $25, voxel_offset, 0
VOXEL_PIXEL1 $26, voxel_offset, 0
VOXEL_PIXEL2 $27, voxel_offset, 0
VOXEL_PIXEL1 $28, voxel_offset, 0
VOXEL_PIXEL2 $29, voxel_offset, 0
VOXEL_PIXEL1 $2a, voxel_offset, 0
VOXEL_PIXEL2 $2b, voxel_offset, 0
VOXEL_PIXEL1 $2c, voxel_offset, 0
VOXEL_PIXEL2 $2d, voxel_offset, 0
VOXEL_PIXEL1 $2e, voxel_offset, 0
VOXEL_PIXEL2 $2f, voxel_offset, 0
VOXEL_PIXEL1 $30, voxel_offset, $100
VOXEL_PIXEL2 $31, voxel_offset, $100
VOXEL_PIXEL1 $32, voxel_offset, $100
VOXEL_PIXEL2 $33, voxel_offset, $100
VOXEL_PIXEL1 $34, voxel_offset, $100
VOXEL_PIXEL2 $35, voxel_offset, $100
VOXEL_PIXEL1 $36, voxel_offset, $100
VOXEL_PIXEL2 $37, voxel_offset, $100
VOXEL_PIXEL1 $38, voxel_offset, $100
VOXEL_PIXEL2 $39, voxel_offset, $100
VOXEL_PIXEL1 $3a, voxel_offset, $100
VOXEL_PIXEL2 $3b, voxel_offset, $100
VOXEL_PIXEL1 $3c, voxel_offset, $100
VOXEL_PIXEL2 $3d, voxel_offset, $100
VOXEL_PIXEL1 $3e, voxel_offset, $100
VOXEL_PIXEL2 $3f, voxel_offset, $100
VOXEL_DOSKY 0, d3, d5, d1, d4
bra.w .voxel_codeend
.voxel_code2: ;64
VOXEL_PIXEL2 $00, -voxel_offset, 0
VOXEL_PIXEL1 $01, -voxel_offset, 0
VOXEL_PIXEL2 $02, -voxel_offset, 0
VOXEL_PIXEL1 $03, -voxel_offset, 0
VOXEL_PIXEL2 $04, -voxel_offset, 0
VOXEL_PIXEL1 $05, -voxel_offset, 0
VOXEL_PIXEL2 $06, -voxel_offset, 0
VOXEL_PIXEL1 $07, -voxel_offset, 0
VOXEL_PIXEL2 $08, -voxel_offset, 0
VOXEL_PIXEL1 $09, -voxel_offset, 0
VOXEL_PIXEL2 $0a, -voxel_offset, 0
VOXEL_PIXEL1 $0b, -voxel_offset, 0
VOXEL_PIXEL2 $0c, -voxel_offset, 0
VOXEL_PIXEL1 $0d, -voxel_offset, 0
VOXEL_PIXEL2 $0e, -voxel_offset, 0
VOXEL_PIXEL1 $0f, -voxel_offset, 0
VOXEL_PIXEL2 $10, -voxel_offset, 0
VOXEL_PIXEL1 $11, -voxel_offset, 0
VOXEL_PIXEL2 $12, -voxel_offset, 0
VOXEL_PIXEL1 $13, -voxel_offset, 0
VOXEL_PIXEL2 $14, -voxel_offset, 0
VOXEL_PIXEL1 $15, -voxel_offset, 0
VOXEL_PIXEL2 $16, -voxel_offset, 0
VOXEL_PIXEL1 $17, -voxel_offset, 0
VOXEL_PIXEL2 $18, -voxel_offset, 0
VOXEL_PIXEL1 $19, -voxel_offset, 0
VOXEL_PIXEL2 $1a, -voxel_offset, 0
VOXEL_PIXEL1 $1b, -voxel_offset, 0
VOXEL_PIXEL2 $1c, -voxel_offset, 0
VOXEL_PIXEL1 $1d, -voxel_offset, 0
VOXEL_PIXEL2 $1e, -voxel_offset, 0
VOXEL_PIXEL1 $1f, -voxel_offset, 0
VOXEL_PIXEL2 $20, -voxel_offset, 0
VOXEL_PIXEL1 $21, -voxel_offset, 0
VOXEL_PIXEL2 $22, -voxel_offset, 0
VOXEL_PIXEL1 $23, -voxel_offset, 0
VOXEL_PIXEL2 $24, -voxel_offset, 0
VOXEL_PIXEL1 $25, -voxel_offset, 0
VOXEL_PIXEL2 $26, -voxel_offset, 0
VOXEL_PIXEL1 $27, -voxel_offset, 0
VOXEL_PIXEL2 $28, -voxel_offset, 0
VOXEL_PIXEL1 $29, -voxel_offset, 0
VOXEL_PIXEL2 $2a, -voxel_offset, 0
VOXEL_PIXEL1 $2b, -voxel_offset, 0
VOXEL_PIXEL2 $2c, -voxel_offset, 0
VOXEL_PIXEL1 $2d, -voxel_offset, 0
VOXEL_PIXEL2 $2e, -voxel_offset, 0
VOXEL_PIXEL1 $2f, -voxel_offset, 0
VOXEL_PIXEL2 $30, -voxel_offset, $100
VOXEL_PIXEL1 $31, -voxel_offset, $100
VOXEL_PIXEL2 $32, -voxel_offset, $100
VOXEL_PIXEL1 $33, -voxel_offset, $100
VOXEL_PIXEL2 $34, -voxel_offset, $100
VOXEL_PIXEL1 $35, -voxel_offset, $100
VOXEL_PIXEL2 $36, -voxel_offset, $100
VOXEL_PIXEL1 $37, -voxel_offset, $100
VOXEL_PIXEL2 $38, -voxel_offset, $100
VOXEL_PIXEL1 $39, -voxel_offset, $100
VOXEL_PIXEL2 $3a, -voxel_offset, $100
VOXEL_PIXEL1 $3b, -voxel_offset, $100
VOXEL_PIXEL2 $3c, -voxel_offset, $100
VOXEL_PIXEL1 $3d, -voxel_offset, $100
VOXEL_PIXEL2 $3e, -voxel_offset, $100
VOXEL_PIXEL1 $3f, -voxel_offset, $100
VOXEL_DOSKY 1, d1, d4, d3, d5
.voxel_codeend:
adda.w #(128-VOXEL_DEPTHS*2),a0
cmp.l d6,a0 ;sprawdź czy mniejsze od zera
blt.b .wrap2
lea voxel_offsets,a0 ;załaduj voxele
.wrap2:
dbra d7,.l0 ;zmniejsz i przejdź
.doblt:
lea BLTBASE,a1
;for savety reasons (faster cpus) we have to do the missing rest of the blits non parallel
.bltloop:
move.w (a5)+,d0
beq.b .bltend
move.w #$8400,$096(a1) ;turn on blitter nasty to speed up blits while waiting
.bltwait2:
btst #$0e,2(a1)
bne.b .bltwait2
move.w #$0400,$096(a1) ;turn off blitter nasty
move.w d0,BLTADAT(a1)
move.l (a5)+,BLTBPTR(a1)
move.l (a5)+,BLTCPTR(a1)
move.l (a5)+,BLTDPTR(a1)
move.l (a5)+,BLTCON0(a1)