From 1ee7c82d8b305dd373e490946ff82017edea982a Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Fri, 16 Oct 2015 02:46:18 -0700 Subject: [PATCH] Fix GC/Wii linker error Add example program (Currently only targets wii) --- CMakeLists.txt | 5 + Example/CMakeLists.txt | 13 +++ Example/main.cpp | 58 +++++++++++ include/Athena/DNAYaml.hpp | 4 - include/gekko_support.h | 1 + src/gekko_support.c | 202 ------------------------------------- toolchain-powerpc.cmake | 9 +- 7 files changed, 84 insertions(+), 208 deletions(-) create mode 100644 Example/CMakeLists.txt create mode 100644 Example/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a927f28..dafd6cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -231,6 +231,11 @@ if(NOT GEKKO) add_subdirectory(atdna) endif() +################## +# Example import # +################## +add_subdirectory(Example) + ######### # CPack # ######### diff --git a/Example/CMakeLists.txt b/Example/CMakeLists.txt new file mode 100644 index 0000000..2d9574f --- /dev/null +++ b/Example/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.0) +project(Example) + +include_directories(${ATHENA_INCLUDE_DIR}) +add_executable(Example + main.cpp) + +if(GEKKO) +target_link_libraries(Example AthenaCore z wiiuse bte ogc m) +else() +#TODO: add normal link libraries +endif() + diff --git a/Example/main.cpp b/Example/main.cpp new file mode 100644 index 0000000..7101442 --- /dev/null +++ b/Example/main.cpp @@ -0,0 +1,58 @@ +#include +#if GEKKO +#include +#if HW_RVL +#include +#endif + +static void *xfb = nullptr; +static GXRModeObj* rmode = nullptr; + +#endif + +#include + +int main() +{ +#if GEKKO + VIDEO_Init(); +#if HW_RVL + WPAD_Init(); +#endif + PAD_Init(); + + rmode = VIDEO_GetPreferredMode(nullptr); + xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); + + CON_Init(xfb, 20, 20, rmode->fbWidth, rmode->xfbHeight, rmode->fbWidth * VI_DISPLAY_PIX_SZ); + CON_EnableGecko(CARD_SLOTB, true); + + VIDEO_Configure(rmode); + VIDEO_SetBlack(false); + + VIDEO_Flush(); + + VIDEO_WaitVSync(); + if (rmode->viTVMode & VI_NON_INTERLACE) + VIDEO_WaitVSync(); + + Athena::io::MemoryCopyReader test("sd:/test.dat"); + while(true) + { +#if HW_RVL + WPAD_ScanPads(); +#endif + PAD_ScanPads(); + if (PAD_ButtonsDown(0) & PAD_BUTTON_START) + break; + +#if HW_RVL + if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) + break; +#endif + VIDEO_WaitVSync(); + } +#endif + return 0; +} + diff --git a/include/Athena/DNAYaml.hpp b/include/Athena/DNAYaml.hpp index 8cf37bf..6294ae3 100644 --- a/include/Athena/DNAYaml.hpp +++ b/include/Athena/DNAYaml.hpp @@ -7,10 +7,6 @@ * Any changes to the types or namespacing must be reflected in 'atdna/main.cpp' */ -#ifdef GEKKO -#include -#include -#endif #include #include #include diff --git a/include/gekko_support.h b/include/gekko_support.h index 0650ae7..05082e2 100644 --- a/include/gekko_support.h +++ b/include/gekko_support.h @@ -21,6 +21,7 @@ long long strtoq(const char *nptr, char **endptr, int base); unsigned long long strtouq(const char *nptr, char **endptr, int base); +/* devkitppc doesn't properly declare strtof for some reason */ float strtof(const char *string, char **endPtr ); #ifdef __cplusplus diff --git a/src/gekko_support.c b/src/gekko_support.c index d8d2b5b..aaf20e6 100644 --- a/src/gekko_support.c +++ b/src/gekko_support.c @@ -288,15 +288,8 @@ int vsnprintf(char *s, size_t n, const char *format, va_list ap) { #endif #include - #include - -#ifdef __STDC__ #include -#else -#include -#endif - /* * PUBLIC: #ifndef HAVE_SNPRINTF * PUBLIC: int snprintf __P((char *, size_t, const char *, ...)); @@ -326,198 +319,3 @@ long long strtoq(const char *nptr, char **endptr, int base) { unsigned long long strtouq(const char *nptr, char **endptr, int base) { return strtoull(nptr, endptr, base); } - -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 -#endif -#ifndef NULL -#define NULL 0 -#endif - -const float _strtof_powersOf10_[] = -{ // Table giving binary powers of 10. Entry - 10.0f, // is 10^2^i. Used to convert decimal - 100.0f, // exponents into floating-point numbers. - 1.0e4f, 1.0e8f, 1.0e16f, 1.0e32f}; - -/* - *---------------------------------------------------------------------- - * - * strtof -- - * - * This procedure converts a floating-point number from an ASCII - * decimal representation to internal double-precision format. - * - * Results: - * The return value is the double-precision floating-point - * representation of the characters in string. If endPtr isn't - * NULL, then *endPtr is filled in with the address of the - * next character after the last one that was part of the - * floating-point number. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -float strtof(const char *string, char **endPtr) { - int sign, expSign = FALSE; - float fraction, dblExp; - const float *d; - const char *p; - int c; - int exp = 0; - int fracExp = 0; - int mantSize; - int decPt; - const char *pExp; - p = string; - while (isspace(*p)) { - p += 1; - } - if (*p == '-') { - sign = TRUE; - p += 1; - } else { - if (*p == '+') { - p += 1; - } - sign = FALSE; - } - - decPt = -1; - for (mantSize = 0;; mantSize += 1) { - c = *p; - if (!isdigit(c)) { - if ((c != '.') || (decPt >= 0)) { - break; - } - decPt = mantSize; - } - p += 1; - } - - /* - * Now suck up the digits in the mantissa. Use two integers to - * collect 9 digits each (this is faster than using floating-point). - * If the mantissa has more than 18 digits, ignore the extras, since - * they can't affect tahe value anyway. - */ - - pExp = p; - p -= mantSize; - if (decPt < 0) { - decPt = mantSize; - } else { - mantSize -= 1; /* One of the digits was the point. */ - } - if (mantSize > 18) { - fracExp = decPt - 18; - mantSize = 18; - } else { - fracExp = decPt - mantSize; - } - if (mantSize == 0) { - fraction = 0.0; - p = string; - goto done; - } else { - int frac1, frac2; - frac1 = 0; - for (; mantSize > 9; mantSize -= 1) { - c = *p; - p += 1; - if (c == '.') { - c = *p; - p += 1; - } - frac1 = 10 * frac1 + (c - '0'); - } - frac2 = 0; - for (; mantSize > 0; mantSize -= 1) { - c = *p; - p += 1; - if (c == '.') { - c = *p; - p += 1; - } - frac2 = 10 * frac2 + (c - '0'); - } - fraction = (1.0e9f * frac1) + frac2; - } - - /* - * Skim off the exponent. - */ - - p = pExp; - if ((*p == 'E') || (*p == 'e')) { - p += 1; - if (*p == '-') { - expSign = TRUE; - p += 1; - } else { - if (*p == '+') { - p += 1; - } - expSign = FALSE; - } - while (isdigit(*p)) { - exp = exp * 10 + (*p - '0'); - p += 1; - } - } - if (expSign) { - exp = fracExp - exp; - } else { - exp = fracExp + exp; - } - - /* - * Generate a floating-point number that represents the exponent. - * Do this by processing the exponent one bit at a time to combine - * many powers of 2 of 10. Then combine the exponent with the - * fraction. - */ - - if (exp < 0) { - expSign = TRUE; - exp = -exp; - } else { - expSign = FALSE; - } - const int maxExponent = 38; /* Largest possible base 10 exponent. Any - * exponent larger than this will already - * produce underflow or overflow, so there's - * no need to worry about additional digits. - */ - - if (exp > maxExponent) { - exp = maxExponent; - } - dblExp = 1.0f; - - for (d = _strtof_powersOf10_; exp != 0; exp >>= 1, d += 1) { - if (exp & 01) { - dblExp *= *d; - } - } - - if (expSign) { - fraction /= dblExp; - } else { - fraction *= dblExp; - } - -done: - if (endPtr != NULL) { - *endPtr = (char *)p; - } - - if (sign) { - return -fraction; - } - return fraction; -} diff --git a/toolchain-powerpc.cmake b/toolchain-powerpc.cmake index bdb9c90..25468c7 100644 --- a/toolchain-powerpc.cmake +++ b/toolchain-powerpc.cmake @@ -4,7 +4,10 @@ set(CMAKE_SYSTEM_PROCESSOR powerpc-eabi) set(DEVKITPRO $ENV{DEVKITPRO}) set(DEVKITPPC $ENV{DEVKITPPC}) -set(GEKKO true) +add_definitions(-DGEKKO=1 -DHW_RVL=1) + +# Let the project know we're targetting GEKKO +set(GEKKO TRUE) if(NOT DEVKITPPC) message(FATAL_ERROR "Please set DEVKITPPC in your environment") @@ -19,6 +22,8 @@ if(NOT LIBOGCDIR) set(LIBOGCDIR ${DEVKITPRO}/libogc) endif() +include_directories(${LIBOGCDIR}/include) +link_directories(${LIBOGCDIR}/lib/wii) if(WIN32) set(CMAKE_C_COMPILER ${DEVKITPPC}/bin/powerpc-eabi-gcc.exe) set(CMAKE_CXX_COMPILER ${DEVKITPPC}/bin/powerpc-eabi-g++.exe) @@ -27,7 +32,7 @@ else() set(CMAKE_CXX_COMPILER ${DEVKITPPC}/bin/powerpc-eabi-g++) endif() -set(MACHDEP "-DGEKKO -mrvl -mcpu=750 -meabi -mhard-float") +set(MACHDEP "-mrvl -mcpu=750 -meabi -mhard-float") set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} ${MACHDEP}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MACHDEP}")