Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build_win_dbg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# NOTE: -gdwarf-2 needed for my version of wine to recognize the symbols.

x86_64-w64-mingw32-gcc -D__USE_MINGW_ANSI_STDIO=0 \
-Wall -W -Werror \
x86_64-w64-mingw32-gcc -D__USE_MINGW_ANSI_STDIO=0 -DPLATFORM_WINDOWS \
-Wall -W -Werror -Wl,--default-image-base-low \
-Wno-unknown-warning-option -Wno-address-of-packed-member \
-g -gdwarf-2 -o beebjit.exe \
main.c config.c bbc.c defs_6502.c state.c video.c via.c \
Expand Down
4 changes: 2 additions & 2 deletions build_win_opt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# NOTE: -gdwarf-2 needed for my version of wine to recognize the symbols.

x86_64-w64-mingw32-gcc -D__USE_MINGW_ANSI_STDIO=0 \
-Wall -W -Werror \
x86_64-w64-mingw32-gcc -D__USE_MINGW_ANSI_STDIO=0 -DPLATFORM_WINDOWS \
-Wall -W -Werror -Wl,--default-image-base-low \
-Wno-unknown-warning-option -Wno-address-of-packed-member \
-O3 -DNDEBUG -flto -o beebjit.exe \
main.c config.c bbc.c defs_6502.c state.c video.c via.c \
Expand Down
29 changes: 28 additions & 1 deletion util.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef PLATFORM_WINDOWS
#include "windows.h"
#endif

void*
util_malloc(size_t size) {
Expand Down Expand Up @@ -279,9 +282,12 @@ util_file_name_split(char** p_file_name_base,
const char* p_sep = NULL;
const char* p_str = p_full_file_name;

/* TODO: respect Windows separator? */
while (*p_str != '\0') {
#ifdef PLATFORM_WINDOWS
if (*p_str == '/' || *p_str == '\\') {
#else
if (*p_str == '/') {
#endif
p_sep = p_str;
}
p_str++;
Expand Down Expand Up @@ -309,7 +315,11 @@ util_file_name_join(const char* p_file_name_base, const char* p_file_name) {
/* TODO: respect Windows separator? */
(void) snprintf(file_name_buf,
sizeof(file_name_buf),
#ifdef PLATFORM_WINDOWS
"%s\\%s",
#else
"%s/%s",
#endif
p_file_name_base,
p_file_name);
return strdup(&file_name_buf[0]);
Expand All @@ -319,6 +329,23 @@ struct util_file*
util_file_open(const char* p_file_name, int writeable, int create) {
struct util_file* p_file = util_file_try_open(p_file_name, writeable, create);
if (p_file == NULL) {
#ifdef PLATFORM_WINDOWS
char executable_path_buf[4096];
char* executable_dir;
char* executable_file_name;
char* joined_file_name;
GetModuleFileNameA(NULL, executable_path_buf, 4096);
util_file_name_split(&executable_dir, &executable_file_name, executable_path_buf);
joined_file_name = util_file_name_join(executable_dir, p_file_name);

p_file = util_file_try_open(joined_file_name, writeable, create);

util_free(joined_file_name);
util_free(executable_file_name);
util_free(executable_dir);
}
if (p_file == NULL) {
#endif
util_bail("couldn't open %s", p_file_name);
}
return p_file;
Expand Down