Show a better message if the game crashes
This commit is contained in:
@@ -78,13 +78,17 @@ static uint16 g_gamepad_last_cmd[kGamepadBtn_Count];
|
||||
extern Snes *g_snes;
|
||||
|
||||
void NORETURN Die(const char *error) {
|
||||
#if defined(NDEBUG) && defined(_WIN32)
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, kWindowTitle, error, NULL);
|
||||
#endif
|
||||
fprintf(stderr, "Error: %s\n", error);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void Warning(const char *error) {
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, kWindowTitle, error, NULL);
|
||||
fprintf(stderr, "Warning: %s\n", error);
|
||||
}
|
||||
|
||||
|
||||
void ChangeWindowScale(int scale_step) {
|
||||
if ((SDL_GetWindowFlags(g_window) & (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED)) != 0)
|
||||
return;
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "../types.h"
|
||||
#include "cart.h"
|
||||
#include "snes.h"
|
||||
|
||||
@@ -72,6 +71,8 @@ void cart_write(Cart* cart, uint8_t bank, uint16_t adr, uint8_t val) {
|
||||
}
|
||||
}
|
||||
|
||||
void DumpCpuHistory();
|
||||
|
||||
static uint8_t cart_readLorom(Cart* cart, uint8_t bank, uint16_t adr) {
|
||||
if(((bank >= 0x70 && bank < 0x7e) || bank >= 0xf0) && adr < 0x8000 && cart->ramSize > 0) {
|
||||
// banks 70-7e and f0-ff, adr 0000-7fff
|
||||
@@ -82,7 +83,9 @@ static uint8_t cart_readLorom(Cart* cart, uint8_t bank, uint16_t adr) {
|
||||
// adr 8000-ffff in all banks or all addresses in banks 40-7f and c0-ff
|
||||
return cart->rom[((bank << 15) | (adr & 0x7fff)) & (cart->romSize - 1)];
|
||||
}
|
||||
assert(0);
|
||||
printf("While trying to read from 0x%x\n", bank << 16 | adr);
|
||||
DumpCpuHistory();
|
||||
Die("The game crashed in cart_readLorom");
|
||||
return cart->snes->openBus;
|
||||
}
|
||||
|
||||
|
||||
@@ -727,6 +727,12 @@ uint32_t pc_hist[8], pc_hist_ctr;
|
||||
|
||||
uint32_t pc_bp = 0;
|
||||
|
||||
void DumpCpuHistory() {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
printf("PC history: 0x%x\n", pc_hist[(pc_hist_ctr + i) & 7]);
|
||||
}
|
||||
}
|
||||
|
||||
static void cpu_doOpcode(Cpu* cpu, uint8_t opcode) {
|
||||
uint32 cur_pc = ((cpu->k << 16) | cpu->pc - 1);
|
||||
pc_hist[pc_hist_ctr] = cur_pc;
|
||||
@@ -1344,9 +1350,7 @@ restart:
|
||||
uint8_t new_k = cpu_readOpcode(cpu);
|
||||
if (new_k == 0x80 && value == 0x8573) {
|
||||
printf("Current PC = 0x%x\n", cpu->k << 16 | cpu->pc);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
printf("PC history: 0x%x\n", pc_hist[(pc_hist_ctr + i) & 7]);
|
||||
}
|
||||
DumpCpuHistory();
|
||||
Die("The game has crashed!\n");
|
||||
}
|
||||
cpu->k = new_k;
|
||||
|
||||
@@ -70,6 +70,7 @@ static FORCEINLINE uint UintMax(uint a, uint b) { return a > b ? a : b; }
|
||||
static inline uint16 swap16(uint16 v) { return (v << 8) | (v >> 8); }
|
||||
|
||||
void NORETURN Die(const char *error);
|
||||
void Warning(const char *error);
|
||||
|
||||
// compile time assertion
|
||||
#define __CASSERT_N0__(l) COMPILE_TIME_ASSERT_ ## l
|
||||
|
||||
Reference in New Issue
Block a user