Skip to content

Commit

Permalink
Extracts and consolidates screen code
Browse files Browse the repository at this point in the history
- Extracts main screen, splash screen and screen.c for common untils
- getPad has global controls, and then hands off to screen controls so that we may have screen specific controls/tables/layout
- Each screen can have an init, show, render and getPad handler for relevant phases
- Uses some enums
  • Loading branch information
tstirrat committed Jul 31, 2024
1 parent ed61a57 commit 2305f6c
Show file tree
Hide file tree
Showing 14 changed files with 318 additions and 261 deletions.
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Mac",
"includePath": ["${workspaceFolder}/gbdk/include"],
"defines": ["__TARGET_gb=1", "__PORT_sm83=1"],
"compilerPath": "${workspaceFolder}/gbdk/bin/lcc",
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"intelliSenseMode": "${default}",
"browse": { "limitSymbolsToIncludedHeaders": true }
Expand Down
37 changes: 37 additions & 0 deletions Source/io/pad.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "pad.h"
#include "../mGB.h"
#include "../screen/main.h"
#include "../screen/screen.h"
#include "../synth/common.h"
#include "../synth/pulse.h"
#include "../synth/wav.h"

uint8_t joyState;

// moved the main pad handler out, split into screen level handlers
// Before: 1770/1628 clock cycles, 379 bytes
// After: getPad: 194 clock cycles, 46 bytes
// getPadMainScreen: 418/387 clock cycles, 97 bytes
// = 612/581, 143 bytes
void getPad(void) {
i = joypad();
if (i != joyState) {
joyState = i;

if ((i & J_A) && (i & J_SELECT)) {
toggleScreen();
return;
}

if (i == J_START) {
stopAllSynths();
return;
}

switch (currentScreen) {
case SCREEN_MAIN:
getPadMainScreen();
break;
}
}
}
7 changes: 7 additions & 0 deletions Source/io/pad.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include <gbdk/platform.h>

extern uint8_t joyState;

void getPad(void);
13 changes: 12 additions & 1 deletion Source/io/sram.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "sram.h"
#include "../mGB.h"
#include "../screen/main.h"
#include "../synth/data.h"
#include <gbdk/platform.h>

void saveDataSet(uint8_t synth) {
// EMU_printf("saveDataSet(synth %d)\n", synth);

ENABLE_RAM_MBC1;
x = (synth + 24U);
x = dataSet[x] * 8;
Expand Down Expand Up @@ -38,6 +41,8 @@ void saveDataSet(uint8_t synth) {
}

void loadDataSet(uint8_t synth) {
// EMU_printf("loadDataSet(synth %d)\n", synth);

ENABLE_RAM_MBC1;
x = dataSet[(synth + 24U)] * 8U;
i = 0;
Expand Down Expand Up @@ -77,6 +82,12 @@ void loadDataSet(uint8_t synth) {

void checkMemory(void) {
ENABLE_RAM_MBC1;

// fixes some SRAM Bugs
SWITCH_ROM(1);
SWITCH_RAM(0);
// end fix

if (saveData[512] != SRAM_INITIALIZED) {
for (x = 0; x != 128; x += 8) {
l = 0;
Expand Down Expand Up @@ -106,4 +117,4 @@ void checkMemory(void) {

for (j = 0; j != 24; j++)
dataSetSnap[j] = dataSet[j];
}
}
9 changes: 5 additions & 4 deletions Source/mGB.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "mGB.h"
#include "io/midi.h"
#include "io/pad.h"
#include "io/sram.h"
#include "screen/main.h"
#include "screen/screen.h"
#include "screen/splash.h"
#include "screen/utils.h"
#include "synth/common.h"
#include "synth/noi.h"
#include "synth/pulse.h"
Expand Down Expand Up @@ -60,10 +61,10 @@ void main(void) {
/* Handle VBL and TIM interrupts */
set_interrupts(VBL_IFLAG | TIM_IFLAG | SIO_IFLAG);

showSplashScreen();
showScreen(SCREEN_SPLASH);
delay(2000);

showMainScreen();
showScreen(SCREEN_MAIN);
printversion();
// testSynths();
gameMain();
Expand Down Expand Up @@ -92,6 +93,6 @@ inline void gameMain(void) {
updateNoi();

if (systemIdle)
mainScreen();
renderCurrentScreen();
}
}
Loading

0 comments on commit 2305f6c

Please sign in to comment.