Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Fazana
2021-09-13 11:41:09 +01:00
9 changed files with 103 additions and 47 deletions

View File

@@ -71,6 +71,8 @@ COMPRESS ?= rnc1
$(eval $(call validate-option,COMPRESS,mio0 yay0 gzip rnc1 rnc2 uncomp))
ifeq ($(COMPRESS),gzip)
DEFINES += GZIP=1
LIBZRULE := $(BUILD_DIR)/libz.a
LIBZLINK := -lz
else ifeq ($(COMPRESS),rnc1)
DEFINES += RNC1=1
else ifeq ($(COMPRESS),rnc2)
@@ -240,6 +242,8 @@ endif
GODDARD ?= 0
$(eval $(call validate-option,GODDARD,0 1))
ifeq ($(GODDARD),1)
GODDARDRULE := $(BUILD_DIR)/libgoddard.a
GODDARDLINK := -lgoddard
DEFINES += GODDARD=1
endif
@@ -461,6 +465,7 @@ FILESIZER := $(TOOLS_DIR)/filesizer
N64CKSUM := $(TOOLS_DIR)/n64cksum
N64GRAPHICS := $(TOOLS_DIR)/n64graphics
N64GRAPHICS_CI := $(TOOLS_DIR)/n64graphics_ci
BINPNG := $(TOOLS_DIR)/BinPNG.py
TEXTCONV := $(TOOLS_DIR)/textconv
AIFF_EXTRACT_CODEBOOK := $(TOOLS_DIR)/aiff_extract_codebook
VADPCM_ENC := $(TOOLS_DIR)/vadpcm_enc
@@ -607,14 +612,14 @@ $(BUILD_DIR)/%.inc.c: %.png
$(V)$(N64GRAPHICS) -s $(TEXTURE_ENCODING) -i $@ -g $< -f $(lastword ,$(subst ., ,$(basename $<)))
# Color Index CI8
$(BUILD_DIR)/%.ci8: %.ci8.png
$(call print,Converting:,$<,$@)
$(V)$(N64GRAPHICS_CI) -i $@ -g $< -f ci8
$(BUILD_DIR)/%.ci8.inc.c: %.ci8.png
$(call print,Converting CI:,$<,$@)
$(V)$(BINPNG) $< $@ 8
# Color Index CI4
$(BUILD_DIR)/%.ci4: %.ci4.png
$(call print,Converting:,$<,$@)
$(V)$(N64GRAPHICS_CI) -i $@ -g $< -f ci4
$(BUILD_DIR)/%.ci4.inc.c: %.ci4.png
$(call print,Converting CI:,$<,$@)
$(V)$(BINPNG) $< $@ 4
#==============================================================================#
@@ -797,9 +802,9 @@ $(BUILD_DIR)/goddard.txt: $(BUILD_DIR)/sm64_prelim.elf
$(V)python3 tools/getGoddardSize.py $(BUILD_DIR)/sm64_prelim.map $(VERSION)
# Link SM64 ELF file
$(ELF): $(BUILD_DIR)/sm64_prelim.elf $(O_FILES) $(YAY0_OBJ_FILES) $(SEG_FILES) $(BUILD_DIR)/$(LD_SCRIPT) undefined_syms.txt $(BUILD_DIR)/libz.a $(BUILD_DIR)/libgoddard.a
$(ELF): $(BUILD_DIR)/sm64_prelim.elf $(O_FILES) $(YAY0_OBJ_FILES) $(SEG_FILES) $(BUILD_DIR)/$(LD_SCRIPT) undefined_syms.txt $(LIBZRULE) $(GODDARDRULE)
@$(PRINT) "$(GREEN)Linking ELF file: $(BLUE)$@ $(NO_COL)\n"
$(V)$(LD) --gc-sections -L $(BUILD_DIR) -T undefined_syms.txt -T $(BUILD_DIR)/$(LD_SCRIPT) -T goddard.txt -Map $(BUILD_DIR)/sm64.$(VERSION).map --no-check-sections $(addprefix -R ,$(SEG_FILES)) -o $@ $(O_FILES) -L$(LIBS_DIR) -l$(ULTRALIB) -Llib $(LINK_LIBRARIES) -u sprintf -u osMapTLB -Llib/gcclib/$(LIBGCCDIR) -lgcc
$(V)$(LD) --gc-sections -L $(BUILD_DIR) -T undefined_syms.txt -T $(BUILD_DIR)/$(LD_SCRIPT) -T goddard.txt -Map $(BUILD_DIR)/sm64.$(VERSION).map --no-check-sections $(addprefix -R ,$(SEG_FILES)) -o $@ $(O_FILES) -L$(LIBS_DIR) -l$(ULTRALIB) -Llib -Llib/gcclib/$(LIBGCCDIR) -lgcc -lnustd -lhvqm2 $(LIBZLINK) $(GODDARDLINK) -u sprintf -u osMapTLB
# Build ROM
$(ROM): $(ELF)

