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.

Ads

#1 2010-08-05 12:38:10

LEOcab
New member
Registered: 2010-08-05
Posts: 2

Game runs on emulators and GBA, but not b/w GB. Why?

I'm almost done with my game so I bought one of these to test it on real consoles:
http://www.robwebb1.plus.com/gb/gb.htm (the 64MB one)

At first I was disappointed to see the background wasn't arranged properly. After an hour of fiddling I realized I was using VRAM without ever checking for v-blank. Oops. After five hours of fixing my code, it runs flawlessly on my GBA but it shows nothing but garbled graphics on my original GB. The game seems to behave fine otherwise, I can see the background and sprites scrolling like they should, but it's like I never copied my tile patterns to memory.

It's odd, though, the first time I ran the game on it it showed the graphics fine. I must've broken it but I can't figure out what I did. I modified it to support SGB palettes while adding v-blank checks (the default palette on the GBA was too ugly) but I tried removing that portion and it still has the same problem.

It runs other games from the flashcart just fine, so it's got to be my code. I also tried running it from both banks (the flashcart has two 32MB banks to store games in and you switch banks by resetting the console quickly.)

Here I'll post the startup part of my game, the first thing that runs. I assume the problem is here, either I'm forgetting to do something or I'm doing something in the wrong order which is causing the memcpy calls to not execute. It just shows a blank screen and waits for a keypress, like an introduction. Actually it also displays some text (right after zeroing _SCRN0), but that was out of this context so I removed it. tongue

I thank whoever helps me out in advance!

Code:

main::
    ; Wait for vblank
    ldh    a, [rLY]
    cp    144
    jr    c, main
    
    ; Disable interrupts
    di
    
    ; Turn the LCD off
    ld    a, LCDCF_OFF
    ldh    [rLCDC], a

    ; Load the default color order
    ld    a, %11100100
    ldh    [rBGP], a
    ldh    [rOBP0], a

    ; Load our font
    ld    bc, FONT_SIZE*16 ; 16 bytes per tile
    ld    hl, Font
    ld    de, _VRAM
    call    memcpy
    
    ;  Load tile data
    ld    bc, TILE_COUNT*16 ; 16 bytes per tile
    ld    hl, Tiles
    ld    de, _VRAM+FONT_SIZE*16 ; font goes first
    call    memcpy
    
    ; Initialize the common globals
    ld    hl, globals_start
    ld    bc, globals_end - globals_start
    call    memzero
    
    ; Set the player sprite's tile
    ld    a, tPLAYER
    ld    [_OAMRAM+2], a
    
    ; Set up the window
    ld    a, 7
    ld    [rWX], a
    ld    a, SCRN_Y - 8 * 3
    ld    [rWY], a
    
    ; First line of window: border
    ld    hl, _SCRN1
    ld    bc, SCRN_X_B
    ld    a, uitBORDER
    call    memset
    
    ; Clear out the background
    ld    hl, _SCRN0
    ld    bc, 32*32
    call    memzero
    
    ; Turn the LCD and background on
    ld    a, LCDCF_ON | LCDCF_BG8000 | LCDCF_BGON
    ldh    [rLCDC], a
    
    ; Enable interrupts
    ld    a, IEF_VBLANK | IEF_TIMER
    ld    [rIE], a
    ei
    
.loop
    call    wait_vblank
    call    pad_Read
    or    a
    jr    z, .loop

Here are my wait_vblank and mem* functions that are called:

Code:

; VblankFlag is set to 1 on vblank interrupt, so that this loop only exits on v-blank
wait_vblank::
    ld    hl, VblankFlag
.wait
    halt
    ld    a, [hl]
    or    a
    jr    z, .wait
    ld    [hl], 0
    ret

memcpy::
    ld    a, [hl+]
    ld    [de], a
    inc    de
    dec    bc
    ld    a, b
    or    c
    jr    nz, memcpy
    ret

memzero::
    xor    a ;branch down to memset
memset::
    ld    d, a
.loop
    ld    [hl+], a
    dec    bc
    ld    a, b
    or    c
    ld    a, d
    jr    nz, .loop

Offline

 

#2 2010-08-07 16:39:43

LEOcab
New member
Registered: 2010-08-05
Posts: 2

Re: Game runs on emulators and GBA, but not b/w GB. Why?

Nevermind... this is odd; I check the second bank of the cart and there it is, working fine. I must've copied it there to rule out the cart as the culprit but failed to perform the actual test. Now I copied the exact same copy to both banks and only bank 1 runs correctly. This is very strange... but it runs perfectly otherwise.

Sorry for the hassle. I'll leave the code up there in case anyone finds it and wants to use it. tongue

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson