Skeetendo

’Cause all games were better on the GBC

You are not logged in.

#1 2012-07-20 12:53:46

FroggestSpirit
Member
Registered: 2012-03-12
Post 8/299
Website

How to play music in RGBY

I'm currently working on turning Pokemon red into a GBC game, like Coolboyman started (credit to him for the idea). I have a large chunk done, but I keep wondering something... What routines do I need to call to get the game to play music, and continually play it? Basically the routine that updates the song, and keeps it playing. I searched around a bit with BGB, but I couldn't find the start of anything, and inserting 3 NOPs into what I thought was the call only froze the game. I want to know this because I have a jump that will tell what gameboy the game is in, so if it's not in a GBC/GBA, I was going to have it jump to a screen saying it's only for the GBC, and have music play in the background. Any help is greatly appreciated, and you will be credited.

Last edited by FroggestSpirit (2012-07-20 15:23:54)


This isn't easy to say, but…
Music and ASM hacker

Offline

#2 2012-07-20 15:15:16

Sawakita
Administrator
Registered: 2010-10-16
Post 288/364

Re: How to play music in RGBY

The location of music data is documented in the ROM Map, so you could try putting access breakpoint based on those pointers.
Also, if you're looking for sound-output routines you should check when sound registers (HRAM 0xFF10 through 0xFF26) are modified, and then backtrack from there.

FroggestSpirit wrote:

inserting a NOP into what I thought was the call only froze the game.

You know a call instruction is made up of three bytes (while a nop is just one byte long), right? NOPing the first only has good odds of screwing up the normal code flow.

Offline

#3 2012-07-20 15:22:56

FroggestSpirit
Member
Registered: 2012-03-12
Post 9/299
Website

Re: How to play music in RGBY

Thank you for the response, but I tried all these. (I probably should heave mentioned that i did 3 NOP's)
The only thing I havent tried yet, is having access breakpoints on the whole music section in ram (which is around 0xC000-0xC100 or so)...

Edit: I got this figured out. Routines 0x2071 through 0x2091 need to be ran each frame. The call at 0x2071 checks if it should load a new song.
So... to change music anytime in game, you can use this:

ld a,nn //where nn is the time it takes to fade the current song
ld (CFC8),a //sets the fade
ld a,nn //where nn is the bank of the song you want. (pallet town would be 02)
ld (C0F0),a //this will be the new song bank after the current one fades out
ld a,nn //where nn is the address to the song pointer mod 0x4000, then divided by 3 (so pallet town is 0xBA)
ld (CFC7),a //sets the song to load next, and starts fading

Use this to find the song banks and pointers

also... I thought i might drop this here. It's my notes on the Sound system so far (In RAM) if anyone wants to add this to something, or add on, please do. I don't need credit, just want to spread knowledge.

C006-Channel 1 Position in memory bank (Pulse 1)
C008-Channel 2 Position in memory bank (Pulse 2)
C00A-Channel 3 Position in memory bank (Wave)
C00C-Channel 4 Position in memory bank (Noise)

C02E-Vibrato position for channel 1 
-bit 4 tells whether vibrato is added (high part) or subtracted (low part) from the pitch (bit set is added, bit not set is subtracted)
-bit 0 is currently unknown...
C02F-Vibrato position for channel 2
C030-Vibrato position for channel 3

C03E-Pulse duty for channel 1
C03F-Pulse duty for channel 2

C03E-Vibrato delay timer for channel 1
-Counts down until 0, then the Vibrato speed/timer starts (the speed timer will not be reset to its initial value)
C03F-Vibrato delay timer for channel 2
C040-Vibrato delay timer for channel 3

C04E-Vibrato speed/timer for channel 1
-bits 7-4 are the initial value, bits 3-0 are the timer
-the timer will count down after the delay timer hits 0, and will count down until zero.
-when it reaches 0, it will switch between high and low position of the vibrato once, and reset the speed timer to the initial value
C04F-Vibrato speed/timer for channel 2
C050-Vibrato speed/timer for channel 3

C056-Vibrato depth for channel 1 
-bits 7-4 are the value added to the pitch when vibrato is in the high part
-bits 3-0 are the value subtracted from the pitch when vibrato is in the low part
C057-Vibrato depth for channel 2
C058-Vibrato depth for channel 3

C066-Pitch for channel 1 (LSB, before vibrato?)
C067-Pitch for channel 2 (LSB, before vibrato?)
C068-Pitch for channel 3 (LSB, before vibrato?)

C0B6-Timer until next note is played for channel 1
C0B7-Timer until next note is played for channel 2
C0B8-Timer until next note is played for channel 3

C0D6-Pitch for channel 1 (MSB, before vibrato?)
C0D7-Pitch for channel 2 (MSB, before vibrato?)
C0D8-Pitch for channel 3 (MSB, before vibrato?)

C0DE-Envelope for channel 1
C0DF-Envelope for channel 2
C0E0-Volume and instrument for channel 3
-bits 5-4 are volume 2=full volume (not sure how this works... thought it might be like FF1C, but didn't mess with it much)
-bits 3-0 are the instrument (defined in the ROM)

C0EE-Pointer to current song pointer (you need to multiply this by 3, and add 0x4000)(this is only here when loading a song)
C0EF-Current song Bank
C0F0-Bank of the song we are fading into

CFC7-Write the Pointer (divided by 3) to the song pointer here to fade into the song
    (EB will be multiplied by 3 to get 2C1, then 4000 is added, so if the current music bank is bank 2, it will play route 1)
CFC8-How long it takes a song to fade out
CFC9-Timer for fading the current song

If anyone wants to move this to the tutorial section, that might be a bit better.

Last edited by FroggestSpirit (2012-07-21 17:14:54)


This isn't easy to say, but…
Music and ASM hacker

Offline

Board footer

Powered by FluxBB