summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Schleifer <js@webkeks.org>2013-04-27 04:22:43 +0200
committerJonathan Schleifer <js@webkeks.org>2013-04-27 04:22:43 +0200
commit9a32a0b952425d06149443bcf94cc2fb9478e2dd (patch)
tree50d60a344d3b728032cdee1fc5cf22efc764623c
parent5b51e3d5f392211bd95ca063f68940d1dd41b4af (diff)
Initial Wii port.
Threads and sockets still missing.
-rw-r--r--.gitignore1
-rw-r--r--configure.ac24
-rw-r--r--extra.mk.in1
-rw-r--r--src/OFFile.m18
-rw-r--r--src/of_asprintf.m27
-rw-r--r--tests/Makefile1
-rw-r--r--tests/TestsAppDelegate.m113
7 files changed, 164 insertions, 21 deletions
diff --git a/.gitignore b/.gitignore
index 9cd95338..06b3c19b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
*.bundle
*.dll
*.dylib
+*.map
*.o
*.orig
*.so
diff --git a/configure.ac b/configure.ac
index d4bea378..190d8173 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,6 +22,14 @@ CPPFLAGS="$CPPFLAGS $OBJCPPFLAGS"
OBJCFLAGS="$OBJCFLAGS -Wall -fexceptions -fobjc-exceptions -funwind-tables"
OBJCFLAGS="$OBJCFLAGS -fconstant-string-class=OFConstantString"
+AC_ARG_WITH(wii,
+ AS_HELP_STRING([--with-wii], [build for Wii]))
+AS_IF([test x"$with_wii" = x"yes"], [
+ OBJCFLAGS="$OBJCFLAGS -DGEKKO -mrvl -mcpu=750 -meabi -mhard-float"
+ LDFLAGS="$LDFLAGS -mrvl -mcpu=750 -meabi -mhard-float"
+ LIBS="-lfat -lwiiuse -lbte -logc"
+])
+
AX_CHECK_COMPILER_FLAGS(-std=gnu99, [OBJCFLAGS="$OBJCFLAGS -std=gnu99"])
case $OBJC in
*clang*)
@@ -816,6 +824,10 @@ AS_IF([test x"$GOBJC" = x"yes"], [
])
])
+AS_IF([test x"$with_wii" = x"yes"], [
+ AC_SUBST(MAP_LDFLAGS, ['-Wl,-Map,$$(basename $@).map'])
+])
+
AS_IF([test x"$cross_compiling" = x"yes"], [
AC_SUBST(BIN_PREFIX, "$host-")
@@ -829,6 +841,18 @@ AS_IF([test x"$cross_compiling" = x"yes"], [
])
;;
esac
+
+ AS_IF([test x"$with_wii" = x"yes"], [
+ dnl Keep this lowercase, as WIILOAD is a variable used by
+ dnl wiiload and thus likely already set by the user to something
+ dnl that is not the path to the binary.
+ AC_CHECK_PROG(wiiload, wiiload, wiiload)
+
+ AS_IF([test x"$wiiload" != x""], [
+ AC_SUBST(TESTS, "tests")
+ AC_SUBST(TEST_LAUNCHER, "$wiiload")
+ ])
+ ])
], [
AC_SUBST(TESTS, "tests")
])
diff --git a/extra.mk.in b/extra.mk.in
index fe843ba6..3c04dece 100644
--- a/extra.mk.in
+++ b/extra.mk.in
@@ -22,6 +22,7 @@ FORWARDING_S = @FORWARDING_S@
FOUNDATION_COMPAT_M = @FOUNDATION_COMPAT_M@
INSTANCE_M = @INSTANCE_M@
LOOKUP_S = @LOOKUP_S@
+MAP_LDFLAGS = @MAP_LDFLAGS@
OFBLOCKTESTS_M = @OFBLOCKTESTS_M@
OFHTTPCLIENTTESTS_M = @OFHTTPCLIENTTESTS_M@
OFPROCESS_M = @OFPROCESS_M@
diff --git a/src/OFFile.m b/src/OFFile.m
index 4a5a5028..b4331524 100644
--- a/src/OFFile.m
+++ b/src/OFFile.m
@@ -42,6 +42,12 @@
# include <grp.h>
#endif
+#ifdef __wii__
+# define BOOL OGC_BOOL
+# include <fat.h>
+# undef BOOL
+#endif
+
#import "OFFile.h"
#import "OFString.h"
#import "OFArray.h"
@@ -133,18 +139,24 @@ static int parse_mode(const char *mode)
}
@implementation OFFile
-#if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS)
+ (void)initialize
{
if (self != [OFFile class])
return;
+#if defined(OF_HAVE_CHOWN) && defined(OF_HAVE_THREADS)
if (!of_mutex_new(&mutex))
@throw [OFInitializationFailedException
exceptionWithClass: self];
-}
#endif
+#ifdef __wii__
+ if (!fatInitDefault())
+ @throw [OFInitializationFailedException
+ exceptionWithClass: self];
+#endif
+}
+
+ (instancetype)fileWithPath: (OFString*)path
mode: (OFString*)mode
{
@@ -288,7 +300,7 @@ static int parse_mode(const char *mode)
OF_STRING_ENCODING_NATIVE])) == NULL)
@throw [OFOpenFileFailedException exceptionWithClass: self
path: path
- mode: @"r"];
+ mode: @"r"];
@try {
while ((dirent = readdir(dir)) != NULL) {
diff --git a/src/of_asprintf.m b/src/of_asprintf.m
index 6bf2ca8a..aafd6037 100644
--- a/src/of_asprintf.m
+++ b/src/of_asprintf.m
@@ -197,11 +197,14 @@ state_format_length_modifier(struct context *ctx)
break;
case 'j':
-#ifndef _WIN32
- if (!append_subformat(ctx, ctx->format + ctx->i, 1))
+#if defined(_WIN32)
+ if (!append_subformat(ctx, "I64", 3))
+ return false;
+#elif defined(__wii__)
+ if (!append_subformat(ctx, "ll", 2))
return false;
#else
- if (!append_subformat(ctx, "I64", 3))
+ if (!append_subformat(ctx, ctx->format + ctx->i, 1))
return false;
#endif
@@ -209,11 +212,14 @@ state_format_length_modifier(struct context *ctx)
break;
case 'z':
-#ifndef _WIN32
- if (!append_subformat(ctx, ctx->format + ctx->i, 1))
+#if defined(_WIN32)
+ if (!append_subformat(ctx, "I", 1))
+ return false;
+#elif defined(__wii__)
+ if (!append_subformat(ctx, "l", 1))
return false;
#else
- if (!append_subformat(ctx, "I", 1))
+ if (!append_subformat(ctx, ctx->format + ctx->i, 1))
return false;
#endif
@@ -221,11 +227,14 @@ state_format_length_modifier(struct context *ctx)
break;
case 't':
-#ifndef _WIN32
- if (!append_subformat(ctx, ctx->format + ctx->i, 1))
+#if defined(_WIN32)
+ if (!append_subformat(ctx, "I", 1))
+ return false;
+#elif defined(__wii__)
+ if (!append_subformat(ctx, "l", 1))
return false;
#else
- if (!append_subformat(ctx, "I", 1))
+ if (!append_subformat(ctx, ctx->format + ctx->i, 1))
return false;
#endif
diff --git a/tests/Makefile b/tests/Makefile
index ffd5330d..2abd801f 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -97,4 +97,5 @@ include ../buildsys.mk
CPPFLAGS += -I../src -I../src/exceptions -I../src/runtime -I.. -DSTDOUT
LIBS := -L../src -lobjfw ${LIBS}
+LDFLAGS += ${MAP_LDFLAGS}
LD = ${OBJC}
diff --git a/tests/TestsAppDelegate.m b/tests/TestsAppDelegate.m
index 6fc2c69e..7be69c7d 100644
--- a/tests/TestsAppDelegate.m
+++ b/tests/TestsAppDelegate.m
@@ -20,6 +20,7 @@
#import "OFString.h"
#import "OFStdIOStream.h"
+#import "OFFile.h"
#import "OFAutoreleasePool.h"
#import "TestsAppDelegate.h"
@@ -31,6 +32,20 @@
PSP_MODULE_INFO("ObjFW Tests", 0, 0, 0);
#endif
+#ifdef __wii__
+# define BOOL OGC_BOOL
+# include <gccore.h>
+# include <wiiuse/wpad.h>
+# undef BOOL
+#endif
+
+enum {
+ NO_COLOR,
+ RED,
+ GREEN,
+ YELLOW
+};
+
int
main(int argc, char *argv[])
{
@@ -41,7 +56,52 @@ main(int argc, char *argv[])
/* We need deterministic hashes for tests */
of_hash_seed = 0;
+#ifdef __wii__
+ GXRModeObj *rmode;
+ void *xfb;
+
+ VIDEO_Init();
+ WPAD_Init();
+
+ rmode = VIDEO_GetPreferredMode(NULL);
+ xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
+ VIDEO_Configure(rmode);
+ VIDEO_SetNextFramebuffer(xfb);
+ VIDEO_SetBlack(FALSE);
+ VIDEO_Flush();
+
+ VIDEO_WaitVSync();
+ if (rmode->viTVMode & VI_NON_INTERLACE)
+ VIDEO_WaitVSync();
+
+ CON_InitEx(rmode, 10, 20, rmode->fbWidth - 10, rmode->xfbHeight - 20);
+ VIDEO_ClearFrameBuffer(rmode, xfb, COLOR_BLACK);
+
+ @try {
+ return of_application_main(&argc, &argv,
+ [TestsAppDelegate class]);
+ } @catch (id e) {
+ TestsAppDelegate *delegate =
+ [[OFApplication sharedApplication] delegate];
+ OFString *string = [OFString stringWithFormat:
+ @"\nRuntime error: Unhandled exception:\n%@\n", e];
+
+ [delegate outputString: string
+ withColor: RED];
+ [delegate outputString: @"Press home button to exit!\n"
+ withColor: NO_COLOR];
+ for (;;) {
+ WPAD_ScanPads();
+
+ if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)
+ [OFApplication terminateWithStatus: 1];
+
+ VIDEO_WaitVSync();
+ }
+ }
+#else
return of_application_main(&argc, &argv, [TestsAppDelegate class]);
+#endif
}
@implementation TestsAppDelegate
@@ -72,14 +132,20 @@ main(int argc, char *argv[])
pspDebugScreenPrintData([str UTF8String], [str UTF8StringLength]);
#elif defined(STDOUT)
switch (color) {
- case 0:
- [of_stdout writeString: @"\r\033[K\033[1;33m"];
+ case NO_COLOR:
+ [of_stdout writeString: @"\r\033[K"];
+# ifdef __wii__
+ [of_stdout writeString: @"\033[37m"];
+# endif
break;
- case 1:
- [of_stdout writeString: @"\r\033[K\033[1;32m"];
+ case RED:
+ [of_stdout writeString: @"\r\033[K\033[31;1m"];
break;
- case 2:
- [of_stdout writeString: @"\r\033[K\033[1;31m"];
+ case GREEN:
+ [of_stdout writeString: @"\r\033[K\033[32;1m"];
+ break;
+ case YELLOW:
+ [of_stdout writeString: @"\r\033[K\033[33;1m"];
break;
}
@@ -96,7 +162,7 @@ main(int argc, char *argv[])
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
[self outputString: [OFString stringWithFormat: @"[%@] %@: testing...",
module, test]
- withColor: 0];
+ withColor: YELLOW];
[pool release];
}
@@ -106,7 +172,7 @@ main(int argc, char *argv[])
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
[self outputString: [OFString stringWithFormat: @"[%@] %@: ok\n",
module, test]
- withColor: 1];
+ withColor: GREEN];
[pool release];
}
@@ -116,8 +182,21 @@ main(int argc, char *argv[])
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
[self outputString: [OFString stringWithFormat: @"[%@] %@: failed\n",
module, test]
- withColor: 2];
+ withColor: RED];
[pool release];
+
+#ifdef __wii__
+ [self outputString: @"Press A to continue!\n"
+ withColor: NO_COLOR];
+ for (;;) {
+ WPAD_ScanPads();
+
+ if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A)
+ return;
+
+ VIDEO_WaitVSync();
+ }
+#endif
}
- (void)applicationDidFinishLaunching
@@ -125,6 +204,9 @@ main(int argc, char *argv[])
#ifdef _PSP
pspDebugScreenInit();
#endif
+#ifdef __wii__
+ [OFFile changeToDirectoryAtPath: @"/objfw-tests"];
+#endif
[self objectTests];
#ifdef OF_HAVE_BLOCKS
@@ -164,6 +246,19 @@ main(int argc, char *argv[])
[self propertiesTests];
#endif
+#ifdef __wii__
+ [self outputString: @"Press home button to exit!\n"
+ withColor: NO_COLOR];
+ for (;;) {
+ WPAD_ScanPads();
+
+ if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)
+ [OFApplication terminateWithStatus: _fails];
+
+ VIDEO_WaitVSync();
+ }
+#else
[OFApplication terminateWithStatus: _fails];
+#endif
}
@end