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.
Hi,
I have a problem with multiple banks in C. It seems, that there is not enough memory for saving the pointers.
I want to have one bank for music, and another for a picture.
Everything works fine, if I just compile without either picture or music data. (obviously it will make random data for music or picture, but the other thing then works great)
But if I try to compile with both of my .o files, it will produce an error:
C:\gbdk\proj\game>lcc -Wa-l -c -o main.o main.c C:\gbdk\proj\game>lcc -Wa-l -Wf-bo1 -c -o music.o music.c C:\gbdk\proj\game>lcc -Wa-l -Wf-bo2 -c -o picture.o picture.c C:\gbdk\proj\game>lcc -Wl-yt1 -Wl-yo2 -Wl-yp0x143=0x80 -o game.gb main.o music.o picture.o ERROR: address overflow (addr c230 >= 8000) lcc: C:\gbdk\bin/link-gbz80: No error
Well, if I change anything in code, it will also change the big address.
What is the problem? Please answer if you know an answer or if you need further data.
//Edit: Solved it using asm for big variables instead of using C-Arrays, which caused insanity.
Last edited by Endres (2011-02-08 08:37:10)
Offline
I hope that someday you'll pass by again! Or anyone else!
Because i have the same problem and can't solve it!
Could you please tell me how did you manage to solve this problem? Or could anyone tell me where this problem comes from?
Do we really need to use asm for this?
I hope that someone answer to this,
Thank you.
EDIT: Well actually i tried what you told to do! Changing C-arrays works! But why is that???
Last edited by Duh_Killer (2011-02-17 18:09:56)
Offline
Hi, I'm having the same problem and I don't know how to solve it.
Exactly what you mean when you say
//Edit: Solved it using asm for big variables instead of using C-Arrays, which caused insanity.
Can you post an example, please?
Thank you very much.
Offline
Sorry, I am not really developing for GameBoy anymore, it was only a really short demo.
I don't know exactly how I did it, but I think I used assembler to assign data into one bitrange. Because if you used C-Values, they need to be declared very extensive. If you still can't find out what I mean, please PM me back so I can look for the sourcecode.
//Edit: As someone asked me per mail, I will show you parts of my sourcecode. You firstly need to create an assembler file, for example name it data.s
In this file we declare our data using assembler:
By the way, you can use any other variable name, but mind the underscore.
.area _CODE_3 .globl _tiledata .dw _tiledata _tiledata: .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 .db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
In this example the data is a tiledata. If all tiles are defined, you can just let the file end with the last tile-line like in this shortened example.
In the C-file where we need the data, we have to declare the variable as extern as it is stored now hopefully in another bank!
extern unsigned char tiledata[];
So you also need to change the bank before setting the tiledata / do anything with the variable, and afterways change back:
SWITCH_ROM_MBC1(3); set_bkg_data(0, 173, tiledata); SWITCH_ROM_MBC1(1);
The function in which this code is should be marked as NONBANKED using this:
void drawPicture() NONBANKED {
I am not really sure if the main function is always nonbanked, it could be, but I don't know...
I also have to say, that I even forgot why we need to NONBANK it... Maybe because it should take place in the code-block.
Finally the compiling arguments are a littlebit different as C, but banking takes place as normal: (All the picture stuff including drawPicture() I got into bank 1... Don't ask ;) )
lcc -c -o main.o main.c lcc -Wf-bo1 -c -o pic.o pic.c lcc -Wa-l -Wf-bo3 -c -o data.o data.s lcc -Wl-yt1 -Wl-yo4 -Wl-yp0x143=0x80 -o game.gb main.o pic.o data.o
If anything is not clear, feel free to ask.
Last edited by Endres (2011-06-27 13:50:49)
Offline
Hi, I've tried today your code, following step by step what you say in the post.
I've organized the code exactly with the same ROM banks, to be sure I don't make some stupid mistakes.
The error while compiler the code was disappeared, but when I try to test the ROM, it freeze at start with a white screen.
I tried to remove this (I don't know what it means):
-Wl-yp0x143=0x80
And the ROM starts correctly, but when I try to call this code:
SWITCH_ROM_MBC1(3); set_bkg_data(0, 255, title); SWITCH_ROM_MBC1(1);
the ROM freezes again.
So I try to comment the set_bkg_data:
When I try to access to something with SWITCH_ROM_MBC1(3), the rom freezes in every case, whatever code I try to execute.
I really don't know what to do.
Last edited by ProGM (2011-07-01 09:56:54)
Offline
I don't know... Do you also use Bank 2? Maybe it only works then.
Offline
My problem is that I really don't know what this means:
-Wl-yp0x143=0x80
Why I have to patch a byte at 0x143? I can't understand it...
If I leave it the game freezes.
If I delete this, the game starts correctly, if i don't try to access to MBC bank 3.
If i try to switch to mbc bank 3 it freezes.
Last edited by ProGM (2011-08-18 07:21:31)
Offline
ProGM wrote:
My problem is that I really don't know what this means:
-Wl-yp0x143=0x80
Why I have to patch a byte at 0x143? I can't understand it...
ROM location 0x143 is the byte that defines whether the game is DMG Exclusive (0x00), DMG/CGB Compatible (0x80) or CGB Exclusive (0xC0). Read pag. 115 of the Programming Manual, to learn more.
Last edited by sawakita (2011-08-20 07:37:39)
Offline
Thank everyone for help, I finally did it.
Offline