aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspicyjpeg <88942473+spicyjpeg@users.noreply.github.com>2021-11-28 18:46:06 +0100
committerspicyjpeg <88942473+spicyjpeg@users.noreply.github.com>2021-11-28 18:46:06 +0100
commit7186b911cc461dbdad9307afd8901be118e20893 (patch)
treed4fe73b268c92345922625329e6a5f43ce914254
parenta75b3fa4b1a1b882c33f533645ddae75c09dd697 (diff)
downloadpsn00bsdk-7186b911cc461dbdad9307afd8901be118e20893.tar.gz
CMake fixes, psxcd and printf/scanf improvements
-rw-r--r--libpsn00b/cmake/flags.cmake9
-rw-r--r--libpsn00b/cmake/sdk.cmake2
-rw-r--r--libpsn00b/libc/scanf.c7
-rw-r--r--libpsn00b/libc/string.c14
-rw-r--r--libpsn00b/libc/vsprintf.c11
-rw-r--r--libpsn00b/psxcd/isofs.c28
6 files changed, 57 insertions, 14 deletions
diff --git a/libpsn00b/cmake/flags.cmake b/libpsn00b/cmake/flags.cmake
index e163e52..249c5b4 100644
--- a/libpsn00b/cmake/flags.cmake
+++ b/libpsn00b/cmake/flags.cmake
@@ -2,9 +2,8 @@
# (C) 2021 spicyjpeg - MPL licensed
# This script creates several "virtual" targets (psn00bsdk_*) that set include
-# directories and compiler flags when a target is linked against them.
-#
-# The following targets are currently defined:
+# directories and compiler flags when a target is linked against them. The
+# following targets are currently defined:
# - psn00bsdk_common
# - psn00bsdk_object_lib (same as psn00bsdk_common)
# - psn00bsdk_static_exe
@@ -16,6 +15,8 @@
# NOTE: building a static library and linking it as part of a DLL is currently
# *not* supported.
+if(NOT TARGET psn00bsdk_common) # Include guard
+
add_library(psn00bsdk_common INTERFACE)
foreach(
@@ -146,3 +147,5 @@ target_link_options(
)
target_link_libraries(psn00bsdk_module_lib INTERFACE psn00bsdk_shared_lib)
+
+endif()
diff --git a/libpsn00b/cmake/sdk.cmake b/libpsn00b/cmake/sdk.cmake
index 1dfa431..d6d9bcd 100644
--- a/libpsn00b/cmake/sdk.cmake
+++ b/libpsn00b/cmake/sdk.cmake
@@ -26,7 +26,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# toolchain settings to the generated test projects. This dodges missing C++
# standard library errors.
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES PSN00BSDK_TC PSN00BSDK_TARGET)
+set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES PSN00BSDK_TC PSN00BSDK_TARGET PSN00BSDK_VERSION)
## Toolchain path setup
diff --git a/libpsn00b/libc/scanf.c b/libpsn00b/libc/scanf.c
index b6d4510..ae3c714 100644
--- a/libpsn00b/libc/scanf.c
+++ b/libpsn00b/libc/scanf.c
@@ -8,6 +8,9 @@
#include <string.h>
#include <strings.h>
+// Uncomment to enable support for %f.
+//#define ALLOW_FLOAT
+
char libc_vsscanf_buf[512];
char libc_vsscanf_allow[256];
@@ -354,7 +357,8 @@ int vsscanf(const char *str, const char *format, va_list ap)
r++;
}
break;
-
+
+#ifdef ALLOW_FLOAT
case 'f': // Floating point number
libc_vsscanf_get_element(libc_vsscanf_buf, &str[sp], elem_skip_space, fsz);
fbuf = strtod(libc_vsscanf_buf, &ep);
@@ -380,6 +384,7 @@ int vsscanf(const char *str, const char *format, va_list ap)
conv = 0;
break;
+#endif
}
}
diff --git a/libpsn00b/libc/string.c b/libpsn00b/libc/string.c
index 445b227..a1a9a05 100644
--- a/libpsn00b/libc/string.c
+++ b/libpsn00b/libc/string.c
@@ -8,6 +8,10 @@
#include <string.h>
#include <stdlib.h>
+// Uncomment to enable strtod(), strtold() and strtof(). Note that these
+// functions use extremely slow software floats.
+//#define ALLOW_FLOAT
+
int tolower(int chr)
{
return (chr >='A' && chr<='Z') ? (chr + 32) : (chr);
@@ -252,6 +256,8 @@ long strtol(const char *nptr, char **endptr, int base)
return (long)strtoll(nptr, endptr, base);
}
+#ifdef ALLOW_FLOAT
+
double strtod(const char *nptr, char **endptr)
{
char strbuf[64];
@@ -302,6 +308,8 @@ double strtod(const char *nptr, char **endptr)
return (i + d)*s;
}
+#endif
+
/* implementation by Lameguy64, behaves like OpenWatcom's strtok() */
/* BIOS strtok seemed either bugged, or designed for wide chars */
@@ -344,6 +352,8 @@ char *strtok( char *s1, char *s2 )
} /* strtok */
+#ifdef ALLOW_FLOAT
+
long double strtold(const char *nptr, char **endptr)
{
return (long double)strtod(nptr, endptr);
@@ -352,4 +362,6 @@ long double strtold(const char *nptr, char **endptr)
float strtof(const char *nptr, char **endptr)
{
return (float)strtod(nptr, endptr);
-} \ No newline at end of file
+}
+
+#endif
diff --git a/libpsn00b/libc/vsprintf.c b/libpsn00b/libc/vsprintf.c
index 0a99dcc..9ca4cc5 100644
--- a/libpsn00b/libc/vsprintf.c
+++ b/libpsn00b/libc/vsprintf.c
@@ -6,6 +6,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <stdarg.h>
+
+// Uncomment to enable support for %f.
+//#define ALLOW_FLOAT
#define SPRINTF_ALT_FLAG (1<<0)
#define SPRINTF_ZERO_FLAG (1<<1)
@@ -208,6 +212,8 @@ int libc_ulltoa(unsigned long i, char *dst, int n)
return n2;
}
+#ifdef ALLOW_FLOAT
+
void libc_float_to_string(float fl, char *dst, int n)
{
unsigned int *p = (unsigned int*)&fl;
@@ -365,6 +371,8 @@ void libc_double_to_string(double fl, char *dst, int n)
char libc_sprintf_floatbuf[64];
+#endif
+
int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap)
{
int string_pos,fmt_pos;
@@ -732,6 +740,7 @@ int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap)
directive_coming = 0;
break;
+#ifdef ALLOW_FLOAT
case 'f':
libc_double_to_string(va_arg(ap, double), libc_sprintf_floatbuf, 64);
@@ -740,6 +749,8 @@ int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap)
directive_coming = 0;
break;
+#endif
+
case 'n': // Number of characters written
*(va_arg(ap,unsigned int*)) = string_pos;
diff --git a/libpsn00b/psxcd/isofs.c b/libpsn00b/psxcd/isofs.c
index 40a40af..29bbb76 100644
--- a/libpsn00b/psxcd/isofs.c
+++ b/libpsn00b/psxcd/isofs.c
@@ -10,6 +10,9 @@
// Uncommend to enable debug output
//#define DEBUG
+#define DEFAULT_PATH_SEP '\\'
+#define IS_PATH_SEP(ch) (((ch) == '/') || ((ch) == '\\'))
+
typedef struct _CdlDIR_INT
{
u_long _pos;
@@ -374,7 +377,7 @@ static char* resolve_pathtable_path(int entry, char *rbuff)
rbuff -= tbl_entry.nameLength;
memcpy(rbuff, namebuff, tbl_entry.nameLength);
rbuff--;
- *rbuff = '\\';
+ *rbuff = DEFAULT_PATH_SEP;
// Parse to the parent
entry = tbl_entry.dirLevel;
@@ -431,12 +434,15 @@ static int find_dir_entry(const char *name, ISO_DIR_ENTRY *dirent)
static char* get_pathname(char *path, const char *filename)
{
- char *c;
- c = strrchr(filename, '\\');
+ char *c = 0;
+ for (char *i = filename; *i; i++) {
+ if (IS_PATH_SEP(*i))
+ c = i;
+ }
if(( c == filename ) || ( !c ))
{
- path[0] = '\\';
+ path[0] = DEFAULT_PATH_SEP;
path[1] = 0;
return NULL;
}
@@ -447,11 +453,17 @@ static char* get_pathname(char *path, const char *filename)
static char* get_filename(char *name, const char *filename)
{
- char *c;
- c = strrchr(filename, '\\');
+ char *c = 0;
+ for (char *i = filename; *i; i++) {
+ if (IS_PATH_SEP(*i))
+ c = i;
+ }
- if(( c == filename ) || ( !c ))
- {
+ if (!c) {
+ strcpy(name, filename);
+ return name;
+ }
+ if (c == filename) {
strcpy(name, filename+1);
return name;
}