View File

@@ -112,6 +112,12 @@ This is a fork of the ultrasm64 repo by CrashOveride which includes the followin
Requirements are the same as regular SM64, however a GCC MIPS cross compiler is also required. If you're on Debian-like Linux, you can use the ``gcc-mips-linux-gnu`` package. The toolchain that comes with my SDK is also supported.
## Additional Prerequisites
BinPNG (the CI texture converter) requires some python3 dependencies. Use pip to install them.
``pip install pypng bitstring``
## UNFLoader support
The repository supports UNFLoader for debugging.
@@ -119,6 +125,8 @@ To build with UNF, run make with ``UNF=1``.
Further instructions can be found at the [official repository](https://github.com/buu342/N64-UNFLoader)
**NOTE: Closing the UNFLoader window will result in your game eventually hanging due to lacking a USB device to send messages to, so beware of that**
## Multi-Save support
The repository supports SRAM in addition to EEPROM. The standard save data functions are #ifdef'd to accommedate this.
To build with SRAM support, run make with ``SAVETYPE=sram``.

View File

@@ -150,7 +150,6 @@ SECTIONS
BUILD_DIR/src/boot*.o(.text);
BUILD_DIR/src/hvqm*.o(.text);
BUILD_DIR/src/usb*.o(.text);
BUILD_DIR/src/audio*.o(.text);
#ifdef S2DEX_TEXT_ENGINE
lib/libs2d_engine.a:*(.text);
@@ -169,7 +168,6 @@ SECTIONS
/* data */
BUILD_DIR/src/boot*.o(.*data*);
BUILD_DIR/src/usb*.o(.*data*);
BUILD_DIR/src/audio*.o(.*data*);
#ifdef S2DEX_TEXT_ENGINE
lib/libs2d_engine.a:*(.*data*);
@@ -187,7 +185,6 @@ SECTIONS
/* rodata */
BUILD_DIR/src/boot*.o(.rodata*);
BUILD_DIR/src/usb*.o(.rodata*);
BUILD_DIR/src/audio*.o(.rodata*);
#ifdef S2DEX_TEXT_ENGINE
lib/libs2d_engine.a:*(.rodata*);
@@ -211,7 +208,6 @@ SECTIONS
{
BUILD_DIR/src/boot*.o(.*bss*);
BUILD_DIR/src/hvqm*.o(.*bss*);
BUILD_DIR/src/usb*.o(.*bss*);
BUILD_DIR/src/audio*.o(.*bss*);
#ifdef S2DEX_TEXT_ENGINE
lib/libs2d_engine.a:*(.*bss*);
@@ -237,19 +233,23 @@ SECTIONS
{
BUILD_DIR/src/game*.o(.text);
BUILD_DIR/src/engine*.o(.text);
BUILD_DIR/src/usb*.o(.text);
/* data */
BUILD_DIR/src/game*.o(.*data*);
BUILD_DIR/src/engine*.o(.data*);
BUILD_DIR/src/engine*.o(.sdata*);
BUILD_DIR/src/usb*.o(.*data*);
/* rodata */
BUILD_DIR/src/game*.o(.rodata*);
BUILD_DIR/src/engine*.o(.rodata*);
BUILD_DIR/src/usb*.o(.rodata*);
}
END_SEG(engine)
BEGIN_NOLOAD(engine)
{
BUILD_DIR/src/game*.o(.*bss*);
BUILD_DIR/src/engine*.o(.bss*);
BUILD_DIR/src/usb*.o(.*bss*);
. = ALIGN(0x40);
}
END_NOLOAD(engine)

View File

@@ -336,6 +336,10 @@ void thread3_main(UNUSED void *arg) {
crash_screen_init();
#endif
#ifdef UNF
debug_initialize();
#endif
#ifdef DEBUG
osSyncPrintf("Super Mario 64\n");
osSyncPrintf("Built by: %s\n", __username__);
@@ -485,9 +489,6 @@ void thread1_idle(UNUSED void *arg) {
osViSetSpecialFeatures(OS_VI_DITHER_FILTER_ON);
osViSetSpecialFeatures(OS_VI_GAMMA_OFF);
osCreatePiManager(OS_PRIORITY_PIMGR, &gPIMesgQueue, gPIMesgBuf, ARRAY_COUNT(gPIMesgBuf));
#ifdef UNF
debug_initialize();
#endif
create_thread(&gMainThread, 3, thread3_main, NULL, gThread3Stack + 0x2000, 100);
osStartThread(&gMainThread);

View File

@@ -22,10 +22,6 @@
#ifdef HVQM
#include <hvqm/hvqm.h>
#endif
#ifdef UNF
#include "usb/usb.h"
#include "usb/debug.h"
#endif
#ifdef SRAM
#include "sram.h"
#endif

View File

@@ -449,7 +449,11 @@ https://github.com/buu342/N64-UNFLoader
==============================*/
void _debug_assert(const char* expression, const char* file, int line)
{
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
volatile char crash;
// Set the assert data
assert_expr = expression;
assert_line = line;
@@ -460,8 +464,9 @@ https://github.com/buu342/N64-UNFLoader
debug_printf("Assertion failed in file '%s', line %d.\n", assert_file, assert_line);
#endif
// Intentionally cause a null pointer exception
*((char*)(NULL)) = 0;
// Intentionally cause a TLB exception on load/instruction fetch
crash = *(volatile char *)1;
#pragma GCC diagnostic pop
}

View File

@@ -385,20 +385,7 @@ static void usb_findcart()
// Check if we have an EverDrive
if (buff == ED7_VERSION || buff == ED3_VERSION)
{
// Initialize the PI
IO_WRITE(PI_STATUS_REG, 3);
IO_WRITE(PI_BSD_DOM1_LAT_REG, 0x40);
IO_WRITE(PI_BSD_DOM1_PWD_REG, 0x12);
IO_WRITE(PI_BSD_DOM1_PGS_REG, 0x07);
IO_WRITE(PI_BSD_DOM1_RLS_REG, 0x03);
IO_WRITE(PI_BSD_DOM2_LAT_REG, 0x05);
IO_WRITE(PI_BSD_DOM2_PWD_REG, 0x0C);
IO_WRITE(PI_BSD_DOM2_PGS_REG, 0x0D);
IO_WRITE(PI_BSD_DOM2_RLS_REG, 0x02);
IO_WRITE(PI_BSD_DOM1_LAT_REG, 0x04);
IO_WRITE(PI_BSD_DOM1_PWD_REG, 0x0C);
{
// Set the USB mode
usb_everdrive_writereg(ED_REG_SYSCFG, 0);
usb_everdrive_writereg(ED_REG_USBCFG, ED_USBMODE_RDNOP);
@@ -453,7 +440,7 @@ void usb_write(int datatype, const void* data, int size)
@return The data header, or 0
==============================*/
u32 usb_poll()
unsigned long usb_poll()
{
// If no debug cart exists, stop
if (usb_cart == CART_NONE)
@@ -604,7 +591,7 @@ static s8 usb_64drive_wait()
#endif
// Took too long, abort
if((timeout++) > 1000000)
if((timeout++) > 10000)
return -1;
}
while((ret >> 8) & D64_CI_BUSY);
@@ -642,9 +629,10 @@ static void usb_64drive_setwritable(u8 enable)
Waits for the 64Drive's USB to be idle
==============================*/
static void usb_64drive_waitidle()
static int usb_64drive_waitidle()
{
u32 status __attribute__((aligned(8)));
u32 timeout = 0;
do
{
#ifdef LIBDRAGON
@@ -657,8 +645,11 @@ static void usb_64drive_waitidle()
#endif
#endif
status = (status >> 4) & D64_USB_BUSY;
if (timeout++ > 128)
return 0;
}
while(status != D64_USB_IDLE);
return 1;
}
@@ -724,7 +715,8 @@ static void usb_64drive_write(int datatype, const void* data, int size)
int read = 0;
// Spin until the write buffer is free and then set the cartridge to write mode
usb_64drive_waitidle();
if (!usb_64drive_waitidle())
return;
usb_64drive_setwritable(TRUE);
// Write data to SDRAM until we've finished
@@ -749,7 +741,11 @@ static void usb_64drive_write(int datatype, const void* data, int size)
}
// Spin until the write buffer is free
usb_64drive_waitidle();
if (!usb_64drive_waitidle())
{
usb_64drive_setwritable(FALSE);
return;
}
// Set up DMA transfer between RDRAM and the PI
#ifdef LIBDRAGON
@@ -1062,7 +1058,8 @@ static void usb_everdrive_writedata(void* buff, u32 pi_address, u32 len)
static void usb_everdrive_writereg(u64 reg, u32 value)
{
usb_everdrive_writedata(&value, ED_GET_REGADD(reg), sizeof(u32));
u32 val __attribute__((aligned(8))) = value;
usb_everdrive_writedata(&val, ED_GET_REGADD(reg), sizeof(u32));
}
@@ -1073,12 +1070,15 @@ static void usb_everdrive_writereg(u64 reg, u32 value)
static void usb_everdrive_usbbusy()
{
u32 timeout = 0;
u32 val __attribute__((aligned(8)));
do
do
{
usb_everdrive_readreg(ED_REG_USBCFG, &val);
}
while ((val & ED_USBSTAT_ACT) != 0);
if (timeout++ != 8192)
continue;
usb_everdrive_writereg(ED_REG_USBCFG, ED_USBMODE_RDNOP);
} while ((val & ED_USBSTAT_ACT) != 0);
}
@@ -1690,4 +1690,4 @@ static void usb_sc64_read(void)
// Invalidate cache
osInvalDCache(usb_buffer, BUFFER_SIZE);
#endif
}
}

View File

@@ -80,7 +80,7 @@
@return The data header, or 0
==============================*/
extern unsigned int usb_poll();
extern unsigned long usb_poll();
/*==============================

41
tools/BinPNG.py Executable file
View File

@@ -0,0 +1,41 @@
#!/usr/bin/env python3
import struct
import png
import math
from bitstring import *
import sys
#convert png to bin
def MakeCI(file,Bpp):
r = png.Reader(file)
re = r.read()
Pal = re[3]['palette']
Pbin = []
shifts = [3,3,3,7]
for p in Pal:
b = [a>>s for a,s in zip(p,shifts)]
if len(p)==4:
b = pack('3*uint:5,uint:1',*b)
else:
b = pack('3*uint:5,uint:1',*b,1)
Pbin.append(b.bytes)
bin = []
for p in re[2]:
for w in range(0,re[0],(8//Bpp)):
b = p[w:w+(8//Bpp)]
b = pack('%d*uint:%d'%((8//Bpp),Bpp),*b)
bin.append(b.bytes)
return [bin,Pbin]
if __name__=='__main__':
[texture,palette] = MakeCI(sys.argv[1],int(sys.argv[3]))
pname = sys.argv[2].split('.')
pname.insert(2,'pal')
pname = pname[:3]
pname = '.'.join(pname)
p = open(pname,'w')
t = open(sys.argv[2],'w')
[t.write('0x{:02X},'.format(tex[0])) for tex in texture]
[p.write('0x{:02X},0x{:02X},'.format(pal[0],pal[1])) for pal in palette]
t.close()
p.close()