Skip to content

Commit bdf2ceb

Browse files
committed
GBC: Enabled SIREN GB2 and DONKEY KONG game-specific hack detection
1 parent 87e04cc commit bdf2ceb

File tree

13 files changed

+73
-49
lines changed

13 files changed

+73
-49
lines changed

components/odroid/odroid_overlay.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ struct odroid_dialog_choice {
2929
int id;
3030
char label[32];
3131
char value[16];
32-
int8_t enabled;
32+
int enabled;
3333
bool (*update_cb)(odroid_dialog_choice_t *, odroid_dialog_event_t);
3434
};
3535

36-
#define ODROID_DIALOG_CHOICE_LAST {0x0F0F0F0F, "LAST", "LAST", 0xFF, NULL}
36+
#define ODROID_DIALOG_CHOICE_LAST {0x0F0F0F0F, "LAST", "LAST", 0xFFFF, NULL}
3737

3838
extern odroid_menu_state_t odroid_menu_state;
3939

gnuboy-go/components/gnuboy/cpu.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ int IRAM_ATTR cpu_emulate(int cycles)
332332
}
333333
IME = IMA;
334334

335-
if (debug_trace) debug_disassemble(PC, 1);
335+
if (enable_disassembler)
336+
debug_disassemble(PC, 1);
337+
336338
op = FETCH;
337339
clen = cycles_table[op];
338340

gnuboy-go/components/gnuboy/cpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct cpu
5252
int timer, div;
5353
};
5454

55-
extern int debug_trace;
55+
extern int enable_disassembler;
5656
extern struct cpu cpu;
5757

5858
void cpu_reset();

gnuboy-go/components/gnuboy/debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ static const byte operand_count[256] =
550550

551551
/* replace with a real interactive debugger eventually... */
552552

553-
int debug_trace = 0;
553+
int enable_disassembler = 0;
554554

555555
void debug_disassemble(addr a, int c)
556556
{

gnuboy-go/components/gnuboy/lcd.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ static int dmg_selected_pal = 0;
5050
static byte *vdest;
5151
static byte pix[8];
5252

53+
// Fix for Fushigi no Dungeon - Fuurai no Shiren GB2 and Donkey Kong
54+
int enable_window_offset_hack = 0;
55+
5356

5457
/**
5558
* Drawing routines
@@ -578,10 +581,9 @@ static inline void lcd_renderline()
578581

579582
// Fix for Fushigi no Dungeon - Fuurai no Shiren GB2 and Donkey Kong
580583
// This is a hack, the real problem is elsewhere
581-
if ((R_LCDC & 0x20) && WT > 12)
584+
if (enable_window_offset_hack && (R_LCDC & 0x20))
582585
{
583-
// printf("WT=%d\n", WT);
584-
// WT %= 12;
586+
WT %= 12;
585587
}
586588

587589
spr_enum();

gnuboy-go/components/gnuboy/lcd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ extern struct lcd lcd;
6161
extern struct scan scan;
6262
extern struct fb fb;
6363

64+
extern int enable_window_offset_hack;
65+
6466
void lcd_reset();
6567
void lcd_emulate();
6668

gnuboy-go/components/gnuboy/loader.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "rtc.h"
1313
#include "sound.h"
1414

15-
#include "esp_heap_caps.h"
1615
#include "odroid_system.h"
1716

1817
static const byte mbc_table[256] =
@@ -74,7 +73,6 @@ static const byte ramsize_table[256] =
7473
4 /* FIXME - what value should this be?! */
7574
};
7675

77-
7876
static FILE* fpRomFile = NULL;
7977

8078
static char *romfile=NULL;
@@ -86,19 +84,13 @@ static int forcebatt=0, nobatt=0;
8684
static int forcedmg=0, gbamode=0;
8785

8886

89-
static inline void initmem(void *mem, int size)
90-
{
91-
memset(mem, 0xff, size);
92-
}
93-
94-
9587
int IRAM_ATTR rom_loadbank(short bank)
9688
{
9789
const size_t BANK_SIZE = 0x4000;
9890
const size_t OFFSET = bank * BANK_SIZE;
9991

10092
printf("bank_load: loading bank %d.\n", bank);
101-
rom.bank[bank] = (byte*)heap_caps_malloc(BANK_SIZE, MALLOC_CAP_SPIRAM);
93+
rom.bank[bank] = (byte*)malloc(BANK_SIZE);
10294
if (rom.bank[bank] == NULL) {
10395
while (true) {
10496
uint8_t i = esp_random() & 0xFF;
@@ -111,10 +103,6 @@ int IRAM_ATTR rom_loadbank(short bank)
111103
}
112104
}
113105

114-
if (rom.bank[bank] == NULL) {
115-
odroid_system_panic("Out of memory");
116-
}
117-
118106
// Make sure no transaction is running
119107
odroid_system_spi_lock_acquire(SPI_LOCK_SDCARD);
120108

@@ -195,27 +183,37 @@ int rom_load()
195183
mbcName, mbc.romsize, rom.length / 1024, mbc.ramsize, mbc.ramsize * 8);
196184

