I'm a total newbie with the SGDK and in addition it's more than 15 years I had not used C, so expect really dummy questions.
I'm at the beginning of the learning process, going through the tutorials and the included samples, and I've thought that the best way to put everything into practice was to port a ZX Spectrum gem to the Megadrive.
Enough introduction for the moment, let's go to my first question.
I've been trying to implement the transition from a screen to another simply by clicking a button, just an extremely simple button handling, but the thing hasn't worked as I expected. I've found a workaround but the truth is I do not understand why it works.
This is the code:
Code: Select all
static u16 pressed;
void IH_waitForPress(u16 joy, u16 button) {
// joy ignored for the moment, only JOY_1 supported
JOY_setEventHandler(&recordButtonEvents);
while (!(pressed & button)) {
VDP_drawText("", 0, 0); // without this line the handling does not work
VDP_waitVSync();
}
resetButtonEvents();
}
static void recordButtonEvents(u16 joy, u16 changed, u16 state) {
if (joy == JOY_1) {
pressed |= (changed & state);
}
}
static void resetButtonEvents() {
pressed = 0;
}
Anybody has an explanation?
The project here:
https://github.com/diegomtassis/md-jetp ... handling.c
Cheers!