Decompile main (#1326)

Decompiles `main`.

Co-authored-by: Jonathan Hohle <jon@ttkb.co>
This commit is contained in:
Jonathan Hohle 2024-06-16 20:11:42 -07:00 committed by GitHub
parent b01fe2b36b
commit 32f42645d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 78 additions and 1 deletions

View File

@ -1,3 +1,6 @@
D_80010960 = 0x80010960; // force_migration:True
D_80010964 = 0x80010964; // force_migration:True
main_fd = 0x800339F8;
main_cdlFile = 0x800339FC;
main_cdlMode = 0x80033A14;
g_MainGame = 0x800A0000;

View File

@ -185,6 +185,7 @@ typedef struct Prim {
#define WEAPON_1_START 0xF0
#ifndef VERSION_PC
#define DRA_PRG_PTR 0x800A0000
#define RIC_PRG_PTR 0x8013C000
#define FAMILIAR_PTR 0x80170000
#define WEAPON0_PTR 0x8017A000
@ -199,6 +200,7 @@ typedef struct Prim {
#define SIM_PTR 0x80280000
#else
#define DRA_PRG_PTR 0x800A0000
#define RIC_PRG_PTR 0x8013C000
#define FAMILIAR_PTR 0x80170000
#define WEAPON0_PTR 0x8017A000
@ -334,6 +336,7 @@ typedef enum {
Game_PrologueEnd,
Game_MainMenu,
Game_Ending,
Game_Boot,
Game_99 = 99,
} GameState;

View File

@ -1,5 +1,76 @@
#include "common.h"
#include "game.h"
INCLUDE_ASM("main/nonmatchings/main", main);
extern void (*g_MainGame)();
extern CdlFILE main_cdlFile;
extern u8 main_cdlMode[];
extern s32 main_fd;
void main(void) {
ResetCallback();
InitHeap((void*)0x801F0000, 0x7800);
CdInit();
g_GameState = Game_Boot;
do {
main_fd = open("sim:c:\\bin\\dra.bin", 1);
} while (main_fd == -1 && --g_GameState != Game_Init);
if (g_GameState != Game_Init) {
read(main_fd, (void*)DRA_PRG_PTR, 0x130000);
close(main_fd);
g_UseDisk = 0;
main_fd = open("sim:c:\\bin\\dra.bio", 1);
if (main_fd != -1) {
g_UseDisk = 2;
}
do {
main_fd = open("sim:c:\\bin\\f_map.bin", 1);
} while (main_fd < 0);
read(main_fd, (void*)CASTLE_MAP_PTR, 0x8000);
close(main_fd);
} else {
main_search_loop_1:
while (!CdSearchFile(&main_cdlFile, "\\DRA.BIN;1")) {
}
*main_cdlMode = CdlModeSpeed | CdlModeSpeedNormal;
CdControl(CdlSetmode, main_cdlMode, NULL);
while (CdSync(1, NULL) != 2) {
}
g_GameState = (main_cdlFile.size + 0x7ff) >> 0xB;
CdControl(CdlSetloc, &main_cdlFile, NULL);
CdRead(g_GameState, (u32*)DRA_PRG_PTR, 0x80);
// block until read is complete
main_fd = CdReadSync(0, NULL);
if (main_fd < 0) {
goto main_search_loop_1;
}
g_UseDisk = 1;
main_search_loop_2:
if (!CdSearchFile(&main_cdlFile, "\\F_MAP.BIN;1")) {
goto main_search_loop_2;
} else {
g_GameState = (main_cdlFile.size + 0x7ff) >> 0xB;
}
CdControl(CdlSetloc, &main_cdlFile, NULL);
CdRead(g_GameState, (u32*)CASTLE_MAP_PTR, 0x80);
// block until read is complete
main_fd = CdReadSync(0, NULL);
if (main_fd < 0) {
goto main_search_loop_2;
}
}
g_MainGame();
}
const char a0123456789abcd[] = "0123456789ABCDEF\0\0\0\0";