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.
Hello, guys.
I've been programming a small rom using C and GBDK. I hadn't have problem getting it to run all my code, load sprites, tiles and backgrounds or anything at all.
Now I'm trying to load different maps in different banks, as otherwise I get an overflow, as is expected.
Problem is I don't think It's compiling in different banks at all (supposedly it is, but i still get exactly the same overflow as if i was loading everything in the bank 0. data also can be accessed without even calling switch_rom_bank() or SWITCH_ROM_MBC1() wich hints that everything is in bank0).
and I can't finish understanding the documentation I read on the subject.
Here's how I'm trying to do it:
maincode.c:
#include <stdio.h> #include <gb\gb.h> extern unsigned char map[]; void main(){ etc... }
map.c:
unsigned char map[] = { 0x00,0x01,0x01,0x00,0x06,0x00,0x00,0x00,0x00,0x00,etc... }
make.bat:
c:\gbdk\bin\lcc -c -o main.o main.c c:\gbdk\bin\lcc -Wf-bo1 -c -o bnk1.o map.c c:\gbdk\bin\lcc -Wl-yt2 -Wl-yo16 -Wl-ya4 -o test.gb main.o bnk1.o
And i get something like this:
ERROR: address overflow (addr 84f6 >= 8000)
c:\gbdk\bin\lcc: c:\gbdk\bin/link-gbz80: No error
What am I missing?
All your help is welcome.
thanks.
by the way, i'm using gbdk3-2.95-3
Last edited by vslean (2014-08-10 18:27:54)
Offline
That error is saying that you are trying to put too much data into one bank. Try with a smaller array. Oh, and the problem could also be that you didn't made the array a const. Try with "const unsigned char map[] = ..." to see if that's the problem.
Last edited by AntonioND (2014-08-11 05:25:19)
Offline
Hey, thanks a lot for your answer!
Well, actually, I'm pretty sure It's not because of the size of the array because I'm loading each array in different banks specially to try that, and none of the arrays causes an overflow on it's own, I only get the error when I load a couple of them... I guess making them const will spare me some space, but as I said, I think it's just not putting them in the banks I indicate but all in the same main one.
Also, if it was actually puting my arrays in different banks, then I shouldn't be able to access them without switching banks, and I am. is there's something else wrong with how I'm doing it?
Offline
Do I just put it in each array's .c file? still the same problem :s
Now, I tried not even putting "extern unsigned char map[];" in my main. Like basically just to compile with the different banks and do nothing more. I STILL get the overflow, wich makes me think there's something wrong in my make file. What do you think? it's something like this:
make.bat
c:\gbdk\bin\lcc -c -o main.o main.c c:\gbdk\bin\lcc -Wf-bo2 -c -o bnk2.o map.c c:\gbdk\bin\lcc -Wf-bo3 -c -o bnk3.o map2a.c c:\gbdk\bin\lcc -Wf-bo4 -c -o bnk4.o map2b.c c:\gbdk\bin\lcc -Wf-bo5 -c -o bnk5.o map2c.c c:\gbdk\bin\lcc -Wf-bo6 -c -o bnk6.o map3.c c:\gbdk\bin\lcc -Wf-bo7 -c -o bnk7.o map4.c c:\gbdk\bin\lcc -Wl-yt2 -Wl-yo16 -Wl-ya4 -o test.gb main.o bnk2.o bnk3.o bnk4.o bnk5.o bnk6.o bnk7.o
Does anyone notice something wrong with how I'm doing it?
Offline
I think is a GBDK bug...
Just be sure you don't fill a bank, and then use "const" at every array you use.. even if it is small, like a colour palette or a precalculated sine array or something like that:
const unsigned char TILE_array[] = {}; const UWORD palette_array[] = {}; const int SINE_array[] = {};
GBDK will sometimes show the compile error if you leave a tiny array without the "cost" like this
UWORD backcolours[] = { 32733,16714,15822,19648};
Last edited by Mills (2014-08-13 06:51:02)
Offline
well, I don't get the overflow error if i use .s files instead of .c files for my data. not sure if that relates somehow to banks, or if it's just gbdk compiling better with .s data rather than .c.
btw, i thought that the use of SWITCH_ROM_MBC1(x); was non-optional if you're working with banks. but somehow my code still works without it. do you know why is that?
Offline
I'm not a very good programmer...
GBDK is cool. But it has a lot of bugs. Even using .s files you will reach a limit and it will show the overflow error if you use a lot of arrays.
I got a 4 MB rom full of images working even on real GB, using the "const" trick.
I don't know why your code is working without SWITCH_ROM_MBC1(x), i used .s parts on a code and you had to set the SWITCH_ROM_MBC1(x) to make it work.
Offline
Well, thanks a lot for helping me out!
I still didn't figure out why I got the overflow in the first place, if I'm compiling to different banks. I'll have to worry about it if I get it again while using .s and const.
I also find it very suspicious that my rom works without SWITCH_ROM_MBC1 if I'm using banks. but I'm out of ideas of what's the source of these issues.
Offline
Hey vslean, what version of GBDK are you using? I had the same issue 1.96 and switched back to 1.95, I do have lots of banks in .c files and they compile fine.
As for the switch_rom_mbc1 issue, if you did put your stuff in bank zero than that's probably it, that's the bank that is always on, if you are actually using another bank than I can't explain it either, but gbdk and the gameboy is kinda ok with lots of invalid stuff, sometimes it looks like it's working but it's in fact just shifting bits around and the error will pop up sooner or later.
Offline
Hey, andreai. Thanks for your answer.
I'm using gbdk3-2.95-3. I'm putting my stuff in different banks and still don't use switch_rom_mbc1, so i might be doing it wrong. I'm using .s for graphics now, and it doesn't crash to this point. i get some a "might be writting twice in the same place" warning, sometimes but the game still compiles and works as intended :s
weird, huh?
Last edited by vslean (2014-09-27 17:46:18)
Offline
hey, friends. while i was working on my game i came to see that "switch_rom_mbc1(#)" is not related to the bank i compile to, but to the number i use in my ".area _CODE_#"
...i THINK...
you know, like if i put some map in ".area _CODE_2", i have to "switch_rom_mbc1(2)" or else it glitches the crap out of it.
i guess it's a good thing cause it means i'm getting closer to know what the hell it's for..
does it make sense?
sorry if this is too old or unimportant or totally wrong.. maybe someone is in the same situation i'm in and this is helpful or something, proper detailed documentation on the matter is not widespread so..
Last edited by vslean (2014-11-22 00:10:55)
Offline
YAY!
i'm happy cause now i'm getting SOME kind of proof that i'm getting the whole thing working..
i know this cause i got an overload in bank2... or _code_1. not sure of the difference. the compiler didn't show any errors, but neither bgb or my gameboy would run my game (freeze) with no explanation. visual boy advance runned as if nothing was wrong.
after messing around with all my code i found out that the problem was that i was overloading so i loaded some of my maps in area code 2 instead of 1, and used switch_rom_mbc1(2) before loading the map, and now it works.
what is still unclear to me is that aparently what matters isn't the "-Wf-bo#" parts in my make.bat but the number i use in area _code_#. like i can still all that data in the same "-Wf-bo#" as long as i put them in different _code_'s...
like, what's the use of the -Wf-bo# part then???
anyone?
Offline