Update UNF (still broken though ) :(

This commit is contained in:
CrashOveride95 committed 2021-04-11 18:20:32 -04:00
1 parent 623bf3bfcb
commit 5048caff1e
7 files changed
+822 -606

No files matched your search

+1 -1
View File
@@ -73,7 +73,7 @@ extern "C" {
*/
/* Perform alignment on input 's' */
//#define ALIGN(s, align) (((u32)(s) + ((align)-1)) & ~((align)-1))
#define ALIGN(s, align) (((u32)(s) + ((align)-1)) & ~((align)-1))
//commented out due to sm64 conflict
/***************************************
+1
View File
@@ -44,6 +44,7 @@ DECLARE_SEGMENT(framebuffers)
extern u8 _goddardSegmentStart[];
extern u8 _engineSegmentStart[];
extern u8 _engineSegmentBssEnd[];
extern u8 _mainSegmentEnd[];
extern u8 _engineSegmentEnd[];
extern u8 _framebuffersSegmentBssEnd[];
+9 -1
View File
@@ -315,7 +315,9 @@ void thread3_main(UNUSED void *arg) {
setup_mesg_queues();
alloc_pool();
load_engine_code_segment();
#ifndef UNF
crash_screen_init();
#endif
#ifdef UNF
debug_printf("Super Mario 64\n");
@@ -475,8 +477,14 @@ void thread1_idle(UNUSED void *arg) {
}
}
static void ClearRAM(void)
{
bzero(_mainSegmentEnd, (size_t)osMemSize - (size_t)OS_K0_TO_PHYSICAL(_mainSegmentEnd));
}
void main_func(void) {
osInitialize();
ClearRAM();
__osInitialize_common();
create_thread(&gIdleThread, 1, thread1_idle, NULL, gIdleThreadStack + 0x800, 100);
osStartThread(&gIdleThread);
+406 -370
View File
@@ -5,12 +5,18 @@ A basic debug library that makes use of the USB library for N64
flashcarts.
https://github.com/buu342/N64-UNFLoader
***************************************************************/
#include <ultra64.h>
#include <stdarg.h> // Located in ultra\GCC\MIPSE\INCLUDE
#include <PR/os_internal.h> // Needed for Crash's Linux toolchain
#include <string.h> // Needed for Crash's Linux toolchain
#include "debug.h"
#ifndef LIBDRAGON
#include <ultra64.h>
#include <PR/os_internal.h> // Needed for Crash's Linux toolchain
#else
#include <libdragon.h>
#include <stdio.h>
#include <math.h>
#endif
#include <stdarg.h>
#include <string.h>
#if DEBUG_MODE
@@ -33,6 +39,34 @@ https://github.com/buu342/N64-UNFLoader
#define COMMAND_TOKENS 10
#define BUFFER_SIZE 256
/*********************************
Libultra types (for libdragon)
*********************************/
#ifdef LIBDRAGON
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long u32;
typedef unsigned long long u64;
typedef signed char s8;
typedef short s16;
typedef long s32;
typedef long long s64;
typedef volatile unsigned char vu8;
typedef volatile unsigned short vu16;
typedef volatile unsigned long vu32;
typedef volatile unsigned long long vu64;
typedef volatile signed char vs8;
typedef volatile short vs16;
typedef volatile long vs32;
typedef volatile long long vs64;
typedef float f32;
typedef double f64;
#endif
/*********************************
Structs
@@ -69,15 +103,19 @@ https://github.com/buu342/N64-UNFLoader
Function Prototypes
*********************************/
// Threads
#if USE_FAULTTHREAD
static void debug_thread_fault(void *arg);
#endif
static void debug_thread_usb(void *arg);
#ifndef LIBDRAGON
// Threads
#if USE_FAULTTHREAD
static void debug_thread_fault(void *arg);
#endif
static void debug_thread_usb(void *arg);
// Other
#if OVERWRITE_OSPRINT
static void* debug_osSyncPrintf_implementation(void *str, const char *buf, size_t n);
// Other
#if OVERWRITE_OSPRINT
static void* debug_osSyncPrintf_implementation(void *unused, const char *str, size_t len);
#endif
#else
static void debug_thread_usb(void *arg);
#endif
@@ -86,8 +124,11 @@ https://github.com/buu342/N64-UNFLoader
*********************************/
// Function pointers
#if OVERWRITE_OSPRINT
extern void* __printfunc;
#ifndef LIBDRAGON
extern int _Printf(void *(*copyfunc)(void *, const char *, size_t), void*, const char*, va_list);
#if OVERWRITE_OSPRINT
extern void* __printfunc;
#endif
#endif
// Debug globals
@@ -111,114 +152,115 @@ https://github.com/buu342/N64-UNFLoader
static const char* assert_file = NULL;
static const char* assert_expr = NULL;
// Fault thread globals
#if USE_FAULTTHREAD
static OSMesgQueue faultMessageQ;
static OSMesg faultMessageBuf;
static OSThread faultThread;
static u64 faultThreadStack[FAULT_THREAD_STACK/sizeof(u64)];
#ifndef LIBDRAGON
// Fault thread globals
#if USE_FAULTTHREAD
static OSMesgQueue faultMessageQ;
static OSMesg faultMessageBuf;
static OSThread faultThread;
static u64 faultThreadStack[FAULT_THREAD_STACK/sizeof(u64)];
#endif
// USB thread globals
static OSMesgQueue usbMessageQ;
static OSMesg usbMessageBuf;
static OSThread usbThread;
static u64 usbThreadStack[USB_THREAD_STACK/sizeof(u64)];
// List of error causes
static regDesc causeDesc[] = {
{CAUSE_BD, CAUSE_BD, "BD"},
{CAUSE_IP8, CAUSE_IP8, "IP8"},
{CAUSE_IP7, CAUSE_IP7, "IP7"},
{CAUSE_IP6, CAUSE_IP6, "IP6"},
{CAUSE_IP5, CAUSE_IP5, "IP5"},
{CAUSE_IP4, CAUSE_IP4, "IP4"},
{CAUSE_IP3, CAUSE_IP3, "IP3"},
{CAUSE_SW2, CAUSE_SW2, "IP2"},
{CAUSE_SW1, CAUSE_SW1, "IP1"},
{CAUSE_EXCMASK, EXC_INT, "Interrupt"},
{CAUSE_EXCMASK, EXC_MOD, "TLB modification exception"},
{CAUSE_EXCMASK, EXC_RMISS, "TLB exception on load or instruction fetch"},
{CAUSE_EXCMASK, EXC_WMISS, "TLB exception on store"},
{CAUSE_EXCMASK, EXC_RADE, "Address error on load or instruction fetch"},
{CAUSE_EXCMASK, EXC_WADE, "Address error on store"},
{CAUSE_EXCMASK, EXC_IBE, "Bus error exception on instruction fetch"},
{CAUSE_EXCMASK, EXC_DBE, "Bus error exception on data reference"},
{CAUSE_EXCMASK, EXC_SYSCALL, "System call exception"},
{CAUSE_EXCMASK, EXC_BREAK, "Breakpoint exception"},
{CAUSE_EXCMASK, EXC_II, "Reserved instruction exception"},
{CAUSE_EXCMASK, EXC_CPU, "Coprocessor unusable exception"},
{CAUSE_EXCMASK, EXC_OV, "Arithmetic overflow exception"},
{CAUSE_EXCMASK, EXC_TRAP, "Trap exception"},
{CAUSE_EXCMASK, EXC_VCEI, "Virtual coherency exception on intruction fetch"},
{CAUSE_EXCMASK, EXC_FPE, "Floating point exception (see fpcsr)"},
{CAUSE_EXCMASK, EXC_WATCH, "Watchpoint exception"},
{CAUSE_EXCMASK, EXC_VCED, "Virtual coherency exception on data reference"},
{0, 0, ""}
};
// List of register descriptions
static regDesc srDesc[] = {
{SR_CU3, SR_CU3, "CU3"},
{SR_CU2, SR_CU2, "CU2"},
{SR_CU1, SR_CU1, "CU1"},
{SR_CU0, SR_CU0, "CU0"},
{SR_RP, SR_RP, "RP"},
{SR_FR, SR_FR, "FR"},
{SR_RE, SR_RE, "RE"},
{SR_BEV, SR_BEV, "BEV"},
{SR_TS, SR_TS, "TS"},
{SR_SR, SR_SR, "SR"},
{SR_CH, SR_CH, "CH"},
{SR_CE, SR_CE, "CE"},
{SR_DE, SR_DE, "DE"},
{SR_IBIT8, SR_IBIT8, "IM8"},
{SR_IBIT7, SR_IBIT7, "IM7"},
{SR_IBIT6, SR_IBIT6, "IM6"},
{SR_IBIT5, SR_IBIT5, "IM5"},
{SR_IBIT4, SR_IBIT4, "IM4"},
{SR_IBIT3, SR_IBIT3, "IM3"},
{SR_IBIT2, SR_IBIT2, "IM2"},
{SR_IBIT1, SR_IBIT1, "IM1"},
{SR_KX, SR_KX, "KX"},
{SR_SX, SR_SX, "SX"},
{SR_UX, SR_UX, "UX"},
{SR_KSU_MASK, SR_KSU_USR, "USR"},
{SR_KSU_MASK, SR_KSU_SUP, "SUP"},
{SR_KSU_MASK, SR_KSU_KER, "KER"},
{SR_ERL, SR_ERL, "ERL"},
{SR_EXL, SR_EXL, "EXL"},
{SR_IE, SR_IE, "IE"},
{0, 0, ""}
};
// List of floating point registers descriptions
static regDesc fpcsrDesc[] = {
{FPCSR_FS, FPCSR_FS, "FS"},
{FPCSR_C, FPCSR_C, "C"},
{FPCSR_CE, FPCSR_CE, "Unimplemented operation"},
{FPCSR_CV, FPCSR_CV, "Invalid operation"},
{FPCSR_CZ, FPCSR_CZ, "Division by zero"},
{FPCSR_CO, FPCSR_CO, "Overflow"},
{FPCSR_CU, FPCSR_CU, "Underflow"},
{FPCSR_CI, FPCSR_CI, "Inexact operation"},
{FPCSR_EV, FPCSR_EV, "EV"},
{FPCSR_EZ, FPCSR_EZ, "EZ"},
{FPCSR_EO, FPCSR_EO, "EO"},
{FPCSR_EU, FPCSR_EU, "EU"},
{FPCSR_EI, FPCSR_EI, "EI"},
{FPCSR_FV, FPCSR_FV, "FV"},
{FPCSR_FZ, FPCSR_FZ, "FZ"},
{FPCSR_FO, FPCSR_FO, "FO"},
{FPCSR_FU, FPCSR_FU, "FU"},
{FPCSR_FI, FPCSR_FI, "FI"},
{FPCSR_RM_MASK, FPCSR_RM_RN, "RN"},
{FPCSR_RM_MASK, FPCSR_RM_RZ, "RZ"},
{FPCSR_RM_MASK, FPCSR_RM_RP, "RP"},
{FPCSR_RM_MASK, FPCSR_RM_RM, "RM"},
{0, 0, ""}
};
#endif
// USB thread globals
static OSMesgQueue usbMessageQ;
static OSMesg usbMessageBuf;
static OSThread usbThread;
static u64 usbThreadStack[USB_THREAD_STACK/sizeof(u64)];
// List of error causes
static regDesc causeDesc[] = {
{CAUSE_BD, CAUSE_BD, "BD"},
{CAUSE_IP8, CAUSE_IP8, "IP8"},
{CAUSE_IP7, CAUSE_IP7, "IP7"},
{CAUSE_IP6, CAUSE_IP6, "IP6"},
{CAUSE_IP5, CAUSE_IP5, "IP5"},
{CAUSE_IP4, CAUSE_IP4, "IP4"},
{CAUSE_IP3, CAUSE_IP3, "IP3"},
{CAUSE_SW2, CAUSE_SW2, "IP2"},
{CAUSE_SW1, CAUSE_SW1, "IP1"},
{CAUSE_EXCMASK, EXC_INT, "Interrupt"},
{CAUSE_EXCMASK, EXC_MOD, "TLB modification exception"},
{CAUSE_EXCMASK, EXC_RMISS, "TLB exception on load or instruction fetch"},
{CAUSE_EXCMASK, EXC_WMISS, "TLB exception on store"},
{CAUSE_EXCMASK, EXC_RADE, "Address error on load or instruction fetch"},
{CAUSE_EXCMASK, EXC_WADE, "Address error on store"},
{CAUSE_EXCMASK, EXC_IBE, "Bus error exception on instruction fetch"},
{CAUSE_EXCMASK, EXC_DBE, "Bus error exception on data reference"},
{CAUSE_EXCMASK, EXC_SYSCALL, "System call exception"},
{CAUSE_EXCMASK, EXC_BREAK, "Breakpoint exception"},
{CAUSE_EXCMASK, EXC_II, "Reserved instruction exception"},
{CAUSE_EXCMASK, EXC_CPU, "Coprocessor unusable exception"},
{CAUSE_EXCMASK, EXC_OV, "Arithmetic overflow exception"},
{CAUSE_EXCMASK, EXC_TRAP, "Trap exception"},
{CAUSE_EXCMASK, EXC_VCEI, "Virtual coherency exception on intruction fetch"},
{CAUSE_EXCMASK, EXC_FPE, "Floating point exception (see fpcsr)"},
{CAUSE_EXCMASK, EXC_WATCH, "Watchpoint exception"},
{CAUSE_EXCMASK, EXC_VCED, "Virtual coherency exception on data reference"},
{0, 0, ""}
};
// List of register descriptions
static regDesc srDesc[] = {
{SR_CU3, SR_CU3, "CU3"},
{SR_CU2, SR_CU2, "CU2"},
{SR_CU1, SR_CU1, "CU1"},
{SR_CU0, SR_CU0, "CU0"},
{SR_RP, SR_RP, "RP"},
{SR_FR, SR_FR, "FR"},
{SR_RE, SR_RE, "RE"},
{SR_BEV, SR_BEV, "BEV"},
{SR_TS, SR_TS, "TS"},
{SR_SR, SR_SR, "SR"},
{SR_CH, SR_CH, "CH"},
{SR_CE, SR_CE, "CE"},
{SR_DE, SR_DE, "DE"},
{SR_IBIT8, SR_IBIT8, "IM8"},
{SR_IBIT7, SR_IBIT7, "IM7"},
{SR_IBIT6, SR_IBIT6, "IM6"},
{SR_IBIT5, SR_IBIT5, "IM5"},
{SR_IBIT4, SR_IBIT4, "IM4"},
{SR_IBIT3, SR_IBIT3, "IM3"},
{SR_IBIT2, SR_IBIT2, "IM2"},
{SR_IBIT1, SR_IBIT1, "IM1"},
{SR_KX, SR_KX, "KX"},
{SR_SX, SR_SX, "SX"},
{SR_UX, SR_UX, "UX"},
{SR_KSU_MASK, SR_KSU_USR, "USR"},
{SR_KSU_MASK, SR_KSU_SUP, "SUP"},
{SR_KSU_MASK, SR_KSU_KER, "KER"},
{SR_ERL, SR_ERL, "ERL"},
{SR_EXL, SR_EXL, "EXL"},
{SR_IE, SR_IE, "IE"},
{0, 0, ""}
};
// List of floating point registers descriptions
static regDesc fpcsrDesc[] = {
{FPCSR_FS, FPCSR_FS, "FS"},
{FPCSR_C, FPCSR_C, "C"},
{FPCSR_CE, FPCSR_CE, "Unimplemented operation"},
{FPCSR_CV, FPCSR_CV, "Invalid operation"},
{FPCSR_CZ, FPCSR_CZ, "Division by zero"},
{FPCSR_CO, FPCSR_CO, "Overflow"},
{FPCSR_CU, FPCSR_CU, "Underflow"},
{FPCSR_CI, FPCSR_CI, "Inexact operation"},
{FPCSR_EV, FPCSR_EV, "EV"},
{FPCSR_EZ, FPCSR_EZ, "EZ"},
{FPCSR_EO, FPCSR_EO, "EO"},
{FPCSR_EU, FPCSR_EU, "EU"},
{FPCSR_EI, FPCSR_EI, "EI"},
{FPCSR_FV, FPCSR_FV, "FV"},
{FPCSR_FZ, FPCSR_FZ, "FZ"},
{FPCSR_FO, FPCSR_FO, "FO"},
{FPCSR_FU, FPCSR_FU, "FU"},
{FPCSR_FI, FPCSR_FI, "FI"},
{FPCSR_RM_MASK, FPCSR_RM_RN, "RN"},
{FPCSR_RM_MASK, FPCSR_RM_RZ, "RZ"},
{FPCSR_RM_MASK, FPCSR_RM_RP, "RP"},
{FPCSR_RM_MASK, FPCSR_RM_RM, "RM"},
{0, 0, ""}
};
/*********************************
Debug functions
@@ -236,24 +278,26 @@ https://github.com/buu342/N64-UNFLoader
return;
// Overwrite osSyncPrintf
#if OVERWRITE_OSPRINT
__printfunc = (void*)debug_osSyncPrintf_implementation;
#ifndef LIBDRAGON
#if OVERWRITE_OSPRINT
__printfunc = (void*)debug_osSyncPrintf_implementation;
#endif
// Initialize the fault thread
#if USE_FAULTTHREAD
osCreateThread(&faultThread, FAULT_THREAD_ID, debug_thread_fault, 0,
(faultThreadStack+FAULT_THREAD_STACK/sizeof(u64)),
FAULT_THREAD_PRI);
osStartThread(&faultThread);
#endif
// Initialize the USB thread
osCreateThread(&usbThread, USB_THREAD_ID, debug_thread_usb, 0,
(usbThreadStack+USB_THREAD_STACK/sizeof(u64)),
USB_THREAD_PRI);
osStartThread(&usbThread);
#endif
// Initialize the fault thread
#if USE_FAULTTHREAD
osCreateThread(&faultThread, FAULT_THREAD_ID, debug_thread_fault, 0,
(faultThreadStack+FAULT_THREAD_STACK/sizeof(u64)),
FAULT_THREAD_PRI);
osStartThread(&faultThread);
#endif
// Initialize the USB thread
osCreateThread(&usbThread, USB_THREAD_ID, debug_thread_usb, 0,
(usbThreadStack+USB_THREAD_STACK/sizeof(u64)),
USB_THREAD_PRI);
osStartThread(&usbThread);
// Mark the debug mode as initialized
debug_initialized = 1;
#if DEBUG_INIT_MSG
@@ -262,6 +306,23 @@ https://github.com/buu342/N64-UNFLoader
}
#ifndef LIBDRAGON
/*==============================
printf_handler
Handles printf memory copying
@param The buffer to copy the partial string to
@param The string to copy
@param The length of the string
@returns The end of the buffer that was written to
==============================*/
static void* printf_handler(void *buf, const char *str, size_t len)
{
return ((char *) memcpy(buf, str, len) + len);
}
#endif
/*==============================
debug_printf
Prints a formatted message to the developer's command prompt.
@@ -269,160 +330,89 @@ https://github.com/buu342/N64-UNFLoader
@param A string to print
@param variadic arguments to print as well
==============================*/
void debug_printf(const char* message, ...)
{
int len = 0;
usbMesg msg;
va_list args;
int i, j=0, delimcount;
int size = strlen(message);
char isdelim = FALSE;
char delim[8] = {0};
memset(debug_buffer, 0, 256);
// Ensure debug mode is initialized
if (!debug_initialized)
return;
// Get the variadic arguments
// use the internal libultra printf function to format the string
va_start(args, message);
// Build the string
for (i=0; i<size; i++)
{
// Decide if we're dealing with %% or something else
if (message[i] == '%')
{
// Handle printing %%
if ((i != 0 && message[i-1] == '%') || (i+1 != size && message[i+1] == '%'))
{
debug_buffer[j++] = message[i];
isdelim = FALSE;
continue;
}
// Handle delimiter start
if (!isdelim)
{
memset(delim, 0, sizeof(delim)/sizeof(delim[0]));
isdelim = TRUE;
delim[0] = '%';
delimcount = 1;
continue;
}
}
// If we're dealing with something else
if (isdelim)
{
char numbuf[25] = {0};
char* vastr = NULL;
// Pick what to attach based on the character after the percentage symbol
delim[delimcount++] = message[i];
switch(message[i])
{
case 'c':
debug_buffer[j++] = (char)va_arg(args, int);
isdelim = FALSE;
break;
case 's':
vastr = (char*)va_arg(args, char*);
break;
case 'u':
case 'X':
sprintf(numbuf, delim, (unsigned int)va_arg(args, unsigned int));
break;
case 'f':
case 'e':
case 'E':
sprintf(numbuf, delim, (double)va_arg(args, double));
break;
case 'x':
case 'i':
case 'd':
case 'o':
sprintf(numbuf, delim, (int)va_arg(args, int));
break;
case 'p':
sprintf(numbuf, delim, (void*)va_arg(args, void*));
break;
case 'l':
case '.':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
continue;
default:
debug_buffer[j++] = '?';
isdelim = FALSE;
continue;
}
// Append the data to the end of our string
if (vastr != NULL)
{
int vastrlen = strlen(vastr);
strcat (debug_buffer, vastr);
j += vastrlen;
isdelim = FALSE;
}
else if (numbuf[0] != '\0')
{
int vastrlen = strlen(numbuf);
strcat (debug_buffer, numbuf);
j += vastrlen;
isdelim = FALSE;
}
}
else
debug_buffer[j++] = message[i];
}
va_end(args);
#ifndef LIBDRAGON
len = _Printf(&printf_handler, debug_buffer, message, args);
#else
len = vsprintf(debug_buffer, message, args);
#endif
va_end(args);
// Get the new size
size = strlen(debug_buffer)+1;
debug_buffer[size-1] = '\0';
// Attach the '\0' if necessary
if (0 <= len)
debug_buffer[len] = '\0';
// Send the printf to the usb thread
msg.msgtype = MSG_WRITE;
msg.datatype = DATATYPE_TEXT;
msg.buff = debug_buffer;
msg.size = len+1;
#ifndef LIBDRAGON
osSendMesg(&usbMessageQ, (OSMesg)&msg, OS_MESG_BLOCK);
#else
debug_thread_usb(&msg);
#endif
}
/*==============================
debug_dumpbinary
Dumps a binary file through USB
@param The file to dump
@param The size of the file
==============================*/
void debug_dumpbinary(void* file, int size)
{
usbMesg msg;
// Send the binary file to the usb thread
msg.msgtype = MSG_WRITE;
msg.datatype = DATATYPE_RAWBINARY;
msg.buff = file;
msg.size = size;
osSendMesg(&usbMessageQ, (OSMesg)&msg, OS_MESG_BLOCK);
#ifndef LIBDRAGON
osSendMesg(&usbMessageQ, (OSMesg)&msg, OS_MESG_BLOCK);
#else
debug_thread_usb(&msg);
#endif
}
/*==============================
debug_screenshot
Sends the currently displayed framebuffer through USB.
Does not pause the drawing thread!
@param The size of each pixel of the framebuffer in bytes
Typically 4 if 32-bit or 2 if 16-bit
@param The width of the framebuffer
@param The height of the framebuffer
DOES NOT PAUSE DRAWING THREAD! Using outside the drawing
thread may lead to a screenshot with visible tearing
==============================*/
void debug_screenshot(int size, int w, int h)
void debug_screenshot()
{
usbMesg msg;
void* frame = osViGetCurrentFramebuffer();
int data[4];
// These addresses were obtained from http://en64.shoutwiki.com/wiki/VI_Registers_Detailed
void* frame = (void*)(0x80000000|(*(u32*)0xA4400004)); // Same as calling osViGetCurrentFramebuffer() in libultra
u32 yscale = (*(u32*)0xA4400034);
u32 w = (*(u32*)0xA4400008);
u32 h = ((((*(u32*)0xA4400028)&0x3FF)-(((*(u32*)0xA4400028)>>16)&0x3FF))*yscale)/2048;
u8 depth = (((*(u32*)0xA4400000)&0x03) == 0x03) ? 4 : 2;
// Ensure debug mode is initialized
if (!debug_initialized)
return;
// Create the data header to send
data[0] = DATATYPE_SCREENSHOT;
data[1] = size;
data[1] = depth;
data[2] = w;
data[3] = h;
@@ -431,14 +421,22 @@ https://github.com/buu342/N64-UNFLoader
msg.datatype = DATATYPE_HEADER;
msg.buff = data;
msg.size = sizeof(data);
osSendMesg(&usbMessageQ, (OSMesg)&msg, OS_MESG_BLOCK);
#ifndef LIBDRAGON
osSendMesg(&usbMessageQ, (OSMesg)&msg, OS_MESG_BLOCK);
#else
debug_thread_usb(&msg);
#endif
// Send the framebuffer to the USB thread
msg.msgtype = MSG_WRITE;
msg.datatype = DATATYPE_SCREENSHOT;
msg.buff = frame;
msg.size = size*w*h;
osSendMesg(&usbMessageQ, (OSMesg)&msg, OS_MESG_BLOCK);
msg.size = depth*w*h;
#ifndef LIBDRAGON
osSendMesg(&usbMessageQ, (OSMesg)&msg, OS_MESG_BLOCK);
#else
debug_thread_usb(&msg);
#endif
}
@@ -457,6 +455,11 @@ https://github.com/buu342/N64-UNFLoader
assert_line = line;
assert_file = file;
// If on libdragon, print where the assertion failed
#ifdef LIBDRAGON
debug_printf("Assertion failed in file '%s', line %d.\n", assert_file, assert_line);
#endif
// Intentionally cause a null pointer exception
*((char*)(NULL)) = 0;
}
@@ -544,7 +547,11 @@ https://github.com/buu342/N64-UNFLoader
// Send a read message to the USB thread
msg.msgtype = MSG_READ;
osSendMesg(&usbMessageQ, (OSMesg)&msg, OS_MESG_BLOCK);
#ifndef LIBDRAGON
osSendMesg(&usbMessageQ, (OSMesg)&msg, OS_MESG_BLOCK);
#else
debug_thread_usb(&msg);
#endif
}
@@ -701,14 +708,21 @@ https://github.com/buu342/N64-UNFLoader
char errortype = USBERROR_NONE;
usbMesg* threadMsg;
// Create the message queue for the USB message
osCreateMesgQueue(&usbMessageQ, &usbMessageBuf, 1);
#ifndef LIBDRAGON
// Create the message queue for the USB message
osCreateMesgQueue(&usbMessageQ, &usbMessageBuf, 1);
#else
// Set the received thread message to the argument
threadMsg = (usbMesg*)arg;
#endif
// Thread loop
while (1)
{
// Wait for a USB message to arrive
osRecvMesg(&usbMessageQ, (OSMesg *)&threadMsg, OS_MESG_BLOCK);
#ifndef LIBDRAGON
// Wait for a USB message to arrive
osRecvMesg(&usbMessageQ, (OSMesg *)&threadMsg, OS_MESG_BLOCK);
#endif
// Ensure there's no data in the USB (which handles MSG_READ)
while (usb_poll() != 0)
@@ -797,118 +811,140 @@ https://github.com/buu342/N64-UNFLoader
usb_write(threadMsg->datatype, threadMsg->buff, threadMsg->size);
break;
}
// If we're in libdragon, break out of the loop as we don't need it
#ifdef LIBDRAGON
break;
#endif
}
}
#if OVERWRITE_OSPRINT
/*==============================
debug_osSyncPrintf_implementation
Overwrites osSyncPrintf calls with this one
Doesn't support variadic arguments
==============================*/
static void* debug_osSyncPrintf_implementation(void *str, const char *buf, size_t n)
{
debug_printf(buf);
return NULL;
}
#ifndef LIBDRAGON
#if OVERWRITE_OSPRINT
#endif
#if USE_FAULTTHREAD
/*==============================
debug_osSyncPrintf_implementation
Overwrites osSyncPrintf calls with this one
@param Unused
@param The buffer with the string
@param The amount of characters to write
@returns The end of the buffer that was written to
==============================*/
/*==============================
debug_printreg
Prints info about a register
@param The value of the register
@param The name of the register
@param The registry description to use
==============================*/
static void debug_printreg(u32 value, char *name, regDesc *desc)
{
char first = 1;
debug_printf("%s\t\t0x%08x <", name, value);
while (desc->mask != 0)
static void* debug_osSyncPrintf_implementation(void *unused, const char *str, size_t len)
{
if ((value & desc->mask) == desc->value)
{
(first) ? (first = 0) : ((void)debug_printf(","));
debug_printf("%s", desc->string);
}
desc++;
}
debug_printf(">\n");
}
/*==============================
debug_thread_fault
Handles the fault thread
@param Arbitrary data that the thread can receive
==============================*/
static void debug_thread_fault(void *arg)
{
OSMesg msg;
OSThread *curr;
// Create the message queue for the fault message
osCreateMesgQueue(&faultMessageQ, &faultMessageBuf, 1);
osSetEventMesg(OS_EVENT_FAULT, &faultMessageQ, (OSMesg)MSG_FAULT);
// Thread loop
while (1)
{
// Wait for a fault message to arrive
osRecvMesg(&faultMessageQ, (OSMesg *)&msg, OS_MESG_BLOCK);
void* ret;
usbMesg msg;
// Get the faulted thread
curr = (OSThread *)__osGetCurrFaultedThread();
if (curr != NULL)
// Clear the debug buffer and copy the formatted string to it
memset(debug_buffer, 0, len+1);
ret = ((char *) memcpy(debug_buffer, str, len) + len);
// Send the printf to the usb thread
msg.msgtype = MSG_WRITE;
msg.datatype = DATATYPE_TEXT;
msg.buff = debug_buffer;
msg.size = len+1;
osSendMesg(&usbMessageQ, (OSMesg)&msg, OS_MESG_BLOCK);
// Return the end of the buffer
return ret;
}
#endif
#if USE_FAULTTHREAD
/*==============================
debug_printreg
Prints info about a register
@param The value of the register
@param The name of the register
@param The registry description to use
==============================*/
static void debug_printreg(u32 value, char *name, regDesc *desc)
{
char first = 1;
debug_printf("%s\t\t0x%08x <", name, value);
while (desc->mask != 0)
{
__OSThreadContext* context = &curr->context;
if ((value & desc->mask) == desc->value)
{
(first) ? (first = 0) : ((void)debug_printf(","));
debug_printf("%s", desc->string);
}
desc++;
}
debug_printf(">\n");
}
/*==============================
debug_thread_fault
Handles the fault thread
@param Arbitrary data that the thread can receive
==============================*/
static void debug_thread_fault(void *arg)
{
OSMesg msg;
OSThread *curr;
// Print the basic info
debug_printf("Fault in thread: %d\n\n", curr->id);
debug_printf("pc\t\t0x%08x\n", context->pc);
if (assert_file == NULL)
debug_printreg(context->cause, "cause", causeDesc);
else
debug_printf("cause\t\tAssertion failed in file '%s', line %d.\n", assert_file, assert_line);
debug_printreg(context->sr, "sr", srDesc);
debug_printf("badvaddr\t0x%08x\n\n", context->badvaddr);
// Create the message queue for the fault message
osCreateMesgQueue(&faultMessageQ, &faultMessageBuf, 1);
osSetEventMesg(OS_EVENT_FAULT, &faultMessageQ, (OSMesg)MSG_FAULT);
// Thread loop
while (1)
{
// Wait for a fault message to arrive
osRecvMesg(&faultMessageQ, (OSMesg *)&msg, OS_MESG_BLOCK);
// Print the registers
debug_printf("at 0x%016llx v0 0x%016llx v1 0x%016llx\n", context->at, context->v0, context->v1);
debug_printf("a0 0x%016llx a1 0x%016llx a2 0x%016llx\n", context->a0, context->a1, context->a2);
debug_printf("a3 0x%016llx t0 0x%016llx t1 0x%016llx\n", context->a3, context->t0, context->t1);
debug_printf("t2 0x%016llx t3 0x%016llx t4 0x%016llx\n", context->t2, context->t3, context->t4);
debug_printf("t5 0x%016llx t6 0x%016llx t7 0x%016llx\n", context->t5, context->t6, context->t7);
debug_printf("s0 0x%016llx s1 0x%016llx s2 0x%016llx\n", context->s0, context->s1, context->s2);
debug_printf("s3 0x%016llx s4 0x%016llx s5 0x%016llx\n", context->s3, context->s4, context->s5);
debug_printf("s6 0x%016llx s7 0x%016llx t8 0x%016llx\n", context->s6, context->s7, context->t8);
debug_printf("t9 0x%016llx gp 0x%016llx sp 0x%016llx\n", context->t9, context->gp, context->sp);
debug_printf("s8 0x%016llx ra 0x%016llx\n\n", context->s8, context->ra);
// Get the faulted thread
curr = (OSThread *)__osGetCurrFaultedThread();
if (curr != NULL)
{
__OSThreadContext* context = &curr->context;
// Print the floating point registers
debug_printreg(context->fpcsr, "fpcsr", fpcsrDesc);
debug_printf("\n");
debug_printf("d0 %.15e\td2 %.15e\n", context->fp0.d, context->fp2.d);
debug_printf("d4 %.15e\td6 %.15e\n", context->fp4.d, context->fp6.d);
debug_printf("d8 %.15e\td10 %.15e\n", context->fp8.d, context->fp10.d);
debug_printf("d12 %.15e\td14 %.15e\n", context->fp12.d, context->fp14.d);
debug_printf("d16 %.15e\td18 %.15e\n", context->fp16.d, context->fp18.d);
debug_printf("d20 %.15e\td22 %.15e\n", context->fp20.d, context->fp22.d);
debug_printf("d24 %.15e\td26 %.15e\n", context->fp24.d, context->fp26.d);
debug_printf("d28 %.15e\td30 %.15e\n", context->fp28.d, context->fp30.d);
// Print the basic info
debug_printf("Fault in thread: %d\n\n", curr->id);
debug_printf("pc\t\t0x%08x\n", context->pc);
if (assert_file == NULL)
debug_printreg(context->cause, "cause", causeDesc);
else
debug_printf("cause\t\tAssertion failed in file '%s', line %d.\n", assert_file, assert_line);
debug_printreg(context->sr, "sr", srDesc);
debug_printf("badvaddr\t0x%08x\n\n", context->badvaddr);
// Print the registers
debug_printf("at 0x%016llx v0 0x%016llx v1 0x%016llx\n", context->at, context->v0, context->v1);
debug_printf("a0 0x%016llx a1 0x%016llx a2 0x%016llx\n", context->a0, context->a1, context->a2);
debug_printf("a3 0x%016llx t0 0x%016llx t1 0x%016llx\n", context->a3, context->t0, context->t1);
debug_printf("t2 0x%016llx t3 0x%016llx t4 0x%016llx\n", context->t2, context->t3, context->t4);
debug_printf("t5 0x%016llx t6 0x%016llx t7 0x%016llx\n", context->t5, context->t6, context->t7);
debug_printf("s0 0x%016llx s1 0x%016llx s2 0x%016llx\n", context->s0, context->s1, context->s2);
debug_printf("s3 0x%016llx s4 0x%016llx s5 0x%016llx\n", context->s3, context->s4, context->s5);
debug_printf("s6 0x%016llx s7 0x%016llx t8 0x%016llx\n", context->s6, context->s7, context->t8);
debug_printf("t9 0x%016llx gp 0x%016llx sp 0x%016llx\n", context->t9, context->gp, context->sp);
debug_printf("s8 0x%016llx ra 0x%016llx\n\n", context->s8, context->ra);
// Print the floating point registers
debug_printreg(context->fpcsr, "fpcsr", fpcsrDesc);
debug_printf("\n");
debug_printf("d0 %.15e\td2 %.15e\n", context->fp0.d, context->fp2.d);
debug_printf("d4 %.15e\td6 %.15e\n", context->fp4.d, context->fp6.d);
debug_printf("d8 %.15e\td10 %.15e\n", context->fp8.d, context->fp10.d);
debug_printf("d12 %.15e\td14 %.15e\n", context->fp12.d, context->fp14.d);
debug_printf("d16 %.15e\td18 %.15e\n", context->fp16.d, context->fp18.d);
debug_printf("d20 %.15e\td22 %.15e\n", context->fp20.d, context->fp22.d);
debug_printf("d24 %.15e\td26 %.15e\n", context->fp24.d, context->fp26.d);
debug_printf("d28 %.15e\td30 %.15e\n", context->fp28.d, context->fp30.d);
}
}
}
}
#endif
#endif
#endif
+21 -13
View File
@@ -7,17 +7,17 @@
// Settings
#define DEBUG_MODE 1 // Enable/Disable debug mode
#define DEBUG_INIT_MSG 0 // Print a message when debug mode has initialized
#define USE_FAULTTHREAD 0 // Create a fault detection thread
#define OVERWRITE_OSPRINT 0 // Replaces osSyncPrintf calls with debug_printf
#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 0 // Replaces osSyncPrintf calls with debug_printf (libultra only)
#define MAX_COMMANDS 25 // The max amount of user defined commands possible
// Fault thread definitions
// Fault thread definitions (libultra only)
#define FAULT_THREAD_ID 13
#define FAULT_THREAD_PRI 125
#define FAULT_THREAD_STACK 0x2000
// USB thread definitions
// USB thread definitions (libultra only)
#define USB_THREAD_ID 14
#define USB_THREAD_PRI 126
#define USB_THREAD_STACK 0x2000
@@ -49,15 +49,23 @@
/*==============================
debug_screenshot
Sends the currently displayed framebuffer through USB.
@param The size of each pixel of the framebuffer in bytes
Typically 4 if 32-bit or 2 if 16-bit
@param The width of the framebuffer
@param The height of the framebuffer
debug_dumpbinary
Dumps a binary file through USB
@param The file to dump
@param The size of the file
==============================*/
extern void debug_screenshot(int size, int w, int h);
extern void debug_dumpbinary(void* file, int size);
/*==============================
debug_screenshot
Sends the currently displayed framebuffer through USB.
DOES NOT PAUSE DRAWING THREAD! Using outside the drawing
thread may lead to a screenshot with visible tearing
==============================*/
extern void debug_screenshot();
/*==============================
@@ -126,7 +134,7 @@
// Overwrite library functions with useless macros if debug mode is disabled
#define debug_initialize()
#define debug_printf(a, __VA_ARGS__)
#define debug_printf(__VA_ARGS__)
#define debug_screenshot(a, b, c)
#define debug_assert(a)
#define debug_pollcommands()
+377 -216
View File
@@ -6,10 +6,13 @@ using UNFLoader.
https://github.com/buu342/N64-UNFLoader
***************************************************************/
#include <ultra64.h>
#include <string.h>
#include "usb.h"
#define ALIGN(s, align) (((u32)(s) + ((align)-1)) & ~((align)-1))
#ifndef LIBDRAGON
#include <ultra64.h>
#else
#include <libdragon.h>
#endif
#include <string.h>
/*********************************
@@ -26,6 +29,51 @@ https://github.com/buu342/N64-UNFLoader
#define USBHEADER_CREATE(type, left) (((type<<24) | (left & 0x00FFFFFF)))
/*********************************
Libultra macros for libdragon
*********************************/
#ifdef LIBDRAGON
// Useful
#define ALIGN(s, align) (((u32)(s) + ((align)-1)) & ~((align)-1))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef NULL
#define NULL 0
#endif
// MIPS addresses
#define KSEG0 0x80000000
#define KSEG1 0xA0000000
// Memory translation stuff
#define PHYS_TO_K1(x) ((u32)(x)|KSEG1)
#define IO_WRITE(addr,data) (*(vu32 *)PHYS_TO_K1(addr)=(u32)(data))
#define IO_READ(addr) (*(vu32 *)PHYS_TO_K1(addr))
// PI registers
#define PI_BASE_REG 0x04600000
#define PI_STATUS_REG (PI_BASE_REG+0x10)
#define PI_STATUS_ERROR 0x04
#define PI_STATUS_IO_BUSY 0x02
#define PI_STATUS_DMA_BUSY 0x01
#define PI_BSD_DOM1_LAT_REG (PI_BASE_REG+0x14)
#define PI_BSD_DOM1_PWD_REG (PI_BASE_REG+0x18)
#define PI_BSD_DOM1_PGS_REG (PI_BASE_REG+0x1C)
#define PI_BSD_DOM1_RLS_REG (PI_BASE_REG+0x20)
#define PI_BSD_DOM2_LAT_REG (PI_BASE_REG+0x24)
#define PI_BSD_DOM2_PWD_REG (PI_BASE_REG+0x28)
#define PI_BSD_DOM2_PGS_REG (PI_BASE_REG+0x2C)
#define PI_BSD_DOM2_RLS_REG (PI_BASE_REG+0x30)
#endif
/*********************************
Parallel Interface macros
*********************************/
@@ -43,6 +91,10 @@ https://github.com/buu342/N64-UNFLoader
64Drive macros
*********************************/
// How many cycles for the 64Drive to wait for data.
// Lowering this might improve performance slightly faster at the expense of USB reading accuracy
#define D64_POLLTIME 2000
// Cartridge Interface definitions. Obtained from 64Drive's Spec Sheet
#define D64_BASE_ADDRESS 0xB0000000
#define D64_CIREG_ADDRESS 0x08000000
@@ -85,7 +137,7 @@ https://github.com/buu342/N64-UNFLoader
/*********************************
EverDrive macros
EverDrive macros
*********************************/
#define ED_BASE 0x10000000
@@ -150,7 +202,37 @@ https://github.com/buu342/N64-UNFLoader
/*********************************
Function Prototypes
Libultra types (for libdragon)
*********************************/
#ifdef LIBDRAGON
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
typedef volatile uint8_t vu8;
typedef volatile uint16_t vu16;
typedef volatile uint32_t vu32;
typedef volatile uint64_t vu64;
typedef volatile int8_t vs8;
typedef volatile int16_t vs16;
typedef volatile int32_t vs32;
typedef volatile int64_t vs64;
typedef float f32;
typedef double f64;
#endif
/*********************************
Function Prototypes
*********************************/
static void usb_findcart();
@@ -163,7 +245,7 @@ static u32 usb_everdrive_poll();
static void usb_everdrive_read();
static void usb_everdrive_writereg(u64 reg, u32 value);
static void usb_sc64_write(int datatype, const void* data, int size);
static u32 usb_sc64_poll();
static u32 usb_sc64_poll();
static void usb_sc64_read();
@@ -178,33 +260,35 @@ void (*funcPointer_read)();
// USB globals
static s8 usb_cart = CART_NONE;
static u8 usb_buffer[BUFFER_SIZE*3] __attribute__((aligned(16)));
static u8 __attribute__((aligned(16))) usb_buffer[BUFFER_SIZE];
int usb_datatype = 0;
int usb_datasize = 0;
int usb_dataleft = 0;
int usb_readblock = -1;
#ifndef LIBDRAGON
// Message globals
#if !USE_OSRAW
OSMesg dmaMessageBuf;
OSIoMesg dmaIOMessageBuf;
OSMesgQueue dmaMessageQ;
#endif
#if !USE_OSRAW
OSMesg dmaMessageBuf;
OSIoMesg dmaIOMessageBuf;
OSMesgQueue dmaMessageQ;
#endif
// osPiRaw
#if USE_OSRAW
extern s32 __osPiRawWriteIo(u32, u32);
extern s32 __osPiRawReadIo(u32, u32 *);
extern s32 __osPiRawStartDma(s32, u32, void *, u32);
#define osPiRawWriteIo(a, b) __osPiRawWriteIo(a, b)
#define osPiRawReadIo(a, b) __osPiRawReadIo(a, b)
#define osPiRawStartDma(a, b, c, d) __osPiRawStartDma(a, b, c, d)
// osPiRaw
#if USE_OSRAW
extern s32 __osPiRawWriteIo(u32, u32);
extern s32 __osPiRawReadIo(u32, u32 *);
extern s32 __osPiRawStartDma(s32, u32, void *, u32);
#define osPiRawWriteIo(a, b) __osPiRawWriteIo(a, b)
#define osPiRawReadIo(a, b) __osPiRawReadIo(a, b)
#define osPiRawStartDma(a, b, c, d) __osPiRawStartDma(a, b, c, d)
#endif
#endif
/*********************************
USB functions
USB functions
*********************************/
/*==============================
@@ -218,9 +302,11 @@ char usb_initialize()
// Initialize the debug related globals
memset(usb_buffer, 0, BUFFER_SIZE);
// Create the message queue
#if !USE_OSRAW
osCreateMesgQueue(&dmaMessageQ, &dmaMessageBuf, 1);
#ifndef LIBDRAGON
// Create the message queue
#if !USE_OSRAW
osCreateMesgQueue(&dmaMessageQ, &dmaMessageBuf, 1);
#endif
#endif
// Find the flashcart
@@ -261,10 +347,14 @@ static void usb_findcart()
u32 buff __attribute__((aligned(8)));
// Read the cartridge and check if we have a 64Drive.
#if USE_OSRAW
osPiRawReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_MAGIC, &buff);
#ifdef LIBDRAGON
buff = io_read(D64_CIBASE_ADDRESS + D64_REGISTER_MAGIC);
#else
osPiReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_MAGIC, &buff);
#if USE_OSRAW
osPiRawReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_MAGIC, &buff);
#else
osPiReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_MAGIC, &buff);
#endif
#endif
if (buff == D64_MAGIC)
{
@@ -273,10 +363,14 @@ static void usb_findcart()
}
// Read the cartridge and check if we have a SummerCart64.
#if USE_OSRAW
osPiRawReadIo(SC64_REG_VERSION, &buff);
#ifdef LIBDRAGON
buff = io_read(SC64_REG_VERSION);
#else
osPiReadIo(SC64_REG_VERSION, &buff);
#if USE_OSRAW
osPiRawReadIo(SC64_REG_VERSION, &buff);
#else
osPiReadIo(SC64_REG_VERSION, &buff);
#endif
#endif
if (buff == SC64_VERSION_A)
{
@@ -499,10 +593,14 @@ static s8 usb_64drive_wait()
// Wait until the cartridge interface is ready
do
{
#if USE_OSRAW
osPiRawReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_STATUS, &ret);
#ifdef LIBDRAGON
ret = io_read(D64_CIBASE_ADDRESS + D64_REGISTER_STATUS);
#else
osPiReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_STATUS, &ret);
#if USE_OSRAW
osPiRawReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_STATUS, &ret);
#else
osPiReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_STATUS, &ret);
#endif
#endif
// Took too long, abort
@@ -510,6 +608,7 @@ static s8 usb_64drive_wait()
return -1;
}
while((ret >> 8) & D64_CI_BUSY);
(void) timeout; // Needed to stop unused variable warning
// Success
return 0;
@@ -525,10 +624,14 @@ static s8 usb_64drive_wait()
static void usb_64drive_setwritable(u8 enable)
{
usb_64drive_wait();
#if USE_OSRAW
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_COMMAND, enable ? D64_ENABLE_ROMWR : D64_DISABLE_ROMWR);
#ifdef LIBDRAGON
io_write(D64_CIBASE_ADDRESS + D64_REGISTER_COMMAND, enable ? D64_ENABLE_ROMWR : D64_DISABLE_ROMWR);
#else
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_COMMAND, enable ? D64_ENABLE_ROMWR : D64_DISABLE_ROMWR);
#if USE_OSRAW
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_COMMAND, enable ? D64_ENABLE_ROMWR : D64_DISABLE_ROMWR);
#else
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_COMMAND, enable ? D64_ENABLE_ROMWR : D64_DISABLE_ROMWR);
#endif
#endif
usb_64drive_wait();
}
@@ -544,10 +647,14 @@ static void usb_64drive_waitidle()
u32 status __attribute__((aligned(8)));
do
{
#if USE_OSRAW
osPiRawReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, &status);
#ifdef LIBDRAGON
status = io_read(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT);
#else
osPiReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, &status);
#if USE_OSRAW
osPiRawReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, &status);
#else
osPiReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, &status);
#endif
#endif
status = (status >> 4) & D64_USB_BUSY;
}
@@ -564,10 +671,14 @@ static void usb_64drive_waitidle()
static u32 usb_64drive_armstatus()
{
u32 status __attribute__((aligned(8)));
#if USE_OSRAW
osPiRawReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, &status);
#ifdef LIBDRAGON
status = io_read(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT);
#else
osPiReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, &status);
#if USE_OSRAW
osPiRawReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, &status);
#else
osPiReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, &status);
#endif
#endif
return status & 0xf;
}
@@ -583,10 +694,14 @@ static void usb_64drive_waitdisarmed()
u32 status __attribute__((aligned(8)));
do
{
#if USE_OSRAW
osPiRawReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, &status);
#ifdef LIBDRAGON
status = io_read(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT);
#else
osPiReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, &status);
#if USE_OSRAW
osPiRawReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, &status);
#else
osPiReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, &status);
#endif
#endif
status &= 0x0F;
}
@@ -637,32 +752,42 @@ static void usb_64drive_write(int datatype, const void* data, int size)
usb_64drive_waitidle();
// Set up DMA transfer between RDRAM and the PI
osWritebackDCache(usb_buffer, block);
#if USE_OSRAW
osPiRawStartDma(OS_WRITE,
D64_BASE_ADDRESS + DEBUG_ADDRESS + read,
usb_buffer, block);
#ifdef LIBDRAGON
data_cache_hit_writeback(usb_buffer, block);
dma_write(usb_buffer, D64_BASE_ADDRESS + DEBUG_ADDRESS + read, block);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_WRITE,
D64_BASE_ADDRESS + DEBUG_ADDRESS + read,
usb_buffer, block, &dmaMessageQ);
(void)osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
osWritebackDCache(usb_buffer, block);
#if USE_OSRAW
osPiRawStartDma(OS_WRITE,
D64_BASE_ADDRESS + DEBUG_ADDRESS + read,
usb_buffer, block);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_WRITE,
D64_BASE_ADDRESS + DEBUG_ADDRESS + read,
usb_buffer, block, &dmaMessageQ);
(void)osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
#endif
#endif
// Keep track of what we've read so far
left -= block;
read += block;
}
// Send the data through USB
#if USE_OSRAW
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP0R0, (DEBUG_ADDRESS) >> 1);
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP1R1, (size & 0xFFFFFF) | (datatype << 24));
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, D64_COMMAND_WRITE);
#ifdef LIBDRAGON
io_write(D64_CIBASE_ADDRESS + D64_REGISTER_USBP0R0, (DEBUG_ADDRESS) >> 1);
io_write(D64_CIBASE_ADDRESS + D64_REGISTER_USBP1R1, (size & 0xFFFFFF) | (datatype << 24));
io_write(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, D64_COMMAND_WRITE);
#else
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP0R0, (DEBUG_ADDRESS) >> 1);
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP1R1, (size & 0xFFFFFF) | (datatype << 24));
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, D64_COMMAND_WRITE);
#if USE_OSRAW
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP0R0, (DEBUG_ADDRESS) >> 1);
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP1R1, (size & 0xFFFFFF) | (datatype << 24));
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, D64_COMMAND_WRITE);
#else
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP0R0, (DEBUG_ADDRESS) >> 1);
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP1R1, (size & 0xFFFFFF) | (datatype << 24));
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, D64_COMMAND_WRITE);
#endif
#endif
// Spin until the write buffer is free and then disable write mode
@@ -688,14 +813,20 @@ static void usb_64drive_arm(u32 offset, u32 size)
usb_64drive_waitidle();
// Arm the 64Drive, using the ROM space as a buffer
#if USE_OSRAW
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, D64_USB_ARM);
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP0R0, (offset >> 1));
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP1R1, (size & 0xFFFFFF));
#ifdef LIBDRAGON
io_write(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, D64_USB_ARM);
io_write(D64_CIBASE_ADDRESS + D64_REGISTER_USBP0R0, (offset >> 1));
io_write(D64_CIBASE_ADDRESS + D64_REGISTER_USBP1R1, (size & 0xFFFFFF));
#else
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, D64_USB_ARM);
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP0R0, (offset >> 1));
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP1R1, (size & 0xFFFFFF));
#if USE_OSRAW
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, D64_USB_ARM);
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP0R0, (offset >> 1));
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP1R1, (size & 0xFFFFFF));
#else
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, D64_USB_ARM);
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP0R0, (offset >> 1));
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP1R1, (size & 0xFFFFFF));
#endif
#endif
}
}
@@ -709,10 +840,14 @@ static void usb_64drive_arm(u32 offset, u32 size)
static void usb_64drive_disarm()
{
// Disarm the USB
#if USE_OSRAW
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, D64_USB_DISARM);
#ifdef LIBDRAGON
io_write(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, D64_USB_DISARM);
#else
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, D64_USB_DISARM);
#if USE_OSRAW
osPiRawWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, D64_USB_DISARM);
#else
osPiWriteIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBCOMSTAT, D64_USB_DISARM);
#endif
#endif
usb_64drive_waitdisarmed();
}
@@ -727,6 +862,7 @@ static void usb_64drive_disarm()
static u32 usb_64drive_poll()
{
int i;
u32 ret __attribute__((aligned(8)));
// Arm the USB buffer
@@ -734,77 +870,29 @@ static u32 usb_64drive_poll()
usb_64drive_setwritable(TRUE);
usb_64drive_arm(DEBUG_ADDRESS, DEBUG_ADDRESS_SIZE);
// Burn some time to see if any USB data comes in
for (i=0; i<D64_POLLTIME; i++)
;
// If there's data to service
if (usb_64drive_armstatus() == D64_USB_DATA)
{
char buff[8];
u32 copyleft;
// Read ROM to get the data header
osWritebackDCacheAll();
#if USE_OSRAW
osPiRawStartDma(OS_READ,
D64_BASE_ADDRESS + DEBUG_ADDRESS, buff,
8);
// Read the data header from the Param0 register
#ifdef LIBDRAGON
ret = io_read(D64_CIBASE_ADDRESS + D64_REGISTER_USBP0R0);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_READ,
D64_BASE_ADDRESS + DEBUG_ADDRESS, buff,
8, &dmaMessageQ);
(void)osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
#if USE_OSRAW
osPiRawReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP0R0, &ret);
#else
osPiReadIo(D64_CIBASE_ADDRESS + D64_REGISTER_USBP0R0, &ret);
#endif
#endif
// Ensure we got a USB request and this isn't something else
if (buff[0] != 'D' && buff[1] != 'M' && buff[2] != 'A' && buff[3] != '@')
return 0;
// Get the data header
ret = buff[4] << 24 | buff[5] << 16 | buff[6] << 8 | buff[7];
usb_datatype = USBHEADER_GETTYPE(ret);
usb_dataleft = USBHEADER_GETSIZE(ret);
usb_datasize = usb_dataleft;
usb_readblock = -1;
copyleft = usb_dataleft;
// Copy data from USB to ROM
while (copyleft > 0)
{
u32 block = copyleft%BUFFER_SIZE;
if (block == 0)
block = BUFFER_SIZE;
// Arm the 64Drive's USB
usb_64drive_arm(DEBUG_ADDRESS, DEBUG_ADDRESS_SIZE);
// Wait for data to arrive
while (usb_64drive_armstatus() != D64_USB_DATA)
;
// Put the data in the correct ROM offset
osWritebackDCacheAll();
#if USE_OSRAW
osPiRawStartDma(OS_READ,
D64_BASE_ADDRESS + DEBUG_ADDRESS, usb_buffer,
BUFFER_SIZE);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_READ,
D64_BASE_ADDRESS + DEBUG_ADDRESS, usb_buffer,
BUFFER_SIZE, &dmaMessageQ);
(void)osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
#endif
osWritebackDCacheAll();
#if USE_OSRAW
osPiRawStartDma(OS_WRITE,
D64_BASE_ADDRESS + DEBUG_ADDRESS + (copyleft-block), usb_buffer,
BUFFER_SIZE);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_WRITE,
D64_BASE_ADDRESS + DEBUG_ADDRESS + (copyleft-block), usb_buffer,
BUFFER_SIZE, &dmaMessageQ);
(void)osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
#endif
copyleft -= block;
}
// Return the data header
usb_64drive_waitidle();
@@ -828,16 +916,21 @@ static u32 usb_64drive_poll()
static void usb_64drive_read()
{
// Set up DMA transfer between RDRAM and the PI
osWritebackDCacheAll();
#if USE_OSRAW
osPiRawStartDma(OS_READ,
D64_BASE_ADDRESS + DEBUG_ADDRESS + usb_readblock, usb_buffer,
BUFFER_SIZE);
#ifdef LIBDRAGON
data_cache_hit_writeback_invalidate(usb_buffer, BUFFER_SIZE);
dma_read(usb_buffer, D64_BASE_ADDRESS + DEBUG_ADDRESS + usb_readblock, BUFFER_SIZE);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_READ,
D64_BASE_ADDRESS + DEBUG_ADDRESS + usb_readblock, usb_buffer,
BUFFER_SIZE, &dmaMessageQ);
(void)osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
osWritebackDCacheAll();
#if USE_OSRAW
osPiRawStartDma(OS_READ,
D64_BASE_ADDRESS + DEBUG_ADDRESS + usb_readblock, usb_buffer,
BUFFER_SIZE);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_READ,
D64_BASE_ADDRESS + DEBUG_ADDRESS + usb_readblock, usb_buffer,
BUFFER_SIZE, &dmaMessageQ);
(void)osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
#endif
#endif
}
@@ -877,16 +970,21 @@ static void usb_everdrive_readdata(void* buff, u32 pi_address, u32 len)
pi_address &= 0x1FFFFFFF;
// Set up DMA transfer between RDRAM and the PI
osInvalDCache(buff, len);
#if USE_OSRAW
osPiRawStartDma(OS_READ,
pi_address, buff,
len);
#ifdef LIBDRAGON
data_cache_hit_writeback_invalidate(buff, len);
disable_interrupts();
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_READ,
pi_address, buff,
len, &dmaMessageQ);
(void)osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
osInvalDCache(buff, len);
#if USE_OSRAW
osPiRawStartDma(OS_READ,
pi_address, buff,
len);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_READ,
pi_address, buff,
len, &dmaMessageQ);
(void)osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
#endif
#endif
// Write the data to the PI
@@ -894,8 +992,17 @@ static void usb_everdrive_readdata(void* buff, u32 pi_address, u32 len)
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;
#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
}
@@ -926,16 +1033,21 @@ static void usb_everdrive_writedata(void* buff, u32 pi_address, u32 len)
pi_address &= 0x1FFFFFFF;
// Set up DMA transfer between RDRAM and the PI
osWritebackDCache(buff, len);
#if USE_OSRAW
osPiRawStartDma(OS_WRITE,
pi_address, buff,
len);
#ifdef LIBDRAGON
data_cache_hit_writeback(buff, len);
disable_interrupts();
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_WRITE,
pi_address, buff,
len, &dmaMessageQ);
(void)osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
osWritebackDCache(buff, len);
#if USE_OSRAW
osPiRawStartDma(OS_WRITE,
pi_address, buff,
len);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_WRITE,
pi_address, buff,
len, &dmaMessageQ);
(void)osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
#endif
#endif
// Write the data to the PI
@@ -943,8 +1055,17 @@ static void usb_everdrive_writedata(void* buff, u32 pi_address, u32 len)
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;
#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
}
@@ -1175,16 +1296,24 @@ static u32 usb_everdrive_poll()
static void usb_everdrive_read()
{
// Set up DMA transfer between RDRAM and the PI
osWritebackDCacheAll();
#if USE_OSRAW
osPiRawStartDma(OS_READ,
ED_BASE + DEBUG_ADDRESS + usb_readblock, usb_buffer,
BUFFER_SIZE);
#ifdef LIBDRAGON
data_cache_hit_writeback_invalidate(usb_buffer, BUFFER_SIZE);
while (dma_busy());
*(vu32*)0xA4600010 = 3;
dma_read(usb_buffer, ED_BASE + DEBUG_ADDRESS + usb_readblock, BUFFER_SIZE);
data_cache_hit_writeback_invalidate(usb_buffer, BUFFER_SIZE);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_READ,
ED_BASE + DEBUG_ADDRESS + usb_readblock, usb_buffer,
BUFFER_SIZE, &dmaMessageQ);
(void)osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
osWritebackDCacheAll();
#if USE_OSRAW
osPiRawStartDma(OS_READ,
ED_BASE + DEBUG_ADDRESS + usb_readblock, usb_buffer,
BUFFER_SIZE);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_READ,
ED_BASE + DEBUG_ADDRESS + usb_readblock, usb_buffer,
BUFFER_SIZE, &dmaMessageQ);
(void)osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
#endif
#endif
}
@@ -1193,7 +1322,6 @@ static void usb_everdrive_read()
SummerCart64 functions
*********************************/
/*==============================
usb_sc64_read_usb_scr
Reads SummerCart64 REG_USB_SCR register
@@ -1204,12 +1332,15 @@ static u32 usb_sc64_read_usb_scr(void)
{
u32 usb_scr __attribute__((aligned(8)));
#if USE_OSRAW
osPiRawReadIo(SC64_REG_USB_SCR, &usb_scr);
#ifdef LIBDRAGON
usb_scr = io_read(SC64_REG_USB_SCR);
#else
osPiReadIo(SC64_REG_USB_SCR, &usb_scr);
#if USE_OSRAW
osPiRawReadIo(SC64_REG_USB_SCR, &usb_scr);
#else
osPiReadIo(SC64_REG_USB_SCR, &usb_scr);
#endif
#endif
return usb_scr;
}
@@ -1224,12 +1355,16 @@ static u32 usb_sc64_read_usb_fifo(void)
{
u32 data __attribute__((aligned(8)));
#if USE_OSRAW
osPiRawReadIo(SC64_MEM_USB_FIFO_BASE, &data);
#ifdef LIBDRAGON
data = io_read(SC64_MEM_USB_FIFO_BASE);
#else
osPiReadIo(SC64_MEM_USB_FIFO_BASE, &data);
#if USE_OSRAW
osPiRawReadIo(SC64_MEM_USB_FIFO_BASE, &data);
#else
osPiReadIo(SC64_MEM_USB_FIFO_BASE, &data);
#endif
#endif
return data;
}
@@ -1296,12 +1431,17 @@ static void usb_sc64_setwritable(u8 enable)
{
u32 scr __attribute__((aligned(8)));
#if USE_OSRAW
osPiRawReadIo(SC64_REG_SCR, &scr);
osPiRawWriteIo(SC64_REG_SCR, enable ? (scr | SC64_SCR_SDRAM_WRITE_EN) : (scr & (~SC64_SCR_SDRAM_WRITE_EN)));
#ifdef LIBDRAGON
scr = io_read(SC64_REG_SCR);
io_write(SC64_REG_SCR, enable ? (scr | SC64_SCR_SDRAM_WRITE_EN) : (scr & (~SC64_SCR_SDRAM_WRITE_EN)));
#else
osPiReadIo(SC64_REG_SCR, &scr);
osPiWriteIo(SC64_REG_SCR, enable ? (scr | SC64_SCR_SDRAM_WRITE_EN) : (scr & (~SC64_SCR_SDRAM_WRITE_EN)));
#if USE_OSRAW
osPiRawReadIo(SC64_REG_SCR, &scr);
osPiRawWriteIo(SC64_REG_SCR, enable ? (scr | SC64_SCR_SDRAM_WRITE_EN) : (scr & (~SC64_SCR_SDRAM_WRITE_EN)));
#else
osPiReadIo(SC64_REG_SCR, &scr);
osPiWriteIo(SC64_REG_SCR, enable ? (scr | SC64_SCR_SDRAM_WRITE_EN) : (scr & (~SC64_SCR_SDRAM_WRITE_EN)));
#endif
#endif
}
@@ -1372,12 +1512,17 @@ static void usb_sc64_write(int datatype, const void* data, int size)
dma_length = ALIGN(offset + data_length, 4);
// Write data to buffer in SDRAM
osWritebackDCache(usb_buffer, dma_length);
#if USE_OSRAW
osPiRawStartDma(OS_WRITE, sdram_address, usb_buffer, dma_length);
#ifdef LIBDRAGON
data_cache_hit_writeback(usb_buffer, dma_length);
dma_write(usb_buffer, sdram_address, dma_length);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_WRITE, sdram_address, usb_buffer, dma_length, &dmaMessageQ);
osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
osWritebackDCache(usb_buffer, dma_length);
#if USE_OSRAW
osPiRawStartDma(OS_WRITE, sdram_address, usb_buffer, dma_length);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_WRITE, sdram_address, usb_buffer, dma_length, &dmaMessageQ);
osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
#endif
#endif
// Update pointers and remaining data tracking
@@ -1400,14 +1545,20 @@ static void usb_sc64_write(int datatype, const void* data, int size)
}
// Setup hardware registers
#if USE_OSRAW
osPiRawWriteIo(SC64_REG_USB_DMA_ADDR, SC64_USB_BANK_ADDR(SC64_BANK_ROM, DEBUG_ADDRESS));
osPiRawWriteIo(SC64_REG_USB_DMA_LEN, SC64_USB_LENGTH(transfer_length));
osPiRawWriteIo(SC64_REG_USB_SCR, SC64_USB_CONTROL_START);
#ifdef LIBDRAGON
io_write(SC64_REG_USB_DMA_ADDR, SC64_USB_BANK_ADDR(SC64_BANK_ROM, DEBUG_ADDRESS));
io_write(SC64_REG_USB_DMA_LEN, SC64_USB_LENGTH(transfer_length));
io_write(SC64_REG_USB_SCR, SC64_USB_CONTROL_START);
#else
osPiWriteIo(SC64_REG_USB_DMA_ADDR, SC64_USB_BANK_ADDR(SC64_BANK_ROM, DEBUG_ADDRESS));
osPiWriteIo(SC64_REG_USB_DMA_LEN, SC64_USB_LENGTH(transfer_length));
osPiWriteIo(SC64_REG_USB_SCR, SC64_USB_CONTROL_START);
#if USE_OSRAW
osPiRawWriteIo(SC64_REG_USB_DMA_ADDR, SC64_USB_BANK_ADDR(SC64_BANK_ROM, DEBUG_ADDRESS));
osPiRawWriteIo(SC64_REG_USB_DMA_LEN, SC64_USB_LENGTH(transfer_length));
osPiRawWriteIo(SC64_REG_USB_SCR, SC64_USB_CONTROL_START);
#else
osPiWriteIo(SC64_REG_USB_DMA_ADDR, SC64_USB_BANK_ADDR(SC64_BANK_ROM, DEBUG_ADDRESS));
osPiWriteIo(SC64_REG_USB_DMA_LEN, SC64_USB_LENGTH(transfer_length));
osPiWriteIo(SC64_REG_USB_SCR, SC64_USB_CONTROL_START);
#endif
#endif
// Wait for transfer to complete if there's more data to send
@@ -1493,19 +1644,24 @@ static u32 usb_sc64_poll(void)
}
// Load data from FIFO to buffer in RDRAM
#if USE_OSRAW
osPiRawStartDma(OS_READ, SC64_MEM_USB_FIFO_BASE, usb_buffer, dma_length);
#ifdef LIBDRAGON
dma_read(usb_buffer, SC64_MEM_USB_FIFO_BASE, dma_length);
dma_write(usb_buffer, sdram_address, dma_length);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_READ, SC64_MEM_USB_FIFO_BASE, usb_buffer, dma_length, &dmaMessageQ);
osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
#endif
#if USE_OSRAW
osPiRawStartDma(OS_READ, SC64_MEM_USB_FIFO_BASE, usb_buffer, dma_length);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_READ, SC64_MEM_USB_FIFO_BASE, usb_buffer, dma_length, &dmaMessageQ);
osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
#endif
// Copy data from RDRAM to SDRAM
#if USE_OSRAW
osPiRawStartDma(OS_WRITE, sdram_address, usb_buffer, dma_length);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_WRITE, sdram_address, usb_buffer, dma_length, &dmaMessageQ);
osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
// Copy data from RDRAM to SDRAM
#if USE_OSRAW
osPiRawStartDma(OS_WRITE, sdram_address, usb_buffer, dma_length);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_WRITE, sdram_address, usb_buffer, dma_length, &dmaMessageQ);
osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
#endif
#endif
// Update tracking variables
@@ -1536,13 +1692,18 @@ static void usb_sc64_read(void)
u32 sdram_address = SC64_SDRAM_BASE + DEBUG_ADDRESS + usb_readblock;
// Set up DMA transfer between RDRAM and the PI
#if USE_OSRAW
osPiRawStartDma(OS_READ, sdram_address, usb_buffer, BUFFER_SIZE);
#ifdef LIBDRAGON
dma_read(usb_buffer, sdram_address, BUFFER_SIZE);
data_cache_hit_invalidate(usb_buffer, BUFFER_SIZE);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_READ, sdram_address, usb_buffer, BUFFER_SIZE, &dmaMessageQ);
osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
#endif
#if USE_OSRAW
osPiRawStartDma(OS_READ, sdram_address, usb_buffer, BUFFER_SIZE);
#else
osPiStartDma(&dmaIOMessageBuf, OS_MESG_PRI_NORMAL, OS_READ, sdram_address, usb_buffer, BUFFER_SIZE, &dmaMessageQ);
osRecvMesg(&dmaMessageQ, NULL, OS_MESG_BLOCK);
#endif
// Invalidate cache
osInvalDCache(usb_buffer, BUFFER_SIZE);
}
// Invalidate cache
osInvalDCache(usb_buffer, BUFFER_SIZE);
#endif
}
+7 -5
View File
@@ -4,11 +4,14 @@
/*********************************
DataType macros
*********************************/
// UNCOMMENT THE #DEFINE IF USING LIBDRAGON
//#define LIBDRAGON
// Settings
#define USE_OSRAW 0 // Use if you're doing USB operations without the PI Manager
#define DEBUG_ADDRESS_SIZE 1*1024*1024 // Max size of USB I/O. The bigger this value, the more ROM you lose!
#define USE_OSRAW 0 // Use if you're doing USB operations without the PI Manager (libultra only)
#define DEBUG_ADDRESS_SIZE 8*1024*1024 // Max size of USB I/O. The bigger this value, the more ROM you lose!
// Cart definitions
#define CART_NONE 0
#define CART_64DRIVE 1
@@ -27,7 +30,6 @@
extern int usb_readblock;
/*********************************
Convenience macros
*********************************/
@@ -78,7 +80,7 @@
@return The data header, or 0
==============================*/
extern u32 usb_poll();
extern unsigned int usb_poll();
/*==============================