Skeetendo

’Cause all games were better on the GBC

You are not logged in.

#1 2014-08-01 17:57:05

Torchickens
Member
Registered: 2011-01-02
Post 35/47

Bank switch function

Is there a bank switch function like the one in Red/Blue/Yellow for Gold/Silver/Crystal? I'd like to know what the pointer for it is for US Gold. JP Gold and US Crystal would be useful too but I don't need all of them, I just want to play around with the Pokémon & Trainer color test menu, which apparently is less glitchy in the Japanese version, and I want to try and make a US Gold/Silver Coin Case arbitrary code execution cheat for it.

Thanks in advance!

Last edited by Torchickens (2014-08-01 18:13:00)

Offline

#2 2014-08-01 19:16:14

Tauwasser
Member
Registered: 2010-10-16
Post 426/452

Re: Bank switch function

ld a,BANK
ld hl,ADDRESS
rst $08

cYa,

Tauwasser

Last edited by Tauwasser (2014-08-01 19:16:33)

Offline

#3 2014-08-01 19:38:33

Torchickens
Member
Registered: 2011-01-02
Post 36/47

Re: Bank switch function

Thanks. I found a bank switch pointer in the end. It was at 0010 in both Gold and Crystal, and I used it to activate the debug screen with Coin Case. :)

Code in Gold:
ld (ff00+9f),a
ld (2000),a
ret

Code in Crystal:
ld (ff00+9d),a
ld (2000),a
ret


Now all I need to do is try and make a version without glitched item quantities. (Thanks to Sanky and TheZZAZZGlitch you can bootstrap Coin Case code to stored item 2 quantity, http://glitchcity.info/wiki/index.php/Coin_Case_Glitch)

I don't exactly get the rst $08, wouldn't that make the game jump to 0008, where a jp 2E27 (in Gold) is? It works anyway, so I don't really care. Just interested.

Last edited by Torchickens (2014-08-01 19:55:48)

Offline

#4 2014-08-02 23:09:50

Tauwasser
Member
Registered: 2010-10-16
Post 427/452

Re: Bank switch function

Yes, the game goes to rst $08, that's restart vector 0x08, at 0x08. There's a call to the actual bank switching code there. The actual bank switching code makes sure to jump to a:hl preserving de and bc and preserves de and bc when the function returns.
You should usually never need to use rst $10 (the code you posted) outside of RB 0x00.
Most game functions expect the shadow rom bank register (0xFF9F in Gold) to be preserved. If you don't preserve it beforehand, you might not safely return from your sub-function, e.g. in case it gets called from code residing in two different rom banks.

cYa,

Tauwasser

Offline

Board footer

Powered by FluxBB