- Code: Select all
; pietro gagliardi 20-22 march 2011
; ya se chuan shuo
ControllerAddress equ $FF2000
MaxSong equ $FF
StopSong equ $00
ori #$700,sr
move.l #$C00000,a5
move.l #$C00004,a6
move.w #$8006,(a6) ; HV latch enable
move.w #$8134,(a6) ; MD, display off, no DMA, 224 lines
move.w #$8228,(a6) ; plane A at $A000
move.w #$833E,(a6) ; window at $F800
move.w #$8406,(a6) ; plane B at $C000
move.w #$851E,(a6) ; sprites at $3C00
move.w #$8700,(a0) ; background color: line 0 color 0
move.w #$8B00,(a0) ; disable external int
move.w #$8D0B,(a0) ; H scroll at $2C00
move.w #$8F02,(a0) ; skip words each write
; TODO see if I can use DMA to clear VRAM
move.w #$FFFF,d0
move.l #$40000000,(a6)
clearvramloop:
move.w #0,(a5)
dbf d0,clearvramloop
lea numbers(pc),a1
move.l #$40000000,(a6)
move.w #numbers_end-numbers,d0
lsr.w #1,d0
subq.w #1,d0
copynumloop:
move.w (a1)+,(a5)
dbf d0,copynumloop
bra.w numbers_end
numbers:
dcb.l 8,$00000000 ; blank tile!
dc.l $01111110
dc.l $10000001
dc.l $10000001
dc.l $10000001
dc.l $10000001
dc.l $10000001
dc.l $10000001
dc.l $01111110
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $11111110
dc.l $00000001
dc.l $00000001
dc.l $01111110
dc.l $10000000
dc.l $10000000
dc.l $10000000
dc.l $01111111
dc.l $11111110
dc.l $00000001
dc.l $00000001
dc.l $01111110
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $11111110
dc.l $10000001
dc.l $10000001
dc.l $10000001
dc.l $01111111
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $01111111
dc.l $10000000
dc.l $10000000
dc.l $01111110
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $11111110
dc.l $01111111
dc.l $10000000
dc.l $10000000
dc.l $11111110
dc.l $10000001
dc.l $10000001
dc.l $10000001
dc.l $01111110
dc.l $11111111
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $01111110
dc.l $10000001
dc.l $10000001
dc.l $01111110
dc.l $10000001
dc.l $10000001
dc.l $10000001
dc.l $01111110
dc.l $01111110
dc.l $10000001
dc.l $10000001
dc.l $01111111
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $11111110
dc.l $01111110
dc.l $10000001
dc.l $10000001
dc.l $11111111
dc.l $10000001
dc.l $10000001
dc.l $10000001
dc.l $10000001
dc.l $10000000
dc.l $10000000
dc.l $10000000
dc.l $10000000
dc.l $11111111
dc.l $10000001
dc.l $10000001
dc.l $11111111
dc.l $11111111
dc.l $10000000
dc.l $10000000
dc.l $10000000
dc.l $10000000
dc.l $10000000
dc.l $10000000
dc.l $11111111
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $00000001
dc.l $11111111
dc.l $10000001
dc.l $10000001
dc.l $11111111
dc.l $11111111
dc.l $10000000
dc.l $10000000
dc.l $11111111
dc.l $10000000
dc.l $10000000
dc.l $10000000
dc.l $11111111
dc.l $11111111
dc.l $10000000
dc.l $10000000
dc.l $11111111
dc.l $10000000
dc.l $10000000
dc.l $10000000
dc.l $10000000
numbers_end:
move.l #$C0000000,(a6) ; load palette
move.l #$00000EEE,(a5)
clr.l d0
clr.l d4
clr.l d7
move.w #$8174,(a6) ; display on, enable VInt
andi #~$700,sr
mainloop:
stop #$2500 ; wait for VInt
bsr.w DoControllers
bsr.w PrintNumber
bra.s mainloop
DoControllers:
move.b (ControllerAddress).l,d0
btst #2,d0 ; left?
bne.s CtlLeft
btst #3,d0 ; right?
bne.s CtlRight
btst #4,d0 ; B
bne.s StopMus
btst #6,d0 ; A
bne.s PlayMus
rts
CtlLeft:
tst.b d4
beq.s noleft
subq.b #1,d4
noleft:
rts
CtlRight:
cmpi.b #MaxSong,d4
beq.s noright
addq.b #1,d4
noright:
rts
StopMus:
move.b #StopSong,d7
bra.w DoPlay
PlayMus:
move.b d4,d7
bra.w DoPlay
PrintNumber:
ori #$700,sr
move.l #$60000002,(a6)
move.b d4,d7
lsr.b #4,d7
and.w #$F,d7
addq.w #1,d7
move.w d7,(a5)
move.b d4,d7
and.w #$F,d7
addq.w #1,d7
move.w d7,(a5)
andi #~$700,sr
rts
DoPlay:
; THIS PART IS GAME SPECIFIC!
Thanks to Sik for help with the VDP registers.
To use this, you need to know where the game loads its sound driver (optional... you could also just jump into this code after the game loads everything), reads controllers, plays a song. I think you need to wait more than one frame to prevent control from moving too fast. Let me know if you need any help with this; I should probably strip some stuff out and make a more template-y version.