Last active
May 27, 2023 17:44
-
-
Save Oxore/cde8d07114d09ca87935edc4d6a1eec9 to your computer and use it in GitHub Desktop.
A patch for Picodrive emulator to obtain all values that program counter had through the game that you were playing. Very handy for disassembling Sega Mega Drive / Genesis games. https://github.com/notaz/picodrive, commit 8cd962d14d7a866c69ebc82b9679a426c7709adb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/cpu/fame/famec.c b/cpu/fame/famec.c | |
index 9e832bc4..f598797a 100644 | |
--- a/cpu/fame/famec.c | |
+++ b/cpu/fame/famec.c | |
@@ -222,8 +222,11 @@ https://github.com/notaz/picodrive, commit 8cd962d14d7a866c69ebc82b9679a426c7709adb | |
#define ROR_32(A, C) (LSR_32(A, C) | LSL_32(A, 32-(C))) | |
#define ROR_33(A, C) (LSR_32(A, C) | LSL_32(A, 33-(C))) | |
+extern void trace_pc(unsigned); | |
+ | |
#ifndef FAMEC_NO_GOTOS | |
#define NEXT \ | |
+ trace_pc((unsigned)((uintptr_t)PC - BasePC)); \ | |
FETCH_WORD(Opcode); \ | |
goto *JumpTable[Opcode]; | |
diff --git a/platform/common/emu.c b/platform/common/emu.c | |
index f371f5bc..7cbfb2cb 100644 | |
--- a/platform/common/emu.c | |
+++ b/platform/common/emu.c | |
@@ -1171,6 +1171,40 @@ static void run_events_ui(unsigned int which) | |
engineState = PGS_Menu; | |
} | |
+#define ROM_SIZE ((size_t)(4*1024*1024)) | |
+static unsigned char pc_map[ROM_SIZE] = {0}; | |
+ | |
+#include <assert.h> | |
+#include <errno.h> | |
+ | |
+void trace_pc(unsigned pc) | |
+{ | |
+ assert(pc < ROM_SIZE); | |
+ pc_map[pc] = 1; | |
+} | |
+ | |
+static void dump_pc(void) | |
+{ | |
+ const char *file_name = "/tmp/trace.txt"; | |
+ FILE *out = fopen(file_name, "w"); | |
+ if (out == NULL) { | |
+ const int err = errno; | |
+ fprintf( | |
+ stderr, | |
+ "dump_pc: fopen(\"%s\", \"r\"): Error (%d): \"%s\"\n", | |
+ file_name, | |
+ err, | |
+ strerror(err)); | |
+ return; | |
+ } | |
+ for (size_t i = 0; i < ROM_SIZE; i++) { | |
+ if (pc_map[i]) { | |
+ fprintf(out, "%zu\n", i); | |
+ } | |
+ } | |
+ fclose(out); | |
+} | |
+ | |
void emu_update_input(void) | |
{ | |
static int prev_events = 0; | |
@@ -1179,6 +1213,16 @@ void emu_update_input(void) | |
int events; | |
in_update(actions); | |
+ // F6 key | |
+ static int pressed_f6 = 0; | |
+ if ((actions[0] & 0x00100000) && !pressed_f6) { | |
+ pressed_f6 = 1; | |
+ printf("Pressed F6\n"); | |
+ } else if (!(actions[0] & 0x00100000) && pressed_f6) { | |
+ pressed_f6 = 0; | |
+ printf("Released F6\n"); | |
+ dump_pc(); | |
+ } | |
pl_actions[0] = actions[IN_BINDTYPE_PLAYER12]; | |
pl_actions[1] = actions[IN_BINDTYPE_PLAYER12] >> 16; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment