Commented Code Snippets

Go down

Commented Code Snippets Empty Commented Code Snippets

Post by Cubear Sat 9 Dec 2023 - 16:11

Hi, once again, I figured I should post a thread to contain useful bits of code in making a Mesen HD Audio patch.

For now, an MSU-1-like approach to playing music.

Code:

NEA_BGM_Play:

cmp #$Firsttrack_number
bcc errorfound
cmp #$Lasttrack_plus1
bcs errorfound

sta $4104 ;store track number as album number because it flows better.
pha
lda #$01
sta $4101 ;stop music.
sta $4105 ;don't need a track number, so track 1 in each album is the song.
pla
;checking for noloops
cmp #$XX ; Game over
beq noloop
cmp #$XX ; Ending
beq noloop
lda #$01
bne yesloop
noloop:
lda #$00
yesloop:
sta $4100 ;set loop
lda #$00
sta $4101 ;start song play
lda $4100 ;checking error bit
cmp #$03 ;is bit 2 (error) set
bcc errorfound ; error is 4+up, values might be 4-7 depending.

Mute Code Goes Here!!

errorfound: ;if there's an error, this should avoid muting.
rts


Last edited by Cubear on Sat 9 Dec 2023 - 18:47; edited 2 times in total
Cubear
Cubear

Commented Code Snippets Image211

Since : 2021-11-17

https://www.patreon.com/Cubear

Back to top Go down

Commented Code Snippets Empty Re: Commented Code Snippets

Post by Cubear Sat 9 Dec 2023 - 16:15

This requires a bit of a strange setup for the NEA audio but it makes the code flow nicely so it's worth it to me.

the track number is sent as the album number. the track number is always sent as 1.
like so:
Code:

<bgm>81,1,gameover.ogg
a quick reminder that in hires.txt the track/album numbers are in decimal, but in mesen your code will be dealing in hexadecimal so you'll need to convert it.

this code also has some filtering at the start, for not activating this code while SFX are passing through the hook. from my small amount of experience, NES games often use the same code to run SFX as Music, so it's probably essential to filter them out.

Cubear
Cubear

Commented Code Snippets Image211

Since : 2021-11-17

https://www.patreon.com/Cubear

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum