Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
Pages: 1
I'm developing a game on the Game Boy using GBDK. The game, which uses the MBC1 microchip, has more than 16 kilobytes of code and thus cannot fit entirely in bank zero. I have recently moved a few of the save functions to bank one, and I am already running out of space again on bank zero to fit code in. Most of the functions in the game switch to banks with tileset data and map data, in order to set up the background map.
Tauwasser wrote:
MrElephant wrote:
Okay it is still not working---am I allowed to post my code on here so we can dissect it? It might be a little long, and I don't know if there is a way to put spoiler boxes on here.
Took a quick look over your code.
Code:
int bank1(int i) BANKED { ... if(key==J_B){ SWITCH_ROM_MBC1(0); <----------------------------- } }You should never ever use SWITCH_ROM_MBCX in a bank other than 0 unless you know what you're doing. Now, with MBC1 you're lucky, because rom bank 0x00 cannot be selected, performing SWITCH_ROM_MBC1(0) has the same effect as SWITCH_ROM_MBC1(1) and in your case that means it has no effect, because your code is already in bank 0x01. On MBC5, SWITCH_ROM_MBC5(0) will actually map rom bank 0x00 to 0x4000-0x7FFF and code will just execute from the same address in bank 0x00, likely crashing and/or misbehaving.
So, how do you read data from other banks while executing in a bank higher than zero without crashing or malfunctioning?? Is it even possible to do that without crashing?!? As I already said, most of the functions in the game access banks with tileset data and map data. I want to somehow move most of the code in these functions to bank one or higher.
Offline
You call a function that's in bank 0 to do it for you. That function can then restore the original bank and return safely.
Online
nitro2k01 wrote:
You call a function that's in bank 0 to do it for you. That function can then restore the original bank and return safely.
What if you're out of space in bank zero? Is it possible to get the data in other banks or is that the only way?
Offline
Most likely, you can move something out of bank 0. Otherwise, you could theoretically move code into RAM and run it there. Maybe with feasible in C, but easy with asm.
Online
Yeah, err, what nitro2k01 said. Also consider that I have only once seen a commercial game fully use bank 0x00. If you somehow manage to have so much functionality in bank 0x00 that it's full, maybe you need to follow a different approach altogether.
Offline
Tauwasser wrote:
Also consider that I have only once seen a commercial game fully use bank 0x00. If you somehow manage to have so much functionality in bank 0x00 that it's full, maybe you need to follow a different approach altogether.
Then what is the average size of bank zero in commercial games? I'm confused on how commercial games don't use bank zero fully, they must have code on other banks.
Offline
Bank 0 is always 16 kiB but that doesn't mean you can't leave empty space in it.
Online
Most games just have a bunch of functions like
@1234: push af ld a, [CURBANK] push af ld a, $03 ld [$2000], a call $5678 pop af ld [$2000], a pop af ret
in ROM bank 0x00. Sure, some other stuff, too. But code that is very long and doesn't access other bank data frequently can just live somewhere else and might only need to be callable through bank 0x00. Then you have the generic "load byte from other bank" code that takes a bank, an address, and returns the byte there to a caller in another bank. It requires some planning, but it's usually very doable to cut down on bank 0x00 size.
Last edited by Tauwasser (2016-06-24 16:11:15)
Offline
Great! Now I know how to make my games larger! Thank you for your information.
Offline
Let's not forget the writes to CURBANK in that code!
@1234: push af ld a, [CURBANK] push af ld a, $03 ld [CURBANK],a ld [$2000], a call $5678 pop af ld [CURBANK],a ld [$2000], a pop af ret
Online
Lol yeah, seems I futzed that up
Offline
Pages: 1