diff --git a/misc/gba/Makefile b/misc/gba/Makefile index f7a53a418..408c742ba 100644 --- a/misc/gba/Makefile +++ b/misc/gba/Makefile @@ -40,16 +40,11 @@ CFLAGS = -g -Wall -O2 -DPLAT_GBA -ffunction-sections -fdata-sections -mcpu=arm7t ASFLAGS = -g $(ARCH) LDFLAGS = -specs=gba.specs -g $(ARCH) -LIBS = -ltonc LIBGBA := $(DEVKITPRO)/libgba INCLUDES += $(foreach dir, $(LIBGBA), -I$(dir)/include) LDFLAGS += $(foreach dir, $(LIBGBA), -L$(dir)/lib) -LIBTONC = $(DEVKITPRO)/libtonc -INCLUDES += $(foreach dir, $(LIBTONC), -I$(dir)/include) -LDFLAGS += $(foreach dir, $(LIBTONC), -L$(dir)/lib) - #--------------------------------------------------------------------------------- # Compiler tools @@ -94,6 +89,9 @@ $(BUILD_DIR)/%.o: src/%.c $(BUILD_DIR)/%.o: src/gba/%.c $(ARM_CC) $(CFLAGS) $(INCLUDES) $(DEPFLAGS) -c $< -o $@ +$(BUILD_DIR)/%.o: src/gba/%.S + $(ARM_CC) $(CFLAGS) $(INCLUDES) $(DEPFLAGS) -c $< -o $@ + #--------------------------------------------------------------------------------- # Dependency tracking diff --git a/readme.md b/readme.md index 231464b35..1f6d9f7ca 100644 --- a/readme.md +++ b/readme.md @@ -259,6 +259,14 @@ Run `make ds`. You'll need [BlocksDS](https://github.com/blocksds/sdk) Run `make n64`. You'll need the opengl branch of [libdragon](https://github.com/DragonMinded/libdragon/tree/opengl) +#### GBA + +Run `make gba`. You'll need [libgba](https://github.com/devkitPro/libgba) + +**NOTE: It is highly recommended that you install the precompiled devkitpro packages from [here](https://devkitpro.org/wiki/Getting_Started) - you need the `gba-dev` group)** + +**NOTE: The GBA port has terrible performance and is unusable in practice.** + @@ -462,6 +470,8 @@ Further information (e.g. style) for ClassiCube's source code can be found in th * [ares](https://github.com/ares-emulator/ares) - Emulator used to test Nintendo 64 port * [BlocksDS](https://github.com/blocksds/sdk) - Backend for Nintendo DS * [melonDS](https://github.com/melonDS-emu/melonDS) - Emulator used to test Nintendo DS port +* [libgba](https://github.com/devkitPro/libgba) - Backend for GBA +* [mGBA](https://github.com/mgba-emu/mgba) - Emulator used to test GBA port * [vitasdk](https://github.com/vitasdk) - Backend for PS Vita * [Vita3K](https://github.com/Vita3K/Vita3K) - Emulator used to test Vita port * [pspsdk](https://github.com/pspdev/pspsdk) - Backend for PSP diff --git a/src/gba/NocashLog.S b/src/gba/NocashLog.S new file mode 100644 index 000000000..b3a2724b6 --- /dev/null +++ b/src/gba/NocashLog.S @@ -0,0 +1,22 @@ +.global nocash_log +.global nocash_msg + +// BEG nocash_log +.section .ewram,"ax",%progbits +.thumb_func +.align 2 + +// nocash looks for this specific pattern +nocash_log: + mov r12, r12 + b nocash_log_return + .short 0x6464, 0x0000 +nocash_msg: + .space 82 + +nocash_log_return: + bx lr + +.size nocash_log, .-nocash_log +.type nocash_log, %function +// END nocash_log diff --git a/src/gba/Platform_GBA.c b/src/gba/Platform_GBA.c index 3e21b58b7..7aaa66311 100644 --- a/src/gba/Platform_GBA.c +++ b/src/gba/Platform_GBA.c @@ -139,35 +139,53 @@ cc_uint64 Stopwatch_Measure(void) { return base_time + raw; } -extern int nocash_puts(const char *str); -static void Log_Nocash(char* buffer) { - nocash_puts(buffer); -} - #define MGBA_LOG_DEBUG 4 #define REG_DEBUG_ENABLE (vu16*)0x4FFF780 #define REG_DEBUG_FLAGS (vu16*)0x4FFF700 #define REG_DEBUG_STRING (char*)0x4FFF600 -static void Log_mgba(char* buffer, int len) { +static void Log_mgba(const char* msg, int len) { *REG_DEBUG_ENABLE = 0xC0DE; // Check if actually emulated or not if (*REG_DEBUG_ENABLE != 0x1DEA) return; - Mem_Copy(REG_DEBUG_STRING, buffer, len); - *REG_DEBUG_FLAGS = MGBA_LOG_DEBUG | 0x100; + while (len) + { + // Can only be up to 120 bytes total + int bit = min(len, 119); + char* dst = REG_DEBUG_STRING; + + Mem_Copy(dst, msg, bit); + dst[bit] = '\0'; + + *REG_DEBUG_FLAGS = MGBA_LOG_DEBUG | 0x100; + msg += bit; len -= bit; + } } +// Log to nocash debugger +extern char nocash_msg[82]; +extern void nocash_log(void); + +static void Log_Nocash(const char* msg, int len) { + while (len) + { + // Can only be up to 80 bytes total + int bit = min(len, 80); + char* dst = nocash_msg; + + Mem_Copy(dst, msg, bit); + dst[bit + 0] = '\0'; + + nocash_log(); + msg += bit; len -= bit; + } +} + + void Platform_Log(const char* msg, int len) { - // Can only be up to 120 bytes total - char buffer[120]; - len = min(len, 118); - - Mem_Copy(buffer, msg, len); - buffer[len + 0] = '\n'; - buffer[len + 1] = '\0'; - Log_Nocash(buffer); - Log_mgba(buffer, len); + Log_mgba(msg, len); + Log_Nocash(msg, len); } TimeMS DateTime_CurrentUTC(void) {