Gameboy Development Forum

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.

Ads

#1 2017-08-11 23:19:20

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

How do I bankswitch?

I can't find any detailed information on how to make a game larger than 32k. Can anyone help or direct me towards any?


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#2 2017-08-13 00:33:08

Tauwasser
Member
Registered: 2010-10-23
Posts: 160

Re: How do I bankswitch?

There are quite a few threads about bank switching in general and using GBDK in particular. First, do you use GBDK or rgbds? In case of GBDK, the example directory contains some example bank switching code, which is unfortunately outdate, see this thread. For RGBDS, you can check out the GitHub documentation, which is sparse, but useful.

Offline

 

#3 2017-08-13 04:20:30

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: How do I bankswitch?

I'm using GBDK. I don't really know what to do. What code do I put in my game? What should I type in when I compile? What I was planning to do was make a 1MB game instead of a 32k game.

Last edited by chris (2017-08-13 04:24:44)


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#4 2017-08-13 05:04:15

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: How do I bankswitch?

OK, I have a 64k ROM, how do I double it?


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#5 2017-08-13 06:34:38

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: How do I bankswitch?

I didn't do it correctly because it doesn't work on a real Game Boy. Help!


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#6 2017-08-13 06:38:34

ISSOtm
Member
From: Somewhere in Echo RAM
Registered: 2017-04-18
Posts: 160
Website

Re: How do I bankswitch?

You might be better reading how bankswitching works on the GB. I'll try giving you a crash course here.

Since the ROM is larger than what the GB can access, inside all >32k cartridges is a chip that allows ROM banking. Most cartridges (AFAIK) use a type of chip known as the MBC (Memory Bank Controller), Nintendo's official chip.
There are a couple chips, some of them are documented here.

