diff --git a/.gitignore b/.gitignore index a32fb12..066f646 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,7 @@ __pycache__/ undefined_funcs_auto.txt undefined_syms_auto.txt + +# qemu-irix compilers +tools/ido5.3_compiler/ +tools/ido7.1_compiler/ diff --git a/Makefile b/Makefile index 60d3152..546326e 100644 --- a/Makefile +++ b/Makefile @@ -42,25 +42,154 @@ CPP := cpp CC = tools/ido_recomp/linux/7.1/cc CC_OLD = tools/ido_recomp/linux/5.3/cc -ASFLAGS = -EB -mtune=vr4300 -march=vr4300 -Iinclude - -# we support Microsoft extensions such as anonymous structs, which the compiler does support but warns for their usage. Surpress the warnings with -woff. -CFLAGS = -G 0 -non_shared -Xfullwarn -Xcpluscomm -Iinclude -Wab,-r4300_mul -D _LANGUAGE_C -D F3DEX_GBI -woff 649,838,712 -mips2 - -LDFLAGS = -T undefined_syms.txt -T undefined_syms_auto.txt -T undefined_funcs_auto.txt -T $(BUILD_DIR)/$(LD_SCRIPT) -Map $(BUILD_DIR)/$(TARGET).map --no-check-sections +MIPS_VERSION := -mips2 OPTFLAGS := -O2 +OBJDUMP_FLAGS := -d -r -z -Mreg-names=32 + ######################## Targets ############################# $(foreach dir,$(SRC_DIRS) $(ASM_DIRS) $(DATA_DIRS) $(COMPRESSED_DIRS) $(MAP_DIRS) $(BGM_DIRS),$(shell mkdir -p build/$(dir))) # Libultra O1 files -build/src/libultra/os/osSendMesg.c.o: OPTFLAGS := -O1 -build/src/libultra/os/osStopThread.c.o: OPTFLAGS := -O1 -build/src/libultra/os/osRecvMesg.c.o: OPTFLAGS := -O1 +build/src/libultra/os/sendmesg.c.o: OPTFLAGS := -O1 +build/src/libultra/os/stopthread.c.o: OPTFLAGS := -O1 +build/src/libultra/os/recvmesg.c.o: OPTFLAGS := -O1 +build/src/libultra/os/destroythread.c.o: OPTFLAGS := -O1 +build/src/libultra/os/dequeuethread.c.o: OPTFLAGS := -O1 +build/src/libultra/os/createthread.c.o: OPTFLAGS := -O1 +build/src/libultra/os/virtualtophysical.c.o: OPTFLAGS := -O1 +build/src/libultra/os/initialize.c.o: OPTFLAGS := -O1 +build/src/libultra/os/epilinkhandle.c.o: OPTFLAGS := -O1 +build/src/libultra/os/getmemsize.c.o: OPTFLAGS := -O1 +build/src/libultra/os/seteventmesg.c.o: OPTFLAGS := -O1 +build/src/libultra/os/createmesgqueue.c.o: OPTFLAGS := -O1 +build/src/libultra/os/jammesg.c.o: OPTFLAGS := -O1 +build/src/libultra/os/setthreadpri.c.o: OPTFLAGS := -O1 +build/src/libultra/os/gettime.c.o: OPTFLAGS := -O1 +build/src/libultra/os/timerintr.c.o: OPTFLAGS := -O1 +build/src/libultra/os/setglobalintmask.c.o: OPTFLAGS := -O1 +build/src/libultra/os/resetglobalintmask.c.o: OPTFLAGS := -O1 +build/src/libultra/os/settime.c.o: OPTFLAGS := -O1 +build/src/libultra/os/yieldthread.c.o: OPTFLAGS := -O1 +build/src/libultra/os/settimer.c.o: OPTFLAGS := -O1 +build/src/libultra/os/startthread.c.o: OPTFLAGS := -O1 +build/src/libultra/os/sethwinterrupt.c.o: OPTFLAGS := -O1 build/src/libultra/io/pigetcmdq.c.o: OPTFLAGS := -O1 build/src/libultra/io/sptask.c.o: OPTFLAGS := -O1 +build/src/libultra/io/controller.c.o: OPTFLAGS := -O1 +build/src/libultra/io/conteeplongread.c.o: OPTFLAGS := -O1 +build/src/libultra/io/viblack.c.o: OPTFLAGS := -O1 +build/src/libultra/io/visetmode.c.o: OPTFLAGS := -O1 +build/src/libultra/io/virepeatline.c.o: OPTFLAGS := -O1 +build/src/libultra/io/pfsisplug.c.o: OPTFLAGS := -O1 +build/src/libultra/io/epidma.c.o: OPTFLAGS := -O1 +build/src/libultra/io/dpctr.c.o: OPTFLAGS := -O1 +build/src/libultra/io/conteeplongwrite.c.o: OPTFLAGS := -O1 +build/src/libultra/io/si.c.o: OPTFLAGS := -O1 +build/src/libultra/io/sp.c.o: OPTFLAGS := -O1 +build/src/libultra/io/viswapbuf.c.o: OPTFLAGS := -O1 +build/src/libultra/io/sptaskyielded.c.o: OPTFLAGS := -O1 +build/src/libultra/io/vi.c.o: OPTFLAGS := -O1 +build/src/libultra/io/visetevent.c.o: OPTFLAGS := -O1 +build/src/libultra/io/aisetnextbuf.c.o: OPTFLAGS := -O1 +build/src/libultra/io/ai.c.o: OPTFLAGS := -O1 +build/src/libultra/io/vigetcurrframebuf.c.o: OPTFLAGS := -O1 +build/src/libultra/io/spsetpc.c.o: OPTFLAGS := -O1 +build/src/libultra/libc/ll.c.o: OPTFLAGS := -O1 +build/src/libultra/libc/ll.c.o: MIPS_VERSION := -mips3 -32 +build/src/libultra/libc/llcvt.c.o: OPTFLAGS := -O1 +build/src/libultra/libc/llcvt.c.o: MIPS_VERSION := -mips3 -32 + +# cheap hack. TODO: Make the override better +build/src/libultra/io/gbpakpower.c.o: OPTFLAGS += -Wo,-loopunroll,0 +build/src/libultra/io/gbpakinit.c.o: OPTFLAGS += -Wo,-loopunroll,0 +build/src/libultra/io/gbpakselectbank.c.o: OPTFLAGS += -Wo,-loopunroll,0 + +# Libultra misc +build/src/libultra/gu/scale.c.o: CC := $(CC_OLD) +build/src/libultra/gu/scale.c.o: OPTFLAGS := -O3 +build/src/libultra/gu/translate.c.o: CC := $(CC_OLD) +build/src/libultra/gu/translate.c.o: OPTFLAGS := -O3 +build/src/libultra/gu/mtxcatf.c.o: CC := $(CC_OLD) +build/src/libultra/gu/mtxcatf.c.o: OPTFLAGS := -O3 +build/src/libultra/gu/mtxcatl.c.o: CC := $(CC_OLD) +build/src/libultra/gu/mtxcatl.c.o: OPTFLAGS := -O3 +build/src/libultra/gu/rotateRPY.c.o: CC := $(CC_OLD) +build/src/libultra/gu/rotateRPY.c.o: OPTFLAGS := -O3 +build/src/libultra/gu/rotate.c.o: CC := $(CC_OLD) +build/src/libultra/gu/rotate.c.o: OPTFLAGS := -O3 +build/src/libultra/gu/ortho.c.o: CC := $(CC_OLD) +build/src/libultra/gu/ortho.c.o: OPTFLAGS := -O3 +build/src/libultra/gu/sinf.c.o: CC := $(CC_OLD) +build/src/libultra/gu/cosf.c.o: CC := $(CC_OLD) +build/src/libultra/gu/random.c.o: CC := $(CC_OLD) +build/src/libultra/libc/xprintf.c.o: CC := $(CC_OLD) +build/src/libultra/libc/xprintf.c.o: OPTFLAGS := -O3 +build/src/libultra/libc/xldtob.c.o: CC := $(CC_OLD) +build/src/libultra/libc/xldtob.c.o: OPTFLAGS := -O3 +build/src/libultra/libc/xlitob.c.o: CC := $(CC_OLD) +build/src/libultra/libc/xlitob.c.o: OPTFLAGS := -O3 +build/src/libultra/libc/string.c.o: CC := $(CC_OLD) +build/src/libultra/libc/string.c.o: OPTFLAGS := -O3 +build/src/libultra/io/controller.c.o: CC := $(CC_OLD) +build/src/libultra/io/contreaddata.c.o: CC := $(CC_OLD) +build/src/libultra/io/devmgr.c.o: CC := $(CC_OLD) +build/src/libultra/os/initialize.c.o: CC := $(CC_OLD) +build/src/libultra/io/pfsgetstatus.c.o: CC := $(CC_OLD) +build/src/libultra/io/epiread.c.o: CC := $(CC_OLD) +build/src/libultra/al/reverb.c.o: CC := $(CC_OLD) +build/src/libultra/al/bnkf.c.o: CC := $(CC_OLD) +build/src/libultra/al/bnkf.c.o: OPTFLAGS := -O3 +build/src/libultra/al/load.c.o: CC := $(CC_OLD) +build/src/libultra/al/load.c.o: OPTFLAGS := -O3 +build/src/libultra/al/synthesizer.c.o: CC := $(CC_OLD) +build/src/libultra/al/drvrNew.c.o: CC := $(CC_OLD) +build/src/libultra/al/mainbus.c.o: CC := $(CC_OLD) +build/src/libultra/al/mainbus.c.o: OPTFLAGS := -O3 +build/src/libultra/al/auxbus.c.o: CC := $(CC_OLD) +build/src/libultra/al/auxbus.c.o: OPTFLAGS := -O3 +build/src/libultra/al/env.c.o: CC := $(CC_OLD) +build/src/libultra/al/resample.c.o: CC := $(CC_OLD) +build/src/libultra/al/resample.c.o: OPTFLAGS := -O3 +build/src/libultra/al/save.c.o: CC := $(CC_OLD) +build/src/libultra/al/heapalloc.c.o: CC := $(CC_OLD) +build/src/libultra/gu/mtxutil.c.o: CC := $(CC_OLD) +build/src/libultra/gu/mtxutil.c.o: OPTFLAGS := -O3 +build/src/libultra/io/pfsisplug.c.o: CC := $(CC_OLD) +build/src/libultra/io/conteepprobe.c.o: CC := $(CC_OLD) +build/src/libultra/io/conteepwrite.c.o: CC := $(CC_OLD) +build/src/libultra/io/conteepread.c.o: CC := $(CC_OLD) +build/src/libultra/io/contpfs.c.o: CC := $(CC_OLD) +build/src/libultra/io/viswapcontext.c.o: CC := $(CC_OLD) +build/src/libultra/io/contramwrite.c.o: CC := $(CC_OLD) +build/src/libultra/io/contramread.c.o: CC := $(CC_OLD) +build/src/libultra/io/crc.c.o: CC := $(CC_OLD) +build/src/libultra/libc/ldiv.c.o: CC := $(CC_OLD) +build/src/libultra/io/vimgr.c.o: CC := $(CC_OLD) +build/src/libultra/io/visetxscale.c.o: CC := $(CC_OLD) +build/src/libultra/io/visetxscale.c.o: OPTFLAGS := -O1 +build/src/libultra/io/visetyscale.c.o: CC := $(CC_OLD) +build/src/libultra/io/visetyscale.c.o: OPTFLAGS := -O1 +build/src/libultra/al/synallocfx.c.o: CC := $(CC_OLD) +build/src/libultra/al/synallocfx.c.o: OPTFLAGS := -O3 + +build/src/libultra/io/gbpakcheckconnector.c.o: CC := $(CC_OLD) +build/src/libultra/io/gbpakreadid.c.o: CC := $(CC_OLD) +build/src/libultra/io/gbpakreadwrite.c.o: CC := $(CC_OLD) +build/src/libultra/io/gbpakselectbank.c.o: CC := $(CC_OLD) + +######################## Flags ############################# + +ASFLAGS = -EB -mtune=vr4300 -march=vr4300 -Iinclude -Iinclude/PR -Iinclude/audio -32 + +# we support Microsoft extensions such as anonymous structs, which the compiler does support but warns for their usage. Surpress the warnings with -woff. +CFLAGS = -G 0 -non_shared -Xfullwarn -Xcpluscomm -Iinclude -Iinclude/PR -Iinclude/audio -Wab,-r4300_mul -D_LANGUAGE_C -DF3DEX_GBI -DNDEBUG -woff 649,838,712 $(MIPS_VERSION) + +LDFLAGS = -T undefined_syms.txt -T undefined_syms_auto.txt -T undefined_funcs_auto.txt -T $(BUILD_DIR)/$(LD_SCRIPT) -Map $(BUILD_DIR)/$(TARGET).map --no-check-sections + +######################## Build ############################# default: all @@ -96,6 +225,16 @@ $(BUILD_DIR)/$(TARGET).elf: $(O_FILES) $(BUILD_DIR)/$(LD_SCRIPT) $(BUILD_DIR)/%.c.o: %.c $(CC) -c $(CFLAGS) $(OPTFLAGS) -o $@ $^ +$(BUILD_DIR)/src/libultra/libc/ll.c.o: src/libultra/libc/ll.c + $(CC) -c $(CFLAGS) $(OPTFLAGS) -o $@ $^ + python3 tools/set_o32abi_bit.py $@ + @$(OBJDUMP) $(OBJDUMP_FLAGS) $@ > $(@:.o=.s) + +$(BUILD_DIR)/src/libultra/libc/llcvt.c.o: src/libultra/libc/llcvt.c + $(CC) -c $(CFLAGS) $(OPTFLAGS) -o $@ $^ + python3 tools/set_o32abi_bit.py $@ + @$(OBJDUMP) $(OBJDUMP_FLAGS) $@ > $(@:.o=.s) + $(BUILD_DIR)/%.s.o: %.s $(AS) $(ASFLAGS) -o $@ $< diff --git a/include/PR/PRimage.h b/include/PR/PRimage.h index 407894f..145e932 100644 --- a/include/PR/PRimage.h +++ b/include/PR/PRimage.h @@ -2,7 +2,7 @@ * * $Revision: 1.4 $ * $Date: 1997/11/26 00:30:50 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/PRimage.h,v $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/PRimage.h,v $ * **************************************************************************/ diff --git a/include/PR/R4300.h b/include/PR/R4300.h index 932694d..0c25f1d 100644 --- a/include/PR/R4300.h +++ b/include/PR/R4300.h @@ -14,7 +14,7 @@ * * $Revision: 1.13 $ * $Date: 1997/02/11 08:15:34 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/R4300.h,v $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/R4300.h,v $ * **************************************************************************/ diff --git a/include/PR/abi.h b/include/PR/abi.h index 2102bc8..02d440d 100644 --- a/include/PR/abi.h +++ b/include/PR/abi.h @@ -17,7 +17,7 @@ * * $Revision: 1.32 $ * $Date: 1997/02/11 08:16:37 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/abi.h,v $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/abi.h,v $ * **************************************************************************/ diff --git a/include/PR/gbi.h b/include/PR/gbi.h index b418e03..f1cf717 100644 --- a/include/PR/gbi.h +++ b/include/PR/gbi.h @@ -1,4 +1,3 @@ - /************************************************************************** * * * Copyright (C) 1994, Silicon Graphics, Inc. * @@ -12,15 +11,17 @@ **************************************************************************/ /************************************************************************** * - * $Revision: 1.128 $ - * $Date: 1997/11/26 00:30:51 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/gbi.h,v $ + * $Revision: 1.138 $ + * $Date: 1998/12/24 09:05:08 $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/gbi.h,v $ * **************************************************************************/ #ifndef _GBI_H_ #define _GBI_H_ +#include + /* * To use the F3DEX ucodes, define F3DEX_GBI before include this file. * @@ -74,19 +75,22 @@ * * IMPLEMENTATION NOTE: * There is another group of RDP commands that includes the triangle commands - * generated by the RSP code. These are the raw commands the rasterizer - * hardware chews on, with slope info, etc. They will follow the RDP + * generated by the RSP code. These are the raw commands the rasterizer + * hardware chews on, with slope info, etc. They will follow the RDP * ordering... * * IMPLEMENTATION NOTE: - * The RDP hardware has some of these bit patterns wired up. If the hardware - * changes, we must adjust this table, likewise we can't change/add things + * The RDP hardware has some of these bit patterns wired up. If the hardware + * changes, we must adjust this table, likewise we can't change/add things * once the hardware is frozen. (actually, the RDP hardware only looks at * the lower 6 bits of the command byte) * */ -#ifdef F3DEX_GBI_2 +#ifdef F3DEX_GBI_2 +# ifndef F3DEX_GBI +# define F3DEX_GBI +# endif #define G_NOOP 0x00 #define G_RDPHALF_2 0xf1 #define G_SETOTHERMODE_H 0xe3 @@ -102,7 +106,10 @@ #define G_GEOMETRYMODE 0xd9 #define G_POPMTX 0xd8 #define G_TEXTURE 0xd7 -#define G_SUBMODULE 0xd6 +#define G_DMA_IO 0xd6 +#define G_SPECIAL_1 0xd5 +#define G_SPECIAL_2 0xd4 +#define G_SPECIAL_3 0xd3 #define G_VTX 0x01 #define G_MODIFYVTX 0x02 @@ -110,7 +117,8 @@ #define G_BRANCH_Z 0x04 #define G_TRI1 0x05 #define G_TRI2 0x06 -#define G_LINE3D 0x07 +#define G_QUAD 0x07 +#define G_LINE3D 0x08 #else /* F3DEX_GBI_2 */ /* DMA commands: */ @@ -190,7 +198,7 @@ #define G_TEXRECT 0xe4 /* -28 */ -/* +/* * The following commands are the "generated" RDP commands; the user * never sees them, the RSP microcode generates them. * @@ -223,8 +231,8 @@ /* masks to build RDP triangle commands: */ #define G_RDP_TRI_FILL_MASK 0x08 #define G_RDP_TRI_SHADE_MASK 0x04 -#define G_RDP_TRI_TXTR_MASK 0x02 -#define G_RDP_TRI_ZBUFF_MASK 0x01 +#define G_RDP_TRI_TXTR_MASK 0x02 +#define G_RDP_TRI_ZBUFF_MASK 0x01 /* * HACK: @@ -288,7 +296,7 @@ /* * G_MTX: parameter flags */ -#ifdef F3DEX_GBI_2x +#ifdef F3DEX_GBI_2 # define G_MTX_MODELVIEW 0x00 /* matrix types */ # define G_MTX_PROJECTION 0x04 # define G_MTX_MUL 0x00 /* concat or load */ @@ -310,7 +318,7 @@ * * DO NOT USE THE LOW 8 BITS OF GEOMETRYMODE: * The weird bit-ordering is for the micro-code: the lower byte - * can be OR'd in with G_TRI_SHADE (11001100) to construct + * can be OR'd in with G_TRI_SHADE (11001100) to construct * the triangle command directly. Don't break it... * * DO NOT USE THE HIGH 8 BITS OF GEOMETRYMODE: @@ -324,19 +332,27 @@ * appropriately and use primcolor to see anything. * * G_SHADING_SMOOTH enabled means use all 3 colors of the triangle. - * If it is not set, then do 'flat shading', where only one vertex color + * If it is not set, then do 'flat shading', where only one vertex color * is used (and all 3 vertices are set to that same color by the ucode) * See the man page for gSP1Triangle(). * */ #define G_ZBUFFER 0x00000001 -#define G_TEXTURE_ENABLE 0x00000002 /* Microcode use only */ #define G_SHADE 0x00000004 /* enable Gouraud interp */ /* rest of low byte reserved for setup ucode */ -#define G_SHADING_SMOOTH 0x00000200 /* flat or smooth shaded */ -#define G_CULL_FRONT 0x00001000 -#define G_CULL_BACK 0x00002000 -#define G_CULL_BOTH 0x00003000 /* To make code cleaner */ +#ifdef F3DEX_GBI_2 +# define G_TEXTURE_ENABLE 0x00000000 /* Ignored */ +# define G_SHADING_SMOOTH 0x00200000 /* flat or smooth shaded */ +# define G_CULL_FRONT 0x00000200 +# define G_CULL_BACK 0x00000400 +# define G_CULL_BOTH 0x00000600 /* To make code cleaner */ +#else +# define G_TEXTURE_ENABLE 0x00000002 /* Microcode use only */ +# define G_SHADING_SMOOTH 0x00000200 /* flat or smooth shaded */ +# define G_CULL_FRONT 0x00001000 +# define G_CULL_BACK 0x00002000 +# define G_CULL_BOTH 0x00003000 /* To make code cleaner */ +#endif #define G_FOG 0x00010000 #define G_LIGHTING 0x00020000 #define G_TEXTURE_GEN 0x00040000 @@ -388,6 +404,7 @@ #define G_IM_SIZ_8b 1 #define G_IM_SIZ_16b 2 #define G_IM_SIZ_32b 3 +#define G_IM_SIZ_DD 5 #define G_IM_SIZ_4b_BYTES 0 #define G_IM_SIZ_4b_TILE_BYTES G_IM_SIZ_4b_BYTES @@ -820,27 +837,27 @@ Z_CMP | Z_UPD | CVG_DST_FULL | ALPHA_CVG_SEL | \ ZMODE_OPA | \ GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - + #define RM_ZB_XLU_SURF(clk) \ Z_CMP | IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_XLU | \ GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - + #define RM_ZB_OPA_DECAL(clk) \ Z_CMP | CVG_DST_FULL | ALPHA_CVG_SEL | ZMODE_DEC | \ GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) - + #define RM_ZB_XLU_DECAL(clk) \ Z_CMP | IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_DEC | \ GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - + #define RM_ZB_CLD_SURF(clk) \ Z_CMP | IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_XLU | \ GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - + #define RM_ZB_OVL_SURF(clk) \ Z_CMP | IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_DEC | \ GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) - + #define RM_ZB_PCL_SURF(clk) \ Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | \ G_AC_DITHER | \ @@ -1027,7 +1044,7 @@ * element, we can't depend on the C compiler to align things * properly. * - * 64-bit structure alignment is enforced by wrapping structures with + * 64-bit structure alignment is enforced by wrapping structures with * unions that contain a dummy "long long int". Why this works is * explained in the ANSI C Spec, or on page 186 of the second edition * of K&R, "The C Programming Language". @@ -1091,14 +1108,14 @@ typedef struct { /* 20 bytes for above */ /* padding to bring structure size to 64 bit allignment */ - char dummy[4]; + char dummy[4]; } uSprite_t; -typedef union { +typedef union { uSprite_t s; - /* Need to make sure this is 64 bit aligned */ + /* Need to make sure this is 64 bit aligned */ long long int force_structure_allignment[3]; } uSprite; @@ -1175,8 +1192,10 @@ typedef union { * which to store a 1-4 word DMA. * */ -#ifdef F3DEX_GBI_2x -/* 0,2,4,6 are reserved by G_MTX */ +#ifdef F3DEX_GBI_2 +/* 0,4 are reserved by G_MTX */ +# define G_MV_MMTX 2 +# define G_MV_PMTX 6 # define G_MV_VIEWPORT 8 # define G_MV_LIGHT 10 # define G_MV_POINT 12 @@ -1224,7 +1243,7 @@ typedef union { #define G_MW_SEGMENT 0x06 #define G_MW_FOG 0x08 #define G_MW_LIGHTCOL 0x0a -#ifdef F3DEX_GBI_2x +#ifdef F3DEX_GBI_2 # define G_MW_FORCEMTX 0x0c #else /* F3DEX_GBI_2 */ # define G_MW_POINTS 0x0c @@ -1233,7 +1252,7 @@ typedef union { /* * These are offsets from the address in the dmem table - */ + */ #define G_MWO_NUMLIGHT 0x00 #define G_MWO_CLIP_RNX 0x04 #define G_MWO_CLIP_RNY 0x0c @@ -1258,6 +1277,22 @@ typedef union { #define G_MWO_FOG 0x00 #define G_MWO_aLIGHT_1 0x00 #define G_MWO_bLIGHT_1 0x04 +#ifdef F3DEX_GBI_2 +#define G_MWO_aLIGHT_2 0x18 +#define G_MWO_bLIGHT_2 0x1c +#define G_MWO_aLIGHT_3 0x30 +#define G_MWO_bLIGHT_3 0x34 +#define G_MWO_aLIGHT_4 0x48 +#define G_MWO_bLIGHT_4 0x4c +#define G_MWO_aLIGHT_5 0x60 +#define G_MWO_bLIGHT_5 0x64 +#define G_MWO_aLIGHT_6 0x78 +#define G_MWO_bLIGHT_6 0x7c +#define G_MWO_aLIGHT_7 0x90 +#define G_MWO_bLIGHT_7 0x94 +#define G_MWO_aLIGHT_8 0xa8 +#define G_MWO_bLIGHT_8 0xac +#else #define G_MWO_aLIGHT_2 0x20 #define G_MWO_bLIGHT_2 0x24 #define G_MWO_aLIGHT_3 0x40 @@ -1272,6 +1307,7 @@ typedef union { #define G_MWO_bLIGHT_7 0xc4 #define G_MWO_aLIGHT_8 0xe0 #define G_MWO_bLIGHT_8 0xe4 +#endif #define G_MWO_MATRIX_XX_XY_I 0x00 #define G_MWO_MATRIX_XZ_XW_I 0x04 #define G_MWO_MATRIX_YX_YY_I 0x08 @@ -1298,7 +1334,7 @@ typedef union { * * Note: only directional (infinite) lights are currently supported. * - * Note: the weird order is for the DMEM alignment benefit of + * Note: the weird order is for the DMEM alignment benefit of * the microcode. * */ @@ -1461,6 +1497,23 @@ typedef struct { Tri tri; } Gtri; +typedef struct { + unsigned char cmd:8; + unsigned char pad:8; + unsigned char z4:4; + unsigned char z3:4; + unsigned char z2:4; + unsigned char z1:4; + unsigned char y4:4; + unsigned char x4:4; + unsigned char y3:4; + unsigned char x3:4; + unsigned char y2:4; + unsigned char x2:4; + unsigned char y1:4; + unsigned char x1:4; +} Gtri4; + typedef struct { int cmd:8; int pad1:24; @@ -1619,7 +1672,7 @@ typedef struct { /* * Textured rectangles are 128 bits not 64 bits - */ + */ typedef struct { unsigned long w0; unsigned long w1; @@ -1635,14 +1688,42 @@ typedef struct { unsigned int w1; } Gwords; +// xxxxxxxx 11223344 44555566 66666777 +// 88888888 99999999 9999aaaa aaaaaaaa +typedef struct { + unsigned int cmd:8; + unsigned int unk08:2; + unsigned int unk0a:2; + unsigned int unk0c:2; + unsigned int unk0e:4; + unsigned int unk12:4; + unsigned int flags:7; + unsigned int subcmd:3; + unsigned int unk20:8; + unsigned int tile1:12; + unsigned int tile2:12; +} GunkC0; + +typedef struct { + unsigned int cmd:8; + unsigned int unk08:4; + unsigned int unk0c:4; + unsigned int unk10:16; + unsigned int seg:8; + unsigned int offset:24; +} Gvtx; + /* * This union is the fundamental type of the display list. * It is, by law, exactly 64 bits in size. */ typedef union { Gwords words; + u8 bytes[8]; Gdma dma; + Gvtx vtx; Gtri tri; + Gtri4 tri4; Gline3D line; Gpopmtx popmtx; Gsegment segment; @@ -1658,6 +1739,7 @@ typedef union { Gloadtile loadtile; /* use for loadblock also, th is dxt */ Gsettilesize settilesize; Gloadtlut loadtlut; + GunkC0 unkc0; long long int force_structure_alignment; } Gfx; @@ -1700,58 +1782,84 @@ typedef union { #define gDma2p(pkt, c, adrs, len, idx, ofs) \ { \ Gfx *_g = (Gfx *)(pkt); \ - _g->words.w0 = (_SHIFTL((c),24,8)|_SHIFTL((ofs)/8,16,8)| \ - _SHIFTL(((len)-1)/8,8,8)|_SHIFTL((idx),0,8)); \ + _g->words.w0 = (_SHIFTL((c),24,8)|_SHIFTL(((len)-1)/8,19,5)| \ + _SHIFTL((ofs)/8,8,8)|_SHIFTL((idx),0,8)); \ _g->words.w1 = (unsigned int)(adrs); \ } #define gsDma2p(c, adrs, len, idx, ofs) \ { \ - (_SHIFTL((c),24,8)|_SHIFTL((ofs)/8,16,8)| \ - _SHIFTL(((len)-1)/8,8,8)|_SHIFTL((idx),0,8)), \ + (_SHIFTL((c),24,8)|_SHIFTL(((len)-1)/8,19,5)| \ + _SHIFTL((ofs)/8,8,8)|_SHIFTL((idx),0,8)), \ (unsigned int)(adrs) \ } #define gSPNoOp(pkt) gDma0p(pkt, G_SPNOOP, 0, 0) #define gsSPNoOp() gsDma0p(G_SPNOOP, 0, 0) -#ifdef F3DEX_GBI_2x -# define gSPMatrix(pkt, m, p) \ - gDma2p((pkt),G_MTX,(m),sizeof(Mtx),(p)^G_MTX_PUSH,0) -# define gsSPMatrix(m, p) \ - gsDma2p( G_MTX,(m),sizeof(Mtx),(p)^G_MTX_PUSH,0) +#ifdef F3DEX_GBI_2 +# define gSPMatrix(pkt, m, p) \ + gDma2p((pkt),G_MTX,(m),sizeof(Mtx),(p)^G_MTX_PUSH,0) +# define gsSPMatrix(m, p) \ + gsDma2p( G_MTX,(m),sizeof(Mtx),(p)^G_MTX_PUSH,0) #else /* F3DEX_GBI_2 */ -# define gSPMatrix(pkt, m, p) gDma1p(pkt, G_MTX, m, sizeof(Mtx), p) -# define gsSPMatrix(m, p) gsDma1p(G_MTX, m, sizeof(Mtx), p) +# define gSPMatrix(pkt, m, p) gDma1p(pkt, G_MTX, m, sizeof(Mtx), p) +# define gsSPMatrix(m, p) gsDma1p(G_MTX, m, sizeof(Mtx), p) #endif /* F3DEX_GBI_2 */ +#if defined(F3DEX_GBI_2) +/* + * F3DEX_GBI_2: G_VTX GBI format was changed. + * + * +--------+----+---+---+----+------+-+ + * G_VTX | cmd:8 |0000| n:8 |0000|v0+n:7|0| + * +-+---+--+----+---+---+----+------+-+ + * | |seg| address | + * +-+---+-----------------------------+ + */ +# define gSPVertex(pkt, v, n, v0) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = \ + _SHIFTL(G_VTX,24,8)|_SHIFTL((n),12,8)|_SHIFTL((v0)+(n),1,7); \ + _g->words.w1 = (unsigned int)(v); \ +} +# define gsSPVertex(v, n, v0) \ +{ \ + (_SHIFTL(G_VTX,24,8)|_SHIFTL((n),12,8)|_SHIFTL((v0)+(n),1,7)), \ + (unsigned int)(v) \ +} +#elif (defined(F3DEX_GBI)||defined(F3DLP_GBI)) /* * F3DEX_GBI: G_VTX GBI format was changed to support 64 vertice. * - * +--------+--------+------+---------------+ - * G_VTX | cmd:8 | v0:8 | n:6 | length:10 | - * +-+---+--+--------+------+---------------+ - * | |seg| address | - * +-+---+----------------------------------+ + * +--------+--------+------+----------+ + * G_VTX | cmd:8 | v0:8 | n:6 |length:10 | + * +-+---+--+--------+------+----------+ + * | |seg| address | + * +-+---+-----------------------------+ */ -#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) -# define gSPVertex(pkt, v, n, v0) \ - gDma1p(pkt, G_VTX, v, ((n)<<10)|(sizeof(Vtx)*(n)-1), (v0)*2) -# define gsSPVertex(v, n, v0) \ - gsDma1p(G_VTX, v, ((n)<<10)|(sizeof(Vtx)*(n)-1), (v0)*2) +# define gSPVertex(pkt, v, n, v0) \ + gDma1p((pkt),G_VTX,(v),((n)<<10)|(sizeof(Vtx)*(n)-1),(v0)*2) +# define gsSPVertex(v, n, v0) \ + gsDma1p(G_VTX,(v),((n)<<10)|(sizeof(Vtx)*(n)-1),(v0)*2) #else -# define gSPVertex(pkt, v, n, v0) \ +# define gSPVertex(pkt, v, n, v0) \ gDma1p(pkt, G_VTX, v, sizeof(Vtx)*(n),((n)-1)<<4|(v0)) -# define gsSPVertex(v, n, v0) \ +# define gsSPVertex(v, n, v0) \ gsDma1p(G_VTX, v, sizeof(Vtx)*(n), ((n)-1)<<4|(v0)) #endif - -#ifdef F3DEX_GBI_2x -# define gSPViewport(pkt, v) gDma2p(pkt,G_MOVEMEM,v,sizeof(Vp),G_MV_VIEWPORT,0) -# define gsSPViewport(v) gsDma2p( G_MOVEMEM,v,sizeof(Vp),G_MV_VIEWPORT,0) + +#ifdef F3DEX_GBI_2 +# define gSPViewport(pkt, v) \ + gDma2p((pkt), G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT, 0) +# define gsSPViewport(v) \ + gsDma2p( G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT, 0) #else /* F3DEX_GBI_2 */ -# define gSPViewport(pkt,v) gDma1p(pkt,G_MOVEMEM,(v),sizeof(Vp),G_MV_VIEWPORT) -# define gsSPViewport(v) gsDma1p( G_MOVEMEM,(v),sizeof(Vp),G_MV_VIEWPORT) +# define gSPViewport(pkt,v) \ + gDma1p((pkt), G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT) +# define gsSPViewport(v) \ + gsDma1p( G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT) #endif /* F3DEX_GBI_2 */ #define gSPDisplayList(pkt,dl) gDma1p(pkt,G_DL,dl,0,G_DL_PUSH) @@ -1834,7 +1942,7 @@ typedef union { (unsigned int) (dat) \ } -#ifdef F3DEX_GBI_2x +#ifdef F3DEX_GBI_2 #define gMoveWd(pkt, index, offset, data) \ gDma1p((pkt), G_MOVEWORD, data, offset, index) #define gsMoveWd( index, offset, data) \ @@ -1901,6 +2009,16 @@ typedef union { # define __gsSPLine3D_w1f(v0, v1, wd, flag) \ (((flag) == 0) ? __gsSPLine3D_w1(v0, v1, wd): \ __gsSPLine3D_w1(v1, v0, wd)) +# define __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag) \ + (((flag) == 0) ? __gsSP1Triangle_w1(v0, v1, v2): \ + ((flag) == 1) ? __gsSP1Triangle_w1(v1, v2, v3): \ + ((flag) == 2) ? __gsSP1Triangle_w1(v2, v3, v0): \ + __gsSP1Triangle_w1(v3, v0, v1)) +# define __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ + (((flag) == 0) ? __gsSP1Triangle_w1(v0, v2, v3): \ + ((flag) == 1) ? __gsSP1Triangle_w1(v1, v3, v0): \ + ((flag) == 2) ? __gsSP1Triangle_w1(v2, v0, v1): \ + __gsSP1Triangle_w1(v3, v1, v2)) #else # define __gsSP1Triangle_w1f(v0, v1, v2, flag) \ (_SHIFTL((flag), 24,8)|_SHIFTL((v0)*10,16,8)| \ @@ -1910,6 +2028,84 @@ typedef union { _SHIFTL((v1)*10, 8,8)|_SHIFTL((wd), 0,8)) #endif +#ifdef F3DEX_GBI_2 +/*** + *** 1 Triangle + ***/ +#define gSP1Triangle(pkt, v0, v1, v2, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_TRI1, 24, 8)| \ + __gsSP1Triangle_w1f(v0, v1, v2, flag); \ + _g->words.w1 = 0; \ +} +#define gsSP1Triangle(v0, v1, v2, flag) \ +{ \ + _SHIFTL(G_TRI1, 24, 8)|__gsSP1Triangle_w1f(v0, v1, v2, flag), \ + 0 \ +} + +/*** + *** Line + ***/ +#define gSPLine3D(pkt, v0, v1, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8)| \ + __gsSPLine3D_w1f(v0, v1, 0, flag); \ + _g->words.w1 = 0; \ +} +#define gsSPLine3D(v0, v1, flag) \ +{ \ + _SHIFTL(G_LINE3D, 24, 8)|__gsSPLine3D_w1f(v0, v1, 0, flag), \ + 0 \ +} + +/*** + *** LineW + ***/ +/* these macros are the same as SPLine3D, except they have an + * additional parameter for width. The width is added to the "minimum" + * thickness, which is 1.5 pixels. The units for width are in + * half-pixel units, so a width of 1 translates to (.5 + 1.5) or + * a 2.0 pixels wide line. + */ +#define gSPLineW3D(pkt, v0, v1, wd, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8)| \ + __gsSPLine3D_w1f(v0, v1, wd, flag); \ + _g->words.w1 = 0; \ +} +#define gsSPLineW3D(v0, v1, wd, flag) \ +{ \ + _SHIFTL(G_LINE3D, 24, 8)|__gsSPLine3D_w1f(v0, v1, wd, flag), \ + 0 \ +} + +/*** + *** 1 Quadrangle + ***/ +#define gSP1Quadrangle(pkt, v0, v1, v2, v3, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_QUAD, 24, 8)| \ + __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)); \ + _g->words.w1 = __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag); \ +} + +#define gsSP1Quadrangle(v0, v1, v2, v3, flag) \ +{ \ + (_SHIFTL(G_QUAD, 24, 8)| \ + __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)), \ + __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ +} +#else /* F3DEX_GBI_2 */ + /*** *** 1 Triangle ***/ @@ -1920,7 +2116,6 @@ typedef union { _g->words.w0 = _SHIFTL(G_TRI1, 24, 8); \ _g->words.w1 = __gsSP1Triangle_w1f(v0, v1, v2, flag); \ } - #define gsSP1Triangle(v0, v1, v2, flag) \ { \ _SHIFTL(G_TRI1, 24, 8), \ @@ -1937,7 +2132,6 @@ typedef union { _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8); \ _g->words.w1 = __gsSPLine3D_w1f(v0, v1, 0, flag); \ } - #define gsSPLine3D(v0, v1, flag) \ { \ _SHIFTL(G_LINE3D, 24, 8), \ @@ -1960,13 +2154,32 @@ typedef union { _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8); \ _g->words.w1 = __gsSPLine3D_w1f(v0, v1, wd, flag); \ } - #define gsSPLineW3D(v0, v1, wd, flag) \ { \ _SHIFTL(G_LINE3D, 24, 8), \ __gsSPLine3D_w1f(v0, v1, wd, flag) \ } +/*** + *** 1 Quadrangle + ***/ +#define gSP1Quadrangle(pkt, v0, v1, v2, v3, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TRI2, 24, 8)| \ + __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)); \ + _g->words.w1 = __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag); \ +} + +#define gsSP1Quadrangle(v0, v1, v2, v3, flag) \ +{ \ + (_SHIFTL(G_TRI2, 24, 8)| \ + __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)), \ + __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ +} +#endif /* F3DEX_GBI_2 */ + #if (defined(F3DLP_GBI)||defined(F3DEX_GBI)) /*** *** 2 Triangles @@ -1987,36 +2200,6 @@ typedef union { __gsSP1Triangle_w1f(v10, v11, v12, flag1) \ } -/*** - *** 1 Quadrangle - ***/ -#define __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag) \ - (((flag) == 0) ? __gsSP1Triangle_w1(v0, v1, v2): \ - ((flag) == 1) ? __gsSP1Triangle_w1(v1, v2, v3): \ - ((flag) == 2) ? __gsSP1Triangle_w1(v2, v3, v0): \ - __gsSP1Triangle_w1(v3, v0, v1)) - -#define __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ - (((flag) == 0) ? __gsSP1Triangle_w1(v0, v2, v3): \ - ((flag) == 1) ? __gsSP1Triangle_w1(v1, v3, v0): \ - ((flag) == 2) ? __gsSP1Triangle_w1(v2, v0, v1): \ - __gsSP1Triangle_w1(v3, v1, v2)) - -#define gSP1Quadrangle(pkt, v0, v1, v2, v3, flag) \ -{ \ - Gfx *_g = (Gfx *)(pkt); \ - \ - _g->words.w0 = (_SHIFTL(G_TRI2, 24, 8)| \ - __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)); \ - _g->words.w1 = __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag); \ -} - -#define gsSP1Quadrangle(v0, v1, v2, v3, flag) \ -{ \ - (_SHIFTL(G_TRI2, 24, 8)| \ - __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)), \ - __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ -} #endif /* F3DEX_GBI/F3DLP_GBI */ #if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) @@ -2093,11 +2276,14 @@ typedef union { * Insert values into Matrix * * where = element of matrix (byte offset) - * num = new element (32 bit value replacing 2 int or 2 frac matrix + * num = new element (32 bit value replacing 2 int or 2 frac matrix * componants */ -#ifdef F3DEX_GBI_2x -ERROR!! gSPInsertMatrix is no longer supported. +#ifdef F3DEX_GBI_2 +#define gSPInsertMatrix(pkt, where, num) \ + ERROR!! gSPInsertMatrix is no longer supported. +#define gsSPInsertMatrix(where, num) \ + ERROR!! gsSPInsertMatrix is no longer supported. #else #define gSPInsertMatrix(pkt, where, num) \ gMoveWd(pkt, G_MW_MATRIX, where, num) @@ -2110,7 +2296,7 @@ ERROR!! gSPInsertMatrix is no longer supported. * * mptr = pointer to matrix */ -#ifdef F3DEX_GBI_2x +#ifdef F3DEX_GBI_2 #define gSPForceMatrix(pkt, mptr) \ { gDma2p((pkt),G_MOVEMEM,(mptr),sizeof(Mtx),G_MV_MATRIX,0); \ gMoveWd((pkt), G_MW_FORCEMTX,0,0x00010000); \ @@ -2118,7 +2304,7 @@ ERROR!! gSPInsertMatrix is no longer supported. #define gsSPForceMatrix(mptr) \ gsDma2p(G_MOVEMEM,(mptr),sizeof(Mtx),G_MV_MATRIX,0), \ gsMoveWd(G_MW_FORCEMTX,0,0x00010000) - + #else /* F3DEX_GBI_2 */ #define gSPForceMatrix(pkt, mptr) \ { \ @@ -2166,7 +2352,7 @@ ERROR!! gSPInsertMatrix is no longer supported. /* * gSPBranchLessZ Branch DL if (vtx.z) less than or equal (zval). * - * dl = DL branch to + * dl = DL branch to * vtx = Vertex * zval = Screen depth * near = Near plane @@ -2213,7 +2399,7 @@ ERROR!! gSPInsertMatrix is no longer supported. /* * gSPBranchLessZraw Branch DL if (vtx.z) less than or equal (raw zval). * - * dl = DL branch to + * dl = DL branch to * vtx = Vertex * zval = Raw value of screen depth */ @@ -2271,10 +2457,35 @@ ERROR!! gSPInsertMatrix is no longer supported. OS_K0_TO_PHYSICAL(&##ucode##DataStart)) #endif +#ifdef F3DEX_GBI_2 +/* + * gSPDma_io DMA to/from DMEM/IMEM for DEBUG. + */ +#define gSPDma_io(pkt, flag, dmem, dram, size) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = _SHIFTL(G_DMA_IO,24,8)|_SHIFTL((flag),23,1)| \ + _SHIFTL((dmem)/8,13,10)|_SHIFTL((size)-1,0,12); \ + _g->words.w1 = (unsigned int)(dram); \ +} + +#define gsSPDma_io(flag, dmem, dram, size) \ +{ \ + _SHIFTL(G_DMA_IO,24,8)|_SHIFTL((flag),23,1)| \ + _SHIFTL((dmem)/8,13,10)|_SHIFTL((size)-1,0,12), \ + (unsigned int)(dram) \ +} + +#define gSPDmaRead(pkt,dmem,dram,size) gSPDma_io((pkt),0,(dmem),(dram),(size)) +#define gsSPDmaRead(dmem,dram,size) gsSPDma_io(0,(dmem),(dram),(size)) +#define gSPDmaWrite(pkt,dmem,dram,size) gSPDma_io((pkt),1,(dmem),(dram),(size)) +#define gsSPDmaWrite(dmem,dram,size) gsSPDma_io(1,(dmem),(dram),(size)) +#endif + /* * Lighting Macros */ -#ifdef F3DEX_GBI_2x +#ifdef F3DEX_GBI_2 # define NUML(n) ((n)*24) #else # define NUML(n) (((n)+1)*32 + 0x80000000) @@ -2289,7 +2500,7 @@ ERROR!! gSPInsertMatrix is no longer supported. #define NUMLIGHTS_7 7 /* * n should be one of: NUMLIGHTS_0, NUMLIGHTS_1, ..., NUMLIGHTS_7 - * NOTE: in addition to the number of directional lights specified, + * NOTE: in addition to the number of directional lights specified, * there is always 1 ambient light */ #define gSPNumLights(pkt, n) \ @@ -2301,7 +2512,7 @@ ERROR!! gSPInsertMatrix is no longer supported. #define LIGHT_2 2 #define LIGHT_3 3 #define LIGHT_4 4 -#define LIGHT_5 5 +#define LIGHT_5 5 #define LIGHT_6 6 #define LIGHT_7 7 #define LIGHT_8 8 @@ -2313,11 +2524,11 @@ ERROR!! gSPInsertMatrix is no longer supported. * LIGHT_1 through LIGHT_3 will be the directional lights and light * LIGHT_4 will be the ambient light. */ -#ifdef F3DEX_GBI_2x +#ifdef F3DEX_GBI_2 # define gSPLight(pkt, l, n) \ - gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,(n)*3+3) + gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,(n)*24+24) # define gsSPLight(l, n) \ - gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,(n)*3+3) + gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,(n)*24+24) #else /* F3DEX_GBI_2 */ # define gSPLight(pkt, l, n) \ gDma1p(pkt, G_MOVEMEM, l, sizeof(Light),((n)-1)*2+G_MV_L0) @@ -2479,13 +2690,13 @@ ERROR!! gSPInsertMatrix is no longer supported. */ #ifdef F3DEX_GBI_2 # define gSPLookAtX(pkt, l) \ - gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LOOKATX,0) + gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATX) # define gsSPLookAtX(l) \ - gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LOOKATX,0) + gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATX) # define gSPLookAtY(pkt, l) \ - gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LOOKATY,0) + gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATY) # define gsSPLookAtY(l) \ - gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LOOKATY,0) + gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATY) #else /* F3DEX_GBI_2 */ # define gSPLookAtX(pkt, l) \ gDma1p(pkt, G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATX) @@ -2531,7 +2742,7 @@ ERROR!! gSPInsertMatrix is no longer supported. * min, max: range 0 to 1000: 0=nearplane, 1000=farplane * min is where fog begins (usually less than max and often 0) * max is where fog is thickest (usually 1000) - * + * */ #define gSPFogFactor(pkt, fm, fo) \ gMoveWd(pkt, G_MW_FOG, G_MWO_FOG, \ @@ -2551,56 +2762,90 @@ ERROR!! gSPInsertMatrix is no longer supported. (_SHIFTL((128000/((max)-(min))),16,16) | \ _SHIFTL(((500-(min))*256/((max)-(min))),0,16))) +#ifdef F3DEX_GBI_2 /* * Macros to turn texture on/off */ -#define gSPTexture(pkt, s, t, level, tile, on) \ +# define gSPTexture(pkt, s, t, level, tile, on) \ { \ Gfx *_g = (Gfx *)(pkt); \ \ - _g->words.w0 = (_SHIFTL(G_TEXTURE, 24, 8) | \ - _SHIFTL(BOWTIE_VAL, 16, 8) | \ - _SHIFTL(level, 11, 3) | _SHIFTL(tile, 8, 3) | \ - _SHIFTL(on, 0, 8)); \ - _g->words.w1 = (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)); \ + _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8) | \ + _SHIFTL(BOWTIE_VAL,16,8) | \ + _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | \ + _SHIFTL((on),1,7)); \ + _g->words.w1 = (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)); \ } - -#define gsSPTexture(s, t, level, tile, on) \ +# define gsSPTexture(s, t, level, tile, on) \ { \ - (_SHIFTL(G_TEXTURE, 24, 8) | _SHIFTL(BOWTIE_VAL, 16, 8) | \ - _SHIFTL(level, 11, 3) | _SHIFTL(tile, 8, 3) | _SHIFTL(on, 0, 8)),\ - (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)) \ + (_SHIFTL(G_TEXTURE,24,8) | _SHIFTL(BOWTIE_VAL,16,8) | \ + _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | _SHIFTL((on),1,7)),\ + (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)) \ } - -/* +/* * Different version of SPTexture macro, has an additional parameter * which is currently reserved in the microcode. */ -#define gSPTextureL(pkt, s, t, level, xparam, tile, on) \ +# define gSPTextureL(pkt, s, t, level, xparam, tile, on) \ { \ Gfx *_g = (Gfx *)(pkt); \ \ - _g->words.w0 = (_SHIFTL(G_TEXTURE, 24, 8) | \ - _SHIFTL(xparam, 16, 8) | \ - _SHIFTL(level, 11, 3) | _SHIFTL(tile, 8, 3) | \ - _SHIFTL(on, 0, 8)); \ - _g->words.w1 = (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)); \ + _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8) | \ + _SHIFTL((xparam),16,8) | \ + _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | \ + _SHIFTL((on),1,7)); \ + _g->words.w1 = (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)); \ } - -#define gsSPTextureL(s, t, level, xparam, tile, on) \ +# define gsSPTextureL(s, t, level, xparam, tile, on) \ { \ - (_SHIFTL(G_TEXTURE, 24, 8) | _SHIFTL(xparam, 16, 8) | \ - _SHIFTL(level, 11, 3) | _SHIFTL(tile, 8, 3) | _SHIFTL(on, 0, 8)),\ - (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)) \ + (_SHIFTL(G_TEXTURE,24,8) | _SHIFTL((xparam),16,8) | \ + _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | _SHIFTL((on),1,7)),\ + (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)) \ } +#else +/* + * Macros to turn texture on/off + */ +# define gSPTexture(pkt, s, t, level, tile, on) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL(BOWTIE_VAL,16,8)|\ + _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)| \ + _SHIFTL((on),0,8)); \ + _g->words.w1 = (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)); \ +} +# define gsSPTexture(s, t, level, tile, on) \ +{ \ + (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL(BOWTIE_VAL,16,8)| \ + _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)|_SHIFTL((on),0,8)), \ + (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)) \ +} +/* + * Different version of SPTexture macro, has an additional parameter + * which is currently reserved in the microcode. + */ +# define gSPTextureL(pkt, s, t, level, xparam, tile, on) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL((xparam),16,8)| \ + _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)| \ + _SHIFTL((on),0,8)); \ + _g->words.w1 = (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)); \ +} +# define gsSPTextureL(s, t, level, xparam, tile, on) \ +{ \ + (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL((xparam),16,8)| \ + _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)|_SHIFTL((on),0,8)), \ + (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)) \ +} +#endif +#define gSPPerspNormalize(pkt, s) gMoveWd(pkt, G_MW_PERSPNORM, 0, (s)) +#define gsSPPerspNormalize(s) gsMoveWd( G_MW_PERSPNORM, 0, (s)) -#define gSPPerspNormalize(pkt, s) \ - gMoveWd(pkt, G_MW_PERSPNORM, 0, (s)) -#define gsSPPerspNormalize(s) \ - gsMoveWd( G_MW_PERSPNORM, 0, (s)) - -#ifdef F3DEX_GBI_2x +#ifdef F3DEX_GBI_2 # define gSPPopMatrixN(pkt, n, num) gDma2p((pkt),G_POPMTX,(num)*64,64,2,0) # define gsSPPopMatrixN(n, num) gsDma2p( G_POPMTX,(num)*64,64,2,0) # define gSPPopMatrix(pkt, n) gSPPopMatrixN((pkt), (n), 1) @@ -2623,7 +2868,7 @@ ERROR!! gSPInsertMatrix is no longer supported. _SHIFTL(G_ENDDL, 24, 8), 0 \ } -#ifdef F3DEX_GBI_2x +#ifdef F3DEX_GBI_2 /* * One gSPGeometryMode(pkt,c,s) GBI is equal to these two GBIs. * @@ -2678,7 +2923,7 @@ ERROR!! gSPInsertMatrix is no longer supported. } #endif /* F3DEX_GBI_2 */ -#ifdef F3DEX_GBI_2x +#ifdef F3DEX_GBI_2 #define gSPSetOtherMode(pkt, cmd, sft, len, data) \ { \ Gfx *_g = (Gfx *)(pkt); \ @@ -2776,7 +3021,7 @@ ERROR!! gSPInsertMatrix is no longer supported. gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 2, mode) #endif -/* 'blendmask' is not supported anymore. +/* 'blendmask' is not supported anymore. * The bits are reserved for future use. * Fri May 26 13:45:55 PDT 1995 */ @@ -2982,7 +3227,7 @@ ERROR!! gSPInsertMatrix is no longer supported. * * This command makes all othermode parameters set. * Do not use this command in the same DL with another g*SPSetOtherMode DLs. - * + * * [Usage] * gDPSetOtherMode(pkt, modeA, modeB) * @@ -3235,9 +3480,9 @@ ERROR!! gSPInsertMatrix is no longer supported. ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ } -/* +/* * Allow tmem address and render tile to be specified. - * The S at the end means odd lines are already word Swapped + * The S at the end means odd lines are already word Swapped */ #define gDPLoadMultiBlockS(pkt, timg, tmem, rtile, fmt, siz, width, \ height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ @@ -3453,13 +3698,13 @@ ERROR!! gSPInsertMatrix is no longer supported. ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ ((height)-1) << G_TEXTURE_IMAGE_FRAC) -/* +/* * Allows tmem and render tile to be specified. Useful when loading * several tiles at a time. * * Here is the static form of the pre-swapped texture block loading * See gDPLoadTextureBlockS() for reference. Basically, just don't - * calculate DxT, use 0 + * calculate DxT, use 0 */ #define gsDPLoadMultiBlockS(timg, tmem, rtile, fmt, siz, width, height, \ @@ -3543,7 +3788,7 @@ ERROR!! gSPInsertMatrix is no longer supported. } /* - * 4-bit load block. Allows tmem and render tile to be specified. Useful when + * 4-bit load block. Allows tmem and render tile to be specified. Useful when * loading multiple tiles. The S means odd lines are already word swapped. */ #define gDPLoadMultiBlock_4bS(pkt, timg, tmem, rtile, fmt, width, height,\ @@ -3978,7 +4223,7 @@ ERROR!! gSPInsertMatrix is no longer supported. G_IM_FMT_RGBA, G_IM_SIZ_16b, 4*16, 1, \ pal, 0, 0, 0, 0, 0, 0) -#endif /* _HW_VERSION_1 */ +#endif /* _HW_VERSION_1 */ /* * Load a 256-entry palette (for 8-bit CI textures) @@ -4020,7 +4265,7 @@ ERROR!! gSPInsertMatrix is no longer supported. gsDPLoadSync(), \ gsDPLoadTLUTCmd(G_TX_LOADTILE, 255), \ gsDPPipeSync() - + #else /* **** WORKAROUND hardware 1 load_tlut bug ****** */ #define gsDPLoadTLUT_pal256(dram) \ @@ -4075,7 +4320,7 @@ ERROR!! gSPInsertMatrix is no longer supported. G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, count, \ 0, 0, 0, 0, 0, 0, 0) -#endif /* _HW_VERSION_1 */ +#endif /* _HW_VERSION_1 */ #define gDPSetScissor(pkt, mode, ulx, uly, lrx, lry) \ { \ @@ -4230,7 +4475,7 @@ ERROR!! gSPInsertMatrix is no longer supported. } /* Notice that textured rectangles are 128-bit commands, therefore - * gsDPTextureRectangle() should not be used in display lists + * gsDPTextureRectangle() should not be used in display lists * under normal circumstances (use gsSPTextureRectangle()). * That is also why there is no gDPTextureRectangle() macros. */ diff --git a/include/PR/gs2dex.h b/include/PR/gs2dex.h index 7e2b2c6..c484ba1 100644 --- a/include/PR/gs2dex.h +++ b/include/PR/gs2dex.h @@ -6,7 +6,7 @@ Modified by Comments Header file for S2DEX ucode. - $Id: gs2dex.h,v 1.15 1997/10/17 08:19:07 yasu Exp $ + $Id: gs2dex.h,v 1.21 1998/05/28 00:14:49 has Exp $ ---------------------------------------------------------------------*/ #ifndef _GS2DEX_H_ @@ -16,6 +16,8 @@ extern "C" { #endif +#include + /*===========================================================================* * Macro *===========================================================================*/ @@ -38,66 +40,66 @@ extern "C" { /* Non scalable background plane */ typedef struct { - u16 imageX; /* The x-coordinate of the upper-left position of the texture. (u11.5)*/ - u16 imageW; /* The width of the texture. (u10.2)*/ - s16 frameX; /* The upper-left position of the transferred frame. (s10.2)*/ - u16 frameW; /* The width of the transferred frame. (u10.2)*/ + u16 imageX; /* テクスチャの左上位置 X 座標 (u10.5) */ + u16 imageW; /* テクスチャの幅 (u10.2) */ + s16 frameX; /* 転送されるフレームの左上位置(s10.2) */ + u16 frameW; /* 転送されるフレームの幅 (u10.2) */ - u16 imageY; /* The y-coordinate of the upper-left position of the texture. (u11.5)*/ - u16 imageH; /* The height of the texture. (u10.2)*/ - s16 frameY; /* The upper-left position of the transferred frame. (s10.2)*/ - u16 frameH; /* The height of the transferred frame. (u10.2)*/ + u16 imageY; /* テクスチャの左上位置 Y 座標 (u10.5) */ + u16 imageH; /* テクスチャの高さ (u10.2) */ + s16 frameY; /* 転送されるフレームの左上位置(s10.2) */ + u16 frameH; /* 転送されるフレームの高さ (u10.2) */ - u64 *imagePtr; /* The texture source address on DRAM. */ - u16 imageLoad; /* Which to use, LoadBlock or LoadTile? */ - u8 imageFmt; /* The format of the texel. G_IM_FMT_* */ - u8 imageSiz; /* The size of the texel G_IM_SIZ_* */ - u16 imagePal; /* The pallet number. */ - u16 imageFlip; /* The right & left inversion of the image. Inverted by G_BG_FLAG_FLIPS*/ + u64 *imagePtr; /* DRAM 上のテクスチャソースアドレス */ + u16 imageLoad; /* LoadBlock, LoadTile のどちらを使用するか */ + u8 imageFmt; /* テクセルのフォーマット G_IM_FMT_* */ + u8 imageSiz; /* テクセルのサイズ G_IM_SIZ_* */ + u16 imagePal; /* パレット番号 */ + u16 imageFlip; /* イメージの左右反転 G_BG_FLAG_FLIPS で反転 */ - /* Because the following are set in the initialization routine guS2DInitBg(), the user doesn't - have to set it.*/ - u16 tmemW; /* The TMEM width and Work size of the frame 1 line. - At LoadBlock, GS_PIX2TMEM(imageW/4,imageSiz) - At LoadTile GS_PIX2TMEM(frameW/4,imageSiz)+1 */ - u16 tmemH; /* The height of TMEM loadable at a time. (s13.2) The 4 times value. - When the normal texture, 512/tmemW*4 - When the CI texture, 256/tmemW*4 */ - u16 tmemLoadSH; /* The SH value - At LoadBlock, tmemSize/2-1 - At LoadTile, tmemW*16-1 */ - u16 tmemLoadTH; /* The TH value or the Stride value - At LoadBlock, GS_CALC_DXT(tmemW) - At LoadTile, tmemH-1 */ - u16 tmemSizeW; /* The skip value of imagePtr for image 1-line. - At LoadBlock, tmemW*2 - At LoadTile, GS_PIX2TMEM(imageW/4,imageSiz)*2 */ - u16 tmemSize; /* The skip value of imagePtr for 1-loading. - = tmemSizeW*tmemH */ + /* 以下は初期化ルーチン guS2DInitBg() 内で設定されるのでユーザが設 + 定する必要はない */ + u16 tmemW; /* frame 1 ラインの TMEM 幅 Word サイズ + LoadBlock の時 GS_PIX2TMEM(imageW/4,imageSiz) + LoadTile の時 GS_PIX2TMEM(frameW/4,imageSiz)+1 */ + u16 tmemH; /* 一度にロードできる TMEM 高さ (s13.2) 4倍値 + 通常テクスチャの時 512/tmemW*4 + CI テクスチャの時 256/tmemW*4 */ + u16 tmemLoadSH; /* SH 値 + LoadBlock の時 tmemSize/2-1 + LoadTile の時 tmemW*16-1 */ + u16 tmemLoadTH; /* TH 値 or Stride 値 + LoadBlock の時 GS_CALC_DXT(tmemW) + LoadTile の時 tmemH-1 */ + u16 tmemSizeW; /* image 1 ライン分の imagePtr のスキップ値 + LoadBlock の時 tmemW*2 + LoadTile の時 GS_PIX2TMEM(imageW/4,imageSiz)*2 */ + u16 tmemSize; /* ロード一回分の imagePtr のスキップ値 + = tmemSizeW*tmemH */ } uObjBg_t; /* 40 bytes */ /* Scalable background plane */ typedef struct { - u16 imageX; /* The x-coordinate of the upper-left position of the texture. (u11.5)*/ - u16 imageW; /* The width of the texture. (u10.2)*/ - s16 frameX; /* The upper-left position of the transferred frame. (s10.2)*/ - u16 frameW; /* The width of the transferred frame. (u10.2)*/ + u16 imageX; /* テクスチャの左上位置 X 座標 (u10.5) */ + u16 imageW; /* テクスチャの幅 (u10.2) */ + s16 frameX; /* 転送されるフレームの左上位置(s10.2) */ + u16 frameW; /* 転送されるフレームの幅 (u10.2) */ - u16 imageY; /* The y-coordinate of the upper-left position of the texture. (u11.5)*/ - u16 imageH; /* The height of the texture. (u10.2)*/ - s16 frameY; /* The upper-left position of the transferred frame. (s10.2)*/ - u16 frameH; /* The height of the transferred frame. (u10.2)*/ + u16 imageY; /* テクスチャの左上位置 Y 座標 (u10.5) */ + u16 imageH; /* テクスチャの高さ (u10.2) */ + s16 frameY; /* 転送されるフレームの左上位置(s10.2) */ + u16 frameH; /* 転送されるフレームの高さ (u10.2) */ - u64 *imagePtr; /* The texture source address on DRAM. */ - u16 imageLoad; /* Which to use, LoadBlock or LoadTile? */ - u8 imageFmt; /* The format of the texel. G_IM_FMT_* */ - u8 imageSiz; /* The size of the texel G_IM_SIZ_* */ - u16 imagePal; /* The pallet number. */ - u16 imageFlip; /* The right & left inversion of the image. Inverted by G_BG_FLAG_FLIPS*/ + u64 *imagePtr; /* DRAM 上のテクスチャソースアドレス */ + u16 imageLoad; /* LoadBlock, LoadTile のどちらを使用するか */ + u8 imageFmt; /* テクセルのフォーマット G_IM_FMT_* */ + u8 imageSiz; /* テクセルのサイズ G_IM_SIZ_* */ + u16 imagePal; /* パレット番号 */ + u16 imageFlip; /* イメージの左右反転 G_BG_FLAG_FLIPS で反転 */ - u16 scaleW; /* The scale value of the X-direction. (u5.10)*/ - u16 scaleH; /* The scale value of the Y-direction. (u5.10)*/ - s32 imageYorig; /* The start point of drawing on the image. (s20.5)*/ + u16 scaleW; /* X 方向スケール値 (u5.10) */ + u16 scaleH; /* Y 方向スケール値 (u5.10) */ + s32 imageYorig; /* image における描画始点 (s20.5) */ u8 padding[4]; @@ -112,24 +114,24 @@ typedef union { /*---------------------------------------------------------------------------* * 2D Objects *---------------------------------------------------------------------------*/ -#define G_OBJ_FLAG_FLIPS 1<<0 /* The inversion to the S-direction. */ -#define G_OBJ_FLAG_FLIPT 1<<4 /* The inversion to the T-direction. */ +#define G_OBJ_FLAG_FLIPS 1<<0 /* S 方向反転 */ +#define G_OBJ_FLAG_FLIPT 1<<4 /* T 方向反転 */ typedef struct { - s16 objX; /* The x-coordinate of the upper-left end. s10.2 OBJ */ - u16 scaleW; /* Scaling of the u5.10 width direction. */ - u16 imageW; /* The width of the u10.5 texture. (The length of the S-direction.) */ - u16 paddingX; /* Unused. Always 0. */ - s16 objY; /* The y-coordinate of the s10.2 OBJ upper-left end. */ - u16 scaleH; /* Scaling of the u5.10 height direction. */ - u16 imageH; /* The height of the u10.5 texture. (The length of the T-direction.)*/ - u16 paddingY; /* Unused. Always 0. */ - u16 imageStride; /* The folding width of the texel. (In units of 64bit word.) */ - u16 imageAdrs; /* The texture header position in TMEM. (In units of 64bit word.) */ - u8 imageFmt; /* The format of the texel. G_IM_FMT_* */ - u8 imageSiz; /* The size of the texel. G_IM_SIZ_* */ - u8 imagePal; /*The pallet number. 0-7 */ - u8 imageFlags; /* The display flag. G_OBJ_FLAG_FLIP* */ + s16 objX; /* s10.2 OBJ 左上端 X 座標 */ + u16 scaleW; /* u5.10 幅方向スケーリング */ + u16 imageW; /* u10.5 テクスチャの幅 (S 方向の長さ) */ + u16 paddingX; /* 未使用 常に 0 */ + s16 objY; /* s10.2 OBJ 左上端 Y 座標 */ + u16 scaleH; /* u5.10 高さ方向スケーリング */ + u16 imageH; /* u10.5 テクスチャの高さ (T 方向の長さ) */ + u16 paddingY; /* 未使用 常に 0 */ + u16 imageStride; /* テクセルの折り返し幅 (64bit word 単位) */ + u16 imageAdrs; /* TMEM 内のテクスチャ先頭位置 (64bit word 単位) */ + u8 imageFmt; /* テクセルのフォーマット G_IM_FMT_* */ + u8 imageSiz; /* テクセルのサイズ G_IM_SIZ_* */ + u8 imagePal; /* パレット番号 0-7 */ + u8 imageFlags; /* 表示フラグ G_OBJ_FLAG_FLIP* */ } uObjSprite_t; /* 24 bytes */ typedef union { @@ -174,12 +176,12 @@ typedef union { #define GS_TB_TLINE(pix,siz) (GS_CALC_DXT(GS_PIX2TMEM((pix),(siz)))) typedef struct { - u32 type; /* G_OBJLT_TXTRBLOCK divided into types. */ - u64 *image; /* The texture source address on DRAM. */ - u16 tmem; /* The transferred TMEM word address. (8byteWORD) */ - u16 tsize; /* The Texture size. Specified by the macro GS_TB_TSIZE(). */ - u16 tline; /* The width of the Texture 1-line. Specified by the macro GS_TB_TLINE()*/ - u16 sid; /* STATE ID Multipled by 4. Either one of 0,4,8 and 12. */ + u32 type; /* Type 種別 G_OBJLT_TXTRBLOCK */ + u64 *image; /* DRAM 上のテクスチャソースアドレス */ + u16 tmem; /* ロード先の TMEM ワードアドレス (8byteWORD) */ + u16 tsize; /* Texture サイズ マクロ GS_TB_TSIZE() で指定 */ + u16 tline; /* Texture 1 ライン幅 マクロ GS_TB_TLINE() で指定 */ + u16 sid; /* STATE ID 4 の倍数で 0,4,8,12 のどれか */ u32 flag; /* STATE flag */ u32 mask; /* STATE mask */ } uObjTxtrBlock_t; /* 24 bytes */ @@ -188,12 +190,12 @@ typedef struct { #define GS_TT_THEIGHT(pix,siz) (((pix)<<2)-1) typedef struct { - u32 type; /* G_OBJLT_TXTRTILE divided into types. */ - u64 *image; /* The texture source address on DRAM. */ - u16 tmem; /* The loaded texture source address on DRAM. (8byteWORD) */ - u16 twidth; /* The width of the Texture. Specified by the macro GS_TT_TWIDTH() */ - u16 theight; /* The height of the Texture. Specified by the macro GS_TT_THEIGHT()*/ - u16 sid; /* STATE ID Multiplied by 4. Either one of 0,4,8 and 12. */ + u32 type; /* Type 種別 G_OBJLT_TXTRTILE */ + u64 *image; /* DRAM 上のテクスチャソースアドレス */ + u16 tmem; /* ロード先の TMEM ワードアドレス (8byteWORD) */ + u16 twidth; /* Texture 幅 マクロ GS_TT_TWIDTH() で指定 */ + u16 theight; /* Texture 高さ マクロ GS_TT_THEIGHT() で指定 */ + u16 sid; /* STATE ID 4 の倍数で 0,4,8,12 のどれか */ u32 flag; /* STATE flag */ u32 mask; /* STATE mask */ } uObjTxtrTile_t; /* 24 bytes */ @@ -202,12 +204,12 @@ typedef struct { #define GS_PAL_NUM(num) ((num)-1) typedef struct { - u32 type; /* G_OBJLT_TLUT divided into types. */ - u64 *image; /* the texture source address on DRAM. */ - u16 phead; /* The pallet number of the load header. Between 256 and 511. */ - u16 pnum; /* The loading pallet number -1. */ - u16 zero; /* Assign 0 all the time. */ - u16 sid; /* STATE ID Multiplied by 4. Either one of 0,4,8 and 12. */ + u32 type; /* Type 種別 G_OBJLT_TLUT */ + u64 *image; /* DRAM 上のテクスチャソースアドレス */ + u16 phead; /* ロード先頭のパレット番号 256 以上 511 以下 */ + u16 pnum; /* ロードするパレット数 - 1 */ + u16 zero; /* 常に 0 を代入する */ + u16 sid; /* STATE ID 4 の倍数で 0,4,8,12 のどれか */ u32 flag; /* STATE flag */ u32 mask; /* STATE mask */ } uObjTxtrTLUT_t; /* 24 bytes */ @@ -231,6 +233,21 @@ typedef struct { * GBI Commands for S2DEX microcode *===========================================================================*/ /* GBI Header */ +#ifdef F3DEX_GBI_2 +#define G_OBJ_RECTANGLE_R 0xda +#define G_OBJ_MOVEMEM 0xdc +#define G_RDPHALF_0 0xe4 +#define G_OBJ_RECTANGLE 0x01 +#define G_OBJ_SPRITE 0x02 +#define G_SELECT_DL 0x04 +#define G_OBJ_LOADTXTR 0x05 +#define G_OBJ_LDTX_SPRITE 0x06 +#define G_OBJ_LDTX_RECT 0x07 +#define G_OBJ_LDTX_RECT_R 0x08 +#define G_BG_1CYC 0x09 +#define G_BG_COPY 0x0a +#define G_OBJ_RENDERMODE 0x0b +#else #define G_BG_1CYC 0x01 #define G_BG_COPY 0x02 #define G_OBJ_RECTANGLE 0x03 @@ -244,7 +261,7 @@ typedef struct { #define G_OBJ_LDTX_RECT 0xc3 #define G_OBJ_LDTX_RECT_R 0xc4 #define G_RDPHALF_0 0xe4 - +#endif /*---------------------------------------------------------------------------* * Background wrapped screen @@ -305,7 +322,7 @@ typedef struct { /*---------------------------------------------------------------------------* * Set general status *---------------------------------------------------------------------------*/ -#define G_MW_GENSTAT 0x08 /* Note that it is the same value of G_MW_FOG. */ +#define G_MW_GENSTAT 0x08 /* G_MW_FOG と同じ値なので注意 */ #define gSPSetStatus(pkt, sid, val) \ gMoveWd((pkt), G_MW_GENSTAT, (sid), (val)) @@ -352,9 +369,21 @@ extern u64 gspS2DEX_fifoTextStart[], gspS2DEX_fifoTextEnd[]; extern u64 gspS2DEX_fifoDataStart[], gspS2DEX_fifoDataEnd[]; extern u64 gspS2DEX_fifo_dTextStart[], gspS2DEX_fifo_dTextEnd[]; extern u64 gspS2DEX_fifo_dDataStart[], gspS2DEX_fifo_dDataEnd[]; +extern u64 gspS2DEX2_fifoTextStart[], gspS2DEX2_fifoTextEnd[]; +extern u64 gspS2DEX2_fifoDataStart[], gspS2DEX2_fifoDataEnd[]; +extern u64 gspS2DEX2_xbusTextStart[], gspS2DEX2_xbusTextEnd[]; +extern u64 gspS2DEX2_xbusDataStart[], gspS2DEX2_xbusDataEnd[]; extern void guS2DInitBg(uObjBg *); -extern void guS2DEmuSetScissor(u32, u32, u32, u32, u8); -extern void guS2DEmuBgRect1Cyc(Gfx **, uObjBg *); + +#ifdef F3DEX_GBI_2 +# define guS2DEmuBgRect1Cyc guS2D2EmuBgRect1Cyc /*Wrapper*/ +# define guS2DEmuSetScissor guS2D2EmuSetScissor /*Wrapper*/ + extern void guS2D2EmuSetScissor(u32, u32, u32, u32, u8); + extern void guS2D2EmuBgRect1Cyc(Gfx **, uObjBg *); +#else + extern void guS2DEmuSetScissor(u32, u32, u32, u32, u8); + extern void guS2DEmuBgRect1Cyc(Gfx **, uObjBg *); +#endif #ifdef _LANGUAGE_C_PLUS_PLUS } diff --git a/include/PR/gt.h b/include/PR/gt.h index 07fa2bc..dbf0945 100644 --- a/include/PR/gt.h +++ b/include/PR/gt.h @@ -38,9 +38,9 @@ /************************************************************************** * - * $Revision: 1.14 $ - * $Date: 1997/02/11 08:22:47 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/gt.h,v $ + * $Revision: 1.16 $ + * $Date: 1998/05/28 00:14:50 $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/gt.h,v $ * **************************************************************************/ @@ -55,6 +55,8 @@ extern "C" { #endif /* _LANGUAGE_C_PLUS_PLUS */ +#include + /* the following #defines seem out of order, but we need them * for the microcode. */ diff --git a/include/PR/gu.h b/include/PR/gu.h index 3063e7b..f7a57ac 100644 --- a/include/PR/gu.h +++ b/include/PR/gu.h @@ -17,7 +17,7 @@ * * $Revision: 1.46 $ * $Date: 1997/11/26 00:30:53 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/gu.h,v $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/gu.h,v $ * **************************************************************************/ diff --git a/include/PR/libaudio.h b/include/PR/libaudio.h index 55f22c8..33017b7 100644 --- a/include/PR/libaudio.h +++ b/include/PR/libaudio.h @@ -22,7 +22,7 @@ * * $Revision: 1.173 $ * $Date: 1997/12/01 12:42:21 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/libaudio.h,v $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/libaudio.h,v $ * **************************************************************************/ diff --git a/include/PR/mbi.h b/include/PR/mbi.h index 9956ef2..fed3510 100644 --- a/include/PR/mbi.h +++ b/include/PR/mbi.h @@ -15,9 +15,9 @@ /************************************************************************** * - * $Revision: 1.135 $ - * $Date: 1997/11/26 00:30:54 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/mbi.h,v $ + * $Revision: 1.136 $ + * $Date: 1999/01/05 13:04:00 $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/mbi.h,v $ * **************************************************************************/ @@ -79,6 +79,8 @@ #define M_GFXTASK 1 #define M_AUDTASK 2 #define M_VIDTASK 3 +#define M_HVQTASK 6 +#define M_HVQMTASK 7 /************************************************************************** * diff --git a/include/PR/n_libaudio.h b/include/PR/n_libaudio.h new file mode 100644 index 0000000..8840668 --- /dev/null +++ b/include/PR/n_libaudio.h @@ -0,0 +1,410 @@ +/*==================================================================== + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#ifndef __N_LIBAUDIO__ +#define __N_LIBAUDIO__ + +#include + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include + +struct var8009c340 { + u8 surround; + u8 mono; + u8 headphone; + u8 unk03; +}; + +extern struct var8009c340 var8009c340; +extern u8 var8009c344[2]; +extern u8 var8009c346[2]; +extern u8 var8009c348[4]; + +/* + * Synthesis driver stuff + */ +typedef struct N_ALVoice_s { + ALLink node; + struct N_PVoice_s *pvoice; + ALWaveTable *table; + void *clientPrivate; + s16 state; + s16 priority; + s16 fxBus; + s16 unityPitch; +} N_ALVoice; + +typedef struct { + ALPlayer *head; /* client list head */ + ALLink pFreeList; /* list of free physical voices */ + ALLink pAllocList; /* list of allocated physical voices */ + ALLink pLameList; /* list of voices ready to be freed */ + s32 paramSamples; + s32 curSamples; /* samples from start of game */ + ALDMANew dma; + ALHeap *heap; + struct ALParam_s *paramList; + struct N_ALMainBus_s *mainBus; + struct N_ALAuxBus_s *auxBus; + s32 numPVoices; + s32 maxAuxBusses; + s32 outputRate; + s32 maxOutSamples; + s32 sv_dramout; + s32 sv_first; +} N_ALSynth; + + +void n_alSynAddPlayer(ALPlayer *client); +void n_alSynAddSndPlayer(ALPlayer *client); +void n_alSynAddSeqPlayer(ALPlayer *client); + +ALFxRef n_alSynAllocFX( s16 bus,ALSynConfig *c, ALHeap *hp); +s32 n_alSynAllocVoice( N_ALVoice *voice, ALVoiceConfig *vc); + + +void n_alSynFreeVoice(N_ALVoice *voice); +ALFxRef n_alSynGetFXRef( s16 bus, s16 index); +s16 n_alSynGetPriority( N_ALVoice *voice); +void n_alSynRemovePlayer( ALPlayer *client); +void n_alSynSetFXMix(N_ALVoice *v, u8 fxmix); +void n_alSynSetFXParam(ALFxRef fx, s16 paramID, void *param); +void n_alSynFreeFX(ALFxRef *fx); +void n_alSynSetPan(N_ALVoice *v, u8 pan); +void n_alSynSetPitch( N_ALVoice *v, f32 pitch); +void n_alSynSetPriority( N_ALVoice *voice, s16 priority); +void n_alSynSetVol( N_ALVoice *v, s16 volume, ALMicroTime t); +void n_alSynStartVoice(N_ALVoice *v, ALWaveTable *table); +void n_alSynStartVoiceParams(N_ALVoice *v, ALWaveTable *w,f32 pitch, s16 vol, + ALPan pan, u8 fxmix, u8 arg6, f32 arg7, u8 arg8, ALMicroTime t); +void n_alSynStopVoice( N_ALVoice *v); + +void n_alSynFilter11(N_ALVoice *v, u8 channel); +void n_alSynFilter12(N_ALVoice *v, u8 arg1); +void n_alSynFilter13(N_ALVoice *v, f32 arg1); + +void n_alSynNew(ALSynConfig *c); +void n_alSynDelete(void); + + +/* + * Audio Library (AL) stuff + */ +typedef struct { + N_ALSynth drvr; +} N_ALGlobals; + +extern N_ALGlobals *n_alGlobals; +extern N_ALSynth *n_syn; + +void n_alInit(N_ALGlobals *g, ALSynConfig *c); +void n_alClose(N_ALGlobals *glob); +Acmd *n_alAudioFrame(Acmd *cmdList, s32 *cmdLen, + s16 *outBuf, s32 outLen); + + +/* + * Sequence Player stuff + */ +typedef struct { + struct N_ALVoice_s *voice; +} N_ALNoteEvent; + + +typedef struct { + struct N_ALVoice_s *voice; + ALMicroTime delta; + u8 vol; +} N_ALVolumeEvent; + + +typedef struct { + struct N_ALVoiceState_s *vs; + void *oscState; + u8 chan; +} N_ALOscEvent; + +typedef struct { + f32 unk00; + f32 unk04; +} N_AL18Event; + +typedef struct { + u8 unk00; + u8 unk01; + u8 unk02; + u8 unk03; + u8 param; +} N_AL19Event; + +typedef struct { + struct sndstate *sndstate; + s32 data; + s32 data2; +} N_ALGenericEvent; + +typedef struct { + s16 type; + union { + ALMIDIEvent midi; + ALTempoEvent tempo; + ALEndEvent end; + N_ALNoteEvent note; + N_ALVolumeEvent vol; + ALSeqpLoopEvent loop; + ALSeqpVolEvent spvol; + ALSeqpPriorityEvent sppriority; + ALSeqpSeqEvent spseq; + ALSeqpBankEvent spbank; + N_ALOscEvent osc; + N_AL18Event evt18; + N_AL19Event evt19; + N_ALGenericEvent generic; + } msg; +} N_ALEvent; + + +typedef struct { + ALLink node; + ALMicroTime delta; + N_ALEvent evt; +} N_ALEventListItem; + +void n_alEvtqNew(ALEventQueue *evtq, N_ALEventListItem *items, s32 itemCount); +ALMicroTime n_alEvtqNextEvent(ALEventQueue *evtq, N_ALEvent *evt); +void n_alEvtqPostEvent(ALEventQueue *evtq, N_ALEvent *evt, ALMicroTime delta, s32 arg3); +void n_alEvtqFlushType(ALEventQueue *evtq, s16 type); + +struct oscstate { + u32 unk00; + u8 unk04; + u32 unk08; + f32 unk0c; + f32 unk10; +}; + +struct fx { + s16 unk00; + s16 unk02; + s32 unk04; + s16 unk08[8]; +}; + +typedef struct N_ALVoiceState_s { + struct N_ALVoiceState_s *next;/* MUST be first */ + N_ALVoice voice; + ALSound *sound; + ALMicroTime envEndTime; /* time of envelope segment end */ + f32 pitch; /* currect pitch ratio */ + f32 vibrato; /* current value of the vibrato */ + u8 envGain; /* current envelope gain */ + u8 channel; /* channel assignment */ + u8 key; /* note on key number */ + u8 velocity; /* note on velocity */ + u8 envPhase; /* what envelope phase */ + u8 phase; + u8 tremelo; /* current value of the tremelo */ + u8 flags; /* bit 0 tremelo flag + bit 1 vibrato flag */ + void *oscState; + struct oscstate *oscState2; +} N_ALVoiceState; + +typedef struct { + ALPlayer node; /* note: must be first in structure */ + N_ALSynth *drvr; /* reference to the client driver */ + ALSeq *target; /* current sequence */ + ALMicroTime curTime; + ALBank *bank; /* current ALBank */ + s32 uspt; /* microseconds per tick */ + s32 nextDelta; /* microseconds to next callback */ + s32 state; + u16 chanMask; /* active channels */ + s16 vol; /* overall sequence volume */ + u8 maxChannels; /* number of MIDI channels */ + u8 debugFlags; /* control which error get reported */ + N_ALEvent nextEvent; + ALEventQueue evtq; + ALMicroTime frameTime; + ALChanState *chanState; /* 16 channels for MIDI */ + N_ALVoiceState *vAllocHead; /* list head for allocated voices */ + N_ALVoiceState *vAllocTail; /* list tail for allocated voices */ + N_ALVoiceState *vFreeList; /* list of free voice state structs */ + ALOscInit initOsc; + ALOscUpdate updateOsc; + ALOscStop stopOsc; + ALSeqMarker *loopStart; + ALSeqMarker *loopEnd; + s32 loopCount; /* -1 = loop forever, 0 = no loop */ + u8 unk88; + u8 unk89; +} N_ALSeqPlayer; + +typedef struct { + ALPlayer node; /* note: must be first in structure */ + N_ALSynth *drvr; /* reference to the client driver */ + ALCSeq *target; /* current sequence */ + ALMicroTime curTime; + ALBank *bank; /* current ALBank */ + s32 uspt; /* microseconds per tick */ + s32 nextDelta; /* microseconds to next callback */ + s32 state; + u16 chanMask; /* active channels */ + s16 vol; /* overall sequence volume */ + u8 maxChannels; /* number of MIDI channels */ + u8 debugFlags; /* control which error get reported */ + N_ALEvent nextEvent; + ALEventQueue evtq; + ALMicroTime frameTime; + ALChanState *chanState; /* 16 channels for MIDI */ + N_ALVoiceState *vAllocHead; /* list head for allocated voices */ + N_ALVoiceState *vAllocTail; /* list tail for allocated voices */ + N_ALVoiceState *vFreeList; /* list of free voice state structs */ + ALOscInit initOsc; + ALOscUpdate updateOsc; + ALOscStop stopOsc; + f32 unk7c; + f32 unk80; + void *queue; + u8 unk88; + u8 unk89; +} N_ALCSPlayer; + + +/* + * Sequence data representation routines + */ +void n_alSeqNextEvent(ALSeq *seq, N_ALEvent *event); +void n_alSeqNewMarker(ALSeq *seq, ALSeqMarker *m, u32 ticks); + +void n_alCSeqNew(ALCSeq *seq, u8 *ptr); +void n_alCSeqNextEvent(ALCSeq *seq, N_ALEvent *evt, s32 arg2); +void n_alCSeqNewMarker(ALCSeq *seq, ALCSeqMarker *m, u32 ticks); + + +/* + * Sequence Player routines + */ +void n_alSeqpNew(N_ALSeqPlayer *seqp, ALSeqpConfig *config); +void n_alSeqpDelete(N_ALSeqPlayer *seqp); +u8 n_alSeqpGetChlVol(N_ALSeqPlayer *seqp, u8 chan); +u8 n_alSeqpGetChlFXMix(N_ALSeqPlayer *seqp, u8 chan); +ALPan n_alSeqpGetChlPan(N_ALSeqPlayer *seqp, u8 chan); +u8 n_alSeqpGetChlPriority(N_ALSeqPlayer *seqp, u8 chan); +s32 n_alSeqpGetChlProgram(N_ALSeqPlayer *seqp, u8 chan); +ALSeq *n_alSeqpGetSeq(N_ALSeqPlayer *seqp); +s32 n_alSeqpGetState(N_ALSeqPlayer *seqp); +s32 n_alSeqpGetTempo(N_ALSeqPlayer *seqp); +s16 n_alSeqpGetVol(N_ALSeqPlayer *seqp); /* Master volume control */ +void n_alSeqpPlay(N_ALSeqPlayer *seqp); +void n_alSeqpSendMidi(N_ALSeqPlayer *seqp, s32 ticks, u8 status, u8 byte1, u8 byte2); +void n_alSeqpSetBank(N_ALSeqPlayer *seqp, ALBank *b); +void n_alSeqpSetChlVol(N_ALSeqPlayer *seqp, u8 chan, u8 vol); +void n_alSeqpSetChlFXMix(N_ALSeqPlayer *seqp, u8 chan, u8 fxmix); +void n_alSeqpSetChlPan(N_ALSeqPlayer *seqp, u8 chan, ALPan pan); +void n_alSeqpSetChlPriority(N_ALSeqPlayer *seqp, u8 chan, u8 priority); +void n_alSeqpSetChlProgram(N_ALSeqPlayer *seqp, u8 chan, u8 prog); +void n_alSeqpSetSeq(N_ALSeqPlayer *seqp, ALSeq *seq); +void n_alSeqpSetTempo(N_ALSeqPlayer *seqp, s32 tempo); +void n_alSeqpSetVol(N_ALSeqPlayer *seqp, s16 vol); +void n_alSeqpStop(N_ALSeqPlayer *seqp); +void n_alSeqpLoop(N_ALSeqPlayer *seqp, ALSeqMarker *start, ALSeqMarker *end, s32 count); +void n_alSeqpSetFilter11(N_ALSeqPlayer *seqp); + + +/* + * Compressed Sequence Player routines + */ +void n_alCSPNew(N_ALCSPlayer *seqp, ALSeqpConfig *config); +void n_alCSPDelete(N_ALCSPlayer *seqp); +u8 n_alCSPGetChlVol(N_ALCSPlayer *seqp, u8 chan); +u8 n_alCSPGetChlFXMix(N_ALCSPlayer *seqp, u8 chan); +ALPan n_alCSPGetChlPan(N_ALCSPlayer *seqp, u8 chan); +u8 n_alCSPGetChlPriority(N_ALCSPlayer *seqp, u8 chan); +s32 n_alCSPGetChlProgram(N_ALCSPlayer *seqp, u8 chan); +ALCSeq *n_alCSPGetSeq(N_ALCSPlayer *seqp); +s32 n_alCSPGetState(N_ALCSPlayer *seqp); +s32 n_alCSPGetTempo(N_ALCSPlayer *seqp); +s16 n_alCSPGetVol(N_ALCSPlayer *seqp); +void n_alCSPPlay(N_ALCSPlayer *seqp); +void n_alCSPSendMidi(N_ALCSPlayer *seqp, s32 ticks, u8 status, u8 byte1, u8 byte2); +void n_alCSPSetBank(N_ALCSPlayer *seqp, ALBank *b); +void n_alCSPSetChlVol(N_ALCSPlayer *seqp, u8 chan, u8 vol); +void n_alCSPSetChlFXMix(N_ALCSPlayer *seqp, u8 chan, u8 fxmix); +void n_alCSPSetChlPan(N_ALCSPlayer *seqp, u8 chan, ALPan pan); +void n_alCSPSetChlPriority(N_ALCSPlayer *seqp, u8 chan, u8 priority); +void n_alCSPSetChlProgram(N_ALCSPlayer *seqp, u8 chan, u8 prog); +void n_alCSPSetSeq(N_ALCSPlayer *seqp, ALCSeq *seq); +void n_alCSPSetTempo(N_ALCSPlayer *seqp, s32 tempo); +void n_alCSPSetVol(N_ALCSPlayer *seqp, s16 vol); +void n_alCSPStop(N_ALCSPlayer *seqp); + + +/* + * Sound Player stuff + */ +typedef struct { + ALPlayer node; /* note: must be first in structure */ + ALEventQueue evtq; + N_ALEvent nextEvent; + N_ALSynth *drvr; /* reference to the client driver */ + struct sndstate *target; + void *sndState; + s32 maxSounds; + ALMicroTime frameTime; + ALMicroTime nextDelta; /* microseconds to next callback */ + ALMicroTime curTime; +} N_ALSndPlayer; + +void n_alSndpNew(ALSndpConfig *c); +void n_alSndpDelete(void); +ALSndId n_alSndpAllocate(ALSound *sound); +void n_alSndpDeallocate(ALSndId id); +s32 n_alSndpGetState(void); +void n_alSndpPlay(void); +void n_alSndpPlayAt(ALMicroTime delta); +void n_alSndpSetFXMix(u8 mix); +void n_alSndpSetPan(ALPan pan); +void n_alSndpSetPitch(f32 pitch); +void n_alSndpSetPriority(ALSndId id, u8 priority); +void n_alSndpSetVol(s16 vol); +void n_alSndpStop(void); +ALSndId n_alSndpGetSound(void); +void n_alSndpSetSound(ALSndId id); + + +/* + * for n_audio micro code + */ +extern long long int n_aspMainTextStart[], n_aspMainTextEnd[]; +extern long long int n_aspMainDataStart[], n_aspMainDataEnd[]; + +f32 func0003b9d4(s32 arg0); +void func0003ba64(struct fx *fx, f32 outputrate); + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* __N_LIBAUDIO__ */ diff --git a/include/PR/n_libaudio_s_to_n.h b/include/PR/n_libaudio_s_to_n.h new file mode 100644 index 0000000..de3e0f9 --- /dev/null +++ b/include/PR/n_libaudio_s_to_n.h @@ -0,0 +1,120 @@ +#define ALVoice N_ALVoice +#define ALSynth N_ALSynth +#define ALGlobals N_ALGlobals + +#define alSynAddPlayer( a, b) n_alSynAddPlayer( b) +#define alSynAllocFX( a, b, c, d) n_alSynAllocFX( b, c, d) +#define alSynAllocVoice( a, b, c) n_alSynAllocVoice( b, c) +#define alSynDelete( a) n_alSynDelete() +#define alSynFreeVoice( a, b) n_alSynFreeVoice( b) +#define alSynGetFXRef( a, b, c) n_alSynGetFXRef( b, c) +#define alSynGetPriority( a, b) n_alSynGetPriority( b) +#define alSynRemovePlayer( a, b) n_alSynRemovePlayer( b) +#define alSynSetFXMix( a, b, c) n_alSynSetFXMix( b, c) +#define alSynSetFXParam( a, b, c, d) n_alSynSetFXParam( b, c, d) +#define alSynFreeFX( a, b) n_alSynFreeFX( b) +#define alSynSetPan( a, b, c) n_alSynSetPan( b, c) +#define alSynSetPitch( a, b, c) n_alSynSetPitch( b, c) +#define alSynSetPriority( a, b, c) n_alSynSetPriority( b, c) +#define alSynSetVol( a, b, c, d) n_alSynSetVol( b, c, d) +#define alSynStartVoice( a, b, c) n_alSynStartVoice( b, c) +#define alSynStartVoiceParams( a, b, c, d, e, f, g, h) \ + n_alSynStartVoiceParams( b, c, d, e, f, g, h) +#define alSynStopVoice( a, b) n_alSynStopVoice( b) +#define alSynNew( a, b) n_alSynNew( b) + +#define alInit n_alInit +#define alClose n_alClose +#define alAudioFrame n_alAudioFrame + +#define ALVoiceState N_ALVoiceState +#define ALSeqPlayer N_ALSeqPlayer +#define ALCSPlayer N_ALCSPlayer + +#define alSeqNextEvent n_alSeqNextEvent +#define alSeqNewMarker n_alSeqNewMarker + +#define alCSeqNew n_alCSeqNew +#define alCSeqNextEvent n_alCSeqNextEvent +#define alCSeqNewMarker n_alCSeqNewMarker + +#define alSeqpNew n_alSeqpNew +#define alSeqpDelete n_alSeqpDelete +#define alSeqpGetChlVol n_alSeqpGetChlVol +#define alSeqpGetChlFXMix n_alSeqpGetChlFXMix +#define alSeqpGetChlPan n_alSeqpGetChlPan +#define alSeqpGetChlPriority n_alSeqpGetChlPriority +#define alSeqpGetChlProgram n_alSeqpGetChlProgram +#define alSeqpGetSeq n_alSeqpGetSeq +#define alSeqpGetState n_alSeqpGetState +#define alSeqpGetTempo n_alSeqpGetTempo +#define alSeqpGetVol n_alSeqpGetVol +#define alSeqpPlay n_alSeqpPlay +#define alSeqpSendMidi n_alSeqpSendMidi +#define alSeqpSetBank n_alSeqpSetBank +#define alSeqpSetChlVol n_alSeqpSetChlVol +#define alSeqpSetChlFXMix n_alSeqpSetChlFXMix +#define alSeqpSetChlPan n_alSeqpSetChlPan +#define alSeqpSetChlPriority n_alSeqpSetChlPriority +#define alSeqpSetChlProgram n_alSeqpSetChlProgram +#define alSeqpSetSeq n_alSeqpSetSeq +#define alSeqpSetTempo n_alSeqpSetTempo +#define alSeqpSetVol n_alSeqpSetVol +#define alSeqpStop n_alSeqpStop +#define alSeqpLoop n_alSeqpLoop + +#define alCSPNew n_alCSPNew +#define alCSPDelete n_alCSPDelete +#define alCSPGetChlVol n_alCSPGetChlVol +#define alCSPGetChlFXMix n_alCSPGetChlFXMix +#define alCSPGetChlPan n_alCSPGetChlPan +#define alCSPGetChlPriority n_alCSPGetChlPriority +#define alCSPGetChlProgram n_alCSPGetChlProgram +#define alCSPGetSeq n_alCSPGetSeq +#define alCSPGetState n_alCSPGetState +#define alCSPGetTempo n_alCSPGetTempo +#define alCSPGetVol n_alCSPGetVol +#define alCSPPlay n_alCSPPlay +#define alCSPSendMidi n_alCSPSendMidi +#define alCSPSetBank n_alCSPSetBank +#define alCSPSetChlVol n_alCSPSetChlVol +#define alCSPSetChlFXMix n_alCSPSetChlFXMix +#define alCSPSetChlPan n_alCSPSetChlPan +#define alCSPSetChlPriority n_alCSPSetChlPriority +#define alCSPSetChlProgram n_alCSPSetChlProgram +#define alCSPSetSeq n_alCSPSetSeq +#define alCSPSetTempo n_alCSPSetTempo +#define alCSPSetVol n_alCSPSetVol +#define alCSPStop n_alCSPStop + +#define ALSoundState N_ALSoundState +#define ALSndpEvent N_ALSndpEvent +#define ALSndPlayer N_ALSndPlayer + +#define alSndpNew( a, b) n_alSndpNew( a, b) +#define alSndpDelete( a) n_alSndpDelete() +#define alSndpAllocate( a, b) n_alSndpAllocate( b) +#define alSndpDeallocate( a, b) n_alSndpDeallocate( b) +#define alSndpGetState( a) n_alSndpGetState() +#define alSndpPlay( a) n_alSndpPlay() +#define alSndpPlayAt( a, b) n_alSndpPlayAt( b) +#define alSndpSetFXMix( a, b) n_alSndpSetFXMix( b) +#define alSndpSetPan( a, b) n_alSndpSetPan( b) +#define alSndpSetPitch( a, b) n_alSndpSetPitch( b) +#define alSndpSetPriority( a, b, c) n_alSndpSetPriority( b, c) +#define alSndpSetVol( a, b) n_alSndpSetVol( b) +#define alSndpStop( a) n_alSndpStop() +#define alSndpGetSound( a) n_alSndpGetSound() +#define alSndpSetSound( a, b) n_alSndpSetSound( b) + +#define alEvtqNew n_alEvtqNew +#define alEvtqNextEvent n_alEvtqNextEvent +#define alEvtqPostEvent n_alEvtqPostEvent +#define alEvtqFlushType n_alEvtqFlushType +#define alEvtqPrintEvtQueue n_alEvtqPrintEvtQueue +#define alEvtqPrintAllocEvts n_alEvtqPrintAllocEvts + + + + + diff --git a/include/PR/os.h b/include/PR/os.h index cd0aea1..0c4b0d5 100644 --- a/include/PR/os.h +++ b/include/PR/os.h @@ -19,414 +19,57 @@ * Copyright Laws of the United States. *====================================================================*/ -/************************************************************************** - * - * $Revision: 1.149 $ - * $Date: 1997/12/15 04:30:52 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/os.h,v $ - * - **************************************************************************/ - +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os.h,v $ + $Revision: 1.167 $ + $Date: 1999/01/18 13:17:43 $ + *---------------------------------------------------------------------*/ #ifndef _OS_H_ #define _OS_H_ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #ifdef _LANGUAGE_C_PLUS_PLUS extern "C" { #endif #include -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -typedef s32 OSPri; -typedef s32 OSId; -typedef union { struct { f32 f_odd; f32 f_even; } f; f64 d; } __OSfp; - -typedef struct { - u64 at, v0, v1, a0, a1, a2, a3; - u64 t0, t1, t2, t3, t4, t5, t6, t7; - u64 s0, s1, s2, s3, s4, s5, s6, s7; - u64 t8, t9, gp, sp, s8, ra; - u64 lo, hi; - u32 sr, pc, cause, badvaddr, rcp; - u32 fpcsr; - __OSfp fp0, fp2, fp4, fp6, fp8, fp10, fp12, fp14; - __OSfp fp16, fp18, fp20, fp22, fp24, fp26, fp28, fp30; -} __OSThreadContext; - -typedef struct OSThread_s { - struct OSThread_s *next; /* run/mesg queue link */ - OSPri priority; /* run/mesg queue priority */ - struct OSThread_s **queue; /* queue thread is on */ - struct OSThread_s *tlnext; /* all threads queue link */ - u16 state; /* OS_STATE_* */ - u16 flags; /* flags for rmon */ - OSId id; /* id for debugging */ - int fp; /* thread has used fp unit */ - __OSThreadContext context; /* register/interrupt mask */ -} OSThread; - -typedef u32 OSEvent; -typedef u32 OSIntMask; -typedef u32 OSPageMask; -typedef u32 OSHWIntr; - -/* - * Structure for message - */ -typedef void * OSMesg; - -/* - * Structure for message queue - */ -typedef struct OSMesgQueue_s { - OSThread *mtqueue; /* Queue to store threads blocked - on empty mailboxes (receive) */ - OSThread *fullqueue; /* Queue to store threads blocked - on full mailboxes (send) */ - s32 validCount; /* Contains number of valid message */ - s32 first; /* Points to first valid message */ - s32 msgCount; /* Contains total # of messages */ - OSMesg *msg; /* Points to message buffer array */ -} OSMesgQueue; - -/* - * Structure for Enhanced PI interface - */ - -/* - * OSTranxInfo is set up for Leo Disk DMA. This info will be maintained - * by exception handler. This is how the PIMGR and the ISR communicate. - */ - -typedef struct { - u32 errStatus; /* error status */ - void *dramAddr; /* RDRAM buffer address (DMA) */ - void *C2Addr; /* C2 buffer address */ - u32 sectorSize; /* size of transfering sector */ - u32 C1ErrNum; /* total # of C1 errors */ - u32 C1ErrSector[4]; /* error sectors */ -} __OSBlockInfo; - -typedef struct { - u32 cmdType; /* for disk only */ - u16 transferMode; /* Block, Track, or sector? */ - u16 blockNum; /* which block is transfering */ - s32 sectorNum; /* which sector is transfering */ - u32 devAddr; /* Device buffer address */ - u32 bmCtlShadow; /* asic bm_ctl(510) register shadow ram */ - u32 seqCtlShadow; /* asic seq_ctl(518) register shadow ram */ - __OSBlockInfo block[2]; /* bolck transfer info */ -} __OSTranxInfo; - - -typedef struct OSPiHandle_s { - struct OSPiHandle_s *next; /* point to next handle on the table */ - u8 type; /* DEVICE_TYPE_BULK for disk */ - u8 latency; /* domain latency */ - u8 pageSize; /* domain page size */ - u8 relDuration; /* domain release duration */ - u8 pulse; /* domain pulse width */ - u8 domain; /* which domain */ - u32 baseAddress; /* Domain address */ - u32 speed; /* for roms only */ - /* The following are "private" elements" */ - __OSTranxInfo transferInfo; /* for disk only */ -} OSPiHandle; - -typedef struct { - u8 type; - u32 address; -} OSPiInfo; - -/* - * Structure for I/O message block - */ -typedef struct { - u16 type; /* Message type */ - u8 pri; /* Message priority (High or Normal) */ - u8 status; /* Return status */ - OSMesgQueue *retQueue; /* Return message queue to notify I/O - * completion */ -} OSIoMesgHdr; - -typedef struct { - OSIoMesgHdr hdr; /* Message header */ - void * dramAddr; /* RDRAM buffer address (DMA) */ - u32 devAddr; /* Device buffer address (DMA) */ - u32 size; /* DMA transfer size in bytes */ - OSPiHandle *piHandle; /* PI device handle */ -} OSIoMesg; - -/* - * Structure for device manager block - */ -typedef struct { - s32 active; /* Status flag */ - OSThread *thread; /* Calling thread */ - OSMesgQueue *cmdQueue; /* Command queue */ - OSMesgQueue *evtQueue; /* Event queue */ - OSMesgQueue *acsQueue; /* Access queue */ - /* Raw DMA routine */ - s32 (*dma)(s32, u32, void *, u32); - s32 (*edma)(OSPiHandle *, s32, u32, void *, u32); -} OSDevMgr; - - -/* - * Structure to store VI register values that remain the same between 2 fields - */ -typedef struct { - u32 ctrl; - u32 width; - u32 burst; - u32 vSync; - u32 hSync; - u32 leap; - u32 hStart; - u32 xScale; - u32 vCurrent; -} OSViCommonRegs; - - -/* - * Structure to store VI register values that change between fields - */ -typedef struct { - u32 origin; - u32 yScale; - u32 vStart; - u32 vBurst; - u32 vIntr; -} OSViFieldRegs; - - -/* - * Structure for VI mode - */ -typedef struct { - u8 type; /* Mode type */ - OSViCommonRegs comRegs; /* Common registers for both fields */ - OSViFieldRegs fldRegs[2]; /* Registers for Field 1 & 2 */ -} OSViMode; - -/* - * Structure for time value - */ -typedef u64 OSTime; - -/* - * Structure for interval timer - */ -typedef struct OSTimer_s { - struct OSTimer_s *next; /* point to next timer in list */ - struct OSTimer_s *prev; /* point to previous timer in list */ - OSTime interval; /* duration set by user */ - OSTime value; /* time remaining before */ - /* timer fires */ - OSMesgQueue *mq; /* Message Queue */ - OSMesg msg; /* Message to send */ -} OSTimer; - -/* - * Structure for controllers - */ - -typedef struct { - u16 type; /* Controller Type */ - u8 status; /* Controller status */ - u8 errno; -}OSContStatus; - -typedef struct { - u16 button; - s8 stick_x; /* -80 <= stick_x <= 80 */ - s8 stick_y; /* -80 <= stick_y <= 80 */ - u8 errno; -} OSContPad; - -typedef struct { - void *address; /* Ram pad Address: 11 bits */ - u8 databuffer[32]; /* address of the data buffer */ - u8 addressCrc; /* CRC code for address */ - u8 dataCrc; /* CRC code for data */ - u8 errno; -} OSContRamIo; - -/* - * Structure for file system - */ - - - -typedef struct { - int status; - OSMesgQueue *queue; - int channel; - u8 id[32]; - u8 label[32]; - int version; - int dir_size; - int inode_table; /* block location */ - int minode_table; /* mirrioring inode_table */ - int dir_table; /* block location */ - int inode_start_page; /* page # */ - u8 banks; - u8 activebank; -} OSPfs; - - -typedef struct { - u32 file_size; /* bytes */ - u32 game_code; - u16 company_code; - char ext_name[4]; - char game_name[16]; -} OSPfsState; - -/* - * Structure for Profiler - */ -typedef struct { - u16 *histo_base; /* histogram base */ - u32 histo_size; /* histogram size */ - u32 *text_start; /* start of text segment */ - u32 *text_end; /* end of text segment */ -} OSProf; - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - /************************************************************************** * * Global definitions * */ -/* Thread states */ - -#define OS_STATE_STOPPED 1 -#define OS_STATE_RUNNABLE 2 -#define OS_STATE_RUNNING 4 -#define OS_STATE_WAITING 8 - -/* Events */ -#ifdef _FINALROM -#define OS_NUM_EVENTS 15 -#else -#define OS_NUM_EVENTS 23 -#endif - -#define OS_EVENT_SW1 0 /* CPU SW1 interrupt */ -#define OS_EVENT_SW2 1 /* CPU SW2 interrupt */ -#define OS_EVENT_CART 2 /* Cartridge interrupt: used by rmon */ -#define OS_EVENT_COUNTER 3 /* Counter int: used by VI/Timer Mgr */ -#define OS_EVENT_SP 4 /* SP task done interrupt */ -#define OS_EVENT_SI 5 /* SI (controller) interrupt */ -#define OS_EVENT_AI 6 /* AI interrupt */ -#define OS_EVENT_VI 7 /* VI interrupt: used by VI/Timer Mgr */ -#define OS_EVENT_PI 8 /* PI interrupt: used by PI Manager */ -#define OS_EVENT_DP 9 /* DP full sync interrupt */ -#define OS_EVENT_CPU_BREAK 10 /* CPU breakpoint: used by rmon */ -#define OS_EVENT_SP_BREAK 11 /* SP breakpoint: used by rmon */ -#define OS_EVENT_FAULT 12 /* CPU fault event: used by rmon */ -#define OS_EVENT_THREADSTATUS 13 /* CPU thread status: used by rmon */ -#define OS_EVENT_PRENMI 14 /* Pre NMI interrupt */ -#ifndef _FINALROM -#define OS_EVENT_RDB_READ_DONE 15 /* RDB read ok event: used by rmon */ -#define OS_EVENT_RDB_LOG_DONE 16 /* read of log data complete */ -#define OS_EVENT_RDB_DATA_DONE 17 /* read of hostio data complete */ -#define OS_EVENT_RDB_REQ_RAMROM 18 /* host needs ramrom access */ -#define OS_EVENT_RDB_FREE_RAMROM 19 /* host is done with ramrom access */ -#define OS_EVENT_RDB_DBG_DONE 20 -#define OS_EVENT_RDB_FLUSH_PROF 21 -#define OS_EVENT_RDB_ACK_PROF 22 -#endif - -/* Flags for debugging purpose */ - -#define OS_FLAG_CPU_BREAK 1 /* Break exception has occurred */ -#define OS_FLAG_FAULT 2 /* CPU fault has occurred */ - -/* Interrupt masks */ - -#define OS_IM_NONE 0x00000001 -#define OS_IM_SW1 0x00000501 -#define OS_IM_SW2 0x00000601 -#define OS_IM_CART 0x00000c01 -#define OS_IM_PRENMI 0x00001401 -#define OS_IM_RDBWRITE 0x00002401 -#define OS_IM_RDBREAD 0x00004401 -#define OS_IM_COUNTER 0x00008401 -#define OS_IM_CPU 0x0000ff01 -#define OS_IM_SP 0x00010401 -#define OS_IM_SI 0x00020401 -#define OS_IM_AI 0x00040401 -#define OS_IM_VI 0x00080401 -#define OS_IM_PI 0x00100401 -#define OS_IM_DP 0x00200401 -#define OS_IM_ALL 0x003fff01 -#define RCP_IMASK 0x003f0000 -#define RCP_IMASKSHIFT 16 - -/* Recommended thread priorities for the system threads */ - -#define OS_PRIORITY_MAX 255 -#define OS_PRIORITY_VIMGR 254 -#define OS_PRIORITY_RMON 250 -#define OS_PRIORITY_RMONSPIN 200 -#define OS_PRIORITY_PIMGR 150 -#define OS_PRIORITY_SIMGR 140 -#define OS_PRIORITY_APPMAX 127 -#define OS_PRIORITY_IDLE 0 /* Must be 0 */ - - -/* Flags to turn blocking on/off when sending/receiving message */ - -#define OS_MESG_NOBLOCK 0 -#define OS_MESG_BLOCK 1 - -/* Flags to indicate direction of data transfer */ - -#define OS_READ 0 /* device -> RDRAM */ -#define OS_WRITE 1 /* device <- RDRAM */ -#define OS_OTHERS 2 /* for Leo disk only */ - -/* - * I/O message types - */ -#define OS_MESG_TYPE_BASE (10) -#define OS_MESG_TYPE_LOOPBACK (OS_MESG_TYPE_BASE+0) -#define OS_MESG_TYPE_DMAREAD (OS_MESG_TYPE_BASE+1) -#define OS_MESG_TYPE_DMAWRITE (OS_MESG_TYPE_BASE+2) -#define OS_MESG_TYPE_VRETRACE (OS_MESG_TYPE_BASE+3) -#define OS_MESG_TYPE_COUNTER (OS_MESG_TYPE_BASE+4) -#define OS_MESG_TYPE_EDMAREAD (OS_MESG_TYPE_BASE+5) -#define OS_MESG_TYPE_EDMAWRITE (OS_MESG_TYPE_BASE+6) - -/* - * I/O message priority - */ -#define OS_MESG_PRI_NORMAL 0 -#define OS_MESG_PRI_HIGH 1 - -/* - * Page size argument for TLB routines - */ -#define OS_PM_4K 0x0000000 -#define OS_PM_16K 0x0006000 -#define OS_PM_64K 0x001e000 -#define OS_PM_256K 0x007e000 -#define OS_PM_1M 0x01fe000 -#define OS_PM_4M 0x07fe000 -#define OS_PM_16M 0x1ffe000 - /* * Stack size for I/O device managers: PIM (PI Manager), VIM (VI Manager), * SIM (SI Manager) @@ -438,89 +81,6 @@ typedef struct { #define OS_MIN_STACKSIZE 72 -/* - * Values for osTvType - */ -#define OS_TV_PAL 0 -#define OS_TV_NTSC 1 -#define OS_TV_MPAL 2 - -/* - * Video Interface (VI) mode type - */ -#define OS_VI_NTSC_LPN1 0 /* NTSC */ -#define OS_VI_NTSC_LPF1 1 -#define OS_VI_NTSC_LAN1 2 -#define OS_VI_NTSC_LAF1 3 -#define OS_VI_NTSC_LPN2 4 -#define OS_VI_NTSC_LPF2 5 -#define OS_VI_NTSC_LAN2 6 -#define OS_VI_NTSC_LAF2 7 -#define OS_VI_NTSC_HPN1 8 -#define OS_VI_NTSC_HPF1 9 -#define OS_VI_NTSC_HAN1 10 -#define OS_VI_NTSC_HAF1 11 -#define OS_VI_NTSC_HPN2 12 -#define OS_VI_NTSC_HPF2 13 - -#define OS_VI_PAL_LPN1 14 /* PAL */ -#define OS_VI_PAL_LPF1 15 -#define OS_VI_PAL_LAN1 16 -#define OS_VI_PAL_LAF1 17 -#define OS_VI_PAL_LPN2 18 -#define OS_VI_PAL_LPF2 19 -#define OS_VI_PAL_LAN2 20 -#define OS_VI_PAL_LAF2 21 -#define OS_VI_PAL_HPN1 22 -#define OS_VI_PAL_HPF1 23 -#define OS_VI_PAL_HAN1 24 -#define OS_VI_PAL_HAF1 25 -#define OS_VI_PAL_HPN2 26 -#define OS_VI_PAL_HPF2 27 - -#define OS_VI_MPAL_LPN1 28 /* MPAL - mainly Brazil */ -#define OS_VI_MPAL_LPF1 29 -#define OS_VI_MPAL_LAN1 30 -#define OS_VI_MPAL_LAF1 31 -#define OS_VI_MPAL_LPN2 32 -#define OS_VI_MPAL_LPF2 33 -#define OS_VI_MPAL_LAN2 34 -#define OS_VI_MPAL_LAF2 35 -#define OS_VI_MPAL_HPN1 36 -#define OS_VI_MPAL_HPF1 37 -#define OS_VI_MPAL_HAN1 38 -#define OS_VI_MPAL_HAF1 39 -#define OS_VI_MPAL_HPN2 40 -#define OS_VI_MPAL_HPF2 41 - -/* - * Video Interface (VI) special features - */ -#define OS_VI_GAMMA_ON 0x0001 -#define OS_VI_GAMMA_OFF 0x0002 -#define OS_VI_GAMMA_DITHER_ON 0x0004 -#define OS_VI_GAMMA_DITHER_OFF 0x0008 -#define OS_VI_DIVOT_ON 0x0010 -#define OS_VI_DIVOT_OFF 0x0020 -#define OS_VI_DITHER_FILTER_ON 0x0040 -#define OS_VI_DITHER_FILTER_OFF 0x0080 - -/* - * Video Interface (VI) mode attribute bit - */ -#define OS_VI_BIT_NONINTERLACE 0x0001 /* lo-res */ -#define OS_VI_BIT_INTERLACE 0x0002 /* lo-res */ -#define OS_VI_BIT_NORMALINTERLACE 0x0004 /* hi-res */ -#define OS_VI_BIT_DEFLICKINTERLACE 0x0008 /* hi-res */ -#define OS_VI_BIT_ANTIALIAS 0x0010 -#define OS_VI_BIT_POINTSAMPLE 0x0020 -#define OS_VI_BIT_16PIXEL 0x0040 -#define OS_VI_BIT_32PIXEL 0x0080 -#define OS_VI_BIT_LORES 0x0100 -#define OS_VI_BIT_HIRES 0x0200 -#define OS_VI_BIT_NTSC 0x0400 -#define OS_VI_BIT_PAL 0x0800 - /* * Leo Disk */ @@ -531,134 +91,6 @@ typedef struct { #define LEO_TRACK_MODE 2 #define LEO_SECTOR_MODE 3 -/* - * Controllers number - */ - -#ifndef _HW_VERSION_1 -#define MAXCONTROLLERS 4 -#else -#define MAXCONTROLLERS 6 -#endif - -/* controller errors */ -#define CONT_NO_RESPONSE_ERROR 0x8 -#define CONT_OVERRUN_ERROR 0x4 -#ifdef _HW_VERSION_1 -#define CONT_FRAME_ERROR 0x2 -#define CONT_COLLISION_ERROR 0x1 -#endif - -/* Controller type */ - -#define CONT_ABSOLUTE 0x0001 -#define CONT_RELATIVE 0x0002 -#define CONT_JOYPORT 0x0004 -#define CONT_EEPROM 0x8000 -#define CONT_EEP16K 0x4000 -#define CONT_TYPE_MASK 0x1f07 -#define CONT_TYPE_NORMAL 0x0005 -#define CONT_TYPE_MOUSE 0x0002 - -/* Controller status */ - -#define CONT_CARD_ON 0x01 -#define CONT_CARD_PULL 0x02 -#define CONT_ADDR_CRC_ER 0x04 -#define CONT_EEPROM_BUSY 0x80 - -/* EEPROM TYPE */ - -#define EEPROM_TYPE_4K 0x01 -#define EEPROM_TYPE_16K 0x02 - -/* Buttons */ - -#define CONT_A 0x8000 -#define CONT_B 0x4000 -#define CONT_G 0x2000 -#define CONT_START 0x1000 -#define CONT_UP 0x0800 -#define CONT_DOWN 0x0400 -#define CONT_LEFT 0x0200 -#define CONT_RIGHT 0x0100 -#define CONT_L 0x0020 -#define CONT_R 0x0010 -#define CONT_E 0x0008 -#define CONT_D 0x0004 -#define CONT_C 0x0002 -#define CONT_F 0x0001 - -/* Nintendo's official button names */ - -#define A_BUTTON CONT_A -#define B_BUTTON CONT_B -#define L_TRIG CONT_L -#define R_TRIG CONT_R -#define Z_TRIG CONT_G -#define START_BUTTON CONT_START -#define U_JPAD CONT_UP -#define L_JPAD CONT_LEFT -#define R_JPAD CONT_RIGHT -#define D_JPAD CONT_DOWN -#define U_CBUTTONS CONT_E -#define L_CBUTTONS CONT_C -#define R_CBUTTONS CONT_F -#define D_CBUTTONS CONT_D - -/* File System size */ -#define OS_PFS_VERSION 0x0200 -#define OS_PFS_VERSION_HI (OS_PFS_VERSION >> 8) -#define OS_PFS_VERSION_LO (OS_PFS_VERSION & 255) - -#define PFS_FILE_NAME_LEN 16 -#define PFS_FILE_EXT_LEN 4 -#define BLOCKSIZE 32 /* bytes */ -#define PFS_ONE_PAGE 8 /* blocks */ -#define PFS_MAX_BANKS 62 - -/* File System flag */ - -#define PFS_READ 0 -#define PFS_WRITE 1 -#define PFS_CREATE 2 - -/* File System status */ -#define PFS_INITIALIZED 0x1 -#define PFS_CORRUPTED 0x2 /* File system was corrupted */ - -/* File System error number */ - -#define PFS_ERR_NOPACK 1 /* no memory card is plugged or */ -#define PFS_ERR_NEW_PACK 2 /* ram pack has been changed to a */ - /* different one */ -#define PFS_ERR_INCONSISTENT 3 /* need to run Pfschecker */ -#define PFS_ERR_CONTRFAIL CONT_OVERRUN_ERROR -#define PFS_ERR_INVALID 5 /* invalid parameter or file not exist*/ -#define PFS_ERR_BAD_DATA 6 /* the data read from pack are bad*/ -#define PFS_DATA_FULL 7 /* no free pages on ram pack */ -#define PFS_DIR_FULL 8 /* no free directories on ram pack*/ -#define PFS_ERR_EXIST 9 /* file exists */ -#define PFS_ERR_ID_FATAL 10 /* dead ram pack */ -#define PFS_ERR_DEVICE 11 /* wrong device type*/ - -/* definition for EEPROM */ - -#define EEPROM_MAXBLOCKS 64 -#define EEP16K_MAXBLOCKS 256 -#define EEPROM_BLOCK_SIZE 8 - -/* - * PI/EPI - */ -#define PI_DOMAIN1 0 -#define PI_DOMAIN2 1 - -/* - * Profiler constants - */ -#define PROF_MIN_INTERVAL 50 /* microseconds */ - /* * Boot addresses */ @@ -667,331 +99,6 @@ typedef struct { #define BOOT_ADDRESS_EMU 0x20010000 #define BOOT_ADDRESS_INDY 0x88100000 -/* - * Size of buffer the retains contents after NMI - */ -#define OS_APP_NMI_BUFSIZE 64 - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - -/* PARTNER-N64 */ -#ifdef PTN64 -#define osReadHost osReadHost_pt -#define osWriteHost osWriteHost_pt -#endif - -/* Get count of valid messages in queue */ -#define MQ_GET_COUNT(mq) ((mq)->validCount) - -/* Figure out if message queue is empty or full */ -#define MQ_IS_EMPTY(mq) (MQ_GET_COUNT(mq) == 0) -#define MQ_IS_FULL(mq) (MQ_GET_COUNT(mq) >= (mq)->msgCount) - -/* - * CPU counter increments at 3/4 of bus clock rate: - * - * Bus Clock Proc Clock Counter (1/2 Proc Clock) - * --------- ---------- ------------------------ - * 62.5 Mhz 93.75 Mhz 46.875 Mhz - */ -extern u64 osClockRate; - -#define OS_CLOCK_RATE 62500000LL -#define OS_CPU_COUNTER (OS_CLOCK_RATE*3/4) -#define OS_NSEC_TO_CYCLES(n) (((u64)(n)*(OS_CPU_COUNTER/15625000LL))/(1000000000LL/15625000LL)) -#define OS_USEC_TO_CYCLES(n) (((u64)(n)*(OS_CPU_COUNTER/15625LL))/(1000000LL/15625LL)) -#define OS_CYCLES_TO_NSEC(c) (((u64)(c)*(1000000000LL/15625000LL))/(OS_CPU_COUNTER/15625000LL)) -#define OS_CYCLES_TO_USEC(c) (((u64)(c)*(1000000LL/15625LL))/(OS_CPU_COUNTER/15625LL)) - -/************************************************************************** - * - * Extern variables - * - */ -extern OSViMode osViModeTable[]; /* Global VI mode table */ - -extern OSViMode osViModeNtscLpn1; /* Individual VI NTSC modes */ -extern OSViMode osViModeNtscLpf1; -extern OSViMode osViModeNtscLan1; -extern OSViMode osViModeNtscLaf1; -extern OSViMode osViModeNtscLpn2; -extern OSViMode osViModeNtscLpf2; -extern OSViMode osViModeNtscLan2; -extern OSViMode osViModeNtscLaf2; -extern OSViMode osViModeNtscHpn1; -extern OSViMode osViModeNtscHpf1; -extern OSViMode osViModeNtscHan1; -extern OSViMode osViModeNtscHaf1; -extern OSViMode osViModeNtscHpn2; -extern OSViMode osViModeNtscHpf2; - -extern OSViMode osViModePalLpn1; /* Individual VI PAL modes */ -extern OSViMode osViModePalLpf1; -extern OSViMode osViModePalLan1; -extern OSViMode osViModePalLaf1; -extern OSViMode osViModePalLpn2; -extern OSViMode osViModePalLpf2; -extern OSViMode osViModePalLan2; -extern OSViMode osViModePalLaf2; -extern OSViMode osViModePalHpn1; -extern OSViMode osViModePalHpf1; -extern OSViMode osViModePalHan1; -extern OSViMode osViModePalHaf1; -extern OSViMode osViModePalHpn2; -extern OSViMode osViModePalHpf2; - -extern OSViMode osViModeMpalLpn1; /* Individual VI MPAL modes */ -extern OSViMode osViModeMpalLpf1; -extern OSViMode osViModeMpalLan1; -extern OSViMode osViModeMpalLaf1; -extern OSViMode osViModeMpalLpn2; -extern OSViMode osViModeMpalLpf2; -extern OSViMode osViModeMpalLan2; -extern OSViMode osViModeMpalLaf2; -extern OSViMode osViModeMpalHpn1; -extern OSViMode osViModeMpalHpf1; -extern OSViMode osViModeMpalHan1; -extern OSViMode osViModeMpalHaf1; -extern OSViMode osViModeMpalHpn2; -extern OSViMode osViModeMpalHpf2; - -extern s32 osRomType; /* Bulk or cartridge ROM. 0=cartridge 1=bulk */ -extern void *osRomBase; /* Rom base address of the game image */ -extern s32 osTvType; /* 0 = PAL, 1 = NTSC, 2 = MPAL */ -extern s32 osResetType; /* 0 = cold reset, 1 = NMI */ -extern s32 osCicId; -extern s32 osVersion; -extern u32 osMemSize; /* Memory Size */ -extern s32 osAppNMIBuffer[]; - -extern OSIntMask __OSGlobalIntMask; /* global interrupt mask */ -extern OSPiHandle *__osPiTable; /* The head of OSPiHandle link list */ -extern OSPiHandle *__osDiskHandle; /* For exceptasm to get disk info*/ - - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Thread operations */ - -extern void osCreateThread(OSThread *, OSId, void (*)(void *), - void *, void *, OSPri); -extern void osDestroyThread(OSThread *); -extern void osYieldThread(void); -extern void osStartThread(OSThread *); -extern void osStopThread(OSThread *); -extern OSId osGetThreadId(OSThread *); -extern void osSetThreadPri(OSThread *, OSPri); -extern OSPri osGetThreadPri(OSThread *); - -/* Message operations */ - -extern void osCreateMesgQueue(OSMesgQueue *, OSMesg *, s32); -extern s32 osSendMesg(OSMesgQueue *, OSMesg, s32); -extern s32 osJamMesg(OSMesgQueue *, OSMesg, s32); -extern s32 osRecvMesg(OSMesgQueue *, OSMesg *, s32); - -/* Event operations */ - -extern void osSetEventMesg(OSEvent, OSMesgQueue *, OSMesg); - -/* Interrupt operations */ - -extern OSIntMask osGetIntMask(void); -extern OSIntMask osSetIntMask(OSIntMask); - -/* RDB port operations */ - -extern void osInitRdb(u8 *sendBuf, u32 sendSize); - -/* Cache operations and macros */ - -extern void osInvalDCache(void *, s32); -extern void osInvalICache(void *, s32); -extern void osWritebackDCache(void *, s32); -extern void osWritebackDCacheAll(void); - -#define OS_DCACHE_ROUNDUP_ADDR(x) (void *)(((((u32)(x)+0xf)/0x10)*0x10)) -#define OS_DCACHE_ROUNDUP_SIZE(x) (u32)(((((u32)(x)+0xf)/0x10)*0x10)) - -/* TLB management routines */ - -extern void osMapTLB(s32, OSPageMask, void *, u32, u32, s32); -extern void osMapTLBRdb(void); -extern void osUnmapTLB(s32); -extern void osUnmapTLBAll(void); -extern void osSetTLBASID(s32); - -/* Address translation routines and macros */ - -extern u32 osVirtualToPhysical(void *); -extern void * osPhysicalToVirtual(u32); - -#define OS_K0_TO_PHYSICAL(x) (u32)(((char *)(x)-0x80000000)) -#define OS_K1_TO_PHYSICAL(x) (u32)(((char *)(x)-0xa0000000)) - -#define OS_PHYSICAL_TO_K0(x) (void *)(((u32)(x)+0x80000000)) -#define OS_PHYSICAL_TO_K1(x) (void *)(((u32)(x)+0xa0000000)) - -/* I/O operations */ - -/* Audio interface (Ai) */ -extern u32 osAiGetStatus(void); -extern u32 osAiGetLength(void); -extern s32 osAiSetFrequency(u32); -extern s32 osAiSetNextBuffer(void *, u32); - -/* Display processor interface (Dp) */ -extern u32 osDpGetStatus(void); -extern void osDpSetStatus(u32); -extern void osDpGetCounters(u32 *); -extern s32 osDpSetNextBuffer(void *, u64); - -/* Peripheral interface (Pi) */ -extern u32 osPiGetStatus(void); -extern s32 osPiGetDeviceType(void); -extern s32 osPiRawWriteIo(u32, u32); -extern s32 osPiRawReadIo(u32, u32 *); -extern s32 osPiRawStartDma(s32, u32, void *, u32); -extern s32 osPiWriteIo(u32, u32); -extern s32 osPiReadIo(u32, u32 *); -extern s32 osPiStartDma(OSIoMesg *, s32, s32, u32, void *, u32, - OSMesgQueue *); -extern void osCreatePiManager(OSPri, OSMesgQueue *, OSMesg *, s32); - -/* Video interface (Vi) */ -extern u32 osViGetStatus(void); -extern u32 osViGetCurrentMode(void); -extern u32 osViGetCurrentLine(void); -extern u32 osViGetCurrentField(void); -extern void *osViGetCurrentFramebuffer(void); -extern void *osViGetNextFramebuffer(void); -extern void osViSetXScale(f32); -extern void osViSetYScale(f32); -extern void osViSetSpecialFeatures(u32); -extern void osViSetMode(OSViMode *); -extern void osViSetEvent(OSMesgQueue *, OSMesg, u32); -extern void osViSwapBuffer(void *); -extern void osViBlack(u8); -extern void osViFade(u8, u16); -extern void osViRepeatLine(u8); -extern void osCreateViManager(OSPri); - -/* Timer interface */ - -extern OSTime osGetTime(void); -extern void osSetTime(OSTime); -extern int osSetTimer(OSTimer *, OSTime, OSTime, - OSMesgQueue *, OSMesg); -extern int osStopTimer(OSTimer *); - -/* Controller interface */ - -extern s32 osContInit(OSMesgQueue *, u8 *, OSContStatus *); -extern s32 osContReset(OSMesgQueue *, OSContStatus *); -extern s32 osContStartQuery(OSMesgQueue *); -extern s32 osContStartReadData(OSMesgQueue *); -#ifndef _HW_VERSION_1 -extern s32 osContSetCh(u8); -#endif -extern void osContGetQuery(OSContStatus *); -extern void osContGetReadData(OSContPad *); - -/* file system interface */ - -extern s32 osPfsInitPak(OSMesgQueue *, OSPfs *, int); -extern s32 osPfsRepairId(OSPfs *); -extern s32 osPfsInit(OSMesgQueue *, OSPfs *, int); -extern s32 osPfsReFormat(OSPfs *, OSMesgQueue *, int); -extern s32 osPfsChecker(OSPfs *); -extern s32 osPfsAllocateFile(OSPfs *, u16, u32, u8 *, u8 *, int, s32 *); -extern s32 osPfsFindFile(OSPfs *, u16, u32, u8 *, u8 *, s32 *); -extern s32 osPfsDeleteFile(OSPfs *, u16, u32, u8 *, u8 *); -extern s32 osPfsReadWriteFile(OSPfs *, s32, u8, int, int, u8 *); -extern s32 osPfsFileState(OSPfs *, s32, OSPfsState *); -extern s32 osPfsGetLabel(OSPfs *, u8 *, int *); -extern s32 osPfsSetLabel(OSPfs *, u8 *); -extern s32 osPfsIsPlug(OSMesgQueue *, u8 *); -extern s32 osPfsFreeBlocks(OSPfs *, s32 *); -extern s32 osPfsNumFiles(OSPfs *, s32 *, s32 *); - -/* EEPROM interface */ - -extern s32 osEepromProbe(OSMesgQueue *); -extern s32 osEepromRead(OSMesgQueue *, u8, u8 *); -extern s32 osEepromWrite(OSMesgQueue *, u8, u8 *); -extern s32 osEepromLongRead(OSMesgQueue *, u8, u8 *, int); -extern s32 osEepromLongWrite(OSMesgQueue *, u8, u8 *, int); - -/* MOTOR interface */ - -extern s32 osMotorInit(OSMesgQueue *, OSPfs *, int); -extern s32 osMotorStop(OSPfs *); -extern s32 osMotorStart(OSPfs *); - -/* Enhanced PI interface */ - -extern OSPiHandle *osCartRomInit(void); -extern OSPiHandle *osLeoDiskInit(void); -extern OSPiHandle *osDriveRomInit(void); - -extern s32 osEPiDeviceType(OSPiHandle *, OSPiInfo *); -extern s32 osEPiRawWriteIo(OSPiHandle *, u32 , u32); -extern s32 osEPiRawReadIo(OSPiHandle *, u32 , u32 *); -extern s32 osEPiRawStartDma(OSPiHandle *, s32 , u32 , void *, u32 ); -extern s32 osEPiWriteIo(OSPiHandle *, u32 , u32 ); -extern s32 osEPiReadIo(OSPiHandle *, u32 , u32 *); -extern s32 osEPiStartDma(OSPiHandle *, OSIoMesg *, s32); -extern s32 osEPiLinkHandle(OSPiHandle *); - -/* Profiler Interface */ - -extern void osProfileInit(OSProf *, u32 profcnt); -extern void osProfileStart(u32); -extern void osProfileFlush(void); -extern void osProfileStop(void); - -/* Game <> Host data transfer functions */ - -extern s32 osTestHost(void); -extern void osReadHost(void *, u32); -extern void osWriteHost(void *, u32); -extern void osAckRamromRead(void); -extern void osAckRamromWrite(void); - - -/* byte string operations */ - -extern void bcopy(const void *, void *, int); -extern int bcmp(const void *, const void *, int); -extern void bzero(void *, int); - -/* Miscellaneous operations */ - -extern void osInitialize(void); -extern u32 osGetCount(void); -extern void osExit(void); -extern u32 osGetMemSize(void); - -/* Printf */ - -extern int sprintf(char *s, const char *fmt, ...); -extern void osSyncPrintf(const char *fmt, ...); -extern void osAsyncPrintf(const char *fmt, ...); -extern int osSyncGetChars(char *buf); -extern int osAsyncGetChars(char *buf); - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ #ifdef _LANGUAGE_C_PLUS_PLUS } diff --git a/include/PR/os_ai.h b/include/PR/os_ai.h new file mode 100644 index 0000000..f89d87c --- /dev/null +++ b/include/PR/os_ai.h @@ -0,0 +1,92 @@ + +/*==================================================================== + * os_ai.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_ai.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:04 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_AI_H_ +#define _OS_AI_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Audio interface (Ai) */ +extern u32 osAiGetStatus(void); +extern u32 osAiGetLength(void); +extern s32 osAiSetFrequency(u32); +extern s32 osAiSetNextBuffer(void *, u32); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_AI_H_ */ diff --git a/include/PR/os_cache.h b/include/PR/os_cache.h new file mode 100644 index 0000000..54ed923 --- /dev/null +++ b/include/PR/os_cache.h @@ -0,0 +1,96 @@ + +/*==================================================================== + * os_cache.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_cache.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:04 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_CACHE_H_ +#define _OS_CACHE_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +#define OS_DCACHE_ROUNDUP_ADDR(x) (void *)(((((u32)(x)+0xf)/0x10)*0x10)) +#define OS_DCACHE_ROUNDUP_SIZE(x) (u32)(((((u32)(x)+0xf)/0x10)*0x10)) + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Cache operations and macros */ + +extern void osInvalDCache(void *, s32); +extern void osInvalICache(void *, s32); +extern void osWritebackDCache(void *, s32); +extern void osWritebackDCacheAll(void); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_CACHE_H_ */ diff --git a/include/PR/os_cont.h b/include/PR/os_cont.h new file mode 100644 index 0000000..2754f25 --- /dev/null +++ b/include/PR/os_cont.h @@ -0,0 +1,207 @@ + +/*==================================================================== + * os_cont.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_cont.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:05 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_CONT_H_ +#define _OS_CONT_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for controllers + */ + +typedef struct { + u16 type; /* Controller Type */ + u8 status; /* Controller status */ + u8 errno; +}OSContStatus; + +typedef struct { + u16 button; + s8 stick_x; /* -80 <= stick_x <= 80 */ + s8 stick_y; /* -80 <= stick_y <= 80 */ + u8 errno; +} OSContPad; + +typedef struct { + void *address; /* Ram pad Address: 11 bits */ + u8 databuffer[32]; /* address of the data buffer */ + u8 addressCrc; /* CRC code for address */ + u8 dataCrc; /* CRC code for data */ + u8 errno; +} OSContRamIo; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Controllers number + */ + +#ifndef _HW_VERSION_1 +#define MAXCONTROLLERS 4 +#else +#define MAXCONTROLLERS 6 +#endif + +/* controller errors */ +#define CONT_NO_RESPONSE_ERROR 0x8 +#define CONT_OVERRUN_ERROR 0x4 +#ifdef _HW_VERSION_1 +#define CONT_FRAME_ERROR 0x2 +#define CONT_COLLISION_ERROR 0x1 +#endif + +/* Controller type */ + +#define CONT_ABSOLUTE 0x0001 +#define CONT_RELATIVE 0x0002 +#define CONT_JOYPORT 0x0004 +#define CONT_EEPROM 0x8000 +#define CONT_EEP16K 0x4000 +#define CONT_TYPE_MASK 0x1f07 +#define CONT_TYPE_NORMAL 0x0005 +#define CONT_TYPE_MOUSE 0x0002 +#define CONT_TYPE_VOICE 0x0100 + +/* Controller status */ + +#define CONT_CARD_ON 0x01 +#define CONT_CARD_PULL 0x02 +#define CONT_ADDR_CRC_ER 0x04 +#define CONT_EEPROM_BUSY 0x80 + +/* Buttons */ + +#define CONT_A 0x8000 +#define CONT_B 0x4000 +#define CONT_G 0x2000 +#define CONT_START 0x1000 +#define CONT_UP 0x0800 +#define CONT_DOWN 0x0400 +#define CONT_LEFT 0x0200 +#define CONT_RIGHT 0x0100 +#define CONT_L 0x0020 +#define CONT_R 0x0010 +#define CONT_E 0x0008 +#define CONT_D 0x0004 +#define CONT_C 0x0002 +#define CONT_F 0x0001 + +/* Nintendo's official button names */ + +#define A_BUTTON CONT_A +#define B_BUTTON CONT_B +#define L_TRIG CONT_L +#define R_TRIG CONT_R +#define Z_TRIG CONT_G +#define START_BUTTON CONT_START +#define U_JPAD CONT_UP +#define L_JPAD CONT_LEFT +#define R_JPAD CONT_RIGHT +#define D_JPAD CONT_DOWN +#define U_CBUTTONS CONT_E +#define L_CBUTTONS CONT_C +#define R_CBUTTONS CONT_F +#define D_CBUTTONS CONT_D + +/* Controller error number */ + +#define CONT_ERR_NO_CONTROLLER PFS_ERR_NOPACK /* 1 */ +#define CONT_ERR_CONTRFAIL CONT_OVERRUN_ERROR /* 4 */ +#define CONT_ERR_INVALID PFS_ERR_INVALID /* 5 */ +#define CONT_ERR_DEVICE PFS_ERR_DEVICE /* 11 */ +#define CONT_ERR_NOT_READY 12 +#define CONT_ERR_VOICE_MEMORY 13 +#define CONT_ERR_VOICE_WORD 14 +#define CONT_ERR_VOICE_NO_RESPONSE 15 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Controller interface */ + +extern s32 osContInit(OSMesgQueue *, u8 *, OSContStatus *); +extern s32 osContReset(OSMesgQueue *, OSContStatus *); +extern s32 osContStartQuery(OSMesgQueue *); +extern s32 osContStartReadData(OSMesgQueue *); +#ifndef _HW_VERSION_1 +extern s32 osContSetCh(u8); +#endif +extern void osContGetQuery(OSContStatus *); +extern void osContGetReadData(OSContPad *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_CONT_H_ */ diff --git a/include/PR/os_convert.h b/include/PR/os_convert.h new file mode 100644 index 0000000..4be88b5 --- /dev/null +++ b/include/PR/os_convert.h @@ -0,0 +1,105 @@ + +/*==================================================================== + * os_convert.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_convert.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:05 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_CONVERT_H_ +#define _OS_CONVERT_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +#define OS_CLOCK_RATE 62500000LL +#define OS_CPU_COUNTER (OS_CLOCK_RATE*3/4) + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +#define OS_NSEC_TO_CYCLES(n) (((u64)(n)*(OS_CPU_COUNTER/15625000LL))/(1000000000LL/15625000LL)) +#define OS_USEC_TO_CYCLES(n) (((u64)(n)*(OS_CPU_COUNTER/15625LL))/(1000000LL/15625LL)) +#define OS_CYCLES_TO_NSEC(c) (((u64)(c)*(1000000000LL/15625000LL))/(OS_CPU_COUNTER/15625000LL)) +#define OS_CYCLES_TO_USEC(c) (((u64)(c)*(1000000LL/15625LL))/(OS_CPU_COUNTER/15625LL)) + +#define OS_K0_TO_PHYSICAL(x) (u32)(((char *)(x)-0x80000000)) +#define OS_K1_TO_PHYSICAL(x) (u32)(((char *)(x)-0xa0000000)) + +#define OS_PHYSICAL_TO_K0(x) (void *)(((u32)(x)+0x80000000)) +#define OS_PHYSICAL_TO_K1(x) (void *)(((u32)(x)+0xa0000000)) + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Address translation routines and macros */ + +extern u32 osVirtualToPhysical(void *); +extern void * osPhysicalToVirtual(u32); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_CONVERT_H_ */ diff --git a/include/PR/os_debug.h b/include/PR/os_debug.h new file mode 100644 index 0000000..5b13d8c --- /dev/null +++ b/include/PR/os_debug.h @@ -0,0 +1,108 @@ + +/*==================================================================== + * os_debug.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_debug.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:06 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_DEBUG_H_ +#define _OS_DEBUG_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for Profiler + */ +typedef struct { + u16 *histo_base; /* histogram base */ + u32 histo_size; /* histogram size */ + u32 *text_start; /* start of text segment */ + u32 *text_end; /* end of text segment */ +} OSProf; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Profiler constants + */ +#define PROF_MIN_INTERVAL 50 /* microseconds */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Profiler Interface */ + +extern void osProfileInit(OSProf *, u32 profcnt); +extern void osProfileStart(u32); +extern void osProfileFlush(void); +extern void osProfileStop(void); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_DEBUG_H_ */ diff --git a/include/PR/os_eeprom.h b/include/PR/os_eeprom.h new file mode 100644 index 0000000..b3bca81 --- /dev/null +++ b/include/PR/os_eeprom.h @@ -0,0 +1,107 @@ + +/*==================================================================== + * os_eeprom.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_eeprom.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:06 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_EEPROM_H_ +#define _OS_EEPROM_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* EEPROM TYPE */ + +#define EEPROM_TYPE_4K 0x01 +#define EEPROM_TYPE_16K 0x02 + +/* definition for EEPROM */ + +#define EEPROM_MAXBLOCKS 64 +#define EEP16K_MAXBLOCKS 256 +#define EEPROM_BLOCK_SIZE 8 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* EEPROM interface */ + +extern s32 osEepromProbe(OSMesgQueue *); +extern s32 osEepromRead(OSMesgQueue *, u8, u8 *); +extern s32 osEepromWrite(OSMesgQueue *, u8, u8 *); +extern s32 osEepromLongRead(OSMesgQueue *, u8, u8 *, int); +extern s32 osEepromLongWrite(OSMesgQueue *, u8, u8 *, int); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_EEPROM_H_ */ diff --git a/include/PR/os_error.h b/include/PR/os_error.h new file mode 100644 index 0000000..f4c3b83 --- /dev/null +++ b/include/PR/os_error.h @@ -0,0 +1,86 @@ + +/*==================================================================== + * os_error.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_error.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:06 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_ERROR_H_ +#define _OS_ERROR_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_ERROR_H_ */ diff --git a/include/PR/os_exception.h b/include/PR/os_exception.h new file mode 100644 index 0000000..2457bde --- /dev/null +++ b/include/PR/os_exception.h @@ -0,0 +1,86 @@ + +/*==================================================================== + * os_exception.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_exception.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:07 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_EXCEPTION_H_ +#define _OS_EXCEPTION_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include "ultratypes.h" + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +typedef u32 OSIntMask; +typedef u32 OSHWIntr; + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/* Flags for debugging purpose */ + +#define OS_FLAG_CPU_BREAK 1 /* Break exception has occurred */ +#define OS_FLAG_FAULT 2 /* CPU fault has occurred */ + +/* Interrupt masks */ + +#define OS_IM_NONE 0x00000001 +#define OS_IM_RCP 0x00000401 +#define OS_IM_SW1 0x00000501 +#define OS_IM_SW2 0x00000601 +#define OS_IM_CART 0x00000c01 +#define OS_IM_PRENMI 0x00001401 +#define OS_IM_RDBWRITE 0x00002401 +#define OS_IM_RDBREAD 0x00004401 +#define OS_IM_COUNTER 0x00008401 +#define OS_IM_CPU 0x0000ff01 +#define OS_IM_SP 0x00010401 +#define OS_IM_SI 0x00020401 +#define OS_IM_AI 0x00040401 +#define OS_IM_VI 0x00080401 +#define OS_IM_PI 0x00100401 +#define OS_IM_DP 0x00200401 +#define OS_IM_ALL 0x003fff01 +#define RCP_IMASK 0x003f0000 +#define RCP_IMASKSHIFT 16 + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Interrupt operations */ + +extern OSIntMask osGetIntMask(void); +extern OSIntMask osSetIntMask(OSIntMask); + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_EXCEPTION_H_ */ diff --git a/include/PR/os_gbpak.h b/include/PR/os_gbpak.h new file mode 100644 index 0000000..0a99994 --- /dev/null +++ b/include/PR/os_gbpak.h @@ -0,0 +1,107 @@ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_gbpak.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:07 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_GBPAK_H_ +#define _OS_GBPAK_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" +#include "os_pfs.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef struct { + u16 fixed1; + u16 start_address; + u8 nintendo_chr[0x30]; + u8 game_title[16]; + u16 company_code; + u8 body_code; + u8 cart_type; + u8 rom_size; + u8 ram_size; + u8 country_code; + u8 fixed2; + u8 version; + u8 isum; + u16 sum; +} OSGbpakId; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* definition for 64GB-PAK */ + +#define OS_GBPAK_POWER 0x01 +#define OS_GBPAK_RSTB_DETECTION 0x04 +#define OS_GBPAK_RSTB_STATUS 0x08 +#define OS_GBPAK_GBCART_PULL 0x40 +#define OS_GBPAK_GBCART_ON 0x80 + +#define OS_GBPAK_POWER_OFF 0x00 /* power of 64GB-PAK */ +#define OS_GBPAK_POWER_ON 0x01 + +#define OS_GBPAK_ROM_ID_SIZE 0x50 /* ID size of GB cartridge */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* 64GB-PAK */ +extern s32 osGbpakInit(OSMesgQueue *, OSPfs *, int); +extern s32 osGbpakPower(OSPfs *, s32); +extern s32 osGbpakGetStatus(OSPfs *, u8 *); +extern s32 osGbpakReadWrite(OSPfs *, u16, u16, u8 *, u16); +extern s32 osGbpakReadId(OSPfs *, OSGbpakId *, u8 *); +extern s32 osGbpakCheckConnector(OSPfs *, u8 *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_GBPAK_H_ */ diff --git a/include/PR/os_gio.h b/include/PR/os_gio.h new file mode 100644 index 0000000..ad3c020 --- /dev/null +++ b/include/PR/os_gio.h @@ -0,0 +1,86 @@ + +/*==================================================================== + * os_gio.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_gio.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:08 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_GIO_H_ +#define _OS_GIO_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_GIO_H_ */ diff --git a/include/PR/os_host.h b/include/PR/os_host.h new file mode 100644 index 0000000..1191189 --- /dev/null +++ b/include/PR/os_host.h @@ -0,0 +1,104 @@ + +/*==================================================================== + * os_host.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_host.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:08 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_HOST_H_ +#define _OS_HOST_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +/* PARTNER-N64 */ +#ifdef PTN64 +#define osReadHost osReadHost_pt +#define osWriteHost osWriteHost_pt +#endif + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Game <> Host data transfer functions */ + +extern s32 osTestHost(void); +extern void osReadHost(void *, u32); +extern void osWriteHost(void *, u32); +extern void osAckRamromRead(void); +extern void osAckRamromWrite(void); + +/* RDB port operations */ + +extern void osInitRdb(u8 *sendBuf, u32 sendSize); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_HOST_H_ */ diff --git a/include/PR/os_internal.h b/include/PR/os_internal.h index 544eb32..754d1ee 100644 --- a/include/PR/os_internal.h +++ b/include/PR/os_internal.h @@ -10,13 +10,13 @@ * * **************************************************************************/ -/************************************************************************** - * - * $Revision: 1.18 $ - * $Date: 1997/02/11 08:26:14 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/os_internal.h,v $ - * - **************************************************************************/ +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal.h,v $ + $Revision: 1.20 $ + $Date: 1998/10/09 08:01:09 $ + *---------------------------------------------------------------------*/ #ifndef _OS_INTERNAL_H_ #define _OS_INTERNAL_H_ @@ -29,85 +29,16 @@ extern "C" { #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) -/* Routines to get/fetch coprocessor 0 registers */ - -extern u32 __osGetCause(void); -extern void __osSetCause(u32); -extern u32 __osGetCompare(void); -extern void __osSetCompare(u32); -extern u32 __osGetConfig(void); -extern void __osSetConfig(u32); -extern void __osSetCount(u32); -extern u32 __osGetSR(void); -extern void __osSetSR(u32); -extern u32 __osDisableInt(void); -extern void __osRestoreInt(u32); - -/* Routines to get/set floating-point control and status register */ -extern u32 __osSetFpcCsr(u32); -extern u32 __osGetFpcCsr(void); - -/* Routine for HW interrupt "handler" */ -extern void __osSetHWIntrRoutine(OSHWIntr, s32 (*handler)(void)); - -/* Routine for global interrupt mask */ -extern void __osSetGlobalIntMask(OSHWIntr); -extern void __osResetGlobalIntMask(OSHWIntr); - -/* Routine for global interrupt mask */ -extern s32 __osLeoInterrupt(void); - -/* Routines for fetch TLB info */ - -extern u32 __osGetTLBASID(void); -extern u32 __osGetTLBPageMask(s32); -extern u32 __osGetTLBHi(s32); -extern u32 __osGetTLBLo0(s32); -extern u32 __osGetTLBLo1(s32); - -/* Serial interface (Si) */ - -extern u32 __osSiGetStatus(void); -extern s32 __osSiRawWriteIo(u32, u32); -extern s32 __osSiRawReadIo(u32, u32 *); -extern s32 __osSiRawStartDma(s32, void *); - -/* Signal processor interface (Sp) */ - -extern u32 __osSpGetStatus(void); -extern void __osSpSetStatus(u32); -extern s32 __osSpSetPc(u32); -extern s32 __osSpRawWriteIo(u32, u32); -extern s32 __osSpRawReadIo(u32, u32 *); -extern s32 __osSpRawStartDma(s32, u32, void *, u32); - -/* Error handling */ - -extern void __osError(s16, s16, ...); -extern OSThread * __osGetCurrFaultedThread(void); -extern OSThread * __osGetNextFaultedThread(OSThread *); - -/* Development board functions */ - -extern void __osGIOInit(s32); -extern void __osGIOInterrupt(s32); -extern void __osGIORawInterrupt(s32); - -/* For debugger use */ - -extern OSThread * __osGetActiveQueue(void); - -/* Debug port */ -extern void __osSyncPutChars(int, int, const char *); -extern int __osSyncGetChars(char *); -extern void __osAsyncPutChars(int, int, const char *); -extern int __osAsyncGetChars(char *); -extern int __osAtomicInc(unsigned int *p); -extern int __osAtomicDec(unsigned int *p); - -/* routine for rdb port */ -extern u32 __osRdbSend(u8 *buf, u32 size, u32 type); - +#include "os_internal_reg.h" +#include "os_internal_exception.h" +#include "os_internal_tlb.h" +#include "os_internal_si.h" +#include "os_internal_rsp.h" +#include "os_internal_error.h" +#include "os_internal_gio.h" +#include "os_internal_thread.h" +#include "os_internal_debug.h" +#include "os_internal_host.h" #endif /* _LANGUAGE_C */ diff --git a/include/PR/os_internal_debug.h b/include/PR/os_internal_debug.h new file mode 100644 index 0000000..7b307d6 --- /dev/null +++ b/include/PR/os_internal_debug.h @@ -0,0 +1,43 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_debug.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:09 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_DEBUG_H_ +#define _OS_INTERNAL_DEBUG_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Debug port */ +extern void __osSyncPutChars(int, int, const char *); +extern int __osAtomicDec(unsigned int *p); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_DEBUG_H */ diff --git a/include/PR/os_internal_error.h b/include/PR/os_internal_error.h new file mode 100644 index 0000000..de188d2 --- /dev/null +++ b/include/PR/os_internal_error.h @@ -0,0 +1,45 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_error.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:10 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_ERROR_H_ +#define _OS_INTERNAL_ERROR_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Error handling */ + +extern void __osError(s16, s16, ...); +extern OSThread * __osGetCurrFaultedThread(void); +extern OSThread * __osGetNextFaultedThread(OSThread *); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_ERROR_H */ diff --git a/include/PR/os_internal_exception.h b/include/PR/os_internal_exception.h new file mode 100644 index 0000000..730dc93 --- /dev/null +++ b/include/PR/os_internal_exception.h @@ -0,0 +1,49 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_exception.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:10 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_EXCEPTION_H_ +#define _OS_INTERNAL_EXCEPTION_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Routine for HW interrupt "handler" */ +extern void __osSetHWIntrRoutine(OSHWIntr interrupt, + s32 (*handler)(void), void *stackEnd); +extern void __osGetHWIntrRoutine(OSHWIntr interrupt, + s32 (**handler)(void), void **stackEnd); + +/* Routine for global interrupt mask */ +extern void __osSetGlobalIntMask(OSHWIntr); +extern void __osResetGlobalIntMask(OSHWIntr); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_EXCEPTION_H */ diff --git a/include/PR/os_internal_gio.h b/include/PR/os_internal_gio.h new file mode 100644 index 0000000..ff13385 --- /dev/null +++ b/include/PR/os_internal_gio.h @@ -0,0 +1,45 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_gio.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:11 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_GIO_H_ +#define _OS_INTERNAL_GIO_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Development board functions */ + +extern void __osGIOInit(s32); +extern void __osGIOInterrupt(s32); +extern void __osGIORawInterrupt(s32); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_GIO_H */ diff --git a/include/PR/os_internal_host.h b/include/PR/os_internal_host.h new file mode 100644 index 0000000..b6d1951 --- /dev/null +++ b/include/PR/os_internal_host.h @@ -0,0 +1,42 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_host.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:11 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_HOST_H_ +#define _OS_INTERNAL_HOST_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* routine for rdb port */ +extern u32 __osRdbSend(u8 *buf, u32 size, u32 type); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_HOST_H */ diff --git a/include/PR/os_internal_reg.h b/include/PR/os_internal_reg.h new file mode 100644 index 0000000..d78fa5e --- /dev/null +++ b/include/PR/os_internal_reg.h @@ -0,0 +1,57 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_reg.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:12 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_REG_H_ +#define _OS_INTERNAL_REG_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Routines to get/fetch coprocessor 0 registers */ + +extern u32 __osGetCause(void); +extern void __osSetCause(u32); +extern u32 __osGetCompare(void); +extern void __osSetCompare(u32); +extern u32 __osGetConfig(void); +extern void __osSetConfig(u32); +extern void __osSetCount(u32); +extern u32 __osGetSR(void); +extern void __osSetSR(u32); +extern u32 __osDisableInt(void); +extern void __osRestoreInt(u32); + +/* Routines to get/set floating-point control and status register */ +extern u32 __osSetFpcCsr(u32); +extern u32 __osGetFpcCsr(void); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_REG_H */ diff --git a/include/PR/os_internal_rsp.h b/include/PR/os_internal_rsp.h new file mode 100644 index 0000000..646e667 --- /dev/null +++ b/include/PR/os_internal_rsp.h @@ -0,0 +1,48 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_rsp.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:12 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_RSP_H_ +#define _OS_INTERNAL_RSP_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Signal processor interface (Sp) */ + +extern u32 __osSpGetStatus(void); +extern void __osSpSetStatus(u32); +extern s32 __osSpSetPc(u32); +extern s32 __osSpRawWriteIo(u32, u32); +extern s32 __osSpRawReadIo(u32, u32 *); +extern s32 __osSpRawStartDma(s32, u32, void *, u32); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_RSP_H */ diff --git a/include/PR/os_internal_si.h b/include/PR/os_internal_si.h new file mode 100644 index 0000000..d0eeedc --- /dev/null +++ b/include/PR/os_internal_si.h @@ -0,0 +1,46 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_si.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:13 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_SI_H_ +#define _OS_INTERNAL_SI_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Serial interface (Si) */ + +extern u32 __osSiGetStatus(void); +extern s32 __osSiRawWriteIo(u32, u32); +extern s32 __osSiRawReadIo(u32, u32 *); +extern s32 __osSiRawStartDma(s32, void *); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_SI_H */ diff --git a/include/PR/os_internal_thread.h b/include/PR/os_internal_thread.h new file mode 100644 index 0000000..1305eb5 --- /dev/null +++ b/include/PR/os_internal_thread.h @@ -0,0 +1,43 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_thread.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:13 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_THREAD_H_ +#define _OS_INTERNAL_THREAD_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* For debugger use */ + +extern OSThread * __osGetActiveQueue(void); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_THREAD_H */ diff --git a/include/PR/os_internal_tlb.h b/include/PR/os_internal_tlb.h new file mode 100644 index 0000000..b92918f --- /dev/null +++ b/include/PR/os_internal_tlb.h @@ -0,0 +1,47 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_internal_tlb.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:14 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_TLB_H_ +#define _OS_INTERNAL_TLB_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Routines for fetch TLB info */ + +extern u32 __osGetTLBASID(void); +extern u32 __osGetTLBPageMask(s32); +extern u32 __osGetTLBHi(s32); +extern u32 __osGetTLBLo0(s32); +extern u32 __osGetTLBLo1(s32); + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_INTERNAL_TLB_H */ diff --git a/include/PR/os_libc.h b/include/PR/os_libc.h new file mode 100644 index 0000000..e210f87 --- /dev/null +++ b/include/PR/os_libc.h @@ -0,0 +1,99 @@ + +/*==================================================================== + * os_libc.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_libc.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:14 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_LIBC_H_ +#define _OS_LIBC_H_ + +#include "os_pfs.h" + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* byte string operations */ + +extern void bcopy(const void *, void *, int); +extern int bcmp(const void *, const void *, int); +extern void bzero(void *, int); + +/* Printf */ + +extern int sprintf(char *s, const char *fmt, ...); +extern void osSyncPrintf(const char *fmt, ...); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_LIBC_H_ */ diff --git a/include/PR/os_message.h b/include/PR/os_message.h new file mode 100644 index 0000000..5bc565e --- /dev/null +++ b/include/PR/os_message.h @@ -0,0 +1,163 @@ + +/*==================================================================== + * os_message.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_message.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:15 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_MESSAGE_H_ +#define _OS_MESSAGE_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef u32 OSEvent; + +/* + * Structure for message + */ +typedef void * OSMesg; + +/* + * Structure for message queue + */ +typedef struct OSMesgQueue_s { + OSThread *mtqueue; /* Queue to store threads blocked + on empty mailboxes (receive) */ + OSThread *fullqueue; /* Queue to store threads blocked + on full mailboxes (send) */ + s32 validCount; /* Contains number of valid message */ + s32 first; /* Points to first valid message */ + s32 msgCount; /* Contains total # of messages */ + OSMesg *msg; /* Points to message buffer array */ +} OSMesgQueue; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* Events */ +#ifdef _FINALROM +#define OS_NUM_EVENTS 15 +#else +#define OS_NUM_EVENTS 23 +#endif + +#define OS_EVENT_SW1 0 /* CPU SW1 interrupt */ +#define OS_EVENT_SW2 1 /* CPU SW2 interrupt */ +#define OS_EVENT_CART 2 /* Cartridge interrupt: used by rmon */ +#define OS_EVENT_COUNTER 3 /* Counter int: used by VI/Timer Mgr */ +#define OS_EVENT_SP 4 /* SP task done interrupt */ +#define OS_EVENT_SI 5 /* SI (controller) interrupt */ +#define OS_EVENT_AI 6 /* AI interrupt */ +#define OS_EVENT_VI 7 /* VI interrupt: used by VI/Timer Mgr */ +#define OS_EVENT_PI 8 /* PI interrupt: used by PI Manager */ +#define OS_EVENT_DP 9 /* DP full sync interrupt */ +#define OS_EVENT_CPU_BREAK 10 /* CPU breakpoint: used by rmon */ +#define OS_EVENT_SP_BREAK 11 /* SP breakpoint: used by rmon */ +#define OS_EVENT_FAULT 12 /* CPU fault event: used by rmon */ +#define OS_EVENT_THREADSTATUS 13 /* CPU thread status: used by rmon */ +#define OS_EVENT_PRENMI 14 /* Pre NMI interrupt */ +#ifndef _FINALROM +#define OS_EVENT_RDB_READ_DONE 15 /* RDB read ok event: used by rmon */ +#define OS_EVENT_RDB_LOG_DONE 16 /* read of log data complete */ +#define OS_EVENT_RDB_DATA_DONE 17 /* read of hostio data complete */ +#define OS_EVENT_RDB_REQ_RAMROM 18 /* host needs ramrom access */ +#define OS_EVENT_RDB_FREE_RAMROM 19 /* host is done with ramrom access */ +#define OS_EVENT_RDB_DBG_DONE 20 +#define OS_EVENT_RDB_FLUSH_PROF 21 +#define OS_EVENT_RDB_ACK_PROF 22 +#endif + +/* Flags to turn blocking on/off when sending/receiving message */ + +#define OS_MESG_NOBLOCK 0 +#define OS_MESG_BLOCK 1 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +/* Get count of valid messages in queue */ +#define MQ_GET_COUNT(mq) ((mq)->validCount) + +/* Figure out if message queue is empty or full */ +#define MQ_IS_EMPTY(mq) (MQ_GET_COUNT(mq) == 0) +#define MQ_IS_FULL(mq) (MQ_GET_COUNT(mq) >= (mq)->msgCount) + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Message operations */ + +extern void osCreateMesgQueue(OSMesgQueue *, OSMesg *, s32); +extern s32 osSendMesg(OSMesgQueue *, OSMesg, s32); +extern s32 osJamMesg(OSMesgQueue *, OSMesg, s32); +extern s32 osRecvMesg(OSMesgQueue *, OSMesg *, s32); + +/* Event operations */ + +extern void osSetEventMesg(OSEvent, OSMesgQueue *, OSMesg); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_MESSAGE_H_ */ diff --git a/include/PR/os_motor.h b/include/PR/os_motor.h new file mode 100644 index 0000000..f8dcbd5 --- /dev/null +++ b/include/PR/os_motor.h @@ -0,0 +1,83 @@ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_motor.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:15 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_MOTOR_H_ +#define _OS_MOTOR_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" +#include "os_pfs.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Rumble PAK interface */ + +extern s32 osMotorInit(OSMesgQueue *, OSPfs *, int); +#if 1 +#define MOTOR_START 1 +#define MOTOR_STOP 0 +#define osMotorStart(x) __osMotorAccess((x), MOTOR_START) +#define osMotorStop(x) __osMotorAccess((x), MOTOR_STOP) +extern s32 __osMotorAccess(OSPfs *, s32); +#else +extern s32 osMotorStop(OSPfs *); +extern s32 osMotorStart(OSPfs *); +#endif + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_MOTOR_H_ */ diff --git a/include/PR/os_pfs.h b/include/PR/os_pfs.h new file mode 100644 index 0000000..83187bb --- /dev/null +++ b/include/PR/os_pfs.h @@ -0,0 +1,199 @@ + +/*==================================================================== + * os_pfs.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_pfs.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:16 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_PFS_H_ +#define _OS_PFS_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for file system + */ +typedef struct { + int status; + OSMesgQueue *queue; + int channel; + u8 id[32]; + u8 label[32]; + int version; + int dir_size; + int inode_table; /* block location */ + int minode_table; /* mirrioring inode_table */ + int dir_table; /* block location */ + int inode_start_page; /* page # */ + u8 banks; + u8 activebank; +} OSPfs; + +typedef struct { + u32 file_size; /* bytes */ + u32 game_code; + u16 company_code; + char ext_name[4]; + char game_name[16]; +} OSPfsState; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* File System size */ +#define OS_PFS_VERSION 0x0200 +#define OS_PFS_VERSION_HI (OS_PFS_VERSION >> 8) +#define OS_PFS_VERSION_LO (OS_PFS_VERSION & 255) + +#define PFS_FILE_NAME_LEN 16 +#define PFS_FILE_EXT_LEN 4 +#define BLOCKSIZE 32 /* bytes */ +#define PFS_ONE_PAGE 8 /* blocks */ +#define PFS_MAX_BANKS 62 + +/* File System flag */ + +#define PFS_READ 0 +#define PFS_WRITE 1 +#define PFS_CREATE 2 + +/* File System status */ +#define PFS_INITIALIZED 0x1 +#define PFS_CORRUPTED 0x2 /* File system was corrupted */ +#define PFS_ID_BROKEN 0x4 +#define PFS_MOTOR_INITIALIZED 0x8 +#define PFS_GBPAK_INITIALIZED 0x10 + +/* File System error number */ + +#define PFS_ERR_NOPACK 1 /* no memory card is plugged or */ +#define PFS_ERR_NEW_PACK 2 /* ram pack has been changed to a */ + /* different one */ +#define PFS_ERR_INCONSISTENT 3 /* need to run Pfschecker */ +#define PFS_ERR_CONTRFAIL CONT_OVERRUN_ERROR +#define PFS_ERR_INVALID 5 /* invalid parameter or file not exist*/ +#define PFS_ERR_BAD_DATA 6 /* the data read from pack are bad*/ +#define PFS_DATA_FULL 7 /* no free pages on ram pack */ +#define PFS_DIR_FULL 8 /* no free directories on ram pack*/ +#define PFS_ERR_EXIST 9 /* file exists */ +#define PFS_ERR_ID_FATAL 10 /* dead ram pack */ +#define PFS_ERR_DEVICE 11 /* wrong device type*/ +#define PFS_ERR_NO_GBCART 12 /* no gb cartridge (64GB-PAK) */ +#define PFS_ERR_NEW_GBCART 13 /* gb cartridge may be changed */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +/* Definition for bank */ +#define PFS_ID_BANK_256K 0 +#define PFS_ID_BANK_1M 4 +#define PFS_BANKS_256K 1 + +#define PFS_WRITTEN 2 +#define DEF_DIR_PAGES 2 + +#define PFS_ID_0AREA 1 +#define PFS_ID_1AREA 3 +#define PFS_ID_2AREA 4 +#define PFS_ID_3AREA 6 +#define PFS_LABEL_AREA 7 +#define PFS_ID_PAGE PFS_ONE_PAGE * 0 + +#define PFS_BANK_LAPPED_BY 8 /* => u8 */ +#define PFS_SECTOR_PER_BANK 32 +#define PFS_INODE_DIST_MAP (PFS_BANK_LAPPED_BY * PFS_SECTOR_PER_BANK) +#define PFS_SECTOR_SIZE (PFS_INODE_SIZE_PER_PAGE/PFS_SECTOR_PER_BANK) + +#define PFS_FORCE 1 + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* file system interface */ + +#if VERSION >= VERSION_NTSC_1_0 +s32 osPfsInitPak(OSMesgQueue *queue, OSPfs *pfs, s32 channel, s32 *arg3); +#else +s32 osPfsInitPak(OSMesgQueue *queue, OSPfs *pfs, s32 channel); +#endif +extern s32 osPfsRepairId(OSPfs *); +extern s32 osPfsInit(OSMesgQueue *, OSPfs *, int); +extern s32 osPfsReFormat(OSPfs *, OSMesgQueue *, int); +extern s32 osPfsChecker(OSPfs *); +extern s32 osPfsAllocateFile(OSPfs *, u16, u32, u8 *, u8 *, int, s32 *); +extern s32 osPfsFindFile(OSPfs *, u16, u32, u8 *, u8 *, s32 *); +extern s32 osPfsDeleteFile(OSPfs *, u16, u32, u8 *, u8 *); +extern s32 osPfsReadWriteFile(OSPfs *, s32, u8, int, int, u8 *); +extern s32 osPfsFileState(OSPfs *, s32, OSPfsState *); +extern s32 osPfsGetLabel(OSPfs *, u8 *, int *); +extern s32 osPfsSetLabel(OSPfs *, u8 *); +extern s32 osPfsIsPlug(OSMesgQueue *, u8 *); +extern s32 osPfsFreeBlocks(OSPfs *, s32 *); +extern s32 osPfsNumFiles(OSPfs *, s32 *, s32 *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_PFS_H_ */ diff --git a/include/PR/os_pi.h b/include/PR/os_pi.h new file mode 100644 index 0000000..0c74597 --- /dev/null +++ b/include/PR/os_pi.h @@ -0,0 +1,224 @@ + +/*==================================================================== + * os_pi.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_pi.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:16 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_PI_H_ +#define _OS_PI_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_thread.h" +#include "os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for Enhanced PI interface + */ + +/* + * OSTranxInfo is set up for Leo Disk DMA. This info will be maintained + * by exception handler. This is how the PIMGR and the ISR communicate. + */ + +typedef struct { + u32 errStatus; /* error status */ + void *dramAddr; /* RDRAM buffer address (DMA) */ + void *C2Addr; /* C2 buffer address */ + u32 sectorSize; /* size of transfering sector */ + u32 C1ErrNum; /* total # of C1 errors */ + u32 C1ErrSector[4]; /* error sectors */ +} __OSBlockInfo; + +typedef struct { + u32 cmdType; /* for disk only */ + u16 transferMode; /* Block, Track, or sector? */ + u16 blockNum; /* which block is transfering */ + s32 sectorNum; /* which sector is transfering */ + u32 devAddr; /* Device buffer address */ + u32 bmCtlShadow; /* asic bm_ctl(510) register shadow ram */ + u32 seqCtlShadow; /* asic seq_ctl(518) register shadow ram */ + __OSBlockInfo block[2]; /* bolck transfer info */ +} __OSTranxInfo; + + +typedef struct OSPiHandle_s { + struct OSPiHandle_s *next; /* point to next handle on the table */ + u8 type; /* DEVICE_TYPE_BULK for disk */ + u8 latency; /* domain latency */ + u8 pageSize; /* domain page size */ + u8 relDuration; /* domain release duration */ + u8 pulse; /* domain pulse width */ + u8 domain; /* which domain */ + u32 baseAddress; /* Domain address */ + u32 speed; /* for roms only */ + /* The following are "private" elements" */ + __OSTranxInfo transferInfo; /* for disk only */ +} OSPiHandle; + +typedef struct { + u8 type; + u32 address; +} OSPiInfo; + +/* + * Structure for I/O message block + */ +typedef struct { + u16 type; /* Message type */ + u8 pri; /* Message priority (High or Normal) */ + u8 status; /* Return status */ + OSMesgQueue *retQueue; /* Return message queue to notify I/O + * completion */ +} OSIoMesgHdr; + +typedef struct { + OSIoMesgHdr hdr; /* Message header */ + void * dramAddr; /* RDRAM buffer address (DMA) */ + u32 devAddr; /* Device buffer address (DMA) */ + u32 size; /* DMA transfer size in bytes */ + OSPiHandle *piHandle; /* PI device handle */ +} OSIoMesg; + +/* + * Structure for device manager block + */ +typedef struct { + s32 active; /* Status flag */ + OSThread *thread; /* Calling thread */ + OSMesgQueue *cmdQueue; /* Command queue */ + OSMesgQueue *evtQueue; /* Event queue */ + OSMesgQueue *acsQueue; /* Access queue */ + /* Raw DMA routine */ + s32 (*dma)(s32, u32, void *, u32); + s32 (*edma)(OSPiHandle *, s32, u32, void *, u32); +} OSDevMgr; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* Flags to indicate direction of data transfer */ + +#define OS_READ 0 /* device -> RDRAM */ +#define OS_WRITE 1 /* device <- RDRAM */ +#define OS_OTHERS 2 /* for Leo disk only */ + +/* + * I/O message types + */ +#define OS_MESG_TYPE_BASE (10) +#define OS_MESG_TYPE_LOOPBACK (OS_MESG_TYPE_BASE+0) +#define OS_MESG_TYPE_DMAREAD (OS_MESG_TYPE_BASE+1) +#define OS_MESG_TYPE_DMAWRITE (OS_MESG_TYPE_BASE+2) +#define OS_MESG_TYPE_VRETRACE (OS_MESG_TYPE_BASE+3) +#define OS_MESG_TYPE_COUNTER (OS_MESG_TYPE_BASE+4) +#define OS_MESG_TYPE_EDMAREAD (OS_MESG_TYPE_BASE+5) +#define OS_MESG_TYPE_EDMAWRITE (OS_MESG_TYPE_BASE+6) + +/* + * I/O message priority + */ +#define OS_MESG_PRI_NORMAL 0 +#define OS_MESG_PRI_HIGH 1 + +/* + * PI/EPI + */ +#define PI_DOMAIN1 0 +#define PI_DOMAIN2 1 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + +extern OSPiHandle *__osPiTable; /* The head of OSPiHandle link list */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Peripheral interface (Pi) */ +extern u32 osPiGetStatus(void); +extern s32 osPiGetDeviceType(void); +extern s32 osPiWriteIo(u32, u32); +extern s32 osPiReadIo(u32, u32 *); +extern s32 osPiStartDma(OSIoMesg *, s32, s32, u32, void *, u32, + OSMesgQueue *); +extern void osCreatePiManager(OSPri, OSMesgQueue *, OSMesg *, s32); + +/* Enhanced PI interface */ + +extern OSPiHandle *osCartRomInit(void); +extern OSPiHandle *osLeoDiskInit(void); +extern OSPiHandle *osDriveRomInit(void); + +extern s32 osEPiDeviceType(OSPiHandle *, OSPiInfo *); +extern s32 osEPiWriteIo(OSPiHandle *, u32 , u32 ); +extern s32 osEPiReadIo(OSPiHandle *, u32 , u32 *); +extern s32 osEPiStartDma(OSPiHandle *, OSIoMesg *, s32); +extern s32 osEPiLinkHandle(OSPiHandle *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_PI_H_ */ diff --git a/include/PR/os_rdp.h b/include/PR/os_rdp.h new file mode 100644 index 0000000..6b3d288 --- /dev/null +++ b/include/PR/os_rdp.h @@ -0,0 +1,92 @@ + +/*==================================================================== + * os_rdp.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_rdp.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:16 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_RDP_H_ +#define _OS_RDP_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Display processor interface (Dp) */ +extern u32 osDpGetStatus(void); +extern void osDpSetStatus(u32); +extern void osDpGetCounters(u32 *); +extern s32 osDpSetNextBuffer(void *, u64); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_RDP_H_ */ diff --git a/include/PR/os_reg.h b/include/PR/os_reg.h new file mode 100644 index 0000000..50aa218 --- /dev/null +++ b/include/PR/os_reg.h @@ -0,0 +1,90 @@ + +/*==================================================================== + * os_reg.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_reg.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:17 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_REG_H_ +#define _OS_REG_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Miscellaneous operations */ + +extern u32 osGetCount(void); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_REG_H_ */ diff --git a/include/PR/os_rsp.h b/include/PR/os_rsp.h new file mode 100644 index 0000000..1211605 --- /dev/null +++ b/include/PR/os_rsp.h @@ -0,0 +1,86 @@ + +/*==================================================================== + * os_rsp.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_rsp.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:17 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_RSP_H_ +#define _OS_RSP_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_RSP_H_ */ diff --git a/include/PR/os_si.h b/include/PR/os_si.h new file mode 100644 index 0000000..23b07c0 --- /dev/null +++ b/include/PR/os_si.h @@ -0,0 +1,86 @@ + +/*==================================================================== + * os_si.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_si.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:18 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_SI_H_ +#define _OS_SI_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_SI_H_ */ diff --git a/include/PR/os_system.h b/include/PR/os_system.h new file mode 100644 index 0000000..1179189 --- /dev/null +++ b/include/PR/os_system.h @@ -0,0 +1,118 @@ + +/*==================================================================== + * os_system.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_system.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:18 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_SYSTEM_H_ +#define _OS_SYSTEM_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Values for osTvType + */ +#define OS_TV_PAL 0 +#define OS_TV_NTSC 1 +#define OS_TV_MPAL 2 + +/* + * Size of buffer the retains contents after NMI + */ +#define OS_APP_NMI_BUFSIZE 64 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + +extern s32 osRomType; /* Bulk or cartridge ROM. 0=cartridge 1=bulk */ +extern void *osRomBase; /* Rom base address of the game image */ +extern s32 osTvType; /* 0 = PAL, 1 = NTSC, 2 = MPAL */ +extern s32 osResetType; /* 0 = cold reset, 1 = NMI */ +extern s32 osCicId; +extern s32 osVersion; +extern u32 osMemSize; /* Memory Size */ +extern s32 osAppNMIBuffer[]; + +extern u64 osClockRate; + +extern OSIntMask __OSGlobalIntMask; /* global interrupt mask */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +extern void osInitialize(void); +extern void osExit(void); +extern u32 osGetMemSize(void); + +/* pre-NMI */ +extern s32 osAfterPreNMI(void); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_SYSTEM_H_ */ diff --git a/include/PR/os_thread.h b/include/PR/os_thread.h new file mode 100644 index 0000000..0a6181a --- /dev/null +++ b/include/PR/os_thread.h @@ -0,0 +1,143 @@ + +/*==================================================================== + * os_thread.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_thread.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:19 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_THREAD_H_ +#define _OS_THREAD_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef s32 OSPri; +typedef s32 OSId; +typedef union { struct { f32 f_odd; f32 f_even; } f; f64 d; } __OSfp; + +typedef struct { + u64 at, v0, v1, a0, a1, a2, a3; + u64 t0, t1, t2, t3, t4, t5, t6, t7; + u64 s0, s1, s2, s3, s4, s5, s6, s7; + u64 t8, t9, gp, sp, s8, ra; + u64 lo, hi; + u32 sr, pc, cause, badvaddr, rcp; + u32 fpcsr; + __OSfp fp0, fp2, fp4, fp6, fp8, fp10, fp12, fp14; + __OSfp fp16, fp18, fp20, fp22, fp24, fp26, fp28, fp30; +} __OSThreadContext; + +typedef struct OSThread_s { + struct OSThread_s *next; /* run/mesg queue link */ + OSPri priority; /* run/mesg queue priority */ + struct OSThread_s **queue; /* queue thread is on */ + struct OSThread_s *tlnext; /* all threads queue link */ + u16 state; /* OS_STATE_* */ + u16 flags; /* flags for rmon */ + OSId id; /* id for debugging */ + int fp; /* thread has used fp unit */ + __OSThreadContext context; /* register/interrupt mask */ +} OSThread; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* Thread states */ + +#define OS_STATE_STOPPED 1 +#define OS_STATE_RUNNABLE 2 +#define OS_STATE_RUNNING 4 +#define OS_STATE_WAITING 8 + +/* Recommended thread priorities for the system threads */ + +#define OS_PRIORITY_MAX 255 +#define OS_PRIORITY_VIMGR 254 +#define OS_PRIORITY_RMON 250 +#define OS_PRIORITY_RMONSPIN 200 +#define OS_PRIORITY_PIMGR 150 +#define OS_PRIORITY_SIMGR 140 +#define OS_PRIORITY_APPMAX 127 +#define OS_PRIORITY_IDLE 0 /* Must be 0 */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Thread operations */ + +extern void osCreateThread(OSThread *, OSId, void (*)(void *), void *, void *, OSPri); +extern void osDestroyThread(OSThread *); +extern void osYieldThread(void); +extern void osStartThread(OSThread *); +extern void osStopThread(OSThread *); +extern OSId osGetThreadId(OSThread *); +extern void osSetThreadPri(OSThread *, OSPri); +extern OSPri osGetThreadPri(OSThread *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_THREAD_H_ */ diff --git a/include/PR/os_time.h b/include/PR/os_time.h new file mode 100644 index 0000000..deaec65 --- /dev/null +++ b/include/PR/os_time.h @@ -0,0 +1,114 @@ + +/*==================================================================== + * os_time.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_time.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:19 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_TIME_H_ +#define _OS_TIME_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for time value + */ +typedef u64 OSTime; + +/* + * Structure for interval timer + */ +typedef struct OSTimer_s { + struct OSTimer_s *next; /* point to next timer in list */ + struct OSTimer_s *prev; /* point to previous timer in list */ + OSTime interval; /* duration set by user */ + OSTime value; /* time remaining before */ + /* timer fires */ + OSMesgQueue *mq; /* Message Queue */ + OSMesg msg; /* Message to send */ +} OSTimer; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Timer interface */ + +extern OSTime osGetTime(void); +extern void osSetTime(OSTime); +extern int osSetTimer(OSTimer *, OSTime, OSTime, + OSMesgQueue *, OSMesg); +extern int osStopTimer(OSTimer *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_TIME_H_ */ diff --git a/include/PR/os_tlb.h b/include/PR/os_tlb.h new file mode 100644 index 0000000..2cdd5c9 --- /dev/null +++ b/include/PR/os_tlb.h @@ -0,0 +1,107 @@ + +/*==================================================================== + * os_tlb.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_tlb.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:20 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_TLB_H_ +#define _OS_TLB_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef u32 OSPageMask; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Page size argument for TLB routines + */ +#define OS_PM_4K 0x0000000 +#define OS_PM_16K 0x0006000 +#define OS_PM_64K 0x001e000 +#define OS_PM_256K 0x007e000 +#define OS_PM_1M 0x01fe000 +#define OS_PM_4M 0x07fe000 +#define OS_PM_16M 0x1ffe000 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* TLB management routines */ + +extern void osMapTLB(s32, OSPageMask, void *, u32, u32, s32); +extern void osMapTLBRdb(void); +extern void osUnmapTLB(s32); +extern void osUnmapTLBAll(void); +extern void osSetTLBASID(s32); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_TLB_H_ */ diff --git a/include/PR/os_version.h b/include/PR/os_version.h new file mode 100644 index 0000000..4f1c327 --- /dev/null +++ b/include/PR/os_version.h @@ -0,0 +1,16 @@ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_version.h,v $ + $Revision: 1.1 $ + $Date: 1999/01/18 13:17:45 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_VERSION_H_ +#define _OS_VERSION_H_ + +#define OS_MAJOR_VERSION "2.0J" /* major version */ +#define OS_MINOR_VERSION 0 /* patch level */ + +#endif /* !_OS_VERSION_H_ */ diff --git a/include/PR/os_vi.h b/include/PR/os_vi.h new file mode 100644 index 0000000..5a17f25 --- /dev/null +++ b/include/PR/os_vi.h @@ -0,0 +1,298 @@ + +/*==================================================================== + * os_vi.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_vi.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:20 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_VI_H_ +#define _OS_VI_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_thread.h" +#include "os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure to store VI register values that remain the same between 2 fields + */ +typedef struct { + u32 ctrl; + u32 width; + u32 burst; + u32 vSync; + u32 hSync; + u32 leap; + u32 hStart; + u32 xScale; + u32 vCurrent; +} OSViCommonRegs; + + +/* + * Structure to store VI register values that change between fields + */ +typedef struct { + u32 origin; + u32 yScale; + u32 vStart; + u32 vBurst; + u32 vIntr; +} OSViFieldRegs; + + +/* + * Structure for VI mode + */ +typedef struct { + u8 type; /* Mode type */ + OSViCommonRegs comRegs; /* Common registers for both fields */ + OSViFieldRegs fldRegs[2]; /* Registers for Field 1 & 2 */ +} OSViMode; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Video Interface (VI) mode type + */ +#define OS_VI_NTSC_LPN1 0 /* NTSC */ +#define OS_VI_NTSC_LPF1 1 +#define OS_VI_NTSC_LAN1 2 +#define OS_VI_NTSC_LAF1 3 +#define OS_VI_NTSC_LPN2 4 +#define OS_VI_NTSC_LPF2 5 +#define OS_VI_NTSC_LAN2 6 +#define OS_VI_NTSC_LAF2 7 +#define OS_VI_NTSC_HPN1 8 +#define OS_VI_NTSC_HPF1 9 +#define OS_VI_NTSC_HAN1 10 +#define OS_VI_NTSC_HAF1 11 +#define OS_VI_NTSC_HPN2 12 +#define OS_VI_NTSC_HPF2 13 + +#define OS_VI_PAL_LPN1 14 /* PAL */ +#define OS_VI_PAL_LPF1 15 +#define OS_VI_PAL_LAN1 16 +#define OS_VI_PAL_LAF1 17 +#define OS_VI_PAL_LPN2 18 +#define OS_VI_PAL_LPF2 19 +#define OS_VI_PAL_LAN2 20 +#define OS_VI_PAL_LAF2 21 +#define OS_VI_PAL_HPN1 22 +#define OS_VI_PAL_HPF1 23 +#define OS_VI_PAL_HAN1 24 +#define OS_VI_PAL_HAF1 25 +#define OS_VI_PAL_HPN2 26 +#define OS_VI_PAL_HPF2 27 + +#define OS_VI_MPAL_LPN1 28 /* MPAL - mainly Brazil */ +#define OS_VI_MPAL_LPF1 29 +#define OS_VI_MPAL_LAN1 30 +#define OS_VI_MPAL_LAF1 31 +#define OS_VI_MPAL_LPN2 32 +#define OS_VI_MPAL_LPF2 33 +#define OS_VI_MPAL_LAN2 34 +#define OS_VI_MPAL_LAF2 35 +#define OS_VI_MPAL_HPN1 36 +#define OS_VI_MPAL_HPF1 37 +#define OS_VI_MPAL_HAN1 38 +#define OS_VI_MPAL_HAF1 39 +#define OS_VI_MPAL_HPN2 40 +#define OS_VI_MPAL_HPF2 41 + +#define OS_VI_FPAL_LPN1 42 /* FPAL - Full screen PAL */ +#define OS_VI_FPAL_LPF1 43 +#define OS_VI_FPAL_LAN1 44 +#define OS_VI_FPAL_LAF1 45 +#define OS_VI_FPAL_LPN2 46 +#define OS_VI_FPAL_LPF2 47 +#define OS_VI_FPAL_LAN2 48 +#define OS_VI_FPAL_LAF2 49 +#define OS_VI_FPAL_HPN1 50 +#define OS_VI_FPAL_HPF1 51 +#define OS_VI_FPAL_HAN1 52 +#define OS_VI_FPAL_HAF1 53 +#define OS_VI_FPAL_HPN2 54 +#define OS_VI_FPAL_HPF2 55 + +/* + * Video Interface (VI) special features + */ +#define OS_VI_GAMMA_ON 0x0001 +#define OS_VI_GAMMA_OFF 0x0002 +#define OS_VI_GAMMA_DITHER_ON 0x0004 +#define OS_VI_GAMMA_DITHER_OFF 0x0008 +#define OS_VI_DIVOT_ON 0x0010 +#define OS_VI_DIVOT_OFF 0x0020 +#define OS_VI_DITHER_FILTER_ON 0x0040 +#define OS_VI_DITHER_FILTER_OFF 0x0080 + +/* + * Video Interface (VI) mode attribute bit + */ +#define OS_VI_BIT_NONINTERLACE 0x0001 /* lo-res */ +#define OS_VI_BIT_INTERLACE 0x0002 /* lo-res */ +#define OS_VI_BIT_NORMALINTERLACE 0x0004 /* hi-res */ +#define OS_VI_BIT_DEFLICKINTERLACE 0x0008 /* hi-res */ +#define OS_VI_BIT_ANTIALIAS 0x0010 +#define OS_VI_BIT_POINTSAMPLE 0x0020 +#define OS_VI_BIT_16PIXEL 0x0040 +#define OS_VI_BIT_32PIXEL 0x0080 +#define OS_VI_BIT_LORES 0x0100 +#define OS_VI_BIT_HIRES 0x0200 +#define OS_VI_BIT_NTSC 0x0400 +#define OS_VI_BIT_PAL 0x0800 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + +extern OSViMode osViModeTable[]; /* Global VI mode table */ + +extern OSViMode osViModeNtscLpn1; /* Individual VI NTSC modes */ +extern OSViMode osViModeNtscLpf1; +extern OSViMode osViModeNtscLan1; +extern OSViMode osViModeNtscLaf1; +extern OSViMode osViModeNtscLpn2; +extern OSViMode osViModeNtscLpf2; +extern OSViMode osViModeNtscLan2; +extern OSViMode osViModeNtscLaf2; +extern OSViMode osViModeNtscHpn1; +extern OSViMode osViModeNtscHpf1; +extern OSViMode osViModeNtscHan1; +extern OSViMode osViModeNtscHaf1; +extern OSViMode osViModeNtscHpn2; +extern OSViMode osViModeNtscHpf2; + +extern OSViMode osViModePalLpn1; /* Individual VI PAL modes */ +extern OSViMode osViModePalLpf1; +extern OSViMode osViModePalLan1; +extern OSViMode osViModePalLaf1; +extern OSViMode osViModePalLpn2; +extern OSViMode osViModePalLpf2; +extern OSViMode osViModePalLan2; +extern OSViMode osViModePalLaf2; +extern OSViMode osViModePalHpn1; +extern OSViMode osViModePalHpf1; +extern OSViMode osViModePalHan1; +extern OSViMode osViModePalHaf1; +extern OSViMode osViModePalHpn2; +extern OSViMode osViModePalHpf2; + +extern OSViMode osViModeMpalLpn1; /* Individual VI MPAL modes */ +extern OSViMode osViModeMpalLpf1; +extern OSViMode osViModeMpalLan1; +extern OSViMode osViModeMpalLaf1; +extern OSViMode osViModeMpalLpn2; +extern OSViMode osViModeMpalLpf2; +extern OSViMode osViModeMpalLan2; +extern OSViMode osViModeMpalLaf2; +extern OSViMode osViModeMpalHpn1; +extern OSViMode osViModeMpalHpf1; +extern OSViMode osViModeMpalHan1; +extern OSViMode osViModeMpalHaf1; +extern OSViMode osViModeMpalHpn2; +extern OSViMode osViModeMpalHpf2; + +extern OSViMode osViModeFpalLpn1; /* Individual VI FPAL modes */ +extern OSViMode osViModeFpalLpf1; +extern OSViMode osViModeFpalLan1; +extern OSViMode osViModeFpalLaf1; +extern OSViMode osViModeFpalLpn2; +extern OSViMode osViModeFpalLpf2; +extern OSViMode osViModeFpalLan2; +extern OSViMode osViModeFpalLaf2; +extern OSViMode osViModeFpalHpn1; +extern OSViMode osViModeFpalHpf1; +extern OSViMode osViModeFpalHan1; +extern OSViMode osViModeFpalHaf1; +extern OSViMode osViModeFpalHpn2; +extern OSViMode osViModeFpalHpf2; + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Video interface (Vi) */ +extern u32 osViGetStatus(void); +extern u32 osViGetCurrentMode(void); +extern u32 osViGetCurrentLine(void); +extern u32 osViGetCurrentField(void); +extern void *osViGetCurrentFramebuffer(void); +extern void *osViGetNextFramebuffer(void); +extern void osViSetXScale(f32); +extern void osViSetYScale(f32); +extern void osViExtendVStart(u32); +extern void osViSetSpecialFeatures(u32); +extern void osViSetMode(OSViMode *); +extern void osViSetEvent(OSMesgQueue *, OSMesg, u32); +extern void osViSwapBuffer(void *); +extern void osViBlack(u8); +extern void osViFade(u8, u16); +extern void osViRepeatLine(u8); +extern void osCreateViManager(OSPri); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_VI_H_ */ diff --git a/include/PR/os_voice.h b/include/PR/os_voice.h new file mode 100644 index 0000000..5416aa8 --- /dev/null +++ b/include/PR/os_voice.h @@ -0,0 +1,108 @@ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_voice.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:21 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_VOICE_H_ +#define _OS_VOICE_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef struct { /* Voice Recognition System */ + OSMesgQueue *__mq; /* SI Message Queue */ + int __channel; /* Controller Port # */ + s32 __mode; + u8 cmd_status; /* Command Status */ +} OSVoiceHandle; + +typedef struct { /* Voice Recognition System */ + u16 warning; + u16 answer_num; /* 0〜5 */ + u16 voice_level; + u16 voice_sn; + u16 voice_time; + u16 answer[5]; + u16 distance[5]; +} OSVoiceData; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* definition for Voice Recognition System */ + +#define VOICE_WARN_TOO_SMALL 0x0400 +#define VOICE_WARN_TOO_LARGE 0x0800 +#define VOICE_WARN_NOT_FIT 0x4000 +#define VOICE_WARN_TOO_NOISY 0x8000 + +#define VOICE_STATUS_READY 0 +#define VOICE_STATUS_START 1 +#define VOICE_STATUS_CANCEL 3 +#define VOICE_STATUS_BUSY 5 +#define VOICE_STATUS_END 7 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Voice Recognition System */ +extern s32 osVoiceInit(OSMesgQueue *, OSVoiceHandle *, int); +extern s32 osVoiceCheckWord(u8 *data); +extern s32 osVoiceClearDictionary(OSVoiceHandle *, u8); +extern s32 osVoiceControlGain(OSVoiceHandle *, s32, s32); +extern s32 osVoiceSetWord(OSVoiceHandle *, u8 *); +extern s32 osVoiceStartReadData(OSVoiceHandle *); +extern s32 osVoiceStopReadData(OSVoiceHandle *); +extern s32 osVoiceGetReadData(OSVoiceHandle *, OSVoiceData *); +extern s32 osVoiceMaskDictionary(OSVoiceHandle *, u8 *, int); +extern void osVoiceCountSyllables(u8 *, u32 *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_VOICE_H_ */ diff --git a/include/PR/ramrom.h b/include/PR/ramrom.h index 397b676..0f29638 100644 --- a/include/PR/ramrom.h +++ b/include/PR/ramrom.h @@ -17,7 +17,7 @@ * * $Revision: 1.20 $ * $Date: 1997/02/11 08:26:47 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/ramrom.h,v $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ramrom.h,v $ * **************************************************************************/ diff --git a/include/PR/rcp.h b/include/PR/rcp.h index 1cc898b..2099e10 100644 --- a/include/PR/rcp.h +++ b/include/PR/rcp.h @@ -1,10 +1,6 @@ #ifndef _RCP_H_ #define _RCP_H_ -#ifdef _LANGUAGE_C -#define HW_REG(reg, type) *(volatile type*)((reg) | 0xA0000000) -#endif - /************************************************************************** * * * Copyright (C) 1995, Silicon Graphics, Inc. * @@ -22,9 +18,9 @@ * File: rcp.h * * This file contains register and bit definitions for RCP memory map. - * $Revision: 1.20 $ - * $Date: 1997/07/23 08:35:21 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/rcp.h,v $ + * $Revision: 1.21 $ + * $Date: 1998/07/31 11:08:29 $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/rcp.h,v $ * **************************************************************************/ @@ -165,6 +161,8 @@ The Indy development board use cartridge domain 1: #define DEVICE_TYPE_BULK 1 /* ROM bulk */ #define DEVICE_TYPE_64DD 2 /* 64 Disk Drive */ #define DEVICE_TYPE_SRAM 3 /* SRAM */ +/* 4-6 are reserved */ +#define DEVICE_TYPE_INIT 7 /* initial value */ /************************************************************************* * SP Memory @@ -604,6 +602,7 @@ The Indy development board use cartridge domain 1: #define VI_PAL_CLOCK 49656530 /* Hz = 49.656530 MHz */ #define VI_MPAL_CLOCK 48628316 /* Hz = 48.628316 MHz */ + /************************************************************************* * Audio Interface (AI) Registers * diff --git a/include/PR/rdb.h b/include/PR/rdb.h index c5c3159..78d7b20 100644 --- a/include/PR/rdb.h +++ b/include/PR/rdb.h @@ -3,7 +3,7 @@ * * $Revision: 1.6 $ * $Date: 1997/02/11 08:29:31 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/rdb.h,v $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/rdb.h,v $ * **************************************************************************/ diff --git a/include/PR/region.h b/include/PR/region.h index 9f8bb7f..574e0b6 100644 --- a/include/PR/region.h +++ b/include/PR/region.h @@ -18,7 +18,7 @@ * $Revision: 1.8 $ * $Date: 1997/11/26 00:30:56 $ * $Author: mitu $ - * $Source: /disk6/Master/cvsmdev2/PR/include/region.h,v $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/region.h,v $ * * Description: * This file contains macros and structure definitions for the region diff --git a/include/PR/rmon.h b/include/PR/rmon.h index ea826d1..93873f2 100644 --- a/include/PR/rmon.h +++ b/include/PR/rmon.h @@ -14,7 +14,7 @@ * * $Revision: 1.6 $ * $Date: 1997/02/11 08:30:08 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/rmon.h,v $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/rmon.h,v $ * **************************************************************************/ diff --git a/include/PR/sched.h b/include/PR/sched.h index 9addae7..166a81b 100644 --- a/include/PR/sched.h +++ b/include/PR/sched.h @@ -24,7 +24,7 @@ * * $Revision: 1.7 $ * $Date: 1997/02/11 08:32:02 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/sched.h,v $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/sched.h,v $ * **************************************************************************/ @@ -38,8 +38,11 @@ #define OS_SC_RETRACE_MSG 1 #define OS_SC_DONE_MSG 2 #define OS_SC_RDP_DONE_MSG 3 -#define OS_SC_PRE_NMI_MSG 4 -#define OS_SC_LAST_MSG 4 /* this should have highest number */ +#define OS_SC_RSP_MSG 4 // custom - tells audiomgr it's time to do an audio frame +#define OS_SC_PRE_NMI_MSG 5 +#define OS_SC_QUIT_MSG 10 +#define OS_SC_LAST_MSG 10 /* this should have highest number */ + #define OS_SC_MAX_MESGS 8 typedef struct { @@ -56,11 +59,7 @@ typedef struct OSScTask_s { OSTask list; OSMesgQueue *msgQ; OSMesg msg; -#ifndef _FINALROM /* all #ifdef items should */ - OSTime startTime; /* remain at the end!!, or */ - OSTime totalTime; /* possible conflict if */ -#endif /* FINALROM library used with */ -} OSScTask; /* non FINALROM code */ +} OSScTask; /* * OSScTask flags: @@ -84,6 +83,7 @@ typedef struct OSScTask_s { typedef struct SCClient_s { struct SCClient_s *next; /* next client in the list */ OSMesgQueue *msgQ; /* where to send the frame msg */ + s32 is8mb; } OSScClient; typedef struct { @@ -93,7 +93,7 @@ typedef struct { OSMesg intBuf[OS_SC_MAX_MESGS]; OSMesgQueue cmdQ; OSMesg cmdMsgBuf[OS_SC_MAX_MESGS]; - OSThread thread; + OSThread *thread; OSScClient *clientList; OSScTask *audioListHead; OSScTask *gfxListHead; @@ -105,9 +105,8 @@ typedef struct { s32 doAudio; } OSSched; -void osCreateScheduler(OSSched *s, void *stack, OSPri priority, - u8 mode, u8 numFields); -void osScAddClient(OSSched *s, OSScClient *c, OSMesgQueue *msgQ); +void osCreateScheduler(OSSched *s, OSThread *thread, u8 mode, u32 numFields); +void osScAddClient(OSSched *s, OSScClient *c, OSMesgQueue *msgQ, int is8mb); void osScRemoveClient(OSSched *s, OSScClient *c); OSMesgQueue *osScGetCmdQ(OSSched *s); diff --git a/include/PR/sp.h b/include/PR/sp.h index 24f11a1..c2ef5f7 100644 --- a/include/PR/sp.h +++ b/include/PR/sp.h @@ -14,9 +14,9 @@ * * Sprite library include file * - * $Revision: 1.15 $ - * $Date: 1997/02/11 08:33:02 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/sp.h,v $ + * $Revision: 1.16 $ + * $Date: 1998/04/17 05:03:46 $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/sp.h,v $ * **************************************************************************/ @@ -155,6 +155,25 @@ typedef struct sprite Sprite; #define SP_TEXSHUF 0x00000200 #define SP_EXTERN 0x00000400 +/* + * Function wrapper + */ +#if defined(F3DEX_GBI_2) +#define spMove spX2Move +#define spSetZ spX2SetZ +#define spScissor spX2Scissor +#define spDraw spX2Draw +#define spInit spX2Init +#define spFinish spX2Finish +#elif defined(F3DEX_GBI) +#define spMove spXMove +#define spSetZ spXSetZ +#define spScissor spXScissor +#define spDraw spXDraw +#define spInit spXInit +#define spFinish spXFinish +#endif + /* * Function prototypes */ diff --git a/include/PR/sptask.h b/include/PR/sptask.h index 8d6ea41..81c9a9f 100644 --- a/include/PR/sptask.h +++ b/include/PR/sptask.h @@ -12,9 +12,9 @@ /************************************************************************** * - * $Revision: 1.8 $ - * $Date: 1997/11/10 10:48:35 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/sptask.h,v $ + * $Revision: 1.9 $ + * $Date: 1998/03/05 06:40:29 $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/sptask.h,v $ * **************************************************************************/ @@ -50,7 +50,7 @@ extern "C" { * - pointer to ucode * - size of ucode * - pointer to initial DMEM data - * - size of initial DMEM data + * - size of initial DMEM data * - pointer to DRAM stack * - size of DRAM stack (max) * - pointer to output buffer @@ -131,13 +131,14 @@ typedef u32 OSYieldResult; #define OS_TASK_USR3 0x0080 /* - * Size of Yield buffer. The taskHdrPtr->t.yield_data_ptr must point to a + * Size of Yield buffer. The taskHdrPtr->t.yield_data_ptr must point to a * buffer of this size. (The size is in bytes). ONLY If the task will NEVER * yield it may be a null pointer. The buffer must be aligned to a 64 bit * boundary. The taskHdrPtr->t.yield_data_ptr must be set to point to the * buffer BEFORE the task is started. */ -#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) +// @todo: Remove this || 1 hack +#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)||defined(F3DEX_GBI_2) || 1) #define OS_YIELD_DATA_SIZE 0xc00 #else #define OS_YIELD_DATA_SIZE 0x900 diff --git a/include/PR/ucode.h b/include/PR/ucode.h index 1025d2f..735f914 100644 --- a/include/PR/ucode.h +++ b/include/PR/ucode.h @@ -12,9 +12,9 @@ /************************************************************************** * - * $Revision: 1.13 $ - * $Date: 1997/11/07 04:55:12 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/ucode.h,v $ + * $Revision: 1.15 $ + * $Date: 1998/03/31 07:58:57 $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ucode.h,v $ * **************************************************************************/ @@ -153,24 +153,30 @@ extern long long int gspL3DEX_fifoTextStart[], gspL3DEX_fifoTextEnd[]; extern long long int gspL3DEX_fifoDataStart[], gspL3DEX_fifoDataEnd[]; /*========== F3DEX2/F3DLX2/F3DLP2/L3DEX2 ==========*/ -/* FIFO version only */ +/* FIFO version */ extern long long int gspF3DEX2_fifoTextStart[], gspF3DEX2_fifoTextEnd[]; extern long long int gspF3DEX2_fifoDataStart[], gspF3DEX2_fifoDataEnd[]; extern long long int gspF3DEX2_NoN_fifoTextStart[],gspF3DEX2_NoN_fifoTextEnd[]; extern long long int gspF3DEX2_NoN_fifoDataStart[],gspF3DEX2_NoN_fifoDataEnd[]; - -extern long long int gspF3DLX2_fifoTextStart[], gspF3DLX2_fifoTextEnd[]; -extern long long int gspF3DLX2_fifoDataStart[], gspF3DLX2_fifoDataEnd[]; -extern long long int gspF3DLX2_NoN_fifoTextStart[],gspF3DLX2_NoN_fifoTextEnd[]; -extern long long int gspF3DLX2_NoN_fifoDataStart[],gspF3DLX2_NoN_fifoDataEnd[]; +extern long long int gspF3DEX2_Rej_fifoTextStart[],gspF3DEX2_Rej_fifoTextEnd[]; +extern long long int gspF3DEX2_Rej_fifoDataStart[],gspF3DEX2_Rej_fifoDataEnd[]; extern long long int gspF3DLX2_Rej_fifoTextStart[],gspF3DLX2_Rej_fifoTextEnd[]; extern long long int gspF3DLX2_Rej_fifoDataStart[],gspF3DLX2_Rej_fifoDataEnd[]; - -extern long long int gspF3DLP2_Rej_fifoTextStart[],gspF3DLP2_Rej_fifoTextEnd[]; -extern long long int gspF3DLP2_Rej_fifoDataStart[],gspF3DLP2_Rej_fifoDataEnd[]; extern long long int gspL3DEX2_fifoTextStart[], gspL3DEX2_fifoTextEnd[]; extern long long int gspL3DEX2_fifoDataStart[], gspL3DEX2_fifoDataEnd[]; +/* XBUS version */ +extern long long int gspF3DEX2_xbusTextStart[], gspF3DEX2_xbusTextEnd[]; +extern long long int gspF3DEX2_xbusDataStart[], gspF3DEX2_xbusDataEnd[]; +extern long long int gspF3DEX2_NoN_xbusTextStart[],gspF3DEX2_NoN_xbusTextEnd[]; +extern long long int gspF3DEX2_NoN_xbusDataStart[],gspF3DEX2_NoN_xbusDataEnd[]; +extern long long int gspF3DEX2_Rej_xbusTextStart[],gspF3DEX2_Rej_xbusTextEnd[]; +extern long long int gspF3DEX2_Rej_xbusDataStart[],gspF3DEX2_Rej_xbusDataEnd[]; +extern long long int gspF3DLX2_Rej_xbusTextStart[],gspF3DLX2_Rej_xbusTextEnd[]; +extern long long int gspF3DLX2_Rej_xbusDataStart[],gspF3DLX2_Rej_xbusDataEnd[]; +extern long long int gspL3DEX2_xbusTextStart[], gspL3DEX2_xbusTextEnd[]; +extern long long int gspL3DEX2_xbusDataStart[], gspL3DEX2_xbusDataEnd[]; + /************************************************************************** * * Function prototypes diff --git a/include/PR/ucode_debug.h b/include/PR/ucode_debug.h new file mode 100644 index 0000000..189a7f2 --- /dev/null +++ b/include/PR/ucode_debug.h @@ -0,0 +1,54 @@ +/*---------------------------------------------------------------------* + Copyright (C) 1998, Nintendo. + + File ucode_debug.h + Coded by Yoshitaka Yasumoto. Nov 15, 1998. + + $Id: ucode_debug.h,v 1.1 1998/12/25 01:06:21 has Exp $ + *---------------------------------------------------------------------*/ +#ifndef _UCODE_DEBUG_H_ +#define _UCODE_DEBUG_H_ + +#define DEBUG_DL_PTR() IO_READ(SP_DMEM_START+0xfc0) + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) +/*========== F3DEX2/F3DLX2/L3DEX2/S2DEX2 ==========*/ +/* FIFO version */ +extern long long int gspF3DEX2d_fifoTextStart[], gspF3DEX2d_fifoTextEnd[]; +extern long long int gspF3DEX2d_fifoDataStart[], gspF3DEX2d_fifoDataEnd[]; +extern long long int gspF3DEX2d_NoN_fifoTextStart[],gspF3DEX2d_NoN_fifoTextEnd[]; +extern long long int gspF3DEX2d_NoN_fifoDataStart[],gspF3DEX2d_NoN_fifoDataEnd[]; +extern long long int gspF3DEX2d_Rej_fifoTextStart[],gspF3DEX2d_Rej_fifoTextEnd[]; +extern long long int gspF3DEX2d_Rej_fifoDataStart[],gspF3DEX2d_Rej_fifoDataEnd[]; +extern long long int gspF3DLX2d_Rej_fifoTextStart[],gspF3DLX2d_Rej_fifoTextEnd[]; +extern long long int gspF3DLX2d_Rej_fifoDataStart[],gspF3DLX2d_Rej_fifoDataEnd[]; +extern long long int gspL3DEX2d_fifoTextStart[], gspL3DEX2d_fifoTextEnd[]; +extern long long int gspL3DEX2d_fifoDataStart[], gspL3DEX2d_fifoDataEnd[]; +extern long long int gspS2DEX2d_fifoTextStart[], gspS2DEX2d_fifoTextEnd[]; +extern long long int gspS2DEX2d_fifoDataStart[], gspS2DEX2d_fifoDataEnd[]; + +/* XBUS version */ +extern long long int gspF3DEX2d_xbusTextStart[], gspF3DEX2d_xbusTextEnd[]; +extern long long int gspF3DEX2d_xbusDataStart[], gspF3DEX2d_xbusDataEnd[]; +extern long long int gspF3DEX2d_NoN_xbusTextStart[],gspF3DEX2d_NoN_xbusTextEnd[]; +extern long long int gspF3DEX2d_NoN_xbusDataStart[],gspF3DEX2d_NoN_xbusDataEnd[]; +extern long long int gspF3DEX2d_Rej_xbusTextStart[],gspF3DEX2d_Rej_xbusTextEnd[]; +extern long long int gspF3DEX2d_Rej_xbusDataStart[],gspF3DEX2d_Rej_xbusDataEnd[]; +extern long long int gspF3DLX2d_Rej_xbusTextStart[],gspF3DLX2d_Rej_xbusTextEnd[]; +extern long long int gspF3DLX2d_Rej_xbusDataStart[],gspF3DLX2d_Rej_xbusDataEnd[]; +extern long long int gspL3DEX2d_xbusTextStart[], gspL3DEX2d_xbusTextEnd[]; +extern long long int gspL3DEX2d_xbusDataStart[], gspL3DEX2d_xbusDataEnd[]; +extern long long int gspS2DEX2d_xbusTextStart[], gspS2DEX2d_xbusTextEnd[]; +extern long long int gspS2DEX2d_xbusDataStart[], gspS2DEX2d_xbusDataEnd[]; + +#endif /* _LANGUAGE_C */ +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif +#endif /* !_UCODE_DEBUG_H */ + +/*======== End of ucode_debug.h ========*/ diff --git a/include/PR/ultraerror.h b/include/PR/ultraerror.h index ef470ba..81ab5ac 100644 --- a/include/PR/ultraerror.h +++ b/include/PR/ultraerror.h @@ -20,9 +20,9 @@ /************************************************************************** * - * $Revision: 1.23 $ - * $Date: 1997/02/11 08:38:08 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/ultraerror.h,v $ + * $Revision: 1.24 $ + * $Date: 1998/01/27 23:52:11 $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ultraerror.h,v $ * **************************************************************************/ @@ -150,7 +150,9 @@ extern "C" { #define ERR_ALCSPVNOTFREE 130 #define ERR_ALSEQOVERRUN 131 #define ERR_OSAISETNEXTBUFFER_ENDADDR 132 -#define ERR_ALMODDELAYOVERFLOW 133 +#define ERR_ALMODDELAYOVERFLOW 133 +#define ERR_OSVIEXTENDVSTART_VIMGR 134 +#define ERR_OSVIEXTENDVSTART_VALUE 135 #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) typedef void (*OSErrorHandler)(s16, s16, ...); diff --git a/include/PR/ultralog.h b/include/PR/ultralog.h index 9f37359..ebd7630 100644 --- a/include/PR/ultralog.h +++ b/include/PR/ultralog.h @@ -22,7 +22,7 @@ * * $Revision: 1.6 $ * $Date: 1997/02/11 08:39:05 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/ultralog.h,v $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ultralog.h,v $ * **************************************************************************/ diff --git a/include/PR/ultratypes.h b/include/PR/ultratypes.h index 58fef8b..b8b9b08 100644 --- a/include/PR/ultratypes.h +++ b/include/PR/ultratypes.h @@ -23,7 +23,7 @@ * * $Revision: 1.6 $ * $Date: 1997/12/17 04:02:06 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/ultratypes.h,v $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ultratypes.h,v $ * **************************************************************************/ @@ -34,15 +34,15 @@ */ #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) -typedef unsigned char u8; /* unsigned 8-bit */ -typedef unsigned short u16; /* unsigned 16-bit */ -typedef unsigned long u32; /* unsigned 32-bit */ -typedef unsigned long long u64; /* unsigned 64-bit */ +typedef unsigned char u8; /* unsigned 8-bit */ +typedef unsigned short int u16; /* unsigned 16-bit */ +typedef unsigned int u32; /* unsigned 32-bit */ +typedef unsigned long long int u64; /* unsigned 64-bit */ -typedef signed char s8; /* signed 8-bit */ -typedef short s16; /* signed 16-bit */ -typedef long s32; /* signed 32-bit */ -typedef long long s64; /* signed 64-bit */ +typedef signed char s8; /* signed 8-bit */ +typedef signed short int s16; /* signed 16-bit */ +typedef signed int s32; /* signed 32-bit */ +typedef signed long long int s64; /* signed 64-bit */ typedef volatile unsigned char vu8; /* unsigned 8-bit */ typedef volatile unsigned short vu16; /* unsigned 16-bit */ diff --git a/include/PR/uportals.h b/include/PR/uportals.h index 28a1466..42359fd 100644 --- a/include/PR/uportals.h +++ b/include/PR/uportals.h @@ -24,7 +24,7 @@ * * $Revision: 1.12 $ * $Date: 1997/02/11 08:40:49 $ - * $Source: /disk6/Master/cvsmdev2/PR/include/uportals.h,v $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/uportals.h,v $ * **************************************************************************/ diff --git a/include/PR/xstdio.h b/include/PR/xstdio.h new file mode 100644 index 0000000..b993644 --- /dev/null +++ b/include/PR/xstdio.h @@ -0,0 +1,58 @@ +#ifndef _XSTDIO_H +#define _XSTDIO_H +#include +#include +#include + +typedef struct +{ + union { + /* 00 */ long long s64; + double f64; + } value; + /* 08 */ char *buff; + /* 0c */ int n0; + /* 10 */ int num_leading_zeros; + /* 14 */ int part2_len; + /* 18 */ int num_mid_zeros; + /* 1c */ int part3_len; + /* 20 */ int num_trailing_zeros; + /* 24 */ int precision; + /* 28 */ int width; + /* 2c */ unsigned int size; + /* 30 */ unsigned int flags; + /* 34 */ char length; +} printf_struct; + +// these are the same struct. TODO: Merge +typedef struct { + /* 0x0 */ union { + /* 0x0 */ long long ll; + /* 0x0 */ double ld; + } v; + /* 0x8 */ unsigned char* s; + /* 0xC */ int n0; + /* 0x10 */ int nz0; + /* 0x14 */ int n1; + /* 0x18 */ int nz1; + /* 0x1C */ int n2; + /* 0x20 */ int nz2; + /* 0x24 */ int prec; + /* 0x28 */ int width; + /* 0x2C */ size_t nchar; + /* 0x30 */ unsigned int flags; + /* 0x34 */ char qual; +} _Pft; + +#define FLAGS_SPACE 1 +#define FLAGS_PLUS 2 +#define FLAGS_MINUS 4 +#define FLAGS_HASH 8 +#define FLAGS_ZERO 16 +typedef char *outfun(char*,const char*,size_t); + +int _Printf(outfun prout, char *arg, const char *fmt, va_list args); +void _Litob(_Pft *args, char type); +void _Ldtob(_Pft *args, char type); + +#endif diff --git a/include/assert.h b/include/assert.h new file mode 100644 index 0000000..a3736e3 --- /dev/null +++ b/include/assert.h @@ -0,0 +1,54 @@ +#ifndef __ASSERT_H__ +#define __ASSERT_H__ +#ifdef __cplusplus +extern "C" { +#endif +/************************************************************************** + * * + * Copyright (C) 1984, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +/* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T */ +/* The copyright notice above does not evidence any */ +/* actual or intended publication of such source code. */ + +#ident "$Revision: 1.17 $" + +/* ANSI C Notes: + * + * - THE IDENTIFIERS APPEARING OUTSIDE OF #ifdef __EXTENSIONS__ IN THIS + * standard header ARE SPECIFIED BY ANSI! CONFORMANCE WILL BE ALTERED + * IF ANY NEW IDENTIFIERS ARE ADDED TO THIS AREA UNLESS THEY ARE IN ANSI's + * RESERVED NAMESPACE. (i.e., unless they are prefixed by __[a-z] or + * _[A-Z]. For external objects, identifiers with the prefix _[a-z] + * are also reserved.) + */ + +#ifdef NDEBUG +#undef assert +#define assert(EX) ((void)0) + +#else + +extern void __assert(const char *, const char *, int); +#ifdef __ANSI_CPP__ +#define assert(EX) ((EX)?((void)0):__assert( # EX , __FILE__, __LINE__)) +#else +#define assert(EX) ((EX)?((void)0):__assert("EX", __FILE__, __LINE__)) +#endif +#endif /* NDEBUG */ + +#ifdef __cplusplus +} +#endif + +#endif /* !__ASSERT_H__ */ diff --git a/include/audio/initfx.h b/include/audio/initfx.h new file mode 100644 index 0000000..704e1f4 --- /dev/null +++ b/include/audio/initfx.h @@ -0,0 +1,59 @@ +/*==================================================================== + * initfx.h + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#ifndef __initfx__ +#define __initfx__ + +#define MAX_L0 AL_FX_BUFFER_SIZE/4 +#define MAX_L1 AL_FX_BUFFER_SIZE/4 +#define MAX_L2 AL_FX_BUFFER_SIZE/2 + +#define L0_INC MAX_L0/128 +#define L1_INC MAX_L1/128 +#define L2_INC MAX_L2/128 + +#define SMALLROOM_SECT_CNT 3 +#define SMALLROOM_SIZE AL_FX_BUFFER_SIZE +#define SMALLROOM_L0 880 /* 22 ms */ +#define SMALLROOM_C0 9830 +#define SMALLROOM_L1 1400 /* 35 ms */ +#define SMALLROOM_C1 3276 +#define SMALLROOM_L2 2640 /* 66 ms */ +#define SMALLROOM_C2 10000 +#define SMALLROOM_FILT_CNT 1 +#define SMALLROOM_FC0 0x4000 /* .25 */ + +#define BIGROOM_SECT_CNT 3 +#define BIGROOM_SIZE AL_FX_BUFFER_SIZE +#define BIGROOM_L0 1408 /* 32 ms */ +#define BIGROOM_C0 9830 +#define BIGROOM_L1 1984 /* 45 ms */ +#define BIGROOM_C1 9830 +#define BIGROOM_L2 3792 /* 86 ms */ +#define BIGROOM_C2 12000 +#define BIGROOM_FILT_CNT 1 +#define BIGROOM_FC0 0x4000 /* .25 */ + +#define ECHO_SIZE AL_FX_BUFFER_SIZE +#define ECHO_SECT_CNT 1 +#define ECHO_L0 7936 /* 180 ms */ +#define ECHO_C0 0x6000 + +#endif diff --git a/include/audio/synthInternals.h b/include/audio/synthInternals.h new file mode 100644 index 0000000..07c08bc --- /dev/null +++ b/include/audio/synthInternals.h @@ -0,0 +1,338 @@ +/*==================================================================== + * audioInternals.h + * + * Synopsis: + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#ifndef __audioInternals__ +#define __audioInternals__ + +#include + +/* + * filter message ids + */ +enum { + AL_FILTER_FREE_VOICE, + AL_FILTER_SET_SOURCE, + AL_FILTER_ADD_SOURCE, + AL_FILTER_ADD_UPDATE, + AL_FILTER_RESET, + AL_FILTER_SET_WAVETABLE, +/* AL_FILTER_SET_DMA_PROC,*/ +/* AL_FILTER_SKIP_LOOP,*/ + AL_FILTER_SET_DRAM, + AL_FILTER_SET_PITCH, + AL_FILTER_SET_UNITY_PITCH, + AL_FILTER_START, +/* AL_FILTER_SET_DECAY,*/ +/* AL_FILTER_SET_FC,*/ + AL_FILTER_SET_STATE, + AL_FILTER_SET_VOLUME, + AL_FILTER_SET_PAN, + AL_FILTER_START_VOICE_ALT, + AL_FILTER_START_VOICE, + AL_FILTER_STOP_VOICE, + AL_FILTER_SET_FXAMT +}; + +#define AL_MAX_RSP_SAMPLES 160 + +/* + * buffer locations based on AL_MAX_RSP_SAMPLES + */ +#define AL_DECODER_IN 0 +#define AL_RESAMPLER_OUT 0 +#define AL_TEMP_0 0 +#define AL_DECODER_OUT 320 +#define AL_TEMP_1 320 +#define AL_TEMP_2 640 +#define AL_MAIN_L_OUT 1088 +#define AL_MAIN_R_OUT 1408 +#define AL_AUX_L_OUT 1728 +#define AL_AUX_R_OUT 2048 + +/* + * filter types + */ +enum { + AL_ADPCM, + AL_RESAMPLE, + AL_BUFFER, + AL_SAVE, + AL_ENVMIX, + AL_FX, + AL_AUXBUS, + AL_MAINBUS +}; + +typedef struct ALParam_s { + struct ALParam_s *next; + s32 delta; + s16 type; + union { + f32 f; + s32 i; + } data; + union { + f32 f; + s32 i; + } moredata; + union { + f32 f; + s32 i; + } stillmoredata; + union { + f32 f; + s32 i; + } yetstillmoredata; +} ALParam; + +typedef struct { + struct ALParam_s *next; + s32 delta; + s16 type; + s16 unity; /* disable resampler */ + f32 pitch; + s16 volume; + ALPan pan; + u8 fxMix; + s32 samples; + struct ALWaveTable_s *wave; +} ALStartParamAlt; + +typedef struct { + struct ALParam_s *next; + s32 delta; + s16 type; + s16 unity; /* disable resampler */ + struct ALWaveTable_s *wave; +} ALStartParam; + +typedef struct { + struct ALParam_s *next; + s32 delta; + s16 type; + struct PVoice_s *pvoice; +} ALFreeParam; + +typedef Acmd *(*ALCmdHandler)(void *, s16 *, s32, s32, Acmd *); +typedef s32 (*ALSetParam)(void *, s32, void *); + +typedef struct ALFilter_s { + struct ALFilter_s *source; + ALCmdHandler handler; + ALSetParam setParam; + s16 inp; + s16 outp; + s32 type; +} ALFilter; + +void alFilterNew(ALFilter *f, ALCmdHandler h, ALSetParam s, s32 type); + +#define AL_MAX_ADPCM_STATES 3 /* Depends on number of subframes + * per frame and loop length + */ +typedef struct { + ALFilter filter; + ADPCM_STATE *state; + ADPCM_STATE *lstate; + ALRawLoop loop; + struct ALWaveTable_s *table; + s32 bookSize; + ALDMAproc dma; + void *dmaState; + s32 sample; + s32 lastsam; + s32 first; + s32 memin; +} ALLoadFilter; + +void alLoadNew(ALLoadFilter *f, ALDMANew dma, ALHeap *hp); +Acmd *alAdpcmPull(void *f, s16 *outp, s32 byteCount, s32 sampleOffset, Acmd *p); +Acmd *alRaw16Pull(void *f, s16 *outp, s32 byteCount, s32 sampleOffset, Acmd *p); +s32 alLoadParam(void *filter, s32 paramID, void *param); + +typedef struct ALResampler_s { + ALFilter filter; + RESAMPLE_STATE *state; + f32 ratio; + s32 upitch; + f32 delta; + s32 first; + ALParam *ctrlList; + ALParam *ctrlTail; + s32 motion; +} ALResampler; + +typedef struct { + s16 fc; + s16 fgain; + union { + s16 fccoef[16]; + s64 force_aligned; + } fcvec; + POLEF_STATE *fstate; + s32 first; +} ALLowPass; + +typedef struct { + u32 input; + u32 output; + s16 ffcoef; + s16 fbcoef; + s16 gain; + f32 rsinc; + f32 rsval; + s32 rsdelta; + f32 rsgain; + ALLowPass *lp; + ALResampler *rs; +} ALDelay; + +typedef s32 (*ALSetFXParam)(void *, s32, void *); +typedef struct { + struct ALFilter_s filter; + s16 *base; + s16 *input; + u32 length; + ALDelay *delay; + u8 section_count; + ALSetFXParam paramHdl; +} ALFx; + +void alFxNew(ALFx *r, ALSynConfig *c, ALHeap *hp); +Acmd *alFxPull(void *f, s16 *outp, s32 out, s32 sampleOffset, Acmd *p); +s32 alFxParam(void *filter, s32 paramID, void *param); +s32 alFxParamHdl(void *filter, s32 paramID, void *param); + +#define AL_MAX_MAIN_BUS_SOURCES 1 +typedef struct ALMainBus_s { + ALFilter filter; + s32 sourceCount; + s32 maxSources; + ALFilter **sources; +} ALMainBus; + +void alMainBusNew(ALMainBus *m, void *ptr, s32 len); +Acmd *alMainBusPull(void *f, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p); +s32 alMainBusParam(void *filter, s32 paramID, void *param); + +#define AL_MAX_AUX_BUS_SOURCES 8 +#define AL_MAX_AUX_BUS_FX 1 +typedef struct ALAuxBus_s { + ALFilter filter; + s32 sourceCount; + s32 maxSources; + ALFilter **sources; + ALFx fx[AL_MAX_AUX_BUS_FX]; +} ALAuxBus; + +void alAuxBusNew(ALAuxBus *m, void *ptr, s32 len); +Acmd *alAuxBusPull(void *f, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p); +s32 alAuxBusParam(void *filter, s32 paramID, void *param); + +void alResampleNew(ALResampler *r, ALHeap *hp); +Acmd *alResamplePull(void *f, s16 *outp, s32 out, s32 sampleOffset, Acmd *p); +s32 alResampleParam(void *f, s32 paramID, void *param); + +typedef struct ALSave_s { + ALFilter filter; + s32 dramout; + s32 first; +} ALSave; + +void alSaveNew(ALSave *r); +Acmd *alSavePull(void *f, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p); +s32 alSaveParam(void *f, s32 paramID, void *param); + +typedef struct ALEnvMixer_s { + ALFilter filter; + ENVMIX_STATE *state; + s16 pan; + s16 volume; + s16 cvolL; + s16 cvolR; + s16 dryamt; + s16 wetamt; + u16 lratl; + s16 lratm; + s16 ltgt; + u16 rratl; + s16 rratm; + s16 rtgt; + s32 delta; + s32 segEnd; + s32 first; + ALParam *ctrlList; + ALParam *ctrlTail; + ALFilter **sources; + s32 motion; +} ALEnvMixer; + +void alEnvmixerNew(ALEnvMixer *e, ALHeap *hp); +Acmd *alEnvmixerPull(void *f, s16 *outp, s32 out, s32 sampleOffset, Acmd *p); +s32 alEnvmixerParam(void *filter, s32 paramID, void *param); + + +/* + * heap stuff + */ +typedef struct { + s32 magic; /* check structure integrety */ + s32 size; /* size of this allocated block */ + u8 *file; /* file that this alloc was called from */ + s32 line; /* line that it was called from */ + s32 count; /* heap call number */ + s32 pad0; + s32 pad1; + s32 pad2; /* Make it 32 bytes */ +} HeapInfo; + +#define AL_CACHE_ALIGN 15 + +/* + * synth stuff + */ + +typedef struct PVoice_s { + ALLink node; + struct ALVoice_s *vvoice; + ALFilter *channelKnob; + ALLoadFilter decoder; + ALResampler resampler; + ALEnvMixer envmixer; + s32 offset; +} PVoice; + +/* + * prototypes for private driver functions + */ +ALParam *__allocParam(void); +void __freeParam(ALParam *param); +void _freePVoice(ALSynth *drvr, PVoice *pvoice); +void _collectPVoices(ALSynth *drvr); + +s32 _timeToSamples(ALSynth *ALSynth, s32 micros); +ALMicroTime _samplesToTime(ALSynth *synth, s32 samples); + +void _init_lpfilter(ALLowPass *lp); + +#endif + diff --git a/include/libc/math.h b/include/libc/math.h new file mode 100644 index 0000000..1cdac0f --- /dev/null +++ b/include/libc/math.h @@ -0,0 +1,35 @@ +#ifndef MATH_H +#define MATH_H + +#include "PR/ultratypes.h" + +#define M_PI 3.14159265358979323846f +#define M_SQRT2 1.41421356237309504880f +#define M_SQRT1_2 0.70710678118654752440f /* 1/sqrt(2) */ +#define FLT_MAX 340282346638528859811704183484516925440.0f +#define SHT_MAX 32767.0f +#define SHT_MINV (1.0f / SHT_MAX) + +typedef union { + f64 d; + struct { + u32 hi; + u32 lo; + } word; +} du; + +typedef union { + u32 i; + f32 f; +} fu; + +extern f32 __libm_qnan_f; + +float fabsf(float f); +#pragma intrinsic(fabsf) +float sqrtf(float f); +#pragma intrinsic(sqrtf) +double sqrt(double d); +#pragma intrinsic(sqrt) + +#endif diff --git a/include/macros.h b/include/macros.h index b00cc7a..cfc6183 100644 --- a/include/macros.h +++ b/include/macros.h @@ -1,12 +1,22 @@ #ifndef _MACROS_H_ #define _MACROS_H_ +#define true 1 +#define false 0 #ifndef __sgi #define GLOBAL_ASM(...) #endif +#ifdef _LANGUAGE_C +#define HW_REG(reg, type) *(volatile type*)((reg) | 0xA0000000) +#endif + #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) +#define SQ(x) ((x) * (x)) +#define ROUND(x) (s32)(((x) >= 0.0) ? ((x) + 0.5) : ((x) - 0.5)) + +#define assert #endif diff --git a/include/math.h b/include/math.h new file mode 100644 index 0000000..fc8e555 --- /dev/null +++ b/include/math.h @@ -0,0 +1,46 @@ +#ifndef MATH_H +#define MATH_H + +#include "PR/ultratypes.h" + +#define M_PI 3.14159265358979323846f +#define M_SQRT2 1.41421356237309504880f +#define M_SQRT1_2 0.70710678118654752440f /* 1/sqrt(2) */ +#define FLT_MAX 340282346638528859811704183484516925440.0f +#define SHT_MAX 32767.0f +#define SHT_MINV (1.0f / SHT_MAX) + +typedef float MtxF_t[4][4]; +typedef union { + MtxF_t mf; + struct { + float xx, yx, zx, wx, + xy, yy, zy, wy, + xz, yz, zz, wz, + xw, yw, zw, ww; + }; +} MtxF; + +typedef union { + f64 d; + struct { + u32 hi; + u32 lo; + } word; +} du; + +typedef union { + u32 i; + f32 f; +} fu; + +extern f32 __libm_qnan_f; + +float fabsf(float f); +#pragma intrinsic(fabsf) +float sqrtf(float f); +#pragma intrinsic(sqrtf) +double sqrt(double d); +#pragma intrinsic(sqrt) + +#endif diff --git a/include/stdarg.h b/include/stdarg.h new file mode 100644 index 0000000..a5d0b13 --- /dev/null +++ b/include/stdarg.h @@ -0,0 +1,42 @@ +#ifndef STDARG_H +#define STDARG_H + +// When not building with IDO, use the builtin vaarg macros for portability. +#ifndef __sgi +#define va_list __builtin_va_list +#define va_start __builtin_va_start +#define va_arg __builtin_va_arg +#define va_end __builtin_va_end +#else + +typedef char *va_list; +#define _FP 1 +#define _INT 0 +#define _STRUCT 2 + +#define _VA_FP_SAVE_AREA 0x10 +#define _VA_ALIGN(p, a) (((unsigned int)(((char *)p) + ((a) > 4 ? (a) : 4) - 1)) & -((a) > 4 ? (a) : 4)) +#define va_start(vp, parmN) (vp = ((va_list)&parmN + sizeof(parmN))) + +#define __va_stack_arg(list, mode) \ + ( \ + ((list) = (char *)_VA_ALIGN(list, __builtin_alignof(mode)) + \ + _VA_ALIGN(sizeof(mode), 4)), \ + (((char *)list) - (_VA_ALIGN(sizeof(mode), 4) - sizeof(mode)))) + +#define __va_double_arg(list, mode) \ + ( \ + (((long)list & 0x1) /* 1 byte aligned? */ \ + ? (list = (char *)((long)list + 7), (char *)((long)list - 6 - _VA_FP_SAVE_AREA)) \ + : (((long)list & 0x2) /* 2 byte aligned? */ \ + ? (list = (char *)((long)list + 10), (char *)((long)list - 24 - _VA_FP_SAVE_AREA)) \ + : __va_stack_arg(list, mode)))) + +#define va_arg(list, mode) ((mode *)(((__builtin_classof(mode) == _FP && \ + __builtin_alignof(mode) == sizeof(double)) \ + ? __va_double_arg(list, mode) \ + : __va_stack_arg(list, mode))))[-1] +#define va_end(__list) + +#endif +#endif diff --git a/include/stdlib.h b/include/stdlib.h new file mode 100644 index 0000000..ee1f140 --- /dev/null +++ b/include/stdlib.h @@ -0,0 +1,21 @@ +#ifndef __STDLIB_H__ +#define __STDLIB_H__ + +#ifndef NULL +#define NULL 0 +#endif +typedef struct lldiv_t +{ + long long quot; + long long rem; +} lldiv_t; + +typedef struct ldiv_t +{ + long quot; + long rem; +} ldiv_t; + +lldiv_t lldiv(long long num, long long denom); +ldiv_t ldiv(long num, long denom); +#endif /* !__STDLIB_H__ */ diff --git a/include/string.h b/include/string.h new file mode 100644 index 0000000..9bc66c9 --- /dev/null +++ b/include/string.h @@ -0,0 +1,55 @@ +#ifndef __STRING_H__ +#define __STRING_H__ +#ifdef __cplusplus +extern "C" { +#endif +#ident "$Revision: 1.23 $" +/* +* +* Copyright 1992, Silicon Graphics, Inc. +* All Rights Reserved. +* +* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.; +* the contents of this file may not be disclosed to third parties, copied or +* duplicated in any form, in whole or in part, without the prior written +* permission of Silicon Graphics, Inc. +* +* RESTRICTED RIGHTS LEGEND: +* Use, duplication or disclosure by the Government is subject to restrictions +* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data +* and Computer Software clause at DFARS 252.227-7013, and/or in similar or +* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished - +* rights reserved under the Copyright Laws of the United States. +*/ +/* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */ +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + +/* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF */ +/* UNIX System Laboratories, Inc. */ +/* The copyright notice above does not evidence any */ +/* actual or intended publication of such source code. */ + + +#if !defined(_SIZE_T) && !defined(_SIZE_T_) +#define _SIZE_T +#if (_MIPS_SZLONG == 32) +typedef unsigned int size_t; +#endif +#if (_MIPS_SZLONG == 64) +typedef unsigned long size_t; +#endif +#endif + +#ifndef NULL +#define NULL 0 +#endif + +extern void *memcpy(void *, const void *, size_t); +extern const char *strchr(const char *, int); +extern size_t strlen(const char *); + +#ifdef __cplusplus +} +#endif +#endif /* !__STRING_H__ */ diff --git a/include/ultra64.h b/include/ultra64.h index 59befbf..bd4f939 100644 --- a/include/ultra64.h +++ b/include/ultra64.h @@ -38,4 +38,10 @@ #include #include +#include "ultra64/thread.h" + +#include "functions.h" +#include "macros.h" +#include "variables.h" + #endif diff --git a/include/ultra64/controller.h b/include/ultra64/controller.h new file mode 100644 index 0000000..e159dbb --- /dev/null +++ b/include/ultra64/controller.h @@ -0,0 +1,207 @@ +#ifndef _CONTROLLER_H +#define _CONTROLLER_H + +//should go somewhere else but +#define ARRLEN(x) ((s32)(sizeof(x) / sizeof(x[0]))) +#define CHNL_ERR(format) ((format.rxsize & CHNL_ERR_MASK) >> 4) + +typedef struct +{ + /* 0x0 */ u32 ramarray[15]; + /* 0x3C */ u32 pifstatus; +} OSPifRam; + +typedef struct +{ + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u16 button; + /* 0x6 */ s8 stick_x; + /* 0x7 */ s8 stick_y; +} __OSContReadFormat; + +typedef struct +{ + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u8 typeh; + /* 0x5 */ u8 typel; + /* 0x6 */ u8 status; + /* 0x7 */ u8 dummy1; +} __OSContRequestFormat; + +typedef struct +{ + /* 0x0 */ u8 txsize; + /* 0x1 */ u8 rxsize; + /* 0x2 */ u8 cmd; + /* 0x3 */ u8 typeh; + /* 0x4 */ u8 typel; + /* 0x5 */ u8 status; +} __OSContRequestFormatShort; + +typedef struct +{ + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u8 hi; + /* 0x5 */ u8 lo; + /* 0x6 */ u8 data[BLOCKSIZE]; + /* 0x26 */ u8 datacrc; +} __OSContRamReadFormat; + +typedef union { + /* 0x0 */ struct + { + /* 0x0 */ u8 bank; + /* 0x1 */ u8 page; + } inode_t; + /* 0x0 */ u16 ipage; +} __OSInodeUnit; + +typedef struct +{ + /* 0x0 */ u32 game_code; + /* 0x4 */ u16 company_code; + /* 0x6 */ __OSInodeUnit start_page; + /* 0x8 */ u8 status; + /* 0x9 */ s8 reserved; + /* 0xA */ u16 data_sum; + /* 0xC */ u8 ext_name[PFS_FILE_EXT_LEN]; + /* 0x10 */ u8 game_name[PFS_FILE_NAME_LEN]; +} __OSDir; + +typedef struct +{ + /* 0x0 */ __OSInodeUnit inode_page[128]; +} __OSInode; + +typedef struct +{ + /* 0x0 */ u32 repaired; + /* 0x4 */ u32 random; + /* 0x8 */ u64 serial_mid; + /* 0x10 */ u64 serial_low; + /* 0x18 */ u16 deviceid; + /* 0x1A */ u8 banks; + /* 0x1B */ u8 version; + /* 0x1C */ u16 checksum; + /* 0x1E */ u16 inverted_checksum; +} __OSPackId; + +typedef struct +{ + /* 0x0 */ u8 txsize; + /* 0x1 */ u8 rxsize; + /* 0x2 */ u8 cmd; + /* 0x3 */ u8 address; + /* 0x4 */ u8 data[EEPROM_BLOCK_SIZE]; +} __OSContEepromFormat; + +//from: http://en64.shoutwiki.com/wiki/SI_Registers_Detailed#CONT_CMD_Usage +#define CONT_CMD_REQUEST_STATUS 0 +#define CONT_CMD_READ_BUTTON 1 +#define CONT_CMD_READ_MEMPACK 2 +#define CONT_CMD_WRITE_MEMPACK 3 +#define CONT_CMD_READ_EEPROM 4 +#define CONT_CMD_WRITE_EEPROM 5 +#define CONT_CMD_RESET 0xff + +#define CONT_CMD_REQUEST_STATUS_TX 1 +#define CONT_CMD_READ_BUTTON_TX 1 +#define CONT_CMD_READ_MEMPACK_TX 3 +#define CONT_CMD_WRITE_MEMPACK_TX 35 +#define CONT_CMD_READ_EEPROM_TX 2 +#define CONT_CMD_WRITE_EEPROM_TX 10 +#define CONT_CMD_RESET_TX 1 + +#define CONT_CMD_REQUEST_STATUS_RX 3 +#define CONT_CMD_READ_BUTTON_RX 4 +#define CONT_CMD_READ_MEMPACK_RX 33 +#define CONT_CMD_WRITE_MEMPACK_RX 1 +#define CONT_CMD_READ_EEPROM_RX 8 +#define CONT_CMD_WRITE_EEPROM_RX 1 +#define CONT_CMD_RESET_RX 3 + +#define CONT_CMD_NOP 0xff +#define CONT_CMD_END 0xfe //indicates end of a command +#define CONT_CMD_EXE 1 //set pif ram status byte to this to do a command + +#define DIR_STATUS_EMPTY 0 +#define DIR_STATUS_UNKNOWN 1 +#define DIR_STATUS_OCCUPIED 2 + + +typedef struct +{ + /* 0x0 */ __OSInode inode; + /* 0x100 */ u8 bank; + /* 0x101 */ u8 map[256]; +} __OSInodeCache; + +extern s32 __osEepStatus(OSMesgQueue *, OSContStatus *); +u16 __osSumcalc(u8 *ptr, int length); +s32 __osIdCheckSum(u16 *ptr, u16 *csum, u16 *icsum); +s32 __osRepairPackId(OSPfs *pfs, __OSPackId *badid, __OSPackId *newid); +s32 __osCheckPackId(OSPfs *pfs, __OSPackId *temp); +s32 __osGetId(OSPfs *pfs); +s32 __osCheckId(OSPfs *pfs); +s32 __osPfsRWInode(OSPfs *pfs, __OSInode *inode, u8 flag, u8 bank); +s32 __osPfsSelectBank(OSPfs *pfs, u8 bank); +s32 __osPfsDeclearPage(OSPfs *pfs, __OSInode *inode, int file_size_in_pages, int *first_page, u8 bank, int *decleared, int *last_page); +s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u8 bank, __OSInodeUnit *last_page); +s32 __osBlockSum(OSPfs *pfs, u8 page_no, u16 *sum, u8 bank); +s32 __osContRamRead(OSMesgQueue *mq, int channel, u16 address, u8 *buffer); +s32 __osContRamWrite(OSMesgQueue *mq, int channel, u16 address, u8 *buffer, int force); +void __osContGetInitData(u8 *pattern, OSContStatus *data); +void __osPackRequestData(u8 cmd); +void __osPfsRequestData(u8 cmd); +void __osPfsGetInitData(u8* pattern, OSContStatus* data); +u8 __osContAddressCrc(u16 addr); +u8 __osContDataCrc(u8 *data); +s32 __osPfsGetStatus(OSMesgQueue *queue, int channel); +s32 __osGbpakSelectBank(OSPfs *pfs, u8 bank); + +extern u8 __osContLastCmd; +extern OSTimer __osEepromTimer; +extern OSMesg __osEepromTimerMsg; +extern OSMesgQueue __osEepromTimerQ; +extern OSPifRam __osEepPifRam; +extern OSPifRam __osContPifRam; +extern OSPifRam __osPfsPifRam; +extern u8 __osMaxControllers; + +//some version of this almost certainly existed since there's plenty of times where it's used right before a return 0 +#define ERRCK(fn) \ + ret = fn; \ + if (ret != 0) \ + return ret; + +#define SET_ACTIVEBANK_TO_ZERO \ + if (pfs->activebank != 0) \ + { \ + pfs->activebank = 0; \ + ERRCK(__osPfsSelectBank(pfs)) \ + } + +#define PFS_CHECK_ID \ + if (__osCheckId(pfs) == PFS_ERR_NEW_PACK) \ + return PFS_ERR_NEW_PACK; +#endif + +#define PFS_CHECK_STATUS \ + if ((pfs->status & PFS_INITIALIZED) == 0) \ + return PFS_ERR_INVALID; + +#define PFS_GET_STATUS \ + __osSiGetAccess(); \ + ret = __osPfsGetStatus(queue, channel); \ + __osSiRelAccess(); \ + if (ret != 0) \ + return ret; diff --git a/include/ultra64/internal.h b/include/ultra64/internal.h new file mode 100644 index 0000000..a15df6a --- /dev/null +++ b/include/ultra64/internal.h @@ -0,0 +1,22 @@ +#ifndef ULTRA64_INTERNAL_H +#define ULTRA64_INTERNAL_H + +typedef struct { + /* 0x00 */ u32 initialized; + /* 0x04 */ OSThread* mgrThread; + /* 0x08 */ OSMesgQueue* cmdQueue; + /* 0x0C */ OSMesgQueue* eventQueue; + /* 0x10 */ OSMesgQueue* acccessQueue; + /* 0x14 */ s32 (*piDmaCallback)(s32, u32, void*, size_t); + /* 0x18 */ s32 (*epiDmaCallback)(OSPiHandle*, s32, u32, void*, size_t); +} OSMgrArgs; // size = 0x1C + +typedef struct { + /* 0x00 */ OSMesgQueue* queue; + /* 0x04 */ OSMesg msg; +} __OSEventState; // size = 0x08 + +extern OSMgrArgs __osPiDevMgr; +extern __OSEventState __osEventStateTab[]; + +#endif diff --git a/include/ultra64/thread.h b/include/ultra64/thread.h new file mode 100644 index 0000000..f4abb2b --- /dev/null +++ b/include/ultra64/thread.h @@ -0,0 +1,87 @@ +#ifndef ULTRA64_THREAD_H +#define ULTRA64_THREAD_H + +#define OS_PRIORITY_MAX 255 +#define OS_PRIORITY_VIMGR 254 +#define OS_PRIORITY_RMON 250 +#define OS_PRIORITY_RMONSPIN 200 +#define OS_PRIORITY_PIMGR 150 +#define OS_PRIORITY_SIMGR 140 +#define OS_PRIORITY_APPMAX 127 +#define OS_PRIORITY_IDLE 0 + +#define OS_PRIORITY_THREADTAIL -1 + +#define OS_STATE_STOPPED 1 +#define OS_STATE_RUNNABLE 2 +#define OS_STATE_RUNNING 4 +#define OS_STATE_WAITING 8 + +#define OS_FLAG_CPU_BREAK 1 +#define OS_FLAG_FAULT 2 + +#define THREAD_NEXT 0x00 +#define THREAD_PRI 0x04 +#define THREAD_QUEUE 0x08 +#define THREAD_TLNEXT 0x0C +#define THREAD_STATE 0x10 +#define THREAD_FLAGS 0x12 +#define THREAD_ID 0x14 +#define THREAD_FP 0x18 +#define THREAD_PROFILE 0x1C +#define THREAD_CONTEXT 0x20 +#define THREAD_AT (THREAD_CONTEXT + 0x000) +#define THREAD_V0 (THREAD_CONTEXT + 0x008) +#define THREAD_V1 (THREAD_CONTEXT + 0x010) +#define THREAD_A0 (THREAD_CONTEXT + 0x018) +#define THREAD_A1 (THREAD_CONTEXT + 0x020) +#define THREAD_A2 (THREAD_CONTEXT + 0x028) +#define THREAD_A3 (THREAD_CONTEXT + 0x030) +#define THREAD_T0 (THREAD_CONTEXT + 0x038) +#define THREAD_T1 (THREAD_CONTEXT + 0x040) +#define THREAD_T2 (THREAD_CONTEXT + 0x048) +#define THREAD_T3 (THREAD_CONTEXT + 0x050) +#define THREAD_T4 (THREAD_CONTEXT + 0x058) +#define THREAD_T5 (THREAD_CONTEXT + 0x060) +#define THREAD_T6 (THREAD_CONTEXT + 0x068) +#define THREAD_T7 (THREAD_CONTEXT + 0x070) +#define THREAD_S0 (THREAD_CONTEXT + 0x078) +#define THREAD_S1 (THREAD_CONTEXT + 0x080) +#define THREAD_S2 (THREAD_CONTEXT + 0x088) +#define THREAD_S3 (THREAD_CONTEXT + 0x090) +#define THREAD_S4 (THREAD_CONTEXT + 0x098) +#define THREAD_S5 (THREAD_CONTEXT + 0x0A0) +#define THREAD_S6 (THREAD_CONTEXT + 0x0A8) +#define THREAD_S7 (THREAD_CONTEXT + 0x0B0) +#define THREAD_T8 (THREAD_CONTEXT + 0x0B8) +#define THREAD_T9 (THREAD_CONTEXT + 0x0C0) +#define THREAD_GP (THREAD_CONTEXT + 0x0C8) +#define THREAD_SP (THREAD_CONTEXT + 0x0D0) +#define THREAD_S8 (THREAD_CONTEXT + 0x0D8) +#define THREAD_RA (THREAD_CONTEXT + 0x0E0) +#define THREAD_LO (THREAD_CONTEXT + 0x0E8) +#define THREAD_HI (THREAD_CONTEXT + 0x0F0) +#define THREAD_SR (THREAD_CONTEXT + 0x0F8) +#define THREAD_PC (THREAD_CONTEXT + 0x0FC) +#define THREAD_CAUSE (THREAD_CONTEXT + 0x100) +#define THREAD_BADVADDR (THREAD_CONTEXT + 0x104) +#define THREAD_RCP (THREAD_CONTEXT + 0x108) +#define THREAD_FPCSR (THREAD_CONTEXT + 0x10C) +#define THREAD_FP0 (THREAD_CONTEXT + 0x110) +#define THREAD_FP2 (THREAD_CONTEXT + 0x118) +#define THREAD_FP4 (THREAD_CONTEXT + 0x120) +#define THREAD_FP6 (THREAD_CONTEXT + 0x128) +#define THREAD_FP8 (THREAD_CONTEXT + 0x130) +#define THREAD_FP10 (THREAD_CONTEXT + 0x138) +#define THREAD_FP12 (THREAD_CONTEXT + 0x140) +#define THREAD_FP14 (THREAD_CONTEXT + 0x148) +#define THREAD_FP16 (THREAD_CONTEXT + 0x150) +#define THREAD_FP18 (THREAD_CONTEXT + 0x158) +#define THREAD_FP20 (THREAD_CONTEXT + 0x160) +#define THREAD_FP22 (THREAD_CONTEXT + 0x168) +#define THREAD_FP24 (THREAD_CONTEXT + 0x170) +#define THREAD_FP26 (THREAD_CONTEXT + 0x178) +#define THREAD_FP28 (THREAD_CONTEXT + 0x180) +#define THREAD_FP30 (THREAD_CONTEXT + 0x188) + +#endif diff --git a/splat.yaml b/splat.yaml index 61d00ef..83a5632 100644 --- a/splat.yaml +++ b/splat.yaml @@ -24,6 +24,7 @@ segments: - [0x0B70, bin, bootcode_font] - name: text type: code + bss_size: 0x85E30 start: 0x1000 vram: 0x80000400 subsegments: @@ -156,164 +157,216 @@ segments: - [0x57270, asm, libleo/readrtc] - [0x572D0, asm, libleo/leoseek] - [0x57390, asm, libleo/seek] - - [0x573F0, asm, libultra/io/piacs] - - [0x574B0, asm, libultra/os/setcause] - - [0x574C0, c, libultra/os/osSendMesg] - - [0x57610, c, libultra/os/osStopThread] - - [0x576D0, c, libultra/os/osRecvMesg] - - [0x57810, asm, libultra/os/setintmask] - - [0x578B0, asm, libultra/os/thread] - - [0x578F0, asm, libultra/gu/scale] - - [0x57990, asm, libultra/gu/sinf] - - [0x57B50, asm, libultra/al/sl] + - [0x573F0, c, libultra/io/piacs] + - [0x574B0, hasm, libultra/os/setcause] + - [0x574C0, c, libultra/os/sendmesg] + - [0x57610, c, libultra/os/stopthread] + - [0x576D0, c, libultra/os/recvmesg] + - [0x57810, hasm, libultra/os/setintmask] + - [0x578B0, c, libultra/os/dequeuethread] + - [0x578F0, c, libultra/gu/scale] + - [0x57990, c, libultra/gu/sinf] + - [0x57B50, c, libultra/al/sl] - [0x57C10, c, libultra/io/sptask] - - [0x57F00, asm, libultra/os/destroythread] - - [0x58010, asm, libultra/libc/ll] - - [0x582D0, asm, libultra/os/exceptasm] - - [0x58BD0, asm, libultra/libc/bzero] - - [0x58C70, asm] # unknown file(s) - - [0x58EC0, asm, libultra/io/gbpakcheckconnector] - - [0x59350, asm, libultra/io/gbpakpower] - - [0x59460, asm, libultra/io/controller] - - [0x597A0, asm, libultra/io/siacs] - - [0x598C0, asm, libultra/os/createthread] - - [0x59A10, asm, libultra/io/contreaddata] - - [0x59BF0, asm, libultra/os/setcount] - - [0x59C00, asm, libultra/io/conteeplongread] - - [0x59C90, asm, libultra/os/virtualtophysical] - - [0x59D10, asm, libultra/os/setsr] - - [0x59D20, asm, libultra/os/writebackdcache] - - [0x59DA0, asm, libultra/os/initialize] - - [0x5A0F0, asm, libultra/os/getsr] - - [0x5A100, asm, libultra/io/gbpakinit] - - [0x5A330, asm, libultra/io/pfsgetstatus] - - [0x5A560, asm, libultra/al/reverb] - - [0x5B1C0, asm, libultra/gu/perspective] - - [0x5B450, asm, libultra/io/sprawdma] - - [0x5B4E0, asm, libultra/io/sirawdma] - - [0x5B590, asm] # unknown file(s) - - [0x5B5E0, asm, libultra/io/viblack] - - [0x5B650, asm, libultra/io/sirawread] - - [0x5B6A0, asm, libultra/io/sptaskyield] - - [0x5B6C0, asm, libultra/gu/lookatref] - - [0x5BB50, asm, libultra/gu/mtxutil] - - [0x5BDC0, asm, libultra/io/visetmode] - - [0x5BE30, asm] # unknown file(s) - - [0x5C1E0, asm, libultra/os/probetlb] - - [0x5C2A0, asm] # unknown file(s) - - [0x5C420, asm, libultra/io/devmgr] - - [0x5C830, asm, libultra/io/pirawdma] - - [0x5C900, hasm, libultra/os/osGetCount] # RNG - - [0x5C910, asm, libultra/io/conteepprobe] - - [0x5C980, asm, libultra/io/conteepwrite] - - [0x5CD50, asm, libultra/os/getmemsize] - - [0x5CE70, asm, libultra/io/contpfs] - - [0x5D9F0, asm, libultra/os/seteventmesg] - - [0x5DAB0, asm, libultra/gu/sqrtf] - - [0x5DAC0, asm, libultra/os/afterprenmi] - - [0x5DAE0, asm, libultra/gu/mtxcatf] - - [0x5DCF0, asm, libultra/gu/mtxcatl] - - [0x5DDB0, asm, libultra/gu/random] - - [0x5DDE0, asm, libultra/libc/xprintf] - - [0x5EAA0, asm, libultra/io/gbpakgetstatus] - - [0x5EC20, asm, libultra/libc/sprintf] - - [0x5ECA0, asm, libultra/os/unmaptlball] - - [0x5ECF0, asm] # unknown file(s) - - [0x5EDD0, asm, libultra/al/heapinit] - - [0x5EE10, asm, libultra/os/syncprintf] - - [0x5EE50, asm, libultra/libc/string] - - [0x5EEF0, asm, libultra/os/invalidcache] - - [0x5EFA0, asm, libultra/os/createmesgqueue] - - [0x5EFD0, asm, libultra/os/invalicache] - - [0x5F050, asm] # unknown file(s) - - [0x5F140, asm, libultra/io/sp] - - [0x5F170, asm, libultra/io/si] - - [0x5F1A0, asm, libultra/gu/translate] - - [0x5F240, asm, libultra/os/jammesg] - - [0x5F390, asm, libultra/os/setthreadpri] - - [0x5F470, asm, libultra/os/getthreadpri] - - [0x5F490, asm, libultra/io/epirawread] - - [0x5F5F0, asm, libultra/io/viswapbuf] - - [0x5F640, asm, libultra/io/epirawdma] - - [0x5F820, asm, libultra/io/sptaskyielded] - - [0x5F8A0, asm] # unknown file(s) - - [0x5FA40, asm, libultra/libc/bcmp] - - [0x5FB60, asm] # unknown file(s) - - [0x5FD50, asm, libultra/os/gettime] - - [0x5FDE0, asm, libultra/os/timerintr] - - [0x601E0, asm, libultra/al/synthesizer] - - [0x60860, asm, libultra/al/drvrNew] - - [0x61010, asm, libultra/al/mainbus] - - [0x61160, asm, libultra/al/auxbus] - - [0x61270, asm, libultra/al/env] - - [0x61EF0, asm, libultra/al/resample] - - [0x621F0, asm] # unknown file(s). might be load.o from AL library, but it's too different to tell. - - [0x62D40, asm, libultra/al/filter] - - [0x62D60, asm, libultra/al/save] - - [0x62E20, asm, libultra/os/setglobalintmask] - - [0x62E70, asm, libultra/io/aisetfreq] - - [0x62FC0, asm, libultra/io/dpctr] - - [0x63010, asm, libultra/os/getactivequeue] - - [0x63020, asm, libultra/gu/normalize] - - [0x630B0, asm, libultra/os/setcompare] - - [0x630C0, asm, libultra/io/aigetstat] - - [0x630D0, asm, libultra/io/dpsetstat] - - [0x630E0, asm, libultra/al/copy] - - [0x63160, asm, libultra/libc/bcopy] - - [0x63470, asm, libultra/os/resetglobalintmask] - - [0x634D0, asm, libultra/gu/ortho] - - [0x63690, asm, libultra/os/interrupt] - - [0x63720, asm, libultra/io/vi] - - [0x63860, asm, libultra/io/viswapcontext] + - [0x57F00, c, libultra/os/destroythread] + - [0x58010, c, libultra/libc/ll] + - [0x582D0, hasm, libultra/os/exceptasm] + - [0x58BD0, hasm, libultra/libc/bzero] + - [0x58C70, c, libultra/al/bnkf] + - [0x58EC0, c, libultra/io/gbpakcheckconnector] + - [0x59350, c, libultra/io/gbpakpower] + - [0x59460, c, libultra/io/controller] + - [0x597A0, c, libultra/io/siacs] + - [0x59860, bin, noppad_59860] # again with the weird nop padding. + - [0x598C0, c, libultra/os/createthread] + - [0x59A10, c, libultra/io/contreaddata] + - [0x59BF0, hasm, libultra/os/setcount] + - [0x59C00, c, libultra/io/conteeplongread] + - [0x59C90, c, libultra/os/virtualtophysical] + - [0x59D10, hasm, libultra/os/setsr] + - [0x59D20, hasm, libultra/os/writebackdcache] + - [0x59DA0, c, libultra/os/initialize] + - [0x5A0F0, hasm, libultra/os/getsr] + - [0x5A100, c, libultra/io/gbpakinit] + - [0x5A330, c, libultra/io/pfsgetstatus] + - [0x5A560, c, libultra/al/reverb] + - [0x5B1C0, c, libultra/gu/perspective] + - [0x5B450, c, libultra/io/sprawdma] + - [0x5B4E0, c, libultra/io/sirawdma] + - [0x5B590, c, libultra/os/epilinkhandle] + - [0x5B5E0, c, libultra/io/viblack] + - [0x5B650, c, libultra/io/sirawread] + - [0x5B6A0, c, libultra/io/sptaskyield] + - [0x5B6C0, c, libultra/gu/lookatref] + - [0x5BB50, c, libultra/gu/mtxutil] + - [0x5BDC0, c, libultra/io/visetmode] + - [0x5BE30, c, libultra/io/virepeatline] + - [0x5BEA0, c, libultra/io/pfsisplug] + - [0x5C1E0, hasm, libultra/os/probetlb] + - [0x5C2A0, c, libultra/io/pimgr] + - [0x5C410, bin, noppad_5C410] + - [0x5C420, c, libultra/io/devmgr] + - [0x5C830, c, libultra/io/pirawdma] + - [0x5C900, hasm, libultra/os/osGetCount] + - [0x5C910, c, libultra/io/conteepprobe] + - [0x5C980, c, libultra/io/conteepwrite] + - [0x5CD50, c, libultra/os/getmemsize] + - [0x5CE70, c, libultra/io/contpfs] + - [0x5D9F0, c, libultra/os/seteventmesg] + - [0x5DAB0, c, libultra/gu/sqrtf] + - [0x5DAC0, c, libultra/os/afterprenmi] + - [0x5DAE0, c, libultra/gu/mtxcatf] + - [0x5DCF0, c, libultra/gu/mtxcatl] + - [0x5DDB0, c, libultra/gu/random] + - [0x5DDE0, c, libultra/libc/xprintf] + - [0x5EAA0, c, libultra/io/gbpakgetstatus] + - [0x5EC20, c, libultra/libc/sprintf] + - [0x5ECA0, hasm, libultra/os/unmaptlball] + - [0x5ECF0, c, libultra/io/epidma] + - [0x5EDD0, c, libultra/al/heapinit] + - [0x5EE10, c, libultra/libc/syncprintf] + - [0x5EE50, c, libultra/libc/string] + - [0x5EEF0, hasm, libultra/os/invalidcache] + - [0x5EFA0, c, libultra/os/createmesgqueue] + - [0x5EFD0, hasm, libultra/os/invalicache] + - [0x5F050, c, libultra/io/conteeplongwrite] + - [0x5F140, c, libultra/io/sp] + - [0x5F170, c, libultra/io/si] + - [0x5F1A0, c, libultra/gu/translate] + - [0x5F240, c, libultra/os/jammesg] + - [0x5F390, c, libultra/os/setthreadpri] + - [0x5F470, c, libultra/os/getthreadpri] + - [0x5F490, c, libultra/io/epirawread] + - [0x5F5F0, c, libultra/io/viswapbuf] + - [0x5F640, c, libultra/io/epirawdma] + - [0x5F820, c, libultra/io/sptaskyielded] + - [0x5F8A0, c, libultra/gu/rotateRPY] + - [0x5FA40, hasm, libultra/libc/bcmp] + - [0x5FB60, c, libultra/gu/rotate] + - [0x5FD50, c, libultra/os/gettime] + - [0x5FDE0, c, libultra/os/timerintr] + - [0x601E0, c, libultra/al/synthesizer] + - [0x60860, c, libultra/al/drvrNew] + - [0x61010, c, libultra/al/mainbus] + - [0x61160, c, libultra/al/auxbus] + - [0x61270, c, libultra/al/env] + - [0x61EF0, c, libultra/al/resample] + - [0x621F0, c, libultra/al/load] + - [0x62D40, c, libultra/al/filter] + - [0x62D60, c, libultra/al/save] + - [0x62E20, c, libultra/os/setglobalintmask] + - [0x62E70, c, libultra/io/aisetfreq] + - [0x62FC0, c, libultra/io/dpctr] + - [0x63010, c, libultra/os/getactivequeue] + - [0x63020, c, libultra/gu/normalize] + - [0x630B0, hasm, libultra/os/setcompare] + - [0x630C0, c, libultra/io/aigetstat] + - [0x630D0, c, libultra/io/dpsetstat] + - [0x630E0, c, libultra/al/copy] + - [0x63160, hasm, libultra/libc/bcopy] + - [0x63470, c, libultra/os/resetglobalintmask] + - [0x634D0, c, libultra/gu/ortho] + - [0x63690, hasm, libultra/os/interrupt] + - [0x63720, c, libultra/io/vi] + - [0x63860, c, libultra/io/viswapcontext] - [0x63B60, c, libultra/io/pigetcmdq] - - [0x63B90, asm, libultra/gu/cosf] - - [0x63D00, asm, libultra/io/epiread] - - [0x63D50, asm, libultra/io/visetspecial] - - [0x63EB0, asm, libultra/os/settime] - - [0x63EE0, asm, libultra/io/visetevent] - - [0x63F50, asm, libultra/io/gbpakreadid] - - [0x64110, asm, libultra/io/cartrominit] - - [0x64270, asm, libultra/io/pfsselectbank] - - [0x642F0, asm, libultra/os/setfpccsr] - - [0x64300, asm, libultra/io/aigetlen] - - [0x64310, asm, libultra/io/epiwrite] - - [0x64360, asm, libultra/os/maptlbrdb] - - [0x643C0, asm, libultra/os/yieldthread] - - [0x64410, asm, libultra/io/contramwrite] - - [0x64660, asm, libultra/io/contramread] - - [0x64890, asm, libultra/io/crc] + - [0x63B90, c, libultra/gu/cosf] + - [0x63D00, c, libultra/io/epiread] + - [0x63D50, c, libultra/io/visetspecial] + - [0x63EB0, c, libultra/os/settime] + - [0x63EE0, c, libultra/io/visetevent] + - [0x63F50, c, libultra/io/gbpakreadid] + - [0x64110, c, libultra/io/cartrominit] + - [0x64270, c, libultra/io/pfsselectbank] + - [0x642F0, hasm, libultra/os/setfpccsr] + - [0x64300, c, libultra/io/aigetlen] + - [0x64310, c, libultra/io/epiwrite] + - [0x64360, hasm, libultra/os/maptlbrdb] + - [0x643C0, c, libultra/os/yieldthread] + - [0x64410, c, libultra/io/contramwrite] + - [0x64660, c, libultra/io/contramread] + - [0x64890, c, libultra/io/crc] - [0x64A00, hasm, libultra/os/__osGetCause] - - [0x64A10, asm, libultra/io/epirawwrite] - - [0x64B70, asm, libultra/os/settimer] - - [0x64C50, asm] # unknown file(s) - - [0x65710, asm, libultra/libc/ldiv] - - [0x658A0, asm, libultra/libc/xlitob] - - [0x65B40, asm, libultra/io/sirawwrite] - - [0x65B90, asm, libultra/io/spsetstat] - - [0x65BA0, asm, libultra/io/spgetstat] - - [0x65BC0, asm, libultra/io/vimgr] - - [0x65ED0, asm, libultra/io/vigetcurrcontext] - - [0x65EE0, asm, libultra/os/writebackdcacheall] - - [0x65F10, asm, libultra/al/heapalloc] - - [0x65F70, asm, libultra/os/startthread] - - [0x660C0, asm, libultra/io/visetxscale] - - [0x661F0, asm, libultra/io/visetyscale] - - [0x66250, asm, libultra/libc/llcvt] - - [0x66460, asm, libultra/al/synallocfx] - - [0x66500, asm, libultra/al/syndelete] - - [0x66510, asm, libultra/io/gbpakreadwrite] - - [0x666D0, asm, libultra/io/gbpakselectbank] - - [0x667A0, asm, libultra/io/aisetnextbuf] - - [0x66850, asm, libultra/io/ai] - - [0x66880, asm, libultra/io/conteepread] - - [0x66AD0, asm, libultra/io/vigetcurrframebuf] - - [0x66B10, asm, libultra/io/spsetpc] - - [0x66B50, asm, libultra/os/sethwinterrupt] + - [0x64A10, c, libultra/io/epirawwrite] + - [0x64B70, c, libultra/os/settimer] + - [0x64C50, c, libultra/libc/xldtob] + - [0x65710, c, libultra/libc/ldiv] + - [0x658A0, c, libultra/libc/xlitob] + - [0x65B40, c, libultra/io/sirawwrite] + - [0x65B90, c, libultra/io/spsetstat] + - [0x65BA0, c, libultra/io/spgetstat] + - [0x65BB0, bin, noppad_65BB0] + - [0x65BC0, c, libultra/io/vimgr] + - [0x65ED0, c, libultra/io/vigetcurrcontext] + - [0x65EE0, hasm, libultra/os/writebackdcacheall] + - [0x65F10, c, libultra/al/heapalloc] + - [0x65F70, c, libultra/os/startthread] + - [0x660C0, c, libultra/io/visetxscale] + - [0x661F0, c, libultra/io/visetyscale] + - [0x66250, c, libultra/libc/llcvt] + - [0x66460, c, libultra/al/synallocfx] + - [0x66500, c, libultra/al/syndelete] + - [0x66510, c, libultra/io/gbpakreadwrite] + - [0x666D0, c, libultra/io/gbpakselectbank] + - [0x667A0, c, libultra/io/aisetnextbuf] + - [0x66850, c, libultra/io/ai] + - [0x66880, c, libultra/io/conteepread] + - [0x66AD0, c, libultra/io/vigetcurrframebuf] + - [0x66B10, c, libultra/io/spsetpc] + - [0x66B50, c, libultra/os/sethwinterrupt] #- [0x66BC0, asm] - [0x66BC0, bin] # rest of rom part 1 + # .data is somewhere in here + - [0x7A2A0, .data, libultra/os/initialize] + - [0x7A2C0, .data, libultra/al/reverb] + - [0x7A2E0, bin, rom_data_7A2E0] + - [0x7B550, .data, libultra/gu/random] + - [0x7B560, .data, libultra/libc/xprintf] + - [0x7B5B0, .data, libultra/os/timerintr] + - [0x7B5C0, .data, libultra/al/drvrNew] + - [0x7B750, .data, libultra/al/env] + - [0x7B890, .data, libultra/io/vi] + - [0x7B900, bin, rom_data_7B900] + - [0x7B9F0, .data, libultra/io/gbpakreadid] + - [0x7BA40, .data, libultra/io/cartrominit] + - [0x7BA50, bin, rom_data_7BA50] + - [0x7BA60, .data, libultra/libc/xlitob] + - [0x7BA90, .data, libultra/io/vimgr] + - [0x7BAB0, .data, libultra/io/aisetnextbuf] + - [0x7BAC0, bin, rom_data_7BAC0] + # Start of .rodata - [0x7BAC0, .rodata, rsp] # rsp.c rodata - - [0x7BB10, bin, rom_rodata] # rest of rodata - - [0x7F980, bin] # rest of rom part 2 + - [0x7BB10, bin, rom_rodata_7BB10] + - [0x7EE90, .rodata, libultra/gu/sinf] + - [0x7EEE0, bin, rom_rodata_7EEE0] + - [0x7EF30, .rodata, libultra/al/reverb] + - [0x7EF60, .rodata, libultra/gu/perspective] + - [0x7EF70, .rodata, libultra/io/devmgr] + - [0x7EF90, .rodata, libultra/libc/xprintf] + - [0x7F090, .rodata, libultra/gu/rotateRPY] + - [0x7F0A0, .rodata, libultra/gu/rotate] + - [0x7F0B0, .rodata, libultra/al/synthesizer] + - [0x7F0C0, .rodata, libultra/al/drvrNew] + - [0x7F0E0, .rodata, libultra/al/env] + - [0x7F130, .rodata, libultra/al/resample] + - [0x7F180, .rodata, libultra/gu/cosf] + - [0x7F1D0, bin, rom_rodata_7F1D0] + - [0x7F1E0, .rodata, libultra/libc/xldtob] + - [0x7F240, .rodata, libultra/libc/llcvt] + - [0x7F250, bin, rom_rodata_7F250] + - [0x7F980] + + # .bss + - {vram: 0x8007F190, type: .bss, name: main} + - {vram: 0x80081900, type: .bss, name: rsp} + - {vram: 0x80083CA0, type: .bss, name: unk_bss} + - {vram: 0x80103880, type: .bss, name: libultra/gu/rotate} + - {vram: 0x80103890, type: .bss, name: libultra/os/timerintr} + - {vram: 0x801038E4, type: .bss, name: libultra/io/cartrominit} + - {vram: 0x80103950, type: .bss, name: libultra/io/vimgr} + + # rest of the ROM + - [0x7F980, bin] - [0x2000000] diff --git a/src/dp_intro.c b/src/dp_intro.c index 31e1d20..c717344 100644 --- a/src/dp_intro.c +++ b/src/dp_intro.c @@ -76,7 +76,7 @@ extern u64 D_80084C68[0x1]; #define ALIGN16(val) (((val) + 0xF) & ~0xF) -extern s32 D_80000300; +extern s32 osTvType; extern char D_80068B74[]; extern f32 D_8007AF10; @@ -132,7 +132,7 @@ void func_80001444(struct UnkStruct80001380* arg0, struct UnkArray4* arg1, s32 a void func_80001474(s8 arg0, s8 arg1) { s32 var_v0; - if (D_80000300 == 2) { + if (osTvType == 2) { var_v0 = (arg0 * 2) + arg1 + 8; } else { var_v0 = (arg0 * 2) + arg1 + 4; @@ -142,7 +142,7 @@ void func_80001474(s8 arg0, s8 arg1) { osViSetSpecialFeatures(0x40U); osViSetSpecialFeatures(2U); osViSetSpecialFeatures(0x10U); - if (D_80000300 == 0) { + if (osTvType == 0) { osViSetYScale(D_8007AF10); } } @@ -191,7 +191,7 @@ void func_800015A8(void) { } if (D_80083CA0.unkAA8 != NULL) { osViSwapBuffer(D_80083CA0.unkAA8->unk8); - func_8005B230(0); + osViRepeatLine(0); if ((D_80083CA0.unkA9D != D_80083CA0.unkAAD) || (D_80083CA0.unkA9E != D_80083CA0.unkAAE)) { func_80001474((s8) D_80083CA0.unkA9D, (s8) D_80083CA0.unkA9E); } @@ -202,7 +202,7 @@ void func_800015A8(void) { } func_80008F54(D_80083CA0.unkAA8->unk8, *(u16 *)&D_80083CA0.unkAA8->unk4, 0x10); } else { - func_8005B230(1); + osViRepeatLine(1); osViSwapBuffer(D_80083CA0.unk9E0->unk8); if ((D_80083CA0.unkA9D != D_80083CA0.unkAAD) || (D_80083CA0.unkA9E != D_80083CA0.unkAAE)) { func_80001474((s8) D_80083CA0.unkA9D, (s8) D_80083CA0.unkA9E); @@ -253,7 +253,7 @@ void func_8000183C(void* arg) { } void func_800019C8(void) { - s32 temp_v0 = D_80000300; + s32 temp_v0 = osTvType; if ((temp_v0 != 1) && (temp_v0 != 2)) { osViBlack(1U); diff --git a/src/libultra/al/auxbus.c b/src/libultra/al/auxbus.c new file mode 100644 index 0000000..471ba41 --- /dev/null +++ b/src/libultra/al/auxbus.c @@ -0,0 +1,65 @@ +/*==================================================================== + * auxbus.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include "synthInternals.h" + +Acmd *alAuxBusPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, + Acmd *p) +{ + Acmd *ptr = p; + ALAuxBus *m = (ALAuxBus *)filter; + ALFilter **sources = m->sources; + s32 i; + + /* + * clear the output buffers here + */ + aClearBuffer(ptr++, AL_AUX_L_OUT, outCount<<1); + aClearBuffer(ptr++, AL_AUX_R_OUT, outCount<<1); + + for (i = 0; i < m->sourceCount; i++) { + ptr = (sources[i]->handler)(sources[i], outp, outCount, sampleOffset, + ptr); + } + + return ptr; +} + +s32 alAuxBusParam(void *filter, s32 paramID, void *param) +{ + ALAuxBus *m = (ALAuxBus *) filter; + ALFilter **sources = m->sources; + + switch (paramID) { + + case (AL_FILTER_ADD_SOURCE): + sources[m->sourceCount++] = (ALFilter *) param; + break; + + default: + /* ??? */ + break; + } + + return 0; + +} + diff --git a/src/libultra/al/bnkf.c b/src/libultra/al/bnkf.c new file mode 100644 index 0000000..dfd312f --- /dev/null +++ b/src/libultra/al/bnkf.c @@ -0,0 +1,143 @@ +/*==================================================================== + * bnkf.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include +#include + +/* + * ### when the file format settles down a little, I'll remove these + * ### for efficiency. + */ +static void _bnkfPatchBank(ALBank *bank, s32 offset, s32 table); +static void _bnkfPatchInst(ALInstrument *i, s32 offset, s32 table); +static void _bnkfPatchSound(ALSound *s, s32 offset, s32 table); +static void _bnkfPatchWaveTable(ALWaveTable *w, s32 offset, s32 table); + +void alSeqFileNew(ALSeqFile *file, u8 *base) +{ + s32 offset = (s32) base; + s32 i; + + /* + * patch the file so that offsets are pointers + */ + for (i = 0; i < file->seqCount; i++) { + file->seqArray[i].offset = (u8 *)((u8 *)file->seqArray[i].offset + offset); + } +} + +void alBnkfNew(ALBankFile *file, u8 *table) +{ + s32 offset = (s32) file; + s32 woffset = (s32) table; + + s32 i; + + /* + * check the file format revision in debug libraries + */ + ALFailIf(file->revision != AL_BANK_VERSION, ERR_ALBNKFNEW); + + /* + * patch the file so that offsets are pointers + */ + for (i = 0; i < file->bankCount; i++) { + file->bankArray[i] = (ALBank *)((u8 *)file->bankArray[i] + offset); + if(file->bankArray[i]) + _bnkfPatchBank(file->bankArray[i], offset, woffset); + } +} + +void _bnkfPatchBank(ALBank *bank, s32 offset, s32 table) +{ + s32 i; + + if (bank->flags) + return; + + bank->flags = 1; + + if (bank->percussion) { + bank->percussion = (ALInstrument *)((u8 *)bank->percussion + offset); + _bnkfPatchInst(bank->percussion, offset, table); + } + + for (i = 0; i < bank->instCount; i++) { + bank->instArray[i] = (ALInstrument *)((u8 *)bank->instArray[i] + + offset); + if(bank->instArray[i]) + _bnkfPatchInst(bank->instArray[i], offset, table); + } +} + +void _bnkfPatchInst(ALInstrument *inst, s32 offset, s32 table) +{ + s32 i; + + if (inst->flags) + return; + + inst->flags = 1; + + for (i = 0; i < inst->soundCount; i++) { + inst->soundArray[i] = (ALSound *)((u8 *)inst->soundArray[i] + + offset); + _bnkfPatchSound(inst->soundArray[i], offset, table); + + } +} + +void _bnkfPatchSound(ALSound *s, s32 offset, s32 table) +{ + if (s->flags) + return; + + s->flags = 1; + + s->envelope = (ALEnvelope *)((u8 *)s->envelope + offset); + s->keyMap = (ALKeyMap *)((u8 *)s->keyMap + offset); + + s->wavetable = (ALWaveTable *)((u8 *)s->wavetable + offset); + _bnkfPatchWaveTable(s->wavetable, offset, table); +} + +void _bnkfPatchWaveTable(ALWaveTable *w, s32 offset, s32 table) +{ + if (w->flags) + return; + + w->flags = 1; + + w->base += table; + + /* sct 2/14/96 - patch wavetable loop info based on type. */ + if (w->type == AL_ADPCM_WAVE) + { + w->waveInfo.adpcmWave.book = (ALADPCMBook *)((u8 *)w->waveInfo.adpcmWave.book + offset); + if (w->waveInfo.adpcmWave.loop) + w->waveInfo.adpcmWave.loop = (ALADPCMloop *)((u8 *)w->waveInfo.adpcmWave.loop + offset); + } + else if (w->type == AL_RAW16_WAVE) + { + if (w->waveInfo.rawWave.loop) + w->waveInfo.rawWave.loop = (ALRawLoop *)((u8 *)w->waveInfo.rawWave.loop + offset); + } +} diff --git a/src/libultra/al/copy.c b/src/libultra/al/copy.c new file mode 100644 index 0000000..e1d7955 --- /dev/null +++ b/src/libultra/al/copy.c @@ -0,0 +1,34 @@ +/*==================================================================== + * copy.c + * + * Synopsis: + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include + +void alCopy(void *src, void *dest, s32 len) +{ + s32 i; + u8 *s = (u8 *)src; + u8 *d = (u8 *)dest; + + for (i = 0; i < len; i++){ + *d++ = *s++; + } +} diff --git a/src/libultra/al/drvrNew.c b/src/libultra/al/drvrNew.c new file mode 100644 index 0000000..f5e2ba2 --- /dev/null +++ b/src/libultra/al/drvrNew.c @@ -0,0 +1,305 @@ +/*==================================================================== + * drvrNew.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include "synthInternals.h" +#include +#include "initfx.h" + +// TODO: this comes from a header +#ident "$Revision: 1.49 $" + +/* + * WARNING: THE FOLLOWING CONSTANT MUST BE KEPT IN SYNC + * WITH SCALING IN MICROCODE!!! + */ +#define SCALE 16384 + +/* + * the following arrays contain default parameters for + * a few hopefully useful effects. + */ +#define ms *(((s32)((f32)44.1))&~0x7) + + +static s32 SMALLROOM_PARAMS[26] = { + /* sections length */ + 3, 100 ms, + /* chorus chorus filter + input output fbcoef ffcoef gain rate depth coef */ + 0, 54 ms, 9830, -9830, 0, 0, 0, 0, + 19 ms, 38 ms, 3276, -3276, 0x3fff, 0, 0, 0, + 0, 60 ms, 5000, 0, 0, 0, 0, 0x5000 +}; + +static s32 BIGROOM_PARAMS[34] = { + /* sections length */ + 4, 100 ms, + /* chorus chorus filter + input output fbcoef ffcoef gain rate depth coef */ + 0, 66 ms, 9830, -9830, 0, 0, 0, 0, + 22 ms, 54 ms, 3276, -3276, 0x3fff, 0, 0, 0, + 66 ms, 91 ms, 3276, -3276, 0x3fff, 0, 0, 0, + 0, 94 ms, 8000, 0, 0, 0, 0, 0x5000 +}; + +static s32 ECHO_PARAMS[10] = { + /* sections length */ + 1, 200 ms, + /* chorus chorus filter + input output fbcoef ffcoef gain rate depth coef */ + 0, 179 ms, 12000, 0, 0x7fff, 0, 0, 0 +}; + +static s32 CHORUS_PARAMS[10] = { + /* sections length */ + 1, 20 ms, + /* chorus chorus filter + input output fbcoef ffcoef gain rate depth coef */ + 0, 5 ms, 0x4000, 0, 0x7fff, 7600, 700, 0 +}; + +static s32 FLANGE_PARAMS[10] = { + /* sections length */ + 1, 20 ms, + /* chorus chorus filter + input output fbcoef ffcoef gain rate depth coef */ + 0, 5 ms, 0, 0x5fff, 0x7fff, 380, 500, 0 +}; + +static s32 NULL_PARAMS[10] = { + 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 +}; + + +void _init_lpfilter(ALLowPass *lp) +{ + s32 i, temp; + s16 fc; + f64 ffc, fcoef; + + temp = lp->fc * SCALE; + fc = temp >> 15; + lp->fgain = SCALE - fc; + + lp->first = 1; + for (i=0; i<8; i++) + lp->fcvec.fccoef[i] = 0; + + lp->fcvec.fccoef[i++] = fc; + fcoef = ffc = (f64)fc/SCALE; + + for (; i<16; i++){ + fcoef *= ffc; + lp->fcvec.fccoef[i] = (s16)(fcoef * SCALE); + } +} + + +void alFxNew(ALFx *r, ALSynConfig *c, ALHeap *hp) +{ + u16 i, j, k; + s32 *param = 0; + ALFilter *f = (ALFilter *) r; + ALDelay *d; + + alFilterNew(f, 0, alFxParam, AL_FX); + f->handler = alFxPull; + r->paramHdl = (ALSetFXParam)alFxParamHdl; + + switch (c->fxType) { + case AL_FX_SMALLROOM: param = SMALLROOM_PARAMS; break; + case AL_FX_BIGROOM: param = BIGROOM_PARAMS; break; + case AL_FX_ECHO: param = ECHO_PARAMS; break; + case AL_FX_CHORUS: param = CHORUS_PARAMS; break; + case AL_FX_FLANGE: param = FLANGE_PARAMS; break; + case AL_FX_CUSTOM: param = c->params; break; + default: param = NULL_PARAMS; break; + } + + + j = 0; + + r->section_count = param[j++]; + r->length = param[j++]; + + r->delay = alHeapAlloc(hp, r->section_count, sizeof(ALDelay)); + r->base = alHeapAlloc(hp, r->length, sizeof(s16)); + r->input = r->base; + + for ( k=0; k < r->length; k++) + r->base[k] = 0; + + for ( i=0; isection_count; i++ ){ + d = &r->delay[i]; + d->input = param[j++]; + d->output = param[j++]; + d->fbcoef = param[j++]; + d->ffcoef = param[j++]; + d->gain = param[j++]; + + if (param[j]) { +#define RANGE 2.0 +/* d->rsinc = ((f32) param[j++])/0xffffff; */ + d->rsinc = ((((f32)param[j++])/1000) * RANGE)/c->outputRate; + + /* + * the following constant is derived from: + * + * ratio = 2^(cents/1200) + * + * and therefore for hundredths of a cent + * x + * ln(ratio) = --------------- + * (120,000)/ln(2) + * where + * 120,000/ln(2) = 173123.40... + */ +#define CONVERT 173123.404906676 +#define LENGTH (d->output - d->input) + d->rsgain = (((f32) param[j++])/CONVERT) * LENGTH; + d->rsval = 1.0; + d->rsdelta = 0.0; + d->rs = alHeapAlloc(hp, 1, sizeof(ALResampler)); + d->rs->state = alHeapAlloc(hp, 1, sizeof(RESAMPLE_STATE)); + d->rs->delta = 0.0; + d->rs->first = 1; + } else { + d->rs = 0; + j++; + j++; + } + + if (param[j]) { + d->lp = alHeapAlloc(hp, 1, sizeof(ALLowPass)); + d->lp->fstate = alHeapAlloc(hp, 1, sizeof(POLEF_STATE)); + d->lp->fc = param[j++]; + _init_lpfilter(d->lp); + } else { + d->lp = 0; + j++; + } + } +} + +void alEnvmixerNew(ALEnvMixer *e, ALHeap *hp) +{ + alFilterNew((ALFilter *) e, alEnvmixerPull, alEnvmixerParam, AL_ENVMIX); + + e->state = alHeapAlloc(hp, 1, sizeof(ENVMIX_STATE)); + + e->first = 1; + e->motion = AL_STOPPED; + e->volume = 1; + e->ltgt = 1; + e->rtgt = 1; + e->cvolL = 1; + e->cvolR = 1; + e->dryamt = 0; + e->wetamt = 0; + e->lratm = 1; + e->lratl = 0; + e->lratm = 1; + e->lratl = 0; + e->delta = 0; + e->segEnd = 0; + e->pan = 0; + e->ctrlList = 0; + e->ctrlTail = 0; + e->sources = 0; +} + +void alLoadNew(ALLoadFilter *f, ALDMANew dmaNew, ALHeap *hp) +{ + s32 + i; + + /* + * init filter superclass + */ + + alFilterNew((ALFilter *) f, alAdpcmPull, alLoadParam, AL_ADPCM); + + f->state = alHeapAlloc(hp, 1, sizeof(ADPCM_STATE)); + f->lstate = alHeapAlloc(hp, 1, sizeof(ADPCM_STATE)); + + f->dma = dmaNew(&f->dmaState); + + /* + * init the adpcm state + */ + f->lastsam = 0; + f->first = 1; + f->memin = 0; +} + +void alResampleNew(ALResampler *r, ALHeap *hp) +{ + alFilterNew((ALFilter *) r, alResamplePull, alResampleParam, AL_RESAMPLE); + + /* + * Init resampler state + */ + r->state = alHeapAlloc(hp, 1, sizeof(RESAMPLE_STATE)); + r->delta = 0.0; + r->first = 1; + r->motion = AL_STOPPED; + r->ratio = 1.0; + r->upitch = 0; + r->ctrlList = 0; + r->ctrlTail = 0; + + /* state in the ucode is initialized by the A_INIT flag */ +} + +void alAuxBusNew(ALAuxBus *m, void *sources, s32 maxSources) +{ + alFilterNew((ALFilter *) m, alAuxBusPull, alAuxBusParam, AL_AUXBUS); + m->sourceCount = 0; + m->maxSources = maxSources; + m->sources = (ALFilter **)sources; +} + +void alMainBusNew(ALMainBus *m, void *sources, s32 maxSources) +{ + alFilterNew((ALFilter *) m, alMainBusPull, alMainBusParam, AL_MAINBUS); + m->sourceCount = 0; + m->maxSources = maxSources; + m->sources = (ALFilter **)sources; +} + +void alSaveNew(ALSave *f) +{ + /* + * init filter superclass + */ + + alFilterNew((ALFilter *) f, alSavePull, alSaveParam, AL_SAVE); + + /* + * init the save state, which is a virtual dram address + */ + + f->dramout = 0; + f->first = 1; + +} + diff --git a/src/libultra/al/env.c b/src/libultra/al/env.c new file mode 100644 index 0000000..3453afa --- /dev/null +++ b/src/libultra/al/env.c @@ -0,0 +1,594 @@ +/*==================================================================== + * envmixer.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include "synthInternals.h" +#include +#include +#include + +// TODO: these come from headers +#ident "$Revision: 1.49 $" +#ident "$Revision: 1.17 $" + +#ifdef AUD_PROFILE +extern u32 cnt_index, env_num, env_cnt, env_max, env_min, lastCnt[]; +extern u32 rate_num, rate_cnt, rate_max, rate_min; +extern u32 vol_num, vol_cnt, vol_max, vol_min; +#endif + +#define EQPOWER_LENGTH 128 +static s16 eqpower[ EQPOWER_LENGTH ] = { + 32767, 32764, 32757, 32744, 32727, 32704, + 32677, 32644, 32607, 32564, 32517, 32464, + 32407, 32344, 32277, 32205, 32127, 32045, + 31958, 31866, 31770, 31668, 31561, 31450, + 31334, 31213, 31087, 30957, 30822, 30682, + 30537, 30388, 30234, 30075, 29912, 29744, + 29572, 29395, 29214, 29028, 28838, 28643, + 28444, 28241, 28033, 27821, 27605, 27385, + 27160, 26931, 26698, 26461, 26220, 25975, + 25726, 25473, 25216, 24956, 24691, 24423, + 24151, 23875, 23596, 23313, 23026, 22736, + 22442, 22145, 21845, 21541, 21234, 20924, + 20610, 20294, 19974, 19651, 19325, 18997, + 18665, 18331, 17993, 17653, 17310, 16965, + 16617, 16266, 15913, 15558, 15200, 14840, + 14477, 14113, 13746, 13377, 13006, 12633, + 12258, 11881, 11503, 11122, 10740, 10357, + 9971, 9584, 9196, 8806, 8415, 8023, + 7630, 7235, 6839, 6442, 6044, 5646, + 5246, 4845, 4444, 4042, 3640, 3237, + 2833, 2429, 2025, 1620, 1216, 810, + 405, 0 +}; + +extern f64 __pow(f64, f64); + +/* + * prototypes for private enveloper functions + */ +static Acmd *_pullSubFrame(void *filter, s16 *inp, s16 *outp, s32 outCount, + s32 sampleOffset, Acmd *p) ; +static s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel); + +static f32 _getVol(f32 ivol, s32 samples, s16 ratem, u16 ratel); + +/*********************************************************************** + * Enveloper filter public interfaces + ***********************************************************************/ +Acmd *alEnvmixerPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, + Acmd *p) +{ + Acmd *ptr = p; + ALEnvMixer *e = (ALEnvMixer *)filter; + s16 inp; + s32 lastOffset; + s32 thisOffset = sampleOffset; + s32 samples; + s16 loutp = 0; + s32 fVol; + ALParam *thisParam; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + /* + * Force the input to be the resampler output + */ + inp = AL_RESAMPLER_OUT; + + while (e->ctrlList != 0) { + + lastOffset = thisOffset; + thisOffset = e->ctrlList->delta; + samples = thisOffset - lastOffset; + if (samples > outCount) + break; + +#ifdef _DEBUG + assert(samples >= 0); + assert(samples <= AL_MAX_RSP_SAMPLES); +#endif + + switch (e->ctrlList->type) { + case (AL_FILTER_START_VOICE_ALT): + { + ALStartParamAlt *param = (ALStartParamAlt *)e->ctrlList; + ALFilter *f = (ALFilter *) e; + s32 tmp; + + if (param->unity) { + (*e->filter.setParam)(&e->filter, + AL_FILTER_SET_UNITY_PITCH, 0); + } + + (*e->filter.setParam)(&e->filter, AL_FILTER_SET_WAVETABLE, + param->wave); + (*e->filter.setParam)(&e->filter, AL_FILTER_START, 0); + + e->first = 1; + + e->delta = 0; + e->segEnd = param->samples; + + tmp = ((s32)param->volume * (s32)param->volume) >> 15; + e->volume = (s16) tmp; + e->pan = param->pan; + e->dryamt = eqpower[param->fxMix]; + e->wetamt = eqpower[EQPOWER_LENGTH - param->fxMix - 1]; + + if (param->samples) { + e->cvolL = 1; + e->cvolR = 1; + } else { + /* + * Attack time is zero. Simply set the + * volume. We don't want an attack segment. + */ + e->cvolL = (e->volume * eqpower[e->pan]) >> 15; + e->cvolR = (e->volume * + eqpower[EQPOWER_LENGTH - e->pan - 1]) >> 15; + } + + if (f->source) { + union { + f32 f; + s32 i; + } data; + data.f = param->pitch; + (*f->source->setParam)(f->source, AL_FILTER_SET_PITCH, + (void *)data.i); + } + + } + + break; + + case (AL_FILTER_SET_FXAMT): + case (AL_FILTER_SET_PAN): + case (AL_FILTER_SET_VOLUME): + ptr = _pullSubFrame(e, &inp, &loutp, samples, sampleOffset, ptr); + + if (e->delta >= e->segEnd){ + /* + * We should have reached our target, calculate + * target in case e->segEnd was 0 + */ + e->ltgt = (e->volume * eqpower[e->pan]) >> 15; + e->rtgt = (e->volume * + eqpower[EQPOWER_LENGTH - e->pan - 1]) >> 15; + e->delta = e->segEnd; /* To prevent overflow */ + e->cvolL = e->ltgt; + e->cvolR = e->rtgt; + } else { + /* + * Estimate the current volume + */ + e->cvolL = _getVol(e->cvolL, e->delta, e->lratm, e->lratl); + e->cvolR = _getVol(e->cvolR, e->delta, e->rratm, e->rratl); + } + + /* + * We can't have volume of zero, because the envelope + * would never go anywhere from there + */ + if( e->cvolL == 0 ) e->cvolL = 1; + if( e->cvolR == 0 ) e->cvolR = 1; + + if (e->ctrlList->type == AL_FILTER_SET_PAN) + + /* + * This should result in a change to the current + * segment rate and target + */ + e->pan = (s16) e->ctrlList->data.i; + + if (e->ctrlList->type == AL_FILTER_SET_VOLUME){ + + /* + * Switching to a new segment + */ + e->delta = 0; + + /* + * Map volume non-linearly to give something close to + * loudness + */ + fVol = (e->ctrlList->data.i); + fVol = (fVol*fVol)>>15; + e->volume = (s16) fVol; + + e->segEnd = e->ctrlList->moredata.i; + + } + + if (e->ctrlList->type == AL_FILTER_SET_FXAMT){ + e->dryamt = eqpower[e->ctrlList->data.i]; + e->wetamt = eqpower[EQPOWER_LENGTH - e->ctrlList->data.i - 1]; + } + + /* + * Force a volume update + */ + e->first = 1; + break; + + case (AL_FILTER_START_VOICE): + { + ALStartParam *p = (ALStartParam *)e->ctrlList; + + /* + * Changing to PLAYING (since the previous state was + * persumable STOPPED, we'll just bump the output + * pointer rather than pull a subframe of zeros). + */ + if (p->unity) { + (*e->filter.setParam)(&e->filter, + AL_FILTER_SET_UNITY_PITCH, 0); + } + + (*e->filter.setParam)(&e->filter, AL_FILTER_SET_WAVETABLE, + p->wave); + (*e->filter.setParam)(&e->filter, AL_FILTER_START, 0); + } + break; + + case (AL_FILTER_STOP_VOICE): + { + /* + * Changing to STOPPED and reset the filter + */ + ptr = _pullSubFrame(e, &inp, &loutp, samples, sampleOffset, ptr); + (*e->filter.setParam)(&e->filter, AL_FILTER_RESET, 0); + } + break; + + case (AL_FILTER_FREE_VOICE): + { + ALSynth *drvr = &alGlobals->drvr; + ALFreeParam *param = (ALFreeParam *)e->ctrlList; + param->pvoice->offset = 0; + _freePVoice(drvr, (PVoice *)param->pvoice); + } + break; + + default: + /* + * Pull the reuired number of samples and then pass the message + * on down the chain + */ + ptr = _pullSubFrame(e, &inp, &loutp, samples, sampleOffset, ptr); + (*e->filter.setParam)(&e->filter, e->ctrlList->type, + (void *) e->ctrlList->data.i); + break; + } + loutp += (samples<<1); + outCount -= samples; + + /* + * put the param record back on the free list + */ + thisParam = e->ctrlList; + e->ctrlList = e->ctrlList->next; + if (e->ctrlList == 0) + e->ctrlTail = 0; + + __freeParam(thisParam); + + } + + ptr = _pullSubFrame(e, &inp, &loutp, outCount, sampleOffset, ptr); + + /* + * Prevent overflow in e->delta + */ + if (e->delta > e->segEnd) + e->delta = e->segEnd; + +#ifdef AUD_PROFILE + PROFILE_AUD(env_num, env_cnt, env_max, env_min); +#endif + return ptr; +} + +s32 +alEnvmixerParam(void *filter, s32 paramID, void *param) +{ + ALFilter *f = (ALFilter *) filter; + ALEnvMixer *e = (ALEnvMixer *) filter; + + switch (paramID) { + + case (AL_FILTER_ADD_UPDATE): + if (e->ctrlTail) { + e->ctrlTail->next = (ALParam *)param; + } else { + e->ctrlList = (ALParam *)param; + } + e->ctrlTail = (ALParam *)param; + + break; + + case (AL_FILTER_RESET): + e->first = 1; + e->motion = AL_STOPPED; + e->volume = 1; + if (f->source) + (*f->source->setParam)(f->source, AL_FILTER_RESET, param); + break; + + case (AL_FILTER_START): + e->motion = AL_PLAYING; + if (f->source) + (*f->source->setParam)(f->source, AL_FILTER_START, param); + break; + + case (AL_FILTER_SET_SOURCE): + f->source = (ALFilter *) param; + break; + + default: + if (f->source) + (*f->source->setParam)(f->source, paramID, param); + } + return 0; +} + +static +Acmd* _pullSubFrame(void *filter, s16 *inp, s16 *outp, s32 outCount, + s32 sampleOffset, Acmd *p) +{ + Acmd *ptr = p; + ALEnvMixer *e = (ALEnvMixer *)filter; + ALFilter *source= e->filter.source; + + /* filter must be playing and request non-zero output samples to pull. */ + if (e->motion != AL_PLAYING || !outCount) + return ptr; + + /* + * ask all filters upstream from us to build their command + * lists. + */ +#ifdef _DEBUG + assert(source); +#endif + + ptr = (*source->handler)(source, inp, outCount, sampleOffset, p); + + /* + * construct our portion of the command list + */ + aSetBuffer(ptr++, A_MAIN, *inp, AL_MAIN_L_OUT + *outp, outCount<<1); + aSetBuffer(ptr++, A_AUX, AL_MAIN_R_OUT + *outp, AL_AUX_L_OUT + *outp, + AL_AUX_R_OUT + *outp); + + if (e->first){ + e->first = 0; + + /* + * Calculate derived parameters + */ + e->ltgt = (e->volume * eqpower[e->pan]) >> 15; + e->lratm = _getRate((f64)e->cvolL, (f64)e->ltgt, + e->segEnd, &(e->lratl)); + e->rtgt = (e->volume * + eqpower[EQPOWER_LENGTH - e->pan - 1]) >> 15; + e->rratm = _getRate((f64)e->cvolR, (f64)e->rtgt, e->segEnd, + &(e->rratl)); + + aSetVolume(ptr++, A_LEFT | A_VOL, e->cvolL, 0, 0); + aSetVolume(ptr++, A_RIGHT | A_VOL, e->cvolR, 0, 0); + aSetVolume(ptr++, A_LEFT | A_RATE, e->ltgt, e->lratm, e->lratl); + aSetVolume(ptr++, A_RIGHT | A_RATE, e->rtgt, e->rratm, e->rratl); + aSetVolume(ptr++, A_AUX, e->dryamt, 0, e->wetamt); + aEnvMixer (ptr++, A_INIT | A_AUX, osVirtualToPhysical(e->state)); + } + else + aEnvMixer(ptr++, A_CONTINUE | A_AUX, osVirtualToPhysical(e->state)); + + /* + * bump the input buffer pointer + */ + + *inp += (outCount<<1); + e->delta += outCount; + + return ptr; +} + +#define EXP_MASK 0x7f800000 +#define MANT_MASK 0x807fffff + +f64 +_frexpf(f64 value, s32 *eptr) +{ + f64 absvalue; + + *eptr = 0; + if (value == 0.0) /* nothing to do for zero */ + return (value); + absvalue = (value > 0.0) ? value : -value; + for ( ; absvalue >= 1.0; absvalue *= 0.5) + ++*eptr; + for ( ; absvalue < 0.5; absvalue += absvalue) + --*eptr; + return (value > 0.0 ? absvalue : -absvalue); +} + +f64 +_ldexpf(f64 in, s32 ex) +{ + s32 exp; + + if ( ex ) { + exp = 1 << ex; + in *= (f64)exp; + } + + return ( in ); +} + +/* + _getRate() -- This function determines how to go from the + current volume level (vol) to the target + volume level (tgt) in some number of steps + (count). Two values are returned that are + used as multipliers to incrementally scale + the volume. Some tricky math is used and + is explained below. + RWW 28jun95 +*/ + +static +s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel) +{ + s16 s; + + f64 invn = 1.0/count, eps, a, fs, mant; + s32 i_invn, ex, indx; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + if (count == 0){ + if (tgt >= vol){ + *ratel = 0xffff; + return 0x7fff; + } + else{ + *ratel = 0; + return 0; + } + } + + if (tgt < 1.0) + tgt = 1.0; + if (vol <= 0) vol = 1; /* zero and neg values not allowed */ + +#define NBITS (3) +#define NPOS (1<>= 1; + } + } + + a *= (a *= (a *= a)); + s = (s16) a; + *ratel = (s16)(0xffff * (a - (f32) s)); + +#ifdef AUD_PROFILE + PROFILE_AUD(rate_num, rate_cnt, rate_max, rate_min); +#endif + return (s16)a; + +} + +static +f32 _getVol(f32 ivol, s32 samples, s16 ratem, u16 ratel) +{ + f32 r, a; + s32 i; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + /* + * Rate values are actually rate^8 + */ + samples >>=3; + if (samples == 0){ + return ivol; + } + r = ((f32) (ratem<<16) + (f32) ratel)/65536; + + a = 1.0; + for (i=0; i<32; i++){ + if( samples & 1 ) + a *= r; + samples >>= 1; + if (samples == 0) + break; + r *= r; + } + ivol *= a; +#ifdef AUD_PROFILE + PROFILE_AUD(vol_num, vol_cnt, vol_max, vol_min); +#endif + return ivol; +} + + + + + + + diff --git a/src/libultra/al/filter.c b/src/libultra/al/filter.c new file mode 100644 index 0000000..d88460b --- /dev/null +++ b/src/libultra/al/filter.c @@ -0,0 +1,32 @@ +/*==================================================================== + * filter.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include "synthInternals.h" + +void alFilterNew(ALFilter *f, ALCmdHandler h, ALSetParam s, s32 type) +{ + f->source = 0; + f->handler = h; + f->setParam = s; + f->inp = 0; + f->outp = 0; + f->type = type; +} diff --git a/src/libultra/al/heapalloc.c b/src/libultra/al/heapalloc.c new file mode 100644 index 0000000..8a37808 --- /dev/null +++ b/src/libultra/al/heapalloc.c @@ -0,0 +1,65 @@ +/*==================================================================== + * heapalloc.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" +#include +#include +#include + +void *alHeapDBAlloc(u8 *file, s32 line, ALHeap *hp, s32 num, s32 size) +{ + s32 bytes; + u8 *ptr = 0; + + bytes = (num*size + AL_CACHE_ALIGN) & ~AL_CACHE_ALIGN; + +#ifdef _DEBUG + hp->count++; + bytes += sizeof(HeapInfo); +#endif + + if ((hp->cur + bytes) <= (hp->base + hp->len)) { + + ptr = hp->cur; + hp->cur += bytes; + +#ifdef _DEBUG + ((HeapInfo *)ptr)->magic = AL_HEAP_MAGIC; + ((HeapInfo *)ptr)->size = bytes; + ((HeapInfo *)ptr)->count = hp->count; + if (file) { + ((HeapInfo *)ptr)->file = file; + ((HeapInfo *)ptr)->line = line; + } else { + ((HeapInfo *)ptr)->file = (u8 *) "unknown"; + ((HeapInfo *)ptr)->line = 0; + } + + ptr += sizeof(HeapInfo); +#endif + + } else { +#ifdef _DEBUG + __osError(ERR_ALHEAPNOFREE, 1, size); +#endif + } + + return ptr; +} diff --git a/src/libultra/al/heapinit.c b/src/libultra/al/heapinit.c new file mode 100644 index 0000000..9053375 --- /dev/null +++ b/src/libultra/al/heapinit.c @@ -0,0 +1,37 @@ +/*==================================================================== + * heapinit.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" +#include + +void alHeapInit(ALHeap *hp, u8 *base, s32 len) +{ + s32 extraAlign = (AL_CACHE_ALIGN+1) - ((s32) base & AL_CACHE_ALIGN); + + if (extraAlign != AL_CACHE_ALIGN+1) + hp->base = base + extraAlign; + else + hp->base = base; + + hp->len = len; + hp->cur = hp->base; + hp->count = 0; +} + diff --git a/src/libultra/al/load.c b/src/libultra/al/load.c new file mode 100644 index 0000000..af07075 --- /dev/null +++ b/src/libultra/al/load.c @@ -0,0 +1,471 @@ +/*==================================================================== + * load.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include "synthInternals.h" +#include +#include + +#ifndef MIN +# define MIN(a,b) (((a)<(b))?(a):(b)) +#endif + +#ifdef AUD_PROFILE +extern u32 cnt_index, adpcm_num, adpcm_cnt, adpcm_max, adpcm_min, lastCnt[]; +#endif + +#define ADPCMFBYTES 9 +#define LFSAMPLES 4 + +static +Acmd *_decodeChunk(Acmd *ptr, ALLoadFilter *f, s32 tsam, s32 nbytes, s16 outp, s16 inp, u32 flags); + +Acmd *alAdpcmPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p) +{ + Acmd *ptr = p; + s16 inp; + s32 tsam; + s32 nframes; + s32 nbytes; + s32 overFlow; + s32 startZero; + s32 nOver; + s32 nSam; + s32 op; + s32 nLeft; + s32 bEnd; + s32 decoded = 0; + s32 looped = 0; + + ALLoadFilter *f = (ALLoadFilter *)filter; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + if (outCount == 0) + return ptr; + + inp = AL_DECODER_IN; + aLoadADPCM(ptr++, f->bookSize, + K0_TO_PHYS(f->table->waveInfo.adpcmWave.book->book)); + + looped = (outCount + f->sample > f->loop.end) && (f->loop.count != 0); + if (looped) + nSam = f->loop.end - f->sample; + else + nSam = outCount; + + if (f->lastsam) + nLeft = ADPCMFSIZE - f->lastsam; + else + nLeft = 0; + tsam = nSam - nLeft; + if (tsam<0) tsam = 0; + + nframes = (tsam+ADPCMFSIZE-1)>>LFSAMPLES; + nbytes = nframes*ADPCMFBYTES; + + if (looped){ + + ptr = _decodeChunk(ptr, f, tsam, nbytes, *outp, inp, f->first); + + /* + * Fix up output pointer, which will be used as the input pointer + * by the following module. + */ + if (f->lastsam) + *outp += (f->lastsam<<1); + else + *outp += (ADPCMFSIZE<<1); + + /* + * Now fix up state info to reflect the loop start point + */ + f->lastsam = f->loop.start &0xf; + f->memin = (s32) f->table->base + ADPCMFBYTES * + ((s32) (f->loop.start>>LFSAMPLES) + 1); + f->sample = f->loop.start; + + bEnd = *outp; + while (outCount > nSam){ + + outCount -= nSam; + + /* + * Put next one after the end of the last lot - on the + * frame boundary (32 byte) after the end. + */ + op = (bEnd + ((nframes+1)<<(LFSAMPLES+1))) & ~0x1f; + + /* + * The actual end of data + */ + bEnd += (nSam<<1); + + /* + * -1 is loop forever - the loop count is not exact now + * for small loops! + */ + if ((f->loop.count != -1) && (f->loop.count != 0)) + f->loop.count--; + + /* + * What's left to compute. + */ + nSam = MIN(outCount, f->loop.end - f->loop.start); + tsam = nSam - ADPCMFSIZE + f->lastsam; + if (tsam<0) tsam = 0; + nframes = (tsam+ADPCMFSIZE-1)>>LFSAMPLES; + nbytes = nframes*ADPCMFBYTES; + ptr = _decodeChunk(ptr, f, tsam, nbytes, op, inp, f->first | A_LOOP); + /* + * Merge the two sections in DMEM. + */ + aDMEMMove(ptr++, op+(f->lastsam<<1), bEnd, nSam<<1); + + } + + f->lastsam = (outCount + f->lastsam) & 0xf; + f->sample += outCount; + f->memin += ADPCMFBYTES*nframes; +#ifdef AUD_PROFILE + PROFILE_AUD(adpcm_num, adpcm_cnt, adpcm_max, adpcm_min); +#endif + return ptr; + } + + /* + * The unlooped case, which is executed most of the time + */ + + nSam = nframes<memin + nbytes - ((s32) f->table->base + f->table->len); + if (overFlow < 0) + overFlow = 0; + nOver = (overFlow/ADPCMFBYTES)< nSam + nLeft) + nOver = nSam + nLeft; + + nbytes -= overFlow; + + if ((nOver - (nOver & 0xf))< outCount){ + decoded = 1; + ptr = _decodeChunk(ptr, f, nSam - nOver, nbytes, *outp, inp, f->first); + + if (f->lastsam) + *outp += (f->lastsam<<1); + else + *outp += (ADPCMFSIZE<<1); + + f->lastsam = (outCount + f->lastsam) & 0xf; + f->sample += outCount; + f->memin += ADPCMFBYTES*nframes; + } else { + f->lastsam = 0; + f->memin += ADPCMFBYTES*nframes; + } + + /* + * Put zeros in if necessary + */ + if (nOver){ + f->lastsam = 0; + if (decoded) + startZero = (nLeft + nSam - nOver)<<1; + else + startZero = 0; + aClearBuffer(ptr++, startZero + *outp, nOver<<1); + } +#ifdef AUD_PROFILE + PROFILE_AUD(adpcm_num, adpcm_cnt, adpcm_max, adpcm_min); +#endif + + return ptr; +} + +Acmd *alRaw16Pull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p) +{ + Acmd *ptr = p; + s32 nbytes; + s32 dramLoc; + s32 dramAlign; + s32 dmemAlign; + s32 overFlow; + s32 startZero; + s32 nSam; + s32 op; + + ALLoadFilter *f = (ALLoadFilter *)filter; + ALFilter *a = (ALFilter *) filter; + + if (outCount == 0) + return ptr; + + if ((outCount + f->sample > f->loop.end) && (f->loop.count != 0)){ + + nSam = f->loop.end - f->sample; + nbytes = nSam<<1; + if (nSam > 0){ + dramLoc = (f->dma)(f->memin, nbytes, f->dmaState); + + /* + * Make sure enough is loaded into DMEM to take care + * of 8 byte alignment + */ + dramAlign = dramLoc & 0x7; + nbytes += dramAlign; + aSetBuffer(ptr++, 0, *outp, 0, nbytes + 8 - (nbytes & 0x7)); + aLoadBuffer(ptr++, dramLoc - dramAlign); + } else + dramAlign = 0; + + /* + * Fix up output pointer to allow for dram alignment + */ + *outp += dramAlign; + + f->memin = (s32) f->table->base + (f->loop.start<<1); + f->sample = f->loop.start; + op = *outp; + + while (outCount > nSam){ + + op += (nSam<<1); + outCount -= nSam; + /* + * -1 is loop forever + */ + if ((f->loop.count != -1) && (f->loop.count != 0)) + f->loop.count--; + + /* + * What to compute. + */ + nSam = MIN(outCount, f->loop.end - f->loop.start); + nbytes = nSam<<1; + + /* + * Do the next section, same as last. + */ + dramLoc = (f->dma)(f->memin, nbytes, f->dmaState); + + /* + * Make sure enough is loaded into DMEM to take care + * of 8 byte alignment + */ + dramAlign = dramLoc & 0x7; + nbytes += dramAlign; + if (op & 0x7) + dmemAlign = 8 - (op & 0x7); + else + dmemAlign = 0; + + aSetBuffer(ptr++, 0, op + dmemAlign, 0, nbytes + 8 - (nbytes & 0x7)); + aLoadBuffer(ptr++, dramLoc - dramAlign); + + /* + * Merge the two sections in DMEM. + */ + if (dramAlign || dmemAlign) + aDMEMMove(ptr++, op+dramAlign+dmemAlign, op, nSam<<1); + + } + + f->sample += outCount; + f->memin += (outCount<<1); + + return ptr; + } + + /* + * The unlooped case, which is executed most of the time + * + * overFlow is the number of bytes past the end + * of the bitstream I try to generate + */ + + nbytes = outCount<<1; + overFlow = f->memin + nbytes - ((s32) f->table->base + f->table->len); + if (overFlow < 0) + overFlow = 0; + if (overFlow > nbytes) + overFlow = nbytes; + + if (overFlow < nbytes){ + if (outCount > 0){ + nbytes -= overFlow; + dramLoc = (f->dma)(f->memin, nbytes, f->dmaState); + + /* + * Make sure enough is loaded into DMEM to take care + * of 8 byte alignment + */ + dramAlign = dramLoc & 0x7; + nbytes += dramAlign; + aSetBuffer(ptr++, 0, *outp, 0, nbytes + 8 - (nbytes & 0x7)); + aLoadBuffer(ptr++, dramLoc - dramAlign); + } else + dramAlign = 0; + *outp += dramAlign; + + f->sample += outCount; + f->memin += outCount<<1; + } else { + f->memin += outCount<<1; + } + + /* + * Put zeros in if necessary + */ + if (overFlow){ + startZero = (outCount<<1) - overFlow; + if (startZero < 0) + startZero = 0; + aClearBuffer(ptr++, startZero + *outp, overFlow); + } + return ptr; +} + + +s32 +alLoadParam(void *filter, s32 paramID, void *param) +{ + ALLoadFilter *a = (ALLoadFilter *) filter; + ALFilter *f = (ALFilter *) filter; + + switch (paramID) { + case (AL_FILTER_SET_WAVETABLE): + a->table = (ALWaveTable *) param; + a->memin = (s32) a->table->base; + a->sample = 0; + switch (a->table->type){ + case (AL_ADPCM_WAVE): + + /* + * Set up the correct handler + */ + f->handler = alAdpcmPull; + + /* + * Make sure the table length is an integer number of + * frames + */ + a->table->len = ADPCMFBYTES * + ((s32) (a->table->len/ADPCMFBYTES)); + + a->bookSize = 2*a->table->waveInfo.adpcmWave.book->order* + a->table->waveInfo.adpcmWave.book->npredictors*ADPCMVSIZE; + if (a->table->waveInfo.adpcmWave.loop) { + a->loop.start = a->table->waveInfo.adpcmWave.loop->start; + a->loop.end = a->table->waveInfo.adpcmWave.loop->end; + a->loop.count = a->table->waveInfo.adpcmWave.loop->count; + alCopy(a->table->waveInfo.adpcmWave.loop->state, + a->lstate, sizeof(ADPCM_STATE)); + } else { + a->loop.start = a->loop.end = a->loop.count = 0; + } + break; + + case (AL_RAW16_WAVE): + f->handler = alRaw16Pull; + if (a->table->waveInfo.rawWave.loop) { + a->loop.start = a->table->waveInfo.rawWave.loop->start; + a->loop.end = a->table->waveInfo.rawWave.loop->end; + a->loop.count = a->table->waveInfo.rawWave.loop->count; + } else { + a->loop.start = a->loop.end = a->loop.count = 0; + } + break; + + default: + break; + + } + break; + + case (AL_FILTER_RESET): + a->lastsam = 0; + a->first = 1; + a->sample = 0; + + /* sct 2/14/96 - Check table since it is initialized to null and */ + /* Get loop info according to table type. */ + if (a->table) + { + a->memin = (s32) a->table->base; + if (a->table->type == AL_ADPCM_WAVE) + { + if (a->table->waveInfo.adpcmWave.loop) + a->loop.count = a->table->waveInfo.adpcmWave.loop->count; + } + else if (a->table->type == AL_RAW16_WAVE) + { + if (a->table->waveInfo.rawWave.loop) + a->loop.count = a->table->waveInfo.rawWave.loop->count; + } + } + + break; + + default: + break; + } +} + +Acmd *_decodeChunk(Acmd *ptr, ALLoadFilter *f, s32 tsam, s32 nbytes, s16 outp, s16 inp, u32 flags) + +{ + + s32 + dramAlign, + dramLoc; + + if (nbytes > 0){ + dramLoc = (f->dma)(f->memin, nbytes, f->dmaState); + /* + * Make sure enough is loaded into DMEM to take care + * of 8 byte alignment + */ + dramAlign = dramLoc & 0x7; + nbytes += dramAlign; + aSetBuffer(ptr++, 0, inp, 0, nbytes + 8 - (nbytes & 0x7)); + aLoadBuffer(ptr++, dramLoc - dramAlign); + } else + dramAlign = 0; + + if (flags & A_LOOP){ + aSetLoop(ptr++, K0_TO_PHYS(f->lstate)); + } + + aSetBuffer(ptr++, 0, inp + dramAlign, outp, tsam<<1); + aADPCMdec(ptr++, flags, K0_TO_PHYS(f->state)); + f->first = 0; + + return ptr; +} + + + diff --git a/src/libultra/al/mainbus.c b/src/libultra/al/mainbus.c new file mode 100644 index 0000000..d5c8eca --- /dev/null +++ b/src/libultra/al/mainbus.c @@ -0,0 +1,67 @@ +/*==================================================================== + * mainbus.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include "synthInternals.h" + +Acmd *alMainBusPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p) +{ + Acmd *ptr = p; + ALMainBus *m = (ALMainBus *)filter; + ALFilter **sources = m->sources; + s32 i; + + /* + * clear the output buffers here + */ + aClearBuffer(ptr++, AL_MAIN_L_OUT, outCount<<1); + aClearBuffer(ptr++, AL_MAIN_R_OUT, outCount<<1); + + for (i = 0; i < m->sourceCount; i++) { + ptr = (sources[i]->handler)(sources[i], outp, outCount, sampleOffset, + ptr); + aSetBuffer(ptr++, 0, 0, 0, outCount<<1); + aMix(ptr++, 0, 0x7fff, AL_AUX_L_OUT, AL_MAIN_L_OUT); + aMix(ptr++, 0, 0x7fff, AL_AUX_R_OUT, AL_MAIN_R_OUT); + } + + return ptr; +} + +s32 alMainBusParam(void *filter, s32 paramID, void *param) +{ + ALMainBus *m = (ALMainBus *) filter; + ALFilter **sources = m->sources; + + switch (paramID) { + + case (AL_FILTER_ADD_SOURCE): + sources[m->sourceCount++] = (ALFilter *) param; + break; + + default: + /* ??? */ + break; + } + + return 0; + +} + diff --git a/src/libultra/al/resample.c b/src/libultra/al/resample.c new file mode 100644 index 0000000..776c015 --- /dev/null +++ b/src/libultra/al/resample.c @@ -0,0 +1,149 @@ +/*==================================================================== + * resample.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include "synthInternals.h" +#include + +// TODO: this comes from a header +#ident "$Revision: 1.49 $" + +#ifdef AUD_PROFILE +extern u32 cnt_index, resampler_num, resampler_cnt, resampler_max, resampler_min, lastCnt[]; +#endif + +/*********************************************************************** + * Resampler filter public interfaces + ***********************************************************************/ +Acmd *alResamplePull(void *filter, s16 *outp, s32 outCnt, s32 sampleOffset, Acmd *p) +{ + ALResampler *f = (ALResampler *)filter; + Acmd *ptr = p; + s16 inp; + s32 inCount; + ALFilter *source = f->filter.source; + s32 incr; + f32 finCount; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + inp = AL_DECODER_OUT; + + if (!outCnt) + return ptr; + + /* + * check if resampler is required + */ + if (f->upitch) { + + ptr = (*source->handler)(source, &inp, outCnt, sampleOffset, p); + aDMEMMove(ptr++, inp, *outp, outCnt<<1); + + } else { + + /* + * clip to maximum allowable pitch + * FIXME: should we check for some minimum as well? + */ + if (f->ratio > MAX_RATIO) f->ratio = MAX_RATIO; + + /* + * quantize the pitch + */ + f->ratio = (s32)(f->ratio * UNITY_PITCH); + f->ratio = f->ratio / UNITY_PITCH; + + /* + * determine how many samples to generate + */ + finCount = f->delta + (f->ratio * (f32) outCnt); + inCount = (s32) finCount; + f->delta = finCount - (f32)inCount; + + /* + * ask all filters upstream from us to build their command + * lists. + */ + ptr = (*source->handler)(source, &inp, inCount, sampleOffset, p); + + /* + * construct our portion of the command list + */ + incr = (s32)(f->ratio * UNITY_PITCH); + aSetBuffer(ptr++, 0, inp, *outp, outCnt<<1); + aResample(ptr++, f->first, incr, osVirtualToPhysical(f->state)); + f->first = 0; + } + +#ifdef AUD_PROFILE + PROFILE_AUD(resampler_num, resampler_cnt, resampler_max, resampler_min); +#endif + return ptr; +} + +s32 alResampleParam(void *filter, s32 paramID, void *param) +{ + ALFilter *f = (ALFilter *) filter; + ALResampler *r = (ALResampler *) filter; + union { + f32 f; + s32 i; + } data; + + switch (paramID) { + + case (AL_FILTER_SET_SOURCE): + f->source = (ALFilter *) param; + break; + + case (AL_FILTER_RESET): + r->delta = 0.0; + r->first = 1; + r->motion = AL_STOPPED; + r->upitch = 0; + if (f->source) + (*f->source->setParam)(f->source, AL_FILTER_RESET, 0); + break; + + case (AL_FILTER_START): + r->motion = AL_PLAYING; + if (f->source) + (*f->source->setParam)(f->source, AL_FILTER_START, 0); + break; + + case (AL_FILTER_SET_PITCH): + data.i = (s32) param; + r->ratio = data.f; + break; + + case (AL_FILTER_SET_UNITY_PITCH): + r->upitch = 1; + break; + + default: + if (f->source) + (*f->source->setParam)(f->source, paramID, param); + break; + } + return 0; +} diff --git a/src/libultra/al/reverb.c b/src/libultra/al/reverb.c new file mode 100644 index 0000000..a4bcecf --- /dev/null +++ b/src/libultra/al/reverb.c @@ -0,0 +1,447 @@ +/*==================================================================== + * reverb.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include +#include "synthInternals.h" +#include +#include +#include +#include "initfx.h" + +#define RANGE 2.0 +extern ALGlobals *alGlobals; + +#ifdef AUD_PROFILE +extern u32 cnt_index, reverb_num, reverb_cnt, reverb_max, reverb_min, lastCnt[]; +extern u32 load_num, load_cnt, load_max, load_min, save_num, save_cnt, save_max, save_min; +#endif + +/* + * macros + */ +#define SWAP(in, out) \ +{ \ + s16 t = out; \ + out = in; \ + in = t; \ +} + +Acmd *_loadOutputBuffer(ALFx *r, ALDelay *d, s32 buff, s32 incount, Acmd *p); +Acmd *_loadBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p); +Acmd *_saveBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p); +Acmd *_filterBuffer(ALLowPass *lp, s32 buff, s32 count, Acmd *p); +f32 _doModFunc(ALDelay *d, s32 count); + +static s32 L_INC[] = { L0_INC, L1_INC, L2_INC }; + +/*********************************************************************** + * Reverb filter public interfaces + ***********************************************************************/ +Acmd *alFxPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, + Acmd *p) +{ + Acmd *ptr = p; + ALFx *r = (ALFx *)filter; + ALFilter *source = r->filter.source; + s16 i, buff1, buff2, input, output; + s16 *in_ptr, *out_ptr, gain, *prev_out_ptr = 0; + ALDelay *d, *pd; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + assert(source); + /* + * pull channels going into this effect first + */ + ptr = (*source->handler)(source, outp, outCount, sampleOffset, p); + + input = AL_AUX_L_OUT; + output = AL_AUX_R_OUT; + buff1 = AL_TEMP_0; + buff2 = AL_TEMP_1; + + aSetBuffer(ptr++, 0, 0, 0, outCount<<1); /* set the buffer size */ + aMix(ptr++, 0, 0xda83, AL_AUX_L_OUT, input); /* .707L = L - .293L */ + aMix(ptr++, 0, 0x5a82, AL_AUX_R_OUT, input); /* mix the AuxL and AuxR into the AuxL */ + /* and write the mixed value to the delay line at r->input */ + ptr = _saveBuffer(r, r->input, input, outCount, ptr); + + aClearBuffer(ptr++, output, outCount<<1); /* clear the AL_AUX_R_OUT */ + + for (i = 0; i < r->section_count; i++) { + d = &r->delay[i]; /* get the ALDelay structure */ + in_ptr = &r->input[-d->input]; + out_ptr = &r->input[-d->output]; + + if (in_ptr == prev_out_ptr) { + SWAP(buff1, buff2); + } else { /* load data at in_ptr into buff1 */ + ptr = _loadBuffer(r, in_ptr, buff1, outCount, ptr); + } + ptr = _loadOutputBuffer(r, d, buff2, outCount, ptr); + + if (d->ffcoef) { + aMix(ptr++, 0, (u16)d->ffcoef, buff1, buff2); + if (!d->rs && !d->lp) { + ptr = _saveBuffer(r, out_ptr, buff2, outCount, ptr); + } + } + + if (d->fbcoef) { + aMix(ptr++, 0, (u16)d->fbcoef, buff2, buff1); + ptr = _saveBuffer(r, in_ptr, buff1, outCount, ptr); + } + + if (d->lp) + ptr = _filterBuffer(d->lp, buff2, outCount, ptr); + + if (!d->rs) + ptr = _saveBuffer(r, out_ptr, buff2, outCount, ptr); + + if (d->gain) + aMix(ptr++, 0, (u16)d->gain, buff2, output); + + prev_out_ptr = &r->input[d->output]; + } + + /* + * bump the master delay line input pointer + * modulo the length + */ + r->input += outCount; + if (r->input > &r->base[r->length]) + r->input -= r->length; + + /* + * output already in AL_AUX_R_OUT + * just copy to AL_AUX_L_OUT + */ + aDMEMMove(ptr++, output, AL_AUX_L_OUT, outCount<<1); + +#ifdef AUD_PROFILE + PROFILE_AUD(reverb_num, reverb_cnt, reverb_max, reverb_min); +#endif + return ptr; +} + +s32 alFxParam(void *filter, s32 paramID, void *param) +{ + if(paramID == AL_FILTER_SET_SOURCE) + { + ALFilter *f = (ALFilter *) filter; + f->source = (ALFilter*) param; + } + return 0; +} + +/* + * This routine gets called by alSynSetFXParam. No checking takes place to + * verify the validity of the paramID or the param value. input and output + * values must be 8 byte aligned, so round down any param passed. + */ +s32 alFxParamHdl(void *filter, s32 paramID, void *param) +{ + ALFx *f = (ALFx *) filter; + s32 p = (paramID - 2) % 8; + s32 s = (paramID - 2) / 8; + s32 val = *(s32*)param; + +#define INPUT_PARAM 0 +#define OUTPUT_PARAM 1 +#define FBCOEF_PARAM 2 +#define FFCOEF_PARAM 3 +#define GAIN_PARAM 4 +#define CHORUSRATE_PARAM 5 +#define CHORUSDEPTH_PARAM 6 +#define LPFILT_PARAM 7 + + switch(p) + { + case INPUT_PARAM: + f->delay[s].input = (u32)val & 0xFFFFFFF8; + break; + case OUTPUT_PARAM: + f->delay[s].output = (u32)val & 0xFFFFFFF8; + break; + case FFCOEF_PARAM: + f->delay[s].ffcoef = (s16)val; + break; + case FBCOEF_PARAM: + f->delay[s].fbcoef = (s16)val; + break; + case GAIN_PARAM: + f->delay[s].gain = (s16)val; + break; + case CHORUSRATE_PARAM: + /* f->delay[s].rsinc = ((f32)val)/0xffffff; */ + f->delay[s].rsinc = ((((f32)val)/1000) * RANGE)/alGlobals->drvr.outputRate; + break; + +/* + * the following constant is derived from: + * + * ratio = 2^(cents/1200) + * + * and therefore for hundredths of a cent + * x + * ln(ratio) = --------------- + * (120,000)/ln(2) + * where + * 120,000/ln(2) = 173123.40... + */ +#define CONVERT 173123.404906676 +#define LENGTH (f->delay[s].output - f->delay[s].input) + + case CHORUSDEPTH_PARAM: + /*f->delay[s].rsgain = (((f32)val) / CONVERT) * LENGTH; */ + f->delay[s].rsgain = (((f32)val) / CONVERT) * LENGTH; + break; + case LPFILT_PARAM: + if(f->delay[s].lp) + { + f->delay[s].lp->fc = (s16)val; + _init_lpfilter(f->delay[s].lp); + } + break; + } + return 0; +} + +Acmd *_loadOutputBuffer(ALFx *r, ALDelay *d, s32 buff, s32 incount, Acmd *p) +{ + Acmd *ptr = p; + s32 ratio, count, rbuff = AL_TEMP_2; + s16 *out_ptr; + f32 fincount, fratio, delta; + s32 ramalign = 0, length; + static f32 val=0.0, lastval=-10.0; + static f32 blob=0; +/* + * The following section implements the chorus resampling. Modulate where you pull + * the samples from, since you need varying amounts of samples. + */ + if (d->rs) { + length = d->output - d->input; + delta = _doModFunc(d, incount); /* get the number of samples to modulate by */ + /* + * find ratio of delta to delay length and quantize + * to same resolution as resampler + */ + delta /= length; /* convert delta from number of samples to a pitch ratio */ + delta = (s32)(delta * UNITY_PITCH); /* quantize to value microcode will use */ + delta = delta / UNITY_PITCH; + fratio = 1.0 - delta; /* pitch ratio needs to be centered around 1, not zero */ + + /* d->rs->delta is the difference between the fractional and integer value + * of the samples needed. fratio * incount + rs->delta gives the number of samples + * needed for this frame. + */ + fincount = d->rs->delta + (fratio * (f32)incount); + count = (s32) fincount; /* quantize to s32 */ + d->rs->delta = fincount - (f32)count; /* calculate the round off and store */ + + /* + * d->rsdelta is amount the out_ptr has deviated from its starting position. + * You calc the out_ptr by taking d->output - d->rsdelta, and then using the + * negative of that as an index into the delay buffer. loadBuffer that uses this + * value then bumps it up if it is below the delay buffer. + */ + out_ptr = &r->input[-(d->output - d->rsdelta)]; + ramalign = ((s32)out_ptr & 0x7) >> 1; /* calculate the number of samples needed + to align the buffer*/ +#ifdef _DEBUG +#if 0 + if(length > 0) { + if (length - d->rsdelta > (s32)r->length) { + __osError(ERR_ALMODDELAYOVERFLOW, 1, length - d->rsdelta - r->length); + } + } + else if(length < 0) { + if ((-length) - d->rsdelta > (s32)r->length) { + __osError(ERR_ALMODDELAYOVERFLOW, 1, (-length) - d->rsdelta - r->length); + } + } +#endif +#endif + /* load the rbuff with samples, note that there will be ramalign worth of + * samples at the begining which you don't care about. */ + ptr = _loadBuffer(r, out_ptr - ramalign, rbuff, count + ramalign, ptr); + + /* convert fratio to 16 bit fraction for microcode use */ + ratio = (s32)(fratio * UNITY_PITCH); + /* set the buffers, and do the resample */ + aSetBuffer(ptr++, 0, rbuff + (ramalign<<1), buff, incount<<1); + aResample(ptr++, d->rs->first, ratio, osVirtualToPhysical(d->rs->state)); + + d->rs->first = 0; /* turn off first time flag */ + d->rsdelta += count - incount; /* add the number of samples to d->rsdelta */ + } else { + out_ptr = &r->input[-d->output]; + ptr = _loadBuffer(r, out_ptr, buff, incount, ptr); + } + + return ptr; +} +/* + * This routine is for loading data from the delay line buff. If the + * address of curr_ptr < r->base, it will force it to be within r->base + * space, If the load goes past the end of r->base it will wrap around. + * Cause count bytes of data at curr_ptr (within the delay line) to be + * loaded into buff. (Buff is a dmem buffer) + */ +Acmd *_loadBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p) +{ + Acmd *ptr = p; + s32 after_end, before_end; + s16 *updated_ptr, *delay_end; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + delay_end = &r->base[r->length]; + +#ifdef _DEBUG + if(curr_ptr > delay_end) + __osError(ERR_ALMODDELAYOVERFLOW, 1, delay_end - curr_ptr); +#endif + + if (curr_ptr < r->base) + curr_ptr += r->length; + updated_ptr = curr_ptr + count; + + if (updated_ptr > delay_end) { + after_end = updated_ptr - delay_end; + before_end = delay_end - curr_ptr; + + aSetBuffer(ptr++, 0, buff, 0, before_end<<1); + aLoadBuffer(ptr++, osVirtualToPhysical(curr_ptr)); + aSetBuffer(ptr++, 0, buff+(before_end<<1), 0, after_end<<1); + aLoadBuffer(ptr++, osVirtualToPhysical(r->base)); + } else { + aSetBuffer(ptr++, 0, buff, 0, count<<1); + aLoadBuffer(ptr++, osVirtualToPhysical(curr_ptr)); + } + + aSetBuffer(ptr++, 0, 0, 0, count<<1); + +#ifdef AUD_PROFILE + PROFILE_AUD(load_num, load_cnt, load_max, load_min); +#endif + return ptr; + +} + +/* + * This routine is for writing data to the delay line buff. If the + * address of curr_ptr < r->base, it will force it to be within r->base + * space. If the write goes past the end of r->base, it will wrap around + * Cause count bytes of data at buff to be written to delay line, curr_ptr. + */ +Acmd *_saveBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p) +{ + Acmd *ptr = p; + s32 after_end, before_end; + s16 *updated_ptr, *delay_end; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + delay_end = &r->base[r->length]; + if (curr_ptr < r->base) /* probably just security */ + curr_ptr += r->length; /* shouldn't occur */ + updated_ptr = curr_ptr + count; + + if (updated_ptr > delay_end) { /* if the data wraps past end of r->base */ + after_end = updated_ptr - delay_end; + before_end = delay_end - curr_ptr; + + aSetBuffer(ptr++, 0, 0, buff, before_end<<1); + aSaveBuffer(ptr++, osVirtualToPhysical(curr_ptr)); + aSetBuffer(ptr++, 0, 0, buff+(before_end<<1), after_end<<1); + aSaveBuffer(ptr++, osVirtualToPhysical(r->base)); + aSetBuffer(ptr++, 0, 0, 0, count<<1); + } else { + aSetBuffer(ptr++, 0, 0, buff, count<<1); + aSaveBuffer(ptr++, osVirtualToPhysical(curr_ptr)); + } + +#ifdef AUD_PROFILE + PROFILE_AUD(save_num, save_cnt, save_max, save_min); +#endif + return ptr; + +} + +Acmd *_filterBuffer(ALLowPass *lp, s32 buff, s32 count, Acmd *p) +{ + Acmd *ptr = p; + + aSetBuffer(ptr++, 0, buff, buff, count<<1); + aLoadADPCM(ptr++, 32, osVirtualToPhysical(lp->fcvec.fccoef)); + aPoleFilter(ptr++, lp->first, lp->fgain, osVirtualToPhysical(lp->fstate)); + lp->first = 0; + + return ptr; +} + + + +/* + * Generate a triangle wave from -1 to 1, and find the current position + * in the wave. (Rate of the wave is controlled by d->rsinc, which is chorus + * rate) Multiply the current triangle wave value by d->rsgain, (chorus depth) + * which is expressed in number of samples back from output pointer the chorus + * should go at it's full chorus. In otherwords, this function returns a number + * of samples the output pointer should modulate backwards. + */ +f32 _doModFunc(ALDelay *d, s32 count) +{ + f32 val; + + /* + * generate bipolar sawtooth + * from -RANGE to +RANGE + */ + d->rsval += d->rsinc * count; + d->rsval = (d->rsval > RANGE) ? d->rsval-(RANGE*2) : d->rsval; + + /* + * convert to monopolar triangle + * from 0 to RANGE + */ + val = d->rsval; + val = (val < 0) ? -val : val; + + /* + * convert to bipolar triangle + * from -1 to 1 + */ + val -= RANGE/2; + + return(d->rsgain * val); +} + + + diff --git a/src/libultra/al/save.c b/src/libultra/al/save.c new file mode 100644 index 0000000..bc15294 --- /dev/null +++ b/src/libultra/al/save.c @@ -0,0 +1,73 @@ +/*==================================================================== + * save.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include +#include "synthInternals.h" +#include +#include + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +Acmd *alSavePull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, + Acmd *p) + +{ + Acmd *ptr = p; + ALSave *f = (ALSave *)filter; + ALFilter *source = f->filter.source; + +#ifdef _DEBUG + assert(f->filter.source); +#endif + + ptr = (*source->handler)(source, outp, outCount, sampleOffset, ptr); + + aSetBuffer (ptr++, 0, 0, 0, outCount<<1); + aInterleave(ptr++, AL_MAIN_L_OUT, AL_MAIN_R_OUT); + aSetBuffer (ptr++, 0, 0, 0, outCount<<2); + aSaveBuffer(ptr++, f->dramout); + return ptr; +} + +s32 alSaveParam(void *filter, s32 paramID, void *param) +{ + ALSave *a = (ALSave *) filter; + ALFilter *f = (ALFilter *) filter; + s32 pp = (s32) param; + + switch (paramID) { + case (AL_FILTER_SET_SOURCE): + f->source = (ALFilter *) param; + break; + + case (AL_FILTER_SET_DRAM): + a->dramout = pp; + break; + + default: + break; + } + return 0; + +} + + + diff --git a/src/libultra/al/sl.c b/src/libultra/al/sl.c new file mode 100644 index 0000000..5f9a9dc --- /dev/null +++ b/src/libultra/al/sl.c @@ -0,0 +1,40 @@ +#include + +extern ALGlobals* D_80079640; + +void alUnlink(ALLink *ln) +{ + if (ln->next) { + ln->next->prev = ln->prev; + } + + if (ln->prev) { + ln->prev->next = ln->next; + } +} + +void alLink(ALLink *ln, ALLink *to) +{ + ln->next = to->next; + ln->prev = to; + + if (to->next) { + to->next->prev = ln; + } + + to->next = ln; +} + +void alClose(ALGlobals* glob) { + if (alGlobals != NULL) { + alSynDelete(&glob->drvr); + alGlobals = NULL; + } +} + +void alInit(ALGlobals* glob, ALSynConfig* c) { + if (alGlobals == NULL) { + alGlobals = glob; + alSynNew(&glob->drvr, c); + } +} diff --git a/src/libultra/al/synallocfx.c b/src/libultra/al/synallocfx.c new file mode 100644 index 0000000..5831062 --- /dev/null +++ b/src/libultra/al/synallocfx.c @@ -0,0 +1,31 @@ +/*==================================================================== + * synallocfx.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" + +ALFxRef *alSynAllocFX(ALSynth *s, s16 bus, ALSynConfig *c, ALHeap *hp) +{ + alFxNew(&s->auxBus[bus].fx[0], c, hp); + alFxParam(&s->auxBus[bus].fx[0], AL_FILTER_SET_SOURCE, + &s->auxBus[bus]); + alMainBusParam(s->mainBus, AL_FILTER_ADD_SOURCE,&s->auxBus[bus].fx[0]); + + return (ALFxRef)(&s->auxBus[bus].fx[0]); +} diff --git a/src/libultra/al/syndelete.c b/src/libultra/al/syndelete.c new file mode 100644 index 0000000..74abaa4 --- /dev/null +++ b/src/libultra/al/syndelete.c @@ -0,0 +1,26 @@ +/*==================================================================== + * syndelete.c + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" + +void alSynDelete(ALSynth *drvr) +{ + drvr->head = 0; +} diff --git a/src/libultra/al/synthesizer.c b/src/libultra/al/synthesizer.c new file mode 100644 index 0000000..d42a21a --- /dev/null +++ b/src/libultra/al/synthesizer.c @@ -0,0 +1,327 @@ +/*==================================================================== + * synthesizer.c + * + * Copyright 1993, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +#include "synthInternals.h" +#include + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +#ifdef AUD_PROFILE +#include +extern u32 cnt_index, drvr_num, drvr_cnt, drvr_max, drvr_min, lastCnt[]; +extern u32 client_num, client_cnt, client_max, client_min; +#endif + +#ifndef MIN +# define MIN(a,b) (((a)<(b))?(a):(b)) +#endif + +static s32 __nextSampleTime(ALSynth *drvr, ALPlayer **client); +static s32 _timeToSamplesNoRound(ALSynth *ALSynth, s32 micros); + +/*********************************************************************** + * Synthesis driver public interfaces + ***********************************************************************/ +void alSynNew(ALSynth *drvr, ALSynConfig *c) +{ + s32 i; + ALVoice *vv; + PVoice *pv; + ALVoice *vvoices; + PVoice *pvoices; + ALHeap *hp = c->heap; + ALSave *save; + ALFilter *sources; + ALParam *params; + ALParam *paramPtr; + + drvr->head = NULL; + drvr->numPVoices = c->maxPVoices; + drvr->curSamples = 0; + drvr->paramSamples = 0; + drvr->outputRate = c->outputRate; + drvr->maxOutSamples = AL_MAX_RSP_SAMPLES; + drvr->dma = (ALDMANew) c->dmaproc; + + save = alHeapAlloc(hp, 1, sizeof(ALSave)); + alSaveNew(save); + drvr->outputFilter = (ALFilter *)save; + + /* + * allocate and initialize the auxilliary effects bus. at present + * we only support 1 effects bus. + */ + drvr->auxBus = alHeapAlloc(hp, 1, sizeof(ALAuxBus)); + drvr->maxAuxBusses = 1; + sources = alHeapAlloc(hp, c->maxPVoices, sizeof(ALFilter *)); + alAuxBusNew(drvr->auxBus, sources, c->maxPVoices); + + /* + * allocate and initialize the main bus. + */ + drvr->mainBus = alHeapAlloc(hp, 1, sizeof(ALMainBus)); + sources = alHeapAlloc(hp, c->maxPVoices, sizeof(ALFilter *)); + alMainBusNew(drvr->mainBus, sources, c->maxPVoices); + + if (c->fxType != AL_FX_NONE){ + /* + * Allocate an effect and set parameters + */ + alSynAllocFX(drvr, 0, c, hp); + } else + /* + * Connect the aux bus to the main bus + */ + alMainBusParam(drvr->mainBus, AL_FILTER_ADD_SOURCE, &drvr->auxBus[0]); + + /* + * Build the physical voice lists + */ + drvr->pFreeList.next = 0; + drvr->pFreeList.prev = 0; + drvr->pLameList.next = 0; + drvr->pLameList.prev = 0; + drvr->pAllocList.next = 0; + drvr->pAllocList.prev = 0; + + pvoices = alHeapAlloc(hp, c->maxPVoices, sizeof(PVoice)); + for (i = 0; i < c->maxPVoices; i++) { + pv = &pvoices[i]; + alLink((ALLink *)pv, &drvr->pFreeList); + pv->vvoice = 0; + + alLoadNew(&pv->decoder, drvr->dma, hp); + alLoadParam(&pv->decoder, AL_FILTER_SET_SOURCE, 0); + + alResampleNew(&pv->resampler, hp); + alResampleParam(&pv->resampler, AL_FILTER_SET_SOURCE, &pv->decoder); + + alEnvmixerNew(&pv->envmixer, hp); + alEnvmixerParam(&pv->envmixer, AL_FILTER_SET_SOURCE, &pv->resampler); + + alAuxBusParam(drvr->auxBus, AL_FILTER_ADD_SOURCE, &pv->envmixer); + + pv->channelKnob = (ALFilter *)&pv->envmixer; + } + + alSaveParam(save, AL_FILTER_SET_SOURCE, drvr->mainBus); + + /* + * build the parameter update list + */ + params = alHeapAlloc(hp, c->maxUpdates, sizeof(ALParam)); + drvr->paramList = 0; + for (i = 0; i < c->maxUpdates; i++) { + paramPtr= ¶ms[i]; + paramPtr->next = drvr->paramList; + drvr->paramList = paramPtr; + } + + drvr->heap = hp; +} + +/* + * slAudioFrame() is called every video frame, and is based on the video + * frame interrupt. It is assumed to be an accurate time source for the + * clients. + */ +Acmd *alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen) +{ + ALPlayer *client; + ALFilter *output; + ALSynth *drvr = &alGlobals->drvr; + s16 tmp = 0; /* Starting buffer in DMEM */ + Acmd *cmdlEnd = cmdList; + Acmd *cmdPtr; + s32 nOut; + s16 *lOutBuf = outBuf; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + if (drvr->head == 0) { + *cmdLen = 0; + return cmdList; /* nothing to do */ + } + + /* + * run down list of clients and execute callback if needed this + * subframe. Here we do all the work for the frame at the + * start. Time offsets that occur before the next frame are + * executed "early". + */ + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + + /* + * paramSamples = time of next parameter change. + * curSamples = current sample time. + * so paramSamples - curSamples is the time until the next parameter change. + * if the next parameter change occurs within this frame time (outLen), + * then call back the client that contains the parameter change. + * Note, paramSamples must be rounded down to 16 sample boundary for use + * during the client handler. + */ + + for (drvr->paramSamples = __nextSampleTime(drvr, &client); + drvr->paramSamples - drvr->curSamples < outLen; + drvr->paramSamples = __nextSampleTime(drvr, &client)) + { + drvr->paramSamples &= ~0xf; + client->samplesLeft += _timeToSamplesNoRound(drvr, (*client->handler)(client)); + } + + /* for safety's sake, always store paramSamples aligned to 16 sample boundary. + * this way, if an voice handler routine gets called outside the ALVoiceHandler + * routine (alSynAllocVoice) it will get timestamped with an aligned value and + * will be processed immediately next audio frame. + */ + drvr->paramSamples &= ~0xf; + + +#ifdef AUD_PROFILE + PROFILE_AUD(client_num, client_cnt, client_max, client_min); +#endif + + /* + * Now build the command list in small chunks + */ + while (outLen > 0){ + nOut = MIN(drvr->maxOutSamples, outLen); + + /* + * construct the command list for each physical voice by calling + * the head of the filter chain. + */ + cmdPtr = cmdlEnd; + aSegment(cmdPtr++, 0, 0); + output = drvr->outputFilter; + (*output->setParam)(output, AL_FILTER_SET_DRAM, lOutBuf); + cmdlEnd = (*output->handler)(output, &tmp, nOut, drvr->curSamples, + cmdPtr); + + outLen -= nOut; + lOutBuf += nOut<<1; /* For Stereo */ + drvr->curSamples += nOut; + + } + *cmdLen = (s32) (cmdlEnd - cmdList); + + _collectPVoices(drvr); /* collect free physical voices */ + +#ifdef AUD_PROFILE + PROFILE_AUD(drvr_num, drvr_cnt, drvr_max, drvr_min); +#endif + return cmdlEnd; +} + +/*********************************************************************** + * Synthesis driver private interfaces + ***********************************************************************/ + +ALParam *__allocParam() +{ + ALParam *update = 0; + ALSynth *drvr = &alGlobals->drvr; + + if (drvr->paramList) { + update = drvr->paramList; + drvr->paramList = drvr->paramList->next; + update->next = 0; + } + return update; +} + +void __freeParam(ALParam *param) +{ + ALSynth *drvr = &alGlobals->drvr; + param->next = drvr->paramList; + drvr->paramList = param; +} + +void _collectPVoices(ALSynth *drvr) +{ + ALLink *dl; + PVoice *pv; + + while ((dl = drvr->pLameList.next) != 0) { + pv = (PVoice *)dl; + + /* ### remove from mixer */ + + alUnlink(dl); + alLink(dl, &drvr->pFreeList); + } +} + +void _freePVoice(ALSynth *drvr, PVoice *pvoice) +{ + /* + * move the voice from the allocated list to the lame list + */ + alUnlink((ALLink *)pvoice); + alLink((ALLink *)pvoice, &drvr->pLameList); +} + + +/* + Add 0.5 to adjust the average affect of + the truncation error produced by casting + a float to an int. +*/ +s32 _timeToSamplesNoRound(ALSynth *synth, s32 micros) +{ + f32 tmp = ((f32)micros) * synth->outputRate / 1000000.0 + 0.5; + + return (s32)tmp; +} + +s32 _timeToSamples(ALSynth *synth, s32 micros) +{ + return _timeToSamplesNoRound(synth, micros) & ~0xf; +} + +static s32 __nextSampleTime(ALSynth *drvr, ALPlayer **client) +{ + ALMicroTime delta = 0x7fffffff; /* max delta for s32 */ + ALPlayer *cl; + +#ifdef _DEBUG + assert(drvr->head); +#endif + + *client = 0; + + for (cl = drvr->head; cl != 0; cl = cl->next) { + if ((cl->samplesLeft - drvr->curSamples) < delta) { + *client = cl; + delta = cl->samplesLeft - drvr->curSamples; + } + } + + return (*client)->samplesLeft; +} + + + diff --git a/src/libultra/gu/cosf.c b/src/libultra/gu/cosf.c new file mode 100644 index 0000000..5a66c1b --- /dev/null +++ b/src/libultra/gu/cosf.c @@ -0,0 +1,137 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +/* ==================================================================== + * ==================================================================== + * + * Module: fcos.c + * $Revision: 1.3 $ + * $Date: 1998/10/09 06:10:53 $ + * $Author: has $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/libultra/monegi/gu/cosf.c,v $ + * + * Revision history: + * 09-Jun-93 - Original Version + * + * Description: source code for fcos function + * + * ==================================================================== + * ==================================================================== + */ + +#pragma weak fcos = __cosf +#pragma weak cosf = __cosf +#define fcos __cosf + +/* coefficients for polynomial approximation of cos on +/- pi/2 */ + +static const du P[] = +{ +{0x3ff00000, 0x00000000}, +{0xbfc55554, 0xbc83656d}, +{0x3f8110ed, 0x3804c2a0}, +{0xbf29f6ff, 0xeea56814}, +{0x3ec5dbdf, 0x0e314bfe}, +}; + +static const du rpi = +{0x3fd45f30, 0x6dc9c883}; + +static const du pihi = +{0x400921fb, 0x50000000}; + +static const du pilo = +{0x3e6110b4, 0x611a6263}; + +static const fu zero = {0x00000000}; + + +/* ==================================================================== + * + * FunctionName fcos + * + * Description computes cosine of arg + * + * ==================================================================== + */ + +float +fcos( float x ) +{ +float absx; +double dx, xsq, poly; +double dn; +int n; +double result; +int ix, xpt; + + + ix = *(int *)&x; + xpt = (ix >> 22); + xpt &= 0x1ff; + + /* xpt is exponent(x) + 1 bit of mantissa */ + + + if ( xpt < 0x136 ) + { + /* |x| < 2^28 */ + + /* use the standard algorithm from Cody and Waite, doing + the computations in double precision + */ + + absx = ABS(x); + + dx = absx; + + dn = dx*rpi.d + 0.5; + n = ROUND(dn); + dn = n; + + dn -= 0.5; + + dx = dx - dn*pihi.d; + dx = dx - dn*pilo.d; /* dx = x - (n - 0.5)*pi */ + + xsq = dx*dx; + + poly = ((P[4].d*xsq + P[3].d)*xsq + P[2].d)*xsq + P[1].d; + + result = dx + (dx*xsq)*poly; + + /* negate result if n is odd */ + + if ( (n & 1) == 0 ) + return ( (float)result ); + + return ( -(float)result ); + } + + if ( x != x ) + { + /* x is a NaN; return a quiet NaN */ + +#ifdef _IP_NAN_SETS_ERRNO + + *__errnoaddr = EDOM; +#endif + + return ( __libm_qnan_f ); + } + + /* just give up and return 0.0 */ + + return ( zero.f ); +} diff --git a/src/libultra/gu/guint.h b/src/libultra/gu/guint.h new file mode 100644 index 0000000..c3206dd --- /dev/null +++ b/src/libultra/gu/guint.h @@ -0,0 +1,42 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "mbi.h" +#include "gu.h" + +typedef union +{ + struct + { + unsigned int hi; + unsigned int lo; + } word; + + double d; +} du; + +typedef union +{ + unsigned int i; + float f; +} fu; + +#ifndef __GL_GL_H__ + +typedef float Matrix[4][4]; + +#endif + +#define ROUND(d) (int)(((d) >= 0.0) ? ((d) + 0.5) : ((d) - 0.5)) +#define ABS(d) ((d) > 0) ? (d) : -(d) + +extern float __libm_qnan_f; diff --git a/src/libultra/gu/lookatref.c b/src/libultra/gu/lookatref.c new file mode 100644 index 0000000..bce2013 --- /dev/null +++ b/src/libultra/gu/lookatref.c @@ -0,0 +1,98 @@ +#include + +void guLookAtReflectF(float mf[4][4], LookAt *l, + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp) +{ + float len, xLook, yLook, zLook, xRight, yRight, zRight; + + guMtxIdentF(mf); + + xLook = xAt - xEye; + yLook = yAt - yEye; + zLook = zAt - zEye; + + /* Negate because positive Z is behind us: */ + len = -1.0 / sqrtf (xLook*xLook + yLook*yLook + zLook*zLook); + xLook *= len; + yLook *= len; + zLook *= len; + + /* Right = Up x Look */ + + xRight = yUp * zLook - zUp * yLook; + yRight = zUp * xLook - xUp * zLook; + zRight = xUp * yLook - yUp * xLook; + len = 1.0 / sqrtf (xRight*xRight + yRight*yRight + zRight*zRight); + xRight *= len; + yRight *= len; + zRight *= len; + + /* Up = Look x Right */ + + xUp = yLook * zRight - zLook * yRight; + yUp = zLook * xRight - xLook * zRight; + zUp = xLook * yRight - yLook * xRight; + len = 1.0 / sqrtf (xUp*xUp + yUp*yUp + zUp*zUp); + xUp *= len; + yUp *= len; + zUp *= len; + + /* reflectance vectors = Up and Right */ + + l->l[0].l.dir[0] = FTOFRAC8(xRight); + l->l[0].l.dir[1] = FTOFRAC8(yRight); + l->l[0].l.dir[2] = FTOFRAC8(zRight); + l->l[1].l.dir[0] = FTOFRAC8(xUp); + l->l[1].l.dir[1] = FTOFRAC8(yUp); + l->l[1].l.dir[2] = FTOFRAC8(zUp); + l->l[0].l.col[0] = 0x00; + l->l[0].l.col[1] = 0x00; + l->l[0].l.col[2] = 0x00; + l->l[0].l.pad1 = 0x00; + l->l[0].l.colc[0] = 0x00; + l->l[0].l.colc[1] = 0x00; + l->l[0].l.colc[2] = 0x00; + l->l[0].l.pad2 = 0x00; + l->l[1].l.col[0] = 0x00; + l->l[1].l.col[1] = 0x80; + l->l[1].l.col[2] = 0x00; + l->l[1].l.pad1 = 0x00; + l->l[1].l.colc[0] = 0x00; + l->l[1].l.colc[1] = 0x80; + l->l[1].l.colc[2] = 0x00; + l->l[1].l.pad2 = 0x00; + + mf[0][0] = xRight; + mf[1][0] = yRight; + mf[2][0] = zRight; + mf[3][0] = -(xEye * xRight + yEye * yRight + zEye * zRight); + + mf[0][1] = xUp; + mf[1][1] = yUp; + mf[2][1] = zUp; + mf[3][1] = -(xEye * xUp + yEye * yUp + zEye * zUp); + + mf[0][2] = xLook; + mf[1][2] = yLook; + mf[2][2] = zLook; + mf[3][2] = -(xEye * xLook + yEye * yLook + zEye * zLook); + + mf[0][3] = 0; + mf[1][3] = 0; + mf[2][3] = 0; + mf[3][3] = 1; +} + +void guLookAtReflect (Mtx *m, LookAt *l, float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp) +{ + float mf[4][4]; + + guLookAtReflectF(mf, l, xEye, yEye, zEye, xAt, yAt, zAt, + xUp, yUp, zUp); + + guMtxF2L(mf, m); +} diff --git a/src/libultra/gu/mtxcatf.c b/src/libultra/gu/mtxcatf.c new file mode 100644 index 0000000..af2ae96 --- /dev/null +++ b/src/libultra/gu/mtxcatf.c @@ -0,0 +1,63 @@ + +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + * + */ + +/* + * File: mtxcatf.c + * Creator: hsa@sgi.com + * Create Date: Thu Nov 2 13:03:02 PST 1995 + * + */ + +#include "guint.h" + +void guMtxCatF(float mf[4][4], float nf[4][4], float res[4][4]) +{ + int i, j, k; + float temp[4][4]; + + for (i=0; i<4; i++) { + for (j=0; j<4; j++) { + temp[i][j] = 0.0; + for (k=0; k<4; k++) { + temp[i][j] += mf[i][k] * nf[k][j]; + } + } + } + + /* make sure we handle case where result is an input */ + for (i=0; i<4; i++) { + for (j=0; j<4; j++) { + res[i][j] = temp[i][j]; + } + } +} + +void guMtxXFMF(float mf[4][4], float x, float y, float z, float *ox, float *oy, float *oz) +{ + *ox = mf[0][0]*x + mf[1][0]*y + mf[2][0]*z + mf[3][0]; + *oy = mf[0][1]*x + mf[1][1]*y + mf[2][1]*z + mf[3][1]; + *oz = mf[0][2]*x + mf[1][2]*y + mf[2][2]*z + mf[3][2]; +} + diff --git a/src/libultra/gu/mtxcatl.c b/src/libultra/gu/mtxcatl.c new file mode 100644 index 0000000..36e3312 --- /dev/null +++ b/src/libultra/gu/mtxcatl.c @@ -0,0 +1,54 @@ + +/* + * Copyright 1995, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * + * UNPUBLISHED -- Rights reserved under the copyright laws of the United + * States. Use of a copyright notice is precautionary only and does not + * imply publication or disclosure. + * + * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to restrictions + * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or + * in similar or successor clauses in the FAR, or the DOD or NASA FAR + * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., + * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. + * + * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY + * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, + * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY + * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON + * GRAPHICS, INC. + * + */ + +/* + * File: mtxcatl.c + * Creator: hsa@sgi.com + * Create Date: Thu Nov 2 13:03:02 PST 1995 + * + */ + +#include "guint.h" + +void guMtxCatL(Mtx *m, Mtx *n, Mtx *res) +{ + float mf[4][4], nf[4][4], resf[4][4]; + + guMtxL2F(mf, m); + guMtxL2F(nf, n); + + guMtxCatF(mf, nf, resf); + + guMtxF2L(resf, res); +} + +void guMtxXFML(Mtx *m, float x, float y, float z, float *ox, float *oy, float *oz) +{ + float mf[4][4]; + + guMtxL2F(mf, m); + + guMtxXFMF(mf, x, y, z, ox, oy, oz); +} diff --git a/src/libultra/gu/mtxutil.c b/src/libultra/gu/mtxutil.c new file mode 100644 index 0000000..2510558 --- /dev/null +++ b/src/libultra/gu/mtxutil.c @@ -0,0 +1,73 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +void guMtxF2L(float mf[4][4], Mtx *m) +{ + int i, j; + int e1,e2; + int *ai,*af; + + + ai=(int *) &m->m[0][0]; + af=(int *) &m->m[2][0]; + + for (i=0; i<4; i++) + for (j=0; j<2; j++) { + e1=FTOFIX32(mf[i][j*2]); + e2=FTOFIX32(mf[i][j*2+1]); + *(ai++) = ( e1 & 0xffff0000 ) | ((e2 >> 16)&0xffff); + *(af++) = ((e1 << 16) & 0xffff0000) | (e2 & 0xffff); + } +} + +void guMtxL2F(float mf[4][4], Mtx *m) +{ + int i, j; + unsigned int e1,e2; + unsigned int *ai,*af; + int q1,q2; + + ai=(unsigned int *) &m->m[0][0]; + af=(unsigned int *) &m->m[2][0]; + + for (i=0; i<4; i++) + for (j=0; j<2; j++) { + e1 = (*ai & 0xffff0000) | ((*af >> 16) & 0xffff); + e2 = ((*(ai++) << 16) & 0xffff0000) | (*(af++) & 0xffff); + q1 = *((int *)&e1); + q2 = *((int *)&e2); + + mf[i][j*2] = FIX32TOF(q1); + mf[i][j*2+1] = FIX32TOF(q2); + } +} + +void guMtxIdentF(float mf[4][4]) +{ + int i, j; + + for (i=0; i<4; i++) + for (j=0; j<4; j++) + if (i == j) mf[i][j] = 1.0; + else mf[i][j] = 0.0; +} + +void guMtxIdent(Mtx *m) +{ + float mf[4][4]; + + guMtxIdentF(mf); + + guMtxF2L(mf, m); +} diff --git a/src/libultra/gu/normalize.c b/src/libultra/gu/normalize.c new file mode 100644 index 0000000..b07848b --- /dev/null +++ b/src/libultra/gu/normalize.c @@ -0,0 +1,23 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +void guNormalize(float *x, float *y, float *z) +{ + float m; + + m = 1/sqrtf((*x)*(*x) + (*y)*(*y) + (*z)*(*z)); + *x *= m; + *y *= m; + *z *= m; +} diff --git a/src/libultra/gu/ortho.c b/src/libultra/gu/ortho.c new file mode 100644 index 0000000..9e52cb3 --- /dev/null +++ b/src/libultra/gu/ortho.c @@ -0,0 +1,41 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +void guOrthoF(float mf[4][4], float l, float r, float b, float t, float n, float f, float scale) +{ + int i, j; + + guMtxIdentF(mf); + + mf[0][0] = 2/(r-l); + mf[1][1] = 2/(t-b); + mf[2][2] = -2/(f-n); + mf[3][0] = -(r+l)/(r-l); + mf[3][1] = -(t+b)/(t-b); + mf[3][2] = -(f+n)/(f-n); + mf[3][3] = 1; + + for (i=0; i<4; i++) + for (j=0; j<4; j++) + mf[i][j] *= scale; +} + +void guOrtho(Mtx *m, float l, float r, float b, float t, float n, float f, float scale) +{ + Matrix mf; + + guOrthoF(mf, l, r, b, t, n, f, scale); + + guMtxF2L(mf, m); +} diff --git a/src/libultra/gu/perspective.c b/src/libultra/gu/perspective.c new file mode 100644 index 0000000..b7ce6a0 --- /dev/null +++ b/src/libultra/gu/perspective.c @@ -0,0 +1,47 @@ +#include +#include "math.h" + +#define GU_PI 3.1415926 + +// todo, fix when pragma aliases this +extern float __cosf(float angle); + +void guPerspectiveF(f32 mf[4][4], u16* perspNorm, f32 fovy, f32 aspect, f32 near, f32 far, f32 scale) { + f32 yscale; + s32 row; + s32 col; + + guMtxIdentF(mf); + + fovy *= GU_PI / 180.0; + yscale = __cosf(fovy / 2) / sinf(fovy / 2); + mf[0][0] = yscale / aspect; + mf[1][1] = yscale; + mf[2][2] = (near + far) / (near - far); + mf[2][3] = -1; + mf[3][2] = 2 * near * far / (near - far); + mf[3][3] = 0.0f; + + for (row = 0; row < 4; row++) { + for (col = 0; col < 4; col++) { + mf[row][col] *= scale; + } + } + + if (perspNorm != NULL) { + if (near + far <= 2.0) { + *perspNorm = 65535; + } else { + *perspNorm = (f64)(1 << 17) / (near + far); + if (*perspNorm <= 0) { + *perspNorm = 1; + } + } + } +} +void guPerspective(Mtx* m, u16* perspNorm, f32 fovy, f32 aspect, f32 near, f32 far, f32 scale) { + f32 mf[4][4]; + + guPerspectiveF(mf, perspNorm, fovy, aspect, near, far, scale); + guMtxF2L((MtxF*)mf, m); +} diff --git a/src/libultra/gu/random.c b/src/libultra/gu/random.c new file mode 100644 index 0000000..32cfde3 --- /dev/null +++ b/src/libultra/gu/random.c @@ -0,0 +1,33 @@ +/************************************************************************** + * * + * Copyright (C) 1995, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +/* + * Return a pseudorandom 32 bit number + * try the RAND macro too + * + */ +int guRandom(void) +{ + static unsigned int xseed = 174823885; + unsigned int x; + + x = (xseed<<2) + 2; + + x *= (x+1); + x = x >> 2; + + xseed = x; + + return( x ); +} diff --git a/src/libultra/gu/rotate.c b/src/libultra/gu/rotate.c new file mode 100644 index 0000000..7612729 --- /dev/null +++ b/src/libultra/gu/rotate.c @@ -0,0 +1,60 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +extern f32 __cosf(f32); + +void guRotateF(float mf[4][4], float a, float x, float y, float z) +{ + static float dtor = 3.1415926f / 180.0f; + float sine; + float cosine; + float ab, bc, ca, t; + + guNormalize(&x, &y, &z); + + a *= dtor; + + sine = sinf(a); + cosine = __cosf(a); + t = 1 - cosine; + ab = x * y * t; + bc = y * z * t; + ca = z * x * t; + + guMtxIdentF(mf); + + t = x * x; + mf[0][0] = t + cosine * (1 - t); + mf[2][1] = bc - x * sine; + mf[1][2] = bc + x * sine; + + t = y * y; + mf[1][1] = t + cosine * (1 - t); + mf[2][0] = ca + y * sine; + mf[0][2] = ca - y * sine; + + t = z * z; + mf[2][2] = t + cosine * (1 - t); + mf[1][0] = ab - z * sine; + mf[0][1] = ab + z * sine; +} + +void guRotate(Mtx *m, float a, float x, float y, float z) +{ + f32 mf[4][4]; + + guRotateF(mf, a, x, y, z); + + guMtxF2L(mf, m); +} \ No newline at end of file diff --git a/src/libultra/gu/rotateRPY.c b/src/libultra/gu/rotateRPY.c new file mode 100644 index 0000000..7c8e2db --- /dev/null +++ b/src/libultra/gu/rotateRPY.c @@ -0,0 +1,68 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +// conflict with gu.h +#define M_DTOR_2 (3.1415926f / 180.0f) + +extern float D_80103870; + +extern float __cosf(float angle); + +/* + * Return rotation matrix given roll, pitch, and yaw in degrees + * + */ + +void guRotateRPYF(float mf[4][4], float r, float p, float h) +{ + // float dtor = ; + float sinr, sinp, sinh; + float cosr, cosp, cosh; + + r *= M_DTOR_2; + p *= M_DTOR_2; + h *= M_DTOR_2; + + D_80103870 = M_DTOR_2; + + sinr = sinf(r); + cosr = __cosf(r); + sinp = sinf(p); + cosp = __cosf(p); + sinh = sinf(h); + cosh = __cosf(h); + + guMtxIdentF(mf); + + mf[0][0] = cosp*cosh; + mf[0][1] = cosp*sinh; + mf[0][2] = -sinp; + + mf[1][0] = sinr*sinp*cosh - cosr*sinh; + mf[1][1] = sinr*sinp*sinh + cosr*cosh; + mf[1][2] = sinr*cosp; + + mf[2][0] = cosr*sinp*cosh + sinr*sinh; + mf[2][1] = cosr*sinp*sinh - sinr*cosh; + mf[2][2] = cosr*cosp; +} + +void guRotateRPY(Mtx *m, float r, float p, float h) +{ + Matrix mf; + + guRotateRPYF(mf, r, p, h); + + guMtxF2L(mf, m); +} diff --git a/src/libultra/gu/scale.c b/src/libultra/gu/scale.c new file mode 100644 index 0000000..fdb838d --- /dev/null +++ b/src/libultra/gu/scale.c @@ -0,0 +1,20 @@ +#include + +void guScaleF(float mf[4][4], float x, float y, float z) +{ + guMtxIdentF(mf); + + mf[0][0] = x; + mf[1][1] = y; + mf[2][2] = z; + mf[3][3] = 1; +} + +void guScale(Mtx *m, float x, float y, float z) +{ + f32 mf[4][4]; + + guScaleF(mf, x, y, z); + + guMtxF2L(mf, m); +} diff --git a/src/libultra/gu/sinf.c b/src/libultra/gu/sinf.c new file mode 100644 index 0000000..2c21848 --- /dev/null +++ b/src/libultra/gu/sinf.c @@ -0,0 +1,86 @@ +#include +#include "libc/math.h" +#include "macros.h" + +#pragma weak sinf = __sinf + +// Coefficients of a degree 9 polynomial approximation of sine. It is not the Maclaurin polynamial, but some as-yet +// undetermined more uniform approximation. +static const du P[] = { + { 1.0 }, + { -0.16666659550427756 }, + { 0.008333066246082155 }, + { -0.0001980960290193795 }, + { 0.000002605780637968037 }, +}; + +static const du rpi = { 1 / 3.14159265358979323846 }; // 1/M_PI, "reciprocal of pi" + +// pihi + pilo is the closest double to pi, this representation allows more precise calculations since pi itself is not +// an exact float +static const du pihi = { 3.1415926218032837 }; + +static const du pilo = { 3.178650954705639E-8 }; + +static const fu zero = { 0x00000000 }; + +/** + * Returns the sine of a float as a float, using the Maclaurin series and shifting. + */ +f32 __sinf(f32 x) { + f64 dx; // x promoted to double + f64 xSq; // square of dx + f64 polyApprox; // Most of the polynomial approximation to sin(x) + f64 dn; // n promoted to double + s32 n; // number of multiples of pi away from the first half-period + f64 result; + s32 ix = *(s32*)&x; // Type-pun x into an s32, i.e. its IEEE-754 hex representation + s32 xpt = (ix >> 22); // Obtain the exponent of x (actually 2 * exponent + 127) + + xpt &= 0x1FF; // Remove the sign bit + + // |x| < 1 + if (xpt < 255) { + dx = x; + + // |x| > 2^{-12}: for x smaller in magnitude than this, sin(x) - x is too small for a float to register the + // error + if (xpt >= 230) { + xSq = SQ(dx); + polyApprox = ((P[4].d * xSq + P[3].d) * xSq + P[2].d) * xSq + P[1].d; + + result = dx + (dx * xSq) * polyApprox; + return (f32)result; + } + return x; + } + + // |x| < 2^{28} (beyond this range, floats are too sparse to make the trig functions useable) + if (xpt < 310) { + dx = x; + dn = dx * rpi.d; + n = ROUND(dn); + dn = n; + + // Bring x to the first half-period where the Maclaurin polynomial can be used + dx -= dn * pihi.d; + dx -= dn * pilo.d; + + xSq = SQ(dx); + polyApprox = ((P[4].d * xSq + P[3].d) * xSq + P[2].d) * xSq + P[1].d; + result = dx + (dx * xSq) * polyApprox; // Actual Maclaurin polynomial for sin(x) + + // add a minus sign if x is an odd number of multiples of pi away from the first half-period + if (n % 2 == 0) { + return (f32)result; + } + return -(f32)result; + } + + // if x is NaN + if (x != x) { + return __libm_qnan_f; + } + + return zero.f; +} diff --git a/src/libultra/gu/sqrtf.c b/src/libultra/gu/sqrtf.c new file mode 100644 index 0000000..7cfab9c --- /dev/null +++ b/src/libultra/gu/sqrtf.c @@ -0,0 +1,11 @@ +#include + +#pragma intrinsic(sqrtf) + +#ifndef __GNUC__ +#define __builtin_sqrtf sqrtf +#endif + +f32 sqrtf(f32 f) { + return __builtin_sqrtf(f); +} diff --git a/src/libultra/gu/translate.c b/src/libultra/gu/translate.c new file mode 100644 index 0000000..8e46be0 --- /dev/null +++ b/src/libultra/gu/translate.c @@ -0,0 +1,31 @@ +/************************************************************************** + * * + * Copyright (C) 1994, Silicon Graphics, Inc. * + * * + * These coded instructions, statements, and computer programs contain * + * unpublished proprietary information of Silicon Graphics, Inc., and * + * are protected by Federal copyright law. They may not be disclosed * + * to third parties or copied or duplicated in any form, in whole or * + * in part, without the prior written consent of Silicon Graphics, Inc. * + * * + **************************************************************************/ + +#include "guint.h" + +void guTranslateF(float mf[4][4], float x, float y, float z) +{ + guMtxIdentF(mf); + + mf[3][0] = x; + mf[3][1] = y; + mf[3][2] = z; +} + +void guTranslate(Mtx *m, float x, float y, float z) +{ + Matrix mf; + + guTranslateF(mf, x, y, z); + + guMtxF2L(mf, m); +} diff --git a/src/libultra/io/ai.c b/src/libultra/io/ai.c new file mode 100644 index 0000000..5e345dc --- /dev/null +++ b/src/libultra/io/ai.c @@ -0,0 +1,15 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osAiDeviceBusy(void) { + register s32 status = IO_READ(AI_STATUS_REG); + + if (status & AI_STATUS_FIFO_FULL) { + return TRUE; + } + + return FALSE; +} diff --git a/src/libultra/io/aigetlen.c b/src/libultra/io/aigetlen.c new file mode 100644 index 0000000..6b83682 --- /dev/null +++ b/src/libultra/io/aigetlen.c @@ -0,0 +1,8 @@ +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +u32 osAiGetLength(void) { + return IO_READ(AI_LEN_REG); +} diff --git a/src/libultra/io/aigetstat.c b/src/libultra/io/aigetstat.c new file mode 100644 index 0000000..c7a3cf7 --- /dev/null +++ b/src/libultra/io/aigetstat.c @@ -0,0 +1,8 @@ +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +u32 osAiGetStatus() { + return IO_READ(AI_STATUS_REG); +} diff --git a/src/libultra/io/aisetfreq.c b/src/libultra/io/aisetfreq.c new file mode 100644 index 0000000..fbd899d --- /dev/null +++ b/src/libultra/io/aisetfreq.c @@ -0,0 +1,30 @@ +#include "PR/rcp.h" + +extern s32 osViClock; + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 osAiSetFrequency(u32 frequency) { + register unsigned int dacRate; + register unsigned char bitRate; + register float f; + + f = osViClock / (float)frequency + .5f; + dacRate = f; + + if (dacRate < AI_MIN_DAC_RATE) { + return -1; + } + + bitRate = dacRate / 66; + + if (bitRate > AI_MAX_BIT_RATE) { + bitRate = AI_MAX_BIT_RATE; + } + + IO_WRITE(AI_DACRATE_REG, dacRate - 1); + IO_WRITE(AI_BITRATE_REG, bitRate - 1); + // IO_WRITE(AI_CONTROL_REG, AI_CONTROL_DMA_ON); + return osViClock / (s32)dacRate; +} diff --git a/src/libultra/io/aisetnextbuf.c b/src/libultra/io/aisetnextbuf.c new file mode 100644 index 0000000..d789133 --- /dev/null +++ b/src/libultra/io/aisetnextbuf.c @@ -0,0 +1,31 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "../os/osint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 osAiSetNextBuffer(void *bufPtr, u32 size) { + static u8 hdwrBugFlag = FALSE; + char *bptr; + + bptr = bufPtr; + + if (hdwrBugFlag) { + bptr -= 0x2000; + } + + if ((((u32)bufPtr + size) & 0x1fff) == 0) { + hdwrBugFlag = TRUE; + } else { + hdwrBugFlag = FALSE; + } + + if (__osAiDeviceBusy()) { + return -1; + } + + IO_WRITE(AI_DRAM_ADDR_REG, osVirtualToPhysical(bptr)); + IO_WRITE(AI_LEN_REG, size); + return 0; +} diff --git a/src/libultra/io/cartrominit.c b/src/libultra/io/cartrominit.c new file mode 100644 index 0000000..35d6e38 --- /dev/null +++ b/src/libultra/io/cartrominit.c @@ -0,0 +1,65 @@ +#include +#include "PR/os_internal.h" +#include "PR/R4300.h" +#include "PR/rcp.h" + +OSPiHandle __CartRomHandle; +OSPiHandle *osCartRomInit(void) +{ + u32 value; + u32 saveMask; + static int first = 1; + register u32 stat; + u32 latency; + u32 pulse; + u32 pageSize; + u32 relDuration; + + __osPiGetAccess(); + + if (!first) { + __osPiRelAccess(); + return &__CartRomHandle; + } + + first = 0; + __CartRomHandle.type = DEVICE_TYPE_CART; + __CartRomHandle.baseAddress = PHYS_TO_K1(PI_DOM1_ADDR2); + __CartRomHandle.domain = PI_DOMAIN1; + __CartRomHandle.speed = 0; + + bzero(&__CartRomHandle.transferInfo, sizeof(__OSTranxInfo)); + + while (stat = IO_READ(PI_STATUS_REG), stat & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) { + ; + } + + latency = IO_READ(PI_BSD_DOM1_LAT_REG); + pageSize = IO_READ(PI_BSD_DOM1_PGS_REG); + relDuration = IO_READ(PI_BSD_DOM1_RLS_REG); + pulse = IO_READ(PI_BSD_DOM1_PWD_REG); + + IO_WRITE(PI_BSD_DOM1_LAT_REG, 0xFF); + IO_WRITE(PI_BSD_DOM1_PGS_REG, 0); + IO_WRITE(PI_BSD_DOM1_RLS_REG, 3); + IO_WRITE(PI_BSD_DOM1_PWD_REG, 0xFF); + + value = IO_READ(__CartRomHandle.baseAddress); + __CartRomHandle.latency = value & 0xFF; + __CartRomHandle.pageSize = (value >> 0x10) & 0xF; + __CartRomHandle.relDuration = (value >> 0x14) & 0xF; + __CartRomHandle.pulse = (value >> 8) & 0xFF; + + IO_WRITE(PI_BSD_DOM1_LAT_REG, latency); + IO_WRITE(PI_BSD_DOM1_PGS_REG, pageSize); + IO_WRITE(PI_BSD_DOM1_RLS_REG, relDuration); + IO_WRITE(PI_BSD_DOM1_PWD_REG, pulse); + + saveMask = __osDisableInt(); + __CartRomHandle.next = __osPiTable; + __osPiTable = &__CartRomHandle; + __osRestoreInt(saveMask); + __osPiRelAccess(); + + return &__CartRomHandle; +} diff --git a/src/libultra/io/conteeplongread.c b/src/libultra/io/conteeplongread.c new file mode 100644 index 0000000..f7ca599 --- /dev/null +++ b/src/libultra/io/conteeplongread.c @@ -0,0 +1,17 @@ +#include +#include "ultra64/controller.h" + +s32 osEepromLongRead(OSMesgQueue *mq, u8 address, u8 *buffer, int length) +{ + s32 ret; + ret = 0; + + while (length > 0) { + ERRCK(osEepromRead(mq, address, buffer)); + length -= EEPROM_BLOCK_SIZE; + address++; + buffer += EEPROM_BLOCK_SIZE; + } + + return ret; +} diff --git a/src/libultra/io/conteeplongwrite.c b/src/libultra/io/conteeplongwrite.c new file mode 100644 index 0000000..0124860 --- /dev/null +++ b/src/libultra/io/conteeplongwrite.c @@ -0,0 +1,18 @@ +#include +#include "ultra64/controller.h" + +s32 osEepromLongWrite(OSMesgQueue *mq, u8 address, u8 *buffer, int length) +{ + s32 ret; + ret = 0; + while (length > 0) + { + ERRCK(osEepromWrite(mq, address, buffer)); + length -= EEPROM_BLOCK_SIZE; + address++; + buffer += EEPROM_BLOCK_SIZE; + osSetTimer(&__osEepromTimer, 562500, 0, &__osEepromTimerQ, &__osEepromTimerMsg); + osRecvMesg(&__osEepromTimerQ, NULL, OS_MESG_BLOCK); + } + return ret; +} diff --git a/src/libultra/io/conteepprobe.c b/src/libultra/io/conteepprobe.c new file mode 100644 index 0000000..040fe47 --- /dev/null +++ b/src/libultra/io/conteepprobe.c @@ -0,0 +1,35 @@ +#include +#include "ultra64/controller.h" +#include "siint.h" + +s32 osEepromProbe(OSMesgQueue *mq) +{ + s32 ret; + u16 type; + OSContStatus sdata; + ret = 0; + __osSiGetAccess(); + ret = __osEepStatus(mq, &sdata); + type = sdata.type & (CONT_EEPROM | CONT_EEP16K); + if (ret != 0) + { + ret = 0; + } + else + { + switch (type) + { + case CONT_EEPROM: + ret = EEPROM_TYPE_4K; + break; + case CONT_EEPROM | CONT_EEP16K: + ret = EEPROM_TYPE_16K; + break; + default: + ret = 0; + break; + } + } + __osSiRelAccess(); + return ret; +} diff --git a/src/libultra/io/conteepread.c b/src/libultra/io/conteepread.c new file mode 100644 index 0000000..23c8ad2 --- /dev/null +++ b/src/libultra/io/conteepread.c @@ -0,0 +1,105 @@ +#include +#include "PR/rcp.h" +#include "ultra64/controller.h" +#include "siint.h" + +void __osPackEepReadData(u8 address); +extern OSPifRam __osEepPifRam; +extern s32 __osEepromRead16K; + +#define CONT_RANGE_ERROR -1 + +s32 osEepromRead(OSMesgQueue *mq, u8 address, u8 *buffer) +{ + s32 ret; + int i; + u16 type; + u8 *ptr; + OSContStatus sdata; + __OSContEepromFormat eepromformat; + ret = 0; + i = 0; + ptr = (u8 *)&__osEepPifRam.ramarray; + __osSiGetAccess(); + ret = __osEepStatus(mq, &sdata); + + if (ret == 0) { + type = sdata.type & (CONT_EEPROM | CONT_EEP16K); + + switch (type) { + case CONT_EEPROM: + // @bug: Should be > EEPROM_MAXBLOCKS + if (address >= EEPROM_MAXBLOCKS) { + ret = -1; + } + break; + case CONT_EEPROM | CONT_EEP16K: + // @bug: Should be > EEP16K_MAXBLOCKS + if (address >= EEP16K_MAXBLOCKS) { + ret = -1; + } + break; + default: + if (1); + ret = CONT_NO_RESPONSE_ERROR; + break; + } + } + + if (ret != 0) { + __osSiRelAccess(); + return ret; + } + + while (sdata.status & CONT_EEPROM_BUSY) { + __osEepStatus(mq, &sdata); + } + + __osPackEepReadData(address); + + ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); + __osContLastCmd = CONT_CMD_READ_EEPROM; + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + for (i = 0; i < 4; i++) { + ptr++; + } + + eepromformat = *(__OSContEepromFormat *)ptr; + + ret = CHNL_ERR(eepromformat); + + if (ret == 0) { + for (i = 0; i < ARRLEN(eepromformat.data); i++) { + *buffer++ = eepromformat.data[i]; + } + } + + __osSiRelAccess(); + + return ret; +} + +void __osPackEepReadData(u8 address) { + u8 *ptr = (u8 *)&__osEepPifRam.ramarray; + __OSContEepromFormat eepromformat; + int i; + + __osEepPifRam.pifstatus = CONT_CMD_EXE; + + eepromformat.txsize = CONT_CMD_READ_EEPROM_TX; + eepromformat.rxsize = CONT_CMD_READ_EEPROM_RX; + eepromformat.cmd = CONT_CMD_READ_EEPROM; + eepromformat.address = address; + + for (i = 0; i < MAXCONTROLLERS; i++) { + *ptr++ = 0; + } + + *(__OSContEepromFormat *)(ptr) = eepromformat; + ptr += sizeof(__OSContEepromFormat); + ptr[0] = CONT_CMD_END; +} diff --git a/src/libultra/io/conteepwrite.c b/src/libultra/io/conteepwrite.c new file mode 100644 index 0000000..705f74d --- /dev/null +++ b/src/libultra/io/conteepwrite.c @@ -0,0 +1,157 @@ +#include +#include "ultra64/controller.h" +#include "siint.h" +#include + +void __osPackEepWriteData(u8 address, u8 *buffer); + +s32 osEepromWrite(OSMesgQueue *mq, u8 address, u8 *buffer) +{ + s32 ret; + u16 type; + u8 *ptr; + __OSContEepromFormat eepromformat; + OSContStatus sdata; + + ret = 0; + ptr = (u8 *)&__osEepPifRam.ramarray; + __osSiGetAccess(); + ret = __osEepStatus(mq, &sdata); + + type = sdata.type & (CONT_EEPROM | CONT_EEP16K); + + if (ret == 0) { + switch (type) { + case CONT_EEPROM: + // @bug: Should be > EEPROM_MAXBLOCKS + if (address >= EEPROM_MAXBLOCKS) { + ret = -1; + } + break; + case CONT_EEPROM | CONT_EEP16K: + // @bug: Should be > EEP16K_MAXBLOCKS + if (address >= EEP16K_MAXBLOCKS) { + ret = -1; + } + break; + default: + if (1); + ret = CONT_NO_RESPONSE_ERROR; + break; + } + } + + if (ret != 0) { + __osSiRelAccess(); + return ret; + } + + while (sdata.status & CONT_EEPROM_BUSY) { + __osEepStatus(mq, &sdata); + } + + __osPackEepWriteData(address, buffer); + + ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); + __osContLastCmd = CONT_CMD_WRITE_EEPROM; + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ptr += 4; + + eepromformat = *(__OSContEepromFormat *)ptr; + + ret = CHNL_ERR(eepromformat); + + __osSiRelAccess(); + return ret; +} + +void __osPackEepWriteData(u8 address, u8 *buffer) +{ + u8 *ptr; + __OSContEepromFormat eepromformat; + int i; + ptr = (u8 *)&__osEepPifRam.ramarray; + __osEepPifRam.pifstatus = CONT_CMD_EXE; + + eepromformat.txsize = CONT_CMD_WRITE_EEPROM_TX; + eepromformat.rxsize = CONT_CMD_WRITE_EEPROM_RX; + eepromformat.cmd = CONT_CMD_WRITE_EEPROM; + eepromformat.address = address; + + for (i = 0; i < ARRLEN(eepromformat.data); i++) { + eepromformat.data[i] = *buffer++; + } + + for (i = 0; i < 4; i++) { + *ptr++ = 0; + } + + *(__OSContEepromFormat *)(ptr) = eepromformat; + ptr += sizeof(__OSContEepromFormat); + ptr[0] = CONT_CMD_END; +} + +s32 __osEepStatus(OSMesgQueue *mq, OSContStatus *data) +{ + s32 ret; + int i; + u8 *ptr; + __OSContRequestFormat requestformat; + + ret = 0; + ptr = (u8 *)__osEepPifRam.ramarray; + + for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) { + __osEepPifRam.ramarray[i] = 0; + } + + __osEepPifRam.pifstatus = CONT_CMD_EXE; + ptr = (u8 *)__osEepPifRam.ramarray; + + for (i = 0; i < 4; i++) { + *ptr++ = 0; + } + + requestformat.dummy = CONT_CMD_NOP; + requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX; + requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX; + requestformat.cmd = CONT_CMD_REQUEST_STATUS; + requestformat.typeh = CONT_CMD_NOP; + requestformat.typel = CONT_CMD_NOP; + requestformat.status = CONT_CMD_NOP; + requestformat.dummy1 = CONT_CMD_NOP; + *(__OSContRequestFormat *)ptr = requestformat; + ptr += sizeof(__OSContRequestFormat); + *ptr = CONT_CMD_END; + + ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + __osContLastCmd = CONT_CMD_END; + ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + if (ret != 0) { + return ret; + } + + ptr = (u8 *)&__osEepPifRam; + + for (i = 0; i < 4; i++) { + *ptr++ = 0; + } + + requestformat = *(__OSContRequestFormat *)ptr; + data->errno = CHNL_ERR(requestformat); + data->type = (requestformat.typel << 8) | requestformat.typeh; + data->status = requestformat.status; + + if (data->errno != 0) { + return data->errno; + } + + return 0; +} diff --git a/src/libultra/io/contpfs.c b/src/libultra/io/contpfs.c new file mode 100644 index 0000000..1ffa6df --- /dev/null +++ b/src/libultra/io/contpfs.c @@ -0,0 +1,317 @@ +#include +#include "ultra64/controller.h" + +typedef unsigned long uintptr_t; + +extern u8 __osPfsInodeCacheBank; +extern s32 __osPfsInodeCacheChannel; + +extern __OSInode __osPfsInodeCache; + +#define PFS_INODE_SIZE_PER_PAGE 128 + +u16 __osSumcalc(u8* ptr, s32 length) { + s32 i; + u32 sum = 0; + u8* temp = ptr; + + for (i = 0; i < length; i++) { + sum += *temp++; + } + return sum & 0xFFFF; +} + +s32 __osIdCheckSum(u16* ptr, u16* checkSum, u16* idSum) { + u16 data = 0; + u32 i; + + *checkSum = *idSum = 0; + for (i = 0; i < ((sizeof(__OSPackId) - sizeof(u32)) / sizeof(u8)); i += sizeof(u16)) { + data = *((u16*)((uintptr_t)ptr + i)); + *checkSum += data; + *idSum += ~data; + } + return 0; +} + +s32 __osRepairPackId(OSPfs* pfs, __OSPackId* badid, __OSPackId* newid) { + s32 ret = 0; + u8 temp[BLOCKSIZE]; + u8 comp[BLOCKSIZE]; + u8 mask = 0; + s32 i; + s32 j = 0; + u16 index[4]; + + newid->repaired = -1; + newid->random = osGetCount(); + newid->serial_mid = badid->serial_mid; + newid->serial_low = badid->serial_low; + + if ((pfs->activebank != 0) && ((ret = __osPfsSelectBank(pfs, 0)) != 0)) { + return ret; + } + + do { + if ((ret = __osPfsSelectBank(pfs, j)) != 0) { + return ret; + } + + if ((ret = __osContRamRead(pfs->queue, pfs->channel, 0, temp)) != 0) { + return ret; + } + temp[0] = j | 0x80; + for (i = 1; i < BLOCKSIZE; i++) { + temp[i] = ~temp[i]; + } + + if ((ret = __osContRamWrite(pfs->queue, pfs->channel, 0, temp, 0)) != 0) { + return ret; + } + if ((ret = __osContRamRead(pfs->queue, pfs->channel, 0, comp)) != 0) { + return (ret); + } + for (i = 0; i < BLOCKSIZE; i++) { + if (comp[i] != temp[i]) { + break; + } + } + if (i != BLOCKSIZE) { + break; + } + + if (j > 0) { + if ((ret = __osPfsSelectBank(pfs, 0)) != 0) { + return ret; + } + if ((ret = __osContRamRead(pfs->queue, pfs->channel, 0, temp)) != 0) { + return ret; + } + if (temp[0] != 0x80) { + break; + } + } + + j++; + } while (j < PFS_MAX_BANKS); + + if ((pfs->activebank != 0) && (ret = __osPfsSelectBank(pfs, 0)) != 0) { + return ret; + } + + mask = (j > 0) ? 1 : 0; + newid->deviceid = (badid->deviceid & 0xFFFE) | mask; + newid->banks = j; + newid->version = badid->version; + __osIdCheckSum((u16*)newid, &newid->checksum, &newid->inverted_checksum); + + index[0] = PFS_ID_0AREA; + index[1] = PFS_ID_1AREA; + index[2] = PFS_ID_2AREA; + index[3] = PFS_ID_3AREA; + for (i = 0; i < 4; i++) { + if ((ret = __osContRamWrite(pfs->queue, pfs->channel, index[i], (u8*)newid, PFS_FORCE)) != 0) { + return ret; + } + } + if ((ret = __osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, temp)) != 0) { + return ret; + } + for (i = 0; i < BLOCKSIZE; i++) { + if (temp[i] != ((u8*)newid)[i]) { + return PFS_ERR_DEVICE; + } + } + return 0; +} + +s32 __osCheckPackId(OSPfs* pfs, __OSPackId* check) { + u16 index[4]; + s32 ret = 0; + u16 sum; + u16 idSum; + s32 i; + s32 j; + + if (pfs->activebank != 0 && (ret = __osPfsSelectBank(pfs, 0)) != 0) { + return ret; + } + + index[0] = PFS_ID_0AREA; + index[1] = PFS_ID_1AREA; + index[2] = PFS_ID_2AREA; + index[3] = PFS_ID_3AREA; + + for (i = 1; i < ARRAY_COUNT(index); i++) { + if ((ret = __osContRamRead(pfs->queue, pfs->channel, index[i], (u8*)check)) != 0) { + return ret; + } + __osIdCheckSum((u16*)check, &sum, &idSum); + if (check->checksum == sum && check->inverted_checksum == idSum) { + break; + } + } + if (i == ARRAY_COUNT(index)) { + return PFS_ERR_ID_FATAL; + } + + for (j = 0; j < ARRAY_COUNT(index); j++) { + if (j != i) { + if ((ret = __osContRamWrite(pfs->queue, pfs->channel, index[j], (u8*)check, PFS_FORCE)) != 0) { + return ret; + } + } + } + return 0; +} + +s32 __osGetId(OSPfs* pfs) { + u16 sum; + u16 isum; + u8 temp[BLOCKSIZE]; + __OSPackId* id; + __OSPackId newid; + s32 ret; + + if (pfs->activebank != 0 && (ret = __osPfsSelectBank(pfs, 0)) != 0) { + return ret; + } + + if ((ret = __osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, temp)) != 0) { + return ret; + } + + __osIdCheckSum((u16*)temp, &sum, &isum); + id = (__OSPackId*)temp; + if (id->checksum != sum || id->inverted_checksum != isum) { + if ((ret = __osCheckPackId(pfs, id)) == PFS_ERR_ID_FATAL) { + ret = __osRepairPackId(pfs, id, &newid); + if (ret) { + return ret; + } + id = &newid; + } else if (ret != 0) { + return ret; + } + } + + if ((id->deviceid & 1) == 0) { + ret = __osRepairPackId(pfs, id, &newid); + if (ret) { + return ret; + } + id = &newid; + if ((id->deviceid & 1) == 0) { + return PFS_ERR_DEVICE; + } + } + + _bcopy(id, pfs->id, BLOCKSIZE); + + if (0) {} + + pfs->version = id->version; + + pfs->banks = id->banks; + pfs->inode_start_page = 1 + DEF_DIR_PAGES + (2 * pfs->banks); + pfs->dir_size = DEF_DIR_PAGES * PFS_ONE_PAGE; + pfs->inode_table = 1 * PFS_ONE_PAGE; + pfs->minode_table = (1 + pfs->banks) * PFS_ONE_PAGE; + pfs->dir_table = pfs->minode_table + (pfs->banks * PFS_ONE_PAGE); + + if ((ret = __osContRamRead(pfs->queue, pfs->channel, PFS_LABEL_AREA, pfs->label)) != 0) { + return ret; + } + + return 0; +} + +s32 __osCheckId(OSPfs* pfs) { + u8 temp[BLOCKSIZE]; + s32 ret; + + if (pfs->activebank != 0) { + ret = __osPfsSelectBank(pfs, 0); + if (ret == PFS_ERR_NEW_PACK) { + ret = __osPfsSelectBank(pfs, 0); + } + if (ret != 0) { + return ret; + } + } + + if ((ret = __osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, temp)) != 0) { + if (ret != PFS_ERR_NEW_PACK) { + return ret; + } + if ((ret = __osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, temp)) != 0) { + return ret; + } + } + + if (bcmp(pfs->id, temp, BLOCKSIZE) != 0) { + return PFS_ERR_NEW_PACK; + } + + return 0; +} + +s32 __osPfsRWInode(OSPfs* pfs, __OSInode* inode, u8 flag, u8 bank) { + u8 sum; + s32 j; + s32 ret; + s32 offset; + u8* addr; + + if (flag == PFS_READ && bank == __osPfsInodeCacheBank && (pfs->channel == __osPfsInodeCacheChannel)) { + _bcopy(&__osPfsInodeCache, inode, sizeof(__OSInode)); + return 0; + } + + if ((pfs->activebank != 0) && (ret = __osPfsSelectBank(pfs, 0)) != 0) { + return ret; + } + + offset = ((bank > 0) ? 1 : pfs->inode_start_page); + + if (flag == PFS_WRITE) { + inode->inode_page[0].inode_t.page = + __osSumcalc((u8*)(inode->inode_page + offset), (PFS_INODE_SIZE_PER_PAGE - offset) * 2); + } + + for (j = 0; j < PFS_ONE_PAGE; j++) { + addr = (u8*)(((u8*)inode) + (j * BLOCKSIZE)); + if (flag == PFS_WRITE) { + ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->inode_table + (bank * PFS_ONE_PAGE) + j, addr, 0); + ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->minode_table + (bank * PFS_ONE_PAGE) + j, addr, 0); + } else { + ret = __osContRamRead(pfs->queue, pfs->channel, pfs->inode_table + (bank * PFS_ONE_PAGE) + j, addr); + } + if (ret) { + return ret; + } + } + + if (flag == PFS_READ) { + sum = __osSumcalc((u8*)(inode->inode_page + offset), (PFS_INODE_SIZE_PER_PAGE - offset) * 2); + if (sum != inode->inode_page[0].inode_t.page) { + for (j = 0; j < PFS_ONE_PAGE; j++) { + addr = (((u8*)inode->inode_page) + (j * BLOCKSIZE)); + ret = __osContRamRead(pfs->queue, pfs->channel, pfs->minode_table + (bank * PFS_ONE_PAGE) + j, addr); + } + sum = __osSumcalc((u8*)(inode->inode_page + offset), (PFS_INODE_SIZE_PER_PAGE - offset) * 2); + if (sum != inode->inode_page[0].inode_t.page) { + return PFS_ERR_INCONSISTENT; + } + for (j = 0; j < PFS_ONE_PAGE; j++) { + addr = (((u8*)inode->inode_page) + (j * BLOCKSIZE)); + ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->inode_table + (bank * PFS_ONE_PAGE) + j, addr, 0); + } + } + } + __osPfsInodeCacheBank = bank; + _bcopy(inode, &__osPfsInodeCache, sizeof(__OSInode)); + __osPfsInodeCacheChannel = pfs->channel; + + return 0; +} diff --git a/src/libultra/io/contramread.c b/src/libultra/io/contramread.c new file mode 100644 index 0000000..cc85547 --- /dev/null +++ b/src/libultra/io/contramread.c @@ -0,0 +1,73 @@ +#include +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "ultra64/controller.h" + +extern s32 __osPfsLastChannel; + +#define READFORMAT(ptr) ((__OSContRamReadFormat*)(ptr)) + +s32 __osContRamRead(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { + s32 ret; + s32 i; + u8* ptr; + s32 retry = 2; + + __osSiGetAccess(); + + do { + ptr = (u8*)&__osPfsPifRam; + + if (__osContLastCmd != CONT_CMD_READ_MEMPACK || __osPfsLastChannel != channel) { + __osContLastCmd = CONT_CMD_READ_MEMPACK; + __osPfsLastChannel = channel; + + for (i = 0; i < channel; i++) { *ptr++ = CONT_CMD_REQUEST_STATUS; } + + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + + READFORMAT(ptr)->dummy = CONT_CMD_NOP; + READFORMAT(ptr)->txsize = CONT_CMD_READ_MEMPACK_TX; + READFORMAT(ptr)->rxsize = CONT_CMD_READ_MEMPACK_RX; + READFORMAT(ptr)->cmd = CONT_CMD_READ_MEMPACK; + READFORMAT(ptr)->datacrc = 0xFF; + + ptr[sizeof(__OSContRamReadFormat)] = CONT_CMD_END; + } else { + ptr += channel; + } + + READFORMAT(ptr)->hi = address >> 3; + READFORMAT(ptr)->lo = (u8)(__osContAddressCrc(address) | (address << 5)); + + __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = ((((__OSContRamReadFormat*)ptr)->rxsize & 0xC0) >> 4); + + if (!ret) { + if (__osContDataCrc(&READFORMAT(ptr)->data) != READFORMAT(ptr)->datacrc) { + ret = __osPfsGetStatus(mq, channel); + + if (ret) { + break; + } + + ret = PFS_ERR_CONTRFAIL; + } else { + _bcopy(&READFORMAT(ptr)->data, buffer, BLOCKSIZE); + } + } else { + ret = PFS_ERR_NOPACK; + } + if (ret != PFS_ERR_CONTRFAIL) { + break; + } + } while (0 <= retry--); + __osSiRelAccess(); + + return ret; +} diff --git a/src/libultra/io/contramwrite.c b/src/libultra/io/contramwrite.c new file mode 100644 index 0000000..8499892 --- /dev/null +++ b/src/libultra/io/contramwrite.c @@ -0,0 +1,74 @@ +#include +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "ultra64/controller.h" + +extern s32 __osPfsLastChannel; + +#define READFORMAT(ptr) ((__OSContRamReadFormat*)(ptr)) + +s32 __osContRamWrite(OSMesgQueue* mq, int channel, u16 address, u8* buffer, int force) { + s32 ret = 0; + s32 i; + u8* ptr; + s32 retry = 2; + u8 crc; + + if ((force != PFS_FORCE) && (address < PFS_LABEL_AREA) && (address != 0)) { + return 0; + } + + __osSiGetAccess(); + + do { + ptr = (u8*)(&__osPfsPifRam.ramarray); + + if (__osContLastCmd != CONT_CMD_WRITE_MEMPACK || __osPfsLastChannel != channel) { + __osContLastCmd = CONT_CMD_WRITE_MEMPACK; + __osPfsLastChannel = channel; + + // clang-format off + for (i = 0; i < channel; i++) { *ptr++ = 0; } + // clang-format on + + __osPfsPifRam.pifstatus = 1; + + READFORMAT(ptr)->dummy = CONT_CMD_NOP; + READFORMAT(ptr)->txsize = CONT_CMD_WRITE_MEMPACK_TX; + READFORMAT(ptr)->rxsize = CONT_CMD_WRITE_MEMPACK_RX; + READFORMAT(ptr)->cmd = CONT_CMD_WRITE_MEMPACK; + READFORMAT(ptr)->datacrc = 0xFF; + + ptr[sizeof(__OSContRamReadFormat)] = CONT_CMD_END; + } else { + ptr += channel; + } + READFORMAT(ptr)->hi = address >> 3; + READFORMAT(ptr)->lo = ((address << 5) | __osContAddressCrc(address)); + + _bcopy(buffer, READFORMAT(ptr)->data, BLOCKSIZE); + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + crc = __osContDataCrc(buffer); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = ((((__OSContRamReadFormat*)ptr)->rxsize & 0xC0) >> 4); + if (!ret) { + if (crc != ((__OSContRamReadFormat*)ptr)->datacrc) { + if ((ret = __osPfsGetStatus(mq, channel))) { + break; + } else { + ret = PFS_ERR_CONTRFAIL; + } + } + } else { + ret = PFS_ERR_NOPACK; + } + } while ((ret == PFS_ERR_CONTRFAIL) && (retry-- >= 0)); + __osSiRelAccess(); + + return ret; +} diff --git a/src/libultra/io/contreaddata.c b/src/libultra/io/contreaddata.c new file mode 100644 index 0000000..81ac291 --- /dev/null +++ b/src/libultra/io/contreaddata.c @@ -0,0 +1,73 @@ +#include +#include "ultra64/controller.h" + +void __osPackReadData(void); + +s32 osContStartReadData(OSMesgQueue *mq) +{ + s32 ret = 0; + s32 i; + + __osSiGetAccess(); + + if (__osContLastCmd != 1) { + __osPackReadData(); + ret = __osSiRawStartDma(OS_WRITE, &__osContPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + } + + ret = __osSiRawStartDma(OS_READ, &__osContPifRam); + + __osContLastCmd = 1; + __osSiRelAccess(); + + return ret; +} + +void osContGetReadData(OSContPad *data) +{ + u8 *ptr; + __OSContReadFormat readformat; + int i; + ptr = (u8 *)&__osContPifRam.ramarray; + + for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContReadFormat), data++) { + readformat = *(__OSContReadFormat *)ptr; + data->errno = CHNL_ERR(readformat); + + if (data->errno == 0) { + data->button = readformat.button; + data->stick_x = readformat.stick_x; + data->stick_y = readformat.stick_y; + } + } +} + +void __osPackReadData(void) +{ + u8 *ptr; + __OSContReadFormat readformat; + int i; + + ptr = (u8*)&__osContPifRam.ramarray; + + for (i = 0; i < ARRLEN(__osContPifRam.ramarray); i++) { + __osContPifRam.ramarray[i] = 0; + } + + __osContPifRam.pifstatus = CONT_CMD_EXE; + readformat.dummy = CONT_CMD_NOP; + readformat.txsize = CONT_CMD_READ_BUTTON_TX; + readformat.rxsize = CONT_CMD_READ_BUTTON_RX; + readformat.cmd = CONT_CMD_READ_BUTTON; + readformat.button = -1; + readformat.stick_x = -1; + readformat.stick_y = -1; + + for(i=0; i < __osMaxControllers; i++) { + *(__OSContReadFormat*)ptr = readformat; + ptr += sizeof(__OSContReadFormat); + } + + *ptr = CONT_CMD_END; +} diff --git a/src/libultra/io/controller.c b/src/libultra/io/controller.c new file mode 100644 index 0000000..10c5c76 --- /dev/null +++ b/src/libultra/io/controller.c @@ -0,0 +1,109 @@ +#include +#include "ultra64/controller.h" + +extern OSPifRam __osContPifRam; +extern u8 __osContLastCmd; +extern u8 __osMaxControllers; +extern OSTimer __osEepromTimer; +extern OSMesgQueue __osEepromTimerQ; +extern OSMesg __osEepromTimerMsg; + +extern u32 __osContInitialized; + +void __osContGetInitData(u8 *pattern, OSContStatus *data); +void __osPackRequestData(u8 cmd); + +s32 osContInit(OSMesgQueue *mq, u8 *bitpattern, OSContStatus *data) +{ + OSMesg dummy; + s32 ret; + OSTime t; + OSTimer mytimer; + OSMesgQueue timerMesgQueue; + + ret = 0; + + if (__osContInitialized) { + return ret; + } + + __osContInitialized = TRUE; + t = osGetTime(); + + if (t < 23437500) { + osCreateMesgQueue(&timerMesgQueue, &dummy, 1); + osSetTimer(&mytimer, 23437500 - t, 0, &timerMesgQueue, &dummy); + osRecvMesg(&timerMesgQueue, &dummy, OS_MESG_BLOCK); + } + + __osMaxControllers = MAXCONTROLLERS; + __osPackRequestData(CONT_CMD_REQUEST_STATUS); + + ret = __osSiRawStartDma(OS_WRITE, &__osContPifRam); + osRecvMesg(mq, &dummy, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &__osContPifRam); + osRecvMesg(mq, &dummy, OS_MESG_BLOCK); + + __osContGetInitData(bitpattern, data); + __osContLastCmd = CONT_CMD_REQUEST_STATUS; + __osSiCreateAccessQueue(); + + osCreateMesgQueue(&__osEepromTimerQ, &__osEepromTimerMsg, 1); + + return ret; +} + +void __osContGetInitData(u8 *pattern, OSContStatus *data) +{ + u8 *ptr; + __OSContRequestFormat requestformat; + int i; + u8 bits; + bits = 0; + ptr = (u8 *)&__osContPifRam; + + for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContRequestFormat), data++) { + requestformat = *(__OSContRequestFormat *)ptr; + data->errno = CHNL_ERR(requestformat); + + if (data->errno == 0) { + data->type = (requestformat.typel << 8) | requestformat.typeh; + data->status = requestformat.status; + bits |= 1 << i; + } + } + + *pattern = bits; +} + +void __osPackRequestData(u8 cmd) +{ + u8 *ptr; + __OSContRequestFormat requestformat; + int i; + + for (i = 0; i < ARRLEN(__osContPifRam.ramarray); i++) { + __osContPifRam.ramarray[i] = 0; + } + + __osContPifRam.pifstatus = CONT_CMD_EXE; + + ptr = (u8 *)&__osContPifRam.ramarray; + + requestformat.dummy = CONT_CMD_NOP; + requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX; + requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX; + requestformat.cmd = cmd; + requestformat.typeh = CONT_CMD_NOP; + requestformat.typel = CONT_CMD_NOP; + requestformat.status = CONT_CMD_NOP; + requestformat.dummy1 = CONT_CMD_NOP; + + for (i = 0; i < __osMaxControllers; i++) { + *(__OSContRequestFormat *)ptr = requestformat; + ptr += sizeof(__OSContRequestFormat); + } + + ptr[0] = CONT_CMD_END; +} diff --git a/src/libultra/io/crc.c b/src/libultra/io/crc.c new file mode 100644 index 0000000..7d39201 --- /dev/null +++ b/src/libultra/io/crc.c @@ -0,0 +1,96 @@ +#include "PR/os_internal.h" + +u8 __osContAddressCrc(u16 inaddr) +{ + u32 crc; + u32 mask; + u32 addr = inaddr; + + crc = 0; + + for (mask = 0x400; mask != 0; mask >>= 1) { + crc *= 2; + + if (addr & mask) { + if (crc & 0x20) { + crc ^= 20; + } else { + crc++; + } + } else { + if (crc & 0x20) { + crc ^= 21; + } + } + } + + crc <<= 1; + + if (crc & 0x20) { + crc ^= 21; + } + + crc <<= 1; + + if (crc & 0x20) { + crc ^= 21; + } + + crc <<= 1; + + if (crc & 0x20) { + crc ^= 21; + } + + crc <<= 1; + + if (crc & 0x20) { + crc ^= 21; + } + + crc <<= 1; + + if (crc & 0x20) { + crc ^= 21; + } + + return crc & 0x1f; +} + +u8 __osContDataCrc(u8 *data) +{ + u32 i; + u32 mask; + u32 crc = 0; + + for (i = 32; i != 0; i--) { + for (mask = 0x80; mask != 0; mask >>= 1) { + crc *= 2; + + if (*data & mask) { + if (crc & 0x100) { + crc ^= 132; + } else { + crc++; + } + } else { + if (crc & 0x100) { + crc ^= 133; + } + } + } + + data++; + } + + do { + crc <<= 1; + + if (crc & 0x100) { + crc ^= 133; + } + i++; + } while (i < 8); + + return crc; +} diff --git a/src/libultra/io/devmgr.c b/src/libultra/io/devmgr.c new file mode 100644 index 0000000..6ddacce --- /dev/null +++ b/src/libultra/io/devmgr.c @@ -0,0 +1,114 @@ +#include +#include +#include "piint.h" + +void __osDevMgrMain(void *args) +{ + OSIoMesg *mb; + OSMesg em; + OSMesg dummy; + s32 ret; + OSDevMgr *dm; + s32 messageSend; + + messageSend = 0; + mb = NULL; + ret = 0; + dm = (OSDevMgr *)args; + while (TRUE) + { + osRecvMesg(dm->cmdQueue, (OSMesg)&mb, OS_MESG_BLOCK); + if (mb->piHandle != NULL && + mb->piHandle->type == DEVICE_TYPE_64DD && + (mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_0 || + mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_1)) + { + __OSBlockInfo *blockInfo; + __OSTranxInfo *info; + info = &mb->piHandle->transferInfo; + blockInfo = &info->block[info->blockNum]; + info->sectorNum = -1; + if (info->transferMode != LEO_SECTOR_MODE) + { + blockInfo->dramAddr = (void *)((u32)blockInfo->dramAddr - blockInfo->sectorSize); + } + if (info->transferMode == LEO_TRACK_MODE && mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_0) + messageSend = 1; + else + messageSend = 0; + osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); + __osResetGlobalIntMask(OS_IM_PI); + osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, (info->bmCtlShadow | 0x80000000)); + while (TRUE) + { + + osRecvMesg(dm->evtQueue, &em, OS_MESG_BLOCK); + info = &mb->piHandle->transferInfo; + blockInfo = &info->block[info->blockNum]; + if (blockInfo->errStatus == LEO_ERROR_29) + { + u32 stat; + osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_RESET); //TODO: remove magic constants + osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, info->bmCtlShadow); + osEPiRawReadIo(mb->piHandle, LEO_STATUS, &stat); + + if (stat & LEO_STATUS_MECHANIC_INTERRUPT) //TODO: remove magic constants + { + osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, info->bmCtlShadow | LEO_BM_CTL_CLR_MECHANIC_INTR); + } + + blockInfo->errStatus = LEO_ERROR_4; + IO_WRITE(PI_STATUS_REG, PI_CLR_INTR); + __osSetGlobalIntMask(OS_IM_PI | SR_IBIT4); + } + osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); + + if (messageSend != 1) + break; + if (mb->piHandle->transferInfo.block[0].errStatus != LEO_ERROR_GOOD) + break; + messageSend = 0; + } + osSendMesg(dm->acsQueue, NULL, OS_MESG_NOBLOCK); + if (mb->piHandle->transferInfo.blockNum == 1) + osYieldThread(); + } + else + { + switch (mb->hdr.type) + { + case OS_MESG_TYPE_DMAREAD: + osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); + ret = dm->dma(OS_READ, mb->devAddr, mb->dramAddr, mb->size); + break; + case OS_MESG_TYPE_DMAWRITE: + osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); + ret = dm->dma(OS_WRITE, mb->devAddr, mb->dramAddr, mb->size); + break; + case OS_MESG_TYPE_EDMAREAD: + osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); + ret = dm->edma(mb->piHandle, OS_READ, mb->devAddr, mb->dramAddr, + mb->size); + break; + case OS_MESG_TYPE_EDMAWRITE: + osRecvMesg(dm->acsQueue, &dummy, OS_MESG_BLOCK); + ret = dm->edma(mb->piHandle, OS_WRITE, mb->devAddr, mb->dramAddr, + mb->size); + break; + case OS_MESG_TYPE_LOOPBACK: + osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); + ret = -1; + break; + default: + ret = -1; + break; + } + if (ret == 0) + { + osRecvMesg(dm->evtQueue, &em, OS_MESG_BLOCK); + osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); + osSendMesg(dm->acsQueue, NULL, OS_MESG_NOBLOCK); + } + } + } +} diff --git a/src/libultra/io/dpctr.c b/src/libultra/io/dpctr.c new file mode 100644 index 0000000..0c2164b --- /dev/null +++ b/src/libultra/io/dpctr.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +void osDpGetCounters(u32 *array) { + *array++ = IO_READ(DPC_CLOCK_REG); + *array++ = IO_READ(DPC_BUFBUSY_REG); + *array++ = IO_READ(DPC_PIPEBUSY_REG); + *array++ = IO_READ(DPC_TMEM_REG); +} diff --git a/src/libultra/io/dpgetstat.c b/src/libultra/io/dpgetstat.c new file mode 100644 index 0000000..af3ccee --- /dev/null +++ b/src/libultra/io/dpgetstat.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +u32 osDpGetStatus() { + return IO_READ(DPC_STATUS_REG); +} diff --git a/src/libultra/io/dpsetstat.c b/src/libultra/io/dpsetstat.c new file mode 100644 index 0000000..5b53867 --- /dev/null +++ b/src/libultra/io/dpsetstat.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osDpSetStatus(u32 data) { + IO_WRITE(DPC_STATUS_REG, data); +} diff --git a/src/libultra/io/epidma.c b/src/libultra/io/epidma.c new file mode 100644 index 0000000..6009385 --- /dev/null +++ b/src/libultra/io/epidma.c @@ -0,0 +1,28 @@ +#include +#include "piint.h" + +s32 osEPiStartDma(OSPiHandle *pihandle, OSIoMesg *mb, s32 direction) +{ + register s32 ret; + + if (!__osPiDevMgr.active) + return -1; + mb->piHandle = pihandle; + if (direction == OS_READ) + { + mb->hdr.type = OS_MESG_TYPE_EDMAREAD; + } + else + { + mb->hdr.type = OS_MESG_TYPE_EDMAWRITE; + } + if (mb->hdr.pri == OS_MESG_PRI_HIGH) + { + ret = osJamMesg(osPiGetCmdQueue(), mb, OS_MESG_NOBLOCK); + } + else + { + ret = osSendMesg(osPiGetCmdQueue(), mb, OS_MESG_NOBLOCK); + } + return ret; +} diff --git a/src/libultra/io/epirawdma.c b/src/libultra/io/epirawdma.c new file mode 100644 index 0000000..0dc889f --- /dev/null +++ b/src/libultra/io/epirawdma.c @@ -0,0 +1,24 @@ +#include "piint.h" + +s32 osEPiRawStartDma(OSPiHandle *pihandle, s32 direction, u32 devAddr, void *dramAddr, u32 size) +{ + u32 stat; + u32 domain; + + EPI_SYNC(pihandle, stat, domain); + IO_WRITE(PI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); + IO_WRITE(PI_CART_ADDR_REG, K1_TO_PHYS(pihandle->baseAddress | devAddr)); + + switch (direction) + { + case OS_READ: + IO_WRITE(PI_WR_LEN_REG, size - 1); + break; + case OS_WRITE: + IO_WRITE(PI_RD_LEN_REG, size - 1); + break; + default: + return -1; + } + return 0; +} diff --git a/src/libultra/io/epirawread.c b/src/libultra/io/epirawread.c new file mode 100644 index 0000000..44be711 --- /dev/null +++ b/src/libultra/io/epirawread.c @@ -0,0 +1,11 @@ +#include "piint.h" + +s32 osEPiRawReadIo(OSPiHandle* pihandle, u32 devAddr, u32* data) { + u32 stat; + u32 domain; + + EPI_SYNC(pihandle, stat, domain); + *data = IO_READ(pihandle->baseAddress | devAddr); + + return 0; +} diff --git a/src/libultra/io/epirawwrite.c b/src/libultra/io/epirawwrite.c new file mode 100644 index 0000000..f5798b1 --- /dev/null +++ b/src/libultra/io/epirawwrite.c @@ -0,0 +1,58 @@ +#include +#include "piint.h" + +s32 osEPiRawWriteIo(OSPiHandle *handle, u32 devAddr, u32 data) +{ + u32 stat = IO_READ(PI_STATUS_REG); + + while (stat & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) { + stat = IO_READ(PI_STATUS_REG); + } + + if (__osCurrentHandle[handle->domain]->type != handle->type) { + OSPiHandle *cHandle = __osCurrentHandle[handle->domain]; + + if (handle->domain == PI_DOMAIN1) { + if (cHandle->latency != handle->latency) { + IO_WRITE(PI_BSD_DOM1_LAT_REG, handle->latency); + } + + if (cHandle->pageSize != handle->pageSize) { + IO_WRITE(PI_BSD_DOM1_PGS_REG, handle->pageSize); + } + + if (cHandle->relDuration != handle->relDuration) { + IO_WRITE(PI_BSD_DOM1_RLS_REG, handle->relDuration); + } + + if (cHandle->pulse != handle->pulse) { + IO_WRITE(PI_BSD_DOM1_PWD_REG, handle->pulse); + } + } else { + if (cHandle->latency != handle->latency) { + IO_WRITE(PI_BSD_DOM2_LAT_REG, handle->latency); + } + + if (cHandle->pageSize != handle->pageSize) { + IO_WRITE(PI_BSD_DOM2_PGS_REG, handle->pageSize); + } + + if (cHandle->relDuration != handle->relDuration) { + IO_WRITE(PI_BSD_DOM2_RLS_REG, handle->relDuration); + } + + if (cHandle->pulse != handle->pulse) { + IO_WRITE(PI_BSD_DOM2_PWD_REG, handle->pulse); + } + } + + cHandle->type = handle->type; + cHandle->latency = handle->latency; + cHandle->pageSize = handle->pageSize; + cHandle->relDuration = handle->relDuration; + cHandle->pulse = handle->pulse; + } + + IO_WRITE(handle->baseAddress | devAddr, data); + return 0; +} diff --git a/src/libultra/io/epiread.c b/src/libultra/io/epiread.c new file mode 100644 index 0000000..c20e61a --- /dev/null +++ b/src/libultra/io/epiread.c @@ -0,0 +1,13 @@ +#include "piint.h" + +s32 osEPiRawReadIo(OSPiHandle*, u32, u32*); + +s32 osEPiReadIo(OSPiHandle* pihandle, u32 devAddr, u32* data) { + register s32 ret; + + __osPiGetAccess(); + ret = osEPiRawReadIo(pihandle, devAddr, data); + __osPiRelAccess(); + + return ret; +} diff --git a/src/libultra/io/epiwrite.c b/src/libultra/io/epiwrite.c new file mode 100644 index 0000000..e5c7a33 --- /dev/null +++ b/src/libultra/io/epiwrite.c @@ -0,0 +1,13 @@ +#include "piint.h" + +s32 osEPiRawWriteIo(OSPiHandle*, u32, u32); + +s32 osEPiWriteIo(OSPiHandle* pihandle, u32 devAddr, u32 data) { + register s32 ret; + + __osPiGetAccess(); + ret = osEPiRawWriteIo(pihandle, devAddr, data); + __osPiRelAccess(); + + return ret; +} diff --git a/src/libultra/io/gbpakcheckconnector.c b/src/libultra/io/gbpakcheckconnector.c new file mode 100644 index 0000000..d6ed4ad --- /dev/null +++ b/src/libultra/io/gbpakcheckconnector.c @@ -0,0 +1,218 @@ +#include + +/** + * The internal operations performed by the osGbpakCheckConnector function are + * as follows. + * + * - Checks the ROM area addresses of the Game Boy Game Pak and performs the + * following processing for 0x0000, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, + * 0x1000, 0x2000, and 0x4000. + * + * 1. Compares data starting at the above addresses with neighboring data in + * 32-byte units. + * 2. If the data are identical, compares the next 32 bytes, and if this is + * also the same, compares the next 32 bytes. Up to 4 comparisons (ie, 128 + * bytes) are performed. If all data are identical, the address line is + * considered insecurely connected and an error is returned. If different + * data are detected even once, it is determined that the data are being + * read properly and the function advances. + * 3. Data at each of the above addresses are compared with the data starting + * at 0x0000 in 32-byte units. + * 4. As in 2., up to 4 comparisons (128 bytes) are made. If all the data are + * identical, an error is returned. If different data are detected even + * once, it is determined that the data are being read properly and the + * function advances. + * + * - If a RAM area exists, the function checks the address of the Game Boy Game + * Pak RAM area and performs the following processing for 0x2000 and 0xa000. + * + * 1. Compares the data starting at the above addresses in 32-byte units. + * 2. If the data are identical, compares the next 32 bytes, and if this is + * also the same, compares the next 32 bytes. Up to 4 comparisons (ie, 128 + * bytes) are performed. If all the data are the same, the address line is + * evaluated to be insecurely connected and an error is returned. If + * different data are detected even once, it is determined that the data + * are being read properly and the function advances. + */ +s32 osGbpakCheckConnector(OSPfs *pfs, u8 *status) +{ + s32 ret; + s32 thisslot = 1; + s32 prevslot = 0; + u16 thischunkaddr; + u16 prevchunkaddr = 0; + u16 offset; + u16 blocknum; + u8 blocks[3][4][0x20]; + u8 blocksloaded[3][4]; + s32 stilllooking; + + ret = osGbpakGetStatus(pfs, status); + + if (ret == PFS_ERR_NEW_GBCART) { + ret = osGbpakGetStatus(pfs, status); + } + + if (ret == PFS_ERR_NEW_GBCART) { + return PFS_ERR_CONTRFAIL; + } + + if (ret == 0) { + if ((*status & OS_GBPAK_POWER) == 0) { + ret = osGbpakPower(pfs, OS_GBPAK_POWER_ON); + + if (ret != 0) { + return ret; + } + } + + bzero(blocksloaded, 12); + + for (thischunkaddr = 0x80; thischunkaddr <= 0x4000; thischunkaddr *= 2) { + blocknum = 0; + offset = 0; + + do { + // Load the current block + ret = osGbpakReadWrite(pfs, PFS_READ, thischunkaddr + offset, blocks[thisslot][blocknum], 32); + + if (ret != 0) { + return ret; + } + + blocksloaded[thisslot][blocknum] = 1; + + // Load the same block from the previous chunk if not already loaded + // (This only applies for the 0x0000 chunk) + if (blocksloaded[prevslot][blocknum] == 0) { + ret = osGbpakReadWrite(pfs, PFS_READ, prevchunkaddr + offset, blocks[prevslot][blocknum], 32); + + if (ret != 0) { + return ret; + } + + blocksloaded[prevslot][blocknum] = 1; + } + + // Compare them and bail out if different + if (bcmp(blocks[thisslot][blocknum], blocks[prevslot][blocknum], 32) != 0) { + blocknum = 0; + break; + } + + stilllooking = blocknum < 3; + offset += 0x20; blocknum++; + } while (stilllooking); + + if (blocknum); + if (blocknum); + if (blocknum); + if (blocknum); + if (blocknum); + if (blocknum); + + stilllooking = blocknum; + + if (stilllooking) { + return PFS_ERR_CONTRFAIL; + } + + // Now compare each block in this chunk with each block in the + // 0x0000 chunk + blocknum = 0; + offset = 0; + + if (prevslot != 0) { + do { + // Make sure the current block is loaded + if (blocksloaded[thisslot][blocknum] == 0) { + ret = osGbpakReadWrite(pfs, PFS_READ, thischunkaddr + offset, blocks[thisslot][blocknum], 32); + + if (ret != 0) { + return ret; + } + + blocksloaded[thisslot][blocknum] = 1; + } + + // Make sure this block in chunk 0x0000 is loaded + if (blocksloaded[0][blocknum] == 0) { + ret = osGbpakReadWrite(pfs, PFS_READ, offset, blocks[0][blocknum], 32); + + if (ret != 0) { + return ret; + } + + blocksloaded[0][blocknum] = 1; + } + + // Compare them and bail out if different + if (bcmp(blocks[thisslot][blocknum], blocks[0][blocknum], 32) != 0) { + stilllooking = 0; + goto end; + } + + stilllooking = blocknum < 3; + offset += 0x20; blocknum++; + } while (stilllooking); + + stilllooking = blocknum; + } + +end: + if (stilllooking) { + return PFS_ERR_CONTRFAIL; + } + + if (prevslot != 0) { + bzero(&blocksloaded[prevslot][0], 4); + } + + prevchunkaddr = thischunkaddr; + prevslot = thisslot; + thisslot ^= 3; // toggle between 1 and 2 + } + + // Check RAM if present + if (pfs->dir_size >= 2 || pfs->version == 2) { + blocknum = 0; + offset = 0; + + do { + ret = osGbpakReadWrite(pfs, PFS_READ, 0xa000 + offset, blocks[thisslot][blocknum], 32); + + if (ret != 0) { + return ret; + } + + ret = osGbpakReadWrite(pfs, PFS_READ, 0x2000 + offset, blocks[prevslot][blocknum], 32); + + if (ret != 0) { + return ret; + } + + if (bcmp(blocks[thisslot][blocknum], blocks[prevslot][blocknum], 32) != 0) { + blocknum = 0; + break; + } + + stilllooking = blocknum < 3; + offset += 0x20; blocknum++; + } while (stilllooking); + + stilllooking = blocknum; + + if (stilllooking) { + return PFS_ERR_CONTRFAIL; + } + } + + ret = osGbpakGetStatus(pfs, status); + + if (ret == PFS_ERR_NEW_GBCART) { + ret = PFS_ERR_CONTRFAIL; + } + } + + return ret; +} diff --git a/src/libultra/io/gbpakgetstatus.c b/src/libultra/io/gbpakgetstatus.c new file mode 100644 index 0000000..2d45bb3 --- /dev/null +++ b/src/libultra/io/gbpakgetstatus.c @@ -0,0 +1,49 @@ +#include +#include "ultra64/controller.h" +#include "siint.h" + +s32 osGbpakGetStatus(OSPfs *pfs, u8 *status) +{ + s32 ret; + s32 i; + u8 buffer[32]; + + ret = __osContRamRead(pfs->queue, pfs->channel, 0x400, buffer); + + if (ret == PFS_ERR_NEW_PACK || buffer[31] != (OS_GBPAK_RSTB_DETECTION | OS_GBPAK_GBCART_ON)) { + ret = osGbpakInit(pfs->queue, pfs, pfs->channel); + + if (ret != 0) { + return ret; + } + } + + ret = __osContRamRead(pfs->queue, pfs->channel, 0x580, buffer); + + if (ret == 0) { + ret = __osPfsGetStatus(pfs->queue, pfs->channel); + + if (ret != 0) { + return ret; + } + + *status = buffer[0]; + + for (i = 1; i < 32; i++) { + *status |= ((u8 *)buffer)[i]; + } + + *status &= (OS_GBPAK_RSTB_DETECTION | OS_GBPAK_GBCART_PULL); + *status |= buffer[31]; + + if ((*status & OS_GBPAK_GBCART_ON) == 0) { + ret = PFS_ERR_NO_GBCART; + } else if (*status & OS_GBPAK_GBCART_PULL) { + ret = PFS_ERR_NEW_GBCART; + } + } else if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + return ret; +} diff --git a/src/libultra/io/gbpakinit.c b/src/libultra/io/gbpakinit.c new file mode 100644 index 0000000..b61eae5 --- /dev/null +++ b/src/libultra/io/gbpakinit.c @@ -0,0 +1,96 @@ +#include +#include "ultra64/controller.h" + +// .bss +extern OSTimer var80090ab0; +extern OSMesgQueue g_GbpakMesgQueue; +extern OSMesg var80090ae8; + +s32 osGbpakInit(OSMesgQueue *queue, OSPfs *pfs, int channel) +{ + s32 ret; + s32 i; + u8 buffer[32]; + + pfs->status = 0; + + for (i = 0; i < 32; i++) { + buffer[i] = 0xfe; + } + + ret = __osContRamWrite(queue, channel, 0x400, buffer, 0); + + if (ret == PFS_ERR_NEW_PACK) { + ret = __osContRamWrite(queue, channel, 0x400, buffer, 0); + } + + if (ret != 0) { + return ret; + } + + ret = __osContRamRead(queue, channel, 0x400, buffer); + + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } + + if (buffer[31] == 0xfe) { + return PFS_ERR_DEVICE; + } + + // ok but why tho. the earlier loop isnt like this + for (i = 0; i < 32; i+=4) { + buffer[i+0] = 0x84; + buffer[i+1] = 0x84; + buffer[i+2] = 0x84; + buffer[i+3] = 0x84; + } + + ret = __osContRamWrite(queue, channel, 0x400, buffer, 0); + + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } + + ret = __osContRamRead(queue, channel, 0x400, buffer); + + if (ret == 2) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } + + if (buffer[31] != 0x84) { + return PFS_ERR_DEVICE; + } + + ret = __osPfsGetStatus(queue, channel); + + if (ret != 0) { + return ret; + } + + osCreateMesgQueue(&g_GbpakMesgQueue, &var80090ae8, 1); + osSetTimer(&var80090ab0, 9000000, 0, &g_GbpakMesgQueue, &var80090ae8); + osRecvMesg(&g_GbpakMesgQueue, 0, OS_MESG_BLOCK); + + pfs->queue = queue; + pfs->status = 0x10; + pfs->channel = channel; + pfs->activebank = 0x84; + pfs->banks = 0xff; + pfs->version = 0xff; + pfs->dir_size = 0xff; + + return 0; +} diff --git a/src/libultra/io/gbpakpower.c b/src/libultra/io/gbpakpower.c new file mode 100644 index 0000000..0eaf8ee --- /dev/null +++ b/src/libultra/io/gbpakpower.c @@ -0,0 +1,40 @@ +#include + +extern OSTimer var80090ab0; +extern OSMesgQueue g_GbpakMesgQueue; +extern OSMesg var80090ae8; + +s32 osGbpakPower(OSPfs *pfs, s32 flag) +{ + s32 i; + s32 ret; + u8 buffer[32]; + + for (i = 0; i < 32; i+=4) { + buffer[i+0] = flag; + buffer[i+1] = flag; + buffer[i+2] = flag; + buffer[i+3] = flag; + } + + ret = __osContRamWrite(pfs->queue, pfs->channel, 0x580, buffer, 0); + + if (ret == PFS_ERR_NEW_PACK) { + ret = osGbpakInit(pfs->queue, pfs, pfs->channel); + + if (ret == 0) { + ret = __osContRamWrite(pfs->queue, pfs->channel, 0x580, buffer, 0); + + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + } + } + + if (flag != OS_GBPAK_POWER_OFF) { + osSetTimer(&var80090ab0, 0x55D4A8, 0, &g_GbpakMesgQueue, &var80090ae8); + osRecvMesg(&g_GbpakMesgQueue, NULL, OS_MESG_BLOCK); + } + + return ret; +} diff --git a/src/libultra/io/gbpakreadid.c b/src/libultra/io/gbpakreadid.c new file mode 100644 index 0000000..3585c99 --- /dev/null +++ b/src/libultra/io/gbpakreadid.c @@ -0,0 +1,91 @@ +#include +#include "ultra64/controller.h" +#include "siint.h" + +extern void _bcopy(void *, void *, u32); + +u32 g_OsGbNintendoData[] = { + 0xceed6666, 0xcc0d000b, 0x03730083, 0x000c000d, + 0x0008111f, 0x8889000e, 0xdccc6ee6, 0xddddd999, + 0xbbbb6763, 0x6e0eeccc, 0xdddc999f, 0xbbb9333e, +}; + +u8 g_OsGbCartVersions[] = { + 0x00, 0x01, 0x01, 0x01, + 0xff, 0x02, 0x02, 0xff, + 0x00, 0x00, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x03, + 0x03, 0x03, 0x03, 0x03, +}; + +s32 osGbpakReadId(OSPfs *pfs, OSGbpakId *id, u8 *status) +{ + s32 i; + s32 ret; + u8 sum; + u8 buffer[0x60]; + + ret = osGbpakGetStatus(pfs, status); + + if (ret == PFS_ERR_NEW_GBCART) { + ret = osGbpakGetStatus(pfs, status); + } + + if (ret == PFS_ERR_NEW_GBCART) { + return PFS_ERR_CONTRFAIL; + } + + if (ret == 0) { + if ((*status & OS_GBPAK_POWER) == 0) { + ret = osGbpakPower(pfs, OS_GBPAK_POWER_ON); + + if (ret != 0) { + return ret; + } + } + + ret = osGbpakReadWrite(pfs, PFS_READ, 0x100, buffer, 0x60); + + if (ret != 0) { + return ret; + } + + ret = osGbpakGetStatus(pfs, status); + + if (ret == PFS_ERR_NEW_GBCART) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } + + // Compare id->nintendo_chr with expected data + if (bcmp(g_OsGbNintendoData, &buffer[4], sizeof(id->nintendo_chr)) != 0) { + return PFS_ERR_CONTRFAIL; + } + + // Sum game_title through to isum + sum = 0; + + for (i = 0x34; i < 0x4e; i++) { + sum += buffer[i]; + } + + sum = (sum + 25) & 0xff; + + if (sum != 0) { + return PFS_ERR_CONTRFAIL; + } + + _bcopy(buffer, id, sizeof(OSGbpakId)); + + if (id->cart_type < 20) { + pfs->version = g_OsGbCartVersions[id->cart_type]; + } + + pfs->dir_size = id->ram_size; + } + + return ret; +} diff --git a/src/libultra/io/gbpakreadwrite.c b/src/libultra/io/gbpakreadwrite.c new file mode 100644 index 0000000..d1c8436 --- /dev/null +++ b/src/libultra/io/gbpakreadwrite.c @@ -0,0 +1,77 @@ +#include +#include "ultra64/controller.h" + +s32 osGbpakReadWrite(OSPfs *pfs, u16 flag, u16 address, u8 *buffer, u16 size) +{ + s32 i; + s32 ret; + u8 bank; + u16 addr; + + bank = address >> 14; + + if (bank != pfs->banks) { + ret = __osGbpakSelectBank(pfs, bank); + + if (ret != 0) { + return ret; + } + } + + size = size >> 5; + address = (address | 0xc000) >> 5; + + if (flag == PFS_WRITE) { + for (i = 0; i < size; i++) { + ret = __osContRamWrite(pfs->queue, pfs->channel, address, buffer, 0); + + if (ret != 0) { + break; + } + + address++; + + if (address >= 0x800 && i < size - 1) { + bank++; + ret = __osGbpakSelectBank(pfs, bank); + + if (ret != 0) { + break; + } + + address = 0x600; + } + + buffer += BLOCKSIZE; + } + } else { + for (i = 0; i < size; i++) { + ret = __osContRamRead(pfs->queue, pfs->channel, address, buffer); + + if (ret != 0) { + break; + } + + address++; + + if (address >= 0x800 && i < size - 1) { + bank++; + ret = __osGbpakSelectBank(pfs, bank); + + if (ret != 0) { + break; + } + + address = 0x600; + } + + buffer += BLOCKSIZE; + } + } + + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + return ret; +} diff --git a/src/libultra/io/gbpakselectbank.c b/src/libultra/io/gbpakselectbank.c new file mode 100644 index 0000000..27de904 --- /dev/null +++ b/src/libultra/io/gbpakselectbank.c @@ -0,0 +1,42 @@ +#include +#include "ultra64/controller.h" +#include "siint.h" + +s32 __osGbpakSelectBank(OSPfs *pfs, u8 bank) +{ + s32 ret; + s32 i; + u8 buffer[32]; + s32 j; + + if (bank >= 3) { + return PFS_ERR_INVALID; + } + + for (i = 0; i < 32; i+=4) { + buffer[i+0] = bank; + buffer[i+1] = bank; + buffer[i+2] = bank; + buffer[i+3] = bank; + } + + ret = __osContRamWrite(pfs->queue, pfs->channel, 0x500, (u8 *)buffer, 0); + + if (ret == PFS_ERR_NEW_PACK) { + ret = osGbpakInit(pfs->queue, pfs, pfs->channel); + + if (ret == 0) { + ret = __osContRamWrite(pfs->queue, pfs->channel, 0x500, (u8 *)buffer, 0); + + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + } + } + + if (ret == 0) { + pfs->banks = bank; + } + + return ret; +} diff --git a/src/libultra/io/pfsgetstatus.c b/src/libultra/io/pfsgetstatus.c new file mode 100644 index 0000000..dc4afdb --- /dev/null +++ b/src/libultra/io/pfsgetstatus.c @@ -0,0 +1,85 @@ +#include +#include "ultra64/controller.h" + +void __osPfsRequestOneChannel(int channel, u8 cmd); +void __osPfsGetOneChannelData(int channel, OSContStatus *data); + +extern u8 __osPfsInodeCacheBank; + +s32 __osPfsGetStatus(OSMesgQueue *queue, int channel) +{ + s32 ret; + OSMesg dummy; + OSContStatus data; + + ret = 0; + __osPfsInodeCacheBank = 0xfa; + + __osPfsRequestOneChannel(channel, CONT_CMD_REQUEST_STATUS); + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(queue, &dummy, OS_MESG_BLOCK); + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(queue, &dummy, OS_MESG_BLOCK); + __osPfsGetOneChannelData(channel, &data); + + if ((data.status & CONT_CARD_ON) && (data.status & CONT_CARD_PULL)) { + return PFS_ERR_NEW_PACK; + } + + if (data.errno != 0 || (data.status & CONT_CARD_ON) == 0) { + return PFS_ERR_NOPACK; + } + + if (data.status & CONT_ADDR_CRC_ER) { + return PFS_ERR_CONTRFAIL; + } + + return ret; +} + +void __osPfsRequestOneChannel(int channel, u8 cmd) +{ + u8 *ptr; + __OSContRequestFormatShort requestformat; + int i; + + __osContLastCmd = CONT_CMD_END; + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + ptr = (u8 *)&__osPfsPifRam; + + requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX; + requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX; + requestformat.cmd = cmd; + requestformat.typeh = CONT_CMD_NOP; + requestformat.typel = CONT_CMD_NOP; + requestformat.status = CONT_CMD_NOP; + + for (i = 0; i < channel; i++) { + *ptr++ = 0; + } + + *(__OSContRequestFormatShort *)ptr = requestformat; + ptr += sizeof(__OSContRequestFormatShort); + *ptr = CONT_CMD_END; +} + +void __osPfsGetOneChannelData(int channel, OSContStatus *data) +{ + u8 *ptr; + __OSContRequestFormatShort requestformat; + int i; + + ptr = (u8*)&__osPfsPifRam; + + for (i = 0; i < channel; i++) { + ptr++; + } + + requestformat = *(__OSContRequestFormatShort *)ptr; + data->errno = CHNL_ERR(requestformat); + + if (data->errno == 0) { + data->type = (requestformat.typel << 8) | (requestformat.typeh); + data->status = requestformat.status; + } +} diff --git a/src/libultra/io/pfsisplug.c b/src/libultra/io/pfsisplug.c new file mode 100644 index 0000000..7b35ef4 --- /dev/null +++ b/src/libultra/io/pfsisplug.c @@ -0,0 +1,94 @@ +#include +#include "ultra64/controller.h" +#include "siint.h" + +extern OSPifRam __osPfsPifRam; +s32 osPfsIsPlug(OSMesgQueue *queue, u8 *pattern) +{ + s32 ret; + OSMesg dummy; + u8 bitpattern; + OSContStatus data[MAXCONTROLLERS]; + int channel; + u8 bits; + int crc_error_cnt; + ret = 0; + bits = 0; + crc_error_cnt = 3; + __osSiGetAccess(); + while (TRUE) + { + __osPfsRequestData(CONT_CMD_REQUEST_STATUS); + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(queue, &dummy, OS_MESG_BLOCK); + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(queue, &dummy, OS_MESG_BLOCK); + __osPfsGetInitData(&bitpattern, data); + for (channel = 0; channel < __osMaxControllers; channel++) + { + if ((data[channel].status & CONT_ADDR_CRC_ER) == 0) + { + crc_error_cnt--; + break; + } + } + if (__osMaxControllers == channel) + crc_error_cnt = 0; + if (crc_error_cnt < 1) + { + for (channel = 0; channel < __osMaxControllers; channel++) + { + if (data[channel].errno == 0 && (data[channel].status & CONT_CARD_ON) != 0) + bits |= 1 << channel; + } + __osSiRelAccess(); + *pattern = bits; + return ret; + } + } +} +void __osPfsRequestData(u8 cmd) +{ + u8 *ptr; + __OSContRequestFormat requestformat; + int i; + ptr = (u8 *)&__osPfsPifRam; + __osContLastCmd = cmd; + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + requestformat.dummy = CONT_CMD_NOP; + requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX; + requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX; + requestformat.cmd = cmd; + requestformat.typeh = CONT_CMD_NOP; + requestformat.typel = CONT_CMD_NOP; + requestformat.status = CONT_CMD_NOP; + requestformat.dummy1 = CONT_CMD_NOP; + for (i = 0; i < __osMaxControllers; i++) + { + *(__OSContRequestFormat *)ptr = requestformat; + ptr += sizeof(__OSContRequestFormat); + } + *ptr = CONT_CMD_END; +} +void __osPfsGetInitData(u8 *pattern, OSContStatus *data) +{ + u8 *ptr; + __OSContRequestFormat requestformat; + int i; + u8 bits; + bits = 0; + ptr = (u8 *)&__osPfsPifRam; + for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContRequestFormat)) + { + requestformat = *(__OSContRequestFormat *)ptr; + data->errno = CHNL_ERR(requestformat); + if (data->errno == 0) + { + data->type = (requestformat.typel << 8) | (requestformat.typeh); + data->status = requestformat.status; + bits |= 1 << i; + } + data++; + } + *pattern = bits; +} diff --git a/src/libultra/io/pfsselectbank.c b/src/libultra/io/pfsselectbank.c new file mode 100644 index 0000000..4c03254 --- /dev/null +++ b/src/libultra/io/pfsselectbank.c @@ -0,0 +1,24 @@ +#include +#include "ultra64/controller.h" + +s32 __osPfsSelectBank(OSPfs *pfs, u8 bank) +{ + u8 temp[8][4]; + int i, j; + s32 ret; + ret = 0; + + for (i = 0; i < 8; i++) { + for(j = 0; j < 4; j++) { + temp[i][j] = bank; + } + } + + ret = __osContRamWrite(pfs->queue, pfs->channel, 1024, (u8*)temp, FALSE); + + if (ret == 0) { + pfs->activebank = bank; + } + + return ret; +} diff --git a/src/libultra/io/piacs.c b/src/libultra/io/piacs.c new file mode 100644 index 0000000..e61222d --- /dev/null +++ b/src/libultra/io/piacs.c @@ -0,0 +1,25 @@ +#include + +extern u32 __osPiAccessQueueEnabled; +extern OSMesg piAccessBuf[1]; +extern OSMesgQueue __osPiAccessQueue; + +void __osPiCreateAccessQueue(void) { + __osPiAccessQueueEnabled = 1; + osCreateMesgQueue(&__osPiAccessQueue, piAccessBuf, ARRAY_COUNT(piAccessBuf)); + osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK); +} + +void __osPiGetAccess(void) { + OSMesg msg; + + if (!__osPiAccessQueueEnabled) { + __osPiCreateAccessQueue(); + } + + osRecvMesg(&__osPiAccessQueue, &msg, OS_MESG_BLOCK); +} + +void __osPiRelAccess(void) { + osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK); +} diff --git a/src/libultra/io/piint.h b/src/libultra/io/piint.h new file mode 100644 index 0000000..734fdde --- /dev/null +++ b/src/libultra/io/piint.h @@ -0,0 +1,154 @@ +#ifndef _PIINT_H_ +#define _PIINT_H_ + +#include "PR/os_internal.h" +#include "PR/rcp.h" + +//https://github.com/LuigiBlood/64dd/wiki/Memory-Map + +#define LEO_BASE_REG 0x05000000 + +#define LEO_CMD (LEO_BASE_REG + 0x508) +#define LEO_STATUS (LEO_BASE_REG + 0x508) + +#define LEO_BM_CTL (LEO_BASE_REG + 0x510) +#define LEO_BM_STATUS (LEO_BASE_REG + 0x510) + +#define LEO_SEQ_CTL (LEO_BASE_REG + 0x518) +#define LEO_SEQ_STATUS (LEO_BASE_REG + 0x518) + +#define LEO_C2_BUFF (LEO_BASE_REG + 0x000) //C2 Sector Buffer +#define LEO_SECTOR_BUFF (LEO_BASE_REG + 0x400) //Data Sector Buffer +#define LEO_DATA (LEO_BASE_REG + 0x500) //Data +#define LEO_MISC_REG (LEO_BASE_REG + 0x504) //Misc Register +#define LEO_CUR_TK (LEO_BASE_REG + 0x50C) //Current Track +#define LEO_ERR_SECTOR (LEO_BASE_REG + 0x514) //Sector Error Status +#define LEO_CUR_SECTOR (LEO_BASE_REG + 0x51C) //Current Sector +#define LEO_HARD_RESET (LEO_BASE_REG + 0x520) //Hard Reset +#define LEO_C1_S0 (LEO_BASE_REG + 0x524) //C1 +#define LEO_HOST_SECBYTE (LEO_BASE_REG + 0x528) //Sector Size (in bytes) +#define LEO_C1_S2 (LEO_BASE_REG + 0x52C) //C1 +#define LEO_SEC_BYTE (LEO_BASE_REG + 0x530) //Sectors per Block, Full Size +#define LEO_C1_S4 (LEO_BASE_REG + 0x534) //C1 +#define LEO_C1_S6 (LEO_BASE_REG + 0x538) //C1 +#define LEO_CUR_ADDR (LEO_BASE_REG + 0x53C) //Current Address? +#define LEO_ID_REG (LEO_BASE_REG + 0x540) //ID +#define LEO_TEST_REG (LEO_BASE_REG + 0x544) //Test Read +#define LEO_TEST_PIN_SEL (LEO_BASE_REG + 0x548) //Test Write +#define LEO_RAM_ADDR (LEO_BASE_REG + 0x580) //Microsequencer RAM + +#define LEO_STATUS_PRESENCE_MASK 0xFFFF + +#define LEO_STATUS_DATA_REQUEST 0x40000000 +#define LEO_STATUS_C2_TRANSFER 0x10000000 +#define LEO_STATUS_BUFFER_MANAGER_ERROR 0x08000000 +#define LEO_STATUS_BUFFER_MANAGER_INTERRUPT 0x04000000 +#define LEO_STATUS_MECHANIC_INTERRUPT 0x02000000 +#define LEO_STATUS_DISK_PRESENT 0x01000000 +#define LEO_STATUS_BUSY_STATE 0x00800000 +#define LEO_STATUS_RESET_STATE 0x00400000 +#define LEO_STATUS_MOTOR_NOT_SPINNING 0x00100000 +#define LEO_STATUS_HEAD_RETRACTED 0x00080000 +#define LEO_STATUS_WRITE_PROTECT_ERROR 0x00040000 +#define LEO_STATUS_MECHANIC_ERROR 0x00020000 +#define LEO_STATUS_DISK_CHANGE 0x00010000 + +#define LEO_STATUS_MODE_MASK (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED) +#define LEO_STATUS_MODE_SLEEP (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED) +#define LEO_STATUS_MODE_STANDBY (LEO_STATUS_HEAD_RETRACTED) +#define LEO_STATUS_MODE_ACTIVE 0 + +#define LEO_CUR_TK_INDEX_LOCK 0x60000000 + +#define LEO_BM_STATUS_RUNNING 0x80000000 //Running +#define LEO_BM_STATUS_ERROR 0x04000000 //Error +#define LEO_BM_STATUS_MICRO 0x02000000 //Micro Status? +#define LEO_BM_STATUS_BLOCK 0x01000000 //Block Transfer +#define LEO_BM_STATUS_C1CORRECTION 0x00800000 //C1 Correction +#define LEO_BM_STATUS_C1DOUBLE 0x00400000 //C1 Double +#define LEO_BM_STATUS_C1SINGLE 0x00200000 //C1 Single +#define LEO_BM_STATUS_C1ERROR 0x00010000 //C1 Error + +#define LEO_BM_CTL_START 0x80000000 //Start Buffer Manager +#define LEO_BM_CTL_MODE 0x40000000 //Buffer Manager Mode +#define LEO_BM_CTL_IMASK 0x20000000 //BM Interrupt Mask +#define LEO_BM_CTL_RESET 0x10000000 //Buffer Manager Reset +#define LEO_BM_CTL_DISABLE_OR 0x08000000 //Disable OR Check? +#define LEO_BM_CTL_DISABLE_C1 0x04000000 //Disable C1 Correction +#define LEO_BM_CTL_BLOCK 0x02000000 //Block Transfer +#define LEO_BM_CTL_CLR_MECHANIC_INTR 0x01000000 //Mechanic Interrupt Reset + +#define LEO_BM_CTL_CONTROL_MASK 0xFF000000 +#define LEO_BM_CTL_SECTOR_MASK 0x00FF0000 +#define LEO_BM_CTL_SECTOR_SHIFT 16 + +#define LEO_CMD_TYPE_0 0 //TODO: name +#define LEO_CMD_TYPE_1 1 //TODO: name +#define LEO_CMD_TYPE_2 2 //TODO: name + +#define LEO_ERROR_GOOD 0 +#define LEO_ERROR_4 4 //maybe busy? +#define LEO_ERROR_22 22 // +#define LEO_ERROR_23 23 //unrecovered read error? +#define LEO_ERROR_24 24 //no reference position found? +#define LEO_ERROR_29 29 // + +extern OSDevMgr __osPiDevMgr; +extern OSPiHandle *__osCurrentHandle[2]; +extern OSPiHandle CartRomHandle; +extern OSPiHandle LeoDiskHandle; +extern OSMesgQueue __osPiAccessQueue; +extern u32 __osPiAccessQueueEnabled; + +int __osPiDeviceBusy(void); +void __osDevMgrMain(void *); +void __osPiCreateAccessQueue(void); +void __osPiRelAccess(void); +void __osPiGetAccess(void); +s32 __osPiRawStartDma(s32, u32 , void *, u32 ); +s32 __osPiRawWriteIo(u32, u32); +s32 __osPiRawReadIo(u32, u32 *); +s32 __osEPiRawWriteIo(OSPiHandle *, u32 , u32); +s32 __osEPiRawReadIo(OSPiHandle *, u32 , u32 *); +s32 __osEPiRawStartDma(OSPiHandle *, s32 , u32 , void *, u32 ); +OSMesgQueue *osPiGetCmdQueue(void); + +#define WAIT_ON_IOBUSY(stat) \ + while (stat = IO_READ(PI_STATUS_REG), stat & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) \ + ; \ + (void)0 + +#define UPDATE_REG(pihandle, reg, var) \ + if (cHandle->var != pihandle->var) \ + IO_WRITE(reg, pihandle->var) + +#define EPI_SYNC(pihandle, stat, domain) \ + \ + WAIT_ON_IOBUSY(stat); \ + \ + domain = pihandle->domain; \ + if (__osCurrentHandle[domain]->type != pihandle->type) \ + { \ + OSPiHandle *cHandle = __osCurrentHandle[domain]; \ + if (domain == PI_DOMAIN1) \ + { \ + UPDATE_REG(pihandle, PI_BSD_DOM1_LAT_REG, latency); \ + UPDATE_REG(pihandle, PI_BSD_DOM1_PGS_REG, pageSize); \ + UPDATE_REG(pihandle, PI_BSD_DOM1_RLS_REG, relDuration); \ + UPDATE_REG(pihandle, PI_BSD_DOM1_PWD_REG, pulse); \ + } \ + else \ + { \ + UPDATE_REG(pihandle, PI_BSD_DOM2_LAT_REG, latency); \ + UPDATE_REG(pihandle, PI_BSD_DOM2_PGS_REG, pageSize); \ + UPDATE_REG(pihandle, PI_BSD_DOM2_RLS_REG, relDuration); \ + UPDATE_REG(pihandle, PI_BSD_DOM2_PWD_REG, pulse); \ + } \ + cHandle->type = pihandle->type; \ + cHandle->latency = pihandle->latency; \ + cHandle->pageSize = pihandle->pageSize; \ + cHandle->relDuration = pihandle->relDuration; \ + cHandle->pulse = pihandle->pulse; \ + }(void)0 + +#endif diff --git a/src/libultra/io/pimgr.c b/src/libultra/io/pimgr.c new file mode 100644 index 0000000..53843dd --- /dev/null +++ b/src/libultra/io/pimgr.c @@ -0,0 +1,58 @@ +#include +#include +#include "piint.h" + +extern s32 osPiRawStartDma(s32, u32, void *, u32); // TODO: DEFINE +extern s32 osEPiRawStartDma(OSPiHandle *, s32, u32, void *, u32); // TODO: DEFINE + +extern OSDevMgr __osPiDevMgr; +extern OSPiHandle *__osPiTable; +extern OSPiHandle *__osCurrentHandle[2]; +extern OSThread piThread; +extern char piThreadStack[OS_PIM_STACKSIZE]; +#ifdef _DEBUG +extern OSThread ramromThread; +extern char ramromThreadStack[OS_RAMROM_STACKSIZE]; +extern OSMesgQueue getRamromQ; +extern OSMesg getRamromBuf[1]; +extern OSMesgQueue freeRamromQ; +extern OSMesg freeRamromBuf[1]; +#endif +extern OSMesgQueue piEventQueue; +extern OSMesg piEventBuf[1]; +void osCreatePiManager(OSPri pri, OSMesgQueue *cmdQ, OSMesg *cmdBuf, s32 cmdMsgCnt) +{ + u32 savedMask; + OSPri oldPri; + OSPri myPri; + if (!__osPiDevMgr.active) + { + osCreateMesgQueue(cmdQ, cmdBuf, cmdMsgCnt); + osCreateMesgQueue(&piEventQueue, (OSMesg*)&piEventBuf, 1); + if (!__osPiAccessQueueEnabled) + __osPiCreateAccessQueue(); + osSetEventMesg(OS_EVENT_PI, &piEventQueue, (OSMesg)0x22222222); + oldPri = -1; + myPri = osGetThreadPri(NULL); + if (myPri < pri) + { + oldPri = myPri; + osSetThreadPri(NULL, pri); + } + savedMask = __osDisableInt(); + __osPiDevMgr.active = 1; + __osPiDevMgr.thread = &piThread; + __osPiDevMgr.cmdQueue = cmdQ; + __osPiDevMgr.evtQueue = &piEventQueue; + __osPiDevMgr.acsQueue = &__osPiAccessQueue; + __osPiDevMgr.dma = osPiRawStartDma; + __osPiDevMgr.edma = osEPiRawStartDma; + osCreateThread(&piThread, 0, __osDevMgrMain, &__osPiDevMgr, &piThreadStack[OS_PIM_STACKSIZE], pri); + osStartThread(&piThread); + __osRestoreInt(savedMask); + if (oldPri != -1) + { + osSetThreadPri(NULL, oldPri); + } + } +} diff --git a/src/libultra/io/pirawdma.c b/src/libultra/io/pirawdma.c new file mode 100644 index 0000000..9fc7901 --- /dev/null +++ b/src/libultra/io/pirawdma.c @@ -0,0 +1,23 @@ +#include +#include +#include "piint.h" + +s32 osPiRawStartDma(s32 direction, u32 devAddr, void *dramAddr, u32 size) +{ + register u32 stat; + WAIT_ON_IOBUSY(stat); + IO_WRITE(PI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); + IO_WRITE(PI_CART_ADDR_REG, K1_TO_PHYS((u32)osRomBase | devAddr)); + switch (direction) + { + case OS_READ: + IO_WRITE(PI_WR_LEN_REG, size - 1); + break; + case OS_WRITE: + IO_WRITE(PI_RD_LEN_REG, size - 1); + break; + default: + return -1; + } + return 0; +} diff --git a/src/libultra/io/si.c b/src/libultra/io/si.c new file mode 100644 index 0000000..c20c71b --- /dev/null +++ b/src/libultra/io/si.c @@ -0,0 +1,10 @@ +#include +#include "siint.h" + +int __osSiDeviceBusy() +{ + register u32 stat = IO_READ(SI_STATUS_REG); + if (stat & (SI_STATUS_DMA_BUSY | SI_STATUS_RD_BUSY)) + return 1; + return 0; +} diff --git a/src/libultra/io/siacs.c b/src/libultra/io/siacs.c new file mode 100644 index 0000000..8001295 --- /dev/null +++ b/src/libultra/io/siacs.c @@ -0,0 +1,30 @@ +#include + +extern OSMesg siAccessBuf; +extern u32 var8009c7c4; +extern OSMesgQueue __osSiAccessQueue; + +extern u32 __osSiAccessQueueEnabled; + +void __osSiCreateAccessQueue(void) +{ + __osSiAccessQueueEnabled = 1; + osCreateMesgQueue(&__osSiAccessQueue, &siAccessBuf, 1); + osSendMesg(&__osSiAccessQueue, NULL, OS_MESG_NOBLOCK); +} + +void __osSiGetAccess(void) +{ + OSMesg dummyMesg; + + if (!__osSiAccessQueueEnabled) { + __osSiCreateAccessQueue(); + } + + osRecvMesg(&__osSiAccessQueue, &dummyMesg, OS_MESG_BLOCK); +} + +void __osSiRelAccess(void) +{ + osSendMesg(&__osSiAccessQueue, NULL, OS_MESG_NOBLOCK); +} diff --git a/src/libultra/io/siint.h b/src/libultra/io/siint.h new file mode 100644 index 0000000..45bf56b --- /dev/null +++ b/src/libultra/io/siint.h @@ -0,0 +1,10 @@ +#ifndef _SIINT_H +#define _SIINT_H +#include +#include + +void __osSiGetAccess(void); +void __osSiRelAccess(void); +int __osSiDeviceBusy(void); +void __osSiCreateAccessQueue(void); +#endif diff --git a/src/libultra/io/sirawdma.c b/src/libultra/io/sirawdma.c new file mode 100644 index 0000000..b464a10 --- /dev/null +++ b/src/libultra/io/sirawdma.c @@ -0,0 +1,26 @@ +#include + +s32 __osSiRawStartDma(s32 direction, void *dramAddr) +{ + if (IO_READ(SI_STATUS_REG) & (SI_STATUS_DMA_BUSY | SI_STATUS_RD_BUSY)) { + return -1; + } + + if (direction == OS_WRITE) { + osWritebackDCache(dramAddr, 64); + } + + IO_WRITE(SI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); + + if (direction == OS_READ) { + IO_WRITE(SI_PIF_ADDR_RD64B_REG, 0x1fc007c0); + } else { + IO_WRITE(SI_PIF_ADDR_WR64B_REG, 0x1fc007c0); + } + + if (direction == OS_READ) { + osInvalDCache(dramAddr, 64); + } + + return 0; +} diff --git a/src/libultra/io/sirawread.c b/src/libultra/io/sirawread.c new file mode 100644 index 0000000..ea27761 --- /dev/null +++ b/src/libultra/io/sirawread.c @@ -0,0 +1,10 @@ +#include +#include "siint.h" + +s32 __osSiRawReadIo(u32 devAddr, u32 *data) +{ + if (__osSiDeviceBusy()) + return -1; + *data = IO_READ(devAddr); + return 0; +} diff --git a/src/libultra/io/sirawwrite.c b/src/libultra/io/sirawwrite.c new file mode 100644 index 0000000..9967c1d --- /dev/null +++ b/src/libultra/io/sirawwrite.c @@ -0,0 +1,14 @@ +#include "PR/os_internal.h" +#include "siint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSiRawWriteIo(u32 devAddr, u32 data) { + if (__osSiDeviceBusy()) { + return -1; + } + + IO_WRITE(devAddr, data); + return 0; +} diff --git a/src/libultra/io/sp.c b/src/libultra/io/sp.c new file mode 100644 index 0000000..9517083 --- /dev/null +++ b/src/libultra/io/sp.c @@ -0,0 +1,11 @@ +#include +#include +#include + +int __osSpDeviceBusy() +{ + register u32 stat = IO_READ(SP_STATUS_REG); + if (stat & (SP_STATUS_DMA_BUSY | SP_STATUS_DMA_FULL | SP_STATUS_IO_FULL)) + return 1; + return 0; +} diff --git a/src/libultra/io/spgetstat.c b/src/libultra/io/spgetstat.c new file mode 100644 index 0000000..0cdfda6 --- /dev/null +++ b/src/libultra/io/spgetstat.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +u32 __osSpGetStatus() { + return IO_READ(SP_STATUS_REG); +} diff --git a/src/libultra/io/sprawdma.c b/src/libultra/io/sprawdma.c new file mode 100644 index 0000000..9d20e5e --- /dev/null +++ b/src/libultra/io/sprawdma.c @@ -0,0 +1,19 @@ +#include + +s32 __osSpRawStartDma(s32 direction, u32 devAddr, void *dramAddr, u32 size) +{ + if (__osSpDeviceBusy()) { + return -1; + } + + IO_WRITE(SP_MEM_ADDR_REG, devAddr); + IO_WRITE(SP_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); + + if (direction == OS_READ) { + IO_WRITE(SP_WR_LEN_REG, size - 1); + } else { + IO_WRITE(SP_RD_LEN_REG, size - 1); + } + + return 0; +} diff --git a/src/libultra/io/spsetpc.c b/src/libultra/io/spsetpc.c new file mode 100644 index 0000000..dce0b5d --- /dev/null +++ b/src/libultra/io/spsetpc.c @@ -0,0 +1,15 @@ +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSpSetPc(u32 pc) { + register u32 status = IO_READ(SP_STATUS_REG); + + if (!(status & SP_STATUS_HALT)) { + return -1; + } + IO_WRITE(SP_PC_REG, pc); + + return 0; +} diff --git a/src/libultra/io/spsetstat.c b/src/libultra/io/spsetstat.c new file mode 100644 index 0000000..2ab47e0 --- /dev/null +++ b/src/libultra/io/spsetstat.c @@ -0,0 +1,9 @@ +#include "PR/os_internal.h" +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void __osSpSetStatus(u32 data) { + IO_WRITE(SP_STATUS_REG, data); +} diff --git a/src/libultra/io/sptaskyield.c b/src/libultra/io/sptaskyield.c new file mode 100644 index 0000000..78637ce --- /dev/null +++ b/src/libultra/io/sptaskyield.c @@ -0,0 +1,7 @@ +#include +#include + +void osSpTaskYield(void) +{ + __osSpSetStatus(SP_SET_YIELD); +} diff --git a/src/libultra/io/sptaskyielded.c b/src/libultra/io/sptaskyielded.c new file mode 100644 index 0000000..030f46e --- /dev/null +++ b/src/libultra/io/sptaskyielded.c @@ -0,0 +1,23 @@ +#include "PR/os_internal.h" +#include "PR/sptask.h" +#include "PR/rcp.h" + +OSYieldResult osSpTaskYielded(OSTask *tp) { + u32 status; + OSYieldResult result; + + status = __osSpGetStatus(); + + if (status & SP_STATUS_YIELDED) { + result = OS_TASK_YIELDED; + } else { + result = 0; + } + + if (status & SP_STATUS_YIELD) { + tp->t.flags |= result; + tp->t.flags &= ~(OS_TASK_DP_WAIT); + } + + return result; +} diff --git a/src/libultra/io/vi.c b/src/libultra/io/vi.c new file mode 100644 index 0000000..93a6795 --- /dev/null +++ b/src/libultra/io/vi.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +static __OSViContext vi[2] = {0}; +__OSViContext *__osViCurr = &vi[0]; +__OSViContext *__osViNext = &vi[1]; + +void __osViInit(void) { + bzero(vi, sizeof(vi)); + __osViCurr = &vi[0]; + __osViNext = &vi[1]; + __osViNext->retraceCount = 1; + __osViCurr->retraceCount = 1; + __osViNext->framep = (void*)K0BASE; + __osViCurr->framep = (void*)K0BASE; + + if (osTvType == OS_TV_TYPE_PAL) { + __osViNext->modep = &osViModePalLan1; + } else if (osTvType == OS_TV_TYPE_MPAL) { + __osViNext->modep = &osViModeMpalLan1; + } else { + __osViNext->modep = &osViModeNtscLan1; + } + + __osViNext->state = VI_STATE_BLACK; + __osViNext->control = __osViNext->modep->comRegs.ctrl; + + while (IO_READ(VI_CURRENT_REG) > 10) { //wait for vsync? + } + + IO_WRITE(VI_CONTROL_REG, 0); //pixel size blank (no data, no sync) + __osViSwapContext(); +} diff --git a/src/libultra/io/viblack.c b/src/libultra/io/viblack.c new file mode 100644 index 0000000..76cd0b2 --- /dev/null +++ b/src/libultra/io/viblack.c @@ -0,0 +1,11 @@ +#include +#include "viint.h" +void osViBlack(u8 active) +{ + register u32 saveMask = __osDisableInt(); + if (active) + __osViNext->state |= VI_STATE_BLACK; + else + __osViNext->state &= ~VI_STATE_BLACK; + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/vigetcurrcontext.c b/src/libultra/io/vigetcurrcontext.c new file mode 100644 index 0000000..729d902 --- /dev/null +++ b/src/libultra/io/vigetcurrcontext.c @@ -0,0 +1,9 @@ +#include +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +__OSViContext *__osViGetCurrentContext(void) { + return __osViCurr; +} diff --git a/src/libultra/io/vigetcurrframebuf.c b/src/libultra/io/vigetcurrframebuf.c new file mode 100644 index 0000000..987e86b --- /dev/null +++ b/src/libultra/io/vigetcurrframebuf.c @@ -0,0 +1,10 @@ +#include +#include "viint.h" + +void *osViGetCurrentFramebuffer(void) { + register u32 saveMask = __osDisableInt(); + void *framep = __osViCurr->framep; + + __osRestoreInt(saveMask); + return framep; +} diff --git a/src/libultra/io/viint.h b/src/libultra/io/viint.h new file mode 100644 index 0000000..3ae94c8 --- /dev/null +++ b/src/libultra/io/viint.h @@ -0,0 +1,70 @@ +#ifndef _VIINT_H +#define _VIINT_H +#include "PR/os_internal.h" + +#define OS_TV_TYPE_PAL 0 +#define OS_TV_TYPE_NTSC 1 +#define OS_TV_TYPE_MPAL 2 + +#define VI_STATE_MODE_UPDATED 0x01 +#define VI_STATE_XSCALE_UPDATED 0x02 +#define VI_STATE_YSCALE_UPDATED 0x04 +#define VI_STATE_CTRL_UPDATED 0x08 // related to control regs changing +#define VI_STATE_BUFFER_UPDATED 0x10 // swap buffer +#define VI_STATE_BLACK 0x20 // probably related to a black screen +#define VI_STATE_REPEATLINE 0x40 // repeat line? +#define VI_STATE_FADE 0x80 // fade + +#define VI_CTRL_ANTIALIAS_MODE_3 0x00300 /* Bit [9:8] anti-alias mode */ +#define VI_CTRL_ANTIALIAS_MODE_2 0x00200 /* Bit [9:8] anti-alias mode */ +#define VI_CTRL_ANTIALIAS_MODE_1 0x00100 /* Bit [9:8] anti-alias mode */ + +#define VI_SCALE_MASK 0xfff //see rcp scale_x/scale_y +#define VI_2_10_FPART_MASK 0x3ff +#define VI_SUBPIXEL_SH 0x10 + +#define BURST(hsync_width, color_width, vsync_width, color_start) \ + (hsync_width | (color_width << 8) | (vsync_width << 16) | (color_start << 20)) +#define WIDTH(v) v +#define VSYNC(v) v +#define HSYNC(duration, leap) (duration | (leap << 16)) +#define LEAP(upper, lower) ((upper << 16) | lower) +#define START(start, end) ((start << 16) | end) + +#define FTOFIX(val, i, f) ((u32)(val * (f32)(1 << f)) & ((1 << (i + f)) - 1)) + +#define F210(val) FTOFIX(val, 2, 10) +#define SCALE(scaleup, off) (F210((1.0f / (f32)scaleup)) | (F210((f32)off) << 16)) + +#define VCURRENT(v) v //seemingly unused +#define ORIGIN(v) v +#define VINTR(v) v +#define HSTART START + +typedef struct +{ + /* 0x0 */ f32 factor; + /* 0x4 */ u16 offset; + /* 0x8 */ u32 scale; +} __OSViScale; + +typedef struct +{ + /* 0x0 */ u16 state; + /* 0x2 */ u16 retraceCount; + /* 0x4 */ void *framep; + /* 0x8 */ OSViMode *modep; + /* 0xC */ u32 control; + /* 0x10 */ OSMesgQueue *msgq; + /* 0x14 */ OSMesg msg; + /* 0x18 */ __OSViScale x; + /* 0x24 */ __OSViScale y; +} __OSViContext; // 0x30 bytes + +void __osViSwapContext(void); +extern __OSViContext *__osViCurr; +extern __OSViContext *__osViNext; +extern u32 __additional_scanline; +__OSViContext *__osViGetCurrentContext(void); +void __osViInit(void); +#endif diff --git a/src/libultra/io/vimgr.c b/src/libultra/io/vimgr.c new file mode 100644 index 0000000..0377d64 --- /dev/null +++ b/src/libultra/io/vimgr.c @@ -0,0 +1,112 @@ +#include +#include +#include +#include "viint.h" +#include "../os/osint.h" + +#define ARRLEN(x) ((s32)(sizeof(x) / sizeof(x[0]))) + +OSDevMgr __osViDevMgr = {0}; +u32 __additional_scanline = 0; +static OSThread viThread; +static unsigned char viThreadStack[OS_VIM_STACKSIZE]; +static OSMesgQueue viEventQueue; +static OSMesg viEventBuf[5]; +static OSIoMesg viRetraceMsg; +static OSIoMesg viCounterMsg; + +static void viMgrMain(void *arg); +void osCreateViManager(OSPri pri) +{ + u32 savedMask; + OSPri oldPri; + OSPri myPri; + + if (!__osViDevMgr.active) { + __osTimerServicesInit(); + __additional_scanline = 0; + osCreateMesgQueue(&viEventQueue, viEventBuf, ARRLEN(viEventBuf)); + viRetraceMsg.hdr.type = OS_MESG_TYPE_VRETRACE; + viRetraceMsg.hdr.pri = OS_MESG_PRI_NORMAL; + viRetraceMsg.hdr.retQueue = NULL; + viCounterMsg.hdr.type = OS_MESG_TYPE_COUNTER; + viCounterMsg.hdr.pri = OS_MESG_PRI_NORMAL; + viCounterMsg.hdr.retQueue = NULL; + osSetEventMesg(OS_EVENT_VI, &viEventQueue, &viRetraceMsg); + osSetEventMesg(OS_EVENT_COUNTER, &viEventQueue, &viCounterMsg); + oldPri = -1; + myPri = osGetThreadPri(NULL); + + if (myPri < pri) { + oldPri = myPri; + osSetThreadPri(NULL, pri); + } + + savedMask = __osDisableInt(); + __osViDevMgr.active = TRUE; + __osViDevMgr.thread = &viThread; + __osViDevMgr.cmdQueue = &viEventQueue; + __osViDevMgr.evtQueue = &viEventQueue; + __osViDevMgr.acsQueue = NULL; + __osViDevMgr.dma = NULL; + __osViDevMgr.edma = NULL; + osCreateThread(&viThread, 0, viMgrMain, &__osViDevMgr, &viThreadStack[OS_VIM_STACKSIZE], pri); + __osViInit(); + osStartThread(&viThread); + __osRestoreInt(savedMask); + + if (oldPri != -1) { + osSetThreadPri(0, oldPri); + } + } +} + +static void viMgrMain(void *arg) { + __OSViContext *vc; + OSDevMgr *dm; + OSIoMesg *mb; + static u16 retrace; + s32 first; + u32 count; + + mb = NULL; + first = 0; + vc = __osViGetCurrentContext(); + retrace = vc->retraceCount; + if (retrace == 0) + retrace = 1; + dm = (OSDevMgr *)arg; + + while (TRUE) { + osRecvMesg(dm->evtQueue, (OSMesg)&mb, OS_MESG_BLOCK); + switch (mb->hdr.type) { + case OS_MESG_TYPE_VRETRACE: + __osViSwapContext(); + retrace--; + + if (retrace == 0) { + vc = __osViGetCurrentContext(); + if (vc->msgq != NULL) + osSendMesg(vc->msgq, vc->msg, OS_MESG_NOBLOCK); + retrace = vc->retraceCount; + } + + __osViIntrCount++; + + if (first) { + count = osGetCount(); + __osCurrentTime = count; + first = 0; + } + + count = __osBaseCounter; + __osBaseCounter = osGetCount(); + count = __osBaseCounter - count; + __osCurrentTime = __osCurrentTime + count; + break; + case OS_MESG_TYPE_COUNTER: + __osTimerInterrupt(); + break; + } + } +} diff --git a/src/libultra/io/virepeatline.c b/src/libultra/io/virepeatline.c new file mode 100644 index 0000000..0eaf66e --- /dev/null +++ b/src/libultra/io/virepeatline.c @@ -0,0 +1,15 @@ +#include +#include "viint.h" + +void osViRepeatLine(u8 active) +{ + register u32 saveMask; + saveMask = __osDisableInt(); + if (active) + { + __osViNext->state |= VI_STATE_REPEATLINE; + } + else + __osViNext->state &= ~VI_STATE_REPEATLINE; + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/visetevent.c b/src/libultra/io/visetevent.c new file mode 100644 index 0000000..589647a --- /dev/null +++ b/src/libultra/io/visetevent.c @@ -0,0 +1,14 @@ +#include +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViSetEvent(OSMesgQueue *mq, OSMesg m, u32 retraceCount) { + register u32 saveMask = __osDisableInt(); + + __osViNext->msgq = mq; + __osViNext->msg = m; + __osViNext->retraceCount = retraceCount; + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/visetmode.c b/src/libultra/io/visetmode.c new file mode 100644 index 0000000..03ddae7 --- /dev/null +++ b/src/libultra/io/visetmode.c @@ -0,0 +1,12 @@ +#include +#include "viint.h" + +void osViSetMode(OSViMode *modep) +{ + register u32 saveMask; + saveMask = __osDisableInt(); + __osViNext->modep = modep; + __osViNext->state = VI_STATE_MODE_UPDATED; + __osViNext->control = __osViNext->modep->comRegs.ctrl; + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/visetspecial.c b/src/libultra/io/visetspecial.c new file mode 100644 index 0000000..e8f90b8 --- /dev/null +++ b/src/libultra/io/visetspecial.c @@ -0,0 +1,48 @@ +#include +#include +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViSetSpecialFeatures(u32 func) { + register u32 saveMask = __osDisableInt(); + + if ((func & OS_VI_GAMMA_ON) != 0) { + __osViNext->control |= VI_CTRL_GAMMA_ON; + } + + if ((func & OS_VI_GAMMA_OFF) != 0) { + __osViNext->control &= ~VI_CTRL_GAMMA_ON; + } + + if ((func & OS_VI_GAMMA_DITHER_ON) != 0) { + __osViNext->control |= VI_CTRL_GAMMA_DITHER_ON; + } + + if ((func & OS_VI_GAMMA_DITHER_OFF) != 0) { + __osViNext->control &= ~VI_CTRL_GAMMA_DITHER_ON; + } + + if ((func & OS_VI_DIVOT_ON) != 0) { + __osViNext->control |= VI_CTRL_DIVOT_ON; + } + + if ((func & OS_VI_DIVOT_OFF) != 0) { + __osViNext->control &= ~VI_CTRL_DIVOT_ON; + } + + if ((func & OS_VI_DITHER_FILTER_ON) != 0) { + __osViNext->control |= VI_CTRL_DITHER_FILTER_ON; + __osViNext->control &= ~VI_CTRL_ANTIALIAS_MASK; + } + + if ((func & OS_VI_DITHER_FILTER_OFF) != 0) { + __osViNext->control &= ~VI_CTRL_DITHER_FILTER_ON; + __osViNext->control |= __osViNext->modep->comRegs.ctrl & VI_CTRL_ANTIALIAS_MASK; + } + + __osViNext->state |= VI_STATE_CTRL_UPDATED; + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/visetxscale.c b/src/libultra/io/visetxscale.c new file mode 100644 index 0000000..328987c --- /dev/null +++ b/src/libultra/io/visetxscale.c @@ -0,0 +1,16 @@ +#include +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViSetXScale(f32 value) { + register u32 nomValue; + register u32 saveMask = __osDisableInt(); + + __osViNext->x.factor = value; + __osViNext->state |= VI_STATE_XSCALE_UPDATED; + nomValue = __osViNext->modep->comRegs.xScale & VI_SCALE_MASK; + __osViNext->x.scale = (u32)(__osViNext->x.factor * nomValue) & VI_SCALE_MASK; + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/visetyscale.c b/src/libultra/io/visetyscale.c new file mode 100644 index 0000000..525e0eb --- /dev/null +++ b/src/libultra/io/visetyscale.c @@ -0,0 +1,13 @@ +#include +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViSetYScale(f32 value) { + register u32 saveMask = __osDisableInt(); + + __osViNext->y.factor = value; + __osViNext->state |= VI_STATE_YSCALE_UPDATED; + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/viswapbuf.c b/src/libultra/io/viswapbuf.c new file mode 100644 index 0000000..ee58f17 --- /dev/null +++ b/src/libultra/io/viswapbuf.c @@ -0,0 +1,10 @@ +#include +#include "viint.h" + +void osViSwapBuffer(void* frameBufPtr) { + u32 saveMask = __osDisableInt(); + + __osViNext->framep = frameBufPtr; + __osViNext->state |= VI_STATE_BUFFER_UPDATED; + __osRestoreInt(saveMask); +} diff --git a/src/libultra/io/viswapcontext.c b/src/libultra/io/viswapcontext.c new file mode 100644 index 0000000..01edcd4 --- /dev/null +++ b/src/libultra/io/viswapcontext.c @@ -0,0 +1,74 @@ +#include +#include +#include "viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void __osViSwapContext() { + register OSViMode *vm; + register __OSViContext *vc; + u32 origin; + u32 hStart; + u32 vStart; + u32 nomValue; + u32 field; + register u32 s2; + + field = 0; + vc = __osViNext; + vm = vc->modep; + + field = IO_READ(VI_CURRENT_REG) & 1; //field num + + s2 = osVirtualToPhysical(vc->framep); + origin = (vm->fldRegs[field].origin) + s2; + if (vc->state & VI_STATE_XSCALE_UPDATED) { + vc->x.scale |= (vm->comRegs.xScale & ~VI_SCALE_MASK); + } else { + vc->x.scale = vm->comRegs.xScale; + } + + if (vc->state & VI_STATE_YSCALE_UPDATED) { + nomValue = vm->fldRegs[field].yScale & VI_SCALE_MASK; + vc->y.scale = vc->y.factor * nomValue; + vc->y.scale |= vm->fldRegs[field].yScale & ~VI_SCALE_MASK; + } else { + vc->y.scale = vm->fldRegs[field].yScale; + } + + vStart = (vm->fldRegs[field].vStart - (__additional_scanline << 0x10)) + __additional_scanline; + hStart = vm->comRegs.hStart; + + if (vc->state & VI_STATE_BLACK) { + hStart = 0; + } + + if (vc->state & VI_STATE_REPEATLINE) { + vc->y.scale = 0; + origin = osVirtualToPhysical(vc->framep); + } + + if (vc->state & VI_STATE_FADE) { + vc->y.scale = (vc->y.offset << VI_SUBPIXEL_SH) & (VI_2_10_FPART_MASK << VI_SUBPIXEL_SH); + origin = osVirtualToPhysical(vc->framep); + } + + IO_WRITE(VI_ORIGIN_REG, origin); + IO_WRITE(VI_WIDTH_REG, vm->comRegs.width); + IO_WRITE(VI_BURST_REG, vm->comRegs.burst); + IO_WRITE(VI_V_SYNC_REG, vm->comRegs.vSync); + IO_WRITE(VI_H_SYNC_REG, vm->comRegs.hSync); + IO_WRITE(VI_LEAP_REG, vm->comRegs.leap); + IO_WRITE(VI_H_START_REG, hStart); + IO_WRITE(VI_V_START_REG, vStart); + IO_WRITE(VI_V_BURST_REG, vm->fldRegs[field].vBurst); + IO_WRITE(VI_INTR_REG, vm->fldRegs[field].vIntr); + IO_WRITE(VI_X_SCALE_REG, vc->x.scale); + IO_WRITE(VI_Y_SCALE_REG, vc->y.scale); + IO_WRITE(VI_CONTROL_REG, vc->control); + + __osViNext = __osViCurr; + __osViCurr = vc; + *__osViNext = *__osViCurr; +} diff --git a/src/libultra/libc/ldiv.c b/src/libultra/libc/ldiv.c new file mode 100644 index 0000000..3a7d57c --- /dev/null +++ b/src/libultra/libc/ldiv.c @@ -0,0 +1,31 @@ +#include + +lldiv_t lldiv(long long num, long long denom) +{ + lldiv_t ret; + + ret.quot = num / denom; + ret.rem = num - denom * ret.quot; + + if (ret.quot < 0 && ret.rem > 0) { + ret.quot++; + ret.rem -= denom; + } + + return ret; +} + +ldiv_t ldiv(long num, long denom) +{ + ldiv_t ret; + + ret.quot = num / denom; + ret.rem = num - denom * ret.quot; + + if (ret.quot < 0 && ret.rem > 0) { + ret.quot++; + ret.rem -= denom; + } + + return ret; +} diff --git a/src/libultra/libc/ll.c b/src/libultra/libc/ll.c new file mode 100644 index 0000000..f05204a --- /dev/null +++ b/src/libultra/libc/ll.c @@ -0,0 +1,47 @@ +#include + +s64 __ull_rshift(u64 l, s64 r) { + return l >> r; +} + +u64 __ull_rem(u64 l, u64 r) { + return l % r; +} + +u64 __ull_div(u64 l, u64 r) { + return l / r; +} + +s64 __ll_lshift(s64 l, s64 r) { + return l << r; +} + +s64 __ll_rem(s64 l, u64 r) { + return l % r; +} + +s64 __ll_div(s64 l, s64 r) { + return l / r; +} + +s64 __ll_mul(s64 l, s64 r) { + return l * r; +} + +void __ull_divremi(u64* quotient, u64* remainder, u64 dividend, u16 divisor) { + *quotient = dividend / divisor; + *remainder = dividend % divisor; +} + +s64 __ll_mod(s64 l, s64 r) { + s64 remainder = l % r; + + if (((remainder < 0) && (r > 0)) || ((remainder > 0) && (r < 0))) { + remainder += r; + } + return remainder; +} + +s64 __ll_rshift(s64 l, s64 r) { + return l >> r; +} diff --git a/src/libultra/libc/llcvt.c b/src/libultra/libc/llcvt.c new file mode 100644 index 0000000..2c423dd --- /dev/null +++ b/src/libultra/libc/llcvt.c @@ -0,0 +1,31 @@ +long long __d_to_ll(double d) { + return d; +} + +long long __f_to_ll(float f) { + return f; +} + +unsigned long long __d_to_ull(double d) { + return d; +} + +unsigned long long __f_to_ull(float f) { + return f; +} + +double __ll_to_d(long long s) { + return s; +} + +float __ll_to_f(long long s) { + return s; +} + +double __ull_to_d(unsigned long long u) { + return u; +} + +float __ull_to_f(unsigned long long u) { + return u; +} diff --git a/src/libultra/libc/sprintf.c b/src/libultra/libc/sprintf.c new file mode 100644 index 0000000..fb0eb6e --- /dev/null +++ b/src/libultra/libc/sprintf.c @@ -0,0 +1,25 @@ +#include +#include "stdarg.h" + +typedef unsigned long uintptr_t; + +int _Printf(char *(*prout)(char *, const char *, size_t), char *dst, const char *fmt, va_list args); + +void* proutSprintf(void* dst, const char* fmt, size_t size) { + return (void*)((uintptr_t)memcpy(dst, fmt, size) + size); +} + +int sprintf(char* dst, char* fmt, ...) { + int ans; + va_list args; + va_start(args, fmt); + + ans = _Printf((void*)&proutSprintf, dst, fmt, args); + if (ans > -1) { + dst[ans] = 0; + } + + va_end(args); + + return ans; +} diff --git a/src/libultra/libc/string.c b/src/libultra/libc/string.c new file mode 100644 index 0000000..5f085f6 --- /dev/null +++ b/src/libultra/libc/string.c @@ -0,0 +1,38 @@ +#include "string.h" + +const char* strchr(const char* s, int c) { + const unsigned char ch = c; + + while (*s != ch) { + if (*s == '\0') { + return NULL; + } + s++; + } + + return s; +} + +size_t strlen(const char* s) { + const char* sc = s; + + while (*sc != '\0') { + sc++; + } + + return (size_t)(sc - s); +} + +void* memcpy(void* s1, const void* s2, size_t n) { + unsigned char* su1 = (unsigned char*)s1; + const unsigned char* su2 = (const unsigned char*)s2; + + while (n > 0) { + *su1 = *su2; + su1++; + su2++; + n--; + } + + return s1; +} diff --git a/src/libultra/libc/syncprintf.c b/src/libultra/libc/syncprintf.c new file mode 100644 index 0000000..0dc0ce9 --- /dev/null +++ b/src/libultra/libc/syncprintf.c @@ -0,0 +1,13 @@ +#include + +void osSyncPrintf(const char *fmt, ...) +{ + int ans; + va_list ap; + // these functions intentionally left blank. ifdeffed out in rom release +} +void rmonPrintf(const char *fmt, ...) +{ + int ans; + va_list ap; +} diff --git a/src/libultra/libc/xldtob.c b/src/libultra/libc/xldtob.c new file mode 100644 index 0000000..b032e57 --- /dev/null +++ b/src/libultra/libc/xldtob.c @@ -0,0 +1,311 @@ +#include "stdlib.h" +#include "string.h" +#include "xstdio.h" + +// TODO: these come from headers +#ident "$Revision: 1.23 $" +#ident "$Revision: 1.34 $" +#ident "$Revision: 1.5 $" + +#define BUFF_LEN 0x20 + +static s16 _Ldunscale(s16* pex, _Pft* px); +static void _Genld(_Pft* px, char code, u8* p, s16 nsig, s16 xexp); + +static const double pows[] = {10e0L, 10e1L, 10e3L, 10e7L, 10e15L, 10e31L, 10e63L, 10e127L, 10e255L}; + +// float properties +#define _D0 0 +#define _DBIAS 0x3ff +#define _DLONG 1 +#define _DOFF 4 +#define _FBIAS 0x7e +#define _FOFF 7 +#define _FRND 1 +#define _LBIAS 0x3ffe +#define _LOFF 15 +// integer properties +#define _C2 1 +#define _CSIGN 1 +#define _ILONG 0 +#define _MBMAX 8 +#define NAN 2 +#define INF 1 +#define FINITE -1 +#define _DFRAC ((1 << _DOFF) - 1) +#define _DMASK (0x7fff & ~_DFRAC) +#define _DMAX ((1 << (15 - _DOFF)) - 1) +#define _DNAN (0x8000 | _DMAX << _DOFF | 1 << (_DOFF - 1)) +#define _DSIGN 0x8000 +#define _D1 1 // big-endian order +#define _D2 2 +#define _D3 3 + +#define ALIGN(s, align) (((u32)(s) + ((align)-1)) & ~((align)-1)) + +void _Ldtob(_Pft* px, char code) { + char buff[BUFF_LEN]; + char *p; + f64 ldval; + s16 err; + s16 nsig; + s16 xexp; + + // char unused[0x4]; + p = buff; + ldval = px->v.ld; + + if (px->prec < 0) { + px->prec = 6; + } else if (px->prec == 0 && (code == 'g' || code == 'G')) { + px->prec = 1; + } + + err = _Ldunscale(&xexp, px); + if (err > 0) { + memcpy(px->s, err == 2 ? "NaN" : "Inf", px->n1 = 3); + return; + } else if (err == 0) { + nsig = 0; + xexp = 0; + } else { + int i; + int n; + + if (ldval < 0) { + ldval = -ldval; + } + + // what + if ((xexp = xexp * 30103 / 100000 - 4) < 0) { + n = ALIGN(-xexp, 4), xexp = -n; + + for (i = 0; n > 0; n >>= 1, i++) { + if (n & 1) { + ldval *= pows[i]; + } + } + } else if (xexp > 0) { + f64 factor = 1; + + xexp &= ~3; + + for (n = xexp, i = 0; n > 0; n >>= 1, i++) { + if (n & 1) { + factor *= pows[i]; + } + } + + ldval /= factor; + } + { + int gen = px->prec + ((code == 'f') ? 10 + xexp : 6); + + if (gen > 0x13) { + gen = 0x13; + } + + for (*p++ = '0'; gen > 0 && 0 < ldval; p += 8) { + int j; + int lo = ldval; + + if ((gen -= 8) > 0) { + ldval = (ldval - lo) * 1e8; + } + + for (p += 8, j = 8; lo > 0 && --j >= 0;) { + ldiv_t qr = ldiv(lo, 10); + *--p = qr.rem + '0', lo = qr.quot; + } + + while (--j >= 0) { + *--p = '0'; + } + } + + gen = p - &buff[1]; + + for (p = &buff[1], xexp += 7; *p == '0'; p++) { + --gen, --xexp; + } + + nsig = px->prec + ((code == 'f') ? xexp + 1 : ((code == 'e' || code == 'E') ? 1 : 0)); + + if (gen < nsig) { + nsig = gen; + } + + if (nsig > 0) { + char drop = nsig < gen && '5' <= p[nsig] ? '9' : '0'; + int n; + + for (n = nsig; p[--n] == drop;) { + --nsig; + } + + if (drop == '9') { + ++p[n]; + } + + if (n < 0) { + --p, ++nsig, ++xexp; + } + } + } + } + + _Genld(px, code, p, nsig, xexp); +} + +s16 _Ldunscale(s16* pex, _Pft* px) { + u16* ps = px; + s16 xchar = (ps[_D0] & _DMASK) >> _DOFF; + + + if (xchar == _DMAX) { + *pex = 0; + + return (ps[_D0] & _DFRAC) || ps[_D1] || ps[_D2] || ps[_D3] ? 2 : 1; + } else if (xchar > 0) { + ps[_D0] = (ps[_D0] & ~_DMASK) | 0x3FF0; + *pex = xchar - 0x3FE; + return -1; + } else if (xchar < 0) { + return 2; + } else { + *pex = 0; + return 0; + } +} + +void _Genld(_Pft* px, char code, u8* p, s16 nsig, s16 xexp) { + const unsigned char point = '.'; + + if (nsig <= 0) { + nsig = 1, p = "0"; // memes + } + + if (code == 'f' || (code == 'g' || code == 'G') && xexp >= -4 && xexp < px->prec) { + xexp += 1; + if (code != 'f') { + if (((px->flags & 8) == 0) && nsig < px->prec) { + px->prec = nsig; + } + + px->prec -= xexp; + if (px->prec < 0) { + px->prec = 0; + } + } + + if (xexp <= 0) { + px->s[px->n1++] = '0'; + + if (px->prec > 0 || (px->flags & 8)) { + px->s[px->n1++] = point; + } + + if (px->prec < -xexp) { + xexp = -px->prec; + } + + px->nz1 = -xexp; + px->prec += xexp; + + if (px->prec < nsig) { + nsig = px->prec; + } + + memcpy(&px->s[px->n1], p, px->n2 = nsig); // , memes (this one is insane) + px->nz2 = px->prec - nsig; + } else if (nsig < xexp) { + memcpy(&px->s[px->n1], p, nsig); + px->n1 += nsig; + px->nz1 = xexp - nsig; + if (px->prec > 0 || (px->flags & 8)) { + px->s[px->n1] = point; + px->n2 += 1; + } + + px->nz2 = px->prec; + } else { + memcpy(&px->s[px->n1], p, xexp); + px->n1 += xexp; + nsig -= xexp; + + if (px->prec > 0 || (px->flags & 8)) { + px->s[px->n1++] = point; + } + + if (px->prec < nsig) { + nsig = px->prec; + } + + memcpy(&px->s[px->n1], &p[xexp], nsig); + px->n1 += nsig; + px->nz1 = px->prec - nsig; + } + } else { + if (code == 'g' || code == 'G') { + if (nsig < px->prec) { + px->prec = nsig; + } + + if (--px->prec < 0) { + px->prec = 0; + } + + if (code == 'g') { + code = 'e'; + } else { + code = 'E'; + } + } + + px->s[px->n1++] = *p++; + + if (px->prec > 0 || (px->flags & 8)) { + px->s[px->n1++] = point; + } + + if (px->prec > 0) { + if (px->prec < --nsig) { + nsig = px->prec; + } + + memcpy(&px->s[px->n1], p, nsig); + px->n1 += nsig; + px->nz1 = px->prec - nsig; + } + + p = &px->s[px->n1]; + *p++ = code; + + if (xexp >= 0) { + *p++ = '+'; + } else { + *p++ = '-'; + xexp = -xexp; + } + + if (xexp >= 100) { + if (xexp >= 1000) { + *p++ = (xexp / 1000) + '0', xexp %= 1000; // , memes + } + *p++ = (xexp / 100) + '0', xexp %= 100; // , memes + } + *p++ = (xexp / 10) + '0', xexp %= 10; // , memes + + *p++ = xexp + '0'; + px->n2 = (size_t)p - ((size_t)px->s + px->n1); + } + + if ((px->flags & 0x14) == 0x10) { + s32 n = px->n0 + px->n1 + px->nz1 + px->n2 + px->nz2; + + if (n < px->width) { + px->nz0 = px->width - n; + } + } +} + diff --git a/src/libultra/libc/xlitob.c b/src/libultra/libc/xlitob.c new file mode 100644 index 0000000..f297df4 --- /dev/null +++ b/src/libultra/libc/xlitob.c @@ -0,0 +1,64 @@ +#include "stdlib.h" +#include "string.h" +#include "xstdio.h" + +// TODO: these come from headers +#ident "$Revision: 1.34 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.23 $" + +#define BUFF_LEN 0x18 + +static char ldigs[] = "0123456789abcdef"; +static char udigs[] = "0123456789ABCDEF"; + +void _Litob(_Pft *args, char type) { + char buff[BUFF_LEN]; + const char *digs; + s32 base; + s32 i; + unsigned long long ullval; + + if (type == 'X') { + digs = udigs; + } else { + digs = ldigs; + } + + base = (type == 'o') ? 8 : ((type != 'x' && type != 'X') ? 10 : 16); + i = BUFF_LEN; + ullval = args->v.ll; + + if ((type == 'd' || type == 'i') && args->v.ll < 0) { + ullval = -ullval; + } + + if (ullval != 0 || args->prec != 0) { + buff[--i] = digs[ullval % base]; + } + + args->v.ll = ullval / base; + + while (args->v.ll > 0 && i > 0) { + lldiv_t qr = lldiv(args->v.ll, base); + + args->v.ll = qr.quot; + buff[--i] = digs[qr.rem]; + } + + args->n1 = BUFF_LEN - i; + + memcpy(args->s, buff + i, args->n1); + + if (args->n1 < args->prec) { + args->nz0 = args->prec - args->n1; + } + + if (args->prec < 0 && (args->flags & (FLAGS_ZERO | FLAGS_MINUS)) == FLAGS_ZERO) { + i = args->width - args->n0 - args->nz0 - args->n1; + + if (i > 0) { + args->nz0 += i; + } + } +} diff --git a/src/libultra/libc/xprintf.c b/src/libultra/libc/xprintf.c new file mode 100644 index 0000000..893ca31 --- /dev/null +++ b/src/libultra/libc/xprintf.c @@ -0,0 +1,244 @@ +#include +#include +#include "xstdio.h" + +#define isdigit(x) ((x >= '0' && x <= '9')) +#define LDSIGN(x) (((unsigned short *)&(x))[0] & 0x8000) + +#define ATOI(dst, src) \ + for (dst = 0; isdigit(*src); ++src) \ + { \ + if (dst < 999) \ + dst = dst * 10 + *src - '0'; \ + } + +#define MAX_PAD ((sizeof(spaces) - 1)) +#define PAD(s, n) \ + if (0 < (n)) \ + { \ + int i, j = (n); \ + for (; 0 < j; j -= i) \ + { \ + i = MAX_PAD < (unsigned int)j ? (int)MAX_PAD : j; \ + PUT(s, i); \ + } \ + } +#define PUT(s, n) \ + if (0 < (n)) \ + { \ + if ((arg = (*prout)(arg, s, n)) != NULL) \ + x.size += (n); \ + else \ + return x.size; \ + } +static char spaces[] = " "; +static char zeroes[] = "00000000000000000000000000000000"; + +static void _Putfld(printf_struct *pf, va_list *pap, char code, char *ac); +int _Printf(outfun prout, char *arg, const char *fmt, va_list args) +{ + printf_struct x; + const char *s; + char c; + const char *t; + static const char fchar[6] = " +-#0"; + static const int fbit[6] = {FLAGS_SPACE, FLAGS_PLUS, FLAGS_MINUS, FLAGS_HASH, FLAGS_ZERO, 0}; + char ac[32]; + x.size = 0; + for (;;) + { + s = fmt; + for (c = *s; c != 0 && c != '%';) + { + + c = *++s; + } + PUT(fmt, s - fmt); + if (c == 0) + return x.size; + fmt = ++s; + for (x.flags = 0; (t = strchr(fchar, *s)) != NULL; s++) + { + x.flags |= fbit[t - fchar]; + } + if (*s == '*') + { + x.width = va_arg(args, int); + if (x.width < 0) + { + x.width = -x.width; + x.flags |= FLAGS_MINUS; + } + s++; + } + else + { + ATOI(x.width, s); + } + if (*s != '.') + x.precision = -1; + else if (*++s == '*') + { + x.precision = va_arg(args, int); + ++s; + } + else + { + ATOI(x.precision, s); + } + x.length = strchr("hlL", *s) ? *s++ : '\0'; + if (x.length == 'l' && *s == 'l') + { + x.length = 'L'; + ++s; + } + _Putfld(&x, &args, *s, ac); + x.width -= x.n0 + x.num_leading_zeros + x.part2_len + x.num_mid_zeros + x.part3_len + x.num_trailing_zeros; + if (!(x.flags & FLAGS_MINUS)) + PAD(spaces, x.width); + PUT(ac, x.n0); + PAD(zeroes, x.num_leading_zeros); + PUT(x.buff, x.part2_len); + PAD(zeroes, x.num_mid_zeros); + PUT(x.buff + x.part2_len, x.part3_len); + PAD(zeroes, x.num_trailing_zeros); + if (x.flags & FLAGS_MINUS) + PAD(spaces, x.width); + fmt = s + 1; + } + return 0; +} + +static void _Putfld(printf_struct *x, va_list *args, char type, char *buff) +{ + x->n0 = x->num_leading_zeros = x->part2_len = x->num_mid_zeros = x->part3_len = + x->num_trailing_zeros = 0; + + switch (type) + { + case 'c': + buff[x->n0++] = va_arg(*args, int); + break; + + case 'd': + case 'i': + if (x->length == 'l') + x->value.s64 = va_arg(*args, int); + else if (x->length == 'L') + x->value.s64 = va_arg(*args, s64); + else + x->value.s64 = va_arg(*args, int); + + if (x->length == 'h') + { + x->value.s64 = (s16)x->value.s64; + } + + if (x->value.s64 < 0) + { + buff[x->n0++] = '-'; + } + else if (x->flags & FLAGS_PLUS) + { + buff[x->n0++] = '+'; + } + else if (x->flags & FLAGS_SPACE) + { + buff[x->n0++] = ' '; + } + + x->buff = (char *)&buff[x->n0]; + + _Litob(x, type); + break; + + case 'x': + case 'X': + case 'u': + case 'o': + if (x->length == 'l') + { + x->value.s64 = va_arg(*args, int); + } + else if (x->length == 'L') + { + x->value.s64 = va_arg(*args, s64); + } + else + { + x->value.s64 = va_arg(*args, int); + } + + if (x->length == 'h') + { + x->value.s64 = (u16)x->value.s64; + } + else if (x->length == 0) + { + x->value.s64 = (unsigned int)x->value.s64; + } + + if (x->flags & FLAGS_HASH) + { + buff[x->n0++] = '0'; + if (type == 'x' || type == 'X') + { + + buff[x->n0++] = type; + } + } + x->buff = (char *)&buff[x->n0]; + _Litob(x, type); + break; + + case 'e': + case 'f': + case 'g': + case 'E': + case 'G': + //... okay? + x->value.f64 = x->length == 'L' ? va_arg(*args, f64) : va_arg(*args, f64); + + if (LDSIGN(x->value.f64)) + buff[x->n0++] = '-'; + else if (x->flags & FLAGS_PLUS) + buff[x->n0++] = '+'; + else if (x->flags & FLAGS_SPACE) + buff[x->n0++] = ' '; + + x->buff = (char *)&buff[x->n0]; + _Ldtob(x, type); + break; + + case 'n': + if (x->length == 'h') + *(va_arg(*args, u16 *)) = x->size; + else if (x->length == 'l') + *va_arg(*args, unsigned int *) = x->size; + else if (x->length == 'L') + *va_arg(*args, u64 *) = x->size; + else + *va_arg(*args, unsigned int *) = x->size; + break; + + case 'p': + x->value.s64 = (long)va_arg(*args, void *); + x->buff = (char *)&buff[x->n0]; + _Litob(x, 'x'); + break; + + case 's': + x->buff = va_arg(*args, char *); + x->part2_len = strlen(x->buff); + if (x->precision >= 0 && x->part2_len > x->precision) + x->part2_len = x->precision; + break; + case '%': + //this doesn't match in -g because of regalloc issues?? + buff[x->n0++] = '%'; + break; + default: + buff[x->n0++] = type; + break; + } +} diff --git a/src/libultra/os/afterprenmi.c b/src/libultra/os/afterprenmi.c new file mode 100644 index 0000000..234d4b7 --- /dev/null +++ b/src/libultra/os/afterprenmi.c @@ -0,0 +1,5 @@ +#include + +s32 osAfterPreNMI(void) { + return __osSpSetPc(0); +} diff --git a/src/libultra/os/createmesgqueue.c b/src/libultra/os/createmesgqueue.c new file mode 100644 index 0000000..2649739 --- /dev/null +++ b/src/libultra/os/createmesgqueue.c @@ -0,0 +1,13 @@ +#include + +extern void *__osThreadTail; + +void osCreateMesgQueue(OSMesgQueue *mq, OSMesg *msg, s32 msgCount) +{ + mq->mtqueue = (OSThread *)&__osThreadTail; + mq->fullqueue = (OSThread *)&__osThreadTail; + mq->validCount = 0; + mq->first = 0; + mq->msgCount = msgCount; + mq->msg = msg; +} diff --git a/src/libultra/os/createthread.c b/src/libultra/os/createthread.c new file mode 100644 index 0000000..7059a40 --- /dev/null +++ b/src/libultra/os/createthread.c @@ -0,0 +1,30 @@ +#include + +void __osCleanupThread(void); + +extern OSThread *__osActiveQueue; + +void osCreateThread(OSThread *t, OSId id, void (*entry)(void *), void *arg, void *sp, OSPri p) +{ + register u32 saveMask; + OSIntMask mask; + t->id = id; + t->priority = p; + t->next = NULL; + t->queue = NULL; + t->context.pc = (u32)entry; + t->context.a0 = (u64)arg; + t->context.sp = (u64)sp - 16; + t->context.ra = (u64)__osCleanupThread; + mask = OS_IM_ALL; + t->context.sr = SR_IMASK | SR_EXL | SR_IE; + t->context.rcp = (mask & RCP_IMASK) >> RCP_IMASKSHIFT; + t->context.fpcsr = (u32)(FPCSR_FS | FPCSR_EV); + t->fp = 0; + t->state = OS_STATE_STOPPED; + t->flags = 0; + saveMask = __osDisableInt(); + t->tlnext = __osActiveQueue; + __osActiveQueue = t; + __osRestoreInt(saveMask); +} diff --git a/src/libultra/os/dequeuethread.c b/src/libultra/os/dequeuethread.c new file mode 100644 index 0000000..df3d1f8 --- /dev/null +++ b/src/libultra/os/dequeuethread.c @@ -0,0 +1,15 @@ +#include + +void __osDequeueThread(OSThread** queue, OSThread* thread) { + register OSThread** a2 = queue; + register OSThread* a3 = *a2; + + while (a3 != NULL) { + if (a3 == thread) { + *a2 = thread->next; + return; + } + a2 = &a3->next; + a3 = *a2; + } +} diff --git a/src/libultra/os/destroythread.c b/src/libultra/os/destroythread.c new file mode 100644 index 0000000..712d6a6 --- /dev/null +++ b/src/libultra/os/destroythread.c @@ -0,0 +1,37 @@ +#include + +extern OSThread *__osRunningThread; +extern OSThread *__osActiveQueue; + +void osDestroyThread(OSThread* thread) { + register u32 prevInt = __osDisableInt(); + register OSThread* s1; + register OSThread* s2; + + if (thread == NULL) { + thread = __osRunningThread; + + } else if (thread->state != OS_STATE_STOPPED) { + __osDequeueThread(thread->queue, thread); + } + + if (__osActiveQueue == thread) { + __osActiveQueue = __osActiveQueue->tlnext; + } else { + s1 = __osActiveQueue; + while (s1->priority != OS_PRIORITY_THREADTAIL) { + s2 = s1->tlnext; + if (s2 == thread) { + s1->tlnext = thread->tlnext; + break; + } + s1 = s2; + } + } + + if (thread == __osRunningThread) { + __osDispatchThread(); + } + + __osRestoreInt(prevInt); +} diff --git a/src/libultra/os/epilinkhandle.c b/src/libultra/os/epilinkhandle.c new file mode 100644 index 0000000..6872c1f --- /dev/null +++ b/src/libultra/os/epilinkhandle.c @@ -0,0 +1,10 @@ +#include + +s32 osEPiLinkHandle(OSPiHandle *EPiHandle) +{ + u32 saveMask = __osDisableInt(); + EPiHandle->next = __osPiTable; + __osPiTable = EPiHandle; + __osRestoreInt(saveMask); + return 0; +} diff --git a/src/libultra/os/getactivequeue.c b/src/libultra/os/getactivequeue.c new file mode 100644 index 0000000..4175e7d --- /dev/null +++ b/src/libultra/os/getactivequeue.c @@ -0,0 +1,6 @@ +#include "PR/os_internal.h" +#include "osint.h" + +OSThread *__osGetActiveQueue(void) { + return __osActiveQueue; +} diff --git a/src/libultra/os/getmemsize.c b/src/libultra/os/getmemsize.c new file mode 100644 index 0000000..f1f4b48 --- /dev/null +++ b/src/libultra/os/getmemsize.c @@ -0,0 +1,31 @@ +#include + +#define STEP 0x100000 + +u32 osGetMemSize(void) { + u32* ptr; + u32 size = 0x400000; + u32 data0; + u32 data1; + + while (size < 0x800000) { + ptr = (u32*)(0xA0000000 + size); + + data0 = *ptr; + data1 = ptr[STEP / 4 - 1]; + + *ptr ^= ~0; + ptr[STEP / 4 - 1] ^= ~0; + + if ((*ptr != (data0 ^ ~0)) || (ptr[STEP / 4 - 1] != (data1 ^ ~0))) { + return size; + } + + *ptr = data0; + ptr[STEP / 4 - 1] = data1; + + size += STEP; + } + + return size; +} diff --git a/src/libultra/os/getthreadpri.c b/src/libultra/os/getthreadpri.c new file mode 100644 index 0000000..21a6dda --- /dev/null +++ b/src/libultra/os/getthreadpri.c @@ -0,0 +1,9 @@ +#include + +extern OSThread *__osRunningThread; +OSPri osGetThreadPri(OSThread *thread) +{ + if (thread == NULL) + thread = __osRunningThread; + return thread->priority; +} diff --git a/src/libultra/os/gettime.c b/src/libultra/os/gettime.c new file mode 100644 index 0000000..de235ed --- /dev/null +++ b/src/libultra/os/gettime.c @@ -0,0 +1,18 @@ +#include + +extern u32 __osBaseCounter; +extern OSTime __osCurrentTime; + +OSTime osGetTime(void) { + u32 count; + u32 base; + u64 t; + register u32 prevInt = __osDisableInt(); + + count = osGetCount(); + base = count - __osBaseCounter; + t = __osCurrentTime; + __osRestoreInt(prevInt); + + return base + t; +} diff --git a/src/libultra/os/initialize.c b/src/libultra/os/initialize.c new file mode 100644 index 0000000..a1cf36e --- /dev/null +++ b/src/libultra/os/initialize.c @@ -0,0 +1,99 @@ +#include + +#define RESETTYPE_COLD 0 +#define RESETTYPE_WARM 1 + +typedef struct { + unsigned int inst1; + unsigned int inst2; + unsigned int inst3; + unsigned int inst4; +} __osExceptionVector; + +extern __osExceptionVector __osExceptionPreamble; +extern s32 osAppNMIBuffer[]; + +extern u32 __osFinalRom; + +OSTime osClockRate = 62500000; + +s32 osViClock = VI_NTSC_CLOCK; + +u32 __osShutdown = 0; +u32 __osGlobalIntMask = OS_IM_ALL; + +u32 var8005cf74 = 0; +u32 var8005cf78 = 0; +u32 var8005cf7c = 0; + +OSPiHandle *__osCartRomInit(void); + +void osInitialize(void) +{ + u32 pifdata; + u32 unused = 0; + + __osFinalRom = TRUE; + __osSetSR(__osGetSR() | SR_CU1); + __osSetFpcCsr(FPCSR_FS | FPCSR_EV); + + while (__osSiRawReadIo(PIF_RAM_END - 3, &pifdata)); + + while (__osSiRawWriteIo(PIF_RAM_END - 3, pifdata | 8)); + + *(__osExceptionVector *)UT_VEC = __osExceptionPreamble; + *(__osExceptionVector *)XUT_VEC = __osExceptionPreamble; + *(__osExceptionVector *)ECC_VEC = __osExceptionPreamble; + *(__osExceptionVector *)E_VEC = __osExceptionPreamble; + + osWritebackDCache((void *)UT_VEC, E_VEC - UT_VEC + sizeof(__osExceptionVector)); + osInvalICache((void *)UT_VEC, E_VEC - UT_VEC + sizeof(__osExceptionVector)); + __osCartRomInit(); + osUnmapTLBAll(); + osMapTLBRdb(); + + osClockRate = osClockRate * 3 / 4; + + if (osResetType == RESETTYPE_COLD) { + bzero(&osAppNMIBuffer, 0x40); + } + + if (osTvType == OS_TV_PAL) { + osViClock = VI_PAL_CLOCK; + } else if (osTvType == OS_TV_MPAL) { + osViClock = VI_MPAL_CLOCK; + } else { + osViClock = VI_NTSC_CLOCK; + } + + if (__osGetCause() & CAUSE_IP5) { + while (1); + } + + *(u32 *)PHYS_TO_K1(AI_CONTROL_REG) = 1; + *(u32 *)PHYS_TO_K1(AI_DACRATE_REG) = 0x3fff; + *(u32 *)PHYS_TO_K1(AI_BITRATE_REG) = 0xf; +} + +extern OSPiHandle CartRomHandle; +extern OSPiHandle LeoDiskHandle; + +/** + * According to Nintendo's SDK this function should return a pointer to an + * OSPiHandle, but the function only matches if the return statement is omitted. + * By chance the value in v0 happens to be &CartRomHandle anyway. + */ +OSPiHandle *__osCartRomInit(void) +{ + CartRomHandle.type = DEVICE_TYPE_INIT; + CartRomHandle.latency = IO_READ(0xa4600014); + CartRomHandle.pulse = IO_READ(0xa4600018); + CartRomHandle.pageSize = IO_READ(0xa460001c); + CartRomHandle.relDuration = IO_READ(0xa4600020); + + LeoDiskHandle.type = DEVICE_TYPE_INIT; + LeoDiskHandle.latency = IO_READ(0xa4600024); + LeoDiskHandle.pulse = IO_READ(0xa4600028); + LeoDiskHandle.pageSize = IO_READ(0xa460002c); + LeoDiskHandle.relDuration = IO_READ(0xa4600030); +} diff --git a/src/libultra/os/jammesg.c b/src/libultra/os/jammesg.c new file mode 100644 index 0000000..894c15c --- /dev/null +++ b/src/libultra/os/jammesg.c @@ -0,0 +1,31 @@ +#include + +extern OSThread *__osRunningThread; + +s32 osJamMesg(OSMesgQueue *mq, OSMesg msg, s32 flag) +{ + register u32 saveMask = __osDisableInt(); + while (mq->validCount >= mq->msgCount) + { + if (flag == OS_MESG_BLOCK) + { + __osRunningThread->state = OS_STATE_WAITING; + __osEnqueueAndYield(&mq->fullqueue); + } + else + { + __osRestoreInt(saveMask); + return -1; + } + } + + mq->first = (mq->first + mq->msgCount - 1) % mq->msgCount; + mq->msg[mq->first] = msg; + mq->validCount++; + if (mq->mtqueue->next != NULL) + { + osStartThread(__osPopThread(&mq->mtqueue)); + } + __osRestoreInt(saveMask); + return 0; +} diff --git a/src/libultra/os/osint.h b/src/libultra/os/osint.h new file mode 100644 index 0000000..7a4c0cd --- /dev/null +++ b/src/libultra/os/osint.h @@ -0,0 +1,55 @@ +#ifndef _OSINT_H +#define _OSINT_H +#include "PR/os_internal.h" +typedef struct __OSEventState +{ + OSMesgQueue *messageQueue; + OSMesg message; +} __OSEventState; +extern struct __osThreadTail +{ + OSThread *next; + OSPri priority; +} __osThreadTail; + +//maybe should be in exceptasm.h? +extern void __osEnqueueAndYield(OSThread **); +extern void __osDequeueThread(OSThread **, OSThread *); +extern void __osEnqueueThread(OSThread **, OSThread *); +extern OSThread *__osPopThread(OSThread **); +extern void __osDispatchThread(void); +extern void __osCleanupThread(void); + +extern void __osSetTimerIntr(OSTime); +extern OSTime __osInsertTimer(OSTimer *); +extern void __osTimerInterrupt(void); +extern u32 __osProbeTLB(void *); +extern int __osSpDeviceBusy(void); + +extern OSThread *__osRunningThread; +extern OSThread *__osActiveQueue; +extern OSThread *__osFaultedThread; +extern OSThread *__osRunQueue; + +extern OSTimer *__osTimerList; +extern OSTimer __osBaseTimer; +extern OSTime __osCurrentTime; +extern u32 __osBaseCounter; +extern u32 __osViIntrCount; +extern u32 __osTimerCounter; +extern u32 __osShutdown; + +extern __OSEventState __osEventStateTab[OS_NUM_EVENTS]; + + +//not sure if this should be here +extern s32 osViClock; +extern void __osTimerServicesInit(void); +extern s32 __osAiDeviceBusy(void); +extern int __osDpDeviceBusy(void); + +#ifndef _FINALROM +extern void* __printfunc; +#endif + +#endif diff --git a/src/libultra/os/osRecvMesg.c b/src/libultra/os/recvmesg.c similarity index 100% rename from src/libultra/os/osRecvMesg.c rename to src/libultra/os/recvmesg.c diff --git a/src/libultra/os/resetglobalintmask.c b/src/libultra/os/resetglobalintmask.c new file mode 100644 index 0000000..9ca3140 --- /dev/null +++ b/src/libultra/os/resetglobalintmask.c @@ -0,0 +1,12 @@ +#include +#include "PR/os_internal.h" + +extern u32 __osGlobalIntMask; + +void __osResetGlobalIntMask(OSHWIntr mask) { + register u32 saveMask = __osDisableInt(); + + __osGlobalIntMask &= ~(mask & ~OS_IM_RCP); + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/os/osSendMesg.c b/src/libultra/os/sendmesg.c similarity index 100% rename from src/libultra/os/osSendMesg.c rename to src/libultra/os/sendmesg.c diff --git a/src/libultra/os/seteventmesg.c b/src/libultra/os/seteventmesg.c new file mode 100644 index 0000000..701eea2 --- /dev/null +++ b/src/libultra/os/seteventmesg.c @@ -0,0 +1,23 @@ +#include +#include "ultra64/internal.h" + +extern __OSEventState __osEventStateTab[OS_NUM_EVENTS]; + +extern u32 __osPreNMI; +extern u32 __osShutdown; + +void osSetEventMesg(OSEvent e, OSMesgQueue* mq, OSMesg msg) { + register u32 prevInt = __osDisableInt(); + __OSEventState* msgs = &__osEventStateTab[e]; + + msgs->queue = mq; + msgs->msg = msg; + + if (e == OS_EVENT_PRENMI) { + if (__osShutdown && !__osPreNMI) { + osSendMesg(mq, msg, OS_MESG_NOBLOCK); + } + __osPreNMI = true; + } + __osRestoreInt(prevInt); +} diff --git a/src/libultra/os/setglobalintmask.c b/src/libultra/os/setglobalintmask.c new file mode 100644 index 0000000..18ebd5a --- /dev/null +++ b/src/libultra/os/setglobalintmask.c @@ -0,0 +1,11 @@ +#include "PR/os_internal.h" + +extern u32 __osGlobalIntMask; + +void __osSetGlobalIntMask(OSHWIntr mask) { + register u32 saveMask = __osDisableInt(); + + __osGlobalIntMask |= mask; + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/os/sethwinterrupt.c b/src/libultra/os/sethwinterrupt.c new file mode 100644 index 0000000..0fc9d30 --- /dev/null +++ b/src/libultra/os/sethwinterrupt.c @@ -0,0 +1,16 @@ +#include "PR/os_internal.h" + +struct __osHwInt { + s32 (*handler)(void); + void *stackEnd; +}; + +extern struct __osHwInt __osHwIntTable[]; + +void __osSetHWIntrRoutine(OSHWIntr interrupt, s32 (*handler)(void), void *stackEnd) { + register u32 saveMask= __osDisableInt(); + + __osHwIntTable[interrupt].handler = handler; + __osHwIntTable[interrupt].stackEnd = stackEnd; + __osRestoreInt(saveMask); +} diff --git a/src/libultra/os/setthreadpri.c b/src/libultra/os/setthreadpri.c new file mode 100644 index 0000000..870c1b3 --- /dev/null +++ b/src/libultra/os/setthreadpri.c @@ -0,0 +1,26 @@ +#include + +extern OSThread* __osRunningThread; +extern OSThread* __osRunQueue; + +void osSetThreadPri(OSThread *t, OSPri pri) +{ + register u32 saveMask = __osDisableInt(); + if (t == NULL) + t = __osRunningThread; + if (t->priority != pri) + { + t->priority = pri; + if (t != __osRunningThread && t->state != OS_STATE_STOPPED) + { + __osDequeueThread(t->queue, t); + __osEnqueueThread(t->queue, t); + } + if (__osRunningThread->priority < __osRunQueue->priority) + { + __osRunningThread->state = OS_STATE_RUNNABLE; + __osEnqueueAndYield(&__osRunQueue); + } + } + __osRestoreInt(saveMask); +} diff --git a/src/libultra/os/settime.c b/src/libultra/os/settime.c new file mode 100644 index 0000000..5bae2a2 --- /dev/null +++ b/src/libultra/os/settime.c @@ -0,0 +1,6 @@ +#include "PR/os_internal.h" +#include "osint.h" + +void osSetTime(OSTime time) { + __osCurrentTime = time; +} diff --git a/src/libultra/os/settimer.c b/src/libultra/os/settimer.c new file mode 100644 index 0000000..7d10f9e --- /dev/null +++ b/src/libultra/os/settimer.c @@ -0,0 +1,27 @@ +#include +#include "osint.h" + +int osSetTimer(OSTimer *t, OSTime value, OSTime interval, OSMesgQueue *mq, OSMesg msg) +{ + OSTime time; + + t->next = NULL; + t->prev = NULL; + t->interval = interval; + + if (value != 0) { + t->value = value; + } else { + t->value = interval; + } + + t->mq = mq; + t->msg = msg; + time = __osInsertTimer(t); + + if (__osTimerList->next == t) { + __osSetTimerIntr(time); + } + + return 0; +} diff --git a/src/libultra/os/startthread.c b/src/libultra/os/startthread.c new file mode 100644 index 0000000..0358ebb --- /dev/null +++ b/src/libultra/os/startthread.c @@ -0,0 +1,33 @@ +#include +#include "osint.h" + +void osStartThread(OSThread *t) +{ + register u32 saveMask = __osDisableInt(); + + switch (t->state) { + case OS_STATE_WAITING: + t->state = OS_STATE_RUNNABLE; + __osEnqueueThread(&__osRunQueue, t); + break; + case OS_STATE_STOPPED: + if (t->queue == NULL || t->queue == &__osRunQueue) { + t->state = OS_STATE_RUNNABLE; + __osEnqueueThread(&__osRunQueue, t); + } else { + t->state = OS_STATE_WAITING; + __osEnqueueThread(t->queue, t); + __osEnqueueThread(&__osRunQueue, __osPopThread(t->queue)); + } + break; + } + + if (__osRunningThread == NULL) { + __osDispatchThread(); + } else if (__osRunningThread->priority < __osRunQueue->priority) { + __osRunningThread->state = OS_STATE_RUNNABLE; + __osEnqueueAndYield(&__osRunQueue); + } + + __osRestoreInt(saveMask); +} diff --git a/src/libultra/os/osStopThread.c b/src/libultra/os/stopthread.c similarity index 100% rename from src/libultra/os/osStopThread.c rename to src/libultra/os/stopthread.c diff --git a/src/libultra/os/timerintr.c b/src/libultra/os/timerintr.c new file mode 100644 index 0000000..18fcde0 --- /dev/null +++ b/src/libultra/os/timerintr.c @@ -0,0 +1,99 @@ +#include "PR/os_internal.h" +#include "osint.h" + +OSTimer *__osTimerList = &__osBaseTimer; +OSTimer __osBaseTimer; +OSTime __osCurrentTime; +u32 __osBaseCounter; +u32 __osViIntrCount; +u32 __osTimerCounter; + +void __osTimerServicesInit(void) { + __osCurrentTime = 0; + __osBaseCounter = 0; + __osViIntrCount = 0; + __osTimerList->prev = __osTimerList; + __osTimerList->next = __osTimerList->prev; + __osTimerList->value = 0; + __osTimerList->interval = __osTimerList->value; + __osTimerList->mq = NULL; + __osTimerList->msg = 0; +} + +void __osTimerInterrupt(void) { + OSTimer *t; + u32 count; + u32 elapsed_cycles; + + if (__osTimerList->next != __osTimerList) { + while (TRUE) { + t = __osTimerList->next; + if (t == __osTimerList) { + __osSetCompare(0); + __osTimerCounter = 0; + break; + } + + count = osGetCount(); + elapsed_cycles = count - __osTimerCounter; + __osTimerCounter = count; + + if (elapsed_cycles < t->value) + { + t->value -= elapsed_cycles; + __osSetTimerIntr(t->value); + break; + } else { + t->prev->next = t->next; + t->next->prev = t->prev; + t->next = NULL; + t->prev = NULL; + + if (t->mq != NULL) { + osSendMesg(t->mq, t->msg, OS_MESG_NOBLOCK); + } + + if (t->interval != 0) { + t->value = t->interval; + __osInsertTimer(t); + } + } + } + } +} + +void __osSetTimerIntr(OSTime tim) { + OSTime NewTime; + u32 savedMask; + + savedMask = __osDisableInt(); + __osTimerCounter = osGetCount(); + NewTime = __osTimerCounter + tim; + __osSetCompare(NewTime); + __osRestoreInt(savedMask); +} + +OSTime __osInsertTimer(OSTimer* timer) { + OSTimer* nextTimer; + u64 timerValue; + u32 prevInt = __osDisableInt(); + + for (nextTimer = __osTimerList->next, timerValue = timer->value; + nextTimer != __osTimerList && timerValue > nextTimer->value; + timerValue -= nextTimer->value, nextTimer = nextTimer->next) { + ; + } + + timer->value = timerValue; + if (nextTimer != __osTimerList) { + nextTimer->value -= timerValue; + } + + timer->next = nextTimer; + timer->prev = nextTimer->prev; + nextTimer->prev->next = timer; + nextTimer->prev = timer; + __osRestoreInt(prevInt); + + return timerValue; +} diff --git a/src/libultra/os/virtualtophysical.c b/src/libultra/os/virtualtophysical.c new file mode 100644 index 0000000..283a8d5 --- /dev/null +++ b/src/libultra/os/virtualtophysical.c @@ -0,0 +1,12 @@ +#include + +u32 osVirtualToPhysical(void *addr) +{ + if (IS_KSEG0(addr)) { + return K0_TO_PHYS(addr); + } else if (IS_KSEG1(addr)) { + return K1_TO_PHYS(addr); + } else { + return __osProbeTLB(addr); + } +} diff --git a/src/libultra/os/yieldthread.c b/src/libultra/os/yieldthread.c new file mode 100644 index 0000000..f4ed7c5 --- /dev/null +++ b/src/libultra/os/yieldthread.c @@ -0,0 +1,10 @@ +#include "PR/os_internal.h" +#include "osint.h" + +void osYieldThread(void) { + register u32 saveMask = __osDisableInt(); + + __osRunningThread->state = OS_STATE_RUNNABLE; + __osEnqueueAndYield(&__osRunQueue); + __osRestoreInt(saveMask); +} diff --git a/src/rsp.c b/src/rsp.c index 83a7a1f..d7e6ca9 100644 --- a/src/rsp.c +++ b/src/rsp.c @@ -14,7 +14,7 @@ OSThread gRspThread; u8 unk_80081AB0[0x2000]; u8 gRspThreadStack[0x9C]; OSMesg D_80083B4C; -u8 unk_80081B50[0x3C]; +u8 unk_80083B50[0x3C]; OSMesg D_80083B8C; u8 unk_80083B90[0x3C]; OSMesg D_80083BCC; @@ -50,8 +50,8 @@ OSPiHandle* func_80000628(void) { sramHandle.domain = PI_DOMAIN2; sramHandle.speed = 0; - func_80057FD0(&sramHandle.transferInfo, sizeof(sramHandle.transferInfo)); - func_8005A990(&sramHandle); + bzero(&sramHandle.transferInfo, sizeof(sramHandle.transferInfo)); + osEPiLinkHandle(&sramHandle); } return &sramHandle; } @@ -66,7 +66,7 @@ s32 func_800006C4(struct UnkStruct800006C4_2* arg0) { unkStruct.sp2C = arg0->unk1C; unkStruct.sp30 = arg0->size; osInvalDCache(arg0->vaddr, arg0->size); - func_8005E0F0(unk1C, &unkStruct.sp20, 0); + osEPiStartDma(unk1C, &unkStruct.sp20, 0); osRecvMesg(&D_80083BD0.queue2, &D_80083BD0.unk0, 1); return 0; } @@ -81,7 +81,7 @@ s32 func_8000074C(struct UnkStruct800006C4_2* arg0) { unkStruct.sp2C = arg0->unk1C; unkStruct.sp30 = arg0->size; osWritebackDCache(arg0->vaddr, arg0->size); - func_8005E0F0(unk1C, &unkStruct.sp20, 1); + osEPiStartDma(unk1C, &unkStruct.sp20, 1); osRecvMesg(&D_80083BD0.queue2, &D_80083BD0.unk0, OS_MESG_BLOCK); return 0; } @@ -101,7 +101,7 @@ s32 func_800007D4(struct UnkStruct800006C4_2* arg0, s32 arg1) { unkStruct.sp2C = arg0->unk1C; unkStruct.sp30 = arg0->size; osInvalDCache(arg0->vaddr, arg0->size); - func_8005E0F0(handle, &unkStruct.sp20, 0); + osEPiStartDma(handle, &unkStruct.sp20, 0); osRecvMesg(&D_80083BD0.queue2, &D_80083BD0.unk0, OS_MESG_BLOCK); return 0; } @@ -117,7 +117,7 @@ s32 func_8000087C(struct UnkStruct800006C4_2* arg0) { unkStruct.sp2C = arg0->unk1C; unkStruct.sp30 = arg0->size; osWritebackDCache(arg0->vaddr, arg0->size); - func_8005E0F0(handle, &unkStruct.sp20, 1); + osEPiStartDma(handle, &unkStruct.sp20, 1); osRecvMesg(&D_80083BD0.queue2, &D_80083BD0.unk0, OS_MESG_BLOCK); return 0; } @@ -257,7 +257,7 @@ void thread20_rsp(void *arg) { void rsp_init(void) { osCreateMesgQueue(&D_80083BD0.queue2, &D_80083BCC, 1); osCreateMesgQueue(&D_80083BD0.queue1, &D_80083B8C, 16); - func_8005B6A0(0x96, &D_80083BD0.unk4, &gRspThreadStack[0x1C], 0x20); + osCreatePiManager(0x96, &D_80083BD0.unk4, &gRspThreadStack[0x1C], 0x20); osCreateThread(&gRspThread, 20, thread20_rsp, NULL, gRspThreadStack, 90); osStartThread(&gRspThread); } diff --git a/src/unk_bss.c b/src/unk_bss.c new file mode 100644 index 0000000..650684b --- /dev/null +++ b/src/unk_bss.c @@ -0,0 +1,4 @@ +#include + +// used for padding. Splat cant auto gen these I guess +u8 unk_bss[0x80103880-0x80083CA0]; diff --git a/tools/ido_recomp/linux/5.3/ujoin b/tools/ido_recomp/linux/5.3/ujoin new file mode 100644 index 0000000..f9c90b8 Binary files /dev/null and b/tools/ido_recomp/linux/5.3/ujoin differ diff --git a/tools/ido_recomp/linux/5.3/uld b/tools/ido_recomp/linux/5.3/uld new file mode 100644 index 0000000..f227222 Binary files /dev/null and b/tools/ido_recomp/linux/5.3/uld differ diff --git a/tools/ido_recomp/linux/5.3/umerge b/tools/ido_recomp/linux/5.3/umerge new file mode 100644 index 0000000..00a8281 Binary files /dev/null and b/tools/ido_recomp/linux/5.3/umerge differ diff --git a/tools/ido_recomp/linux/5.3/usplit b/tools/ido_recomp/linux/5.3/usplit new file mode 100644 index 0000000..a1c5eba Binary files /dev/null and b/tools/ido_recomp/linux/5.3/usplit differ diff --git a/tools/set_o32abi_bit.py b/tools/set_o32abi_bit.py new file mode 100644 index 0000000..c76d8bc --- /dev/null +++ b/tools/set_o32abi_bit.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +import argparse, struct, sys + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + + parser.add_argument('file', help='input file') + args = parser.parse_args() + + with open(args.file, 'r+b') as f: + magic = struct.unpack('>I', f.read(4))[0] + if magic != 0x7F454C46: + print('Error: Not an ELF file') + sys.exit(1) + + f.seek(36) + flags = struct.unpack('>I', f.read(4))[0] + if flags & 0xF0000000 != 0x20000000: # test for mips3 + print('Error: Architecture not mips3') + sys.exit(1) + + flags |= 0x00001000 # set EF_MIPS_ABI_O32 + f.seek(36) + f.write(struct.pack('>I', flags)) diff --git a/tools/symbol_addrs.txt b/tools/symbol_addrs.txt index db78df6..5a07750 100644 --- a/tools/symbol_addrs.txt +++ b/tools/symbol_addrs.txt @@ -32,7 +32,6 @@ __osDisableInt = 0x80062A90; __osDispatchThread = 0x80057E44; // ! __osEepStatus = 0x8005BFA4; __osEnqueueAndYield = 0x80057CEC; // ! -__osFaultedThread = 0x80056CC4; __osGbpakSelectBank = 0x80065AD0; __osGetId = 0x8005C894; __osIdCheckSum = 0x8005C2E4; @@ -53,7 +52,6 @@ __osPopThread = 0x80057E34; // ! __osRepairPackId = 0x8005C3E0; __osResetGlobalIntMask = 0x80062870; __osRestoreInt = 0x80062B00; -__osRunQueue = 0x80056CB8; __osRunningThread = 0x80079630; __osSetCause = 0x800568B0; __osSetGlobalIntMask = 0x80062220; @@ -219,7 +217,7 @@ alHeapInit = 0x8005E1D0; osInvalDCache = 0x8005E2F0; osCreateMesgQueue = 0x8005E3A0; osInvalICache = 0x8005E3D0; -_bcmp = 0x8005EE40; +bcmp = 0x8005EE40; __osTimerServicesInit = 0x8005F1E0; __osTimerInterrupt = 0x8005F26C; __osSetTimerIntr = 0x8005F3E4; @@ -286,4 +284,107 @@ alInit = 0x80056FDC; _VirtualToPhysicalTask = 0x80057010; osSpTaskLoad = 0x8005712C; osSpTaskStartGo = 0x800572BC; -sTmpTask = 0x80102100; \ No newline at end of file +sTmpTask = 0x80102100; +__osPiAccessQueue = 0x801020E8; +__osPiAccessQueueEnabled = 0x80079610; +piAccessBuf = 0x801020E0; +__sinf = 0x80056D90; +__libm_qnan_f = 0x8007E5D0; +bzero = 0x80057FD0; +var80090ab0 = 0x80102200; +g_GbpakMesgQueue = 0x80102220; +var80090ae8 = 0x80102238; +__osContPifRam = 0x80102140; +__osMaxControllers = 0x80102181; +__osContLastCmd = 0x80102180; +__osEepromTimerQ = 0x801021A8; +__osEepromTimerMsg = 0x801021C0; +__osContInitialized = 0x80079680; +__osSiAccessQueue = 0x801021D8; +__osSiAccessQueueEnabled = 0x80079690; +siAccessBuf = 0x801021D0; +__osCleanupThread = 0x80057FC0; +__osProbeTLB = 0x8005B5E0; +__osFinalRom = 0x801021F0; +__osExceptionPreamble = 0x800576D0; +__osCartRomInit = 0x80059448; +osResetType = 0x8000030C; +osAppNMIBuffer = 0x8000031C; +osTvType = 0x80000300; +__osGetCause = 0x80063E00; +CartRomHandle = 0x80102430; +LeoDiskHandle = 0x801024A8; +__osGlobalIntMask = 0x800796B0; +__osShutdown = 0x800796AC; +osViClock = 0x800796A8; +__osPfsInodeCacheBank = 0x8007A934; +__osPfsPifRam = 0x801023F0; +alGlobals = 0x80079640; +guPerspectiveF = 0x8005A5C0; +guPerspective = 0x8005A7F0; +alSeqFileNew = 0x80058278; +__osPiTable = 0x8007A87C; +osViRepeatLine = 0x8005B230; +osPfsIsPlug = 0x8005B2A0; +__osPfsRequestData = 0x8005B440; +__osPfsGetInitData = 0x8005B510; +osCreatePiManager = 0x8005B6A0; +osEPiStartDma = 0x8005E0F0; +__osEepromTimer = 0x80102188; +osEepromLongWrite = 0x8005E450; +guRotateRPYF = 0x8005ECA0; +guRotateRPY = 0x8005EDEC; +guRotateF = 0x8005EF60; +guRotate = 0x8005F0F4; +_Ldtob = 0x800645C0; +alAdpcmPull = 0x80061C9C; +alLoadParam = 0x800615F0; +osEPiLinkHandle = 0x8005A990; +__osViNext = 0x8007ACF4; +piEventQueue = 0x801036D0; +piEventBuf = 0x801036E8; +piThread = 0x80102520; +__osPiDevMgr = 0x8007A860; +piThreadStack = 0x801026D0; +osRomBase = 0x80000308; +__osEepPifRam = 0x80104B70; +osGetCount = 0x8005BD00; +__osPfsInodeCacheChannel = 0x8007A930; +__osPfsInodeCache = 0x801036F0; +__osPreNMI = 0x8007A940; +__osEventStateTab = 0x801037F0; +osAfterPreNMI = 0x8005CEC0; +__osThreadTail = 0x80079620; +__osRunQueue = 0x80079628; +__osEnqueueThread = 0x80057DEC; +__osCurrentHandle = 0x8007A880; +__osTimerList = 0x8007A9B0; +__osBaseTimer = 0x80103890; +__osCurrentTime = 0x801038B0; +__osCurrentTime+4 = 0x801038B4; +__osBaseCounter = 0x801038B8; +__osViIntrCount = 0x801038BC; +__osTimerCounter = 0x801038C0; +_timeToSamplesNoRound = 0x8005FB90; +alEnvmixerParam = 0x80060B78; +_pullSubFrame = 0x80060C58; +_frexpf = 0x80060F40; +_ldexpf = 0x8006102C; +_getRate = 0x80061054; +_getVol = 0x80061238; +osViModePalLan1 = 0x8007AD00; +osViModeMpalLan1 = 0x8007ADA0; +osViModeNtscLan1 = 0x8007AD50; +g_OsGbNintendoData = 0x8007ADF0; +g_OsGbCartVersions = 0x8007AE20; +__CartRomHandle = 0x801038D0; +__osPfsLastChannel = 0x8007AE50; +__osViDevMgr = 0x8007AE90; +__additional_scanline = 0x8007AEAC; +viThread = 0x80103950; +viThreadStack = 0x80103B00; +viEventQueue = 0x80104B00; +viEventBuf = 0x80104B18; +viRetraceMsg = 0x80104B30; +viCounterMsg = 0x80104B48; +__osHwIntTable = 0x80079650; \ No newline at end of file diff --git a/undefined_syms.txt b/undefined_syms.txt index 023a0ba..46ce95a 100644 --- a/undefined_syms.txt +++ b/undefined_syms.txt @@ -5,3 +5,7 @@ D_8007A868 = 0x8007A868; __osRunningThread = 0x80079630; D_80080001 = 0x80080001; D_80083ACC = 0x80083ACC; +__osGlobalIntMask = 0x800796B0; +CartRomHandle = 0x80102430; +LeoDiskHandle = 0x801024A8; +piThreadStack = 0x801026D0; \ No newline at end of file