197185
// SRAM
198-
ram.sbank = heap_caps_malloc_prefer(8192 * mbc.ramsize, MALLOC_CAP_INTERNAL, MALLOC_CAP_SPIRAM);
186+
ram.sbank = rg_alloc(8192 * mbc.ramsize, MEM_FAST);
199187
ram.sram_dirty = 0;
200188

201-
initmem(ram.sbank, 8192 * mbc.ramsize);
202-
initmem(ram.ibank, 4096 * 8);
189+
memset(ram.sbank, 0xff, 8192 * mbc.ramsize);
190+
memset(ram.ibank, 0xff, 4096 * 8);
203191

204192
mbc.rombank = 1;
205193
mbc.rambank = 0;
206194

207195
int preload = mbc.romsize < 64 ? mbc.romsize : 64;
208196

209-
if (strncmp(rom.name, "RAYMAN", 6) == 0) {
197+
// RAYMAN stutters too much if we don't fully preload it
198+
if (strncmp(rom.name, "RAYMAN", 6) == 0)
199+
{
210200
printf("loader: Special preloading for Rayman 1/2\n");
211201
preload = mbc.romsize - 8;
212202
}
213203

214204
printf("loader: Preloading the first %d banks\n", preload);
215-
for (int i = 1; i < preload; i++) {
205+
for (int i = 1; i < preload; i++)
206+
{
216207
rom_loadbank(i);
217208
}
218209

210+
// Apply game-specific hacks
211+
if (strncmp(rom.name, "SIREN GB2 ", 11) == 0 || strncmp(rom.name, "DONKEY KONG", 11) == 0)
212+
{
213+
printf("loader: HACK: Window offset hack enabled\n");
214+
enable_window_offset_hack = 1;
215+
}
216+
219217
return 0;
220218
}
221219

gnuboy-go/main/main.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ static uint skipFrames = 0;
4141
static bool netplay = false;
4242

4343
static bool saveSRAM = false;
44-
static int sramSaveTimer = 0;
45-
46-
extern int debug_trace;
44+
static int saveSRAM_Timer = 0;
4745
// --- MAIN
4846

4947

@@ -317,11 +315,11 @@ void app_main(void)
317315
{
318316
if (ram.sram_dirty)
319317
{
320-
sramSaveTimer = 90;
318+
saveSRAM_Timer = 90;
321319
ram.sram_dirty = 0;
322320
}
323321

324-
if (sramSaveTimer > 0 && --sramSaveTimer == 0)
322+
if (saveSRAM_Timer > 0 && --saveSRAM_Timer == 0)
325323
{
326324
// TO DO: Try compressing the sram file, it might reduce stuttering
327325
sram_save();

handy-go/components/handy/system.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ ULONG gThrottleLastTimerCount=0;
7575
ULONG gThrottleNextCycleCheckpoint=0;
7676
ULONG gEndOfFrame=0;
7777
ULONG gTimerCount=0;
78+
ULONG gRenderFrame=1;
7879

7980
ULONG gAudioEnabled=FALSE;
8081
UBYTE *gAudioBuffer;//[HANDY_AUDIO_BUFFER_SIZE];

handy-go/components/handy/system.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ extern ULONG gThrottleLastTimerCount;
116116
extern ULONG gThrottleNextCycleCheckpoint;
117117
extern ULONG gEndOfFrame;
118118
extern ULONG gTimerCount;
119+
extern ULONG gRenderFrame;
119120

120121
extern ULONG gAudioEnabled;
121122
extern UBYTE *gAudioBuffer;
@@ -216,9 +217,10 @@ class CSystem : public CSystemBase
216217
// fprintf(stderr, "end sys update\n");
217218
}
218219

219-
inline void UpdateFrame(void)
220+
inline void UpdateFrame(bool draw)
220221
{
221222
gEndOfFrame = FALSE;
223+
gRenderFrame = draw;
222224

223225
while(gEndOfFrame != TRUE)
224226
{

handy-go/main/main.cpp

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@ extern "C" {
1616
#define PIXEL_MASK 0xFF
1717
#define PAL_SHIFT_MASK 0x00
1818

19-
DMA_ATTR static short audioBuffer[AUDIO_BUFFER_LENGTH * 2];
19+
static DMA_ATTR short audioBuffer[AUDIO_BUFFER_LENGTH * 2];
2020

2121
static odroid_video_frame update1;
2222
static odroid_video_frame update2;
2323
static odroid_video_frame *currentUpdate = &update1;
2424
static odroid_video_frame *previousUpdate = &update2;
2525

2626
static CSystem *lynx = NULL;
27-
28-
static uint startTime = 0;
29-
static uint frameTime = 16667;
3027
// static bool netplay = false;
3128
// --- MAIN
3229

@@ -67,6 +64,7 @@ extern "C" void app_main(void)
6764
lynx = new CSystem(romFile);
6865
lynx->DisplaySetAttributes(MIKIE_NO_ROTATE, MIKIE_PIXEL_FORMAT_16BPP_565_BE, update1.stride);
6966

67+
gPrimaryFrameBuffer = (UBYTE*)currentUpdate->buffer + currentUpdate->stride;
7068
gAudioBuffer = (UBYTE*)&audioBuffer;
7169
gAudioEnabled = 0;
7270

@@ -76,8 +74,10 @@ extern "C" void app_main(void)
7674
}
7775

7876
odroid_gamepad_state joystick;
79-
ULONG buttons;
80-
bool fullFrame;
77+
78+
uint frameTime = get_frame_time(60);
79+
uint skipFrames = 0;
80+
bool fullFrame = 0;
8181

8282
// Start emulation
8383
while (1)
@@ -88,13 +88,17 @@ extern "C" void app_main(void)
8888
odroid_overlay_game_menu();
8989
}
9090
else if (joystick.values[ODROID_INPUT_VOLUME]) {
91-
odroid_overlay_game_settings_menu(NULL);
91+
odroid_dialog_choice_t options[] = {
92+
{100, "Rotation", "Off ", 0, NULL},
93+
ODROID_DIALOG_CHOICE_LAST
94+
};
95+
odroid_overlay_game_settings_menu(options);
9296
}
9397

94-
gPrimaryFrameBuffer = (UBYTE*)currentUpdate->buffer + currentUpdate->stride;
98+
uint startTime = get_elapsed_time();
99+
bool drawFrame = !skipFrames;
95100

96-
startTime = get_elapsed_time();
97-
buttons = 0;
101+
ULONG buttons = 0;
98102

99103
if (joystick.values[ODROID_INPUT_UP]) buttons |= BUTTON_UP;
100104
if (joystick.values[ODROID_INPUT_DOWN]) buttons |= BUTTON_DOWN;
@@ -107,13 +111,28 @@ extern "C" void app_main(void)
107111

108112
lynx->SetButtonData(buttons);
109113

110-
lynx->UpdateFrame();
114+
lynx->UpdateFrame(drawFrame);
115+
116+
if (drawFrame)
117+
{
118+
fullFrame = odroid_display_queue_update(currentUpdate, previousUpdate) == SCREEN_UPDATE_FULL;
119+
previousUpdate = currentUpdate;
120+
currentUpdate = (currentUpdate == &update1) ? &update2 : &update1;
121+
gPrimaryFrameBuffer = (UBYTE*)currentUpdate->buffer + currentUpdate->stride;
122+
}
111123

112-
fullFrame = odroid_display_queue_update(currentUpdate, previousUpdate) == SCREEN_UPDATE_FULL;
113-
previousUpdate = currentUpdate;
114-
currentUpdate = (currentUpdate == &update1) ? &update2 : &update1;
124+
// See if we need to skip a frame to keep up
125+
if (skipFrames == 0)
126+
{
127+
if (get_elapsed_time_since(startTime) > frameTime) skipFrames = 1;
128+
if (speedupEnabled) skipFrames += speedupEnabled * 2.5;
129+
}
130+
else if (skipFrames > 0)
131+
{
132+
skipFrames--;
133+
}
115134

116-
odroid_system_tick(0, fullFrame, get_elapsed_time_since(startTime));
135+
odroid_system_tick(!drawFrame, fullFrame, get_elapsed_time_since(startTime));
117136

118137
if (!speedupEnabled)
119138
{

handy-go/sdkconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS=y
236236
CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS=4
237237
CONFIG_SYSTEM_EVENT_QUEUE_SIZE=32
238238
CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=2048
239-
CONFIG_MAIN_TASK_STACK_SIZE=24576
239+
CONFIG_MAIN_TASK_STACK_SIZE=16384
240240
CONFIG_IPC_TASK_STACK_SIZE=1024
241241
CONFIG_TIMER_TASK_STACK_SIZE=2048
242242
CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF=y

mkfw.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ release=`date +%Y%m%d`;
1414
$mkfw "Retro-Go ($release)" assets/tile.raw \
1515
0 16 524288 frontend retro-go/build/retro-go.bin \
1616
0 17 458752 nofrendo nofrendo-go/build/nofrendo-go.bin \
17-
0 18 393216 gnuboy gnuboy-go/build/gnuboy-go.bin \
17+
0 18 458752 gnuboy gnuboy-go/build/gnuboy-go.bin \
1818
0 19 458752 smsplusgx smsplusgx-go/build/smsplusgx-go.bin \
1919
0 20 393216 huexpress huexpress-go/build/huexpress-go.bin \
2020
0 21 393216 handy handy-go/build/handy-go.bin

0 commit comments

Comments
 (0)