’Cause all games were better on the GBC

You are not logged in.

#1 2016-12-29 10:39:27

Registered: 2016-05-09
Post 428/587

[pokecrystal] Shift only some tiles with hSCX

I have an experience bar that's a bit too long for its available space, and was thinking that shifting its tiles would work.


I know that this is possible for only some tiles on the screen by changing the hSCX value. engine/pokedex.asm uses "ld a, $5; ld [hSCX], a" to do this for part of its screen: (note the left tiles, like "Seen 5" and "Select → Option", are shifted 3 (not 5?) tiles right)


My experience bar code is in a relatively-unmodified part of engine/stats_screen.asm. I've tried doing this, based on what appears to be the flow of execution for the Pokédex display code:

; only shift the exp bar tiles
    ld a, [hSCX]
    push af
    ld a, [VramState]
    push af
    xor a
    ld [VramState], a
    ld a, $6
    ld [hSCX], a
    call WaitBGMap

    hlcoord 12, 16
    ld a, [TempMonLevel]
    ld b, a
    ld de, TempMonExp + 2
    predef FillInExpBar
    hlcoord 10, 16
    ld [hl], $6e ; first "EXP" tile
    inc hl
    ld [hl], $6f ; second "EXP" tile
    hlcoord 19, 16
    ld [hl], $77 ; exp bar end cap

    call DelayFrame
    ld a, $3
    ld [hBGMapMode], a
    ld c, 4
    call DelayFrames
    xor a
    ld [hBGMapMode], a

This does not work. When I view the stats screen it shows up partially-drawn (everything prior to the FillInExpBar call) for a few frames with everything shifted left, then redraws with everything unshifted, including the exp bar. I've been playing around with it but have not had insight into how this part of the graphics engine works. What do I need to do to get the display I'd like?

Last edited by Rangi (2016-12-29 10:40:36)

ROM hack: Pokémon Polished Crystal — version 2.2.0 released!


#2 2016-12-29 15:04:06

Registered: 2013-12-04
Post 339/341

Re: [pokecrystal] Shift only some tiles with hSCX

I don't have a working example of what you want, but I can tell you about how this works, if my memory is correct.

hSCX controls the the X Scroll Amount for the entire gameboy background layer.  When the pokedex screen sets hSCX=5, it scrolls the background window to the right by 5 pixels.  This means that any tiles visible on screen are actually shifted 5 pixels left, not 3 pixels right.  What you're trying to achieve is a bit different, because you only want to shift certain pixels rows using hSCX.  This is possible, but you have to set hSCX at certain times, with respect to the LCD drawing rows of pixels onto the screen.  I know in pokered, it uses this technique when scrolling the wild pokemon/trainer's backsprite at the start of a battle.  I assume pokecrystal uses the same technique.  The technique works by periodically checking the hLY ($FF44) register during H-Blank to see which row of pixels is being drawn.  If hLY if one of the rows containing the experience bar, set hSCX=-3, else set hSCX=0.

EDIT:  In your case, this technique may not be ideal, since it's only possible to shift entire rows of pixels.  This means that the vertical black line in your stats screen would be shifted with the exp. bar, which would look pretty bad.

Last edited by ShantyTown (2016-12-29 15:07:05)


#3 2016-12-31 05:42:22

Registered: 2016-05-09
Post 440/587

Re: [pokecrystal] Shift only some tiles with hSCX

Thank you, ShantyTown! I ended up not needing to shift tiles for this particular feature, since the Exp bar is not going to be that long, but this will probably be helpful later on.

ROM hack: Pokémon Polished Crystal — version 2.2.0 released!


Board footer

Powered by FluxBB