Sequencing the APU (ASM)

Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music.

Moderator: Moderators

Post Reply
VenoSci
Posts: 4
Joined: Mon Dec 03, 2018 1:56 am

Sequencing the APU (ASM)

Post by VenoSci » Mon Dec 03, 2018 2:01 am

Hey everyone!
Right now i am working on a project where i manually code music and sounds for the NES via assembly only.
Currently, my issue seems to be an inability to trigger a sequence of more than one note.
I know that once the counter reaches 0 on the note length, the flag for the note length at register $4015 will set to 0.
My code looks like this:

.inesprg 1
.ineschr 0
.inesmap 1
.inesmir 0

.bank 1
.org $FFFA
.dw 0 ;vbank
.dw Main
.dw 0

.bank 0
.org $C000

Main:

;period/frequ and also set length
One:
JSR D3

ldx $4015
cpx #%00000000
beq Two

Infiniteloop
jmp Infiniteloop

Two:
JSR D4

jmp Infiniteloop

D3:
;D3, eighth note
lda #%00000001
sta $4015
lda #%10011111
sta $4000
lda #%11111001
sta $4002
lda #%01001010
sta $4003

RTS

D4:
lda #%00000001
sta $4015
lda #%10011111
sta $4000
lda #%01111100
sta $4002
lda #%01001001
sta $4003

RTS

In my head, the code should.
1. From main, jump to my subroutine D3, where I
a. enable PU1 by writing 1 to the first bit of register $4015
b. write the duty cycle/volume/period/length data to registers $4000, $4002, and $4003
c. return to main
2. Load the value stored at $4015 to the x register
3. test the value against a correct zero-d out $4015, meaning that the timer on PU1 had counted to zero
4. Jump to D4, where i would do the same process as in step one.

On paper, i feel like my code checks out, but clearly i am missing something here, so if anyone could help me (again) that would be extremely cool.
Thanks!

User avatar
nin-kuuku
Posts: 15
Joined: Tue Jan 24, 2017 1:23 am

Re: Sequencing the APU (ASM)

Post by nin-kuuku » Mon Dec 03, 2018 3:38 am

ldx $4015
cpx #%00000000
beq Two

Infiniteloop
jmp Infiniteloop
The test goes to Infiniteloop if $4015 is nonzero (note still playing)
Try this:

test:
ldx $4015
cpx #%00000000
beq Two
jmp test

Infiniteloop
jmp Infiniteloop

VenoSci
Posts: 4
Joined: Mon Dec 03, 2018 1:56 am

Re: Sequencing the APU (ASM)

Post by VenoSci » Tue Dec 04, 2018 2:05 am

nin-kuuku wrote:
ldx $4015
cpx #%00000000
beq Two

Infiniteloop
jmp Infiniteloop
The test goes to Infiniteloop if $4015 is nonzero (note still playing)
Try this:

test:
ldx $4015
cpx #%00000000
beq Two
jmp test

Infiniteloop
jmp Infiniteloop
This works! thank you so much!

Post Reply