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.


#1 2015-10-29 14:32:48

New member
Registered: 2015-10-29
Posts: 2

SDCC + multiple rom banks

Been playing around with SDCC and hit a bit of a stumbling point.
I've got everything up and running using a single rom bank so I was looking into a multi bank setup so when that time comes I'll be able to quickly move into the larger memory space.
SDCC seems to make this pretty simple, just add a `#pragma bank 1` at the top of your source file and the compiler knows to put that code into `.area _CODE_1` instead of `.area _CODE`.
The problem I'm running into is at the linking stage. The linker is wanting to put `_CODE_1` at 0xC131. The makebin tool included with SDCC seems to have a hardcoded rom size value of 32kb (and obviously the 0xC131 start of code_1 is outside of that).
I've gotten around this to get 2 bank support (`_CODE` and `_CODE_1`) by telling the linker to place the `_CODE_1` section at location 0x4000. By doing this banking works as expected, the bank 1 code is placed correctly at 0x4000 and the rom can be loaded and run.

So the next step is say I want 3 banks of rom (`_CODE`, `_CODE_1`, `_CODE_2`). I've gotten around the 32kb rom size in makebin by just ignoring the max size value and creating whatever size I want via a flag. But where does the bank 2 code area need to be placed in the eventual rom? I was thinking I'd have to move the `_CODE_1` section out of 0x4000 as that's where the hardware (or emulator) will have to swap the banked code into so because of this I tried setting the code location for code_1 and code_2 to 0x10000 and 0x140000 respectively in the resulting rom. This fails miserably, the code is actually placed at 0x0000 and 0x4000.

At this point I'm assuming that either I'm doing something dumb or the multi bank support in SDCC is not great...
I may also be making some terrible assumptions about how multi bank roms are laid out.

Any thoughts would be greatly appreciated!



#2 2015-10-29 14:47:26

New member
Registered: 2015-10-29
Posts: 2

Re: SDCC + multiple rom banks

Specifically my linker call looks something like this (from my makefile)


$(SDCC) -mgbz80 --no-std-crt0 --data-loc 0xc0a0 -Wl-b_CODE_1=0x10000 -Wl-b_CODE_2=0x14000  \ 
-l $(GBDK_LIB)/gb.lib $(GBDK_LIB)/crt0.rel path/to/.rel1 path/to/.rel2 /path/to/.rel3 -o $(OBJ_DIR)/output.ihx

Last edited by joekarl (2015-10-29 14:47:55)



#3 2015-10-30 12:22:47

a cat
Registered: 2014-07-27
Posts: 98

Re: SDCC + multiple rom banks

sorry i don’t know the answer to your problem but
the people here probably will:

a cat in need of knowledge!!



Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson