forked from uhef/amiga-assembly-crashcourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.s
1172 lines (1060 loc) · 31.4 KB
/
example.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
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
include registers.s
; DMA (chip-ram) memory is 0x0 - 0x7FFFF
; TODO(lucasw) but what about the sky/mountains memory below?
; can I allocate this below instead of doing this?
; The regular memory may contain many variations on the ship or bugs,
; but the real chip memory just needs what needs to be accessed
; on short notice
SHIP_DST EQU $25000
FIREBALL0A_DST EQU SHIP_DST+end_ship_data-ship_data
FIREBALL0B_DST EQU FIREBALL0A_DST+end_ship_data-ship_data
FIREBALL0C_DST EQU FIREBALL0B_DST+end_ship_data-ship_data
FIREBALL1A_DST EQU FIREBALL0C_DST+end_fireball_data-fireball_data
FIREBALL1B_DST EQU FIREBALL1A_DST+end_fireball_data-fireball_data
FIREBALL1C_DST EQU FIREBALL1B_DST+end_fireball_data-fireball_data
BUG1_DST EQU FIREBALL1C_DST+end_fireball_data-fireball_data
BUG2_DST EQU BUG1_DST+end_bug_data-bug_data
DUMMY_DST EQU BUG2_DST+end_bug_data-bug_data
SCREEN_WIDTH EQU 320
PF_WIDTH EQU 640
init:
; store data in hardwareregisters ORed with $8000
;(bit 15 is a write-set bit when values are written back into the system)
move.w BASEADD+DMACONR,d0
or.w #$8000,d0
move.w d0,olddmareq
move.w BASEADD+INTENAR,d0
or.w #$8000,d0
move.w d0,oldintena
move.w BASEADD+INTREQR,d0
or.w #$8000,d0
move.w d0,oldintreq
move.w BASEADD+ADKCONR,d0
or.w #$8000,d0
move.w d0,oldadkcon
move.l $4,a6
move.l #gfxname,a1
moveq #0,d0
jsr -552(a6)
move.l d0,gfxbase
move.l d0,a6
move.l 34(a6),oldview
move.l 38(a6),oldcopper
move.l #0,a1
jsr -222(a6) ; LoadView
jsr -270(a6) ; WaitTOF
jsr -270(a6) ; WaitTOF
move.l $4,a6
jsr -132(a6) ; Forbid
; allow all sprites to collide with each other
move.b #$f0,BASEADD+CLXCON+1
; setup displayhardware to show a 640x200px 3 bitplanes playfield
; with zero horizontal scroll and zero modulos
; move.w #$3200,BPLCON0 ; three bitplanes, single playfield
move.w #$6600,BASEADD+BPLCON0 ; three bitplanes, dual playfield
move.w #$0000,BASEADD+BPLCON1 ; horizontal scroll 0
; move.w BPLCON2,d0 ; moving BPLCON2 seems to change it
move.b #$1f,BASEADD+BPLCON2 ; priority
; move.w #$0004,BASEADD+BPLCON2 ; priority
; horizontal arrangement- given that the 3 color channels are on one row
; bplmod = (width of the playfield * (num bitplanes) - width screen) / 8
; move.w #$00c8,BPL1MOD ; odd modulo
; move.w #$00c8,BPL2MOD ; even modulo
; vertical arrangement
; bplmod = (width of the playfield - width screen) / 8
move.w #(PF_WIDTH-SCREEN_WIDTH)/8,BASEADD+BPL1MOD ; odd modulo
move.w #(PF_WIDTH-SCREEN_WIDTH)/8,BASEADD+BPL2MOD ; even modulo
move.w #$2c91,BASEADD+DIWSTRT ; DIWSTRT - topleft corner (2c81)
move.w #$f8c1,BASEADD+DIWSTOP ; DIWSTOP - bottomright corner (c8d1)
move.w #$0038,BASEADD+DDFSTRT ; DDFSTRT
move.w #$00d0,BASEADD+DDFSTOP ; DDFSTOP
;move.w #%1000000111100000,BASEADD+DMACON ; DMA set ON
move.w #%1000000100000000,BASEADD+DMACON ; DMA set ON
move.w #%0000000000011111,BASEADD+DMACON ; DMA set OFF
move.w #%1100000000000000,BASEADD+INTENA ; IRQ set ON
move.w #%0011111111111111,BASEADD+INTENA ; IRQ set OFF
; TODO(lucasw) make this general for loading any sprite
; the ship sprite
move.l #SHIP_DST,a1
move.l #ship_data,a2
move.w #32,d0
jsr copy_data
move.w #$0080,player_ship ; y1
move.w #$00a0,player_ship+4 ; y2
move.w #$0050,player_ship+2 ; x1
move.w #$0060,player_ship+6 ; x2
move.l #FIREBALL0A_DST,a1
move.l #fireball_data,a2
move.w #8,d0
jsr copy_data
move.l #FIREBALL0B_DST,a1
move.l #fireballb_data,a2
move.w #8,d0
jsr copy_data
move.l #FIREBALL0C_DST,a1
move.l #fireballc_data,a2
move.w #8,d0
jsr copy_data
move.w #$0070,fireball0 ; y1
move.w #$0078,fireball0+4 ; y2
move.w #$00f8,fireball0+2 ; x1
move.w #$0108,fireball0+6 ; x2
move.w #$0000,fireball0+8 ; counter
move.l #FIREBALL0A_DST,fireball0+12 ; memory address
move.l #FIREBALL0B_DST,fireball0+16 ; memory address
move.l #FIREBALL0C_DST,fireball0+20 ; memory address
move.l #FIREBALL1A_DST,a1
move.l #fireball_data,a2
move.w #8,d0
jsr copy_data
move.l #FIREBALL1B_DST,a1
move.l #fireballb_data,a2
move.w #8,d0
jsr copy_data
move.l #FIREBALL1C_DST,a1
move.l #fireballc_data,a2
move.w #8,d0
jsr copy_data
move.w #$0060,fireball1 ; y1
move.w #$0068,fireball1+4 ; y2
move.w #$00f8,fireball1+2
move.w #$0108,fireball1+6
move.w #$0000,fireball1+8 ; counter
move.l #FIREBALL1A_DST,fireball1+12 ; current frame
move.l #FIREBALL1B_DST,fireball1+16 ; frame 1
move.l #FIREBALL1C_DST,fireball1+20 ; frame 2
;;;;;;;;;;;;;;;;;;;
; Enemy 0
move.l #BUG1_DST,a1
move.l #bug_data,a2
move.w #16,d0
jsr copy_data
; position the bug
; works
move.w #$0090,enemy0+2 ; x1
move.w #$00a0,enemy0+6 ; x2
move.w #$0060,enemy0 ; y1
move.w #$0070,enemy0+4 ; y2
move.w #$0003,enemy0+8 ; counter
; these glitch the screen up - because using words with non-aligned odd address
move.b enemy0+1,BUG1_DST ; VSTART
move.b enemy0+3,BUG1_DST+1 ; HSTART
move.b enemy0+5,BUG1_DST+2 ; VSTOP
; Enemy 1
move.l #BUG2_DST,a1
move.l #bug_data,a2
move.w #16,d0
jsr copy_data
move.w #$00a0,enemy1+2 ; x1
move.w #$00b0,enemy1+6 ; x2
move.w #$0080,enemy1 ; y1
move.w #$0090,enemy1+4 ; y2
; these glitch the screen up - because using words with non-aligned odd address
move.b enemy1+1,BUG2_DST ; VSTART
move.b enemy1+3,BUG2_DST+1 ; HSTART
move.b enemy1+5,BUG2_DST+2 ; VSTOP
;;;;;;;;;;;;;;;;;;;;;
bra skip_copy_data
copy_data:
copy_data_loop:
move.l (a2)+,(a1)+
dbra d0,copy_data_loop
rts
; the dummy sprite
move.l #$00000000,DUMMY_DST
skip_copy_data:
; set up all blit sources with valid address, even if not used
move.l #sky_data,BLTAPTH
move.l #sky_data,BLTBPTH
move.l #sky_data,BLTCPTH
move.l #sky_data,BLTDPTH
; trying the blit here results in no changes on screen, but
; the system crashes after exiting the program.
;bra skip_blit
test_blit:
;move.w #$8040,DMACON
; doa single blit before entering the main loop
bltx = 16/8 ; byte not pixel position
blty = 32
blth = 16
bltw = 128
jsr blit_wait
move.l #$01ff0000,BLTCON0
move.l #mountains_data+PF_WIDTH/8*blty+bltx,BLTDPTH
;move.l #sky_data+PF_WIDTH*bltx+blty,BLTDPTH
move.l #(PF_WIDTH-bltw)/8,BLTDMOD
move.l #blth*64+bltw/16,BLTSIZE ; bltw needs word size, not byte size
;jsr blit_wait
;rts
skip_blit:
main_loop:
; increment frame count
addq.l #1,frame
;move.l frame,d1
;addq.l #1,d1
;move.l d1,frame
; write instructions into copperlist
; TODO(lucasw) couldn't this be done once if they aren't changing?
; start setting up copper list
move.l #copper_list,a6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; mountains bitplanes
move.l frame,d1
lsr #7,d1 ; scroll slowly
move.l #sky_data,d0
add.w d1,d0 ; scroll 8 pixels per increment
move.w #BPL2PTL,d2
move.w #BPL2PTH,d3
jsr load_bpl
move.l #sky_data+16000,d0
add.l d1,d0
move.w #BPL4PTL,d2
move.w #BPL4PTH,d3
jsr load_bpl
move.l #sky_data+32000,d0
add.l d1,d0
move.w #BPL6PTL,d2
move.w #BPL6PTH,d3
jsr load_bpl
;;;;;;;;;;;;;;;;;;;;;;
; mountains bitplanes
move.l pf_scroll_x,d1
lsr #3,d1 ; divide by 8 for byte scroll value
move.l #mountains_data,d0
add.w d1,d0 ; scroll 8 pixels when scroll_x/8 increments
move.w #BPL1PTL,d2
move.w #BPL1PTH,d3
jsr load_bpl
move.l #mountains_data+16000,d0
add.w d1,d0
move.w #BPL3PTL,d2
move.w #BPL3PTH,d3
jsr load_bpl
move.l #mountains_data+32000,d0
add.w d1,d0
move.w #BPL5PTL,d2
move.w #BPL5PTH,d3
jsr load_bpl
bra skip_load_bpl
load_bpl: ; d0 is the movement amount, d2 is the BPLxPTL, d3 is BPLxPTH
; a6 is the current copper address, d1 should be untouched
move.w d2,(a6)+ ; LO-bits of start of bitplane
move.w d0,(a6)+ ; go into $0e2 BPL1PTL Bitplane pointer 1 (low 15 bits)
swap d0
move.w d3,(a6)+ ; HI-bits of start of bitplane
move.w d0,(a6)+ ; go into $0e0 BPL1PTH Bitplane pointer 1 (high 5 bits)
rts
skip_load_bpl
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; colors, last 3 characters/12 bits are rgb
; TODO(lucasw) replace with inc() command to get externally generated palett
; playfield 1 - foreground mountains
;move.w #COLOR00,(a6)+
;move.w $0000,(a6)+
move.l #COLOR00<<16+$0000,(a6)+
move.l #COLOR01<<16+$0000,(a6)+
move.l #COLOR02<<16+$0235,(a6)+ ; color 2
move.l #COLOR03<<16+$0e01,(a6)+ ; color 3
move.l #COLOR04<<16+$0545,(a6)+ ; color 4
move.l #COLOR05<<16+$0a36,(a6)+ ; color 5
move.l #COLOR06<<16+$0569,(a6)+ ; color 6
move.l #COLOR07<<16+$0b83,(a6)+ ; color 7
; playfield 2 - background sky
move.l #COLOR08<<16+$0000,(a6)+ ; color 8
move.l #COLOR09<<16+$0fff,(a6)+ ; color 9
move.l #COLOR10<<16+$0112,(a6)+ ; color 10
move.l #COLOR11<<16+$0324,(a6)+ ; color 11
move.l #COLOR12<<16+$0446,(a6)+ ; color 12
move.l #COLOR13<<16+$0545,(a6)+ ; color 13
move.l #COLOR14<<16+$0946,(a6)+ ; color 14
move.l #COLOR15<<16+$0659,(a6)+ ; color 15
; sprite 0,1 - the ship
move.l #COLOR16<<16+$0000,(a6)+ ; color 16
move.l #COLOR17<<16+$0300,(a6)+ ; color 17
move.l #COLOR18<<16+$0b43,(a6)+ ; color 18
move.l #COLOR19<<16+$0d98,(a6)+ ; color 19
; sprite 2,3 the fireball
move.l #COLOR20<<16+$0000,(a6)+ ; color 20
move.l #COLOR21<<16+$0fd0,(a6)+ ; color 21
move.l #COLOR22<<16+$0ffc,(a6)+ ; color 22
move.l #COLOR23<<16+$0fff,(a6)+ ; color 23
; sprite 4,5 - enemy bugs
move.l #COLOR24<<16+$0000,(a6)+ ; color 25
move.l #COLOR25<<16+$0437,(a6)+ ; color 26
move.l #COLOR26<<16+$084a,(a6)+ ; color 27
move.l #COLOR27<<16+$06ab,(a6)+ ; color 29
; sprite 6,7 - enemy bugs?
; TODO(lucasw) fill these colors in
; TODO(lucasw) unless wanting to cycle colors, could store the address
; at end of static copper list and then use it below for dynamic copper list stuff?
bra skip3
move.l #32,d0 ; Number of iterations
move.l #$07,d1 ; Current row wait
move.l #sin32_15,a0 ; Sine base
move.l frame,d2 ; Current sine
scrollrows:
; Wait for correct offset row
move.w d1,(a6)+
move.w #$fffe,(a6)+
; Fetch sine from table
move.l d2,d3
and.l #$1f,d3
move.b (a0,d3),d4
; Transform sine to horizontal offset value
move.l d4,d5
lsl.l #4,d4
add.l d4,d5
; Add horizontal offset to copperlist - BPLCON1
move.w #BPLCON1,(a6)+
move.w d5,(a6)+
; Proceed to next row that we want to offset
add.l #$500,d1
; Move to next sine position for next offset row
addq.w #1,d2
subq.w #1,d0
bne scrollrows
skip3:
; scroll every row the same
; the mountains
move.w #BPLCON1,(a6)+ ; BPLCON1
move.l pf_scroll_x,d2
and.w #$000f,d2 ; only take last four bits for scroll within 1 byte
move.w #$f,d3
; reverse direction because scrolling right
sub.w d2,d3
; scroll playfield2 slowerr
; the sky
move.l frame,d2
lsr #4,d2 ; slow down the scrolling
and.w #$000f,d2
move.w #$f,d4
; reverse direction because scrolling right
sub.w d2,d4
; combine the two scroll values
lsl.w #4,d4
add.w d4,d3
move.w d3,(a6)+
; blitter - TODO(lucasw) is this a good place in the frame to do this?
; TODO(lucasw) do it all in the copper list
bra after_blit ; disable this copper blit for now
; instead of an animation just a single frame for now
;bsr blit_wait
;cmp.b #1,do_blit
;bne.b after_blit
;move.b #0,do_blit
; bsr blit_wait only the cpu has to do a blit_wait?
move.w #BLTCON0,(a6)+
; move.w #$09f0,(a6)+
move.w #$0100,(a6)+
move.w #BLTCON1,(a6)+
move.w #$0000,(a6)+
move.w #BLTAFWM,(a6)+
move.w #$ffff,(a6)+
move.w #BLTALWM,(a6)+
move.w #$ffff,(a6)+
move.w #BLTAMOD,(a6)+ ; A modulo : vertical arrangement so set to zero
move.w #0,(a6)+
move.w #BLTDMOD,(a6)+ ; D modulo : playfield width/8-blitwidth*2
; blitw EQU 32
blitw EQU 128
blith EQU 32
; move.w #(PF_WIDTH-32)/8,(a6)+
move.w #(PF_WIDTH-blitw)/8,(a6)+
move.l #explosion_data,a0
move.w #BLTAPTH,(a6)+
move.l (a0),(a6)+
move.w #BLTAPTL,(a6)+
move.w 2(a0),(a6)+
; calculate byte offset into mountains_data
;clr.l d0
;add.w 2(a0),d0 ; x position for the explosion
;clr.l d1
;add.w (a0),d1 ; y position for the explosion
;mulu.w #PF_WIDTH/8,d1
;add.l d0,d1
;move.l #mountains_data,d2
;add.l d1,d2
;move.l pf_scroll_x,d3
;lsr.l #3,d3 ; only want byte address, worry about pixel offsets later
;add.l d3,d2
;move.l d2,BLTDPTH
; width and height
; height is in lines, width is in words
move.l #mountains_data,a0
add.l #$20,(a0)
move.w BLTDPTH,(a6)+
move.w (a0),(a6)+
move.w BLTDPTL,(a6)+
move.w 2(a0),(a6)+
; these two are supposed to trigger the blit, but nothing is happening currently
move.w #BLTSIZE,(a6)+
; height shifted 6 bits left + last 6 bits for width in words
move.w #blith*64+blitw/16,(a6)+
after_blit:
; end of copperlist
move.l #$fffffffe,(a6)+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; detect key press, use special keys for now
;cmp.b #$37,SKEYS ; shift left
;beq move_left
;cmp.b #$3d,SKEYS ; shift right
;beq move_right
;move.w #0,d1
;bra done_keys
;move_left:
; move.w #1,d1
; bra done_keys
;move_right:
; move.w #1,d1
;done_keys:
; debug command, use w 0 100 2 to set a breakpoint here
;clr.w $100
; detect joystick left/right
; move.w BASEADD+JOY1DAT,d2
; btst.l #9,d2
; bne move_left
; btst.l #1,d2
; bne move_right
; bra done_joy
; jmp done_joy_left_right
; http://eab.abime.net/showthread.php?t=75779&page=3
move.l BASEADD+JOY0DAT,d0
move.l d0,d1
add.l d1,d1
eor.l d0,d1
; d2 is the left/right move value
move.w #0,d2
; d3 is the up/down move value
move.w #0,d3
test_left:
btst.l #9,d0
bne move_left
bra test_right
move_left:
add.w #-1,d2
test_right:
btst.l #1,d0
bne move_right
bra test_up
move_right:
add.w #1,d2
test_up:
btst.l #9,d1
bne move_up
bra test_down
move_up:
add.w #-$2,d3
test_down:
btst.l #1,d1
bne move_down
bra done_joy
move_down:
add.w #$2,d3
done_joy:
update_ship:
add.w d2,player_ship+2 ; x
add.w d2,player_ship+6
add.w d3,player_ship ; y
add.w d3,player_ship+4
; limit movement to scrreen
; this only works for slow movement, if movement is fast
; need to test the player position moving changing it
x_test_left: ; $48 to $d8
cmp.w #$48,player_ship+2
bgt x_test_right
move.w #$48,player_ship+2
move.w #$58,player_ship+6
x_test_right:
cmp.w #$d8,player_ship+2
blt y_test_top
move.w #$d8,player_ship+2
move.w #$e8,player_ship+6
y_test_top:
cmp.w #$30,player_ship
bgt y_test_bottom
move.w #$30,player_ship
move.w #$50,player_ship+4
y_test_bottom:
cmp.w #$d0,player_ship
blt done_xy_test
move.w #$d0,player_ship
move.w #$f0,player_ship+4
done_xy_test:
;;;;;;;;;;;;;;;;;;;;;;;
collision_detection:
move.w BASEADD+CLXDAT,d0
; ship bug collision
btst.l #10,d0
bne ship_bug_collision
bra test_fireball_bug_collision
ship_bug_collision:
move.l #explosion_audio_data,BASEADD+AUD0LCH
move.w #end_explosion_audio_data-explosion_audio_data,BASEADD+AUD0LEN
move.w #447,BASEADD+AUD0PER
move.w #60,BASEADD+AUD0VOL
move.w #1,audio0 ; stop whatever is playing
move.w #1,audio0+2 ; start this next
move.w #70,audio0+4 ; play this for this long
; sub.w #10,player_ship+2
move.w #$48,player_ship+2
move.w #$58,player_ship+6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
test_fireball_bug_collision:
bra fireball_bug_collision ; temp always test for collisions with rect-rect code
btst.l #12,d0
bne fireball_bug_collision
bra done_collision
fireball_bug_collision:
; TODO(lucasw) this needs to be a double for loop- loop through all
; fireballs, which loop through all enemies
test_enemy_collision:
; unrolled loop
move.l #fireball1,a1
move.l #enemy0,a0
jsr rect_rect_detect
; the lea method is faster than jsr, but maybe can only be used
; from near enough code?
; http://www.easy68k.com/paulrsm/doc/trick68k.htm
;lea #test_enemy0_collision_return,a0
;jmp rect_rect_detect
jsr test_enemy_collision_return
move.l #enemy1,a0
jsr rect_rect_detect
jsr test_enemy_collision_return
move.l #fireball0,a1
move.l #enemy0,a0
jsr rect_rect_detect
jsr test_enemy_collision_return
move.l #enemy1,a0
jsr rect_rect_detect
jsr test_enemy_collision_return
bra done_collision
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
test_enemy_collision_return:
; a0 the enemy
; a1 the fireball
cmp.b #$1,d0
bne done_enemy_collision
; there was a collision, play a sound effect and start an explosion animation
move.l #bug_death_audio_data,BASEADD+AUD0LCH
move.w #end_bug_death_audio_data-bug_death_audio_data,BASEADD+AUD0LEN
move.w #447,BASEADD+AUD0PER
move.w #60,BASEADD+AUD0VOL
move.w #1,audio0 ; stop whatever is playing
move.w #1,audio0+2 ; start this next
move.w #70,audio0+4 ; play this for this long
move.l (a0),blit_yx
move.b #1,do_blit
; move the enemy off screen
move.w #$100,2(a0) ; x1
move.w #$110,6(a0) ; x2
jsr new_y_position
;move.b frame,(a2)
;move.b frame+$10,4(a2)
; reset fireball if it hits an enemy
; TODO(lucasw) make a subroutine for this- or is that slower?
move.w #$0110,2(a1)
move.w #$0120,6(a1)
move.w #$0,(a1)
move.w #$8,4(a1)
done_enemy_collision:
rts
;;;;;;;;;;;;;;;;;;;;;;;;;
rect_rect_detect:
; ~~a0 is return address~~
; a0 is rect 1 with y1 x1 y2 x2 in sequential words
; a1 is rect 2 with y1 x1 y2 x2 in sequential words
; d0 will be set to 1 if there is overlap
; can't dow cmp.w 6(a1),2(a2) , the second arg can't be displaced
move.w (a1),d1
move.w 4(a0),d2
;move.w #5,d1
;move.w #4,d2
; cmp.w 4(a1),d1 ; fewer instructions, TODO(lucasw) do this once it is working
cmp.w d1,d2
blt rect_no_overlap
move.w (a0),d1
move.w 4(a1),d2
cmp.w d1,d2
blt rect_no_overlap
move.w 2(a1),d1
move.w 6(a0),d2
cmp.w d1,d2
blt rect_no_overlap
move.w 2(a0),d1
move.w 6(a1),d2
cmp.w d1,d2
blt rect_no_overlap
; there was an overlap
move.b #$1,d0
rts
;jmp (a0)
rect_no_overlap:
move.b #$0,d0
rts
;jmp (a0)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
done_collision:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
update_fire:
; mouse/joy button 2 - TODO(lucasw) capture in interrupt?
move.b #0,d0 ; don't fire a new fireball
; has the joystick button been pressed - rising edge?
move.b old_ciaapra,d1
move.b CIAAPRA,d2
move.b d2,old_ciaapra
not.b d1
and.b d2,d1
; can't do btst.b on d registers, so instead of btst.b #7:
and.b #%10000000,d1
tst.b d1
beq update_fireballs
move.b #1,d0 ; do fire a new fireball
update_fireballs:
; copy the ship location first
move.l #fireball0,a0
jsr test_fireball
move.l #fireball1,a0
jsr test_fireball
bra done_fireballs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; subroutine launch/update fireball
test_fireball:
cmp.w #$00f0,2(a0)
bge test_shoot_fireball
move_fireball:
add.w #2,2(a0)
add.w #2,6(a0)
add.w #1,8(a0)
;rts ; temp disable of not working animation below
; update fireball animation
; error 3005: reloc type 1, size 16, mask 0xffffffffffffffff (symbol frame + 0x920) not supported
; move.l #frame,d3 ; this was wrong anyway, but gives the above error without a line number
move.w 8(a0),d3
and.l #$0f,d3
cmp.l #$08,d3
bge fireball_frame2
fireball_frame1:
move.l 16(a0),12(a0) ; use frame1
rts
fireball_frame2:
move.l 20(a0),12(a0) ; use frame2
rts
test_shoot_fireball:
cmp.b #1,d0
bne done_test_fireball
shoot_fireball:
; shoot the fireball at the current ship location
move.b #0,d0
move.l player_ship,(a0)
move.l player_ship,4(a0)
;add.w #2,fireball0+2 ; offset the hstart to the front of the ship
add.w #12,(a0) ; offset the start position to so fire from middle of ship
add.w #12,4(a0) ; offset the start position to so fire from middle of ship
add.w #8,4(a0) ; add height of fireball
; play shoot sound
move.l #shoot_audio_data,BASEADD+AUD0LCH
move.w #end_shoot_audio_data-shoot_audio_data,BASEADD+AUD0LEN
;move.w #3000,BASEADD+AUD0LEN
move.w #447,BASEADD+AUD0PER
; move.w #%111111,BASEADD+AUD0VOL
; move.w #$20,BASEADD+AUD0VOL
move.w #60,BASEADD+AUD0VOL
move.w #1,audio0 ; stop whatever is playing
move.w #1,audio0+2 ; start this next
move.w #33,audio0+4 ; play this for this long
; move.w #$8000+$200+1,BASEADD+DMACON ; DMA set ON - TODO(lucasw) doesn't the $200 turn all dma on?
done_test_fireball:
rts
; end launch/update fireball subroutine
done_fireballs:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;move.b frame,d0
;and.b #$01,d0
; lsr.w #3,d0
;sub.w #0,enemy0 ; y1
;add.w #1,enemy0+2 ; x1
;sub.w #0,enemy0+4 ; y2
;sub.w #1,enemy0+6 ; x2
update_enemies:
; TODO(lucasw) enemy0+8 should be xvel, +10 should be yvel
sub.w #1,enemy0+2 ; x1
sub.w #1,enemy0+6 ; x2
sub.w #1,enemy1+2 ; x1
sub.w #1,enemy1+6 ; x2
init_enemy_y_movement:
; update y infrequently
move.l frame,d1
and.l #$3,d1
cmp.l #$3,d1
bne update_enemy_y_movement
add.b #1,enemy0+8 ; enemy counter
add.b #1,enemy1+8 ; enemy counter
update_enemy_y_movement:
move.l #signed_sin32_15,a0
; TODO(lucasw) subroutine
move.l #$00000000,d1
move.b enemy0+8,d1
ext.w d1
and.w #$1f,d1
move.l #$00000000,d0
move.w d1,d0
move.b (a0,d1),d0
ext.w d0 ; sign extend
add.w d0,enemy0 ; y1
add.w d0,enemy0+4 ; y2
move.b enemy1+8,d1
ext.w d1
and.w #$1f,d1
move.b (a0,d1),d0
ext.w d0 ; sign extend
add.w d0,enemy1 ; y1
add.w d0,enemy1+4 ; y2
end_enemy_y_movement:
move.l #enemy0,a0
jsr test_reset_enemy
move.l #enemy1,a0
jsr test_reset_enemy
bra done_update_enemies
test_reset_enemy: ; $48 to $d8
cmp.w #$0038,2(a0)
bgt enemy_x_test_done
move.w #$00f8,2(a0)
move.w #$0108,6(a0)
; TODO(lucasw) respawn somewhere random in y
;move.w frame,d0
;and.w #$3f,d0
enemy_x_test_done:
jsr ey_test
rts
; TODO(lucasw) don't make this a subroutine if nothing else needs it
ey_test:
ey_test_top:
cmp.w #$0030,(a0)
bgt.w ey_test_bottom
move.w #$0030,(a0)
move.w #$0040,4(a0)
bra edone_xy_test
ey_test_bottom:
cmp.w #$e0,(a0)
blt edone_xy_test
move.w #$e0,(a0)
move.w #$f0,4(a0)
edone_xy_test
rts
new_y_position:
add.w #$43,(a0)
and.w #$ff,(a0)
move.w (a0),4(a0)
add.w #$10,4(a0)
rts
done_update_enemies:
; TODO(lucasw) need to reposition the sprites at right of screen,
; they can wrap around visually but the rect rect collision will fail because the high
; order bits aren't colliding.
update_audio:
update_audio0:
; wait some counts before turning off audio
cmp.w #0,audio0
; if audio0 goes negative then that will end the counting
beq audio0_off
bgt.w dec_audio0_off
; now wait some counts before turning on audio (otherwise the sound may not reset to start)
cmp.w #0,audio0+2
beq audio0_on
bgt.w dec_audio0_on
audio0_off:
move.w #-1,audio0
move.w #$0001,BASEADD+DMACON ; DMA audio OFF
dec_audio0_off:
sub.w #1,audio0
bra done_update_audio0
audio0_on:
move.w #-1,audio0+2 ; don't play again the next time
move.w #$8001,BASEADD+DMACON
move.w audio0+4,audio0 ; turn this newly turned on sound off in this many counts
move.w #-1,audio0+4 ; don't play again the next time
dec_audio0_on:
sub.w #1,audio0+2
bra done_update_audio0
done_update_audio0:
mouse_test:
; if mousebutton/joystick 1 or 2 pressed then exit
; mouse/joy button 1
btst.b #6,CIAAPRA
beq exit
; btst.b #7,CIAAPRA
; beq exit
update_scroll:
move.l frame,d0
lsr.l #1,d0 ; scroll 1 pixel every other frame
move.l d0,pf_scroll_x
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Wait for vertical blanking before taking the copper list into use
wait_vertical_blank:
move.l BASEADD+VPOSR,d0
and.l #$1ff00,d0
cmp.l #300<<8,d0
bne wait_vertical_blank
; this crashes the amiga on exit, also doesn't draw anything
;jsr test_blit
; setup sprite registers, have to be setup every vblank
; TODO(lucasw) but this isn't the vblank? or it is still vblank
; because before jumping to mainloop there was a wait for vblank.
move.l #SHIP_DST,BASEADD+SPR0PTH ; Sprite 0 pointer = $25000 actually used sprite
move.l #DUMMY_DST,BASEADD+SPR1PTH ; Sprite 1 pointer = $30000 dummy sprite
move.l fireball0+12,BASEADD+SPR2PTH ; Sprite 2 pointer = $25000 actually used sprite
move.l fireball1+12,BASEADD+SPR3PTH ; Sprite 2 pointer = $25000 actually used sprite
move.l #BUG1_DST,BASEADD+SPR4PTH
move.l #BUG2_DST,BASEADD+SPR5PTH
move.l #DUMMY_DST,BASEADD+SPR6PTH ; Sprite 6 pointer = $25000 actually used sprite
move.l #DUMMY_DST,BASEADD+SPR7PTH ; Sprite 7 pointer = $25000 actually used sprite
;;;;
; TODO(lucasw) may not want the blitting done here, wait for vblank instead? or some other time?
bra skip_blit_wait
blit_wait:
tst BASEADD+DMACONR ; A1000 compatibility
.waitblit:
btst #6,BASEADD+DMACONR
bne.s .waitblit
rts
skip_blit_wait:
;;;;;;;;;;;;;;;;
; seems like this should be done during vblank unless re-using sprites
update_sprite_registers:
move.b player_ship+1,SHIP_DST ; VSTART
move.b player_ship+3,SHIP_DST+1 ; HSTART
move.b player_ship+5,SHIP_DST+2 ; VSTOP
move.b enemy0+1,BUG1_DST ; VSTART
move.b enemy0+3,BUG1_DST+1 ; HSTART
move.b enemy0+5,BUG1_DST+2 ; VSTOP
move.b enemy1+1,BUG2_DST ; VSTART
move.b enemy1+3,BUG2_DST+1 ; HSTART
move.b enemy1+5,BUG2_DST+2 ; VSTOP
move.l fireball0+12,a0
move.b fireball0+1,(a0) ; VSTART
move.b fireball0+3,1(a0) ; HSTART
move.b fireball0+5,2(a0) ; VSTOP
move.l fireball1+12,a0
move.b fireball1+1,(a0) ; VSTART
move.b fireball1+3,1(a0) ; HSTART
move.b fireball1+5,2(a0) ; VSTOP
; TODO add the higher bits to SPRxCTL?
; Take copper list into use - but only after above updates have been made?
move.l #copper_list,a6
move.l a6,BASEADD+COP1LCH ; this is automatically used at beginning of each vertical blank
skip4:
;sub.b #1,BUG1_DST+1
;sub.b #1,BUG2_DST+1
;;;;;;;;;;;;;
bra main_loop
exit:
; exit gracefully - reverse everything done in init
move.w #$7fff,BASEADD+DMACON
move.w olddmareq,BASEADD+DMACON
move.w #$7fff,BASEADD+INTENA
move.w oldintena,BASEADD+INTENA
move.w #$7fff,BASEADD+INTREQ
move.w oldintreq,BASEADD+INTREQ
move.w #$7fff,BASEADD+ADKCON
move.w oldadkcon,BASEADD+ADKCON
move.l oldcopper,BASEADD+COP1LCH
move.l gfxbase,a6
move.l oldview,a1
jsr -222(a6) ; LoadView
jsr -270(a6) ; WaitTOF
jsr -270(a6) ; WaitTOF
move.l $4,a6
jsr -138(a6) ; Permit
; end program
rts
; *******************************************************************************
; *******************************************************************************
; DATA
; *******************************************************************************
; *******************************************************************************
; storage for 32-bit addresses and data
CNOP 0,4
oldview: dc.l 0
oldcopper: dc.l 0
olddmareq: dc.w 0
oldintreq: dc.w 0
oldintena: dc.w 0
oldadkcon: dc.w 0
frame:
dc.l 0
; storage for 16-bit data
CNOP 0,4
pf_scroll_x:
dc.l 0
CNOP 0,4
blit_yx
dc.w 0 ; y
dc.w 0 ; x
do_blit:
dc.b 0
CNOP 0,4
old_ciaapra:
dc.l 0