Fix various issues with MSYS2/mingw build

This commit is contained in:
Nunuhara Cabbage
2020-02-14 16:29:44 -08:00
parent 623f8c8ebf
commit 608aedb500
13 changed files with 54 additions and 17 deletions
+6
View File
@@ -87,4 +87,10 @@ char *unix_path(const char *path);
char *gamedir_path(const char *path);
char *savedir_path(const char *filename);
#ifdef _WIN32
#define SIZE_T_FMT "I"
#else
#define SIZE_T_FMT "z"
#endif
#endif /* SYSTEM4_H */
+1 -1
View File
@@ -147,7 +147,7 @@ struct ain_variable {
};
struct ain_function {
int32_t address;
ain_addr_t address;
char *name;
bool is_label;
struct ain_type return_type;
+2
View File
@@ -378,6 +378,8 @@ struct instruction {
struct instruction instructions[NR_OPCODES];
void initialize_instructions(void);
static const_pure inline int32_t instruction_width(enum opcode opcode)
{
return 2 + instructions[opcode].nr_args * 4;
+1 -1
View File
@@ -631,7 +631,7 @@ static struct ain_function_type *read_function_types(struct ain_reader *r, int c
do { \
const struct instruction *instr; \
for (size_t addr = start; addr < ain->code_size; addr += instruction_width(instr->opcode)) { \
int16_t _fei_opcode = LittleEndian_getW(ain->code, addr); \
uint16_t _fei_opcode = LittleEndian_getW(ain->code, addr); \
if (_fei_opcode >= NR_OPCODES) \
ERROR("Unknown/invalid opcode: %u", _fei_opcode); \
instr = &instructions[_fei_opcode]; \
+6 -5
View File
@@ -393,21 +393,21 @@ static void ain_audit(FILE *f, struct ain *ain)
uint16_t opcode = LittleEndian_getW(ain->code, addr);
const struct instruction *instr = &instructions[opcode];
if (opcode >= NR_OPCODES) {
ERROR("0x%08lx: Invalid/unknown opcode: %x", opcode);
ERROR("0x%08" SIZE_T_FMT "x: Invalid/unknown opcode: %x", opcode);
}
if (!instr->implemented) {
fprintf(f, "0x%08lx: %s (unimplemented instruction)\n", addr, instr->name);
fprintf(f, "0x%08" SIZE_T_FMT "x: %s (unimplemented instruction)\n", addr, instr->name);
}
if (opcode == CALLSYS) {
uint32_t syscode = LittleEndian_getDW(ain->code, addr + 2);
if (syscode >= NR_SYSCALLS) {
ERROR("0x%08lx: CALLSYS system.(0x%x)\n", addr, syscode);
ERROR("0x%08" SIZE_T_FMT "x: CALLSYS system.(0x%x)\n", addr, syscode);
}
const char * const name = syscalls[syscode].name;
if (!name) {
fprintf(f, "0x%08lx: CALLSYS system.(0x%x)\n", addr, syscode);
fprintf(f, "0x%08" SIZE_T_FMT "x: CALLSYS system.(0x%x)\n", addr, syscode);
} else if (!syscalls[syscode].implemented) {
fprintf(f, "0x%08lx: CALLSYS %s (unimplemented system call)\n", addr, name);
fprintf(f, "0x%08" SIZE_T_FMT "x: CALLSYS %s (unimplemented system call)\n", addr, name);
}
}
@@ -490,6 +490,7 @@ enum {
int main(int argc, char *argv[])
{
initialize_instructions();
bool decrypt = false;
char *output_file = NULL;
FILE *output = stdout;
+5 -5
View File
@@ -318,7 +318,7 @@ static void print_argument(struct dasm_state *dasm, int32_t arg, enum instructio
switch (type) {
case T_INT:
case T_SWITCH:
fprintf(dasm->out, "0x%x", arg);
fprintf(dasm->out, "%d", arg);
break;
case T_FLOAT:
fprintf(dasm->out, "%f", arg_to_float(arg));
@@ -469,7 +469,7 @@ static void dasm_leave_function(struct dasm_state *dasm)
static void print_instruction(struct dasm_state *dasm, const struct instruction *instr)
{
if (dasm->flags & DASM_RAW)
fprintf(dasm->out, "0x%08lX:\t", dasm->addr);
fprintf(dasm->out, "0x%08" SIZE_T_FMT "X:\t", dasm->addr);
switch (instr->opcode) {
case FUNC:
@@ -503,7 +503,7 @@ static const struct instruction *get_instruction(struct dasm_state *dasm)
static void print_switch_case(struct dasm_state *dasm, struct ain_switch_case *c)
{
fprintf(dasm->out, ".CASE %ld:%ld ", c->parent - dasm->ain->switches, c - c->parent->cases);
fprintf(dasm->out, ".CASE %" SIZE_T_FMT "d:%" SIZE_T_FMT "d ", c->parent - dasm->ain->switches, c - c->parent->cases);
switch (c->parent->case_type) {
case AIN_SWITCH_INT:
fprintf(dasm->out, "%d", c->value);
@@ -527,7 +527,7 @@ static void print_switch_case(struct dasm_state *dasm, struct ain_switch_case *c
static char *genlabel(size_t addr)
{
char name[64];
snprintf(name, 64, "0x%lx", addr);
snprintf(name, 64, "0x%" SIZE_T_FMT "x", addr);
return strdup(name);
}
@@ -589,7 +589,7 @@ void disassemble_ain(FILE *out, struct ain *ain, unsigned int flags)
print_switch_case(&dasm, t->switch_case);
break;
case JMP_DEFAULT:
fprintf(dasm.out, ".DEFAULT %ld\n", t->switch_default - dasm.ain->switches);
fprintf(dasm.out, ".DEFAULT %" SIZE_T_FMT "d\n", t->switch_default - dasm.ain->switches);
break;
}
}
+1 -1
View File
@@ -42,7 +42,7 @@ static size_t get_prefix_length(char *a, char *b)
static char *guess_itoa(possibly_unused struct guesser_state *state, size_t n)
{
char buf[512];
snprintf(buf, 512, "%lu", n);
snprintf(buf, 512, "%" SIZE_T_FMT "u", n);
return strdup(buf);
}
+1
View File
@@ -51,6 +51,7 @@ enum {
int main(int argc, char *argv[])
{
initialize_instructions();
struct ain *ain;
int err = AIN_SUCCESS;
const char *code_file = NULL;
+1 -1
View File
@@ -427,7 +427,7 @@ void ain_write(const char *filename, struct ain *ain)
else
buf = ain_compress(buf, &len);
FILE *out = fopen(filename, "w");
FILE *out = fopen(filename, "wb");
if (!out)
ERROR("Failed to open '%s': %s", filename, strerror(errno));
if (fwrite(buf, len, 1, out) != 1)
+13 -1
View File
@@ -23,11 +23,19 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
#include "little_endian.h"
#include "system4.h"
#include "system4/ald.h"
#ifdef _WIN32
#define mmap(...) (ERROR("mmap not supported on Windows"), NULL)
#define munmap(...) ERROR("munmap not supported on Windows")
#define MAP_FAILED 0
#else
#include <sys/mman.h>
#endif
static const char *errtab[ALD_MAX_ERROR] = {
[ALD_SUCCESS] = "Success",
[ALD_FILE_ERROR] = "Error opening ALD file",
@@ -258,6 +266,10 @@ struct ald_archive *ald_open(char **files, int count, int flags, int *error)
struct ald_archive *ar = calloc(1, sizeof(struct ald_archive));
bool gotmap = false;
#ifdef _WIN32
flags &= ~ALD_MMAP;
#endif
for (int i = 0; i < count; i++) {
// XXX: why allow this?
if (!files[i])
+9 -2
View File
@@ -60,6 +60,13 @@ bool file_exists(const char *path)
return access(path, F_OK) != -1;
}
#if (defined(_WIN32) || defined(__WIN32__))
#include <direct.h>
#define make_dir(path, mode) _mkdir(path)
#else
#define make_dir(path, mode) mkdir(path, mode)
#endif
// Adapted from http://stackoverflow.com/a/2336245/119527
int mkdir_p(const char *path)
{
@@ -82,7 +89,7 @@ int mkdir_p(const char *path)
// Temporarily truncate
*p = '\0';
if (mkdir(_path, S_IRWXU) != 0) {
if (make_dir(_path, S_IRWXU) != 0) {
if (errno != EEXIST)
return -1;
}
@@ -91,7 +98,7 @@ int mkdir_p(const char *path)
}
}
if (mkdir(_path, S_IRWXU) != 0) {
if (make_dir(_path, S_IRWXU) != 0) {
if (errno != EEXIST)
return -1;
}
+6
View File
@@ -378,3 +378,9 @@ struct instruction instructions[NR_OPCODES] = {
TODO ( OP_0X104, 0 ),
TODO ( OP_0X105, 1, T_STRUCT ),
};
void initialize_instructions(void)
{
// this is a dumb hack to force linking/initialization of the above
// arrays on Windows.
}
+2
View File
@@ -26,6 +26,7 @@
#include "system4.h"
#include "system4/ain.h"
#include "system4/ald.h"
#include "system4/instructions.h"
#include "system4/utfsjis.h"
#include "vm.h"
@@ -196,6 +197,7 @@ static void config_init(void)
int main(int argc, char *argv[])
{
initialize_instructions();
size_t len;
char *ainfile;
int err = AIN_SUCCESS;