From d6e7623463eab7691f148f9b84048dad593e3ba5 Mon Sep 17 00:00:00 2001 From: ikari Date: Wed, 29 Dec 2010 15:12:09 +0100 Subject: [PATCH] MSU1 AV player demo --- snes/msu1/Makefile | 2 +- snes/msu1/const.a65 | 42 +++++++++++++++++++++++++++++-------- snes/msu1/dma.a65 | 6 ++++-- snes/msu1/header.a65 | 27 ++++++++++++------------ snes/msu1/main.a65 | 4 ++-- snes/msu1/msu1.a65 | 12 ++++++++--- snes/msu1/reset.a65 | 10 ++++++--- snes/msu1/spc.a65 | 50 ++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 119 insertions(+), 34 deletions(-) create mode 100644 snes/msu1/spc.a65 diff --git a/snes/msu1/Makefile b/snes/msu1/Makefile index 6687d8b..b858f83 100644 --- a/snes/msu1/Makefile +++ b/snes/msu1/Makefile @@ -1,4 +1,4 @@ -OBJS = header.ips reset.o65 main.o65 data.o65 const.o65 dma.o65 msu1.o65 # gfx.o65 # vars.o65 +OBJS = header.ips reset.o65 main.o65 data.o65 const.o65 dma.o65 msu1.o65 spc.o65 # gfx.o65 # vars.o65 all: msu1vid.sfc diff --git a/snes/msu1/const.a65 b/snes/msu1/const.a65 index 6f3f9bd..c75d2e5 100644 --- a/snes/msu1/const.a65 +++ b/snes/msu1/const.a65 @@ -14,11 +14,9 @@ hdma_blank .byt 40 ; h/vscroll: write to $210d twice, write to $210e twice (mode 3) ; adjust hscroll and vscroll to split one tilemap row into two display rows -; (tilemap memory saving measure) -hdma_scroll .byt 40 - .word 0 - .word 511 - .byt 16 +; in conjunction with 16x16 tiles this reduces the effective tilemap size +; to 288 bytes +hdma_scroll .byt 56 .word 0 .word 152+255 .byt 16 @@ -51,13 +49,13 @@ hdma_scroll .byt 40 ; tilemap address switch: write to $2107 once (mode 0) ; last row of tilemap is located elsewhere due to size hdma_tilemap .byt 40 - .byt $3c + .byt $bc .byt 127 - .byt $3c + .byt $bc .byt 1 - .byt $3c + .byt $bc .byt 1 - .byt $7c + .byt $fc .byt 0 ; tilemap part 1 (goes to VRAM 7F00-7FFF) @@ -89,3 +87,29 @@ tilemap .word $0000, $0000, $0002, $0004, $0006, $0008, $000a, $000c tilemap2 .word $0000, $01c0, $01c2, $01c4, $01c6, $01c8, $01ca, $01cc .word $01ce, $01e0, $01e2, $01e4, $01e6, $01e8, $01ea, $0000 +spcaddr .word $0100 ; target address +spcexec .word $0100 ; execute address +spclen .byt 100 ; length + +spccode .byt $e8, $6c ; - MOV A, #$6c + .byt $c4, $f2 ; MOV $f2, A + .byt $e8, $20 ; MOV A, #$20 + .byt $c4, $f3 ; MOV $f3, A + .byt $78, $20, $f3 ; CMP $f3, #$20 + .byt $d0, $f3 ; BNE - + + .byt $e8, $2c ; - MOV A, #$6c + .byt $c4, $f2 ; MOV $f2, A + .byt $e8, $00 ; MOV A, #$20 + .byt $c4, $f3 ; MOV $f3, A + .byt $78, $00, $f3 ; CMP $f3, #$20 + .byt $d0, $f3 ; BNE - + + .byt $e8, $3c ; - MOV A, #$6c + .byt $c4, $f2 ; MOV $f2, A + .byt $e8, $00 ; MOV A, #$20 + .byt $c4, $f3 ; MOV $f3, A + .byt $78, $00, $f3 ; CMP $f3, #$20 + .byt $d0, $f3 ; BNE - + + .byt $2f, $fe ; - BRA - diff --git a/snes/msu1/dma.a65 b/snes/msu1/dma.a65 index 07b3028..bc2d54a 100644 --- a/snes/msu1/dma.a65 +++ b/snes/msu1/dma.a65 @@ -49,10 +49,12 @@ setup_hdma: sty $4332 sta $4334 - ldx #184 ;Set IRQ trigger to line 184 + ldx #185 ;Set IRQ trigger to line 185 stx $4209 ; - lda #$a1 ;NMI + V-Count IRQ + Auto Joypad Read + lda #$21 ;V-Count IRQ + Auto Joypad Read sta $4200 + lda #$0e + sta $420c rts diff --git a/snes/msu1/header.a65 b/snes/msu1/header.a65 index b04b8f6..becc5e6 100644 --- a/snes/msu1/header.a65 +++ b/snes/msu1/header.a65 @@ -9,23 +9,22 @@ RESET: jmp @GAME_MAIN NMI_16bit: - php - rep #$30 : .al : .xl - pha: phx: phy: phd: phb - jsl @NMI_ROUTINE - rep #$30 : .al : .xl -int_exit: - plb: pld: ply: plx: pla - plp + pha + sep #$20 : .as + lda $4210 ; ack interrupt + lda #$0e + sta $420c ; enable HDMA ch. 1-3 + pla rti IRQ_16bit: - php - rep #$30 : .al : .xl - pha: phx: phy: phd: phb - jsl @IRQ_ROUTINE - rep #$30 : .al : .xl - bra int_exit + pha + sep #$20 : .as + lda #$01 + sta isr_flag + lda $4211 ;Acknowledge irq + pla + rti ;error vectors ABT_8bit: ABT_16bit: diff --git a/snes/msu1/main.a65 b/snes/msu1/main.a65 index d48da89..a95c0b9 100644 --- a/snes/msu1/main.a65 +++ b/snes/msu1/main.a65 @@ -6,6 +6,7 @@ GAME_MAIN: jsr killdma jsr waitblank jsr snes_init + jsr spc_upload lda #$01 sta $420d ; fast cpu jsr setup_gfx @@ -148,8 +149,7 @@ snes_init: stz $420a ; stz $420b ; stz $420c ; - lda #$01 - sta $420d ; FAAAAAST + stz $420d ; FAAAAAST lda #$8f sta $2100 ;INIDISP: force blank stz $2101 ; diff --git a/snes/msu1/msu1.a65 b/snes/msu1/msu1.a65 index b3bac82..7c29b23 100644 --- a/snes/msu1/msu1.a65 +++ b/snes/msu1/msu1.a65 @@ -9,6 +9,10 @@ msu1init: stx MSU_SEEK_BANK - bit MSU_STATUS bmi - + + stx MSU_TRACK +- bit MSU_STATUS + bvs - ldx #$0000 stx $2116 @@ -27,6 +31,8 @@ msu1loop: sep #$20 : .as rep #$10 : .xl stz dispcnt + lda #$01 + sta MSU_CONTROL msu1loop2 lda isr_flag beq msu1loop2 @@ -45,7 +51,6 @@ msu1loop2 cmp #$02 bne msu1loop2 - stz dispcnt ;load palette stz $2121 lda #$22 @@ -56,6 +61,7 @@ msu1loop2 stx $4305 lda #$01 sta $420b + stz dispcnt lda charptr bne ptr2 ptr1 @@ -64,10 +70,10 @@ ptr1 sta charptr ldx #$0000 stx $2116 - bra msu1loop2 + jmp msu1loop2 ptr2 stz $210b stz charptr ldx #$4000 stx $2116 - bra msu1loop2 + jmp msu1loop2 diff --git a/snes/msu1/reset.a65 b/snes/msu1/reset.a65 index dd93eeb..8d7b91c 100644 --- a/snes/msu1/reset.a65 +++ b/snes/msu1/reset.a65 @@ -11,16 +11,20 @@ ; NMI - called on VBlank NMI_ROUTINE: sep #$20 : .as + pha lda $4210 ; ack interrupt - lda #$0e - sta $420c ; enable HDMA ch. 1-3 +; lda #$0e +; sta $420c ; enable HDMA ch. 1-3 + pla rtl ; IRQ - called when triggered IRQ_ROUTINE: sep #$20 : .as + pha + lda $4211 ;Acknowledge irq lda #$01 sta isr_flag - lda $4211 ;Acknowledge irq + pla rtl diff --git a/snes/msu1/spc.a65 b/snes/msu1/spc.a65 new file mode 100644 index 0000000..4526b5a --- /dev/null +++ b/snes/msu1/spc.a65 @@ -0,0 +1,50 @@ +spc_upload: + rep #$20 : .al + sep #$10 : .xs + + lda #$bbaa ; wait for IPL bootup +- cmp $2140 + bne - + + ; IPL protocol: $2142-3 = target address + lda @spcaddr + sta $2142 + ldx #$01 + stx $2141 + ldx #$cc + stx $2140 + ; wait for echo +- cpx $2140 + bne - + + ; init counters + sep #$20 : .as + ldx #$00 ; sequence counter + lda @spclen + tay ; countdown +spc_loop + lda @spccode, x ; fill data byte + sta $2141 ; write data... + stx $2140 ; ...and write sequence counter +- cpx $2140 ; wait for echo from IPL + bne - + inx ; increment sequence counter... + dey + bne spc_loop ; if not, do it again + +spc_end + rep #$20 : .al + lda @spcexec + sta $2142 + stz $2141 ; data = 0 + ldx $2140 + inx + inx + stx $2140 ; send sequence end / execute +- cpx $2140 ; wait for last echo + bne - + + sep #$20 : .as + rep #$10 : .xl + + rts ; and done!