gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > GBC coding

#177735 - mills26 - Sat Dec 29, 2012 8:35 pm

Hi, i'm trying to make games for game boy color. I asked in gbdev forums but no luck. I'm using GBDK.

I made cool things, but i can't overcome a bug or something in gbdk.

When i compile roms with more than 2 banks (bigger tham 32 Kb) the compiler complains:
Code:
ERROR: address overflow (addr c230 >= 8000)
lcc: C:\gbdk\bin/link-gbz80: No error


Some guy solved it by using asm for big variables instead of C arrays.

I also tried this, but ended up with lots of lines with something like "mnemonic errors".

My question is, how do i include asm code inside the main c program?

In my game, i load a background map and some sprites made with gameboy tools that can export asm code as well as c.


Thanks a lot

#177834 - WriteASM - Sun Mar 31, 2013 12:47 pm

Have you looked at the source code for the GBDK "Banked" example? (Including Make.bat) I have also found at least one more GBDK example that uses multiple ROM banks.

Including ASM code inside a C project? I did that back a few years, but unfortunately can't seem to find the source code. Basically, you need to put the ASM code inside a ".s" file (use the Space.s GBDK example for ideas), and add the ".s" file to the "make.bat" list. What I'm not sure about is how to actually call the routine.
I'll keep hunting for the source.

#177841 - WriteASM - Wed Apr 03, 2013 12:54 pm

Found the source code...on a different computer. I made an ASM function called "LScroll" that scrolled a portion of the graphics screen left by one pixel, on an attempted audio recorder project. Here goes:

In a C source file (in my case, "m-audio.c"):
Code:
void LScroll(void);           //ASM function declaration

LScroll();      //Call the function



In the "S" file (in my case, "gfx.s"):
Code:
.include "../libc/gb/global.s"
.globl _LScroll             ;  define the routine

;  VOID LScroll(VOID)
_LScroll: push af
...
...
done:    pop AF
       ret


In the makefile ("make.bat"), one command does it all (the other C source files were "#included" in the main file):
Code:
..\bin\lcc -Wl-m -Wl -yp0x143=0xC0 -O audiorec.gbc audiorec.c gfx.s


The "yp" tag sets the GBC flag in the cartridge header.

Hope this helps. Perhaps I should check out GBDev also?
_________________
"Finally, brethren, whatever is true, whatever is honorable, whatever is right, whatever is pure, whatever is lovely, whatever is of good repute, if there is any excellence and if anything worthy of praise, dwell on these things." (Philippians 4:8)