From 92b984692c3d1404a9b2520b10501be05f8ae6e9 Mon Sep 17 00:00:00 2001 From: XProger Date: Sat, 22 Jan 2022 17:33:18 +0300 Subject: [PATCH] #368 improve checkROM, add vsync option, fix LineH rasterization --- src/fixed/common.h | 3 ++- src/fixed/game.h | 1 + src/fixed/inventory.h | 11 ++++++++ src/platform/gba/asm/rasterizeLineH.s | 2 +- src/platform/gba/checkROM.cpp | 39 ++++++++++++++++++--------- src/platform/gba/main.cpp | 5 ++++ 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/fixed/common.h b/src/fixed/common.h index 699ba71..36c8b55 100644 --- a/src/fixed/common.h +++ b/src/fixed/common.h @@ -1668,7 +1668,7 @@ struct SaveGame uint8 tracks[64]; }; -#define SETTINGS_VER 1 +#define SETTINGS_VER 2 #define SETTINGS_SIZE 128 struct Settings @@ -1679,6 +1679,7 @@ struct Settings uint8 audio_music:1; uint8 video_gamma:5; uint8 video_fps:1; + uint8 video_vsync:1; }; #define FD_SET_END(x,end) ((x) |= ((end) << 15)) diff --git a/src/fixed/game.h b/src/fixed/game.h index 064d5ff..1357cd3 100644 --- a/src/fixed/game.h +++ b/src/fixed/game.h @@ -90,6 +90,7 @@ void gameInit(const char* name) gSettings.audio_music = 1; gSettings.video_gamma = 0; gSettings.video_fps = 1; + gSettings.video_vsync = 0; osLoadSettings(); inventory.init(); diff --git a/src/fixed/inventory.h b/src/fixed/inventory.h index 4c6d570..19d630c 100644 --- a/src/fixed/inventory.h +++ b/src/fixed/inventory.h @@ -90,6 +90,7 @@ enum OptionID // video OPT_ID_GAMMA = 0, OPT_ID_FPS = 1, + OPT_ID_VSYNC = 2, // passport OPT_ID_OK = 5 }; @@ -911,6 +912,15 @@ struct Inventory osSaveSettings(); } } + + if (optionIndex == OPT_ID_VSYNC) + { + if (gSettings.video_vsync != opt.value) + { + gSettings.video_vsync = opt.value; + osSaveSettings(); + } + } } void onSound() @@ -1231,6 +1241,7 @@ struct Inventory { OPTION_BAR(STR_OPT_DETAIL_GAMMA, gSettings.video_gamma << 4); OPTION_SWITCH(STR_OPT_DETAIL_FPS, gSettings.video_fps); + OPTION_SWITCH(STR_OPT_DETAIL_VSYNC, gSettings.video_vsync); break; } case SLOT_SOUND: diff --git a/src/platform/gba/asm/rasterizeLineH.s b/src/platform/gba/asm/rasterizeLineH.s index 667b708..fab7a0f 100644 --- a/src/platform/gba/asm/rasterizeLineH.s +++ b/src/platform/gba/asm/rasterizeLineH.s @@ -24,7 +24,7 @@ rasterizeLineH_asm: strh tmp, [pixel], #2 subs width, #1 beq .scanline_end - mov pc, lr + .align_right: tst width, #1 beq .scanline_block_2px diff --git a/src/platform/gba/checkROM.cpp b/src/platform/gba/checkROM.cpp index 6b2a589..8290e8f 100644 --- a/src/platform/gba/checkROM.cpp +++ b/src/platform/gba/checkROM.cpp @@ -1,32 +1,33 @@ #include #define MEM_CHECK_MAGIC 14021968 +#define MEM_CHECK_SIZE 16 -const int ROM_MAGIC[] = { - MEM_CHECK_MAGIC, +const int ROM_MAGIC[MEM_CHECK_SIZE] = { + MEM_CHECK_MAGIC + 0, MEM_CHECK_MAGIC + 1, MEM_CHECK_MAGIC + 2, MEM_CHECK_MAGIC + 3, MEM_CHECK_MAGIC + 4, MEM_CHECK_MAGIC + 5, MEM_CHECK_MAGIC + 6, - MEM_CHECK_MAGIC + 7 + MEM_CHECK_MAGIC + 7, + MEM_CHECK_MAGIC + 8, + MEM_CHECK_MAGIC + 9, + MEM_CHECK_MAGIC + 10, + MEM_CHECK_MAGIC + 11, + MEM_CHECK_MAGIC + 12, + MEM_CHECK_MAGIC + 13, + MEM_CHECK_MAGIC + 14, + MEM_CHECK_MAGIC + 15, }; EWRAM_CODE bool checkROM(unsigned int mask) { REG_WSCNT = mask; - for (int i = 0; i < 8; i++) - { - if (*(volatile int*)&ROM_MAGIC[i] != (MEM_CHECK_MAGIC + i)) - { - REG_WSCNT = WS_ROM0_N4 | WS_ROM0_S2 | WS_PREFETCH; - return false; - } - } - - for (int i = 7; i >= 0; i--) + // check sequential read (S) + for (int i = 0; i < MEM_CHECK_SIZE; i++) { if (*(volatile int*)&ROM_MAGIC[i] != (MEM_CHECK_MAGIC + i)) { @@ -35,5 +36,17 @@ EWRAM_CODE bool checkROM(unsigned int mask) } } + // check non-sequential read (N) + for (int i = 0, j = MEM_CHECK_SIZE - 1; i < MEM_CHECK_SIZE; i++, j--) + { + bool L = *(volatile int*)&ROM_MAGIC[i] == (MEM_CHECK_MAGIC + i); + bool R = *(volatile int*)&ROM_MAGIC[j] == (MEM_CHECK_MAGIC + j); + + if (L && R) continue; + + REG_WSCNT = WS_ROM0_N4 | WS_ROM0_S2 | WS_PREFETCH; + return false; + } + return true; } \ No newline at end of file diff --git a/src/platform/gba/main.cpp b/src/platform/gba/main.cpp index 9aaea30..c18c9c5 100644 --- a/src/platform/gba/main.cpp +++ b/src/platform/gba/main.cpp @@ -596,7 +596,12 @@ int main(void) #ifdef PROFILING VBlankIntrWait(); + #else + if (gSettings.video_vsync) { + VBlankIntrWait(); + } #endif + REG_DISPCNT = (mode ^= DCNT_PAGE); fb ^= VRAM_PAGE_SIZE;