Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
*.dSYM
/.vs/
/packages/
/saves/
/saves/*
!/saves/SAV_TESTS/
!/saves/testyourmine's/
*.o
/sm
/build/
Expand Down
Binary file added saves/SAV_TESTS/001-controller-inputs.sav
Binary file not shown.
Binary file added saves/SAV_TESTS/002-intro.sav
Binary file not shown.
Binary file added saves/SAV_TESTS/101-shine-spark.sav
Binary file not shown.
Binary file added saves/SAV_TESTS/102-moon-fall.sav
Binary file not shown.
Binary file added saves/SAV_TESTS/103-mock-ball.sav
Binary file not shown.
Binary file added saves/SAV_TESTS/104-crystal-flash.sav
Binary file not shown.
Binary file added saves/SAV_TESTS/201-alcatraz-escape.sav
Binary file not shown.
Binary file added saves/SAV_TESTS/202-green-gate-glitch.sav
Binary file not shown.
Binary file added saves/SAV_TESTS/999-black-out.sav
Binary file not shown.
Binary file added saves/testyourmine's/100 Percent.sav
Binary file not shown.
Binary file added saves/testyourmine's/Baby Metroid.sav
Binary file not shown.
Binary file added saves/testyourmine's/Bluesuit.sav
Binary file not shown.
Binary file added saves/testyourmine's/Bomb Torizo.sav
Binary file not shown.
Binary file added saves/testyourmine's/Botwoon.sav
Binary file not shown.
Binary file added saves/testyourmine's/Brinstar Pirates Appear.sav
Binary file not shown.
Binary file added saves/testyourmine's/Crocomire.sav
Binary file not shown.
Binary file added saves/testyourmine's/Draygon.sav
Binary file not shown.
Binary file added saves/testyourmine's/Golden Torizo.sav
Binary file not shown.
Binary file added saves/testyourmine's/Gravity Suit.sav
Binary file not shown.
Binary file added saves/testyourmine's/Green Brinstar.sav
Binary file not shown.
Binary file added saves/testyourmine's/Kraid's Lair.sav
Binary file not shown.
Binary file added saves/testyourmine's/Kraid.sav
Binary file not shown.
Binary file added saves/testyourmine's/Lower Maridia.sav
Binary file not shown.
Binary file added saves/testyourmine's/Lower Norfair.sav
Binary file not shown.
Binary file added saves/testyourmine's/Mother Brain Phase 1.sav
Binary file not shown.
Binary file added saves/testyourmine's/Mother Brain Phase 2.sav
Binary file not shown.
Binary file added saves/testyourmine's/Mother Brain Phase 3.sav
Binary file not shown.
Binary file added saves/testyourmine's/Norfair Enter.sav
Binary file not shown.
Binary file added saves/testyourmine's/Phantoon.sav
Binary file not shown.
Binary file added saves/testyourmine's/Red Brinstar Enter.sav
Binary file not shown.
Binary file added saves/testyourmine's/Red Brinstar Escape.sav
Binary file not shown.
Binary file added saves/testyourmine's/Ridley.sav
Binary file not shown.
Binary file added saves/testyourmine's/Spore Spawn Defeat.sav
Binary file not shown.
Binary file added saves/testyourmine's/Spore Spawn.sav
Binary file not shown.
Binary file added saves/testyourmine's/Tourian.sav
Binary file not shown.
Binary file added saves/testyourmine's/Wrecked Ship.sav
Binary file not shown.
Binary file added saves/testyourmine's/Zebes Escape.sav
Binary file not shown.
Binary file added saves/testyourmine's/Zebes Landing.sav
Binary file not shown.
Binary file added saves/testyourmine's/sm.srm
Binary file not shown.
Binary file added saves/testyourmine's/sm.srm.bak
Binary file not shown.
2 changes: 2 additions & 0 deletions sm.ini
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ Replay= Ctrl+F1,Ctrl+F2,Ctrl+F3,Ctrl+F4,Ctrl+F5,Ctrl+F6,Ctrl+F7,Ctrl+F8,Ctrl+F9,
LoadRef = 1,2,3,4,5,6,7,8,9,0,-,=,Backspace
ReplayRef = Ctrl+1,Ctrl+2,Ctrl+3,Ctrl+4,Ctrl+5,Ctrl+6,Ctrl+7,Ctrl+8,Ctrl+9,Ctrl+0,Ctrl+-,Ctrl+=,Ctrl+Backspace

SavTests = Shift+Ctrl+a

[GamepadMap]
# Any keys used in KeyMap can be used also in this section.
# The shoulder button is called L1/Lb and L2, and the thumbstick button is called L3
Expand Down
1 change: 1 addition & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static const KeyNameId kKeyNameId[] = {
S(CheatLife), S(CheatJump), S(ToggleWhichFrame),
S(ClearKeyLog), S(StopReplay), S(Fullscreen), S(Reset),
S(Pause), S(PauseDimmed), S(Turbo), S(ReplayTurbo), S(WindowBigger), S(WindowSmaller), S(VolumeUp), S(VolumeDown), S(DisplayPerf), S(ToggleRenderer),
S(SavTests)
};
#undef S
#undef M
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum {
kKeys_VolumeUp,
kKeys_VolumeDown,
kKeys_Total,
kKeys_SavTests
};

enum {
Expand Down
4 changes: 4 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "config.h"
#include "util.h"
#include "spc_player.h"
#include "rtk2/rtk2_sav_test.h"

#ifdef __SWITCH__
#include "switch_impl.h"
Expand Down Expand Up @@ -451,6 +452,8 @@ int main(int argc, char** argv) {
bool has_bug_in_title = false;

while (running) {
Rtk2_Rtl_Rtk2SaveTestRunner_StateMachine_Run();

SDL_Event event;

while (SDL_PollEvent(&event)) {
Expand Down Expand Up @@ -645,6 +648,7 @@ static void HandleCommand(uint32 j, bool pressed) {
RtlSaveLoad(kSaveLoad_Replay, 256 + j - kKeys_ReplayRef);
} else {
switch (j) {
case kKeys_SavTests: Rtk2SavTestRunner_Start(&g_sav_test_runner); break;
case kKeys_CheatLife: RtlCheat('w'); break;
case kKeys_CheatJump: RtlCheat('q'); break;
case kKeys_ToggleWhichFrame:
Expand Down
1 change: 1 addition & 0 deletions src/rtk2/rtk2_globals.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "rtk2_globals.h"
3 changes: 3 additions & 0 deletions src/rtk2/rtk2_globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#define log(fmt, ...) printf(fmt "\n", ##__VA_ARGS__)
76 changes: 76 additions & 0 deletions src/rtk2/rtk2_sav_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include "rtk2_sav_test.h"
#include "rtk2_globals.h"
#include "src/sm_rtl.h"

static Rtk2SaveTest SavTests[] = {
{001, "SAV_TESTS/001-controller-inputs"},
{002, "SAV_TESTS/002-intro"},
{101, "SAV_TESTS/101-shine-spark"},
{102, "SAV_TESTS/102-moon-fall"},
{103, "SAV_TESTS/103-mock-ball"},
{104, "SAV_TESTS/104-crystal-flash"},
{201, "SAV_TESTS/201-alcatraz-escape"},
{202, "SAV_TESTS/202-green-gate-glitch"},
{999, NULL}
};

Rtk2SaveTestRunner g_sav_test_runner = {
.state = kSavTestState_NONE,
.now_test_idx = 0,
.tests = SavTests
};


#define now_test(x) x->tests[x->now_test_idx]

void Rtk2SavTestRunner_ResolveSnapshotFail(Rtk2SaveTestRunner* x, bool has_failed)
{
if (x->state == kSavTestState_NONE) return;
if (!has_failed) return;
now_test(x).has_failed = has_failed;
}

void Rtk2SavTestRunner_Start(Rtk2SaveTestRunner* x)
{
x->state = kSavTestState_STARTING;
}

void Rtk2SavTestRunner_StateMachine_Run(Rtk2SaveTestRunner* x, bool is_replay)
{
switch (x->state)
{
case kSavTestState_STARTING:
x->state = kSavTestState_RUNNING;
x->now_test_idx = -1;
log("[SAV_TESTS] - tests stated");
break;
case kSavTestState_RUNNING:
if (is_replay) return;
x->now_test_idx++;
if (now_test(x).name != NULL)
{
Rtk2_RtlSaveLoad_ByName(kSaveLoad_Replay, now_test(x).name);
}
else
{
Rtk2_RtlSaveLoad_ByName(kSaveLoad_Replay, "SAV_TESTS/999-black-out");
x->state = kSavTestState_FINISHING;
log("[SAV_TESTS] - tests ended");
}
break;
case kSavTestState_FINISHING:
log("\n*** SAV TESTS RESULTS ******************");
for (struct Rtk2SavTest* test = x->tests; test && test->name != NULL; test++)
{
log("TEST #%03d | %s | %s", test->id, test->has_failed ? "FAIL" : "PASS", test->name);
}
log("****************************************");
x->state = kSavTestState_NONE;
break;
default:
break;
}
}
30 changes: 30 additions & 0 deletions src/rtk2/rtk2_sav_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <stdbool.h>
#include "src/types.h"

typedef struct Rtk2SavTest {
int id;
const char* name;
bool has_failed;
} Rtk2SaveTest;

typedef enum
{
kSavTestState_NONE,
kSavTestState_STARTING,
kSavTestState_RUNNING,
kSavTestState_FINISHING
} SavTestStates;

typedef struct Rtk2SaveTestRunner {
SavTestStates state;
int8 now_test_idx;
struct Rtk2SavTest* tests;
} Rtk2SaveTestRunner;

extern Rtk2SaveTestRunner g_sav_test_runner;

void Rtk2SavTestRunner_Start(Rtk2SaveTestRunner* x);
void Rtk2SavTestRunner_StateMachine_Run(Rtk2SaveTestRunner* x, bool is_replay);
void Rtk2SavTestRunner_ResolveSnapshotFail(Rtk2SaveTestRunner* x, bool has_failed);
4 changes: 4 additions & 0 deletions src/sm.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@
<ClCompile Include="main.c" />
<ClCompile Include="opengl.c" />
<ClCompile Include="platform\win32\volume_control.c" />
<ClCompile Include="rtk2\rtk2_globals.c" />
<ClCompile Include="rtk2\rtk2_sav_test.c" />
<ClCompile Include="sm_80.c" />
<ClCompile Include="sm_81.c" />
<ClCompile Include="sm_82.c" />
Expand Down Expand Up @@ -239,6 +241,8 @@
<ClInclude Include="glsl_shader.h" />
<ClInclude Include="ida_types.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="rtk2\rtk2_globals.h" />
<ClInclude Include="rtk2\rtk2_sav_test.h" />
<ClInclude Include="sm_80.h" />
<ClInclude Include="sm_81.h" />
<ClInclude Include="sm_82.h" />
Expand Down
46 changes: 22 additions & 24 deletions src/sm_82.c
Original file line number Diff line number Diff line change
Expand Up @@ -5029,28 +5029,26 @@ void OptionsMenuFunc6_DrawControllerBindings(void) {
}
}


void OptionsMenuControllerFunc_SetBinding(void) { // 0x82F6B9
uint16 v0 = 12;
while ((kControllerInputMasks[v0 >> 1] & joypad1_newkeys) == 0) {
v0 -= 2;
if ((v0 & 0x8000) != 0)
return;
}
uint16 r18 = v0 >> 1;
uint16 v1 = 2 * menu_option_index + 2;
if (!sign16(2 * menu_option_index - 12))
v1 = 0;
uint16 v2 = v1;
for (int i = 5; i >= 0; --i) {
if (eproj_F[(v2 >> 1) + 13] == r18)
break;
v2 += 2;
if ((int16)(v2 - 14) >= 0)
v2 = 0;
}
int v4 = menu_option_index;
uint16 r20 = eproj_F[v4 + 13];
eproj_F[v4 + 13] = r18;
eproj_F[(v2 >> 1) + 13] = r20;
OptionsMenuFunc6_DrawControllerBindings();
}
// Get the new button pressed, excluding the left and right dpad

const int16 MAX_INPUT_MASK_INDEX = 6;
int16 mask_index = MAX_INPUT_MASK_INDEX;
while ((kControllerInputMasks[mask_index] & joypad1_newkeys) == 0) {
--mask_index;
if (mask_index < 0) return;
}

uint16 new_binding = mask_index;
uint16 next_option_down = (menu_option_index + 1) % 7;

for (int i = 5; i >= 0; --i) {
if (optionsmenu_input_bindings[next_option_down] == new_binding) break;
next_option_down = (next_option_down + 1) % 7;
}

optionsmenu_input_bindings[next_option_down] = optionsmenu_input_bindings[menu_option_index];
optionsmenu_input_bindings[menu_option_index] = new_binding;
OptionsMenuFunc6_DrawControllerBindings();
}
4 changes: 4 additions & 0 deletions src/sm_cpu_infra.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "enemy_types.h"
#include <time.h>

#include "rtk2/rtk2_sav_test.h"

void RtlRunFrameCompare(uint16 input, int run_what);

enum RunMode { RM_BOTH, RM_MINE, RM_THEIRS };
Expand Down Expand Up @@ -991,6 +993,8 @@ void RunOneFrameOfGame_Both(void) {
// Compare both snapshots
VerifySnapshotsEq(&g_snapshot_mine, &g_snapshot_theirs, &g_snapshot_before);

Rtk2SavTestRunner_ResolveSnapshotFail(&g_sav_test_runner, g_fail);

if (g_fail) {
g_fail = false;

Expand Down
47 changes: 47 additions & 0 deletions src/sm_rtl.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "funcs.h"
#include "spc_player.h"
#include "util.h"
#include "rtk2/rtk2_sav_test.h"

struct StateRecorder;

Expand Down Expand Up @@ -490,6 +491,52 @@ void RtlSaveLoad(int cmd, int slot) {
}
}

void Rtk2_Rtl_Rtk2SaveTestRunner_StateMachine_Run()
{
// added bcuz state_recorder is private
Rtk2SavTestRunner_StateMachine_Run(&g_sav_test_runner, state_recorder.replay_mode);
}

void Rtk2_RtlSaveLoad_ByName(int cmd, const char* filename) {
//carbon copy of RtlSaveLoad... I'm just to scared to refactor them at this point :D
char name[128];
sprintf(name, "saves/%s.sav", filename);

printf("*** %s filename %s\n", cmd == kSaveLoad_Save ? "Saving" : cmd == kSaveLoad_Load ? "Loading" : "Replaying", filename);
if (cmd != kSaveLoad_Save) {

FILE* f = fopen(name, "rb");
if (f == NULL) {
printf("Failed fopen: %s\n", name);
return;
}
RtlApuLock();
StateRecorder_Load(&state_recorder, f, cmd == kSaveLoad_Replay);
ppu_copy(g_snes->my_ppu, g_snes->ppu);
RtlApuUnlock();
RtlSynchronizeWholeState();
fclose(f);

if (coroutine_state_0 | coroutine_state_1 | coroutine_state_2 | coroutine_state_3 | coroutine_state_4) {
printf("Coroutine state: %d, %d, %d, %d, %d\n",
coroutine_state_0, coroutine_state_1, coroutine_state_2, coroutine_state_3, coroutine_state_4);
}

// Earlier versions used coroutine_state_0 differently
if (coroutine_state_0 == 4)
coroutine_state_0 = 10 + game_state;

// bug_fix_counter_BAD didn't actually belong to free ram...
if (bug_fix_counter == 0)
bug_fix_counter = bug_fix_counter_BAD;

}
else {
RtlSaveSnapshot(name, false);
}
}


/**
* @brief Copies size bytes from the source to the destination
* @param *dst Pointer to destination
Expand Down
3 changes: 3 additions & 0 deletions src/sm_rtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ enum {
};

void RtlSaveLoad(int cmd, int slot);

void Rtk2_Rtl_Rtk2SaveTestRunner_StateMachine_Run();
void Rtk2_RtlSaveLoad_ByName(int cmd, const char* filename);
void RtlCheat(char c);
void RtlApuLock();
void RtlApuUnlock();
Expand Down