Options menu

SGDK only sub forum

Moderator: Stef

Post Reply
Hik
Very interested
Posts: 68
Joined: Thu Jul 30, 2015 11:39 pm
Location: Iceland

Options menu

Post by Hik » Tue Oct 04, 2016 4:10 pm

How would you go about making an options menu that brings up a screen of options?

I ran into an issue with the way in which I'm doing it which is basically drawing a new image and text and resetting the screen
every time the player enter's or exits the options menu (changing a variable which tells the screen to change).
After returning from the menu for the 3rd or 4th time the game starts breaking ,in that it stops drawing to the screen
in the way it's supposed to. The code compiles fine without any issues or warnings.

Image

main.c

Code: Select all

//...code...

titleScreen();

//Initialize joypad
JOY_init();
JOY_setEventHandler( &joyInput );

while(1)
{
	//Wait for screen refresh
        updateOptions();
        optionState();
        handleSprite(); //Is this the issue?
        SPR_update();
        VDP_waitVSync();
}
return 0;
commons.c

Code: Select all

#include "commons.h"
#include "options.h"

//functions used in main c and or in the game loop

void titleScreen()
{
    // Disable interrupts when accessing VDP
    SYS_disableInts();

    VDP_resetScreen();
        // reset palettes

    // Load images
    VDP_drawImageEx(PLAN_A, &title_image, TILE_ATTR_FULL(PAL1, FALSE, FALSE, FALSE, ind), 7, 2, FALSE, TRUE);
    ind += title_image.tileset->numTile;

    // Prepare palettes
    memcpy(&palette[16], title_image.palette->data, 16 * 2);
    VDP_setPalette(1, title_image.palette->data);

    //VDP process done - re-enable interrupts
    SYS_enableInts();

    VDP_drawText("Start", 17, 22);
    VDP_drawText("Options", 17, 24);

    //timerCountdown();
}

void optionState()
{
    if(options == 1)
    {
        SYS_disableInts();

        VDP_resetScreen();
        VDP_drawImageEx(PLAN_A, &blackscreen_image, TILE_ATTR_FULL(PAL2, FALSE, FALSE, FALSE, ind), 7, 4, FALSE, TRUE);
        ind += blackscreen_image.tileset->numTile;

        memcpy(&palette[32], blackscreen_image.palette->data, 16 * 2);
        VDP_setPalette(2, blackscreen_image.palette->data);

        SYS_enableInts();
        options = 2;

        //timerCountdown();
    }

//...code for the other options...

}
sprite.c

Code: Select all

#include "sprite.h"
#include "variables.h"

Sprite *soaker[1];

void handleSprite()
{
    u16 pal[64];

    SYS_disableInts();

    // Init sprites engine
    SPR_init(8,128,128);

    soaker[0] = SPR_addSprite(&soaker_sprite, posx-8, posy-3, TILE_ATTR(PAL2, TRUE, FALSE, FALSE));
    // Prepare palettes
    memcpy(&pal[32], soaker_sprite.palette->data, 16 * 2);
    VDP_setPalette(2, soaker_sprite.palette->data);

    SYS_enableInts();

}

Grind
Very interested
Posts: 69
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

Re: Options menu

Post by Grind » Wed Oct 05, 2016 6:31 pm

Could it be the sprite is not being released?

SPR_releaseSprite() or alternatively SPR_reset() to kill them all.

EDIT: Also there is this "ind" variable I see being used to send tiles to VDP. Do you reset this to a default value when restarting the menus?

What does the issue look like exactly? Are tiles not drawing or sprites?

Hik
Very interested
Posts: 68
Joined: Thu Jul 30, 2015 11:39 pm
Location: Iceland

Re: Options menu

Post by Hik » Wed Oct 05, 2016 7:46 pm

Thanks for the reply. I did try SPR_releaseSprite() but it didn't change anything. SPR_reset() doesn't seem to do anything either.

The ind variable is used earlier in the main.c code for the user base tile index. To reset it might be a good idea ,
I'm just not sure how to do that yet. I only have cursory knowledge of how this works based on what I've seen in this forum.

I noticed that when exiting the title screen ,the sprite goes green before changing the position.
After 4th exit from the menu ,right after the sprite goes green and gets moved to the new position ,
the title screen image gets garbled pixels and after 5th exit the text is unreadable. After 6th exit everything is garbled.
Last edited by Hik on Thu Oct 06, 2016 12:13 pm, edited 1 time in total.

Grind
Very interested
Posts: 69
Joined: Fri Jun 13, 2014 1:26 pm
Location: US
Contact:

Re: Options menu

Post by Grind » Wed Oct 05, 2016 10:07 pm

Looking through the VRAM in Gens KMod, each time the title screen is reloaded, it loads a copy of itself further down. Eventually, this clashes with the sprite table, then the font, and finally the planes:

Image

Image

Image

Image

I noticed the splash screens do something similar, continually incrementing the tile index without resetting the value, but there aren't enough tiles during that sequence to cause any problem.

You can take a look yourself, kmod has helped me solve quite a few odd problems.
http://gendev.spritesmind.net/page-gensK.html

That window in the screenshots is at CPU > Debug > Genesis > VDP

SGDK has some built in routines you can use to print messages as well.
https://github.com/Stephane-D/SGDK/blob ... c/kdebug.h

Hik
Very interested
Posts: 68
Joined: Thu Jul 30, 2015 11:39 pm
Location: Iceland

Re: Options menu

Post by Hik » Thu Oct 06, 2016 12:12 pm

Thanks for the help Grind. I looked up TILE_USERINDEX in the forum.
Turns out it was easier to fix than I thought.

I just added ind = 0; ind = TILE_USERINDEX; before loading each of the screens
and it works like a charm. I learned some things from this so it was useful.

The flowchart works fine for the Options menu.

If anyone has better alternatives or other issues related to Options menus ,
they can use this thread.

Post Reply