I don't know how you do this with GBDK, but you should pick
- Which chip you want (usually : MBC3 if planning to use RTC features, MBC5 otherwise)
- How many banks you will use (see this chart

... and then write to the appropriate memory location to perform the bankswitch.


The French Lord Of Laziness.
Legend of Zelda and Undertale fan, I also tend to break Pokémon R/B/Y a little too much.

Twitter | Me on GCL | Discord : ISSOtm#9015 | Skype : isso.tm (I don't login anymore)

Offline

 

#7 2017-08-13 10:31:18

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: How do I bankswitch?

I got the 64k ROM working good now, but how do I make it 128k (1 MB)? I want to tell it to use 8 banks.
How will I know when I run out of room and need to use a different bank?


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#8 2017-08-14 09:20:29

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: How do I bankswitch?

So I got a 128k file, but I use 8 ROM banks and 4 RAM banks. It told me 8 RAM banks wasn't usable. I don't know what a RAM bank is. I know RAM stands for "random access memory," and ROM stands for "read-only memory," but I don't know why it's called Random access. What is random about it?

Code:

bin\lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -c -o test.o ftff20.c
bin\lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wf-bo1 -Wf-ba1 -c -o bank_1.o bank_1.c
bin\lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wf-bo2 -Wf-ba2 -c -o bank_2.o bank_2.c
bin\lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wf-bo3 -Wf-ba3 -c -o bank_3.o bank_3.c

bin\lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wf-bo1 -Wf-ba1 -c -o bank_3.o bank_3.c
bin\lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wf-bo2 -Wf-ba2 -c -o bank_3.o bank_3.c
bin\lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wf-bo3 -Wf-ba3 -c -o bank_3.o bank_3.c
bin\lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wf-bo3 -Wf-ba3 -c -o bank_3.o bank_3.c

bin\lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wl-yt5 -Wl-yo8 -Wl-ya4 -o ftff21.gb test.o bank_1.o bank_2.o bank_3.o bank_3.o bank_3.o bank_3.o bank_3.o 

pause

My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#9 2017-08-14 21:39:23

ISSOtm
Member
From: Somewhere in Echo RAM
Registered: 2017-04-18
Posts: 160
Website

Re: How do I bankswitch?

RAM banks, in this case, refer to SRAM banks : the number of banks of RAM that are present in the (emulated) cartridge that contains your game.
There are only a select number of SRAM banks you can use, which is further restricted by which MBC you're using.

As for why RAM is "random", Wikipedia is your friend.


The French Lord Of Laziness.
Legend of Zelda and Undertale fan, I also tend to break Pokémon R/B/Y a little too much.

Twitter | Me on GCL | Discord : ISSOtm#9015 | Skype : isso.tm (I don't login anymore)

Offline

 

#10 2017-08-18 16:12:19

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: How do I bankswitch?

How will I know I've used up a bank and need to start a new one?


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#11 2017-08-31 01:31:37

Tag365
Member
Registered: 2016-06-01
Posts: 41

Re: How do I bankswitch?

If you start seeing messages like "WARNING: possibly wrote twice at addr 42ce (20->21)", or if you get an error message like "ERROR: address overflow (addr 8853 >= 8000)" and your resulting ROM image is blanked out, then you have filled up a ROM bank and are now wrapping around to the beginning of the ROM bank. If this occurs you need to either start shrinking code or data or move some code or data to another ROM bank.

To change the amount of ROM banks in your game change the number in "-Wl-yo8" to a different multiple of two. Choose between 4, 8, 16, 32, 64, 128, 256, or 512 ROM banks.

The maximum amount of ROM banks you can ever possibly have in a Game Boy game is 512 banks of 16,384 bytes of data, allowing you to store up to 8 megabytes of data, or 8,388,608 bytes (this requires the MBC5 memory bank controller though). This may not seem like much, however almost all Game Boy games use less than 512 banks of ROM data. I have not yet seen a Game Boy game ROM file that is actually eight megabytes in size. For example, the English version of Pokémon Crystal Version has 128 banks of ROM data equating to 2 megabytes of ROM data. I don't think anyone will actually even reach the maximum ROM size possible of 512 banks.

You can also add a "-Wl-ya4" to the line which has "-Wl-yo8" to add SRAM (Save RAM) to your game. The maximum amount of SRAM banks is 16 banks of 8,192 bytes of data, allowing you to save up to 128 kilobytes of data equal to 131,072 bytes of data (this requires the MBC5 memory bank controller as well). This SRAM can be used for any purpose, and a battery can be added to save the SRAM data across restarts, allowing you to add a save game feature to your game, or add. Of course you don't need to have SRAM if you aren't going to save data across multiple sessions.

You are not forced to use a certain MBC for your game, but each MBC works differently so read the wiki article about the MBC controller to see a general idea of how you're supposed to access it.

By the way 128 kilobytes does not equal 1 megabyte, it equals 1 megabit of data (1 megabyte divided by eight).

Offline

 

#12 2017-09-03 21:31:19

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: How do I bankswitch?

I got messages that say "WARNING: possibly wrote twice at addr 40xx", where xx is between 00-1d, and the ROM works fine. What is wrong? My code can be downloaded in the link in my signature.


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#13 2017-10-09 04:19:57

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: How do I bankswitch?

All I want to do is compile a .gb file with 2 separate banks, but god forbid I be able to do that. I keep getting files with nothing in them. How do I make this? Please help me.
Here are the two files I want together.
http://www.atari2600land.com/gameboy/help.zip


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#14 2017-10-17 22:04:16

Tag365
Member
Registered: 2016-06-01
Posts: 41

Re: How do I bankswitch?

Sorry for not replying quickly, but I haven't come on the forum in a while. The "WARNING: possibly wrote twice at addr 40xx" messages mean that you have filled up a ROM bank and are now wrapping around to the beginning of the ROM bank. If this occurs you need to either start shrinking code or data or move some code or data to another ROM bank.

Last edited by Tag365 (2017-10-17 22:04:54)

Offline

 

#15 2017-10-19 21:00:37

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: How do I bankswitch?

I don't know how to bankswitch. I looked at various codes, tried everything I could possibly think of and nothing worked. What am I doing wrong? How do I do this?
http://www.atari2600land.com/gameboy/tr … switch.zip


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#16 2017-10-20 14:38:04

Tag365
Member
Registered: 2016-06-01
Posts: 41

Re: How do I bankswitch?

It appears that you're putting too much data into the first bank, making it spill into the second bank... I haven't coded games for the Game Boy in a while, so I will probably need to get used to it again before I can help. Also, I'm more interested in improving my wiki, more specifically at this time trying to create some new infoboxes for my wiki... so it will have to wait. Sorry.

Last edited by Tag365 (2017-10-20 14:44:00)

Offline

 

#17 2017-10-20 17:49:18

Jonas
Member
From: Frankfurt, Germany
Registered: 2016-06-06
Posts: 112
Website

Re: How do I bankswitch?

chris wrote:

I got messages that say "WARNING: possibly wrote twice at addr 40xx", where xx is between 00-1d, and the ROM works fine. What is wrong? My code can be downloaded in the link in my signature.

I currently don't have the time to have a closer look at your code (which at first glance looks quite complex). But as far as I remember, that particular error can occur if you don't declare your variables and functions properly. If you want to access a variable or function that is declared in another C file that goes to a different bank, you have to declare it as "extern" in the file that uses the variable or function. Did you do that?

For example, if you declare a UINT8 variable that is called MyNumber in Bank2.c (which goes to bank 2) and you want to use that variable in Bank0.c (which goes to bank 0), it must look like this:

Declare the variable in Bank2.c:

Code:

UINT8 MyNumber;

And include this declaration in Bank0.c:

Code:

extern UINT8 MyNumber;

Offline

 

#18 2017-10-21 11:39:44

chris
Member
From: USA
Registered: 2016-11-27
Posts: 142
Website

Re: How do I bankswitch?

Right now I have made it so it freezes once it reaches the part of the code where I tell it to change banks.


My avatar is from Nintendo Power. I miss those days, so I decided to bring them back.

Offline

 

#19 2017-10-22 07:49:01

Jonas
Member
From: Frankfurt, Germany
Registered: 2016-06-06
Posts: 112
Website

Re: How do I bankswitch?

So at least you managed to compile it.

There are countless possible reasons for the game freezing. The most probable in relation to bank switching are:

- You tried to call a function that is located in a ROM bank other than bank 0 and that bank is not switched in.

- You have code in your game that switches banks and isn't located in bank 0. That won't work. All bank switching instructions must be located in the code that goes to ROM bank 0.

- You have code in one of the upper banks that tries to access functions or data located in one of the other upper banks. That won't work either. The code in the upper ROM banks can only access functions or data which are either in the same ROM bank or in ROM bank 0.

Last edited by Jonas (2017-10-22 07:50:12)

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson