From a39a82cc9773c8336eaa48379f2d2fe3615f178c Mon Sep 17 00:00:00 2001 From: Mike Pavone Date: Tue, 17 Jun 2014 01:50:29 -0400 Subject: blastem builds and almost works on OS X now --- util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'util.c') diff --git a/util.c b/util.c index 2bc3109..5367cd5 100644 --- a/util.c +++ b/util.c @@ -92,7 +92,7 @@ char * readlink_alloc(char * path) if (linksize == -1) { perror("readlink"); free(linktext); - linktext = NULL; + return NULL; } } while ((linksize+1) > cursize); linktext[linksize] = 0; -- cgit v1.2.3 From 983959f838575b6af3e64be442a63647312fcc61 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sun, 28 Jun 2015 18:44:11 -0700 Subject: Get "portable" builds working on Linux and add a build time check for whether /proc exists --- util.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'util.c') diff --git a/util.c b/util.c index fc95011..20aa2ee 100644 --- a/util.c +++ b/util.c @@ -138,11 +138,12 @@ char * get_exe_dir() { static char * exe_dir; if (!exe_dir) { + char * cur; +#ifndef HAS_PROC char * linktext = readlink_alloc("/proc/self/exe"); if (!linktext) { goto fallback; } - char * cur; int linksize = strlen(linktext); for(cur = linktext + linksize - 1; cur != linktext; cur--) { @@ -154,6 +155,7 @@ char * get_exe_dir() if (cur == linktext) { free(linktext); fallback: +#endif if (!exe_str) { fputs("/proc/self/exe is not available and set_exe_str was not called!", stderr); } @@ -167,9 +169,11 @@ fallback: break; } } +#ifndef HAS_PROC } else { exe_dir = linktext; } +#endif } return exe_dir; } -- cgit v1.2.3 From 631c3b800a023f7c7021ada70760dfeb0617d47b Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sun, 28 Jun 2015 19:23:38 -0700 Subject: Fix sense of HAS_PROC check --- util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 20aa2ee..89b5273 100644 --- a/util.c +++ b/util.c @@ -139,7 +139,7 @@ char * get_exe_dir() static char * exe_dir; if (!exe_dir) { char * cur; -#ifndef HAS_PROC +#ifdef HAS_PROC char * linktext = readlink_alloc("/proc/self/exe"); if (!linktext) { goto fallback; @@ -169,7 +169,7 @@ fallback: break; } } -#ifndef HAS_PROC +#ifdef HAS_PROC } else { exe_dir = linktext; } -- cgit v1.2.3 From 8af1d14863bb6ffad2c50b5275a848240c68c62e Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Tue, 7 Jul 2015 19:33:33 -0700 Subject: Add support for reading cartridge memory map from ROM database, though without EEPROM support for now --- util.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index 20aa2ee..361d26b 100644 --- a/util.c +++ b/util.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -68,6 +69,16 @@ char * split_keyval(char * text) return text+1; } +uint32_t nearest_pow2(uint32_t val) +{ + uint32_t ret = 1; + while (ret < val) + { + ret = ret << 1; + } + return ret; +} + static char * exe_str; void set_exe_str(char * str) -- cgit v1.2.3 From 80ff833dd8ad011b579bff26ac654819e6735bce Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sat, 25 Jul 2015 18:22:07 -0700 Subject: Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows). --- util.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index 2a59b08..3ad290d 100644 --- a/util.c +++ b/util.c @@ -8,6 +8,9 @@ #include #include +#include "blastem.h" //for headless global +#include "render.h" //for render_errorbox + char * alloc_concat(char * first, char * second) { int flen = strlen(first); @@ -86,6 +89,62 @@ void set_exe_str(char * str) exe_str = str; } +void fatal_error(char *format, ...) +{ + va_list args; + va_start(args, format); + if (!headless) { + //take a guess at the final size + size_t size = strlen(format) * 2; + char *buf = malloc(size); + size_t actual = vsnprintf(buf, size, format, args); + if (actual >= size) { + actual++; + free(buf); + buf = malloc(actual); + va_end(args); + va_start(args, format); + vsnprintf(buf, actual, format, args); + } + fputs(buf, stderr); + render_errorbox("Fatal Error", buf); + free(buf); + } else { + vfprintf(stderr, format, args); + } + va_end(args); + exit(1); +} + +void info_message(char *format, ...) +{ + va_list args; + va_start(args, format); +#ifndef _WIN32 + if (headless || (isatty(STDOUT_FILENO) && isatty(STDIN_FILENO))) { + vprintf(format, args); + } else { +#endif + size_t size = strlen(format) * 2; + char *buf = malloc(size); + size_t actual = vsnprintf(buf, size, format, args); + if (actual >= size) { + actual++; + free(buf); + buf = malloc(actual); + va_end(args); + va_start(args, format); + vsnprintf(buf, actual, format, args); + } + fputs(buf, stdout); + render_infobox("BlastEm Info", buf); + free(buf); +#ifndef _WIN32 + } +#endif + va_end(args); +} + #ifdef _WIN32 #include "Shlobj.h" #include "Windows.h" -- cgit v1.2.3 From bee8b42029900ca034675c54d98813a61ca4407a Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sun, 26 Jul 2015 01:11:04 -0700 Subject: Spawn a terminal for the debugger when needed if we are not already attached to one --- util.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index 3ad290d..c0131b2 100644 --- a/util.c +++ b/util.c @@ -116,6 +116,35 @@ void fatal_error(char *format, ...) exit(1); } +void warning(char *format, ...) +{ + va_list args; + va_start(args, format); +#ifndef _WIN32 + if (headless || (isatty(STDERR_FILENO) && isatty(STDIN_FILENO))) { + vfprintf(stderr, format, args); + } else { +#endif + size_t size = strlen(format) * 2; + char *buf = malloc(size); + size_t actual = vsnprintf(buf, size, format, args); + if (actual >= size) { + actual++; + free(buf); + buf = malloc(actual); + va_end(args); + va_start(args, format); + vsnprintf(buf, actual, format, args); + } + fputs(buf, stderr); + render_infobox("BlastEm Info", buf); + free(buf); +#ifndef _WIN32 + } +#endif + va_end(args); +} + void info_message(char *format, ...) { va_list args; -- cgit v1.2.3 From eb2f5614ca10aed240f2d7b310c6929874effc3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=3D=3FUTF-8=3Fq=3FHigor=3D20Eur=3DC3=3DADpedes=3F=3D?= Date: Sun, 26 Jul 2015 10:59:41 -0700 Subject: Fix mingw-w64 build and cross-compilation --- util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 2a59b08..9722d3e 100644 --- a/util.c +++ b/util.c @@ -87,8 +87,8 @@ void set_exe_str(char * str) } #ifdef _WIN32 -#include "Shlobj.h" -#include "Windows.h" +#include +#include char * get_home_dir() { -- cgit v1.2.3