-
Notifications
You must be signed in to change notification settings - Fork 0
/
copper.asm
1209 lines (896 loc) · 42.9 KB
/
copper.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
;----------------------------------
;CUSTOM REGISTER MNEMONICS
;----------------------------------
DMACONR EQU $dff002
ADKCONR EQU $dff010
INTENAR EQU $dff01c
INTREQR EQU $dff01e
DMACON EQU $dff096
ADKCON EQU $dff09e
INTENA EQU $dff09a
INTREQ EQU $dff09c
BPLCON0 EQU $dff100
BPLCON1 EQU $dff102
BPLCON2 EQU $dff104
BPL1MOD EQU $dff108
BPL2MOD EQU $dff10a
DIWSTRT EQU $dff08e
DIWSTOP EQU $dff090
DDFSTRT EQU $dff092
DDFSTOP EQU $dff094
VPOSR EQU $dff004
COP1LCH EQU $dff080
CIAAPRA EQU $bfe001
CIAICR EQU $bfed01
;------------------------------------------
;GLOBAL CONSTANTS
;------------------------------------------
BACKGROUND EQU $01800022
GREENEND EQU $64
BLUEEND EQU $96
TITLESTART EQU 800 ; frame counter
TITLEEND EQU TITLESTART+300
PLANESTART EQU TITLEEND+300
HEARTTRANS EQU PLANESTART+3850 ; 3800
HEARTSTART EQU HEARTTRANS+450 ;reminder fix to 3800
HAMTRANS EQU HEARTSTART+350
HAMSTART EQU HAMTRANS+50
;------------------------------------------
;MACROS
;------------------------------------------
macro breakpoint
clr.l $100
endm
macro pushHAMpalette
move.l (a3)+,(a6)+
move.l (a3)+,(a6)+
move.l (a3)+,(a6)+
move.l (a3)+,(a6)+
move.l (a3)+,(a6)+
move.l (a3)+,(a6)+
move.l (a3)+,(a6)+
move.l (a3)+,(a6)+
move.l (a3)+,(a6)+
move.l (a3)+,(a6)+
move.l (a3)+,(a6)+
move.l (a3)+,(a6)+
move.l (a3)+,(a6)+
move.l (a3)+,(a6)+
move.l (a3)+,(a6)+
move.l (a3)+,(a6)+
endm
;macro for pushing plane to copperlist. \1: pointer to bitplane
;\2: value of HI bitplane pointer
;\3: value of LO bitplane pointer
macro pushPlane
move.l \1,d0
move.w \3,(a6)+
move.w d0,(a6)+
swap d0
move.w \2,(a6)+
move.w d0,(a6)+
endm
macro findModulo
move.w debug,d3
addq.w #2,d3
move.w d3,debug
endm
;------------------------------------------
;CODE
;------------------------------------------
init:
move.w DMACONR,d0
or.w #$8000,d0
move.w d0,oldmareq
move.w INTENAR,d0
or.w #$8000,d0
move.w d0,oldintena
move.w INTREQR,d0
or.w #$8000,d0
move.w d0,oldintreq
move.w ADKCONR,d0
or.w #$8000,d0
move.w d0,oldadkcon
move.l $4,a6 ; address for exec.library
move.l #gfxname,a1 ;string for graphics.library
moveq #0,d0 ;lib version we want. 0 = any
jsr -552(a6) ;OpenLibrary function
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 Function
jsr -270(a6) ;WaitTOF (wait for vertical blank?)
jsr -270(a6) ;WaitTOF
move.l $4,a6 ;back to exec.library
jsr -132(a6) ;Forbid multitasking
;setup keyboard
tst.b $bfed01
move.b #$88,$bfed01
and.b #$bf,$bfee01
move.w #%1000000111100000,DMACON ; Set DMA on for bitplane/copper
move.w #%0000000000011111,DMACON ; Set DMA explicitly disabled for all else
move.w #%1100000000000000,INTENA ; enable master interrupt
move.w #$1200,BPLCON0 ; Setup 1 bitplane for sprites
move.w #$0000,BPLCON1
move.w #$0000,BPL1MOD
move.w #$0000,BPL2MOD
move.w #$0024,BPLCON2 ; sprite priority
move.w #$0038,DDFSTRT
move.w #$00d0,DDFSTOP
move.w #$2c81,DIWSTRT
move.w #$f4c1,DIWSTOP
move.w #$38c1,DIWSTOP ; PAL 256 Vline screen trick
lea.l currentframe,a4
mainloop:
move.l frame,d1
addq.l #1,d1
move.l d1,frame
move.l #copper,a6
cmp.l #TITLESTART,d1
bls bunk
cmp.l #HAMSTART,d1
bhi HAMplanes
cmp.l #HAMTRANS,d1
bhi prebunk
cmp.l #HEARTSTART,d1
bhi heartbeat
cmp.l #HEARTTRANS,d1
bhi prebunk
cmp.l #PLANESTART,d1 ; insert branch to end card here somewhere
bhi plane1
move.l #title,d0
;Foreground colour palette for titleplane
;list stepping is handled by waitVB
move.l titlepos,d3
lea.l titletransition,a3
; index addressing mode: a3 + 0 + d3 (An+disp+Rn)
; for some reason can't simply do Rn(An)
move.l 0(a3,d3),(a6)+
bra playplane
; First montage planes
plane1:
move.l frame,d1
cmp.l #HAMSTART,d1 ;MESS!
bhi HAMplanes
move.w #$4200,BPLCON0
move.w #$1b8-2,BPL1MOD
move.w #$1b8-2,BPL2MOD
move.w #$0038-8,DDFSTRT
; move.w #$015e,DDFSTOP
move.l x_offset,d3 ;current xoffset. d4 = word_skip, d5 = pixel_shift
divs #16,d3
clr.l d4
move.w d3,d4
swap d3
move.l #16,d5
sub.w d3,d5
cmp.w #16,d5
bne .nowordskip
subq.l #1,d4
clr.l d5
.nowordskip
move.l d5,d6
lsl.l #4,d6
or.l d5,d6
move.w d6,BPLCON1
muls #2,d4
move.l frame,d1
move.l #montage_p1,d0
add.l d4,d0
move.w #$00e2,(a6)+
move.w d0,(a6)+
swap d0
move.w #$00e0,(a6)+
move.w d0,(a6)+
move.l #montage_p1+1*120,d0 ; 40 bytes per 320 px. 640px = 80 bytes
add.l d4,d0
move.w #$00e6,(a6)+
move.w d0,(a6)+
swap d0
move.w #$00e4,(a6)+
move.w d0,(a6)+
move.l #montage_p1+2*120,d0
add.l d4,d0
move.w #$00ea,(a6)+
move.w d0,(a6)+
swap d0
move.w #$00e8,(a6)+
move.w d0,(a6)+
move.l #montage_p1+3*120,d0
add.l d4,d0
move.w #$00ee,(a6)+
move.w d0,(a6)+
swap d0
move.w #$00ec,(a6)+
move.w d0,(a6)+
move.l #$01800000,(a6)+
move.l #$01820222,(a6)+
move.l #$01840521,(a6)+
move.l #$01860543,(a6)+
move.l #$01880a52,(a6)+
move.l #$018a0765,(a6)+
move.l #$018c0e44,(a6)+ ;UP TO HERE - colors swizzled RGB-->BGR
move.l #$018e0c62,(a6)+
move.l #$01900976,(a6)+
move.l #$01920988,(a6)+
move.l #$01940d86,(a6)+
move.l #$01960aa9,(a6)+
move.l #$01980db8,(a6)+
move.l #$019a0ccb,(a6)+
move.l #$019c0ddc,(a6)+
move.l #$019e0eee,(a6)+
move.l #$01a00eee,(a6)+
and.l #$4-1,d1
tst.b d1
bne .noupdate
move.l x_offset,d3
addq.l #1,d3
move.l d3,x_offset
.noupdate
move.l frame,d1
bra pushpalettes
HAMplanes:
move.w #$6a00,BPLCON0
move.w #$0000,BPLCON1
move.w #$0000,BPLCON2
move.w #$00c8,BPL1MOD
move.w #$00c8,BPL2MOD
move.w #$2c81,DIWSTRT
move.w #$f4c1,DIWSTOP
move.w #$38c1,DIWSTOP
move.w #$0038,DDFSTRT
move.l frame,d1
move.l #end,d0
move.w #$00e2,(a6)+
move.w d0,(a6)+
swap d0
move.w #$00e0,(a6)+
move.w d0,(a6)+
move.l #end+40,d0
move.w #$00e6,(a6)+
move.w d0,(a6)+
swap d0
move.w #$00e4,(a6)+
move.w d0,(a6)+
move.l #end+80,d0
move.w #$00ea,(a6)+
move.w d0,(a6)+
swap d0
move.w #$00e8,(a6)+
move.w d0,(a6)+
move.l #end+120,d0
move.w #$00ee,(a6)+
move.w d0,(a6)+
swap d0
move.w #$00ec,(a6)+
move.w d0,(a6)+
move.l #end+160,d0
move.w #$00f2,(a6)+
move.w d0,(a6)+
swap d0
move.w #$00f0,(a6)+
move.w d0,(a6)+
move.l #end+200,d0
move.w #$00f6,(a6)+
move.w d0,(a6)+
swap d0
move.w #$00f4,(a6)+
move.w d0,(a6)+
lea.l plane_palette_4,a3
; transition in the palettes every 8 frames
; lea.l transitionpointer,a2
; move.l (a2),a2
; and.l #$8-1,d1
; tst.b d1
; bne .noupdate
; cmp.l #$fffffffe,(a2)
; beq .endlist
; move.l (a2)+,a3
; move.l a2,transitionpointer
; bra .push
; .endlist
; lea.l plane_palette_4,a3
; .noupdate
; move.l (a2),a3
; move.l a2,transitionpointer
.push
pushHAMpalette
move.l #$fffffffe,(a6)+
bra endbars
heartbeat:
jsr heartplane
bra endbars
prebunk:
move.w #$1200,BPLCON0
move.w #$0000,BPLCON1
move.w #$0000,BPL1MOD
move.w #$0000,BPL2MOD
move.w #$0038,DDFSTRT
cmp.l #HAMTRANS,frame
bhi hamtransition
cmp.b #$10,endpos
blo bunk
sub.b #$2,endpos
bra bunk
hamtransition:
breakpoint
move.l frame,d1
move.l hampos,d2
cmpi.b #$14,d2
beq hambunk
lea.l titletransition,a3
move.l (a3,d2),d3
swap d3
subq.w #$2,d3
swap d3
move.l d3,(a6)+
and.l #$8-1,d1
tst.b d1
bne hambunk
add.l #$4,hampos
hambunk:
move.l #plane,d0
jsr pushplane
bra endbars
bunk:
; bunk plane
move.l #plane,d0
playplane:
jsr pushplane
pushpalettes:
; spritepalette - in theory shouldn't need all of this
move.l #$01a2005a,(a6)+
move.l #$01a4005a,(a6)+
move.l #$01a6005a,(a6)+
move.l #$01a8005a,(a6)+
move.l #$01aa005a,(a6)+
move.l #$01ac005a,(a6)+
move.l #$01ae005a,(a6)+
move.l #$01b0005a,(a6)+
move.l #$01b2005a,(a6)+
; Wait until greenbar at end before starting spritewalk
move.l bluepos,d2
swap d2
cmpi.b #$a0,d2
bhi bars
;tests if sprite should start moving again
cmp.l #TITLEEND+30,frame
bhi walk
; test if spritepos = middle. (64+96/4 bc offset is from back of smudge) Better way to start/stop?
move.w spritepos,d2
cmpi.b #$7c,d2
bhi sit
bra walk
sit:
jsr sitsprite
bra bars
walk:
move.l #currentframe,anim_pointer
jsr walksprite
;CopperBar routine
bars:
move.l frame,d1
move.l #BACKGROUND,d2
; copper bars
cmp.l #$64,d1 ;branch to mousetest if < 2 seconds
blt endbars
move.l redpos,d3 ; waitpos V = 2c H = 85 every frame
move.l #$01800f00,d0
jsr createbar ;creates a bar
cmp.l #$c8,d1 ;frame 150 green bar
blt endbars
move.l #$018000f0,d0
move.l greenpos,d3
jsr createbar
cmp.l #$12c,d1
blt endbars
move.l #$0180000f,d0
move.l bluepos,d3
jsr createbar
endbars:
move.l #$fffffffe,(a6)+
; INPUT CHECKS
mouse:
btst.b #6,CIAAPRA
beq exit
btst.b #7,CIAAPRA
beq exit
keyboard:
;keyboard test - only check for q key
move.b $bfec01,d0 ; move contents of keyboard register into scratch
btst #0,d0
not.b d0
lsr.b #1,d0 ; bit magic stuff idk
cmpi.b #$10,d0
beq exit
bne _notKey
_notKey: ;if it's not the key we want we need to wait 85us. SILLY
bset #6,$bfee01
move.l VPOSR,d0
lsr.l #8,d0
and.w #$01ff,d0
moveq #2-1,d1
_keyboardWait85us:
move.l VPOSR,d2
lsr.l #8,d2
and.w #$01ff,d2 ;wait 2 raster lines?
cmp.w d0,d2
beq _keyboardWait85us
move.w d2,d0
dbf d1,_keyboardWait85us
bclr #6,$bfee01
;VERTICAL BLANKING
waitVB:
move.l VPOSR,d0 ; busy loop - how to improve? Look into IRQ
and.l #$1ff00,d0
cmp.l #300<<8,d0
bne waitVB
move.w spritepos,d2
cmpi.b #$b0,d2
bhs _setbackflag
bra _startbars
_setbackflag:
move.l frame,d1
cmpi.l #HEARTTRANS,d1
bls .setflag
move.b #$00,backflag
neg.b bardecrement
move.b #$fe,targetbarpos
bra _startbars
.setflag
move.b #$ff,backflag
_startbars:
;StartBars
move.l frame,d1
cmpi.l #$64,d1
blo cop
cmpi.l #HEARTTRANS+100,d1
bls .continuebars
move.b #$00,backflag
.continuebars
;test if its time to transition into the titlescreen, or transition out
;could probably be a subroutine.
cmpi.l #TITLEEND,d1
bhi fadeout
cmpi.l #TITLESTART,d1
bls _red
and.l #16-1,d1
tst.b d1
bne _red
;increment foreground colour index. Check if > length of list (16)
move.l titlepos,d3
cmpi.b #$10,d3
bne _dontendfade
beq _endfade
_endfade:
move.l #$10,titlepos
bra _red
_dontendfade:
move.l titlepos,d3
addq.b #$4,d3
move.l d3,titlepos
bra _red
;fade the title screen OUT
fadeout:
move.l titlepos,d3
cmpi.b #$0,d3
bne _hasntfaded
beq _hasfaded
_hasfaded:
move.l #$0,titlepos
bra _red
_hasntfaded:
move.l titlepos,d3
subq.b #$4,d3
move.l d3,titlepos
; Handles horizontal scrolling of copperbar
_red:
move.l redpos,d3
swap d3
cmp.b targetbarpos,d3
blo _green
sub.b bardecrement,d3 ; subtract 2, scroll horizontally from right
swap d3
move.l d3,redpos
bra _green
_green:
; test if its time to come on screen yet
move.l frame,d1
cmp.l #$c8,d1
blo cop
;test if we need to move greenbar to the end
move.b backflag,d2
cmpi.b #$ff,d2
beq green_totheend
move.l greenpos,d3 ; change hpos for green
swap d3
cmpi.b #GREENEND,d3
blo _blue
green_totheend:
move.l greenpos,d3
swap d3
cmp.b targetbarpos,d3
blo _blue
sub.b bardecrement,d3
swap d3
move.l d3,greenpos
_blue:
move.l frame,d1
cmp.l #$12c,d1
blo cop
cmpi.b #$ff,d2
beq blue_totheend
move.l bluepos,d3 ; change hpos for blue
swap d3
cmpi.b #BLUEEND,d3
blo cop
blue_totheend:
move.l bluepos,d3
swap d3
cmp.b targetbarpos,d3
blo cop
sub.b bardecrement,d3
swap d3
move.l d3,bluepos
cop:
move.l #copper,a6
move.l a6,COP1LCH
bra mainloop
exit:
move.w #$7fff,DMACON
move.w oldmareq,DMACON
move.w #$7fff,INTENA
move.w oldintena,INTENA
move.w #$7fff,INTREQ
move.w oldintreq,INTREQ
move.w #$7fff,ADKCON
move.w oldadkcon,ADKCON
move.l oldcopper,COP1LCH
move.l gfxbase,a6
move.l oldview,a1
jsr -222(a6)
jsr -270(a6)
jsr -270(a6)
move.l $4,a6
jsr -138(a6)
rts
;---------------------------------------------------------------
;SUBROUTINES
;---------------------------------------------------------------
; sit sprite routine
; Steps through a sitting animation routine.
; initially checks if this is the first entry into routine (i.e. state change walking -> sitting)
; and updates the anim_pointer and a4 register to head of list, so that it reads the correct animation sequence
;
; steps through the framelist every 8 ticks. When at the end of the sit-down, hold for a little bit and then transition to
; sit-up state.
;consume d1 as framecount
;consume a4 as framelist pointer
;consume a2 as frame pointer
;consume a3 as scratch
;consume d2 as flag
sitsprite:
move.b spritetransflag,d2 ; test if this is first entry (i.e. state change) to subroutine,
cmpi.b #$ff,d2 ; need to setup animpointer if so
bne .notfirst
move.l #sit_currentframe,anim_pointer
lea.l anim_pointer,a3
move.l (a3),a4
move.b #$00,spritetransflag
.notfirst
and.l #$8-1,d1 ; increment frames only every 8 ticks
tst.b d1
bne .update
addq.l #$4,a4
cmp.l #$fffffffe,(a4)
bne .update
move.l frame,d1
cmpi.l #TITLEEND-((14*8)-30),d1 ;14 frames x 8 ticks per frame, minus the offset for walking to begin again
blo .sub
lea.l anim_pointer,a3 ; compare anim_pointer against reverse_sit_currentframe to see if we want to sit up
move.l #reverse_sit_currentframe,a2 ; or start walking again
cmp.l (a3),a2
beq .sub
move.l #reverse_sit_currentframe,anim_pointer ; state change from sit-down to sit-up
lea.l anim_pointer,a3
move.l (a3),a4
bra .update
.sub
subq.l #$4,a4 ; hold frame at end (sitting)
.update
move.l (a4),a2
jsr updatesprite
move.l (a4),a2
jsr writesprites
move.l frame,d1
rts
;walksprite routine
;consume d1 as framecount
;consume a4 as framelist pointer
;consume a2 as frame pointer
;consume a3 as scratch
;consume d2 as spritepos
walksprite:
and.l #$4-1,d1
tst.b d1
bne .noreset
addq.l #$4,a4
cmp.l #$fffffffe,(a4)
bne .noreset
lea.l anim_pointer,a3
move.l (a3),a4
.noreset:
move.w spritepos,d2
move.l frame,d1
and.l #$2-1,d1
bne .nomove
move.b backflag,d3
cmpi.b #$ff,d3
beq .moveback
.move:
move.w spritepos,d2 ;probably want to do a cmp to ensure we don't loop
addq.b #$1,d2
bra .nomove
.moveback:
move.w spritepos,d2
cmpi.b #$40,d2
blo .nomove
subq.b #$2,d2
.nomove:
move.w d2,spritepos
.noupdate:
move.l (a4),a2
jsr updatesprite
move.l (a4),a2
jsr writesprites
move.l frame,d1
rts
; Draws a copper bar of a given height and width on screen
; createbar(d3,d0,a6)
; - d3 is WAITPOS value - defines vertical and horizontal start of bar
; - d0 is the colour of the bar. This operates on the background palette
; - a6 is a pointer to the copperlist - make sure this doesn't overwrite/is overwritten by existing copper instructions!
; - d2 is background color
; -d4,d5 are used as scratch, and are recovered at RTS
; - a0 is used as scratch - VALUE IS LOST!
; OUT:
; -Instructions in copperlist corresponding to a single raster bar
createbar: ;d3 is WAITPOS pointer, d0 is colour. a6 is copperlist.
;subroutine initialise - store old register states in mem
move.l #barstorage,a0
move.l d0,(a0)+
move.l d3,(a0)+
move.l d4,(a0)+
move.l d5,(a0)+
move.l d2,(a6)+ ;move background into color00
move.l #$0a,d4 ;setup loop counter - this corresponds to height of bar
inline
_loop:
move.l d3,(a6)+ ;move waitpos into copperlist
move.l d0,(a6)+ ;move new colour into copperlist
swap d3 ;swap waitpos to fffe[xxxx]
move.l d3,d5
move.b endpos,d5 ;d5 stores the endpos
swap d5 ;swap back around to [xxff]fffe
move.l d5,(a6)+
move.l d2,(a6)+ ;move back to correct colour
add.w #$0100,d3 ;change VPOSwait
swap d3
subq.b #$1,d4 ;decrement loop
cmp.w #$0,d4
bne _loop
einline
;cleanup and restore registers
move.l #barstorage,a0
move.l (a0)+,d0
move.l (a0)+,d3
move.l (a0)+,d4
move.l (a0)+,d5
rts
; writes sprite instructions to copperlist
; consumes d0,d1 as scratch
; uses d2 as SPRxPTx register pointer starting from register 0
; uses a2 as sprite STRUCT pointer
; a3 is scratch register recovery - It is discarded!
; uses a6 as copperlist pointer
writesprites:
move.l #barstorage,a3
move.l d0,(a3)+
move.l d1,(a3)+
move.l d2,(a3)+
move.l a2,(a3)+
move.b #$6,d1
move.l #$01200122,d2 ; SPR0PTL.SPR0PTH packed into a long.
inline
_spriteloop:
move.l (a2)+,d0 ; move sprite pointer to scratch and increment
move.w d2,(a6)+ ; move SPRxPTH pointer (HI)?
move.w d0,(a6)+ ; move low bits of sprite address
swap d2 ;swap to LO word register
swap d0 ;swap to LO word pointer
move.w d2,(a6)+ ; move SPRxPTL pointer (LO)
move.w d0,(a6)+ ; move HI bits of sprite address
; increments sprite register pointers. Because pointers need to be written into copperlist IN THIS ORDER:
; xPTH, HI_word
; xPTL, LO_word
; and n+1PTL = nPTL + 4 bytes and n+1PTH = nPTH + 4 bytes:
; we add $00040004 to our packed long to get to the next set of sprite registers
swap d2
add.l #$00040004,d2 ;increment sprite register pointers.
subq.b #$1,d1 ;test counter
cmp.b #$0,d1
bne _spriteloop
einline
; recover registers
move.l #barstorage,a3
move.l (a3)+,d0
move.l (a3)+,d1
move.l (a3)+,d2
move.l (a3)+,a2
rts
; Update pos of every tile in given sprite struct
; consumes d0 as newpos word of format $VVHH
; consumes a3 as pointer to spritestruct
; consumes a2 as pointer to spritestruct
; Loops through struct until it sees end-words: $fffffffe - broken?
updatesprite:
move.w spritepos,d0
inline
_updateloop:
move.l (a2)+,a3 ;frame ---> fx_0
move.w d0,(a3)
addq.b #$8,d0 ;increment HPOS by 8 so that tiles stitch nicely
cmp.l #$fffffffe,a3
bne _updateloop
einline
rts
;BITPLANE ZERO
; TODO:
; Rewrite for any bitplane(s).
;consumes d0 as bitplane pointer
pushplane: