Made Config.cpp ASM-accurate

This commit is contained in:
Clownacy 2019-05-07 13:18:32 +01:00
parent f204e14291
commit 666269029d
3 changed files with 36 additions and 10 deletions

View file

@ -271,6 +271,14 @@ addr = 0x40ABC0
name = "SetCaret" name = "SetCaret"
addr = 0x40AC90 addr = 0x40AC90
[[func]]
name = "LoadConfigData"
addr = 0x40AD60
[[func]]
name = "DefaultConfigData"
addr = 0x40AE30
[[func]] [[func]]
name = "Call_Escape" name = "Call_Escape"
addr = 0x40DD70 addr = 0x40DD70

View file

@ -11,21 +11,27 @@
#include "Tags.h" #include "Tags.h"
#include "Types.h" #include "Types.h"
bool LoadConfigData(CONFIG *conf) static const char* const config_filename = "Config.dat"; // Not the original name
static const char* const config_magic = "DOUKUTSU20041206"; // Not the original name
BOOL LoadConfigData(CONFIG *conf)
{ {
//Clear old config data //Clear old config data
memset(conf, 0, sizeof(CONFIG)); memset(conf, 0, sizeof(CONFIG));
//Get path //Get path
char path[PATH_LENGTH]; char path[PATH_LENGTH];
sprintf(path, "%s/%s", gModulePath, "Config.dat"); sprintf(path, "%s/%s", gModulePath, config_filename);
//Open file //Open file
FILE *fp = fopen(path, "rb"); FILE *fp = fopen(path, "rb");
if (fp == NULL) if (fp == NULL)
return false; return FALSE;
//Read data //Read data
#ifdef NONPORTABLE
size_t fread_result = fread(conf, sizeof(CONFIG), 1, fp); // Not the original name
#else
//Read the version id and font name //Read the version id and font name
fread(conf->proof, sizeof(conf->proof), 1, fp); fread(conf->proof, sizeof(conf->proof), 1, fp);
fread(conf->font_name, sizeof(conf->font_name), 1, fp); fread(conf->font_name, sizeof(conf->font_name), 1, fp);
@ -42,23 +48,33 @@ bool LoadConfigData(CONFIG *conf)
conf->bJoystick = File_ReadLE32(fp); conf->bJoystick = File_ReadLE32(fp);
for (int button = 0; button < 8; button++) for (int button = 0; button < 8; button++)
conf->joystick_button[button] = File_ReadLE32(fp); conf->joystick_button[button] = File_ReadLE32(fp);
#endif
//Close file //Close file
fclose(fp); fclose(fp);
//Check if version is correct, return that it succeeded //Check if version is not correct, and return if it failed
if (!strcmp(conf->proof, "DOUKUTSU20041206")) #ifdef NONPORTABLE
return true; if (fread_result != 1 || strcmp(conf->proof, config_magic))
#else
if (strcmp(conf->proof, config_magic))
#endif
{
memset(conf, 0, sizeof(CONFIG));
return FALSE;
}
//If not, return that it failed return TRUE;
return false;
} }
void DefaultConfigData(CONFIG *conf) void DefaultConfigData(CONFIG *conf)
{ {
//Claer old config data //Clear old config data
memset(conf, 0, sizeof(CONFIG)); memset(conf, 0, sizeof(CONFIG));
//Fun fact: The Linux port added this line:
//conf->display_mode = 1;
//Reset joystick settings (as these can't simply be set to 0) //Reset joystick settings (as these can't simply be set to 0)
conf->bJoystick = 1; conf->bJoystick = 1;
conf->joystick_button[0] = 2; conf->joystick_button[0] = 2;

View file

@ -2,6 +2,8 @@
#include <stdint.h> #include <stdint.h>
#include "WindowsWrapper.h"
struct CONFIG struct CONFIG
{ {
char proof[0x20]; char proof[0x20];
@ -14,5 +16,5 @@ struct CONFIG
int32_t joystick_button[8]; int32_t joystick_button[8];
}; };
bool LoadConfigData(CONFIG *conf); BOOL LoadConfigData(CONFIG *conf);
void DefaultConfigData(CONFIG *conf); void DefaultConfigData(CONFIG *conf);