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 2017-03-23 17:54:25

MrElephant
Member
Registered: 2014-01-29
Posts: 40

Switching Bank

Hello Everyone,

So I am trying to add a bank using the example found in gbdk using the source.

REM Automatically generated from Makefile
C:\gbdk\gbdk\bin
lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -c -o game.o game.c
lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wf-ba0 -c -o bank_0.o bank_0.c
lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wf-bo1 -Wf-ba1 -c -o bank_1.o bank_1.c
lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wf-bo2 -Wf-ba2 -c -o bank_2.o bank_2.c
lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wf-bo3 -Wf-ba3 -c -o bank_3.o bank_3.c
lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wf-bo4 -Wf-ba4 -c -o bank_4.o bank_4.c  **this line was added**
lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wl-yt512 -Wl-yo512 -Wl-ya4 -o game.gb game.o bank_0.o bank_1.o bank_2.o bank_3.o bank_4.o

*bank_4.o was added

The source is exactly the same in all ways, except when I compile it, it crashes when the start button is pressed, or any other button that switches banks.  So that leads me to believe that how I am compiling the game is wrong.

So to sum things up this is what I am trying to do, add a bank, and if start button is pressed-go to bank 4.
Any ideas? (I have included a link to some of the files below, a compiled source and makes)

http://www.mediafire.com/file/xxsgnyw9xav1bvm/game.7z


Working in Gameboy BASIC.

Offline

 

#2 2017-03-26 04:26:25

Alexander the bat
Member
Registered: 2017-03-19
Posts: 31

Re: Switching Bank

You have made -yt wrong if you need like MBC1 you need to do -yt1 (for MBC1 support) or -yt5 (if you need MBC5)

Offline

 

#3 2017-03-26 18:11:04

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

Re: Switching Bank

The main difference is here:

Original:

Code:

call $3075
ld c, e
ld a, c
cp a, $80
jp nz, @03E2
jr @03E5
@03E2:
jp $0244
@03E5:
ld de, $2000
ld a, $04
ld [de], a
call $0000
add sp, $+05
pop bc
ret

vs. added bank:

Code:

call $40A8
ld c, e
ld a, c
cp a, $80
jp nz, @03E2
jr @03E5
@03E2:
jp $0244
@03E5:
ld de, $2000
ld a, $04
ld [de], a
call $2D18
add sp, $+05
pop bc
ret

The first call is the routine that does button input checking. Notice how in the second listing that code got pushed out of ROM bank 0x00 into ROM bank 0x01. In your first example, ROM bank 0x04 is loaded and then a jump to 0x0000 occurs (where a single ret is located). In your modified ROM, 0x2D18 is called, but all further calls it tries to make don't work, because ROM bank 0x04 is actually empty.

We would need to see some of your source code in order to determine why it's empty. Since the linker can obviously find all symbols, your code is actually in there. I manually modified the code to use ROM bank 0x01 and this is the screen I'm getting:

https://i1290.photobucket.com/albums/b527/tauwasser/MrElephant_zpsyculo85h.png

As Alexander pointed out, the yt option is wrong, see GBDK library reference.

Something obviously goes wrong when the ROM is put together, because it seems your bank4 code is just put into rom bank 0x00 and 0x01 instead of where you wanted.

Offline

 

#4 2017-03-26 19:44:57

MrElephant
Member
Registered: 2014-01-29
Posts: 40

Re: Switching Bank

Hello Tauwasser,

Thank you for getting back to me.

On the gameboy channel I talked with some other individuals about my code being messy (coupling, and the use of NONBANK), but I will point out once again that without the extra bank, my code work, and I put this together right of the example (except for the yt compiling part)

Something that I saw that you posted on was this thread http://gbdev.gg8.se/forums/viewtopic.php?id=262
It is ironic that I find this now, but I will do what you suggest, and what others have suggested, and take out all NONBANKED functions, and try with the BANKED function.


EDIT:  Tauwasser, I got it to work, I didnt see your other thread until a few minutes ago.  So thankful for your help.  Using the BANKED function in the original code was the key, but using NONBANKED in the other files worked.  big_smile   Again, so thankful.

Last edited by MrElephant (2017-03-26 19:52:52)


Working in Gameboy BASIC.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson