Add (BROKEN) UNFLoader

This commit is contained in:
CrashOveride95
2020-12-09 16:38:26 -05:00
parent d5106362b9
commit 5b97e1072a
14 changed files with 2894 additions and 1 deletions

View File

@@ -136,6 +136,17 @@ ifeq ($(filter $(TARGET_STRING), sm64.jp.f3d_old sm64.us.f3d_old sm64.eu.f3d_new
COMPARE := 0
endif
# UNF - whether to use UNFLoader flashcart library
# 1 - includes code in ROM
# 0 - does not
UNF ?= 0
$(eval $(call validate-option,UNF,0 1))
ifeq ($(UNF),1)
DEFINES += UNF=1
endif
# Whether to hide commands or not
VERBOSE ?= 0
ifeq ($(VERBOSE),0)
@@ -219,7 +230,7 @@ ACTOR_DIR := actors
LEVEL_DIRS := $(patsubst levels/%,%,$(dir $(wildcard levels/*/header.h)))
# Directories containing source files
SRC_DIRS := src src/engine src/game src/audio src/menu src/buffers actors levels bin data assets asm lib sound
SRC_DIRS := src src/usb src/engine src/game src/audio src/menu src/buffers actors levels bin data assets asm lib sound
BIN_DIRS := bin bin/$(VERSION)
# File dependencies and variables for specific files
@@ -464,6 +475,11 @@ else
endif
endif
$(BUILD_DIR)/src/usb/usb.o: OPT_FLAGS := -O0
$(BUILD_DIR)/src/usb/usb.o: CFLAGS += -Wno-unused-variable -Wno-sign-compare -Wno-unused-function
$(BUILD_DIR)/src/usb/debug.o: OPT_FLAGS := -O0
$(BUILD_DIR)/src/usb/debug.o: CFLAGS += -Wno-unused-parameter -Wno-maybe-uninitialized
ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(GODDARD_SRC_DIRS) $(ULTRA_SRC_DIRS) $(ULTRA_BIN_DIRS) $(BIN_DIRS) $(TEXTURE_DIRS) $(TEXT_DIRS) $(SOUND_SAMPLE_DIRS) $(addprefix levels/,$(LEVEL_DIRS)) rsp include) $(YAY0_DIR) $(addprefix $(YAY0_DIR)/,$(VERSION)) $(SOUND_BIN_DIR) $(SOUND_BIN_DIR)/sequences/$(VERSION)
# Make sure build directory exists before compiling anything

View File

@@ -6,5 +6,9 @@
void *memcpy(void *dst, const void *src, size_t size);
size_t strlen(const char *str);
char *strchr(const char *str, s32 ch);
int memcmp(const void *buf1, const void *buf2, size_t count);
void *memset(void* dst, int c, size_t count);
char *strcat(char *str1, const char *str2);
int strncmp(const char *str1, const char *str2, int n);
#endif

14
sm64.ld
View File

@@ -116,6 +116,9 @@ SECTIONS
BUILD_DIR/asm/entry.o(.text);
BUILD_DIR/src/game*.o(.text);
#ifdef UNF
BUILD_DIR/src/usb*.o(.text);
#endif
BUILD_DIR/src/audio*.o(.text);
BUILD_DIR/asm/llmuldiv_gcc.o(.text);
BUILD_DIR/asm/slidec.o(.text);
@@ -129,6 +132,10 @@ SECTIONS
/* data */
BUILD_DIR/src/game*.o(.data*);
BUILD_DIR/src/game*.o(.sdata*);
#ifdef UNF
BUILD_DIR/src/usb*.o(.data*);
BUILD_DIR/src/usb*.o(.sdata*);
#endif
BUILD_DIR/src/audio*.o(.data*);
BUILD_DIR/src/audio*.o(.sdata*);
@@ -141,6 +148,9 @@ SECTIONS
/* rodata */
BUILD_DIR/src/game*.o(.rodata*);
#ifdef UNF
BUILD_DIR/src/usb*.o(.rodata*);
#endif
BUILD_DIR/src/audio*.o(.rodata*);
*/libultra_rom.a:*.o(.rodata*);
@@ -154,6 +164,8 @@ SECTIONS
{
BUILD_DIR/src/game*.o(.bss*);
BUILD_DIR/src/game*.o(.sbss*);
BUILD_DIR/src/usb*.o(.bss*);
BUILD_DIR/src/usb*.o(.sbss*);
BUILD_DIR/src/audio*.o(.bss*);
BUILD_DIR/src/audio*.o(.sbss*);
@@ -355,11 +367,13 @@ SECTIONS
BUILD_DIR/data/capcom.o(.data);
}
END_SEG(capcom)
#if 0
BEGIN_SEG(sein, __romPos) SUBALIGN(2)
{
BUILD_DIR/data/sein.o(.data);
}
END_SEG(sein)
#endif
/* Discard everything not specifically mentioned above. */
/DISCARD/ :
{

View File

@@ -19,6 +19,9 @@
#include "segment2.h"
#include "segment_symbols.h"
#include "rumble_init.h"
#include "hvqm.h"
#include "usb/usb.h"
#include "usb/debug.h"
#include <prevent_bss_reordering.h>
// FIXME: I'm not sure all of these variables belong in this file, but I don't
@@ -601,6 +604,9 @@ void thread5_game_loop(UNUSED void *arg) {
setup_game_memory();
#if ENABLE_RUMBLE
init_rumble_pak_scheduler_queue();
#endif
#ifdef UNF
debug_initialize();
#endif
init_controllers();
#if ENABLE_RUMBLE

View File

@@ -46,6 +46,7 @@ void tkStart(tkRewindProc rewind, u32 samples_per_sec);
void tkPushVideoframe(void *vaddr, u32 *statP, u64 disptime);
u64 tkGetTime(void);
void tkStop(void);
void createHvqmThread(void);

View File

@@ -12,6 +12,8 @@
#include "segments.h"
#include "main.h"
#include "rumble_init.h"
#include "usb/usb.h"
#include "usb/debug.h"
// Message IDs
#define MESG_SP_COMPLETE 100

914
src/usb/debug.c Normal file

File diff suppressed because it is too large Load Diff

148
src/usb/debug.h Normal file
View File

@@ -0,0 +1,148 @@
#ifndef UNFL_DEBUG_H
#define UNFL_DEBUG_H
/*********************************
Settings macros
*********************************/
// 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 1 // Create a fault detection thread
#define OVERWRITE_OSPRINT 0 // Replaces osSyncPrintf calls with debug_printf
#define MAX_COMMANDS 25 // The max amount of user defined commands possible
// Fault thread definitions
#define FAULT_THREAD_ID 13
#define FAULT_THREAD_PRI 125
#define FAULT_THREAD_STACK 0x2000
// USB thread definitions
#define USB_THREAD_ID 14
#define USB_THREAD_PRI 126
#define USB_THREAD_STACK 0x2000
/*********************************
Debug Functions
*********************************/
#if DEBUG_MODE
/*==============================
debug_initialize
Initializes the debug and USB library.
==============================*/
extern void debug_initialize();
/*==============================
debug_printf
Prints a formatted message to the developer's command prompt.
Supports up to 256 characters.
@param A string to print
@param variadic arguments to print as well
==============================*/
extern void debug_printf(const char* message, ...);
/*==============================
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
==============================*/
extern void debug_screenshot(int size, int w, int h);
/*==============================
debug_assert
Halts the program if the expression fails.
@param The expression to test
==============================*/
#define debug_assert(expr) (expr) ? ((void)0) : _debug_assert(#expr, __FILE__, __LINE__)
/*==============================
debug_pollcommands
Check the USB for incoming commands.
==============================*/
extern void debug_pollcommands();
/*==============================
debug_addcommand
Adds a command for the USB to read.
@param The command name
@param The command description
@param The function pointer to execute
==============================*/
extern void debug_addcommand(char* command, char* description, char*(*execute)());
/*==============================
debug_parsecommand
Stores the next part of the incoming command into the provided buffer.
Make sure the buffer can fit the amount of data from debug_sizecommand!
If you pass NULL, it skips this command.
@param The buffer to store the data in
==============================*/
extern void debug_parsecommand(void* buffer);
/*==============================
debug_sizecommand
Returns the size of the data from this part of the command.
@return The size of the data in bytes, or 0
==============================*/
extern int debug_sizecommand();
/*==============================
debug_printcommands
Prints a list of commands to the developer's command prompt.
==============================*/
extern void debug_printcommands();
// Ignore this, use the macro instead
extern void _debug_assert(const char* expression, const char* file, int line);
// Include usb.h automatically
#include "usb.h"
#else
// Overwrite library functions with useless macros if debug mode is disabled
#define debug_initialize()
#define debug_printf(a, __VA_ARGS__)
#define debug_screenshot(a, b, c)
#define debug_assert(a)
#define debug_pollcommands()
#define debug_addcommand(a, b, c)
#define debug_parsecommand() NULL
#define debug_sizecommand() 0
#define debug_printcommands()
#define usb_initialize() 0
#define usb_getcart() 0
#define usb_write(a, b, c)
#define usb_poll() 0
#define usb_read(a, b)
#define usb_skip(a)
#define usb_rewind(a)
#define usb_purge()
#endif
#endif

34
src/usb/memcmp.c Executable file
View File

@@ -0,0 +1,34 @@
/*
=============================================================================
Copyright (C) 1997-1999 NINTENDO Co.,Ltd.
$RCSfile: memcmp.c,v $
$Revision: 1.1 $
$Date: 1999/04/14 07:18:40 $
=============================================================================
function name: memcmp
-----------------------------------------------------------------------------
format: #include <string.h>
int memcmp(const void *buf1, const void *buf2, size_t count)
argument: buf1 pointer to be compared
buf2 pointer to be compared
count the number of bytes to be compared
return value: if less than 0 buf1 is smaller than buf2
if 0 buf1 is equal to buf2
if more than 0 buf1 is larger than buf2
explanation: compares the contents of pointer buf1 and pointer buf2 by the number of count bytes
-----------------------------------------------------------------------------
*/
#include <string.h>
int memcmp(const void *buf1, const void *buf2, size_t count)
{
char *b1 = (char *)buf1, *b2 = (char *)buf2;
while(count) {
if (*b1 != *b2) return *b1 - *b2;
b1 ++;
b2 ++;
count--;
}
return 0;
}

27
src/usb/memset.c Executable file
View File

@@ -0,0 +1,27 @@
/*
=============================================================================
Copyright (C) 1997-1999 NINTENDO Co.,Ltd.
$RCSfile: memset.c,v $
$Revision: 1.1 $
$Date: 1999/04/14 07:18:41 $
=============================================================================
function name: memset
-----------------------------------------------------------------------------
format: #include <string.h>
void *memset(void* dst, int c, size_t count);
argument: dst pointer of destination to be written
c byte data to be written
count the number of characters to be written
return value: pointer of destination to be written, dst
explanation: writes byte data c from the pointer dst indicates by the amount of count
-----------------------------------------------------------------------------
*/
#include <string.h>
void *memset(void* dst, int c, size_t count)
{
char *p = (char *)dst;
while(count--) *p++ = c;
return dst;
}

29
src/usb/strcat.c Executable file
View File

@@ -0,0 +1,29 @@
/*
=============================================================================
Copyright (C) 1997-1999 NINTENDO Co.,Ltd.
$RCSfile: strcat.c,v $
$Revision: 1.1 $
$Date: 1999/04/14 07:18:41 $
=============================================================================
function name: strcat
-----------------------------------------------------------------------------
format: #include <string.h>
char *strcat(char *str1, const char *str2);
argument: str1 character string buffer to be added
str2 character string buffer to add
return value: pointer of str1
explanation: adds character string, str2 to the end of character string, str1
-----------------------------------------------------------------------------
*/
#include <string.h>
char *strcat(char *str1, const char *str2)
{
char *p;
p = str1;
while(*p) p++;
while(*str2) *p++ = *str2++;
*p = '\0';
return str1;
}

34
src/usb/strncmp.c Executable file
View File

@@ -0,0 +1,34 @@
/*
=============================================================================
Copyright (C) 1997-1999 NINTENDO Co.,Ltd.
$RCSfile: strncmp.c,v $
$Revision: 1.1 $
$Date: 1999/04/14 07:18:42 $
=============================================================================
function name: strncmp
-----------------------------------------------------------------------------
format : #include <string.h>
int strncmp(const char *str1, const char *str2, int n)
argument: str1 character string buffer to be compared
str2 character string buffer to be compared
n character number to be compared
return value: if less than 0, str1 is smaller than str2
if 0 str1 is equal to str2
if more than 0, str1 is larger than str2
explanation: compares character string, str1 with character string, str2 by
n character
-----------------------------------------------------------------------------
*/
#include <string.h>
int strncmp(const char *str1, const char *str2, int n)
{
char c1 = 1,c2;
while(c1 && n--) {
c1=*str1++;
c2=*str2++;
if (c1 != c2) return c1 - c2;
}
return 0;
}

1545
src/usb/usb.c Normal file

File diff suppressed because it is too large Load Diff

119
src/usb/usb.h Normal file
View File

@@ -0,0 +1,119 @@
#ifndef UNFL_USB_H
#define UNFL_USB_H
/*********************************
DataType macros
*********************************/
// 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!
// Cart definitions
#define CART_NONE 0
#define CART_64DRIVE 1
#define CART_EVERDRIVE 2
#define CART_SC64 3
// Data types defintions
#define DATATYPE_TEXT 0x01
#define DATATYPE_RAWBINARY 0x02
#define DATATYPE_HEADER 0x03
#define DATATYPE_SCREENSHOT 0x04
extern int usb_datatype;
extern int usb_datasize;
extern int usb_dataleft;
extern int usb_readblock;
/*********************************
Convenience macros
*********************************/
// Use these to conveniently read the header from usb_poll()
#define USBHEADER_GETTYPE(header) ((header & 0xFF000000) >> 24)
#define USBHEADER_GETSIZE(header) ((header & 0x00FFFFFF))
/*********************************
USB Functions
*********************************/
/*==============================
usb_initialize
Initializes the USB buffers and pointers
@return 1 if the USB initialization was successful, 0 if not
==============================*/
extern char usb_initialize();
/*==============================
usb_getcart
Returns which flashcart is currently connected
@return The CART macro that corresponds to the identified flashcart
==============================*/
extern char usb_getcart();
/*==============================
usb_write
Writes data to the USB.
Will not write if there is data to read from USB
@param The DATATYPE that is being sent
@param A buffer with the data to send
@param The size of the data being sent
==============================*/
extern void usb_write(int datatype, const void* data, int size);
/*==============================
usb_poll
Returns the header of data being received via USB
The first byte contains the data type, the next 3 the number of bytes left to read
@return The data header, or 0
==============================*/
extern u32 usb_poll();
/*==============================
usb_read
Reads bytes from USB into the provided buffer
@param The buffer to put the read data in
@param The number of bytes to read
==============================*/
extern void usb_read(void* buffer, int size);
/*==============================
usb_skip
Skips a USB read by the specified amount of bytes
@param The number of bytes to skip
==============================*/
extern void usb_skip(int nbytes);
/*==============================
usb_rewind
Rewinds a USB read by the specified amount of bytes
@param The number of bytes to rewind
==============================*/
extern void usb_rewind(int nbytes);
/*==============================
usb_purge
Purges the incoming USB data
==============================*/
extern void usb_purge();
#endif