Skeetendo

’Cause all games were better on the GBC

You are not logged in.

#1 2017-12-24 14:24:07

Ax461
Member
Registered: 2016-10-24
Post 12/15

Help me understanding how does pokemon red display images

What i'm trying to do is to open the start menu when going to a specific spot in the overworld, here's the code:

ld a, [wYCoord]
cp $6
ret nz
ld a, [wXCoord]
cp $3
ret nz

xor a
ld [hSCX], a
ld [hSCY], a
ld [hWY], a
inc a
ld [hAutoBGTransferEnabled], a

call LoadFontTilePatterns
call DisplayStartMenu

And it works pretty much as intended

What i don't understand is why i have to set the screen and window positioning to 0 before calling DisplayStartMenu from a script, whereas when i call it by pressing start hSCX, hSCY aren't set to 0

My final objective is to draw an image to a white screen, this one is just an exercise to see if i understand how it works
I also wonder if there's a better way to do it

Last edited by Ax461 (2017-12-24 14:29:57)

Offline

#2 2017-12-25 17:51:22

Danny-E 33
Administrator
Registered: 2012-06-09
Post 1,051/1,119

Re: Help me understanding how does pokemon red display images

Interesting question!

There is actually a better way to do this.
Replace your snip of code with this:

ld a, [wYCoord]
cp $6
ret nz
ld a, [wXCoord]
cp $3
ret nz

xor a
ld [hSpriteIndexOrTextID],a
call DisplayTextID

Text ID 0 is a shortcut to display the start menu from the overworld

By simply loading the right tiles and calling DisplayStartMenu, you skip some other necessary initialization that is done by DisplayTextID


The only piece of initialization that you are missing is a call to DisplayTextIDInit, so you can also use this code:

ld a, [wYCoord]
cp $6
ret nz
ld a, [wXCoord]
cp $3
ret nz

callba DisplayTextIDInit
call DisplayStartMenu

To just take the most essential stuff out of DisplayTextIDInit, you could use this code:

ld a, [wYCoord]
cp $6
ret nz
ld a, [wXCoord]
cp $3
ret nz

ld hl,wFontLoaded
set 0,[hl]
ld b,$9c
call CopyScreenTileBufferToVRAM
xor a
ld [hWY],a
call LoadFontTilePatterns
ld a,$01
ld [H_AUTOBGTRANSFERENABLED],a
call DisplayStartMenu

However, the sprite data copy loops that I excluded are still necessary to prevent very minor graphical glitches

The two most important steps you were missing are setting the wFontLoaded flag (which fixes how sprites are updated/reloaded when the text box is closed) and copying the BG Map at $9800 into the BG Map at $9C00 (where the text box is displayed from)
Since the BG Map at $9C00 is used, you actually don't want to set hSCX and hSCY to 0. That causes the player to get de-synchronized from the overworld map.

Offline

Board footer

Powered by FluxBB