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: 70
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?


Frank the Fruit Fly: The Game Boy game I'm working on: http://www.atari2600land.com/gameboy/ftff.html

Offline

 

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

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

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: 70
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)


Frank the Fruit Fly: The Game Boy game I'm working on: http://www.atari2600land.com/gameboy/ftff.html

Offline

 

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

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

Re: How do I bankswitch?

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


Frank the Fruit Fly: The Game Boy game I'm working on: http://www.atari2600land.com/gameboy/ftff.html

Offline

 

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

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

Re: How do I bankswitch?

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


Frank the Fruit Fly: The Game Boy game I'm working on: http://www.atari2600land.com/gameboy/ftff.html

Offline

 

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

ISSOtm
Member
From: Somewhere in Echo RAM
Registered: 2017-04-18
Posts: 42
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: 70
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?


Frank the Fruit Fly: The Game Boy game I'm working on: http://www.atari2600land.com/gameboy/ftff.html

Offline

 

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

chris
Member
From: USA
Registered: 2016-11-27
Posts: 70
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

Frank the Fruit Fly: The Game Boy game I'm working on: http://www.atari2600land.com/gameboy/ftff.html

Offline

 

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

ISSOtm
Member
From: Somewhere in Echo RAM
Registered: 2017-04-18
Posts: 42
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: 70
Website

Re: How do I bankswitch?

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


Frank the Fruit Fly: The Game Boy game I'm working on: http://www.atari2600land.com/gameboy/ftff.html

Offline

 

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

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

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: 70
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.


Frank the Fruit Fly: The Game Boy game I'm working on: http://www.atari2600land.com/gameboy/ftff.html

Offline

 

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

chris
Member
From: USA
Registered: 2016-11-27
Posts: 70
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


Frank the Fruit Fly: The Game Boy game I'm working on: http://www.atari2600land.com/gameboy/ftff.html

Offline

 

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

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

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

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson