From 3ae5eeb1e8032c1c0ad8f4fd1b83e0404b92d0f1 Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Thu, 15 Apr 2021 21:30:00 -0400 Subject: [PATCH] Fixed usb library --- Makefile | 3 --- sm64.ld | 8 ++++---- src/game/memory.c | 4 ++++ src/usb/debug.h | 4 +++- src/usb/usb.c | 52 ++++++++++++++++------------------------------- 5 files changed, 29 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 7395e5c8..ca6af533 100644 --- a/Makefile +++ b/Makefile @@ -170,9 +170,6 @@ $(eval $(call validate-option,UNF,0 1)) ifeq ($(UNF),1) DEFINES += UNF=1 SRC_DIRS += src/usb - ULTRALIB := ultra_d -else - ULTRALIB := ultra_rom endif diff --git a/sm64.ld b/sm64.ld index f2aaeabb..5e86b935 100755 --- a/sm64.ld +++ b/sm64.ld @@ -132,7 +132,7 @@ SECTIONS BUILD_DIR/src/usb*.o(.text); #endif BUILD_DIR/src/audio*.o(.text); -#if defined(ISVPRINT) || defined(UNF) +#if defined(ISVPRINT) */libultra_d.a:*.o(.text); #else */libultra_rom.a:*.o(.text); @@ -158,7 +158,7 @@ SECTIONS #ifdef GZIP */libz.a:*.o(.*data*); #endif -#if defined(ISVPRINT) || defined(UNF) +#if defined(ISVPRINT) */libultra_d.a:*.o(.*data*); #else */libultra_rom.a:*.o(.*data*); @@ -178,7 +178,7 @@ SECTIONS BUILD_DIR/src/usb*.o(.rodata*); #endif BUILD_DIR/src/audio*.o(.rodata*); -#if defined(ISVPRINT) || defined(UNF) +#if defined(ISVPRINT) */libultra_d.a:*.o(.*rodata*); #else */libultra_rom.a:*.o(.*rodata*); @@ -208,7 +208,7 @@ SECTIONS BUILD_DIR/src/gzip*.o(.bss*); #endif BUILD_DIR/src/audio*.o(.*bss*); -#if defined(ISVPRINT) || defined(UNF) +#if defined(ISVPRINT) */libultra_d.a:*.o(COMMON); */libultra_d.a:*.o(.scommon); */libultra_d.a:*.o(.*bss*); diff --git a/src/game/memory.c b/src/game/memory.c index 687c99a8..2dd33eb6 100644 --- a/src/game/memory.c +++ b/src/game/memory.c @@ -17,6 +17,10 @@ #if defined(RNC1) || defined(RNC2) #include #endif +#ifdef UNF +#include "usb/usb.h" +#include "usb/debug.h" +#endif // round up to the next multiple diff --git a/src/usb/debug.h b/src/usb/debug.h index ebe7ea69..e77a76ea 100644 --- a/src/usb/debug.h +++ b/src/usb/debug.h @@ -9,8 +9,10 @@ #define DEBUG_MODE 1 // Enable/Disable debug mode #define DEBUG_INIT_MSG 1 // Print a message when debug mode has initialized #define USE_FAULTTHREAD 1 // Create a fault detection thread (libultra only) - #define OVERWRITE_OSPRINT 1 // Replaces osSyncPrintf calls with debug_printf (libultra only) + #define OVERWRITE_OSPRINT 0 // Replaces osSyncPrintf calls with debug_printf (libultra only) #define MAX_COMMANDS 25 // The max amount of user defined commands possible + + #define osSyncPrintf debug_printf // Temporary until libultra_d is linked instead // Fault thread definitions (libultra only) #define FAULT_THREAD_ID 13 diff --git a/src/usb/usb.c b/src/usb/usb.c index c8922883..43bfdb00 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -973,6 +973,15 @@ static void usb_everdrive_readdata(void* buff, u32 pi_address, u32 len) #ifdef LIBDRAGON data_cache_hit_writeback_invalidate(buff, len); disable_interrupts(); + // Write the data to the PI + usb_everdrive_wait_pidma(); + IO_WRITE(PI_STATUS_REG, 3); + *(volatile unsigned long *)(N64_PI_ADDRESS + N64_PI_RAMADDRESS) = (u32)buff; + *(volatile unsigned long *)(N64_PI_ADDRESS + N64_PI_PIADDRESS) = pi_address; + *(volatile unsigned long *)(N64_PI_ADDRESS + N64_PI_WRITELENGTH) = len-1; + usb_everdrive_wait_pidma(); + // Enable system interrupts + enable_interrupts(); #else osInvalDCache(buff, len); #if USE_OSRAW @@ -986,23 +995,6 @@ static void usb_everdrive_readdata(void* buff, u32 pi_address, u32 len) (void)osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK); #endif #endif - - // Write the data to the PI - usb_everdrive_wait_pidma(); - IO_WRITE(PI_STATUS_REG, 3); - *(volatile unsigned long *)(N64_PI_ADDRESS + N64_PI_RAMADDRESS) = (u32)buff; - *(volatile unsigned long *)(N64_PI_ADDRESS + N64_PI_PIADDRESS) = pi_address; - #ifdef LIBDRAGON - *(volatile unsigned long *)(N64_PI_ADDRESS + N64_PI_WRITELENGTH) = len-1; - #else - *(volatile unsigned long *)(N64_PI_ADDRESS + N64_PI_READLENGTH) = len-1; - #endif - usb_everdrive_wait_pidma(); - - // Enable system interrupts - #ifdef LIBDRAGON - enable_interrupts(); - #endif } @@ -1036,6 +1028,15 @@ static void usb_everdrive_writedata(void* buff, u32 pi_address, u32 len) #ifdef LIBDRAGON data_cache_hit_writeback(buff, len); disable_interrupts(); + // Write the data to the PI + usb_everdrive_wait_pidma(); + IO_WRITE(PI_STATUS_REG, 3); + *(volatile unsigned long *)(N64_PI_ADDRESS + N64_PI_RAMADDRESS) = (u32)buff; + *(volatile unsigned long *)(N64_PI_ADDRESS + N64_PI_PIADDRESS) = pi_address; + *(volatile unsigned long *)(N64_PI_ADDRESS + N64_PI_READLENGTH) = len-1; + usb_everdrive_wait_pidma(); + // Enable system interrupts + enable_interrupts(); #else osWritebackDCache(buff, len); #if USE_OSRAW @@ -1049,23 +1050,6 @@ static void usb_everdrive_writedata(void* buff, u32 pi_address, u32 len) (void)osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK); #endif #endif - - // Write the data to the PI - usb_everdrive_wait_pidma(); - IO_WRITE(PI_STATUS_REG, 3); - *(volatile unsigned long *)(N64_PI_ADDRESS + N64_PI_RAMADDRESS) = (u32)buff; - *(volatile unsigned long *)(N64_PI_ADDRESS + N64_PI_PIADDRESS) = pi_address; - #ifdef LIBDRAGON - *(volatile unsigned long *)(N64_PI_ADDRESS + N64_PI_READLENGTH) = len-1; - #else - *(volatile unsigned long *)(N64_PI_ADDRESS + N64_PI_WRITELENGTH) = len-1; - #endif - usb_everdrive_wait_pidma(); - - // Enable system interrupts - #ifdef LIBDRAGON - enable_interrupts(); - #endif }