diff --git a/Makefile b/Makefile index d55a52ba..f3a7320b 100755 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ VERSION := us_1.0 NON_MATCHING ?= 0 $(eval $(call validate-option,NON_MATCHING,0 1)) -LIBULTRA_VERSION_DEFINE := -DBUILD_VERSION=4 -DBUILD_VERSION_STRING=\"2.0G\" -DRAREDIFFS +LIBULTRA_VERSION_DEFINE := -DBUILD_VERSION=4 -DBUILD_VERSION_STRING=\"2.0G\" ifeq ($(VERSION),us_1.0) DEFINES += VERSION_US_1_0=1 @@ -157,7 +157,7 @@ endif MIPSISET := -mips1 OPT_FLAGS := -O2 -Xfullwarn #include -Xfullwarn here since it's not supported with -O3 -INCLUDE_DIRS := include $(BUILD_DIR) $(BUILD_DIR)/include src include/libc . +INCLUDE_DIRS := include $(BUILD_DIR) $(BUILD_DIR)/include src include/libc include/PR include/sys lib/src lib/src/audio lib/src/debug lib/src/gu lib/src/libc lib/src/os . C_DEFINES := $(foreach d,$(DEFINES),-D$(d)) $(LIBULTRA_VERSION_DEFINE) -D_MIPS_SZLONG=32 DEF_INC_CFLAGS := $(foreach i,$(INCLUDE_DIRS),-I$(i)) $(C_DEFINES) @@ -165,7 +165,7 @@ DEF_INC_CFLAGS := $(foreach i,$(INCLUDE_DIRS),-I$(i)) $(C_DEFINES) #IDO Warnings to Ignore. These are coding style warnings we don't follow IDO_IGNORE_WARNINGS = -woff 838,649,624 -ASFLAGS = -mtune=vr4300 -march=vr4300 -mabi=32 $(foreach d,$(DEFINES),--defsym $(d)) +ASFLAGS = -mtune=vr4300 -march=vr4300 -mabi=32 -I include $(foreach d,$(DEFINES),--defsym $(d)) INCLUDE_CFLAGS := -I include -I $(BUILD_DIR) -I src -I . -I include/libc CFLAGS = -c -Wab,-r4300_mul -non_shared -G 0 -Xcpluscomm -DNDEBUG $(OPT_FLAGS) $(MIPSISET) $(INCLUDE_CFLAGS) $(DEF_INC_CFLAGS) $(IDO_IGNORE_WARNINGS) LDFLAGS = undefined_syms.txt -T $(BUILD_DIR)/$(LD_SCRIPT) -Map $(BUILD_DIR)/dkr.map @@ -185,7 +185,7 @@ FIXCHECKSUMS = python3 $(TOOLS_DIR)/python/calc_func_checksums.py $(VERSION) BUILDER = $(TOOLS_DIR)/dkr_assets_tool -dkrv $(VERSION) build LIB_DIRS := lib -ASM_DIRS := asm asm/boot asm/assets lib/asm lib/asm/non_decompilable +ASM_DIRS := asm asm/boot asm/assets lib/asm SRC_DIRS := $(sort $(patsubst %/,%,$(dir $(wildcard src/* src/**/* lib/src/* lib/src/**/* lib/src/**/**/*)))) OS := $(shell uname) @@ -277,25 +277,35 @@ ALL_ASSETS_BUILT += $(patsubst $(UCODE_IN_DIR)/%.bin,$(UCODE_OUT_DIR)/%.bin,$(UC ####################### LIBULTRA ######################### -$(BUILD_DIR)/lib/%.o: OPT_FLAGS := -O2 -Xfullwarn -$(BUILD_DIR)/lib/src/al/%.o: OPT_FLAGS := -O3 -$(BUILD_DIR)/lib/src/os/%.o: OPT_FLAGS := -O1 -Xfullwarn -$(BUILD_DIR)/lib/src/os/osViMgr.o: OPT_FLAGS := -O2 -Xfullwarn -$(BUILD_DIR)/lib/src/os/osCreatePiManager.o: OPT_FLAGS := -O2 -Xfullwarn -$(BUILD_DIR)/lib/src/os/osMotor.o: OPT_FLAGS := -O2 -Xfullwarn -$(BUILD_DIR)/lib/src/libc/xprintf.o : OPT_FLAGS := -O3 -$(BUILD_DIR)/lib/src/al/env.o: OPT_FLAGS := -g -$(BUILD_DIR)/lib/src/libc/llcvt.o: OPT_FLAGS := -O1 -$(BUILD_DIR)/lib/src/libc/llcvt.o: MIPSISET := -mips3 -32 -$(BUILD_DIR)/lib/src/libc/ll.o: OPT_FLAGS := -O1 -$(BUILD_DIR)/lib/src/libc/ll.o: MIPSISET := -mips3 -32 -$(BUILD_DIR)/lib/src/libc/ldiv.o: OPT_FLAGS := -O3 -$(BUILD_DIR)/lib/src/libc/ldiv.o: MIPSISET := -mips2 +$(BUILD_DIR)/$(LIB_DIRS)/%.o: OPT_FLAGS := -O2 +$(BUILD_DIR)/$(LIB_DIRS)/src/audio/%.o: OPT_FLAGS := -O3 +$(BUILD_DIR)/$(LIB_DIRS)/src/audio/mips1/%.o: OPT_FLAGS := -O2 +$(BUILD_DIR)/$(LIB_DIRS)/src/os/%.o: OPT_FLAGS := -O1 +$(BUILD_DIR)/$(LIB_DIRS)/src/io/%.o: OPT_FLAGS := -O1 +$(BUILD_DIR)/$(LIB_DIRS)/src/io/vimgr.o: OPT_FLAGS := -O2 +$(BUILD_DIR)/$(LIB_DIRS)/src/io/pimgr.o: OPT_FLAGS := -O2 +$(BUILD_DIR)/$(LIB_DIRS)/src/io/motor.o: OPT_FLAGS := -O2 +$(BUILD_DIR)/$(LIB_DIRS)/src/libc/xprintf.o : OPT_FLAGS := -O3 +$(BUILD_DIR)/$(LIB_DIRS)/src/audio/env.o: OPT_FLAGS := -g +$(BUILD_DIR)/$(LIB_DIRS)/src/libc/llcvt.o: OPT_FLAGS := -O1 +$(BUILD_DIR)/$(LIB_DIRS)/src/libc/llcvt.o: MIPSISET := -mips3 -32 +$(BUILD_DIR)/$(LIB_DIRS)/src/libc/ll.o: OPT_FLAGS := -O1 +$(BUILD_DIR)/$(LIB_DIRS)/src/libc/ll.o: MIPSISET := -mips3 -32 +$(BUILD_DIR)/$(LIB_DIRS)/src/libc/ldiv.o: OPT_FLAGS := -O3 +$(BUILD_DIR)/$(LIB_DIRS)/src/libc/ldiv.o: MIPSISET := -mips2 +$(BUILD_DIR)/$(LIB_DIRS)/src/libc/xldtob.o: OPT_FLAGS := -O3 +$(BUILD_DIR)/$(LIB_DIRS)/src/libc/xldtob.o: MIPSISET := -mips2 -$(BUILD_DIR)/lib/%.o: MIPSISET := -mips2 -$(BUILD_DIR)/lib/src/mips1/%.o: MIPSISET := -mips1 -$(BUILD_DIR)/lib/src/os/osMotor.o: MIPSISET := -mips1 -$(BUILD_DIR)/lib/src/al/env.o: MIPSISET := -mips1 +$(BUILD_DIR)/$(LIB_DIRS)/%.o: MIPSISET := -mips2 +$(BUILD_DIR)/$(LIB_DIRS)/src/audio/mips1/%.o: MIPSISET := -mips1 +$(BUILD_DIR)/$(LIB_DIRS)/src/io/pimgr.o: MIPSISET := -mips1 +$(BUILD_DIR)/$(LIB_DIRS)/src/sc/sched.o: MIPSISET := -mips1 +$(BUILD_DIR)/$(LIB_DIRS)/src/io/motor.o: MIPSISET := -mips1 +$(BUILD_DIR)/$(LIB_DIRS)/src/audio/env.o: MIPSISET := -mips1 + +#Ignore warnings for libultra files +$(BUILD_DIR)/$(LIB_DIRS)/%.o: CC_WARNINGS := -w +$(BUILD_DIR)/$(LIB_DIRS)/%.o: CC_CHECK := : ####################### MATH UTIL ######################### @@ -388,12 +398,12 @@ $(BUILD_DIR)/%.o: %.c | $(ALL_ASSETS_BUILT) @$(CC_CHECK) $(CC_CHECK_CFLAGS) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $< $(V)$(CC) $(CFLAGS) -o $@ $< -$(BUILD_DIR)/lib/src/libc/llcvt.o: lib/src/libc/llcvt.c | $(ALL_ASSETS_BUILT) +$(BUILD_DIR)/$(LIB_DIRS)/src/libc/llcvt.o: $(LIB_DIRS)/src/libc/llcvt.c | $(ALL_ASSETS_BUILT) $(call print,Compiling mips3:,$<,$@) $(V)$(CC) $(CFLAGS) -o $@ $< $(V)python3 tools/python/patchmips3.py $@ || rm $@ -$(BUILD_DIR)/lib/src/libc/ll.o: lib/src/libc/ll.c | $(ALL_ASSETS_BUILT) +$(BUILD_DIR)/$(LIB_DIRS)/src/libc/ll.o: $(LIB_DIRS)/src/libc/ll.c | $(ALL_ASSETS_BUILT) $(call print,Compiling mips3:,$<,$@) $(V)$(CC) $(CFLAGS) -o $@ $< $(V)python3 tools/python/patchmips3.py $@ || rm $@ diff --git a/README.md b/README.md index 37387004..5f60c7ea 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,11 @@ This repo contains a work-in-progress decompilation of Diddy Kong Racing for the Currently, only the US 1.0 version (SHA1 = 0cb115d8716dbbc2922fda38e533b9fe63bb9670) of the game is supported. US 1.1, EU 1.0, EU 1.1, and JP are not supported at this time. -As of February 18, 2025, this is our current score: +As of February 22, 2025, this is our current score: -    Decomp progress: 70.26% +    Decomp progress: 71.39% -    Documentation progress: 49.72% +    Documentation progress: 50.35% --- @@ -126,31 +126,31 @@ s32 is_drumstick_unlocked(void) { ``` -As of February 18th, 2025, this is our current score: +As of February 22nd, 2025, this is our current score: ``` - ============================================= - ADVENTURE ONE (ASM -> C Decompilation) - --- 70.26% Complete (72.90% NON_MATCHING) --- - # Decompiled functions: 1706 - # GLOBAL_ASM remaining: 139 - # NON_MATCHING functions: 15 - # NON_EQUIVALENT WIP functions: 44 - ---------------- Game Status ---------------- - Balloons: 34/47, Keys: 4/4, Trophies: 3/5 - T.T. Amulets: 3/4, Wizpig Amulets: 3/4 - --------------------------------------------- - We are racing in Haunted Woods. (Lap 2/3) - ============================================= - ADVENTURE TWO (Cleanup & Documentation) - -------------- 49.72% Complete -------------- - # Documented functions: 1091 - # Undocumented remaining: 477 - ---------------- Game Status ---------------- - Balloons: 24/47, Keys: 3/4, Trophies: 2/5 - T.T. Amulets: 2/4, Wizpig Amulets: 2/4 - --------------------------------------------- - We are racing in Pirate Lagoon. (Lap 3/3) - ============================================= + =============================================== + ADVENTURE ONE (ASM -> C Decompilation) + ---- 71.39% Complete (74.02% NON_MATCHING) ---- + # Decompiled functions: 1726 + # GLOBAL_ASM remaining: 133 + # NON_MATCHING functions: 15 + # NON_EQUIVALENT WIP functions: 44 + ----------------- Game Status ----------------- + Balloons: 35/47, Keys: 4/4, Trophies: 3/5 + T.T. Amulets: 3/4, Wizpig Amulets: 3/4 + ----------------------------------------------- + We are racing the dragon boss Smokey. (Lap 1/3) + =============================================== + ADVENTURE TWO (Cleanup & Documentation) + --------------- 50.35% Complete --------------- + # Documented functions: 1091 + # Undocumented remaining: 471 + ----------------- Game Status ----------------- + Balloons: 25/47, Keys: 3/4, Trophies: 2/5 + T.T. Amulets: 2/4, Wizpig Amulets: 2/4 + ----------------------------------------------- + We are racing in Treasure Caves. (Lap 1/3) + =============================================== ``` diff --git a/asm/math_util/coss.s b/asm/math_util/coss.s index e757bb5b..0483ae61 100644 --- a/asm/math_util/coss.s +++ b/asm/math_util/coss.s @@ -1,6 +1,6 @@ -glabel coss /* Official Name: mathCosInterp */ +glabel coss_s16 /* Official Name: mathCosInterp */ /* 07142C 8007082C 24844000 */ addiu $a0, $a0, 0x4000 -glabel sins /* Official name: mathSinInterp */ +glabel sins_s16 /* Official name: mathSinInterp */ /* 071430 80070830 00041440 */ sll $v0, $a0, 0x11 /* 071434 80070834 04430003 */ bgezl $v0, .L80070844 /* 071438 80070838 000450C2 */ srl $t2, $a0, 3 diff --git a/asm/math_util/coss_f.s b/asm/math_util/coss_f.s index a499f1fd..5f735518 100644 --- a/asm/math_util/coss_f.s +++ b/asm/math_util/coss_f.s @@ -1,7 +1,7 @@ glabel coss_f /* 0713F8 800707F8 27BDFFF8 */ addiu $sp, $sp, -8 /* 0713FC 800707FC FFBF0000 */ sd $ra, ($sp) -/* 071400 80070800 0C01C20B */ jal coss +/* 071400 80070800 0C01C20B */ jal coss_s16 /* 071404 80070804 00000000 */ nop /* 071408 80070808 44820000 */ mtc1 $v0, $f0 /* 07140C 8007080C 3C013780 */ li $at, 0x37800000 # 0.000015 diff --git a/asm/math_util/f32_matrix_from_rotation_and_scale.s b/asm/math_util/f32_matrix_from_rotation_and_scale.s index 5afd9283..d21dcbc6 100644 --- a/asm/math_util/f32_matrix_from_rotation_and_scale.s +++ b/asm/math_util/f32_matrix_from_rotation_and_scale.s @@ -5,13 +5,13 @@ glabel f32_matrix_from_rotation_and_scale /* 070D3C 8007013C FFBF0000 */ sd $ra, ($sp) /* 070D40 80070140 00803825 */ move $a3, $a0 /* 070D44 80070144 44819000 */ mtc1 $at, $f18 -/* 070D48 80070148 0C01C20C */ jal sins +/* 070D48 80070148 0C01C20C */ jal sins_s16 /* 070D4C 8007014C 00A02025 */ move $a0, $a1 /* 070D50 80070150 44824000 */ mtc1 $v0, $f8 /* 070D54 80070154 00A02025 */ move $a0, $a1 /* 070D58 80070158 46804220 */ cvt.s.w $f8, $f8 /* 070D5C 8007015C 46124202 */ mul.s $f8, $f8, $f18 -/* 070D60 80070160 0C01C20B */ jal coss +/* 070D60 80070160 0C01C20B */ jal coss_s16 /* 070D64 80070164 00000000 */ nop /* 070D68 80070168 44825000 */ mtc1 $v0, $f10 /* 070D6C 8007016C 44868000 */ mtc1 $a2, $f16 diff --git a/asm/math_util/func_80070058.s b/asm/math_util/func_80070058.s index b7a8a059..445daad1 100644 --- a/asm/math_util/func_80070058.s +++ b/asm/math_util/func_80070058.s @@ -4,37 +4,37 @@ glabel func_80070058 /* 070C60 80070060 FFBF0000 */ sd $ra, ($sp) /* 070C64 80070064 00803825 */ move $a3, $a0 /* 070C68 80070068 44819000 */ mtc1 $at, $f18 -/* 070C6C 8007006C 0C01C20C */ jal sins +/* 070C6C 8007006C 0C01C20C */ jal sins_s16 /* 070C70 80070070 84A40000 */ lh $a0, ($a1) /* 070C74 80070074 44820000 */ mtc1 $v0, $f0 /* 070C78 80070078 84A40000 */ lh $a0, ($a1) /* 070C7C 8007007C 46800020 */ cvt.s.w $f0, $f0 /* 070C80 80070080 46120002 */ mul.s $f0, $f0, $f18 -/* 070C84 80070084 0C01C20B */ jal coss +/* 070C84 80070084 0C01C20B */ jal coss_s16 /* 070C88 80070088 00000000 */ nop /* 070C8C 8007008C 44821000 */ mtc1 $v0, $f2 /* 070C90 80070090 84A40002 */ lh $a0, 2($a1) /* 070C94 80070094 468010A0 */ cvt.s.w $f2, $f2 /* 070C98 80070098 46121082 */ mul.s $f2, $f2, $f18 -/* 070C9C 8007009C 0C01C20C */ jal sins +/* 070C9C 8007009C 0C01C20C */ jal sins_s16 /* 070CA0 800700A0 00000000 */ nop /* 070CA4 800700A4 44822000 */ mtc1 $v0, $f4 /* 070CA8 800700A8 84A40002 */ lh $a0, 2($a1) /* 070CAC 800700AC 46802120 */ cvt.s.w $f4, $f4 /* 070CB0 800700B0 46122102 */ mul.s $f4, $f4, $f18 -/* 070CB4 800700B4 0C01C20B */ jal coss +/* 070CB4 800700B4 0C01C20B */ jal coss_s16 /* 070CB8 800700B8 00000000 */ nop /* 070CBC 800700BC 44823000 */ mtc1 $v0, $f6 /* 070CC0 800700C0 84A40004 */ lh $a0, 4($a1) /* 070CC4 800700C4 468031A0 */ cvt.s.w $f6, $f6 /* 070CC8 800700C8 46123182 */ mul.s $f6, $f6, $f18 -/* 070CCC 800700CC 0C01C20C */ jal sins +/* 070CCC 800700CC 0C01C20C */ jal sins_s16 /* 070CD0 800700D0 00000000 */ nop /* 070CD4 800700D4 44824000 */ mtc1 $v0, $f8 /* 070CD8 800700D8 84A40004 */ lh $a0, 4($a1) /* 070CDC 800700DC 46804220 */ cvt.s.w $f8, $f8 /* 070CE0 800700E0 46124202 */ mul.s $f8, $f8, $f18 -/* 070CE4 800700E4 0C01C20B */ jal coss +/* 070CE4 800700E4 0C01C20B */ jal coss_s16 /* 070CE8 800700E8 00000000 */ nop /* 070CEC 800700EC 44825000 */ mtc1 $v0, $f10 /* 070CF0 800700F0 3C013F80 */ li $at, 0x3F800000 # 1.000000 diff --git a/asm/math_util/object_transform_to_matrix.s b/asm/math_util/object_transform_to_matrix.s index 511c7fc2..6a05d75c 100644 --- a/asm/math_util/object_transform_to_matrix.s +++ b/asm/math_util/object_transform_to_matrix.s @@ -4,37 +4,37 @@ glabel object_transform_to_matrix /* 070838 8006FC38 FFBF0000 */ sd $ra, ($sp) /* 07083C 8006FC3C 00803825 */ move $a3, $a0 /* 070840 8006FC40 44819000 */ mtc1 $at, $f18 -/* 070844 8006FC44 0C01C20C */ jal sins +/* 070844 8006FC44 0C01C20C */ jal sins_s16 /* 070848 8006FC48 84A40000 */ lh $a0, ($a1) /* 07084C 8006FC4C 44820000 */ mtc1 $v0, $f0 /* 070850 8006FC50 84A40000 */ lh $a0, ($a1) /* 070854 8006FC54 46800020 */ cvt.s.w $f0, $f0 /* 070858 8006FC58 46120002 */ mul.s $f0, $f0, $f18 -/* 07085C 8006FC5C 0C01C20B */ jal coss +/* 07085C 8006FC5C 0C01C20B */ jal coss_s16 /* 070860 8006FC60 00000000 */ nop /* 070864 8006FC64 44821000 */ mtc1 $v0, $f2 /* 070868 8006FC68 84A40002 */ lh $a0, 2($a1) /* 07086C 8006FC6C 468010A0 */ cvt.s.w $f2, $f2 /* 070870 8006FC70 46121082 */ mul.s $f2, $f2, $f18 -/* 070874 8006FC74 0C01C20C */ jal sins +/* 070874 8006FC74 0C01C20C */ jal sins_s16 /* 070878 8006FC78 00000000 */ nop /* 07087C 8006FC7C 44822000 */ mtc1 $v0, $f4 /* 070880 8006FC80 84A40002 */ lh $a0, 2($a1) /* 070884 8006FC84 46802120 */ cvt.s.w $f4, $f4 /* 070888 8006FC88 46122102 */ mul.s $f4, $f4, $f18 -/* 07088C 8006FC8C 0C01C20B */ jal coss +/* 07088C 8006FC8C 0C01C20B */ jal coss_s16 /* 070890 8006FC90 00000000 */ nop /* 070894 8006FC94 44823000 */ mtc1 $v0, $f6 /* 070898 8006FC98 84A40004 */ lh $a0, 4($a1) /* 07089C 8006FC9C 468031A0 */ cvt.s.w $f6, $f6 /* 0708A0 8006FCA0 46123182 */ mul.s $f6, $f6, $f18 -/* 0708A4 8006FCA4 0C01C20C */ jal sins +/* 0708A4 8006FCA4 0C01C20C */ jal sins_s16 /* 0708A8 8006FCA8 00000000 */ nop /* 0708AC 8006FCAC 44824000 */ mtc1 $v0, $f8 /* 0708B0 8006FCB0 84A40004 */ lh $a0, 4($a1) /* 0708B4 8006FCB4 46804220 */ cvt.s.w $f8, $f8 /* 0708B8 8006FCB8 46124202 */ mul.s $f8, $f8, $f18 -/* 0708BC 8006FCBC 0C01C20B */ jal coss +/* 0708BC 8006FCBC 0C01C20B */ jal coss_s16 /* 0708C0 8006FCC0 00000000 */ nop /* 0708C4 8006FCC4 44825000 */ mtc1 $v0, $f10 /* 0708C8 8006FCC8 8CAA0008 */ lw $t2, 8($a1) diff --git a/asm/math_util/object_transform_to_matrix_2.s b/asm/math_util/object_transform_to_matrix_2.s index 98493797..98dc8af1 100644 --- a/asm/math_util/object_transform_to_matrix_2.s +++ b/asm/math_util/object_transform_to_matrix_2.s @@ -4,37 +4,37 @@ glabel object_transform_to_matrix_2 /* 070A7C 8006FE7C FFBF0000 */ sd $ra, ($sp) /* 070A80 8006FE80 00803825 */ move $a3, $a0 /* 070A84 8006FE84 44819000 */ mtc1 $at, $f18 -/* 070A88 8006FE88 0C01C20C */ jal sins +/* 070A88 8006FE88 0C01C20C */ jal sins_s16 /* 070A8C 8006FE8C 84A40000 */ lh $a0, ($a1) /* 070A90 8006FE90 44820000 */ mtc1 $v0, $f0 /* 070A94 8006FE94 84A40000 */ lh $a0, ($a1) /* 070A98 8006FE98 46800020 */ cvt.s.w $f0, $f0 /* 070A9C 8006FE9C 46120002 */ mul.s $f0, $f0, $f18 -/* 070AA0 8006FEA0 0C01C20B */ jal coss +/* 070AA0 8006FEA0 0C01C20B */ jal coss_s16 /* 070AA4 8006FEA4 00000000 */ nop /* 070AA8 8006FEA8 44821000 */ mtc1 $v0, $f2 /* 070AAC 8006FEAC 84A40002 */ lh $a0, 2($a1) /* 070AB0 8006FEB0 468010A0 */ cvt.s.w $f2, $f2 /* 070AB4 8006FEB4 46121082 */ mul.s $f2, $f2, $f18 -/* 070AB8 8006FEB8 0C01C20C */ jal sins +/* 070AB8 8006FEB8 0C01C20C */ jal sins_s16 /* 070ABC 8006FEBC 00000000 */ nop /* 070AC0 8006FEC0 44822000 */ mtc1 $v0, $f4 /* 070AC4 8006FEC4 84A40002 */ lh $a0, 2($a1) /* 070AC8 8006FEC8 46802120 */ cvt.s.w $f4, $f4 /* 070ACC 8006FECC 46122102 */ mul.s $f4, $f4, $f18 -/* 070AD0 8006FED0 0C01C20B */ jal coss +/* 070AD0 8006FED0 0C01C20B */ jal coss_s16 /* 070AD4 8006FED4 00000000 */ nop /* 070AD8 8006FED8 44823000 */ mtc1 $v0, $f6 /* 070ADC 8006FEDC 84A40004 */ lh $a0, 4($a1) /* 070AE0 8006FEE0 468031A0 */ cvt.s.w $f6, $f6 /* 070AE4 8006FEE4 46123182 */ mul.s $f6, $f6, $f18 -/* 070AE8 8006FEE8 0C01C20C */ jal sins +/* 070AE8 8006FEE8 0C01C20C */ jal sins_s16 /* 070AEC 8006FEEC 00000000 */ nop /* 070AF0 8006FEF0 44824000 */ mtc1 $v0, $f8 /* 070AF4 8006FEF4 84A40004 */ lh $a0, 4($a1) /* 070AF8 8006FEF8 46804220 */ cvt.s.w $f8, $f8 /* 070AFC 8006FEFC 46124202 */ mul.s $f8, $f8, $f18 -/* 070B00 8006FF00 0C01C20B */ jal coss +/* 070B00 8006FF00 0C01C20B */ jal coss_s16 /* 070B04 8006FF04 00000000 */ nop /* 070B08 8006FF08 44825000 */ mtc1 $v0, $f10 /* 070B0C 8006FF0C ACE0000C */ sw $zero, 0xc($a3) diff --git a/asm/math_util/s16_vec3_apply_object_rotation.s b/asm/math_util/s16_vec3_apply_object_rotation.s index 71f11922..903481f2 100644 --- a/asm/math_util/s16_vec3_apply_object_rotation.s +++ b/asm/math_util/s16_vec3_apply_object_rotation.s @@ -5,10 +5,10 @@ glabel s16_vec3_apply_object_rotation /* 070DF0 800701F0 84AB0000 */ lh $t3, ($a1) /* 070DF4 800701F4 84AC0002 */ lh $t4, 2($a1) /* 070DF8 800701F8 84AD0004 */ lh $t5, 4($a1) -/* 070DFC 800701FC 0C01C20C */ jal sins +/* 070DFC 800701FC 0C01C20C */ jal sins_s16 /* 070E00 80070200 84C40000 */ lh $a0, ($a2) /* 070E04 80070204 00407025 */ move $t6, $v0 -/* 070E08 80070208 0C01C20B */ jal coss +/* 070E08 80070208 0C01C20B */ jal coss_s16 /* 070E0C 8007020C 84C40000 */ lh $a0, ($a2) /* 070E10 80070210 016E0018 */ mult $t3, $t6 /* 070E14 80070214 00407825 */ move $t7, $v0 @@ -27,10 +27,10 @@ glabel s16_vec3_apply_object_rotation /* 070E48 80070248 018F0018 */ mult $t4, $t7 /* 070E4C 8007024C 00006012 */ mflo $t4 /* 070E50 80070250 01886020 */ add $t4, $t4, $t0 -/* 070E54 80070254 0C01C20C */ jal sins +/* 070E54 80070254 0C01C20C */ jal sins_s16 /* 070E58 80070258 000C6403 */ sra $t4, $t4, 0x10 /* 070E5C 8007025C 00407025 */ move $t6, $v0 -/* 070E60 80070260 0C01C20B */ jal coss +/* 070E60 80070260 0C01C20B */ jal coss_s16 /* 070E64 80070264 84C40002 */ lh $a0, 2($a2) /* 070E68 80070268 018E0018 */ mult $t4, $t6 /* 070E6C 8007026C 00407825 */ move $t7, $v0 @@ -49,10 +49,10 @@ glabel s16_vec3_apply_object_rotation /* 070EA0 800702A0 01AF0018 */ mult $t5, $t7 /* 070EA4 800702A4 00006812 */ mflo $t5 /* 070EA8 800702A8 01A86820 */ add $t5, $t5, $t0 -/* 070EAC 800702AC 0C01C20C */ jal sins +/* 070EAC 800702AC 0C01C20C */ jal sins_s16 /* 070EB0 800702B0 000D6C03 */ sra $t5, $t5, 0x10 /* 070EB4 800702B4 00407025 */ move $t6, $v0 -/* 070EB8 800702B8 0C01C20B */ jal coss +/* 070EB8 800702B8 0C01C20B */ jal coss_s16 /* 070EBC 800702BC 84C40004 */ lh $a0, 4($a2) /* 070EC0 800702C0 016E0018 */ mult $t3, $t6 /* 070EC4 800702C4 00407825 */ move $t7, $v0 diff --git a/asm/math_util/sins_f.s b/asm/math_util/sins_f.s index f5621b83..471bb8d5 100644 --- a/asm/math_util/sins_f.s +++ b/asm/math_util/sins_f.s @@ -1,7 +1,7 @@ glabel sins_f /* 0713C4 800707C4 27BDFFF8 */ addiu $sp, $sp, -8 /* 0713C8 800707C8 FFBF0000 */ sd $ra, ($sp) -/* 0713CC 800707CC 0C01C20C */ jal sins +/* 0713CC 800707CC 0C01C20C */ jal sins_s16 /* 0713D0 800707D0 00000000 */ nop /* 0713D4 800707D4 44820000 */ mtc1 $v0, $f0 /* 0713D8 800707D8 3C013780 */ li $at, 0x37800000 # 0.000015 diff --git a/asm/non_matchings/menu/menu_credits_loop.s b/asm/non_matchings/menu/menu_credits_loop.s index 73be073c..1a8af518 100644 --- a/asm/non_matchings/menu/menu_credits_loop.s +++ b/asm/non_matchings/menu/menu_credits_loop.s @@ -102,12 +102,12 @@ glabel menu_credits_loop /* 09C090 8009B490 00092400 */ sll $a0, $t1, 0x10 /* 09C094 8009B494 00045403 */ sra $t2, $a0, 0x10 /* 09C098 8009B498 01402025 */ move $a0, $t2 -/* 09C09C 8009B49C 0C01C20C */ jal sins +/* 09C09C 8009B49C 0C01C20C */ jal sins_s16 /* 09C0A0 8009B4A0 01208825 */ move $s1, $t1 /* 09C0A4 8009B4A4 00112400 */ sll $a0, $s1, 0x10 /* 09C0A8 8009B4A8 00046403 */ sra $t4, $a0, 0x10 /* 09C0AC 8009B4AC 01802025 */ move $a0, $t4 -/* 09C0B0 8009B4B0 0C01C20B */ jal coss +/* 09C0B0 8009B4B0 0C01C20B */ jal coss_s16 /* 09C0B4 8009B4B4 00409825 */ move $s3, $v0 /* 09C0B8 8009B4B8 02740019 */ multu $s3, $s4 /* 09C0BC 8009B4BC 8E050000 */ lw $a1, ($s0) diff --git a/asm/non_matchings/objects/func_8000B38C.s b/asm/non_matchings/objects/func_8000B38C.s index 662ec8fc..b2b51608 100644 --- a/asm/non_matchings/objects/func_8000B38C.s +++ b/asm/non_matchings/objects/func_8000B38C.s @@ -138,7 +138,7 @@ glabel func_8000B38C .L8000B5A8: /* 00C1A8 8000B5A8 00112400 */ sll $a0, $s1, 0x10 /* 00C1AC 8000B5AC 0004C403 */ sra $t8, $a0, 0x10 -/* 00C1B0 8000B5B0 0C01C20C */ jal sins +/* 00C1B0 8000B5B0 0C01C20C */ jal sins_s16 /* 00C1B4 8000B5B4 03002025 */ move $a0, $t8 /* 00C1B8 8000B5B8 00520019 */ multu $v0, $s2 /* 00C1BC 8000B5BC 00112400 */ sll $a0, $s1, 0x10 @@ -147,7 +147,7 @@ glabel func_8000B38C /* 00C1C8 8000B5C8 0000C812 */ mflo $t9 /* 00C1CC 8000B5CC 00197403 */ sra $t6, $t9, 0x10 /* 00C1D0 8000B5D0 01D27821 */ addu $t7, $t6, $s2 -/* 00C1D4 8000B5D4 0C01C20B */ jal coss +/* 00C1D4 8000B5D4 0C01C20B */ jal coss_s16 /* 00C1D8 8000B5D8 AE0F0000 */ sw $t7, ($s0) /* 00C1DC 8000B5DC 02C20019 */ multu $s6, $v0 /* 00C1E0 8000B5E0 8E190000 */ lw $t9, ($s0) diff --git a/generate_ld.sh b/generate_ld.sh deleted file mode 100755 index 7e6017fb..00000000 --- a/generate_ld.sh +++ /dev/null @@ -1,7 +0,0 @@ -if [[ $# == 0 || (($1 != "us_1.0") && ($1 != "us_1.1") && ($1 != "eu_1.0") && ($1 != "eu_1.1") && ($1 != "jp"))]]; then - echo 'Usage: ./generate_ld.sh ' - echo 'Acceptable versions: us_1.0, us_1.1, eu_1.0, eu_1.1, jp' - exit 1 -fi - -python3 ./tools/python/generate_ld.py "$1" diff --git a/include/PR/R4300.h b/include/PR/R4300.h index 932694d3..fd70d07f 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: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/R4300.h,v $ * **************************************************************************/ diff --git a/include/PR/abi.h b/include/PR/abi.h index e783c433..e1215260 100644 --- a/include/PR/abi.h +++ b/include/PR/abi.h @@ -1,16 +1,16 @@ #ifndef _ABI_H_ -#define _ABI_H_ +#define _ABI_H_ /************************************************************************** - * * - * Copyright (C) 1994, Silicon Graphics, Inc. * - * * + * * + * 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. * - * * + * * **************************************************************************/ /************************************************************************** @@ -31,19 +31,19 @@ */ /* Audio commands: */ -#define A_SPNOOP 0 -#define A_ADPCM 1 -#define A_CLEARBUFF 2 -#define A_ENVMIXER 3 -#define A_LOADBUFF 4 -#define A_RESAMPLE 5 -#define A_SAVEBUFF 6 -#define A_SEGMENT 7 -#define A_SETBUFF 8 -#define A_SETVOL 9 +#define A_SPNOOP 0 +#define A_ADPCM 1 +#define A_CLEARBUFF 2 +#define A_ENVMIXER 3 +#define A_LOADBUFF 4 +#define A_RESAMPLE 5 +#define A_SAVEBUFF 6 +#define A_SEGMENT 7 +#define A_SETBUFF 8 +#define A_SETVOL 9 #define A_DMEMMOVE 10 #define A_LOADADPCM 11 -#define A_MIXER 12 +#define A_MIXER 12 #define A_INTERLEAVE 13 #define A_POLEF 14 #define A_SETLOOP 15 @@ -53,18 +53,18 @@ * Audio flags */ -#define A_INIT 0x01 -#define A_CONTINUE 0x00 +#define A_INIT 0x01 +#define A_CONTINUE 0x00 #define A_LOOP 0x02 #define A_OUT 0x02 -#define A_LEFT 0x02 -#define A_RIGHT 0x00 -#define A_VOL 0x04 -#define A_RATE 0x00 -#define A_AUX 0x08 -#define A_NOAUX 0x00 -#define A_MAIN 0x00 -#define A_MIX 0x10 +#define A_LEFT 0x02 +#define A_RIGHT 0x00 +#define A_VOL 0x04 +#define A_RATE 0x00 +#define A_AUX 0x08 +#define A_NOAUX 0x00 +#define A_MAIN 0x00 +#define A_MIX 0x10 /* * BEGIN C-specific section: (typedef's) @@ -76,134 +76,134 @@ */ typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int gain:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int gain:16; + unsigned int addr; } Aadpcm; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int gain:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int gain:16; + unsigned int addr; } Apolef; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int pad1:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int pad1:16; + unsigned int addr; } Aenvelope; typedef struct { - unsigned int cmd:8; - unsigned int pad1:8; - unsigned int dmem:16; - unsigned int pad2:16; - unsigned int count:16; + unsigned int cmd:8; + unsigned int pad1:8; + unsigned int dmem:16; + unsigned int pad2:16; + unsigned int count:16; } Aclearbuff; typedef struct { - unsigned int cmd:8; - unsigned int pad1:8; - unsigned int pad2:16; - unsigned int inL:16; - unsigned int inR:16; + unsigned int cmd:8; + unsigned int pad1:8; + unsigned int pad2:16; + unsigned int inL:16; + unsigned int inR:16; } Ainterleave; typedef struct { - unsigned int cmd:8; - unsigned int pad1:24; - unsigned int addr; + unsigned int cmd:8; + unsigned int pad1:24; + unsigned int addr; } Aloadbuff; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int pad1:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int pad1:16; + unsigned int addr; } Aenvmixer; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int gain:16; - unsigned int dmemi:16; - unsigned int dmemo:16; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int gain:16; + unsigned int dmemi:16; + unsigned int dmemo:16; } Amixer; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int dmem2:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int dmem2:16; + unsigned int addr; } Apan; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int pitch:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int pitch:16; + unsigned int addr; } Aresample; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int pad1:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int pad1:16; + unsigned int addr; } Areverb; typedef struct { - unsigned int cmd:8; - unsigned int pad1:24; - unsigned int addr; + unsigned int cmd:8; + unsigned int pad1:24; + unsigned int addr; } Asavebuff; typedef struct { - unsigned int cmd:8; - unsigned int pad1:24; - unsigned int pad2:2; - unsigned int number:4; - unsigned int base:24; + unsigned int cmd:8; + unsigned int pad1:24; + unsigned int pad2:2; + unsigned int number:4; + unsigned int base:24; } Asegment; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int dmemin:16; - unsigned int dmemout:16; - unsigned int count:16; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int dmemin:16; + unsigned int dmemout:16; + unsigned int count:16; } Asetbuff; typedef struct { - unsigned int cmd:8; - unsigned int flags:8; - unsigned int vol:16; - unsigned int voltgt:16; - unsigned int volrate:16; + unsigned int cmd:8; + unsigned int flags:8; + unsigned int vol:16; + unsigned int voltgt:16; + unsigned int volrate:16; } Asetvol; typedef struct { - unsigned int cmd:8; - unsigned int pad1:8; - unsigned int dmemin:16; - unsigned int dmemout:16; - unsigned int count:16; + unsigned int cmd:8; + unsigned int pad1:8; + unsigned int dmemin:16; + unsigned int dmemout:16; + unsigned int count:16; } Admemmove; typedef struct { - unsigned int cmd:8; - unsigned int pad1:8; - unsigned int count:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int pad1:8; + unsigned int count:16; + unsigned int addr; } Aloadadpcm; typedef struct { - unsigned int cmd:8; - unsigned int pad1:8; - unsigned int pad2:16; - unsigned int addr; + unsigned int cmd:8; + unsigned int pad1:8; + unsigned int pad2:16; + unsigned int addr; } Asetloop; /* @@ -211,32 +211,30 @@ typedef struct { */ typedef struct { - uintptr_t w0; - uintptr_t w1; + unsigned int w0; + unsigned int w1; } Awords; typedef union { - Awords words; -#if IS_BIG_ENDIAN && !IS_64_BIT - Aadpcm adpcm; - Apolef polef; - Aclearbuff clearbuff; - Aenvelope envelope; - Ainterleave interleave; - Aloadbuff loadbuff; - Aenvmixer envmixer; - Aresample resample; - Areverb reverb; - Asavebuff savebuff; - Asegment segment; - Asetbuff setbuff; - Asetvol setvol; - Admemmove dmemmove; - Aloadadpcm loadadpcm; - Amixer mixer; - Asetloop setloop; -#endif - long long int force_union_align; /* dummy, force alignment */ + Awords words; + Aadpcm adpcm; + Apolef polef; + Aclearbuff clearbuff; + Aenvelope envelope; + Ainterleave interleave; + Aloadbuff loadbuff; + Aenvmixer envmixer; + Aresample resample; + Areverb reverb; + Asavebuff savebuff; + Asegment segment; + Asetbuff setbuff; + Asetvol setvol; + Admemmove dmemmove; + Aloadadpcm loadadpcm; + Amixer mixer; + Asetloop setloop; + long long int force_union_align; /* dummy, force alignment */ } Acmd; /* @@ -260,7 +258,7 @@ typedef short RESAMPLE_STATE[16]; * Resampler constants */ #define UNITY_PITCH 0x8000 -#define MAX_RATIO 1.99996 /* within .03 cents of +1 octave */ +#define MAX_RATIO 1.99996 /* within .03 cents of +1 octave */ /* * Enveloper/Mixer state @@ -271,354 +269,142 @@ typedef short ENVMIX_STATE[40]; * Macros to assemble the audio command list */ -/* - * Info about parameters: - * - * A "count" in the following macros is always measured in bytes. - * - * All volumes/gains are in Q1.15 signed fixed point numbers: - * 0x8000 is the minimum volume (-100%), negating the audio curve. - * 0x0000 is silent. - * 0x7fff is maximum volume (99.997%). - * - * All DRAM addresses refer to segmented addresses. A segment table shall - * first be set up by calling aSegment for each segment. When a DRAM - * address is later used as parameter, the 8 high bits will be an index - * to the segment table and the lower 24 bits are added to the base address - * stored in the segment table for this entry. The result is the physical address. - * - * Transfers to/from DRAM are executed using DMA and hence follow these restrictions: - * All DRAM addresses should be aligned by 8 bytes, or they will be - * rounded down to the nearest multiple of 8 bytes. - * All DRAM lengths should be aligned by 8 bytes, or they will be - * rounded up to the nearest multiple of 8 bytes. - */ - -/* - * Decompresses ADPCM data. - * Possible flags: A_INIT and A_LOOP. - * - * First set up internal data in DMEM: - * aLoadADPCM(cmd++, nEntries * 16, physicalAddressOfBook) - * aSetLoop(cmd++, physicalAddressOfLoopState) (if A_LOOP is set) - * - * Then before this command, call: - * aSetBuffer(cmd++, 0, in, out, count) - * - * Note: count will be rounded up to the nearest multiple of 32 bytes. - * - * ADPCM decompression works on a block of 16 (uncompressed) samples. - * The previous 2 samples and 9 bytes of input are decompressed to - * 16 new samples using the code book previously loaded. - * - * Before the algorithm starts, the previous 16 samples are loaded according to flag: - * A_INIT: all zeros - * A_LOOP: the address set by aSetLoop - * no flags: the DRAM address in the s parameter - * These 16 samples are immediately copied to the destination address. - * - * The result of "count" bytes will be written after these 16 initial samples. - * The last 16 samples written to the destination will also be written to - * the state address in DRAM. - */ -#define aADPCMdec(pkt, f, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_ADPCM, 24, 8) | _SHIFTL(f, 16, 8); \ - _a->words.w1 = (uintptr_t)(s); \ +#define aADPCMdec(pkt, f, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_ADPCM, 24, 8) | _SHIFTL(f, 16, 8); \ + _a->words.w1 = (unsigned int)(s); \ } -/* - * Not used in SM64. - */ -#define aPoleFilter(pkt, f, g, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_POLEF, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(g, 0, 16)); \ - _a->words.w1 = (uintptr_t)(s); \ +#define aPoleFilter(pkt, f, g, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_POLEF, 24, 8) | _SHIFTL(f, 16, 8) | \ + _SHIFTL(g, 0, 16)); \ + _a->words.w1 = (unsigned int)(s); \ } -/* - * Clears DMEM data, where d is address and c is count, by writing zeros. - * - * Note: c is rounded up to the nearest multiple of 16 bytes. - */ -#define aClearBuffer(pkt, d, c) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_CLEARBUFF, 24, 8) | _SHIFTL(d, 0, 24); \ - _a->words.w1 = (uintptr_t)(c); \ +#define aClearBuffer(pkt, d, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_CLEARBUFF, 24, 8) | _SHIFTL(d, 0, 24); \ + _a->words.w1 = (unsigned int)(c); \ } -/* - * Mixes an envelope with mono sound into 2 or 4 channels. - * Possible flags: A_INIT, A_AUX (indicates that 4 channels should be used). - * - * Before this command, call: - * aSetBuffer(cmd++, 0, inBuf, dryLeft, count) - * aSetBuffer(cmd++, A_AUX, dryRight, wetLeft, wetRight) - * - * The first time (A_INIT is set), volume also needs to be set: - * aSetVolume(cmd++, A_VOL | A_LEFT, initialVolumeLeft, 0, 0) - * aSetVolume(cmd++, A_VOL | A_RIGHT, initialVolumeRight, 0, 0) - * aSetVolume32(cmd++, A_RATE | A_LEFT, targetVolumeLeft, rampLeft) - * aSetVolume32(cmd++, A_RATE | A_RIGHT, targetVolumeRight, rampRight) - * aSetVolume(cmd++, A_AUX, dryVolume, 0, wetVolume) - * - * This command will now mix samples in inBuf into the destination buffers (dry and wet), - * but with the volume increased (or decreased) from initial volumes to target volumes, - * with the specified ramp rate. Once the target volume is reached, the volume stays - * at that level. Before the samples are finally mixed (added) into the destination - * buffers (dry and wet), the volume is changed according to dryVolume and wetVolume. - * - * Note: count will be rounded up to the nearest multiple of 16 bytes. - * Note: the wet channels are used for reverb. - * - */ -#define aEnvMixer(pkt, f, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_ENVMIXER, 24, 8) | _SHIFTL(f, 16, 8); \ - _a->words.w1 = (uintptr_t)(s); \ +#define aEnvMixer(pkt, f, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_ENVMIXER, 24, 8) | _SHIFTL(f, 16, 8); \ + _a->words.w1 = (unsigned int)(s); \ } -/* - * Interleaves two mono channels into stereo. - * - * First call: - * aSetBuffer(cmd++, 0, 0, output, count) - * - * The count refers to the size of the output. - * A left sample will be placed before the right sample. - * - * Note: count will be rounded up to the nearest multiple of 16 bytes. - */ -#define aInterleave(pkt, l, r) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_INTERLEAVE, 24, 8); \ - _a->words.w1 = _SHIFTL(l, 16, 16) | _SHIFTL(r, 0, 16); \ +#define aInterleave(pkt, l, r) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_INTERLEAVE, 24, 8); \ + _a->words.w1 = _SHIFTL(l, 16, 16) | _SHIFTL(r, 0, 16); \ } -/* - * Loads a buffer from DRAM to DMEM. - * - * First call: - * aSetBuffer(cmd++, 0, in, 0, count) - * - * The in parameter to aSetBuffer is the destination in DMEM and the - * s parameter to this command is the source in DRAM. - */ -#define aLoadBuffer(pkt, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_LOADBUFF, 24, 8); \ - _a->words.w1 = (uintptr_t)(s); \ +#define aLoadBuffer(pkt, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_LOADBUFF, 24, 8); \ + _a->words.w1 = (unsigned int)(s); \ } -/* - * Mixes audio. - * Possible flags: no flags used, although parameter present. - * - * First call: - * aSetBuffer(cmd++, 0, 0, 0, count) - * - * Input and output addresses are taken from the i and o parameters. - * The volume with which the input is changed is taken from the g parameter. - * After the volume of the input samples have been changed, the result - * is added to the output. - * - * Note: count will be rounded up to the nearest multiple of 32 bytes. - */ -#define aMix(pkt, f, g, i, o) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_MIXER, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(g, 0, 16)); \ - _a->words.w1 = _SHIFTL(i,16, 16) | _SHIFTL(o, 0, 16); \ +#define aMix(pkt, f, g, i, o) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_MIXER, 24, 8) | _SHIFTL(f, 16, 8) | \ + _SHIFTL(g, 0, 16)); \ + _a->words.w1 = _SHIFTL(i,16, 16) | _SHIFTL(o, 0, 16); \ } -// Not present in the audio microcode. -#define aPan(pkt, f, d, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_PAN, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(d, 0, 16)); \ - _a->words.w1 = (uintptr_t)(s); \ +#define aPan(pkt, f, d, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_PAN, 24, 8) | _SHIFTL(f, 16, 8) | \ + _SHIFTL(d, 0, 16)); \ + _a->words.w1 = (unsigned int)(s); \ } -/* - * Resamples audio. - * Possible flags: A_INIT, A_OUT? (not used in SM64). - * - * First call: - * aSetBuffer(cmd++, 0, in, out, count) - * - * This command resamples the audio using the given frequency ratio (pitch) - * using a filter that uses a window of 4 source samples. This can be used - * either for just resampling audio to be able to be played back at a different - * sample rate, or to change the pitch if the result is played back at - * the same sample rate as the input. - * - * The frequency ratio is given in UQ1.15 fixed point format. - * For no change in frequency, use pitch 0x8000. - * For 1 octave up or downsampling to (roughly) half number of samples, use pitch 0xffff. - * For 1 octave down or upsampling to double as many samples, use pitch 0x4000. - * - * Note: count represents the number of output samples and is rounded up to - * the nearest multiple of 16 bytes. - * - * The state consists of the four following source samples when the algorithm stopped as - * well as a fractional position, and is initialized to all zeros if A_INIT is given. - * Otherwise it is loaded from DRAM at address s. - * - * The algorithm starts by writing the four source samples from the state (or zero) - * to just before the input address given. It then creates one output sample by examining - * the four next source samples and then moving the source position zero or more - * samples forward. The first output sample (when A_INIT is given) is always 0. - * - * When "count" samples have been written, the following four source samples - * are written to the state in DRAM as well as a fractional position. - */ -#define aResample(pkt, f, p, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_RESAMPLE, 24, 8) | _SHIFTL(f, 16, 8) |\ - _SHIFTL(p, 0, 16)); \ - _a->words.w1 = (uintptr_t)(s); \ +#define aResample(pkt, f, p, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_RESAMPLE, 24, 8) | _SHIFTL(f, 16, 8) |\ + _SHIFTL(p, 0, 16)); \ + _a->words.w1 = (unsigned int)(s); \ } -/* - * Stores a buffer in DMEM to DRAM. - * - * First call: - * aSetBuffer(cmd++, 0, 0, out, count) - * - * The out parameter to aSetBuffer is the source in DMEM and the - * s parameter to this command is the destination in DRAM. - */ -#define aSaveBuffer(pkt, s) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_SAVEBUFF, 24, 8); \ - _a->words.w1 = (uintptr_t)(s); \ +#define aSaveBuffer(pkt, s) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_SAVEBUFF, 24, 8); \ + _a->words.w1 = (unsigned int)(s); \ } -/* - * Sets up an entry in the segment table. - * - * The s parameter is a segment index, 0 to 15. - * The b parameter is the base offset. - */ -#define aSegment(pkt, s, b) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_SEGMENT, 24, 8); \ - _a->words.w1 = _SHIFTL(s, 24, 8) | _SHIFTL(b, 0, 24); \ +#define aSegment(pkt, s, b) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_SEGMENT, 24, 8); \ + _a->words.w1 = _SHIFTL(s, 24, 8) | _SHIFTL(b, 0, 24); \ } -/* - * Sets internal DMEM buffer addresses used for later commands. - * See each command for how to use aSetBuffer. - */ -#define aSetBuffer(pkt, f, i, o, c) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_SETBUFF, 24, 8) | _SHIFTL(f, 16, 8) | \ - _SHIFTL(i, 0, 16)); \ - _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ +#define aSetBuffer(pkt, f, i, o, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_SETBUFF, 24, 8) | _SHIFTL(f, 16, 8) | \ + _SHIFTL(i, 0, 16)); \ + _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ } -/* - * Sets internal volume parameters. - * See aEnvMixer for more info. - */ -#define aSetVolume(pkt, f, v, t, r) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_SETVOL, 24, 8) | _SHIFTL(f, 16, 16) | \ - _SHIFTL(v, 0, 16)); \ - _a->words.w1 = _SHIFTL(t, 16, 16) | _SHIFTL(r, 0, 16); \ +#define aSetVolume(pkt, f, v, t, r) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = (_SHIFTL(A_SETVOL, 24, 8) | _SHIFTL(f, 16, 16) | \ + _SHIFTL(v, 0, 16)); \ + _a->words.w1 = _SHIFTL(t, 16, 16) | _SHIFTL(r, 0, 16); \ } -/* - * Sets the address to ADPCM loop state. - * - * The a parameter is a DRAM address. - * See aADPCMdec for more info. - */ #define aSetLoop(pkt, a) \ { \ Acmd *_a = (Acmd *)pkt; \ _a->words.w0 = _SHIFTL(A_SETLOOP, 24, 8); \ - _a->words.w1 = (uintptr_t)(a); \ + _a->words.w1 = (unsigned int)(a); \ +} + +#define aDMEMMove(pkt, i, o, c) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_DMEMMOVE, 24, 8) | _SHIFTL(i, 0, 24); \ + _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ } -/* - * Copies memory in DMEM. - * - * Copies c bytes from address i to address o. - * - * Note: count is rounded up to the nearest multiple of 16 bytes. - * - * Note: This acts as memcpy where 16 bytes are moved at a time, therefore - * if input and output overlap, output address should be less than input address. - */ -#define aDMEMMove(pkt, i, o, c) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_DMEMMOVE, 24, 8) | _SHIFTL(i, 0, 24); \ - _a->words.w1 = _SHIFTL(o, 16, 16) | _SHIFTL(c, 0, 16); \ -} - -/* - * Loads ADPCM book from DRAM into DMEM. - * - * This command loads ADPCM table entries from DRAM to DMEM. - * - * The count parameter c should be a multiple of 16 bytes. - * The d parameter is a DRAM address. - */ -#define aLoadADPCM(pkt, c, d) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = _SHIFTL(A_LOADADPCM, 24, 8) | _SHIFTL(c, 0, 24); \ - _a->words.w1 = (uintptr_t) d; \ -} - -// This is a version of aSetVolume which takes a single 32-bit parameter -// instead of two 16-bit ones. According to AziAudio, it is used to set -// ramping values when neither bit 4 nor bit 8 is set in the flags parameter. -// It does not appear in the official abi.h header. -/* - * Sets internal volume parameters. - * See aEnvMixer for more info. - */ -#define aSetVolume32(pkt, f, v, tr) \ -{ \ - Acmd *_a = (Acmd *)pkt; \ - \ - _a->words.w0 = (_SHIFTL(A_SETVOL, 24, 8) | _SHIFTL(f, 16, 16) | \ - _SHIFTL(v, 0, 16)); \ - _a->words.w1 = (uintptr_t)(tr); \ +#define aLoadADPCM(pkt, c, d) \ +{ \ + Acmd *_a = (Acmd *)pkt; \ + \ + _a->words.w0 = _SHIFTL(A_LOADADPCM, 24, 8) | _SHIFTL(c, 0, 24); \ + _a->words.w1 = (unsigned int) d; \ } #endif /* _LANGUAGE_C */ #endif /* !_ABI_H_ */ + + + diff --git a/include/PR/gbi.h b/include/PR/gbi.h index ca1f3101..6bb9961d 100644 --- a/include/PR/gbi.h +++ b/include/PR/gbi.h @@ -18,7 +18,7 @@ **************************************************************************/ #ifndef _GBI_H_ -#define _GBI_H_ +#define _GBI_H_ #define F3D_OLD @@ -93,109 +93,109 @@ # ifndef F3DEX_GBI # define F3DEX_GBI # endif -#define G_NOOP 0x00 -#define G_RDPHALF_2 0xf1 -#define G_SETOTHERMODE_H 0xe3 -#define G_SETOTHERMODE_L 0xe2 -#define G_RDPHALF_1 0xe1 -#define G_SPNOOP 0xe0 -#define G_ENDDL 0xdf -#define G_DL 0xde -#define G_LOAD_UCODE 0xdd -#define G_MOVEMEM 0xdc -#define G_MOVEWORD 0xdb -#define G_MTX 0xda +#define G_NOOP 0x00 +#define G_RDPHALF_2 0xf1 +#define G_SETOTHERMODE_H 0xe3 +#define G_SETOTHERMODE_L 0xe2 +#define G_RDPHALF_1 0xe1 +#define G_SPNOOP 0xe0 +#define G_ENDDL 0xdf +#define G_DL 0xde +#define G_LOAD_UCODE 0xdd +#define G_MOVEMEM 0xdc +#define G_MOVEWORD 0xdb +#define G_MTX 0xda #define G_GEOMETRYMODE 0xd9 -#define G_POPMTX 0xd8 -#define G_TEXTURE 0xd7 -#define G_DMA_IO 0xd6 -#define G_SPECIAL_1 0xd5 -#define G_SPECIAL_2 0xd4 -#define G_SPECIAL_3 0xd3 +#define G_POPMTX 0xd8 +#define G_TEXTURE 0xd7 +#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 -#define G_CULLDL 0x03 -#define G_BRANCH_Z 0x04 -#define G_TRI1 0x05 +#define G_VTX 0x01 +#define G_MODIFYVTX 0x02 +#define G_CULLDL 0x03 +#define G_BRANCH_Z 0x04 +#define G_TRI1 0x05 #define G_TRI2 0x06 #define G_QUAD 0x07 #define G_LINE3D 0x08 -#else /* F3DEX_GBI_2 */ +#else /* F3DEX_GBI_2 */ /* DMA commands: */ -#define G_SPNOOP 0 /* handle 0 gracefully */ -#define G_MTX 1 +#define G_SPNOOP 0 /* handle 0 gracefully */ +#define G_MTX 1 #define G_RESERVED0 2 /* not implemeted */ #define G_MOVEMEM 3 /* move a block of memory (up to 4 words) to dmem */ -#define G_VTX 4 +#define G_VTX 4 #define G_RESERVED1 5 /* not implemeted */ -#define G_DL 6 +#define G_DL 6 #define G_RESERVED2 7 /* not implemeted */ #define G_RESERVED3 8 /* not implemeted */ #define G_SPRITE2D_BASE 9 /* sprite command */ /* IMMEDIATE commands: */ -#define G_IMMFIRST -65 -#define G_TRI1 (G_IMMFIRST-0) //0xBF -#define G_CULLDL (G_IMMFIRST-1) //0xBE -#define G_POPMTX (G_IMMFIRST-2) //0xBD -#define G_MOVEWORD (G_IMMFIRST-3) //0xBC -#define G_TEXTURE (G_IMMFIRST-4) //0xBB -#define G_SETOTHERMODE_H (G_IMMFIRST-5) //0xBA -#define G_SETOTHERMODE_L (G_IMMFIRST-6) //0xB9 -#define G_ENDDL (G_IMMFIRST-7) //0xB8 -#define G_SETGEOMETRYMODE (G_IMMFIRST-8) //0xB7 -#define G_CLEARGEOMETRYMODE (G_IMMFIRST-9) //0xB6 -#define G_LINE3D (G_IMMFIRST-10) //0xB5 -#define G_RDPHALF_1 (G_IMMFIRST-11) //0xB4 -#define G_RDPHALF_2 (G_IMMFIRST-12) //0xB3 +#define G_IMMFIRST -65 +#define G_TRI1 (G_IMMFIRST-0) +#define G_CULLDL (G_IMMFIRST-1) +#define G_POPMTX (G_IMMFIRST-2) +#define G_MOVEWORD (G_IMMFIRST-3) +#define G_TEXTURE (G_IMMFIRST-4) +#define G_SETOTHERMODE_H (G_IMMFIRST-5) +#define G_SETOTHERMODE_L (G_IMMFIRST-6) +#define G_ENDDL (G_IMMFIRST-7) +#define G_SETGEOMETRYMODE (G_IMMFIRST-8) +#define G_CLEARGEOMETRYMODE (G_IMMFIRST-9) +#define G_LINE3D (G_IMMFIRST-10) +#define G_RDPHALF_1 (G_IMMFIRST-11) +#define G_RDPHALF_2 (G_IMMFIRST-12) #if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) # define G_MODIFYVTX (G_IMMFIRST-13) # define G_TRI2 (G_IMMFIRST-14) # define G_BRANCH_Z (G_IMMFIRST-15) # define G_LOAD_UCODE (G_IMMFIRST-16) #else -# define G_RDPHALF_CONT (G_IMMFIRST-13) /*0xB2*/ +# define G_RDPHALF_CONT (G_IMMFIRST-13) #endif /* We are overloading 2 of the immediate commands to keep the byte alignment of dmem the same */ -#define G_SPRITE2D_SCALEFLIP (G_IMMFIRST-1) //0xBE -#define G_SPRITE2D_DRAW (G_IMMFIRST-2) //0xBD +#define G_SPRITE2D_SCALEFLIP (G_IMMFIRST-1) +#define G_SPRITE2D_DRAW (G_IMMFIRST-2) /* RDP commands: */ -#define G_NOOP 0xc0 /* 0 */ +#define G_NOOP 0xc0 /* 0 */ -#endif /* F3DEX_GBI_2 */ +#endif /* F3DEX_GBI_2 */ /* RDP commands: */ -#define G_SETCIMG 0xff /* -1 */ -#define G_SETZIMG 0xfe /* -2 */ -#define G_SETTIMG 0xfd /* -3 */ -#define G_SETCOMBINE 0xfc /* -4 */ -#define G_SETENVCOLOR 0xfb /* -5 */ -#define G_SETPRIMCOLOR 0xfa /* -6 */ -#define G_SETBLENDCOLOR 0xf9 /* -7 */ -#define G_SETFOGCOLOR 0xf8 /* -8 */ -#define G_SETFILLCOLOR 0xf7 /* -9 */ -#define G_FILLRECT 0xf6 /* -10 */ -#define G_SETTILE 0xf5 /* -11 */ -#define G_LOADTILE 0xf4 /* -12 */ -#define G_LOADBLOCK 0xf3 /* -13 */ -#define G_SETTILESIZE 0xf2 /* -14 */ -#define G_LOADTLUT 0xf0 /* -16 */ -#define G_RDPSETOTHERMODE 0xef /* -17 */ -#define G_SETPRIMDEPTH 0xee /* -18 */ -#define G_SETSCISSOR 0xed /* -19 */ -#define G_SETCONVERT 0xec /* -20 */ -#define G_SETKEYR 0xeb /* -21 */ -#define G_SETKEYGB 0xea /* -22 */ -#define G_RDPFULLSYNC 0xe9 /* -23 */ -#define G_RDPTILESYNC 0xe8 /* -24 */ -#define G_RDPPIPESYNC 0xe7 /* -25 */ -#define G_RDPLOADSYNC 0xe6 /* -26 */ +#define G_SETCIMG 0xff /* -1 */ +#define G_SETZIMG 0xfe /* -2 */ +#define G_SETTIMG 0xfd /* -3 */ +#define G_SETCOMBINE 0xfc /* -4 */ +#define G_SETENVCOLOR 0xfb /* -5 */ +#define G_SETPRIMCOLOR 0xfa /* -6 */ +#define G_SETBLENDCOLOR 0xf9 /* -7 */ +#define G_SETFOGCOLOR 0xf8 /* -8 */ +#define G_SETFILLCOLOR 0xf7 /* -9 */ +#define G_FILLRECT 0xf6 /* -10 */ +#define G_SETTILE 0xf5 /* -11 */ +#define G_LOADTILE 0xf4 /* -12 */ +#define G_LOADBLOCK 0xf3 /* -13 */ +#define G_SETTILESIZE 0xf2 /* -14 */ +#define G_LOADTLUT 0xf0 /* -16 */ +#define G_RDPSETOTHERMODE 0xef /* -17 */ +#define G_SETPRIMDEPTH 0xee /* -18 */ +#define G_SETSCISSOR 0xed /* -19 */ +#define G_SETCONVERT 0xec /* -20 */ +#define G_SETKEYR 0xeb /* -21 */ +#define G_SETKEYGB 0xea /* -22 */ +#define G_RDPFULLSYNC 0xe9 /* -23 */ +#define G_RDPTILESYNC 0xe8 /* -24 */ +#define G_RDPPIPESYNC 0xe7 /* -25 */ +#define G_RDPLOADSYNC 0xe6 /* -26 */ #define G_TEXRECTFLIP 0xe5 /* -27 */ #define G_TEXRECT 0xe4 /* -28 */ @@ -231,10 +231,10 @@ */ /* 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_FILL_MASK 0x08 +#define G_RDP_TRI_SHADE_MASK 0x04 +#define G_RDP_TRI_TXTR_MASK 0x02 +#define G_RDP_TRI_ZBUFF_MASK 0x01 /* * HACK: @@ -299,19 +299,19 @@ * G_MTX: parameter flags */ #ifdef F3DEX_GBI_2 -# define G_MTX_MODELVIEW 0x00 /* matrix types */ -# define G_MTX_PROJECTION 0x04 -# define G_MTX_MUL 0x00 /* concat or load */ -# define G_MTX_LOAD 0x02 -# define G_MTX_NOPUSH 0x00 /* push or not */ -# define G_MTX_PUSH 0x01 +# define G_MTX_MODELVIEW 0x00 /* matrix types */ +# define G_MTX_PROJECTION 0x04 +# define G_MTX_MUL 0x00 /* concat or load */ +# define G_MTX_LOAD 0x02 +# define G_MTX_NOPUSH 0x00 /* push or not */ +# define G_MTX_PUSH 0x01 #else /* F3DEX_GBI_2 */ -# define G_MTX_MODELVIEW 0x00 /* matrix types */ -# define G_MTX_PROJECTION 0x01 -# define G_MTX_MUL 0x00 /* concat or load */ -# define G_MTX_LOAD 0x02 -# define G_MTX_NOPUSH 0x00 /* push or not */ -# define G_MTX_PUSH 0x04 +# define G_MTX_MODELVIEW 0x00 /* matrix types */ +# define G_MTX_PROJECTION 0x01 +# define G_MTX_MUL 0x00 /* concat or load */ +# define G_MTX_LOAD 0x02 +# define G_MTX_NOPUSH 0x00 /* push or not */ +# define G_MTX_PUSH 0x04 #endif /* F3DEX_GBI_2 */ /* @@ -443,147 +443,118 @@ * G_SETCOMBINE: color combine modes */ /* Color combiner constants: */ -#define G_CCMUX_COMBINED 0 -#define G_CCMUX_TEXEL0 1 -#define G_CCMUX_TEXEL1 2 -#define G_CCMUX_PRIMITIVE 3 -#define G_CCMUX_SHADE 4 -#define G_CCMUX_ENVIRONMENT 5 -#define G_CCMUX_CENTER 6 -#define G_CCMUX_SCALE 6 -#define G_CCMUX_COMBINED_ALPHA 7 -#define G_CCMUX_TEXEL0_ALPHA 8 -#define G_CCMUX_TEXEL1_ALPHA 9 -#define G_CCMUX_PRIMITIVE_ALPHA 10 -#define G_CCMUX_SHADE_ALPHA 11 -#define G_CCMUX_ENV_ALPHA 12 -#define G_CCMUX_LOD_FRACTION 13 -#define G_CCMUX_PRIM_LOD_FRAC 14 -#define G_CCMUX_NOISE 7 -#define G_CCMUX_K4 7 -#define G_CCMUX_K5 15 -#define G_CCMUX_1 6 -#define G_CCMUX_0 31 +#define G_CCMUX_COMBINED 0 +#define G_CCMUX_TEXEL0 1 +#define G_CCMUX_TEXEL1 2 +#define G_CCMUX_PRIMITIVE 3 +#define G_CCMUX_SHADE 4 +#define G_CCMUX_ENVIRONMENT 5 +#define G_CCMUX_CENTER 6 +#define G_CCMUX_SCALE 6 +#define G_CCMUX_COMBINED_ALPHA 7 +#define G_CCMUX_TEXEL0_ALPHA 8 +#define G_CCMUX_TEXEL1_ALPHA 9 +#define G_CCMUX_PRIMITIVE_ALPHA 10 +#define G_CCMUX_SHADE_ALPHA 11 +#define G_CCMUX_ENV_ALPHA 12 +#define G_CCMUX_LOD_FRACTION 13 +#define G_CCMUX_PRIM_LOD_FRAC 14 +#define G_CCMUX_NOISE 7 +#define G_CCMUX_K4 7 +#define G_CCMUX_K5 15 +#define G_CCMUX_1 6 +#define G_CCMUX_0 31 /* Alpha combiner constants: */ -#define G_ACMUX_COMBINED 0 -#define G_ACMUX_TEXEL0 1 -#define G_ACMUX_TEXEL1 2 -#define G_ACMUX_PRIMITIVE 3 -#define G_ACMUX_SHADE 4 -#define G_ACMUX_ENVIRONMENT 5 +#define G_ACMUX_COMBINED 0 +#define G_ACMUX_TEXEL0 1 +#define G_ACMUX_TEXEL1 2 +#define G_ACMUX_PRIMITIVE 3 +#define G_ACMUX_SHADE 4 +#define G_ACMUX_ENVIRONMENT 5 #define G_ACMUX_LOD_FRACTION 0 #define G_ACMUX_PRIM_LOD_FRAC 6 -#define G_ACMUX_1 6 -#define G_ACMUX_0 7 +#define G_ACMUX_1 6 +#define G_ACMUX_0 7 /* typical CC cycle 1 modes */ -#define G_CC_PRIMITIVE 0, 0, 0, PRIMITIVE, 0, 0, 0, PRIMITIVE -#define G_CC_SHADE 0, 0, 0, SHADE, 0, 0, 0, SHADE - -#define G_CC_MODULATEI TEXEL0, 0, SHADE, 0, 0, 0, 0, SHADE -#define G_CC_MODULATEIDECALA TEXEL0, 0, SHADE, 0, 0, 0, 0, TEXEL0 -#define G_CC_MODULATEIFADE TEXEL0, 0, SHADE, 0, 0, 0, 0, ENVIRONMENT - -#define G_CC_MODULATERGB G_CC_MODULATEI -#define G_CC_MODULATERGBDECALA G_CC_MODULATEIDECALA -#define G_CC_MODULATERGBFADE G_CC_MODULATEIFADE - -#define G_CC_MODULATEIA TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0 -#define G_CC_MODULATEIFADEA TEXEL0, 0, SHADE, 0, TEXEL0, 0, ENVIRONMENT, 0 - -#define G_CC_MODULATEFADE TEXEL0, 0, SHADE, 0, ENVIRONMENT, 0, TEXEL0, 0 - -#define G_CC_MODULATERGBA G_CC_MODULATEIA -#define G_CC_MODULATERGBFADEA G_CC_MODULATEIFADEA - -#define G_CC_MODULATEI_PRIM TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE -#define G_CC_MODULATEIA_PRIM TEXEL0, 0, PRIMITIVE, 0, TEXEL0, 0, PRIMITIVE, 0 -#define G_CC_MODULATEIDECALA_PRIM TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, TEXEL0 - -#define G_CC_MODULATERGB_PRIM G_CC_MODULATEI_PRIM -#define G_CC_MODULATERGBA_PRIM G_CC_MODULATEIA_PRIM -#define G_CC_MODULATERGBDECALA_PRIM G_CC_MODULATEIDECALA_PRIM - -#define G_CC_FADE SHADE, 0, ENVIRONMENT, 0, SHADE, 0, ENVIRONMENT, 0 -#define G_CC_FADEA TEXEL0, 0, ENVIRONMENT, 0, TEXEL0, 0, ENVIRONMENT, 0 - -#define G_CC_DECALRGB 0, 0, 0, TEXEL0, 0, 0, 0, SHADE -#define G_CC_DECALRGBA 0, 0, 0, TEXEL0, 0, 0, 0, TEXEL0 -#define G_CC_DECALFADE 0, 0, 0, TEXEL0, 0, 0, 0, ENVIRONMENT - -#define G_CC_DECALFADEA 0, 0, 0, TEXEL0, TEXEL0, 0, ENVIRONMENT, 0 - -#define G_CC_BLENDI ENVIRONMENT, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE -#define G_CC_BLENDIA ENVIRONMENT, SHADE, TEXEL0, SHADE, TEXEL0, 0, SHADE, 0 -#define G_CC_BLENDIDECALA ENVIRONMENT, SHADE, TEXEL0, SHADE, 0, 0, 0, TEXEL0 - -#define G_CC_BLENDRGBA TEXEL0, SHADE, TEXEL0_ALPHA, SHADE, 0, 0, 0, SHADE -#define G_CC_BLENDRGBDECALA TEXEL0, SHADE, TEXEL0_ALPHA, SHADE, 0, 0, 0, TEXEL0 -#define G_CC_BLENDRGBFADEA TEXEL0, SHADE, TEXEL0_ALPHA, SHADE, 0, 0, 0, ENVIRONMENT - -#define G_CC_ADDRGB TEXEL0, 0, TEXEL0, SHADE, 0, 0, 0, SHADE -#define G_CC_ADDRGBDECALA TEXEL0, 0, TEXEL0, SHADE, 0, 0, 0, TEXEL0 -#define G_CC_ADDRGBFADE TEXEL0, 0, TEXEL0, SHADE, 0, 0, 0, ENVIRONMENT - -#define G_CC_REFLECTRGB ENVIRONMENT, 0, TEXEL0, SHADE, 0, 0, 0, SHADE -#define G_CC_REFLECTRGBDECALA ENVIRONMENT, 0, TEXEL0, SHADE, 0, 0, 0, TEXEL0 - -#define G_CC_HILITERGB PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE -#define G_CC_HILITERGBA PRIMITIVE, SHADE, TEXEL0, SHADE, PRIMITIVE, SHADE, TEXEL0, SHADE -#define G_CC_HILITERGBDECALA PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, TEXEL0 - -#define G_CC_SHADEDECALA 0, 0, 0, SHADE, 0, 0, 0, TEXEL0 -#define G_CC_SHADEFADEA 0, 0, 0, SHADE, 0, 0, 0, ENVIRONMENT - -#define G_CC_BLENDPE PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, SHADE, 0 -#define G_CC_BLENDPEDECALA PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, TEXEL0 +#define G_CC_PRIMITIVE 0, 0, 0, PRIMITIVE, 0, 0, 0, PRIMITIVE +#define G_CC_SHADE 0, 0, 0, SHADE, 0, 0, 0, SHADE +#define G_CC_MODULATEI TEXEL0, 0, SHADE, 0, 0, 0, 0, SHADE +#define G_CC_MODULATEIA TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0 +#define G_CC_MODULATEIDECALA TEXEL0, 0, SHADE, 0, 0, 0, 0, TEXEL0 +#define G_CC_MODULATERGB G_CC_MODULATEI +#define G_CC_MODULATERGBA G_CC_MODULATEIA +#define G_CC_MODULATERGBDECALA G_CC_MODULATEIDECALA +#define G_CC_MODULATEI_PRIM TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE +#define G_CC_MODULATEIA_PRIM TEXEL0, 0, PRIMITIVE, 0, TEXEL0, 0, PRIMITIVE, 0 +#define G_CC_MODULATEIDECALA_PRIM TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, TEXEL0 +#define G_CC_MODULATERGB_PRIM G_CC_MODULATEI_PRIM +#define G_CC_MODULATERGBA_PRIM G_CC_MODULATEIA_PRIM +#define G_CC_MODULATERGBDECALA_PRIM G_CC_MODULATEIDECALA_PRIM +#define G_CC_DECALRGB 0, 0, 0, TEXEL0, 0, 0, 0, SHADE +#define G_CC_DECALRGBA 0, 0, 0, TEXEL0, 0, 0, 0, TEXEL0 +#define G_CC_BLENDI ENVIRONMENT, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE +#define G_CC_BLENDIA ENVIRONMENT, SHADE, TEXEL0, SHADE, TEXEL0, 0, SHADE, 0 +#define G_CC_BLENDIDECALA ENVIRONMENT, SHADE, TEXEL0, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_BLENDRGBA TEXEL0, SHADE, TEXEL0_ALPHA, SHADE, 0, 0, 0, SHADE +#define G_CC_BLENDRGBDECALA TEXEL0, SHADE, TEXEL0_ALPHA, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_ADDRGB 1, 0, TEXEL0, SHADE, 0, 0, 0, SHADE +#define G_CC_ADDRGBDECALA 1, 0, TEXEL0, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_REFLECTRGB ENVIRONMENT, 0, TEXEL0, SHADE, 0, 0, 0, SHADE +#define G_CC_REFLECTRGBDECALA ENVIRONMENT, 0, TEXEL0, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_HILITERGB PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE +#define G_CC_HILITERGBA PRIMITIVE, SHADE, TEXEL0, SHADE, PRIMITIVE, SHADE, TEXEL0, SHADE +#define G_CC_HILITERGBDECALA PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_SHADEDECALA 0, 0, 0, SHADE, 0, 0, 0, TEXEL0 +#define G_CC_BLENDPE PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, SHADE, 0 +#define G_CC_BLENDPEDECALA PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, TEXEL0 /* oddball modes */ -#define _G_CC_BLENDPE ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, TEXEL0, 0, SHADE, 0 -#define _G_CC_BLENDPEDECALA ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, 0, 0, 0, TEXEL0 -#define _G_CC_TWOCOLORTEX PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE +#define _G_CC_BLENDPE ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, TEXEL0, 0, SHADE, 0 +#define _G_CC_BLENDPEDECALA ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, 0, 0, 0, TEXEL0 +#define _G_CC_TWOCOLORTEX PRIMITIVE, SHADE, TEXEL0, SHADE, 0, 0, 0, SHADE /* used for 1-cycle sparse mip-maps, primitive color has color of lowest LOD */ -#define _G_CC_SPARSEST PRIMITIVE, TEXEL0, LOD_FRACTION, TEXEL0, PRIMITIVE, TEXEL0, LOD_FRACTION, TEXEL0 -#define G_CC_TEMPLERP TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0, TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0 +#define _G_CC_SPARSEST PRIMITIVE, TEXEL0, LOD_FRACTION, TEXEL0, PRIMITIVE, TEXEL0, LOD_FRACTION, TEXEL0 +#define G_CC_TEMPLERP TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0, TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0 /* typical CC cycle 1 modes, usually followed by other cycle 2 modes */ -#define G_CC_TRILERP TEXEL1, TEXEL0, LOD_FRACTION, TEXEL0, TEXEL1, TEXEL0, LOD_FRACTION, TEXEL0 -#define G_CC_INTERFERENCE TEXEL0, 0, TEXEL1, 0, TEXEL0, 0, TEXEL1, 0 +#define G_CC_TRILERP TEXEL1, TEXEL0, LOD_FRACTION, TEXEL0, TEXEL1, TEXEL0, LOD_FRACTION, TEXEL0 +#define G_CC_INTERFERENCE TEXEL0, 0, TEXEL1, 0, TEXEL0, 0, TEXEL1, 0 /* * One-cycle color convert operation */ -#define G_CC_1CYUV2RGB TEXEL0, K4, K5, TEXEL0, 0, 0, 0, SHADE +#define G_CC_1CYUV2RGB TEXEL0, K4, K5, TEXEL0, 0, 0, 0, SHADE /* * NOTE: YUV2RGB expects TF step1 color conversion to occur in 2nd clock. * Therefore, CC looks for step1 results in TEXEL1 */ -#define G_CC_YUV2RGB TEXEL1, K4, K5, TEXEL1, 0, 0, 0, 0 +#define G_CC_YUV2RGB TEXEL1, K4, K5, TEXEL1, 0, 0, 0, 0 /* typical CC cycle 2 modes */ -#define G_CC_PASS2 0, 0, 0, COMBINED, 0, 0, 0, COMBINED -#define G_CC_MODULATEI2 COMBINED, 0, SHADE, 0, 0, 0, 0, SHADE -#define G_CC_MODULATEIA2 COMBINED, 0, SHADE, 0, COMBINED, 0, SHADE, 0 -#define G_CC_MODULATERGB2 G_CC_MODULATEI2 -#define G_CC_MODULATERGBA2 G_CC_MODULATEIA2 -#define G_CC_MODULATEI_PRIM2 COMBINED, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE -#define G_CC_MODULATEIA_PRIM2 COMBINED, 0, PRIMITIVE, 0, COMBINED, 0, PRIMITIVE, 0 -#define G_CC_MODULATERGB_PRIM2 G_CC_MODULATEI_PRIM2 -#define G_CC_MODULATERGBA_PRIM2 G_CC_MODULATEIA_PRIM2 -#define G_CC_DECALRGB2 0, 0, 0, COMBINED, 0, 0, 0, SHADE +#define G_CC_PASS2 0, 0, 0, COMBINED, 0, 0, 0, COMBINED +#define G_CC_MODULATEI2 COMBINED, 0, SHADE, 0, 0, 0, 0, SHADE +#define G_CC_MODULATEIA2 COMBINED, 0, SHADE, 0, COMBINED, 0, SHADE, 0 +#define G_CC_MODULATERGB2 G_CC_MODULATEI2 +#define G_CC_MODULATERGBA2 G_CC_MODULATEIA2 +#define G_CC_MODULATEI_PRIM2 COMBINED, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE +#define G_CC_MODULATEIA_PRIM2 COMBINED, 0, PRIMITIVE, 0, COMBINED, 0, PRIMITIVE, 0 +#define G_CC_MODULATERGB_PRIM2 G_CC_MODULATEI_PRIM2 +#define G_CC_MODULATERGBA_PRIM2 G_CC_MODULATEIA_PRIM2 +#define G_CC_DECALRGB2 0, 0, 0, COMBINED, 0, 0, 0, SHADE /* * ? #define G_CC_DECALRGBA2 COMBINED, SHADE, COMBINED_ALPHA, SHADE, 0, 0, 0, SHADE */ -#define G_CC_BLENDI2 ENVIRONMENT, SHADE, COMBINED, SHADE, 0, 0, 0, SHADE -#define G_CC_BLENDIA2 ENVIRONMENT, SHADE, COMBINED, SHADE, COMBINED, 0, SHADE, 0 -#define G_CC_CHROMA_KEY2 TEXEL0, CENTER, SCALE, 0, 0, 0, 0, 0 -#define G_CC_HILITERGB2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, SHADE -#define G_CC_HILITERGBA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, ENVIRONMENT, COMBINED, TEXEL0, COMBINED -#define G_CC_HILITERGBDECALA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, TEXEL0 -#define G_CC_HILITERGBPASSA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, COMBINED +#define G_CC_BLENDI2 ENVIRONMENT, SHADE, COMBINED, SHADE, 0, 0, 0, SHADE +#define G_CC_BLENDIA2 ENVIRONMENT, SHADE, COMBINED, SHADE, COMBINED, 0, SHADE, 0 +#define G_CC_CHROMA_KEY2 TEXEL0, CENTER, SCALE, 0, 0, 0, 0, 0 +#define G_CC_HILITERGB2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, SHADE +#define G_CC_HILITERGBA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, ENVIRONMENT, COMBINED, TEXEL0, COMBINED +#define G_CC_HILITERGBDECALA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, TEXEL0 +#define G_CC_HILITERGBPASSA2 ENVIRONMENT, COMBINED, TEXEL0, COMBINED, 0, 0, 0, COMBINED /* * G_SETOTHERMODE_L sft: shift count @@ -933,9 +904,6 @@ CVG_DST_CLAMP | ZMODE_OPA | \ GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) -/* Custom version of RM_AA_ZB_XLU_SURF with Z_UPD */ -#define RM_CUSTOM_AA_ZB_XLU_SURF(clk) \ - RM_AA_ZB_XLU_SURF(clk) | Z_UPD #define G_RM_AA_ZB_OPA_SURF RM_AA_ZB_OPA_SURF(1) @@ -1034,9 +1002,6 @@ #define G_RM_OPA_CI RM_OPA_CI(1) #define G_RM_OPA_CI2 RM_OPA_CI(2) -#define G_RM_CUSTOM_AA_ZB_XLU_SURF RM_CUSTOM_AA_ZB_XLU_SURF(1) -#define G_RM_CUSTOM_AA_ZB_XLU_SURF2 RM_CUSTOM_AA_ZB_XLU_SURF(2) - #define G_RM_FOG_SHADE_A GBL_c1(G_BL_CLR_FOG, G_BL_A_SHADE, G_BL_CLR_IN, G_BL_1MA) #define G_RM_FOG_PRIM_A GBL_c1(G_BL_CLR_FOG, G_BL_A_FOG, G_BL_CLR_IN, G_BL_1MA) @@ -1169,7 +1134,7 @@ typedef struct { * First 8 words are integer portion of the 4x4 matrix * Last 8 words are the fraction portion of the 4x4 matrix */ -typedef s32 Mtx_t[4][4]; +typedef long Mtx_t[4][4]; typedef union { Mtx_t m; @@ -1515,8 +1480,6 @@ typedef union { { {{ {{0,0,0},0,{0,0,0},0,{rightx,righty,rightz},0}}, \ { {{0,0x80,0},0,{0,0x80,0},0,{upx,upy,upz},0}}} } -/* Don't declare these for F3D_OLD to avoid bss reordering */ -#ifndef F3D_OLD /* * Graphics DMA Packet */ @@ -1524,7 +1487,7 @@ typedef struct { int cmd:8; unsigned int par:8; unsigned int len:16; - uintptr_t addr; + unsigned int addr; } Gdma; /* @@ -1609,7 +1572,7 @@ typedef struct { unsigned int siz:2; unsigned int pad:7; unsigned int wd:12; /* really only 10 bits, extra */ - uintptr_t dram; /* to account for 1024 */ + unsigned int dram; /* to account for 1024 */ } Gsetimg; typedef struct { @@ -1689,6 +1652,9 @@ typedef struct { unsigned int dtdy:16;/* Change in T per change in Y */ } Gtexrect; +#define MakeTexRect(xh,yh,flip,tile,xl,yl,s,t,dsdx,dtdy) \ + G_TEXRECT, xh, yh, 0, flip, 0, tile, xl, yl, s, t, dsdx, dtdy + /* * Textured rectangles are 128 bits not 64 bits */ @@ -1698,30 +1664,21 @@ typedef struct { unsigned long w2; unsigned long w3; } TexRect; -#endif - -#define MakeTexRect(xh,yh,flip,tile,xl,yl,s,t,dsdx,dtdy) \ - G_TEXRECT, xh, yh, 0, flip, 0, tile, xl, yl, s, t, dsdx, dtdy /* * Generic Gfx Packet */ typedef struct { - uintptr_t w0; - uintptr_t w1; + unsigned int w0; + unsigned int w1; } Gwords; /* * This union is the fundamental type of the display list. * It is, by law, exactly 64 bits in size. - * - * (Edit: except on 64-bit, where it is exactly 128 bit. On little-endian or - * 64-bit systems, only the 'words' member may be accessed; the rest of the - * structs don't have matching layouts for now.) */ typedef union { Gwords words; -#if !defined(F3D_OLD) && IS_BIG_ENDIAN && !IS_64_BIT Gdma dma; Gtri tri; Gline3D line; @@ -1739,8 +1696,7 @@ typedef union { Gloadtile loadtile; /* use for loadblock also, th is dxt */ Gsettilesize settilesize; Gloadtlut loadtlut; -#endif - long long int force_structure_alignment; + long long int force_structure_alignment; } Gfx; /* @@ -1755,12 +1711,12 @@ typedef union { Gfx *_g = (Gfx *)(pkt); \ \ _g->words.w0 = _SHIFTL((c), 24, 8) | _SHIFTL((l), 0, 24); \ - _g->words.w1 = (uintptr_t)(s); \ + _g->words.w1 = (unsigned int)(s); \ } #define gsDma0p(c, s, l) \ {{ \ - _SHIFTL((c), 24, 8) | _SHIFTL((l), 0, 24), (uintptr_t)(s) \ + _SHIFTL((c), 24, 8) | _SHIFTL((l), 0, 24), (unsigned int)(s) \ }} #define gDma1p(pkt, c, s, l, p) \ @@ -1769,14 +1725,14 @@ typedef union { \ _g->words.w0 = (_SHIFTL((c), 24, 8) | _SHIFTL((p), 16, 8) | \ _SHIFTL((l), 0, 16)); \ - _g->words.w1 = (uintptr_t)(s); \ + _g->words.w1 = (unsigned int)(s); \ } #define gsDma1p(c, s, l, p) \ {{ \ (_SHIFTL((c), 24, 8) | _SHIFTL((p), 16, 8) | \ _SHIFTL((l), 0, 16)), \ - (uintptr_t)(s) \ + (unsigned int)(s) \ }} #define gDma2p(pkt, c, adrs, len, idx, ofs) \ @@ -1784,13 +1740,13 @@ typedef union { Gfx *_g = (Gfx *)(pkt); \ _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 = (uintptr_t)(adrs); \ + _g->words.w1 = (unsigned int)(adrs); \ } #define gsDma2p(c, adrs, len, idx, ofs) \ {{ \ (_SHIFTL((c),24,8)|_SHIFTL(((len)-1)/8,19,5)| \ _SHIFTL((ofs)/8,8,8)|_SHIFTL((idx),0,8)), \ - (uintptr_t)(adrs) \ + (unsigned int)(adrs) \ }} #define gSPNoOp(pkt) gDma0p(pkt, G_SPNOOP, 0, 0) @@ -1821,12 +1777,12 @@ typedef union { Gfx *_g = (Gfx *)(pkt); \ _g->words.w0 = \ _SHIFTL(G_VTX,24,8)|_SHIFTL((n),12,8)|_SHIFTL((v0)+(n),1,7); \ - _g->words.w1 = (uintptr_t)(v); \ + _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)), \ - (uintptr_t)(v) \ + (unsigned int)(v) \ }} #elif (defined(F3DEX_GBI)||defined(F3DLP_GBI)) /* @@ -1891,12 +1847,12 @@ typedef union { Gfx *_g = (Gfx *)(pkt); \ \ _g->words.w0 = _SHIFTL((c), 24, 8); \ - _g->words.w1 = (uintptr_t)(p0); \ + _g->words.w1 = (unsigned int)(p0); \ } #define gsImmp1(c, p0) \ {{ \ - _SHIFTL((c), 24, 8), (uintptr_t)(p0) \ + _SHIFTL((c), 24, 8), (unsigned int)(p0) \ }} #define gImmp2(pkt, c, p0, p1) \ @@ -1933,13 +1889,13 @@ typedef union { \ _g->words.w0 = (_SHIFTL((c), 24, 8) | _SHIFTL((p0), 8, 16) | \ _SHIFTL((p1), 0, 8)); \ - _g->words.w1 = (uintptr_t) (dat); \ + _g->words.w1 = (unsigned int) (dat); \ } #define gsImmp21(c, p0, p1, dat) \ {{ \ _SHIFTL((c), 24, 8) | _SHIFTL((p0), 8, 16) | _SHIFTL((p1), 0, 8),\ - (uintptr_t) (dat) \ + (unsigned int) (dat) \ }} #ifdef F3DEX_GBI_2 @@ -2199,15 +2155,7 @@ typedef union { __gsSP1Triangle_w1f(v00, v01, v02, flag0)), \ __gsSP1Triangle_w1f(v10, v11, v12, flag1) \ }} -#else -#define gSP2Triangles(pkt, v00, v01, v02, flag0, v10, v11, v12, flag1) \ -{ \ - gSP1Triangle(pkt, v00, v01, v02, flag0); \ - gSP1Triangle(pkt, v10, v11, v12, flag1); \ -} -#define gsSP2Triangles(v00, v01, v02, flag0, v10, v11, v12, flag1) \ - gsSP1Triangle(v00, v01, v02, flag0), \ - gsSP1Triangle(v10, v11, v12, flag1) + #endif /* F3DEX_GBI/F3DLP_GBI */ #if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) @@ -2386,7 +2334,7 @@ typedef union { { \ Gfx *_g = (Gfx *)(pkt); \ _g->words.w0 = _SHIFTL(G_RDPHALF_1,24,8); \ - _g->words.w1 = (uintptr_t)(dl); \ + _g->words.w1 = (unsigned int)(dl); \ _g = (Gfx *)(pkt); \ _g->words.w0 = (_SHIFTL(G_BRANCH_Z,24,8)| \ _SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12)); \ @@ -2395,7 +2343,7 @@ typedef union { #define gsSPBranchLessZrg(dl, vtx, zval, near, far, flag, zmin, zmax) \ {{ _SHIFTL(G_RDPHALF_1,24,8), \ - (uintptr_t)(dl), }}, \ + (unsigned int)(dl), }}, \ {{ _SHIFTL(G_BRANCH_Z,24,8)|_SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12),\ G_DEPTOZSrg(zval, near, far, flag, zmin, zmax), }} @@ -2415,7 +2363,7 @@ typedef union { { \ Gfx *_g = (Gfx *)(pkt); \ _g->words.w0 = _SHIFTL(G_RDPHALF_1,24,8); \ - _g->words.w1 = (uintptr_t)(dl); \ + _g->words.w1 = (unsigned int)(dl); \ _g = (Gfx *)(pkt); \ _g->words.w0 = (_SHIFTL(G_BRANCH_Z,24,8)| \ _SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12)); \ @@ -2424,7 +2372,7 @@ typedef union { #define gsSPBranchLessZraw(dl, vtx, zval) \ {{ _SHIFTL(G_RDPHALF_1,24,8), \ - (uintptr_t)(dl), }}, \ + (unsigned int)(dl), }}, \ {{ _SHIFTL(G_BRANCH_Z,24,8)|_SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12),\ (unsigned int)(zval), }} @@ -2438,19 +2386,19 @@ typedef union { { \ Gfx *_g = (Gfx *)(pkt); \ _g->words.w0 = _SHIFTL(G_RDPHALF_1,24,8); \ - _g->words.w1 = (uintptr_t)(uc_dstart); \ + _g->words.w1 = (unsigned int)(uc_dstart); \ _g = (Gfx *)(pkt); \ _g->words.w0 = (_SHIFTL(G_LOAD_UCODE,24,8)| \ _SHIFTL((int)(uc_dsize)-1,0,16)); \ - _g->words.w1 = (uintptr_t)(uc_start); \ + _g->words.w1 = (unsigned int)(uc_start); \ } #define gsSPLoadUcodeEx(uc_start, uc_dstart, uc_dsize) \ {{ _SHIFTL(G_RDPHALF_1,24,8), \ - (uintptr_t)(uc_dstart), }}, \ + (unsigned int)(uc_dstart), }}, \ {{ _SHIFTL(G_LOAD_UCODE,24,8)| \ _SHIFTL((int)(uc_dsize)-1,0,16), \ - (uintptr_t)(uc_start), }} + (unsigned int)(uc_start), }} #define gSPLoadUcode(pkt, uc_start, uc_dstart) \ gSPLoadUcodeEx((pkt), (uc_start), (uc_dstart), SP_UCODE_DATA_SIZE) @@ -2474,14 +2422,14 @@ typedef union { 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 = (uintptr_t)(dram); \ + _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), \ - (uintptr_t)(dram) \ + (unsigned int)(dram) \ }} #define gSPDmaRead(pkt,dmem,dram,size) gSPDma_io((pkt),0,(dmem),(dram),(size)) @@ -2845,22 +2793,22 @@ typedef union { }} #endif -#ifndef F3D_OLD -# define gSPPerspNormalize(pkt, s) gMoveWd(pkt, G_MW_PERSPNORM, 0, (s)) -# define gsSPPerspNormalize(s) gsMoveWd( G_MW_PERSPNORM, 0, (s)) -#else -# define gSPPerspNormalize(pkt, s) \ +#ifdef F3D_OLD +#define gSPPerspNormalize(pkt, s) \ { \ Gfx *_g = (Gfx *)(pkt); \ \ _g->words.w0 = _SHIFTL(G_RDPHALF_1, 24, 8); \ _g->words.w1 = (s); \ } -# define gsSPPerspNormalize(s) \ +#define gsSPPerspNormalize(s) \ {{ \ _SHIFTL(G_RDPHALF_1, 24, 8), \ (s) \ }} +#else +#define gSPPerspNormalize(pkt, s) gMoveWd(pkt, G_MW_PERSPNORM, 0, (s)) +#define gsSPPerspNormalize(s) gsMoveWd( G_MW_PERSPNORM, 0, (s)) #endif #ifdef F3DEX_GBI_2 @@ -2912,7 +2860,7 @@ typedef union { #define gsSPClearGeometryMode(word) gsSPGeometryMode((word),0) #define gSPLoadGeometryMode(pkt, word) gSPGeometryMode((pkt),-1,(word)) #define gsSPLoadGeometryMode(word) gsSPGeometryMode(-1,(word)) -#define gsSPGeometryModeSetFirst(c, s) gsSPGeometryMode(c, s) + #else /* F3DEX_GBI_2 */ #define gSPSetGeometryMode(pkt, word) \ { \ @@ -2939,18 +2887,6 @@ typedef union { {{ \ _SHIFTL(G_CLEARGEOMETRYMODE, 24, 8), (unsigned int)(word) \ }} - -/* - * gsSPGeometryMode - * In Fast3DEX2 it is better to use this, as the RSP geometry mode - * is able to be set and cleared in a single command. - */ -#define gsSPGeometryMode(c, s) \ - gsSPClearGeometryMode(c), \ - gsSPSetGeometryMode(s) -#define gsSPGeometryModeSetFirst(c, s) \ - gsSPSetGeometryMode(s), \ - gsSPClearGeometryMode(c) #endif /* F3DEX_GBI_2 */ #ifdef F3DEX_GBI_2 @@ -3081,14 +3017,14 @@ typedef union { \ _g->words.w0 = _SHIFTL(cmd, 24, 8) | _SHIFTL(fmt, 21, 3) | \ _SHIFTL(siz, 19, 2) | _SHIFTL((width)-1, 0, 12); \ - _g->words.w1 = (uintptr_t)(i); \ + _g->words.w1 = (unsigned int)(i); \ } #define gsSetImage(cmd, fmt, siz, width, i) \ {{ \ _SHIFTL(cmd, 24, 8) | _SHIFTL(fmt, 21, 3) | \ _SHIFTL(siz, 19, 2) | _SHIFTL((width)-1, 0, 12), \ - (uintptr_t)(i) \ + (unsigned int)(i) \ }} #define gDPSetColorImage(pkt, f, s, w, i) gSetImage(pkt, G_SETCIMG, f, s, w, i) @@ -4558,7 +4494,7 @@ typedef union { } #ifdef F3D_OLD -# define gSPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ +#define gSPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ { \ Gfx *_g = (Gfx *)(pkt); \ \ @@ -4623,7 +4559,13 @@ typedef union { gImmp1(pkt, G_RDPHALF_CONT, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))); \ } #else -# define gSPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ +#define gsSPTextureRectangle(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ + {{(_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | _SHIFTL(yh, 0, 12)),\ + (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12))}}, \ + gsImmp1(G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))), \ + gsImmp1(G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))) + +#define gSPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ { \ Gfx *_g = (Gfx *)(pkt); \ \ @@ -4635,14 +4577,8 @@ typedef union { gImmp1(pkt, G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)));\ } -#define gsSPTextureRectangle(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ - {{(_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | _SHIFTL(yh, 0, 12)),\ - (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12))}}, \ - gsImmp1(G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))), \ - gsImmp1(G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))) - /* like gSPTextureRectangle but accepts negative position arguments */ -# define gSPScisTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ +#define gSPScisTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ { \ Gfx *_g = (Gfx *)(pkt); \ \ @@ -4669,14 +4605,14 @@ typedef union { _SHIFTL((dtdy), 0, 16))); \ } -# define gsSPTextureRectangleFlip(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ +#define gsSPTextureRectangleFlip(xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ {{(_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) | \ _SHIFTL(yh, 0, 12)), \ (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | _SHIFTL(yl, 0, 12))}}, \ gsImmp1(G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))), \ gsImmp1(G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))) -# define gSPTextureRectangleFlip(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ +#define gSPTextureRectangleFlip(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ { \ Gfx *_g = (Gfx *)(pkt); \ \ @@ -4688,17 +4624,16 @@ typedef union { gImmp1(pkt, G_RDPHALF_2, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))); \ } #endif - #define gsDPWord(wordhi, wordlo) \ - gsImmp1(G_RDPHALF_1, (uintptr_t)(wordhi)), \ - gsImmp1(G_RDPHALF_2, (uintptr_t)(wordlo)) + gsImmp1(G_RDPHALF_1, (unsigned int)(wordhi)), \ + gsImmp1(G_RDPHALF_2, (unsigned int)(wordlo)) #define gDPWord(pkt, wordhi, wordlo) \ { \ Gfx *_g = (Gfx *)(pkt); \ \ - gImmp1(pkt, G_RDPHALF_1, (uintptr_t)(wordhi)); \ - gImmp1(pkt, G_RDPHALF_2, (uintptr_t)(wordlo)); \ + gImmp1(pkt, G_RDPHALF_1, (unsigned int)(wordhi)); \ + gImmp1(pkt, G_RDPHALF_2, (unsigned int)(wordlo)); \ } #define gDPFullSync(pkt) gDPNoParam(pkt, G_RDPFULLSYNC) diff --git a/include/PR/gt.h b/include/PR/gt.h new file mode 100644 index 00000000..09b6ba2d --- /dev/null +++ b/include/PR/gt.h @@ -0,0 +1,365 @@ + +/* + * 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: gt.h + * Creator: hsa@sgi.com + * Create Date: Thu Oct 12 15:48:14 PDT 1995 + * + * This file defines the GBI for the TURBO 3D graphics microcode. + * The turbo microcode is a special FEATURE-LIMITED microcode designed + * for specific applications. It is not for general use. + * + * (see XXX for more information) + * + */ + +/************************************************************************** + * + * $Revision: 1.16 $ + * $Date: 1998/05/28 00:14:50 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/gt.h,v $ + * + **************************************************************************/ + +#ifndef _GT_H_ +#define _GT_H_ + +/* this file should be #included AFTER gbi.h */ + +#include "sptask.h" + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif /* _LANGUAGE_C_PLUS_PLUS */ + +#include + +/* the following #defines seem out of order, but we need them + * for the microcode. + */ + +/* + * object state field: rendState + * + * This flag word is built up out of the bits from a + * subset of the G_SETGEOMETRYMODE flags from gbi.h. + * + * When each of these bits is '1', the comments below explain + * the effect on the triangles. + */ +#define GT_ZBUFFER G_ZBUFFER +#define GT_TEXTURE G_TEXTURE_ENABLE /* texture ON */ +#define GT_CULL_BACK G_CULL_BACK /* reject backfaces */ +#define GT_SHADING_SMOOTH G_SHADING_SMOOTH /* smooth shade ON */ + +/* + * object state field: textureState + * + * The lower 3 bits of this flag word contain the texture tile number + * to be used. All triangles of an object are rendered with the same + * texture tile. + */ + +/* + * object state field: flag + * + * This is a group of what would be pad bits. We use them for some + * flag bits. + */ +#define GT_FLAG_NOMTX 0x01 /* don't load the matrix */ +#define GT_FLAG_NO_XFM 0x02 /* load vtx, use verbatim */ +#define GT_FLAG_XFM_ONLY 0x04 /* xform vtx, write to *TriN */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* turbo 3D ucode: */ +extern long long int gspTurbo3DTextStart[], gspTurbo3DTextEnd[]; +extern long long int gspTurbo3DDataStart[], gspTurbo3DDataEnd[]; +extern long long int gspTurbo3D_dramTextStart[], gspTurbo3D_dramTextEnd[]; +extern long long int gspTurbo3D_dramDataStart[], gspTurbo3D_dramDataEnd[]; +extern long long int gspTurbo3D_fifoTextStart[], gspTurbo3D_fifoTextEnd[]; +extern long long int gspTurbo3D_fifoDataStart[], gspTurbo3D_fifoDataEnd[]; + +/* + * This is the global state structure. It's definition carefully + * matches the ucode, so if this structure changes, you must also change + * the ucode. + */ +typedef struct { + u16 perspNorm; /* persp normalization */ + u16 pad0; + u32 flag; + Gfx rdpOthermode; + u32 segBases[16]; /* table of segment base addrs (SEE NOTE!) */ + Vp viewport; /* the viewport to use */ + Gfx *rdpCmds; /* block of RDP data, process if !NULL + * block terminated by gDPEndDisplayList() + * (This is a segment address) + */ +} gtGlobState_t; + +/* NOTE: + * Although there are 16 segment table entries, the first one (segment 0) + * is reserved for physical memory mapping. You should not segment 0 + * to anything other than 0x0. + */ + +typedef union { + gtGlobState_t sp; + long long int force_structure_alignment; +} gtGlobState; + + +/* + * This is the 'state' structure associated with each object + * to be rendered. It's definition carefully matches the + * ucode, so if this structure changes, you must also change + * the gtoff.c tool and the ucode. + */ +typedef struct { + u32 renderState; /* render state */ + u32 textureState; /* texture state */ + u8 vtxCount; /* how many verts? */ + u8 vtxV0; /* where to load verts? */ + u8 triCount; /* how many tris? */ + u8 flag; + Gfx *rdpCmds; /* ptr (segment address) to RDP DL */ + Gfx rdpOthermode; + Mtx transform; /* the transform matrix to use */ +} gtState_t; + +typedef union { + gtState_t sp; + long long int force_structure_alignment; +} gtState; + +/* gtStateLite : same as gtState, but no matrix (see flags below) */ +/* this structure must be identical to gtState! (bad) */ +typedef struct { + u32 renderState; /* render state */ + u32 textureState; /* texture state */ + u8 vtxCount; /* how many verts? */ + u8 vtxV0; /* where to load verts? */ + u8 triCount; /* how many tris? */ + u8 flag; + Gfx *rdpCmds; /* ptr (segment address) to RDP DL */ + Gfx rdpOthermode; +} gtStateL_t; + +typedef union { + gtStateL_t sp; + long long int force_structure_alignment; +} gtStateL; + +/* + * The vertex list for the turbo display list uses the + * Vtx struct in gbi.h + * + */ + + +/* + * This structure represents a single triangle, part of the + * triangle list of the object to be rendered. + * + * NOTE: The triangle list MUST be aligned to an 8-byte boundary. + * Since this structure is only 4 bytes, we are REQUIRING that + * this structure only be used as an array of triangles, and we + * depend on the MIPS C compiler (which always aligns arrays to + * 8-byte boundaries). THIS IS DANGEROUS!!!! + * + */ +typedef struct { + u8 v0, v1, v2, flag; /* flag is which one for flat shade */ +} gtTriN; + + +/* + * This structure represents the transformed points. It is the format + * of the points written out when GT_FLAG_XFM_ONLY is set, as well as + * the format expected when GT_FLAG_NO_XFM is used. + * + * NOTE: The size and layout of these points is very similar to Vtx, + * except the screen coordinates overwrite the x,y,z,pad fields. + * (we could consider adding to the Vtx union, but we want to keep + * turbo stuff out of gbi.h) + * + * NOTE: The z is a special format. It can be used to compare vertices + * for sorting, but it should not be used for other purposes. If modified, + * the z-buffer hardware might not understand the data. + * + */ +typedef struct { + short int xscrn; /* x,y screen coordinates are SSSS10.2 */ + short int yscrn; + int zscrn; /* z screen is S15.16 */ + + short int s; /* transformed texture coord, S10.5 */ + short int t; + + u8 r; /* color (or normal) */ + u8 g; + u8 b; + u8 a; +} gtVtxOut_t; + +/* see "Data Structure" comment in gbi.h for information about why + * we use this union. + */ +typedef union { + gtVtxOut_t v; + long long int force_structure_alignment; +} gtVtxOut; + + + +/* + * state field: rdpOthermode + * + * This is one of the trickier state fields. The turbo interface + * requires the RDP othermode command to be cached by the host, + * therefore we provide a different interface in libultra to help cache + * this in the gt state (this word is just bits, you could pack them + * on your own). + * + * gtStateSetOthermode() accomplishs this, taking as arguments + * the state, one of the following mode enums, and a piece of data + * (othermode parameters from gbi.h). + * + * By definition, the othermode word from the gt state structure is sent + * to the RDP *before* any RDP commands from the rdpCmds[] field. The + * othermode is *always* sent. + * + * Stated another way, NONE of the gbi RDP othermode commands equivalent + * to those listed here are allowed in the rdpCmd[] field of the + * gt state structure. + * + * Notice also that many of these commands do not make sense for + * the turbo ucode (they control features not supported, like mip-mapping). + * They are only included here for completeness. + * + */ +typedef enum { + GT_CLEAR, /* special gt mode, clears othermode state */ + GT_ALPHACOMPARE, + GT_ZSRCSEL, + GT_RENDERMODE, + GT_ALPHADITHER, + GT_RGBDITHER, + GT_COMBKEY, + GT_TEXTCONV, + GT_TEXTFILT, + GT_TEXTLUT, + GT_TEXTLOD, + GT_TEXTDETAIL, + GT_TEXTPERSP, + GT_CYCLETYPE, + GT_PIPELINE +} gtStateOthermode_t; + +/* + * This call builds up an othermode command word. The 'mode' is one of + * the above modes, the 'data' field comes from gbi.h, it is the data + * field for the equivalent gbi setothermode macro. + */ +extern void gtStateSetOthermode(Gfx *om, gtStateOthermode_t mode, int data); + +/* + * This call dumps a turbo display list for use with gbi2mem and RSPSIM + */ +#define GT_DUMPTURBO_HANGAFTER 64 +#define GT_DUMPTURBO_NOTEXTURES 128 +extern void gtDumpTurbo(OSTask *tp,u8 flags); + +/* + * Special macros to init othermode words to all 0's, a good default + * value. + */ +#define gDPClearOtherMode(pkt) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_RDPSETOTHERMODE, 24, 8); \ + _g->words.w1 = 0x0; \ +} + +#define gsDPClearOtherMode() \ +{ \ + _SHIFTL(G_RDPSETOTHERMODE, 24, 8), 0x0 \ +} + +/* + * Special macros to end DP blocks (see above). These commands + * generate all 0's, which the turbo ucode looks for. They *aren't* + * real DP commands! + */ +#define gDPEndDisplayList(pkt) gSPNoOp(pkt) +#define gsDPEndDisplayList() gsSPNoOp() + +/* + * This structure is a turbo 'object', the turbo display list is + * simply a list of these. + * + * NOTE: All pointers are segment addresses + * + * NOTE: If (statep->flag & GT_FLAG_XFM_ONLY), the trip field is + * interpreted as a pointer to gtVtxOut[] that can be used to store + * the transformed points. (statep->triCount should be 0, else bad + * things could happen...) + * + * NOTE: If (statep->flag & GT_FLAG_NO_XFM), the vtxp field is + * interpreted as a pointer to gtVtxOut[] that can be used to load + * pre-transformed points. + * + */ +typedef struct { + gtGlobState *gstatep; /* global state, usually NULL */ + gtState *statep; /* if this is NULL, end object processing */ + Vtx *vtxp; /* if this is NULL, use points in buffer */ + gtTriN *trip; /* if this is NULL, use tris in buffer */ +} gtGfx_t; + +typedef union { + gtGfx_t obj; + long long int force_structure_alignment; +} gtGfx; + + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_ASSEMBLY +#include +#endif /* _LANGUAGE_ASSEMBLY */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif /* _LANGUAGE_C_PLUS_PLUS */ + +#ifdef _LANGUAGE_MAKEROM +#endif /* _LANGUAGE_MAKEROM */ + +#endif /* _GT_H_ */ diff --git a/include/PR/gu.h b/include/PR/gu.h index 6527777d..9a2fa2bc 100644 --- a/include/PR/gu.h +++ b/include/PR/gu.h @@ -1,29 +1,270 @@ -#ifndef _ULTRA64_GU_H_ -#define _ULTRA64_GU_H_ +#ifndef _GU_H_ +#define _GU_H_ + +/************************************************************************** + * * + * 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. * + * * + **************************************************************************/ + +/************************************************************************** + * + * $Revision: 1.48 $ + * $Date: 1999/07/13 08:00:20 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/gu.h,v $ + * + **************************************************************************/ #include #include +#include +#include -#define GU_PI 3.1415926 -/* Functions */ - -void guPerspectiveF(float mf[4][4], u16 *perspNorm, float fovy, float aspect, - float near, float far, float scale); -void guPerspective(Mtx *m, u16 *perspNorm, float fovy, float aspect, float near, - float far, float scale); -void guOrtho(Mtx *m, float left, float right, float bottom, float top, - float near, float far, float scale); -void guTranslate(Mtx *m, float x, float y, float z); -void guRotate(Mtx *m, float a, float x, float y, float z); -void guScale(Mtx *m, float x, float y, float z); -void guMtxF2L(float mf[4][4], Mtx *m); -void guMtxIdent(Mtx *m); -void guMtxIdentF(float mf[4][4]); -void guMtxL2F(float mf[4][4], Mtx *m); -void guNormalize(float *, float *, float *); - -/* Used only in Fast3DEX2 */ -void guLookAtReflect (Mtx *m, LookAt *l, float xEye, float yEye, float zEye, - float xAt, float yAt, float zAt, - float xUp, float yUp, float zUp); +#ifndef MAX +#define MAX(a,b) (((a)>(b))?(a):(b)) #endif +#ifndef MIN +#define MIN(a,b) (((a)<(b))?(a):(b)) +#endif + +#define M_PI 3.14159265358979323846 +#define M_DTOR (3.14159265358979323846/180.0) + +#define FTOFIX32(x) (long)((x) * (float)0x00010000) +#define FIX32TOF(x) ((float)(x) * (1.0f / (float)0x00010000)) +#define FTOFRAC8(x) ((int) MIN(((x) * (128.0f)), 127.0f) & 0xff) + +#define FILTER_WRAP 0 +#define FILTER_CLAMP 1 + +#define RAND(x) (guRandom()%x) /* random number between 0 to x */ + +/* + * Data Structures + */ +typedef struct { + unsigned char *base; + int fmt, siz; + int xsize, ysize; + int lsize; + /* current tile info */ + int addr; + int w, h; + int s, t; +} Image; + +typedef struct { + float col[3]; + float pos[3]; + float a1, a2; /* actual color = col/(a1*dist + a2) */ +} PositionalLight; + + +/* + * Function Prototypes + */ + +extern int guLoadTextureBlockMipMap(Gfx **glist, unsigned char *tbuf, Image *im, + unsigned char startTile, unsigned char pal, unsigned char cms, + unsigned char cmt, unsigned char masks, unsigned char maskt, + unsigned char shifts, unsigned char shiftt, unsigned char cfs, + unsigned char cft); + +extern int guGetDPLoadTextureTileSz (int ult, int lrt); +extern void guDPLoadTextureTile (Gfx *glistp, void *timg, + int texl_fmt, int texl_size, + int img_width, int img_height, + int uls, int ult, int lrs, int lrt, + int palette, + int cms, int cmt, + int masks, int maskt, + int shifts, int shiftt); + + +/* + * matrix operations: + * + * The 'F' version is floating point, in case the application wants + * to do matrix manipulations and convert to fixed-point at the last + * minute. + */ +extern void guMtxIdent(Mtx *m); +extern void guMtxIdentF(float mf[4][4]); +extern void guOrtho(Mtx *m, float l, float r, float b, float t, + float n, float f, float scale); +extern void guOrthoF(float mf[4][4], float l, float r, float b, float t, + float n, float f, float scale); +extern void guFrustum(Mtx *m, float l, float r, float b, float t, + float n, float f, float scale); +extern void guFrustumF(float mf[4][4], float l, float r, float b, float t, + float n, float f, float scale); +extern void guPerspective(Mtx *m, u16 *perspNorm, float fovy, + float aspect, float near, float far, float scale); +extern void guPerspectiveF(float mf[4][4], u16 *perspNorm, float fovy, + float aspect, float near, float far, float scale); +extern void guLookAt(Mtx *m, + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp); +extern void guLookAtF(float mf[4][4], float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp); +extern void guLookAtReflect(Mtx *m, LookAt *l, + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp); +extern 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); +extern void guLookAtHilite(Mtx *m, LookAt *l, Hilite *h, + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp, + float xl1, float yl1, float zl1, + float xl2, float yl2, float zl2, + int twidth, int theight); +extern void guLookAtHiliteF(float mf[4][4], LookAt *l, Hilite *h, + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp, + float xl1, float yl1, float zl1, + float xl2, float yl2, float zl2, + int twidth, int theight); +extern void guLookAtStereo(Mtx *m, + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp, + float eyedist); +extern void guLookAtStereoF(float mf[4][4], + float xEye, float yEye, float zEye, + float xAt, float yAt, float zAt, + float xUp, float yUp, float zUp, + float eyedist); +extern void guRotate(Mtx *m, float a, float x, float y, float z); +extern void guRotateF(float mf[4][4], float a, float x, float y, float z); +extern void guRotateRPY(Mtx *m, float r, float p, float y); +extern void guRotateRPYF(float mf[4][4], float r, float p, float h); +extern void guAlign(Mtx *m, float a, float x, float y, float z); +extern void guAlignF(float mf[4][4], float a, float x, float y, float z); +extern void guScale(Mtx *m, float x, float y, float z); +extern void guScaleF(float mf[4][4], float x, float y, float z); +extern void guTranslate(Mtx *m, float x, float y, float z); +extern void guTranslateF(float mf[4][4], float x, float y, float z); +extern void guPosition(Mtx *m, float r, float p, float h, float s, + float x, float y, float z); +extern void guPositionF(float mf[4][4], float r, float p, float h, float s, + float x, float y, float z); +extern void guMtxF2L(float mf[4][4], Mtx *m); +extern void guMtxL2F(float mf[4][4], Mtx *m); +extern void guMtxCatF(float m[4][4], float n[4][4], float r[4][4]); +extern void guMtxCatL(Mtx *m, Mtx *n, Mtx *res); +extern void guMtxXFMF(float mf[4][4], float x, float y, float z, + float *ox, float *oy, float *oz); +extern void guMtxXFML(Mtx *m, float x, float y, float z, + float *ox, float *oy, float *oz); + +/* vector utility: */ +extern void guNormalize(float *x, float *y, float *z); + +/* light utilities: */ +void guPosLight(PositionalLight *pl, Light *l, + float xOb, float yOb, float zOb); +void guPosLightHilite(PositionalLight *pl1, PositionalLight *pl2, + Light *l1, Light *l2, + LookAt *l, Hilite *h, + float xEye, float yEye, float zEye, + float xOb, float yOb, float zOb, + float xUp, float yUp, float zUp, + int twidth, int theight); +extern int guRandom(void); + +/* + * Math functions + */ +extern float sinf(float angle); +extern float cosf(float angle); +extern signed short sins (unsigned short angle); +extern signed short coss (unsigned short angle); +extern float sqrtf(float value); +#if defined(__sgi) && BUILD_VERSION >= VERSION_K +#pragma intrinsic(sqrtf); +#endif + +/* + * Dump routines for low-level display lists + */ +/* flag values for guParseRdpDL() */ +#define GU_PARSERDP_VERBOSE 1 +#define GU_PARSERDP_PRAREA 2 +#define GU_PARSERDP_PRHISTO 4 +#define GU_PARSERDP_DUMPONLY 32 /* doesn't need to be same as */ + /* GU_PARSEGBI_DUMPOLNY, but this */ + /* allows app to use interchangeably */ + +extern void guParseRdpDL(u64 *rdp_dl, u64 nbytes, u8 flags); +extern void guParseString(char *StringPointer, u64 nbytes); + +/* + * NO LONGER SUPPORTED, + * use guParseRdpDL with GU_PARSERDP_DUMPONLY flags + */ +/* extern void guDumpRawRdpDL(u64 *rdp_dl, u64 nbytes); */ + +/* flag values for guBlinkRdpDL() */ +#define GU_BLINKRDP_HILITE 1 +#define GU_BLINKRDP_EXTRACT 2 + +extern void +guBlinkRdpDL(u64 *rdp_dl_in, u64 nbytes_in, + u64 *rdp_dl_out, u64 *nbytes_out, + u32 x, u32 y, u32 radius, + u8 red, u8 green, u8 blue, + u8 flags); + +/* flag values for guParseGbiDL() */ +#define GU_PARSEGBI_ROWMAJOR 1 +#define GU_PARSEGBI_NONEST 2 +#define GU_PARSEGBI_FLTMTX 4 +#define GU_PARSEGBI_SHOWDMA 8 +#define GU_PARSEGBI_ALLMTX 16 +#define GU_PARSEGBI_DUMPONLY 32 +/* +#define GU_PARSEGBI_HANGAFTER 64 +#define GU_PARSEGBI_NOTEXTURES 128 +*/ +extern void guParseGbiDL(u64 *gbi_dl, u32 nbytes, u8 flags); +extern void guDumpGbiDL(OSTask *tp,u8 flags); + +#define GU_PARSE_GBI_TYPE 1 +#define GU_PARSE_RDP_TYPE 2 +#define GU_PARSE_READY 3 +#define GU_PARSE_MEM_BLOCK 4 +#define GU_PARSE_ABI_TYPE 5 +#define GU_PARSE_STRING_TYPE 6 + +typedef struct { + int dataSize; + int dlType; + int flags; + u32 paddr; +} guDLPrintCB; + +void guSprite2DInit(uSprite *SpritePointer, + void *SourceImagePointer, + void *TlutPointer, + int Stride, + int SubImageWidth, + int SubImageHeight, + int SourceImageType, + int SourceImageBitSize, + int SourceImageOffsetS, + int SourceImageOffsetT); + +#endif /* !_GU_H_ */ diff --git a/include/PR/libaudio.h b/include/PR/libaudio.h index a8e0a356..df2e92cf 100644 --- a/include/PR/libaudio.h +++ b/include/PR/libaudio.h @@ -1,13 +1,40 @@ -#ifndef _ULTRA64_LIBAUDIO_H_ -#define _ULTRA64_LIBAUDIO_H_ +/*==================================================================== + * libaudio.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. + *====================================================================*/ + +/************************************************************************** + * + * $Revision: 1.173 $ + * $Date: 1997/12/01 12:42:21 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/libaudio.h,v $ + * + **************************************************************************/ + +#ifndef __LIB_AUDIO__ +#define __LIB_AUDIO__ #ifdef _LANGUAGE_C_PLUS_PLUS extern "C" { #endif -#include "ultratypes.h" -#include "mbi.h" -#include "abi.h" +#include +#include /*********************************************************************** * misc defines @@ -88,7 +115,6 @@ typedef struct ALLink_s { struct ALLink_s *prev; } ALLink; - void alUnlink(ALLink *element); void alLink(ALLink *element, ALLink *after); @@ -108,7 +134,10 @@ typedef struct { #define AL_HEAP_MAGIC 0x20736a73 #define AL_HEAP_INIT 0 -void *alHeapDBAlloc(u8 *file, s32 line, ALHeap *hp, s32 num, s32 size); +void alHeapInit(ALHeap *hp, u8 *base, s32 len); +void *alHeapDBAlloc(u8 *file, s32 line, ALHeap *hp, s32 num, s32 size); +s32 alHeapCheck(ALHeap *hp); + #ifdef _DEBUG #define alHeapAlloc(hp, elem ,size) alHeapDBAlloc((u8 *) __FILE__,__LINE__,(hp),(elem),(size)) #else @@ -222,7 +251,6 @@ typedef struct { ALSound *soundArray[1]; } ALInstrument; -/* Size: 0x10 bytes */ typedef struct ALBank_s { s16 instCount; /* number of programs in this bank */ u8 flags; @@ -238,6 +266,7 @@ typedef struct { /* Note: sizeof won't be correct */ ALBank *bankArray[1]; /* ARRAY of bank offsets */ } ALBankFile; +void alBnkfNew(ALBankFile *f, u8 *table); /*********************************************************************** * Sequence Files @@ -255,6 +284,7 @@ typedef struct { /* Note: sizeof won't be correct */ ALSeqData seqArray[1]; /* ARRAY of sequence info */ } ALSeqFile; +void alSeqFileNew(ALSeqFile *f, u8 *base); /*********************************************************************** * Synthesis driver stuff @@ -273,7 +303,6 @@ typedef struct { s32 *params; } ALSynConfig; -/* Size: 0x14 bytes */ typedef struct ALPlayer_s { struct ALPlayer_s *next; void *clientData; /* storage for client callback */ @@ -299,7 +328,6 @@ typedef struct ALVoiceConfig_s { u8 unityPitch; /* unity pitch flag */ } ALVoiceConfig; -/* Size: 0x4C bytes */ typedef struct { ALPlayer *head; /* client list head */ ALLink pFreeList; /* list of free physical voices */ @@ -350,7 +378,6 @@ ALFxRef alSynGetFXRef(ALSynth *s, s16 bus, s16 index); void alSynFreeFX(ALSynth *s, ALFxRef *fx); void alSynSetFXParam(ALSynth *s, ALFxRef fx, s16 paramID, void *param); - /*********************************************************************** * Audio Library (AL) stuff ***********************************************************************/ @@ -360,6 +387,11 @@ typedef struct { extern ALGlobals *alGlobals; +void alInit(ALGlobals *glob, ALSynConfig *c); +void alClose(ALGlobals *glob); + +Acmd *alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen); + /*********************************************************************** * Sequence Player stuff ***********************************************************************/ @@ -468,7 +500,10 @@ enum AL_MIDIctrl { AL_MIDI_FX_CTRL_9 = 0x1D, AL_MIDI_SUSTAIN_CTRL = 0x40, AL_MIDI_FX1_CTRL = 0x5B, - AL_MIDI_FX3_CTRL = 0x5D + AL_MIDI_FX3_CTRL = 0x5D, + AL_MIDI_UNK_5F = 0x5F, + AL_MIDI_UNK_6A = 0x6A, /* channel off? */ + AL_MIDI_UNK_6C = 0x6C /* channel on? */ }; enum AL_MIDImeta { @@ -556,7 +591,6 @@ typedef struct { u8 chan; } ALOscEvent; -/* Size: 0x10 bytes */ typedef struct { s16 type; union { @@ -567,9 +601,9 @@ typedef struct { ALVolumeEvent vol; ALSeqpLoopEvent loop; ALSeqpVolEvent spvol; - ALSeqpPriorityEvent sppriority; - ALSeqpSeqEvent spseq; - ALSeqpBankEvent spbank; + ALSeqpPriorityEvent sppriority; + ALSeqpSeqEvent spseq; + ALSeqpBankEvent spbank; ALOscEvent osc; } msg; } ALEvent; @@ -580,7 +614,6 @@ typedef struct { ALEvent evt; } ALEventListItem; -/* Size: 0x14 bytes */ typedef struct { ALLink freeList; ALLink allocList; @@ -595,6 +628,7 @@ void alEvtqPostEvent(ALEventQueue *evtq, ALEvent *evt, void alEvtqFlush(ALEventQueue *evtq); void alEvtqFlushType(ALEventQueue *evtq, s16 type); + #define AL_PHASE_ATTACK 0 #define AL_PHASE_NOTEON 0 #define AL_PHASE_DECAY 1 @@ -632,7 +666,7 @@ typedef struct { f32 pitchBend; /* current pitch bend val in cents */ } ALChanState; -// Can't just replace the original with this, because alCSPGetChlVol won't match. +/* Can't just replace the original with this, because alCSPGetChlVol won't match. */ typedef struct { ALInstrument *instrument; /* instrument assigned to this chan */ s16 bendRange; /* pitch bend range in cents */ @@ -647,7 +681,6 @@ typedef struct { u8 unk11; } ALChanState_Custom; -/* Size: 0x1C bytes */ typedef struct ALSeq_s { u8 *base; /* ptr to start of sequence file */ u8 *trackStart; /* ptr to first MIDI event */ @@ -664,7 +697,6 @@ typedef struct { u32 division; } ALCMidiHdr; -/* size 0x20 */ typedef struct ALCSeq_s { ALCMidiHdr *base; /* ptr to start of sequence file */ u32 validTracks; /* set of flags, showing valid tracks */ @@ -713,72 +745,66 @@ typedef ALMicroTime (*ALOscInit)(void **oscState,f32 *initVal, u8 oscType, typedef ALMicroTime (*ALOscUpdate)(void *oscState, f32 *updateVal); typedef void (*ALOscStop)(void *oscState); -/** - * Has an extra two bytes for the voice limit not found in standard implementations - * Size: 0x92 */ typedef struct { - /* 0x00 */ ALPlayer node; /* note: must be first in structure */ - /* 0x14 */ ALSynth *drvr; /* reference to the client driver */ - /* 0x18 */ ALSeq *target; /* current sequence */ - /* 0x1C */ ALMicroTime curTime; - /* 0x20 */ ALBank *bank; /* current ALBank */ - /* 0x24 */ s32 uspt; /* microseconds per tick */ - /* 0x28 */ s32 nextDelta; /* microseconds to next callback */ - /* 0x2C */ s32 state; - /* 0x30 */ u16 chanMask; /* active channels */ - /* 0x32 */ s16 vol; /* overall sequence volume */ - /* 0x34 */ u8 maxChannels; /* number of MIDI channels */ - /* 0x35 */ u8 debugFlags; /* control which error get reported */ - /* 0x36 */ ALEvent nextEvent; - /* 0x48 */ ALEventQueue evtq; - /* 0x5C */ ALMicroTime frameTime; - /* 0x60 */ ALChanState *chanState; /* 16 channels for MIDI */ - /* 0x64 */ ALVoiceState *vAllocHead; /* list head for allocated voices */ - /* 0x68 */ ALVoiceState *vAllocTail; /* list tail for allocated voices */ - /* 0x6C */ ALVoiceState *vFreeList; /* list of free voice state structs */ - /* 0x70 */ u8 voiceLimit; - /* 0x71 */ u8 mappedVoices; - /* 0x72 */ u16 unk72; /* Might just be padding? */ - /* 0x74 */ ALOscInit initOsc; - /* 0x78 */ ALOscUpdate updateOsc; - /* 0x7C */ ALOscStop stopOsc; - /* 0x80 */ ALSeqMarker *loopStart; - /* 0x84 */ ALSeqMarker *loopEnd; - /* 0x88 */ s32 loopCount; /* -1 = loop forever, 0 = no loop */ + ALPlayer node; /* note: must be first in structure */ + 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 */ + ALEvent nextEvent; + ALEventQueue evtq; + ALMicroTime frameTime; + ALChanState *chanState; /* 16 channels for MIDI */ + ALVoiceState *vAllocHead; /* list head for allocated voices */ + ALVoiceState *vAllocTail; /* list tail for allocated voices */ + ALVoiceState *vFreeList; /* list of free voice state structs */ + u8 voiceLimit; + u8 mappedVoices; + u16 unk72; /* Might just be padding? */ + ALOscInit initOsc; + ALOscUpdate updateOsc; + ALOscStop stopOsc; + ALSeqMarker *loopStart; + ALSeqMarker *loopEnd; + s32 loopCount; /* -1 = loop forever, 0 = no loop */ } ALSeqPlayer; -/** - * This struct was modified by Rare with a few new fields - * Size: 0x80 bytes */ typedef struct { - /* 0x00 */ ALPlayer node; /* note: must be first in structure */ - /* 0x14 */ ALSynth *drvr; /* reference to the client driver */ - /* 0x18 */ ALCSeq *target; /* current sequence */ - /* 0x1C */ ALMicroTime curTime; - /* 0x20 */ ALBank *bank; /* current ALBank */ - /* 0x24 */ s32 uspt; /* microseconds per tick */ - /* 0x28 */ s32 nextDelta; /* microseconds to next callback */ - /* 0x2C */ s32 state; - /* 0x30 */ u16 chanMask; /* active channels */ - /* 0x32 */ s16 vol; /* overall sequence volume */ - /* 0x34 */ u8 maxChannels; /* number of MIDI channels */ - /* 0x35 */ u8 debugFlags; /* control which error get reported */ - /* 0x36 */ u8 unk36; - /* 0x37 */ u8 unk37; - /* 0x38 */ ALEvent nextEvent; - /* 0x48 */ ALEventQueue evtq; - /* 0x5C */ ALMicroTime frameTime; - /* 0x60 */ ALChanState *chanState; /* 16 channels for MIDI */ - /* 0x64 */ ALVoiceState *vAllocHead; /* list head for allocated voices */ - /* 0x68 */ ALVoiceState *vAllocTail; /* list tail for allocated voices */ - /* 0x6C */ ALVoiceState *vFreeList; /* list of free voice state structs */ - /* 0x70 */ s8 unk70; - /* 0x71 */ s8 unk71; - /* 0x72 */ s8 unk72; - /* 0x73 */ s8 unk73; - /* 0x74 */ ALOscInit initOsc; - /* 0x78 */ ALOscUpdate updateOsc; - /* 0x7C */ ALOscStop stopOsc; + ALPlayer node; /* note: must be first in structure */ + 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 */ + u8 unk36; + u8 unk37; + ALEvent nextEvent; + ALEventQueue evtq; + ALMicroTime frameTime; + ALChanState *chanState; /* 16 channels for MIDI */ + ALVoiceState *vAllocHead; /* list head for allocated voices */ + ALVoiceState *vAllocTail; /* list tail for allocated voices */ + ALVoiceState *vFreeList; /* list of free voice state structs */ + s8 unk70; + s8 unk71; + s8 unk72; + s8 unk73; + ALOscInit initOsc; + ALOscUpdate updateOsc; + ALOscStop stopOsc; } ALCSPlayer; /** @@ -815,35 +841,6 @@ typedef struct { /* 0x7C */ ALOscStop stopOsc; } ALCSPlayer_Custom; -/* - * Compressed Sequence Player routines - */ -void alCSPNew(ALCSPlayer *seqp, ALSeqpConfig *config); -void alCSPDelete(ALCSPlayer *seqp); -void alCSPSetSeq(ALCSPlayer *seqp, ALCSeq *seq); -ALCSeq *alCSPGetSeq(ALCSPlayer *seqp); -void alCSPPlay(ALCSPlayer *seqp); -void alCSPStop(ALCSPlayer *seqp); -s32 alCSPGetState(ALCSPlayer *seqp); -void alCSPSetBank(ALCSPlayer *seqp, ALBank *b); -void alCSPSetTempo(ALCSPlayer *seqp, s32 tempo); -s32 alCSPGetTempo(ALCSPlayer *seqp); -s16 alCSPGetVol(ALCSPlayer *seqp); -void alCSPSetVol(ALCSPlayer *seqp, s16 vol); - -void alCSPSetChlProgram(ALCSPlayer *seqp, u8 chan, u8 prog); -s32 alCSPGetChlProgram(ALCSPlayer *seqp, u8 chan); -void alCSPSetChlFXMix(ALCSPlayer *seqp, u8 chan, u8 fxmix); -u8 alCSPGetChlFXMix(ALCSPlayer *seqp, u8 chan); -void alCSPSetChlPan(ALCSPlayer *seqp, u8 chan, ALPan pan); -ALPan alCSPGetChlPan(ALCSPlayer *seqp, u8 chan); -void alCSPSetChlVol(ALCSPlayer *seqp, u8 chan, u8 vol); -u8 alCSPGetChlVol(ALCSPlayer *seqp, u8 chan); -void alCSPSetChlPriority(ALCSPlayer *seqp, u8 chan, u8 priority); -u8 alCSPGetChlPriority(ALCSPlayer *seqp, u8 chan); -void alCSPSendMidi(ALCSPlayer *seqp, s32 ticks, u8 status, - u8 byte1, u8 byte2); - /* * Sequence data representation routines */ @@ -898,6 +895,49 @@ void alSeqpSetChlPriority(ALSeqPlayer *seqp, u8 chan, u8 priority); u8 alSeqpGetChlPriority(ALSeqPlayer *seqp, u8 chan); void alSeqpSendMidi(ALSeqPlayer *seqp, s32 ticks, u8 status, u8 byte1, u8 byte2); + +/* Maintain backwards compatibility with old routine names. */ +#define alSeqpSetProgram alSeqpSetChlProgram +#define alSeqpGetProgram alSeqpGetChlProgram +#define alSeqpSetFXMix alSeqpSetChlFXMix +#define alSeqpGetFXMix alSeqpGetChlFXMix +#define alSeqpSetPan alSeqpSetChlPan +#define alSeqpGetPan alSeqpGetChlPan +#define alSeqpSetChannelPriority alSeqpSetChlPriority +#define alSeqpGetChannelPriority alSeqpGetChlPriority + + + +/* + * Compressed Sequence Player routines + */ +void alCSPNew(ALCSPlayer *seqp, ALSeqpConfig *config); +void alCSPDelete(ALCSPlayer *seqp); +void alCSPSetSeq(ALCSPlayer *seqp, ALCSeq *seq); +ALCSeq *alCSPGetSeq(ALCSPlayer *seqp); +void alCSPPlay(ALCSPlayer *seqp); +void alCSPStop(ALCSPlayer *seqp); +s32 alCSPGetState(ALCSPlayer *seqp); +void alCSPSetBank(ALCSPlayer *seqp, ALBank *b); +void alCSPSetTempo(ALCSPlayer *seqp, s32 tempo); +s32 alCSPGetTempo(ALCSPlayer *seqp); +s16 alCSPGetVol(ALCSPlayer *seqp); +void alCSPSetVol(ALCSPlayer *seqp, s16 vol); + +void alCSPSetChlProgram(ALCSPlayer *seqp, u8 chan, u8 prog); +s32 alCSPGetChlProgram(ALCSPlayer *seqp, u8 chan); +void alCSPSetChlFXMix(ALCSPlayer *seqp, u8 chan, u8 fxmix); +u8 alCSPGetChlFXMix(ALCSPlayer *seqp, u8 chan); +void alCSPSetChlPan(ALCSPlayer *seqp, u8 chan, ALPan pan); +ALPan alCSPGetChlPan(ALCSPlayer *seqp, u8 chan); +void alCSPSetChlVol(ALCSPlayer *seqp, u8 chan, u8 vol); +u8 alCSPGetChlVol(ALCSPlayer *seqp, u8 chan); +void alCSPSetChlPriority(ALCSPlayer *seqp, u8 chan, u8 priority); +u8 alCSPGetChlPriority(ALCSPlayer *seqp, u8 chan); +void alCSPSendMidi(ALCSPlayer *seqp, s32 ticks, u8 status, + u8 byte1, u8 byte2); + + /* Maintain backwards compatibility with old routine names. */ #define alCSPSetProgram alCSPSetChlProgram #define alCSPGetProgram alCSPGetChlProgram @@ -909,6 +949,7 @@ void alSeqpSendMidi(ALSeqPlayer *seqp, s32 ticks, u8 status, u8 byte1, u8 byt #define alCSPGetChannelPriority alCSPGetChlPriority + /*********************************************************************** * Sound Player stuff ***********************************************************************/ @@ -934,5 +975,35 @@ typedef struct { typedef s16 ALSndId; +void alSndpNew(ALSndPlayer *sndp, ALSndpConfig *c); +void alSndpDelete(ALSndPlayer *sndp); +ALSndId alSndpAllocate(ALSndPlayer *sndp, ALSound *sound); +void alSndpDeallocate(ALSndPlayer *sndp, ALSndId id); + +void alSndpSetSound(ALSndPlayer *sndp, ALSndId id); +ALSndId alSndpGetSound(ALSndPlayer *sndp); + +void alSndpPlay(ALSndPlayer *sndp); +void alSndpPlayAt(ALSndPlayer *sndp, ALMicroTime delta); +void alSndpStop(ALSndPlayer *sndp); + +void alSndpSetVol(ALSndPlayer *sndp, s16 vol); +void alSndpSetPitch(ALSndPlayer *sndp, f32 pitch); +void alSndpSetPan(ALSndPlayer *sndp, ALPan pan); +void alSndpSetPriority(ALSndPlayer *sndp, ALSndId id, u8 priority); + +void alSndpSetFXMix(ALSndPlayer *sndp, u8 mix); +s32 alSndpGetState(ALSndPlayer *sndp); + +#ifndef _FINALROM +void alParseAbiCL(Acmd *cmdList, u32 nbytes); #endif +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !__LIB_AUDIO__ */ + + + diff --git a/include/PR/libultra.h b/include/PR/libultra.h deleted file mode 100644 index 22b390e1..00000000 --- a/include/PR/libultra.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _LIBULTRA_H -#define _LIBULTRA_H - -#define TV_TYPE_NTSC 1 -#define TV_TYPE_PAL 0 -#define TV_TYPE_MPAL 2 - -#define OS_TV_TYPE_PAL 0 -#define OS_TV_TYPE_NTSC 1 -#define OS_TV_TYPE_MPAL 2 - -#define RESET_TYPE_COLD_RESET 0 -#define RESET_TYPE_NMI 1 -#define RESET_TYPE_BOOT_DISK 2 - -extern u32 osTvType; -extern u32 osRomBase; -extern u32 osResetType; -extern u32 osMemSize; -extern u8 osAppNmiBuffer[64]; - -#endif /* _LIBULTRA_H */ diff --git a/include/PR/mbi.h b/include/PR/mbi.h index fed3510f..ac900a54 100644 --- a/include/PR/mbi.h +++ b/include/PR/mbi.h @@ -17,7 +17,7 @@ * * $Revision: 1.136 $ * $Date: 1999/01/05 13:04:00 $ - * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/mbi.h,v $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/mbi.h,v $ * **************************************************************************/ diff --git a/include/PR/os.h b/include/PR/os.h index 1dd5ccc1..927a6ec1 100644 --- a/include/PR/os.h +++ b/include/PR/os.h @@ -1,13 +1,91 @@ -#ifndef _ULTRA64_OS_INTERNAL_H_ -#define _ULTRA64_OS_INTERNAL_H_ -/* Internal functions used by the operating system */ -/* Do not include this header in application code */ +/*==================================================================== + * os.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. + *====================================================================*/ -#include "os_thread.h" +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os.h,v $ + $Revision: 1.168 $ + $Date: 2000/06/15 06:24:52 $ + *---------------------------------------------------------------------*/ + +#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 +/* #include */ + +/* TODO: Why the 3 includes above fail? */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +/************************************************************************** + * + * Global definitions + * + */ /* - * Leo Disk + * Stack size for I/O device managers: PIM (PI Manager), VIM (VI Manager), + * SIM (SI Manager) + * + */ +#define OS_PIM_STACKSIZE 256 +#define OS_VIM_STACKSIZE 256 +#define OS_SIM_STACKSIZE 4096 + +#define OS_MIN_STACKSIZE 72 + +/* + * Leo Disk */ /* transfer mode */ @@ -16,39 +94,17 @@ #define LEO_TRACK_MODE 2 #define LEO_SECTOR_MODE 3 -/* Variables */ /* - * 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 + * Boot addresses */ -extern u64 osClockRate; +#define BOOT_ADDRESS_ULTRA 0x80000400 +#define BOOT_ADDRESS_COSIM 0x80002000 +#define BOOT_ADDRESS_EMU 0x20010000 +#define BOOT_ADDRESS_INDY 0x88100000 -#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)) - -/* Functions */ - -u32 __osProbeTLB(void *); -u32 __osDisableInt(void); -void __osRestoreInt(u32); -OSThread *__osGetCurrFaultedThread(void); - -/* 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)) +#ifdef _LANGUAGE_C_PLUS_PLUS +} #endif + +#endif /* !_OS_H */ diff --git a/include/PR/os_cache.h b/include/PR/os_cache.h index 93d53c5f..54ed9230 100644 --- a/include/PR/os_cache.h +++ b/include/PR/os_cache.h @@ -81,9 +81,9 @@ extern "C" { /* Cache operations and macros */ -extern void osInvalDCache(void *, size_t); -extern void osInvalICache(void *, size_t); -extern void osWritebackDCache(void *, size_t); +extern void osInvalDCache(void *, s32); +extern void osInvalICache(void *, s32); +extern void osWritebackDCache(void *, s32); extern void osWritebackDCacheAll(void); diff --git a/include/PR/os_cont.h b/include/PR/os_cont.h index 6e9c14f2..2b69330f 100644 --- a/include/PR/os_cont.h +++ b/include/PR/os_cont.h @@ -93,6 +93,7 @@ typedef struct { /* controller errors */ #define CONT_NO_RESPONSE_ERROR 0x8 #define CONT_OVERRUN_ERROR 0x4 +#define CONT_RANGE_ERROR -1 #ifdef _HW_VERSION_1 #define CONT_FRAME_ERROR 0x2 #define CONT_COLLISION_ERROR 0x1 @@ -187,10 +188,10 @@ typedef struct { /* Controller interface */ -extern s32 osContInit(OSMesgQueue *mq, u8 *bitpattern, OSContStatus *data); +extern s32 osContInit(OSMesgQueue *, u8 *, OSContStatus *); extern s32 osContReset(OSMesgQueue *, OSContStatus *); extern s32 osContStartQuery(OSMesgQueue *); -extern s32 osContStartReadData(OSMesgQueue *mq); +extern s32 osContStartReadData(OSMesgQueue *); #ifndef _HW_VERSION_1 extern s32 osContSetCh(u8); #endif diff --git a/include/PR/os_convert.h b/include/PR/os_convert.h new file mode 100644 index 00000000..0a5da10a --- /dev/null +++ b/include/PR/os_convert.h @@ -0,0 +1,111 @@ + +/*==================================================================== + * 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.2 $ + $Date: 1999/04/21 02:53:11 $ + *---------------------------------------------------------------------*/ + +#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)) + +/* OS_K?_TO_PHYSICAL macro bug fix for CodeWarrior */ +#ifndef __MWERKS__ +#define OS_K0_TO_PHYSICAL(x) (u32)(((char *)(x)-0x80000000)) +#define OS_K1_TO_PHYSICAL(x) (u32)(((char *)(x)-0xa0000000)) +#else +#define OS_K0_TO_PHYSICAL(x) ((char *)(x)-0x80000000) +#define OS_K1_TO_PHYSICAL(x) ((char *)(x)-0xa0000000) +#endif + +#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 00000000..f8f5a89a --- /dev/null +++ b/include/PR/os_debug.h @@ -0,0 +1,117 @@ + +/*==================================================================== + * 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.4 $ + $Date: 1999/06/30 03:04:08 $ + *---------------------------------------------------------------------*/ + +#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); + +/* Thread Profiler Interface */ +extern void osThreadProfileClear(OSId); +extern void osThreadProfileInit(void); +extern void osThreadProfileStart(void); +extern void osThreadProfileStop(void); +extern u32 osThreadProfileReadCount(OSId); +extern u32 osThreadProfileReadCountTh(OSThread*); +extern OSTime osThreadProfileReadTime(OSId); +extern OSTime osThreadProfileReadTimeTh(OSThread*); + +#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 index 18cd04e6..b3bca814 100644 --- a/include/PR/os_eeprom.h +++ b/include/PR/os_eeprom.h @@ -91,11 +91,11 @@ extern "C" { /* EEPROM interface */ -extern s32 osEepromProbe(OSMesgQueue *mq); -extern s32 osEepromRead(OSMesgQueue *mq, u8 address, u8 *buffer); -extern s32 osEepromWrite(OSMesgQueue *mq, u8 address, u8 *buffer); -extern s32 osEepromLongRead(OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes); -extern s32 osEepromLongWrite(OSMesgQueue *mq, u8 address, u8 *buffer, int nbytes); +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) */ diff --git a/include/PR/os_error.h b/include/PR/os_error.h new file mode 100644 index 00000000..f4c3b83c --- /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 index 245e5e69..2457bdea 100644 --- a/include/PR/os_exception.h +++ b/include/PR/os_exception.h @@ -28,87 +28,54 @@ *---------------------------------------------------------------------*/ #ifndef _OS_EXCEPTION_H_ -#define _OS_EXCEPTION_H_ +#define _OS_EXCEPTION_H_ #ifdef _LANGUAGE_C_PLUS_PLUS extern "C" { #endif -#include +#include "ultratypes.h" #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) -/************************************************************************** - * - * Type definitions - * - */ - typedef u32 OSIntMask; typedef u32 OSHWIntr; #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ -/************************************************************************** - * - * Global definitions - * - */ - /* Flags for debugging purpose */ -#define OS_FLAG_CPU_BREAK 1 /* Break exception has occurred */ -#define OS_FLAG_FAULT 2 /* CPU fault has occurred */ +#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 - +#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) -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - /* Interrupt operations */ -extern OSIntMask osGetIntMask(void); -extern OSIntMask osSetIntMask(OSIntMask); - +extern OSIntMask osGetIntMask(void); +extern OSIntMask osSetIntMask(OSIntMask); #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ diff --git a/include/PR/os_flash.h b/include/PR/os_flash.h new file mode 100644 index 00000000..9eb0bf7f --- /dev/null +++ b/include/PR/os_flash.h @@ -0,0 +1,77 @@ +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_flash.h,v $ + $Revision: 1.1 $ + $Date: 2000/06/15 06:24:55 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_FLASH_H_ +#define _OS_FLASH_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include "ultratypes.h" +#include "os_pi.h" + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* + * defines for FLASH + */ +#define FLASH_START_ADDR 0x08000000 + +#define FLASH_SIZE 0x20000 + +#define FLASH_LATENCY 0x5 +#define FLASH_PULSE 0x0c +#define FLASH_PAGE_SIZE 0xf +#define FLASH_REL_DURATION 0x2 +#define DEVICE_TYPE_FLASH 8 + +#define FLASH_VERSION_MX_PROTO_A 0x00c20000 +#define FLASH_VERSION_MX_A 0x00c20001 +#define FLASH_VERSION_MX_C 0x00c2001e +#define FLASH_VERSION_MX_B_AND_D 0x00c2001d +#define FLASH_VERSION_MEI 0x003200f1 + +/* OLD_FLASH is MX_PROTO_A, MX_A and MX_C */ +#define OLD_FLASH 0 +/* NEW_FLASH is MX_B_AND_D and MATSUSHITA flash */ +#define NEW_FLASH 1 + +#define FLASH_STATUS_ERASE_BUSY 2 +#define FLASH_STATUS_ERASE_OK 0 +#define FLASH_STATUS_ERASE_ERROR -1 + +#define FLASH_STATUS_WRITE_BUSY 1 +#define FLASH_STATUS_WRITE_OK 0 +#define FLASH_STATUS_WRITE_ERROR -1 + +extern OSPiHandle *osFlashReInit(u8 latency, u8 pulse, + u8 page_size, u8 rel_duration, u32 start); +extern OSPiHandle *osFlashInit(void); +extern void osFlashReadStatus(u8 *flash_status); +extern void osFlashReadId(u32 *flash_type, u32 *flash_maker); +extern void osFlashClearStatus(void); +extern s32 osFlashAllErase(void); +extern s32 osFlashSectorErase(u32 page_num); +extern s32 osFlashWriteBuffer(OSIoMesg *mb, s32 priority, + void *dramAddr, OSMesgQueue *mq); +extern s32 osFlashWriteArray(u32 page_num); +extern s32 osFlashReadArray(OSIoMesg *mb, s32 priority, u32 page_num, + void *dramAddr, u32 n_pages, OSMesgQueue *mq); +extern void osFlashChange(u32 flash_num); +extern void osFlashAllEraseThrough(void); +extern void osFlashSectorEraseThrough(u32 page_num); +extern s32 osFlashCheckEraseEnd(void); + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_FLASH_H_ */ diff --git a/include/PR/os_gbpak.h b/include/PR/os_gbpak.h new file mode 100644 index 00000000..0a999945 --- /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 00000000..ad3c020f --- /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 00000000..3192f6a7 --- /dev/null +++ b/include/PR/os_host.h @@ -0,0 +1,166 @@ + +/*==================================================================== + * 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.3 $ + $Date: 1999/06/24 09:23:06 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_HOST_H_ +#define _OS_HOST_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#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 void __osInitialize_common(void); + +#if defined(_FINALROM) + +#define osInitialize() __osInitialize_common() + +#else + +/* PARTNER-N64 */ +#if defined(PTN64) +extern void __osInitialize_kmc(void); +#define osReadHost osReadHost_pt +#define osWriteHost osWriteHost_pt +#define osInitialize() \ +{ \ + __osInitialize_common(); \ + __osInitialize_kmc(); \ +} + +/* MONEGI SMART PACK A */ +#elif defined(MWN64) +extern void __osInitialize_msp(void); +#define osReadHost osReadHost_pt +#define osWriteHost osWriteHost_pt +#define osInitialize() \ +{ \ + __osInitialize_common(); \ + __osInitialize_msp(); \ +} + +/* IS-Viewer(for Debugger) */ +#elif defined(ISV64) +extern void __osInitialize_isv(void); +#define osInitialize() \ +{ \ + __osInitialize_common(); \ + __osInitialize_isv(); \ +} + +/* Emulation board for INDY */ +#elif defined(EMU64) +extern void __osInitialize_emu(void); +#define osInitialize() \ +{ \ + __osInitialize_common(); \ + __osInitialize_emu(); \ +} + +#else +/* Default (auto detect) */ +extern void __osInitialize_autodetect(void); +extern void __osInitialize_msp(void); +extern void __osInitialize_kmc(void); +extern void __osInitialize_isv(void); +extern void __osInitialize_emu(void); +#define osInitialize() \ +{ \ + __osInitialize_common(); \ + __osInitialize_autodetect(); \ +} +#endif + +#endif /* _FINAL_ROM */ + +#if BUILD_VERSION < VERSION_K +#undef osInitialize +#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 c1361cb8..8da78b79 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_ @@ -26,89 +26,19 @@ extern "C" { #endif #include -#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); - -/* 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" //TODO: Why does this include break things? +#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 00000000..7b307d6e --- /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 00000000..de188d23 --- /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 00000000..dae8a9f1 --- /dev/null +++ b/include/PR/os_internal_exception.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_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 "os.h" +#include "os_version.h" + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Routine for HW interrupt "handler" */ +#if BUILD_VERSION >= VERSION_J +extern void __osSetHWIntrRoutine(OSHWIntr interrupt, + s32 (*handler)(void), void *stackEnd); +extern void __osGetHWIntrRoutine(OSHWIntr interrupt, + s32 (**handler)(void), void **stackEnd); +#else +extern void __osSetHWIntrRoutine(OSHWIntr interrupt, + s32 (*handler)(void)); +extern void __osGetHWIntrRoutine(OSHWIntr interrupt, + s32 (**handler)(void)); +#endif + +/* 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_flash.h b/include/PR/os_internal_flash.h new file mode 100644 index 00000000..1c6f7809 --- /dev/null +++ b/include/PR/os_internal_flash.h @@ -0,0 +1,40 @@ +#ifndef _OS_INTERNAL_FLASH_H_ +#define _OS_INTERNAL_FLASH_H_ + +#include "os_message.h" +#include "os_flash.h" + +#define FLASH_BLOCK_SIZE 128 + +/** + * Flash commands + */ +#define FLASH_CMD_REG 0x10000 + +/* set whole chip erase mode */ +#define FLASH_CMD_CHIP_ERASE 0x3C000000 +/* set sector erase mode */ +#define FLASH_CMD_SECTOR_ERASE 0x4B000000 +/* do erasure */ +#define FLASH_CMD_EXECUTE_ERASE 0x78000000 +/* program selected page */ +#define FLASH_CMD_PROGRAM_PAGE 0xA5000000 +/* set page program mode */ +#define FLASH_CMD_PAGE_PROGRAM 0xB4000000 +/* set status mode */ +#define FLASH_CMD_STATUS 0xD2000000 +/* set silicon id mode */ +#define FLASH_CMD_ID 0xE1000000 +/* set read mode */ +#define FLASH_CMD_READ_ARRAY 0xF0000000 + +extern OSIoMesg __osFlashMsg; +extern OSMesgQueue __osFlashMessageQ; +extern OSPiHandle __osFlashHandler; +extern OSMesg __osFlashMsgBuf[1]; +extern s32 __osFlashVersion; +extern u32 __osFlashID[4]; + +u32 __osFlashGetAddr(u32 page_num); + +#endif diff --git a/include/PR/os_internal_gio.h b/include/PR/os_internal_gio.h new file mode 100644 index 00000000..ff133850 --- /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 00000000..b6d19513 --- /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 00000000..206b721c --- /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.2 $ + $Date: 1999/03/10 12:19:14 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_INTERNAL_REG_H_ +#define _OS_INTERNAL_REG_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include "os.h" + +#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); +extern u32 __osGetWatchLo(void); +extern void __osSetWatchLo(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 00000000..646e6679 --- /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 00000000..d0eeedcc --- /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 00000000..1305eb58 --- /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 00000000..b92918ff --- /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 index ce5372fb..71d6d76f 100644 --- a/include/PR/os_libc.h +++ b/include/PR/os_libc.h @@ -1,9 +1,105 @@ -#ifndef _OS_LIBC_H_ -#define _OS_LIBC_H_ -#include "ultratypes.h" -// Old deprecated functions from strings.h, replaced by memcpy/memset. -extern void bcopy(const void *, void *, size_t); -extern void bzero(void *, size_t); +/*==================================================================== + * 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.3 $ + $Date: 1999/07/13 01:43:47 $ + *---------------------------------------------------------------------*/ + +#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 */ + +#ifndef MODERN_CC +extern void bcopy(const void *, void *, int); +extern int bcmp(const void *, const void *, int); +extern void bzero(void *, int); +#else +extern void bcopy(const void *, void *, size_t); +extern int bcmp(const void *, const void *, size_t); +extern void bzero(void *, size_t); +#endif + +/* Printf */ + +extern int sprintf(char *s, const char *format, ...); +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 index 8cc50ace..606c5cb0 100644 --- a/include/PR/os_message.h +++ b/include/PR/os_message.h @@ -1,3 +1,4 @@ + /*==================================================================== * os_message.h * @@ -27,14 +28,14 @@ *---------------------------------------------------------------------*/ #ifndef _OS_MESSAGE_H_ -#define _OS_MESSAGE_H_ +#define _OS_MESSAGE_H_ #ifdef _LANGUAGE_C_PLUS_PLUS extern "C" { #endif -#include -#include +#include "ultratypes.h" +#include "os_thread.h" #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) @@ -49,21 +50,18 @@ typedef u32 OSEvent; /* * Structure for message */ -typedef void * OSMesg; +typedef void *OSMesg; /* * Structure for message queue */ typedef struct OSMesgQueue_s { - // sizeof = 0x18 or 24 bytes - 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 */ + 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; @@ -110,26 +108,9 @@ typedef struct OSMesgQueue_s { /* Flags to turn blocking on/off when sending/receiving message */ -#define OS_MESG_NOBLOCK 0 -#define OS_MESG_BLOCK 1 +#define OS_MESG_NOBLOCK 0 +#define OS_MESG_BLOCK 1 -/* - * 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 #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) @@ -140,11 +121,11 @@ typedef struct OSMesgQueue_s { */ /* Get count of valid messages in queue */ -#define MQ_GET_COUNT(mq) ((mq)->validCount) +#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) +#define MQ_IS_EMPTY(mq) (MQ_GET_COUNT(mq) == 0) +#define MQ_IS_FULL(mq) (MQ_GET_COUNT(mq) >= (mq)->msgCount) /************************************************************************** @@ -162,14 +143,14 @@ typedef struct OSMesgQueue_s { /* Message operations */ -extern void osCreateMesgQueue(OSMesgQueue *mq, OSMesg *msg, s32 msgCount); -extern s32 osSendMesg(OSMesgQueue *, OSMesg, s32); -extern s32 osJamMesg(OSMesgQueue *, OSMesg, s32); -extern s32 osRecvMesg(OSMesgQueue *, OSMesg *, s32); +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); +extern void osSetEventMesg(OSEvent, OSMesgQueue *, OSMesg); #endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ diff --git a/include/PR/os_misc.h b/include/PR/os_misc.h deleted file mode 100644 index f0a0818c..00000000 --- a/include/PR/os_misc.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _ULTRA64_OS_MISC_H_ -#define _ULTRA64_OS_MISC_H_ -#include -/* Miscellaneous OS functions */ - -void osInitialize(void); -u32 osGetCount(void); - -#endif diff --git a/include/PR/os_motor.h b/include/PR/os_motor.h new file mode 100644 index 00000000..2edb8e6c --- /dev/null +++ b/include/PR/os_motor.h @@ -0,0 +1,84 @@ + +/*---------------------------------------------------------------------* + 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" +#include "os_version.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 BUILD_VERSION >= VERSION_J +#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 00000000..9c86e238 --- /dev/null +++ b/include/PR/os_pfs.h @@ -0,0 +1,200 @@ + +/*==================================================================== + * 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_INODE_SIZE_PER_PAGE 128 +#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 +#define PFS_ID_BROKEN 0x4 +#define PFS_MOTOR_INITIALIZED 0x8 +#define PFS_GBPAK_INITIALIZED 0x10 + +/* Definition for page usage */ +#define PFS_EOF 1 +#define PFS_PAGE_NOT_EXIST 2 +#define PFS_PAGE_NOT_USED 3 + +/* 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 */ + +/* 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) + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* 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 *); + + +#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 index e4d61996..f408d6ce 100644 --- a/include/PR/os_pi.h +++ b/include/PR/os_pi.h @@ -1,99 +1,221 @@ -#ifndef _ULTRA64_PI_H_ -#define _ULTRA64_PI_H_ -/* Ultra64 Parallel Interface */ +/*==================================================================== + * 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. + *====================================================================*/ -/* Types */ +/*---------------------------------------------------------------------* + 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 "ultratypes.h" +#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 { -#if !defined(VERSION_EU) && !defined(VERSION_SH) - u32 errStatus; -#endif - void *dramAddr; - void *C2Addr; - u32 sectorSize; - u32 C1ErrNum; - u32 C1ErrSector[4]; + 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; // 0 - u16 transferMode; // 4 - u16 blockNum; // 6 - s32 sectorNum; // 8 - uintptr_t devAddr; // c -#if defined(VERSION_EU) || defined(VERSION_SH) - u32 errStatus; //error status added moved to blockinfo -#endif - u32 bmCtlShadow; // 10 - u32 seqCtlShadow; // 14 - __OSBlockInfo block[2]; // 18 + 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; - u8 type; - u8 latency; - u8 pageSize; - u8 relDuration; - u8 pulse; - u8 domain; - u32 baseAddress; - u32 speed; - __OSTranxInfo transferInfo; + 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; - uintptr_t address; + u8 type; + u32 address; } OSPiInfo; +/* + * Structure for I/O message block + */ typedef struct { - u16 type; - u8 pri; - u8 status; - OSMesgQueue *retQueue; + 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 { - /*0x00*/ OSIoMesgHdr hdr; - /*0x08*/ void *dramAddr; - /*0x0C*/ uintptr_t devAddr; - /*0x10*/ size_t size; - OSPiHandle *piHandle; // from the official definition + 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); + 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; -/* Definitions */ -#define OS_READ 0 // device -> RDRAM -#define OS_WRITE 1 // device <- RDRAM +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ -#define OS_MESG_PRI_NORMAL 0 -#define OS_MESG_PRI_HIGH 1 +/************************************************************************** + * + * Global definitions + * + */ -/* Functions */ +/* Flags to indicate direction of data transfer */ -s32 osPiStartDma(OSIoMesg *mb, s32 priority, s32 direction, uintptr_t devAddr, void *vAddr, - size_t nbytes, OSMesgQueue *mq); -void osCreatePiManager(OSPri pri, OSMesgQueue *cmdQ, OSMesg *cmdBuf, s32 cmdMsgCnt); -OSMesgQueue *osPiGetCmdQueue(void); -s32 osPiWriteIo(uintptr_t devAddr, u32 data); -s32 osPiReadIo(uintptr_t devAddr, u32 *data); -s32 osPiRawReadIo(u32 devAddr, u32 *data); +#define OS_READ 0 /* device -> RDRAM */ +#define OS_WRITE 1 /* device <- RDRAM */ +#define OS_OTHERS 2 /* for Leo disk only */ -s32 __osPiRawStartDma(s32 dir, u32 cart_addr, void *dram_addr, size_t size); -s32 __osEPiRawStartDma(OSPiHandle *piHandle, s32 dir, u32 cart_addr, void *dram_addr, size_t size); -s32 osEPiRawWriteIo(OSPiHandle *, u32 , u32); +/* + * 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 + * + */ + +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_reg.h b/include/PR/os_reg.h new file mode 100644 index 00000000..50aa2188 --- /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 00000000..12116053 --- /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 00000000..23b07c07 --- /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 00000000..1179189a --- /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 index 76e528b5..68c8e74f 100644 --- a/include/PR/os_thread.h +++ b/include/PR/os_thread.h @@ -1,75 +1,161 @@ -#ifndef _ULTRA64_THREAD_H_ -#define _ULTRA64_THREAD_H_ -#include "ultratypes.h" -/* Recommended priorities for 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 -#define OS_STATE_STOPPED 1 -#define OS_STATE_RUNNABLE 2 -#define OS_STATE_RUNNING 4 -#define OS_STATE_WAITING 8 +/*==================================================================== + * 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. + *====================================================================*/ -/* Types */ +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_thread.h,v $ + $Revision: 1.3 $ + $Date: 1999/06/15 12:39:40 $ + *---------------------------------------------------------------------*/ + +#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; +typedef union { + struct { + f32 f_odd; + f32 f_even; + } f; + f64 d; } __OSfp; -typedef struct -{ - /* registers */ - /*0x20*/ u64 at, v0, v1, a0, a1, a2, a3; - /*0x58*/ u64 t0, t1, t2, t3, t4, t5, t6, t7; - /*0x98*/ u64 s0, s1, s2, s3, s4, s5, s6, s7; - /*0xD8*/ u64 t8, t9, gp, sp, s8, ra; - /*0x108*/ u64 lo, hi; - /*0x118*/ u32 sr, pc, cause, badvaddr, rcp; - /*0x12C*/ u32 fpcsr; +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; + u64 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 -{ +typedef struct { u32 flag; u32 count; u64 time; } __OSThreadprofile_s; -typedef struct OSThread_s -{ - /*0x00*/ struct OSThread_s *next; - /*0x04*/ OSPri priority; - /*0x08*/ struct OSThread_s **queue; - /*0x0C*/ struct OSThread_s *tlnext; - /*0x10*/ u16 state; - /*0x12*/ u16 flags; - /*0x14*/ OSId id; - /*0x18*/ int fp; - /*0x1C*/ __OSThreadprofile_s *thprof; - /*0x20*/ __OSThreadContext context; +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 */ + __OSThreadprofile_s *thprof; /* workarea for thread profiler */ + __OSThreadContext context; /* register/interrupt mask */ } OSThread; -/* Functions */ +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ -void osCreateThread(OSThread *thread, OSId id, void (*entry)(void *), - void *arg, void *sp, OSPri pri); -OSId osGetThreadId(OSThread *thread); -OSPri osGetThreadPri(OSThread *thread); -void osSetThreadPri(OSThread *thread, OSPri pri); -void osStartThread(OSThread *thread); -void osStopThread(OSThread *thread); +/************************************************************************** + * + * Global definitions + * + */ +/* Thread states */ + +#define OS_STATE_STOPPED (1 << 0) +#define OS_STATE_RUNNABLE (1 << 1) +#define OS_STATE_RUNNING (1 << 2) +#define OS_STATE_WAITING (1 << 3) + +/* 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 */ + +/* For thread profiler */ +#define THPROF_IDMAX 64 +#define THPROF_STACKSIZE 256 + +#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 index edd3d258..deaec659 100644 --- a/include/PR/os_time.h +++ b/include/PR/os_time.h @@ -1,26 +1,114 @@ -#ifndef _ULTRA64_TIME_H_ -#define _ULTRA64_TIME_H_ + +/*==================================================================== + * 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 +#include "os_message.h" -/* Types */ -typedef u64 OSTime; +#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; - struct OSTimer_s *prev; - OSTime interval; - OSTime remaining; - OSMesgQueue *mq; - OSMesg *msg; + 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; -/* Functions */ -OSTime osGetTime(void); -void osSetTime(OSTime time); -s32 osSetTimer(OSTimer *t, OSTime value, OSTime interval, OSMesgQueue *mq, OSMesg msg); +#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_version.h b/include/PR/os_version.h new file mode 100644 index 00000000..aa10d20e --- /dev/null +++ b/include/PR/os_version.h @@ -0,0 +1,26 @@ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_version.h,v $ + $Revision: 1.2 $ + $Date: 1999/06/17 01:33:01 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_VERSION_H_ +#define _OS_VERSION_H_ + +#define VERSION_D 1 +#define VERSION_E 2 +#define VERSION_F 3 +#define VERSION_G 4 +#define VERSION_H 5 +#define VERSION_I 6 +#define VERSION_J 7 +#define VERSION_K 8 +#define VERSION_L 9 + +#define OS_MAJOR_VERSION BUILD_VERSION_STRING /* 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 index 7a741959..5a17f258 100644 --- a/include/PR/os_vi.h +++ b/include/PR/os_vi.h @@ -1,95 +1,101 @@ -#ifndef _ULTRA64_VI_H_ -#define _ULTRA64_VI_H_ -/* Ultra64 Video Interface */ +/*==================================================================== + * 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 + * + */ /* - * Video Interface (VI) special features + * Structure to store VI register values that remain the same between 2 fields */ -#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 - - -/* Types */ - -typedef struct -{ - u32 ctrl; - u32 width; - u32 burst; - u32 vSync; - u32 hSync; - u32 leap; - u32 hStart; - u32 xScale; - u32 vCurrent; +typedef struct { + u32 ctrl; + u32 width; + u32 burst; + u32 vSync; + u32 hSync; + u32 leap; + u32 hStart; + u32 xScale; + u32 vCurrent; } OSViCommonRegs; -typedef struct -{ - u32 origin; - u32 yScale; - u32 vStart; - u32 vBurst; - u32 vIntr; + +/* + * Structure to store VI register values that change between fields + */ +typedef struct { + u32 origin; + u32 yScale; + u32 vStart; + u32 vBurst; + u32 vIntr; } OSViFieldRegs; -typedef struct -{ - u8 type; - OSViCommonRegs comRegs; - OSViFieldRegs fldRegs[2]; + +/* + * 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; -typedef struct -{ - /* 0x00 */ u16 unk00; //some kind of flags. swap buffer sets to 0x10 - /* 0x02 */ u16 retraceCount; - /* 0x04 */ void* buffer; - /* 0x08 */ OSViMode *unk08; - /* 0x0c */ u32 features; - /* 0x10 */ OSMesgQueue *mq; - /* 0x14 */ OSMesg *msg; - /* 0x18 */ u32 unk18; - /* 0x1c */ u32 unk1c; - /* 0x20 */ u32 unk20; - /* 0x24 */ f32 unk24; - /* 0x28 */ u16 unk28; - /* 0x2c */ u32 unk2c; -} OSViContext; -void osCreateViManager(OSPri pri); -void osViSetMode(OSViMode *mode); -void osViSetEvent(OSMesgQueue *mq, OSMesg msg, u32 retraceCount); -void osViBlack(u8 active); -void osViSetSpecialFeatures(u32 func); -void osViSwapBuffer(void *vaddr); -void osYieldThread(void); +#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 @@ -135,7 +141,158 @@ void osYieldThread(void); #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 00000000..4e3cf6ec --- /dev/null +++ b/include/PR/os_voice.h @@ -0,0 +1,108 @@ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. + + $RCSfile: os_voice.h,v $ + $Revision: 1.2 $ + $Date: 1999/07/13 08:36:42 $ + *---------------------------------------------------------------------*/ + +#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/pfs.h b/include/PR/pfs.h deleted file mode 100644 index f8e3ffe9..00000000 --- a/include/PR/pfs.h +++ /dev/null @@ -1,159 +0,0 @@ -#ifndef _ULTRA64_PFS_H_ -#define _ULTRA64_PFS_H_ - -#include - -/* 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_INODE_SIZE_PER_PAGE 128 -#define PFS_FILE_NAME_LEN 16 -#define PFS_FILE_EXT_LEN 4 -#define BLOCKSIZE 32 -#define PFS_ONE_PAGE 8 -#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 -#define PFS_ID_BROKEN 0x4 -#define PFS_MOTOR_INITIALIZED 0x8 -#define PFS_GBPAK_INITIALIZED 0x10 - -/* Definition for page usage */ -#define PFS_EOF 1 -#define PFS_PAGE_NOT_EXIST 2 -#define PFS_PAGE_NOT_USED 3 - -/* 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 */ - -/* 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) - -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; - -typedef union { - struct { - u8 bank; - u8 page; - } inode_t; - u16 ipage; -} __OSInodeUnit; - -typedef struct { - __OSInodeUnit inode_page[128]; -} __OSInode; - -typedef struct { - u32 game_code; - u16 company_code; - __OSInodeUnit start_page; - u8 status; - s8 reserved; - u16 data_sum; - u8 ext_name[PFS_FILE_EXT_LEN]; - u8 game_name[PFS_FILE_NAME_LEN]; -} __OSDir; - -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 { - __OSInode inode; - u8 bank; - u8 map[PFS_INODE_DIST_MAP]; -} __OSInodeCache; - -/* 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 *pfs, s32 file_no, u8 flag, int offset, int nbytes, u8 * data_buffer); -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 *); -extern s32 osMotorInit(OSMesgQueue *mq, OSPfs *pfs, int channel); -extern s32 osMotorStop(OSPfs *pfs); -extern s32 osMotorStart(OSPfs *pfs); - -#endif diff --git a/include/PR/ramrom.h b/include/PR/ramrom.h new file mode 100644 index 00000000..42e5c2d5 --- /dev/null +++ b/include/PR/ramrom.h @@ -0,0 +1,113 @@ +#ifndef _RAMROM_H +#define _RAMROM_H + +/************************************************************************** + * * + * 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. * + * * + **************************************************************************/ + +/************************************************************************** + * + * $Revision: 1.20 $ + * $Date: 1997/02/11 08:26:47 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ramrom.h,v $ + * + **************************************************************************/ + +/* + * Defines for the GIO card in the Nintendo Development Station + * + * The RAM on the GIO card acts as ROM for the game + * Interrupts available between the game and the Indy host + * + * The last part of the ramrom is used for communication between + * game and host. There are 6 4K buffers defined: + * log, printf, rmon to indy, rmon from indy, app to indy, app from indy + * The last 8 bytes of the buffer are used in the emulator environment + */ + +#define RAMROM_SIZE (0x1000000) + +#define RAMROM_BUF_SIZE (4096) +#define RAMROM_MSG_SIZE (RAMROM_BUF_SIZE*6) +#define RAMROM_MSG_ADDR (RAMROM_SIZE - RAMROM_MSG_SIZE) +#define RAMROM_MSG_HDR_SIZE (3*sizeof(long)) +#define RAMROM_USER_DATA_SIZE (RAMROM_MSG_SIZE-RAMROM_MSG_HDR_SIZE) + +#define RAMROM_APP_READ_ADDR (RAMROM_MSG_ADDR + (0*RAMROM_BUF_SIZE)) +#define RAMROM_APP_WRITE_ADDR (RAMROM_MSG_ADDR + (1*RAMROM_BUF_SIZE)) +#define RAMROM_RMON_READ_ADDR (RAMROM_MSG_ADDR + (2*RAMROM_BUF_SIZE)) +#define RAMROM_RMON_WRITE_ADDR (RAMROM_MSG_ADDR + (3*RAMROM_BUF_SIZE)) +#define RAMROM_PRINTF_ADDR (RAMROM_MSG_ADDR + (4*RAMROM_BUF_SIZE)) +#define RAMROM_LOG_ADDR (RAMROM_MSG_ADDR + (5*RAMROM_BUF_SIZE)) + +/*#define RAMROM_GIO_INTERRUPT (RAMROM_MSG_ADDR + RAMROM_MSG_SIZE - 4)*/ + +/* + * For the initial round of PIF bringup, we will load in a bootstrap loader + * 0x400 bytes into the ramrom, and the rom will be loaded at 0x2000 + */ +#ifndef _HW_VERSION_1 +#define RAMROM_BOOTSTRAP_OFFSET 0x40 +#define RAMROM_GAME_OFFSET 0x1000 +#define RAMROM_FONTDATA_OFFSET 0xb70 +#define RAMROM_FONTDATA_SIZE 1152 +#else +#define RAMROM_BOOTSTRAP_OFFSET 0x400 +#define RAMROM_GAME_OFFSET 0x2000 +#endif +#define RAMROM_CLOCKRATE_OFFSET 0x4 +#define RAMROM_CLOCKRATE_MASK 0xfffffff0 +#define RAMROM_BOOTADDR_OFFSET 0x8 +#define RAMROM_RELEASE_OFFSET 0xc +/* + * Second version of the PIF jumps to location 0x1000, and we'll put a jump to + * location 0x400 into the ramrom (for backwards compatibility). + */ +#define RAMROM_PIF2BOOTSTRAP_OFFSET 0x1000 + +typedef struct { + long type; + long length; /* in bytes of userdata */ + long magic; + char userdata[RAMROM_USER_DATA_SIZE]; +} RamRomBuffer; + +/* + * Interrupt values (must fit in 6 bits!) + * values are used for both request & response + * Transactions initiated by the host start with HOST + * and those initiated by the target start with GAME. + */ + +#define HOST_PIACCESS_REQ 1 +#define HOST_DBG_CMD_READY 2 +#define GAME_DBG_DATA_SEND 3 +#define HOST_DBG_DATA_ACK 4 +#define GAME_PRINTF_SEND 5 +#define HOST_PRINTF_ACK 6 +#define GAME_LOG_SEND 7 +#define HOST_LOG_ACK 8 +#define HOST_APP_CMD_READY 9 +#define GAME_APP_DATA_READY 10 +#define HOST_PROF_REQ 11 +#define GAME_PROF_SEND 12 +#define HOST_PROF_ACK 13 +#define GAME_FAULT_SEND 14 +#define HOST_FAULT_ACK 15 +#define GAME_EXIT 16 +#define HOST_DATA_ACK 17 + +#ifdef _EMULATOR +void __RamRomInit(int key, void *romaddr); +void __RamRomDestroy(int key); +#endif /* _EMULATOR */ + +#endif /* !_RAMROM_H */ diff --git a/include/PR/rcp.h b/include/PR/rcp.h index 99b8b60c..7c065908 100644 --- a/include/PR/rcp.h +++ b/include/PR/rcp.h @@ -18,128 +18,106 @@ * 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.22 $ + * $Date: 1999/05/20 03:01:49 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/rcp.h,v $ * **************************************************************************/ -#include -#include +#include "R4300.h" +#include "ultratypes.h" -/********************************************************************** - * - * Here is a quick overview of the RCP memory map: - * - -0x0000_0000 .. 0x03ef_ffff RDRAM memory -0x03f0_0000 .. 0x03ff_ffff RDRAM registers - - RCP registers (see below) -0x0400_0000 .. 0x040f_ffff SP registers -0x0410_0000 .. 0x041f_ffff DP command registers -0x0420_0000 .. 0x042f_ffff DP span registers -0x0430_0000 .. 0x043f_ffff MI registers -0x0440_0000 .. 0x044f_ffff VI registers -0x0450_0000 .. 0x045f_ffff AI registers -0x0460_0000 .. 0x046f_ffff PI registers -0x0470_0000 .. 0x047f_ffff RI registers -0x0480_0000 .. 0x048f_ffff SI registers -0x0490_0000 .. 0x04ff_ffff unused - -0x0500_0000 .. 0x05ff_ffff cartridge domain 2 -0x0600_0000 .. 0x07ff_ffff cartridge domain 1 -0x0800_0000 .. 0x0fff_ffff cartridge domain 2 -0x1000_0000 .. 0x1fbf_ffff cartridge domain 1 - -0x1fc0_0000 .. 0x1fc0_07bf PIF Boot Rom (1984 bytes) -0x1fc0_07c0 .. 0x1fc0_07ff PIF (JoyChannel) RAM (64 bytes) -0x1fc0_0800 .. 0x1fcf_ffff Reserved -0x1fd0_0000 .. 0x7fff_ffff cartridge domain 1 -0x8000_0000 .. 0xffff_ffff external SysAD device - -The Indy development board use cartridge domain 1: -0x1000_0000 .. 0x10ff_ffff RAMROM -0x1800_0000 .. 0x1800_0003 GIO interrupt (6 bits valid in 4 bytes) -0x1800_0400 .. 0x1800_0403 GIO sync (6 bits valid in 4 bytes) -0x1800_0800 .. 0x1800_0803 CART interrupt (6 bits valid in 4 bytes) - - - -**************************************************************************/ - -/************************************************************************* - * RDRAM Memory (Assumes that maximum size is 4 MB) +/** + * RCP memory map overview: + * + * 0x0000_0000 .. 0x03ef_ffff RDRAM memory + * 0x03f0_0000 .. 0x03ff_ffff RDRAM registers + * + * 0x0400_0000 .. 0x0400_2000 SP memory + * 0x0404_0000 .. 0x040f_ffff SP registers + * 0x0410_0000 .. 0x041f_ffff DP command registers + * 0x0420_0000 .. 0x042f_ffff DP span registers + * 0x0430_0000 .. 0x043f_ffff MI registers + * 0x0440_0000 .. 0x044f_ffff VI registers + * 0x0450_0000 .. 0x045f_ffff AI registers + * 0x0460_0000 .. 0x046f_ffff PI registers + * 0x0470_0000 .. 0x047f_ffff RI registers + * 0x0480_0000 .. 0x048f_ffff SI registers + * 0x0490_0000 .. 0x04ff_ffff unused + * + * 0x0500_0000 .. 0x05ff_ffff cartridge domain 2 + * 0x0600_0000 .. 0x07ff_ffff cartridge domain 1 + * 0x0800_0000 .. 0x0fff_ffff cartridge domain 2 + * 0x1000_0000 .. 0x1fbf_ffff cartridge domain 1 + * + * 0x1fc0_0000 .. 0x1fc0_07bf PIF Boot Rom (1984 bytes) + * 0x1fc0_07c0 .. 0x1fc0_07ff PIF (JoyChannel) RAM (64 bytes) + * 0x1fc0_0800 .. 0x1fcf_ffff Reserved + * 0x1fd0_0000 .. 0x7fff_ffff cartridge domain 1 + * 0x8000_0000 .. 0xffff_ffff external SysAD device */ -#define RDRAM_0_START 0x00000000 -#define RDRAM_0_END 0x001FFFFF -#define RDRAM_1_START 0x00200000 -#define RDRAM_1_END 0x003FFFFF -#define RDRAM_START RDRAM_0_START -#define RDRAM_END RDRAM_1_END - - -/************************************************************************* - * Address predicates +/** + * RDRAM memory */ -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) -#define IS_RDRAM(x) ((unsigned)(x) >= RDRAM_START && \ - (unsigned)(x) < RDRAM_END) -#endif +#define RDRAM_0_START 0x00000000 +#define RDRAM_0_END 0x001FFFFF +#define RDRAM_1_START 0x00200000 +#define RDRAM_1_END 0x003FFFFF -/************************************************************************* - * RDRAM Registers (0x03f0_0000 .. 0x03ff_ffff) +#define RDRAM_START RDRAM_0_START +#define RDRAM_END RDRAM_1_END + +/** + * RDRAM registers */ -#define RDRAM_BASE_REG 0x03F00000 +#define RDRAM_BASE_REG 0x03F00000 -#define RDRAM_CONFIG_REG (RDRAM_BASE_REG+0x00) -#define RDRAM_DEVICE_TYPE_REG (RDRAM_BASE_REG+0x00) -#define RDRAM_DEVICE_ID_REG (RDRAM_BASE_REG+0x04) -#define RDRAM_DELAY_REG (RDRAM_BASE_REG+0x08) -#define RDRAM_MODE_REG (RDRAM_BASE_REG+0x0c) -#define RDRAM_REF_INTERVAL_REG (RDRAM_BASE_REG+0x10) -#define RDRAM_REF_ROW_REG (RDRAM_BASE_REG+0x14) -#define RDRAM_RAS_INTERVAL_REG (RDRAM_BASE_REG+0x18) -#define RDRAM_MIN_INTERVAL_REG (RDRAM_BASE_REG+0x1c) -#define RDRAM_ADDR_SELECT_REG (RDRAM_BASE_REG+0x20) -#define RDRAM_DEVICE_MANUF_REG (RDRAM_BASE_REG+0x24) +#define RDRAM_CONFIG_REG (RDRAM_BASE_REG + 0x00) +#define RDRAM_DEVICE_TYPE_REG (RDRAM_BASE_REG + 0x00) +#define RDRAM_DEVICE_ID_REG (RDRAM_BASE_REG + 0x04) +#define RDRAM_DELAY_REG (RDRAM_BASE_REG + 0x08) +#define RDRAM_MODE_REG (RDRAM_BASE_REG + 0x0c) +#define RDRAM_REF_INTERVAL_REG (RDRAM_BASE_REG + 0x10) +#define RDRAM_REF_ROW_REG (RDRAM_BASE_REG + 0x14) +#define RDRAM_RAS_INTERVAL_REG (RDRAM_BASE_REG + 0x18) +#define RDRAM_MIN_INTERVAL_REG (RDRAM_BASE_REG + 0x1c) +#define RDRAM_ADDR_SELECT_REG (RDRAM_BASE_REG + 0x20) +#define RDRAM_DEVICE_MANUF_REG (RDRAM_BASE_REG + 0x24) -#define RDRAM_0_DEVICE_ID 0 -#define RDRAM_1_DEVICE_ID 1 +#define RDRAM_0_DEVICE_ID 0 +#define RDRAM_1_DEVICE_ID 1 -#define RDRAM_RESET_MODE 0 -#define RDRAM_ACTIVE_MODE 1 -#define RDRAM_STANDBY_MODE 2 +#define RDRAM_RESET_MODE 0 +#define RDRAM_ACTIVE_MODE 1 +#define RDRAM_STANDBY_MODE 2 -#define RDRAM_LENGTH (2*512*2048) -#define RDRAM_0_BASE_ADDRESS (RDRAM_0_DEVICE_ID*RDRAM_LENGTH) -#define RDRAM_1_BASE_ADDRESS (RDRAM_1_DEVICE_ID*RDRAM_LENGTH) +#define RDRAM_LENGTH (2 * 512 * 2048) +#define RDRAM_0_BASE_ADDRESS (RDRAM_0_DEVICE_ID * RDRAM_LENGTH) +#define RDRAM_1_BASE_ADDRESS (RDRAM_1_DEVICE_ID * RDRAM_LENGTH) -#define RDRAM_0_CONFIG 0x00000 -#define RDRAM_1_CONFIG 0x00400 -#define RDRAM_GLOBAL_CONFIG 0x80000 +#define RDRAM_0_CONFIG 0x00000 +#define RDRAM_1_CONFIG 0x00400 +#define RDRAM_GLOBAL_CONFIG 0x80000 - -/************************************************************************* +/** * PIF Physical memory map (total size = 2 KB) * - * Size Description Mode - * 1FC007FF +-------+-----------------+-----+ - * | 64 B | JoyChannel RAM | R/W | - * 1FC007C0 +-------+-----------------+-----+ - * |1984 B | Boot ROM | * | * = Reserved - * 1FC00000 +-------+-----------------+-----+ - * + * Size Description Mode + * 1FC007FF +-------+-----------------+-----+ + * | 64 B | JoyChannel RAM | R/W | + * 1FC007C0 +-------+-----------------+-----+ + * |1984 B | Boot ROM | * | * = Reserved + * 1FC00000 +-------+-----------------+-----+ */ -#define PIF_ROM_START 0x1FC00000 -#define PIF_ROM_END 0x1FC007BF -#define PIF_RAM_START 0x1FC007C0 -#define PIF_RAM_END 0x1FC007FF +#define PIF_ROM_START 0x1FC00000 +#define PIF_ROM_END 0x1FC007BF +#define PIF_RAM_START 0x1FC007C0 +#define PIF_RAM_END 0x1FC007FF -/************************************************************************* +/** * Controller channel * Each game controller channel has 4 error bits that are defined in bit 6-7 of * the Rx and Tx data size area bytes. Programmers need to clear these bits @@ -153,699 +131,691 @@ The Indy development board use cartridge domain 1: #define CHNL_ERR_MASK 0xC0 /* Bit 6-7: channel errors */ -/************************************************************************* +/** * External device info */ #define DEVICE_TYPE_CART 0 /* ROM cartridge */ #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 */ +/* 8-14 are reserved */ -/************************************************************************* - * SP Memory +/** + * Signal Processor (SP) Memory */ -#define SP_DMEM_START 0x04000000 /* read/write */ -#define SP_DMEM_END 0x04000FFF -#define SP_IMEM_START 0x04001000 /* read/write */ -#define SP_IMEM_END 0x04001FFF +#define SP_DMEM_START 0x04000000 +#define SP_DMEM_END 0x04000FFF +#define SP_IMEM_START 0x04001000 +#define SP_IMEM_END 0x04001FFF -/************************************************************************* - * SP CP0 Registers +/** + * Signal Processor (SP) CP0 Registers */ -#define SP_BASE_REG 0x04040000 +#define SP_BASE_REG 0x04040000 -/* SP memory address (R/W): [11:0] DMEM/IMEM address; [12] 0=DMEM,1=IMEM */ -#define SP_MEM_ADDR_REG (SP_BASE_REG+0x00) /* Master */ +/* SP memory address (R/W): [11:0] DMEM/IMEM address, [12] 0=DMEM,1=IMEM */ +#define SP_MEM_ADDR_REG (SP_BASE_REG + 0x00) /* SP DRAM DMA address (R/W): [23:0] RDRAM address */ -#define SP_DRAM_ADDR_REG (SP_BASE_REG+0x04) /* Slave */ +#define SP_DRAM_ADDR_REG (SP_BASE_REG + 0x04) -/* SP read DMA length (R/W): [11:0] length, [19:12] count, [31:20] skip */ -/* direction: I/DMEM <- RDRAM */ -#define SP_RD_LEN_REG (SP_BASE_REG+0x08) /* R/W: read len */ +/* SP read DMA length (R/W): [11:0] length, [19:12] count, [31:20] skip; RDRAM -> I/DMEM */ +#define SP_RD_LEN_REG (SP_BASE_REG + 0x08) -/* SP write DMA length (R/W): [11:0] length, [19:12] count, [31:20] skip */ -/* direction: I/DMEM -> RDRAM */ -#define SP_WR_LEN_REG (SP_BASE_REG+0x0C) /* R/W: write len */ +/* SP write DMA length (R/W): [11:0] length, [19:12] count, [31:20] skip; I/DMEM -> RDRAM */ +#define SP_WR_LEN_REG (SP_BASE_REG + 0x0C) /* SP status (R/W): [14:0] valid bits; see below for write/read mode */ -#define SP_STATUS_REG (SP_BASE_REG+0x10) +#define SP_STATUS_REG (SP_BASE_REG + 0x10) -/* SP DMA full (R): [0] valid bit; dma full */ -#define SP_DMA_FULL_REG (SP_BASE_REG+0x14) +/* SP DMA full (R): [0] dma full */ +#define SP_DMA_FULL_REG (SP_BASE_REG + 0x14) -/* SP DMA busy (R): [0] valid bit; dma busy */ -#define SP_DMA_BUSY_REG (SP_BASE_REG+0x18) +/* SP DMA busy (R): [0] dma busy */ +#define SP_DMA_BUSY_REG (SP_BASE_REG + 0x18) -/* SP semaphore (R/W): Read: [0] semaphore flag (set on read) */ -/* Write: [] clear semaphore flag */ -#define SP_SEMAPHORE_REG (SP_BASE_REG+0x1C) +/* SP semaphore (R/W): Read: [0] acquire semaphore; Write: [] release semaphore */ +#define SP_SEMAPHORE_REG (SP_BASE_REG + 0x1C) /* SP PC (R/W): [11:0] program counter */ -#define SP_PC_REG 0x04080000 +#define SP_PC_REG 0x04080000 -/* SP MEM address: bit 12 specifies if address is IMEM or DMEM */ -#define SP_DMA_DMEM 0x0000 /* Bit 12: 0=DMEM, 1=IMEM */ -#define SP_DMA_IMEM 0x1000 /* Bit 12: 0=DMEM, 1=IMEM */ +/** + * SP_MEM_ADDR_REG: bit 12 + */ +#define SP_DMA_DMEM (0 << 12) +#define SP_DMA_IMEM (1 << 12) + +/** + * SP_STATUS_REG: write bits + */ +#define SP_CLR_HALT (1 << 0) /* clear halt */ +#define SP_SET_HALT (1 << 1) /* set halt */ +#define SP_CLR_BROKE (1 << 2) /* clear broke */ +#define SP_CLR_INTR (1 << 3) /* clear interrupt */ +#define SP_SET_INTR (1 << 4) /* set interrupt */ +#define SP_CLR_SSTEP (1 << 5) /* clear sstep */ +#define SP_SET_SSTEP (1 << 6) /* set sstep */ +#define SP_CLR_INTR_BREAK (1 << 7) /* clear interrupt on break */ +#define SP_SET_INTR_BREAK (1 << 8) /* set interrupt on break */ +#define SP_CLR_SIG0 (1 << 9) /* clear signal 0 */ +#define SP_SET_SIG0 (1 << 10) /* set signal 0 */ +#define SP_CLR_SIG1 (1 << 11) /* clear signal 1 */ +#define SP_SET_SIG1 (1 << 12) /* set signal 1 */ +#define SP_CLR_SIG2 (1 << 13) /* clear signal 2 */ +#define SP_SET_SIG2 (1 << 14) /* set signal 2 */ +#define SP_CLR_SIG3 (1 << 15) /* clear signal 3 */ +#define SP_SET_SIG3 (1 << 16) /* set signal 3 */ +#define SP_CLR_SIG4 (1 << 17) /* clear signal 4 */ +#define SP_SET_SIG4 (1 << 18) /* set signal 4 */ +#define SP_CLR_SIG5 (1 << 19) /* clear signal 5 */ +#define SP_SET_SIG5 (1 << 20) /* set signal 5 */ +#define SP_CLR_SIG6 (1 << 21) /* clear signal 6 */ +#define SP_SET_SIG6 (1 << 22) /* set signal 6 */ +#define SP_CLR_SIG7 (1 << 23) /* clear signal 7 */ +#define SP_SET_SIG7 (1 << 24) /* set signal 7 */ /* - * Values to clear/set bit in status reg (SP_STATUS_REG - write) + * SP_STATUS_REG: read bits */ -#define SP_CLR_HALT 0x00001 /* Bit 0: clear halt */ -#define SP_SET_HALT 0x00002 /* Bit 1: set halt */ -#define SP_CLR_BROKE 0x00004 /* Bit 2: clear broke */ -#define SP_CLR_INTR 0x00008 /* Bit 3: clear intr */ -#define SP_SET_INTR 0x00010 /* Bit 4: set intr */ -#define SP_CLR_SSTEP 0x00020 /* Bit 5: clear sstep */ -#define SP_SET_SSTEP 0x00040 /* Bit 6: set sstep */ -#define SP_CLR_INTR_BREAK 0x00080 /* Bit 7: clear intr on break */ -#define SP_SET_INTR_BREAK 0x00100 /* Bit 8: set intr on break */ -#define SP_CLR_SIG0 0x00200 /* Bit 9: clear signal 0 */ -#define SP_SET_SIG0 0x00400 /* Bit 10: set signal 0 */ -#define SP_CLR_SIG1 0x00800 /* Bit 11: clear signal 1 */ -#define SP_SET_SIG1 0x01000 /* Bit 12: set signal 1 */ -#define SP_CLR_SIG2 0x02000 /* Bit 13: clear signal 2 */ -#define SP_SET_SIG2 0x04000 /* Bit 14: set signal 2 */ -#define SP_CLR_SIG3 0x08000 /* Bit 15: clear signal 3 */ -#define SP_SET_SIG3 0x10000 /* Bit 16: set signal 3 */ -#define SP_CLR_SIG4 0x20000 /* Bit 17: clear signal 4 */ -#define SP_SET_SIG4 0x40000 /* Bit 18: set signal 4 */ -#define SP_CLR_SIG5 0x80000 /* Bit 19: clear signal 5 */ -#define SP_SET_SIG5 0x100000 /* Bit 20: set signal 5 */ -#define SP_CLR_SIG6 0x200000 /* Bit 21: clear signal 6 */ -#define SP_SET_SIG6 0x400000 /* Bit 22: set signal 6 */ -#define SP_CLR_SIG7 0x800000 /* Bit 23: clear signal 7 */ -#define SP_SET_SIG7 0x1000000 /* Bit 24: set signal 7 */ - -/* - * Patterns to interpret status reg (SP_STATUS_REG - read) - */ -#define SP_STATUS_HALT 0x001 /* Bit 0: halt */ -#define SP_STATUS_BROKE 0x002 /* Bit 1: broke */ -#define SP_STATUS_DMA_BUSY 0x004 /* Bit 2: dma busy */ -#define SP_STATUS_DMA_FULL 0x008 /* Bit 3: dma full */ -#define SP_STATUS_IO_FULL 0x010 /* Bit 4: io full */ -#define SP_STATUS_SSTEP 0x020 /* Bit 5: single step */ -#define SP_STATUS_INTR_BREAK 0x040 /* Bit 6: interrupt on break */ -#define SP_STATUS_SIG0 0x080 /* Bit 7: signal 0 set */ -#define SP_STATUS_SIG1 0x100 /* Bit 8: signal 1 set */ -#define SP_STATUS_SIG2 0x200 /* Bit 9: signal 2 set */ -#define SP_STATUS_SIG3 0x400 /* Bit 10: signal 3 set */ -#define SP_STATUS_SIG4 0x800 /* Bit 11: signal 4 set */ -#define SP_STATUS_SIG5 0x1000 /* Bit 12: signal 5 set */ -#define SP_STATUS_SIG6 0x2000 /* Bit 13: signal 6 set */ -#define SP_STATUS_SIG7 0x4000 /* Bit 14: signal 7 set */ +#define SP_STATUS_HALT (1 << 0) +#define SP_STATUS_BROKE (1 << 1) +#define SP_STATUS_DMA_BUSY (1 << 2) +#define SP_STATUS_DMA_FULL (1 << 3) +#define SP_STATUS_IO_FULL (1 << 4) +#define SP_STATUS_SSTEP (1 << 5) +#define SP_STATUS_INTR_BREAK (1 << 6) +#define SP_STATUS_SIG0 (1 << 7) +#define SP_STATUS_SIG1 (1 << 8) +#define SP_STATUS_SIG2 (1 << 9) +#define SP_STATUS_SIG3 (1 << 10) +#define SP_STATUS_SIG4 (1 << 11) +#define SP_STATUS_SIG5 (1 << 12) +#define SP_STATUS_SIG6 (1 << 13) +#define SP_STATUS_SIG7 (1 << 14) /* - * Use of SIG bits + * SP_STATUS_REG: use of SIG bits */ -#define SP_CLR_YIELD SP_CLR_SIG0 /* Bit 9 */ -#define SP_SET_YIELD SP_SET_SIG0 /* Bit 10 */ -#define SP_STATUS_YIELD SP_STATUS_SIG0 /* Bit 7 */ -#define SP_CLR_YIELDED SP_CLR_SIG1 /* Bit 11 */ -#define SP_SET_YIELDED SP_SET_SIG1 /* Bit 12 */ -#define SP_STATUS_YIELDED SP_STATUS_SIG1 /* Bit 8 */ -#define SP_CLR_TASKDONE SP_CLR_SIG2 /* Bit 13 */ -#define SP_SET_TASKDONE SP_SET_SIG2 /* Bit 14 */ -#define SP_STATUS_TASKDONE SP_STATUS_SIG2 /* Bit 9 */ -#define SP_CLR_RSPSIGNAL SP_CLR_SIG3 /* Bit 15 */ -#define SP_SET_RSPSIGNAL SP_SET_SIG3 /* Bit 16 */ -#define SP_STATUS_RSPSIGNAL SP_STATUS_SIG3 /* Bit 10 */ -#define SP_CLR_CPUSIGNAL SP_CLR_SIG4 /* Bit 17 */ -#define SP_SET_CPUSIGNAL SP_SET_SIG4 /* Bit 18 */ -#define SP_STATUS_CPUSIGNAL SP_STATUS_SIG4 /* Bit 11 */ - -/* SP IMEM BIST REG (R/W): [6:0] BIST status bits; see below for detail */ -#define SP_IBIST_REG 0x04080004 +#define SP_CLR_YIELD SP_CLR_SIG0 +#define SP_SET_YIELD SP_SET_SIG0 +#define SP_STATUS_YIELD SP_STATUS_SIG0 +#define SP_CLR_YIELDED SP_CLR_SIG1 +#define SP_SET_YIELDED SP_SET_SIG1 +#define SP_STATUS_YIELDED SP_STATUS_SIG1 +#define SP_CLR_TASKDONE SP_CLR_SIG2 +#define SP_SET_TASKDONE SP_SET_SIG2 +#define SP_STATUS_TASKDONE SP_STATUS_SIG2 +#define SP_CLR_RSPSIGNAL SP_CLR_SIG3 +#define SP_SET_RSPSIGNAL SP_SET_SIG3 +#define SP_STATUS_RSPSIGNAL SP_STATUS_SIG3 +#define SP_CLR_CPUSIGNAL SP_CLR_SIG4 +#define SP_SET_CPUSIGNAL SP_SET_SIG4 +#define SP_STATUS_CPUSIGNAL SP_STATUS_SIG4 /* - * Patterns to interpret status reg (SP_BIST_REG - write) + * SP IMEM BIST REG (R/W): [6:0] BIST status bits; see below for detail */ -#define SP_IBIST_CHECK 0x01 /* Bit 0: BIST check */ -#define SP_IBIST_GO 0x02 /* Bit 1: BIST go */ -#define SP_IBIST_CLEAR 0x04 /* Bit 2: BIST clear */ +#define SP_IBIST_REG 0x04080004 /* - * Patterns to interpret status reg (SP_BIST_REG - read) + * SP_IBIST_REG: write bits */ -/* First 2 bits are same as in write mode: - * Bit 0: BIST check; Bit 1: BIST go - */ -#define SP_IBIST_DONE 0x04 /* Bit 2: BIST done */ -#define SP_IBIST_FAILED 0x78 /* Bit [6:3]: BIST fail */ +#define SP_IBIST_CHECK (1 << 0) /* BIST check */ +#define SP_IBIST_GO (1 << 1) /* BIST go */ +#define SP_IBIST_CLEAR (1 << 2) /* BIST clear */ - -/************************************************************************* - * DP Command Registers +/* + * SP_BIST_REG: read bits + * First 2 bits are same as in write mode */ -#define DPC_BASE_REG 0x04100000 +#define SP_IBIST_DONE (1 << 2) +#define SP_IBIST_FAILED 0x78 /* bits [6:3], BIST fail */ + +/** + * Display Processor Command (DPC) Registers + */ +#define DPC_BASE_REG 0x04100000 /* DP CMD DMA start (R/W): [23:0] DMEM/RDRAM start address */ -#define DPC_START_REG (DPC_BASE_REG+0x00) +#define DPC_START_REG (DPC_BASE_REG + 0x00) /* DP CMD DMA end (R/W): [23:0] DMEM/RDRAM end address */ -#define DPC_END_REG (DPC_BASE_REG+0x04) +#define DPC_END_REG (DPC_BASE_REG + 0x04) /* DP CMD DMA end (R): [23:0] DMEM/RDRAM current address */ -#define DPC_CURRENT_REG (DPC_BASE_REG+0x08) +#define DPC_CURRENT_REG (DPC_BASE_REG + 0x08) /* DP CMD status (R/W): [9:0] valid bits - see below for definitions */ -#define DPC_STATUS_REG (DPC_BASE_REG+0x0C) +#define DPC_STATUS_REG (DPC_BASE_REG + 0x0C) /* DP clock counter (R): [23:0] clock counter */ -#define DPC_CLOCK_REG (DPC_BASE_REG+0x10) +#define DPC_CLOCK_REG (DPC_BASE_REG + 0x10) /* DP buffer busy counter (R): [23:0] clock counter */ -#define DPC_BUFBUSY_REG (DPC_BASE_REG+0x14) +#define DPC_BUFBUSY_REG (DPC_BASE_REG + 0x14) /* DP pipe busy counter (R): [23:0] clock counter */ -#define DPC_PIPEBUSY_REG (DPC_BASE_REG+0x18) +#define DPC_PIPEBUSY_REG (DPC_BASE_REG + 0x18) /* DP TMEM load counter (R): [23:0] clock counter */ -#define DPC_TMEM_REG (DPC_BASE_REG+0x1C) +#define DPC_TMEM_REG (DPC_BASE_REG + 0x1C) -/* - * Values to clear/set bit in status reg (DPC_STATUS_REG - write) +/** + * DPC_STATUS_REG: write bits */ -#define DPC_CLR_XBUS_DMEM_DMA 0x0001 /* Bit 0: clear xbus_dmem_dma */ -#define DPC_SET_XBUS_DMEM_DMA 0x0002 /* Bit 1: set xbus_dmem_dma */ -#define DPC_CLR_FREEZE 0x0004 /* Bit 2: clear freeze */ -#define DPC_SET_FREEZE 0x0008 /* Bit 3: set freeze */ -#define DPC_CLR_FLUSH 0x0010 /* Bit 4: clear flush */ -#define DPC_SET_FLUSH 0x0020 /* Bit 5: set flush */ -#define DPC_CLR_TMEM_CTR 0x0040 /* Bit 6: clear tmem ctr */ -#define DPC_CLR_PIPE_CTR 0x0080 /* Bit 7: clear pipe ctr */ -#define DPC_CLR_CMD_CTR 0x0100 /* Bit 8: clear cmd ctr */ -#define DPC_CLR_CLOCK_CTR 0x0200 /* Bit 9: clear clock ctr */ +#define DPC_CLR_XBUS_DMEM_DMA (1 << 0) +#define DPC_SET_XBUS_DMEM_DMA (1 << 1) +#define DPC_CLR_FREEZE (1 << 2) +#define DPC_SET_FREEZE (1 << 3) +#define DPC_CLR_FLUSH (1 << 4) +#define DPC_SET_FLUSH (1 << 5) +#define DPC_CLR_TMEM_CTR (1 << 6) +#define DPC_CLR_PIPE_CTR (1 << 7) +#define DPC_CLR_CMD_CTR (1 << 8) +#define DPC_CLR_CLOCK_CTR (1 << 9) -/* - * Patterns to interpret status reg (DPC_STATUS_REG - read) +/** + * DPC_STATUS_REG: read bits */ -#define DPC_STATUS_XBUS_DMEM_DMA 0x001 /* Bit 0: xbus_dmem_dma */ -#define DPC_STATUS_FREEZE 0x002 /* Bit 1: freeze */ -#define DPC_STATUS_FLUSH 0x004 /* Bit 2: flush */ -/*#define DPC_STATUS_FROZEN 0x008*/ /* Bit 3: frozen */ -#define DPC_STATUS_START_GCLK 0x008 /* Bit 3: start gclk */ -#define DPC_STATUS_TMEM_BUSY 0x010 /* Bit 4: tmem busy */ -#define DPC_STATUS_PIPE_BUSY 0x020 /* Bit 5: pipe busy */ -#define DPC_STATUS_CMD_BUSY 0x040 /* Bit 6: cmd busy */ -#define DPC_STATUS_CBUF_READY 0x080 /* Bit 7: cbuf ready */ -#define DPC_STATUS_DMA_BUSY 0x100 /* Bit 8: dma busy */ -#define DPC_STATUS_END_VALID 0x200 /* Bit 9: end valid */ -#define DPC_STATUS_START_VALID 0x400 /* Bit 10: start valid */ +#define DPC_STATUS_XBUS_DMEM_DMA (1 << 0) +#define DPC_STATUS_FREEZE (1 << 1) +#define DPC_STATUS_FLUSH (1 << 2) +#define DPC_STATUS_START_GCLK (1 << 3) +#define DPC_STATUS_TMEM_BUSY (1 << 4) +#define DPC_STATUS_PIPE_BUSY (1 << 5) +#define DPC_STATUS_CMD_BUSY (1 << 6) +#define DPC_STATUS_CBUF_READY (1 << 7) +#define DPC_STATUS_DMA_BUSY (1 << 8) +#define DPC_STATUS_END_VALID (1 << 9) +#define DPC_STATUS_START_VALID (1 << 10) - -/************************************************************************* - * DP Span Registers +/** + * Display Processor Span (DPS) Registers */ -#define DPS_BASE_REG 0x04200000 +#define DPS_BASE_REG 0x04200000 -/* DP tmem bist (R/W): [10:0] BIST status bits; see below for detail */ -#define DPS_TBIST_REG (DPS_BASE_REG+0x00) +/* DP tmem built-in self-test (R/W): [10:0] BIST status bits */ +#define DPS_TBIST_REG (DPS_BASE_REG + 0x00) /* DP span test mode (R/W): [0] Span buffer test access enable */ -#define DPS_TEST_MODE_REG (DPS_BASE_REG+0x04) +#define DPS_TEST_MODE_REG (DPS_BASE_REG + 0x04) -/* DP span buffer test address (R/W): [6:0] bits; see below for detail */ -#define DPS_BUFTEST_ADDR_REG (DPS_BASE_REG+0x08) +/* DP span buffer test address (R/W): [6:0] bits */ +#define DPS_BUFTEST_ADDR_REG (DPS_BASE_REG + 0x08) /* DP span buffer test data (R/W): [31:0] span buffer data */ -#define DPS_BUFTEST_DATA_REG (DPS_BASE_REG+0x0C) +#define DPS_BUFTEST_DATA_REG (DPS_BASE_REG + 0x0C) /* - * Patterns to interpret status reg (DPS_TMEM_BIST_REG - write) + * DPS_TMEM_BIST_REG: write bits */ -#define DPS_TBIST_CHECK 0x01 /* Bit 0: BIST check */ -#define DPS_TBIST_GO 0x02 /* Bit 1: BIST go */ -#define DPS_TBIST_CLEAR 0x04 /* Bit 2: BIST clear */ +#define DPS_TBIST_CHECK (1 << 0) +#define DPS_TBIST_GO (1 << 1) +#define DPS_TBIST_CLEAR (1 << 2) /* - * Patterns to interpret status reg (DPS_TMEM_BIST_REG - read) + * DPS_TMEM_BIST_REG: read bits + * First 2 bits are same as in write mode */ -/* First 2 bits are same as in write mode: - * Bit 0: BIST check; Bit 1: BIST go - */ -#define DPS_TBIST_DONE 0x004 /* Bit 2: BIST done */ -#define DPS_TBIST_FAILED 0x7F8 /* Bit [10:3]: BIST fail */ +#define DPS_TBIST_DONE (1 << 2) +#define DPS_TBIST_FAILED 0x7F8 /* bits [10:3], BIST fail */ - -/************************************************************************* - * MIPS Interface (MI) Registers +/** + * MIPS Interface (MI) Registers */ -#define MI_BASE_REG 0x04300000 +#define MI_BASE_REG 0x04300000 /* * MI init mode (W): [6:0] init length, [7] clear init mode, [8] set init mode * [9/10] clear/set ebus test mode, [11] clear DP interrupt * (R): [6:0] init length, [7] init mode, [8] ebus test mode */ -#define MI_INIT_MODE_REG (MI_BASE_REG+0x00) -#define MI_MODE_REG MI_INIT_MODE_REG +#define MI_INIT_MODE_REG (MI_BASE_REG + 0x00) +#define MI_MODE_REG MI_INIT_MODE_REG /* - * Values to clear/set bit in mode reg (MI_MODE_REG - write) + * MI_MODE_REG: write bits */ -#define MI_CLR_INIT 0x0080 /* Bit 7: clear init mode */ -#define MI_SET_INIT 0x0100 /* Bit 8: set init mode */ -#define MI_CLR_EBUS 0x0200 /* Bit 9: clear ebus test */ -#define MI_SET_EBUS 0x0400 /* Bit 10: set ebus test mode */ -#define MI_CLR_DP_INTR 0x0800 /* Bit 11: clear dp interrupt */ -#define MI_CLR_RDRAM 0x1000 /* Bit 12: clear RDRAM reg */ -#define MI_SET_RDRAM 0x2000 /* Bit 13: set RDRAM reg mode */ +#define MI_CLR_INIT (1 << 7) /* clear init mode */ +#define MI_SET_INIT (1 << 8) /* set init mode */ +#define MI_CLR_EBUS (1 << 9) /* clear ebus test */ +#define MI_SET_EBUS (1 << 10) /* set ebus test mode */ +#define MI_CLR_DP_INTR (1 << 11) /* clear dp interrupt */ +#define MI_CLR_RDRAM (1 << 12) /* clear RDRAM reg */ +#define MI_SET_RDRAM (1 << 13) /* set RDRAM reg mode */ /* - * Patterns to interpret mode reg (MI_MODE_REG - read) + * MI_MODE_REG: read bits */ -#define MI_MODE_INIT 0x0080 /* Bit 7: init mode */ -#define MI_MODE_EBUS 0x0100 /* Bit 8: ebus test mode */ -#define MI_MODE_RDRAM 0x0200 /* Bit 9: RDRAM reg mode */ +#define MI_MODE_INIT (1 << 7) /* init mode */ +#define MI_MODE_EBUS (1 << 8) /* ebus test mode */ +#define MI_MODE_RDRAM (1 << 9) /* RDRAM reg mode */ /* MI version (R): [7:0] io, [15:8] rac, [23:16] rdp, [31:24] rsp */ -#define MI_VERSION_REG (MI_BASE_REG+0x04) -#define MI_NOOP_REG MI_VERSION_REG +#define MI_VERSION_REG (MI_BASE_REG + 0x04) +#define MI_NOOP_REG MI_VERSION_REG /* MI interrupt (R): [5:0] valid bits - see below for bit patterns */ -#define MI_INTR_REG (MI_BASE_REG+0x08) +#define MI_INTR_REG (MI_BASE_REG + 0x08) /* * MI interrupt mask (W): [11:0] valid bits - see below for bit patterns * (R): [5:0] valid bits - see below for bit patterns */ -#define MI_INTR_MASK_REG (MI_BASE_REG+0x0C) +#define MI_INTR_MASK_REG (MI_BASE_REG + 0x0C) /* - * The following are values to check for interrupt setting (MI_INTR_REG) + * MI_INTR_REG: read bits */ -#define MI_INTR_SP 0x01 /* Bit 0: SP intr */ -#define MI_INTR_SI 0x02 /* Bit 1: SI intr */ -#define MI_INTR_AI 0x04 /* Bit 2: AI intr */ -#define MI_INTR_VI 0x08 /* Bit 3: VI intr */ -#define MI_INTR_PI 0x10 /* Bit 4: PI intr */ -#define MI_INTR_DP 0x20 /* Bit 5: DP intr */ +#define MI_INTR_SP (1 << 0) /* SP intr */ +#define MI_INTR_SI (1 << 1) /* SI intr */ +#define MI_INTR_AI (1 << 2) /* AI intr */ +#define MI_INTR_VI (1 << 3) /* VI intr */ +#define MI_INTR_PI (1 << 4) /* PI intr */ +#define MI_INTR_DP (1 << 5) /* DP intr */ /* - * The following are values to clear/set various interrupt bit mask - * They can be ORed together to manipulate multiple bits - * (MI_INTR_MASK_REG - write) + * MI_INTR_MASK_REG: write bits */ -#define MI_INTR_MASK_CLR_SP 0x0001 /* Bit 0: clear SP mask */ -#define MI_INTR_MASK_SET_SP 0x0002 /* Bit 1: set SP mask */ -#define MI_INTR_MASK_CLR_SI 0x0004 /* Bit 2: clear SI mask */ -#define MI_INTR_MASK_SET_SI 0x0008 /* Bit 3: set SI mask */ -#define MI_INTR_MASK_CLR_AI 0x0010 /* Bit 4: clear AI mask */ -#define MI_INTR_MASK_SET_AI 0x0020 /* Bit 5: set AI mask */ -#define MI_INTR_MASK_CLR_VI 0x0040 /* Bit 6: clear VI mask */ -#define MI_INTR_MASK_SET_VI 0x0080 /* Bit 7: set VI mask */ -#define MI_INTR_MASK_CLR_PI 0x0100 /* Bit 8: clear PI mask */ -#define MI_INTR_MASK_SET_PI 0x0200 /* Bit 9: set PI mask */ -#define MI_INTR_MASK_CLR_DP 0x0400 /* Bit 10: clear DP mask */ -#define MI_INTR_MASK_SET_DP 0x0800 /* Bit 11: set DP mask */ +#define MI_INTR_MASK_CLR_SP (1 << 0) /* clear SP mask */ +#define MI_INTR_MASK_SET_SP (1 << 1) /* set SP mask */ +#define MI_INTR_MASK_CLR_SI (1 << 2) /* clear SI mask */ +#define MI_INTR_MASK_SET_SI (1 << 3) /* set SI mask */ +#define MI_INTR_MASK_CLR_AI (1 << 4) /* clear AI mask */ +#define MI_INTR_MASK_SET_AI (1 << 5) /* set AI mask */ +#define MI_INTR_MASK_CLR_VI (1 << 6) /* clear VI mask */ +#define MI_INTR_MASK_SET_VI (1 << 7) /* set VI mask */ +#define MI_INTR_MASK_CLR_PI (1 << 8) /* clear PI mask */ +#define MI_INTR_MASK_SET_PI (1 << 9) /* set PI mask */ +#define MI_INTR_MASK_CLR_DP (1 << 10) /* clear DP mask */ +#define MI_INTR_MASK_SET_DP (1 << 11) /* set DP mask */ /* - * The following are values to check for interrupt mask setting - * (MI_INTR_MASK_REG - read) + * MI_INTR_MASK_REG: read bits */ -#define MI_INTR_MASK_SP 0x01 /* Bit 0: SP intr mask */ -#define MI_INTR_MASK_SI 0x02 /* Bit 1: SI intr mask */ -#define MI_INTR_MASK_AI 0x04 /* Bit 2: AI intr mask */ -#define MI_INTR_MASK_VI 0x08 /* Bit 3: VI intr mask */ -#define MI_INTR_MASK_PI 0x10 /* Bit 4: PI intr mask */ -#define MI_INTR_MASK_DP 0x20 /* Bit 5: DP intr mask */ +#define MI_INTR_MASK_SP (1 << 0) /* SP intr mask */ +#define MI_INTR_MASK_SI (1 << 1) /* SI intr mask */ +#define MI_INTR_MASK_AI (1 << 2) /* AI intr mask */ +#define MI_INTR_MASK_VI (1 << 3) /* VI intr mask */ +#define MI_INTR_MASK_PI (1 << 4) /* PI intr mask */ +#define MI_INTR_MASK_DP (1 << 5) /* DP intr mask */ - -/************************************************************************* - * Video Interface (VI) Registers +/** + * Video Interface (VI) Registers */ -#define VI_BASE_REG 0x04400000 +#define VI_BASE_REG 0x04400000 /* VI status/control (R/W): [15-0] valid bits: - * [1:0] = type[1:0] (pixel size) - * 0: blank (no data, no sync) - * 1: reserved - * 2: 5/5/5/3 ("16" bit) - * 3: 8/8/8/8 (32 bit) - * [2] = gamma_dither_enable (normally on, unless "special effect") - * [3] = gamma_enable (normally on, unless MPEG/JPEG) - * [4] = divot_enable (normally on if antialiased, unless decal lines) - * [5] = reserved - always off - * [6] = serrate (always on if interlaced, off if not) - * [7] = reserved - diagnostics only - * [9:8] = anti-alias (aa) mode[1:0] - * 0: aa & resamp (always fetch extra lines) + * [1:0] = type[1:0] (pixel size) + * 0: blank (no data, no sync) + * 1: reserved + * 2: 5/5/5/3 ("16" bit) + * 3: 8/8/8/8 (32 bit) + * [2] = gamma_dither_enable (normally on, unless "special effect") + * [3] = gamma_enable (normally on, unless MPEG/JPEG) + * [4] = divot_enable (normally on if antialiased, unless decal lines) + * [5] = reserved - always off + * [6] = serrate (always on if interlaced, off if not) + * [7] = reserved - diagnostics only + * [9:8] = anti-alias (aa) mode[1:0] + * 0: aa & resamp (always fetch extra lines) * 1: aa & resamp (fetch extra lines if needed) * 2: resamp only (treat as all fully covered) * 3: neither (replicate pixels, no interpolate) - * [11] = reserved - diagnostics only - * [15:12] = reserved + * [11] = reserved - diagnostics only + * [15:12] = reserved * */ -#define VI_STATUS_REG (VI_BASE_REG+0x00) -#define VI_CONTROL_REG VI_STATUS_REG +#define VI_CONTROL_REG (VI_BASE_REG + 0x00) +#define VI_STATUS_REG VI_CONTROL_REG /* VI origin (R/W): [23:0] frame buffer origin in bytes */ -#define VI_ORIGIN_REG (VI_BASE_REG+0x04) -#define VI_DRAM_ADDR_REG VI_ORIGIN_REG +#define VI_ORIGIN_REG (VI_BASE_REG + 0x04) +#define VI_DRAM_ADDR_REG VI_ORIGIN_REG /* VI width (R/W): [11:0] frame buffer line width in pixels */ -#define VI_WIDTH_REG (VI_BASE_REG+0x08) -#define VI_H_WIDTH_REG VI_WIDTH_REG +#define VI_WIDTH_REG (VI_BASE_REG + 0x08) +#define VI_H_WIDTH_REG VI_WIDTH_REG /* VI vertical intr (R/W): [9:0] interrupt when current half-line = V_INTR */ -#define VI_INTR_REG (VI_BASE_REG+0x0C) -#define VI_V_INTR_REG VI_INTR_REG +#define VI_INTR_REG (VI_BASE_REG + 0x0C) +#define VI_V_INTR_REG VI_INTR_REG /* * VI current vertical line (R/W): [9:0] current half line, sampled once per - * line (the lsb of V_CURRENT is constant within a field, and in - * interlaced modes gives the field number - which is constant for non- - * interlaced modes) - * - Any write to this register will clear interrupt line + * line (the lsb of V_CURRENT is constant within a field, and in + * interlaced modes gives the field number - which is constant for non- + * interlaced modes) + * - Any write to this register will clear interrupt line */ -#define VI_CURRENT_REG (VI_BASE_REG+0x10) -#define VI_V_CURRENT_LINE_REG VI_CURRENT_REG +#define VI_CURRENT_REG (VI_BASE_REG + 0x10) +#define VI_V_CURRENT_LINE_REG VI_CURRENT_REG /* * VI video timing (R/W): [ 7: 0] horizontal sync width in pixels, - * [15: 8] color burst width in pixels, + * [15: 8] color burst width in pixels, * [19:16] vertical sync width in half lines, - * [29:20] start of color burst in pixels from h-sync + * [29:20] start of color burst in pixels from h-sync */ -#define VI_BURST_REG (VI_BASE_REG+0x14) -#define VI_TIMING_REG VI_BURST_REG +#define VI_BURST_REG (VI_BASE_REG + 0x14) +#define VI_TIMING_REG VI_BURST_REG /* VI vertical sync (R/W): [9:0] number of half-lines per field */ -#define VI_V_SYNC_REG (VI_BASE_REG+0x18) +#define VI_V_SYNC_REG (VI_BASE_REG + 0x18) /* VI horizontal sync (R/W): [11: 0] total duration of a line in 1/4 pixel - * [20:16] a 5-bit leap pattern used for PAL only - * (h_sync_period) + * [20:16] a 5-bit leap pattern used for PAL only + * (h_sync_period) */ -#define VI_H_SYNC_REG (VI_BASE_REG+0x1C) +#define VI_H_SYNC_REG (VI_BASE_REG + 0x1C) /* * VI horizontal sync leap (R/W): [11: 0] identical to h_sync_period * [27:16] identical to h_sync_period */ -#define VI_LEAP_REG (VI_BASE_REG+0x20) -#define VI_H_SYNC_LEAP_REG VI_LEAP_REG +#define VI_LEAP_REG (VI_BASE_REG + 0x20) +#define VI_H_SYNC_LEAP_REG VI_LEAP_REG /* * VI horizontal video (R/W): [ 9: 0] end of active video in screen pixels * : [25:16] start of active video in screen pixels */ -#define VI_H_START_REG (VI_BASE_REG+0x24) -#define VI_H_VIDEO_REG VI_H_START_REG +#define VI_H_START_REG (VI_BASE_REG + 0x24) +#define VI_H_VIDEO_REG VI_H_START_REG /* * VI vertical video (R/W): [ 9: 0] end of active video in screen half-lines * : [25:16] start of active video in screen half-lines */ -#define VI_V_START_REG (VI_BASE_REG+0x28) -#define VI_V_VIDEO_REG VI_V_START_REG +#define VI_V_START_REG (VI_BASE_REG + 0x28) +#define VI_V_VIDEO_REG VI_V_START_REG /* * VI vertical burst (R/W): [ 9: 0] end of color burst enable in half-lines * : [25:16] start of color burst enable in half-lines */ -#define VI_V_BURST_REG (VI_BASE_REG+0x2C) +#define VI_V_BURST_REG (VI_BASE_REG + 0x2C) /* VI x-scale (R/W): [11: 0] 1/horizontal scale up factor (2.10 format) - * [27:16] horizontal subpixel offset (2.10 format) + * [27:16] horizontal subpixel offset (2.10 format) */ -#define VI_X_SCALE_REG (VI_BASE_REG+0x30) +#define VI_X_SCALE_REG (VI_BASE_REG + 0x30) /* VI y-scale (R/W): [11: 0] 1/vertical scale up factor (2.10 format) - * [27:16] vertical subpixel offset (2.10 format) + * [27:16] vertical subpixel offset (2.10 format) */ -#define VI_Y_SCALE_REG (VI_BASE_REG+0x34) +#define VI_Y_SCALE_REG (VI_BASE_REG + 0x34) /* * Patterns to interpret VI_CONTROL_REG */ -#define VI_CTRL_TYPE_16 0x00002 /* Bit [1:0] pixel size: 16 bit */ -#define VI_CTRL_TYPE_32 0x00003 /* Bit [1:0] pixel size: 32 bit */ -#define VI_CTRL_GAMMA_DITHER_ON 0x00004 /* Bit 2: default = on */ -#define VI_CTRL_GAMMA_ON 0x00008 /* Bit 3: default = on */ -#define VI_CTRL_DIVOT_ON 0x00010 /* Bit 4: default = on */ -#define VI_CTRL_SERRATE_ON 0x00040 /* Bit 6: on if interlaced */ -#define VI_CTRL_ANTIALIAS_MASK 0x00300 /* Bit [9:8] anti-alias mode */ -#define VI_CTRL_DITHER_FILTER_ON 0x10000 /* Bit 16: dither-filter mode */ +#define VI_CTRL_TYPE_16 0x00002 /* [1:0] pixel size: 16 bit */ +#define VI_CTRL_TYPE_32 0x00003 /* [1:0] pixel size: 32 bit */ +#define VI_CTRL_GAMMA_DITHER_ON 0x00004 /* 2: default = on */ +#define VI_CTRL_GAMMA_ON 0x00008 /* 3: default = on */ +#define VI_CTRL_DIVOT_ON 0x00010 /* 4: default = on */ +#define VI_CTRL_SERRATE_ON 0x00040 /* 6: on if interlaced */ +#define VI_CTRL_ANTIALIAS_MASK 0x00300 /* [9:8] anti-alias mode */ +#define VI_CTRL_ANTIALIAS_MODE_0 0x00000 /* Bit [9:8] anti-alias mode: AA enabled, resampling enabled, always fetch extra lines */ +#define VI_CTRL_ANTIALIAS_MODE_1 0x00100 /* Bit [9:8] anti-alias mode: AA enabled, resampling enabled, fetch extra lines as-needed */ +#define VI_CTRL_ANTIALIAS_MODE_2 0x00200 /* Bit [9:8] anti-alias mode: AA disabled, resampling enabled, operate as if everything is covered */ +#define VI_CTRL_ANTIALIAS_MODE_3 0x00300 /* Bit [9:8] anti-alias mode: AA disabled, resampling disabled, replicate pixels */ +#define VI_CTRL_PIXEL_ADV_MASK 0x0F000 /* [15:12] pixel advance mode? */ +#define VI_CTRL_PIXEL_ADV_1 0x01000 /* Bit [15:12] pixel advance mode? */ +#define VI_CTRL_PIXEL_ADV_2 0x02000 /* Bit [15:12] pixel advance mode? */ +#define VI_CTRL_PIXEL_ADV_3 0x03000 /* Bit [15:12] pixel advance mode? */ +#define VI_CTRL_DITHER_FILTER_ON 0x10000 /* 16: dither-filter mode */ /* * Possible video clocks (NTSC or PAL) */ -#define VI_NTSC_CLOCK 48681812 /* Hz = 48.681812 MHz */ -#define VI_PAL_CLOCK 49656530 /* Hz = 49.656530 MHz */ -#define VI_MPAL_CLOCK 48628316 /* Hz = 48.628316 MHz */ +#define VI_NTSC_CLOCK 48681812 /* Hz = 48.681812 MHz */ +#define VI_PAL_CLOCK 49656530 /* Hz = 49.656530 MHz */ +#define VI_MPAL_CLOCK 48628316 /* Hz = 48.628316 MHz */ - -/************************************************************************* - * Audio Interface (AI) Registers - * +/** * The address and length registers are double buffered; that is, they * can be written twice before becoming full. * The address must be written before the length. */ -#define AI_BASE_REG 0x04500000 + +/** + * Audio Interface (AI) Registers + */ +#define AI_BASE_REG 0x04500000 /* AI DRAM address (W): [23:0] starting RDRAM address (8B-aligned) */ -#define AI_DRAM_ADDR_REG (AI_BASE_REG+0x00) /* R0: DRAM address */ +#define AI_DRAM_ADDR_REG (AI_BASE_REG + 0x00) /* R0: DRAM address */ /* AI length (R/W): [14:0] transfer length (v1.0) - Bottom 3 bits are ignored */ /* [17:0] transfer length (v2.0) - Bottom 3 bits are ignored */ -#define AI_LEN_REG (AI_BASE_REG+0x04) /* R1: Length */ +#define AI_LEN_REG (AI_BASE_REG + 0x04) /* R1: Length */ /* AI control (W): [0] DMA enable - if LSB == 1, DMA is enabled */ -#define AI_CONTROL_REG (AI_BASE_REG+0x08) /* R2: DMA Control */ +#define AI_CONTROL_REG (AI_BASE_REG + 0x08) /* R2: DMA Control */ + +/* Value for control register */ +#define AI_CONTROL_DMA_ON 1 /* LSB = 1: DMA enable*/ +#define AI_CONTROL_DMA_OFF 0 /* LSB = 1: DMA enable*/ /* * AI status (R): [31]/[0] ai_full (addr & len buffer full), [30] ai_busy - * Note that a 1->0 transition in ai_full will set interrupt + * Note that a 1->0 transition in ai_full will set interrupt * (W): clear audio interrupt */ -#define AI_STATUS_REG (AI_BASE_REG+0x0C) /* R3: Status */ +#define AI_STATUS_REG (AI_BASE_REG + 0x0C) /* R3: Status */ + +/* Value for status register */ +#define AI_STATUS_FIFO_FULL (1 << 31) +#define AI_STATUS_DMA_BUSY (1 << 30) /* * AI DAC sample period register (W): [13:0] dac rate * - vid_clock/(dperiod + 1) is the DAC sample rate * - (dperiod + 1) >= 66 * (aclockhp + 1) must be true */ -#define AI_DACRATE_REG (AI_BASE_REG+0x10) /* R4: DAC rate 14-lsb*/ +#define AI_DACRATE_REG (AI_BASE_REG + 0x10) /* R4: DAC rate 14-lsb*/ + +/* DAC rate = video clock / audio frequency + * - DAC rate >= (66 * Bit rate) must be true + */ +#define AI_MAX_DAC_RATE 16384 /* 14-bit+1 */ +#define AI_MIN_DAC_RATE 132 /* * AI bit rate (W): [3:0] bit rate (abus clock half period register - aclockhp) * - vid_clock/(2 * (aclockhp + 1)) is the DAC clock rate * - The abus clock stops if aclockhp is zero */ -#define AI_BITRATE_REG (AI_BASE_REG+0x14) /* R5: Bit rate 4-lsb */ - -/* Value for control register */ -#define AI_CONTROL_DMA_ON 0x01 /* LSB = 1: DMA enable*/ -#define AI_CONTROL_DMA_OFF 0x00 /* LSB = 1: DMA enable*/ - -/* Value for status register */ -#define AI_STATUS_FIFO_FULL 0x80000000 /* Bit 31: full */ -#define AI_STATUS_DMA_BUSY 0x40000000 /* Bit 30: busy */ - -/* DAC rate = video clock / audio frequency - * - DAC rate >= (66 * Bit rate) must be true - */ -#define AI_MAX_DAC_RATE 16384 /* 14-bit+1 */ -#define AI_MIN_DAC_RATE 132 +#define AI_BITRATE_REG (AI_BASE_REG + 0x14) /* R5: Bit rate 4-lsb */ /* Bit rate <= (DAC rate / 66) */ -#define AI_MAX_BIT_RATE 16 /* 4-bit+1 */ -#define AI_MIN_BIT_RATE 2 +#define AI_MAX_BIT_RATE 16 /* 4-bit+1 */ +#define AI_MIN_BIT_RATE 2 /* * Maximum and minimum values for audio frequency based on video clocks * max frequency = (video clock / min dac rate) * min frequency = (video clock / max dac rate) */ -#define AI_NTSC_MAX_FREQ 368000 /* 368 KHz */ -#define AI_NTSC_MIN_FREQ 3000 /* 3 KHz ~ 2971 Hz */ +#define AI_NTSC_MAX_FREQ 368000 /* 368 KHz */ +#define AI_NTSC_MIN_FREQ 3000 /* 3 KHz ~ 2971 Hz */ -#define AI_PAL_MAX_FREQ 376000 /* 376 KHz */ -#define AI_PAL_MIN_FREQ 3050 /* 3 KHz ~ 3031 Hz */ +#define AI_PAL_MAX_FREQ 376000 /* 376 KHz */ +#define AI_PAL_MIN_FREQ 3050 /* 3 KHz ~ 3031 Hz */ -#define AI_MPAL_MAX_FREQ 368000 /* 368 KHz */ -#define AI_MPAL_MIN_FREQ 3000 /* 3 KHz ~ 2968 Hz */ +#define AI_MPAL_MAX_FREQ 368000 /* 368 KHz */ +#define AI_MPAL_MIN_FREQ 3000 /* 3 KHz ~ 2968 Hz */ - -/************************************************************************* +/** * Peripheral Interface (PI) Registers */ -#define PI_BASE_REG 0x04600000 +#define PI_BASE_REG 0x04600000 /* PI DRAM address (R/W): [23:0] starting RDRAM address */ -#define PI_DRAM_ADDR_REG (PI_BASE_REG+0x00) /* DRAM address */ +#define PI_DRAM_ADDR_REG (PI_BASE_REG + 0x00) /* DRAM address */ /* PI pbus (cartridge) address (R/W): [31:0] starting AD16 address */ -#define PI_CART_ADDR_REG (PI_BASE_REG+0x04) +#define PI_CART_ADDR_REG (PI_BASE_REG + 0x04) /* PI read length (R/W): [23:0] read data length */ -#define PI_RD_LEN_REG (PI_BASE_REG+0x08) +#define PI_RD_LEN_REG (PI_BASE_REG + 0x08) /* PI write length (R/W): [23:0] write data length */ -#define PI_WR_LEN_REG (PI_BASE_REG+0x0C) +#define PI_WR_LEN_REG (PI_BASE_REG + 0x0C) /* * PI status (R): [0] DMA busy, [1] IO busy, [2], error * (W): [0] reset controller (and abort current op), [1] clear intr */ -#define PI_STATUS_REG (PI_BASE_REG+0x10) +#define PI_STATUS_REG (PI_BASE_REG + 0x10) /* PI dom1 latency (R/W): [7:0] domain 1 device latency */ -#define PI_BSD_DOM1_LAT_REG (PI_BASE_REG+0x14) +#define PI_BSD_DOM1_LAT_REG (PI_BASE_REG + 0x14) /* PI dom1 pulse width (R/W): [7:0] domain 1 device R/W strobe pulse width */ -#define PI_BSD_DOM1_PWD_REG (PI_BASE_REG+0x18) +#define PI_BSD_DOM1_PWD_REG (PI_BASE_REG + 0x18) /* PI dom1 page size (R/W): [3:0] domain 1 device page size */ -#define PI_BSD_DOM1_PGS_REG (PI_BASE_REG+0x1C) /* page size */ +#define PI_BSD_DOM1_PGS_REG (PI_BASE_REG + 0x1C) /* page size */ /* PI dom1 release (R/W): [1:0] domain 1 device R/W release duration */ -#define PI_BSD_DOM1_RLS_REG (PI_BASE_REG+0x20) +#define PI_BSD_DOM1_RLS_REG (PI_BASE_REG + 0x20) /* PI dom2 latency (R/W): [7:0] domain 2 device latency */ -#define PI_BSD_DOM2_LAT_REG (PI_BASE_REG+0x24) /* Domain 2 latency */ +#define PI_BSD_DOM2_LAT_REG (PI_BASE_REG + 0x24) /* Domain 2 latency */ /* PI dom2 pulse width (R/W): [7:0] domain 2 device R/W strobe pulse width */ -#define PI_BSD_DOM2_PWD_REG (PI_BASE_REG+0x28) /* pulse width */ +#define PI_BSD_DOM2_PWD_REG (PI_BASE_REG + 0x28) /* pulse width */ /* PI dom2 page size (R/W): [3:0] domain 2 device page size */ -#define PI_BSD_DOM2_PGS_REG (PI_BASE_REG+0x2C) /* page size */ +#define PI_BSD_DOM2_PGS_REG (PI_BASE_REG + 0x2C) /* page size */ /* PI dom2 release (R/W): [1:0] domain 2 device R/W release duration */ -#define PI_BSD_DOM2_RLS_REG (PI_BASE_REG+0x30) /* release duration */ +#define PI_BSD_DOM2_RLS_REG (PI_BASE_REG + 0x30) /* release duration */ -#define PI_DOMAIN1_REG PI_BSD_DOM1_LAT_REG -#define PI_DOMAIN2_REG PI_BSD_DOM2_LAT_REG +#define PI_DOMAIN1_REG PI_BSD_DOM1_LAT_REG +#define PI_DOMAIN2_REG PI_BSD_DOM2_LAT_REG -#define PI_DOM_LAT_OFS 0x00 -#define PI_DOM_PWD_OFS 0x04 -#define PI_DOM_PGS_OFS 0x08 -#define PI_DOM_RLS_OFS 0x0C +#define PI_DOM_LAT_OFS 0x00 +#define PI_DOM_PWD_OFS 0x04 +#define PI_DOM_PGS_OFS 0x08 +#define PI_DOM_RLS_OFS 0x0C /* * PI status register has 3 bits active when read from (PI_STATUS_REG - read) - * Bit 0: DMA busy - set when DMA is in progress - * Bit 1: IO busy - set when IO is in progress - * Bit 2: Error - set when CPU issues IO request while DMA is busy + * 1: DMA busy - set when DMA is in progress + * 2: IO busy - set when IO is in progress + * 3: Error - set when CPU issues IO request while DMA is busy */ -#define PI_STATUS_ERROR 0x03 -#define PI_STATUS_IO_BUSY 0x02 #define PI_STATUS_DMA_BUSY 0x01 +#define PI_STATUS_IO_BUSY 0x02 +#define PI_STATUS_ERROR 0x03 /* PI status register has 2 bits active when written to: - * Bit 0: When set, reset PIC - * Bit 1: When set, clear interrupt flag + * Bit 0: When set, reset PIC + * Bit 1: When set, clear interrupt flag * The values of the two bits can be ORed together to both reset PIC and * clear interrupt at the same time. * * Note: - * - The PIC does generate an interrupt at the end of each DMA. CPU - * needs to clear the interrupt flag explicitly (from an interrupt - * handler) by writing into the STATUS register with bit 1 set. + * - The PIC does generate an interrupt at the end of each DMA. CPU + * needs to clear the interrupt flag explicitly (from an interrupt + * handler) by writing into the STATUS register with bit 1 set. * - * - When a DMA completes, the interrupt flag is set. CPU can issue - * another request even while the interrupt flag is set (as long as - * PIC is idle). However, it is the CPU's responsibility for - * maintaining accurate correspondence between DMA completions and - * interrupts. + * - When a DMA completes, the interrupt flag is set. CPU can issue + * another request even while the interrupt flag is set (as long as + * PIC is idle). However, it is the CPU's responsibility for + * maintaining accurate correspondence between DMA completions and + * interrupts. * - * - When PIC is reset, if PIC happens to be busy, an interrupt will - * be generated as PIC returns to idle. Otherwise, no interrupt will - * be generated and PIC remains idle. + * - When PIC is reset, if PIC happens to be busy, an interrupt will + * be generated as PIC returns to idle. Otherwise, no interrupt will + * be generated and PIC remains idle. */ + /* - * Values to clear interrupt/reset PIC (PI_STATUS_REG - write) + * PI_STATUS_REG: write bits */ -#define PI_STATUS_RESET 0x01 -#define PI_SET_RESET PI_STATUS_RESET +#define PI_STATUS_RESET (1 << 0) +#define PI_SET_RESET PI_STATUS_RESET -#define PI_STATUS_CLR_INTR 0x02 -#define PI_CLR_INTR PI_STATUS_CLR_INTR +#define PI_STATUS_CLR_INTR (1 << 1) +#define PI_CLR_INTR PI_STATUS_CLR_INTR -#define PI_DMA_BUFFER_SIZE 128 +#define PI_DMA_BUFFER_SIZE 128 -#define PI_DOM1_ADDR1 0x06000000 /* to 0x07FFFFFF */ -#define PI_DOM1_ADDR2 0x10000000 /* to 0x1FBFFFFF */ -#define PI_DOM1_ADDR3 0x1FD00000 /* to 0x7FFFFFFF */ -#define PI_DOM2_ADDR1 0x05000000 /* to 0x05FFFFFF */ -#define PI_DOM2_ADDR2 0x08000000 /* to 0x0FFFFFFF */ +#define PI_DOM1_ADDR1 0x06000000 /* to 0x07FFFFFF */ +#define PI_DOM1_ADDR2 0x10000000 /* to 0x1FBFFFFF */ +#define PI_DOM1_ADDR3 0x1FD00000 /* to 0x7FFFFFFF */ +#define PI_DOM2_ADDR1 0x05000000 /* to 0x05FFFFFF */ +#define PI_DOM2_ADDR2 0x08000000 /* to 0x0FFFFFFF */ - -/************************************************************************* +/** * RDRAM Interface (RI) Registers */ -#define RI_BASE_REG 0x04700000 +#define RI_BASE_REG 0x04700000 /* RI mode (R/W): [1:0] operating mode, [2] stop T active, [3] stop R active */ -#define RI_MODE_REG (RI_BASE_REG+0x00) +#define RI_MODE_REG (RI_BASE_REG + 0x00) /* RI config (R/W): [5:0] current control input, [6] current control enable */ -#define RI_CONFIG_REG (RI_BASE_REG+0x04) +#define RI_CONFIG_REG (RI_BASE_REG + 0x04) /* RI current load (W): [] any write updates current control register */ -#define RI_CURRENT_LOAD_REG (RI_BASE_REG+0x08) +#define RI_CURRENT_LOAD_REG (RI_BASE_REG + 0x08) /* RI select (R/W): [2:0] receive select, [2:0] transmit select */ -#define RI_SELECT_REG (RI_BASE_REG+0x0C) +#define RI_SELECT_REG (RI_BASE_REG + 0x0C) /* RI refresh (R/W): [7:0] clean refresh delay, [15:8] dirty refresh delay, - * [16] refresh bank, [17] refresh enable - * [18] refresh optimize + * [16] refresh bank, [17] refresh enable + * [18] refresh optimize */ -#define RI_REFRESH_REG (RI_BASE_REG+0x10) -#define RI_COUNT_REG RI_REFRESH_REG +#define RI_REFRESH_REG (RI_BASE_REG + 0x10) +#define RI_COUNT_REG RI_REFRESH_REG /* RI latency (R/W): [3:0] DMA latency/overlap */ -#define RI_LATENCY_REG (RI_BASE_REG+0x14) +#define RI_LATENCY_REG (RI_BASE_REG + 0x14) /* RI error (R): [0] nack error, [1] ack error */ -#define RI_RERROR_REG (RI_BASE_REG+0x18) +#define RI_RERROR_REG (RI_BASE_REG + 0x18) /* RI error (W): [] any write clears all error bits */ -#define RI_WERROR_REG (RI_BASE_REG+0x1C) +#define RI_WERROR_REG (RI_BASE_REG + 0x1C) - -/************************************************************************* - * Serial Interface (SI) Registers +/** + * Serial Interface (SI) Registers */ -#define SI_BASE_REG 0x04800000 +#define SI_BASE_REG 0x04800000 /* SI DRAM address (R/W): [23:0] starting RDRAM address */ -#define SI_DRAM_ADDR_REG (SI_BASE_REG+0x00) /* R0: DRAM address */ +#define SI_DRAM_ADDR_REG (SI_BASE_REG + 0x00) -/* SI address read 64B (W): [] any write causes a 64B DMA write */ -#define SI_PIF_ADDR_RD64B_REG (SI_BASE_REG+0x04) /* R1: 64B PIF->DRAM */ +/* SI address read 64B (W): [] write begins a 64B DMA write PIF RAM -> RDRAM */ +#define SI_PIF_ADDR_RD64B_REG (SI_BASE_REG + 0x04) -/* Address SI_BASE_REG + (0x08, 0x0c, 0x14) are reserved */ +/* Address SI_BASE_REG + (0x08, 0x0C, 0x14) are reserved */ -/* SI address write 64B (W): [] any write causes a 64B DMA read */ -#define SI_PIF_ADDR_WR64B_REG (SI_BASE_REG+0x10) /* R4: 64B DRAM->PIF */ +/* SI address write 64B (W): [] write begins a 64B DMA read RDRAM -> PIF RAM */ +#define SI_PIF_ADDR_WR64B_REG (SI_BASE_REG + 0x10) -/* - * SI status (W): [] any write clears interrupt - * (R): [0] DMA busy, [1] IO read busy, [2] reserved - * [3] DMA error, [12] interrupt +/* SI status (R/W): [] any write clears interrupt */ +#define SI_STATUS_REG (SI_BASE_REG + 0x18) + +/* + * SI_STATUS_REG: read bits */ -#define SI_STATUS_REG (SI_BASE_REG+0x18) /* R6: Status */ +#define SI_STATUS_DMA_BUSY (1 << 0) /* DMA in progress */ +#define SI_STATUS_RD_BUSY (1 << 1) /* IO access in progress */ +#define SI_STATUS_DMA_ERROR (1 << 3) /* Overlapping DMA requests */ +#define SI_STATUS_INTERRUPT (1 << 12) /* Interrupt is set */ -/* SI status register has the following bits active: - * 0: DMA busy - set when DMA is in progress - * 1: IO busy - set when IO access is in progress - * 3: DMA error - set when there are overlapping DMA requests - * 12: Interrupt - Interrupt set - */ -#define SI_STATUS_DMA_BUSY 0x0001 -#define SI_STATUS_RD_BUSY 0x0002 -#define SI_STATUS_DMA_ERROR 0x0008 -#define SI_STATUS_INTERRUPT 0x1000 - -/************************************************************************* +/** * Development Board GIO Control Registers */ @@ -860,22 +830,20 @@ The Indy development board use cartridge domain 1: /* Host to Game Interrupt */ #define GIO_CART_INTR_REG (GIO_BASE_REG+0x800) - -/************************************************************************* +/** * Common macros */ #if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) -#define IO_READ(addr) (*(vu32 *)PHYS_TO_K1(addr)) -#define IO_WRITE(addr,data) (*(vu32 *)PHYS_TO_K1(addr)=(u32)(data)) -#define RCP_STAT_PRINT \ - rmonPrintf("current=%x start=%x end=%x dpstat=%x spstat=%x\n", \ - IO_READ(DPC_CURRENT_REG), \ - IO_READ(DPC_START_REG), \ - IO_READ(DPC_END_REG), \ - IO_READ(DPC_STATUS_REG), \ +#define IO_READ(addr) (*(vu32*)PHYS_TO_K1(addr)) +#define IO_WRITE(addr,data) (*(vu32*)PHYS_TO_K1(addr)=(u32)(data)) +#define RCP_STAT_PRINT \ + rmonPrintf("current=%x start=%x end=%x dpstat=%x spstat=%x\n", \ + IO_READ(DPC_CURRENT_REG), \ + IO_READ(DPC_START_REG), \ + IO_READ(DPC_END_REG), \ + IO_READ(DPC_STATUS_REG), \ IO_READ(SP_STATUS_REG)) #endif #endif /* _RCP_H_ */ - diff --git a/include/PR/rdb.h b/include/PR/rdb.h new file mode 100644 index 00000000..e0897493 --- /dev/null +++ b/include/PR/rdb.h @@ -0,0 +1,93 @@ + +/************************************************************************** + * + * $Revision: 1.6 $ + * $Date: 1997/02/11 08:29:31 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/rdb.h,v $ + * + **************************************************************************/ + +#ifndef _RDB_H +#define _RDB_H + +/* U64 side address */ +#define RDB_BASE_REG 0xc0000000 +#define RDB_WRITE_INTR_REG (RDB_BASE_REG + 0x8) +#define RDB_READ_INTR_REG (RDB_BASE_REG + 0xc) +#define RDB_BASE_VIRTUAL_ADDR 0x80000000 + +/* packet type Have six bits, so can have up to 63 types */ +#define RDB_TYPE_INVALID 0 +#define RDB_TYPE_GtoH_PRINT 1 +#define RDB_TYPE_GtoH_FAULT 2 +#define RDB_TYPE_GtoH_LOG_CT 3 +#define RDB_TYPE_GtoH_LOG 4 +#define RDB_TYPE_GtoH_READY_FOR_DATA 5 +#define RDB_TYPE_GtoH_DATA_CT 6 +#define RDB_TYPE_GtoH_DATA 7 +#define RDB_TYPE_GtoH_DEBUG 8 +#define RDB_TYPE_GtoH_RAMROM 9 +#define RDB_TYPE_GtoH_DEBUG_DONE 10 +#define RDB_TYPE_GtoH_DEBUG_READY 11 +#define RDB_TYPE_GtoH_KDEBUG 12 +#define RDB_TYPE_GtoH_PROF_DATA 22 + + +#define RDB_TYPE_HtoG_LOG_DONE 13 +#define RDB_TYPE_HtoG_DEBUG 14 +#define RDB_TYPE_HtoG_DEBUG_CT 15 +#define RDB_TYPE_HtoG_DATA 16 +#define RDB_TYPE_HtoG_DATA_DONE 17 +#define RDB_TYPE_HtoG_REQ_RAMROM 18 +#define RDB_TYPE_HtoG_FREE_RAMROM 19 +#define RDB_TYPE_HtoG_KDEBUG 20 +#define RDB_TYPE_HtoG_PROF_SIGNAL 21 + + +#define RDB_PROF_ACK_SIG 1 +#define RDB_PROF_FLUSH_SIG 2 +#define PROF_BLOCK_SIZE 2048 + +#define RDB_LOG_MAX_BLOCK_SIZE 0x8000 +#define RDB_DATA_MAX_BLOCK_SIZE 0x8000 + + +/* GIO side address */ +#define GIO_RDB_BASE_REG 0xbf480000 +#define GIO_RDB_WRITE_INTR_REG (GIO_RDB_BASE_REG + 0x8) +#define GIO_RDB_READ_INTR_REG (GIO_RDB_BASE_REG + 0xc) + +/* minor device number */ +#define GIO_RDB_PRINT_MINOR 1 +#define GIO_RDB_DEBUG_MINOR 2 + +/* interrupt bit */ +#define GIO_RDB_WRITE_INTR_BIT 0x80000000 +#define GIO_RDB_READ_INTR_BIT 0x40000000 + +/* debug command */ +#define DEBUG_COMMAND_NULL 0 +#define DEBUG_COMMAND_MEMORY 1 +#define DEBUG_COMMAND_REGISTER 2 +#define DEBUG_COMMAND_INVALID 255 + +/* debug state */ +#define DEBUG_STATE_NULL 0 +#define DEBUG_STATE_RECEIVE 1 +#define DEBUG_STATE_INVALID 255 + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* Structure for debug port */ +typedef struct { + unsigned type : 6; /* 0: invalid, 1: print, 2: debug */ + unsigned length : 2; /* 1, 2, or 3 */ + char buf[3]; /* character buffer */ +} rdbPacket; + +extern unsigned int __osRdbWriteOK; +extern unsigned int __osRdbSendMessage; + +#endif /* _LANGUAGE_C */ + +#endif /* !_RDB_H */ diff --git a/include/PR/region.h b/include/PR/region.h new file mode 100644 index 00000000..0ac8a253 --- /dev/null +++ b/include/PR/region.h @@ -0,0 +1,123 @@ + +/************************************************************************** + * * + * 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. * + * * + **************************************************************************/ + +/************************************************************************** + * + * Module: region.h + * + * $Revision: 1.8 $ + * $Date: 1997/11/26 00:30:56 $ + * $Author: mitu $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/region.h,v $ + * + * Description: + * This file contains macros and structure definitions for the region + * library. + * + **************************************************************************/ + + +#ifndef _REGION_H_ +#define _REGION_H_ + + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + + +/*************************************** + * + * Global defines + * + */ + /* Alignment sizes */ +#define ALIGNSZ (sizeof(long long)) /* 8 bytes */ +#define ALIGNOFFST (ALIGNSZ-1) + + /* size for storing index to free buffer */ +#define BUF_CTRL_SIZE ALIGNSZ + + /* Max bufcount = 32K */ +#define MAX_BUFCOUNT 0x8000 + /* code for last free buffer */ +#define BUF_FREE_WO_NEXT 0x8000 + +/* + * Global defines for alignment size (default is 8-byte alignment) + */ +#define OS_RG_ALIGN_2B 2 /* 2 bytes = 16-bit alignment */ +#define OS_RG_ALIGN_4B 4 /* 4 bytes = 32-bit alignment */ +#define OS_RG_ALIGN_8B 8 /* 8 bytes = 64-bit alignment */ +#define OS_RG_ALIGN_16B 16 /* 16 bytes = 128-bit alignment */ + +#define OS_RG_ALIGN_DEFAULT OS_RG_ALIGN_8B + + +/*************************************** + * + * Macro definitions + * + */ + +/* Perform alignment on input 's' */ +#define ALIGN(s, align) (((u32)(s) + ((align)-1)) & ~((align)-1)) + + +/*************************************** + * + * Typedefs & structure definitions + * + */ +/* + * Structure for region header/control area + */ +typedef struct _Region_s { + u8 *r_startBufferAddress; /* start address to data buffer */ + u8 *r_endAddress; /* end address of region */ + s32 r_bufferSize; /* size of buffers for this region */ + s32 r_bufferCount; /* up to 32K entries; MSB is used for + setting end-of-list/used */ + u16 r_freeList; /* point to array index of first + available memory buffer */ + u16 r_alignSize; /* alignment size (# of bytes) */ +} OSRegion; + +/* + * Macro to simplify accessing region header structure + */ +#define RP(x) rp->r_##x + + +/*************************************** + * + * Function prototypes + * + */ +extern void *osCreateRegion(void *, u32, u32, u32); +extern void *osMalloc(void *); +extern void osFree(void *, void *); +extern s32 osGetRegionBufCount(void *); +extern s32 osGetRegionBufSize(void *); + + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + + +#endif /* _REGION_H_ */ + + diff --git a/include/PR/rmon.h b/include/PR/rmon.h new file mode 100644 index 00000000..199e5699 --- /dev/null +++ b/include/PR/rmon.h @@ -0,0 +1,39 @@ +/************************************************************************** + * * + * 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. * + * * + **************************************************************************/ + +/************************************************************************** + * + * $Revision: 1.6 $ + * $Date: 1997/02/11 08:30:08 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/rmon.h,v $ + * + **************************************************************************/ + +#ifndef _RMON_H_ +#define _RMON_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#define RMON_DBG_BUF_SIZE 2048 +#define RMON_STACKSIZE 0x1000 + +extern void rmonMain( void * ); +extern void rmonPrintf( const char *, ... ); + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_H */ diff --git a/include/PR/sched.h b/include/PR/sched.h new file mode 100644 index 00000000..319f2054 --- /dev/null +++ b/include/PR/sched.h @@ -0,0 +1,135 @@ +/*==================================================================== + * sched.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. + *====================================================================*/ + +/************************************************************************** + * + * $Revision: 1.7 $ + * $Date: 1997/02/11 08:32:02 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/sched.h,v $ + * + **************************************************************************/ + +#ifndef __sched__ +#define __sched__ + +#include +#include "macros.h" +#include "os_internal_rsp.h" + +#define OS_SC_STACKSIZE 0x2000 + +#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_MAX_MESGS 8 + +#define OS_SC_ID_NONE 0 +#define OS_SC_ID_AUDIO 1 +#define OS_SC_ID_VIDEO 2 +#define OS_SC_ID_PRENMI 3 + +#define OSMESG_SWAP_BUFFER 0 +#define MESG_SKIP_BUFFER_SWAP 8 + +typedef struct { + short type; + char misc[30]; +} OSScMsg; + +typedef struct OSScTask_s { + struct OSScTask_s *next; /* note: this must be first */ + u32 state; + u32 flags; + void *framebuffer; /* used by graphics tasks */ + + 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 */ + s32 unk58; + s32 unk5C; + s32 unk60; + s32 unk64; + s32 unk68; /* Added by Rare? */ + s32 unk6C; /* Task ID, used in debug functions in JFG */ +} OSScTask; /* non FINALROM code */ + +/* + * OSScTask flags: + */ +#define OS_SC_NEEDS_RDP 0x0001 /* uses the RDP */ +#define OS_SC_NEEDS_RSP 0x0002 /* uses the RSP */ +#define OS_SC_DRAM_DLIST 0x0004 /* SP & DP communicate through DRAM */ +#define OS_SC_PARALLEL_TASK 0x0010 /* must be first gfx task on list */ +#define OS_SC_LAST_TASK 0x0020 /* last task in queue for frame */ +#define OS_SC_SWAPBUFFER 0x0040 /* swapbuffers when gfx task done */ + +#define OS_SC_RCP_MASK 0x0003 /* mask for needs bits */ +#define OS_SC_TYPE_MASK 0x0007 /* complete type mask */ +/* + * OSScClient: + * + * Data structure used by threads that wish to communicate to the + * scheduling thread + * + */ +typedef struct SCClient_s { + u8 id; /* Client ID, added by Rareware to single out individual scheduler clients */ + struct SCClient_s *next; /* next client in the list */ + OSMesgQueue *msgQ; /* where to send the frame msg */ +} OSScClient; + +typedef struct { + OSScMsg retraceMsg; + OSScMsg prenmiMsg; + OSMesgQueue interruptQ; + OSMesg intBuf[OS_SC_MAX_MESGS]; + OSMesgQueue cmdQ; + OSMesg cmdMsgBuf[OS_SC_MAX_MESGS]; + OSThread thread; + OSScClient *clientList; + OSScTask *audioListHead; + OSScTask *gfxListHead; + OSScTask *audioListTail; + OSScTask *gfxListTail; + OSScTask *curRSPTask; + OSScTask *curRDPTask; + OSScTask *unkTask; + u32 frameCount; + s32 doAudio; +} OSSched; + +void osCreateScheduler(OSSched *s, void *stack, OSPri priority, + u8 mode, u8 numFields); +void osScAddClient(OSSched *s, OSScClient *c, OSMesgQueue *msgQ, u8 id); +OSMesgQueue *osScGetInterruptQ(OSSched *s); +void func_80079760(OSSched *s); +void osScRemoveClient(OSSched *s, OSScClient *c); +OSMesgQueue *osScGetCmdQ(OSSched *s); + +#endif + diff --git a/include/PR/sp.h b/include/PR/sp.h new file mode 100644 index 00000000..8167ca23 --- /dev/null +++ b/include/PR/sp.h @@ -0,0 +1,196 @@ +/************************************************************************** + * * + * 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. * + * * + **************************************************************************/ + +/************************************************************************** + * + * Sprite library include file + * + * $Revision: 1.16 $ + * $Date: 1998/04/17 05:03:46 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/sp.h,v $ + * + **************************************************************************/ + +#ifndef _SP_H_ +#define _SP_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include + +struct bitmap { + s16 width; /* Size across to draw in texels */ + /* Done if width = 0 */ + + s16 width_img; /* Size across of bitmap in texels */ + /* Done if width = 0 */ + + s16 s; /* Horizontal offset into bitmap */ + /* if (s > width), then load only! */ + + s16 t; /* Vertical offset into base */ + + void *buf; /* Pointer to bitmap data */ + /* Don't re-load if new buf */ + /* is the same as the old one */ + /* Skip if NULL */ + + s16 actualHeight; /* True Height of this bitmap piece */ + + s16 LUToffset; /* LUT base index */ +}; + +typedef struct bitmap Bitmap; + +struct sprite { + s16 x,y; /* Target position */ + + s16 width, height; /* Target size */ + + f32 scalex, scaley; /* Texel to Pixel scale factor */ + + s16 expx, expy; /* Explosion spacing */ + + u16 attr; /* Attribute Flags */ + s16 zdepth; /* Z Depth */ + + u8 red; /* Red component */ + u8 green; /* Green component */ + u8 blue; /* Blue component */ + u8 alpha; /* Alpha component */ + + s16 startTLUT; /* Lookup Table Entry Starting index */ + s16 nTLUT; /* Total number of Lookup Table Entries */ + + int *LUT; /* Pointer to Lookup Table */ + + s16 istart; /* Starting bitmap index */ + s16 istep; /* Bitmaps index step (see SP_INCY) */ + /* if 0, then variable width bitmaps */ + + s16 nbitmaps; /* Total number of bitmaps */ + s16 ndisplist; /* Total number of display-list words */ + + s16 bmheight; /* Bitmap Texel height (Used) */ + s16 bmHreal; /* Bitmap Texel height (Real) */ + u8 bmfmt; /* Bitmap Format */ + u8 bmsiz; /* Bitmap Texel Size */ + + Bitmap *bitmap; /* Pointer to first bitmap */ + + Gfx *rsp_dl; /* Pointer to RSP display list */ + + Gfx *rsp_dl_next; /* Pointer to next RSP display entry */ + + s16 frac_s, /* Fractional Texture offsets */ + frac_t; /* These have 5 fraction bits */ +}; + +typedef struct sprite Sprite; + +/* + * DANGER! + * This is bad programming. Where the *heck* do these numbers come + * from? + * + * They are obviously 'maximums' from the sprite library, but since + * the sprite library is built on top of gbi.h, which includes macros + * that decode into multiple macros, etc., it is nearly impossible to + * know what these maximums should be. + * + * Worse, there are some gbi macros (texture alignment mostly) that + * decode into *many* macros, so if we choose that as a maximum, we + * are wasting TONS of space... + * + * These numbers work for "reasonable" sprite library usage, and + * there is an assert() in the library to detect when they aren't + * enough. (use the debug version) + */ +#define DL_BM_OVERHEAD (12) +#define DL_SPRITE_OVERHEAD (24) + +#define NUM_DL(nb) ((nb)*DL_BM_OVERHEAD +DL_SPRITE_OVERHEAD) + +/* + * Misc constants + */ + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +/* + * For sprite->attr + */ + +#define SP_TRANSPARENT 0x00000001 +#define SP_CUTOUT 0x00000002 +#define SP_HIDDEN 0x00000004 +#define SP_Z 0x00000008 +#define SP_SCALE 0x00000010 +#define SP_FASTCOPY 0x00000020 +#define SP_OVERLAP 0x00000040 +#define SP_TEXSHIFT 0x00000080 +#define SP_FRACPOS 0x00000100 +#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 + */ + +void spSetAttribute (Sprite *sp, s32 attr); +void spClearAttribute (Sprite *sp, s32 attr); +void spMove (Sprite *sp, s32 x, s32 y); +void spScale (Sprite *sp, f32 sx, f32 sy); +void spSetZ (Sprite *sp, s32 z ); +void spColor (Sprite *sp, u8 red, u8 green, u8 blue, u8 alpha); +Gfx *spDraw (Sprite *sp); +void spInit( Gfx **glistp ); +void spScissor( s32 xmin, s32 xmax, s32 ymin, s32 ymax ); +void spFinish( Gfx **glistp ); + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* _SP_H_ */ diff --git a/include/PR/sptask.h b/include/PR/sptask.h index 13c85f93..e33db751 100644 --- a/include/PR/sptask.h +++ b/include/PR/sptask.h @@ -1,21 +1,122 @@ -#ifndef _ULTRA64_SPTASK_H_ -#define _ULTRA64_SPTASK_H_ +/************************************************************************** + * * + * 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. * + * * + **************************************************************************/ -/* Task Types */ -#define M_GFXTASK 1 -#define M_AUDTASK 2 -#define M_VIDTASK 3 -#define M_HVQTASK 6 -#define M_HVQMTASK 7 +/************************************************************************** + * + * $Revision: 1.9 $ + * $Date: 1998/03/05 06:40:29 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/sptask.h,v $ + * + **************************************************************************/ + +#ifndef _SPTASK_H_ +#define _SPTASK_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Task List Structure. + * + * Things an app might pass to the SP via the task list. + * Not every task ucode would need/use every field, but + * + * - type (audio, gfx, video, ...) + * - flags + * - wait for DP to drain before running new task + * - SEE BIT DEFINITIONS UNDER "Task Flags field" + * - pointer to boot ucode + * - size of boot ucode + * - pointer to ucode + * - size of ucode + * - pointer to initial DMEM data + * - size of initial DMEM data + * - pointer to DRAM stack + * - size of DRAM stack (max) + * - pointer to output buffer + * - pointer to store output buffer length + * - generic data pointer (for display list, etc.) + * - generic data length (for display list, etc.) + * - pointer to buffer where to store saved DMEM (in yield case) + * - size of buffer to store saved DMEM. + * + * IMPORTANT!!! Watch alignment issues. + * + * IMPORTANT!!! Watch data cache issues. The RCP may write data into the + * dram_stack, output_buff, output_buff_size, and the yield_data_ptr areas. + * These buffers should be cache aligned and use the entire line (16 bytes) to + * avoid corruption by writebacks by the CPU (cache tearing). + * + * IMPORTANT!!! all addresses are virtual addresses. Library does + * any necessary translation. + * + */ +typedef struct { + u32 type; + u32 flags; + + u64 *ucode_boot; + u32 ucode_boot_size; + + u64 *ucode; + u32 ucode_size; + + u64 *ucode_data; + u32 ucode_data_size; + + u64 *dram_stack; + u32 dram_stack_size; + + u64 *output_buff; + u64 *output_buff_size; + + u64 *data_ptr; + u32 data_size; + + u64 *yield_data_ptr; + u32 yield_data_size; + +} OSTask_t; + +typedef union { + OSTask_t t; + long long int force_structure_alignment; +} OSTask; + +typedef u32 OSYieldResult; + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_ASSEMBLY + +/* + * For the RSP ucode: + * offsets into the task structure + */ + +#include -#if (defined(F3DEX_GBI) || defined(F3DLP_GBI) || defined(F3DEX_GBI_2)) && !defined(F3DDKR_GBI) -#define OS_YIELD_DATA_SIZE 0xC00 -#elif defined(F3DDKR_GBI) -#define OS_YIELD_DATA_SIZE 0xA00 -#else -#define OS_YIELD_DATA_SIZE 0x900 #endif -#define OS_YIELD_AUDIO_SIZE 0x400 /* * Task Flags field @@ -29,99 +130,74 @@ #define OS_TASK_USR2 0x0040 #define OS_TASK_USR3 0x0080 -/* Flags */ -#define M_TASK_FLAG0 1 -#define M_TASK_FLAG1 2 - -/* SpStatus */ -#define SPSTATUS_CLEAR_HALT 0x00000001 -#define SPSTATUS_SET_HALT 0x00000002 -#define SPSTATUS_CLEAR_BROKE 0x00000004 -#define SPSTATUS_CLEAR_INTR 0x00000008 -#define SPSTATUS_SET_INTR 0x00000010 -#define SPSTATUS_CLEAR_SSTEP 0x00000020 -#define SPSTATUS_SET_SSTEP 0x00000040 -#define SPSTATUS_CLEAR_INTR_ON_BREAK 0x00000080 -#define SPSTATUS_SET_INTR_ON_BREAK 0x00000100 -#define SPSTATUS_CLEAR_SIGNAL0 0x00000200 -#define SPSTATUS_SET_SIGNAL0 0x00000400 -#define SPSTATUS_CLEAR_SIGNAL1 0x00000800 -#define SPSTATUS_SET_SIGNAL1 0x00001000 -#define SPSTATUS_CLEAR_SIGNAL2 0x00002000 -#define SPSTATUS_SET_SIGNAL2 0x00004000 -#define SPSTATUS_CLEAR_SIGNAL3 0x00008000 -#define SPSTATUS_SET_SIGNAL3 0x00010000 -#define SPSTATUS_CLEAR_SIGNAL4 0x00020000 -#define SPSTATUS_SET_SIGNAL4 0x00040000 -#define SPSTATUS_CLEAR_SIGNAL5 0x00080000 -#define SPSTATUS_SET_SIGNAL5 0x00100000 -#define SPSTATUS_CLEAR_SIGNAL6 0x00200000 -#define SPSTATUS_SET_SIGNAL6 0x00800000 -#define SPSTATUS_CLEAR_SIGNAL7 0x01000000 -#define SPSTATUS_SET_SIGNAL7 0x02000000 - -#define SPSTATUS_HALT 0x0001 -#define SPSTATUS_BROKE 0x0002 -#define SPSTATUS_DMA_BUSY 0x0004 -#define SPSTATUS_DMA_FULL 0x0008 -#define SPSTATUS_IO_FULL 0x0010 -#define SPSTATUS_SINGLE_STEP 0x0020 -#define SPSTATUS_INTERRUPT_ON_BREAK 0x0040 -#define SPSTATUS_SIGNAL0_SET 0x0080 -#define SPSTATUS_SIGNAL1_SET 0x0100 -#define SPSTATUS_SIGNAL2_SET 0x0200 -#define SPSTATUS_SIGNAL3_SET 0x0400 -#define SPSTATUS_SIGNAL4_SET 0x0800 -#define SPSTATUS_SIGNAL5_SET 0x1000 -#define SPSTATUS_SIGNAL6_SET 0x2000 -#define SPSTATUS_SIGNAL7_SET 0x4000 - -/* Types */ -/* Types */ - -typedef struct -{ - /*0x00*/ u32 type; - /*0x04*/ u32 flags; - - /*0x08*/ u64 *ucode_boot; - /*0x0C*/ u32 ucode_boot_size; - - /*0x10*/ u64 *ucode; - /*0x14*/ u32 ucode_size; - - /*0x18*/ u64 *ucode_data; - /*0x1C*/ u32 ucode_data_size; - - /*0x20*/ u64 *dram_stack; - /*0x24*/ u32 dram_stack_size; - - /*0x28*/ u64 *output_buff; - /*0x2C*/ u64 *output_buff_size; - - /*0x30*/ u64 *data_ptr; - /*0x34*/ u32 data_size; - - /*0x38*/ u64 *yield_data_ptr; - /*0x3C*/ u32 yield_data_size; -} OSTask_t; // size = 0x40 - -typedef union { - OSTask_t t; - long long int force_structure_alignment; -} OSTask; - -typedef u32 OSYieldResult; - -/* Functions */ - -#define osSpTaskStart(p) \ - osSpTaskLoad(p); \ - osSpTaskStartGo(p); - -void osSpTaskLoad(OSTask *task); -void osSpTaskStartGo(OSTask *task); -void osSpTaskYield(void); -OSYieldResult osSpTaskYielded(OSTask *task); - +/* + * 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)||defined(F3DEX_GBI_2)) +#define OS_YIELD_DATA_SIZE 0xc00 +#elif defined(F3DDKR_GBI) +#define OS_YIELD_DATA_SIZE 0xA00 +#else +#define OS_YIELD_DATA_SIZE 0x900 #endif +#define OS_YIELD_AUDIO_SIZE 0x400 + +/************************************************************************** + * + * Global definitions + * + */ + + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +/* + * this macro simulates atomic action. + */ +#define osSpTaskStart(tp) \ + { \ + osSpTaskLoad((tp)); \ + osSpTaskStartGo((tp)); \ + } + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* + * break this up into two steps for debugging. + */ +extern void osSpTaskLoad(OSTask *tp); +extern void osSpTaskStartGo(OSTask *tp); + +extern void osSpTaskYield(void); +extern OSYieldResult osSpTaskYielded(OSTask *tp); + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_SPTASK_H */ diff --git a/include/PR/ucode.h b/include/PR/ucode.h index 37fd1977..e43f52ae 100644 --- a/include/PR/ucode.h +++ b/include/PR/ucode.h @@ -1,23 +1,192 @@ -#ifndef _ULTRA64_UCODE_H_ -#define _ULTRA64_UCODE_H_ +/************************************************************************** + * * + * 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. * + * * + **************************************************************************/ -#define SP_DRAM_STACK_SIZE8 0x400 -#define SP_UCODE_SIZE 0x1000 -#define SP_UCODE_DATA_SIZE 0x800 +/************************************************************************** + * + * $Revision: 1.15 $ + * $Date: 1998/03/31 07:58:57 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ucode.h,v $ + * + **************************************************************************/ -// standard boot ucode -extern u64 rspF3DBootStart[], rspF3DBootEnd[]; - -// F3D ucode -extern u64 rspF3DStart[], rspF3DEnd[]; - -// F3D ucode data -extern u64 rspF3DDataStart[], rspF3DDataEnd[]; - -// aspMain (audio) ucode -extern u64 rspAspMainStart[], rspAspMainEnd[]; - -// aspMain ucode data -extern u64 rspAspMainDataStart[], rspAspMainDataEnd[]; +#ifndef _UCODE_H_ +#define _UCODE_H_ +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { #endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +/* + * This is the recommended size of the SP DRAM stack area, used + * by the graphics ucode. This stack is used primarily for the + * matrix stack, so it needs to be AT LEAST (10 * 64bytes) in size. + */ +#define SP_DRAM_STACK_SIZE8 (1024) +#define SP_DRAM_STACK_SIZE64 (SP_DRAM_STACK_SIZE8 >> 3) + +/* + * This is the size of the IMEM, which is also the size of the + * graphics microcode. (other ucode might be less) + * This value is used in apps to tell the OS how much ucode to + * load. + */ +#define SP_UCODE_SIZE 4096 + +/* + * This is 1/2 the size of DMEM, which is the maximum amount of + * initialized DMEM data any of the ucode tasks need to start up. + * This value is dependent on all of the task ucodes, and is therefore + * fixed per release. + */ +#define SP_UCODE_DATA_SIZE 2048 + + +/************************************************************************** + * + * Extern variables + * + */ + +/* + * Symbols generated by "rsp2elf", included by "makerom" that indicate + * the location and size of the SP microcode objects. The ucode objects + * are loaded as part of the codesegment (arbitrary, could do other + * ways) + * + */ + +/* standard boot ucode: */ +extern long long int rspbootTextStart[], rspbootTextEnd[]; + +/* standard 3D ucode: */ +extern long long int gspFast3DTextStart[], gspFast3DTextEnd[]; +extern long long int gspFast3DDataStart[], gspFast3DDataEnd[]; + +/* 3D ucode with output to DRAM: */ +extern long long int gspFast3D_dramTextStart[], gspFast3D_dramTextEnd[]; +extern long long int gspFast3D_dramDataStart[], gspFast3D_dramDataEnd[]; + +/* 3D ucode with output through DRAM FIFO to RDP: */ +extern long long int gspFast3D_fifoTextStart[], gspFast3D_fifoTextEnd[]; +extern long long int gspFast3D_fifoDataStart[], gspFast3D_fifoDataEnd[]; + +/* 3D ucode without nearclip: */ +extern long long int gspF3DNoNTextStart[], gspF3DNoNTextEnd[]; +extern long long int gspF3DNoNDataStart[], gspF3DNoNDataEnd[]; + +/* 3D ucode without nearclip with output to DRAM: */ +extern long long int gspF3DNoN_dramTextStart[]; +extern long long int gspF3DNoN_dramTextEnd[]; +extern long long int gspF3DNoN_dramDataStart[]; +extern long long int gspF3DNoN_dramDataEnd[]; + +/* 3D ucode without nearclip with output through DRAM FIFO to RDP: */ +extern long long int gspF3DNoN_fifoTextStart[]; +extern long long int gspF3DNoN_fifoTextEnd[]; +extern long long int gspF3DNoN_fifoDataStart[]; +extern long long int gspF3DNoN_fifoDataEnd[]; + +/* 3D line ucode: */ +extern long long int gspLine3DTextStart[], gspLine3DTextEnd[]; +extern long long int gspLine3DDataStart[], gspLine3DDataEnd[]; + +/* 3D line ucode with output to DRAM: */ +extern long long int gspLine3D_dramTextStart[], gspLine3D_dramTextEnd[]; +extern long long int gspLine3D_dramDataStart[], gspLine3D_dramDataEnd[]; + +/* 3D line ucode with output through DRAM FIFO to RDP: */ +extern long long int gspLine3D_fifoTextStart[], gspLine3D_fifoTextEnd[]; +extern long long int gspLine3D_fifoDataStart[], gspLine3D_fifoDataEnd[]; + +/* 2D sprite ucode: */ +extern long long int gspSprite2DTextStart[], gspSprite2DTextEnd[]; +extern long long int gspSprite2DDataStart[], gspSprite2DDataEnd[]; + +/* 2D sprite ucode with output to DRAM: */ +extern long long int gspSprite2D_dramTextStart[], gspSprite2D_dramTextEnd[]; +extern long long int gspSprite2D_dramDataStart[], gspSprite2D_dramDataEnd[]; + +/* 2D sprite ucode with output through DRAM FIFO to RDP: */ +extern long long int gspSprite2D_fifoTextStart[], gspSprite2D_fifoTextEnd[]; +extern long long int gspSprite2D_fifoDataStart[], gspSprite2D_fifoDataEnd[]; + +/* basic audio ucode: */ +extern long long int aspMainTextStart[], aspMainTextEnd[]; +extern long long int aspMainDataStart[], aspMainDataEnd[]; + +/*========== F3DEX/F3DLX/F3DLP/L3DEX ==========*/ +/* FIFO version only */ +extern long long int gspF3DEX_fifoTextStart[], gspF3DEX_fifoTextEnd[]; +extern long long int gspF3DEX_fifoDataStart[], gspF3DEX_fifoDataEnd[]; +extern long long int gspF3DEX_NoN_fifoTextStart[], gspF3DEX_NoN_fifoTextEnd[]; +extern long long int gspF3DEX_NoN_fifoDataStart[], gspF3DEX_NoN_fifoDataEnd[]; + +extern long long int gspF3DLX_fifoTextStart[], gspF3DLX_fifoTextEnd[]; +extern long long int gspF3DLX_fifoDataStart[], gspF3DLX_fifoDataEnd[]; +extern long long int gspF3DLX_NoN_fifoTextStart[], gspF3DLX_NoN_fifoTextEnd[]; +extern long long int gspF3DLX_NoN_fifoDataStart[], gspF3DLX_NoN_fifoDataEnd[]; +extern long long int gspF3DLX_Rej_fifoTextStart[], gspF3DLX_Rej_fifoTextEnd[]; +extern long long int gspF3DLX_Rej_fifoDataStart[], gspF3DLX_Rej_fifoDataEnd[]; + +extern long long int gspF3DLP_Rej_fifoTextStart[], gspF3DLP_Rej_fifoTextEnd[]; +extern long long int gspF3DLP_Rej_fifoDataStart[], gspF3DLP_Rej_fifoDataEnd[]; +extern long long int gspL3DEX_fifoTextStart[], gspL3DEX_fifoTextEnd[]; +extern long long int gspL3DEX_fifoDataStart[], gspL3DEX_fifoDataEnd[]; + +/*========== F3DEX2/F3DLX2/F3DLP2/L3DEX2 ==========*/ +/* 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 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 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 + * + */ + +#endif /* _LANGUAGE_C */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_UCODE_H */ diff --git a/include/PR/ultraerror.h b/include/PR/ultraerror.h new file mode 100644 index 00000000..ebaf59aa --- /dev/null +++ b/include/PR/ultraerror.h @@ -0,0 +1,165 @@ +/*==================================================================== + * ultraerror.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. + *====================================================================*/ + +/************************************************************************** + * + * $Revision: 1.27 $ + * $Date: 1999/07/14 02:44:00 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ultraerror.h,v $ + * + **************************************************************************/ + +#ifndef __ULTRAERROR_H__ +#define __ULTRAERROR_H__ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include "ultratypes.h" + +#define OS_ERROR_FMT "/usr/lib/PR/error.fmt" +#define OS_ERROR_MAGIC 0x6b617479 + +/* OS error codes */ + +#define ERR_OSCREATETHREAD_SP 1 +#define ERR_OSCREATETHREAD_PRI 2 +#define ERR_OSSTARTTHREAD 3 +#define ERR_OSSETTHREADPRI 4 +#define ERR_OSCREATEMESGQUEUE 5 +#define ERR_OSSENDMESG 6 +#define ERR_OSJAMMESG 7 +#define ERR_OSRECVMESG 8 +#define ERR_OSSETEVENTMESG 9 +#define ERR_OSMAPTLB_INDEX 10 +#define ERR_OSMAPTLB_ASID 11 +#define ERR_OSUNMAPTLB 12 +#define ERR_OSSETTLBASID 13 +#define ERR_OSAISETFREQUENCY 14 +#define ERR_OSAISETNEXTBUFFER_ADDR 15 +#define ERR_OSAISETNEXTBUFFER_SIZE 16 +#define ERR_OSDPSETNEXTBUFFER_ADDR 17 +#define ERR_OSDPSETNEXTBUFFER_SIZE 18 +#define ERR_OSPIRAWREADIO 19 +#define ERR_OSPIRAWWRITEIO 20 +#define ERR_OSPIRAWSTARTDMA_DIR 21 +#define ERR_OSPIRAWSTARTDMA_DEVADDR 22 +#define ERR_OSPIRAWSTARTDMA_ADDR 23 +#define ERR_OSPIRAWSTARTDMA_SIZE 24 +#define ERR_OSPIRAWSTARTDMA_RANGE 25 +#define ERR_OSPIREADIO 26 +#define ERR_OSPIWRITEIO 27 +#define ERR_OSPISTARTDMA_PIMGR 28 +#define ERR_OSPISTARTDMA_PRI 29 +#define ERR_OSPISTARTDMA_DIR 30 +#define ERR_OSPISTARTDMA_DEVADDR 31 +#define ERR_OSPISTARTDMA_ADDR 32 +#define ERR_OSPISTARTDMA_SIZE 33 +#define ERR_OSPISTARTDMA_RANGE 34 +#define ERR_OSCREATEPIMANAGER 35 +#define ERR_OSVIGETCURRENTMODE 36 +#define ERR_OSVIGETCURRENTFRAMEBUFFER 37 +#define ERR_OSVIGETNEXTFRAMEBUFFER 38 +#define ERR_OSVISETXSCALE_VALUE 39 +#define ERR_OSVISETXSCALE_VIMGR 40 +#define ERR_OSVISETYSCALE_VALUE 41 +#define ERR_OSVISETYSCALE_VIMGR 42 +#define ERR_OSVISETSPECIAL_VALUE 43 +#define ERR_OSVISETSPECIAL_VIMGR 44 +#define ERR_OSVISETMODE 45 +#define ERR_OSVISETEVENT 46 +#define ERR_OSVISWAPBUFFER_ADDR 47 +#define ERR_OSVISWAPBUFFER_VIMGR 48 +#define ERR_OSCREATEVIMANAGER 49 +#define ERR_OSCREATEREGION_ALIGN 50 +#define ERR_OSCREATEREGION_SIZE 51 +#define ERR_OSMALLOC 52 +#define ERR_OSFREE_REGION 53 +#define ERR_OSFREE_ADDR 54 +#define ERR_OSGETREGIONBUFCOUNT 55 +#define ERR_OSGETREGIONBUFSIZE 56 +#define ERR_OSSPTASKLOAD_DRAM 57 +#define ERR_OSSPTASKLOAD_OUT 58 +#define ERR_OSSPTASKLOAD_OUTSIZE 59 +#define ERR_OSSPTASKLOAD_YIELD 60 +#define ERR_OSPROFILEINIT_STR 61 +#define ERR_OSPROFILEINIT_CNT 62 +#define ERR_OSPROFILEINIT_ALN 63 +#define ERR_OSPROFILEINIT_ORD 64 +#define ERR_OSPROFILEINIT_SIZ 65 +#define ERR_OSPROFILESTART_TIME 66 +#define ERR_OSPROFILESTART_FLAG 67 +#define ERR_OSPROFILESTOP_FLAG 68 +#define ERR_OSPROFILESTOP_TIMER 69 +#define ERR_OSREADHOST_ADDR 70 +#define ERR_OSREADHOST_SIZE 71 +#define ERR_OSWRITEHOST_ADDR 72 +#define ERR_OSWRITEHOST_SIZE 73 +#define ERR_OSGETTIME 74 +#define ERR_OSSETTIME 75 +#define ERR_OSSETTIMER 76 +#define ERR_OSSTOPTIMER 77 +#define ERR_ALSEQP_NO_SOUND 100 +#define ERR_ALSEQP_NO_VOICE 101 +#define ERR_ALSEQP_MAP_VOICE 102 +#define ERR_ALSEQP_OFF_VOICE 103 +#define ERR_ALSEQP_POLY_VOICE 104 +#define ERR_ALSNDP_NO_VOICE 105 +#define ERR_ALSYN_NO_UPDATE 106 +#define ERR_ALSNDPDEALLOCATE 107 +#define ERR_ALSNDPDELETE 108 +#define ERR_ALSNDPPLAY 109 +#define ERR_ALSNDPSETSOUND 110 +#define ERR_ALSNDPSETPRIORITY 111 +#define ERR_ALSNDPSETPAR 112 +#define ERR_ALBNKFNEW 113 +#define ERR_ALSEQNOTMIDI 114 +#define ERR_ALSEQNOTMIDI0 115 +#define ERR_ALSEQNUMTRACKS 116 +#define ERR_ALSEQTIME 117 +#define ERR_ALSEQTRACKHDR 118 +#define ERR_ALSEQSYSEX 119 +#define ERR_ALSEQMETA 120 +#define ERR_ALSEQPINVALIDPROG 121 +#define ERR_ALSEQPUNKNOWNMIDI 122 +#define ERR_ALSEQPUNMAP 123 +#define ERR_ALEVENTNOFREE 124 +#define ERR_ALHEAPNOFREE 125 +#define ERR_ALHEAPCORRUPT 126 +#define ERR_ALHEAPFIRSTBLOCK 127 +#define ERR_ALCSEQZEROSTATUS 128 +#define ERR_ALCSEQZEROVEL 129 +#define ERR_ALCSPVNOTFREE 130 +#define ERR_ALSEQOVERRUN 131 +#define ERR_OSAISETNEXTBUFFER_ENDADDR 132 +#define ERR_ALMODDELAYOVERFLOW 133 + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) +typedef void (*OSErrorHandler)(s16, s16, ...); + +OSErrorHandler osSetErrorHandler(OSErrorHandler); +#endif + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* __ULTRAERROR_H__ */ diff --git a/include/PR/ultralog.h b/include/PR/ultralog.h new file mode 100644 index 00000000..48b84b97 --- /dev/null +++ b/include/PR/ultralog.h @@ -0,0 +1,74 @@ +/*==================================================================== + * ultralog.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. + *====================================================================*/ + +/************************************************************************** + * + * $Revision: 1.6 $ + * $Date: 1997/02/11 08:39:05 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ultralog.h,v $ + * + **************************************************************************/ + +#ifndef __log__ +#define __log__ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#define OS_LOG_MAX_ARGS 16 +#define OS_LOG_MAGIC 0x20736a73 +#define OS_LOG_FLOAT(x) (*(int *) &(x)) +#define OS_LOG_VERSION 1 + +typedef struct { + u32 magic; /* log identifier */ + u32 len; /* length of log data + log structure */ + u32 *base; /* starting addr array */ + s32 startCount; /* read offset from dataBase */ + s32 writeOffset; /* write offset from dataBase */ +} OSLog; + +typedef struct { + u32 magic; + u32 timeStamp; + u16 argCount; + u16 eventID; +} OSLogItem; + +typedef struct { + u32 magic; /* log identifier */ + u32 version; /* 1 */ +} OSLogFileHdr; + +void osCreateLog(OSLog *log, u32 *base, s32 len); +void osLogEvent(OSLog *log, s16 code, s16 numArgs, ...); +void osFlushLog(OSLog *log); +u32 osLogFloat(f32); + +extern void osDelay(int count); + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif diff --git a/include/PR/ultratypes.h b/include/PR/ultratypes.h index eb132291..235cc739 100644 --- a/include/PR/ultratypes.h +++ b/include/PR/ultratypes.h @@ -1,46 +1,85 @@ -#ifndef _TYPES_H_ -#define _TYPES_H_ +#ifndef _ULTRATYPES_H_ +#define _ULTRATYPES_H_ + + +/************************************************************************** + * * + * 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. * + * * + **************************************************************************/ + + +/************************************************************************* + * + * File: ultratypes.h + * + * This file contains various types used in Ultra64 interfaces. + * + * $Revision: 1.6 $ + * $Date: 1997/12/17 04:02:06 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ultratypes.h,v $ + * + **************************************************************************/ + + + +/********************************************************************** + * General data types for R4300 + */ +#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 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 volatile unsigned char vu8; /* unsigned 8-bit */ +typedef volatile unsigned short vu16; /* unsigned 16-bit */ +typedef volatile unsigned long vu32; /* unsigned 32-bit */ +typedef volatile unsigned long long vu64; /* unsigned 64-bit */ + +typedef volatile signed char vs8; /* signed 8-bit */ +typedef volatile short vs16; /* signed 16-bit */ +typedef volatile long vs32; /* signed 32-bit */ +typedef volatile long long vs64; /* signed 64-bit */ + +typedef float f32; /* single prec floating point */ +typedef double f64; /* double prec floating point */ + +#if !defined(_SIZE_T) && !defined(_SIZE_T_) && !defined(_SIZE_T_DEF) +#define _SIZE_T +#define _SIZE_T_DEF /* exeGCC size_t define label */ +#if (_MIPS_SZLONG == 32) +typedef unsigned int size_t; +#endif +#if (_MIPS_SZLONG == 64) +typedef unsigned long size_t; +#endif +#endif + +#endif /* _LANGUAGE_C */ + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif #ifndef NULL -#define NULL 0 +#define NULL 0 #endif -#define TRUE 1 -#define FALSE 0 - -typedef signed char s8; -typedef unsigned char u8; -typedef signed short s16; -typedef unsigned short u16; -typedef long s32; -typedef unsigned long u32; -typedef signed long long s64; -typedef unsigned long long u64; - -typedef volatile u8 vu8; -typedef volatile u16 vu16; -typedef volatile u32 vu32; -typedef volatile u64 vu64; -typedef volatile s8 vs8; -typedef volatile s16 vs16; -typedef volatile s32 vs32; -typedef volatile s64 vs64; - -typedef float f32; -typedef double f64; - -//#ifdef TARGET_N64 -typedef u32 size_t; -typedef s32 ssize_t; -typedef u32 uintptr_t; -typedef s32 intptr_t; -typedef s32 ptrdiff_t; -//#else -//#include -//#endif - -typedef float Matrix[4][4]; -typedef s16 VertexList; -typedef u8 TriangleList; - -#endif +#endif /* _ULTRATYPES_H_ */ diff --git a/include/PRinternal/controller.h b/include/PRinternal/controller.h new file mode 100644 index 00000000..92e545e6 --- /dev/null +++ b/include/PRinternal/controller.h @@ -0,0 +1,290 @@ +#ifndef _CONTROLLER_H +#define _CONTROLLER_H + +#include +#include "PR/os_internal.h" +#include "PR/os_version.h" +#include "PR/rcp.h" + +#include "PRinternal/macros.h" + +#define CHNL_ERR(format) (((format).rxsize & CHNL_ERR_MASK) >> 4) + +typedef struct +{ + /* 0x0 */ u32 ramarray[15]; + /* 0x3C */ u32 pifstatus; +} OSPifRam ALIGNED(0x10); + +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; +} __OSContRequesFormat; + +typedef struct +{ + /* 0x0 */ u8 txsize; + /* 0x1 */ u8 rxsize; + /* 0x2 */ u8 cmd; + /* 0x3 */ u8 typeh; + /* 0x4 */ u8 typel; + /* 0x5 */ u8 status; +} __OSContRequesFormatShort; + +typedef struct +{ + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; +#if BUILD_VERSION >= VERSION_J + /* 0x4 */ u8 addrh; + /* 0x5 */ u8 addrl; +#else + /* 0x4 */ u16 address; +#endif + /* 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; + +// Joybus commands +//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_PAK 2 +#define CONT_CMD_WRITE_PAK 3 +#define CONT_CMD_READ_EEPROM 4 +#define CONT_CMD_WRITE_EEPROM 5 +#define CONT_CMD_READ36_VOICE 9 +#define CONT_CMD_WRITE20_VOICE 10 +#define CONT_CMD_READ2_VOICE 11 +#define CONT_CMD_WRITE4_VOICE 12 +#define CONT_CMD_SWRITE_VOICE 13 +#define CONT_CMD_CHANNEL_RESET 0xFD +#define CONT_CMD_RESET 0xFF + +// Bytes transmitted for each joybus command +#define CONT_CMD_REQUEST_STATUS_TX 1 +#define CONT_CMD_READ_BUTTON_TX 1 +#define CONT_CMD_READ_PAK_TX 3 +#define CONT_CMD_WRITE_PAK_TX 35 +#define CONT_CMD_READ_EEPROM_TX 2 +#define CONT_CMD_WRITE_EEPROM_TX 10 +#define CONT_CMD_READ36_VOICE_TX 3 +#define CONT_CMD_WRITE20_VOICE_TX 23 +#define CONT_CMD_READ2_VOICE_TX 3 +#define CONT_CMD_WRITE4_VOICE_TX 7 +#define CONT_CMD_SWRITE_VOICE_TX 3 +#define CONT_CMD_RESET_TX 1 + +// Bytes received for each joybus command +#define CONT_CMD_REQUEST_STATUS_RX 3 +#define CONT_CMD_READ_BUTTON_RX 4 +#define CONT_CMD_READ_PAK_RX 33 +#define CONT_CMD_WRITE_PAK_RX 1 +#define CONT_CMD_READ_EEPROM_RX 8 +#define CONT_CMD_WRITE_EEPROM_RX 1 +#define CONT_CMD_READ36_VOICE_RX 37 +#define CONT_CMD_WRITE20_VOICE_RX 1 +#define CONT_CMD_READ2_VOICE_RX 3 +#define CONT_CMD_WRITE4_VOICE_RX 1 +#define CONT_CMD_SWRITE_VOICE_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 + +// Controller accessory addresses +// https://github.com/joeldipops/TransferBoy/blob/master/docs/TransferPakReference.md + +// Accesory detection +#define CONT_ADDR_DETECT 0x8000 +// Rumble +#define CONT_ADDR_RUMBLE 0xC000 +// Controller Pak +// Transfer Pak +#define CONT_ADDR_GB_POWER 0x8000 // Same as the detection address, but semantically different +#define CONT_ADDR_GB_BANK 0xA000 +#define CONT_ADDR_GB_STATUS 0xB000 + +// Addresses sent to controller accessories are in blocks, not bytes +#define CONT_BLOCKS(x) ((x) / BLOCKSIZE) + +// Block addresses of the above +#define CONT_BLOCK_DETECT CONT_BLOCKS(CONT_ADDR_DETECT) +#define CONT_BLOCK_RUMBLE CONT_BLOCKS(CONT_ADDR_RUMBLE) +#define CONT_BLOCK_GB_POWER CONT_BLOCKS(CONT_ADDR_GB_POWER) +#define CONT_BLOCK_GB_BANK CONT_BLOCKS(CONT_ADDR_GB_BANK) +#define CONT_BLOCK_GB_STATUS CONT_BLOCKS(CONT_ADDR_GB_STATUS) + + +// Transfer pak + +#define GB_POWER_ON 0x84 +#define GB_POWER_OFF 0xFE + + +typedef struct +{ + /* 0x0 */ __OSInode inode; + /* 0x100 */ u8 bank; + /* 0x101 */ u8 map[PFS_INODE_DIST_MAP]; +} __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); +#if BUILD_VERSION >= VERSION_J +s32 __osPfsSelectBank(OSPfs *pfs, u8 bank); +#else +s32 __osPfsSelectBank(OSPfs *pfs); +#endif +s32 __osPfsDeclearPage(OSPfs *pfs, __OSInode *inode, int file_size_in_pages, int *first_page, u8 bank, int *decleared, int *last_page); +#if BUILD_VERSION >= VERSION_J +s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u8 bank, __OSInodeUnit *last_page); +#else +s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u16 *sum, u8 bank, __OSInodeUnit *last_page, int flag); +#endif +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); + +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 + +#if BUILD_VERSION >= VERSION_J + +#define SELECT_BANK(pfs, bank) \ + __osPfsSelectBank((pfs), (bank)) + +#define SET_ACTIVEBANK_TO_ZERO() \ + if (pfs->activebank != 0) \ + { \ + ERRCK(__osPfsSelectBank(pfs, 0)); \ + } (void)0 + +#else + +#define SELECT_BANK(pfs, bank) \ + (pfs->activebank = (bank), __osPfsSelectBank((pfs))) + +#define SET_ACTIVEBANK_TO_ZERO() \ + if (pfs->activebank != 0) \ + { \ + pfs->activebank = 0; \ + ERRCK(__osPfsSelectBank(pfs)); \ + } (void)0 + +#endif + +#define PFS_CHECK_ID() \ + if (__osCheckId(pfs) == PFS_ERR_NEW_PACK) \ + return PFS_ERR_NEW_PACK + +#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 + +#endif diff --git a/include/PRinternal/controller_gbpak.h b/include/PRinternal/controller_gbpak.h new file mode 100644 index 00000000..db98bd48 --- /dev/null +++ b/include/PRinternal/controller_gbpak.h @@ -0,0 +1,8 @@ +#ifndef _CONTROLLER_GBPAK_H +#define _CONTROLLER_GBPAK_H + +extern OSTimer __osGbpakTimer; +extern OSMesg __osGbpakTimerMsg; +extern OSMesgQueue __osGbpakTimerQ; + +#endif diff --git a/include/PRinternal/controller_voice.h b/include/PRinternal/controller_voice.h new file mode 100644 index 00000000..1b9dee6d --- /dev/null +++ b/include/PRinternal/controller_voice.h @@ -0,0 +1,59 @@ +#ifndef CONTROLLER_VOICE_H +#define CONTROLLER_VOICE_H + +#include "PR/ultratypes.h" + +typedef struct { + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u8 addrh; + /* 0x5 */ u8 addrl; + /* 0x6 */ u8 data[2]; + /* 0x8 */ u8 datacrc; +} __OSVoiceRead2Format; + +typedef struct { + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u8 addrh; + /* 0x5 */ u8 addrl; + /* 0x6 */ u8 data[36]; + /* 0x2A */ u8 datacrc; +} __OSVoiceRead36Format; + +typedef struct { + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u8 addrh; + /* 0x5 */ u8 addrl; + /* 0x6 */ u8 data[4]; + /* 0xA */ u8 datacrc; +} __OSVoiceWrite4Format; + +typedef struct { + /* 0x0 */ u8 dummy; + /* 0x1 */ u8 txsize; + /* 0x2 */ u8 rxsize; + /* 0x3 */ u8 cmd; + /* 0x4 */ u8 addrh; + /* 0x5 */ u8 addrl; + /* 0x6 */ u8 data[20]; + /* 0x1A */ u8 datacrc; +} __OSVoiceWrite20Format; + +typedef struct { + /* 0x0 */ u8 txsize; + /* 0x1 */ u8 rxsize; + /* 0x2 */ u8 cmd; + /* 0x3 */ u8 data; + /* 0x4 */ u8 scrc; + /* 0x5 */ u8 datacrc; +} __OSVoiceSWriteFormat; + +#endif // CONTROLLER_VOICE_H diff --git a/include/PRinternal/dbgdefs.h b/include/PRinternal/dbgdefs.h new file mode 100644 index 00000000..f7ead714 --- /dev/null +++ b/include/PRinternal/dbgdefs.h @@ -0,0 +1,8 @@ +#ifndef _DBGDEFS_H__ +#define _DBGDEFS_H__ + +typedef int TVid; +typedef unsigned short TVushort; +typedef char TVuchar; + +#endif diff --git a/include/PRinternal/dbgproto.h b/include/PRinternal/dbgproto.h new file mode 100644 index 00000000..e4d36565 --- /dev/null +++ b/include/PRinternal/dbgproto.h @@ -0,0 +1,402 @@ +#ifndef _DBGPROTO_H__ +#define _DBGPROTO_H__ + +#include "PRinternal/dbgdefs.h" + +#define KK_REV 2 + +#define KK_CODE_THREAD_STATUS 4 + +#define KK_TYPE_REQUEST 0 +#define KK_TYPE_REPLY 1 +#define KK_TYPE_EXCEPTION 2 +#define KK_TYPE_THREAD_EXIT 3 +#define KK_TYPE_PROCESS_EXIT 4 +#define KK_TYPE_CONSOLE 5 + +#define TV_ERROR_NO_ERROR 0 +#define TV_ERROR_ILLEGAL_CALL -1 +#define TV_ERROR_INVALID_ID -2 +#define TV_ERROR_INVALID_TYPE -3 +#define TV_ERROR_OPERATIONS_PROTECTED -4 +#define TV_ERROR_INVALID_ADDRESS -5 +#define TV_ERROR_INVALID_PRIORITY -6 +#define TV_ERROR_INVALID_FLAGS -7 +#define TV_ERROR_INVALID_CAPABILITY -8 +#define TV_ERROR_NO_HANDLER -9 +#define TV_ERROR_NO_MORE_IDS -10 +#define TV_ERROR_NO_MORE_MESSAGES -11 +#define TV_ERROR_NO_MORE_PROCESSES -12 +#define TV_ERROR_NO_MORE_THREADS -13 +#define TV_ERROR_NO_MORE_REGIONS -14 +#define TV_ERROR_NO_MORE_TIMERS -15 +#define TV_ERROR_NO_MORE_LOCKS -16 +#define TV_ERROR_NO_MORE_QUEUES -17 +#define TV_ERROR_NO_MORE_SETS -18 +#define TV_ERROR_NO_MORE_MEMORY -19 +#define TV_ERROR_NOT_LOCKED -20 + +typedef struct __KKTimeStruct { + long seconds; + long nanoseconds; +} KKTimeStruct; + +typedef struct __KKObjsStruct { + TVushort number; + TVid objects[1]; +} KKObjs; + +typedef struct __KKFaultInfoStruct { + unsigned int addr; + short major; + short minor; +} KKFaultInfo; + +typedef struct __KKThreadStatusStruct { + int flags; + short why; + short what; + TVid tid; + TVid pid; + unsigned int instr; + KKFaultInfo info; + int priority; + int start; + int rv; + unsigned int args[6]; +} KKThreadStatus; + +#define KK_RUN_SSTEP (1 << 0) +#define KK_RUN_SETPC (1 << 1) + +typedef struct __KKRunStruct { + int flags; + unsigned int vaddr; +} KKRun; + +typedef struct __KKFaultStruct { + short majorMask; + short minorMask; +} KKFault; + +typedef struct __KKRegionStruct { + unsigned int vaddr; + unsigned int size; + short flags; + unsigned int paddr; +} KKRegion; + +typedef struct __KKGregSetStruct { + unsigned int gregs[37]; +} KKGregSet; + +typedef struct __KKFPregSetStruct { + union { + double dregs[16]; + float fregs[32]; + unsigned int regs[32]; + } fpregs; + unsigned int fpcsr; + unsigned int fppad; +} KKFPregSet; + +typedef struct __KKRegisterContextStruct { + KKGregSet gregs; + KKFPregSet fpregs; +} KKRegisterContext; + +typedef struct __KKCpScalarSetStruct { + unsigned int sregs[40]; +} KKCpScalarRegSet; + +typedef struct __KKCpVectorSetStruct { + unsigned int vregs[128]; +} KKCpVectorRegSet; + +typedef struct __KKCpRegisterContextStruct { + KKCpScalarRegSet sregs; + KKCpVectorRegSet vregs; +} KKCpRegisterContext; + +typedef struct __KKUsageStruct { + KKTimeStruct tstamp; + KKTimeStruct created; + KKTimeStruct states[10]; +} KKUsage; + +typedef struct __KKLogEventSetStruct { + int from; + int to; +} KKLogEventSet; + +typedef struct __KKLogStatusStruct { + int bufferType; + int bufferSize; + int dataSize; + int logState; + int flushLimit; +} KKLogStatus; + +typedef struct __KKProcUsageStruct { + TVid pid; + KKTimeStruct states[10]; +} KKProcUsage; + +typedef struct __KKHeaderStruct { + int length; + char code; + char type; + short error; + char rev; + char method; + short notused2; +} KKHeader; + +typedef struct __KKGetFrameRequestStruct { + KKHeader header; + int height; + int width; + int which; +} KKGetFrameRequest; + +typedef struct __KKLoadExecutableRequestStruct { + KKHeader header; + char str[1]; +} KKLoadExecutableRequest; + +typedef struct __KKObjectRequestStruct { + KKHeader header; + TVid object; +} KKObjectRequest; + +typedef struct __KKRunThreadRequestStruct { + KKHeader header; + TVid tid; + KKRun actions; +} KKRunThreadRequest; + +typedef struct __KKFaultRequestStruct { + KKHeader header; + TVid tid; + KKFault fault; + TVuchar stopAllThreads; +} KKFaultRequest; + +typedef struct __KKGRegsetRequestStruct { + KKHeader header; + TVid tid; + KKGregSet registers; +} KKGRegsetRequest; + +typedef struct __KKFPRegsetRequestStruct { + KKHeader header; + TVid tid; + KKFPregSet registers; +} KKFPRegsetRequest; + +typedef struct __KKCpScalarRegsetRequestStruct { + KKHeader header; + TVid tid; + KKCpScalarRegSet registers; +} KKCpScalarRegsetRequest; + +typedef struct __KKCpVectorRegsetRequestStruct { + KKHeader header; + TVid tid; + KKCpVectorRegSet registers; +} KKCpVectorRegsetRequest; + +typedef struct __KKReadRequestStruct { + KKHeader header; + TVid object; + unsigned int addr; + unsigned int nbytes; +} KKReadRequest; + +typedef struct __KKWriteHeaderStruct { + KKHeader header; + TVid object; + unsigned int addr; + unsigned int nbytes; +} KKWriteHeader; + +typedef struct __KKWriteRequestStruct { + KKWriteHeader writeHeader; + char buffer[1]; +} KKWriteRequest; + +typedef struct __KKSetBkptRequestStruct { + KKHeader header; + TVid object; + unsigned int addr; +} KKSetBkptRequest; + +typedef struct __KKClrBkptRequestStruct { + KKHeader header; + TVid object; + TVid bp; +} KKClrBkptRequest; + +typedef struct __KKWatchRequestStruct { + KKHeader header; + TVid object; + unsigned int number; + KKRegion wp[1]; +} KKWatchRequest; + +typedef struct __KKSetCommRequestStruct { + KKHeader header; + unsigned int how; + unsigned int addr; +} KKSetCommRequest; + +typedef struct __KKSysCallSetStruct { + unsigned int word[8]; +} KKSysCallSet; + +typedef struct __KKSysCallRequestStruct { + KKHeader header; + TVid pid; + KKSysCallSet syscallset; +} KKSysCallRequest; + +typedef struct __KKLogEventRequestStruct { + KKHeader header; + unsigned int numSet; + KKLogEventSet set[1]; +} KKLogEventRequest; + +typedef struct __KKNewLogRequestStruct { + KKHeader header; + char str[1]; +} KKNewLogRequest; + +typedef struct __KKRemoteRequestStruct { + KKHeader header; + int len; + char buf[16]; +} KKRemoteRequest; + +typedef struct __KKFlushLogRequestStruct { + KKHeader header; + int no_block; +} KKFlushLogRequest; + +typedef struct __KKLogControlRequestStruct { + KKHeader header; + int command; + int arg; +} KKLogControlRequest; + +typedef struct __KKSetTrptRequestStruct { + KKSetBkptRequest bpRequest; + unsigned short code; +} KKSetTrptRequest; + +typedef KKClrBkptRequest KKClrTrptRequest; + +typedef struct __KKObjectEventStruct { + KKHeader header; + TVid object; +} KKObjectEvent; + +typedef struct __KKObjsEventStruct { + KKHeader header; + TVid object; + KKObjs objs; +} KKObjsEvent; + +typedef struct __KKBufferEventStruct { + KKHeader header; + TVid object; + char buffer[1]; +} KKBufferEvent; + +typedef struct __KKStatusEventStruct { + KKHeader header; + KKThreadStatus status; +} KKStatusEvent; + +typedef struct __KKFaultEventStruct { + KKHeader header; + TVid tid; + KKFault fault; + TVuchar stopAllThreads; +} KKFaultEvent; + +typedef struct __KKNumberEventStruct { + KKHeader header; + TVid object; + unsigned int number; +} KKNumberEvent; + +typedef struct __KKRegionEventStruct { + KKHeader header; + TVid object; + unsigned int number; + KKRegion regions[1]; +} KKRegionEvent; + +typedef struct __KKGregEventStruct { + KKHeader header; + TVid tid; + KKGregSet registers; +} KKGregEvent; + +typedef struct __KKFPregEventStruct { + KKHeader header; + TVid tid; + KKFPregSet registers; +} KKFPregEvent; + +typedef struct __KKCpSregEventStruct { + KKHeader header; + TVid tid; + KKCpScalarRegSet registers; +} KKCpSregEvent; + +typedef struct __KKCpVregEventStruct { + KKHeader header; + TVid tid; + KKCpVectorRegSet registers; +} KKCpVregEvent; + +typedef struct __KKBkptEventStruct { + KKHeader header; + TVid object; + TVid bp; + unsigned int instruction; +} KKBkptEvent; + +typedef struct __KKUsageEventStruct { + KKHeader header; + TVid tid; + KKUsage usage; +} KKUsageEvent; + +typedef struct __KKFlushEventStruct { + KKHeader header; + int bufferType; + char buffer[1]; +} KKFlushEvent; + +typedef struct __KKLogStatusEventStruct { + KKHeader header; + KKLogStatus status; +} KKLogStatusEvent; + +typedef struct __KKSysUsageEventStruct { + KKHeader header; + KKTimeStruct tstamp; + int numProc; + KKProcUsage usage[1]; +} KKSysUsageEvent; + +typedef struct __KKStringEventStruct { + KKHeader header; + char str[1]; +} KKStringEvent; + +typedef KKSysCallRequest KKSysCallEvent; + +#endif diff --git a/include/PRinternal/macros.h b/include/PRinternal/macros.h new file mode 100644 index 00000000..c84c7ad8 --- /dev/null +++ b/include/PRinternal/macros.h @@ -0,0 +1,24 @@ +#ifndef __MACROS_H__ +#define __MACROS_H__ + +#define ALIGNED(x) __attribute__((aligned(x))) + +#define ARRLEN(x) ((s32)(sizeof(x) / sizeof(x[0]))) + +#define STUBBED_PRINTF(x) ((void)(x)) + +#define UNUSED __attribute__((unused)) + +#ifndef __GNUC__ +#define __attribute__(x) +#endif + +#define ALIGN8(val) (((val) + 7) & ~7) + +#define STACK(stack, size) \ + u64 stack[ALIGN8(size) / sizeof(u64)] + +#define STACK_START(stack) \ + ((u8*)(stack) + sizeof(stack)) + +#endif diff --git a/lib/src/os/osint.h b/include/PRinternal/osint.h similarity index 72% rename from lib/src/os/osint.h rename to include/PRinternal/osint.h index 124b6b03..690c8810 100644 --- a/lib/src/os/osint.h +++ b/include/PRinternal/osint.h @@ -1,12 +1,14 @@ #ifndef _OSINT_H #define _OSINT_H -#include - -typedef struct __OSEventState { +#include "PR/os_internal.h" +#include +typedef struct __OSEventState +{ OSMesgQueue *messageQueue; OSMesg message; } __OSEventState; -extern struct __osThreadTail { +extern struct __osThreadTail +{ OSThread *next; OSPri priority; } __osThreadTail; @@ -17,6 +19,7 @@ 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 *); @@ -35,12 +38,22 @@ extern OSTime __osCurrentTime; extern u32 __osBaseCounter; extern u32 __osViIntrCount; extern u32 __osTimerCounter; +extern u32 __osShutdown; + +extern OSMesgQueue __osProfTimerQ; +extern OSProf *__osProfileList; +extern OSProf *__osProfileListEnd; +extern u32 __osProfileOverflowBin; + +extern __OSEventState __osEventStateTab[]; -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/lib/src/os/piint.h b/include/PRinternal/piint.h similarity index 57% rename from lib/src/os/piint.h rename to include/PRinternal/piint.h index 9c3f06b8..6474aff6 100644 --- a/lib/src/os/piint.h +++ b/include/PRinternal/piint.h @@ -1,6 +1,9 @@ -#ifndef _PIINT_H -#define _PIINT_H -#include "libultra_internal.h" +#ifndef _PIINT_H_ +#define _PIINT_H_ + +#include +#include "PR/os_internal.h" +#include "PR/rcp.h" //https://github.com/LuigiBlood/64dd/wiki/Memory-Map @@ -91,40 +94,83 @@ #define LEO_ERROR_24 24 //no reference position found? #define LEO_ERROR_29 29 // -/* - * PI/EPI - */ -#define PI_DOMAIN1 0 -#define PI_DOMAIN2 1 - extern OSDevMgr __osPiDevMgr; -extern OSPiHandle *__osCurrentHandle[2]; +extern OSPiHandle *__osCurrentHandle[]; extern OSPiHandle CartRomHandle; extern OSPiHandle LeoDiskHandle; extern OSMesgQueue __osPiAccessQueue; extern u32 __osPiAccessQueueEnabled; +// These symbols were all renamed in 2.0J. +#if BUILD_VERSION < VERSION_J +#define __osEPiRawStartDma osEPiRawStartDma +#define __osEPiRawReadIo osEPiRawReadIo +#define __osEPiRawWriteIo osEPiRawWriteIo +#define __osPiRawStartDma osPiRawStartDma +#define __osPiRawWriteIo osPiRawWriteIo +#define __osPiRawReadIo osPiRawReadIo +#endif + 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 OS_RAMROM_STACKSIZE 1024 +#define WAIT_ON_IOBUSY(stat) \ + { \ + stat = IO_READ(PI_STATUS_REG); \ + while (stat & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) \ + stat = IO_READ(PI_STATUS_REG); \ + } (void)0 -#define WAIT_ON_IOBUSY(stat) \ - stat = IO_READ(PI_STATUS_REG); \ - while (stat & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) \ - stat = IO_READ(PI_STATUS_REG); - -#define UPDATE_REG(reg, var) \ +#define UPDATE_REG(pihandle, reg, var) \ if (cHandle->var != pihandle->var) \ - IO_WRITE(reg, pihandle->var); + IO_WRITE(reg, pihandle->var) + +#if BUILD_VERSION >= VERSION_J + +#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 + +#else #define EPI_SYNC(pihandle, stat, domain) \ \ - WAIT_ON_IOBUSY(stat) \ + WAIT_ON_IOBUSY(stat); \ \ domain = pihandle->domain; \ if (__osCurrentHandle[domain] != pihandle) \ @@ -132,19 +178,21 @@ OSMesgQueue *osPiGetCmdQueue(void); OSPiHandle *cHandle = __osCurrentHandle[domain]; \ if (domain == PI_DOMAIN1) \ { \ - UPDATE_REG(PI_BSD_DOM1_LAT_REG, latency); \ - UPDATE_REG(PI_BSD_DOM1_PGS_REG, pageSize); \ - UPDATE_REG(PI_BSD_DOM1_RLS_REG, relDuration); \ - UPDATE_REG(PI_BSD_DOM1_PWD_REG, pulse); \ + 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(PI_BSD_DOM2_LAT_REG, latency); \ - UPDATE_REG(PI_BSD_DOM2_PGS_REG, pageSize); \ - UPDATE_REG(PI_BSD_DOM2_RLS_REG, relDuration); \ - UPDATE_REG(PI_BSD_DOM2_PWD_REG, pulse); \ + 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); \ } \ __osCurrentHandle[domain] = pihandle; \ - } + }(void)0 + +#endif #endif diff --git a/include/PRinternal/rmonint.h b/include/PRinternal/rmonint.h new file mode 100644 index 00000000..714a63ff --- /dev/null +++ b/include/PRinternal/rmonint.h @@ -0,0 +1,169 @@ +#ifndef _RMONINT_H +#define _RMONINT_H + +#include "PRinternal/dbgproto.h" +#include "PR/os_internal.h" + +/* mips */ + +#define MIPS_LWC2_OPCODE 50 +#define MIPS_SWC2_OPCODE 58 + +#define MIPS_LW_OPCODE 35 +#define MIPS_SW_OPCODE 43 + +#define MIPS_BREAK_OPCODE 0xD +#define MIPS_BREAK_MASK 0xFC00003F + +#define MIPS_BREAK(code) \ + ((((code) & 0xFFFFF) << 6) | MIPS_BREAK_OPCODE) + +/* R4300 General Purpose Register Indices */ +#define GREG_IDX_ZERO 0 +#define GREG_IDX_AT 1 +#define GREG_IDX_T9 25 +#define GREG_IDX_K0 26 +#define GREG_IDX_GP 28 +#define GREG_IDX_RA 31 +#define GREG_IDX_LO 32 +#define GREG_IDX_HI 33 +#define GREG_IDX_CAUSE 34 +#define GREG_IDX_PC 35 +#define GREG_IDX_SR 36 + +/* RSP Scalar Register Indices */ +#define SREG_IDX_ZERO 0 +#define SREG_IDX_RA 31 +#define SREG_IDX_DRAM_ADDR (32 + 0) +#define SREG_IDX_MEM_ADDR (32 + 1) +#define SREG_IDX_RD_LEN (32 + 2) +#define SREG_IDX_PC (32 + 3) +#define SREG_IDX_WR_LEN (32 + 4) +#define SREG_IDX_STATUS (32 + 5) +#define SREG_IDX_DMA_FULL (32 + 6) +#define SREG_IDX_DMA_BUSY (32 + 7) + +/* RSP Vector Register Properties */ +#define VREG_NUM 32 +#define VREG_SIZE 0x10 + +/* rmon */ + +#define RMON_MESG_CPU_BREAK 2 +#define RMON_MESG_SP_BREAK 4 +#define RMON_MESG_FAULT 8 + +#define RMON_CPU 0 +#define RMON_RSP 1 + +/* "thread id" for rsp */ +#define RMON_TID_RSP 1000 +/* "thread priority" for rsp */ +#define RMON_PRI_RSP 42 + +/* "thread id" for no thread running */ +#define RMON_TID_NOTHREAD 1003 + +#define RMON_PID_CPU 1002 +#define RMON_PID_RSP 1001 + +/* Largest serviceable read/write memory request */ +#define RMON_MAX_XFER_SIZE 1024 + +/* rmonmain */ + +void __rmonSendHeader(KKHeader* const block, u32 blockSize, u32 type); +void __rmonSendReply(KKHeader* const block, u32 blockSize, u32 replyType); +void __rmonSendData(char* const block, unsigned int blockSize); + +extern int __rmonActive; + +/* rmonmisc */ + +void __rmonInit(void); +void __rmonPanic(void); + +extern OSMesgQueue __rmonMQ; + +/* rmonmem */ + +void __rmonWriteWordTo(u32* addr, u32 val); +u32 __rmonReadWordAt(u32* addr); +void __rmonMemcpy(u8* dest, u8* srce, u32 count); +void __rmonCopyWords(u32* dest, u32* srce, u32 count); + +extern u8 __rmonUtilityBuffer[]; + +/* rmonsio */ + +void __rmonSendFault(OSThread* thread); +void __rmonIOflush(void); +void __rmonIOputw(u32 word); +void __rmonIOhandler(void); + +extern void* __osRdb_DbgRead_Buf; +extern u8 rmonRdbReadBuf[]; + +/* rmonrcp */ + +int __rmonRCPrunning(void); +void __rmonIdleRCP(void); +void __rmonStepRCP(void); +void __rmonRunRCP(void); + +/* rmonbrk */ + +u32 __rmonGetBranchTarget(int method, int thread, char* addr); +int __rmonSetSingleStep(int thread, u32* instptr); +void __rmonGetExceptionStatus(KKStatusEvent* reply); +void __rmonHitBreak(void); +void __rmonHitSpBreak(void); +void __rmonHitCpuFault(void); + +extern u8 __rmonRcpAtBreak; + +/* rmonregs */ + +u32 __rmonGetRegisterContents(int method, int threadNumber, int regNumber); + +/* rmontask */ + +void __rmonMaskIdleThreadInts(void); +OSThread* __rmonGetTCB(int threadNumber); +int __rmonStopUserThreads(int whichThread); +int __rmonGetThreadStatus(int method, int id, KKStatusEvent* reply); + +/* rmoncmds */ + +int __rmonExecute(KKHeader* request); + +/* commands */ + +typedef int (*FUNPTR)(); + +int __rmonLoadProgram(KKHeader* req); +int __rmonListProcesses(KKHeader* req); +int __rmonGetExeName(KKHeader* req); +int __rmonListThreads(KKHeader* req); +int __rmonThreadStatus(KKHeader* req); +int __rmonStopThread(KKHeader* req); +int __rmonRunThread(KKHeader* req); +int __rmonSetFault(KKHeader* req); +int __rmonGetRegionCount(KKHeader* req); +int __rmonGetRegions(KKHeader* req); +int __rmonGetGRegisters(KKHeader* req); +int __rmonSetGRegisters(KKHeader* req); +int __rmonGetFRegisters(KKHeader* req); +int __rmonSetFRegisters(KKHeader* req); +int __rmonReadMem(KKHeader* req); +int __rmonWriteMem(KKHeader* req); +int __rmonSetBreak(KKHeader* req); +int __rmonClearBreak(KKHeader* req); +int __rmonListBreak(KKHeader* req); +int __rmonSetComm(KKHeader* req); +int __rmonGetSRegs(KKHeader* req); +int __rmonSetSRegs(KKHeader* req); +int __rmonGetVRegs(KKHeader* req); +int __rmonSetVRegs(KKHeader* req); + +#endif diff --git a/include/siint.h b/include/PRinternal/siint.h similarity index 64% rename from include/siint.h rename to include/PRinternal/siint.h index e9fb2b83..636a87ff 100644 --- a/include/siint.h +++ b/include/PRinternal/siint.h @@ -1,11 +1,15 @@ -#ifndef _SIINT_H_ -#define _SIINT_H_ +#ifndef _SIINT_H +#define _SIINT_H #include "PR/os_internal.h" #include "PR/rcp.h" +extern s32 __osEepromRead16K; +extern u8 __osPfsInodeCacheBank; + void __osSiGetAccess(void); void __osSiRelAccess(void); int __osSiDeviceBusy(void); void __osSiCreateAccessQueue(void); + #endif diff --git a/include/viint.h b/include/PRinternal/viint.h similarity index 54% rename from include/viint.h rename to include/PRinternal/viint.h index e366b788..45526ff4 100644 --- a/include/viint.h +++ b/include/PRinternal/viint.h @@ -1,21 +1,19 @@ -#ifndef _VIINT_H_ -#define _VIINT_H_ - -#include "libultra_internal.h" +#ifndef _VIINT_H +#define _VIINT_H +#include #define OS_TV_TYPE_PAL 0 #define OS_TV_TYPE_NTSC 1 #define OS_TV_TYPE_MPAL 2 -//TODO: figure out what this is -#define VI_STATE_01 0x01 +#define VI_STATE_MODE_UPDATED 0x01 #define VI_STATE_XSCALE_UPDATED 0x02 #define VI_STATE_YSCALE_UPDATED 0x04 -#define VI_STATE_08 0x08 //related to control regs changing -#define VI_STATE_10 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_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 */ @@ -26,17 +24,17 @@ #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) + (((u32)(hsync_width) & 0xFF) | (((u32)(color_width) & 0xFF) << 8) | (((u32)(vsync_width) & 0xF) << 16) | (((u32)(color_start) & 0xFFFF) << 20)) +#define WIDTH(v) (v) +#define VSYNC(v) (v) +#define HSYNC(duration, leap) (((u32)(leap) << 16) | ((u32)(duration) & 0xFFFF)) +#define LEAP(upper, lower) (((u32)(upper) << 16) | ((u32)(lower) & 0xFFFF)) +#define START(start, end) (((u32)(start) << 16) | ((u32)(end) & 0xFFFF)) -#define FTOFIX(val, i, f) ((u32)(val * (f32)(1 << f)) & ((1 << (i + f)) - 1)) +#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 SCALE(scaleup, off) (F210((1.0f / (f32)(scaleup))) | (F210((f32)(off)) << 16)) #define VCURRENT(v) v //seemingly unused #define ORIGIN(v) v @@ -61,13 +59,13 @@ typedef struct /* 0x14 */ OSMesg msg; /* 0x18 */ __OSViScale x; /* 0x24 */ __OSViScale y; -} __OSViContext; +} __OSViContext; // 0x30 bytes void __osViSwapContext(void); extern __OSViContext *__osViCurr; extern __OSViContext *__osViNext; +extern u32 __additional_scanline; __OSViContext *__osViGetCurrentContext(void); void __osViInit(void); -void *osViGetCurrentFramebuffer(void); -void *osViGetNextFramebuffer(void); +extern OSDevMgr __osViDevMgr; #endif diff --git a/include/asm.h b/include/asm.h new file mode 100644 index 00000000..1de9f0ad --- /dev/null +++ b/include/asm.h @@ -0,0 +1 @@ +#include diff --git a/include/audio_internal.h b/include/audio_internal.h index 12758993..288feee7 100644 --- a/include/audio_internal.h +++ b/include/audio_internal.h @@ -27,7 +27,8 @@ enum { AL_FILTER_START_VOICE_ALT, AL_FILTER_START_VOICE, AL_FILTER_STOP_VOICE, - AL_FILTER_SET_FXAMT + AL_FILTER_SET_FXAMT, + AL_FILTER_UNK11 }; #define AL_MAX_RSP_SAMPLES 160 @@ -304,12 +305,14 @@ typedef struct PVoice_s { */ ALParam *__allocParam(void); void __freeParam(ALParam *param); -void __freePVoices(ALSynth *drvr, PVoice *pvoice); +void _freePVoice(ALSynth *drvr, PVoice *pvoice); void _collectPVoices(ALSynth *drvr); -s32 __timeToSamples(ALSynth *ALSynth, s32 micros); +s32 _timeToSamples(ALSynth *ALSynth, s32 micros); ALMicroTime _samplesToTime(ALSynth *synth, s32 samples); +void func_80065A80(ALSynth *arg0, PVoice *arg1, s16 arg2); + void _init_lpfilter(ALLowPass *lp); void alClose(ALGlobals *glob); diff --git a/include/controller.h b/include/controller.h deleted file mode 100644 index 3da78fa4..00000000 --- a/include/controller.h +++ /dev/null @@ -1,162 +0,0 @@ -#ifndef _CONTROLLER_H_ -#define _CONTROLLER_H_ - -#include "libultra_internal.h" -//#include - -//should go somewhere else but -#define ARRLEN(x) ((s32)(sizeof(x) / sizeof(x[0]))) -#define CHNL_ERR(format) ((format.rxsize & 0xC0) >> 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; -} __OSContRequesFormat; - -typedef struct -{ - /* 0x0 */ u8 txsize; - /* 0x1 */ u8 rxsize; - /* 0x2 */ u8 cmd; - /* 0x3 */ u8 typeh; - /* 0x4 */ u8 typel; - /* 0x5 */ u8 status; -} __OSContRequesFormatShort; - -typedef struct -{ - /* 0x0 */ u8 dummy; - /* 0x1 */ u8 txsize; - /* 0x2 */ u8 rxsize; - /* 0x3 */ u8 cmd; - /* 0x4 */ u16 address; - /* 0x6 */ u8 data[32]; - /* 0x26 */ u8 datacrc; -} __OSContRamReadFormat; - - -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 - -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); -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, u16 *sum, u8 bank, __OSInodeUnit *last_page, int flag); -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); - -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/f3ddkr.h b/include/f3ddkr.h index 269aab5f..534b96ec 100644 --- a/include/f3ddkr.h +++ b/include/f3ddkr.h @@ -19,7 +19,8 @@ #define DKR_CC_UNK9 PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0 #define DKR_CC_UNK10 TEXEL0, 0, SCALE, 0, 0, 0, 0, TEXEL0 #define DKR_CC_UNK11 ENVIRONMENT, TEXEL0, ENV_ALPHA, TEXEL0, TEXEL0, 0, PRIMITIVE, 0 -#define DKR_CC_UNK12 0, 0, 0, ENVIRONMENT, 0, 0, 0, TEXEL0 +#define DKR_CC_UNK12 0, 0, 0, ENVIRONMENT, 0, 0, 0, TEXEL0 +#define DKR_CC_UNK13 ENVIRONMENT, TEXEL0, ENV_ALPHA, TEXEL0, TEXEL1, 0, PRIMITIVE, 0 #define DKR_CC_ENVIRONMENT 0, 0, 0, ENVIRONMENT, 0, 0, 0, ENVIRONMENT #define DKR_CC_DECALFADEPRIM 0, 0, 0, TEXEL0, TEXEL0, 0, PRIMITIVE, 0 @@ -38,6 +39,7 @@ #define DKR_OMH_1CYC_CI_BILERP DKR_OMH_COMMON | G_CYC_1CYCLE | G_TT_RGBA16 | G_TF_BILERP | G_TP_PERSP #define DKR_OMH_2CYC_BILERP DKR_OMH_COMMON | G_CYC_2CYCLE | G_TT_NONE | G_TF_BILERP | G_TP_PERSP #define DKR_OMH_2CYC_POINT DKR_OMH_COMMON | G_CYC_2CYCLE | G_TT_NONE | G_TF_POINT | G_TP_PERSP +#define DKR_OMH_2CYC_POINT_NOPERSP DKR_OMH_COMMON | G_CYC_2CYCLE | G_TT_NONE | G_TF_POINT | G_TP_NONE #define DKR_OMH_2CYC_CI_BILERP DKR_OMH_COMMON | G_CYC_2CYCLE | G_TT_RGBA16 | G_TF_BILERP | G_TP_PERSP #define DKR_OMH_COPY_POINT_NOPERSP G_DKR_BLENDMASK | G_PM_NPRIMITIVE | G_TD_CLAMP | G_TL_TILE | G_TC_FILT \ @@ -93,10 +95,10 @@ #define TRIN_DISABLE_TEXTURE 0 #define TRIN_ENABLE_TEXTURE 1 -#define gSPPolygon(dl, ptr, numTris, texEnabled) { \ - Gfx *_g = (Gfx *)(dl); \ - _g->words.w0 = _SHIFTL(((numTris - 1) << 4) | (texEnabled), 16, 8) | _SHIFTL(G_TRIN, 24, 8) | _SHIFTL((numTris*16), 0, 16); \ - _g->words.w1 = (unsigned int)(ptr); \ +#define gSPPolygon(dl, ptr, numTris, texEnabled) { \ + Gfx *_g = (Gfx *)(dl); \ + _g->words.w0 = _SHIFTL((((numTris) - 1) << 4) | (texEnabled), 16, 8) | _SHIFTL(G_TRIN, 24, 8) | _SHIFTL(((numTris)*16), 0, 16); \ + _g->words.w1 = (unsigned int)(ptr); \ } #define numberOfGfxCommands(gfxCmds) (sizeof(gfxCmds) / sizeof(Gwords)) diff --git a/include/fpregdef.h b/include/fpregdef.h new file mode 100644 index 00000000..e69de29b diff --git a/include/gcc/sgidefs.h b/include/gcc/sgidefs.h new file mode 100644 index 00000000..56567e88 --- /dev/null +++ b/include/gcc/sgidefs.h @@ -0,0 +1,44 @@ +/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ralf Baechle . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef _SGIDEFS_H +#define _SGIDEFS_H 1 + +/* + * Definitions for the ISA level + */ +#define _MIPS_ISA_MIPS1 1 +#define _MIPS_ISA_MIPS2 2 +#define _MIPS_ISA_MIPS3 3 +#define _MIPS_ISA_MIPS4 4 +#define _MIPS_ISA_MIPS5 5 + +/* + * Subprogram calling convention + * + * At the moment only _MIPS_SIM_ABI32 is in use. This will change rsn. + * Until GCC 2.8.0 is released don't rely on this definitions because the + * 64bit code is essentially using the 32bit interface model just with + * 64bit registers. + */ +#define _MIPS_SIM_ABI32 1 +#define _MIPS_SIM_NABI32 2 +#define _MIPS_SIM_ABI64 3 + +#endif /* sgidefs.h */ diff --git a/include/libc/stdlib.h b/include/libc/stdlib.h index c23b4542..98f8a2e1 100644 --- a/include/libc/stdlib.h +++ b/include/libc/stdlib.h @@ -1,19 +1,81 @@ -#ifndef STDLIB_H -#define STDLIB_H +#ifndef _STDLIB_H +#define _STDLIB_H +/* + stdlib.h +*/ +#ifndef _SIZE_T_DEF +#define _SIZE_T_DEF +typedef unsigned size_t; +#endif + +#ifndef _DIV_T_DEF +#define _DIV_T_DEF +typedef struct DIV_T { + int quot; + int rem; +} div_t; +#endif + +#ifndef _LDIV_T_DEF +#define _LDIV_T_DEF +typedef struct LDIV_T { + long quot; + long rem; +} ldiv_t; +#endif + +#ifndef _LLDIV_T_DEF +#define _LLDIV_T_DEF typedef struct lldiv_t { long long quot; long long rem; } lldiv_t; +#endif -typedef struct ldiv_t -{ - long quot; - long rem; -} ldiv_t; +#ifndef NULL +#define NULL 0 +#endif -lldiv_t lldiv(long long num, long long denom); -ldiv_t ldiv(long num, long denom); +#define _max(a,b) (((a) > (b)) ? (a) : (b)) +#define _min(a,b) (((a) < (b)) ? (a) : (b)) + +#define RAND_MAX 32767 + +int rand(void); +void srand(unsigned); + +int abs(int); +long labs(long); + +div_t div(int,int); +ldiv_t ldiv(long,long); +lldiv_t lldiv(long long, long long); + +int atoi(const char *); +long atol(const char *); + +long strtol(const char *,char **,int); +unsigned long strtoul(const char *,char **,int); + +char *itoa(int,char *,int); +char *ltoa(long,char *,int); +char *ultoa(unsigned long,char *,int); + +double atof(const char *); +double strtod(const char *,char **); + +void qsort(void *,size_t,size_t,int (*)(const void *,const void *)); +void *bsearch(const void *,const void *,size_t,size_t,int (*)(const void *,const void *)); + +void *malloc(size_t); +void *calloc(size_t,size_t); +void *realloc(void *,size_t); +void free(void *); + +void exit(int); + +void abort(void); #endif diff --git a/include/libc/string.h b/include/libc/string.h index 183409eb..1701cb98 100644 --- a/include/libc/string.h +++ b/include/libc/string.h @@ -5,6 +5,6 @@ void *memcpy(void *dst, const void *src, size_t size); size_t strlen(const char *str); -char *strchr(const char *str, s32 ch); +char *strchr(const char *str, int ch); #endif diff --git a/include/libultra_internal.h b/include/libultra_internal.h deleted file mode 100644 index df20d090..00000000 --- a/include/libultra_internal.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _LIBULTRA_INTERNAL_H_ -#define _LIBULTRA_INTERNAL_H_ - -#include - -#endif diff --git a/include/macro.inc b/include/macro.inc new file mode 100644 index 00000000..518a1c72 --- /dev/null +++ b/include/macro.inc @@ -0,0 +1,25 @@ +# common macros + +# Assembly Macros + +.set K0BASE, 0x80000000 +.set K1BASE, 0xA0000000 +.set K2BASE, 0xC0000000 + +.macro glabel label + .global \label + \label: +.endm + +.macro .word32 x + .word \x +.endm + +.macro BANK_INDEX bank, index + .half \bank + .half \index +.endm + +.macro move a, b + addu \a, \b, $zero +.endm diff --git a/include/macros.h b/include/macros.h index 815befcd..2d7a3f47 100644 --- a/include/macros.h +++ b/include/macros.h @@ -1,6 +1,8 @@ #ifndef _MACROS_H_ #define _MACROS_H_ +#include + #ifndef __sgi #define GLOBAL_ASM(...) #endif @@ -8,7 +10,7 @@ #if !defined(__sgi) && (!defined(NON_MATCHING) || !defined(AVOID_UB)) // asm-process isn't supported outside of IDO, and undefined behavior causes // crashes. -#error Matching build is only possible on IDO; please build with NON_MATCHING=1. +// #error Matching build is only possible on IDO; please build with NON_MATCHING=1. #endif #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) @@ -16,13 +18,6 @@ #define GLUE(a, b) a ## b #define GLUE2(a, b) GLUE(a, b) -// Avoid compiler warnings for unused variables -#ifdef __GNUC__ -#define UNUSED __attribute__((unused)) -#else -#define UNUSED -#endif - // Avoid undefined behaviour for non-returning functions #ifdef __GNUC__ #define NORETURN __attribute__((noreturn)) @@ -37,13 +32,6 @@ #define STATIC_ASSERT(cond, msg) typedef char GLUE2(static_assertion_failed, __LINE__)[(cond) ? 1 : -1] #endif - -#ifdef __GNUC__ -#define ALIGNED(x) __attribute__((aligned(x))) -#else -#define ALIGNED(x) -#endif - // Align to 8-byte boundary for DMA requirements #ifdef __GNUC__ #define ALIGNED8 __attribute__((aligned(8))) @@ -75,12 +63,4 @@ // Used to make a u32 colour value look clearer. Transforms 0xFF0000FF to 255, 0, 0, 255 #define COLOUR_RGBA32(r, g, b, a) (((r << 24) | (g << 16) | (b << 8) | a)) -#define ALIGN8(val) (((val) + 7) & ~7) - -#define STACK(stack, size) \ - u64 stack[ALIGN8(size) / sizeof(u64)] - -#define STACK_START(stack) \ - ((u8*)(stack) + sizeof(stack)) - #endif diff --git a/include/regdef.h b/include/regdef.h new file mode 100644 index 00000000..c29cc699 --- /dev/null +++ b/include/regdef.h @@ -0,0 +1,3 @@ +#include +#include +#include diff --git a/include/sched.h b/include/sched.h deleted file mode 100644 index f5534f0f..00000000 --- a/include/sched.h +++ /dev/null @@ -1,125 +0,0 @@ -#ifndef _SCHED_H_ -#define _SCHED_H_ - -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" - -#define OS_SC_RETRACE_MSG 1 -#define OS_SC_PRE_NMI_MSG 4 -#define OS_SC_AUDIO_MSG 5 -#define OS_SC_MAX_MESGS 8 - -#define OS_SC_ID_NONE 0 -#define OS_SC_ID_AUDIO 1 -#define OS_SC_ID_VIDEO 2 -#define OS_SC_ID_PRENMI 3 - -#define OSMESG_SWAP_BUFFER 0 -#define MESG_SKIP_BUFFER_SWAP 8 - -/* - * OSScTask state - */ -#define OS_SC_DP 0x0001 /* set if still needs dp */ -#define OS_SC_SP 0x0002 /* set if still needs sp */ -#define OS_SC_YIELD 0x0010 /* set if yield requested */ -#define OS_SC_YIELDED 0x0020 /* set if yield completed */ - -/* - * OSScTask->flags type identifier - */ -#define OS_SC_XBUS (OS_SC_SP | OS_SC_DP) -#define OS_SC_DRAM (OS_SC_SP | OS_SC_DP | OS_SC_DRAM_DLIST) -#define OS_SC_DP_XBUS (OS_SC_SP) -#define OS_SC_DP_DRAM (OS_SC_SP | OS_SC_DRAM_DLIST) -#define OS_SC_SP_XBUS (OS_SC_DP) -#define OS_SC_SP_DRAM (OS_SC_DP | OS_SC_DRAM_DLIST) -/* - * OSScTask flags: - */ -#define OS_SC_NEEDS_RDP 0x0001 /* uses the RDP */ -#define OS_SC_NEEDS_RSP 0x0002 /* uses the RSP */ -#define OS_SC_DRAM_DLIST 0x0004 /* SP & DP communicate through DRAM */ -#define OS_SC_PARALLEL_TASK 0x0010 /* must be first gfx task on list */ -#define OS_SC_LAST_TASK 0x0020 /* last task in queue for frame */ -#define OS_SC_SWAPBUFFER 0x0040 /* swapbuffers when gfx task done */ - -#define OS_SC_RCP_MASK 0x0003 /* mask for needs bits */ -#define OS_SC_TYPE_MASK 0x0007 /* complete type mask */ - -typedef struct { - short type; - char misc[30]; -} OSScMsg; - -typedef struct OSScTask_s { - struct OSScTask_s *next; /* note: this must be first */ - u32 state; - u32 flags; - void *framebuffer; /* used by graphics tasks */ - - OSTask list; - OSMesgQueue *msgQ; - OSMesg msg; - s32 unk58; - s32 unk5C; - s32 unk60; - s32 unk64; - s32 unk68; /* Added by Rare? */ - s32 unk6C; /* Task ID, used in debug functions in JFG */ -} OSScTask; - -typedef struct SCClient_s { - u8 id; /* Client ID, added by Rareware to single out individual scheduler clients*/ - struct SCClient_s *next; /* next client in the list */ - OSMesgQueue *msgQ; /* where to send the frame msg */ -} OSScClient; - -/* 0x288 bytes */ -typedef struct { - /* 0x00 */ OSScMsg retraceMsg; - /* 0x20 */ OSScMsg prenmiMsg; - /* 0x40 */ OSMesgQueue interruptQ; - /* 0x58 */ OSMesg intBuf[OS_SC_MAX_MESGS]; //0x8 per OSMesg - /* 0x78 */ OSMesgQueue cmdQ; - /* 0x90 */ OSMesg cmdMsgBuf[OS_SC_MAX_MESGS]; //0x8 per OSMesg - /* 0xB0 */ OSThread thread; - /* 0x260 */ OSScClient *clientList; - /* 0x264 */ OSScTask *audioListHead; - /* 0x268 */ OSScTask *gfxListHead; - /* 0x26C */ OSScTask *audioListTail; - /* 0x270 */ OSScTask *gfxListTail; - /* 0x274 */ OSScTask *curRSPTask; - /* 0x278 */ OSScTask *curRDPTask; - /* 0x27C */ OSScTask *unkTask; //Rare added? - /* 0x280 */ u32 frameCount; - /* 0x284 */ s32 doAudio; -} OSSched; - -typedef struct{ - u8 pad00[0x50]; -} unk800E3900; - -extern OSViMode osViModeTable[]; - -/*******************************/ - -void __scYield(OSSched *sc); -void __scExec(OSSched *sc, OSScTask *sp, OSScTask *dp); -void osCreateScheduler(OSSched *sc, void *stack, OSPri priority, u8 mode, u8 numFields); -void osScAddClient(OSSched *sc, OSScClient *c, OSMesgQueue *msgQ, u8 id); -void osScRemoveClient(OSSched *sc, OSScClient *c); -OSMesgQueue *osScGetCmdQ(OSSched *sc); -OSMesgQueue *osScGetInterruptQ(OSSched *sc); -void func_80079584(f32 *arg0, f32 *arg1, f32 *arg2); -void func_80079760(OSSched *sc); -void __scHandleRDP(OSSched *sc); -void __scHandleRSP(OSSched *sc); -OSScTask *__scTaskReady(OSScTask *t); -s32 __scTaskComplete(OSSched *sc, OSScTask *t); -void __scAppendList(OSSched *sc, OSScTask *t); -void __scExec(OSSched *sc, OSScTask *sp, OSScTask *dp); -void __scHandleRetrace(OSSched *sc); - -#endif diff --git a/include/sgidefs.h b/include/sgidefs.h new file mode 100644 index 00000000..8d4b6e14 --- /dev/null +++ b/include/sgidefs.h @@ -0,0 +1,3 @@ +#ifdef __GNUC__ +#include "gcc/sgidefs.h" +#endif diff --git a/include/sys/asm.h b/include/sys/asm.h index 445a2bf3..60e6ccd2 100644 --- a/include/sys/asm.h +++ b/include/sys/asm.h @@ -1,7 +1,7 @@ /************************************************************************ Copyright (C) 1998,1999 NINTENDO Co,Ltd, Copyright (C) 1998,1999 MONEGI CORPORATION, - All Rights Reserved + All Rights Reserved This program is a trade secret of NINTENDO Co,Ltd and MONEGI Corp. and it is not to be reproduced, published, disclosed to others, copied, adapted, distributed, or displayed without the prior authorization of @@ -22,48 +22,97 @@ modified versions thereof. extern "C" { #endif -#define _MIPS_ISA_MIPS1 1 /* R2/3K */ -#define _MIPS_ISA_MIPS2 2 /* R4K/6K */ -#define _MIPS_ISA_MIPS3 3 /* R4K */ -#define _MIPS_ISA_MIPS4 4 /* TFP */ +#define _MIPS_ISA_MIPS1 1 /* R2/3K */ +#define _MIPS_ISA_MIPS2 2 /* R4K/6K */ +#define _MIPS_ISA_MIPS3 3 /* R4K */ +#define _MIPS_ISA_MIPS4 4 /* TFP */ -#define _MIPS_SIM_ABI32 1 /* MIPS MSIG calling convention */ -#define _MIPS_SIM_NABI32 2 /* MIPS new 32-bit abi */ - /* NABI32 is 64bit calling convention but 32bit type sizes) */ -#define _MIPS_SIM_ABI64 3 /* MIPS 64 calling convention */ +#define _MIPS_SIM_ABI32 1 /* MIPS MSIG calling convention */ +#define _MIPS_SIM_NABI32 2 /* MIPS new 32-bit abi */ + /* NABI32 is 64bit calling convention but 32bit type sizes) */ +#define _MIPS_SIM_ABI64 3 /* MIPS 64 calling convention */ -#define LEAF(x) \ - .globl x; \ - .ent x,0; \ -x:; \ - .frame sp,0,ra -#define XLEAF(x) \ - .global x; +/* libgultra doesn't match with the .type directive but iQue sdk asm.h uses it */ +#ifdef BBPLAYER +#define ASM_TYPE_FUNC(x) .type x, @function +#else +#define ASM_TYPE_FUNC(x) +#endif -#define END(proc) \ - .end proc +#define LEAF(x) \ + .globl x ;\ + .align 2 ;\ + ASM_TYPE_FUNC(x) ;\ + .ent x,0 ;\ + x: ;\ + .frame sp,0,ra -#define ABS(x, y) \ - .globl x; \ - x = y - -#define EXPORT(x) \ - .globl x; \ -x: -/* -#define WEAK(x, y) \ - .weak x; \ - .set x,y; -*/ +#if defined(BBPLAYER) || defined(__sgi) +#define XLEAF(x) \ + .globl x ;\ + .aent x,0 ;\ + x: +#else +#define XLEAF(x) \ + .globl x +#endif +#ifdef BBPLAYER +#define END(proc) \ + .end proc ;\ + .size proc, . - proc +#else +#define END(proc) \ + .end proc +#endif + +#define ABS(x, y) \ + .globl x ;\ + x = y + +#define EXPORT(x) \ + .globl x ;\ + x: + +#if defined(BBPLAYER) || defined(__sgi) +#define WEAK(x, y) \ + .weakext x, y +#else #define WEAK(x, y) +#endif + + +#define NOP \ + .set noreorder ;\ + nop ;\ + .set reorder + +#define CACHE(op, reg) \ + .set noreorder ;\ + cache op, reg ;\ + .set reorder + +#define MFC0(reg, op) \ + .set noreorder ;\ + mfc0 reg, op ;\ + .set reorder + +#define MTC0(reg, op) \ + .set noreorder ;\ + mtc0 reg, op ;\ + .set reorder + +#define CFC1(reg, op) \ + .set noreorder ;\ + cfc1 reg, op ;\ + .set reorder + +#define CTC1(reg, op) \ + .set noreorder ;\ + ctc1 reg, op ;\ + .set reorder -#define STAY1(stmnt) .set noreorder; stmnt; .set reorder; -#define STAY2(stmnt, arg1) .set noreorder; stmnt, arg1; .set reorder; -#define STAY3(stmnt, arg1, arg2) .set noreorder; stmnt, arg1, arg2; .set reorder; -#define NOP .set noreorder; nop; .set reorder; -#define CACHE(op, reg) .set noreorder; cache op, reg; .set reorder; #ifdef __cplusplus } diff --git a/include/sys/fpregdef.h b/include/sys/fpregdef.h new file mode 100644 index 00000000..e69de29b diff --git a/include/types.h b/include/types.h index c3674fb3..7c37fd8c 100644 --- a/include/types.h +++ b/include/types.h @@ -1,48 +1,13 @@ #ifndef _TYPES_H_ #define _TYPES_H_ -#ifndef NULL -#define NULL 0 -#endif - -#define TRUE 1 -#define FALSE 0 - -typedef signed char s8; -typedef unsigned char u8; -typedef signed short int s16; -typedef unsigned short int u16; -typedef signed int s32; -typedef unsigned int u32; -typedef signed long long int s64; -typedef unsigned long long int u64; - -typedef volatile u8 vu8; -typedef volatile u16 vu16; -typedef volatile u32 vu32; -typedef volatile u64 vu64; -typedef volatile s8 vs8; -typedef volatile s16 vs16; -typedef volatile s32 vs32; -typedef volatile s64 vs64; - -typedef float f32; -typedef double f64; - -//#ifdef TARGET_N64 -typedef u32 size_t; -typedef s32 ssize_t; -typedef u32 uintptr_t; -typedef s32 intptr_t; -typedef s32 ptrdiff_t; -//#else -//#include -//#endif +#include typedef float Matrix[4][4]; typedef s32 MatrixS[4][4]; typedef s16 VertexList; typedef u8 TriangleList; +typedef u32 uintptr_t; #if defined(__sgi) #define stubbed_printf diff --git a/include/ultra64.h b/include/ultra64.h index e6e3b468..1cfb9bf8 100644 --- a/include/ultra64.h +++ b/include/ultra64.h @@ -1,36 +1,43 @@ + +/************************************************************************** + * * + * 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. * + * * + *************************************************************************/ + +/************************************************************************** + * + * $Revision: 1.10 $ + * $Date: 1997/02/11 08:37:33 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/ultra64.h,v $ + * + **************************************************************************/ + #ifndef _ULTRA64_H_ #define _ULTRA64_H_ -//#include - -#ifndef _LANGUAGE_C -#define _LANGUAGE_C -#endif - #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 +#include +#include +#include +#include +#include +#if 0 +/* This file fails in DKR because of the same named sprite structs. */ +#include +#endif +#include +#include +#include #endif diff --git a/include/ultrahost.h b/include/ultrahost.h new file mode 100644 index 00000000..2c50b95d --- /dev/null +++ b/include/ultrahost.h @@ -0,0 +1,59 @@ +/************************************************************************** + * + * $Revision: 1.1 $ + * $Date: 1999/07/05 02:16:07 $ + * + **************************************************************************/ + +#ifndef _ULTRAHOST_H_ +#define _ULTRAHOST_H_ + +#ifdef WIN32 /* { */ + +int __stdcall uhOpenGame(char *); +int __stdcall uhCloseGame(int); +int __stdcall uhReadGame(int hfd,void *buf,int count); +int __stdcall uhWriteGame(int hfd,void *buf,int count); +int __stdcall uhReadRamrom(int hfd,void *ramrom_adr,void *buf,int count); +int __stdcall uhWriteRamrom(int hfd,void *ramrom_adr,void *buf,int count); +int __stdcall uhPartnerInit(int hfd); +int __stdcall uhPartnerCmd(int hfd,char *ptcmd); +int __stdcall uhGload(int hfd,char *loadfile); + +#else /* }{ */ +#ifdef PTN64 /* { */ + +#define execl execl_pt + +#define uhOpenGame uhOpenGame_pt +#define uhCloseGame uhCloseGame_pt + +#define uhReadGame uhReadGame_pt +#define uhWriteGame uhWriteGame_pt +#define uhReadRamrom uhReadRamrom_pt +#define uhWriteRamrom uhWriteRamrom_pt +#define uhPartnerCmd uhPartnerCmd_pt +#define uhGload uhGload_pt + +int uhPartnerCmd(int,char *); +int uhGload(int,char *); + +#endif /* } */ + +#ifdef __cplusplus +extern "C" { +#endif +int uhOpenGame(const char *); +int uhCloseGame(int); + +int uhReadGame(int, void *, int); +int uhWriteGame(int, void *, int); +int uhWriteRamrom(int, void *, void*, int); +int uhReadRamrom(int, void *, void*, int); + +#ifdef __cplusplus +} +#endif +#endif /* } */ + +#endif /* ULTRAHOST */ diff --git a/lib/asm/__osDisableInt.s b/lib/asm/__osDisableInt.s deleted file mode 100644 index c3968a85..00000000 --- a/lib/asm/__osDisableInt.s +++ /dev/null @@ -1,18 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D2560 */ - -.include "macros.inc" - -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used - -glabel __osDisableInt -/* 0D3160 800D2560 40086000 */ mfc0 $t0, $12 -/* 0D3164 800D2564 2401FFFE */ li $at, -2 -/* 0D3168 800D2568 01014824 */ and $t1, $t0, $at -/* 0D316C 800D256C 40896000 */ mtc0 $t1, $12 -/* 0D3170 800D2570 31020001 */ andi $v0, $t0, 1 -/* 0D3174 800D2574 00000000 */ nop -/* 0D3178 800D2578 03E00008 */ jr $ra -/* 0D317C 800D257C 00000000 */ nop diff --git a/lib/asm/__osGetSR.s b/lib/asm/__osGetSR.s deleted file mode 100644 index 0523c887..00000000 --- a/lib/asm/__osGetSR.s +++ /dev/null @@ -1,15 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D4570 */ - -.include "macros.inc" - -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used - -glabel __osGetSR -/* 0D5170 800D4570 40026000 */ mfc0 $v0, $12 -/* 0D5174 800D4574 03E00008 */ jr $ra -/* 0D5178 800D4578 00000000 */ nop - -/* 0D517C 800D457C 00000000 */ nop diff --git a/lib/asm/__osProbeTLB.s b/lib/asm/__osProbeTLB.s deleted file mode 100644 index a461a278..00000000 --- a/lib/asm/__osProbeTLB.s +++ /dev/null @@ -1,63 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D35B0 */ - -.include "macros.inc" - -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used - -glabel __osProbeTLB -/* 0D41B0 800D35B0 40085000 */ mfc0 $t0, $10 -/* 0D41B4 800D35B4 310900FF */ andi $t1, $t0, 0xff -/* 0D41B8 800D35B8 2401E000 */ li $at, -8192 -/* 0D41BC 800D35BC 00815024 */ and $t2, $a0, $at -/* 0D41C0 800D35C0 012A4825 */ or $t1, $t1, $t2 -/* 0D41C4 800D35C4 40895000 */ mtc0 $t1, $10 -/* 0D41C8 800D35C8 00000000 */ nop -/* 0D41CC 800D35CC 00000000 */ nop -/* 0D41D0 800D35D0 00000000 */ nop -/* 0D41D4 800D35D4 42000008 */ tlbp -/* 0D41D8 800D35D8 00000000 */ nop -/* 0D41DC 800D35DC 00000000 */ nop -/* 0D41E0 800D35E0 400B0000 */ mfc0 $t3, $0 -/* 0D41E4 800D35E4 3C018000 */ lui $at, 0x8000 -/* 0D41E8 800D35E8 01615824 */ and $t3, $t3, $at -/* 0D41EC 800D35EC 1560001A */ bnez $t3, .L800D3658 -/* 0D41F0 800D35F0 00000000 */ nop -/* 0D41F4 800D35F4 42000001 */ tlbr -/* 0D41F8 800D35F8 00000000 */ nop -/* 0D41FC 800D35FC 00000000 */ nop -/* 0D4200 800D3600 00000000 */ nop -/* 0D4204 800D3604 400B2800 */ mfc0 $t3, $5 -/* 0D4208 800D3608 216B2000 */ addi $t3, $t3, 0x2000 -/* 0D420C 800D360C 000B5842 */ srl $t3, $t3, 1 -/* 0D4210 800D3610 01646024 */ and $t4, $t3, $a0 -/* 0D4214 800D3614 15800004 */ bnez $t4, .L800D3628 -/* 0D4218 800D3618 216BFFFF */ addi $t3, $t3, -1 -/* 0D421C 800D361C 40021000 */ mfc0 $v0, $2 -/* 0D4220 800D3620 10000002 */ b .L800D362C -/* 0D4224 800D3624 00000000 */ nop -.L800D3628: -/* 0D4228 800D3628 40021800 */ mfc0 $v0, $3 -.L800D362C: -/* 0D422C 800D362C 304D0002 */ andi $t5, $v0, 2 -/* 0D4230 800D3630 11A00009 */ beqz $t5, .L800D3658 -/* 0D4234 800D3634 00000000 */ nop -/* 0D4238 800D3638 3C013FFF */ lui $at, (0x3FFFFFC0 >> 16) # lui $at, 0x3fff -/* 0D423C 800D363C 3421FFC0 */ ori $at, (0x3FFFFFC0 & 0xFFFF) # ori $at, $at, 0xffc0 -/* 0D4240 800D3640 00411024 */ and $v0, $v0, $at -/* 0D4244 800D3644 00021180 */ sll $v0, $v0, 6 -/* 0D4248 800D3648 008B6824 */ and $t5, $a0, $t3 -/* 0D424C 800D364C 004D1020 */ add $v0, $v0, $t5 -/* 0D4250 800D3650 10000002 */ b .L800D365C -/* 0D4254 800D3654 00000000 */ nop -.L800D3658: -/* 0D4258 800D3658 2402FFFF */ li $v0, -1 -.L800D365C: -/* 0D425C 800D365C 40885000 */ mtc0 $t0, $10 -/* 0D4260 800D3660 03E00008 */ jr $ra -/* 0D4264 800D3664 00000000 */ nop - -/* 0D4268 800D3668 00000000 */ nop -/* 0D426C 800D366C 00000000 */ nop diff --git a/lib/asm/__osRestoreInt.s b/lib/asm/__osRestoreInt.s deleted file mode 100644 index fad510d1..00000000 --- a/lib/asm/__osRestoreInt.s +++ /dev/null @@ -1,19 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D2580 */ - -.include "macros.inc" - -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used - -glabel __osRestoreInt -/* 0D3180 800D2580 40086000 */ mfc0 $t0, $12 -/* 0D3184 800D2584 01044025 */ or $t0, $t0, $a0 -/* 0D3188 800D2588 40886000 */ mtc0 $t0, $12 -/* 0D318C 800D258C 00000000 */ nop -/* 0D3190 800D2590 00000000 */ nop -/* 0D3194 800D2594 03E00008 */ jr $ra -/* 0D3198 800D2598 00000000 */ nop - -/* 0D319C 800D259C 00000000 */ nop diff --git a/lib/asm/__osSetCompare.s b/lib/asm/__osSetCompare.s deleted file mode 100644 index 96733d3a..00000000 --- a/lib/asm/__osSetCompare.s +++ /dev/null @@ -1,15 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D7460 */ - -.include "macros.inc" - -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used - -glabel __osSetCompare -/* 0D8060 800D7460 40845800 */ mtc0 $a0, $11 -/* 0D8064 800D7464 03E00008 */ jr $ra -/* 0D8068 800D7468 00000000 */ nop - -/* 0D806C 800D746C 00000000 */ nop diff --git a/lib/asm/__osSetFpcCsr.s b/lib/asm/__osSetFpcCsr.s deleted file mode 100644 index 5e6b0d44..00000000 --- a/lib/asm/__osSetFpcCsr.s +++ /dev/null @@ -1,14 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D4580 */ - -.include "macros.inc" - -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used - -glabel __osSetFpcCsr -/* 0D5180 800D4580 4442F800 */ cfc1 $v0, $31 -/* 0D5184 800D4584 44C4F800 */ ctc1 $a0, $31 -/* 0D5188 800D4588 03E00008 */ jr $ra -/* 0D518C 800D458C 00000000 */ nop diff --git a/lib/asm/__osSetSR.s b/lib/asm/__osSetSR.s deleted file mode 100644 index 86e40a66..00000000 --- a/lib/asm/__osSetSR.s +++ /dev/null @@ -1,15 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D4560 */ - -.include "macros.inc" - -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used - -glabel __osSetSR -/* 0D5160 800D4560 40846000 */ mtc0 $a0, $12 -/* 0D5164 800D4564 00000000 */ nop -/* 0D5168 800D4568 03E00008 */ jr $ra -/* 0D516C 800D456C 00000000 */ nop - diff --git a/lib/asm/bcmp.s b/lib/asm/bcmp.s index 5fa610a5..31c52316 100644 --- a/lib/asm/bcmp.s +++ b/lib/asm/bcmp.s @@ -1,95 +1,97 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CE050 */ -.include "macros.inc" +.include "macro.inc" -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ glabel bcmp /* Official name: _bcmp */ -/* 0CEC50 800CE050 28C10010 */ slti $at, $a2, 0x10 -/* 0CEC54 800CE054 14200037 */ bnez $at, .L800CE134 -/* 0CEC58 800CE058 00851026 */ xor $v0, $a0, $a1 -/* 0CEC5C 800CE05C 30420003 */ andi $v0, $v0, 3 -/* 0CEC60 800CE060 14400019 */ bnez $v0, .L800CE0C8 -/* 0CEC64 800CE064 0004C023 */ negu $t8, $a0 -/* 0CEC68 800CE068 33180003 */ andi $t8, $t8, 3 -/* 0CEC6C 800CE06C 13000007 */ beqz $t8, .L800CE08C -/* 0CEC70 800CE070 00D83023 */ subu $a2, $a2, $t8 -/* 0CEC74 800CE074 00601025 */ move $v0, $v1 -/* 0CEC78 800CE078 88820000 */ lwl $v0, ($a0) -/* 0CEC7C 800CE07C 88A30000 */ lwl $v1, ($a1) -/* 0CEC80 800CE080 00982021 */ addu $a0, $a0, $t8 -/* 0CEC84 800CE084 00B82821 */ addu $a1, $a1, $t8 -/* 0CEC88 800CE088 14430036 */ bne $v0, $v1, .L800CE164 +/* CEC50 800CE050 28C10010 */ slti $at, $a2, 0x10 +/* CEC54 800CE054 14200037 */ bnez $at, .L800CE134 +/* CEC58 800CE058 00851026 */ xor $v0, $a0, $a1 +/* CEC5C 800CE05C 30420003 */ andi $v0, $v0, 0x3 +/* CEC60 800CE060 14400019 */ bnez $v0, .L800CE0C8 +/* CEC64 800CE064 0004C023 */ negu $t8, $a0 +/* CEC68 800CE068 33180003 */ andi $t8, $t8, 0x3 +/* CEC6C 800CE06C 13000007 */ beqz $t8, .L800CE08C +/* CEC70 800CE070 00D83023 */ subu $a2, $a2, $t8 +/* CEC74 800CE074 00601025 */ or $v0, $v1, $zero +/* CEC78 800CE078 88820000 */ lwl $v0, 0x0($a0) +/* CEC7C 800CE07C 88A30000 */ lwl $v1, 0x0($a1) +/* CEC80 800CE080 00982021 */ addu $a0, $a0, $t8 +/* CEC84 800CE084 00B82821 */ addu $a1, $a1, $t8 +/* CEC88 800CE088 14430036 */ bne $v0, $v1, .L800CE164 .L800CE08C: -/* 0CEC8C 800CE08C 2401FFFC */ li $at, -4 -/* 0CEC90 800CE090 00C13824 */ and $a3, $a2, $at -/* 0CEC94 800CE094 10E00027 */ beqz $a3, .L800CE134 -/* 0CEC98 800CE098 00C73023 */ subu $a2, $a2, $a3 -/* 0CEC9C 800CE09C 00E43821 */ addu $a3, $a3, $a0 -/* 0CECA0 800CE0A0 8C820000 */ lw $v0, ($a0) +/* CEC8C 800CE08C 2401FFFC */ addiu $at, $zero, -0x4 +/* CEC90 800CE090 00C13824 */ and $a3, $a2, $at +/* CEC94 800CE094 10E00027 */ beqz $a3, .L800CE134 +/* CEC98 800CE098 00C73023 */ subu $a2, $a2, $a3 +/* CEC9C 800CE09C 00E43821 */ addu $a3, $a3, $a0 +/* CECA0 800CE0A0 8C820000 */ lw $v0, 0x0($a0) .L800CE0A4: -/* 0CECA4 800CE0A4 8CA30000 */ lw $v1, ($a1) -/* 0CECA8 800CE0A8 24840004 */ addiu $a0, $a0, 4 -/* 0CECAC 800CE0AC 24A50004 */ addiu $a1, $a1, 4 -/* 0CECB0 800CE0B0 1443002C */ bne $v0, $v1, .L800CE164 -/* 0CECB4 800CE0B4 00000000 */ nop -/* 0CECB8 800CE0B8 5487FFFA */ bnel $a0, $a3, .L800CE0A4 -/* 0CECBC 800CE0BC 8C820000 */ lw $v0, ($a0) -/* 0CECC0 800CE0C0 1000001C */ b .L800CE134 -/* 0CECC4 800CE0C4 00000000 */ nop +/* CECA4 800CE0A4 8CA30000 */ lw $v1, 0x0($a1) +/* CECA8 800CE0A8 24840004 */ addiu $a0, $a0, 0x4 +/* CECAC 800CE0AC 24A50004 */ addiu $a1, $a1, 0x4 +/* CECB0 800CE0B0 1443002C */ bne $v0, $v1, .L800CE164 +/* CECB4 800CE0B4 00000000 */ nop +/* CECB8 800CE0B8 5487FFFA */ bnel $a0, $a3, .L800CE0A4 +/* CECBC 800CE0BC 8C820000 */ lw $v0, 0x0($a0) +/* CECC0 800CE0C0 1000001C */ b .L800CE134 +/* CECC4 800CE0C4 00000000 */ nop .L800CE0C8: -/* 0CECC8 800CE0C8 00053823 */ negu $a3, $a1 -/* 0CECCC 800CE0CC 30E70003 */ andi $a3, $a3, 3 -/* 0CECD0 800CE0D0 10E0000A */ beqz $a3, .L800CE0FC -/* 0CECD4 800CE0D4 00C73023 */ subu $a2, $a2, $a3 -/* 0CECD8 800CE0D8 00E43821 */ addu $a3, $a3, $a0 -/* 0CECDC 800CE0DC 90820000 */ lbu $v0, ($a0) +/* CECC8 800CE0C8 00053823 */ negu $a3, $a1 +/* CECCC 800CE0CC 30E70003 */ andi $a3, $a3, 0x3 +/* CECD0 800CE0D0 10E0000A */ beqz $a3, .L800CE0FC +/* CECD4 800CE0D4 00C73023 */ subu $a2, $a2, $a3 +/* CECD8 800CE0D8 00E43821 */ addu $a3, $a3, $a0 +/* CECDC 800CE0DC 90820000 */ lbu $v0, 0x0($a0) .L800CE0E0: -/* 0CECE0 800CE0E0 90A30000 */ lbu $v1, ($a1) -/* 0CECE4 800CE0E4 24840001 */ addiu $a0, $a0, 1 -/* 0CECE8 800CE0E8 24A50001 */ addiu $a1, $a1, 1 -/* 0CECEC 800CE0EC 1443001D */ bne $v0, $v1, .L800CE164 -/* 0CECF0 800CE0F0 00000000 */ nop -/* 0CECF4 800CE0F4 5487FFFA */ bnel $a0, $a3, .L800CE0E0 -/* 0CECF8 800CE0F8 90820000 */ lbu $v0, ($a0) +/* CECE0 800CE0E0 90A30000 */ lbu $v1, 0x0($a1) +/* CECE4 800CE0E4 24840001 */ addiu $a0, $a0, 0x1 +/* CECE8 800CE0E8 24A50001 */ addiu $a1, $a1, 0x1 +/* CECEC 800CE0EC 1443001D */ bne $v0, $v1, .L800CE164 +/* CECF0 800CE0F0 00000000 */ nop +/* CECF4 800CE0F4 5487FFFA */ bnel $a0, $a3, .L800CE0E0 +/* CECF8 800CE0F8 90820000 */ lbu $v0, 0x0($a0) .L800CE0FC: -/* 0CECFC 800CE0FC 2401FFFC */ li $at, -4 -/* 0CED00 800CE100 00C13824 */ and $a3, $a2, $at -/* 0CED04 800CE104 10E0000B */ beqz $a3, .L800CE134 -/* 0CED08 800CE108 00C73023 */ subu $a2, $a2, $a3 -/* 0CED0C 800CE10C 00E43821 */ addu $a3, $a3, $a0 -/* 0CED10 800CE110 88820000 */ lwl $v0, ($a0) +/* CECFC 800CE0FC 2401FFFC */ addiu $at, $zero, -0x4 +/* CED00 800CE100 00C13824 */ and $a3, $a2, $at +/* CED04 800CE104 10E0000B */ beqz $a3, .L800CE134 +/* CED08 800CE108 00C73023 */ subu $a2, $a2, $a3 +/* CED0C 800CE10C 00E43821 */ addu $a3, $a3, $a0 +/* CED10 800CE110 88820000 */ lwl $v0, 0x0($a0) .L800CE114: -/* 0CED14 800CE114 8CA30000 */ lw $v1, ($a1) -/* 0CED18 800CE118 98820003 */ lwr $v0, 3($a0) -/* 0CED1C 800CE11C 24840004 */ addiu $a0, $a0, 4 -/* 0CED20 800CE120 24A50004 */ addiu $a1, $a1, 4 -/* 0CED24 800CE124 1443000F */ bne $v0, $v1, .L800CE164 -/* 0CED28 800CE128 00000000 */ nop -/* 0CED2C 800CE12C 5487FFF9 */ bnel $a0, $a3, .L800CE114 -/* 0CED30 800CE130 88820000 */ lwl $v0, ($a0) +/* CED14 800CE114 8CA30000 */ lw $v1, 0x0($a1) +/* CED18 800CE118 98820003 */ lwr $v0, 0x3($a0) +/* CED1C 800CE11C 24840004 */ addiu $a0, $a0, 0x4 +/* CED20 800CE120 24A50004 */ addiu $a1, $a1, 0x4 +/* CED24 800CE124 1443000F */ bne $v0, $v1, .L800CE164 +/* CED28 800CE128 00000000 */ nop +/* CED2C 800CE12C 5487FFF9 */ bnel $a0, $a3, .L800CE114 +/* CED30 800CE130 88820000 */ lwl $v0, 0x0($a0) .L800CE134: -/* 0CED34 800CE134 18C00009 */ blez $a2, .L800CE15C -/* 0CED38 800CE138 00C43821 */ addu $a3, $a2, $a0 -/* 0CED3C 800CE13C 90820000 */ lbu $v0, ($a0) +/* CED34 800CE134 18C00009 */ blez $a2, .L800CE15C +/* CED38 800CE138 00C43821 */ addu $a3, $a2, $a0 +/* CED3C 800CE13C 90820000 */ lbu $v0, 0x0($a0) .L800CE140: -/* 0CED40 800CE140 90A30000 */ lbu $v1, ($a1) -/* 0CED44 800CE144 24840001 */ addiu $a0, $a0, 1 -/* 0CED48 800CE148 24A50001 */ addiu $a1, $a1, 1 -/* 0CED4C 800CE14C 14430005 */ bne $v0, $v1, .L800CE164 -/* 0CED50 800CE150 00000000 */ nop -/* 0CED54 800CE154 5487FFFA */ bnel $a0, $a3, .L800CE140 -/* 0CED58 800CE158 90820000 */ lbu $v0, ($a0) +/* CED40 800CE140 90A30000 */ lbu $v1, 0x0($a1) +/* CED44 800CE144 24840001 */ addiu $a0, $a0, 0x1 +/* CED48 800CE148 24A50001 */ addiu $a1, $a1, 0x1 +/* CED4C 800CE14C 14430005 */ bne $v0, $v1, .L800CE164 +/* CED50 800CE150 00000000 */ nop +/* CED54 800CE154 5487FFFA */ bnel $a0, $a3, .L800CE140 +/* CED58 800CE158 90820000 */ lbu $v0, 0x0($a0) .L800CE15C: -/* 0CED5C 800CE15C 03E00008 */ jr $ra -/* 0CED60 800CE160 00001025 */ move $v0, $zero - +/* CED5C 800CE15C 03E00008 */ jr $ra +/* CED60 800CE160 00001025 */ or $v0, $zero, $zero .L800CE164: -/* 0CED64 800CE164 03E00008 */ jr $ra -/* 0CED68 800CE168 24020001 */ li $v0, 1 - -/* 0CED6C 800CE16C 00000000 */ nop - +/* CED64 800CE164 03E00008 */ jr $ra +/* CED68 800CE168 24020001 */ addiu $v0, $zero, 0x1 +/* CED6C 800CE16C 00000000 */ nop diff --git a/lib/asm/bcopy.s b/lib/asm/bcopy.s index 9eec765e..bcb12b0e 100644 --- a/lib/asm/bcopy.s +++ b/lib/asm/bcopy.s @@ -1,231 +1,235 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C9DA0 */ -.include "macros.inc" +.include "macro.inc" -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ + +/* Handwritten function */ glabel bcopy /* Official name: _bcopy */ -/* 0CA9A0 800C9DA0 10C0001A */ beqz $a2, .L800C9E0C -/* 0CA9A4 800C9DA4 00A03825 */ move $a3, $a1 -/* 0CA9A8 800C9DA8 10850018 */ beq $a0, $a1, .L800C9E0C -/* 0CA9AC 800C9DAC 00A4082A */ slt $at, $a1, $a0 -/* 0CA9B0 800C9DB0 54200008 */ bnezl $at, .L800C9DD4 -/* 0CA9B4 800C9DB4 28C10010 */ slti $at, $a2, 0x10 -/* 0CA9B8 800C9DB8 00861020 */ add $v0, $a0, $a2 -/* 0CA9BC 800C9DBC 00A2082A */ slt $at, $a1, $v0 -/* 0CA9C0 800C9DC0 50200004 */ beql $at, $zero, .L800C9DD4 -/* 0CA9C4 800C9DC4 28C10010 */ slti $at, $a2, 0x10 -/* 0CA9C8 800C9DC8 1000005B */ b .L800C9F38 -/* 0CA9CC 800C9DCC 28C10010 */ slti $at, $a2, 0x10 -/* 0CA9D0 800C9DD0 28C10010 */ slti $at, $a2, 0x10 +/* CA9A0 800C9DA0 10C0001A */ beqz $a2, .L800C9E0C +/* CA9A4 800C9DA4 00A03825 */ or $a3, $a1, $zero +/* CA9A8 800C9DA8 10850018 */ beq $a0, $a1, .L800C9E0C +/* CA9AC 800C9DAC 00A4082A */ slt $at, $a1, $a0 +/* CA9B0 800C9DB0 54200008 */ bnel $at, $zero, .L800C9DD4 +/* CA9B4 800C9DB4 28C10010 */ slti $at, $a2, 0x10 +/* CA9B8 800C9DB8 00861020 */ add $v0, $a0, $a2 /* handwritten instruction */ +/* CA9BC 800C9DBC 00A2082A */ slt $at, $a1, $v0 +/* CA9C0 800C9DC0 50200004 */ beql $at, $zero, .L800C9DD4 +/* CA9C4 800C9DC4 28C10010 */ slti $at, $a2, 0x10 +/* CA9C8 800C9DC8 1000005B */ b .L800C9F38 +/* CA9CC 800C9DCC 28C10010 */ slti $at, $a2, 0x10 +/* CA9D0 800C9DD0 28C10010 */ slti $at, $a2, 0x10 .L800C9DD4: -/* 0CA9D4 800C9DD4 14200005 */ bnez $at, .L800C9DEC -/* 0CA9D8 800C9DD8 00000000 */ nop -/* 0CA9DC 800C9DDC 30820003 */ andi $v0, $a0, 3 -/* 0CA9E0 800C9DE0 30A30003 */ andi $v1, $a1, 3 -/* 0CA9E4 800C9DE4 1043000B */ beq $v0, $v1, .L800C9E14 -/* 0CA9E8 800C9DE8 00000000 */ nop +/* CA9D4 800C9DD4 14200005 */ bnez $at, .L800C9DEC +/* CA9D8 800C9DD8 00000000 */ nop +/* CA9DC 800C9DDC 30820003 */ andi $v0, $a0, 0x3 +/* CA9E0 800C9DE0 30A30003 */ andi $v1, $a1, 0x3 +/* CA9E4 800C9DE4 1043000B */ beq $v0, $v1, .L800C9E14 +/* CA9E8 800C9DE8 00000000 */ nop .L800C9DEC: -/* 0CA9EC 800C9DEC 10C00007 */ beqz $a2, .L800C9E0C -/* 0CA9F0 800C9DF0 00000000 */ nop -/* 0CA9F4 800C9DF4 00861821 */ addu $v1, $a0, $a2 +/* CA9EC 800C9DEC 10C00007 */ beqz $a2, .L800C9E0C +/* CA9F0 800C9DF0 00000000 */ nop +/* CA9F4 800C9DF4 00861821 */ addu $v1, $a0, $a2 .L800C9DF8: -/* 0CA9F8 800C9DF8 80820000 */ lb $v0, ($a0) -/* 0CA9FC 800C9DFC 24840001 */ addiu $a0, $a0, 1 -/* 0CAA00 800C9E00 24A50001 */ addiu $a1, $a1, 1 -/* 0CAA04 800C9E04 1483FFFC */ bne $a0, $v1, .L800C9DF8 -/* 0CAA08 800C9E08 A0A2FFFF */ sb $v0, -1($a1) +/* CA9F8 800C9DF8 80820000 */ lb $v0, 0x0($a0) +/* CA9FC 800C9DFC 24840001 */ addiu $a0, $a0, 0x1 +/* CAA00 800C9E00 24A50001 */ addiu $a1, $a1, 0x1 +/* CAA04 800C9E04 1483FFFC */ bne $a0, $v1, .L800C9DF8 +/* CAA08 800C9E08 A0A2FFFF */ sb $v0, -0x1($a1) .L800C9E0C: -/* 0CAA0C 800C9E0C 03E00008 */ jr $ra -/* 0CAA10 800C9E10 00E01025 */ move $v0, $a3 - +/* CAA0C 800C9E0C 03E00008 */ jr $ra +/* CAA10 800C9E10 00E01025 */ or $v0, $a3, $zero .L800C9E14: -/* 0CAA14 800C9E14 10400018 */ beqz $v0, .L800C9E78 -/* 0CAA18 800C9E18 24010001 */ li $at, 1 -/* 0CAA1C 800C9E1C 1041000F */ beq $v0, $at, .L800C9E5C -/* 0CAA20 800C9E20 24010002 */ li $at, 2 -/* 0CAA24 800C9E24 50410008 */ beql $v0, $at, .L800C9E48 -/* 0CAA28 800C9E28 84820000 */ lh $v0, ($a0) -/* 0CAA2C 800C9E2C 80820000 */ lb $v0, ($a0) -/* 0CAA30 800C9E30 24840001 */ addiu $a0, $a0, 1 -/* 0CAA34 800C9E34 24A50001 */ addiu $a1, $a1, 1 -/* 0CAA38 800C9E38 24C6FFFF */ addiu $a2, $a2, -1 -/* 0CAA3C 800C9E3C 1000000E */ b .L800C9E78 -/* 0CAA40 800C9E40 A0A2FFFF */ sb $v0, -1($a1) -/* 0CAA44 800C9E44 84820000 */ lh $v0, ($a0) +/* CAA14 800C9E14 10400018 */ beqz $v0, .L800C9E78 +/* CAA18 800C9E18 24010001 */ addiu $at, $zero, 0x1 +/* CAA1C 800C9E1C 1041000F */ beq $v0, $at, .L800C9E5C +/* CAA20 800C9E20 24010002 */ addiu $at, $zero, 0x2 +/* CAA24 800C9E24 50410008 */ beql $v0, $at, .L800C9E48 +/* CAA28 800C9E28 84820000 */ lh $v0, 0x0($a0) +/* CAA2C 800C9E2C 80820000 */ lb $v0, 0x0($a0) +/* CAA30 800C9E30 24840001 */ addiu $a0, $a0, 0x1 +/* CAA34 800C9E34 24A50001 */ addiu $a1, $a1, 0x1 +/* CAA38 800C9E38 24C6FFFF */ addiu $a2, $a2, -0x1 +/* CAA3C 800C9E3C 1000000E */ b .L800C9E78 +/* CAA40 800C9E40 A0A2FFFF */ sb $v0, -0x1($a1) +/* CAA44 800C9E44 84820000 */ lh $v0, 0x0($a0) .L800C9E48: -/* 0CAA48 800C9E48 24840002 */ addiu $a0, $a0, 2 -/* 0CAA4C 800C9E4C 24A50002 */ addiu $a1, $a1, 2 -/* 0CAA50 800C9E50 24C6FFFE */ addiu $a2, $a2, -2 -/* 0CAA54 800C9E54 10000008 */ b .L800C9E78 -/* 0CAA58 800C9E58 A4A2FFFE */ sh $v0, -2($a1) +/* CAA48 800C9E48 24840002 */ addiu $a0, $a0, 0x2 +/* CAA4C 800C9E4C 24A50002 */ addiu $a1, $a1, 0x2 +/* CAA50 800C9E50 24C6FFFE */ addiu $a2, $a2, -0x2 +/* CAA54 800C9E54 10000008 */ b .L800C9E78 +/* CAA58 800C9E58 A4A2FFFE */ sh $v0, -0x2($a1) .L800C9E5C: -/* 0CAA5C 800C9E5C 80820000 */ lb $v0, ($a0) -/* 0CAA60 800C9E60 84830001 */ lh $v1, 1($a0) -/* 0CAA64 800C9E64 24840003 */ addiu $a0, $a0, 3 -/* 0CAA68 800C9E68 24A50003 */ addiu $a1, $a1, 3 -/* 0CAA6C 800C9E6C 24C6FFFD */ addiu $a2, $a2, -3 -/* 0CAA70 800C9E70 A0A2FFFD */ sb $v0, -3($a1) -/* 0CAA74 800C9E74 A4A3FFFE */ sh $v1, -2($a1) +/* CAA5C 800C9E5C 80820000 */ lb $v0, 0x0($a0) +/* CAA60 800C9E60 84830001 */ lh $v1, 0x1($a0) +/* CAA64 800C9E64 24840003 */ addiu $a0, $a0, 0x3 +/* CAA68 800C9E68 24A50003 */ addiu $a1, $a1, 0x3 +/* CAA6C 800C9E6C 24C6FFFD */ addiu $a2, $a2, -0x3 +/* CAA70 800C9E70 A0A2FFFD */ sb $v0, -0x3($a1) +/* CAA74 800C9E74 A4A3FFFE */ sh $v1, -0x2($a1) .L800C9E78: -/* 0CAA78 800C9E78 28C10020 */ slti $at, $a2, 0x20 -/* 0CAA7C 800C9E7C 54200016 */ bnezl $at, .L800C9ED8 -/* 0CAA80 800C9E80 28C10010 */ slti $at, $a2, 0x10 -/* 0CAA84 800C9E84 8C820000 */ lw $v0, ($a0) -/* 0CAA88 800C9E88 8C830004 */ lw $v1, 4($a0) -/* 0CAA8C 800C9E8C 8C880008 */ lw $t0, 8($a0) -/* 0CAA90 800C9E90 8C89000C */ lw $t1, 0xc($a0) -/* 0CAA94 800C9E94 8C8A0010 */ lw $t2, 0x10($a0) -/* 0CAA98 800C9E98 8C8B0014 */ lw $t3, 0x14($a0) -/* 0CAA9C 800C9E9C 8C8C0018 */ lw $t4, 0x18($a0) -/* 0CAAA0 800C9EA0 8C8D001C */ lw $t5, 0x1c($a0) -/* 0CAAA4 800C9EA4 24840020 */ addiu $a0, $a0, 0x20 -/* 0CAAA8 800C9EA8 24A50020 */ addiu $a1, $a1, 0x20 -/* 0CAAAC 800C9EAC 24C6FFE0 */ addiu $a2, $a2, -0x20 -/* 0CAAB0 800C9EB0 ACA2FFE0 */ sw $v0, -0x20($a1) -/* 0CAAB4 800C9EB4 ACA3FFE4 */ sw $v1, -0x1c($a1) -/* 0CAAB8 800C9EB8 ACA8FFE8 */ sw $t0, -0x18($a1) -/* 0CAABC 800C9EBC ACA9FFEC */ sw $t1, -0x14($a1) -/* 0CAAC0 800C9EC0 ACAAFFF0 */ sw $t2, -0x10($a1) -/* 0CAAC4 800C9EC4 ACABFFF4 */ sw $t3, -0xc($a1) -/* 0CAAC8 800C9EC8 ACACFFF8 */ sw $t4, -8($a1) -/* 0CAACC 800C9ECC 1000FFEA */ b .L800C9E78 -/* 0CAAD0 800C9ED0 ACADFFFC */ sw $t5, -4($a1) +/* CAA78 800C9E78 28C10020 */ slti $at, $a2, 0x20 +/* CAA7C 800C9E7C 54200016 */ bnel $at, $zero, .L800C9ED8 +/* CAA80 800C9E80 28C10010 */ slti $at, $a2, 0x10 +/* CAA84 800C9E84 8C820000 */ lw $v0, 0x0($a0) +/* CAA88 800C9E88 8C830004 */ lw $v1, 0x4($a0) +/* CAA8C 800C9E8C 8C880008 */ lw $t0, 0x8($a0) +/* CAA90 800C9E90 8C89000C */ lw $t1, 0xC($a0) +/* CAA94 800C9E94 8C8A0010 */ lw $t2, 0x10($a0) +/* CAA98 800C9E98 8C8B0014 */ lw $t3, 0x14($a0) +/* CAA9C 800C9E9C 8C8C0018 */ lw $t4, 0x18($a0) +/* CAAA0 800C9EA0 8C8D001C */ lw $t5, 0x1C($a0) +/* CAAA4 800C9EA4 24840020 */ addiu $a0, $a0, 0x20 +/* CAAA8 800C9EA8 24A50020 */ addiu $a1, $a1, 0x20 +/* CAAAC 800C9EAC 24C6FFE0 */ addiu $a2, $a2, -0x20 +/* CAAB0 800C9EB0 ACA2FFE0 */ sw $v0, -0x20($a1) +/* CAAB4 800C9EB4 ACA3FFE4 */ sw $v1, -0x1C($a1) +/* CAAB8 800C9EB8 ACA8FFE8 */ sw $t0, -0x18($a1) +/* CAABC 800C9EBC ACA9FFEC */ sw $t1, -0x14($a1) +/* CAAC0 800C9EC0 ACAAFFF0 */ sw $t2, -0x10($a1) +/* CAAC4 800C9EC4 ACABFFF4 */ sw $t3, -0xC($a1) +/* CAAC8 800C9EC8 ACACFFF8 */ sw $t4, -0x8($a1) +/* CAACC 800C9ECC 1000FFEA */ b .L800C9E78 +/* CAAD0 800C9ED0 ACADFFFC */ sw $t5, -0x4($a1) .L800C9ED4: -/* 0CAAD4 800C9ED4 28C10010 */ slti $at, $a2, 0x10 +/* CAAD4 800C9ED4 28C10010 */ slti $at, $a2, 0x10 .L800C9ED8: -/* 0CAAD8 800C9ED8 5420000E */ bnezl $at, .L800C9F14 -/* 0CAADC 800C9EDC 28C10004 */ slti $at, $a2, 4 -/* 0CAAE0 800C9EE0 8C820000 */ lw $v0, ($a0) -/* 0CAAE4 800C9EE4 8C830004 */ lw $v1, 4($a0) -/* 0CAAE8 800C9EE8 8C880008 */ lw $t0, 8($a0) -/* 0CAAEC 800C9EEC 8C89000C */ lw $t1, 0xc($a0) -/* 0CAAF0 800C9EF0 24840010 */ addiu $a0, $a0, 0x10 -/* 0CAAF4 800C9EF4 24A50010 */ addiu $a1, $a1, 0x10 -/* 0CAAF8 800C9EF8 24C6FFF0 */ addiu $a2, $a2, -0x10 -/* 0CAAFC 800C9EFC ACA2FFF0 */ sw $v0, -0x10($a1) -/* 0CAB00 800C9F00 ACA3FFF4 */ sw $v1, -0xc($a1) -/* 0CAB04 800C9F04 ACA8FFF8 */ sw $t0, -8($a1) -/* 0CAB08 800C9F08 1000FFF2 */ b .L800C9ED4 -/* 0CAB0C 800C9F0C ACA9FFFC */ sw $t1, -4($a1) +/* CAAD8 800C9ED8 5420000E */ bnel $at, $zero, .L800C9F14 +/* CAADC 800C9EDC 28C10004 */ slti $at, $a2, 0x4 +/* CAAE0 800C9EE0 8C820000 */ lw $v0, 0x0($a0) +/* CAAE4 800C9EE4 8C830004 */ lw $v1, 0x4($a0) +/* CAAE8 800C9EE8 8C880008 */ lw $t0, 0x8($a0) +/* CAAEC 800C9EEC 8C89000C */ lw $t1, 0xC($a0) +/* CAAF0 800C9EF0 24840010 */ addiu $a0, $a0, 0x10 +/* CAAF4 800C9EF4 24A50010 */ addiu $a1, $a1, 0x10 +/* CAAF8 800C9EF8 24C6FFF0 */ addiu $a2, $a2, -0x10 +/* CAAFC 800C9EFC ACA2FFF0 */ sw $v0, -0x10($a1) +/* CAB00 800C9F00 ACA3FFF4 */ sw $v1, -0xC($a1) +/* CAB04 800C9F04 ACA8FFF8 */ sw $t0, -0x8($a1) +/* CAB08 800C9F08 1000FFF2 */ b .L800C9ED4 +/* CAB0C 800C9F0C ACA9FFFC */ sw $t1, -0x4($a1) .L800C9F10: -/* 0CAB10 800C9F10 28C10004 */ slti $at, $a2, 4 +/* CAB10 800C9F10 28C10004 */ slti $at, $a2, 0x4 .L800C9F14: -/* 0CAB14 800C9F14 1420FFB5 */ bnez $at, .L800C9DEC -/* 0CAB18 800C9F18 00000000 */ nop -/* 0CAB1C 800C9F1C 8C820000 */ lw $v0, ($a0) -/* 0CAB20 800C9F20 24840004 */ addiu $a0, $a0, 4 -/* 0CAB24 800C9F24 24A50004 */ addiu $a1, $a1, 4 -/* 0CAB28 800C9F28 24C6FFFC */ addiu $a2, $a2, -4 -/* 0CAB2C 800C9F2C 1000FFF8 */ b .L800C9F10 -/* 0CAB30 800C9F30 ACA2FFFC */ sw $v0, -4($a1) -/* 0CAB34 800C9F34 28C10010 */ slti $at, $a2, 0x10 +/* CAB14 800C9F14 1420FFB5 */ bnez $at, .L800C9DEC +/* CAB18 800C9F18 00000000 */ nop +/* CAB1C 800C9F1C 8C820000 */ lw $v0, 0x0($a0) +/* CAB20 800C9F20 24840004 */ addiu $a0, $a0, 0x4 +/* CAB24 800C9F24 24A50004 */ addiu $a1, $a1, 0x4 +/* CAB28 800C9F28 24C6FFFC */ addiu $a2, $a2, -0x4 +/* CAB2C 800C9F2C 1000FFF8 */ b .L800C9F10 +/* CAB30 800C9F30 ACA2FFFC */ sw $v0, -0x4($a1) +/* CAB34 800C9F34 28C10010 */ slti $at, $a2, 0x10 .L800C9F38: -/* 0CAB38 800C9F38 00862020 */ add $a0, $a0, $a2 -/* 0CAB3C 800C9F3C 14200005 */ bnez $at, .L800C9F54 -/* 0CAB40 800C9F40 00A62820 */ add $a1, $a1, $a2 -/* 0CAB44 800C9F44 30820003 */ andi $v0, $a0, 3 -/* 0CAB48 800C9F48 30A30003 */ andi $v1, $a1, 3 -/* 0CAB4C 800C9F4C 1043000D */ beq $v0, $v1, .L800C9F84 -/* 0CAB50 800C9F50 00000000 */ nop +/* CAB38 800C9F38 00862020 */ add $a0, $a0, $a2 /* handwritten instruction */ +/* CAB3C 800C9F3C 14200005 */ bnez $at, .L800C9F54 +/* CAB40 800C9F40 00A62820 */ add $a1, $a1, $a2 /* handwritten instruction */ +/* CAB44 800C9F44 30820003 */ andi $v0, $a0, 0x3 +/* CAB48 800C9F48 30A30003 */ andi $v1, $a1, 0x3 +/* CAB4C 800C9F4C 1043000D */ beq $v0, $v1, .L800C9F84 +/* CAB50 800C9F50 00000000 */ nop .L800C9F54: -/* 0CAB54 800C9F54 10C0FFAD */ beqz $a2, .L800C9E0C -/* 0CAB58 800C9F58 00000000 */ nop -/* 0CAB5C 800C9F5C 2484FFFF */ addiu $a0, $a0, -1 -/* 0CAB60 800C9F60 24A5FFFF */ addiu $a1, $a1, -1 -/* 0CAB64 800C9F64 00861823 */ subu $v1, $a0, $a2 +/* CAB54 800C9F54 10C0FFAD */ beqz $a2, .L800C9E0C +/* CAB58 800C9F58 00000000 */ nop +/* CAB5C 800C9F5C 2484FFFF */ addiu $a0, $a0, -0x1 +/* CAB60 800C9F60 24A5FFFF */ addiu $a1, $a1, -0x1 +/* CAB64 800C9F64 00861823 */ subu $v1, $a0, $a2 .L800C9F68: -/* 0CAB68 800C9F68 80820000 */ lb $v0, ($a0) -/* 0CAB6C 800C9F6C 2484FFFF */ addiu $a0, $a0, -1 -/* 0CAB70 800C9F70 24A5FFFF */ addiu $a1, $a1, -1 -/* 0CAB74 800C9F74 1483FFFC */ bne $a0, $v1, .L800C9F68 -/* 0CAB78 800C9F78 A0A20001 */ sb $v0, 1($a1) -/* 0CAB7C 800C9F7C 03E00008 */ jr $ra -/* 0CAB80 800C9F80 00E01025 */ move $v0, $a3 - +/* CAB68 800C9F68 80820000 */ lb $v0, 0x0($a0) +/* CAB6C 800C9F6C 2484FFFF */ addiu $a0, $a0, -0x1 +/* CAB70 800C9F70 24A5FFFF */ addiu $a1, $a1, -0x1 +/* CAB74 800C9F74 1483FFFC */ bne $a0, $v1, .L800C9F68 +/* CAB78 800C9F78 A0A20001 */ sb $v0, 0x1($a1) +/* CAB7C 800C9F7C 03E00008 */ jr $ra +/* CAB80 800C9F80 00E01025 */ or $v0, $a3, $zero .L800C9F84: -/* 0CAB84 800C9F84 10400018 */ beqz $v0, .L800C9FE8 -/* 0CAB88 800C9F88 24010003 */ li $at, 3 -/* 0CAB8C 800C9F8C 1041000F */ beq $v0, $at, .L800C9FCC -/* 0CAB90 800C9F90 24010002 */ li $at, 2 -/* 0CAB94 800C9F94 50410008 */ beql $v0, $at, .L800C9FB8 -/* 0CAB98 800C9F98 8482FFFE */ lh $v0, -2($a0) -/* 0CAB9C 800C9F9C 8082FFFF */ lb $v0, -1($a0) -/* 0CABA0 800C9FA0 2484FFFF */ addiu $a0, $a0, -1 -/* 0CABA4 800C9FA4 24A5FFFF */ addiu $a1, $a1, -1 -/* 0CABA8 800C9FA8 24C6FFFF */ addiu $a2, $a2, -1 -/* 0CABAC 800C9FAC 1000000E */ b .L800C9FE8 -/* 0CABB0 800C9FB0 A0A20000 */ sb $v0, ($a1) -/* 0CABB4 800C9FB4 8482FFFE */ lh $v0, -2($a0) +/* CAB84 800C9F84 10400018 */ beqz $v0, .L800C9FE8 +/* CAB88 800C9F88 24010003 */ addiu $at, $zero, 0x3 +/* CAB8C 800C9F8C 1041000F */ beq $v0, $at, .L800C9FCC +/* CAB90 800C9F90 24010002 */ addiu $at, $zero, 0x2 +/* CAB94 800C9F94 50410008 */ beql $v0, $at, .L800C9FB8 +/* CAB98 800C9F98 8482FFFE */ lh $v0, -0x2($a0) +/* CAB9C 800C9F9C 8082FFFF */ lb $v0, -0x1($a0) +/* CABA0 800C9FA0 2484FFFF */ addiu $a0, $a0, -0x1 +/* CABA4 800C9FA4 24A5FFFF */ addiu $a1, $a1, -0x1 +/* CABA8 800C9FA8 24C6FFFF */ addiu $a2, $a2, -0x1 +/* CABAC 800C9FAC 1000000E */ b .L800C9FE8 +/* CABB0 800C9FB0 A0A20000 */ sb $v0, 0x0($a1) +/* CABB4 800C9FB4 8482FFFE */ lh $v0, -0x2($a0) .L800C9FB8: -/* 0CABB8 800C9FB8 2484FFFE */ addiu $a0, $a0, -2 -/* 0CABBC 800C9FBC 24A5FFFE */ addiu $a1, $a1, -2 -/* 0CABC0 800C9FC0 24C6FFFE */ addiu $a2, $a2, -2 -/* 0CABC4 800C9FC4 10000008 */ b .L800C9FE8 -/* 0CABC8 800C9FC8 A4A20000 */ sh $v0, ($a1) +/* CABB8 800C9FB8 2484FFFE */ addiu $a0, $a0, -0x2 +/* CABBC 800C9FBC 24A5FFFE */ addiu $a1, $a1, -0x2 +/* CABC0 800C9FC0 24C6FFFE */ addiu $a2, $a2, -0x2 +/* CABC4 800C9FC4 10000008 */ b .L800C9FE8 +/* CABC8 800C9FC8 A4A20000 */ sh $v0, 0x0($a1) .L800C9FCC: -/* 0CABCC 800C9FCC 8082FFFF */ lb $v0, -1($a0) -/* 0CABD0 800C9FD0 8483FFFD */ lh $v1, -3($a0) -/* 0CABD4 800C9FD4 2484FFFD */ addiu $a0, $a0, -3 -/* 0CABD8 800C9FD8 24A5FFFD */ addiu $a1, $a1, -3 -/* 0CABDC 800C9FDC 24C6FFFD */ addiu $a2, $a2, -3 -/* 0CABE0 800C9FE0 A0A20002 */ sb $v0, 2($a1) -/* 0CABE4 800C9FE4 A4A30000 */ sh $v1, ($a1) +/* CABCC 800C9FCC 8082FFFF */ lb $v0, -0x1($a0) +/* CABD0 800C9FD0 8483FFFD */ lh $v1, -0x3($a0) +/* CABD4 800C9FD4 2484FFFD */ addiu $a0, $a0, -0x3 +/* CABD8 800C9FD8 24A5FFFD */ addiu $a1, $a1, -0x3 +/* CABDC 800C9FDC 24C6FFFD */ addiu $a2, $a2, -0x3 +/* CABE0 800C9FE0 A0A20002 */ sb $v0, 0x2($a1) +/* CABE4 800C9FE4 A4A30000 */ sh $v1, 0x0($a1) .L800C9FE8: -/* 0CABE8 800C9FE8 28C10020 */ slti $at, $a2, 0x20 -/* 0CABEC 800C9FEC 54200016 */ bnezl $at, .L800CA048 -/* 0CABF0 800C9FF0 28C10010 */ slti $at, $a2, 0x10 -/* 0CABF4 800C9FF4 8C82FFFC */ lw $v0, -4($a0) -/* 0CABF8 800C9FF8 8C83FFF8 */ lw $v1, -8($a0) -/* 0CABFC 800C9FFC 8C88FFF4 */ lw $t0, -0xc($a0) -/* 0CAC00 800CA000 8C89FFF0 */ lw $t1, -0x10($a0) -/* 0CAC04 800CA004 8C8AFFEC */ lw $t2, -0x14($a0) -/* 0CAC08 800CA008 8C8BFFE8 */ lw $t3, -0x18($a0) -/* 0CAC0C 800CA00C 8C8CFFE4 */ lw $t4, -0x1c($a0) -/* 0CAC10 800CA010 8C8DFFE0 */ lw $t5, -0x20($a0) -/* 0CAC14 800CA014 2484FFE0 */ addiu $a0, $a0, -0x20 -/* 0CAC18 800CA018 24A5FFE0 */ addiu $a1, $a1, -0x20 -/* 0CAC1C 800CA01C 24C6FFE0 */ addiu $a2, $a2, -0x20 -/* 0CAC20 800CA020 ACA2001C */ sw $v0, 0x1c($a1) -/* 0CAC24 800CA024 ACA30018 */ sw $v1, 0x18($a1) -/* 0CAC28 800CA028 ACA80014 */ sw $t0, 0x14($a1) -/* 0CAC2C 800CA02C ACA90010 */ sw $t1, 0x10($a1) -/* 0CAC30 800CA030 ACAA000C */ sw $t2, 0xc($a1) -/* 0CAC34 800CA034 ACAB0008 */ sw $t3, 8($a1) -/* 0CAC38 800CA038 ACAC0004 */ sw $t4, 4($a1) -/* 0CAC3C 800CA03C 1000FFEA */ b .L800C9FE8 -/* 0CAC40 800CA040 ACAD0000 */ sw $t5, ($a1) +/* CABE8 800C9FE8 28C10020 */ slti $at, $a2, 0x20 +/* CABEC 800C9FEC 54200016 */ bnel $at, $zero, .L800CA048 +/* CABF0 800C9FF0 28C10010 */ slti $at, $a2, 0x10 +/* CABF4 800C9FF4 8C82FFFC */ lw $v0, -0x4($a0) +/* CABF8 800C9FF8 8C83FFF8 */ lw $v1, -0x8($a0) +/* CABFC 800C9FFC 8C88FFF4 */ lw $t0, -0xC($a0) +/* CAC00 800CA000 8C89FFF0 */ lw $t1, -0x10($a0) +/* CAC04 800CA004 8C8AFFEC */ lw $t2, -0x14($a0) +/* CAC08 800CA008 8C8BFFE8 */ lw $t3, -0x18($a0) +/* CAC0C 800CA00C 8C8CFFE4 */ lw $t4, -0x1C($a0) +/* CAC10 800CA010 8C8DFFE0 */ lw $t5, -0x20($a0) +/* CAC14 800CA014 2484FFE0 */ addiu $a0, $a0, -0x20 +/* CAC18 800CA018 24A5FFE0 */ addiu $a1, $a1, -0x20 +/* CAC1C 800CA01C 24C6FFE0 */ addiu $a2, $a2, -0x20 +/* CAC20 800CA020 ACA2001C */ sw $v0, 0x1C($a1) +/* CAC24 800CA024 ACA30018 */ sw $v1, 0x18($a1) +/* CAC28 800CA028 ACA80014 */ sw $t0, 0x14($a1) +/* CAC2C 800CA02C ACA90010 */ sw $t1, 0x10($a1) +/* CAC30 800CA030 ACAA000C */ sw $t2, 0xC($a1) +/* CAC34 800CA034 ACAB0008 */ sw $t3, 0x8($a1) +/* CAC38 800CA038 ACAC0004 */ sw $t4, 0x4($a1) +/* CAC3C 800CA03C 1000FFEA */ b .L800C9FE8 +/* CAC40 800CA040 ACAD0000 */ sw $t5, 0x0($a1) .L800CA044: -/* 0CAC44 800CA044 28C10010 */ slti $at, $a2, 0x10 +/* CAC44 800CA044 28C10010 */ slti $at, $a2, 0x10 .L800CA048: -/* 0CAC48 800CA048 5420000E */ bnezl $at, .L800CA084 -/* 0CAC4C 800CA04C 28C10004 */ slti $at, $a2, 4 -/* 0CAC50 800CA050 8C82FFFC */ lw $v0, -4($a0) -/* 0CAC54 800CA054 8C83FFF8 */ lw $v1, -8($a0) -/* 0CAC58 800CA058 8C88FFF4 */ lw $t0, -0xc($a0) -/* 0CAC5C 800CA05C 8C89FFF0 */ lw $t1, -0x10($a0) -/* 0CAC60 800CA060 2484FFF0 */ addiu $a0, $a0, -0x10 -/* 0CAC64 800CA064 24A5FFF0 */ addiu $a1, $a1, -0x10 -/* 0CAC68 800CA068 24C6FFF0 */ addiu $a2, $a2, -0x10 -/* 0CAC6C 800CA06C ACA2000C */ sw $v0, 0xc($a1) -/* 0CAC70 800CA070 ACA30008 */ sw $v1, 8($a1) -/* 0CAC74 800CA074 ACA80004 */ sw $t0, 4($a1) -/* 0CAC78 800CA078 1000FFF2 */ b .L800CA044 -/* 0CAC7C 800CA07C ACA90000 */ sw $t1, ($a1) +/* CAC48 800CA048 5420000E */ bnel $at, $zero, .L800CA084 +/* CAC4C 800CA04C 28C10004 */ slti $at, $a2, 0x4 +/* CAC50 800CA050 8C82FFFC */ lw $v0, -0x4($a0) +/* CAC54 800CA054 8C83FFF8 */ lw $v1, -0x8($a0) +/* CAC58 800CA058 8C88FFF4 */ lw $t0, -0xC($a0) +/* CAC5C 800CA05C 8C89FFF0 */ lw $t1, -0x10($a0) +/* CAC60 800CA060 2484FFF0 */ addiu $a0, $a0, -0x10 +/* CAC64 800CA064 24A5FFF0 */ addiu $a1, $a1, -0x10 +/* CAC68 800CA068 24C6FFF0 */ addiu $a2, $a2, -0x10 +/* CAC6C 800CA06C ACA2000C */ sw $v0, 0xC($a1) +/* CAC70 800CA070 ACA30008 */ sw $v1, 0x8($a1) +/* CAC74 800CA074 ACA80004 */ sw $t0, 0x4($a1) +/* CAC78 800CA078 1000FFF2 */ b .L800CA044 +/* CAC7C 800CA07C ACA90000 */ sw $t1, 0x0($a1) .L800CA080: -/* 0CAC80 800CA080 28C10004 */ slti $at, $a2, 4 +/* CAC80 800CA080 28C10004 */ slti $at, $a2, 0x4 .L800CA084: -/* 0CAC84 800CA084 1420FFB3 */ bnez $at, .L800C9F54 -/* 0CAC88 800CA088 00000000 */ nop -/* 0CAC8C 800CA08C 8C82FFFC */ lw $v0, -4($a0) -/* 0CAC90 800CA090 2484FFFC */ addiu $a0, $a0, -4 -/* 0CAC94 800CA094 24A5FFFC */ addiu $a1, $a1, -4 -/* 0CAC98 800CA098 24C6FFFC */ addiu $a2, $a2, -4 -/* 0CAC9C 800CA09C 1000FFF8 */ b .L800CA080 -/* 0CACA0 800CA0A0 ACA20000 */ sw $v0, ($a1) -/* 0CACA4 800CA0A4 00000000 */ nop -/* 0CACA8 800CA0A8 00000000 */ nop -/* 0CACAC 800CA0AC 00000000 */ nop +/* CAC84 800CA084 1420FFB3 */ bnez $at, .L800C9F54 +/* CAC88 800CA088 00000000 */ nop +/* CAC8C 800CA08C 8C82FFFC */ lw $v0, -0x4($a0) +/* CAC90 800CA090 2484FFFC */ addiu $a0, $a0, -0x4 +/* CAC94 800CA094 24A5FFFC */ addiu $a1, $a1, -0x4 +/* CAC98 800CA098 24C6FFFC */ addiu $a2, $a2, -0x4 +/* CAC9C 800CA09C 1000FFF8 */ b .L800CA080 +/* CACA0 800CA0A0 ACA20000 */ sw $v0, 0x0($a1) +/* CACA4 800CA0A4 00000000 */ nop +/* CACA8 800CA0A8 00000000 */ nop +/* CACAC 800CA0AC 00000000 */ nop diff --git a/lib/asm/bzero.s b/lib/asm/bzero.s index 863d1e19..2c9de746 100644 --- a/lib/asm/bzero.s +++ b/lib/asm/bzero.s @@ -1,59 +1,62 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D04E0 */ -.include "macros.inc" +.include "macro.inc" -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ glabel bzero /* Official name: _blkclr */ -/* 0D10E0 800D04E0 28A1000C */ slti $at, $a1, 0xc -/* 0D10E4 800D04E4 1420001D */ bnez $at, .L800D055C -/* 0D10E8 800D04E8 00041823 */ negu $v1, $a0 -/* 0D10EC 800D04EC 30630003 */ andi $v1, $v1, 3 -/* 0D10F0 800D04F0 10600003 */ beqz $v1, .L800D0500 -/* 0D10F4 800D04F4 00A32823 */ subu $a1, $a1, $v1 -/* 0D10F8 800D04F8 A8800000 */ swl $zero, ($a0) -/* 0D10FC 800D04FC 00832021 */ addu $a0, $a0, $v1 +/* D10E0 800D04E0 28A1000C */ slti $at, $a1, 0xC +/* D10E4 800D04E4 1420001D */ bnez $at, .L800D055C +/* D10E8 800D04E8 00041823 */ negu $v1, $a0 +/* D10EC 800D04EC 30630003 */ andi $v1, $v1, 0x3 +/* D10F0 800D04F0 10600003 */ beqz $v1, .L800D0500 +/* D10F4 800D04F4 00A32823 */ subu $a1, $a1, $v1 +/* D10F8 800D04F8 A8800000 */ swl $zero, 0x0($a0) +/* D10FC 800D04FC 00832021 */ addu $a0, $a0, $v1 .L800D0500: -/* 0D1100 800D0500 2401FFE0 */ li $at, -32 -/* 0D1104 800D0504 00A13824 */ and $a3, $a1, $at -/* 0D1108 800D0508 10E0000C */ beqz $a3, .L800D053C -/* 0D110C 800D050C 00A72823 */ subu $a1, $a1, $a3 -/* 0D1110 800D0510 00E43821 */ addu $a3, $a3, $a0 +/* D1100 800D0500 2401FFE0 */ addiu $at, $zero, -0x20 +/* D1104 800D0504 00A13824 */ and $a3, $a1, $at +/* D1108 800D0508 10E0000C */ beqz $a3, .L800D053C +/* D110C 800D050C 00A72823 */ subu $a1, $a1, $a3 +/* D1110 800D0510 00E43821 */ addu $a3, $a3, $a0 .L800D0514: -/* 0D1114 800D0514 24840020 */ addiu $a0, $a0, 0x20 -/* 0D1118 800D0518 AC80FFE0 */ sw $zero, -0x20($a0) -/* 0D111C 800D051C AC80FFE4 */ sw $zero, -0x1c($a0) -/* 0D1120 800D0520 AC80FFE8 */ sw $zero, -0x18($a0) -/* 0D1124 800D0524 AC80FFEC */ sw $zero, -0x14($a0) -/* 0D1128 800D0528 AC80FFF0 */ sw $zero, -0x10($a0) -/* 0D112C 800D052C AC80FFF4 */ sw $zero, -0xc($a0) -/* 0D1130 800D0530 AC80FFF8 */ sw $zero, -8($a0) -/* 0D1134 800D0534 1487FFF7 */ bne $a0, $a3, .L800D0514 -/* 0D1138 800D0538 AC80FFFC */ sw $zero, -4($a0) +/* D1114 800D0514 24840020 */ addiu $a0, $a0, 0x20 +/* D1118 800D0518 AC80FFE0 */ sw $zero, -0x20($a0) +/* D111C 800D051C AC80FFE4 */ sw $zero, -0x1C($a0) +/* D1120 800D0520 AC80FFE8 */ sw $zero, -0x18($a0) +/* D1124 800D0524 AC80FFEC */ sw $zero, -0x14($a0) +/* D1128 800D0528 AC80FFF0 */ sw $zero, -0x10($a0) +/* D112C 800D052C AC80FFF4 */ sw $zero, -0xC($a0) +/* D1130 800D0530 AC80FFF8 */ sw $zero, -0x8($a0) +/* D1134 800D0534 1487FFF7 */ bne $a0, $a3, .L800D0514 +/* D1138 800D0538 AC80FFFC */ sw $zero, -0x4($a0) .L800D053C: -/* 0D113C 800D053C 2401FFFC */ li $at, -4 -/* 0D1140 800D0540 00A13824 */ and $a3, $a1, $at -/* 0D1144 800D0544 10E00005 */ beqz $a3, .L800D055C -/* 0D1148 800D0548 00A72823 */ subu $a1, $a1, $a3 -/* 0D114C 800D054C 00E43821 */ addu $a3, $a3, $a0 +/* D113C 800D053C 2401FFFC */ addiu $at, $zero, -0x4 +/* D1140 800D0540 00A13824 */ and $a3, $a1, $at +/* D1144 800D0544 10E00005 */ beqz $a3, .L800D055C +/* D1148 800D0548 00A72823 */ subu $a1, $a1, $a3 +/* D114C 800D054C 00E43821 */ addu $a3, $a3, $a0 .L800D0550: -/* 0D1150 800D0550 24840004 */ addiu $a0, $a0, 4 -/* 0D1154 800D0554 1487FFFE */ bne $a0, $a3, .L800D0550 -/* 0D1158 800D0558 AC80FFFC */ sw $zero, -4($a0) +/* D1150 800D0550 24840004 */ addiu $a0, $a0, 0x4 +/* D1154 800D0554 1487FFFE */ bne $a0, $a3, .L800D0550 +/* D1158 800D0558 AC80FFFC */ sw $zero, -0x4($a0) .L800D055C: -/* 0D115C 800D055C 18A00005 */ blez $a1, .L800D0574 -/* 0D1160 800D0560 00000000 */ nop -/* 0D1164 800D0564 00A42821 */ addu $a1, $a1, $a0 +/* D115C 800D055C 18A00005 */ blez $a1, .L800D0574 +/* D1160 800D0560 00000000 */ nop +/* D1164 800D0564 00A42821 */ addu $a1, $a1, $a0 .L800D0568: -/* 0D1168 800D0568 24840001 */ addiu $a0, $a0, 1 -/* 0D116C 800D056C 1485FFFE */ bne $a0, $a1, .L800D0568 -/* 0D1170 800D0570 A080FFFF */ sb $zero, -1($a0) +/* D1168 800D0568 24840001 */ addiu $a0, $a0, 0x1 +/* D116C 800D056C 1485FFFE */ bne $a0, $a1, .L800D0568 +/* D1170 800D0570 A080FFFF */ sb $zero, -0x1($a0) .L800D0574: -/* 0D1174 800D0574 03E00008 */ jr $ra -/* 0D1178 800D0578 00000000 */ nop - -/* 0D117C 800D057C 00000000 */ nop - +/* D1174 800D0574 03E00008 */ jr $ra +/* D1178 800D0578 00000000 */ nop +/* D117C 800D057C 00000000 */ nop diff --git a/lib/asm/exceptasm.bss.s b/lib/asm/exceptasm.bss.s new file mode 100644 index 00000000..7c38fc74 --- /dev/null +++ b/lib/asm/exceptasm.bss.s @@ -0,0 +1,14 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x8012D240 */ + +.include "macro.inc" + +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .bss + +glabel __osThreadSave +.space 0x1B0 \ No newline at end of file diff --git a/lib/asm/exceptasm.s b/lib/asm/exceptasm.s new file mode 100644 index 00000000..39c5e42f --- /dev/null +++ b/lib/asm/exceptasm.s @@ -0,0 +1,704 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D2CB0 */ + +.include "macro.inc" + +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .data + +glabel __osHwIntTable +.word 0 +.word 0 +.word 0 +.word 0 +.word 0 + +.section .rodata + +glabel __osIntOffTable +.byte 0x00 +.byte 0x14 +.byte 0x18 +.byte 0x18 +.byte 0x1C +.byte 0x1C +.byte 0x1C +.byte 0x1C +.byte 0x20 +.byte 0x20 +.byte 0x20 +.byte 0x20 +.byte 0x20 +.byte 0x20 +.byte 0x20 +.byte 0x20 +.byte 0x00 +.byte 0x04 +.byte 0x08 +.byte 0x08 +.byte 0x0C +.byte 0x0C +.byte 0x0C +.byte 0x0C +.byte 0x10 +.byte 0x10 +.byte 0x10 +.byte 0x10 +.byte 0x10 +.byte 0x10 +.byte 0x10 +.byte 0x10 + +glabel __osIntTable +.word .L800D3168 +.word .L800D3130 +.word .L800D3110 +.word .L800D2F74 +.word .L800D2F20 +.word .L800D30B4 +.word .L800D2EE8 +.word .L800D2EF4 +.word .L800D2F00 + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ + +/* Handwritten function */ +glabel __osExceptionPreamble +/* D38B0 800D2CB0 3C1A800D */ lui $k0, %hi(__osException) /* handwritten instruction */ +/* D38B4 800D2CB4 275A2CC0 */ addiu $k0, $k0, %lo(__osException) /* handwritten instruction */ +/* D38B8 800D2CB8 03400008 */ jr $k0 +/* D38BC 800D2CBC 00000000 */ nop + +/* Handwritten function */ +glabel __osException +/* D38C0 800D2CC0 3C1A8013 */ lui $k0, %hi(__osThreadSave) /* handwritten instruction */ +/* D38C4 800D2CC4 275AD240 */ addiu $k0, $k0, %lo(__osThreadSave) /* handwritten instruction */ +/* D38C8 800D2CC8 FF410020 */ sd $at, 0x20($k0) /* handwritten instruction */ +/* D38CC 800D2CCC 401B6000 */ mfc0 $k1, $12 /* handwritten instruction */ +/* D38D0 800D2CD0 AF5B0118 */ sw $k1, 0x118($k0) /* handwritten instruction */ +/* D38D4 800D2CD4 2401FFFC */ addiu $at, $zero, -0x4 +/* D38D8 800D2CD8 0361D824 */ and $k1, $k1, $at +/* D38DC 800D2CDC 409B6000 */ mtc0 $k1, $12 /* handwritten instruction */ +/* D38E0 800D2CE0 FF480058 */ sd $t0, 0x58($k0) /* handwritten instruction */ +/* D38E4 800D2CE4 FF490060 */ sd $t1, 0x60($k0) /* handwritten instruction */ +/* D38E8 800D2CE8 FF4A0068 */ sd $t2, 0x68($k0) /* handwritten instruction */ +/* D38EC 800D2CEC AF400018 */ sw $zero, 0x18($k0) /* handwritten instruction */ +/* D38F0 800D2CF0 40086800 */ mfc0 $t0, $13 /* handwritten instruction */ +/* D38F4 800D2CF4 03404025 */ or $t0, $k0, $zero +/* D38F8 800D2CF8 3C1A800E */ lui $k0, %hi(__osRunningThread) /* handwritten instruction */ +/* D38FC 800D2CFC 8F5A4890 */ lw $k0, %lo(__osRunningThread)($k0) /* handwritten instruction */ +/* D3900 800D2D00 DD090020 */ ld $t1, 0x20($t0) +/* D3904 800D2D04 FF490020 */ sd $t1, 0x20($k0) /* handwritten instruction */ +/* D3908 800D2D08 DD090118 */ ld $t1, 0x118($t0) +/* D390C 800D2D0C FF490118 */ sd $t1, 0x118($k0) /* handwritten instruction */ +/* D3910 800D2D10 DD090058 */ ld $t1, 0x58($t0) +/* D3914 800D2D14 FF490058 */ sd $t1, 0x58($k0) /* handwritten instruction */ +/* D3918 800D2D18 DD090060 */ ld $t1, 0x60($t0) +/* D391C 800D2D1C FF490060 */ sd $t1, 0x60($k0) /* handwritten instruction */ +/* D3920 800D2D20 DD090068 */ ld $t1, 0x68($t0) +/* D3924 800D2D24 FF490068 */ sd $t1, 0x68($k0) /* handwritten instruction */ +/* D3928 800D2D28 8F5B0118 */ lw $k1, 0x118($k0) /* handwritten instruction */ +/* D392C 800D2D2C 00004012 */ mflo $t0 +/* D3930 800D2D30 FF480108 */ sd $t0, 0x108($k0) /* handwritten instruction */ +/* D3934 800D2D34 00004010 */ mfhi $t0 +/* D3938 800D2D38 3369FF00 */ andi $t1, $k1, 0xFF00 /* handwritten instruction */ +/* D393C 800D2D3C FF420028 */ sd $v0, 0x28($k0) /* handwritten instruction */ +/* D3940 800D2D40 FF430030 */ sd $v1, 0x30($k0) /* handwritten instruction */ +/* D3944 800D2D44 FF440038 */ sd $a0, 0x38($k0) /* handwritten instruction */ +/* D3948 800D2D48 FF450040 */ sd $a1, 0x40($k0) /* handwritten instruction */ +/* D394C 800D2D4C FF460048 */ sd $a2, 0x48($k0) /* handwritten instruction */ +/* D3950 800D2D50 FF470050 */ sd $a3, 0x50($k0) /* handwritten instruction */ +/* D3954 800D2D54 FF4B0070 */ sd $t3, 0x70($k0) /* handwritten instruction */ +/* D3958 800D2D58 FF4C0078 */ sd $t4, 0x78($k0) /* handwritten instruction */ +/* D395C 800D2D5C FF4D0080 */ sd $t5, 0x80($k0) /* handwritten instruction */ +/* D3960 800D2D60 FF4E0088 */ sd $t6, 0x88($k0) /* handwritten instruction */ +/* D3964 800D2D64 FF4F0090 */ sd $t7, 0x90($k0) /* handwritten instruction */ +/* D3968 800D2D68 FF500098 */ sd $s0, 0x98($k0) /* handwritten instruction */ +/* D396C 800D2D6C FF5100A0 */ sd $s1, 0xA0($k0) /* handwritten instruction */ +/* D3970 800D2D70 FF5200A8 */ sd $s2, 0xA8($k0) /* handwritten instruction */ +/* D3974 800D2D74 FF5300B0 */ sd $s3, 0xB0($k0) /* handwritten instruction */ +/* D3978 800D2D78 FF5400B8 */ sd $s4, 0xB8($k0) /* handwritten instruction */ +/* D397C 800D2D7C FF5500C0 */ sd $s5, 0xC0($k0) /* handwritten instruction */ +/* D3980 800D2D80 FF5600C8 */ sd $s6, 0xC8($k0) /* handwritten instruction */ +/* D3984 800D2D84 FF5700D0 */ sd $s7, 0xD0($k0) /* handwritten instruction */ +/* D3988 800D2D88 FF5800D8 */ sd $t8, 0xD8($k0) /* handwritten instruction */ +/* D398C 800D2D8C FF5900E0 */ sd $t9, 0xE0($k0) /* handwritten instruction */ +/* D3990 800D2D90 FF5C00E8 */ sd $gp, 0xE8($k0) /* handwritten instruction */ +/* D3994 800D2D94 FF5D00F0 */ sd $sp, 0xF0($k0) /* handwritten instruction */ +/* D3998 800D2D98 FF5E00F8 */ sd $fp, 0xF8($k0) /* handwritten instruction */ +/* D399C 800D2D9C FF5F0100 */ sd $ra, 0x100($k0) /* handwritten instruction */ +/* D39A0 800D2DA0 1120000D */ beqz $t1, .L800D2DD8 +/* D39A4 800D2DA4 FF480110 */ sd $t0, 0x110($k0) /* handwritten instruction */ +/* D39A8 800D2DA8 3C08800E */ lui $t0, %hi(__OSGlobalIntMask) +/* D39AC 800D2DAC 250838AC */ addiu $t0, $t0, %lo(__OSGlobalIntMask) +/* D39B0 800D2DB0 8D080000 */ lw $t0, 0x0($t0) +/* D39B4 800D2DB4 2401FFFF */ addiu $at, $zero, -0x1 +/* D39B8 800D2DB8 01014026 */ xor $t0, $t0, $at +/* D39BC 800D2DBC 3C01FFFF */ lui $at, (0xFFFF00FF >> 16) +/* D39C0 800D2DC0 3108FF00 */ andi $t0, $t0, 0xFF00 +/* D39C4 800D2DC4 342100FF */ ori $at, $at, (0xFFFF00FF & 0xFFFF) +/* D39C8 800D2DC8 01284825 */ or $t1, $t1, $t0 +/* D39CC 800D2DCC 0361D824 */ and $k1, $k1, $at +/* D39D0 800D2DD0 0369D825 */ or $k1, $k1, $t1 +/* D39D4 800D2DD4 AF5B0118 */ sw $k1, 0x118($k0) /* handwritten instruction */ +.L800D2DD8: +/* D39D8 800D2DD8 3C09A430 */ lui $t1, %hi(MI_INTR_MASK_REG) +/* D39DC 800D2DDC 8D29000C */ lw $t1, %lo(MI_INTR_MASK_REG)($t1) +/* D39E0 800D2DE0 1120000B */ beqz $t1, .L800D2E10 +/* D39E4 800D2DE4 00000000 */ nop +/* D39E8 800D2DE8 3C08800E */ lui $t0, %hi(__OSGlobalIntMask) +/* D39EC 800D2DEC 250838AC */ addiu $t0, $t0, %lo(__OSGlobalIntMask) +/* D39F0 800D2DF0 8D080000 */ lw $t0, 0x0($t0) +/* D39F4 800D2DF4 8F4C0128 */ lw $t4, 0x128($k0) /* handwritten instruction */ +/* D39F8 800D2DF8 2401FFFF */ addiu $at, $zero, -0x1 +/* D39FC 800D2DFC 00084402 */ srl $t0, $t0, 16 +/* D3A00 800D2E00 01014026 */ xor $t0, $t0, $at +/* D3A04 800D2E04 3108003F */ andi $t0, $t0, 0x3F +/* D3A08 800D2E08 010C4024 */ and $t0, $t0, $t4 +/* D3A0C 800D2E0C 01284825 */ or $t1, $t1, $t0 +.L800D2E10: +/* D3A10 800D2E10 AF490128 */ sw $t1, 0x128($k0) /* handwritten instruction */ +/* D3A14 800D2E14 40087000 */ mfc0 $t0, $14 /* handwritten instruction */ +/* D3A18 800D2E18 AF48011C */ sw $t0, 0x11C($k0) /* handwritten instruction */ +/* D3A1C 800D2E1C 8F480018 */ lw $t0, 0x18($k0) /* handwritten instruction */ +/* D3A20 800D2E20 11000014 */ beqz $t0, .L800D2E74 +/* D3A24 800D2E24 00000000 */ nop +/* D3A28 800D2E28 4448F800 */ cfc1 $t0, $31 +/* D3A2C 800D2E2C 00000000 */ nop +/* D3A30 800D2E30 AF48012C */ sw $t0, 0x12C($k0) /* handwritten instruction */ +/* D3A34 800D2E34 F7400130 */ sdc1 $f0, 0x130($k0) +/* D3A38 800D2E38 F7420138 */ sdc1 $f2, 0x138($k0) +/* D3A3C 800D2E3C F7440140 */ sdc1 $f4, 0x140($k0) +/* D3A40 800D2E40 F7460148 */ sdc1 $f6, 0x148($k0) +/* D3A44 800D2E44 F7480150 */ sdc1 $f8, 0x150($k0) +/* D3A48 800D2E48 F74A0158 */ sdc1 $f10, 0x158($k0) +/* D3A4C 800D2E4C F74C0160 */ sdc1 $f12, 0x160($k0) +/* D3A50 800D2E50 F74E0168 */ sdc1 $f14, 0x168($k0) +/* D3A54 800D2E54 F7500170 */ sdc1 $f16, 0x170($k0) +/* D3A58 800D2E58 F7520178 */ sdc1 $f18, 0x178($k0) +/* D3A5C 800D2E5C F7540180 */ sdc1 $f20, 0x180($k0) +/* D3A60 800D2E60 F7560188 */ sdc1 $f22, 0x188($k0) +/* D3A64 800D2E64 F7580190 */ sdc1 $f24, 0x190($k0) +/* D3A68 800D2E68 F75A0198 */ sdc1 $f26, 0x198($k0) +/* D3A6C 800D2E6C F75C01A0 */ sdc1 $f28, 0x1A0($k0) +/* D3A70 800D2E70 F75E01A8 */ sdc1 $f30, 0x1A8($k0) +.L800D2E74: +/* D3A74 800D2E74 40086800 */ mfc0 $t0, $13 /* handwritten instruction */ +/* D3A78 800D2E78 AF480120 */ sw $t0, 0x120($k0) /* handwritten instruction */ +/* D3A7C 800D2E7C 24090002 */ addiu $t1, $zero, 0x2 +/* D3A80 800D2E80 A7490010 */ sh $t1, 0x10($k0) /* handwritten instruction */ +/* D3A84 800D2E84 3109007C */ andi $t1, $t0, 0x7C +/* D3A88 800D2E88 240A0024 */ addiu $t2, $zero, 0x24 +/* D3A8C 800D2E8C 112A00B0 */ beq $t1, $t2, .L800D3150 +/* D3A90 800D2E90 00000000 */ nop +/* D3A94 800D2E94 240A002C */ addiu $t2, $zero, 0x2C +/* D3A98 800D2E98 112A00FF */ beq $t1, $t2, handle_CpU +/* D3A9C 800D2E9C 00000000 */ nop +/* D3AA0 800D2EA0 240A0000 */ addiu $t2, $zero, 0x0 +/* D3AA4 800D2EA4 152A00C3 */ bne $t1, $t2, .L800D31B4 +/* D3AA8 800D2EA8 00000000 */ nop +/* D3AAC 800D2EAC 03688024 */ and $s0, $k1, $t0 +.L800D2EB0: +/* D3AB0 800D2EB0 3209FF00 */ andi $t1, $s0, 0xFF00 +/* D3AB4 800D2EB4 00095302 */ srl $t2, $t1, 12 +/* D3AB8 800D2EB8 15400003 */ bnez $t2, .L800D2EC8 +/* D3ABC 800D2EBC 00000000 */ nop +/* D3AC0 800D2EC0 00095202 */ srl $t2, $t1, 8 +/* D3AC4 800D2EC4 214A0010 */ addi $t2, $t2, 0x10 /* handwritten instruction */ +.L800D2EC8: +/* D3AC8 800D2EC8 3C01800F */ lui $at, %hi(__osIntOffTable) +/* D3ACC 800D2ECC 002A0821 */ addu $at, $at, $t2 +/* D3AD0 800D2ED0 902A9670 */ lbu $t2, %lo(__osIntOffTable)($at) +/* D3AD4 800D2ED4 3C01800F */ lui $at, %hi(__osIntTable) +/* D3AD8 800D2ED8 002A0821 */ addu $at, $at, $t2 +/* D3ADC 800D2EDC 8C2A9690 */ lw $t2, %lo(__osIntTable)($at) +/* D3AE0 800D2EE0 01400008 */ jr $t2 +/* D3AE4 800D2EE4 00000000 */ nop +glabel .L800D2EE8 +/* D3AE8 800D2EE8 2401DFFF */ addiu $at, $zero, -0x2001 +/* D3AEC 800D2EEC 1000FFF0 */ b .L800D2EB0 +/* D3AF0 800D2EF0 02018024 */ and $s0, $s0, $at +glabel .L800D2EF4 +/* D3AF4 800D2EF4 2401BFFF */ addiu $at, $zero, -0x4001 +/* D3AF8 800D2EF8 1000FFED */ b .L800D2EB0 +/* D3AFC 800D2EFC 02018024 */ and $s0, $s0, $at +glabel .L800D2F00 +/* D3B00 800D2F00 40095800 */ mfc0 $t1, $11 /* handwritten instruction */ +/* D3B04 800D2F04 40895800 */ mtc0 $t1, $11 /* handwritten instruction */ +/* D3B08 800D2F08 0C034C79 */ jal send_mesg +/* D3B0C 800D2F0C 24040018 */ addiu $a0, $zero, 0x18 +/* D3B10 800D2F10 3C01FFFF */ lui $at, (0xFFFF7FFF >> 16) +/* D3B14 800D2F14 34217FFF */ ori $at, $at, (0xFFFF7FFF & 0xFFFF) +/* D3B18 800D2F18 1000FFE5 */ b .L800D2EB0 +/* D3B1C 800D2F1C 02018024 */ and $s0, $s0, $at +glabel .L800D2F20 +/* D3B20 800D2F20 2401F7FF */ addiu $at, $zero, -0x801 +/* D3B24 800D2F24 02018024 */ and $s0, $s0, $at +/* D3B28 800D2F28 240A0004 */ addiu $t2, $zero, 0x4 +/* D3B2C 800D2F2C 3C01800E */ lui $at, %hi(__osHwIntTable) +/* D3B30 800D2F30 002A0821 */ addu $at, $at, $t2 +/* D3B34 800D2F34 8C2A48A0 */ lw $t2, %lo(__osHwIntTable)($at) +/* D3B38 800D2F38 3C1D8013 */ lui $sp, %hi(leoDiskStack) +/* D3B3C 800D2F3C 27BDAAE0 */ addiu $sp, $sp, %lo(leoDiskStack) +/* D3B40 800D2F40 24040010 */ addiu $a0, $zero, 0x10 +/* D3B44 800D2F44 11400007 */ beqz $t2, .L800D2F64 +/* D3B48 800D2F48 27BD0FF0 */ addiu $sp, $sp, 0xFF0 +/* D3B4C 800D2F4C 0140F809 */ jalr $t2 +/* D3B50 800D2F50 00000000 */ nop +/* D3B54 800D2F54 10400003 */ beqz $v0, .L800D2F64 +/* D3B58 800D2F58 00000000 */ nop +/* D3B5C 800D2F5C 10000082 */ b .L800D3168 +/* D3B60 800D2F60 00000000 */ nop +.L800D2F64: +/* D3B64 800D2F64 0C034C79 */ jal send_mesg +/* D3B68 800D2F68 00000000 */ nop +/* D3B6C 800D2F6C 1000FFD0 */ b .L800D2EB0 +/* D3B70 800D2F70 00000000 */ nop +glabel .L800D2F74 +/* D3B74 800D2F74 3C08800E */ lui $t0, %hi(__OSGlobalIntMask) +/* D3B78 800D2F78 250838AC */ addiu $t0, $t0, %lo(__OSGlobalIntMask) +/* D3B7C 800D2F7C 8D080000 */ lw $t0, 0x0($t0) +/* D3B80 800D2F80 3C11A430 */ lui $s1, %hi(MI_INTR_REG) +/* D3B84 800D2F84 8E310008 */ lw $s1, %lo(MI_INTR_REG)($s1) +/* D3B88 800D2F88 00084402 */ srl $t0, $t0, 16 +/* D3B8C 800D2F8C 02288824 */ and $s1, $s1, $t0 +/* D3B90 800D2F90 32290001 */ andi $t1, $s1, 0x1 +/* D3B94 800D2F94 11200013 */ beqz $t1, .L800D2FE4 +/* D3B98 800D2F98 00000000 */ nop +/* D3B9C 800D2F9C 3C0CA404 */ lui $t4, %hi(SP_STATUS_REG) +/* D3BA0 800D2FA0 8D8C0010 */ lw $t4, %lo(SP_STATUS_REG)($t4) +/* D3BA4 800D2FA4 24090008 */ addiu $t1, $zero, 0x8 +/* D3BA8 800D2FA8 3C01A404 */ lui $at, %hi(SP_STATUS_REG) +/* D3BAC 800D2FAC 318C0300 */ andi $t4, $t4, 0x300 +/* D3BB0 800D2FB0 3231003E */ andi $s1, $s1, 0x3E +/* D3BB4 800D2FB4 11800007 */ beqz $t4, .L800D2FD4 +/* D3BB8 800D2FB8 AC290010 */ sw $t1, %lo(SP_STATUS_REG)($at) +/* D3BBC 800D2FBC 0C034C79 */ jal send_mesg +/* D3BC0 800D2FC0 24040020 */ addiu $a0, $zero, 0x20 +/* D3BC4 800D2FC4 12200038 */ beqz $s1, .L800D30A8 +/* D3BC8 800D2FC8 00000000 */ nop +/* D3BCC 800D2FCC 10000005 */ b .L800D2FE4 +/* D3BD0 800D2FD0 00000000 */ nop +.L800D2FD4: +/* D3BD4 800D2FD4 0C034C79 */ jal send_mesg +/* D3BD8 800D2FD8 24040058 */ addiu $a0, $zero, 0x58 +/* D3BDC 800D2FDC 12200032 */ beqz $s1, .L800D30A8 +/* D3BE0 800D2FE0 00000000 */ nop +.L800D2FE4: +/* D3BE4 800D2FE4 32290008 */ andi $t1, $s1, 0x8 +/* D3BE8 800D2FE8 11200007 */ beqz $t1, .L800D3008 +/* D3BEC 800D2FEC 3C01A440 */ lui $at, %hi(VI_V_CURRENT_LINE_REG) +/* D3BF0 800D2FF0 32310037 */ andi $s1, $s1, 0x37 +/* D3BF4 800D2FF4 AC200010 */ sw $zero, %lo(VI_V_CURRENT_LINE_REG)($at) +/* D3BF8 800D2FF8 0C034C79 */ jal send_mesg +/* D3BFC 800D2FFC 24040038 */ addiu $a0, $zero, 0x38 +/* D3C00 800D3000 12200029 */ beqz $s1, .L800D30A8 +/* D3C04 800D3004 00000000 */ nop +.L800D3008: +/* D3C08 800D3008 32290004 */ andi $t1, $s1, 0x4 +/* D3C0C 800D300C 11200009 */ beqz $t1, .L800D3034 +/* D3C10 800D3010 00000000 */ nop +/* D3C14 800D3014 24090001 */ addiu $t1, $zero, 0x1 +/* D3C18 800D3018 3C01A450 */ lui $at, %hi(AI_STATUS_REG) +/* D3C1C 800D301C 3231003B */ andi $s1, $s1, 0x3B +/* D3C20 800D3020 AC29000C */ sw $t1, %lo(AI_STATUS_REG)($at) +/* D3C24 800D3024 0C034C79 */ jal send_mesg +/* D3C28 800D3028 24040030 */ addiu $a0, $zero, 0x30 +/* D3C2C 800D302C 1220001E */ beqz $s1, .L800D30A8 +/* D3C30 800D3030 00000000 */ nop +.L800D3034: +/* D3C34 800D3034 32290002 */ andi $t1, $s1, 0x2 +/* D3C38 800D3038 11200007 */ beqz $t1, .L800D3058 +/* D3C3C 800D303C 3C01A480 */ lui $at, %hi(SI_STATUS_REG) +/* D3C40 800D3040 3231003D */ andi $s1, $s1, 0x3D +/* D3C44 800D3044 AC200018 */ sw $zero, %lo(SI_STATUS_REG)($at) +/* D3C48 800D3048 0C034C79 */ jal send_mesg +/* D3C4C 800D304C 24040028 */ addiu $a0, $zero, 0x28 +/* D3C50 800D3050 12200015 */ beqz $s1, .L800D30A8 +/* D3C54 800D3054 00000000 */ nop +.L800D3058: +/* D3C58 800D3058 32290010 */ andi $t1, $s1, 0x10 +/* D3C5C 800D305C 11200009 */ beqz $t1, .L800D3084 +/* D3C60 800D3060 00000000 */ nop +/* D3C64 800D3064 24090002 */ addiu $t1, $zero, 0x2 +/* D3C68 800D3068 3C01A460 */ lui $at, %hi(PI_STATUS_REG) +/* D3C6C 800D306C 3231002F */ andi $s1, $s1, 0x2F +/* D3C70 800D3070 AC290010 */ sw $t1, %lo(PI_STATUS_REG)($at) +/* D3C74 800D3074 0C034C79 */ jal send_mesg +/* D3C78 800D3078 24040040 */ addiu $a0, $zero, 0x40 +/* D3C7C 800D307C 1220000A */ beqz $s1, .L800D30A8 +/* D3C80 800D3080 00000000 */ nop +.L800D3084: +/* D3C84 800D3084 32290020 */ andi $t1, $s1, 0x20 +/* D3C88 800D3088 11200007 */ beqz $t1, .L800D30A8 +/* D3C8C 800D308C 00000000 */ nop +/* D3C90 800D3090 24090800 */ addiu $t1, $zero, 0x800 +/* D3C94 800D3094 3C01A430 */ lui $at, %hi(MI_MODE_REG) +/* D3C98 800D3098 3231001F */ andi $s1, $s1, 0x1F +/* D3C9C 800D309C AC290000 */ sw $t1, %lo(MI_MODE_REG)($at) +/* D3CA0 800D30A0 0C034C79 */ jal send_mesg +/* D3CA4 800D30A4 24040048 */ addiu $a0, $zero, 0x48 +.L800D30A8: +/* D3CA8 800D30A8 2401FBFF */ addiu $at, $zero, -0x401 +/* D3CAC 800D30AC 1000FF80 */ b .L800D2EB0 +/* D3CB0 800D30B0 02018024 */ and $s0, $s0, $at +glabel .L800D30B4 +/* D3CB4 800D30B4 8F5B0118 */ lw $k1, 0x118($k0) /* handwritten instruction */ +/* D3CB8 800D30B8 2401EFFF */ addiu $at, $zero, -0x1001 +/* D3CBC 800D30BC 3C09800E */ lui $t1, %hi(__osShutdown) +/* D3CC0 800D30C0 0361D824 */ and $k1, $k1, $at +/* D3CC4 800D30C4 AF5B0118 */ sw $k1, 0x118($k0) /* handwritten instruction */ +/* D3CC8 800D30C8 252938A8 */ addiu $t1, $t1, %lo(__osShutdown) +/* D3CCC 800D30CC 8D2A0000 */ lw $t2, 0x0($t1) +/* D3CD0 800D30D0 11400003 */ beqz $t2, .L800D30E0 +/* D3CD4 800D30D4 2401EFFF */ addiu $at, $zero, -0x1001 +/* D3CD8 800D30D8 10000023 */ b .L800D3168 +/* D3CDC 800D30DC 02018024 */ and $s0, $s0, $at +.L800D30E0: +/* D3CE0 800D30E0 240A0001 */ addiu $t2, $zero, 0x1 +/* D3CE4 800D30E4 AD2A0000 */ sw $t2, 0x0($t1) +/* D3CE8 800D30E8 0C034C79 */ jal send_mesg +/* D3CEC 800D30EC 24040070 */ addiu $a0, $zero, 0x70 +/* D3CF0 800D30F0 3C0A800E */ lui $t2, %hi(__osRunQueue) +/* D3CF4 800D30F4 8D4A4888 */ lw $t2, %lo(__osRunQueue)($t2) +/* D3CF8 800D30F8 2401EFFF */ addiu $at, $zero, -0x1001 +/* D3CFC 800D30FC 02018024 */ and $s0, $s0, $at +/* D3D00 800D3100 8D5B0118 */ lw $k1, 0x118($t2) /* handwritten instruction */ +/* D3D04 800D3104 0361D824 */ and $k1, $k1, $at +/* D3D08 800D3108 10000017 */ b .L800D3168 +/* D3D0C 800D310C AD5B0118 */ sw $k1, 0x118($t2) /* handwritten instruction */ +glabel .L800D3110 +/* D3D10 800D3110 2401FDFF */ addiu $at, $zero, -0x201 +/* D3D14 800D3114 01014024 */ and $t0, $t0, $at +/* D3D18 800D3118 40886800 */ mtc0 $t0, $13 /* handwritten instruction */ +/* D3D1C 800D311C 0C034C79 */ jal send_mesg +/* D3D20 800D3120 24040008 */ addiu $a0, $zero, 0x8 +/* D3D24 800D3124 2401FDFF */ addiu $at, $zero, -0x201 +/* D3D28 800D3128 1000FF61 */ b .L800D2EB0 +/* D3D2C 800D312C 02018024 */ and $s0, $s0, $at +glabel .L800D3130 +/* D3D30 800D3130 2401FEFF */ addiu $at, $zero, -0x101 +/* D3D34 800D3134 01014024 */ and $t0, $t0, $at +/* D3D38 800D3138 40886800 */ mtc0 $t0, $13 /* handwritten instruction */ +/* D3D3C 800D313C 0C034C79 */ jal send_mesg +/* D3D40 800D3140 24040000 */ addiu $a0, $zero, 0x0 +/* D3D44 800D3144 2401FEFF */ addiu $at, $zero, -0x101 +/* D3D48 800D3148 1000FF59 */ b .L800D2EB0 +/* D3D4C 800D314C 02018024 */ and $s0, $s0, $at +.L800D3150: +/* D3D50 800D3150 24090001 */ addiu $t1, $zero, 0x1 +/* D3D54 800D3154 A7490012 */ sh $t1, 0x12($k0) /* handwritten instruction */ +/* D3D58 800D3158 0C034C79 */ jal send_mesg +/* D3D5C 800D315C 24040050 */ addiu $a0, $zero, 0x50 +/* D3D60 800D3160 10000001 */ b .L800D3168 +/* D3D64 800D3164 00000000 */ nop +glabel .L800D3168 +/* D3D68 800D3168 3C0A800E */ lui $t2, %hi(__osRunQueue) +/* D3D6C 800D316C 8D4A4888 */ lw $t2, %lo(__osRunQueue)($t2) +/* D3D70 800D3170 8F490004 */ lw $t1, 0x4($k0) /* handwritten instruction */ +/* D3D74 800D3174 8D4B0004 */ lw $t3, 0x4($t2) +/* D3D78 800D3178 012B082A */ slt $at, $t1, $t3 +/* D3D7C 800D317C 10200007 */ beqz $at, .L800D319C +/* D3D80 800D3180 00000000 */ nop +/* D3D84 800D3184 3C04800E */ lui $a0, %hi(__osRunQueue) +/* D3D88 800D3188 03402825 */ or $a1, $k0, $zero +/* D3D8C 800D318C 0C034CF3 */ jal __osEnqueueThread +/* D3D90 800D3190 24844888 */ addiu $a0, $a0, %lo(__osRunQueue) +/* D3D94 800D3194 08034D09 */ j __osDispatchThread +/* D3D98 800D3198 00000000 */ nop +.L800D319C: +/* D3D9C 800D319C 3C09800E */ lui $t1, %hi(__osRunQueue) +/* D3DA0 800D31A0 25294888 */ addiu $t1, $t1, %lo(__osRunQueue) +/* D3DA4 800D31A4 8D2A0000 */ lw $t2, 0x0($t1) +/* D3DA8 800D31A8 AF4A0000 */ sw $t2, 0x0($k0) /* handwritten instruction */ +/* D3DAC 800D31AC 08034D09 */ j __osDispatchThread +/* D3DB0 800D31B0 AD3A0000 */ sw $k0, 0x0($t1) /* handwritten instruction */ +.L800D31B4: +/* D3DB4 800D31B4 3C01800E */ lui $at, %hi(__osFaultedThread) +/* D3DB8 800D31B8 AC3A4894 */ sw $k0, %lo(__osFaultedThread)($at) /* handwritten instruction */ +/* D3DBC 800D31BC 24090001 */ addiu $t1, $zero, 0x1 +/* D3DC0 800D31C0 A7490010 */ sh $t1, 0x10($k0) /* handwritten instruction */ +/* D3DC4 800D31C4 24090002 */ addiu $t1, $zero, 0x2 +/* D3DC8 800D31C8 A7490012 */ sh $t1, 0x12($k0) /* handwritten instruction */ +/* D3DCC 800D31CC 400A4000 */ mfc0 $t2, $8 /* handwritten instruction */ +/* D3DD0 800D31D0 AF4A0124 */ sw $t2, 0x124($k0) /* handwritten instruction */ +/* D3DD4 800D31D4 0C034C79 */ jal send_mesg +/* D3DD8 800D31D8 24040060 */ addiu $a0, $zero, 0x60 +/* D3DDC 800D31DC 08034D09 */ j __osDispatchThread +/* D3DE0 800D31E0 00000000 */ nop + +glabel send_mesg +/* D3DE4 800D31E4 3C0A8013 */ lui $t2, %hi(__osEventStateTab) +/* D3DE8 800D31E8 254ACCD0 */ addiu $t2, $t2, %lo(__osEventStateTab) +/* D3DEC 800D31EC 01445021 */ addu $t2, $t2, $a0 +/* D3DF0 800D31F0 8D490000 */ lw $t1, 0x0($t2) +/* D3DF4 800D31F4 03E09025 */ or $s2, $ra, $zero +/* D3DF8 800D31F8 11200025 */ beqz $t1, .L800D3290 +/* D3DFC 800D31FC 00000000 */ nop +/* D3E00 800D3200 8D2B0008 */ lw $t3, 0x8($t1) +/* D3E04 800D3204 8D2C0010 */ lw $t4, 0x10($t1) +/* D3E08 800D3208 016C082A */ slt $at, $t3, $t4 +/* D3E0C 800D320C 10200020 */ beqz $at, .L800D3290 +/* D3E10 800D3210 00000000 */ nop +/* D3E14 800D3214 8D2D000C */ lw $t5, 0xC($t1) +/* D3E18 800D3218 01AB6821 */ addu $t5, $t5, $t3 +/* D3E1C 800D321C 01AC001A */ div $zero, $t5, $t4 +/* D3E20 800D3220 15800002 */ bnez $t4, .L800D322C +/* D3E24 800D3224 00000000 */ nop +/* D3E28 800D3228 0007000D */ break 7 +.L800D322C: +/* D3E2C 800D322C 2401FFFF */ addiu $at, $zero, -0x1 +/* D3E30 800D3230 15810004 */ bne $t4, $at, .L800D3244 +/* D3E34 800D3234 3C018000 */ lui $at, (0x80000000 >> 16) +/* D3E38 800D3238 15A10002 */ bne $t5, $at, .L800D3244 +/* D3E3C 800D323C 00000000 */ nop +/* D3E40 800D3240 0006000D */ break 6 +.L800D3244: +/* D3E44 800D3244 8D2C0014 */ lw $t4, 0x14($t1) +/* D3E48 800D3248 00006810 */ mfhi $t5 +/* D3E4C 800D324C 000D6880 */ sll $t5, $t5, 2 +/* D3E50 800D3250 018D6021 */ addu $t4, $t4, $t5 +/* D3E54 800D3254 8D4D0004 */ lw $t5, 0x4($t2) +/* D3E58 800D3258 256A0001 */ addiu $t2, $t3, 0x1 +/* D3E5C 800D325C AD8D0000 */ sw $t5, 0x0($t4) +/* D3E60 800D3260 AD2A0008 */ sw $t2, 0x8($t1) +/* D3E64 800D3264 8D2A0000 */ lw $t2, 0x0($t1) +/* D3E68 800D3268 8D4B0000 */ lw $t3, 0x0($t2) +/* D3E6C 800D326C 11600008 */ beqz $t3, .L800D3290 +/* D3E70 800D3270 00000000 */ nop +/* D3E74 800D3274 0C034D05 */ jal __osPopThread +/* D3E78 800D3278 01202025 */ or $a0, $t1, $zero +/* D3E7C 800D327C 00405025 */ or $t2, $v0, $zero +/* D3E80 800D3280 3C04800E */ lui $a0, %hi(__osRunQueue) +/* D3E84 800D3284 01402825 */ or $a1, $t2, $zero +/* D3E88 800D3288 0C034CF3 */ jal __osEnqueueThread +/* D3E8C 800D328C 24844888 */ addiu $a0, $a0, %lo(__osRunQueue) +.L800D3290: +/* D3E90 800D3290 02400008 */ jr $s2 +/* D3E94 800D3294 00000000 */ nop + +/* Handwritten function */ +glabel handle_CpU +/* D3E98 800D3298 3C013000 */ lui $at, (0x30000000 >> 16) +/* D3E9C 800D329C 01014824 */ and $t1, $t0, $at +/* D3EA0 800D32A0 00094F02 */ srl $t1, $t1, 28 +/* D3EA4 800D32A4 240A0001 */ addiu $t2, $zero, 0x1 +/* D3EA8 800D32A8 152AFFC2 */ bne $t1, $t2, .L800D31B4 +/* D3EAC 800D32AC 00000000 */ nop +/* D3EB0 800D32B0 8F5B0118 */ lw $k1, 0x118($k0) /* handwritten instruction */ +/* D3EB4 800D32B4 3C012000 */ lui $at, (0x20000000 >> 16) +/* D3EB8 800D32B8 24090001 */ addiu $t1, $zero, 0x1 +/* D3EBC 800D32BC 0361D825 */ or $k1, $k1, $at +/* D3EC0 800D32C0 AF490018 */ sw $t1, 0x18($k0) /* handwritten instruction */ +/* D3EC4 800D32C4 1000FFB5 */ b .L800D319C +/* D3EC8 800D32C8 AF5B0118 */ sw $k1, 0x118($k0) /* handwritten instruction */ + +/* Handwritten function */ +glabel __osEnqueueAndYield +/* D3ECC 800D32CC 3C05800E */ lui $a1, %hi(__osRunningThread) +/* D3ED0 800D32D0 8CA54890 */ lw $a1, %lo(__osRunningThread)($a1) +/* D3ED4 800D32D4 40086000 */ mfc0 $t0, $12 /* handwritten instruction */ +/* D3ED8 800D32D8 8CBB0018 */ lw $k1, 0x18($a1) /* handwritten instruction */ +/* D3EDC 800D32DC 35080002 */ ori $t0, $t0, 0x2 +/* D3EE0 800D32E0 ACA80118 */ sw $t0, 0x118($a1) +/* D3EE4 800D32E4 FCB00098 */ sd $s0, 0x98($a1) +/* D3EE8 800D32E8 FCB100A0 */ sd $s1, 0xA0($a1) +/* D3EEC 800D32EC FCB200A8 */ sd $s2, 0xA8($a1) +/* D3EF0 800D32F0 FCB300B0 */ sd $s3, 0xB0($a1) +/* D3EF4 800D32F4 FCB400B8 */ sd $s4, 0xB8($a1) +/* D3EF8 800D32F8 FCB500C0 */ sd $s5, 0xC0($a1) +/* D3EFC 800D32FC FCB600C8 */ sd $s6, 0xC8($a1) +/* D3F00 800D3300 FCB700D0 */ sd $s7, 0xD0($a1) +/* D3F04 800D3304 FCBC00E8 */ sd $gp, 0xE8($a1) +/* D3F08 800D3308 FCBD00F0 */ sd $sp, 0xF0($a1) +/* D3F0C 800D330C FCBE00F8 */ sd $fp, 0xF8($a1) +/* D3F10 800D3310 FCBF0100 */ sd $ra, 0x100($a1) +/* D3F14 800D3314 13600009 */ beqz $k1, .L800D333C /* handwritten instruction */ +/* D3F18 800D3318 ACBF011C */ sw $ra, 0x11C($a1) +/* D3F1C 800D331C 445BF800 */ cfc1 $k1, $31 +/* D3F20 800D3320 F4B40180 */ sdc1 $f20, 0x180($a1) +/* D3F24 800D3324 F4B60188 */ sdc1 $f22, 0x188($a1) +/* D3F28 800D3328 F4B80190 */ sdc1 $f24, 0x190($a1) +/* D3F2C 800D332C F4BA0198 */ sdc1 $f26, 0x198($a1) +/* D3F30 800D3330 F4BC01A0 */ sdc1 $f28, 0x1A0($a1) +/* D3F34 800D3334 F4BE01A8 */ sdc1 $f30, 0x1A8($a1) +/* D3F38 800D3338 ACBB012C */ sw $k1, 0x12C($a1) /* handwritten instruction */ +.L800D333C: +/* D3F3C 800D333C 8CBB0118 */ lw $k1, 0x118($a1) /* handwritten instruction */ +/* D3F40 800D3340 3369FF00 */ andi $t1, $k1, 0xFF00 /* handwritten instruction */ +/* D3F44 800D3344 1120000D */ beqz $t1, .L800D337C +/* D3F48 800D3348 00000000 */ nop +/* D3F4C 800D334C 3C08800E */ lui $t0, %hi(__OSGlobalIntMask) +/* D3F50 800D3350 250838AC */ addiu $t0, $t0, %lo(__OSGlobalIntMask) +/* D3F54 800D3354 8D080000 */ lw $t0, 0x0($t0) +/* D3F58 800D3358 2401FFFF */ addiu $at, $zero, -0x1 +/* D3F5C 800D335C 01014026 */ xor $t0, $t0, $at +/* D3F60 800D3360 3C01FFFF */ lui $at, (0xFFFF00FF >> 16) +/* D3F64 800D3364 3108FF00 */ andi $t0, $t0, 0xFF00 +/* D3F68 800D3368 342100FF */ ori $at, $at, (0xFFFF00FF & 0xFFFF) +/* D3F6C 800D336C 01284825 */ or $t1, $t1, $t0 +/* D3F70 800D3370 0361D824 */ and $k1, $k1, $at +/* D3F74 800D3374 0369D825 */ or $k1, $k1, $t1 +/* D3F78 800D3378 ACBB0118 */ sw $k1, 0x118($a1) /* handwritten instruction */ +.L800D337C: +/* D3F7C 800D337C 3C1BA430 */ lui $k1, %hi(MI_INTR_MASK_REG) /* handwritten instruction */ +/* D3F80 800D3380 8F7B000C */ lw $k1, %lo(MI_INTR_MASK_REG)($k1) /* handwritten instruction */ +/* D3F84 800D3384 1360000B */ beqz $k1, .L800D33B4 /* handwritten instruction */ +/* D3F88 800D3388 00000000 */ nop +/* D3F8C 800D338C 3C1A800E */ lui $k0, %hi(__OSGlobalIntMask) /* handwritten instruction */ +/* D3F90 800D3390 275A38AC */ addiu $k0, $k0, %lo(__OSGlobalIntMask) /* handwritten instruction */ +/* D3F94 800D3394 8F5A0000 */ lw $k0, 0x0($k0) /* handwritten instruction */ +/* D3F98 800D3398 8CA80128 */ lw $t0, 0x128($a1) +/* D3F9C 800D339C 2401FFFF */ addiu $at, $zero, -0x1 +/* D3FA0 800D33A0 001AD402 */ srl $k0, $k0, 16 +/* D3FA4 800D33A4 0341D026 */ xor $k0, $k0, $at +/* D3FA8 800D33A8 335A003F */ andi $k0, $k0, 0x3F /* handwritten instruction */ +/* D3FAC 800D33AC 0348D024 */ and $k0, $k0, $t0 +/* D3FB0 800D33B0 037AD825 */ or $k1, $k1, $k0 +.L800D33B4: +/* D3FB4 800D33B4 10800003 */ beqz $a0, .L800D33C4 +/* D3FB8 800D33B8 ACBB0128 */ sw $k1, 0x128($a1) /* handwritten instruction */ +/* D3FBC 800D33BC 0C034CF3 */ jal __osEnqueueThread +/* D3FC0 800D33C0 00000000 */ nop +.L800D33C4: +/* D3FC4 800D33C4 08034D09 */ j __osDispatchThread +/* D3FC8 800D33C8 00000000 */ nop + +glabel __osEnqueueThread +/* D3FCC 800D33CC 8C980000 */ lw $t8, 0x0($a0) +/* D3FD0 800D33D0 8CAF0004 */ lw $t7, 0x4($a1) +/* D3FD4 800D33D4 0080C825 */ or $t9, $a0, $zero +/* D3FD8 800D33D8 8F0E0004 */ lw $t6, 0x4($t8) +/* D3FDC 800D33DC 01CF082A */ slt $at, $t6, $t7 +/* D3FE0 800D33E0 14200007 */ bnez $at, .L800D3400 +/* D3FE4 800D33E4 00000000 */ nop +.L800D33E8: +/* D3FE8 800D33E8 0300C825 */ or $t9, $t8, $zero +/* D3FEC 800D33EC 8F180000 */ lw $t8, 0x0($t8) +/* D3FF0 800D33F0 8F0E0004 */ lw $t6, 0x4($t8) +/* D3FF4 800D33F4 01CF082A */ slt $at, $t6, $t7 +/* D3FF8 800D33F8 1020FFFB */ beqz $at, .L800D33E8 +/* D3FFC 800D33FC 00000000 */ nop +.L800D3400: +/* D4000 800D3400 8F380000 */ lw $t8, 0x0($t9) +/* D4004 800D3404 ACB80000 */ sw $t8, 0x0($a1) +/* D4008 800D3408 AF250000 */ sw $a1, 0x0($t9) +/* D400C 800D340C 03E00008 */ jr $ra +/* D4010 800D3410 ACA40008 */ sw $a0, 0x8($a1) + +glabel __osPopThread +/* D4014 800D3414 8C820000 */ lw $v0, 0x0($a0) +/* D4018 800D3418 8C590000 */ lw $t9, 0x0($v0) +/* D401C 800D341C 03E00008 */ jr $ra +/* D4020 800D3420 AC990000 */ sw $t9, 0x0($a0) + +/* Handwritten function */ +glabel __osDispatchThread +/* D4024 800D3424 3C04800E */ lui $a0, %hi(__osRunQueue) +/* D4028 800D3428 0C034D05 */ jal __osPopThread +/* D402C 800D342C 24844888 */ addiu $a0, $a0, %lo(__osRunQueue) +/* D4030 800D3430 3C01800E */ lui $at, %hi(__osRunningThread) +/* D4034 800D3434 AC224890 */ sw $v0, %lo(__osRunningThread)($at) +/* D4038 800D3438 24080004 */ addiu $t0, $zero, 0x4 +/* D403C 800D343C A4480010 */ sh $t0, 0x10($v0) +/* D4040 800D3440 0040D025 */ or $k0, $v0, $zero +/* D4044 800D3444 3C08800E */ lui $t0, %hi(__OSGlobalIntMask) +/* D4048 800D3448 8F5B0118 */ lw $k1, 0x118($k0) /* handwritten instruction */ +/* D404C 800D344C 250838AC */ addiu $t0, $t0, %lo(__OSGlobalIntMask) +/* D4050 800D3450 8D080000 */ lw $t0, 0x0($t0) +/* D4054 800D3454 3C01FFFF */ lui $at, (0xFFFF00FF >> 16) +/* D4058 800D3458 3369FF00 */ andi $t1, $k1, 0xFF00 /* handwritten instruction */ +/* D405C 800D345C 342100FF */ ori $at, $at, (0xFFFF00FF & 0xFFFF) +/* D4060 800D3460 3108FF00 */ andi $t0, $t0, 0xFF00 +/* D4064 800D3464 01284824 */ and $t1, $t1, $t0 +/* D4068 800D3468 0361D824 */ and $k1, $k1, $at +/* D406C 800D346C 0369D825 */ or $k1, $k1, $t1 +/* D4070 800D3470 409B6000 */ mtc0 $k1, $12 /* handwritten instruction */ +/* D4074 800D3474 DF5B0108 */ ld $k1, 0x108($k0) /* handwritten instruction */ +/* D4078 800D3478 DF410020 */ ld $at, 0x20($k0) /* handwritten instruction */ +/* D407C 800D347C DF420028 */ ld $v0, 0x28($k0) /* handwritten instruction */ +/* D4080 800D3480 03600013 */ mtlo $k1 +/* D4084 800D3484 DF5B0110 */ ld $k1, 0x110($k0) /* handwritten instruction */ +/* D4088 800D3488 DF430030 */ ld $v1, 0x30($k0) /* handwritten instruction */ +/* D408C 800D348C DF440038 */ ld $a0, 0x38($k0) /* handwritten instruction */ +/* D4090 800D3490 DF450040 */ ld $a1, 0x40($k0) /* handwritten instruction */ +/* D4094 800D3494 DF460048 */ ld $a2, 0x48($k0) /* handwritten instruction */ +/* D4098 800D3498 DF470050 */ ld $a3, 0x50($k0) /* handwritten instruction */ +/* D409C 800D349C DF480058 */ ld $t0, 0x58($k0) /* handwritten instruction */ +/* D40A0 800D34A0 DF490060 */ ld $t1, 0x60($k0) /* handwritten instruction */ +/* D40A4 800D34A4 DF4A0068 */ ld $t2, 0x68($k0) /* handwritten instruction */ +/* D40A8 800D34A8 DF4B0070 */ ld $t3, 0x70($k0) /* handwritten instruction */ +/* D40AC 800D34AC DF4C0078 */ ld $t4, 0x78($k0) /* handwritten instruction */ +/* D40B0 800D34B0 DF4D0080 */ ld $t5, 0x80($k0) /* handwritten instruction */ +/* D40B4 800D34B4 DF4E0088 */ ld $t6, 0x88($k0) /* handwritten instruction */ +/* D40B8 800D34B8 DF4F0090 */ ld $t7, 0x90($k0) /* handwritten instruction */ +/* D40BC 800D34BC DF500098 */ ld $s0, 0x98($k0) /* handwritten instruction */ +/* D40C0 800D34C0 DF5100A0 */ ld $s1, 0xA0($k0) /* handwritten instruction */ +/* D40C4 800D34C4 DF5200A8 */ ld $s2, 0xA8($k0) /* handwritten instruction */ +/* D40C8 800D34C8 DF5300B0 */ ld $s3, 0xB0($k0) /* handwritten instruction */ +/* D40CC 800D34CC DF5400B8 */ ld $s4, 0xB8($k0) /* handwritten instruction */ +/* D40D0 800D34D0 DF5500C0 */ ld $s5, 0xC0($k0) /* handwritten instruction */ +/* D40D4 800D34D4 DF5600C8 */ ld $s6, 0xC8($k0) /* handwritten instruction */ +/* D40D8 800D34D8 DF5700D0 */ ld $s7, 0xD0($k0) /* handwritten instruction */ +/* D40DC 800D34DC DF5800D8 */ ld $t8, 0xD8($k0) /* handwritten instruction */ +/* D40E0 800D34E0 DF5900E0 */ ld $t9, 0xE0($k0) /* handwritten instruction */ +/* D40E4 800D34E4 DF5C00E8 */ ld $gp, 0xE8($k0) /* handwritten instruction */ +/* D40E8 800D34E8 03600011 */ mthi $k1 +/* D40EC 800D34EC DF5D00F0 */ ld $sp, 0xF0($k0) /* handwritten instruction */ +/* D40F0 800D34F0 DF5E00F8 */ ld $fp, 0xF8($k0) /* handwritten instruction */ +/* D40F4 800D34F4 DF5F0100 */ ld $ra, 0x100($k0) /* handwritten instruction */ +/* D40F8 800D34F8 8F5B011C */ lw $k1, 0x11C($k0) /* handwritten instruction */ +/* D40FC 800D34FC 409B7000 */ mtc0 $k1, $14 /* handwritten instruction */ +/* D4100 800D3500 8F5B0018 */ lw $k1, 0x18($k0) /* handwritten instruction */ +/* D4104 800D3504 13600013 */ beqz $k1, .L800D3554 /* handwritten instruction */ +/* D4108 800D3508 00000000 */ nop +/* D410C 800D350C 8F5B012C */ lw $k1, 0x12C($k0) /* handwritten instruction */ +/* D4110 800D3510 44DBF800 */ ctc1 $k1, $31 +/* D4114 800D3514 D7400130 */ ldc1 $f0, 0x130($k0) +/* D4118 800D3518 D7420138 */ ldc1 $f2, 0x138($k0) +/* D411C 800D351C D7440140 */ ldc1 $f4, 0x140($k0) +/* D4120 800D3520 D7460148 */ ldc1 $f6, 0x148($k0) +/* D4124 800D3524 D7480150 */ ldc1 $f8, 0x150($k0) +/* D4128 800D3528 D74A0158 */ ldc1 $f10, 0x158($k0) +/* D412C 800D352C D74C0160 */ ldc1 $f12, 0x160($k0) +/* D4130 800D3530 D74E0168 */ ldc1 $f14, 0x168($k0) +/* D4134 800D3534 D7500170 */ ldc1 $f16, 0x170($k0) +/* D4138 800D3538 D7520178 */ ldc1 $f18, 0x178($k0) +/* D413C 800D353C D7540180 */ ldc1 $f20, 0x180($k0) +/* D4140 800D3540 D7560188 */ ldc1 $f22, 0x188($k0) +/* D4144 800D3544 D7580190 */ ldc1 $f24, 0x190($k0) +/* D4148 800D3548 D75A0198 */ ldc1 $f26, 0x198($k0) +/* D414C 800D354C D75C01A0 */ ldc1 $f28, 0x1A0($k0) +/* D4150 800D3550 D75E01A8 */ ldc1 $f30, 0x1A8($k0) +.L800D3554: +/* D4154 800D3554 8F5B0128 */ lw $k1, 0x128($k0) /* handwritten instruction */ +/* D4158 800D3558 3C1A800E */ lui $k0, %hi(__OSGlobalIntMask) /* handwritten instruction */ +/* D415C 800D355C 275A38AC */ addiu $k0, $k0, %lo(__OSGlobalIntMask) /* handwritten instruction */ +/* D4160 800D3560 8F5A0000 */ lw $k0, 0x0($k0) /* handwritten instruction */ +/* D4164 800D3564 001AD402 */ srl $k0, $k0, 16 +/* D4168 800D3568 037AD824 */ and $k1, $k1, $k0 +/* D416C 800D356C 001BD840 */ sll $k1, $k1, 1 +/* D4170 800D3570 3C1A800F */ lui $k0, %hi(__osRcpImTable) /* handwritten instruction */ +/* D4174 800D3574 275A94D0 */ addiu $k0, $k0, %lo(__osRcpImTable) /* handwritten instruction */ +/* D4178 800D3578 037AD821 */ addu $k1, $k1, $k0 +/* D417C 800D357C 977B0000 */ lhu $k1, 0x0($k1) /* handwritten instruction */ +/* D4180 800D3580 3C1AA430 */ lui $k0, %hi(MI_INTR_MASK_REG) /* handwritten instruction */ +/* D4184 800D3584 275A000C */ addiu $k0, $k0, %lo(MI_INTR_MASK_REG) /* handwritten instruction */ +/* D4188 800D3588 AF5B0000 */ sw $k1, 0x0($k0) /* handwritten instruction */ +/* D418C 800D358C 00000000 */ nop +/* D4190 800D3590 00000000 */ nop +/* D4194 800D3594 00000000 */ nop +/* D4198 800D3598 00000000 */ nop +/* D419C 800D359C 42000018 */ eret /* handwritten instruction */ + +glabel __osCleanupThread +/* D41A0 800D35A0 0C035980 */ jal osDestroyThread +/* D41A4 800D35A4 00002025 */ or $a0, $zero, $zero +/* D41A8 800D35A8 00000000 */ nop +/* D41AC 800D35AC 00000000 */ nop diff --git a/lib/asm/exception.s b/lib/asm/exception.s deleted file mode 100644 index c3b4b52d..00000000 --- a/lib/asm/exception.s +++ /dev/null @@ -1,17 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D2CB0 */ - -.include "macros.inc" - -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used - -.include "lib/asm/exception/__osExceptionPreamble.s" -.include "lib/asm/exception/__osException.s" -.include "lib/asm/exception/send_mesg.s" -.include "lib/asm/exception/__osEnqueueAndYield.s" -.include "lib/asm/exception/__osEnqueueThread.s" -.include "lib/asm/exception/__osPopThread.s" -.include "lib/asm/exception/__osDispatchThread.s" -.include "lib/asm/exception/__osCleanupThread.s" diff --git a/lib/asm/exception/__osCleanupThread.s b/lib/asm/exception/__osCleanupThread.s deleted file mode 100644 index 686faede..00000000 --- a/lib/asm/exception/__osCleanupThread.s +++ /dev/null @@ -1,5 +0,0 @@ -glabel __osCleanupThread -/* 0D41A0 800D35A0 0C035980 */ jal osDestroyThread -/* 0D41A4 800D35A4 00002025 */ move $a0, $zero -/* 0D41A8 800D35A8 00000000 */ nop -/* 0D41AC 800D35AC 00000000 */ nop diff --git a/lib/asm/exception/__osDispatchThread.s b/lib/asm/exception/__osDispatchThread.s deleted file mode 100644 index 8acbcb76..00000000 --- a/lib/asm/exception/__osDispatchThread.s +++ /dev/null @@ -1,97 +0,0 @@ -glabel __osDispatchThread -/* 0D4024 800D3424 3C04800E */ lui $a0, %hi(__osRunQueue) # $a0, 0x800e -/* 0D4028 800D3428 0C034D05 */ jal __osPopThread -/* 0D402C 800D342C 24844888 */ addiu $a0, %lo(__osRunQueue) # addiu $a0, $a0, 0x4888 -/* 0D4030 800D3430 3C01800E */ lui $at, %hi(__osRunningThread) # $at, 0x800e -/* 0D4034 800D3434 AC224890 */ sw $v0, %lo(__osRunningThread)($at) -/* 0D4038 800D3438 24080004 */ li $t0, 4 -/* 0D403C 800D343C A4480010 */ sh $t0, 0x10($v0) -/* 0D4040 800D3440 0040D025 */ move $k0, $v0 -/* 0D4044 800D3444 3C08800E */ lui $t0, %hi(__OSGlobalIntMask) # $t0, 0x800e -/* 0D4048 800D3448 8F5B0118 */ lw $k1, 0x118($k0) -/* 0D404C 800D344C 250838AC */ addiu $t0, %lo(__OSGlobalIntMask) # addiu $t0, $t0, 0x38ac -/* 0D4050 800D3450 8D080000 */ lw $t0, ($t0) -/* 0D4054 800D3454 3C01FFFF */ lui $at, (0xFFFF00FF >> 16) # lui $at, 0xffff -/* 0D4058 800D3458 3369FF00 */ andi $t1, $k1, 0xff00 -/* 0D405C 800D345C 342100FF */ ori $at, (0xFFFF00FF & 0xFFFF) # ori $at, $at, 0xff -/* 0D4060 800D3460 3108FF00 */ andi $t0, $t0, 0xff00 -/* 0D4064 800D3464 01284824 */ and $t1, $t1, $t0 -/* 0D4068 800D3468 0361D824 */ and $k1, $k1, $at -/* 0D406C 800D346C 0369D825 */ or $k1, $k1, $t1 -/* 0D4070 800D3470 409B6000 */ mtc0 $k1, $12 -/* 0D4074 800D3474 DF5B0108 */ ld $k1, 0x108($k0) -/* 0D4078 800D3478 DF410020 */ ld $at, 0x20($k0) -/* 0D407C 800D347C DF420028 */ ld $v0, 0x28($k0) -/* 0D4080 800D3480 03600013 */ mtlo $k1 -/* 0D4084 800D3484 DF5B0110 */ ld $k1, 0x110($k0) -/* 0D4088 800D3488 DF430030 */ ld $v1, 0x30($k0) -/* 0D408C 800D348C DF440038 */ ld $a0, 0x38($k0) -/* 0D4090 800D3490 DF450040 */ ld $a1, 0x40($k0) -/* 0D4094 800D3494 DF460048 */ ld $a2, 0x48($k0) -/* 0D4098 800D3498 DF470050 */ ld $a3, 0x50($k0) -/* 0D409C 800D349C DF480058 */ ld $t0, 0x58($k0) -/* 0D40A0 800D34A0 DF490060 */ ld $t1, 0x60($k0) -/* 0D40A4 800D34A4 DF4A0068 */ ld $t2, 0x68($k0) -/* 0D40A8 800D34A8 DF4B0070 */ ld $t3, 0x70($k0) -/* 0D40AC 800D34AC DF4C0078 */ ld $t4, 0x78($k0) -/* 0D40B0 800D34B0 DF4D0080 */ ld $t5, 0x80($k0) -/* 0D40B4 800D34B4 DF4E0088 */ ld $t6, 0x88($k0) -/* 0D40B8 800D34B8 DF4F0090 */ ld $t7, 0x90($k0) -/* 0D40BC 800D34BC DF500098 */ ld $s0, 0x98($k0) -/* 0D40C0 800D34C0 DF5100A0 */ ld $s1, 0xa0($k0) -/* 0D40C4 800D34C4 DF5200A8 */ ld $s2, 0xa8($k0) -/* 0D40C8 800D34C8 DF5300B0 */ ld $s3, 0xb0($k0) -/* 0D40CC 800D34CC DF5400B8 */ ld $s4, 0xb8($k0) -/* 0D40D0 800D34D0 DF5500C0 */ ld $s5, 0xc0($k0) -/* 0D40D4 800D34D4 DF5600C8 */ ld $s6, 0xc8($k0) -/* 0D40D8 800D34D8 DF5700D0 */ ld $s7, 0xd0($k0) -/* 0D40DC 800D34DC DF5800D8 */ ld $t8, 0xd8($k0) -/* 0D40E0 800D34E0 DF5900E0 */ ld $t9, 0xe0($k0) -/* 0D40E4 800D34E4 DF5C00E8 */ ld $gp, 0xe8($k0) -/* 0D40E8 800D34E8 03600011 */ mthi $k1 -/* 0D40EC 800D34EC DF5D00F0 */ ld $sp, 0xf0($k0) -/* 0D40F0 800D34F0 DF5E00F8 */ ld $fp, 0xf8($k0) -/* 0D40F4 800D34F4 DF5F0100 */ ld $ra, 0x100($k0) -/* 0D40F8 800D34F8 8F5B011C */ lw $k1, 0x11c($k0) -/* 0D40FC 800D34FC 409B7000 */ mtc0 $k1, $14 -/* 0D4100 800D3500 8F5B0018 */ lw $k1, 0x18($k0) -/* 0D4104 800D3504 13600013 */ beqz $k1, .L800D3554 -/* 0D4108 800D3508 00000000 */ nop -/* 0D410C 800D350C 8F5B012C */ lw $k1, 0x12c($k0) -/* 0D4110 800D3510 44DBF800 */ ctc1 $k1, $31 -/* 0D4114 800D3514 D7400130 */ ldc1 $f0, 0x130($k0) -/* 0D4118 800D3518 D7420138 */ ldc1 $f2, 0x138($k0) -/* 0D411C 800D351C D7440140 */ ldc1 $f4, 0x140($k0) -/* 0D4120 800D3520 D7460148 */ ldc1 $f6, 0x148($k0) -/* 0D4124 800D3524 D7480150 */ ldc1 $f8, 0x150($k0) -/* 0D4128 800D3528 D74A0158 */ ldc1 $f10, 0x158($k0) -/* 0D412C 800D352C D74C0160 */ ldc1 $f12, 0x160($k0) -/* 0D4130 800D3530 D74E0168 */ ldc1 $f14, 0x168($k0) -/* 0D4134 800D3534 D7500170 */ ldc1 $f16, 0x170($k0) -/* 0D4138 800D3538 D7520178 */ ldc1 $f18, 0x178($k0) -/* 0D413C 800D353C D7540180 */ ldc1 $f20, 0x180($k0) -/* 0D4140 800D3540 D7560188 */ ldc1 $f22, 0x188($k0) -/* 0D4144 800D3544 D7580190 */ ldc1 $f24, 0x190($k0) -/* 0D4148 800D3548 D75A0198 */ ldc1 $f26, 0x198($k0) -/* 0D414C 800D354C D75C01A0 */ ldc1 $f28, 0x1a0($k0) -/* 0D4150 800D3550 D75E01A8 */ ldc1 $f30, 0x1a8($k0) -.L800D3554: -/* 0D4154 800D3554 8F5B0128 */ lw $k1, 0x128($k0) -/* 0D4158 800D3558 3C1A800E */ lui $k0, %hi(__OSGlobalIntMask) # $k0, 0x800e -/* 0D415C 800D355C 275A38AC */ addiu $k0, %lo(__OSGlobalIntMask) # addiu $k0, $k0, 0x38ac -/* 0D4160 800D3560 8F5A0000 */ lw $k0, ($k0) -/* 0D4164 800D3564 001AD402 */ srl $k0, $k0, 0x10 -/* 0D4168 800D3568 037AD824 */ and $k1, $k1, $k0 -/* 0D416C 800D356C 001BD840 */ sll $k1, $k1, 1 -/* 0D4170 800D3570 3C1A800F */ lui $k0, %hi(__osRcpImTable) # $k0, 0x800f -/* 0D4174 800D3574 275A94D0 */ addiu $k0, %lo(__osRcpImTable) # addiu $k0, $k0, -0x6b30 -/* 0D4178 800D3578 037AD821 */ addu $k1, $k1, $k0 -/* 0D417C 800D357C 977B0000 */ lhu $k1, ($k1) -/* 0D4180 800D3580 3C1AA430 */ lui $k0, %hi(MI_INTR_MASK_REG) # $k0, 0xa430 -/* 0D4184 800D3584 275A000C */ addiu $k0, %lo(MI_INTR_MASK_REG) # addiu $k0, $k0, 0xc -/* 0D4188 800D3588 AF5B0000 */ sw $k1, ($k0) -/* 0D418C 800D358C 00000000 */ nop -/* 0D4190 800D3590 00000000 */ nop -/* 0D4194 800D3594 00000000 */ nop -/* 0D4198 800D3598 00000000 */ nop -/* 0D419C 800D359C 42000018 */ eret diff --git a/lib/asm/exception/__osEnqueueAndYield.s b/lib/asm/exception/__osEnqueueAndYield.s deleted file mode 100644 index 3a5bef63..00000000 --- a/lib/asm/exception/__osEnqueueAndYield.s +++ /dev/null @@ -1,70 +0,0 @@ -glabel __osEnqueueAndYield -/* 0D3ECC 800D32CC 3C05800E */ lui $a1, %hi(__osRunningThread) # $a1, 0x800e -/* 0D3ED0 800D32D0 8CA54890 */ lw $a1, %lo(__osRunningThread)($a1) -/* 0D3ED4 800D32D4 40086000 */ mfc0 $t0, $12 -/* 0D3ED8 800D32D8 8CBB0018 */ lw $k1, 0x18($a1) -/* 0D3EDC 800D32DC 35080002 */ ori $t0, $t0, 2 -/* 0D3EE0 800D32E0 ACA80118 */ sw $t0, 0x118($a1) -/* 0D3EE4 800D32E4 FCB00098 */ sd $s0, 0x98($a1) -/* 0D3EE8 800D32E8 FCB100A0 */ sd $s1, 0xa0($a1) -/* 0D3EEC 800D32EC FCB200A8 */ sd $s2, 0xa8($a1) -/* 0D3EF0 800D32F0 FCB300B0 */ sd $s3, 0xb0($a1) -/* 0D3EF4 800D32F4 FCB400B8 */ sd $s4, 0xb8($a1) -/* 0D3EF8 800D32F8 FCB500C0 */ sd $s5, 0xc0($a1) -/* 0D3EFC 800D32FC FCB600C8 */ sd $s6, 0xc8($a1) -/* 0D3F00 800D3300 FCB700D0 */ sd $s7, 0xd0($a1) -/* 0D3F04 800D3304 FCBC00E8 */ sd $gp, 0xe8($a1) -/* 0D3F08 800D3308 FCBD00F0 */ sd $sp, 0xf0($a1) -/* 0D3F0C 800D330C FCBE00F8 */ sd $fp, 0xf8($a1) -/* 0D3F10 800D3310 FCBF0100 */ sd $ra, 0x100($a1) -/* 0D3F14 800D3314 13600009 */ beqz $k1, .L800D333C -/* 0D3F18 800D3318 ACBF011C */ sw $ra, 0x11c($a1) -/* 0D3F1C 800D331C 445BF800 */ cfc1 $k1, $31 -/* 0D3F20 800D3320 F4B40180 */ sdc1 $f20, 0x180($a1) -/* 0D3F24 800D3324 F4B60188 */ sdc1 $f22, 0x188($a1) -/* 0D3F28 800D3328 F4B80190 */ sdc1 $f24, 0x190($a1) -/* 0D3F2C 800D332C F4BA0198 */ sdc1 $f26, 0x198($a1) -/* 0D3F30 800D3330 F4BC01A0 */ sdc1 $f28, 0x1a0($a1) -/* 0D3F34 800D3334 F4BE01A8 */ sdc1 $f30, 0x1a8($a1) -/* 0D3F38 800D3338 ACBB012C */ sw $k1, 0x12c($a1) -.L800D333C: -/* 0D3F3C 800D333C 8CBB0118 */ lw $k1, 0x118($a1) -/* 0D3F40 800D3340 3369FF00 */ andi $t1, $k1, 0xff00 -/* 0D3F44 800D3344 1120000D */ beqz $t1, .L800D337C -/* 0D3F48 800D3348 00000000 */ nop -/* 0D3F4C 800D334C 3C08800E */ lui $t0, %hi(__OSGlobalIntMask) # $t0, 0x800e -/* 0D3F50 800D3350 250838AC */ addiu $t0, %lo(__OSGlobalIntMask) # addiu $t0, $t0, 0x38ac -/* 0D3F54 800D3354 8D080000 */ lw $t0, ($t0) -/* 0D3F58 800D3358 2401FFFF */ li $at, -1 -/* 0D3F5C 800D335C 01014026 */ xor $t0, $t0, $at -/* 0D3F60 800D3360 3C01FFFF */ lui $at, (0xFFFF00FF >> 16) # lui $at, 0xffff -/* 0D3F64 800D3364 3108FF00 */ andi $t0, $t0, 0xff00 -/* 0D3F68 800D3368 342100FF */ ori $at, (0xFFFF00FF & 0xFFFF) # ori $at, $at, 0xff -/* 0D3F6C 800D336C 01284825 */ or $t1, $t1, $t0 -/* 0D3F70 800D3370 0361D824 */ and $k1, $k1, $at -/* 0D3F74 800D3374 0369D825 */ or $k1, $k1, $t1 -/* 0D3F78 800D3378 ACBB0118 */ sw $k1, 0x118($a1) -.L800D337C: -/* 0D3F7C 800D337C 3C1BA430 */ lui $k1, %hi(MI_INTR_MASK_REG) # $k1, 0xa430 -/* 0D3F80 800D3380 8F7B000C */ lw $k1, %lo(MI_INTR_MASK_REG)($k1) -/* 0D3F84 800D3384 1360000B */ beqz $k1, .L800D33B4 -/* 0D3F88 800D3388 00000000 */ nop -/* 0D3F8C 800D338C 3C1A800E */ lui $k0, %hi(__OSGlobalIntMask) # $k0, 0x800e -/* 0D3F90 800D3390 275A38AC */ addiu $k0, %lo(__OSGlobalIntMask) # addiu $k0, $k0, 0x38ac -/* 0D3F94 800D3394 8F5A0000 */ lw $k0, ($k0) -/* 0D3F98 800D3398 8CA80128 */ lw $t0, 0x128($a1) -/* 0D3F9C 800D339C 2401FFFF */ li $at, -1 -/* 0D3FA0 800D33A0 001AD402 */ srl $k0, $k0, 0x10 -/* 0D3FA4 800D33A4 0341D026 */ xor $k0, $k0, $at -/* 0D3FA8 800D33A8 335A003F */ andi $k0, $k0, 0x3f -/* 0D3FAC 800D33AC 0348D024 */ and $k0, $k0, $t0 -/* 0D3FB0 800D33B0 037AD825 */ or $k1, $k1, $k0 -.L800D33B4: -/* 0D3FB4 800D33B4 10800003 */ beqz $a0, .L800D33C4 -/* 0D3FB8 800D33B8 ACBB0128 */ sw $k1, 0x128($a1) -/* 0D3FBC 800D33BC 0C034CF3 */ jal __osEnqueueThread -/* 0D3FC0 800D33C0 00000000 */ nop -.L800D33C4: -/* 0D3FC4 800D33C4 08034D09 */ j __osDispatchThread -/* 0D3FC8 800D33C8 00000000 */ nop - diff --git a/lib/asm/exception/__osEnqueueThread.s b/lib/asm/exception/__osEnqueueThread.s deleted file mode 100644 index bd3a5ab7..00000000 --- a/lib/asm/exception/__osEnqueueThread.s +++ /dev/null @@ -1,22 +0,0 @@ -glabel __osEnqueueThread -/* 0D3FCC 800D33CC 8C980000 */ lw $t8, ($a0) -/* 0D3FD0 800D33D0 8CAF0004 */ lw $t7, 4($a1) -/* 0D3FD4 800D33D4 0080C825 */ move $t9, $a0 -/* 0D3FD8 800D33D8 8F0E0004 */ lw $t6, 4($t8) -/* 0D3FDC 800D33DC 01CF082A */ slt $at, $t6, $t7 -/* 0D3FE0 800D33E0 14200007 */ bnez $at, .L800D3400 -/* 0D3FE4 800D33E4 00000000 */ nop -.L800D33E8: -/* 0D3FE8 800D33E8 0300C825 */ move $t9, $t8 -/* 0D3FEC 800D33EC 8F180000 */ lw $t8, ($t8) -/* 0D3FF0 800D33F0 8F0E0004 */ lw $t6, 4($t8) -/* 0D3FF4 800D33F4 01CF082A */ slt $at, $t6, $t7 -/* 0D3FF8 800D33F8 1020FFFB */ beqz $at, .L800D33E8 -/* 0D3FFC 800D33FC 00000000 */ nop -.L800D3400: -/* 0D4000 800D3400 8F380000 */ lw $t8, ($t9) -/* 0D4004 800D3404 ACB80000 */ sw $t8, ($a1) -/* 0D4008 800D3408 AF250000 */ sw $a1, ($t9) -/* 0D400C 800D340C 03E00008 */ jr $ra -/* 0D4010 800D3410 ACA40008 */ sw $a0, 8($a1) - diff --git a/lib/asm/exception/__osException.s b/lib/asm/exception/__osException.s deleted file mode 100644 index 0932b9a5..00000000 --- a/lib/asm/exception/__osException.s +++ /dev/null @@ -1,384 +0,0 @@ -.section .rodata - -glabel __osIntOffTable -.word 0x00141818 -.word 0x1C1C1C1C -.word 0x20202020 -.word 0x20202020 -.word 0x00040808 -.word 0x0C0C0C0C -.word 0x10101010 -.word 0x10101010 - -glabel __osIntTable -.word .L800D3168 -.word .L800D3130 -.word .L800D3110 -.word .L800D2F74 -.word .L800D2F20 -.word .L800D30B4 -.word .L800D2EE8 -.word .L800D2EF4 -.word .L800D2F00 - -.section .text - -glabel __osException -/* 0D38C0 800D2CC0 3C1A8013 */ lui $k0, %hi(gInterruptedThread) # $k0, 0x8013 -/* 0D38C4 800D2CC4 275AD240 */ addiu $k0, %lo(gInterruptedThread) # addiu $k0, $k0, -0x2dc0 -/* 0D38C8 800D2CC8 FF410020 */ sd $at, 0x20($k0) -/* 0D38CC 800D2CCC 401B6000 */ mfc0 $k1, $12 -/* 0D38D0 800D2CD0 AF5B0118 */ sw $k1, 0x118($k0) -/* 0D38D4 800D2CD4 2401FFFC */ li $at, -4 -/* 0D38D8 800D2CD8 0361D824 */ and $k1, $k1, $at -/* 0D38DC 800D2CDC 409B6000 */ mtc0 $k1, $12 -/* 0D38E0 800D2CE0 FF480058 */ sd $t0, 0x58($k0) -/* 0D38E4 800D2CE4 FF490060 */ sd $t1, 0x60($k0) -/* 0D38E8 800D2CE8 FF4A0068 */ sd $t2, 0x68($k0) -/* 0D38EC 800D2CEC AF400018 */ sw $zero, 0x18($k0) -/* 0D38F0 800D2CF0 40086800 */ mfc0 $t0, $13 -/* 0D38F4 800D2CF4 03404025 */ move $t0, $k0 -/* 0D38F8 800D2CF8 3C1A800E */ lui $k0, %hi(__osRunningThread) # $k0, 0x800e -/* 0D38FC 800D2CFC 8F5A4890 */ lw $k0, %lo(__osRunningThread)($k0) -/* 0D3900 800D2D00 DD090020 */ ld $t1, 0x20($t0) -/* 0D3904 800D2D04 FF490020 */ sd $t1, 0x20($k0) -/* 0D3908 800D2D08 DD090118 */ ld $t1, 0x118($t0) -/* 0D390C 800D2D0C FF490118 */ sd $t1, 0x118($k0) -/* 0D3910 800D2D10 DD090058 */ ld $t1, 0x58($t0) -/* 0D3914 800D2D14 FF490058 */ sd $t1, 0x58($k0) -/* 0D3918 800D2D18 DD090060 */ ld $t1, 0x60($t0) -/* 0D391C 800D2D1C FF490060 */ sd $t1, 0x60($k0) -/* 0D3920 800D2D20 DD090068 */ ld $t1, 0x68($t0) -/* 0D3924 800D2D24 FF490068 */ sd $t1, 0x68($k0) -/* 0D3928 800D2D28 8F5B0118 */ lw $k1, 0x118($k0) -/* 0D392C 800D2D2C 00004012 */ mflo $t0 -/* 0D3930 800D2D30 FF480108 */ sd $t0, 0x108($k0) -/* 0D3934 800D2D34 00004010 */ mfhi $t0 -/* 0D3938 800D2D38 3369FF00 */ andi $t1, $k1, 0xff00 -/* 0D393C 800D2D3C FF420028 */ sd $v0, 0x28($k0) -/* 0D3940 800D2D40 FF430030 */ sd $v1, 0x30($k0) -/* 0D3944 800D2D44 FF440038 */ sd $a0, 0x38($k0) -/* 0D3948 800D2D48 FF450040 */ sd $a1, 0x40($k0) -/* 0D394C 800D2D4C FF460048 */ sd $a2, 0x48($k0) -/* 0D3950 800D2D50 FF470050 */ sd $a3, 0x50($k0) -/* 0D3954 800D2D54 FF4B0070 */ sd $t3, 0x70($k0) -/* 0D3958 800D2D58 FF4C0078 */ sd $t4, 0x78($k0) -/* 0D395C 800D2D5C FF4D0080 */ sd $t5, 0x80($k0) -/* 0D3960 800D2D60 FF4E0088 */ sd $t6, 0x88($k0) -/* 0D3964 800D2D64 FF4F0090 */ sd $t7, 0x90($k0) -/* 0D3968 800D2D68 FF500098 */ sd $s0, 0x98($k0) -/* 0D396C 800D2D6C FF5100A0 */ sd $s1, 0xa0($k0) -/* 0D3970 800D2D70 FF5200A8 */ sd $s2, 0xa8($k0) -/* 0D3974 800D2D74 FF5300B0 */ sd $s3, 0xb0($k0) -/* 0D3978 800D2D78 FF5400B8 */ sd $s4, 0xb8($k0) -/* 0D397C 800D2D7C FF5500C0 */ sd $s5, 0xc0($k0) -/* 0D3980 800D2D80 FF5600C8 */ sd $s6, 0xc8($k0) -/* 0D3984 800D2D84 FF5700D0 */ sd $s7, 0xd0($k0) -/* 0D3988 800D2D88 FF5800D8 */ sd $t8, 0xd8($k0) -/* 0D398C 800D2D8C FF5900E0 */ sd $t9, 0xe0($k0) -/* 0D3990 800D2D90 FF5C00E8 */ sd $gp, 0xe8($k0) -/* 0D3994 800D2D94 FF5D00F0 */ sd $sp, 0xf0($k0) -/* 0D3998 800D2D98 FF5E00F8 */ sd $fp, 0xf8($k0) -/* 0D399C 800D2D9C FF5F0100 */ sd $ra, 0x100($k0) -/* 0D39A0 800D2DA0 1120000D */ beqz $t1, .L800D2DD8 -/* 0D39A4 800D2DA4 FF480110 */ sd $t0, 0x110($k0) -/* 0D39A8 800D2DA8 3C08800E */ lui $t0, %hi(__OSGlobalIntMask) # $t0, 0x800e -/* 0D39AC 800D2DAC 250838AC */ addiu $t0, %lo(__OSGlobalIntMask) # addiu $t0, $t0, 0x38ac -/* 0D39B0 800D2DB0 8D080000 */ lw $t0, ($t0) -/* 0D39B4 800D2DB4 2401FFFF */ li $at, -1 -/* 0D39B8 800D2DB8 01014026 */ xor $t0, $t0, $at -/* 0D39BC 800D2DBC 3C01FFFF */ lui $at, (0xFFFF00FF >> 16) # lui $at, 0xffff -/* 0D39C0 800D2DC0 3108FF00 */ andi $t0, $t0, 0xff00 -/* 0D39C4 800D2DC4 342100FF */ ori $at, (0xFFFF00FF & 0xFFFF) # ori $at, $at, 0xff -/* 0D39C8 800D2DC8 01284825 */ or $t1, $t1, $t0 -/* 0D39CC 800D2DCC 0361D824 */ and $k1, $k1, $at -/* 0D39D0 800D2DD0 0369D825 */ or $k1, $k1, $t1 -/* 0D39D4 800D2DD4 AF5B0118 */ sw $k1, 0x118($k0) -.L800D2DD8: -/* 0D39D8 800D2DD8 3C09A430 */ lui $t1, %hi(MI_INTR_MASK_REG) # $t1, 0xa430 -/* 0D39DC 800D2DDC 8D29000C */ lw $t1, %lo(MI_INTR_MASK_REG)($t1) -/* 0D39E0 800D2DE0 1120000B */ beqz $t1, .L800D2E10 -/* 0D39E4 800D2DE4 00000000 */ nop -/* 0D39E8 800D2DE8 3C08800E */ lui $t0, %hi(__OSGlobalIntMask) # $t0, 0x800e -/* 0D39EC 800D2DEC 250838AC */ addiu $t0, %lo(__OSGlobalIntMask) # addiu $t0, $t0, 0x38ac -/* 0D39F0 800D2DF0 8D080000 */ lw $t0, ($t0) -/* 0D39F4 800D2DF4 8F4C0128 */ lw $t4, 0x128($k0) -/* 0D39F8 800D2DF8 2401FFFF */ li $at, -1 -/* 0D39FC 800D2DFC 00084402 */ srl $t0, $t0, 0x10 -/* 0D3A00 800D2E00 01014026 */ xor $t0, $t0, $at -/* 0D3A04 800D2E04 3108003F */ andi $t0, $t0, 0x3f -/* 0D3A08 800D2E08 010C4024 */ and $t0, $t0, $t4 -/* 0D3A0C 800D2E0C 01284825 */ or $t1, $t1, $t0 -.L800D2E10: -/* 0D3A10 800D2E10 AF490128 */ sw $t1, 0x128($k0) -/* 0D3A14 800D2E14 40087000 */ mfc0 $t0, $14 -/* 0D3A18 800D2E18 AF48011C */ sw $t0, 0x11c($k0) -/* 0D3A1C 800D2E1C 8F480018 */ lw $t0, 0x18($k0) -/* 0D3A20 800D2E20 11000014 */ beqz $t0, .L800D2E74 -/* 0D3A24 800D2E24 00000000 */ nop -/* 0D3A28 800D2E28 4448F800 */ cfc1 $t0, $31 -/* 0D3A2C 800D2E2C 00000000 */ nop -/* 0D3A30 800D2E30 AF48012C */ sw $t0, 0x12c($k0) -/* 0D3A34 800D2E34 F7400130 */ sdc1 $f0, 0x130($k0) -/* 0D3A38 800D2E38 F7420138 */ sdc1 $f2, 0x138($k0) -/* 0D3A3C 800D2E3C F7440140 */ sdc1 $f4, 0x140($k0) -/* 0D3A40 800D2E40 F7460148 */ sdc1 $f6, 0x148($k0) -/* 0D3A44 800D2E44 F7480150 */ sdc1 $f8, 0x150($k0) -/* 0D3A48 800D2E48 F74A0158 */ sdc1 $f10, 0x158($k0) -/* 0D3A4C 800D2E4C F74C0160 */ sdc1 $f12, 0x160($k0) -/* 0D3A50 800D2E50 F74E0168 */ sdc1 $f14, 0x168($k0) -/* 0D3A54 800D2E54 F7500170 */ sdc1 $f16, 0x170($k0) -/* 0D3A58 800D2E58 F7520178 */ sdc1 $f18, 0x178($k0) -/* 0D3A5C 800D2E5C F7540180 */ sdc1 $f20, 0x180($k0) -/* 0D3A60 800D2E60 F7560188 */ sdc1 $f22, 0x188($k0) -/* 0D3A64 800D2E64 F7580190 */ sdc1 $f24, 0x190($k0) -/* 0D3A68 800D2E68 F75A0198 */ sdc1 $f26, 0x198($k0) -/* 0D3A6C 800D2E6C F75C01A0 */ sdc1 $f28, 0x1a0($k0) -/* 0D3A70 800D2E70 F75E01A8 */ sdc1 $f30, 0x1a8($k0) -.L800D2E74: -/* 0D3A74 800D2E74 40086800 */ mfc0 $t0, $13 -/* 0D3A78 800D2E78 AF480120 */ sw $t0, 0x120($k0) -/* 0D3A7C 800D2E7C 24090002 */ li $t1, 2 -/* 0D3A80 800D2E80 A7490010 */ sh $t1, 0x10($k0) -/* 0D3A84 800D2E84 3109007C */ andi $t1, $t0, 0x7c -/* 0D3A88 800D2E88 240A0024 */ li $t2, 36 -/* 0D3A8C 800D2E8C 112A00B0 */ beq $t1, $t2, .L800D3150 -/* 0D3A90 800D2E90 00000000 */ nop -/* 0D3A94 800D2E94 240A002C */ li $t2, 44 -/* 0D3A98 800D2E98 112A00FF */ beq $t1, $t2, handle_CpU -/* 0D3A9C 800D2E9C 00000000 */ nop -/* 0D3AA0 800D2EA0 240A0000 */ li $t2, 0 -/* 0D3AA4 800D2EA4 152A00C3 */ bne $t1, $t2, .L800D31B4 -/* 0D3AA8 800D2EA8 00000000 */ nop -/* 0D3AAC 800D2EAC 03688024 */ and $s0, $k1, $t0 -.L800D2EB0: -/* 0D3AB0 800D2EB0 3209FF00 */ andi $t1, $s0, 0xff00 -/* 0D3AB4 800D2EB4 00095302 */ srl $t2, $t1, 0xc -/* 0D3AB8 800D2EB8 15400003 */ bnez $t2, .L800D2EC8 -/* 0D3ABC 800D2EBC 00000000 */ nop -/* 0D3AC0 800D2EC0 00095202 */ srl $t2, $t1, 8 -/* 0D3AC4 800D2EC4 214A0010 */ addi $t2, $t2, 0x10 -.L800D2EC8: -/* 0D3AC8 800D2EC8 3C01800F */ lui $at, %hi(__osIntOffTable) # $at, 0x800f -/* 0D3ACC 800D2ECC 002A0821 */ addu $at, $at, $t2 -/* 0D3AD0 800D2ED0 902A9670 */ lbu $t2, %lo(__osIntOffTable)($at) -/* 0D3AD4 800D2ED4 3C01800F */ lui $at, %hi(__osIntTable) # $at, 0x800f -/* 0D3AD8 800D2ED8 002A0821 */ addu $at, $at, $t2 -/* 0D3ADC 800D2EDC 8C2A9690 */ lw $t2, %lo(__osIntTable)($at) -/* 0D3AE0 800D2EE0 01400008 */ jr $t2 -/* 0D3AE4 800D2EE4 00000000 */ nop -.L800D2EE8: -/* 0D3AE8 800D2EE8 2401DFFF */ li $at, -8193 -/* 0D3AEC 800D2EEC 1000FFF0 */ b .L800D2EB0 -/* 0D3AF0 800D2EF0 02018024 */ and $s0, $s0, $at -.L800D2EF4: -/* 0D3AF4 800D2EF4 2401BFFF */ li $at, -16385 -/* 0D3AF8 800D2EF8 1000FFED */ b .L800D2EB0 -/* 0D3AFC 800D2EFC 02018024 */ and $s0, $s0, $at -.L800D2F00: -/* 0D3B00 800D2F00 40095800 */ mfc0 $t1, $11 -/* 0D3B04 800D2F04 40895800 */ mtc0 $t1, $11 -/* 0D3B08 800D2F08 0C034C79 */ jal send_mesg -/* 0D3B0C 800D2F0C 24040018 */ li $a0, 24 -/* 0D3B10 800D2F10 3C01FFFF */ lui $at, (0xFFFF7FFF >> 16) # lui $at, 0xffff -/* 0D3B14 800D2F14 34217FFF */ ori $at, (0xFFFF7FFF & 0xFFFF) # ori $at, $at, 0x7fff -/* 0D3B18 800D2F18 1000FFE5 */ b .L800D2EB0 -/* 0D3B1C 800D2F1C 02018024 */ and $s0, $s0, $at -.L800D2F20: -/* 0D3B20 800D2F20 2401F7FF */ li $at, -2049 -/* 0D3B24 800D2F24 02018024 */ and $s0, $s0, $at -/* 0D3B28 800D2F28 240A0004 */ li $t2, 4 -/* 0D3B2C 800D2F2C 3C01800E */ lui $at, %hi(__osHwIntTable) # $at, 0x800e -/* 0D3B30 800D2F30 002A0821 */ addu $at, $at, $t2 -/* 0D3B34 800D2F34 8C2A48A0 */ lw $t2, %lo(__osHwIntTable)($at) -/* 0D3B38 800D2F38 3C1D8013 */ lui $sp, %hi(leoDiskStack) # $sp, 0x8013 -/* 0D3B3C 800D2F3C 27BDAAE0 */ addiu $sp, %lo(leoDiskStack) # addiu $sp, $sp, -0x5520 -/* 0D3B40 800D2F40 24040010 */ li $a0, 16 -/* 0D3B44 800D2F44 11400007 */ beqz $t2, .L800D2F64 -/* 0D3B48 800D2F48 27BD0FF0 */ addiu $sp, $sp, 0xff0 -/* 0D3B4C 800D2F4C 0140F809 */ jalr $t2 -/* 0D3B50 800D2F50 00000000 */ nop -/* 0D3B54 800D2F54 10400003 */ beqz $v0, .L800D2F64 -/* 0D3B58 800D2F58 00000000 */ nop -/* 0D3B5C 800D2F5C 10000082 */ b .L800D3168 -/* 0D3B60 800D2F60 00000000 */ nop -.L800D2F64: -/* 0D3B64 800D2F64 0C034C79 */ jal send_mesg -/* 0D3B68 800D2F68 00000000 */ nop -/* 0D3B6C 800D2F6C 1000FFD0 */ b .L800D2EB0 -/* 0D3B70 800D2F70 00000000 */ nop -.L800D2F74: -/* 0D3B74 800D2F74 3C08800E */ lui $t0, %hi(__OSGlobalIntMask) # $t0, 0x800e -/* 0D3B78 800D2F78 250838AC */ addiu $t0, %lo(__OSGlobalIntMask) # addiu $t0, $t0, 0x38ac -/* 0D3B7C 800D2F7C 8D080000 */ lw $t0, ($t0) -/* 0D3B80 800D2F80 3C11A430 */ lui $s1, %hi(MI_INTR_REG) # $s1, 0xa430 -/* 0D3B84 800D2F84 8E310008 */ lw $s1, %lo(MI_INTR_REG)($s1) -/* 0D3B88 800D2F88 00084402 */ srl $t0, $t0, 0x10 -/* 0D3B8C 800D2F8C 02288824 */ and $s1, $s1, $t0 -/* 0D3B90 800D2F90 32290001 */ andi $t1, $s1, 1 -/* 0D3B94 800D2F94 11200013 */ beqz $t1, .L800D2FE4 -/* 0D3B98 800D2F98 00000000 */ nop -/* 0D3B9C 800D2F9C 3C0CA404 */ lui $t4, %hi(SP_STATUS_REG) # $t4, 0xa404 -/* 0D3BA0 800D2FA0 8D8C0010 */ lw $t4, %lo(SP_STATUS_REG)($t4) -/* 0D3BA4 800D2FA4 24090008 */ li $t1, 8 -/* 0D3BA8 800D2FA8 3C01A404 */ lui $at, %hi(SP_STATUS_REG) # $at, 0xa404 -/* 0D3BAC 800D2FAC 318C0300 */ andi $t4, $t4, 0x300 -/* 0D3BB0 800D2FB0 3231003E */ andi $s1, $s1, 0x3e -/* 0D3BB4 800D2FB4 11800007 */ beqz $t4, .L800D2FD4 -/* 0D3BB8 800D2FB8 AC290010 */ sw $t1, %lo(SP_STATUS_REG)($at) -/* 0D3BBC 800D2FBC 0C034C79 */ jal send_mesg -/* 0D3BC0 800D2FC0 24040020 */ li $a0, 32 -/* 0D3BC4 800D2FC4 12200038 */ beqz $s1, .L800D30A8 -/* 0D3BC8 800D2FC8 00000000 */ nop -/* 0D3BCC 800D2FCC 10000005 */ b .L800D2FE4 -/* 0D3BD0 800D2FD0 00000000 */ nop -.L800D2FD4: -/* 0D3BD4 800D2FD4 0C034C79 */ jal send_mesg -/* 0D3BD8 800D2FD8 24040058 */ li $a0, 88 -/* 0D3BDC 800D2FDC 12200032 */ beqz $s1, .L800D30A8 -/* 0D3BE0 800D2FE0 00000000 */ nop -.L800D2FE4: -/* 0D3BE4 800D2FE4 32290008 */ andi $t1, $s1, 8 -/* 0D3BE8 800D2FE8 11200007 */ beqz $t1, .L800D3008 -/* 0D3BEC 800D2FEC 3C01A440 */ lui $at, %hi(VI_CURRENT_REG) # $at, 0xa440 -/* 0D3BF0 800D2FF0 32310037 */ andi $s1, $s1, 0x37 -/* 0D3BF4 800D2FF4 AC200010 */ sw $zero, %lo(VI_CURRENT_REG)($at) -/* 0D3BF8 800D2FF8 0C034C79 */ jal send_mesg -/* 0D3BFC 800D2FFC 24040038 */ li $a0, 56 -/* 0D3C00 800D3000 12200029 */ beqz $s1, .L800D30A8 -/* 0D3C04 800D3004 00000000 */ nop -.L800D3008: -/* 0D3C08 800D3008 32290004 */ andi $t1, $s1, 4 -/* 0D3C0C 800D300C 11200009 */ beqz $t1, .L800D3034 -/* 0D3C10 800D3010 00000000 */ nop -/* 0D3C14 800D3014 24090001 */ li $t1, 1 -/* 0D3C18 800D3018 3C01A450 */ lui $at, %hi(AI_STATUS_REG) # $at, 0xa450 -/* 0D3C1C 800D301C 3231003B */ andi $s1, $s1, 0x3b -/* 0D3C20 800D3020 AC29000C */ sw $t1, %lo(AI_STATUS_REG)($at) -/* 0D3C24 800D3024 0C034C79 */ jal send_mesg -/* 0D3C28 800D3028 24040030 */ li $a0, 48 -/* 0D3C2C 800D302C 1220001E */ beqz $s1, .L800D30A8 -/* 0D3C30 800D3030 00000000 */ nop -.L800D3034: -/* 0D3C34 800D3034 32290002 */ andi $t1, $s1, 2 -/* 0D3C38 800D3038 11200007 */ beqz $t1, .L800D3058 -/* 0D3C3C 800D303C 3C01A480 */ lui $at, %hi(SI_STATUS_REG) # $at, 0xa480 -/* 0D3C40 800D3040 3231003D */ andi $s1, $s1, 0x3d -/* 0D3C44 800D3044 AC200018 */ sw $zero, %lo(SI_STATUS_REG)($at) -/* 0D3C48 800D3048 0C034C79 */ jal send_mesg -/* 0D3C4C 800D304C 24040028 */ li $a0, 40 -/* 0D3C50 800D3050 12200015 */ beqz $s1, .L800D30A8 -/* 0D3C54 800D3054 00000000 */ nop -.L800D3058: -/* 0D3C58 800D3058 32290010 */ andi $t1, $s1, 0x10 -/* 0D3C5C 800D305C 11200009 */ beqz $t1, .L800D3084 -/* 0D3C60 800D3060 00000000 */ nop -/* 0D3C64 800D3064 24090002 */ li $t1, 2 -/* 0D3C68 800D3068 3C01A460 */ lui $at, %hi(PI_STATUS_REG) # $at, 0xa460 -/* 0D3C6C 800D306C 3231002F */ andi $s1, $s1, 0x2f -/* 0D3C70 800D3070 AC290010 */ sw $t1, %lo(PI_STATUS_REG)($at) -/* 0D3C74 800D3074 0C034C79 */ jal send_mesg -/* 0D3C78 800D3078 24040040 */ li $a0, 64 -/* 0D3C7C 800D307C 1220000A */ beqz $s1, .L800D30A8 -/* 0D3C80 800D3080 00000000 */ nop -.L800D3084: -/* 0D3C84 800D3084 32290020 */ andi $t1, $s1, 0x20 -/* 0D3C88 800D3088 11200007 */ beqz $t1, .L800D30A8 -/* 0D3C8C 800D308C 00000000 */ nop -/* 0D3C90 800D3090 24090800 */ li $t1, 2048 -/* 0D3C94 800D3094 3C01A430 */ lui $at, 0xa430 -/* 0D3C98 800D3098 3231001F */ andi $s1, $s1, 0x1f -/* 0D3C9C 800D309C AC290000 */ sw $t1, ($at) -/* 0D3CA0 800D30A0 0C034C79 */ jal send_mesg -/* 0D3CA4 800D30A4 24040048 */ li $a0, 72 -.L800D30A8: -/* 0D3CA8 800D30A8 2401FBFF */ li $at, -1025 -/* 0D3CAC 800D30AC 1000FF80 */ b .L800D2EB0 -/* 0D3CB0 800D30B0 02018024 */ and $s0, $s0, $at -.L800D30B4: -/* 0D3CB4 800D30B4 8F5B0118 */ lw $k1, 0x118($k0) -/* 0D3CB8 800D30B8 2401EFFF */ li $at, -4097 -/* 0D3CBC 800D30BC 3C09800E */ lui $t1, %hi(__osShutdown) # $t1, 0x800e -/* 0D3CC0 800D30C0 0361D824 */ and $k1, $k1, $at -/* 0D3CC4 800D30C4 AF5B0118 */ sw $k1, 0x118($k0) -/* 0D3CC8 800D30C8 252938A8 */ addiu $t1, %lo(__osShutdown) # addiu $t1, $t1, 0x38a8 -/* 0D3CCC 800D30CC 8D2A0000 */ lw $t2, ($t1) -/* 0D3CD0 800D30D0 11400003 */ beqz $t2, .L800D30E0 -/* 0D3CD4 800D30D4 2401EFFF */ li $at, -4097 -/* 0D3CD8 800D30D8 10000023 */ b .L800D3168 -/* 0D3CDC 800D30DC 02018024 */ and $s0, $s0, $at -.L800D30E0: -/* 0D3CE0 800D30E0 240A0001 */ li $t2, 1 -/* 0D3CE4 800D30E4 AD2A0000 */ sw $t2, ($t1) -/* 0D3CE8 800D30E8 0C034C79 */ jal send_mesg -/* 0D3CEC 800D30EC 24040070 */ li $a0, 112 -/* 0D3CF0 800D30F0 3C0A800E */ lui $t2, %hi(__osRunQueue) # $t2, 0x800e -/* 0D3CF4 800D30F4 8D4A4888 */ lw $t2, %lo(__osRunQueue)($t2) -/* 0D3CF8 800D30F8 2401EFFF */ li $at, -4097 -/* 0D3CFC 800D30FC 02018024 */ and $s0, $s0, $at -/* 0D3D00 800D3100 8D5B0118 */ lw $k1, 0x118($t2) -/* 0D3D04 800D3104 0361D824 */ and $k1, $k1, $at -/* 0D3D08 800D3108 10000017 */ b .L800D3168 -/* 0D3D0C 800D310C AD5B0118 */ sw $k1, 0x118($t2) -.L800D3110: -/* 0D3D10 800D3110 2401FDFF */ li $at, -513 -/* 0D3D14 800D3114 01014024 */ and $t0, $t0, $at -/* 0D3D18 800D3118 40886800 */ mtc0 $t0, $13 -/* 0D3D1C 800D311C 0C034C79 */ jal send_mesg -/* 0D3D20 800D3120 24040008 */ li $a0, 8 -/* 0D3D24 800D3124 2401FDFF */ li $at, -513 -/* 0D3D28 800D3128 1000FF61 */ b .L800D2EB0 -/* 0D3D2C 800D312C 02018024 */ and $s0, $s0, $at -.L800D3130: -/* 0D3D30 800D3130 2401FEFF */ li $at, -257 -/* 0D3D34 800D3134 01014024 */ and $t0, $t0, $at -/* 0D3D38 800D3138 40886800 */ mtc0 $t0, $13 -/* 0D3D3C 800D313C 0C034C79 */ jal send_mesg -/* 0D3D40 800D3140 24040000 */ li $a0, 0 -/* 0D3D44 800D3144 2401FEFF */ li $at, -257 -/* 0D3D48 800D3148 1000FF59 */ b .L800D2EB0 -/* 0D3D4C 800D314C 02018024 */ and $s0, $s0, $at -.L800D3150: -/* 0D3D50 800D3150 24090001 */ li $t1, 1 -/* 0D3D54 800D3154 A7490012 */ sh $t1, 0x12($k0) -/* 0D3D58 800D3158 0C034C79 */ jal send_mesg -/* 0D3D5C 800D315C 24040050 */ li $a0, 80 -/* 0D3D60 800D3160 10000001 */ b .L800D3168 -/* 0D3D64 800D3164 00000000 */ nop -.L800D3168: -/* 0D3D68 800D3168 3C0A800E */ lui $t2, %hi(__osRunQueue) # $t2, 0x800e -/* 0D3D6C 800D316C 8D4A4888 */ lw $t2, %lo(__osRunQueue)($t2) -/* 0D3D70 800D3170 8F490004 */ lw $t1, 4($k0) -/* 0D3D74 800D3174 8D4B0004 */ lw $t3, 4($t2) -/* 0D3D78 800D3178 012B082A */ slt $at, $t1, $t3 -/* 0D3D7C 800D317C 10200007 */ beqz $at, .L800D319C -/* 0D3D80 800D3180 00000000 */ nop -/* 0D3D84 800D3184 3C04800E */ lui $a0, %hi(__osRunQueue) # $a0, 0x800e -/* 0D3D88 800D3188 03402825 */ move $a1, $k0 -/* 0D3D8C 800D318C 0C034CF3 */ jal __osEnqueueThread -/* 0D3D90 800D3190 24844888 */ addiu $a0, %lo(__osRunQueue) # addiu $a0, $a0, 0x4888 -/* 0D3D94 800D3194 08034D09 */ j __osDispatchThread -/* 0D3D98 800D3198 00000000 */ nop - -.L800D319C: -/* 0D3D9C 800D319C 3C09800E */ lui $t1, %hi(__osRunQueue) # $t1, 0x800e -/* 0D3DA0 800D31A0 25294888 */ addiu $t1, %lo(__osRunQueue) # addiu $t1, $t1, 0x4888 -/* 0D3DA4 800D31A4 8D2A0000 */ lw $t2, ($t1) -/* 0D3DA8 800D31A8 AF4A0000 */ sw $t2, ($k0) -/* 0D3DAC 800D31AC 08034D09 */ j __osDispatchThread -/* 0D3DB0 800D31B0 AD3A0000 */ sw $k0, ($t1) - -.L800D31B4: -/* 0D3DB4 800D31B4 3C01800E */ lui $at, %hi(__osFaultedThread) # $at, 0x800e -/* 0D3DB8 800D31B8 AC3A4894 */ sw $k0, %lo(__osFaultedThread)($at) -/* 0D3DBC 800D31BC 24090001 */ li $t1, 1 -/* 0D3DC0 800D31C0 A7490010 */ sh $t1, 0x10($k0) -/* 0D3DC4 800D31C4 24090002 */ li $t1, 2 -/* 0D3DC8 800D31C8 A7490012 */ sh $t1, 0x12($k0) -/* 0D3DCC 800D31CC 400A4000 */ mfc0 $t2, $8 -/* 0D3DD0 800D31D0 AF4A0124 */ sw $t2, 0x124($k0) -/* 0D3DD4 800D31D4 0C034C79 */ jal send_mesg -/* 0D3DD8 800D31D8 24040060 */ li $a0, 96 -/* 0D3DDC 800D31DC 08034D09 */ j __osDispatchThread -/* 0D3DE0 800D31E0 00000000 */ nop - diff --git a/lib/asm/exception/__osExceptionPreamble.s b/lib/asm/exception/__osExceptionPreamble.s deleted file mode 100644 index f832c6eb..00000000 --- a/lib/asm/exception/__osExceptionPreamble.s +++ /dev/null @@ -1,5 +0,0 @@ -glabel __osExceptionPreamble -/* 0D38B0 800D2CB0 3C1A800D */ lui $k0, %hi(__osException) # $k0, 0x800d -/* 0D38B4 800D2CB4 275A2CC0 */ addiu $k0, %lo(__osException) # addiu $k0, $k0, 0x2cc0 -/* 0D38B8 800D2CB8 03400008 */ jr $k0 -/* 0D38BC 800D2CBC 00000000 */ nop diff --git a/lib/asm/exception/__osPopThread.s b/lib/asm/exception/__osPopThread.s deleted file mode 100644 index 868b19df..00000000 --- a/lib/asm/exception/__osPopThread.s +++ /dev/null @@ -1,6 +0,0 @@ -glabel __osPopThread -/* 0D4014 800D3414 8C820000 */ lw $v0, ($a0) -/* 0D4018 800D3418 8C590000 */ lw $t9, ($v0) -/* 0D401C 800D341C 03E00008 */ jr $ra -/* 0D4020 800D3420 AC990000 */ sw $t9, ($a0) - diff --git a/lib/asm/exception/send_mesg.s b/lib/asm/exception/send_mesg.s deleted file mode 100644 index 9bea017a..00000000 --- a/lib/asm/exception/send_mesg.s +++ /dev/null @@ -1,63 +0,0 @@ -glabel send_mesg -/* 0D3DE4 800D31E4 3C0A8013 */ lui $t2, %hi(__osEventStateTab) # $t2, 0x8013 -/* 0D3DE8 800D31E8 254ACCD0 */ addiu $t2, %lo(__osEventStateTab) # addiu $t2, $t2, -0x3330 -/* 0D3DEC 800D31EC 01445021 */ addu $t2, $t2, $a0 -/* 0D3DF0 800D31F0 8D490000 */ lw $t1, ($t2) -/* 0D3DF4 800D31F4 03E09025 */ move $s2, $ra -/* 0D3DF8 800D31F8 11200025 */ beqz $t1, .L800D3290 -/* 0D3DFC 800D31FC 00000000 */ nop -/* 0D3E00 800D3200 8D2B0008 */ lw $t3, 8($t1) -/* 0D3E04 800D3204 8D2C0010 */ lw $t4, 0x10($t1) -/* 0D3E08 800D3208 016C082A */ slt $at, $t3, $t4 -/* 0D3E0C 800D320C 10200020 */ beqz $at, .L800D3290 -/* 0D3E10 800D3210 00000000 */ nop -/* 0D3E14 800D3214 8D2D000C */ lw $t5, 0xc($t1) -/* 0D3E18 800D3218 01AB6821 */ addu $t5, $t5, $t3 -/* 0D3E1C 800D321C 01AC001A */ div $zero, $t5, $t4 -/* 0D3E20 800D3220 15800002 */ bnez $t4, .L800D322C -/* 0D3E24 800D3224 00000000 */ nop -/* 0D3E28 800D3228 0007000D */ break 7 -.L800D322C: -/* 0D3E2C 800D322C 2401FFFF */ li $at, -1 -/* 0D3E30 800D3230 15810004 */ bne $t4, $at, .L800D3244 -/* 0D3E34 800D3234 3C018000 */ lui $at, 0x8000 -/* 0D3E38 800D3238 15A10002 */ bne $t5, $at, .L800D3244 -/* 0D3E3C 800D323C 00000000 */ nop -/* 0D3E40 800D3240 0006000D */ break 6 -.L800D3244: -/* 0D3E44 800D3244 8D2C0014 */ lw $t4, 0x14($t1) -/* 0D3E48 800D3248 00006810 */ mfhi $t5 -/* 0D3E4C 800D324C 000D6880 */ sll $t5, $t5, 2 -/* 0D3E50 800D3250 018D6021 */ addu $t4, $t4, $t5 -/* 0D3E54 800D3254 8D4D0004 */ lw $t5, 4($t2) -/* 0D3E58 800D3258 256A0001 */ addiu $t2, $t3, 1 -/* 0D3E5C 800D325C AD8D0000 */ sw $t5, ($t4) -/* 0D3E60 800D3260 AD2A0008 */ sw $t2, 8($t1) -/* 0D3E64 800D3264 8D2A0000 */ lw $t2, ($t1) -/* 0D3E68 800D3268 8D4B0000 */ lw $t3, ($t2) -/* 0D3E6C 800D326C 11600008 */ beqz $t3, .L800D3290 -/* 0D3E70 800D3270 00000000 */ nop -/* 0D3E74 800D3274 0C034D05 */ jal __osPopThread -/* 0D3E78 800D3278 01202025 */ move $a0, $t1 -/* 0D3E7C 800D327C 00405025 */ move $t2, $v0 -/* 0D3E80 800D3280 3C04800E */ lui $a0, %hi(__osRunQueue) # $a0, 0x800e -/* 0D3E84 800D3284 01402825 */ move $a1, $t2 -/* 0D3E88 800D3288 0C034CF3 */ jal __osEnqueueThread -/* 0D3E8C 800D328C 24844888 */ addiu $a0, %lo(__osRunQueue) # addiu $a0, $a0, 0x4888 -.L800D3290: -/* 0D3E90 800D3290 02400008 */ jr $s2 -/* 0D3E94 800D3294 00000000 */ nop -glabel handle_CpU -/* 0D3E98 800D3298 3C013000 */ lui $at, 0x3000 -/* 0D3E9C 800D329C 01014824 */ and $t1, $t0, $at -/* 0D3EA0 800D32A0 00094F02 */ srl $t1, $t1, 0x1c -/* 0D3EA4 800D32A4 240A0001 */ li $t2, 1 -/* 0D3EA8 800D32A8 152AFFC2 */ bne $t1, $t2, .L800D31B4 -/* 0D3EAC 800D32AC 00000000 */ nop -/* 0D3EB0 800D32B0 8F5B0118 */ lw $k1, 0x118($k0) -/* 0D3EB4 800D32B4 3C012000 */ lui $at, 0x2000 -/* 0D3EB8 800D32B8 24090001 */ li $t1, 1 -/* 0D3EBC 800D32BC 0361D825 */ or $k1, $k1, $at -/* 0D3EC0 800D32C0 AF490018 */ sw $t1, 0x18($k0) -/* 0D3EC4 800D32C4 1000FFB5 */ b .L800D319C -/* 0D3EC8 800D32C8 AF5B0118 */ sw $k1, 0x118($k0) diff --git a/lib/asm/getcount.s b/lib/asm/getcount.s new file mode 100644 index 00000000..49627f2b --- /dev/null +++ b/lib/asm/getcount.s @@ -0,0 +1,20 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C78D0 */ + +.include "macro.inc" + +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ + +/* Handwritten function */ +glabel osGetCount +/* C84D0 800C78D0 40024800 */ mfc0 $v0, $9 /* handwritten instruction */ +/* C84D4 800C78D4 03E00008 */ jr $ra +/* C84D8 800C78D8 00000000 */ nop +/* C84DC 800C78DC 00000000 */ nop diff --git a/lib/asm/getsr.s b/lib/asm/getsr.s new file mode 100644 index 00000000..ff26c74b --- /dev/null +++ b/lib/asm/getsr.s @@ -0,0 +1,20 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D4570 */ + +.include "macro.inc" + +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ + +/* Handwritten function */ +glabel __osGetSR +/* D5170 800D4570 40026000 */ mfc0 $v0, $12 /* handwritten instruction */ +/* D5174 800D4574 03E00008 */ jr $ra +/* D5178 800D4578 00000000 */ nop +/* D517C 800D457C 00000000 */ nop diff --git a/lib/asm/interrupt.s b/lib/asm/interrupt.s new file mode 100644 index 00000000..954c2fc9 --- /dev/null +++ b/lib/asm/interrupt.s @@ -0,0 +1,35 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D2560 */ + +.include "macro.inc" + +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ + +/* Handwritten function */ +glabel __osDisableInt +/* D3160 800D2560 40086000 */ mfc0 $t0, $12 /* handwritten instruction */ +/* D3164 800D2564 2401FFFE */ addiu $at, $zero, -0x2 +/* D3168 800D2568 01014824 */ and $t1, $t0, $at +/* D316C 800D256C 40896000 */ mtc0 $t1, $12 /* handwritten instruction */ +/* D3170 800D2570 31020001 */ andi $v0, $t0, 0x1 +/* D3174 800D2574 00000000 */ nop +/* D3178 800D2578 03E00008 */ jr $ra +/* D317C 800D257C 00000000 */ nop + +/* Handwritten function */ +glabel __osRestoreInt +/* D3180 800D2580 40086000 */ mfc0 $t0, $12 /* handwritten instruction */ +/* D3184 800D2584 01044025 */ or $t0, $t0, $a0 +/* D3188 800D2588 40886000 */ mtc0 $t0, $12 /* handwritten instruction */ +/* D318C 800D258C 00000000 */ nop +/* D3190 800D2590 00000000 */ nop +/* D3194 800D2594 03E00008 */ jr $ra +/* D3198 800D2598 00000000 */ nop +/* D319C 800D259C 00000000 */ nop diff --git a/lib/asm/invaldcache.s b/lib/asm/invaldcache.s new file mode 100644 index 00000000..64d18bf0 --- /dev/null +++ b/lib/asm/invaldcache.s @@ -0,0 +1,65 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D17F0 */ + +.include "macro.inc" + +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ + +/* Handwritten function */ +glabel osInvalDCache +/* D23F0 800D17F0 18A0001F */ blez $a1, .L800D1870 +/* D23F4 800D17F4 00000000 */ nop +/* D23F8 800D17F8 240B2000 */ addiu $t3, $zero, 0x2000 +/* D23FC 800D17FC 00AB082B */ sltu $at, $a1, $t3 +/* D2400 800D1800 1020001D */ beqz $at, .L800D1878 +/* D2404 800D1804 00000000 */ nop +/* D2408 800D1808 00804025 */ or $t0, $a0, $zero +/* D240C 800D180C 00854821 */ addu $t1, $a0, $a1 +/* D2410 800D1810 0109082B */ sltu $at, $t0, $t1 +/* D2414 800D1814 10200016 */ beqz $at, .L800D1870 +/* D2418 800D1818 00000000 */ nop +/* D241C 800D181C 310A000F */ andi $t2, $t0, 0xF +/* D2420 800D1820 11400007 */ beqz $t2, .L800D1840 +/* D2424 800D1824 2529FFF0 */ addiu $t1, $t1, -0x10 +/* D2428 800D1828 010A4023 */ subu $t0, $t0, $t2 +/* D242C 800D182C BD150000 */ cache 0x15, 0x0($t0) /* handwritten instruction */ +/* D2430 800D1830 0109082B */ sltu $at, $t0, $t1 +/* D2434 800D1834 1020000E */ beqz $at, .L800D1870 +/* D2438 800D1838 00000000 */ nop +/* D243C 800D183C 25080010 */ addiu $t0, $t0, 0x10 +.L800D1840: +/* D2440 800D1840 312A000F */ andi $t2, $t1, 0xF +/* D2444 800D1844 11400006 */ beqz $t2, .L800D1860 +/* D2448 800D1848 00000000 */ nop +/* D244C 800D184C 012A4823 */ subu $t1, $t1, $t2 +/* D2450 800D1850 BD350010 */ cache 0x15, 0x10($t1) /* handwritten instruction */ +/* D2454 800D1854 0128082B */ sltu $at, $t1, $t0 +/* D2458 800D1858 14200005 */ bnez $at, .L800D1870 +/* D245C 800D185C 00000000 */ nop +.L800D1860: +/* D2460 800D1860 BD110000 */ cache 0x11, 0x0($t0) /* handwritten instruction */ +/* D2464 800D1864 0109082B */ sltu $at, $t0, $t1 +/* D2468 800D1868 1420FFFD */ bnez $at, .L800D1860 +/* D246C 800D186C 25080010 */ addiu $t0, $t0, 0x10 +.L800D1870: +/* D2470 800D1870 03E00008 */ jr $ra +/* D2474 800D1874 00000000 */ nop +.L800D1878: +/* D2478 800D1878 3C088000 */ lui $t0, 0x8000 +/* D247C 800D187C 010B4821 */ addu $t1, $t0, $t3 +/* D2480 800D1880 2529FFF0 */ addiu $t1, $t1, -0x10 +.L800D1884: +/* D2484 800D1884 BD010000 */ cache 0x01, 0x0($t0) /* handwritten instruction */ +/* D2488 800D1888 0109082B */ sltu $at, $t0, $t1 +/* D248C 800D188C 1420FFFD */ bnez $at, .L800D1884 +/* D2490 800D1890 25080010 */ addiu $t0, $t0, (0x80000010 & 0xFFFF) +/* D2494 800D1894 03E00008 */ jr $ra +/* D2498 800D1898 00000000 */ nop +/* D249C 800D189C 00000000 */ nop diff --git a/lib/asm/invalicache.s b/lib/asm/invalicache.s new file mode 100644 index 00000000..b9b145d4 --- /dev/null +++ b/lib/asm/invalicache.s @@ -0,0 +1,52 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D46B0 */ + +.include "macro.inc" + +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ + +/* Handwritten function */ +glabel osInvalICache +/* D52B0 800D46B0 18A00011 */ blez $a1, .L800D46F8 +/* D52B4 800D46B4 00000000 */ nop +/* D52B8 800D46B8 240B4000 */ addiu $t3, $zero, 0x4000 +/* D52BC 800D46BC 00AB082B */ sltu $at, $a1, $t3 +/* D52C0 800D46C0 1020000F */ beqz $at, .L800D4700 +/* D52C4 800D46C4 00000000 */ nop +/* D52C8 800D46C8 00804025 */ or $t0, $a0, $zero +/* D52CC 800D46CC 00854821 */ addu $t1, $a0, $a1 +/* D52D0 800D46D0 0109082B */ sltu $at, $t0, $t1 +/* D52D4 800D46D4 10200008 */ beqz $at, .L800D46F8 +/* D52D8 800D46D8 00000000 */ nop +/* D52DC 800D46DC 310A001F */ andi $t2, $t0, 0x1F +/* D52E0 800D46E0 2529FFE0 */ addiu $t1, $t1, -0x20 +/* D52E4 800D46E4 010A4023 */ subu $t0, $t0, $t2 +.L800D46E8: +/* D52E8 800D46E8 BD100000 */ cache 0x10, 0x0($t0) /* handwritten instruction */ +/* D52EC 800D46EC 0109082B */ sltu $at, $t0, $t1 +/* D52F0 800D46F0 1420FFFD */ bnez $at, .L800D46E8 +/* D52F4 800D46F4 25080020 */ addiu $t0, $t0, 0x20 +.L800D46F8: +/* D52F8 800D46F8 03E00008 */ jr $ra +/* D52FC 800D46FC 00000000 */ nop +.L800D4700: +/* D5300 800D4700 3C088000 */ lui $t0, 0x8000 +/* D5304 800D4704 010B4821 */ addu $t1, $t0, $t3 +/* D5308 800D4708 2529FFE0 */ addiu $t1, $t1, -0x20 +.L800D470C: +/* D530C 800D470C BD000000 */ cache 0x00, 0x0($t0) /* handwritten instruction */ +/* D5310 800D4710 0109082B */ sltu $at, $t0, $t1 +/* D5314 800D4714 1420FFFD */ bnez $at, .L800D470C +/* D5318 800D4718 25080020 */ addiu $t0, $t0, (0x80000020 & 0xFFFF) +/* D531C 800D471C 03E00008 */ jr $ra +/* D5320 800D4720 00000000 */ nop +/* D5324 800D4724 00000000 */ nop +/* D5328 800D4728 00000000 */ nop +/* D532C 800D472C 00000000 */ nop diff --git a/lib/asm/libm_vals.s b/lib/asm/libm_vals.s new file mode 100644 index 00000000..3e7f4aca --- /dev/null +++ b/lib/asm/libm_vals.s @@ -0,0 +1,8 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800E0000 */ +/* RODATA ONLY try a randomly high RAM_POS to see if it works. */ + .rdata + .align 4 + .globl __libm_qnan_f +__libm_qnan_f: + .word 0x7F810000 diff --git a/lib/asm/maptlbrdb.s b/lib/asm/maptlbrdb.s new file mode 100644 index 00000000..4f129293 --- /dev/null +++ b/lib/asm/maptlbrdb.s @@ -0,0 +1,40 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D4730 */ + +.include "macro.inc" + +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ + +/* Handwritten function */ +glabel osMapTLBRdb +/* D5330 800D4730 40085000 */ mfc0 $t0, $10 /* handwritten instruction */ +/* D5334 800D4734 2409001F */ addiu $t1, $zero, 0x1F +/* D5338 800D4738 40890000 */ mtc0 $t1, $0 /* handwritten instruction */ +/* D533C 800D473C 40802800 */ mtc0 $zero, $5 /* handwritten instruction */ +/* D5340 800D4740 240A0017 */ addiu $t2, $zero, 0x17 +/* D5344 800D4744 3C09C000 */ lui $t1, (0xC0000000 >> 16) +/* D5348 800D4748 40895000 */ mtc0 $t1, $10 /* handwritten instruction */ +/* D534C 800D474C 3C098000 */ lui $t1, (0x80000000 >> 16) +/* D5350 800D4750 00095982 */ srl $t3, $t1, 6 +/* D5354 800D4754 016A5825 */ or $t3, $t3, $t2 +/* D5358 800D4758 408B1000 */ mtc0 $t3, $2 /* handwritten instruction */ +/* D535C 800D475C 24090001 */ addiu $t1, $zero, 0x1 +/* D5360 800D4760 40891800 */ mtc0 $t1, $3 /* handwritten instruction */ +/* D5364 800D4764 00000000 */ nop +/* D5368 800D4768 42000002 */ tlbwi /* handwritten instruction */ +/* D536C 800D476C 00000000 */ nop +/* D5370 800D4770 00000000 */ nop +/* D5374 800D4774 00000000 */ nop +/* D5378 800D4778 00000000 */ nop +/* D537C 800D477C 40885000 */ mtc0 $t0, $10 /* handwritten instruction */ +/* D5380 800D4780 03E00008 */ jr $ra +/* D5384 800D4784 00000000 */ nop +/* D5388 800D4788 00000000 */ nop +/* D538C 800D478C 00000000 */ nop diff --git a/lib/asm/non_matchings/osViMgr_0D2590/viMgrMain.s b/lib/asm/non_matchings/osViMgr_0D2590/viMgrMain.s deleted file mode 100644 index 477d87aa..00000000 --- a/lib/asm/non_matchings/osViMgr_0D2590/viMgrMain.s +++ /dev/null @@ -1,112 +0,0 @@ -glabel viMgrMain -/* 0D2708 800D1B08 27BDFFB0 */ addiu $sp, $sp, -0x50 -/* 0D270C 800D1B0C AFBF0034 */ sw $ra, 0x34($sp) -/* 0D2710 800D1B10 AFB70030 */ sw $s7, 0x30($sp) -/* 0D2714 800D1B14 0080B825 */ move $s7, $a0 -/* 0D2718 800D1B18 AFB6002C */ sw $s6, 0x2c($sp) -/* 0D271C 800D1B1C AFB50028 */ sw $s5, 0x28($sp) -/* 0D2720 800D1B20 AFB40024 */ sw $s4, 0x24($sp) -/* 0D2724 800D1B24 AFB30020 */ sw $s3, 0x20($sp) -/* 0D2728 800D1B28 AFB2001C */ sw $s2, 0x1c($sp) -/* 0D272C 800D1B2C AFB10018 */ sw $s1, 0x18($sp) -/* 0D2730 800D1B30 AFB00014 */ sw $s0, 0x14($sp) -/* 0D2734 800D1B34 0C035820 */ jal __osViGetCurrentContext -/* 0D2738 800D1B38 AFA00044 */ sw $zero, 0x44($sp) -/* 0D273C 800D1B3C 94430002 */ lhu $v1, 2($v0) -/* 0D2740 800D1B40 3C018013 */ lui $at, %hi(retrace) # $at, 0x8013 -/* 0D2744 800D1B44 2416000E */ li $s6, 14 -/* 0D2748 800D1B48 14600004 */ bnez $v1, .L800D1B5C -/* 0D274C 800D1B4C A423D190 */ sh $v1, %lo(retrace)($at) -/* 0D2750 800D1B50 24030001 */ li $v1, 1 -/* 0D2754 800D1B54 3C018013 */ lui $at, %hi(retrace) # $at, 0x8013 -/* 0D2758 800D1B58 A423D190 */ sh $v1, %lo(retrace)($at) -.L800D1B5C: -/* 0D275C 800D1B5C 3C138013 */ lui $s3, %hi(__osViIntrCount) # $s3, 0x8013 -/* 0D2760 800D1B60 3C128013 */ lui $s2, %hi(__osBaseCounter) # $s2, 0x8013 -/* 0D2764 800D1B64 3C118013 */ lui $s1, %hi(__osCurrentTime) # $s1, 0x8013 -/* 0D2768 800D1B68 2631D220 */ addiu $s1, %lo(__osCurrentTime) # addiu $s1, $s1, -0x2de0 -/* 0D276C 800D1B6C 2652D228 */ addiu $s2, %lo(__osBaseCounter) # addiu $s2, $s2, -0x2dd8 -/* 0D2770 800D1B70 2673D22C */ addiu $s3, %lo(__osViIntrCount) # addiu $s3, $s3, -0x2dd4 -/* 0D2774 800D1B74 2415000D */ li $s5, 13 -/* 0D2778 800D1B78 27B40044 */ addiu $s4, $sp, 0x44 -.L800D1B7C: -/* 0D277C 800D1B7C 8EE4000C */ lw $a0, 0xc($s7) -.L800D1B80: -/* 0D2780 800D1B80 02802825 */ move $a1, $s4 -/* 0D2784 800D1B84 0C0322EC */ jal osRecvMesg -/* 0D2788 800D1B88 24060001 */ li $a2, 1 -/* 0D278C 800D1B8C 8FAE0044 */ lw $t6, 0x44($sp) -/* 0D2790 800D1B90 95C30000 */ lhu $v1, ($t6) -/* 0D2794 800D1B94 10750005 */ beq $v1, $s5, .L800D1BAC -/* 0D2798 800D1B98 00000000 */ nop -/* 0D279C 800D1B9C 1076002A */ beq $v1, $s6, .L800D1C48 -/* 0D27A0 800D1BA0 00000000 */ nop -/* 0D27A4 800D1BA4 1000FFF6 */ b .L800D1B80 -/* 0D27A8 800D1BA8 8EE4000C */ lw $a0, 0xc($s7) -.L800D1BAC: -/* 0D27AC 800D1BAC 0C035824 */ jal __osViSwapContext -/* 0D27B0 800D1BB0 00000000 */ nop -/* 0D27B4 800D1BB4 3C038013 */ lui $v1, %hi(retrace) # $v1, 0x8013 -/* 0D27B8 800D1BB8 9463D190 */ lhu $v1, %lo(retrace)($v1) -/* 0D27BC 800D1BBC 3C018013 */ lui $at, %hi(retrace) # $at, 0x8013 -/* 0D27C0 800D1BC0 2463FFFF */ addiu $v1, $v1, -1 -/* 0D27C4 800D1BC4 306FFFFF */ andi $t7, $v1, 0xffff -/* 0D27C8 800D1BC8 15E0000E */ bnez $t7, .L800D1C04 -/* 0D27CC 800D1BCC A42FD190 */ sh $t7, %lo(retrace)($at) -/* 0D27D0 800D1BD0 0C035820 */ jal __osViGetCurrentContext -/* 0D27D4 800D1BD4 00000000 */ nop -/* 0D27D8 800D1BD8 8C580010 */ lw $t8, 0x10($v0) -/* 0D27DC 800D1BDC 00408025 */ move $s0, $v0 -/* 0D27E0 800D1BE0 00003025 */ move $a2, $zero -/* 0D27E4 800D1BE4 53000005 */ beql $t8, $zero, .L800D1BFC -/* 0D27E8 800D1BE8 96030002 */ lhu $v1, 2($s0) -/* 0D27EC 800D1BEC 8C440010 */ lw $a0, 0x10($v0) -/* 0D27F0 800D1BF0 0C03238C */ jal osSendMesg -/* 0D27F4 800D1BF4 8C450014 */ lw $a1, 0x14($v0) -/* 0D27F8 800D1BF8 96030002 */ lhu $v1, 2($s0) -.L800D1BFC: -/* 0D27FC 800D1BFC 3C018013 */ lui $at, %hi(retrace) # $at, 0x8013 -/* 0D2800 800D1C00 A423D190 */ sh $v1, %lo(retrace)($at) -.L800D1C04: -/* 0D2804 800D1C04 8E790000 */ lw $t9, ($s3) -/* 0D2808 800D1C08 8E500000 */ lw $s0, ($s2) -/* 0D280C 800D1C0C 27280001 */ addiu $t0, $t9, 1 -/* 0D2810 800D1C10 0C031E34 */ jal osGetCount -/* 0D2814 800D1C14 AE680000 */ sw $t0, ($s3) -/* 0D2818 800D1C18 8E2D0004 */ lw $t5, 4($s1) -/* 0D281C 800D1C1C 00508023 */ subu $s0, $v0, $s0 -/* 0D2820 800D1C20 8E2C0000 */ lw $t4, ($s1) -/* 0D2824 800D1C24 020D7821 */ addu $t7, $s0, $t5 -/* 0D2828 800D1C28 240A0000 */ li $t2, 0 -/* 0D282C 800D1C2C 01ED082B */ sltu $at, $t7, $t5 -/* 0D2830 800D1C30 002A7021 */ addu $t6, $at, $t2 -/* 0D2834 800D1C34 01CC7021 */ addu $t6, $t6, $t4 -/* 0D2838 800D1C38 AE420000 */ sw $v0, ($s2) -/* 0D283C 800D1C3C AE2E0000 */ sw $t6, ($s1) -/* 0D2840 800D1C40 1000FFCE */ b .L800D1B7C -/* 0D2844 800D1C44 AE2F0004 */ sw $t7, 4($s1) -.L800D1C48: -/* 0D2848 800D1C48 0C0353D3 */ jal __osTimerInterrupt -/* 0D284C 800D1C4C 00000000 */ nop -/* 0D2850 800D1C50 1000FFCB */ b .L800D1B80 -/* 0D2854 800D1C54 8EE4000C */ lw $a0, 0xc($s7) -/* 0D2858 800D1C58 00000000 */ nop -/* 0D285C 800D1C5C 00000000 */ nop -/* 0D2860 800D1C60 00000000 */ nop -/* 0D2864 800D1C64 00000000 */ nop -/* 0D2868 800D1C68 00000000 */ nop -/* 0D286C 800D1C6C 00000000 */ nop -/* 0D2870 800D1C70 8FBF0034 */ lw $ra, 0x34($sp) -/* 0D2874 800D1C74 8FB00014 */ lw $s0, 0x14($sp) -/* 0D2878 800D1C78 8FB10018 */ lw $s1, 0x18($sp) -/* 0D287C 800D1C7C 8FB2001C */ lw $s2, 0x1c($sp) -/* 0D2880 800D1C80 8FB30020 */ lw $s3, 0x20($sp) -/* 0D2884 800D1C84 8FB40024 */ lw $s4, 0x24($sp) -/* 0D2888 800D1C88 8FB50028 */ lw $s5, 0x28($sp) -/* 0D288C 800D1C8C 8FB6002C */ lw $s6, 0x2c($sp) -/* 0D2890 800D1C90 8FB70030 */ lw $s7, 0x30($sp) -/* 0D2894 800D1C94 03E00008 */ jr $ra -/* 0D2898 800D1C98 27BD0050 */ addiu $sp, $sp, 0x50 - -/* 0D289C 800D1C9C 00000000 */ nop - diff --git a/lib/asm/non_matchings/unknown_0D3020/_Genld.s b/lib/asm/non_matchings/unknown_0D3020/_Genld.s deleted file mode 100644 index 146d6546..00000000 --- a/lib/asm/non_matchings/unknown_0D3020/_Genld.s +++ /dev/null @@ -1,391 +0,0 @@ -glabel _Genld -/* 0D75A0 800D69A0 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 0D75A4 800D69A4 AFB20028 */ sw $s2, 0x28($sp) -/* 0D75A8 800D69A8 00127400 */ sll $t6, $s2, 0x10 -/* 0D75AC 800D69AC 000E9403 */ sra $s2, $t6, 0x10 -/* 0D75B0 800D69B0 AFB30024 */ sw $s3, 0x24($sp) -/* 0D75B4 800D69B4 0013C400 */ sll $t8, $s3, 0x10 -/* 0D75B8 800D69B8 00189C03 */ sra $s3, $t8, 0x10 -/* 0D75BC 800D69BC 328E00FF */ andi $t6, $s4, 0xff -/* 0D75C0 800D69C0 AFB4001C */ sw $s4, 0x1c($sp) -/* 0D75C4 800D69C4 01C0A025 */ move $s4, $t6 -/* 0D75C8 800D69C8 1E600004 */ bgtz $s3, .L800D69DC -/* 0D75CC 800D69CC AFBF0014 */ sw $ra, 0x14($sp) -/* 0D75D0 800D69D0 3C11800F */ lui $s1, %hi(_Genld_0_string) # $s1, 0x800f -/* 0D75D4 800D69D4 263198B0 */ addiu $s1, %lo(_Genld_0_string) # addiu $s1, $s1, -0x6750 -/* 0D75D8 800D69D8 24130001 */ li $s3, 1 -.L800D69DC: -/* 0D75DC 800D69DC 24020066 */ li $v0, 102 -/* 0D75E0 800D69E0 1054000C */ beq $v0, $s4, .L800D6A14 -/* 0D75E4 800D69E4 02801825 */ move $v1, $s4 -/* 0D75E8 800D69E8 24040067 */ li $a0, 103 -/* 0D75EC 800D69EC 10830002 */ beq $a0, $v1, .L800D69F8 -/* 0D75F0 800D69F0 24010047 */ li $at, 71 -/* 0D75F4 800D69F4 14610096 */ bne $v1, $at, .L800D6C50 -.L800D69F8: -/* 0D75F8 800D69F8 2A41FFFC */ slti $at, $s2, -4 -/* 0D75FC 800D69FC 14200094 */ bnez $at, .L800D6C50 -/* 0D7600 800D6A00 00000000 */ nop -/* 0D7604 800D6A04 8E0F0024 */ lw $t7, 0x24($s0) -/* 0D7608 800D6A08 024F082A */ slt $at, $s2, $t7 -/* 0D760C 800D6A0C 10200090 */ beqz $at, .L800D6C50 -/* 0D7610 800D6A10 00000000 */ nop -.L800D6A14: -/* 0D7614 800D6A14 26520001 */ addiu $s2, $s2, 1 -/* 0D7618 800D6A18 0012C400 */ sll $t8, $s2, 0x10 -/* 0D761C 800D6A1C 1043000E */ beq $v0, $v1, .L800D6A58 -/* 0D7620 800D6A20 00189403 */ sra $s2, $t8, 0x10 -/* 0D7624 800D6A24 8E0E0030 */ lw $t6, 0x30($s0) -/* 0D7628 800D6A28 8E020024 */ lw $v0, 0x24($s0) -/* 0D762C 800D6A2C 31CF0008 */ andi $t7, $t6, 8 -/* 0D7630 800D6A30 15E00005 */ bnez $t7, .L800D6A48 -/* 0D7634 800D6A34 0262082A */ slt $at, $s3, $v0 -/* 0D7638 800D6A38 50200004 */ beql $at, $zero, .L800D6A4C -/* 0D763C 800D6A3C 0052C023 */ subu $t8, $v0, $s2 -/* 0D7640 800D6A40 AE130024 */ sw $s3, 0x24($s0) -/* 0D7644 800D6A44 02601025 */ move $v0, $s3 -.L800D6A48: -/* 0D7648 800D6A48 0052C023 */ subu $t8, $v0, $s2 -.L800D6A4C: -/* 0D764C 800D6A4C 07010002 */ bgez $t8, .L800D6A58 -/* 0D7650 800D6A50 AE180024 */ sw $t8, 0x24($s0) -/* 0D7654 800D6A54 AE000024 */ sw $zero, 0x24($s0) -.L800D6A58: -/* 0D7658 800D6A58 1E400033 */ bgtz $s2, .L800D6B28 -/* 0D765C 800D6A5C 0272082A */ slt $at, $s3, $s2 -/* 0D7660 800D6A60 8E0F0008 */ lw $t7, 8($s0) -/* 0D7664 800D6A64 8E180014 */ lw $t8, 0x14($s0) -/* 0D7668 800D6A68 240E0030 */ li $t6, 48 -/* 0D766C 800D6A6C 00121823 */ negu $v1, $s2 -/* 0D7670 800D6A70 01F8C821 */ addu $t9, $t7, $t8 -/* 0D7674 800D6A74 A32E0000 */ sb $t6, ($t9) -/* 0D7678 800D6A78 8E0F0014 */ lw $t7, 0x14($s0) -/* 0D767C 800D6A7C 8E020024 */ lw $v0, 0x24($s0) -/* 0D7680 800D6A80 02202825 */ move $a1, $s1 -/* 0D7684 800D6A84 25F80001 */ addiu $t8, $t7, 1 -/* 0D7688 800D6A88 1C400005 */ bgtz $v0, .L800D6AA0 -/* 0D768C 800D6A8C AE180014 */ sw $t8, 0x14($s0) -/* 0D7690 800D6A90 8E0E0030 */ lw $t6, 0x30($s0) -/* 0D7694 800D6A94 31D90008 */ andi $t9, $t6, 8 -/* 0D7698 800D6A98 5320000B */ beql $t9, $zero, .L800D6AC8 -/* 0D769C 800D6A9C 0043082A */ slt $at, $v0, $v1 -.L800D6AA0: -/* 0D76A0 800D6AA0 8E180008 */ lw $t8, 8($s0) -/* 0D76A4 800D6AA4 8E0E0014 */ lw $t6, 0x14($s0) -/* 0D76A8 800D6AA8 240F002E */ li $t7, 46 -/* 0D76AC 800D6AAC 030EC821 */ addu $t9, $t8, $t6 -/* 0D76B0 800D6AB0 A32F0000 */ sb $t7, ($t9) -/* 0D76B4 800D6AB4 8E180014 */ lw $t8, 0x14($s0) -/* 0D76B8 800D6AB8 8E020024 */ lw $v0, 0x24($s0) -/* 0D76BC 800D6ABC 270E0001 */ addiu $t6, $t8, 1 -/* 0D76C0 800D6AC0 AE0E0014 */ sw $t6, 0x14($s0) -/* 0D76C4 800D6AC4 0043082A */ slt $at, $v0, $v1 -.L800D6AC8: -/* 0D76C8 800D6AC8 50200006 */ beql $at, $zero, .L800D6AE4 -/* 0D76CC 800D6ACC 0052C021 */ addu $t8, $v0, $s2 -/* 0D76D0 800D6AD0 00029023 */ negu $s2, $v0 -/* 0D76D4 800D6AD4 00127C00 */ sll $t7, $s2, 0x10 -/* 0D76D8 800D6AD8 000F9403 */ sra $s2, $t7, 0x10 -/* 0D76DC 800D6ADC 00121823 */ negu $v1, $s2 -/* 0D76E0 800D6AE0 0052C021 */ addu $t8, $v0, $s2 -.L800D6AE4: -/* 0D76E4 800D6AE4 0313082A */ slt $at, $t8, $s3 -/* 0D76E8 800D6AE8 AE030018 */ sw $v1, 0x18($s0) -/* 0D76EC 800D6AEC 10200004 */ beqz $at, .L800D6B00 -/* 0D76F0 800D6AF0 AE180024 */ sw $t8, 0x24($s0) -/* 0D76F4 800D6AF4 00189C00 */ sll $s3, $t8, 0x10 -/* 0D76F8 800D6AF8 00137403 */ sra $t6, $s3, 0x10 -/* 0D76FC 800D6AFC 01C09825 */ move $s3, $t6 -.L800D6B00: -/* 0D7700 800D6B00 8E0F0008 */ lw $t7, 8($s0) -/* 0D7704 800D6B04 8E190014 */ lw $t9, 0x14($s0) -/* 0D7708 800D6B08 AE13001C */ sw $s3, 0x1c($s0) -/* 0D770C 800D6B0C 02603025 */ move $a2, $s3 -/* 0D7710 800D6B10 0C03385C */ jal memcpy -/* 0D7714 800D6B14 01F92021 */ addu $a0, $t7, $t9 -/* 0D7718 800D6B18 8E180024 */ lw $t8, 0x24($s0) -/* 0D771C 800D6B1C 03137023 */ subu $t6, $t8, $s3 -/* 0D7720 800D6B20 100000E2 */ b .L800D6EAC -/* 0D7724 800D6B24 AE0E0020 */ sw $t6, 0x20($s0) -.L800D6B28: -/* 0D7728 800D6B28 1020001D */ beqz $at, .L800D6BA0 -/* 0D772C 800D6B2C 02202825 */ move $a1, $s1 -/* 0D7730 800D6B30 8E0F0008 */ lw $t7, 8($s0) -/* 0D7734 800D6B34 8E190014 */ lw $t9, 0x14($s0) -/* 0D7738 800D6B38 02202825 */ move $a1, $s1 -/* 0D773C 800D6B3C 02603025 */ move $a2, $s3 -/* 0D7740 800D6B40 0C03385C */ jal memcpy -/* 0D7744 800D6B44 01F92021 */ addu $a0, $t7, $t9 -/* 0D7748 800D6B48 8E180014 */ lw $t8, 0x14($s0) -/* 0D774C 800D6B4C 8E020024 */ lw $v0, 0x24($s0) -/* 0D7750 800D6B50 02537823 */ subu $t7, $s2, $s3 -/* 0D7754 800D6B54 03137021 */ addu $t6, $t8, $s3 -/* 0D7758 800D6B58 AE0E0014 */ sw $t6, 0x14($s0) -/* 0D775C 800D6B5C 1C400005 */ bgtz $v0, .L800D6B74 -/* 0D7760 800D6B60 AE0F0018 */ sw $t7, 0x18($s0) -/* 0D7764 800D6B64 8E190030 */ lw $t9, 0x30($s0) -/* 0D7768 800D6B68 33380008 */ andi $t8, $t9, 8 -/* 0D776C 800D6B6C 1300000A */ beqz $t8, .L800D6B98 -/* 0D7770 800D6B70 00000000 */ nop -.L800D6B74: -/* 0D7774 800D6B74 8E0F0008 */ lw $t7, 8($s0) -/* 0D7778 800D6B78 8E190014 */ lw $t9, 0x14($s0) -/* 0D777C 800D6B7C 240E002E */ li $t6, 46 -/* 0D7780 800D6B80 01F9C021 */ addu $t8, $t7, $t9 -/* 0D7784 800D6B84 A30E0000 */ sb $t6, ($t8) -/* 0D7788 800D6B88 8E0F001C */ lw $t7, 0x1c($s0) -/* 0D778C 800D6B8C 8E020024 */ lw $v0, 0x24($s0) -/* 0D7790 800D6B90 25F90001 */ addiu $t9, $t7, 1 -/* 0D7794 800D6B94 AE19001C */ sw $t9, 0x1c($s0) -.L800D6B98: -/* 0D7798 800D6B98 100000C4 */ b .L800D6EAC -/* 0D779C 800D6B9C AE020020 */ sw $v0, 0x20($s0) -.L800D6BA0: -/* 0D77A0 800D6BA0 8E0E0008 */ lw $t6, 8($s0) -/* 0D77A4 800D6BA4 8E180014 */ lw $t8, 0x14($s0) -/* 0D77A8 800D6BA8 02403025 */ move $a2, $s2 -/* 0D77AC 800D6BAC 0C03385C */ jal memcpy -/* 0D77B0 800D6BB0 01D82021 */ addu $a0, $t6, $t8 -/* 0D77B4 800D6BB4 8E0F0014 */ lw $t7, 0x14($s0) -/* 0D77B8 800D6BB8 8E020024 */ lw $v0, 0x24($s0) -/* 0D77BC 800D6BBC 02729823 */ subu $s3, $s3, $s2 -/* 0D77C0 800D6BC0 00137400 */ sll $t6, $s3, 0x10 -/* 0D77C4 800D6BC4 01F2C821 */ addu $t9, $t7, $s2 -/* 0D77C8 800D6BC8 AE190014 */ sw $t9, 0x14($s0) -/* 0D77CC 800D6BCC 1C400005 */ bgtz $v0, .L800D6BE4 -/* 0D77D0 800D6BD0 000E9C03 */ sra $s3, $t6, 0x10 -/* 0D77D4 800D6BD4 8E0F0030 */ lw $t7, 0x30($s0) -/* 0D77D8 800D6BD8 31F90008 */ andi $t9, $t7, 8 -/* 0D77DC 800D6BDC 5320000B */ beql $t9, $zero, .L800D6C0C -/* 0D77E0 800D6BE0 0053082A */ slt $at, $v0, $s3 -.L800D6BE4: -/* 0D77E4 800D6BE4 8E180008 */ lw $t8, 8($s0) -/* 0D77E8 800D6BE8 8E0F0014 */ lw $t7, 0x14($s0) -/* 0D77EC 800D6BEC 240E002E */ li $t6, 46 -/* 0D77F0 800D6BF0 030FC821 */ addu $t9, $t8, $t7 -/* 0D77F4 800D6BF4 A32E0000 */ sb $t6, ($t9) -/* 0D77F8 800D6BF8 8E180014 */ lw $t8, 0x14($s0) -/* 0D77FC 800D6BFC 8E020024 */ lw $v0, 0x24($s0) -/* 0D7800 800D6C00 270F0001 */ addiu $t7, $t8, 1 -/* 0D7804 800D6C04 AE0F0014 */ sw $t7, 0x14($s0) -/* 0D7808 800D6C08 0053082A */ slt $at, $v0, $s3 -.L800D6C0C: -/* 0D780C 800D6C0C 10200004 */ beqz $at, .L800D6C20 -/* 0D7810 800D6C10 02512821 */ addu $a1, $s2, $s1 -/* 0D7814 800D6C14 00029C00 */ sll $s3, $v0, 0x10 -/* 0D7818 800D6C18 00137403 */ sra $t6, $s3, 0x10 -/* 0D781C 800D6C1C 01C09825 */ move $s3, $t6 -.L800D6C20: -/* 0D7820 800D6C20 8E190008 */ lw $t9, 8($s0) -/* 0D7824 800D6C24 8E180014 */ lw $t8, 0x14($s0) -/* 0D7828 800D6C28 02603025 */ move $a2, $s3 -/* 0D782C 800D6C2C 0C03385C */ jal memcpy -/* 0D7830 800D6C30 03382021 */ addu $a0, $t9, $t8 -/* 0D7834 800D6C34 8E0F0014 */ lw $t7, 0x14($s0) -/* 0D7838 800D6C38 8E190024 */ lw $t9, 0x24($s0) -/* 0D783C 800D6C3C 01F37021 */ addu $t6, $t7, $s3 -/* 0D7840 800D6C40 0333C023 */ subu $t8, $t9, $s3 -/* 0D7844 800D6C44 AE0E0014 */ sw $t6, 0x14($s0) -/* 0D7848 800D6C48 10000098 */ b .L800D6EAC -/* 0D784C 800D6C4C AE180018 */ sw $t8, 0x18($s0) -.L800D6C50: -/* 0D7850 800D6C50 10830003 */ beq $a0, $v1, .L800D6C60 -/* 0D7854 800D6C54 24010047 */ li $at, 71 -/* 0D7858 800D6C58 54610011 */ bnel $v1, $at, .L800D6CA0 -/* 0D785C 800D6C5C 8E180008 */ lw $t8, 8($s0) -.L800D6C60: -/* 0D7860 800D6C60 8E020024 */ lw $v0, 0x24($s0) -/* 0D7864 800D6C64 24140045 */ li $s4, 69 -/* 0D7868 800D6C68 0262082A */ slt $at, $s3, $v0 -/* 0D786C 800D6C6C 50200004 */ beql $at, $zero, .L800D6C80 -/* 0D7870 800D6C70 244FFFFF */ addiu $t7, $v0, -1 -/* 0D7874 800D6C74 AE130024 */ sw $s3, 0x24($s0) -/* 0D7878 800D6C78 02601025 */ move $v0, $s3 -/* 0D787C 800D6C7C 244FFFFF */ addiu $t7, $v0, -1 -.L800D6C80: -/* 0D7880 800D6C80 05E10002 */ bgez $t7, .L800D6C8C -/* 0D7884 800D6C84 AE0F0024 */ sw $t7, 0x24($s0) -/* 0D7888 800D6C88 AE000024 */ sw $zero, 0x24($s0) -.L800D6C8C: -/* 0D788C 800D6C8C 14830003 */ bne $a0, $v1, .L800D6C9C -/* 0D7890 800D6C90 00000000 */ nop -/* 0D7894 800D6C94 10000001 */ b .L800D6C9C -/* 0D7898 800D6C98 24140065 */ li $s4, 101 -.L800D6C9C: -/* 0D789C 800D6C9C 8E180008 */ lw $t8, 8($s0) -.L800D6CA0: -/* 0D78A0 800D6CA0 8E0F0014 */ lw $t7, 0x14($s0) -/* 0D78A4 800D6CA4 92390000 */ lbu $t9, ($s1) -/* 0D78A8 800D6CA8 26310001 */ addiu $s1, $s1, 1 -/* 0D78AC 800D6CAC 030F7021 */ addu $t6, $t8, $t7 -/* 0D78B0 800D6CB0 A1D90000 */ sb $t9, ($t6) -/* 0D78B4 800D6CB4 8E180014 */ lw $t8, 0x14($s0) -/* 0D78B8 800D6CB8 8E020024 */ lw $v0, 0x24($s0) -/* 0D78BC 800D6CBC 270F0001 */ addiu $t7, $t8, 1 -/* 0D78C0 800D6CC0 1C400005 */ bgtz $v0, .L800D6CD8 -/* 0D78C4 800D6CC4 AE0F0014 */ sw $t7, 0x14($s0) -/* 0D78C8 800D6CC8 8E190030 */ lw $t9, 0x30($s0) -/* 0D78CC 800D6CCC 332E0008 */ andi $t6, $t9, 8 -/* 0D78D0 800D6CD0 11C0000A */ beqz $t6, .L800D6CFC -/* 0D78D4 800D6CD4 00000000 */ nop -.L800D6CD8: -/* 0D78D8 800D6CD8 8E0F0008 */ lw $t7, 8($s0) -/* 0D78DC 800D6CDC 8E190014 */ lw $t9, 0x14($s0) -/* 0D78E0 800D6CE0 2418002E */ li $t8, 46 -/* 0D78E4 800D6CE4 01F97021 */ addu $t6, $t7, $t9 -/* 0D78E8 800D6CE8 A1D80000 */ sb $t8, ($t6) -/* 0D78EC 800D6CEC 8E0F0014 */ lw $t7, 0x14($s0) -/* 0D78F0 800D6CF0 8E020024 */ lw $v0, 0x24($s0) -/* 0D78F4 800D6CF4 25F90001 */ addiu $t9, $t7, 1 -/* 0D78F8 800D6CF8 AE190014 */ sw $t9, 0x14($s0) -.L800D6CFC: -/* 0D78FC 800D6CFC 58400016 */ blezl $v0, .L800D6D58 -/* 0D7900 800D6D00 8E0E0008 */ lw $t6, 8($s0) -/* 0D7904 800D6D04 2673FFFF */ addiu $s3, $s3, -1 -/* 0D7908 800D6D08 0013C400 */ sll $t8, $s3, 0x10 -/* 0D790C 800D6D0C 00189C03 */ sra $s3, $t8, 0x10 -/* 0D7910 800D6D10 0053082A */ slt $at, $v0, $s3 -/* 0D7914 800D6D14 10200004 */ beqz $at, .L800D6D28 -/* 0D7918 800D6D18 02202825 */ move $a1, $s1 -/* 0D791C 800D6D1C 00029C00 */ sll $s3, $v0, 0x10 -/* 0D7920 800D6D20 00137C03 */ sra $t7, $s3, 0x10 -/* 0D7924 800D6D24 01E09825 */ move $s3, $t7 -.L800D6D28: -/* 0D7928 800D6D28 8E190008 */ lw $t9, 8($s0) -/* 0D792C 800D6D2C 8E180014 */ lw $t8, 0x14($s0) -/* 0D7930 800D6D30 02603025 */ move $a2, $s3 -/* 0D7934 800D6D34 0C03385C */ jal memcpy -/* 0D7938 800D6D38 03382021 */ addu $a0, $t9, $t8 -/* 0D793C 800D6D3C 8E0E0014 */ lw $t6, 0x14($s0) -/* 0D7940 800D6D40 8E190024 */ lw $t9, 0x24($s0) -/* 0D7944 800D6D44 01D37821 */ addu $t7, $t6, $s3 -/* 0D7948 800D6D48 0333C023 */ subu $t8, $t9, $s3 -/* 0D794C 800D6D4C AE0F0014 */ sw $t7, 0x14($s0) -/* 0D7950 800D6D50 AE180018 */ sw $t8, 0x18($s0) -/* 0D7954 800D6D54 8E0E0008 */ lw $t6, 8($s0) -.L800D6D58: -/* 0D7958 800D6D58 8E0F0014 */ lw $t7, 0x14($s0) -/* 0D795C 800D6D5C 01CF8821 */ addu $s1, $t6, $t7 -/* 0D7960 800D6D60 26310001 */ addiu $s1, $s1, 1 -/* 0D7964 800D6D64 06400005 */ bltz $s2, .L800D6D7C -/* 0D7968 800D6D68 A234FFFF */ sb $s4, -1($s1) -/* 0D796C 800D6D6C 2419002B */ li $t9, 43 -/* 0D7970 800D6D70 A2390000 */ sb $t9, ($s1) -/* 0D7974 800D6D74 10000008 */ b .L800D6D98 -/* 0D7978 800D6D78 26310001 */ addiu $s1, $s1, 1 -.L800D6D7C: -/* 0D797C 800D6D7C 00129023 */ negu $s2, $s2 -/* 0D7980 800D6D80 00127400 */ sll $t6, $s2, 0x10 -/* 0D7984 800D6D84 2418002D */ li $t8, 45 -/* 0D7988 800D6D88 000E7C03 */ sra $t7, $t6, 0x10 -/* 0D798C 800D6D8C A2380000 */ sb $t8, ($s1) -/* 0D7990 800D6D90 26310001 */ addiu $s1, $s1, 1 -/* 0D7994 800D6D94 01E09025 */ move $s2, $t7 -.L800D6D98: -/* 0D7998 800D6D98 2A410064 */ slti $at, $s2, 0x64 -/* 0D799C 800D6D9C 5420002A */ bnezl $at, .L800D6E48 -/* 0D79A0 800D6DA0 2402000A */ li $v0, 10 -/* 0D79A4 800D6DA4 2A4103E8 */ slti $at, $s2, 0x3e8 -/* 0D79A8 800D6DA8 14200013 */ bnez $at, .L800D6DF8 -/* 0D79AC 800D6DAC 240203E8 */ li $v0, 1000 -/* 0D79B0 800D6DB0 0242001A */ div $zero, $s2, $v0 -/* 0D79B4 800D6DB4 14400002 */ bnez $v0, .L800D6DC0 -/* 0D79B8 800D6DB8 00000000 */ nop -/* 0D79BC 800D6DBC 0007000D */ break 7 -.L800D6DC0: -/* 0D79C0 800D6DC0 2401FFFF */ li $at, -1 -/* 0D79C4 800D6DC4 14410004 */ bne $v0, $at, .L800D6DD8 -/* 0D79C8 800D6DC8 3C018000 */ lui $at, 0x8000 -/* 0D79CC 800D6DCC 16410002 */ bne $s2, $at, .L800D6DD8 -/* 0D79D0 800D6DD0 00000000 */ nop -/* 0D79D4 800D6DD4 0006000D */ break 6 -.L800D6DD8: -/* 0D79D8 800D6DD8 00009010 */ mfhi $s2 -/* 0D79DC 800D6DDC 00127400 */ sll $t6, $s2, 0x10 -/* 0D79E0 800D6DE0 0000C812 */ mflo $t9 -/* 0D79E4 800D6DE4 27380030 */ addiu $t8, $t9, 0x30 -/* 0D79E8 800D6DE8 000E7C03 */ sra $t7, $t6, 0x10 -/* 0D79EC 800D6DEC 01E09025 */ move $s2, $t7 -/* 0D79F0 800D6DF0 A2380000 */ sb $t8, ($s1) -/* 0D79F4 800D6DF4 26310001 */ addiu $s1, $s1, 1 -.L800D6DF8: -/* 0D79F8 800D6DF8 24020064 */ li $v0, 100 -/* 0D79FC 800D6DFC 0242001A */ div $zero, $s2, $v0 -/* 0D7A00 800D6E00 14400002 */ bnez $v0, .L800D6E0C -/* 0D7A04 800D6E04 00000000 */ nop -/* 0D7A08 800D6E08 0007000D */ break 7 -.L800D6E0C: -/* 0D7A0C 800D6E0C 2401FFFF */ li $at, -1 -/* 0D7A10 800D6E10 14410004 */ bne $v0, $at, .L800D6E24 -/* 0D7A14 800D6E14 3C018000 */ lui $at, 0x8000 -/* 0D7A18 800D6E18 16410002 */ bne $s2, $at, .L800D6E24 -/* 0D7A1C 800D6E1C 00000000 */ nop -/* 0D7A20 800D6E20 0006000D */ break 6 -.L800D6E24: -/* 0D7A24 800D6E24 00009010 */ mfhi $s2 -/* 0D7A28 800D6E28 00127400 */ sll $t6, $s2, 0x10 -/* 0D7A2C 800D6E2C 0000C812 */ mflo $t9 -/* 0D7A30 800D6E30 27380030 */ addiu $t8, $t9, 0x30 -/* 0D7A34 800D6E34 000E7C03 */ sra $t7, $t6, 0x10 -/* 0D7A38 800D6E38 01E09025 */ move $s2, $t7 -/* 0D7A3C 800D6E3C A2380000 */ sb $t8, ($s1) -/* 0D7A40 800D6E40 26310001 */ addiu $s1, $s1, 1 -/* 0D7A44 800D6E44 2402000A */ li $v0, 10 -.L800D6E48: -/* 0D7A48 800D6E48 0242001A */ div $zero, $s2, $v0 -/* 0D7A4C 800D6E4C 14400002 */ bnez $v0, .L800D6E58 -/* 0D7A50 800D6E50 00000000 */ nop -/* 0D7A54 800D6E54 0007000D */ break 7 -.L800D6E58: -/* 0D7A58 800D6E58 2401FFFF */ li $at, -1 -/* 0D7A5C 800D6E5C 14410004 */ bne $v0, $at, .L800D6E70 -/* 0D7A60 800D6E60 3C018000 */ lui $at, 0x8000 -/* 0D7A64 800D6E64 16410002 */ bne $s2, $at, .L800D6E70 -/* 0D7A68 800D6E68 00000000 */ nop -/* 0D7A6C 800D6E6C 0006000D */ break 6 -.L800D6E70: -/* 0D7A70 800D6E70 00009010 */ mfhi $s2 -/* 0D7A74 800D6E74 00127400 */ sll $t6, $s2, 0x10 -/* 0D7A78 800D6E78 0000C812 */ mflo $t9 -/* 0D7A7C 800D6E7C 27380030 */ addiu $t8, $t9, 0x30 -/* 0D7A80 800D6E80 000E7C03 */ sra $t7, $t6, 0x10 -/* 0D7A84 800D6E84 25F90030 */ addiu $t9, $t7, 0x30 -/* 0D7A88 800D6E88 A2380000 */ sb $t8, ($s1) -/* 0D7A8C 800D6E8C A2390001 */ sb $t9, 1($s1) -/* 0D7A90 800D6E90 8E180008 */ lw $t8, 8($s0) -/* 0D7A94 800D6E94 01E09025 */ move $s2, $t7 -/* 0D7A98 800D6E98 8E0F0014 */ lw $t7, 0x14($s0) -/* 0D7A9C 800D6E9C 26310002 */ addiu $s1, $s1, 2 -/* 0D7AA0 800D6EA0 02387023 */ subu $t6, $s1, $t8 -/* 0D7AA4 800D6EA4 01CFC823 */ subu $t9, $t6, $t7 -/* 0D7AA8 800D6EA8 AE19001C */ sw $t9, 0x1c($s0) -.L800D6EAC: -/* 0D7AAC 800D6EAC 8E180030 */ lw $t8, 0x30($s0) -/* 0D7AB0 800D6EB0 24010010 */ li $at, 16 -/* 0D7AB4 800D6EB4 330E0014 */ andi $t6, $t8, 0x14 -/* 0D7AB8 800D6EB8 55C10010 */ bnel $t6, $at, .L800D6EFC -/* 0D7ABC 800D6EBC 8FBF0014 */ lw $ra, 0x14($sp) -/* 0D7AC0 800D6EC0 8E0F000C */ lw $t7, 0xc($s0) -/* 0D7AC4 800D6EC4 8E190014 */ lw $t9, 0x14($s0) -/* 0D7AC8 800D6EC8 8E0E0018 */ lw $t6, 0x18($s0) -/* 0D7ACC 800D6ECC 8E030028 */ lw $v1, 0x28($s0) -/* 0D7AD0 800D6ED0 01F9C021 */ addu $t8, $t7, $t9 -/* 0D7AD4 800D6ED4 8E19001C */ lw $t9, 0x1c($s0) -/* 0D7AD8 800D6ED8 030E7821 */ addu $t7, $t8, $t6 -/* 0D7ADC 800D6EDC 8E0E0020 */ lw $t6, 0x20($s0) -/* 0D7AE0 800D6EE0 01F9C021 */ addu $t8, $t7, $t9 -/* 0D7AE4 800D6EE4 030E1021 */ addu $v0, $t8, $t6 -/* 0D7AE8 800D6EE8 0043082A */ slt $at, $v0, $v1 -/* 0D7AEC 800D6EEC 10200002 */ beqz $at, .L800D6EF8 -/* 0D7AF0 800D6EF0 00627823 */ subu $t7, $v1, $v0 -/* 0D7AF4 800D6EF4 AE0F0010 */ sw $t7, 0x10($s0) -.L800D6EF8: -/* 0D7AF8 800D6EF8 8FBF0014 */ lw $ra, 0x14($sp) -.L800D6EFC: -/* 0D7AFC 800D6EFC 27BD0018 */ addiu $sp, $sp, 0x18 -/* 0D7B00 800D6F00 03E00008 */ jr $ra -/* 0D7B04 800D6F04 00000000 */ nop - -/* 0D7B08 800D6F08 03E00008 */ jr $ra -/* 0D7B0C 800D6F0C 00000000 */ nop - diff --git a/lib/asm/non_matchings/unknown_0D3020/_Ldtob.s b/lib/asm/non_matchings/unknown_0D3020/_Ldtob.s deleted file mode 100644 index fc92c6fa..00000000 --- a/lib/asm/non_matchings/unknown_0D3020/_Ldtob.s +++ /dev/null @@ -1,391 +0,0 @@ -glabel _Ldtob -/* 0D7B10 800D6F10 27BDFF30 */ addiu $sp, $sp, -0xd0 -/* 0D7B14 800D6F14 AFBF003C */ sw $ra, 0x3c($sp) -/* 0D7B18 800D6F18 AFB50038 */ sw $s5, 0x38($sp) -/* 0D7B1C 800D6F1C AFB40034 */ sw $s4, 0x34($sp) -/* 0D7B20 800D6F20 AFB30030 */ sw $s3, 0x30($sp) -/* 0D7B24 800D6F24 AFB2002C */ sw $s2, 0x2c($sp) -/* 0D7B28 800D6F28 AFB10028 */ sw $s1, 0x28($sp) -/* 0D7B2C 800D6F2C AFB00024 */ sw $s0, 0x24($sp) -/* 0D7B30 800D6F30 F7B40018 */ sdc1 $f20, 0x18($sp) -/* 0D7B34 800D6F34 AFA400D0 */ sw $a0, 0xd0($sp) -/* 0D7B38 800D6F38 AFA500D4 */ sw $a1, 0xd4($sp) -/* 0D7B3C 800D6F3C 8C820024 */ lw $v0, 0x24($a0) -/* 0D7B40 800D6F40 27B500B0 */ addiu $s5, $sp, 0xb0 -/* 0D7B44 800D6F44 D4940000 */ ldc1 $f20, ($a0) -/* 0D7B48 800D6F48 04410003 */ bgez $v0, .L800D6F58 -/* 0D7B4C 800D6F4C 240F0006 */ li $t7, 6 -/* 0D7B50 800D6F50 1000000C */ b .L800D6F84 -/* 0D7B54 800D6F54 AC8F0024 */ sw $t7, 0x24($a0) -.L800D6F58: -/* 0D7B58 800D6F58 1440000A */ bnez $v0, .L800D6F84 -/* 0D7B5C 800D6F5C 93B800D7 */ lbu $t8, 0xd7($sp) -/* 0D7B60 800D6F60 24010067 */ li $at, 103 -/* 0D7B64 800D6F64 13010004 */ beq $t8, $at, .L800D6F78 -/* 0D7B68 800D6F68 AFB80048 */ sw $t8, 0x48($sp) -/* 0D7B6C 800D6F6C 24010047 */ li $at, 71 -/* 0D7B70 800D6F70 57010005 */ bnel $t8, $at, .L800D6F88 -/* 0D7B74 800D6F74 8FAE00D0 */ lw $t6, 0xd0($sp) -.L800D6F78: -/* 0D7B78 800D6F78 8FAF00D0 */ lw $t7, 0xd0($sp) -/* 0D7B7C 800D6F7C 24190001 */ li $t9, 1 -/* 0D7B80 800D6F80 ADF90024 */ sw $t9, 0x24($t7) -.L800D6F84: -/* 0D7B84 800D6F84 8FAE00D0 */ lw $t6, 0xd0($sp) -.L800D6F88: -/* 0D7B88 800D6F88 240107FF */ li $at, 2047 -/* 0D7B8C 800D6F8C 95C40000 */ lhu $a0, ($t6) -/* 0D7B90 800D6F90 30837FF0 */ andi $v1, $a0, 0x7ff0 -/* 0D7B94 800D6F94 0003C103 */ sra $t8, $v1, 4 -/* 0D7B98 800D6F98 0018CC00 */ sll $t9, $t8, 0x10 -/* 0D7B9C 800D6F9C 00191C03 */ sra $v1, $t9, 0x10 -/* 0D7BA0 800D6FA0 14610018 */ bne $v1, $at, .L800D7004 -/* 0D7BA4 800D6FA4 00000000 */ nop -/* 0D7BA8 800D6FA8 A7A0009A */ sh $zero, 0x9a($sp) -/* 0D7BAC 800D6FAC 95D80000 */ lhu $t8, ($t6) -/* 0D7BB0 800D6FB0 24030002 */ li $v1, 2 -/* 0D7BB4 800D6FB4 00031400 */ sll $v0, $v1, 0x10 -/* 0D7BB8 800D6FB8 3319000F */ andi $t9, $t8, 0xf -/* 0D7BBC 800D6FBC 5720000A */ bnezl $t9, .L800D6FE8 -/* 0D7BC0 800D6FC0 00027C03 */ sra $t7, $v0, 0x10 -/* 0D7BC4 800D6FC4 95CF0002 */ lhu $t7, 2($t6) -/* 0D7BC8 800D6FC8 55E00007 */ bnezl $t7, .L800D6FE8 -/* 0D7BCC 800D6FCC 00027C03 */ sra $t7, $v0, 0x10 -/* 0D7BD0 800D6FD0 95D80004 */ lhu $t8, 4($t6) -/* 0D7BD4 800D6FD4 57000004 */ bnezl $t8, .L800D6FE8 -/* 0D7BD8 800D6FD8 00027C03 */ sra $t7, $v0, 0x10 -/* 0D7BDC 800D6FDC 95D90006 */ lhu $t9, 6($t6) -/* 0D7BE0 800D6FE0 13200003 */ beqz $t9, .L800D6FF0 -/* 0D7BE4 800D6FE4 00027C03 */ sra $t7, $v0, 0x10 -.L800D6FE8: -/* 0D7BE8 800D6FE8 10000014 */ b .L800D703C -/* 0D7BEC 800D6FEC 01E01025 */ move $v0, $t7 -.L800D6FF0: -/* 0D7BF0 800D6FF0 24030001 */ li $v1, 1 -/* 0D7BF4 800D6FF4 00031400 */ sll $v0, $v1, 0x10 -/* 0D7BF8 800D6FF8 00027C03 */ sra $t7, $v0, 0x10 -/* 0D7BFC 800D6FFC 1000000F */ b .L800D703C -/* 0D7C00 800D7000 01E01025 */ move $v0, $t7 -.L800D7004: -/* 0D7C04 800D7004 18600008 */ blez $v1, .L800D7028 -/* 0D7C08 800D7008 3098800F */ andi $t8, $a0, 0x800f -/* 0D7C0C 800D700C 8FB900D0 */ lw $t9, 0xd0($sp) -/* 0D7C10 800D7010 370E3FF0 */ ori $t6, $t8, 0x3ff0 -/* 0D7C14 800D7014 246FFC02 */ addiu $t7, $v1, -0x3fe -/* 0D7C18 800D7018 A72E0000 */ sh $t6, ($t9) -/* 0D7C1C 800D701C A7AF009A */ sh $t7, 0x9a($sp) -/* 0D7C20 800D7020 10000006 */ b .L800D703C -/* 0D7C24 800D7024 2402FFFF */ li $v0, -1 -.L800D7028: -/* 0D7C28 800D7028 04610003 */ bgez $v1, .L800D7038 -/* 0D7C2C 800D702C 00001025 */ move $v0, $zero -/* 0D7C30 800D7030 10000002 */ b .L800D703C -/* 0D7C34 800D7034 24020002 */ li $v0, 2 -.L800D7038: -/* 0D7C38 800D7038 A7A0009A */ sh $zero, 0x9a($sp) -.L800D703C: -/* 0D7C3C 800D703C 18400012 */ blez $v0, .L800D7088 -/* 0D7C40 800D7040 0002C400 */ sll $t8, $v0, 0x10 -/* 0D7C44 800D7044 0002C400 */ sll $t8, $v0, 0x10 -/* 0D7C48 800D7048 00187403 */ sra $t6, $t8, 0x10 -/* 0D7C4C 800D704C 24010002 */ li $at, 2 -/* 0D7C50 800D7050 15C10004 */ bne $t6, $at, .L800D7064 -/* 0D7C54 800D7054 8FB900D0 */ lw $t9, 0xd0($sp) -/* 0D7C58 800D7058 3C05800F */ lui $a1, %hi(Ldtob_NaN) # $a1, 0x800f -/* 0D7C5C 800D705C 10000003 */ b .L800D706C -/* 0D7C60 800D7060 24A598A8 */ addiu $a1, %lo(Ldtob_NaN) # addiu $a1, $a1, -0x6758 -.L800D7064: -/* 0D7C64 800D7064 3C05800F */ lui $a1, %hi(Ldtob_Inf) # $a1, 0x800f -/* 0D7C68 800D7068 24A598AC */ addiu $a1, %lo(Ldtob_Inf) # addiu $a1, $a1, -0x6754 -.L800D706C: -/* 0D7C6C 800D706C 240F0003 */ li $t7, 3 -/* 0D7C70 800D7070 AF2F0014 */ sw $t7, 0x14($t9) -/* 0D7C74 800D7074 8F240008 */ lw $a0, 8($t9) -/* 0D7C78 800D7078 0C03385C */ jal memcpy -/* 0D7C7C 800D707C 24060003 */ li $a2, 3 -/* 0D7C80 800D7080 100000ED */ b .L800D7438 -/* 0D7C84 800D7084 8FBF003C */ lw $ra, 0x3c($sp) -.L800D7088: -/* 0D7C88 800D7088 00187403 */ sra $t6, $t8, 0x10 -/* 0D7C8C 800D708C 15C00003 */ bnez $t6, .L800D709C -/* 0D7C90 800D7090 00009825 */ move $s3, $zero -/* 0D7C94 800D7094 100000E2 */ b .L800D7420 -/* 0D7C98 800D7098 A7A0009A */ sh $zero, 0x9a($sp) -.L800D709C: -/* 0D7C9C 800D709C 44801800 */ mtc1 $zero, $f3 -/* 0D7CA0 800D70A0 44801000 */ mtc1 $zero, $f2 -/* 0D7CA4 800D70A4 93AF00D7 */ lbu $t7, 0xd7($sp) -/* 0D7CA8 800D70A8 87B9009A */ lh $t9, 0x9a($sp) -/* 0D7CAC 800D70AC 4622A03C */ c.lt.d $f20, $f2 -/* 0D7CB0 800D70B0 24017597 */ li $at, 30103 -/* 0D7CB4 800D70B4 00001825 */ move $v1, $zero -/* 0D7CB8 800D70B8 27B500B1 */ addiu $s5, $sp, 0xb1 -/* 0D7CBC 800D70BC 45000002 */ bc1f .L800D70C8 -/* 0D7CC0 800D70C0 AFAF0048 */ sw $t7, 0x48($sp) -/* 0D7CC4 800D70C4 4620A507 */ neg.d $f20, $f20 -.L800D70C8: -/* 0D7CC8 800D70C8 03210019 */ multu $t9, $at -/* 0D7CCC 800D70CC 3C010001 */ lui $at, (0x000186A0 >> 16) # lui $at, 1 -/* 0D7CD0 800D70D0 342186A0 */ ori $at, (0x000186A0 & 0xFFFF) # ori $at, $at, 0x86a0 -/* 0D7CD4 800D70D4 24050006 */ li $a1, 6 -/* 0D7CD8 800D70D8 0000C012 */ mflo $t8 -/* 0D7CDC 800D70DC 00000000 */ nop -/* 0D7CE0 800D70E0 00000000 */ nop -/* 0D7CE4 800D70E4 0301001A */ div $zero, $t8, $at -/* 0D7CE8 800D70E8 00007012 */ mflo $t6 -/* 0D7CEC 800D70EC 25CFFFFC */ addiu $t7, $t6, -4 -/* 0D7CF0 800D70F0 000FCC00 */ sll $t9, $t7, 0x10 -/* 0D7CF4 800D70F4 0019C403 */ sra $t8, $t9, 0x10 -/* 0D7CF8 800D70F8 07010019 */ bgez $t8, .L800D7160 -/* 0D7CFC 800D70FC A7AF009A */ sh $t7, 0x9a($sp) -/* 0D7D00 800D7100 000FCC00 */ sll $t9, $t7, 0x10 -/* 0D7D04 800D7104 0019C403 */ sra $t8, $t9, 0x10 -/* 0D7D08 800D7108 240E0003 */ li $t6, 3 -/* 0D7D0C 800D710C 01D82023 */ subu $a0, $t6, $t8 -/* 0D7D10 800D7110 2401FFFC */ li $at, -4 -/* 0D7D14 800D7114 00811024 */ and $v0, $a0, $at -/* 0D7D18 800D7118 0002C823 */ negu $t9, $v0 -/* 0D7D1C 800D711C 1840002C */ blez $v0, .L800D71D0 -/* 0D7D20 800D7120 A7B9009A */ sh $t9, 0x9a($sp) -/* 0D7D24 800D7124 3C04800F */ lui $a0, %hi(pows) # $a0, 0x800f -/* 0D7D28 800D7128 24849860 */ addiu $a0, %lo(pows) # addiu $a0, $a0, -0x67a0 -.L800D712C: -/* 0D7D2C 800D712C 304E0001 */ andi $t6, $v0, 1 -/* 0D7D30 800D7130 11C00006 */ beqz $t6, .L800D714C -/* 0D7D34 800D7134 0002C843 */ sra $t9, $v0, 1 -/* 0D7D38 800D7138 0003C0C0 */ sll $t8, $v1, 3 -/* 0D7D3C 800D713C 00987821 */ addu $t7, $a0, $t8 -/* 0D7D40 800D7140 D5E40000 */ ldc1 $f4, ($t7) -/* 0D7D44 800D7144 4624A502 */ mul.d $f20, $f20, $f4 -/* 0D7D48 800D7148 00000000 */ nop -.L800D714C: -/* 0D7D4C 800D714C 03201025 */ move $v0, $t9 -/* 0D7D50 800D7150 1F20FFF6 */ bgtz $t9, .L800D712C -/* 0D7D54 800D7154 24630001 */ addiu $v1, $v1, 1 -/* 0D7D58 800D7158 1000001E */ b .L800D71D4 -/* 0D7D5C 800D715C 8FAF0048 */ lw $t7, 0x48($sp) -.L800D7160: -/* 0D7D60 800D7160 87AE009A */ lh $t6, 0x9a($sp) -/* 0D7D64 800D7164 3C013FF0 */ li $at, 0x3FF00000 # 1.875000 -/* 0D7D68 800D7168 00001825 */ move $v1, $zero -/* 0D7D6C 800D716C 19C00018 */ blez $t6, .L800D71D0 -/* 0D7D70 800D7170 31D8FFFC */ andi $t8, $t6, 0xfffc -/* 0D7D74 800D7174 00181400 */ sll $v0, $t8, 0x10 -/* 0D7D78 800D7178 0018CC00 */ sll $t9, $t8, 0x10 -/* 0D7D7C 800D717C 44810800 */ mtc1 $at, $f1 -/* 0D7D80 800D7180 44800000 */ mtc1 $zero, $f0 -/* 0D7D84 800D7184 00197403 */ sra $t6, $t9, 0x10 -/* 0D7D88 800D7188 00027C03 */ sra $t7, $v0, 0x10 -/* 0D7D8C 800D718C A7B8009A */ sh $t8, 0x9a($sp) -/* 0D7D90 800D7190 19C0000E */ blez $t6, .L800D71CC -/* 0D7D94 800D7194 01E01025 */ move $v0, $t7 -/* 0D7D98 800D7198 3C04800F */ lui $a0, %hi(pows) # $a0, 0x800f -/* 0D7D9C 800D719C 24849860 */ addiu $a0, %lo(pows) # addiu $a0, $a0, -0x67a0 -.L800D71A0: -/* 0D7DA0 800D71A0 304F0001 */ andi $t7, $v0, 1 -/* 0D7DA4 800D71A4 11E00006 */ beqz $t7, .L800D71C0 -/* 0D7DA8 800D71A8 00027043 */ sra $t6, $v0, 1 -/* 0D7DAC 800D71AC 0003C0C0 */ sll $t8, $v1, 3 -/* 0D7DB0 800D71B0 0098C821 */ addu $t9, $a0, $t8 -/* 0D7DB4 800D71B4 D7260000 */ ldc1 $f6, ($t9) -/* 0D7DB8 800D71B8 46260002 */ mul.d $f0, $f0, $f6 -/* 0D7DBC 800D71BC 00000000 */ nop -.L800D71C0: -/* 0D7DC0 800D71C0 01C01025 */ move $v0, $t6 -/* 0D7DC4 800D71C4 1DC0FFF6 */ bgtz $t6, .L800D71A0 -/* 0D7DC8 800D71C8 24630001 */ addiu $v1, $v1, 1 -.L800D71CC: -/* 0D7DCC 800D71CC 4620A503 */ div.d $f20, $f20, $f0 -.L800D71D0: -/* 0D7DD0 800D71D0 8FAF0048 */ lw $t7, 0x48($sp) -.L800D71D4: -/* 0D7DD4 800D71D4 24010066 */ li $at, 102 -/* 0D7DD8 800D71D8 8FB800D0 */ lw $t8, 0xd0($sp) -/* 0D7DDC 800D71DC 15E10004 */ bne $t7, $at, .L800D71F0 -/* 0D7DE0 800D71E0 240E0030 */ li $t6, 48 -/* 0D7DE4 800D71E4 87A5009A */ lh $a1, 0x9a($sp) -/* 0D7DE8 800D71E8 10000001 */ b .L800D71F0 -/* 0D7DEC 800D71EC 24A5000A */ addiu $a1, $a1, 0xa -.L800D71F0: -/* 0D7DF0 800D71F0 8F190024 */ lw $t9, 0x24($t8) -/* 0D7DF4 800D71F4 00B9A021 */ addu $s4, $a1, $t9 -/* 0D7DF8 800D71F8 2A810014 */ slti $at, $s4, 0x14 -/* 0D7DFC 800D71FC 14200002 */ bnez $at, .L800D7208 -/* 0D7E00 800D7200 00000000 */ nop -/* 0D7E04 800D7204 24140013 */ li $s4, 19 -.L800D7208: -/* 0D7E08 800D7208 1A800033 */ blez $s4, .L800D72D8 -/* 0D7E0C 800D720C A3AE00B0 */ sb $t6, 0xb0($sp) -/* 0D7E10 800D7210 4634103C */ c.lt.d $f2, $f20 -/* 0D7E14 800D7214 24130030 */ li $s3, 48 -/* 0D7E18 800D7218 27B20074 */ addiu $s2, $sp, 0x74 -/* 0D7E1C 800D721C 4502002F */ bc1fl .L800D72DC -/* 0D7E20 800D7220 87B8009A */ lh $t8, 0x9a($sp) -/* 0D7E24 800D7224 4620A20D */ trunc.w.d $f8, $f20 -.L800D7228: -/* 0D7E28 800D7228 2694FFF8 */ addiu $s4, $s4, -8 -/* 0D7E2C 800D722C 26B50008 */ addiu $s5, $s5, 8 -/* 0D7E30 800D7230 44114000 */ mfc1 $s1, $f8 -/* 0D7E34 800D7234 1A800008 */ blez $s4, .L800D7258 -/* 0D7E38 800D7238 00000000 */ nop -/* 0D7E3C 800D723C 44915000 */ mtc1 $s1, $f10 -/* 0D7E40 800D7240 3C01800F */ lui $at, %hi(_Ldtob_1e8) # $at, 0x800f -/* 0D7E44 800D7244 D42898B8 */ ldc1 $f8, %lo(_Ldtob_1e8)($at) -/* 0D7E48 800D7248 46805121 */ cvt.d.w $f4, $f10 -/* 0D7E4C 800D724C 4624A181 */ sub.d $f6, $f20, $f4 -/* 0D7E50 800D7250 46283502 */ mul.d $f20, $f6, $f8 -/* 0D7E54 800D7254 00000000 */ nop -.L800D7258: -/* 0D7E58 800D7258 1A200011 */ blez $s1, .L800D72A0 -/* 0D7E5C 800D725C 24100008 */ li $s0, 8 -/* 0D7E60 800D7260 24100007 */ li $s0, 7 -/* 0D7E64 800D7264 0600000E */ bltz $s0, .L800D72A0 -/* 0D7E68 800D7268 02402025 */ move $a0, $s2 -.L800D726C: -/* 0D7E6C 800D726C 02202825 */ move $a1, $s1 -/* 0D7E70 800D7270 0C035D5C */ jal ldiv -/* 0D7E74 800D7274 2406000A */ li $a2, 10 -/* 0D7E78 800D7278 8FB80078 */ lw $t8, 0x78($sp) -/* 0D7E7C 800D727C 26B5FFFF */ addiu $s5, $s5, -1 -/* 0D7E80 800D7280 27190030 */ addiu $t9, $t8, 0x30 -/* 0D7E84 800D7284 A2B90000 */ sb $t9, ($s5) -/* 0D7E88 800D7288 8FB10074 */ lw $s1, 0x74($sp) -/* 0D7E8C 800D728C 5A200005 */ blezl $s1, .L800D72A4 -/* 0D7E90 800D7290 44801800 */ mtc1 $zero, $f3 -/* 0D7E94 800D7294 2610FFFF */ addiu $s0, $s0, -1 -/* 0D7E98 800D7298 0603FFF4 */ bgezl $s0, .L800D726C -/* 0D7E9C 800D729C 02402025 */ move $a0, $s2 -.L800D72A0: -/* 0D7EA0 800D72A0 44801800 */ mtc1 $zero, $f3 -.L800D72A4: -/* 0D7EA4 800D72A4 44801000 */ mtc1 $zero, $f2 -/* 0D7EA8 800D72A8 2610FFFF */ addiu $s0, $s0, -1 -/* 0D7EAC 800D72AC 06000004 */ bltz $s0, .L800D72C0 -.L800D72B0: -/* 0D7EB0 800D72B0 2610FFFF */ addiu $s0, $s0, -1 -/* 0D7EB4 800D72B4 26B5FFFF */ addiu $s5, $s5, -1 -/* 0D7EB8 800D72B8 0601FFFD */ bgez $s0, .L800D72B0 -/* 0D7EBC 800D72BC A2B30000 */ sb $s3, ($s5) -.L800D72C0: -/* 0D7EC0 800D72C0 1A800005 */ blez $s4, .L800D72D8 -/* 0D7EC4 800D72C4 26B50008 */ addiu $s5, $s5, 8 -/* 0D7EC8 800D72C8 4634103C */ c.lt.d $f2, $f20 -/* 0D7ECC 800D72CC 00000000 */ nop -/* 0D7ED0 800D72D0 4503FFD5 */ bc1tl .L800D7228 -/* 0D7ED4 800D72D4 4620A20D */ trunc.w.d $f8, $f20 -.L800D72D8: -/* 0D7ED8 800D72D8 87B8009A */ lh $t8, 0x9a($sp) -.L800D72DC: -/* 0D7EDC 800D72DC 93AE00B1 */ lbu $t6, 0xb1($sp) -/* 0D7EE0 800D72E0 27AF00B0 */ addiu $t7, $sp, 0xb0 -/* 0D7EE4 800D72E4 24020030 */ li $v0, 48 -/* 0D7EE8 800D72E8 02AFA023 */ subu $s4, $s5, $t7 -/* 0D7EEC 800D72EC 27190007 */ addiu $t9, $t8, 7 -/* 0D7EF0 800D72F0 2694FFFF */ addiu $s4, $s4, -1 -/* 0D7EF4 800D72F4 A7B9009A */ sh $t9, 0x9a($sp) -/* 0D7EF8 800D72F8 144E0009 */ bne $v0, $t6, .L800D7320 -/* 0D7EFC 800D72FC 27B500B1 */ addiu $s5, $sp, 0xb1 -/* 0D7F00 800D7300 87AF009A */ lh $t7, 0x9a($sp) -.L800D7304: -/* 0D7F04 800D7304 26B50001 */ addiu $s5, $s5, 1 -/* 0D7F08 800D7308 2694FFFF */ addiu $s4, $s4, -1 -/* 0D7F0C 800D730C 25F8FFFF */ addiu $t8, $t7, -1 -/* 0D7F10 800D7310 A7B8009A */ sh $t8, 0x9a($sp) -/* 0D7F14 800D7314 92B90000 */ lbu $t9, ($s5) -/* 0D7F18 800D7318 5059FFFA */ beql $v0, $t9, .L800D7304 -/* 0D7F1C 800D731C 87AF009A */ lh $t7, 0x9a($sp) -.L800D7320: -/* 0D7F20 800D7320 8FAE0048 */ lw $t6, 0x48($sp) -/* 0D7F24 800D7324 24010066 */ li $at, 102 -/* 0D7F28 800D7328 8FB800D0 */ lw $t8, 0xd0($sp) -/* 0D7F2C 800D732C 15C10004 */ bne $t6, $at, .L800D7340 -/* 0D7F30 800D7330 8FAF0048 */ lw $t7, 0x48($sp) -/* 0D7F34 800D7334 87A5009A */ lh $a1, 0x9a($sp) -/* 0D7F38 800D7338 10000009 */ b .L800D7360 -/* 0D7F3C 800D733C 24A50001 */ addiu $a1, $a1, 1 -.L800D7340: -/* 0D7F40 800D7340 24010065 */ li $at, 101 -/* 0D7F44 800D7344 11E10003 */ beq $t7, $at, .L800D7354 -/* 0D7F48 800D7348 24010045 */ li $at, 69 -/* 0D7F4C 800D734C 15E10003 */ bne $t7, $at, .L800D735C -/* 0D7F50 800D7350 00001025 */ move $v0, $zero -.L800D7354: -/* 0D7F54 800D7354 10000001 */ b .L800D735C -/* 0D7F58 800D7358 24020001 */ li $v0, 1 -.L800D735C: -/* 0D7F5C 800D735C 00402825 */ move $a1, $v0 -.L800D7360: -/* 0D7F60 800D7360 8F190024 */ lw $t9, 0x24($t8) -/* 0D7F64 800D7364 00B99821 */ addu $s3, $a1, $t9 -/* 0D7F68 800D7368 00137400 */ sll $t6, $s3, 0x10 -/* 0D7F6C 800D736C 000E9C03 */ sra $s3, $t6, 0x10 -/* 0D7F70 800D7370 0293082A */ slt $at, $s4, $s3 -/* 0D7F74 800D7374 10200004 */ beqz $at, .L800D7388 -/* 0D7F78 800D7378 00000000 */ nop -/* 0D7F7C 800D737C 00149C00 */ sll $s3, $s4, 0x10 -/* 0D7F80 800D7380 0013C403 */ sra $t8, $s3, 0x10 -/* 0D7F84 800D7384 03009825 */ move $s3, $t8 -.L800D7388: -/* 0D7F88 800D7388 1A600025 */ blez $s3, .L800D7420 -/* 0D7F8C 800D738C 0274082A */ slt $at, $s3, $s4 -/* 0D7F90 800D7390 10200007 */ beqz $at, .L800D73B0 -/* 0D7F94 800D7394 02751021 */ addu $v0, $s3, $s5 -/* 0D7F98 800D7398 90590000 */ lbu $t9, ($v0) -/* 0D7F9C 800D739C 2B210035 */ slti $at, $t9, 0x35 -/* 0D7FA0 800D73A0 54200004 */ bnezl $at, .L800D73B4 -/* 0D7FA4 800D73A4 24050030 */ li $a1, 48 -/* 0D7FA8 800D73A8 10000003 */ b .L800D73B8 -/* 0D7FAC 800D73AC 24050039 */ li $a1, 57 -.L800D73B0: -/* 0D7FB0 800D73B0 24050030 */ li $a1, 48 -.L800D73B4: -/* 0D7FB4 800D73B4 02751021 */ addu $v0, $s3, $s5 -.L800D73B8: -/* 0D7FB8 800D73B8 904EFFFF */ lbu $t6, -1($v0) -/* 0D7FBC 800D73BC 2663FFFF */ addiu $v1, $s3, -1 -/* 0D7FC0 800D73C0 00A02025 */ move $a0, $a1 -/* 0D7FC4 800D73C4 14AE0009 */ bne $a1, $t6, .L800D73EC -/* 0D7FC8 800D73C8 24010039 */ li $at, 57 -/* 0D7FCC 800D73CC 00751021 */ addu $v0, $v1, $s5 -.L800D73D0: -/* 0D7FD0 800D73D0 9059FFFF */ lbu $t9, -1($v0) -/* 0D7FD4 800D73D4 2673FFFF */ addiu $s3, $s3, -1 -/* 0D7FD8 800D73D8 00137C00 */ sll $t7, $s3, 0x10 -/* 0D7FDC 800D73DC 2463FFFF */ addiu $v1, $v1, -1 -/* 0D7FE0 800D73E0 2442FFFF */ addiu $v0, $v0, -1 -/* 0D7FE4 800D73E4 1099FFFA */ beq $a0, $t9, .L800D73D0 -/* 0D7FE8 800D73E8 000F9C03 */ sra $s3, $t7, 0x10 -.L800D73EC: -/* 0D7FEC 800D73EC 14810004 */ bne $a0, $at, .L800D7400 -/* 0D7FF0 800D73F0 02A31021 */ addu $v0, $s5, $v1 -/* 0D7FF4 800D73F4 904E0000 */ lbu $t6, ($v0) -/* 0D7FF8 800D73F8 25CF0001 */ addiu $t7, $t6, 1 -/* 0D7FFC 800D73FC A04F0000 */ sb $t7, ($v0) -.L800D7400: -/* 0D8000 800D7400 04610007 */ bgez $v1, .L800D7420 -/* 0D8004 800D7404 87AE009A */ lh $t6, 0x9a($sp) -/* 0D8008 800D7408 26730001 */ addiu $s3, $s3, 1 -/* 0D800C 800D740C 0013C400 */ sll $t8, $s3, 0x10 -/* 0D8010 800D7410 25CF0001 */ addiu $t7, $t6, 1 -/* 0D8014 800D7414 A7AF009A */ sh $t7, 0x9a($sp) -/* 0D8018 800D7418 00189C03 */ sra $s3, $t8, 0x10 -/* 0D801C 800D741C 26B5FFFF */ addiu $s5, $s5, -1 -.L800D7420: -/* 0D8020 800D7420 8FB000D0 */ lw $s0, 0xd0($sp) -/* 0D8024 800D7424 93B400D7 */ lbu $s4, 0xd7($sp) -/* 0D8028 800D7428 02A08825 */ move $s1, $s5 -/* 0D802C 800D742C 0C035A68 */ jal _Genld -/* 0D8030 800D7430 87B2009A */ lh $s2, 0x9a($sp) -/* 0D8034 800D7434 8FBF003C */ lw $ra, 0x3c($sp) -.L800D7438: -/* 0D8038 800D7438 D7B40018 */ ldc1 $f20, 0x18($sp) -/* 0D803C 800D743C 8FB00024 */ lw $s0, 0x24($sp) -/* 0D8040 800D7440 8FB10028 */ lw $s1, 0x28($sp) -/* 0D8044 800D7444 8FB2002C */ lw $s2, 0x2c($sp) -/* 0D8048 800D7448 8FB30030 */ lw $s3, 0x30($sp) -/* 0D804C 800D744C 8FB40034 */ lw $s4, 0x34($sp) -/* 0D8050 800D7450 8FB50038 */ lw $s5, 0x38($sp) -/* 0D8054 800D7454 03E00008 */ jr $ra -/* 0D8058 800D7458 27BD00D0 */ addiu $sp, $sp, 0xd0 - -/* 0D805C 800D745C 00000000 */ nop diff --git a/lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s b/lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s deleted file mode 100644 index 34fb800b..00000000 --- a/lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s +++ /dev/null @@ -1,37 +0,0 @@ -glabel __osTimerServicesInit -/* 0D5AC0 800D4EC0 3C018013 */ lui $at, %hi(__osCurrentTime) # $at, 0x8013 -/* 0D5AC4 800D4EC4 240E0000 */ li $t6, 0 -/* 0D5AC8 800D4EC8 240F0000 */ li $t7, 0 -/* 0D5ACC 800D4ECC AC2FD224 */ sw $t7, %lo(__osCurrentTime+4)($at) -/* 0D5AD0 800D4ED0 AC2ED220 */ sw $t6, %lo(__osCurrentTime)($at) -/* 0D5AD4 800D4ED4 3C018013 */ lui $at, %hi(__osBaseCounter) # $at, 0x8013 -/* 0D5AD8 800D4ED8 3C18800E */ lui $t8, %hi(__osTimerList) # $t8, 0x800e -/* 0D5ADC 800D4EDC 8F184910 */ lw $t8, %lo(__osTimerList)($t8) -/* 0D5AE0 800D4EE0 AC20D228 */ sw $zero, %lo(__osBaseCounter)($at) -/* 0D5AE4 800D4EE4 3C018013 */ lui $at, %hi(__osViIntrCount) # $at, 0x8013 -/* 0D5AE8 800D4EE8 AC20D22C */ sw $zero, %lo(__osViIntrCount)($at) -/* 0D5AEC 800D4EEC 3C19800E */ lui $t9, %hi(__osTimerList) # $t9, 0x800e -/* 0D5AF0 800D4EF0 AF180004 */ sw $t8, 4($t8) -/* 0D5AF4 800D4EF4 8F394910 */ lw $t9, %lo(__osTimerList)($t9) -/* 0D5AF8 800D4EF8 3C09800E */ lui $t1, %hi(__osTimerList) # $t1, 0x800e -/* 0D5AFC 800D4EFC 240A0000 */ li $t2, 0 -/* 0D5B00 800D4F00 8F280004 */ lw $t0, 4($t9) -/* 0D5B04 800D4F04 240B0000 */ li $t3, 0 -/* 0D5B08 800D4F08 3C0C800E */ lui $t4, %hi(__osTimerList) # $t4, 0x800e -/* 0D5B0C 800D4F0C AF280000 */ sw $t0, ($t9) -/* 0D5B10 800D4F10 8D294910 */ lw $t1, %lo(__osTimerList)($t1) -/* 0D5B14 800D4F14 3C0D800E */ lui $t5, %hi(__osTimerList) # $t5, 0x800e -/* 0D5B18 800D4F18 3C18800E */ lui $t8, %hi(__osTimerList) # $t8, 0x800e -/* 0D5B1C 800D4F1C AD2A0010 */ sw $t2, 0x10($t1) -/* 0D5B20 800D4F20 AD2B0014 */ sw $t3, 0x14($t1) -/* 0D5B24 800D4F24 8D8C4910 */ lw $t4, %lo(__osTimerList)($t4) -/* 0D5B28 800D4F28 8D8E0010 */ lw $t6, 0x10($t4) -/* 0D5B2C 800D4F2C 8D8F0014 */ lw $t7, 0x14($t4) -/* 0D5B30 800D4F30 AD8E0008 */ sw $t6, 8($t4) -/* 0D5B34 800D4F34 AD8F000C */ sw $t7, 0xc($t4) -/* 0D5B38 800D4F38 8DAD4910 */ lw $t5, %lo(__osTimerList)($t5) -/* 0D5B3C 800D4F3C ADA00018 */ sw $zero, 0x18($t5) -/* 0D5B40 800D4F40 8F184910 */ lw $t8, %lo(__osTimerList)($t8) -/* 0D5B44 800D4F44 03E00008 */ jr $ra -/* 0D5B48 800D4F48 AF00001C */ sw $zero, 0x1c($t8) - diff --git a/lib/asm/osGetCount.s b/lib/asm/osGetCount.s deleted file mode 100644 index 1021d3ad..00000000 --- a/lib/asm/osGetCount.s +++ /dev/null @@ -1,16 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C78D0 */ - -.include "macros.inc" - -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used - -glabel osGetCount -/* 0C84D0 800C78D0 40024800 */ mfc0 $v0, $9 -/* 0C84D4 800C78D4 03E00008 */ jr $ra -/* 0C84D8 800C78D8 00000000 */ nop - -/* 0C84DC 800C78DC 00000000 */ nop - diff --git a/lib/asm/osInvalDCache.s b/lib/asm/osInvalDCache.s deleted file mode 100644 index 01caef38..00000000 --- a/lib/asm/osInvalDCache.s +++ /dev/null @@ -1,62 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D17F0 */ - -.include "macros.inc" - -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used - -glabel osInvalDCache -/* 0D23F0 800D17F0 18A0001F */ blez $a1, .L800D1870 -/* 0D23F4 800D17F4 00000000 */ nop -/* 0D23F8 800D17F8 240B2000 */ li $t3, 8192 -/* 0D23FC 800D17FC 00AB082B */ sltu $at, $a1, $t3 -/* 0D2400 800D1800 1020001D */ beqz $at, .L800D1878 -/* 0D2404 800D1804 00000000 */ nop -/* 0D2408 800D1808 00804025 */ move $t0, $a0 -/* 0D240C 800D180C 00854821 */ addu $t1, $a0, $a1 -/* 0D2410 800D1810 0109082B */ sltu $at, $t0, $t1 -/* 0D2414 800D1814 10200016 */ beqz $at, .L800D1870 -/* 0D2418 800D1818 00000000 */ nop -/* 0D241C 800D181C 310A000F */ andi $t2, $t0, 0xf -/* 0D2420 800D1820 11400007 */ beqz $t2, .L800D1840 -/* 0D2424 800D1824 2529FFF0 */ addiu $t1, $t1, -0x10 -/* 0D2428 800D1828 010A4023 */ subu $t0, $t0, $t2 -/* 0D242C 800D182C BD150000 */ cache 0x15, ($t0) -/* 0D2430 800D1830 0109082B */ sltu $at, $t0, $t1 -/* 0D2434 800D1834 1020000E */ beqz $at, .L800D1870 -/* 0D2438 800D1838 00000000 */ nop -/* 0D243C 800D183C 25080010 */ addiu $t0, $t0, 0x10 -.L800D1840: -/* 0D2440 800D1840 312A000F */ andi $t2, $t1, 0xf -/* 0D2444 800D1844 11400006 */ beqz $t2, .L800D1860 -/* 0D2448 800D1848 00000000 */ nop -/* 0D244C 800D184C 012A4823 */ subu $t1, $t1, $t2 -/* 0D2450 800D1850 BD350010 */ cache 0x15, 0x10($t1) -/* 0D2454 800D1854 0128082B */ sltu $at, $t1, $t0 -/* 0D2458 800D1858 14200005 */ bnez $at, .L800D1870 -/* 0D245C 800D185C 00000000 */ nop -.L800D1860: -/* 0D2460 800D1860 BD110000 */ cache 0x11, ($t0) -/* 0D2464 800D1864 0109082B */ sltu $at, $t0, $t1 -/* 0D2468 800D1868 1420FFFD */ bnez $at, .L800D1860 -/* 0D246C 800D186C 25080010 */ addiu $t0, $t0, 0x10 -.L800D1870: -/* 0D2470 800D1870 03E00008 */ jr $ra -/* 0D2474 800D1874 00000000 */ nop - -.L800D1878: -/* 0D2478 800D1878 3C088000 */ lui $t0, 0x8000 -/* 0D247C 800D187C 010B4821 */ addu $t1, $t0, $t3 -/* 0D2480 800D1880 2529FFF0 */ addiu $t1, $t1, -0x10 -.L800D1884: -/* 0D2484 800D1884 BD010000 */ cache 1, ($t0) -/* 0D2488 800D1888 0109082B */ sltu $at, $t0, $t1 -/* 0D248C 800D188C 1420FFFD */ bnez $at, .L800D1884 -/* 0D2490 800D1890 25080010 */ addiu $t0, $t0, 0x10 -/* 0D2494 800D1894 03E00008 */ jr $ra -/* 0D2498 800D1898 00000000 */ nop - -/* 0D249C 800D189C 00000000 */ nop - diff --git a/lib/asm/osInvalICache.s b/lib/asm/osInvalICache.s deleted file mode 100644 index 8954b15a..00000000 --- a/lib/asm/osInvalICache.s +++ /dev/null @@ -1,48 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D46B0 */ - -.include "macros.inc" - -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used - -glabel osInvalICache -/* 0D52B0 800D46B0 18A00011 */ blez $a1, .L800D46F8 -/* 0D52B4 800D46B4 00000000 */ nop -/* 0D52B8 800D46B8 240B4000 */ li $t3, 16384 -/* 0D52BC 800D46BC 00AB082B */ sltu $at, $a1, $t3 -/* 0D52C0 800D46C0 1020000F */ beqz $at, .L800D4700 -/* 0D52C4 800D46C4 00000000 */ nop -/* 0D52C8 800D46C8 00804025 */ move $t0, $a0 -/* 0D52CC 800D46CC 00854821 */ addu $t1, $a0, $a1 -/* 0D52D0 800D46D0 0109082B */ sltu $at, $t0, $t1 -/* 0D52D4 800D46D4 10200008 */ beqz $at, .L800D46F8 -/* 0D52D8 800D46D8 00000000 */ nop -/* 0D52DC 800D46DC 310A001F */ andi $t2, $t0, 0x1f -/* 0D52E0 800D46E0 2529FFE0 */ addiu $t1, $t1, -0x20 -/* 0D52E4 800D46E4 010A4023 */ subu $t0, $t0, $t2 -.L800D46E8: -/* 0D52E8 800D46E8 BD100000 */ cache 0x10, ($t0) -/* 0D52EC 800D46EC 0109082B */ sltu $at, $t0, $t1 -/* 0D52F0 800D46F0 1420FFFD */ bnez $at, .L800D46E8 -/* 0D52F4 800D46F4 25080020 */ addiu $t0, $t0, 0x20 -.L800D46F8: -/* 0D52F8 800D46F8 03E00008 */ jr $ra -/* 0D52FC 800D46FC 00000000 */ nop - -.L800D4700: -/* 0D5300 800D4700 3C088000 */ lui $t0, 0x8000 -/* 0D5304 800D4704 010B4821 */ addu $t1, $t0, $t3 -/* 0D5308 800D4708 2529FFE0 */ addiu $t1, $t1, -0x20 -.L800D470C: -/* 0D530C 800D470C BD000000 */ cache 0, ($t0) -/* 0D5310 800D4710 0109082B */ sltu $at, $t0, $t1 -/* 0D5314 800D4714 1420FFFD */ bnez $at, .L800D470C -/* 0D5318 800D4718 25080020 */ addiu $t0, $t0, 0x20 -/* 0D531C 800D471C 03E00008 */ jr $ra -/* 0D5320 800D4720 00000000 */ nop - -/* 0D5324 800D4724 00000000 */ nop -/* 0D5328 800D4728 00000000 */ nop -/* 0D532C 800D472C 00000000 */ nop diff --git a/lib/asm/osMapTLBRdb.s b/lib/asm/osMapTLBRdb.s deleted file mode 100644 index f0455e8e..00000000 --- a/lib/asm/osMapTLBRdb.s +++ /dev/null @@ -1,35 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D4730 */ - -.include "macros.inc" - -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used - -glabel osMapTLBRdb -/* 0D5330 800D4730 40085000 */ mfc0 $t0, $10 -/* 0D5334 800D4734 2409001F */ li $t1, 31 -/* 0D5338 800D4738 40890000 */ mtc0 $t1, $0 -/* 0D533C 800D473C 40802800 */ mtc0 $zero, $5 -/* 0D5340 800D4740 240A0017 */ li $t2, 23 -/* 0D5344 800D4744 3C09C000 */ lui $t1, 0xc000 -/* 0D5348 800D4748 40895000 */ mtc0 $t1, $10 -/* 0D534C 800D474C 3C098000 */ lui $t1, 0x8000 -/* 0D5350 800D4750 00095982 */ srl $t3, $t1, 6 -/* 0D5354 800D4754 016A5825 */ or $t3, $t3, $t2 -/* 0D5358 800D4758 408B1000 */ mtc0 $t3, $2 -/* 0D535C 800D475C 24090001 */ li $t1, 1 -/* 0D5360 800D4760 40891800 */ mtc0 $t1, $3 -/* 0D5364 800D4764 00000000 */ nop -/* 0D5368 800D4768 42000002 */ tlbwi -/* 0D536C 800D476C 00000000 */ nop -/* 0D5370 800D4770 00000000 */ nop -/* 0D5374 800D4774 00000000 */ nop -/* 0D5378 800D4778 00000000 */ nop -/* 0D537C 800D477C 40885000 */ mtc0 $t0, $10 -/* 0D5380 800D4780 03E00008 */ jr $ra -/* 0D5384 800D4784 00000000 */ nop - -/* 0D5388 800D4788 00000000 */ nop -/* 0D538C 800D478C 00000000 */ nop diff --git a/lib/asm/osSetIntMask.s b/lib/asm/osSetIntMask.s deleted file mode 100644 index fc1cf4f9..00000000 --- a/lib/asm/osSetIntMask.s +++ /dev/null @@ -1,65 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C9A30 */ - -.include "macros.inc" - -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used - -glabel osSetIntMask -/* 0CA630 800C9A30 400C6000 */ mfc0 $t4, $12 -/* 0CA634 800C9A34 3182FF01 */ andi $v0, $t4, 0xff01 -/* 0CA638 800C9A38 3C08800E */ lui $t0, %hi(__OSGlobalIntMask) # $t0, 0x800e -/* 0CA63C 800C9A3C 250838AC */ addiu $t0, %lo(__OSGlobalIntMask) # addiu $t0, $t0, 0x38ac -/* 0CA640 800C9A40 8D0B0000 */ lw $t3, ($t0) -/* 0CA644 800C9A44 2401FFFF */ li $at, -1 -/* 0CA648 800C9A48 01614026 */ xor $t0, $t3, $at -/* 0CA64C 800C9A4C 3108FF00 */ andi $t0, $t0, 0xff00 -/* 0CA650 800C9A50 00481025 */ or $v0, $v0, $t0 -/* 0CA654 800C9A54 3C0AA430 */ lui $t2, %hi(MI_INTR_MASK_REG) # $t2, 0xa430 -/* 0CA658 800C9A58 8D4A000C */ lw $t2, %lo(MI_INTR_MASK_REG)($t2) -/* 0CA65C 800C9A5C 11400005 */ beqz $t2, .L800C9A74 -/* 0CA660 800C9A60 000B4C02 */ srl $t1, $t3, 0x10 -/* 0CA664 800C9A64 2401FFFF */ li $at, -1 -/* 0CA668 800C9A68 01214826 */ xor $t1, $t1, $at -/* 0CA66C 800C9A6C 3129003F */ andi $t1, $t1, 0x3f -/* 0CA670 800C9A70 01495025 */ or $t2, $t2, $t1 -.L800C9A74: -/* 0CA674 800C9A74 000A5400 */ sll $t2, $t2, 0x10 -/* 0CA678 800C9A78 004A1025 */ or $v0, $v0, $t2 -/* 0CA67C 800C9A7C 3C01003F */ lui $at, 0x3f -/* 0CA680 800C9A80 00814024 */ and $t0, $a0, $at -/* 0CA684 800C9A84 010B4024 */ and $t0, $t0, $t3 -/* 0CA688 800C9A88 000843C2 */ srl $t0, $t0, 0xf -/* 0CA68C 800C9A8C 3C0A800F */ lui $t2, %hi(__osRcpImTable) # $t2, 0x800f -/* 0CA690 800C9A90 01485021 */ addu $t2, $t2, $t0 -/* 0CA694 800C9A94 954A94D0 */ lhu $t2, %lo(__osRcpImTable)($t2) -/* 0CA698 800C9A98 3C01A430 */ lui $at, %hi(MI_INTR_MASK_REG) # $at, 0xa430 -/* 0CA69C 800C9A9C AC2A000C */ sw $t2, %lo(MI_INTR_MASK_REG)($at) -/* 0CA6A0 800C9AA0 3088FF01 */ andi $t0, $a0, 0xff01 -/* 0CA6A4 800C9AA4 3169FF00 */ andi $t1, $t3, 0xff00 -/* 0CA6A8 800C9AA8 01094024 */ and $t0, $t0, $t1 -/* 0CA6AC 800C9AAC 3C01FFFF */ lui $at, (0xFFFF00FF >> 16) # lui $at, 0xffff -/* 0CA6B0 800C9AB0 342100FF */ ori $at, (0xFFFF00FF & 0xFFFF) # ori $at, $at, 0xff -/* 0CA6B4 800C9AB4 01816024 */ and $t4, $t4, $at -/* 0CA6B8 800C9AB8 01886025 */ or $t4, $t4, $t0 -/* 0CA6BC 800C9ABC 408C6000 */ mtc0 $t4, $12 -/* 0CA6C0 800C9AC0 00000000 */ nop -/* 0CA6C4 800C9AC4 00000000 */ nop -/* 0CA6C8 800C9AC8 03E00008 */ jr $ra -/* 0CA6CC 800C9ACC 00000000 */ nop - -.rdata -glabel __osRcpImTable -/* LUT to convert between MI_INTR and MI_INTR_MASK */ -/* MI_INTR is status for each interrupt whereas */ -/* MI_INTR_MASK has seperate bits for set/clr */ -.half 0x0555, 0x0556, 0x0559, 0x055A, 0x0565, 0x0566, 0x0569, 0x056A -.half 0x0595, 0x0596, 0x0599, 0x059A, 0x05A5, 0x05A6, 0x05A9, 0x05AA -.half 0x0655, 0x0656, 0x0659, 0x065A, 0x0665, 0x0666, 0x0669, 0x066A -.half 0x0695, 0x0696, 0x0699, 0x069A, 0x06A5, 0x06A6, 0x06A9, 0x06AA -.half 0x0955, 0x0956, 0x0959, 0x095A, 0x0965, 0x0966, 0x0969, 0x096A -.half 0x0995, 0x0996, 0x0999, 0x099A, 0x09A5, 0x09A6, 0x09A9, 0x09AA -.half 0x0A55, 0x0A56, 0x0A59, 0x0A5A, 0x0A65, 0x0A66, 0x0A69, 0x0A6A -.half 0x0A95, 0x0A96, 0x0A99, 0x0A9A, 0x0AA5, 0x0AA6, 0x0AA9, 0x0AAA diff --git a/lib/asm/osWritebackDCache.s b/lib/asm/osWritebackDCache.s deleted file mode 100644 index 942c6de5..00000000 --- a/lib/asm/osWritebackDCache.s +++ /dev/null @@ -1,49 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D4630 */ - -.include "macros.inc" - -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used - - -glabel osWritebackDCache -/* 0D5230 800D4630 18A00011 */ blez $a1, .L800D4678 -/* 0D5234 800D4634 00000000 */ nop -/* 0D5238 800D4638 240B2000 */ li $t3, 8192 -/* 0D523C 800D463C 00AB082B */ sltu $at, $a1, $t3 -/* 0D5240 800D4640 1020000F */ beqz $at, .L800D4680 -/* 0D5244 800D4644 00000000 */ nop -/* 0D5248 800D4648 00804025 */ move $t0, $a0 -/* 0D524C 800D464C 00854821 */ addu $t1, $a0, $a1 -/* 0D5250 800D4650 0109082B */ sltu $at, $t0, $t1 -/* 0D5254 800D4654 10200008 */ beqz $at, .L800D4678 -/* 0D5258 800D4658 00000000 */ nop -/* 0D525C 800D465C 310A000F */ andi $t2, $t0, 0xf -/* 0D5260 800D4660 2529FFF0 */ addiu $t1, $t1, -0x10 -/* 0D5264 800D4664 010A4023 */ subu $t0, $t0, $t2 -.L800D4668: -/* 0D5268 800D4668 BD190000 */ cache 0x19, ($t0) -/* 0D526C 800D466C 0109082B */ sltu $at, $t0, $t1 -/* 0D5270 800D4670 1420FFFD */ bnez $at, .L800D4668 -/* 0D5274 800D4674 25080010 */ addiu $t0, $t0, 0x10 -.L800D4678: -/* 0D5278 800D4678 03E00008 */ jr $ra -/* 0D527C 800D467C 00000000 */ nop - -.L800D4680: -/* 0D5280 800D4680 3C088000 */ lui $t0, 0x8000 -/* 0D5284 800D4684 010B4821 */ addu $t1, $t0, $t3 -/* 0D5288 800D4688 2529FFF0 */ addiu $t1, $t1, -0x10 -.L800D468C: -/* 0D528C 800D468C BD010000 */ cache 1, ($t0) -/* 0D5290 800D4690 0109082B */ sltu $at, $t0, $t1 -/* 0D5294 800D4694 1420FFFD */ bnez $at, .L800D468C -/* 0D5298 800D4698 25080010 */ addiu $t0, $t0, 0x10 -/* 0D529C 800D469C 03E00008 */ jr $ra -/* 0D52A0 800D46A0 00000000 */ nop - -/* 0D52A4 800D46A4 00000000 */ nop -/* 0D52A8 800D46A8 00000000 */ nop -/* 0D52AC 800D46AC 00000000 */ nop diff --git a/lib/asm/osWritebackDCacheAll.s b/lib/asm/osWritebackDCacheAll.s deleted file mode 100644 index 8fe146a5..00000000 --- a/lib/asm/osWritebackDCacheAll.s +++ /dev/null @@ -1,25 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D18A0 */ - -.include "macros.inc" - -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used - -glabel osWritebackDCacheAll -/* 0D24A0 800D18A0 3C088000 */ lui $t0, 0x8000 -/* 0D24A4 800D18A4 240A2000 */ li $t2, 8192 -/* 0D24A8 800D18A8 010A4821 */ addu $t1, $t0, $t2 -/* 0D24AC 800D18AC 2529FFF0 */ addiu $t1, $t1, -0x10 -.L800D18B0: -/* 0D24B0 800D18B0 BD010000 */ cache 1, ($t0) -/* 0D24B4 800D18B4 0109082B */ sltu $at, $t0, $t1 -/* 0D24B8 800D18B8 1420FFFD */ bnez $at, .L800D18B0 -/* 0D24BC 800D18BC 25080010 */ addiu $t0, $t0, 0x10 -/* 0D24C0 800D18C0 03E00008 */ jr $ra -/* 0D24C4 800D18C4 00000000 */ nop - -/* 0D24C8 800D18C8 00000000 */ nop -/* 0D24CC 800D18CC 00000000 */ nop - diff --git a/lib/asm/probetlb.s b/lib/asm/probetlb.s new file mode 100644 index 00000000..1d4bf4cf --- /dev/null +++ b/lib/asm/probetlb.s @@ -0,0 +1,68 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D35B0 */ + +.include "macro.inc" + +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ + +/* Handwritten function */ +glabel __osProbeTLB +/* D41B0 800D35B0 40085000 */ mfc0 $t0, $10 /* handwritten instruction */ +/* D41B4 800D35B4 310900FF */ andi $t1, $t0, 0xFF +/* D41B8 800D35B8 2401E000 */ addiu $at, $zero, -0x2000 +/* D41BC 800D35BC 00815024 */ and $t2, $a0, $at +/* D41C0 800D35C0 012A4825 */ or $t1, $t1, $t2 +/* D41C4 800D35C4 40895000 */ mtc0 $t1, $10 /* handwritten instruction */ +/* D41C8 800D35C8 00000000 */ nop +/* D41CC 800D35CC 00000000 */ nop +/* D41D0 800D35D0 00000000 */ nop +/* D41D4 800D35D4 42000008 */ tlbp /* handwritten instruction */ +/* D41D8 800D35D8 00000000 */ nop +/* D41DC 800D35DC 00000000 */ nop +/* D41E0 800D35E0 400B0000 */ mfc0 $t3, $0 /* handwritten instruction */ +/* D41E4 800D35E4 3C018000 */ lui $at, (0x80000000 >> 16) +/* D41E8 800D35E8 01615824 */ and $t3, $t3, $at +/* D41EC 800D35EC 1560001A */ bnez $t3, .L800D3658 +/* D41F0 800D35F0 00000000 */ nop +/* D41F4 800D35F4 42000001 */ tlbr /* handwritten instruction */ +/* D41F8 800D35F8 00000000 */ nop +/* D41FC 800D35FC 00000000 */ nop +/* D4200 800D3600 00000000 */ nop +/* D4204 800D3604 400B2800 */ mfc0 $t3, $5 /* handwritten instruction */ +/* D4208 800D3608 216B2000 */ addi $t3, $t3, 0x2000 /* handwritten instruction */ +/* D420C 800D360C 000B5842 */ srl $t3, $t3, 1 +/* D4210 800D3610 01646024 */ and $t4, $t3, $a0 +/* D4214 800D3614 15800004 */ bnez $t4, .L800D3628 +/* D4218 800D3618 216BFFFF */ addi $t3, $t3, -0x1 /* handwritten instruction */ +/* D421C 800D361C 40021000 */ mfc0 $v0, $2 /* handwritten instruction */ +/* D4220 800D3620 10000002 */ b .L800D362C +/* D4224 800D3624 00000000 */ nop +.L800D3628: +/* D4228 800D3628 40021800 */ mfc0 $v0, $3 /* handwritten instruction */ +.L800D362C: +/* D422C 800D362C 304D0002 */ andi $t5, $v0, 0x2 +/* D4230 800D3630 11A00009 */ beqz $t5, .L800D3658 +/* D4234 800D3634 00000000 */ nop +/* D4238 800D3638 3C013FFF */ lui $at, (0x3FFFFFC0 >> 16) +/* D423C 800D363C 3421FFC0 */ ori $at, $at, (0x3FFFFFC0 & 0xFFFF) +/* D4240 800D3640 00411024 */ and $v0, $v0, $at +/* D4244 800D3644 00021180 */ sll $v0, $v0, 6 +/* D4248 800D3648 008B6824 */ and $t5, $a0, $t3 +/* D424C 800D364C 004D1020 */ add $v0, $v0, $t5 /* handwritten instruction */ +/* D4250 800D3650 10000002 */ b .L800D365C +/* D4254 800D3654 00000000 */ nop +.L800D3658: +/* D4258 800D3658 2402FFFF */ addiu $v0, $zero, -0x1 +.L800D365C: +/* D425C 800D365C 40885000 */ mtc0 $t0, $10 /* handwritten instruction */ +/* D4260 800D3660 03E00008 */ jr $ra +/* D4264 800D3664 00000000 */ nop +/* D4268 800D3668 00000000 */ nop +/* D426C 800D366C 00000000 */ nop diff --git a/lib/asm/setcompare.s b/lib/asm/setcompare.s new file mode 100644 index 00000000..a06bae9e --- /dev/null +++ b/lib/asm/setcompare.s @@ -0,0 +1,20 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D7460 */ + +.include "macro.inc" + +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ + +/* Handwritten function */ +glabel __osSetCompare +/* D8060 800D7460 40845800 */ mtc0 $a0, $11 /* handwritten instruction */ +/* D8064 800D7464 03E00008 */ jr $ra +/* D8068 800D7468 00000000 */ nop +/* D806C 800D746C 00000000 */ nop diff --git a/lib/asm/setfpccsr.s b/lib/asm/setfpccsr.s new file mode 100644 index 00000000..ed80ab6d --- /dev/null +++ b/lib/asm/setfpccsr.s @@ -0,0 +1,19 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D4580 */ + +.include "macro.inc" + +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ + +glabel __osSetFpcCsr +/* D5180 800D4580 4442F800 */ cfc1 $v0, $31 +/* D5184 800D4584 44C4F800 */ ctc1 $a0, $31 +/* D5188 800D4588 03E00008 */ jr $ra +/* D518C 800D458C 00000000 */ nop diff --git a/lib/asm/setintmask.s b/lib/asm/setintmask.s new file mode 100644 index 00000000..d3e7a2db --- /dev/null +++ b/lib/asm/setintmask.s @@ -0,0 +1,72 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C9A30 */ + +.include "macro.inc" + +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .rodata + +glabel __osRcpImTable +/* LUT to convert between MI_INTR and MI_INTR_MASK */ +/* MI_INTR is status for each interrupt whereas */ +/* MI_INTR_MASK has seperate bits for set/clr */ +.half 0x0555, 0x0556, 0x0559, 0x055A, 0x0565, 0x0566, 0x0569, 0x056A +.half 0x0595, 0x0596, 0x0599, 0x059A, 0x05A5, 0x05A6, 0x05A9, 0x05AA +.half 0x0655, 0x0656, 0x0659, 0x065A, 0x0665, 0x0666, 0x0669, 0x066A +.half 0x0695, 0x0696, 0x0699, 0x069A, 0x06A5, 0x06A6, 0x06A9, 0x06AA +.half 0x0955, 0x0956, 0x0959, 0x095A, 0x0965, 0x0966, 0x0969, 0x096A +.half 0x0995, 0x0996, 0x0999, 0x099A, 0x09A5, 0x09A6, 0x09A9, 0x09AA +.half 0x0A55, 0x0A56, 0x0A59, 0x0A5A, 0x0A65, 0x0A66, 0x0A69, 0x0A6A +.half 0x0A95, 0x0A96, 0x0A99, 0x0A9A, 0x0AA5, 0x0AA6, 0x0AA9, 0x0AAA + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ + +/* Handwritten function */ +glabel osSetIntMask +/* CA630 800C9A30 400C6000 */ mfc0 $t4, $12 /* handwritten instruction */ +/* CA634 800C9A34 3182FF01 */ andi $v0, $t4, 0xFF01 +/* CA638 800C9A38 3C08800E */ lui $t0, %hi(__OSGlobalIntMask) +/* CA63C 800C9A3C 250838AC */ addiu $t0, $t0, %lo(__OSGlobalIntMask) +/* CA640 800C9A40 8D0B0000 */ lw $t3, 0x0($t0) +/* CA644 800C9A44 2401FFFF */ addiu $at, $zero, -0x1 +/* CA648 800C9A48 01614026 */ xor $t0, $t3, $at +/* CA64C 800C9A4C 3108FF00 */ andi $t0, $t0, 0xFF00 +/* CA650 800C9A50 00481025 */ or $v0, $v0, $t0 +/* CA654 800C9A54 3C0AA430 */ lui $t2, %hi(MI_INTR_MASK_REG) +/* CA658 800C9A58 8D4A000C */ lw $t2, %lo(MI_INTR_MASK_REG)($t2) +/* CA65C 800C9A5C 11400005 */ beqz $t2, .L800C9A74 +/* CA660 800C9A60 000B4C02 */ srl $t1, $t3, 16 +/* CA664 800C9A64 2401FFFF */ addiu $at, $zero, -0x1 +/* CA668 800C9A68 01214826 */ xor $t1, $t1, $at +/* CA66C 800C9A6C 3129003F */ andi $t1, $t1, 0x3F +/* CA670 800C9A70 01495025 */ or $t2, $t2, $t1 +.L800C9A74: +/* CA674 800C9A74 000A5400 */ sll $t2, $t2, 16 +/* CA678 800C9A78 004A1025 */ or $v0, $v0, $t2 +/* CA67C 800C9A7C 3C01003F */ lui $at, (0x3F0000 >> 16) +/* CA680 800C9A80 00814024 */ and $t0, $a0, $at +/* CA684 800C9A84 010B4024 */ and $t0, $t0, $t3 +/* CA688 800C9A88 000843C2 */ srl $t0, $t0, 15 +/* CA68C 800C9A8C 3C0A800F */ lui $t2, %hi(__osRcpImTable) +/* CA690 800C9A90 01485021 */ addu $t2, $t2, $t0 +/* CA694 800C9A94 954A94D0 */ lhu $t2, %lo(__osRcpImTable)($t2) +/* CA698 800C9A98 3C01A430 */ lui $at, %hi(MI_INTR_MASK_REG) +/* CA69C 800C9A9C AC2A000C */ sw $t2, %lo(MI_INTR_MASK_REG)($at) +/* CA6A0 800C9AA0 3088FF01 */ andi $t0, $a0, 0xFF01 +/* CA6A4 800C9AA4 3169FF00 */ andi $t1, $t3, 0xFF00 +/* CA6A8 800C9AA8 01094024 */ and $t0, $t0, $t1 +/* CA6AC 800C9AAC 3C01FFFF */ lui $at, (0xFFFF00FF >> 16) +/* CA6B0 800C9AB0 342100FF */ ori $at, $at, (0xFFFF00FF & 0xFFFF) +/* CA6B4 800C9AB4 01816024 */ and $t4, $t4, $at +/* CA6B8 800C9AB8 01886025 */ or $t4, $t4, $t0 +/* CA6BC 800C9ABC 408C6000 */ mtc0 $t4, $12 /* handwritten instruction */ +/* CA6C0 800C9AC0 00000000 */ nop +/* CA6C4 800C9AC4 00000000 */ nop +/* CA6C8 800C9AC8 03E00008 */ jr $ra +/* CA6CC 800C9ACC 00000000 */ nop diff --git a/lib/asm/setsr.s b/lib/asm/setsr.s new file mode 100644 index 00000000..a7a4a4b6 --- /dev/null +++ b/lib/asm/setsr.s @@ -0,0 +1,20 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D4560 */ + +.include "macro.inc" + +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ + +/* Handwritten function */ +glabel __osSetSR +/* D5160 800D4560 40846000 */ mtc0 $a0, $12 /* handwritten instruction */ +/* D5164 800D4564 00000000 */ nop +/* D5168 800D4568 03E00008 */ jr $ra +/* D516C 800D456C 00000000 */ nop diff --git a/lib/asm/__NOPS_NEEDED.s b/lib/asm/spaces.s similarity index 100% rename from lib/asm/__NOPS_NEEDED.s rename to lib/asm/spaces.s diff --git a/lib/asm/sqrtf.s b/lib/asm/sqrtf.s index d652ce16..4c6de0fd 100644 --- a/lib/asm/sqrtf.s +++ b/lib/asm/sqrtf.s @@ -1,16 +1,18 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C9AD0 */ +.include "macro.inc" -.include "macros.inc" +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ -.set noat # allow manual use of $at -.set noreorder # dont insert nops after branches -.set gp=64 # 64-bit instructions are used +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ glabel sqrtf -/* 0CA6D0 800C9AD0 03E00008 */ jr $ra -/* 0CA6D4 800C9AD4 46006004 */ sqrt.s $f0, $f12 - -/* 0CA6D8 800C9AD8 00000000 */ nop -/* 0CA6DC 800C9ADC 00000000 */ nop - +/* CA6D0 800C9AD0 03E00008 */ jr $ra +/* CA6D4 800C9AD4 46006004 */ sqrt.s $f0, $f12 +/* CA6D8 800C9AD8 00000000 */ nop +/* CA6DC 800C9ADC 00000000 */ nop diff --git a/lib/asm/writebackdcache.s b/lib/asm/writebackdcache.s new file mode 100644 index 00000000..2da0eddd --- /dev/null +++ b/lib/asm/writebackdcache.s @@ -0,0 +1,52 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D4630 */ + +.include "macro.inc" + +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ + +/* Handwritten function */ +glabel osWritebackDCache +/* D5230 800D4630 18A00011 */ blez $a1, .L800D4678 +/* D5234 800D4634 00000000 */ nop +/* D5238 800D4638 240B2000 */ addiu $t3, $zero, 0x2000 +/* D523C 800D463C 00AB082B */ sltu $at, $a1, $t3 +/* D5240 800D4640 1020000F */ beqz $at, .L800D4680 +/* D5244 800D4644 00000000 */ nop +/* D5248 800D4648 00804025 */ or $t0, $a0, $zero +/* D524C 800D464C 00854821 */ addu $t1, $a0, $a1 +/* D5250 800D4650 0109082B */ sltu $at, $t0, $t1 +/* D5254 800D4654 10200008 */ beqz $at, .L800D4678 +/* D5258 800D4658 00000000 */ nop +/* D525C 800D465C 310A000F */ andi $t2, $t0, 0xF +/* D5260 800D4660 2529FFF0 */ addiu $t1, $t1, -0x10 +/* D5264 800D4664 010A4023 */ subu $t0, $t0, $t2 +.L800D4668: +/* D5268 800D4668 BD190000 */ cache 0x19, 0x0($t0) /* handwritten instruction */ +/* D526C 800D466C 0109082B */ sltu $at, $t0, $t1 +/* D5270 800D4670 1420FFFD */ bnez $at, .L800D4668 +/* D5274 800D4674 25080010 */ addiu $t0, $t0, 0x10 +.L800D4678: +/* D5278 800D4678 03E00008 */ jr $ra +/* D527C 800D467C 00000000 */ nop +.L800D4680: +/* D5280 800D4680 3C088000 */ lui $t0, 0x8000 +/* D5284 800D4684 010B4821 */ addu $t1, $t0, $t3 +/* D5288 800D4688 2529FFF0 */ addiu $t1, $t1, -0x10 +.L800D468C: +/* D528C 800D468C BD010000 */ cache 0x01, 0x0($t0) /* handwritten instruction */ +/* D5290 800D4690 0109082B */ sltu $at, $t0, $t1 +/* D5294 800D4694 1420FFFD */ bnez $at, .L800D468C +/* D5298 800D4698 25080010 */ addiu $t0, $t0, (0x80000010 & 0xFFFF) +/* D529C 800D469C 03E00008 */ jr $ra +/* D52A0 800D46A0 00000000 */ nop +/* D52A4 800D46A4 00000000 */ nop +/* D52A8 800D46A8 00000000 */ nop +/* D52AC 800D46AC 00000000 */ nop diff --git a/lib/asm/writebackdcacheall.s b/lib/asm/writebackdcacheall.s new file mode 100644 index 00000000..3d32eb3d --- /dev/null +++ b/lib/asm/writebackdcacheall.s @@ -0,0 +1,29 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D18A0 */ + +.include "macro.inc" + +/* assembler directives */ +.set noat /* allow manual use of $at */ +.set noreorder /* don't insert nops after branches */ +.set gp=64 /* allow use of 64-bit general purpose registers */ + +.section .text, "ax" + +/* Generated by spimdisasm 1.30.0 */ + +/* Handwritten function */ +glabel osWritebackDCacheAll +/* D24A0 800D18A0 3C088000 */ lui $t0, 0x8000 +/* D24A4 800D18A4 240A2000 */ addiu $t2, $zero, 0x2000 +/* D24A8 800D18A8 010A4821 */ addu $t1, $t0, $t2 +/* D24AC 800D18AC 2529FFF0 */ addiu $t1, $t1, -0x10 +.L800D18B0: +/* D24B0 800D18B0 BD010000 */ cache 0x01, 0x0($t0) /* handwritten instruction */ +/* D24B4 800D18B4 0109082B */ sltu $at, $t0, $t1 +/* D24B8 800D18B8 1420FFFD */ bnez $at, .L800D18B0 +/* D24BC 800D18BC 25080010 */ addiu $t0, $t0, (0x80000010 & 0xFFFF) +/* D24C0 800D18C0 03E00008 */ jr $ra +/* D24C4 800D18C4 00000000 */ nop +/* D24C8 800D18C8 00000000 */ nop +/* D24CC 800D18CC 00000000 */ nop diff --git a/lib/src/al/alCSPGetChlVol.c b/lib/src/al/alCSPGetChlVol.c deleted file mode 100644 index 4d7dbc18..00000000 --- a/lib/src/al/alCSPGetChlVol.c +++ /dev/null @@ -1,8 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C79A0 */ - -#include "audio_internal.h" - -u8 alCSPGetChlVol(ALCSPlayer *seqp, u8 chan) { - return seqp->chanState[chan].vol; -} diff --git a/lib/src/al/alCSPSetChlPan.c b/lib/src/al/alCSPSetChlPan.c deleted file mode 100644 index 96d4513a..00000000 --- a/lib/src/al/alCSPSetChlPan.c +++ /dev/null @@ -1,18 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C78E0 */ - -#include "types.h" -#include "macros.h" -#include "audio_internal.h" - -void alCSPSetChlPan(ALCSPlayer *seqp, u8 chan, ALPan pan) { - ALEvent evt; - - evt.type = AL_SEQP_MIDI_EVT; - evt.msg.midi.ticks = 0; - evt.msg.midi.status = AL_MIDI_ControlChange | chan; - evt.msg.midi.byte1 = AL_MIDI_PAN_CTRL; - evt.msg.midi.byte2 = pan; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} diff --git a/lib/src/al/alCSPSetTempo.c b/lib/src/al/alCSPSetTempo.c deleted file mode 100644 index 5969ed34..00000000 --- a/lib/src/al/alCSPSetTempo.c +++ /dev/null @@ -1,19 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C79E0 */ - -#include "types.h" -#include "macros.h" -#include "audio_internal.h" - -void alCSPSetTempo(ALCSPlayer *seqp, s32 tempo) { - ALEvent evt; - - evt.type = AL_SEQP_META_EVT; - evt.msg.tempo.status = AL_MIDI_Meta; - evt.msg.tempo.type = AL_MIDI_META_TEMPO; - evt.msg.tempo.byte1 = (tempo & 0xff0000)>>16; - evt.msg.tempo.byte2 = (tempo & 0xff00)>>8; - evt.msg.tempo.byte3 = tempo & 0xff; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} diff --git a/lib/src/al/alCSPSetVol.c b/lib/src/al/alCSPSetVol.c deleted file mode 100644 index d704d962..00000000 --- a/lib/src/al/alCSPSetVol.c +++ /dev/null @@ -1,13 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C7850 */ - -#include "audio_internal.h" - -void alCSPSetVol(ALCSPlayer *seqp, s16 vol) { - ALEvent evt; - - evt.type = AL_SEQP_VOL_EVT; - evt.msg.spvol.vol = vol; - - alEvtqPostEvent(&seqp->evtq, &evt, 0); -} diff --git a/lib/src/al/alCopy.c b/lib/src/al/alCopy.c deleted file mode 100644 index 8826cf0c..00000000 --- a/lib/src/al/alCopy.c +++ /dev/null @@ -1,18 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D3820 */ - -#include "types.h" -#include "macros.h" - -//TODO: This probably belongs somewhere else -s32 __osHwIntTable[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - -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/lib/src/al/alHeapDBAlloc.c b/lib/src/al/alHeapDBAlloc.c deleted file mode 100644 index a3824a60..00000000 --- a/lib/src/al/alHeapDBAlloc.c +++ /dev/null @@ -1,20 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C77F0 */ - -#include "audio_internal.h" -#include "macros.h" - -void *alHeapDBAlloc(UNUSED u8 *file, UNUSED s32 line, ALHeap *hp, s32 num, s32 size) { - s32 bytes; - u8 *ptr = 0; - - bytes = (num*size + AL_CACHE_ALIGN) & ~AL_CACHE_ALIGN; - - if ((hp->cur + bytes) <= (hp->base + hp->len)) { - ptr = hp->cur; - hp->cur += bytes; - } else { - } - - return ptr; -} diff --git a/lib/src/al/alHeapInit.c b/lib/src/al/alHeapInit.c deleted file mode 100644 index 2aa43af8..00000000 --- a/lib/src/al/alHeapInit.c +++ /dev/null @@ -1,17 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C7560 */ - -#include "audio_internal.h" - -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/lib/src/al/alSeqpGetChlFXMix.c b/lib/src/al/alSeqpGetChlFXMix.c deleted file mode 100644 index e26daa7d..00000000 --- a/lib/src/al/alSeqpGetChlFXMix.c +++ /dev/null @@ -1,8 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C79C0 */ - -#include "audio_internal.h" - -u8 alSeqpGetChlFXMix(ALSeqPlayer *seqp, u8 chan) { - return seqp->chanState[chan].fxmix; -} diff --git a/lib/src/al/alBnkfNew.c b/lib/src/audio/bnkf.c similarity index 92% rename from lib/src/al/alBnkfNew.c rename to lib/src/audio/bnkf.c index e2de481b..91145f2b 100644 --- a/lib/src/al/alBnkfNew.c +++ b/lib/src/audio/bnkf.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C75A0 */ - /*==================================================================== * bnkf.c * @@ -21,9 +20,9 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include +#include +#include /* * ### when the file format settles down a little, I'll remove these @@ -69,7 +68,7 @@ void alBnkfNew(ALBankFile *file, u8 *table) } } -static void _bnkfPatchBank(ALBank *bank, s32 offset, s32 table) +void _bnkfPatchBank(ALBank *bank, s32 offset, s32 table) { s32 i; @@ -91,7 +90,7 @@ static void _bnkfPatchBank(ALBank *bank, s32 offset, s32 table) } } -static void _bnkfPatchInst(ALInstrument *inst, s32 offset, s32 table) +void _bnkfPatchInst(ALInstrument *inst, s32 offset, s32 table) { s32 i; @@ -108,7 +107,7 @@ static void _bnkfPatchInst(ALInstrument *inst, s32 offset, s32 table) } } -static void _bnkfPatchSound(ALSound *s, s32 offset, s32 table) +void _bnkfPatchSound(ALSound *s, s32 offset, s32 table) { if (s->flags) return; @@ -122,7 +121,7 @@ static void _bnkfPatchSound(ALSound *s, s32 offset, s32 table) _bnkfPatchWaveTable(s->wavetable, offset, table); } -static void _bnkfPatchWaveTable(ALWaveTable *w, s32 offset, s32 table) +void _bnkfPatchWaveTable(ALWaveTable *w, s32 offset, s32 table) { if (w->flags) return; diff --git a/lib/src/al/cents2ratio.c b/lib/src/audio/cents2ratio.c similarity index 87% rename from lib/src/al/cents2ratio.c rename to lib/src/audio/cents2ratio.c index 43dee5ed..2dd55812 100644 --- a/lib/src/al/cents2ratio.c +++ b/lib/src/audio/cents2ratio.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C99E0 */ - /* * alCents2Ratio() * @@ -11,10 +10,7 @@ * two ocataves. */ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" -#include "libultra_internal.h" +#include f32 alCents2Ratio(s32 cents) { diff --git a/lib/src/audio/copy.c b/lib/src/audio/copy.c new file mode 100644 index 00000000..06b353da --- /dev/null +++ b/lib/src/audio/copy.c @@ -0,0 +1,37 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D3820 */ +/*==================================================================== + * 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/lib/src/al/cseq.c b/lib/src/audio/cseq.c similarity index 99% rename from lib/src/al/cseq.c rename to lib/src/audio/cseq.c index cc5ac220..b05fb5f1 100644 --- a/lib/src/al/cseq.c +++ b/lib/src/audio/cseq.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C7AA0 */ - /*==================================================================== * cseq.c * @@ -21,9 +20,11 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include +#include +#include +#include "cseq.h" + static u32 __readVarLen(ALCSeq *s,u32 track); static u8 __getTrackByte(ALCSeq *s,u32 track); @@ -398,3 +399,13 @@ static u32 __readVarLen(ALCSeq *seq,u32 track) } return (value); } + + + + + + + + + + diff --git a/lib/src/mips1/al/cseq.h b/lib/src/audio/cseq.h similarity index 100% rename from lib/src/mips1/al/cseq.h rename to lib/src/audio/cseq.h diff --git a/lib/src/mips1/al/cseqp.h b/lib/src/audio/cseqp.h similarity index 100% rename from lib/src/mips1/al/cseqp.h rename to lib/src/audio/cseqp.h diff --git a/lib/src/audio/cspgetchlvol.c b/lib/src/audio/cspgetchlvol.c new file mode 100644 index 00000000..3717de60 --- /dev/null +++ b/lib/src/audio/cspgetchlvol.c @@ -0,0 +1,29 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C79A0 */ +/*==================================================================== + * cspgetchlvol.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 + +u8 alCSPGetChlVol(ALCSPlayer *seqp, u8 chan) +{ + return seqp->chanState[chan].vol; +} + diff --git a/lib/src/al/alCSPGetState.c b/lib/src/audio/cspgetstate.c similarity index 94% rename from lib/src/al/alCSPGetState.c rename to lib/src/audio/cspgetstate.c index d1933135..608ff28a 100644 --- a/lib/src/al/alCSPGetState.c +++ b/lib/src/audio/cspgetstate.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C7A50 */ - /*==================================================================== * cspgetstate.c * @@ -23,11 +22,10 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include s32 alCSPGetState(ALCSPlayer *seqp) { return seqp->state; } + diff --git a/lib/src/al/alCSPGetTempo.c b/lib/src/audio/cspgettempo.c similarity index 94% rename from lib/src/al/alCSPGetTempo.c rename to lib/src/audio/cspgettempo.c index b6b42508..99c4044c 100644 --- a/lib/src/al/alCSPGetTempo.c +++ b/lib/src/audio/cspgettempo.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C7890 */ - /*==================================================================== * cspgettempo.c * @@ -21,9 +20,7 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include s32 alCSPGetTempo(ALCSPlayer *seqp) { diff --git a/lib/src/al/cspplay.c b/lib/src/audio/cspplay.c similarity index 94% rename from lib/src/al/cspplay.c rename to lib/src/audio/cspplay.c index 7dd0b0e4..e180c5b6 100644 --- a/lib/src/al/cspplay.c +++ b/lib/src/audio/cspplay.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C85A0 */ - /*==================================================================== * cspplay.c * @@ -23,9 +22,8 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include +#include "cseqp.h" void alCSPPlay(ALCSPlayer *seqp) { @@ -35,3 +33,4 @@ void alCSPPlay(ALCSPlayer *seqp) alEvtqPostEvent(&seqp->evtq, &evt, 0); } + diff --git a/lib/src/al/alCSPSetBank.c b/lib/src/audio/cspsetbank.c similarity index 94% rename from lib/src/al/alCSPSetBank.c rename to lib/src/audio/cspsetbank.c index a00ff00d..b7c27f19 100644 --- a/lib/src/al/alCSPSetBank.c +++ b/lib/src/audio/cspsetbank.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C7A60 */ - /*==================================================================== * cspsetbank.c * @@ -21,10 +20,7 @@ * Copyright Laws of the United States. *====================================================================*/ - -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include void alCSPSetBank(ALCSPlayer *seqp, ALBank *b) { @@ -35,3 +31,4 @@ void alCSPSetBank(ALCSPlayer *seqp, ALBank *b) alEvtqPostEvent(&seqp->evtq, &evt, 0); } + diff --git a/lib/src/al/alCSPSetChlVol.c b/lib/src/audio/cspsetchlvol.c similarity index 95% rename from lib/src/al/alCSPSetChlVol.c rename to lib/src/audio/cspsetchlvol.c index 6ee60a68..63854d2b 100644 --- a/lib/src/al/alCSPSetChlVol.c +++ b/lib/src/audio/cspsetchlvol.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C7940 */ - /*==================================================================== * cspsetchlvol.c * @@ -21,9 +20,7 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include void alCSPSetChlVol(ALCSPlayer *seqp, u8 chan, u8 vol) { @@ -38,4 +35,3 @@ void alCSPSetChlVol(ALCSPlayer *seqp, u8 chan, u8 vol) alEvtqPostEvent(&seqp->evtq, &evt, 0); } - diff --git a/lib/src/audio/cspsetpan.c b/lib/src/audio/cspsetpan.c new file mode 100644 index 00000000..e5d4131d --- /dev/null +++ b/lib/src/audio/cspsetpan.c @@ -0,0 +1,37 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C78E0 */ +/*==================================================================== + * cspsetpan.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 + +void alCSPSetChlPan(ALCSPlayer *seqp, u8 chan, ALPan pan) +{ + ALEvent evt; + + evt.type = AL_SEQP_MIDI_EVT; + evt.msg.midi.ticks = 0; + evt.msg.midi.status = AL_MIDI_ControlChange | chan; + evt.msg.midi.byte1 = AL_MIDI_PAN_CTRL; + evt.msg.midi.byte2 = pan; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/src/al/alCSPSetSeq.c b/lib/src/audio/cspsetseq.c similarity index 94% rename from lib/src/al/alCSPSetSeq.c rename to lib/src/audio/cspsetseq.c index 35ce54cb..0c84d0b3 100644 --- a/lib/src/al/alCSPSetSeq.c +++ b/lib/src/audio/cspsetseq.c @@ -1,7 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C8560 */ - - /*==================================================================== * cspsetseq.c * @@ -24,9 +22,7 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include void alCSPSetSeq(ALCSPlayer *seqp, ALCSeq *seq) { @@ -37,3 +33,4 @@ void alCSPSetSeq(ALCSPlayer *seqp, ALCSeq *seq) alEvtqPostEvent(&seqp->evtq, &evt, 0); } + diff --git a/lib/src/audio/cspsettempo.c b/lib/src/audio/cspsettempo.c new file mode 100644 index 00000000..2af3305d --- /dev/null +++ b/lib/src/audio/cspsettempo.c @@ -0,0 +1,38 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C79E0 */ +/*==================================================================== + * cspsettempo.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 + +void alCSPSetTempo(ALCSPlayer *seqp, s32 tempo) +{ + ALEvent evt; + + evt.type = AL_SEQP_META_EVT; + evt.msg.tempo.status = AL_MIDI_Meta; + evt.msg.tempo.type = AL_MIDI_META_TEMPO; + evt.msg.tempo.byte1 = (tempo & 0xff0000)>>16; + evt.msg.tempo.byte2 = (tempo & 0xff00)>>8; + evt.msg.tempo.byte3 = tempo & 0xff; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/src/audio/cspsetvol.c b/lib/src/audio/cspsetvol.c new file mode 100644 index 00000000..23e130d5 --- /dev/null +++ b/lib/src/audio/cspsetvol.c @@ -0,0 +1,34 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C7850 */ +/*==================================================================== + * cspsetvol.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 + +void alCSPSetVol(ALCSPlayer *seqp, s16 vol) +{ + ALEvent evt; + + evt.type = AL_SEQP_VOL_EVT; + evt.msg.spvol.vol = vol; + + alEvtqPostEvent(&seqp->evtq, &evt, 0); +} + diff --git a/lib/src/al/cspstop.c b/lib/src/audio/cspstop.c similarity index 94% rename from lib/src/al/cspstop.c rename to lib/src/audio/cspstop.c index ca0427fb..b1a82bc5 100644 --- a/lib/src/al/cspstop.c +++ b/lib/src/audio/cspstop.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C85D0 */ - /*==================================================================== * cspstop.c * @@ -23,9 +22,7 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include void alCSPStop(ALCSPlayer *seqp) { @@ -34,3 +31,4 @@ void alCSPStop(ALCSPlayer *seqp) evt.type = AL_SEQP_STOPPING_EVT; alEvtqPostEvent(&seqp->evtq, &evt, 0); } + diff --git a/lib/src/al/env.c b/lib/src/audio/env.c similarity index 92% rename from lib/src/al/env.c rename to lib/src/audio/env.c index aa42a7a2..bfa00fcc 100644 --- a/lib/src/al/env.c +++ b/lib/src/audio/env.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CA0D0 */ - /*==================================================================== * envmixer.c * @@ -20,21 +19,20 @@ * DOD or NASA FAR Supplement. Unpublished - rights reserved under the * Copyright Laws of the United States. *====================================================================*/ - -#include "types.h" -#include "macros.h" -#include "audio_internal.h" -#include "audio_assert.h" - +#include +#include "synthInternals.h" +#include +#include +#include +#include "lib/src/debug/assert.h" // 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, @@ -70,13 +68,12 @@ 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); -extern u32 osVirtualToPhysical(void *); +static f32 _getVol(f32 ivol, s32 samples, s16 ratem, u16 ratel); /*********************************************************************** * Enveloper filter public interfaces ***********************************************************************/ -Acmd *alEnvmixerPull(void *filter, UNUSED s16 *outp, s32 outCount, s32 sampleOffset, +Acmd *alEnvmixerPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p) { Acmd *ptr = p; @@ -98,26 +95,21 @@ Acmd *alEnvmixerPull(void *filter, UNUSED s16 *outp, s32 outCount, s32 sampleOff */ inp = AL_RESAMPLER_OUT; - while (e->ctrlList != 0) { - + 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); -#else +#if BUILD_VERSION < VERSION_J +#line 103 +#endif // Something must have gone wrong when compiling this file, and the asserts got left in. if (samples >= 0) {} - else { assert_stub("samples >= 0", "env.c", 104); } + else { __assert("samples >= 0", "env.c", 104); } if (samples <= AL_MAX_RSP_SAMPLES) {} - else { assert_stub("samples <= AL_MAX_RSP_SAMPLES", "env.c", 105); } -#endif + else { __assert("samples <= AL_MAX_RSP_SAMPLES", "env.c", 105); } - switch (e->ctrlList->type) { case (AL_FILTER_START_VOICE_ALT): { @@ -138,8 +130,8 @@ Acmd *alEnvmixerPull(void *filter, UNUSED s16 *outp, s32 outCount, s32 sampleOff e->delta = 0; e->segEnd = param->samples; - - tmp = ((s32)param->volume + (s32)param->volume) / 2; //Diff + + tmp = ((s32)param->volume + (s32)param->volume) / 2; e->volume = (s16) tmp; e->pan = param->pan; e->dryamt = eqpower[param->fxMix]; @@ -176,7 +168,7 @@ Acmd *alEnvmixerPull(void *filter, UNUSED s16 *outp, s32 outCount, s32 sampleOff case (AL_FILTER_SET_PAN): case (AL_FILTER_SET_VOLUME): ptr = _pullSubFrame(e, &inp, &loutp, samples, sampleOffset, ptr); - e->delta += samples; //Diff + e->delta += samples; if (e->delta >= e->segEnd){ /* * We should have reached our target, calculate @@ -223,7 +215,7 @@ Acmd *alEnvmixerPull(void *filter, UNUSED s16 *outp, s32 outCount, s32 sampleOff * loudness */ fVol = (e->ctrlList->data.i); - fVol = (fVol+fVol)/2; //Diff + fVol = (fVol+fVol)/2; e->volume = (s16) fVol; e->segEnd = e->ctrlList->moredata.i; @@ -276,7 +268,7 @@ Acmd *alEnvmixerPull(void *filter, UNUSED s16 *outp, s32 outCount, s32 sampleOff ALSynth *drvr = &alGlobals->drvr; ALFreeParam *param = (ALFreeParam *)e->ctrlList; param->pvoice->offset = 0; - __freePVoices(drvr, (PVoice *)param->pvoice); + _freePVoice(drvr, (PVoice *)param->pvoice); } break; @@ -286,7 +278,7 @@ Acmd *alEnvmixerPull(void *filter, UNUSED s16 *outp, s32 outCount, s32 sampleOff * on down the chain */ ptr = _pullSubFrame(e, &inp, &loutp, samples, sampleOffset, ptr); - e->delta += samples; //Diff + e->delta += samples; (*e->filter.setParam)(&e->filter, e->ctrlList->type, (void *) e->ctrlList->data.i); break; @@ -306,16 +298,14 @@ Acmd *alEnvmixerPull(void *filter, UNUSED s16 *outp, s32 outCount, s32 sampleOff } - //Diff if (e->motion == 1) { ptr = _pullSubFrame(e, &inp, &loutp, outCount, sampleOffset, ptr); - e->delta += outCount; //Diff - } + e->delta += outCount; + } /* * Prevent overflow in e->delta */ - if (e->delta > e->segEnd) e->delta = e->segEnd; @@ -325,8 +315,7 @@ Acmd *alEnvmixerPull(void *filter, UNUSED s16 *outp, s32 outCount, s32 sampleOff return ptr; } -s32 -alEnvmixerParam(void *filter, s32 paramID, void *param) +s32 alEnvmixerParam(void *filter, s32 paramID, void *param) { ALFilter *f = (ALFilter *) filter; ALEnvMixer *e = (ALEnvMixer *) filter; @@ -367,9 +356,10 @@ alEnvmixerParam(void *filter, s32 paramID, void *param) } return 0; } - -static -Acmd* _pullSubFrame(void *filter, s16 *inp, s16 *outp, s32 outCount, +#if BUILD_VERSION < VERSION_J +#line 350 +#endif +static Acmd* _pullSubFrame(void *filter, s16 *inp, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p) { Acmd *ptr = p; @@ -377,20 +367,17 @@ Acmd* _pullSubFrame(void *filter, s16 *inp, s16 *outp, s32 outCount, ALFilter *source= e->filter.source; /* filter must be playing and request non-zero output samples to pull. */ - if (!outCount) //Diff + if (!outCount) return ptr; /* * ask all filters upstream from us to build their command * lists. */ -#ifdef _DEBUG - assert(source); -#else + // Something must have gone wrong when compiling this file, and the asserts got left in. if (source) {} - else { assert_stub("source", "env.c", 373); } -#endif + else { __assert("source", "env.c", 373); } ptr = (*source->handler)(source, inp, outCount, sampleOffset, p); @@ -430,7 +417,6 @@ Acmd* _pullSubFrame(void *filter, s16 *inp, s16 *outp, s32 outCount, */ *inp += (outCount<<1); - //e->delta += outCount; //Diff return ptr; } @@ -481,8 +467,12 @@ _ldexpf(f64 in, s32 ex) static s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel) { - s16 s; + s16 s; f64 a; + +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif if (count == 0){ if (tgt >= vol){ @@ -491,7 +481,7 @@ s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel) } else{ *ratel = 0; - return -0x8000; //Diff + return -0x8000; } } @@ -501,9 +491,13 @@ s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel) a -= 1.0; } s = (s16) a; - *ratel = (s16)((0xffff * (a - (f32) s))); - + *ratel = (s16)(0xffff * (a - (f32) s)); + +#ifdef AUD_PROFILE + PROFILE_AUD(rate_num, rate_cnt, rate_max, rate_min); +#endif return (s16)a; + } static @@ -513,3 +507,9 @@ f32 _getVol(f32 ivol, s32 samples, s16 ratem, u16 ratel) { ivol += (r * samples) / 8.0; return ivol; } + + + + + + diff --git a/lib/src/al/event.c b/lib/src/audio/event.c similarity index 69% rename from lib/src/al/event.c rename to lib/src/audio/event.c index dcc6e230..ae2719be 100644 --- a/lib/src/al/event.c +++ b/lib/src/audio/event.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C9090 */ - /*==================================================================== * event.c * @@ -21,10 +20,10 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" -#include "libultra_internal.h" +#include +#include +#include + void alEvtqNew(ALEventQueue *evtq, ALEventListItem *items, s32 itemCount) { @@ -123,7 +122,8 @@ void alEvtqPostEvent(ALEventQueue *evtq, ALEvent *evt, ALMicroTime delta) } } - osSetIntMask(mask); + osSetIntMask(mask); + } void alEvtqFlush(ALEventQueue *evtq) @@ -145,6 +145,7 @@ void alEvtqFlush(ALEventQueue *evtq) osSetIntMask(mask); } + /* This routine flushes events according their type. */ @@ -175,3 +176,99 @@ void alEvtqFlushType(ALEventQueue *evtq, s16 type) osSetIntMask(mask); } + + +#ifdef _DEBUG_INTERNAL +void alEvtqPrintEvtQueue(ALEventQueue *evtq) +{ + s32 count1 = 0; + s32 count2 = 0; + ALLink *node; + ALEventListItem *item; + + /* count free events */ + for (node = evtq->freeList.next; node != 0; node= node->next) { + count1++; + } + + PRINTF("----- Allocated Events -----\n"); + for (node = evtq->allocList.next; node != 0; node= node->next) { + item = (ALEventListItem *)node; + + PRINTF("\tdelta: %d\ttype %d\n", item->delta, item->evt.type); + count2++; + } + PRINTF("\n"); + + PRINTF("free events\t %d\n", count1); + PRINTF("alloc events\t %d\n", count2); + PRINTF("total events\t %d\n", count1 + count2); +} + +char *MidiStatus2Str (char status, char *str); + +void +alEvtqPrintAllocEvts(ALEventQueue *evtq) +{ + ALLink *node; + ALEventListItem *item; + ALMicroTime itemTime = 0; + char str[32]; + + PRINTF("----- Allocated Events -----\n"); + for (node = evtq->allocList.next; node != 0; node= node->next) + { + item = (ALEventListItem *)node; + itemTime += item->delta; + + PRINTF("\tdelta: %d\tabs: %d\t", item->delta, itemTime); + + switch (item->evt.type) + { + case AL_NOTE_END_EVT: + PRINTF("NOTE_END\tvox: %x\n", item->evt.msg.note.voice); + break; + + case AL_SEQP_MIDI_EVT: + PRINTF("SEQP_MIDI\t%s\n", MidiStatus2Str(item->evt.msg.midi.status & AL_MIDI_StatusMask, str)); + break; + + case AL_SEQP_PRIORITY_EVT: + PRINTF("SEQP_PRIORITY\n"); + break; + + default: + PRINTF("type: %d\n", item->evt.type); + break; + } + + } + PRINTF("\n"); + +} + +char * +MidiStatus2Str (char status, char *str) +{ + switch (status) + { + case AL_MIDI_NoteOn: + sprintf(str, "note on"); + break; + + case AL_MIDI_NoteOff: + sprintf(str, "note off"); + break; + + default: + sprintf(str, "status:%d", status); + break; + } + + return str; +} + +#endif /* _DEBUG_INTERNAL */ + + + diff --git a/lib/src/al/filter.c b/lib/src/audio/filter.c similarity index 94% rename from lib/src/al/filter.c rename to lib/src/audio/filter.c index 31037dae..825af02a 100644 --- a/lib/src/al/filter.c +++ b/lib/src/audio/filter.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CA0B0 */ - /*==================================================================== * filter.c * @@ -21,9 +20,8 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include +#include "synthInternals.h" void alFilterNew(ALFilter *f, ALCmdHandler h, ALSetParam s, s32 type) { diff --git a/lib/src/audio/heapalloc.c b/lib/src/audio/heapalloc.c new file mode 100644 index 00000000..f6696207 --- /dev/null +++ b/lib/src/audio/heapalloc.c @@ -0,0 +1,67 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C77F0 */ +/*==================================================================== + * 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/lib/src/audio/heapinit.c b/lib/src/audio/heapinit.c new file mode 100644 index 00000000..0d1d7533 --- /dev/null +++ b/lib/src/audio/heapinit.c @@ -0,0 +1,39 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C7560 */ +/*==================================================================== + * 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/lib/src/mips1/al/initfx.h b/lib/src/audio/initfx.h similarity index 100% rename from lib/src/mips1/al/initfx.h rename to lib/src/audio/initfx.h diff --git a/lib/src/al/load.c b/lib/src/audio/load.c similarity index 94% rename from lib/src/al/load.c rename to lib/src/audio/load.c index 782f0ea5..2dbdfa96 100644 --- a/lib/src/al/load.c +++ b/lib/src/audio/load.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CB540 */ - /*==================================================================== * load.c * @@ -21,10 +20,10 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" -#include "PR/R4300.h" +#include +#include "synthInternals.h" +#include +#include #ifndef MIN # define MIN(a,b) (((a)<(b))?(a):(b)) @@ -40,7 +39,7 @@ extern u32 cnt_index, adpcm_num, adpcm_cnt, adpcm_max, adpcm_min, lastCnt[]; 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, UNUSED s32 sampleOffset, Acmd *p) +Acmd *alAdpcmPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p) { Acmd *ptr = p; s16 inp; @@ -70,7 +69,7 @@ Acmd *alAdpcmPull(void *filter, s16 *outp, s32 outCount, UNUSED s32 sampleOffset aLoadADPCM(ptr++, f->bookSize, K0_TO_PHYS(f->table->waveInfo.adpcmWave.book->book)); - looped = ((u32)(outCount + f->sample) > f->loop.end) && (f->loop.count != 0); + looped = (outCount + f->sample > f->loop.end) && (f->loop.count != 0); if (looped) nSam = f->loop.end - f->sample; else @@ -127,13 +126,13 @@ Acmd *alAdpcmPull(void *filter, s16 *outp, s32 outCount, UNUSED s32 sampleOffset * -1 is loop forever - the loop count is not exact now * for small loops! */ - if ((f->loop.count != -1U) && (f->loop.count != 0)) + if ((f->loop.count != -1) && (f->loop.count != 0)) f->loop.count--; /* * What's left to compute. */ - nSam = MIN((u32)outCount, f->loop.end - f->loop.start); + nSam = MIN(outCount, f->loop.end - f->loop.start); tsam = nSam - ADPCMFSIZE + f->lastsam; if (tsam<0) tsam = 0; nframes = (tsam+ADPCMFSIZE-1)>>LFSAMPLES; @@ -209,7 +208,7 @@ Acmd *alAdpcmPull(void *filter, s16 *outp, s32 outCount, UNUSED s32 sampleOffset return ptr; } -Acmd *alRaw16Pull(void *filter, s16 *outp, s32 outCount, UNUSED s32 sampleOffset, Acmd *p) +Acmd *alRaw16Pull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p) { Acmd *ptr = p; s32 nbytes; @@ -222,11 +221,12 @@ Acmd *alRaw16Pull(void *filter, s16 *outp, s32 outCount, UNUSED s32 sampleOffset s32 op; ALLoadFilter *f = (ALLoadFilter *)filter; + ALFilter *a = (ALFilter *) filter; if (outCount == 0) return ptr; - if (((u32)(outCount + f->sample) > f->loop.end) && (f->loop.count != 0)){ + if ((outCount + f->sample > f->loop.end) && (f->loop.count != 0)){ nSam = f->loop.end - f->sample; nbytes = nSam<<1; @@ -260,13 +260,13 @@ Acmd *alRaw16Pull(void *filter, s16 *outp, s32 outCount, UNUSED s32 sampleOffset /* * -1 is loop forever */ - if ((f->loop.count != -1U) && (f->loop.count != 0)) + if ((f->loop.count != -1) && (f->loop.count != 0)) f->loop.count--; /* * What to compute. */ - nSam = MIN((u32)outCount, f->loop.end - f->loop.start); + nSam = MIN(outCount, f->loop.end - f->loop.start); nbytes = nSam<<1; /* @@ -437,7 +437,6 @@ alLoadParam(void *filter, s32 paramID, void *param) } } -static Acmd *_decodeChunk(Acmd *ptr, ALLoadFilter *f, s32 tsam, s32 nbytes, s16 outp, s16 inp, u32 flags) { @@ -469,3 +468,6 @@ Acmd *_decodeChunk(Acmd *ptr, ALLoadFilter *f, s32 tsam, s32 nbytes, s16 outp, s return ptr; } + + + diff --git a/lib/src/al/mainbus.c b/lib/src/audio/mainbus.c similarity index 96% rename from lib/src/al/mainbus.c rename to lib/src/audio/mainbus.c index 5f1672e5..17044cb6 100644 --- a/lib/src/al/mainbus.c +++ b/lib/src/audio/mainbus.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CC390 */ - /*==================================================================== * mainbus.c * @@ -21,9 +20,8 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include +#include "synthInternals.h" Acmd *alMainBusPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, Acmd *p) { @@ -68,3 +66,4 @@ s32 alMainBusParam(void *filter, s32 paramID, void *param) return 0; } + diff --git a/lib/src/audio/mips1/auxbus.c b/lib/src/audio/mips1/auxbus.c new file mode 100644 index 00000000..21bae020 --- /dev/null +++ b/lib/src/audio/mips1/auxbus.c @@ -0,0 +1,81 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80065900 */ + +/*==================================================================== + * 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; + s32 i; + + switch (paramID) { + case AL_FILTER_ADD_SOURCE: + sources[m->sourceCount++] = (ALFilter *) param; + break; + case AL_FILTER_UNK11: + for (i = 0; i < m->sourceCount; i++) { + if ((ALFilter *) param == sources[i]) { + m->sourceCount--; + sources[i] = sources[m->sourceCount]; + } + } + break; + default: + /* ??? */ + break; + } + + return 0; + +} + +void func_80065A80(ALSynth *arg0, PVoice *arg1, s16 arg2) { + if (arg2 != arg1->unkDC) { + alAuxBusParam(&arg0->auxBus[arg1->unkDC], AL_FILTER_UNK11, &arg1->envmixer); + alAuxBusParam(&arg0->auxBus[arg2], AL_FILTER_ADD_SOURCE, &arg1->envmixer); + arg1->unkDC = arg2; + } +} diff --git a/lib/src/mips1/al/alCSPGetFadeIn.c b/lib/src/audio/mips1/cspgetfadein.c similarity index 76% rename from lib/src/mips1/al/alCSPGetFadeIn.c rename to lib/src/audio/mips1/cspgetfadein.c index c69b955c..2cf12f43 100644 --- a/lib/src/mips1/al/alCSPGetFadeIn.c +++ b/lib/src/audio/mips1/cspgetfadein.c @@ -1,9 +1,7 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x80063C00 */ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include u8 alCSPGetFadeIn(ALCSPlayer *seqp, u8 chan) { return ((ALChanState_Custom*)seqp->chanState)[chan].fade; diff --git a/lib/src/audio/mips1/csplayer.c b/lib/src/audio/mips1/csplayer.c new file mode 100644 index 00000000..883ef749 --- /dev/null +++ b/lib/src/audio/mips1/csplayer.c @@ -0,0 +1,949 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80062290 */ + +/*==================================================================== + * csplayer.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. + *====================================================================*/ + +/* + * Notes: + * + * Controller Numbers: + * 1 Modulation + * 7 Volume + * 10 Pan + * 11 Expression + * 64 Sustain + * 121 Reset All Controllers + * 123 All Notes Off + * + * Registered Parameters + * 0 Pitch Bend Sensitivity + * 1 Fine Tuning + * 2 Coarse Tuning + */ + + #include + #include + #include + #include + #include "seqp.h" + #include "cseqp.h" + #include "cseq.h" + #include "synthInternals.h" + + /************ .rodata ************/ + const char D_800E6C20[] = "CSP: oh oh \n"; + + // TODO: this comes from a header + #ident "$Revision: 1.17 $" + static ALMicroTime __CSPVoiceHandler(void *node); + static void __CSPHandleNextSeqEvent(ALCSPlayer *seqp); + static void __CSPHandleMIDIMsg(ALCSPlayer_Custom *seqp, ALEvent *event); + static void __CSPHandleMetaMsg(ALCSPlayer *seqp, ALEvent *event); + static void __CSPRepostEvent(ALEventQueue *evtq, ALEventListItem *item); + static void __setUsptFromTempo(ALCSPlayer *seqp, f32 tempo); /* sct 1/8/96 */ + + + /* + * Sequence Player public functions + */ + void alCSPNew(ALCSPlayer *seqp, ALSeqpConfig *c) + { + s32 i; + ALEventListItem *items; + ALVoiceState *vs; + ALVoiceState *voices; + + ALHeap *hp = c->heap; + + /* + * initialize member variables + */ + seqp->bank = 0; + seqp->target = NULL; + seqp->drvr = &alGlobals->drvr; + seqp->chanMask = 0xffff; + seqp->uspt = 488; + seqp->nextDelta = 0; + seqp->state = AL_STOPPED; + seqp->vol = 0x7FFF; /* full volume */ + seqp->frameTime = AL_USEC_PER_FRAME; /* should get this from driver */ + seqp->curTime = 0; + seqp->initOsc = c->initOsc; + seqp->updateOsc = c->updateOsc; + seqp->stopOsc = c->stopOsc; + seqp->unk71 = 0; + seqp->unk70 = c->unknown_0x10; + + seqp->nextEvent.type = AL_SEQP_API_EVT; /* this will start the voice handler "spinning" */ + + /* + * init the channel state + */ + seqp->maxChannels = c->maxChannels; + seqp->chanState = alHeapAlloc(hp, c->maxChannels, sizeof(ALChanState) + 4); + __initChanState((ALSeqPlayer*)seqp); /* sct 11/6/95 */ + + /* + * init the voice state array + */ + voices = alHeapAlloc(hp, c->maxVoices, sizeof(ALVoiceState)); + seqp->vFreeList = 0; + for (i = 0; i < c->maxVoices; i++) { + vs = &voices[i]; + vs->next = seqp->vFreeList; + seqp->vFreeList = vs; + } + + seqp->vAllocHead = 0; + seqp->vAllocTail = 0; + #if BUILD_VERSION < VERSION_J + #line 109 + #endif + // init the event queue + items = alHeapAlloc(hp, c->maxEvents, sizeof(ALEventListItem)); + alEvtqNew(&seqp->evtq, items, c->maxEvents); + + /* + * add ourselves to the driver + */ + seqp->node.next = NULL; + seqp->node.handler = __CSPVoiceHandler; + seqp->node.clientData = seqp; + alSynAddPlayer(&alGlobals->drvr, &seqp->node); + } + + /************************************************************* + * private routines or driver callback routines + *************************************************************/ + static ALMicroTime __CSPVoiceHandler(void *node) + { + ALCSPlayer_Custom *seqp = (ALCSPlayer_Custom *) node; + ALEvent evt; + ALVoice *voice; + ALMicroTime delta; + ALVoiceState *vs; + void *oscState; + f32 oscValue; + u8 chan; + + do { + switch (seqp->nextEvent.type) + { + case (AL_SEQ_REF_EVT): + __CSPHandleNextSeqEvent(seqp); + break; + + case (AL_SEQP_API_EVT): + evt.type = AL_SEQP_API_EVT; + alEvtqPostEvent(&seqp->evtq, (ALEvent *)&evt, seqp->frameTime); + break; + + case (AL_NOTE_END_EVT): + voice = seqp->nextEvent.msg.note.voice; + + alSynStopVoice(seqp->drvr, voice); + alSynFreeVoice(seqp->drvr, voice); + vs = (ALVoiceState *)voice->clientPrivate; + if(vs->flags) + __seqpStopOsc((ALSeqPlayer*)seqp,vs); + __unmapVoice((ALSeqPlayer*)seqp, voice); + break; + + case (AL_SEQP_ENV_EVT): + voice = seqp->nextEvent.msg.vol.voice; + vs = (ALVoiceState *)voice->clientPrivate; + + if(vs->envPhase == AL_PHASE_ATTACK) + vs->envPhase = AL_PHASE_DECAY; + + delta = seqp->nextEvent.msg.vol.delta; + vs->envEndTime = seqp->curTime + delta; + vs->envGain = seqp->nextEvent.msg.vol.vol; + alSynSetVol(seqp->drvr, voice, __vsVol(vs, (ALSeqPlayer*)seqp), delta); + break; + + case (AL_TREM_OSC_EVT): + vs = seqp->nextEvent.msg.osc.vs; + oscState = seqp->nextEvent.msg.osc.oscState; + delta = (*seqp->updateOsc)(oscState,&oscValue); + vs->tremelo = (u8)oscValue; + alSynSetVol(seqp->drvr, &vs->voice, __vsVol(vs,(ALSeqPlayer*)seqp), + __vsDelta(vs,seqp->curTime)); + evt.type = AL_TREM_OSC_EVT; + evt.msg.osc.vs = vs; + evt.msg.osc.oscState = oscState; + alEvtqPostEvent(&seqp->evtq, &evt, delta); + break; + + case (AL_VIB_OSC_EVT): + vs = seqp->nextEvent.msg.osc.vs; + oscState = seqp->nextEvent.msg.osc.oscState; + chan = seqp->nextEvent.msg.osc.chan; + delta = (*seqp->updateOsc)(oscState,&oscValue); + vs->vibrato = oscValue; + alSynSetPitch(seqp->drvr, &vs->voice, vs->pitch * vs->vibrato + * seqp->chanState[chan].pitchBend); + evt.type = AL_VIB_OSC_EVT; + evt.msg.osc.vs = vs; + evt.msg.osc.oscState = oscState; + evt.msg.osc.chan = chan; + alEvtqPostEvent(&seqp->evtq, &evt, delta); + break; + + case (AL_SEQP_MIDI_EVT): + case (AL_CSP_NOTEOFF_EVT): /* nextEvent is a note off midi message */ + __CSPHandleMIDIMsg(seqp, &seqp->nextEvent); + break; + + case (AL_SEQP_META_EVT): + __CSPHandleMetaMsg(seqp, &seqp->nextEvent); + break; + + case (AL_SEQP_VOL_EVT): + seqp->vol = seqp->nextEvent.msg.spvol.vol; + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + alSynSetVol(seqp->drvr, &vs->voice, + __vsVol(vs, (ALSeqPlayer*)seqp), + __vsDelta(vs, seqp->curTime)); + } + break; + + case (AL_SEQP_PLAY_EVT): + if (seqp->state != AL_PLAYING) + { + seqp->state = AL_PLAYING; + __CSPPostNextSeqEvent(seqp); /* seqp must be AL_PLAYING before we call this routine. */ + } + break; + + case (AL_SEQP_STOP_EVT): + if ( seqp->state == AL_STOPPING ) + { + seqp->chanMask = 0xFFFF; + for (chan = 0; chan < seqp->maxChannels; chan++) + { + seqp->chanState[chan].fade = 0x7F; + seqp->chanState[chan].vol = seqp->chanState[chan].unk11; + } + + for (vs = seqp->vAllocHead; vs != 0; vs = seqp->vAllocHead) + { + #ifdef _DEBUG + __osError(ERR_ALCSPVNOTFREE, 2, vs->channel, vs->key); + #endif + alSynStopVoice(seqp->drvr, &vs->voice); + alSynFreeVoice(seqp->drvr, &vs->voice); + if(vs->flags) + __seqpStopOsc((ALSeqPlayer*)seqp,vs); + __unmapVoice((ALSeqPlayer*)seqp, &vs->voice); + } + seqp->state = AL_STOPPED; + + /* alEvtqFlush(&seqp->evtq); - Don't flush event queue + anymore. */ + /* sct 1/3/96 - Don't overwrite nextEvent with + AL_SEQP_API_EVT or set nextDelta to + AL_USEC_PER_FRAME since we're not stopping event + processing. */ + /* sct 1/3/96 - Don't return here since we keep + processing events as usual. */ + } + break; + + case (AL_SEQP_STOPPING_EVT): + if (seqp->state == AL_PLAYING) + { + /* sct 12/29/95 - Remove events associated with the + * stopping sequence. For compact sequence player, + * also remove all queued note off events since they + * are not contained in a compact sequence but are + * generated in response to note ons. Note that + * flushing AL_SEQP_MIDI_EVTs may flush events that + * were posted after the call to alSeqpStop, so the + * application must queue these events either when + * the player is fully stopped, or when it is + * playing. */ + alEvtqFlushType(&seqp->evtq, AL_SEQ_REF_EVT); + alEvtqFlushType(&seqp->evtq, AL_CSP_NOTEOFF_EVT); + alEvtqFlushType(&seqp->evtq, AL_SEQP_MIDI_EVT); + + /* sct 1/3/96 - Check to see which voices need to be + killed and release them. */ + /* Unkilled voices should have note end events + occurring prior to KILL_TIME. */ + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + if (__voiceNeedsNoteKill ((ALSeqPlayer*)seqp, &vs->voice, KILL_TIME)) + __seqpReleaseVoice((ALSeqPlayer*)seqp, &vs->voice, KILL_TIME); + } + + seqp->state = AL_STOPPING; + evt.type = AL_SEQP_STOP_EVT; + alEvtqPostEvent(&seqp->evtq, &evt, AL_EVTQ_END); + } + break; + + case (AL_SEQP_PRIORITY_EVT): + chan = seqp->nextEvent.msg.sppriority.chan; + seqp->chanState[chan].priority = seqp->nextEvent.msg.sppriority.priority; + break; + + case (AL_SEQP_SEQ_EVT): + #if BUILD_VERSION < VERSION_J + #line 294 + #endif + assert(seqp->state != AL_PLAYING); /* Must be done playing to change sequences. */ + + seqp->target = seqp->nextEvent.msg.spseq.seq; + if (seqp->bank) + __initFromBank((ALSeqPlayer *)seqp, seqp->bank); + break; + + case (AL_SEQP_BANK_EVT): + #if BUILD_VERSION < VERSION_J + #line 303 + #endif + assert(seqp->state == AL_STOPPED); /* Must be fully stopped to change banks. */ + + seqp->bank = seqp->nextEvent.msg.spbank.bank; + __initFromBank((ALSeqPlayer *)seqp, seqp->bank); + break; + + /* sct 11/6/95 - these events should now be handled by __CSPHandleNextSeqEvent */ + case (AL_SEQ_END_EVT): + case (AL_TEMPO_EVT): + case (AL_SEQ_MIDI_EVT): + #if BUILD_VERSION < VERSION_J + #line 313 + #endif + assert(FALSE); + + break; + } + seqp->nextDelta = alEvtqNextEvent(&seqp->evtq, &seqp->nextEvent); + + } while (seqp->nextDelta == 0); + + /* + * assume that next callback won't be more than half an + * hour away + */ + seqp->curTime += seqp->nextDelta; /* sct 11/7/95 */ + return seqp->nextDelta; + } + + /* + Calculates the delta time in ticks until the next sequence + event and posts a sequence reference event with the time in usecs. + Loops are handled automatically by the compact sequence. + + Does nothing if the sequence player is not playing or if there + is no target sequence. + + sct 11/7/95 + */ + void __CSPPostNextSeqEvent(ALCSPlayer *seqp) + { + ALEvent evt; + s32 deltaTicks; + + if (seqp->state != AL_PLAYING || seqp->target == NULL) + return; + + /* Get the next event time in ticks. */ + /* If false is returned, then there is no next delta (ie. end of sequence reached). */ + if (!__alCSeqNextDelta(seqp->target, &deltaTicks)) + return; + + evt.type = AL_SEQ_REF_EVT; + alEvtqPostEvent(&seqp->evtq, &evt, deltaTicks * seqp->uspt); + } + + + /* + Call this routine to handle the next event in the sequence. + Assumes that the next sequence event is scheduled to be processed + immediately since it does not check the event's tick time. + + sct 11/7/95 + */ + static void + __CSPHandleNextSeqEvent(ALCSPlayer *seqp) + { + ALEvent evt; + + /* sct 1/5/96 - Do nothing if we don't have a target sequence. */ + if (seqp->target == NULL) + return; + + alCSeqNextEvent(seqp->target, &evt); + + switch (evt.type) + { + case AL_SEQ_MIDI_EVT: + __CSPHandleMIDIMsg(seqp, &evt); + __CSPPostNextSeqEvent(seqp); + break; + + case AL_TEMPO_EVT: + __CSPHandleMetaMsg(seqp, &evt); + __CSPPostNextSeqEvent(seqp); + break; + + case AL_SEQ_END_EVT: + seqp->state = AL_STOPPING; + evt.type = AL_SEQP_STOP_EVT; + alEvtqPostEvent(&seqp->evtq, &evt, AL_EVTQ_END); + break; + + case AL_TRACK_END: + case AL_CSP_LOOPSTART: + case AL_CSP_LOOPEND: + __CSPPostNextSeqEvent(seqp); + break; + + default: + #if BUILD_VERSION < VERSION_J + #line 399 + #endif + assert(FALSE); /* Sequence event type not supported. */ + #if BUILD_VERSION >= VERSION_J + break; + #endif + } + } + + //Significantly different from the standard version + void __CSPHandleMIDIMsg(ALCSPlayer_Custom *seqp, ALEvent *event) + { + ALVoiceState *vs; + s32 i; + s32 status; + u8 chan; + u8 byte1; + u8 byte2; + u8 fxmix; + ALVoice *voice; + ALMIDIEvent *midi = &event->msg.midi; + s16 vol; + u8 new_var2; + ALEvent evt; + ALVoiceState *vstate; + ALFxRef fxref; + ALPan pan; + ALMicroTime deltaTime; + + ALVoiceConfig config; + ALSound *sound; + u8 new_var; + f32 pitch; + f32 oscValue; + s32 pad; + void *oscState; + ALInstrument *inst; + + s32 bendVal; + ALChanState_Custom *chanState; + s32 pad2; + f32 bendRatio; + + status = midi->status & AL_MIDI_StatusMask; + chan = midi->status & AL_MIDI_ChannelMask; + new_var = byte1 = midi->byte1; + new_var2 = byte2 = midi->byte2; + chanState = &seqp->chanState[chan]; + + if (status == AL_MIDI_ChannelModeSelect) + { + if (new_var == 0x6A) + { + seqp->chanMask &= ~(1 << byte2); + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + if (vs->channel == byte2) + __seqpReleaseVoice((ALSeqPlayer *) seqp, &vs->voice, vs->sound->envelope->releaseTime); + } + return; + } + else if (new_var == 0x6C) + { + seqp->chanMask |= 1 << byte2; + return; + } + + } + if ((seqp->chanMask & (((0, 1)) << chan)) != 0) { + } + else if ( + status != AL_MIDI_ProgramChange && + status != AL_MIDI_ControlChange && + status != AL_MIDI_PitchBendChange + ) { + return; + } + + switch (status) + { + case (AL_MIDI_NoteOn): + if (byte2 != 0) /* a real note on */ + { + + /* If we're not playing, don't process note ons. */ + if (seqp->state != AL_PLAYING) + break; + + sound = __lookupSoundQuick((ALSeqPlayer*)seqp, byte1, byte2, chan); + ALFlagFailIf(!sound, seqp->debugFlags & NO_SOUND_ERR_MASK, + ERR_ALSEQP_NO_SOUND); + + config.priority = seqp->chanState[chan].priority; + config.fxBus = 0; + config.unityPitch = 0; + + vstate = __mapVoice((ALSeqPlayer*)seqp, byte1, byte2, chan); + ALFlagFailIf(!vstate, seqp->debugFlags & NO_VOICE_ERR_MASK, + ERR_ALSEQP_NO_VOICE ); + + voice = &vstate->voice; + + if (alSynAllocVoice(seqp->drvr, voice, &config)) + func_80065A80(seqp->drvr, voice->pvoice, 0); + + /* + * set up the voice state structure + */ + vstate->sound = sound; + vstate->envPhase = AL_PHASE_ATTACK; + if (seqp->chanState[chan].sustain > AL_SUSTAIN) + vstate->phase = AL_PHASE_SUSTAIN; + else + vstate->phase = AL_PHASE_NOTEON; + + vstate->pitch = alCents2Ratio((s16)((byte1 - sound->keyMap->keyBase) * 100 + sound->keyMap->detune)); + vstate->envGain = sound->envelope->attackVolume; + vstate->envEndTime = seqp->curTime + + sound->envelope->attackTime; + + /* + * setup tremelo and vibrato if active + */ + vstate->flags = 0; + inst = seqp->chanState[chan].instrument; + + oscValue = (f32)AL_VOL_FULL; /* set this as a default */ + if(inst->tremType) + { + if(seqp->initOsc) + { + deltaTime = (*seqp->initOsc)(&oscState,&oscValue,inst->tremType, + inst->tremRate,inst->tremDepth,inst->tremDelay); + + if(deltaTime) /* a deltaTime of zero means don't run osc */ + { + evt.type = AL_TREM_OSC_EVT; + evt.msg.osc.vs = vstate; + evt.msg.osc.oscState = oscState; + alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); + vstate->flags |= 0x01; /* set tremelo flag bit */ + } + } + } + vstate->tremelo = (u8)oscValue; /* will default if not changed by initOsc */ + + oscValue = 1.0f; /* set this as a default */ + if(inst->vibType) + { + if(seqp->initOsc) + { + deltaTime = (*seqp->initOsc)(&oscState,&oscValue,inst->vibType, + inst->vibRate,inst->vibDepth,inst->vibDelay); + + if(deltaTime) /* a deltaTime of zero means don't run osc. */ + { + evt.type = AL_VIB_OSC_EVT; + evt.msg.osc.vs = vstate; + evt.msg.osc.oscState = oscState; + evt.msg.osc.chan = chan; + alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); + vstate->flags |= 0x02; /* set the vibrato flag bit */ + } + } + } + vstate->vibrato = oscValue; /* will default if not changed by initOsc */ + + /* + * calculate the note on parameters + */ + pitch = vstate->pitch * seqp->chanState[chan].pitchBend * + vstate->vibrato; + fxmix = seqp->chanState[chan].fxmix; + pan = __vsPan(vstate, (ALSeqPlayer*)seqp); + vol = __vsVol(vstate, (ALSeqPlayer*)seqp); + deltaTime = sound->envelope->attackTime; + + alSynStartVoiceParams(seqp->drvr, voice, sound->wavetable, + pitch, vol, pan, fxmix, deltaTime); + /* + * set up callbacks for envelope + */ + evt.type = AL_SEQP_ENV_EVT; + evt.msg.vol.voice = voice; + evt.msg.vol.vol = sound->envelope->decayVolume; + evt.msg.vol.delta = sound->envelope->decayTime; + + alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); + + if(midi->duration) + { + /* + * set up note off evt. if no duration don't do this + */ + evt.type = AL_CSP_NOTEOFF_EVT; + evt.msg.midi.status = chan | AL_MIDI_NoteOff; + evt.msg.midi.byte1 = byte1; + evt.msg.midi.byte2 = 0; /* not needed ? */ + deltaTime = seqp->uspt * midi->duration; + + /* max time would be about one hour ten minutes */ + alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); + } + + break; + } + + /* + * NOTE: intentional fall-through for note on with zero + * velocity (Should never happen with compact midi sequence, + * but could happen with real time midi.) + */ + + case (AL_MIDI_NoteOff): + vstate = __lookupVoice((ALSeqPlayer*)seqp, byte1, chan); + ALFlagFailIf(!vstate, seqp->debugFlags & NOTE_OFF_ERR_MASK, + ERR_ALSEQP_OFF_VOICE ); + + if (vstate->phase == AL_PHASE_SUSTAIN) + vstate->phase = AL_PHASE_SUSTREL; + else + { + vstate->phase = AL_PHASE_RELEASE; + __seqpReleaseVoice((ALSeqPlayer*)seqp, &vstate->voice, + vstate->sound->envelope->releaseTime); + } + + break; + + case (AL_MIDI_PolyKeyPressure): + /* + * Aftertouch per byte1 (hardwired to volume). Note that + * aftertouch affects only notes that are already + * sounding. + */ + vstate = __lookupVoice((ALSeqPlayer*)seqp, byte1, chan); + ALFailIf(!vstate, ERR_ALSEQP_POLY_VOICE ); + + vstate->velocity = byte2; + alSynSetVol(seqp->drvr, &vstate->voice, + __vsVol(vstate, (ALSeqPlayer*)seqp), + __vsDelta(vstate,seqp->curTime)); + break; + + case (AL_MIDI_ChannelPressure): + /* + * Aftertouch per channel (hardwired to volume). Note that + * aftertouch affects only notes that are already + * sounding. + */ + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { + if (vs->channel == chan) { + vs->velocity = byte1; + alSynSetVol(seqp->drvr, &vs->voice, + __vsVol(vs, (ALSeqPlayer*)seqp), + __vsDelta(vs,seqp->curTime)); + } + } + break; + + case (AL_MIDI_ControlChange): + switch (byte1) + { + case (AL_MIDI_PAN_CTRL): + seqp->chanState[chan].pan = byte2; + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + if (vs->channel == chan) + { + pan = __vsPan(vs, (ALSeqPlayer*)seqp); + alSynSetPan(seqp->drvr, &vs->voice, pan); + } + } + break; + case (AL_MIDI_VOLUME_CTRL): + { + seqp->chanState[chan].unk11 = byte2; + seqp->chanState[chan].vol = ((f32)seqp->chanState[chan].fade * byte2) / 127.0f; + + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + if ((vs->channel == chan) && (vs->envPhase != AL_PHASE_RELEASE)) + { + vol = __vsVol(vs, (ALSeqPlayer*)seqp); + alSynSetVol(seqp->drvr, &vs->voice, vol, + __vsDelta(vs,seqp->curTime)); + } + } + } + break; + case (8): + seqp->chanState[chan].fade = byte2; + seqp->chanState[chan].vol = (seqp->chanState[chan].unk11 * seqp->chanState[chan].fade) / 127.0f; + + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + if ((vs->channel == chan) && (vs->envPhase != AL_PHASE_RELEASE)) + { + vol = __vsVol(vs, (ALSeqPlayer*)seqp); + alSynSetVol(seqp->drvr, &vs->voice, vol, + __vsDelta(vs,seqp->curTime)); + } + } + break; + case (AL_MIDI_PRIORITY_CTRL): + /* leave current voices where they are */ + seqp->chanState[chan].priority = byte2; + break; + case (AL_MIDI_SUSTAIN_CTRL): + seqp->chanState[chan].sustain = byte2; + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + if ((vs->channel == chan) && (vs->phase != AL_PHASE_RELEASE)) + { + if ( byte2 > AL_SUSTAIN ) + { + /* + * sustain pedal down + */ + if (vs->phase == AL_PHASE_NOTEON) + vs->phase = AL_PHASE_SUSTAIN; + } + else + { + /* + * sustain pedal up + */ + if (vs->phase == AL_PHASE_SUSTAIN) + vs->phase = AL_PHASE_NOTEON; + + else if(vs->phase == AL_PHASE_SUSTREL) + { + vs->phase = AL_PHASE_RELEASE; + __seqpReleaseVoice((ALSeqPlayer*)seqp, + &vs->voice, + vs->sound->envelope->releaseTime); + } + } + } + } + break; + case (AL_MIDI_FX1_CTRL): + seqp->chanState[chan].fxmix = byte2; + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + if (vs->channel == chan) + alSynSetFXMix(seqp->drvr, &vs->voice, byte2); + } + break; + case (0x5F): + seqp->unk36 = byte2; + for (i = 0; i < seqp->maxChannels; i++) + { + if (seqp->chanState[i].fxmix < byte2) + { + seqp->chanState[i].fxmix = 0; + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + { + if (vs->channel == i) + alSynSetFXMix(seqp->drvr, &vs->voice, byte2); + } + } + } + break; + default: + break; + } + break; + case (AL_MIDI_ProgramChange): + /* sct 1/16/96 - We must have a valid bank in order to process the program change. */ + #if BUILD_VERSION < VERSION_J + #line 710 + #endif + assert(seqp->bank != NULL); + + if (byte1 < seqp->bank->instCount) + { + ALInstrument *inst = seqp->bank->instArray[byte1]; + __setInstChanState((ALSeqPlayer*)seqp, inst, chan); /* sct 11/6/95 */ + } + else + { + #ifdef _DEBUG + __osError(ERR_ALSEQPINVALIDPROG, 2, byte1, seqp->bank->instCount); + #endif + } + break; + case (AL_MIDI_PitchBendChange): + { + + /* get 14-bit unsigned midi value */ + bendVal = ( (byte2 << 7) + byte1) - 8192; + + /* calculate pitch bend in cents */ + + /* calculate the corresponding ratio */ + bendRatio = alCents2Ratio((seqp->chanState[chan].bendRange * bendVal)/8192); + seqp->chanState[chan].pitchBend = bendRatio; + + for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) + if (vs->channel == chan) + alSynSetPitch(seqp->drvr, &vs->voice, + vs->pitch * bendRatio * vs->vibrato); + + } + break; + + default: + #ifdef _DEBUG + __osError(ERR_ALSEQPUNKNOWNMIDI, 1, status); + #endif + break; + } + } + + static void __CSPHandleMetaMsg(ALCSPlayer *seqp, ALEvent *event) + { + ALTempoEvent *tevt = &event->msg.tempo; + ALEvent evt; + s32 tempo; + s32 oldUspt; + u32 ticks; + ALMicroTime tempDelta,curDelta = 0; + ALEventListItem *thisNode,*nextNode,*firstTemp = 0; + + + if (event->msg.tempo.status == AL_MIDI_Meta) + { + if (event->msg.tempo.type == AL_MIDI_META_TEMPO) + { + oldUspt = seqp->uspt; + tempo = (tevt->byte1 << 16) | (tevt->byte2 << 8) | (tevt->byte3 << 0); + __setUsptFromTempo (seqp, (f32)tempo); /* sct 1/8/96 */ + + thisNode = (ALEventListItem*)seqp->evtq.allocList.next; + while(thisNode) + { + curDelta += thisNode->delta; + nextNode = (ALEventListItem*)thisNode->node.next; + if(thisNode->evt.type == AL_CSP_NOTEOFF_EVT) + { + alUnlink((ALLink*)thisNode); + + if(firstTemp) + alLink((ALLink*)thisNode,(ALLink*)firstTemp); + else + { + thisNode->node.next = 0; + thisNode->node.prev = 0; + firstTemp = thisNode; + } + tempDelta = curDelta; /* record the current delta */ + if(nextNode) /* don't do this if no nextNode */ + { + curDelta -= thisNode->delta; /* subtract out this delta */ + nextNode->delta += thisNode->delta; /* add it to next event */ + } + thisNode->delta = tempDelta; /* set this event delta from current */ + } + thisNode = nextNode; + } + + thisNode = firstTemp; + while(thisNode) + { + nextNode = (ALEventListItem*)thisNode->node.next; + ticks = thisNode->delta/oldUspt; + thisNode->delta = ticks * seqp->uspt; + __CSPRepostEvent(&seqp->evtq,thisNode); + thisNode = nextNode; + } + } + } + } + + static void __CSPRepostEvent(ALEventQueue *evtq, ALEventListItem *item) + { + OSIntMask mask; + ALLink *node; + ALEventListItem *nextItem; + + mask = osSetIntMask(OS_IM_NONE); + + for (node = &evtq->allocList; node != 0; node = node->next) + { + if (!node->next) /* end of the list */ + { + alLink((ALLink *)item, node); + break; + } + else + { + nextItem = (ALEventListItem *)node->next; + if (item->delta < nextItem->delta) + { + nextItem->delta -= item->delta; + alLink((ALLink *)item, node); + break; + } + item->delta -= nextItem->delta; + } + } + osSetIntMask(mask); + } + + + /* + This routine safely calculates the sequence player's + uspt value based on the given tempo. It does this safely + by making sure that the player has a target sequence and + therefore a qnpt value which is needed for the calculation. + + Compact sequence player needs its own version of this routine + since the ALCSeq's qnpt field is at a different offset. + */ + static void __setUsptFromTempo (ALCSPlayer *seqp, f32 tempo) + { + if (seqp->target) + seqp->uspt = (s32)((f32)tempo * seqp->target->qnpt); + else + seqp->uspt = 488; /* This is the initial value set by alSeqpNew. */ + } + + \ No newline at end of file diff --git a/lib/src/mips1/al/alCSPSetFadeIn.c b/lib/src/audio/mips1/cspsetfadein.c similarity index 86% rename from lib/src/mips1/al/alCSPSetFadeIn.c rename to lib/src/audio/mips1/cspsetfadein.c index 7346168e..4fffe170 100644 --- a/lib/src/mips1/al/alCSPSetFadeIn.c +++ b/lib/src/audio/mips1/cspsetfadein.c @@ -1,9 +1,7 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x80063BA0 */ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include void alCSPSetFadeIn(ALSeqPlayer *seqp, u8 chan, ALPan pan) { ALEvent evt; diff --git a/lib/src/mips1/al/alFxNew.c b/lib/src/audio/mips1/drvrnew.c similarity index 74% rename from lib/src/mips1/al/alFxNew.c rename to lib/src/audio/mips1/drvrnew.c index 8bb253af..70c206a8 100644 --- a/lib/src/mips1/al/alFxNew.c +++ b/lib/src/audio/mips1/drvrnew.c @@ -19,14 +19,15 @@ * DOD or NASA FAR Supplement. Unpublished - rights reserved under the * Copyright Laws of the United States. *====================================================================*/ - -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" -#include "audio_internal.h" -#include "audio.h" +#include +#include "synthInternals.h" +#include +#include +#include "initfx.h" #include "src/memory.h" +// TODO: this comes from a header +#ident "$Revision: 1.49 $" /* * WARNING: THE FOLLOWING CONSTANT MUST BE KEPT IN SYNC * WITH SCALING IN MICROCODE!!! @@ -38,7 +39,7 @@ * a few hopefully useful effects. */ #define ms *(((s32)((f32)44.1))&~0x7) - + static s32 SMALLROOM_PARAMS[26] = { /* sections length */ @@ -91,7 +92,8 @@ static s32 NULL_PARAMS[10] = { }; -void init_lpfilter(ALLowPass *lp) { +void _init_lpfilter(ALLowPass *lp) +{ s32 i, temp; s16 fc; f64 ffc, fcoef; @@ -113,86 +115,98 @@ void init_lpfilter(ALLowPass *lp) { } } -//This function differs from libreultra's, but still mostly the same -void alFxNew(ALFx *r, ALSynConfig *c, s16 bus, UNUSED ALHeap *hp) { +void alFxNew(ALFx *r, ALSynConfig *c, s16 bus, UNUSED 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[bus]) { 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_FLANGE: param = FLANGE_PARAMS; break; case AL_FX_CUSTOM: param = (&c->params)[bus]; break; default: param = NULL_PARAMS; break; } + + j = 0; + r->section_count = param[j++]; r->length = param[j++]; + r->delay = mempool_alloc_safe(sizeof(ALDelay) * r->section_count, COLOUR_TAG_CYAN); r->base = mempool_alloc_safe(sizeof(s16) * r->length, COLOUR_TAG_CYAN); 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 = mempool_alloc_safe(sizeof(ALResampler), COLOUR_TAG_CYAN); - d->rs->state = mempool_alloc_safe(sizeof(RESAMPLE_STATE), COLOUR_TAG_CYAN); - d->rs->delta = 0.0; - d->rs->first = 1; - } else { - d->rs = 0; - j++; - j++; - } - if (param[j]) { - d->lp = mempool_alloc_safe(sizeof(ALLowPass), COLOUR_TAG_CYAN); - d->lp->fstate = mempool_alloc_safe(sizeof(POLEF_STATE), COLOUR_TAG_CYAN); - d->lp->fc = param[j++]; - init_lpfilter(d->lp); - } else { - d->lp = 0; - j++; - } + + 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 = mempool_alloc_safe(sizeof(ALResampler), COLOUR_TAG_CYAN); + d->rs->state = mempool_alloc_safe(sizeof(RESAMPLE_STATE), COLOUR_TAG_CYAN); + d->rs->delta = 0.0; + d->rs->first = 1; + } else { + d->rs = 0; + j++; + j++; + } + + if (param[j]) { + d->lp = mempool_alloc_safe(sizeof(ALLowPass), COLOUR_TAG_CYAN); + d->lp->fstate = mempool_alloc_safe(sizeof(POLEF_STATE), COLOUR_TAG_CYAN); + d->lp->fc = param[j++]; + _init_lpfilter(d->lp); + } else { + d->lp = 0; + j++; + } } } -void alEnvmixerNew(ALEnvMixer *e, ALHeap *hp) { +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; @@ -214,9 +228,11 @@ void alEnvmixerNew(ALEnvMixer *e, ALHeap *hp) { e->sources = 0; } -void alLoadNew(ALLoadFilter *f, ALDMANew dmaNew, ALHeap *hp) { - UNUSED s32 i; - +void alLoadNew(ALLoadFilter *f, ALDMANew dmaNew, ALHeap *hp) +{ + s32 + i; + /* * init filter superclass */ @@ -225,9 +241,9 @@ void alLoadNew(ALLoadFilter *f, ALDMANew dmaNew, ALHeap *hp) { 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 */ @@ -236,7 +252,8 @@ void alLoadNew(ALLoadFilter *f, ALDMANew dmaNew, ALHeap *hp) { f->memin = 0; } -void alResampleNew(ALResampler *r, ALHeap *hp) { +void alResampleNew(ALResampler *r, ALHeap *hp) +{ alFilterNew((ALFilter *) r, alResamplePull, alResampleParam, AL_RESAMPLE); /* @@ -250,36 +267,40 @@ void alResampleNew(ALResampler *r, ALHeap *hp) { 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) { +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) { +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) { +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/lib/src/mips1/al/reverb.c b/lib/src/audio/mips1/reverb.c similarity index 90% rename from lib/src/mips1/al/reverb.c rename to lib/src/audio/mips1/reverb.c index b472ab35..6e423197 100644 --- a/lib/src/mips1/al/reverb.c +++ b/lib/src/audio/mips1/reverb.c @@ -1,16 +1,34 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x80063C30 */ - -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" -#include "audio_internal.h" +/*==================================================================== + * 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 #include "initfx.h" - // TODO: these come from headers #ident "$Revision: 1.49 $" #ident "$Revision: 1.17 $" - #define RANGE 2.0 extern ALGlobals *alGlobals; @@ -30,15 +48,14 @@ extern u32 load_num, load_cnt, load_max, load_min, save_num, save_cnt, save_max, } - 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); -void init_lpfilter(ALLowPass *lp); u8 alFXEnabled = TRUE; + static s32 L_INC[] = { L0_INC, L1_INC, L2_INC }; /*********************************************************************** @@ -57,17 +74,16 @@ Acmd *alFxPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, #ifdef AUD_PROFILE lastCnt[++cnt_index] = osGetCount(); #endif - -#ifdef _DEBUG - assert(source); +#if BUILD_VERSION < VERSION_J +#line 74 #endif + assert(source); /* * pull channels going into this effect first */ ptr = (*source->handler)(source, outp, outCount, sampleOffset, p); - //Added by Rare Devs if (alFXEnabled == FALSE) { return ptr; } @@ -141,9 +157,12 @@ Acmd *alFxPull(void *filter, s16 *outp, s32 outCount, s32 sampleOffset, return ptr; } -s32 alFxParam(void *filter, s32 paramID, void *param) { - if (paramID == 1) { - ((ALFilter *)filter)->source = param; +s32 alFxParam(void *filter, s32 paramID, void *param) +{ + if(paramID == AL_FILTER_SET_SOURCE) + { + ALFilter *f = (ALFilter *) filter; + f->source = (ALFilter*) param; } return 0; } @@ -214,7 +233,7 @@ s32 alFxParamHdl(void *filter, s32 paramID, void *param) if(f->delay[s].lp) { f->delay[s].lp->fc = (s16)val; - init_lpfilter(f->delay[s].lp); + _init_lpfilter(f->delay[s].lp); } break; } @@ -228,6 +247,7 @@ Acmd *_loadOutputBuffer(ALFx *r, ALDelay *d, s32 buff, s32 incount, Acmd *p) s16 *out_ptr; f32 fincount, fratio, delta; s32 ramalign = 0, length; + /* * The following section implements the chorus resampling. Modulate where you pull * the samples from, since you need varying amounts of samples. @@ -294,7 +314,6 @@ Acmd *_loadOutputBuffer(ALFx *r, ALDelay *d, s32 buff, s32 incount, Acmd *p) 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 @@ -399,6 +418,8 @@ Acmd *_filterBuffer(ALLowPass *lp, s32 buff, s32 count, Acmd *p) 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 diff --git a/lib/src/mips1/al/seqchannel.c b/lib/src/audio/mips1/seqchannel.c similarity index 82% rename from lib/src/mips1/al/seqchannel.c rename to lib/src/audio/mips1/seqchannel.c index b052a260..b8884051 100644 --- a/lib/src/mips1/al/seqchannel.c +++ b/lib/src/audio/mips1/seqchannel.c @@ -1,9 +1,7 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x80063AF0 */ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include void alSeqChOff(ALSeqPlayer *seqp, u8 chan) { ALEvent evt; @@ -11,7 +9,7 @@ void alSeqChOff(ALSeqPlayer *seqp, u8 chan) { evt.type = AL_SEQP_MIDI_EVT; evt.msg.midi.ticks = 0; evt.msg.midi.status = AL_MIDI_ControlChange; - evt.msg.midi.byte1 = 0x6A; + evt.msg.midi.byte1 = AL_MIDI_UNK_6A; evt.msg.midi.byte2 = chan; alEvtqPostEvent(&seqp->evtq, &evt, 0); } @@ -22,7 +20,7 @@ void alSeqChOn(ALSeqPlayer *seqp, u8 chan) { evt.type = AL_SEQP_MIDI_EVT; evt.msg.midi.ticks = 0; evt.msg.midi.status = AL_MIDI_ControlChange; - evt.msg.midi.byte1 = 0x6C; + evt.msg.midi.byte1 = AL_MIDI_UNK_6C; evt.msg.midi.byte2 = chan; alEvtqPostEvent(&seqp->evtq, &evt, 0); } diff --git a/lib/src/mips1/al/seqplayer.c b/lib/src/audio/mips1/seqplayer.c similarity index 50% rename from lib/src/mips1/al/seqplayer.c rename to lib/src/audio/mips1/seqplayer.c index 6c153757..13aa6026 100644 --- a/lib/src/mips1/al/seqplayer.c +++ b/lib/src/audio/mips1/seqplayer.c @@ -1,20 +1,68 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x8000A710 */ +/*==================================================================== + * seqplayer.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. + *====================================================================*/ +/* + * Notes: + * + * Controller Numbers: + * 1 Modulation + * 7 Volume + * 10 Pan + * 11 Expression + * 64 Sustain + * 121 Reset All Controllers + * 123 All Notes Off + * + * Registered Parameters + * 0 Pitch Bend Sensitivity + * 1 Fine Tuning + * 2 Coarse Tuning + */ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include +#include +#include +#include +#include "seqp.h" +#include "seq.h" -void __setInstChanState(ALSeqPlayer *seqp, ALInstrument *inst, s32 chan); -void __resetPerfChanState(ALSeqPlayer *seqp, s32 chan) ; +#if defined(__sgi) +#define stubbed_printf +#else +#define stubbed_printf(...) +#endif -UNUSED void dummy_8000A710(UNUSED s32 arg0, UNUSED s32 arg1) { -} +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + + +static ALMicroTime __seqpVoiceHandler(void *node); +static void __handleMIDIMsg(ALSeqPlayer *seqp, ALEvent *event); +static void __handleMetaMsg(ALSeqPlayer *seqp, ALEvent *event); +static void __handleNextSeqEvent(ALSeqPlayer *seqp); + +void alSeqpNew(ALSeqPlayer *seqp, ALSeqpConfig *c) { } ALVoiceState *__mapVoice(ALSeqPlayer *seqp, u8 key, u8 vel, u8 channel) { ALVoiceState *vs = seqp->vFreeList; - + if(seqp->voiceLimit < seqp->mappedVoices) { stubbed_printf("Exceeded voice limit of %d (%d)\n", seqp->voiceLimit, seqp->mappedVoices); return NULL; @@ -47,9 +95,15 @@ void __unmapVoice(ALSeqPlayer *seqp, ALVoice *voice) { ALVoiceState *prev = 0; ALVoiceState *vs; - + + /* + * we could use doubly linked lists here and save some code and + * execution time, but time spent here in negligible, so it won't + * make much difference. + */ for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) { if (&vs->voice == voice) { + if (prev) prev->next = vs->next; else @@ -67,6 +121,9 @@ void __unmapVoice(ALSeqPlayer *seqp, ALVoice *voice) } prev = vs; } +#ifdef _DEBUG + __osError(ERR_ALSEQPUNMAP, 1, voice); +#endif } ALVoiceState *__lookupVoice(ALSeqPlayer *seqp, u8 key, u8 channel) @@ -82,13 +139,20 @@ ALVoiceState *__lookupVoice(ALSeqPlayer *seqp, u8 key, u8 channel) return 0; } +#define _AlChanState ALChanState_Custom + ALSound *__lookupSoundQuick(ALSeqPlayer *seqp, u8 key, u8 vel, u8 chan) { - ALInstrument *inst = ((ALChanState_Custom*)seqp->chanState)[chan].instrument; + ALInstrument *inst = ((_AlChanState*)seqp->chanState)[chan].instrument; s32 l = 1; s32 r = inst->soundCount; s32 i; ALKeyMap *keymap; +#if BUILD_VERSION < VERSION_J +#line 885 +#endif + assert(inst != NULL); /* sct 10/31/95 - If inst is NULL, then the seqp probably wasn't setup correctly. */ + while (r >= l) { i = (l+r)/2; @@ -109,21 +173,35 @@ ALSound *__lookupSoundQuick(ALSeqPlayer *seqp, u8 key, u8 vel, u8 chan) return 0; } + +/* + * __vsVol calculates the target volume for the voice based on the + * note on velocity, envelope, sampleVolume and controller. + */ s16 __vsVol(ALVoiceState *vs, ALSeqPlayer *seqp) { - u32 t1, t2; + + u32 t1,t2; t1 = (vs->tremelo*vs->velocity*vs->envGain) >> 6; - t2 = (vs->sound->sampleVolume*seqp->vol * ((ALChanState_Custom*)seqp->chanState)[vs->channel].vol) >> 14; - + t2 = (vs->sound->sampleVolume*seqp->vol* + ((_AlChanState*)seqp->chanState)[vs->channel].vol) >> 14; t1 *= t2; t1 >>= 15; - return((s16)t1); + return( (s16)t1 ); + } ALMicroTime __vsDelta(ALVoiceState *vs, ALMicroTime t) { + /* + * If we are interrupting a previously set envelope segment, we + * need to recalculate the segment end time given the current + * time. Note: this routine assumes that the voice is currently + * playing. + */ + s32 delta = vs->envEndTime - t; if (delta >= 0) { @@ -133,22 +211,40 @@ ALMicroTime __vsDelta(ALVoiceState *vs, ALMicroTime t) } } + ALPan __vsPan(ALVoiceState *vs, ALSeqPlayer *seqp) { s32 tmp; - tmp = ((ALChanState_Custom*)seqp->chanState)[vs->channel].pan - AL_PAN_CENTER + vs->sound->samplePan; + tmp = ((_AlChanState*)seqp->chanState)[vs->channel].pan - AL_PAN_CENTER + + vs->sound->samplePan; tmp = MAX(tmp, AL_PAN_LEFT); tmp = MIN(tmp, AL_PAN_RIGHT); return (ALPan) tmp; } -void __seqpReleaseVoice(ALSeqPlayer *seqp, ALVoice *voice, ALMicroTime deltaTime) +#ifdef IMPLEMENTED + +s32 seqpGetVoices(SEQP *seqp); +s32 seqpSetVoices(SEQP *seqp, s32 numvoices); + +u16 seqpGetChannelMask(SEQP *seqp); +s32 seqpSetChannelMask(SEQP *seqp, u16 bitmask); + +#endif + +void __seqpReleaseVoice(ALSeqPlayer *seqp, ALVoice *voice, + ALMicroTime deltaTime) { ALEvent evt; ALVoiceState *vs = (ALVoiceState *)voice->clientPrivate; + /* + * if in attack phase, remove all pending volume + * events for this voice from the queue + */ + if (vs->envPhase == AL_PHASE_ATTACK) { ALLink *thisNode; ALLink *nextNode; @@ -176,7 +272,7 @@ void __seqpReleaseVoice(ALSeqPlayer *seqp, ALVoice *voice, ALMicroTime deltaTime vs->envGain = 0; vs->envEndTime = seqp->curTime + deltaTime; - alSynSetPriority(seqp->drvr, voice, 0); + alSynSetPriority(seqp->drvr, voice, 0); /* make candidate for stealing */ alSynSetVol(seqp->drvr, voice, 0, deltaTime); evt.type = AL_NOTE_END_EVT; evt.msg.note.voice = voice; @@ -184,13 +280,35 @@ void __seqpReleaseVoice(ALSeqPlayer *seqp, ALVoice *voice, ALMicroTime deltaTime alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); } -u8 __voiceNeedsNoteKill (ALSeqPlayer *seqp, ALVoice *voice, ALMicroTime killTime) + + +/* + This special purpose routine is called only when processing + a stopping event in order to properly kill all active voices. + + The routine searches through the seqp's event queue for an + AL_NOTE_END_EVT for the given voice. If the event's execution + time is greater than kill time, it removes the event from the + event queue and returns true that it needs to kill the voice. + Otherwise, if the event's time is less than the kill time, it + returns false that the voice needs to be killed. + + sct 1/3/96 +*/ + +#define VOICENEEDSNOTEKILL_DEBUG _DEBUG_INTERNAL&&0 /* For debugging voiceNeedsNoteKill routine. */ + +char __voiceNeedsNoteKill (ALSeqPlayer *seqp, ALVoice *voice, ALMicroTime killTime) { ALLink *thisNode; ALLink *nextNode; ALEventListItem *thisItem; ALMicroTime itemTime = 0; - u8 needsNoteKill = TRUE; + char needsNoteKill = TRUE; + +#if VOICENEEDSNOTEKILL_DEBUG + alEvtqPrintAllocEvts (&seqp->evtq); +#endif thisNode = seqp->evtq.allocList.next; while (thisNode != 0) @@ -218,17 +336,36 @@ u8 __voiceNeedsNoteKill (ALSeqPlayer *seqp, ALVoice *voice, ALMicroTime killTime thisNode = nextNode; } +#if VOICENEEDSNOTEKILL_DEBUG + if (thisNode) + osSyncPrintf("vox 0x%0x: end time %d kill time %d\n\n", voice, itemTime, killTime); + else + osSyncPrintf("vox 0x%0x: not found\n\n", voice); + + alEvtqPrintAllocEvts (&seqp->evtq); +#endif + return needsNoteKill; } + + + void __initFromBank(ALSeqPlayer *seqp, ALBank *b) { + /* + * init the chanState with the default instrument + */ s32 i; ALInstrument *inst = 0; + /* set to the first available instrument. */ for(i = 0; !inst ; i++) inst = b->instArray[i]; + /* sct 11/6/95 - Setup the channel state for the given instrument. */ + /* There is some wasted effort here since both calls the same state vars */ + /* but it's safer. */ for (i = 0; i < seqp->maxChannels; i++) { __resetPerfChanState(seqp, i); __setInstChanState(seqp, inst, i); @@ -240,39 +377,54 @@ void __initFromBank(ALSeqPlayer *seqp, ALBank *b) } } +/* + sct 11/6/95 - Call this whenever a new instrument gets assigned to a channel + such as when changing banks or in response to a MIDI program change event. + Currently also gets called when changing sequences. +*/ void __setInstChanState(ALSeqPlayer *seqp, ALInstrument *inst, s32 chan) { - ((ALChanState_Custom*)seqp->chanState)[chan].instrument = inst; - ((ALChanState_Custom*)seqp->chanState)[chan].pan = inst->pan; - ((ALChanState_Custom*)seqp->chanState)[chan].vol = inst->volume; - ((ALChanState_Custom*)seqp->chanState)[chan].priority = inst->priority; - ((ALChanState_Custom*)seqp->chanState)[chan].bendRange = inst->bendRange; + ((_AlChanState*)seqp->chanState)[chan].instrument = inst; + ((_AlChanState*)seqp->chanState)[chan].pan = inst->pan; + ((_AlChanState*)seqp->chanState)[chan].vol = inst->volume; + ((_AlChanState*)seqp->chanState)[chan].priority = inst->priority; + ((_AlChanState*)seqp->chanState)[chan].bendRange = inst->bendRange; } + +/* + sct 11/6/95 -- Call this whenever a new sequence is to be played or when + initializing a sequence player. +*/ void __resetPerfChanState(ALSeqPlayer *seqp, s32 chan) { - ((ALChanState_Custom*)seqp->chanState)[chan].fxId = AL_FX_NONE; - ((ALChanState_Custom*)seqp->chanState)[chan].fxmix = AL_DEFAULT_FXMIX; - ((ALChanState_Custom*)seqp->chanState)[chan].pan = AL_PAN_CENTER; - ((ALChanState_Custom*)seqp->chanState)[chan].vol = AL_VOL_FULL; - ((ALChanState_Custom*)seqp->chanState)[chan].fade = AL_VOL_FULL; - ((ALChanState_Custom*)seqp->chanState)[chan].priority = AL_DEFAULT_PRIORITY; - ((ALChanState_Custom*)seqp->chanState)[chan].sustain = 0; - ((ALChanState_Custom*)seqp->chanState)[chan].bendRange = 200; - ((ALChanState_Custom*)seqp->chanState)[chan].pitchBend = 1.0f; + ((_AlChanState*)seqp->chanState)[chan].fxId = AL_FX_NONE; + ((_AlChanState*)seqp->chanState)[chan].fxmix = AL_DEFAULT_FXMIX; + ((_AlChanState*)seqp->chanState)[chan].pan = AL_PAN_CENTER; + ((_AlChanState*)seqp->chanState)[chan].vol = AL_VOL_FULL; + ((_AlChanState*)seqp->chanState)[chan].fade = AL_VOL_FULL; + ((_AlChanState*)seqp->chanState)[chan].priority = AL_DEFAULT_PRIORITY; + ((_AlChanState*)seqp->chanState)[chan].sustain = 0; + ((_AlChanState*)seqp->chanState)[chan].bendRange = 200; + ((_AlChanState*)seqp->chanState)[chan].pitchBend = 1.0f; } + +/* + sct 11/6/95 - Called only when creating a new sequence player. +*/ void __initChanState(ALSeqPlayer *seqp) { int i; for (i = 0; i < seqp->maxChannels; i++) { - ((ALChanState_Custom*)seqp->chanState)[i].instrument = 0; - __resetPerfChanState(seqp, i); + ((_AlChanState*)seqp->chanState)[i].instrument = 0; + __resetPerfChanState (seqp, i); } } + void __seqpStopOsc(ALSeqPlayer *seqp, ALVoiceState *vs) { ALEventListItem *thisNode,*nextNode; @@ -287,17 +439,17 @@ void __seqpStopOsc(ALSeqPlayer *seqp, ALVoiceState *vs) { if(thisNode->evt.msg.osc.vs == vs) { - (*(seqp->stopOsc))(thisNode->evt.msg.osc.oscState); + (*seqp->stopOsc)(thisNode->evt.msg.osc.oscState); alUnlink((ALLink*)thisNode); if(nextNode) nextNode->delta += thisNode->delta; alLink((ALLink*)thisNode, &seqp->evtq.freeList); if(evtType == AL_TREM_OSC_EVT) vs->flags = vs->flags & 0xFE; - else + else /* must be a AL_VIB_OSC_EVT */ vs->flags = vs->flags & 0xFD; if(!vs->flags) - return; + return; /* there should be no more events */ } } diff --git a/lib/src/audio/mips1/synallocfx.c b/lib/src/audio/mips1/synallocfx.c new file mode 100644 index 00000000..16269e59 --- /dev/null +++ b/lib/src/audio/mips1/synallocfx.c @@ -0,0 +1,34 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80065860 */ +/*==================================================================== + * 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, bus, 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/lib/src/audio/mips1/synsetpan.c b/lib/src/audio/mips1/synsetpan.c new file mode 100644 index 00000000..2166135b --- /dev/null +++ b/lib/src/audio/mips1/synsetpan.c @@ -0,0 +1,53 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80065B20 */ +/*==================================================================== + * synsetpan.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 "synstartvoiceparam.h" + +void alSynSetPan(ALSynth *synth, ALVoice *v, u8 pan) +{ + ALParam *update; + ALFilter *f; + + if (v->pvoice) { + + /* + * get new update struct from the free list + */ + update = __allocParam(); + ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); + + /* + * set offset and pan data + */ + update->delta = synth->paramSamples + v->pvoice->offset; + update->type = AL_FILTER_SET_PAN; + update->data.i = modify_panning(pan); + update->next = 0; + + f = v->pvoice->channelKnob; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + } +} + diff --git a/lib/src/audio/mips1/synstartvoiceparam.c b/lib/src/audio/mips1/synstartvoiceparam.c new file mode 100644 index 00000000..95d0ff82 --- /dev/null +++ b/lib/src/audio/mips1/synstartvoiceparam.c @@ -0,0 +1,101 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80065BD0 */ +/*==================================================================== + * synquickstartvoice + * + * 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 + +#if BUILD_VERSION < VERSION_J +#ident "$Revision: 1.17 $" +#endif + +#include "synstartvoiceparam.h" +#include "macros.h" + +s16 gStereoPanMode = STEREO; + +void set_stereo_pan_mode(s32 panMode) { + gStereoPanMode = panMode; +} + +UNUSED s16 get_stereo_pan_mode(void) { + return gStereoPanMode; +} + +s32 modify_panning(s32 pan) { + switch(gStereoPanMode) { + case STEREO: + return pan; + case HEADPHONES: + pan = ((pan - 64) >> 1) + 64; + return pan; + case MONO: + default: + return 64; + } +} + +void alSynStartVoiceParams(ALSynth *s, ALVoice *v, ALWaveTable *w, + f32 pitch, s16 vol, ALPan pan, u8 fxmix, + ALMicroTime t) +{ + ALStartParamAlt *update; + ALFilter *f; + + if (v->pvoice) { + /* + * get new update struct from the free list + */ + update = (ALStartParamAlt *)__allocParam(); + ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); + +#if BUILD_VERSION >= VERSION_J + if (fxmix > 127) { + fxmix = 127; + } +#elif BUILD_VERSION > VERSION_G + if (fxmix < 0) { // Not possible + fxmix = -fxmix; + } +#endif + + /* + * set offset and fxmix data + */ + update->delta = s->paramSamples + v->pvoice->offset; + update->next = 0; + update->type = AL_FILTER_START_VOICE_ALT; + + update->unity = v->unityPitch; + update->pan = modify_panning(pan); + update->volume = vol; + update->fxMix = fxmix; + update->pitch = pitch; + update->samples = _timeToSamples(s, t); + update->wave = w; + + f = v->pvoice->channelKnob; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + } + +} diff --git a/lib/src/mips1/al/synthesizer.c b/lib/src/audio/mips1/synthesizer.c similarity index 50% rename from lib/src/mips1/al/synthesizer.c rename to lib/src/audio/mips1/synthesizer.c index 8577aad9..17619ffe 100644 --- a/lib/src/mips1/al/synthesizer.c +++ b/lib/src/audio/mips1/synthesizer.c @@ -1,13 +1,44 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x80065130 */ +/*==================================================================== + * 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 +#include +// TODO: this comes from a header +#ident "$Revision: 1.17 $" -#include "types.h" -#include "audio_internal.h" -#include "macros.h" +#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 -s32 __nextSampleTime(ALSynth *drvr, ALPlayer **client); -s32 _timeToSamplesNoRound(ALSynth *ALSynth, s32 micros); +#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; @@ -38,19 +69,31 @@ void alSynNew(ALSynth *drvr, ALSynConfig *c) sources = alHeapAlloc(hp, c->maxPVoices, sizeof(ALFilter *)); alAuxBusNew(drvr->auxBus + 1, 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); for(i = 0; i < 2; i++) { if (c->fxType[i] != 0) { + /* + * Allocate an effect and set parameters + */ alSynAllocFX(drvr, (s16)i, c, hp); } else { + /* + * Connect the aux bus to the main bus + */ alMainBusParam(drvr->mainBus, 2, drvr->auxBus + i); } } + /* + * Build the physical voice lists + */ drvr->pFreeList.next = 0; drvr->pFreeList.prev = 0; drvr->pLameList.next = 0; @@ -80,6 +123,9 @@ void alSynNew(ALSynth *drvr, ALSynConfig *c) 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++) { @@ -91,9 +137,11 @@ void alSynNew(ALSynth *drvr, ALSynConfig *c) drvr->heap = hp; } -void __collectPVoices(ALSynth *drvr); -s32 __timeToSamplesNoRound(ALSynth *synth, s32 micros); - +/* + * 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; @@ -105,24 +153,66 @@ Acmd *alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen) s32 nOut; s16 *lOutBuf = outBuf; +#ifdef AUD_PROFILE + lastCnt[++cnt_index] = osGetCount(); +#endif + if (drvr->head == 0) { - *cmdLen = 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)); + 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; @@ -131,17 +221,24 @@ Acmd *alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen) cmdPtr); outLen -= nOut; - lOutBuf += nOut<<1; + lOutBuf += nOut<<1; /* For Stereo */ drvr->curSamples += nOut; } *cmdLen = (s32) (cmdlEnd - cmdList); - __collectPVoices(drvr); + _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; @@ -154,7 +251,7 @@ ALParam *__allocParam() } return update; } - + void __freeParam(ALParam *param) { ALSynth *drvr = &alGlobals->drvr; @@ -162,38 +259,55 @@ void __freeParam(ALParam *param) drvr->paramList = param; } -void __collectPVoices(ALSynth *drvr) +void _collectPVoices(ALSynth *drvr) { - ALLink *dl; + ALLink *dl; + PVoice *pv; while ((dl = drvr->pLameList.next) != 0) { + pv = (PVoice *)dl; + + /* ### remove from mixer */ + alUnlink(dl); alLink(dl, &drvr->pFreeList); } } -void __freePVoices(ALSynth *drvr, PVoice *pvoice) +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); } -s32 __timeToSamplesNoRound(ALSynth *synth, s32 micros) +/* + 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) +s32 _timeToSamples(ALSynth *synth, s32 micros) { - return __timeToSamplesNoRound(synth, micros) & ~0xF; + return _timeToSamplesNoRound(synth, micros) & ~0xf; } -s32 __nextSampleTime(ALSynth *drvr, ALPlayer **client) +static s32 __nextSampleTime(ALSynth *drvr, ALPlayer **client) { - ALMicroTime delta = 0x7fffffff; + ALMicroTime delta = 0x7fffffff; /* max delta for s32 */ ALPlayer *cl; +#if BUILD_VERSION < VERSION_J // Adjust line numbers to match assert +#line 306 +#endif + assert(drvr->head); *client = 0; @@ -206,3 +320,6 @@ s32 __nextSampleTime(ALSynth *drvr, ALPlayer **client) return (*client)->samplesLeft; } + + + diff --git a/lib/src/mips1/al/unknown_064690.c b/lib/src/audio/mips1/unknown_064690.c similarity index 78% rename from lib/src/mips1/al/unknown_064690.c rename to lib/src/audio/mips1/unknown_064690.c index e62320fd..c4243009 100644 --- a/lib/src/mips1/al/unknown_064690.c +++ b/lib/src/audio/mips1/unknown_064690.c @@ -1,9 +1,6 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x80063A90 */ - -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include void func_80063A90(ALSeqPlayer *seqp, u8 chan) { ALEvent evt; @@ -11,7 +8,7 @@ void func_80063A90(ALSeqPlayer *seqp, u8 chan) { evt.type = AL_SEQP_MIDI_EVT; evt.msg.midi.ticks = 0; evt.msg.midi.status = AL_MIDI_ControlChange; - evt.msg.midi.byte1 = 0x5F; + evt.msg.midi.byte1 = AL_MIDI_UNK_5F; evt.msg.midi.byte2 = chan; alEvtqPostEvent(&seqp->evtq, &evt, 0); } diff --git a/lib/src/al/resample.c b/lib/src/audio/resample.c similarity index 97% rename from lib/src/al/resample.c rename to lib/src/audio/resample.c index 9f1b9ac6..add2c04e 100644 --- a/lib/src/al/resample.c +++ b/lib/src/audio/resample.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CC090 */ - /*==================================================================== * resample.c * @@ -21,11 +20,10 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" -#include "PR/os.h" -#include "PR/abi.h" +#include +#include "synthInternals.h" +#include +#include // TODO: this comes from a header #ident "$Revision: 1.49 $" diff --git a/lib/src/al/save.c b/lib/src/audio/save.c similarity index 94% rename from lib/src/al/save.c rename to lib/src/audio/save.c index 878b736b..9d8a0b27 100644 --- a/lib/src/al/save.c +++ b/lib/src/audio/save.c @@ -5,7 +5,6 @@ * * 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, @@ -19,25 +18,24 @@ * DOD or NASA FAR Supplement. Unpublished - rights reserved under the * Copyright Laws of the United States. *====================================================================*/ - -#include "types.h" -#include "macros.h" -#include "audio_internal.h" - +#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); +#if BUILD_VERSION < VERSION_J +#line 33 #endif + assert(f->filter.source); + ptr = (*source->handler)(source, outp, outCount, sampleOffset, ptr); @@ -69,3 +67,6 @@ s32 alSaveParam(void *filter, s32 paramID, void *param) return 0; } + + + diff --git a/lib/src/audio/seq.h b/lib/src/audio/seq.h new file mode 100644 index 00000000..479b3396 --- /dev/null +++ b/lib/src/audio/seq.h @@ -0,0 +1,9 @@ + + +#ifndef __seq__ +#define __seq__ + +char __alSeqNextDelta (ALSeq *seq, s32 *pDeltaTicks); + + +#endif /* __seq__ */ diff --git a/lib/src/mips1/al/seqchannel.h b/lib/src/audio/seqchannel.h similarity index 100% rename from lib/src/mips1/al/seqchannel.h rename to lib/src/audio/seqchannel.h diff --git a/lib/src/mips1/al/seqp.h b/lib/src/audio/seqp.h similarity index 100% rename from lib/src/mips1/al/seqp.h rename to lib/src/audio/seqp.h diff --git a/lib/src/audio/seqpgetfxmix.c b/lib/src/audio/seqpgetfxmix.c new file mode 100644 index 00000000..39706d19 --- /dev/null +++ b/lib/src/audio/seqpgetfxmix.c @@ -0,0 +1,29 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C79C0 */ +/*==================================================================== + * seqpgetfxmix.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 + +u8 alSeqpGetChlFXMix(ALSeqPlayer *seqp, u8 chan) +{ + return seqp->chanState[chan].fxmix; +} + diff --git a/lib/src/al/sl.c b/lib/src/audio/sl.c similarity index 96% rename from lib/src/al/sl.c rename to lib/src/audio/sl.c index 517f6a35..8cc960be 100644 --- a/lib/src/al/sl.c +++ b/lib/src/audio/sl.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C8760 */ - /*==================================================================== * sl.c * @@ -24,10 +23,7 @@ * Copyright Laws of the United States. *====================================================================*/ - -#include "libultra_internal.h" -#include "types.h" -#include "macros.h" +#include ALGlobals *alGlobals=0; @@ -64,3 +60,8 @@ void alUnlink(ALLink *ln) if (ln->prev) ln->prev->next = ln->next; } + + + + + diff --git a/lib/src/al/synaddplayer.c b/lib/src/audio/synaddplayer.c similarity index 92% rename from lib/src/al/synaddplayer.c rename to lib/src/audio/synaddplayer.c index 53aa3455..967d5317 100644 --- a/lib/src/al/synaddplayer.c +++ b/lib/src/audio/synaddplayer.c @@ -20,10 +20,8 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" -#include "libultra_internal.h" +#include "synthInternals.h" +#include void alSynAddPlayer(ALSynth *drvr, ALPlayer *client) { @@ -35,3 +33,4 @@ void alSynAddPlayer(ALSynth *drvr, ALPlayer *client) osSetIntMask(mask); } + diff --git a/lib/src/al/synallocvoice.c b/lib/src/audio/synallocvoice.c similarity index 96% rename from lib/src/al/synallocvoice.c rename to lib/src/audio/synallocvoice.c index 10116206..dcce4f6e 100644 --- a/lib/src/al/synallocvoice.c +++ b/lib/src/audio/synallocvoice.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C9420 */ - /*==================================================================== * synallocvoice.c * @@ -21,43 +20,11 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" -#include "libultra_internal.h" +#include +#include +#include "synthInternals.h" -s32 _allocatePVoice(ALSynth *drvr, PVoice **pvoice, s16 priority) -{ - ALLink *dl; - PVoice *pv; - s32 stolen = 0; - - if ((dl = drvr->pLameList.next) != 0) { /* check the lame list first */ - *pvoice = (PVoice *) dl; - alUnlink(dl); - alLink(dl, &drvr->pAllocList); - } else if ((dl = drvr->pFreeList.next) != 0) { /* from the free list */ - *pvoice = (PVoice *) dl; - alUnlink(dl); - alLink(dl, &drvr->pAllocList); - } else { /* steal one */ - for (dl = drvr->pAllocList.next; dl != 0; dl = dl->next) { - pv = (PVoice *)dl; - - /* - * if it is lower priority and not already stolen, keep it - * as a candidate for stealing - */ - if ((pv->vvoice->priority <= priority) && (pv->offset == 0)) { - *pvoice = pv; - priority = pv->vvoice->priority; - stolen = 1; - } - } - } - - return stolen; -} +s32 _allocatePVoice(ALSynth *drvr, PVoice **pvoice, s16 priority); s32 alSynAllocVoice(ALSynth *drvr, ALVoice *voice, ALVoiceConfig *vc) { @@ -131,3 +98,37 @@ s32 alSynAllocVoice(ALSynth *drvr, ALVoice *voice, ALVoiceConfig *vc) return (pvoice != 0); } + +s32 _allocatePVoice(ALSynth *drvr, PVoice **pvoice, s16 priority) +{ + ALLink *dl; + PVoice *pv; + s32 stolen = 0; + + if ((dl = drvr->pLameList.next) != 0) { /* check the lame list first */ + *pvoice = (PVoice *) dl; + alUnlink(dl); + alLink(dl, &drvr->pAllocList); + } else if ((dl = drvr->pFreeList.next) != 0) { /* from the free list */ + *pvoice = (PVoice *) dl; + alUnlink(dl); + alLink(dl, &drvr->pAllocList); + } else { /* steal one */ + for (dl = drvr->pAllocList.next; dl != 0; dl = dl->next) { + pv = (PVoice *)dl; + + /* + * if it is lower priority and not already stolen, keep it + * as a candidate for stealing + */ + if ((pv->vvoice->priority <= priority) && (pv->offset == 0)) { + *pvoice = pv; + priority = pv->vvoice->priority; + stolen = 1; + } + } + } + + return stolen; +} + diff --git a/lib/src/al/alSynDelete.c b/lib/src/audio/syndelete.c similarity index 94% rename from lib/src/al/alSynDelete.c rename to lib/src/audio/syndelete.c index e745aefb..2eab412b 100644 --- a/lib/src/al/alSynDelete.c +++ b/lib/src/audio/syndelete.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D2C60 */ - /*==================================================================== * syndelete.c * @@ -21,11 +20,10 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include "synthInternals.h" void alSynDelete(ALSynth *drvr) { drvr->head = 0; } + diff --git a/lib/src/al/synfreevoice.c b/lib/src/audio/synfreevoice.c similarity index 92% rename from lib/src/al/synfreevoice.c rename to lib/src/audio/synfreevoice.c index a677cfd0..20eab24d 100644 --- a/lib/src/al/synfreevoice.c +++ b/lib/src/audio/synfreevoice.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C9930 */ - /*==================================================================== * synfreevoice.c * @@ -21,10 +20,11 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" -#include "libultra_internal.h" +#include +#include +#include "synthInternals.h" + +#include void alSynFreeVoice(ALSynth *drvr, ALVoice *voice) { @@ -47,7 +47,7 @@ void alSynFreeVoice(ALSynth *drvr, ALVoice *voice) f = voice->pvoice->channelKnob; (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); } else { - __freePVoices(drvr, voice->pvoice); + _freePVoice(drvr, voice->pvoice); } voice->pvoice = 0; diff --git a/lib/src/al/alSynSetFXMix.c b/lib/src/audio/synsetfxmix.c similarity index 80% rename from lib/src/al/alSynSetFXMix.c rename to lib/src/audio/synsetfxmix.c index 11a4859f..65d189d5 100644 --- a/lib/src/al/alSynSetFXMix.c +++ b/lib/src/audio/synsetfxmix.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C9810 */ - /*==================================================================== * synsetfxmix.c * @@ -21,11 +20,9 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" - -ALParam *__allocParam(); +#include "synthInternals.h" +#include +#include void alSynSetFXMix(ALSynth *synth, ALVoice *v, u8 fxmix) { @@ -44,22 +41,22 @@ void alSynSetFXMix(ALSynth *synth, ALVoice *v, u8 fxmix) */ update->delta = synth->paramSamples + v->pvoice->offset; update->type = AL_FILTER_SET_FXAMT; - -//Ignore GCC warnings for this line, as there's no other way to match this. -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wtype-limits" - //Differs from ultralib - if (fxmix < 0) +#if BUILD_VERSION >= VERSION_J + if (fxmix > 127) { + fxmix = 127; + } + update->data.i = fxmix; +#else + if (fxmix < 0) { // Not possible update->data.i = -fxmix; - else + } else { update->data.i = fxmix; -#pragma GCC diagnostic pop - + } +#endif update->next = 0; f = v->pvoice->channelKnob; - (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); } } - diff --git a/lib/src/al/alSynSetPitch.c b/lib/src/audio/synsetpitch.c similarity index 95% rename from lib/src/al/alSynSetPitch.c rename to lib/src/audio/synsetpitch.c index 973b81ce..8cc7760d 100644 --- a/lib/src/al/alSynSetPitch.c +++ b/lib/src/audio/synsetpitch.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C9780 */ - /*==================================================================== * synsetpitch.c * @@ -21,9 +20,9 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include "synthInternals.h" +#include +#include void alSynSetPitch(ALSynth *synth, ALVoice *v, f32 pitch) { @@ -50,3 +49,4 @@ void alSynSetPitch(ALSynth *synth, ALVoice *v, f32 pitch) (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); } } + diff --git a/lib/src/al/alSynSetPriority.c b/lib/src/audio/synsetpriority.c similarity index 88% rename from lib/src/al/alSynSetPriority.c rename to lib/src/audio/synsetpriority.c index dd72427d..5277b1b9 100644 --- a/lib/src/al/alSynSetPriority.c +++ b/lib/src/audio/synsetpriority.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C9AE0 */ - /*==================================================================== * synsetpriority.c * @@ -21,11 +20,10 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include -void alSynSetPriority(UNUSED ALSynth *s, ALVoice *voice, s16 priority) +void alSynSetPriority(ALSynth *s, ALVoice *voice, s16 priority) { voice->priority = priority; } + diff --git a/lib/src/al/alSynSetVol.c b/lib/src/audio/synsetvol.c similarity index 92% rename from lib/src/al/alSynSetVol.c rename to lib/src/audio/synsetvol.c index 6bda99b4..b1f51812 100644 --- a/lib/src/al/alSynSetVol.c +++ b/lib/src/audio/synsetvol.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C9650 */ - /*==================================================================== * synsetvol.c * @@ -21,9 +20,9 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include "synthInternals.h" +#include +#include void alSynSetVol(ALSynth *synth, ALVoice *v, s16 volume, ALMicroTime t) { @@ -43,7 +42,7 @@ void alSynSetVol(ALSynth *synth, ALVoice *v, s16 volume, ALMicroTime t) update->delta = synth->paramSamples + v->pvoice->offset; update->type = AL_FILTER_SET_VOLUME; update->data.i = volume; - update->moredata.i = __timeToSamples(synth, t); + update->moredata.i = _timeToSamples(synth, t); update->next = 0; f = v->pvoice->channelKnob; @@ -51,4 +50,3 @@ void alSynSetVol(ALSynth *synth, ALVoice *v, s16 volume, ALMicroTime t) } } - diff --git a/lib/src/al/alSynStartVoice.c b/lib/src/audio/synstartvoice.c similarity index 95% rename from lib/src/al/alSynStartVoice.c rename to lib/src/audio/synstartvoice.c index 054fe05f..5b4ed02d 100644 --- a/lib/src/al/alSynStartVoice.c +++ b/lib/src/audio/synstartvoice.c @@ -20,9 +20,9 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include "synthInternals.h" +#include +#include void alSynStartVoice(ALSynth *synth, ALVoice *v, ALWaveTable *table) { diff --git a/lib/src/mips1/al/alSynStartVoiceParams.h b/lib/src/audio/synstartvoiceparam.h similarity index 91% rename from lib/src/mips1/al/alSynStartVoiceParams.h rename to lib/src/audio/synstartvoiceparam.h index 1e7eb6e7..51d8e388 100644 --- a/lib/src/mips1/al/alSynStartVoiceParams.h +++ b/lib/src/audio/synstartvoiceparam.h @@ -2,7 +2,7 @@ #define AL_SYN_START_VOICE_PARAMS #include "types.h" -#include "audio_internal.h" +#include // Can be changed in the "Audio Options" menu. typedef enum StereoPanMode { diff --git a/lib/src/al/alSynStopVoice.c b/lib/src/audio/synstopvoice.c similarity index 95% rename from lib/src/al/alSynStopVoice.c rename to lib/src/audio/synstopvoice.c index e41ec5ac..af9577d5 100644 --- a/lib/src/al/alSynStopVoice.c +++ b/lib/src/audio/synstopvoice.c @@ -1,6 +1,5 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C98B0 */ - /*==================================================================== * synstopvoice.c * @@ -21,9 +20,9 @@ * Copyright Laws of the United States. *====================================================================*/ -#include "types.h" -#include "macros.h" -#include "audio_internal.h" +#include "synthInternals.h" +#include +#include void alSynStopVoice(ALSynth *synth, ALVoice *v) @@ -44,3 +43,4 @@ void alSynStopVoice(ALSynth *synth, ALVoice *v) (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); } } + diff --git a/lib/src/audio/synthInternals.h b/lib/src/audio/synthInternals.h new file mode 100644 index 00000000..5da7c78a --- /dev/null +++ b/lib/src/audio/synthInternals.h @@ -0,0 +1,348 @@ +/*==================================================================== + * 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 +#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, + AL_FILTER_UNK11 +}; + +#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, s16 bus, 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; + u8 unkDC; +} 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 func_80065A80(ALSynth *arg0, PVoice *arg1, s16 arg2); + +// This was renamed to have a leading underscore in 2.0J +#if BUILD_VERSION < VERSION_J +#define _init_lpfilter init_lpfilter +#endif + +void _init_lpfilter(ALLowPass *lp); + +#endif + diff --git a/lib/src/debug/assert.c b/lib/src/debug/assert.c new file mode 100644 index 00000000..29ddd032 --- /dev/null +++ b/lib/src/debug/assert.c @@ -0,0 +1,15 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800B6F30 */ + +#include "os.h" +#include "PRinternal/osint.h" +#include "osint_debug.h" + +void __assertBreak(void); + +void __assert(const char* exp, const char* filename, int line) { +#ifndef _FINALROM + osSyncPrintf("\nASSERTION FAULT: %s, %d: \"%s\"\n", filename, line, exp); + __assertBreak; // Doesn't actually do anything, but is needed for matching +#endif +} diff --git a/lib/src/debug/assert.h b/lib/src/debug/assert.h new file mode 100644 index 00000000..518762e9 --- /dev/null +++ b/lib/src/debug/assert.h @@ -0,0 +1,10 @@ +#ifndef _ASSERT_H_ +#define _ASSERT_H_ + +#include "types.h" +#include +#include "macros.h" + +void __assert(const char* exp, const char* filename, int line); + +#endif diff --git a/lib/src/debug/osint_debug.h b/lib/src/debug/osint_debug.h new file mode 100644 index 00000000..6d644f2f --- /dev/null +++ b/lib/src/debug/osint_debug.h @@ -0,0 +1,11 @@ +#include "PR/os_internal.h" + +extern s32 __osThprofFlag; +extern void (*__osThprofFunc)(OSThread*); +extern u32 __osThprofLastTimer; +extern u32 __osThprofCount; +extern __OSThreadprofile_s thprof[]; +extern u64 __osThprofHeap[]; +extern void* __osThprofStack; + +void osThreadProfileCallback(OSThread*); diff --git a/lib/src/gu/cosf.c b/lib/src/gu/cosf.c index 27b857ac..1d656e03 100644 --- a/lib/src/gu/cosf.c +++ b/lib/src/gu/cosf.c @@ -1,66 +1,139 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D4AB0 */ +/************************************************************************** + * * + * 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 "types.h" -#include "macros.h" #include "guint.h" -extern du P_cosf[]; -extern du rpi_cosf; -extern du pihi_cosf; -extern du pilo_cosf; -extern fu zero_cosf; -extern fu __libm_qnan_f; +/* ==================================================================== + * ==================================================================== + * + * 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 + * + * ==================================================================== + * ==================================================================== + */ -f32 cosf(f32 x) { - f64 dx; // double x - f64 xsq; // x squared - f64 poly; - f64 dn; - f32 xabs; - s32 n; - f64 result; - s32 ix; // int x - s32 xpt; - - ix = *(s32 *) &x; - xpt = (ix >> 22) & 0x1FF; +#pragma weak fcos = __cosf +#pragma weak cosf = __cosf +#define fcos __cosf - if (xpt < 310) { - if (0 < x) { - xabs = x; - } else { - xabs = -x; - } +/* coefficients for polynomial approximation of cos on +/- pi/2 */ - dx = xabs; - dn = dx * rpi_cosf.d + 0.5; +static const du P[] = +{ +{0x3ff00000, 0x00000000}, +{0xbfc55554, 0xbc83656d}, +{0x3f8110ed, 0x3804c2a0}, +{0xbf29f6ff, 0xeea56814}, +{0x3ec5dbdf, 0x0e314bfe}, +}; - if (0 <= dn) { - n = dn + 0.5; - } else { - n = dn - 0.5; - } +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; - dx -= (dn - 0.5) * pihi_cosf.d; - dx -= (dn - 0.5) * pilo_cosf.d; - xsq = dx * dx; - poly = (((((P_cosf[4].d * xsq) + P_cosf[3].d) * xsq) + P_cosf[2].d) * xsq) + P_cosf[1].d; + dn -= 0.5; - result = ((dx * xsq) * poly) + dx; + dx = dx - dn*pihi.d; + dx = dx - dn*pilo.d; /* dx = x - (n - 0.5)*pi */ - if ((n & 1) == 0) { - return result; - } else { - return -(f32) result; - } + 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) { - return __libm_qnan_f.f; + if ( x != x ) + { + /* x is a NaN; return a quiet NaN */ + +#ifdef _IP_NAN_SETS_ERRNO + + *__errnoaddr = EDOM; +#endif + + return ( __libm_qnan_f ); } - return zero_cosf.f; + /* just give up and return 0.0 */ + + return ( zero.f ); } diff --git a/lib/src/gu/guMtxUtil.c b/lib/src/gu/guMtxUtil.c deleted file mode 100644 index f2cc2377..00000000 --- a/lib/src/gu/guMtxUtil.c +++ /dev/null @@ -1,64 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D4840 */ - -#include "libultra_internal.h" - -void guMtxF2L(float mf[4][4], Mtx *m) { - int r, c; - s32 tmp1; - s32 tmp2; - s32 *m1 = &m->m[0][0]; - s32 *m2 = &m->m[2][0]; - for (r = 0; r < 4; r++) { - for (c = 0; c < 2; c++) { - tmp1 = mf[r][2 * c] * 65536.0f; - tmp2 = mf[r][2 * c + 1] * 65536.0f; - *m1++ = (tmp1 & 0xffff0000) | ((tmp2 >> 0x10) & 0xffff); - *m2++ = ((tmp1 << 0x10) & 0xffff0000) | (tmp2 & 0xffff); - } - } -} - -void guMtxIdentF(float mf[4][4]) { - int r, c; - for (r = 0; r < 4; r++) { - for (c = 0; c < 4; c++) { - if (r == c) { - mf[r][c] = 1.0f; - } else { - mf[r][c] = 0.0f; - } - } - } -} - -void guMtxIdent(Mtx *m) { -#ifndef GBI_FLOATS - float mf[4][4]; - guMtxIdentF(mf); - guMtxF2L(mf, m); -#else - guMtxIdentF(m->m); -#endif -} - -void guMtxL2F(float mf[4][4], Mtx *m) { - int r, c; - u32 tmp1; - u32 tmp2; - u32 *m1; - u32 *m2; - s32 stmp1, stmp2; - m1 = (u32 *) &m->m[0][0]; - m2 = (u32 *) &m->m[2][0]; - for (r = 0; r < 4; r++) { - for (c = 0; c < 2; c++) { - tmp1 = (*m1 & 0xffff0000) | ((*m2 >> 0x10) & 0xffff); - tmp2 = ((*m1++ << 0x10) & 0xffff0000) | (*m2++ & 0xffff); - stmp1 = *(s32 *) &tmp1; - stmp2 = *(s32 *) &tmp2; - mf[r][c * 2 + 0] = stmp1 / 65536.0f; - mf[r][c * 2 + 1] = stmp2 / 65536.0f; - } - } -} diff --git a/lib/src/gu/guPerspectiveF.c b/lib/src/gu/guPerspectiveF.c deleted file mode 100644 index 6ad42a70..00000000 --- a/lib/src/gu/guPerspectiveF.c +++ /dev/null @@ -1,47 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CC920 */ - -#include "types.h" -#include "macros.h" -#include "libc/math.h" -#include "PR/gu.h" - -void guPerspectiveF(Matrix mf, u16 *perspNorm, float fovy, float aspect, float near, float far, float scale) { - float cot; - int i, j; - - guMtxIdentF(mf); - - fovy *= 3.1415926 / 180.0; - cot = cosf (fovy/2) / sinf (fovy/2); - - mf[0][0] = cot / aspect; - mf[1][1] = cot; - mf[2][2] = (near + far) / (near - far); - mf[2][3] = -1; - mf[3][2] = (2 * near * far) / (near - far); - mf[3][3] = 0; - - for (i=0; i<4; i++) { - for (j=0; j<4; j++) - mf[i][j] *= scale; - } - - if (perspNorm != (u16 *) NULL) { - if (near+far<=2.0) { - *perspNorm = (u16) 0xFFFF; - } else { - *perspNorm = (u16) ((2.0*65536.0)/(near+far)); - if (*perspNorm<=0) - *perspNorm = (u16) 0x0001; - } - } -} - -void guPerspective(Mtx *m, u16 *perspNorm, float fovy, float aspect, float near, float far, float scale) { - Matrix mf; - - guPerspectiveF(mf, perspNorm, fovy, aspect, near, far, scale); - - guMtxF2L(mf, m); -} diff --git a/lib/src/gu/guint.h b/lib/src/gu/guint.h index c9c1614b..c3206dd5 100644 --- a/lib/src/gu/guint.h +++ b/lib/src/gu/guint.h @@ -9,10 +9,10 @@ * in part, without the prior written consent of Silicon Graphics, Inc. * * * **************************************************************************/ -/* + #include "mbi.h" #include "gu.h" -*/ + typedef union { struct @@ -32,11 +32,11 @@ typedef union #ifndef __GL_GL_H__ -//typedef float Matrix[4][4]; +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; +extern float __libm_qnan_f; diff --git a/lib/src/gu/libm_vals.s b/lib/src/gu/libm_vals.s deleted file mode 100644 index b88ad985..00000000 --- a/lib/src/gu/libm_vals.s +++ /dev/null @@ -1,5 +0,0 @@ - .rdata - .align 4 - .globl __libm_qnan_f -__libm_qnan_f: - .word 0x7F810000 diff --git a/lib/src/gu/mtxutil.c b/lib/src/gu/mtxutil.c new file mode 100644 index 00000000..2a8b834a --- /dev/null +++ b/lib/src/gu/mtxutil.c @@ -0,0 +1,75 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D4840 */ +/************************************************************************** + * * + * 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 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); +} + +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] = q1 / (float)0x00010000; + mf[i][j*2+1] = q2 / (float)0x00010000; + } +} diff --git a/lib/src/gu/perspective.c b/lib/src/gu/perspective.c new file mode 100644 index 00000000..63b4453d --- /dev/null +++ b/lib/src/gu/perspective.c @@ -0,0 +1,59 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CC920 */ +/************************************************************************** + * * + * 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" +#include + +void guPerspectiveF(float mf[4][4], u16 *perspNorm, float fovy, float aspect, float near, float far, float scale) +{ + float cot; + int i, j; + + guMtxIdentF(mf); + + fovy *= 3.1415926 / 180.0; + cot = cosf (fovy/2) / sinf (fovy/2); + + mf[0][0] = cot / aspect; + mf[1][1] = cot; + mf[2][2] = (near + far) / (near - far); + mf[2][3] = -1; + mf[3][2] = (2 * near * far) / (near - far); + mf[3][3] = 0; + + for (i=0; i<4; i++) + for (j=0; j<4; j++) + mf[i][j] *= scale; + + if (perspNorm != (u16 *) NULL) { + if (near+far<=2.0) { + *perspNorm = (u16) 0xFFFF; + } else { + *perspNorm = (u16) ((2.0*65536.0)/(near+far)); + if (*perspNorm<=0) + *perspNorm = (u16) 0x0001; + } + } +} + +void guPerspective(Mtx *m, u16 *perspNorm, float fovy, float aspect, float near, float far, float scale) +{ + Matrix mf; + + guPerspectiveF(mf, perspNorm, fovy, aspect, near, far, scale); + + guMtxF2L(mf, m); +} + + diff --git a/lib/src/gu/sinf.c b/lib/src/gu/sinf.c index 0ca4fef1..f7dc0cf1 100644 --- a/lib/src/gu/sinf.c +++ b/lib/src/gu/sinf.c @@ -1,72 +1,160 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D4C20 */ -#include "types.h" -#include "macros.h" +/************************************************************************** + * * + * 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 du P_sinf[]; -extern du rpi_sinf; -extern du pihi_sinf; -extern du pilo_sinf; -extern fu zero_sinf; -extern fu __libm_qnan_f; +/* ==================================================================== + * ==================================================================== + * + * Module: fsin.c + * $Revision: 1.3 $ + * $Date: 1998/10/09 06:14:51 $ + * $Author: has $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/libultra/monegi/gu/sinf.c,v $ + * + * Revision history: + * 09-Jun-93 - Original Version + * + * Description: source code for fsin function + * + * ==================================================================== + * ==================================================================== + */ -f32 sinf(f32 x) { - f64 dx; // double x - f64 xsq; // x squared - f64 poly; - f64 dn; - s32 n; - f64 result; - s32 ix; // int x - s32 xpt; +#pragma weak fsin = __sinf +#pragma weak sinf = __sinf +#define fsin __sinf - ix = *(s32 *) &x; - xpt = (ix >> 22) & 0x1FF; +/* coefficients for polynomial approximation of sin 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 fsin + * + * Description computes sine of arg + * + * ==================================================================== + */ + +float +fsin( float x ) +{ +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 < 0xff ) + { + /* |x| < 1.5 */ - if (xpt < 255) { dx = x; - if (xpt >= 230) { - xsq = dx * dx; - poly = (((((P_sinf[4].d * xsq) + P_sinf[3].d) * xsq) + P_sinf[2].d) * xsq) + P_sinf[1].d; - result = ((dx * xsq) * poly) + dx; - return result; - } else { - return x; + if ( xpt >= 0xe6 ) + { + /* |x| >= 2^(-12) */ + + /* compute sin(x) with a standard polynomial approximation */ + + xsq = dx*dx; + + poly = ((P[4].d*xsq + P[3].d)*xsq + P[2].d)*xsq + P[1].d; + + result = dx + (dx*xsq)*poly; + + return ( (float)result ); } + + return ( x ); } - if (xpt < 310) { + if ( xpt < 0x136 ) + { + /* |x| < 2^28 */ + dx = x; - dn = dx * rpi_sinf.d; - if (dn >= 0) { - n = dn + 0.5; - } - else { - n = dn - 0.5; - } + /* reduce argument to +/- pi/2 */ + dn = dx*rpi.d; + + n = ROUND(dn); dn = n; - dx -= dn * pihi_sinf.d; - dx -= dn * pilo_sinf.d; - xsq = dx * dx; - poly = (((((P_sinf[4].d * xsq) + P_sinf[3].d) * xsq) + P_sinf[2].d) * xsq) + P_sinf[1].d; - result = ((dx * xsq) * poly) + dx; - if ((n & 1) == 0) { - return result; - } - else { - return -(f32) result; - } + dx = dx - dn*pihi.d; + dx = dx - dn*pilo.d; /* dx = x - n*pi */ + + /* compute sin(dx) as before, negating result if n is odd + */ + + xsq = dx*dx; + + poly = ((P[4].d*xsq + P[3].d)*xsq + P[2].d)*xsq + P[1].d; + + result = dx + (dx*xsq)*poly; + + + if ( (n & 1) == 0 ) + return ( (float)result ); + + return ( -(float)result ); } - if (x != x) { - return __libm_qnan_f.f; + if ( x != x ) + { + /* x is a NaN; return a quiet NaN */ + +#ifdef _IP_NAN_SETS_ERRNO + + *__errnoaddr = EDOM; +#endif + + return ( __libm_qnan_f ); } - return zero_sinf.f; + /* just give up and return 0.0 */ + + return ( zero.f ); } + diff --git a/lib/src/os/__osAiDeviceBusy.c b/lib/src/io/ai.c similarity index 52% rename from lib/src/os/__osAiDeviceBusy.c rename to lib/src/io/ai.c index 6aedb115..a398147b 100644 --- a/lib/src/os/__osAiDeviceBusy.c +++ b/lib/src/io/ai.c @@ -1,12 +1,18 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D3670 */ -#include "libultra_internal.h" +#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; + if (status & AI_STATUS_FIFO_FULL) { + return TRUE; + } else { + return FALSE; + } } diff --git a/lib/src/io/aigetlen.c b/lib/src/io/aigetlen.c new file mode 100644 index 00000000..b9ef5ca5 --- /dev/null +++ b/lib/src/io/aigetlen.c @@ -0,0 +1,16 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C8E20 */ +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +/** + * Returns the number of bytes remaining in a currently ongoing audio DMA. + * + * Note that audio DMA is double-buffered, a DMA can be queued while another is in-progress. This only returns + * information about the currently in-progress DMA. + */ +u32 osAiGetLength(void) { + return IO_READ(AI_LEN_REG); +} diff --git a/lib/src/io/aisetfreq.c b/lib/src/io/aisetfreq.c new file mode 100644 index 00000000..c9d0e7fd --- /dev/null +++ b/lib/src/io/aisetfreq.c @@ -0,0 +1,69 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C8600 */ + +#include "PR/rcp.h" +#include "PR/ultraerror.h" +#include "PRinternal/osint.h" +// TODO: not sure if this should be here +extern s32 osViClock; + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +/** + * Programs the operating frequency of the Audio DAC. + * + * @param frequency Target Playback frequency. + * @return The actual playback frequency, or -1 if the supplied frequency cannot be used. + */ +s32 osAiSetFrequency(u32 frequency) { + register unsigned int dacRate; + register unsigned char bitRate; + register float f; + +#ifdef _DEBUG + if (osViClock == VI_PAL_CLOCK) { + if (frequency < AI_PAL_MIN_FREQ || frequency > AI_PAL_MAX_FREQ) { + __osError(ERR_OSAISETFREQUENCY, 3, AI_PAL_MIN_FREQ, AI_PAL_MAX_FREQ, frequency); + return -1; + } + } else if (osViClock == VI_MPAL_CLOCK) { + if (frequency < AI_MPAL_MIN_FREQ || frequency > AI_MPAL_MAX_FREQ) { + __osError(ERR_OSAISETFREQUENCY, 3, AI_MPAL_MIN_FREQ, AI_MPAL_MAX_FREQ, frequency); + return -1; + } + } else { + if (frequency < AI_NTSC_MIN_FREQ || frequency > AI_NTSC_MAX_FREQ) { + __osError(ERR_OSAISETFREQUENCY, 3, AI_NTSC_MIN_FREQ, AI_NTSC_MAX_FREQ, frequency); + return -1; + } + } +#endif + + // Calculate the DAC sample period ("dperiod") (dperiod + 1 = vid_clock / frequency) + f = osViClock / (float)frequency + .5f; + dacRate = f; + + // Upcoming division by 66. If dacRate is smaller than 2 * 66 = 132, bitrate will be 1 and AI_BITRATE_REG will be + // programmed with 0, which results in no audio output. Return -1 to indicate an unusable frequency. + if (dacRate < AI_MIN_DAC_RATE) { + return -1; + } + + // Calculate the largest "bitrate" (ABUS clock half period, "aclockhp") supported for this dacrate. These two + // quantities must satisfy (dperiod + 1) >= 66 * (aclockhp + 1), here this is taken as equality. + bitRate = dacRate / 66; + // Clamp to max value + 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); +#if BUILD_VERSION < VERSION_J + IO_WRITE(AI_CONTROL_REG, AI_CONTROL_DMA_ON); +#endif + // Return the true playback frequency (frequency = vid_clock / (dperiod + 1)), which may differ from the target + // frequency. + return osViClock / (s32)dacRate; +} diff --git a/lib/src/io/aisetnextbuf.c b/lib/src/io/aisetnextbuf.c new file mode 100644 index 00000000..e53e5458 --- /dev/null +++ b/lib/src/io/aisetnextbuf.c @@ -0,0 +1,67 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C8D70 */ + +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/rcp.h" +#include "PRinternal/osint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +/** + * Submits an audio buffer to be consumed by the Audio DAC. The audio interface can queue a second DMA while another + * is in progress and automatically begin the next one as soon as the current DMA completes. If there is already a + * second DMA queued (DMA is full), -1 is returned to indicate the buffer could not be submitted. + * + * @param bufPtr Next audio buffer. Must be an 8-byte aligned KSEG0 (0x80XXXXXX) address. + * @param size Length of next audio buffer in bytes, maximum size 0x40000 bytes / 256 KiB. Should be a multiple of 8. + * @return 0 if the DMA was enqueued successfully, -1 if the DMA could not yet be queued. + */ +s32 osAiSetNextBuffer(void* bufPtr, u32 size) { + static u8 hdwrBugFlag = FALSE; + char* bptr; + +#if BUILD_VERSION >= VERSION_J + if (__osAiDeviceBusy()) { + return -1; + } +#endif + +#ifdef _DEBUG + if ((u32)bufPtr & (8 - 1)) { + __osError(ERR_OSAISETNEXTBUFFER_ADDR, 1, bufPtr); + return -1; + } + + if ((u32)size & (8 - 1)) { + __osError(ERR_OSAISETNEXTBUFFER_SIZE, 1, size); + return -1; + } +#endif + + bptr = bufPtr; + + if (hdwrBugFlag) { + bptr = (u8*)bufPtr - 0x2000; + } + + if ((((u32)bufPtr + size) & 0x3fff) == 0x2000) { + hdwrBugFlag = TRUE; + } else { + hdwrBugFlag = FALSE; + } + +#if BUILD_VERSION < VERSION_J + //! @bug The __osAiDeviceBusy call should be above the hardware bug workaround to ensure that it was only + //! performed when a transfer was guaranteed to start. If this condition passes and this function returns without + //! submitting a buffer for DMA, the code above will lose track of when to apply the workaround. + if (__osAiDeviceBusy()) { + return -1; + } +#endif + + IO_WRITE(AI_DRAM_ADDR_REG, osVirtualToPhysical(bptr)); + IO_WRITE(AI_LEN_REG, size); + return 0; +} diff --git a/lib/src/os/osEepromProbe.c b/lib/src/io/conteepprobe.c similarity index 69% rename from lib/src/os/osEepromProbe.c rename to lib/src/io/conteepprobe.c index 351e8e7e..87e02684 100644 --- a/lib/src/os/osEepromProbe.c +++ b/lib/src/io/conteepprobe.c @@ -1,12 +1,10 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CE210 */ -#include "libultra_internal.h" -#include "siint.h" +#include "PRinternal/controller.h" +#include "PRinternal/siint.h" -s32 __osEepStatus(OSMesgQueue *mq, OSContStatus *data); - -s32 osEepromProbe(OSMesgQueue *mq) { +s32 osEepromProbe(OSMesgQueue* mq) { s32 ret = 0; OSContStatus sdata; @@ -17,6 +15,10 @@ s32 osEepromProbe(OSMesgQueue *mq) { } else { ret = 0; } + +#if BUILD_VERSION >= VERSION_L + __osEepromRead16K = 0; +#endif __osSiRelAccess(); return ret; } diff --git a/lib/src/os/osEepromRead.c b/lib/src/io/conteepread.c similarity index 50% rename from lib/src/os/osEepromRead.c rename to lib/src/io/conteepread.c index 69077d33..c065a68c 100644 --- a/lib/src/os/osEepromRead.c +++ b/lib/src/io/conteepread.c @@ -1,27 +1,25 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CE280 */ -#include "libultra_internal.h" +#include "PRinternal/macros.h" #include "PR/rcp.h" -#include "controller.h" -#include "siint.h" +#include "PRinternal/controller.h" +#include "PRinternal/siint.h" -extern u8 __osContLastCmd; -extern OSPifRam __osEepPifRam; -s32 __osPackEepReadData(u8 address); -s32 __osEepStatus(OSMesgQueue *mq, OSContStatus *data); -s32 __osSiRawStartDma(s32, void *); +OSPifRam __osEepPifRam; +#if BUILD_VERSION >= VERSION_L +s32 __osEepromRead16K; +#endif +static void __osPackEepReadData(u8 address); -s32 osEepromRead(OSMesgQueue *mq, u8 address, u8 *buffer) { - s32 ret; - s32 i; - u8 *ptr; +s32 osEepromRead(OSMesgQueue* mq, u8 address, u8* buffer) { + s32 ret = 0; + int i = 0; + u8* ptr; OSContStatus sdata; __OSContEepromFormat eepromformat; - ret = 0; - i = 0; - ptr = (u8 *)&__osEepPifRam.ramarray; + ptr = (u8*)&__osEepPifRam.ramarray; if (address > EEPROM_MAXBLOCKS) { return -1; @@ -30,35 +28,64 @@ s32 osEepromRead(OSMesgQueue *mq, u8 address, u8 *buffer) { __osSiGetAccess(); ret = __osEepStatus(mq, &sdata); - if (ret != 0 || sdata.type != CONT_EEPROM) { +#if BUILD_VERSION >= VERSION_J + if (ret == 0) { + switch (type) { + case CONT_EEPROM: + if (address >= EEPROM_MAXBLOCKS) { + ret = CONT_RANGE_ERROR; + } + break; + case CONT_EEPROM | CONT_EEP16K: + if (address >= EEP16K_MAXBLOCKS) { + // not technically possible + ret = CONT_RANGE_ERROR; + } +#if BUILD_VERSION >= VERSION_L + else { + __osEepromRead16K = 1; + } +#endif + break; + default: + ret = CONT_NO_RESPONSE_ERROR; + } + } + + if (ret != 0) { + __osSiRelAccess(); + return ret; + } +#else + if (ret != 0 || sdata.type != CONT_EEPROM) + { return CONT_NO_RESPONSE_ERROR; } +#endif while (sdata.status & CONT_EEPROM_BUSY) { __osEepStatus(mq, &sdata); } __osPackEepReadData(address); - ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam.ramarray); + ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); // send command to pif osRecvMesg(mq, NULL, OS_MESG_BLOCK); - for (i = 0; i <= ARRLEN(__osEepPifRam.ramarray); i++) { __osEepPifRam.ramarray[i] = CONT_CMD_NOP; } __osEepPifRam.pifstatus = CONT_CMD_REQUEST_STATUS; - ret = __osSiRawStartDma(OS_READ, __osEepPifRam.ramarray); - + ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); // recv response __osContLastCmd = CONT_CMD_READ_EEPROM; osRecvMesg(mq, NULL, OS_MESG_BLOCK); - //skip the first 4 bytes for (i = 0; i < MAXCONTROLLERS; i++) { + // skip the first 4 bytes ptr++; } - eepromformat = *(__OSContEepromFormat *) ptr; + eepromformat = *(__OSContEepromFormat*)ptr; ret = CHNL_ERR(eepromformat); if (ret == 0) { @@ -66,36 +93,39 @@ s32 osEepromRead(OSMesgQueue *mq, u8 address, u8 *buffer) { *buffer++ = eepromformat.data[i]; } } - __osSiRelAccess(); - return ret; } -s32 __osPackEepReadData(u8 address) { - u8 *ptr; +static void __osPackEepReadData(u8 address) { + u8* ptr = (u8*)&__osEepPifRam.ramarray; __OSContEepromFormat eepromformat; - s32 i; + int i; - ptr = (u8 *)&__osEepPifRam.ramarray; - //@bug? i <= here, but in libreultra its i < +#if BUILD_VERSION < VERSION_J for (i = 0; i <= ARRLEN(__osEepPifRam.ramarray); i++) { __osEepPifRam.ramarray[i] = CONT_CMD_NOP; } +#endif + __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; + +#if BUILD_VERSION < VERSION_J for (i = 0; i < ARRLEN(eepromformat.data); i++) { eepromformat.data[i] = 0; } - //skip the first 4 bytes +#endif + for (i = 0; i < MAXCONTROLLERS; i++) { *ptr++ = 0; } - *(__OSContEepromFormat *)ptr = eepromformat; + + *(__OSContEepromFormat*)(ptr) = eepromformat; ptr += sizeof(__OSContEepromFormat); ptr[0] = CONT_CMD_END; } diff --git a/lib/src/os/osEepromWrite.c b/lib/src/io/conteepwrite.c similarity index 50% rename from lib/src/os/osEepromWrite.c rename to lib/src/io/conteepwrite.c index 94288775..395db295 100644 --- a/lib/src/os/osEepromWrite.c +++ b/lib/src/io/conteepwrite.c @@ -1,21 +1,24 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CE580 */ -#include "libultra_internal.h" +#include "PRinternal/macros.h" +#include "PR/os_internal.h" #include "PR/rcp.h" -#include "controller.h" -#include "siint.h" +#include "PRinternal/controller.h" +#include "PRinternal/siint.h" -void __osPackEepWriteData(u8 address, u8 *buffer); -s32 osEepromWrite(OSMesgQueue *mq, u8 address, u8 *buffer) { - s32 ret; +static void __osPackEepWriteData(u8 address, u8* buffer); +s32 osEepromWrite(OSMesgQueue* mq, u8 address, u8* buffer) { + s32 ret = 0; +#if BUILD_VERSION < VERSION_J int i; - u8 *ptr; +#endif + u8* ptr = (u8*)&__osEepPifRam.ramarray; __OSContEepromFormat eepromformat; OSContStatus sdata; - - ret = 0; - ptr = (u8 *)&__osEepPifRam.ramarray; +#if BUILD_VERSION >= VERSION_L + u8 temp[8]; +#endif if (address > EEPROM_MAXBLOCKS) { return -1; @@ -24,14 +27,50 @@ s32 osEepromWrite(OSMesgQueue *mq, u8 address, u8 *buffer) { __osSiGetAccess(); ret = __osEepStatus(mq, &sdata); - if (ret != 0 || sdata.type != CONT_EEPROM) { +#if BUILD_VERSION >= VERSION_J + if (ret == 0) { + switch (type) { + case CONT_EEPROM: + if (address >= EEPROM_MAXBLOCKS) { + ret = CONT_RANGE_ERROR; + } + break; + case CONT_EEPROM | CONT_EEP16K: + if (address >= EEP16K_MAXBLOCKS) { + // not technically possible + ret = CONT_RANGE_ERROR; + } +#if BUILD_VERSION >= VERSION_L + else if (__osEepromRead16K) { + __osEepromRead16K = 0; + __osSiRelAccess(); + osEepromRead(mq, (address ^ 1), temp); + __osSiGetAccess(); + } +#endif + break; + default: + ret = CONT_NO_RESPONSE_ERROR; + } + } + + if (ret != 0) { + __osSiRelAccess(); + return ret; + } +#else + if (ret != 0 || sdata.type != CONT_EEPROM) + { return CONT_NO_RESPONSE_ERROR; } +#endif + while (sdata.status & CONT_EEPROM_BUSY) { __osEepStatus(mq, &sdata); } + __osPackEepWriteData(address, buffer); - ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); //send command to pif + ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); // send command to pif osRecvMesg(mq, NULL, OS_MESG_BLOCK); for (i = 0; i <= ARRLEN(__osEepPifRam.ramarray); i++) { @@ -39,63 +78,75 @@ s32 osEepromWrite(OSMesgQueue *mq, u8 address, u8 *buffer) { } __osEepPifRam.pifstatus = CONT_CMD_REQUEST_STATUS; - ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); //recv response + + ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); // recv response __osContLastCmd = CONT_CMD_WRITE_EEPROM; osRecvMesg(mq, NULL, OS_MESG_BLOCK); - //skip the first 4 bytes - for (i = 0; i < MAXCONTROLLERS; i++) { + + // skip the first 4 bytes +#if BUILD_VERSION >= VERSION_J + ptr += 4; +#else + for (i = 0; i < 4; i++) { ptr++; } - eepromformat = *(__OSContEepromFormat *)ptr; +#endif - //probably indicates an error, from PIF - ret = CHNL_ERR(eepromformat); //TODO: remove magic constants + eepromformat = *(__OSContEepromFormat*)ptr; + + ret = CHNL_ERR(eepromformat); __osSiRelAccess(); return ret; } -void __osPackEepWriteData(u8 address, u8 *buffer) { - u8 *ptr; +static void __osPackEepWriteData(u8 address, u8* buffer) { + u8* ptr = (u8*)&__osEepPifRam.ramarray; __OSContEepromFormat eepromformat; int i; - ptr = (u8 *)&__osEepPifRam.ramarray; + +#if BUILD_VERSION < VERSION_J for (i = 0; i < ARRLEN(__osEepPifRam.ramarray) + 1; i++) { __osEepPifRam.ramarray[i] = CONT_CMD_NOP; } +#endif __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++; } - //skip the first 4 bytes + for (i = 0; i < MAXCONTROLLERS; i++) { *ptr++ = 0; } - *(__OSContEepromFormat *)(ptr) = eepromformat; + + *(__OSContEepromFormat*)(ptr) = eepromformat; ptr += sizeof(__OSContEepromFormat); ptr[0] = CONT_CMD_END; } -s32 __osEepStatus(OSMesgQueue *mq, OSContStatus *data) { - s32 ret; - s32 i; - u8 *ptr; +s32 __osEepStatus(OSMesgQueue* mq, OSContStatus* data) { + s32 ret = 0; + int i; + u8* ptr = (u8*)__osEepPifRam.ramarray; __OSContRequesFormat 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 < MAXCONTROLLERS; i++) //zero 4 bytes? - *ptr++ = 0; + ptr = (u8*)__osEepPifRam.ramarray; + + for (i = 0; i < MAXCONTROLLERS; i++) { + *ptr++ = CONT_CMD_REQUEST_STATUS; + } + requestformat.dummy = CONT_CMD_NOP; requestformat.txsize = CONT_CMD_REQUEST_STATUS_TX; requestformat.rxsize = CONT_CMD_REQUEST_STATUS_RX; @@ -104,28 +155,38 @@ s32 __osEepStatus(OSMesgQueue *mq, OSContStatus *data) { requestformat.typel = CONT_CMD_NOP; requestformat.status = CONT_CMD_NOP; requestformat.dummy1 = CONT_CMD_NOP; - *(__OSContRequesFormat *)ptr = requestformat; + *(__OSContRequesFormat*)ptr = requestformat; ptr += sizeof(__OSContRequesFormat); *ptr = CONT_CMD_END; ret = __osSiRawStartDma(OS_WRITE, &__osEepPifRam); osRecvMesg(mq, NULL, OS_MESG_BLOCK); - __osContLastCmd = 5; +#if BUILD_VERSION >= VERSION_J + __osContLastCmd = CONT_CMD_END; +#else + __osContLastCmd = CONT_CMD_WRITE_EEPROM; +#endif ret = __osSiRawStartDma(OS_READ, &__osEepPifRam); osRecvMesg(mq, NULL, OS_MESG_BLOCK); - if (ret != 0) + if (ret != 0) { return ret; + } - ptr = (u8 *)&__osEepPifRam; - for (i = 0; i < MAXCONTROLLERS; i++) + ptr = (u8*)&__osEepPifRam; + + for (i = 0; i < MAXCONTROLLERS; i++) { *ptr++ = 0; + } - requestformat = *(__OSContRequesFormat *)ptr; + requestformat = *(__OSContRequesFormat*)ptr; data->errno = CHNL_ERR(requestformat); data->type = (requestformat.typel << 8) | requestformat.typeh; data->status = requestformat.status; - if (data->errno != 0) + + if (data->errno != 0) { return data->errno; + } + return 0; } diff --git a/lib/src/io/contpfs.c b/lib/src/io/contpfs.c new file mode 100644 index 00000000..87714e00 --- /dev/null +++ b/lib/src/io/contpfs.c @@ -0,0 +1,395 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D52EC */ +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PR/os_version.h" +#include "PRinternal/controller.h" +#include "PR/rmon.h" + +#if BUILD_VERSION >= VERSION_J +__OSInode __osPfsInodeCache ALIGNED(0x8); +s32 __osPfsInodeCacheChannel = -1; +u8 __osPfsInodeCacheBank = 250; +#endif + +u16 __osSumcalc(u8* ptr, int length) { + int i; + u32 sum = 0; + u8* tmp = ptr; + + for (i = 0; i < length; i++) { + sum += *tmp++; +#if BUILD_VERSION < VERSION_J + sum = sum & 0xFFFF; +#endif + } + +#if BUILD_VERSION >= VERSION_J + return sum & 0xFFFF; +#else + return sum; +#endif +} + +s32 __osIdCheckSum(u16* ptr, u16* csum, u16* icsum) { + u16 data = 0; + u32 j; + + *csum = *icsum = 0; + + for (j = 0; j < ((sizeof(__OSPackId) - sizeof(u32)) / sizeof(u8)); j += 2) { + data = *(u16*)((u32)ptr + j); + *csum += data; + *icsum += ~data; + } + + return 0; +} + +s32 __osRepairPackId(OSPfs* pfs, __OSPackId* badid, __OSPackId* newid) { + s32 ret = 0; + u8 temp[BLOCKSIZE]; + u8 comp[BLOCKSIZE]; + u8 mask = 0; + int i; + int j; + u16 index[4]; + +#if BUILD_VERSION >= VERSION_J + j = 0; +#else + SET_ACTIVEBANK_TO_ZERO(); +#endif + + newid->repaired = -1; + newid->random = osGetCount(); + newid->serial_mid = badid->serial_mid; + newid->serial_low = badid->serial_low; + +#if BUILD_VERSION >= VERSION_J + SET_ACTIVEBANK_TO_ZERO(); +#else + j = 0; +#endif + do { + ERRCK(SELECT_BANK(pfs, j)); + ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, temp)); + + temp[0] = j | 0x80; + + for (i = 1; i < BLOCKSIZE; i++) { + temp[i] = ~temp[i]; + } + + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, 0, temp, FALSE)); + ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, comp)); + + for (i = 0; i < BLOCKSIZE; i++) { + if (comp[i] != temp[i]) { + break; + } + } + + if (i != BLOCKSIZE) { + break; + } + + if (j > 0) { + ERRCK(SELECT_BANK(pfs, 0)); + ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, (u8*)temp)); + + if (temp[0] != 0x80) { + break; + } + } + + j++; + } while (j < PFS_MAX_BANKS); + +#if BUILD_VERSION >= VERSION_J + SET_ACTIVEBANK_TO_ZERO(); +#else + ERRCK(SELECT_BANK(pfs, 0)); +#endif + + mask = (j > 0) ? 1 : 0; + + newid->deviceid = (badid->deviceid & (u16)~1) | 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 < ARRLEN(index); i++) { + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, index[i], (u8*)newid, TRUE)); + } + + ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, (u8*)temp)); + + for (i = 0; i < BLOCKSIZE; i++) { + if (temp[i] != ((u8*)newid)[i]) { +#if BUILD_VERSION >= VERSION_J + return PFS_ERR_DEVICE; +#else + return PFS_ERR_ID_FATAL; +#endif + } + } + return 0; +} + +s32 __osCheckPackId(OSPfs* pfs, __OSPackId* temp) { + u16 index[4]; + s32 ret = 0; + u16 sum; + u16 isum; + int i; + int j; + + SET_ACTIVEBANK_TO_ZERO(); + index[0] = PFS_ID_0AREA; + index[1] = PFS_ID_1AREA; + index[2] = PFS_ID_2AREA; + index[3] = PFS_ID_3AREA; + for (i = 1; i < ARRLEN(index); i++) { + ERRCK(__osContRamRead(pfs->queue, pfs->channel, index[i], (u8*)temp)); + __osIdCheckSum((u16*)temp, &sum, &isum); + if (temp->checksum == sum && temp->inverted_checksum == isum) { + break; + } + } + + if (i == ARRLEN(index)) { + return PFS_ERR_ID_FATAL; + } + + for (j = 0; j < ARRLEN(index); j++) { + if (j != i) { + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, index[j], (u8*)temp, TRUE)); + } + } + + return 0; +} + +s32 __osGetId(OSPfs* pfs) { +#if BUILD_VERSION < VERSION_J + int k; +#endif + u16 sum; + u16 isum; + u8 temp[BLOCKSIZE]; + __OSPackId newid; + s32 ret; + __OSPackId* id; + + SET_ACTIVEBANK_TO_ZERO(); + ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, (u8*)temp)); + __osIdCheckSum((u16*)temp, &sum, &isum); + id = (__OSPackId*)temp; + + if (id->checksum != sum || id->inverted_checksum != isum) { + ret = __osCheckPackId(pfs, id); + + if (ret == PFS_ERR_ID_FATAL) { + ERRCK(__osRepairPackId(pfs, id, &newid)); + id = &newid; + } else if (ret != 0) { + return ret; + } + } + + if ((id->deviceid & 1) == 0) { + ERRCK(__osRepairPackId(pfs, id, &newid)); + id = &newid; + + if ((id->deviceid & 1) == 0) { + return PFS_ERR_DEVICE; + } + } + +#if BUILD_VERSION >= VERSION_J + bcopy(id, pfs->id, BLOCKSIZE); +#else + for (k = 0; k < ARRLEN(pfs->id); k++) { + pfs->id[k] = ((u8 *)id)[k]; + } +#endif + pfs->version = id->version; + pfs->banks = id->banks; + pfs->inode_start_page = 1 + DEF_DIR_PAGES + (2 * pfs->banks); + pfs->dir_size = 16; + pfs->inode_table = PFS_ONE_PAGE; + pfs->minode_table = (1 + pfs->banks) * PFS_ONE_PAGE; + pfs->dir_table = pfs->minode_table + pfs->banks * PFS_ONE_PAGE; + ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_LABEL_AREA, pfs->label)); + return 0; +} + +s32 __osCheckId(OSPfs* pfs) { +#if BUILD_VERSION < VERSION_J + int k; +#endif + u8 temp[BLOCKSIZE]; + s32 ret; + +#if BUILD_VERSION >= VERSION_J + if (pfs->activebank != 0) { + ret = __osPfsSelectBank(pfs, 0); + + if (ret == PFS_ERR_NEW_PACK) { + ret = __osPfsSelectBank(pfs, 0); + } + + if (ret != 0) { + return ret; + } + } +#else + SET_ACTIVEBANK_TO_ZERO(); +#endif + + ret = __osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, (u8*)temp); + + if (ret != 0) { + if (ret != PFS_ERR_NEW_PACK) { + return ret; + } + ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, (u8*)temp)); + } + +#if BUILD_VERSION >= VERSION_J + if (bcmp(pfs->id, temp, BLOCKSIZE) != 0) { + return PFS_ERR_NEW_PACK; + } +#else + for (k = 0; k < ARRLEN(temp); k++) { + if (pfs->id[k] != temp[k]) + return PFS_ERR_NEW_PACK; + } +#endif + + return 0; +} + +s32 __osPfsRWInode(OSPfs* pfs, __OSInode* inode, u8 flag, u8 bank) { + u8 sum; + int j; + s32 ret; + int offset; + u8* addr; + +#if BUILD_VERSION >= VERSION_J + if (flag == PFS_READ && bank == __osPfsInodeCacheBank && (pfs->channel == __osPfsInodeCacheChannel)) { + bcopy(&__osPfsInodeCache, inode, sizeof(__OSInode)); + return 0; + } +#endif + + SET_ACTIVEBANK_TO_ZERO(); + + 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*)inode->inode_page + j * BLOCKSIZE); + + if (flag == PFS_WRITE) { + ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->inode_table + bank * PFS_ONE_PAGE + j, addr, FALSE); + ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->minode_table + bank * PFS_ONE_PAGE + j, addr, FALSE); + } else { + ret = __osContRamRead(pfs->queue, pfs->channel, pfs->inode_table + bank * PFS_ONE_PAGE + j, addr); + } + + if (ret != 0) { + 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); + } + +#if BUILD_VERSION >= VERSION_J + sum = __osSumcalc((u8*)&inode->inode_page[offset], (PFS_INODE_SIZE_PER_PAGE - offset) * 2); +#endif + + 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, FALSE); + } + } +#if BUILD_VERSION < VERSION_J + else + { + for (j = 0; j < PFS_ONE_PAGE; j++) + { + addr = ((u8 *)inode->inode_page + j * 32); + ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->minode_table + bank * PFS_ONE_PAGE + j, addr, FALSE); + } + } +#endif + } + +#if BUILD_VERSION >= VERSION_J + __osPfsInodeCacheBank = bank; + bcopy(inode, &__osPfsInodeCache, sizeof(__OSInode)); + __osPfsInodeCacheChannel = pfs->channel; +#endif + + return 0; +} + +// This was moved into it's own file in 2.0J +#if BUILD_VERSION < VERSION_J +s32 __osPfsSelectBank(OSPfs* pfs) { + u8 temp[BLOCKSIZE]; + int i; + s32 ret = 0; + + for (i = 0; i < BLOCKSIZE; i++) { + temp[i] = pfs->activebank; + } + + ret = __osContRamWrite(pfs->queue, pfs->channel, CONT_BLOCK_DETECT, temp, FALSE); + return ret; +} +#endif + +#ifdef _DEBUG +s32 __osDumpId(OSPfs* pfs) { + u8 id[BLOCKSIZE]; + __OSPackId* temp; + s32 ret; + + ERRCK(__osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, id)); + + temp = (__OSPackId*)id; + rmonPrintf("repaired %x\n", temp->repaired); + rmonPrintf("random %x\n", temp->random); + rmonPrintf("serial_mid %llu\n", temp->serial_mid); + rmonPrintf("serial_low %llu\n", temp->serial_low); + rmonPrintf("deviceid %x\n", temp->deviceid); + rmonPrintf("banks %x\n", temp->banks); + rmonPrintf("version %x\n", temp->version); + rmonPrintf("checksum %x\n", temp->checksum); + rmonPrintf("inverted_checksum %x\n", temp->inverted_checksum); + return 0; +} +#endif diff --git a/lib/src/io/contramread.c b/lib/src/io/contramread.c new file mode 100644 index 00000000..725d9b8c --- /dev/null +++ b/lib/src/io/contramread.c @@ -0,0 +1,174 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CDCA0 */ +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PRinternal/controller.h" +#include "PRinternal/siint.h" + +#define READFORMAT(ptr) ((__OSContRamReadFormat*)(ptr)) + +#if BUILD_VERSION >= VERSION_J +s32 __osPfsLastChannel = -1; + +s32 __osContRamRead(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { + s32 ret = 0; + s32 i; + u8* ptr; + s32 retry = 2; + + __osSiGetAccess(); + + do { + ptr = (u8*)&__osPfsPifRam; + + if (__osContLastCmd != CONT_CMD_READ_PAK || (u32)__osPfsLastChannel != channel) { + __osContLastCmd = CONT_CMD_READ_PAK; + __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_PAK_TX; + READFORMAT(ptr)->rxsize = CONT_CMD_READ_PAK_RX; + READFORMAT(ptr)->cmd = CONT_CMD_READ_PAK; + READFORMAT(ptr)->datacrc = 0xFF; + + ptr[sizeof(__OSContRamReadFormat)] = CONT_CMD_END; + } else { + ptr += channel; + } + +#if BUILD_VERSION >= VERSION_J + READFORMAT(ptr)->addrh = address >> 3; + READFORMAT(ptr)->addrl = (u8)((address << 5) | __osContAddressCrc(address)); +#else + READFORMAT(ptr)->address = (address << 0x5) | __osContAddressCrc(address); +#endif + + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + ret = CHNL_ERR(*READFORMAT(ptr)); + + if (!ret) { + if (__osContDataCrc(READFORMAT(ptr)->data) != READFORMAT(ptr)->datacrc) { + ret = __osPfsGetStatus(mq, channel); + + if (ret) { + break; + } else { + ret = PFS_ERR_CONTRFAIL; + } + } else { + bcopy(READFORMAT(ptr)->data, buffer, BLOCKSIZE); + } + } else { + ret = PFS_ERR_NOPACK; + } + } while ((ret == PFS_ERR_CONTRFAIL) && (retry-- >= 0)); + __osSiRelAccess(); + return ret; +} +#else + +static void __osPackRamReadData(int channel, u16 address); + +s32 __osContRamRead(OSMesgQueue* mq, int channel, u16 address, u8* buffer) { + s32 ret = 0; + int i; + u8* ptr = (u8*)&__osPfsPifRam; + __OSContRamReadFormat ramreadformat; + int retry = 2; + + __osSiGetAccess(); + __osContLastCmd = CONT_CMD_READ_PAK; + __osPackRamReadData(channel, address); + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + do { + for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus + __osPfsPifRam.ramarray[i] = 0xFFU; + } + __osPfsPifRam.pifstatus = CONT_CMD_REQUEST_STATUS; + + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + ptr = (u8*)&__osPfsPifRam; + + if (channel != 0) { + for (i = 0; i < channel; i++) { + ptr++; + } + } + + ramreadformat = *READFORMAT(ptr); + + ret = CHNL_ERR(ramreadformat); + if (ret == 0) { + u8 c = __osContDataCrc((u8*)&ramreadformat.data); + if (c != ramreadformat.datacrc) { + ret = __osPfsGetStatus(mq, channel); + + if (ret != 0) { + __osSiRelAccess(); + return ret; + } + + ret = PFS_ERR_CONTRFAIL; + } else { + for (i = 0; i < ARRLEN(ramreadformat.data); i++) { + *buffer++ = ramreadformat.data[i]; + } + } + } + } while ((ret == PFS_ERR_CONTRFAIL) && retry-- >= 0); + + __osSiRelAccess(); + + return ret; +} + +static void __osPackRamReadData(int channel, u16 address) { + u8 *ptr; + __OSContRamReadFormat ramreadformat; + int i; + + ptr = (u8 *)__osPfsPifRam.ramarray; + + for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus + __osPfsPifRam.ramarray[i] = 0; + } + + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + ramreadformat.dummy = CONT_CMD_NOP; + ramreadformat.txsize = CONT_CMD_READ_PAK_TX; + ramreadformat.rxsize = CONT_CMD_READ_PAK_RX; + ramreadformat.cmd = CONT_CMD_READ_PAK; + ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); + ramreadformat.datacrc = CONT_CMD_NOP; + + for (i = 0; i < ARRLEN(ramreadformat.data); i++) { + ramreadformat.data[i] = CONT_CMD_NOP; + } + + if (channel != 0) { + for (i = 0; i < channel; i++) { + *ptr++ = CONT_CMD_REQUEST_STATUS; + } + } + + *(__OSContRamReadFormat *)ptr = ramreadformat; + ptr += sizeof(__OSContRamReadFormat); + ptr[0] = CONT_CMD_END; +} + +#endif + diff --git a/lib/src/io/contramwrite.c b/lib/src/io/contramwrite.c new file mode 100644 index 00000000..c1ba2bb6 --- /dev/null +++ b/lib/src/io/contramwrite.c @@ -0,0 +1,179 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CD8F0 */ + +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PRinternal/controller.h" +#include "PRinternal/siint.h" + +extern s32 __osPfsLastChannel; + +#define READFORMAT(ptr) ((__OSContRamReadFormat*)(ptr)) + +#if BUILD_VERSION >= VERSION_J +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 != TRUE) && (address < PFS_LABEL_AREA) && (address != 0)) { + return 0; + } + + __osSiGetAccess(); + + do { + ptr = (u8*)__osPfsPifRam.ramarray; + + if (__osContLastCmd != CONT_CMD_WRITE_PAK || (u32)__osPfsLastChannel != channel) { + __osContLastCmd = CONT_CMD_WRITE_PAK; + __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_WRITE_PAK_TX; + READFORMAT(ptr)->rxsize = CONT_CMD_WRITE_PAK_RX; + READFORMAT(ptr)->cmd = CONT_CMD_WRITE_PAK; + READFORMAT(ptr)->datacrc = 0xFF; + + ptr[sizeof(__OSContRamReadFormat)] = CONT_CMD_END; + } else { + ptr += channel; + } + +#if BUILD_VERSION >= VERSION_J + READFORMAT(ptr)->addrh = address >> 3; + READFORMAT(ptr)->addrl = ((address << 5) | __osContAddressCrc(address)); +#else + READFORMAT(ptr)->address = (address << 0x5) | __osContAddressCrc(address); +#endif + + 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 = CHNL_ERR(*READFORMAT(ptr)); + + if (!ret) { + if (crc != READFORMAT(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; +} +#else + +static void __osPackRamWriteData(int channel, u16 address, u8 *buffer); + +s32 __osContRamWrite(OSMesgQueue* mq, int channel, u16 address, u8* buffer, int force) { + s32 ret = 0; + s32 i; + u8* ptr = (u8*)&__osPfsPifRam; + __OSContRamReadFormat ramreadformat; + s32 retry = 2; + u8 crc; + + if ((force != TRUE) && (address < PFS_LABEL_AREA) && (address != 0)) { + return 0; + } + + __osSiGetAccess(); + __osContLastCmd = CONT_CMD_WRITE_PAK; + __osPackRamWriteData(channel, address, buffer); + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + do { + for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus + __osPfsPifRam.ramarray[i] = 0xFFU; + } + __osPfsPifRam.pifstatus = CONT_CMD_REQUEST_STATUS; + + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + ptr = (u8*)&__osPfsPifRam; + + if (channel != 0) { + for (i = 0; i < channel; i++) { + ptr++; + } + } + + ramreadformat = *READFORMAT(ptr); + + ret = CHNL_ERR(ramreadformat); + if (ret == 0) { + if (__osContDataCrc(buffer) != ramreadformat.datacrc) { + ret = __osPfsGetStatus(mq, channel); + + if (ret != 0) { + __osSiRelAccess(); + return ret; + } + + ret = PFS_ERR_CONTRFAIL; + } + } + } while ((ret == PFS_ERR_CONTRFAIL) && retry-- >= 0); + + __osSiRelAccess(); + + return ret; +} + +static void __osPackRamWriteData(int channel, u16 address, u8 *buffer) { + u8 *ptr; + __OSContRamReadFormat ramreadformat; + int i; + + ptr = (u8 *)__osPfsPifRam.ramarray; + + for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus + __osPfsPifRam.ramarray[i] = 0; + } + + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + ramreadformat.dummy = CONT_CMD_NOP; + ramreadformat.txsize = CONT_CMD_WRITE_PAK_TX; + ramreadformat.rxsize = CONT_CMD_WRITE_PAK_RX; + ramreadformat.cmd = CONT_CMD_WRITE_PAK; + ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); + ramreadformat.datacrc = CONT_CMD_NOP; + + for (i = 0; i < ARRLEN(ramreadformat.data); i++) { + ramreadformat.data[i] = *buffer++; + } + + if (channel != 0) { + for (i = 0; i < channel; i++) { + *ptr++ = CONT_CMD_REQUEST_STATUS; + } + } + + *(__OSContRamReadFormat *)ptr = ramreadformat; + ptr += sizeof(__OSContRamReadFormat); + ptr[0] = CONT_CMD_END; +} + +#endif diff --git a/lib/src/os/contreaddata.c b/lib/src/io/contreaddata.c similarity index 61% rename from lib/src/os/contreaddata.c rename to lib/src/io/contreaddata.c index 175bfca8..c88bdf67 100644 --- a/lib/src/os/contreaddata.c +++ b/lib/src/io/contreaddata.c @@ -1,74 +1,79 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CCFE0 */ -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" -#include "controller.h" -#include "siint.h" +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PRinternal/controller.h" +#include "PRinternal/siint.h" static void __osPackReadData(void); -s32 osContStartReadData(OSMesgQueue *mq) { - s32 ret; + +s32 osContStartReadData(OSMesgQueue* mq) { + s32 ret = 0; int i; - ret = 0; + __osSiGetAccess(); - if (__osContLastCmd != CONT_CMD_READ_BUTTON) { + if (__osContLastCmd != CONT_CMD_READ_BUTTON) { __osPackReadData(); - ret = __osSiRawStartDma(OS_WRITE, &__osContPifRam); + ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); osRecvMesg(mq, NULL, OS_MESG_BLOCK); } for (i = 0; i <= ARRLEN(__osContPifRam.ramarray); i++) { __osContPifRam.ramarray[i] = CONT_CMD_RESET; } - __osContPifRam.pifstatus = CONT_CMD_REQUEST_STATUS; - ret = __osSiRawStartDma(OS_READ, &__osContPifRam); + ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); __osContLastCmd = CONT_CMD_READ_BUTTON; __osSiRelAccess(); + return ret; } -void osContGetReadData(OSContPad *data) { - u8 *ptr; +void osContGetReadData(OSContPad* data) { + u8* ptr = (u8*)__osContPifRam.ramarray; __OSContReadFormat readformat; int i; - ptr = (u8 *)&__osContPifRam.ramarray; + for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContReadFormat), data++) { - readformat = *(__OSContReadFormat *)ptr; + 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; + + if (data->errno != 0) { + continue; } + + data->button = readformat.button; + data->stick_x = readformat.stick_x; + data->stick_y = readformat.stick_y; } } static void __osPackReadData(void) { - u8 *ptr; + u8* ptr = (u8*)__osContPifRam.ramarray; __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.button = 0xFFFF; readformat.stick_x = -1; readformat.stick_y = -1; - for(i=0; i < __osMaxControllers; i++) { + + for (i = 0; i < __osMaxControllers; i++) { *(__OSContReadFormat*)ptr = readformat; ptr += sizeof(__OSContReadFormat); } + *ptr = CONT_CMD_END; } diff --git a/lib/src/io/controller.c b/lib/src/io/controller.c new file mode 100644 index 00000000..1c27194a --- /dev/null +++ b/lib/src/io/controller.c @@ -0,0 +1,109 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CCC20 */ + +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PRinternal/controller.h" +#include "PRinternal/siint.h" + +#define HALF_MIL_CYLCES 500000U +#define ONE_MIL_CYLCES 1000000U +#define HALF_A_SECOND HALF_MIL_CYLCES * osClockRate / ONE_MIL_CYLCES + +OSPifRam __osContPifRam; +u8 __osContLastCmd; +u8 __osMaxControllers; + +OSTimer __osEepromTimer; +OSMesgQueue __osEepromTimerQ ALIGNED(0x8); +OSMesg __osEepromTimerMsg; + +s32 __osContinitialized = FALSE; +extern OSTime osClockRate; + +s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data) { + OSMesg dummy; + s32 ret = 0; + OSTime t; + OSTimer mytimer; + OSMesgQueue timerMesgQueue; + + if (__osContinitialized) { + return 0; + } + + __osContinitialized = TRUE; + + t = osGetTime(); + if (HALF_A_SECOND > t) { + osCreateMesgQueue(&timerMesgQueue, &dummy, 1); + osSetTimer(&mytimer, HALF_A_SECOND - t, 0, &timerMesgQueue, &dummy); + osRecvMesg(&timerMesgQueue, &dummy, OS_MESG_BLOCK); + } + + __osMaxControllers = MAXCONTROLLERS; + + __osPackRequestData(CONT_CMD_REQUEST_STATUS); + + ret = __osSiRawStartDma(OS_WRITE, __osContPifRam.ramarray); + osRecvMesg(mq, &dummy, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, __osContPifRam.ramarray); + 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; + __OSContRequesFormat requestHeader; + int i; + u8 bits = 0; + + ptr = (u8*)__osContPifRam.ramarray; + for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(requestHeader), data++) { + requestHeader = *(__OSContRequesFormat*)ptr; + data->errno = CHNL_ERR(requestHeader); + + if (data->errno != 0) { + continue; + } + + data->type = requestHeader.typel << 8 | requestHeader.typeh; + data->status = requestHeader.status; + bits |= 1 << i; + } + *pattern = bits; +} + +void __osPackRequestData(u8 cmd) { + u8* ptr; + __OSContRequesFormat requestHeader; + s32 i; + + for (i = 0; i <= ARRLEN(__osContPifRam.ramarray); i++) { + __osContPifRam.ramarray[i] = 0; + } + + __osContPifRam.pifstatus = CONT_CMD_EXE; + ptr = (u8*)__osContPifRam.ramarray; + requestHeader.dummy = CONT_CMD_NOP; + requestHeader.txsize = CONT_CMD_RESET_TX; + requestHeader.rxsize = CONT_CMD_RESET_RX; + requestHeader.cmd = cmd; + requestHeader.typeh = CONT_CMD_NOP; + requestHeader.typel = CONT_CMD_NOP; + requestHeader.status = CONT_CMD_NOP; + requestHeader.dummy1 = CONT_CMD_NOP; + + for (i = 0; i < __osMaxControllers; i++) { + *(__OSContRequesFormat*)ptr = requestHeader; + ptr += sizeof(requestHeader); + } + *ptr = CONT_CMD_END; +} diff --git a/lib/src/io/crc.c b/lib/src/io/crc.c new file mode 100644 index 00000000..9aa833e6 --- /dev/null +++ b/lib/src/io/crc.c @@ -0,0 +1,149 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CD770 */ + +/** + * File: crc.c + * Description: Functions to compute Cyclic Redundancy Check for specific addresses and data. + */ +#include "PR/os_internal.h" +#include + +#if BUILD_VERSION >= VERSION_J + +#define ADDRESS_CRC_MESSAGE_LENGTH 10 +#define ADDRESS_CRC_LENGTH 5 +#define ADDRESS_CRC_GENERATOR 0x15 +#define ADDRESS_CRC_MASK ((1 << ADDRESS_CRC_LENGTH) - 1) + +/** + * CRC-5 with the generating polynomial \f$ x^5 + x^4 + x^2 + 1 \f$, AKA 0x15 = 0b(1)1 0101. + * It only works on the bits from 0x7FF = 11 11111111, i.e. 10 bits. + * + * Usually used as __osContAddressCrc(addr) | (addr << 5) to add the CRC to the end. The overall length of 10 + 5 bits + * allows the address + CRC to fit into one s16. + * + * `addr` is the address of a block in the mempak, only valid up to 0x7FF. + */ +u8 __osContAddressCrc(u16 addr) { + u32 temp = 0; + u32 i = (1 << ADDRESS_CRC_MESSAGE_LENGTH); + + do { + // temp is used as a shift register for the CRC + temp <<= 1; + + if ((u32)addr & i) { + if (temp & (1 << ADDRESS_CRC_LENGTH)) { + // Same as temp++; temp ^= 0x15 since last bit always 0 after the shift + temp ^= ADDRESS_CRC_GENERATOR - 1; + } else { + ++temp; + } + } else if (temp & (1 << ADDRESS_CRC_LENGTH)) { + temp ^= ADDRESS_CRC_GENERATOR; + } + + i >>= 1; + } while (i != 0); + + // Acts like 5 bits of 0s are appended to addr + i = ADDRESS_CRC_LENGTH; + do { + temp <<= 1; + if (temp & (1 << ADDRESS_CRC_LENGTH)) { + temp ^= ADDRESS_CRC_GENERATOR; + } + } while (--i != 0); + + // Discard the irrelevant bits above the actual remainder + return temp & ADDRESS_CRC_MASK; +} + +#define DATA_CRC_MESSAGE_BYTES 32 +#define DATA_CRC_LENGTH 8 +#define DATA_CRC_GENERATOR 0x85 + +/** + * CRC-8 with generating polynomial \f$ x^8 + x^7 + x^2 + 1 \f$, AKA 0x85 = 0b(1) 1000 0101. + * Expects exactly 0x20 = 32 bytes of data. + */ +u8 __osContDataCrc(u8* data) { + u32 temp = 0; + u32 i; + u32 j; + + for (i = DATA_CRC_MESSAGE_BYTES; i; --i) { + // Loop over each bit in the byte starting with most significant + for (j = (1 << (DATA_CRC_LENGTH - 1)); j; j >>= 1) { + temp <<= 1; + + if ((*data & j) != 0) { + if ((temp & (1 << DATA_CRC_LENGTH)) != 0) { + // Same as ret++; ret ^= 0x85 since last bit always 0 after the shift + temp ^= DATA_CRC_GENERATOR - 1; + } else { + ++temp; + } + } else if (temp & (1 << DATA_CRC_LENGTH)) { + temp ^= DATA_CRC_GENERATOR; + } + } + + data++; + } + do { + temp <<= 1; + + if (temp & (1 << DATA_CRC_LENGTH)) { + temp ^= DATA_CRC_GENERATOR; + } + } while (++i < DATA_CRC_LENGTH); + + return temp; +} + +#else + +u8 __osContAddressCrc(u16 addr) { + u8 temp = 0; + u8 temp2; + int i; + + for (i = 0; i < 16; i++) { + temp2 = (temp & 0x10) ? 0x15 : 0; + + temp <<= 1; + temp |= (u8)((addr & 0x400) ? 1 : 0); + addr <<= 1; + temp ^= temp2; + } + + return temp & 0x1f; +} + +u8 __osContDataCrc(u8 *data) { + u8 temp = 0; + u8 temp2; + int i; + int j; + + for (i = 0; i <= 32; i++) { + for (j = 7; j > -1; j--) { + temp2 = (temp & 0x80) ? 0x85 : 0; + + temp <<= 1; + + if (i == 32) { + temp &= -1; + } else { + temp |= ((*data & (1 << j)) ? 1 : 0); + } + + temp ^= temp2; + } + data++; + } + return temp; +} + +#endif diff --git a/lib/src/os/devmgr.c b/lib/src/io/devmgr.c similarity index 65% rename from lib/src/os/devmgr.c rename to lib/src/io/devmgr.c index 5fa26c91..d84e0a97 100644 --- a/lib/src/os/devmgr.c +++ b/lib/src/io/devmgr.c @@ -1,57 +1,62 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D2760 */ -#include "libultra_internal.h" -#include "piint.h" -#include "osint.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PRinternal/piint.h" +#include "PR/os_internal_exception.h" -void __osDevMgrMain(void *args) { - OSIoMesg *mb; +void __osDevMgrMain(void* args) { + OSIoMesg* mb; OSMesg em; OSMesg dummy; s32 ret; - OSDevMgr *dm; - s32 messageSend; + OSDevMgr* dm; + s32 messageSend = 0; - messageSend = 0; + dm = (OSDevMgr*)args; 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; + 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); + blockInfo->dramAddr = (void*)((u32)blockInfo->dramAddr - blockInfo->sectorSize); } - if (info->transferMode == LEO_TRACK_MODE && mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_0) + + if (info->transferMode == LEO_TRACK_MODE && mb->piHandle->transferInfo.cmdType == LEO_CMD_TYPE_0) { messageSend = 1; - else + } 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); - osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); + __osEPiRawWriteIo(mb->piHandle, LEO_BM_CTL, (info->bmCtlShadow | 0x80000000)); - if (messageSend != 1) - break; - if (mb->piHandle->transferInfo.block[0].errStatus != LEO_ERROR_GOOD) - break; + readblock1: + osRecvMesg(dm->evtQueue, &em, OS_MESG_BLOCK); + osSendMesg(mb->hdr.retQueue, mb, OS_MESG_NOBLOCK); + + if (messageSend == 1 && mb->piHandle->transferInfo.block[0].errStatus == LEO_ERROR_GOOD) { messageSend = 0; + goto readblock1; } + osSendMesg(dm->acsQueue, NULL, OS_MESG_NOBLOCK); - if (mb->piHandle->transferInfo.blockNum == 1) + if (mb->piHandle->transferInfo.blockNum == 1) { osYieldThread(); + } } else { switch (mb->hdr.type) { case OS_MESG_TYPE_DMAREAD: @@ -64,13 +69,11 @@ void __osDevMgrMain(void *args) { 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); + 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); + 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); diff --git a/lib/src/io/dp.c b/lib/src/io/dp.c new file mode 100644 index 00000000..342681b5 --- /dev/null +++ b/lib/src/io/dp.c @@ -0,0 +1,18 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D6050 */ + +#include "PR/os_internal.h" +#include "PR/rcp.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +int __osDpDeviceBusy(void) { + register u32 stat = IO_READ(DPC_STATUS_REG); + + if (stat & DPC_STATUS_DMA_BUSY) { + return TRUE; + } else { + return FALSE; + } +} diff --git a/lib/src/os/osDpGetStatus.c b/lib/src/io/dpgetstat.c similarity index 51% rename from lib/src/os/osDpGetStatus.c rename to lib/src/io/dpgetstat.c index 68f2344e..ac1d00cf 100644 --- a/lib/src/os/osDpGetStatus.c +++ b/lib/src/io/dpgetstat.c @@ -1,9 +1,12 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D18D0 */ -#include "types.h" -#include "libultra_internal.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" -u32 osDpGetStatus(){ +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +u32 osDpGetStatus(void) { return IO_READ(DPC_STATUS_REG); } diff --git a/lib/src/io/dpsetnextbuf.c b/lib/src/io/dpsetnextbuf.c new file mode 100644 index 00000000..ee5caa3b --- /dev/null +++ b/lib/src/io/dpsetnextbuf.c @@ -0,0 +1,42 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D18E0 */ + +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/rcp.h" +#include "PRinternal/osint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 osDpSetNextBuffer(void* bufPtr, u64 size) { + register u32 stat; + +#ifdef _DEBUG + if ((u32)bufPtr & 0x7) { + __osError(ERR_OSDPSETNEXTBUFFER_ADDR, 1, bufPtr); + return -1; + } + if (size & 0x7) { + __osError(ERR_OSDPSETNEXTBUFFER_SIZE, 1, size); + return -1; + } +#endif + + if (__osDpDeviceBusy()) { + return -1; + } + + IO_WRITE(DPC_STATUS_REG, DPC_CLR_XBUS_DMEM_DMA); + + while (TRUE) { + stat = IO_READ(DPC_STATUS_REG); + if ((stat & DPC_STATUS_XBUS_DMEM_DMA) == 0) { + break; + } + } + + IO_WRITE(DPC_START_REG, osVirtualToPhysical(bufPtr)); + IO_WRITE(DPC_END_REG, osVirtualToPhysical(bufPtr) + size); + return 0; +} diff --git a/lib/src/os/osDpSetStatus.c b/lib/src/io/dpsetstat.c similarity index 61% rename from lib/src/os/osDpSetStatus.c rename to lib/src/io/dpsetstat.c index c14cb5a7..e4eee1a6 100644 --- a/lib/src/os/osDpSetStatus.c +++ b/lib/src/io/dpsetstat.c @@ -1,7 +1,11 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CD250 */ -#include "libultra_internal.h" +#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/lib/src/io/epirawdma.c b/lib/src/io/epirawdma.c new file mode 100644 index 00000000..19fe6605 --- /dev/null +++ b/lib/src/io/epirawdma.c @@ -0,0 +1,55 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D2680 */ + +#include "PRinternal/piint.h" +#include "PR/ultraerror.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osEPiRawStartDma(OSPiHandle* pihandle, s32 direction, u32 devAddr, void* dramAddr, u32 size) { + register u32 stat; + +#ifdef _DEBUG + if ((direction != OS_READ) && (direction != OS_WRITE)) { + __osError(ERR_OSPIRAWSTARTDMA_DIR, 1, direction); + return -1; + } + + if (devAddr & 0x1) { + __osError(ERR_OSPIRAWSTARTDMA_DEVADDR, 1, devAddr); + return -1; + } + + if ((u32)dramAddr & 0x7) { + __osError(ERR_OSPIRAWSTARTDMA_ADDR, 1, dramAddr); + return -1; + } + + if (size & 0x1) { + __osError(ERR_OSPIRAWSTARTDMA_SIZE, 1, size); + return -1; + } + + if ((size == 0) || (size > (16 * 1024 * 1024))) { + __osError(ERR_OSPIRAWSTARTDMA_RANGE, 1, size); + return -1; + } +#endif + + WAIT_ON_IOBUSY(stat); + 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/lib/src/io/epirawwrite.c b/lib/src/io/epirawwrite.c new file mode 100644 index 00000000..435a5716 --- /dev/null +++ b/lib/src/io/epirawwrite.c @@ -0,0 +1,25 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D6560 */ + +#include "PRinternal/piint.h" +#include "PR/ultraerror.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osEPiRawWriteIo(OSPiHandle* pihandle, u32 devAddr, u32 data) { + register u32 stat; + register u32 domain; + +#ifdef _DEBUG + if (devAddr & 0x3) { + __osError(ERR_OSPIRAWWRITEIO, 1, devAddr); + return -1; + } +#endif + + WAIT_ON_IOBUSY(stat); + IO_WRITE(pihandle->baseAddress | devAddr, data); + + return 0; +} diff --git a/lib/src/os/__osLeoInterrupt.c b/lib/src/io/leointerrupt.c similarity index 100% rename from lib/src/os/__osLeoInterrupt.c rename to lib/src/io/leointerrupt.c diff --git a/lib/src/io/motor.c b/lib/src/io/motor.c new file mode 100644 index 00000000..aeab77e6 --- /dev/null +++ b/lib/src/io/motor.c @@ -0,0 +1,289 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80071D30 */ + +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PR/os_version.h" +#include "PRinternal/controller.h" +#include "PRinternal/siint.h" + +#if BUILD_VERSION >= VERSION_J +static OSPifRam __MotorDataBuf[MAXCONTROLLERS]; + +#define READFORMAT(ptr) ((__OSContRamReadFormat*)(ptr)) + +s32 __osMotorAccess(OSPfs* pfs, s32 flag) { + int i; + s32 ret; + u8* ptr = (u8*)&__MotorDataBuf[pfs->channel]; + + if (!(pfs->status & PFS_MOTOR_INITIALIZED)) { + return 5; + } + + __osSiGetAccess(); + __MotorDataBuf[pfs->channel].pifstatus = CONT_CMD_EXE; + ptr += pfs->channel; + + for (i = 0; i < BLOCKSIZE; i++) { + READFORMAT(ptr)->data[i] = flag; + } + + __osContLastCmd = CONT_CMD_END; + __osSiRawStartDma(OS_WRITE, &__MotorDataBuf[pfs->channel]); + osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); + ret = __osSiRawStartDma(OS_READ, &__MotorDataBuf[pfs->channel]); + osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); + + ret = READFORMAT(ptr)->rxsize & CHNL_ERR_MASK; + if (!ret) { + if (!flag) { + if (READFORMAT(ptr)->datacrc != 0) { + ret = PFS_ERR_CONTRFAIL; + } + } else { + if (READFORMAT(ptr)->datacrc != 0xEB) { + ret = PFS_ERR_CONTRFAIL; + } + } + } + + __osSiRelAccess(); + + return ret; +} + +static void __osMakeMotorData(int channel, OSPifRam* mdata) { + u8* ptr = (u8*)mdata->ramarray; + __OSContRamReadFormat ramreadformat; + int i; + + ramreadformat.dummy = CONT_CMD_NOP; + ramreadformat.txsize = CONT_CMD_WRITE_PAK_TX; + ramreadformat.rxsize = CONT_CMD_WRITE_PAK_RX; + ramreadformat.cmd = CONT_CMD_WRITE_PAK; + ramreadformat.addrh = CONT_BLOCK_RUMBLE >> 3; + ramreadformat.addrl = (u8)(__osContAddressCrc(CONT_BLOCK_RUMBLE) | (CONT_BLOCK_RUMBLE << 5)); + + if (channel != 0) { + for (i = 0; i < channel; i++) { + *ptr++ = CONT_CMD_REQUEST_STATUS; + } + } + + *READFORMAT(ptr) = ramreadformat; + ptr += sizeof(__OSContRamReadFormat); + ptr[0] = CONT_CMD_END; +} + +s32 osMotorInit(OSMesgQueue* mq, OSPfs* pfs, int channel) { + s32 ret; + u8 temp[32]; + + pfs->queue = mq; + pfs->channel = channel; + pfs->activebank = 0xFF; + pfs->status = 0; + + ret = SELECT_BANK(pfs, 0xFE); + + if (ret == PFS_ERR_NEW_PACK) { + ret = SELECT_BANK(pfs, 0x80); + } + + if (ret != 0) { + return ret; + } + + ret = __osContRamRead(mq, channel, CONT_BLOCK_DETECT, temp); + + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } else if (temp[31] == 254) { + return PFS_ERR_DEVICE; + } + + ret = SELECT_BANK(pfs, 0x80); + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } + + ret = __osContRamRead(mq, channel, CONT_BLOCK_DETECT, temp); + if (ret == PFS_ERR_NEW_PACK) { + ret = PFS_ERR_CONTRFAIL; + } + + if (ret != 0) { + return ret; + } else if (temp[31] != 0x80) { + return PFS_ERR_DEVICE; + } + + if (!(pfs->status & PFS_MOTOR_INITIALIZED)) { + __osMakeMotorData(channel, &__MotorDataBuf[channel]); + } + + pfs->status = PFS_MOTOR_INITIALIZED; + return 0; +} + +#else + +OSPifRam _MotorStopData[MAXCONTROLLERS] ALIGNED(0x8); +OSPifRam _MotorStartData[MAXCONTROLLERS] ALIGNED(0x8); +u8 _motorstopbuf[32] ALIGNED(0x8); +u8 _motorstartbuf[32] ALIGNED(0x8); + +s32 osMotorStop(OSPfs *pfs) { + int i; + s32 ret; + u8 *ptr; + __OSContRamReadFormat ramreadformat; + + ptr = (u8 *)&__osPfsPifRam; + + __osSiGetAccess(); + + __osContLastCmd = CONT_CMD_WRITE_PAK; + __osSiRawStartDma(OS_WRITE, &_MotorStopData[pfs->channel]); + osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); + ptr = (u8 *)&__osPfsPifRam; + + if (pfs->channel != 0) { + for (i = 0; i < pfs->channel; i++) { + ptr++; + } + } + + ramreadformat = *(__OSContRamReadFormat *)ptr; + ret = CHNL_ERR(ramreadformat); + + if (ret == 0 && ramreadformat.datacrc != 0) { + ret = PFS_ERR_CONTRFAIL; + } + + __osSiRelAccess(); + return ret; +} + +s32 osMotorStart(OSPfs *pfs) { + + int i; + s32 ret; + u8 *ptr; + __OSContRamReadFormat ramreadformat; + + __osSiGetAccess(); + + __osContLastCmd = CONT_CMD_WRITE_PAK; + __osSiRawStartDma(OS_WRITE, &_MotorStartData[pfs->channel]); + osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); + ptr = (u8 *)&__osPfsPifRam; + + if (pfs->channel != 0) { + for (i = 0; i < pfs->channel; i++) { + ptr++; + } + } + + ramreadformat = *(__OSContRamReadFormat *)ptr; + ret = CHNL_ERR(ramreadformat); + if (ret == 0 && ramreadformat.datacrc != 0xEB) { + ret = PFS_ERR_CONTRFAIL; + } + + __osSiRelAccess(); + return ret; +} + +static void _MakeMotorData(int channel, u16 address, u8 *buffer, OSPifRam *mdata) +{ + u8 *ptr = (u8 *)mdata->ramarray; + __OSContRamReadFormat ramreadformat; + int i; + + for (i = 0; i < ARRLEN(mdata->ramarray); i++) { + mdata->ramarray[i] = 0; + } + + mdata->pifstatus = CONT_CMD_EXE; + ramreadformat.dummy = CONT_CMD_NOP; + ramreadformat.txsize = CONT_CMD_WRITE_PAK_TX; + ramreadformat.rxsize = CONT_CMD_WRITE_PAK_RX; + ramreadformat.cmd = CONT_CMD_WRITE_PAK; + + ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); + ramreadformat.datacrc = CONT_CMD_NOP; + + for (i = 0; i < ARRLEN(ramreadformat.data); i++) { + ramreadformat.data[i] = *buffer++; + } + + if (channel != 0) { + for (i = 0; i < channel; i++) { + *ptr++ = 0; + } + } + + *(__OSContRamReadFormat *)ptr = ramreadformat; + ptr += sizeof(__OSContRamReadFormat); + ptr[0] = CONT_CMD_END; +} + +s32 osMotorInit(OSMesgQueue* mq, OSPfs* pfs, int channel) { + int i; + s32 ret; + u8 temp[32]; + + pfs->queue = mq; + pfs->channel = channel; + pfs->status = 0; + pfs->activebank = 128; + + for (i = 0; i < ARRLEN(temp); i++) { + temp[i] = 128; + } + + ret = __osContRamWrite(mq, channel, CONT_BLOCK_DETECT, temp, FALSE); + + if (ret == PFS_ERR_NEW_PACK) { + ret = __osContRamWrite(mq, channel, CONT_BLOCK_DETECT, temp, FALSE); + } + + if (ret != 0) { + return ret; + } + + ret = __osContRamRead(mq, channel, CONT_BLOCK_DETECT, temp); + + if (ret != 0) { + return ret; + } + + if (temp[31] != 0x80) { + return PFS_ERR_DEVICE; + } + + for (i = 0; i < ARRLEN(_motorstartbuf); i++) { + _motorstartbuf[i] = 1; + _motorstopbuf[i] = 0; + } + _MakeMotorData(channel, CONT_BLOCK_RUMBLE, _motorstartbuf, &_MotorStartData[channel]); + _MakeMotorData(channel, CONT_BLOCK_RUMBLE, _motorstopbuf, &_MotorStopData[channel]); + + return 0; +} + +#endif diff --git a/lib/src/io/pfsallocatefile.c b/lib/src/io/pfsallocatefile.c new file mode 100644 index 00000000..1aab8a79 --- /dev/null +++ b/lib/src/io/pfsallocatefile.c @@ -0,0 +1,375 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D1040 */ + +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PRinternal/controller.h" +#include "PR/rmon.h" + +#define ROUND_UP_DIVIDE(numerator, denominator) (((numerator) + (denominator)-1) / (denominator)) + +#if BUILD_VERSION >= VERSION_J + +s32 osPfsAllocateFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name, int file_size_in_bytes, + s32* file_no) { + int start_page; + int decleared; + int last_page; + int old_last_page = 0; + s32 ret = 0; + int file_size_in_pages; + __OSInode inode; + __OSInode backup_inode; + __OSDir dir; + u8 bank; + u8 old_bank = 0; + int firsttime = 0; + s32 bytes; + __OSInodeUnit fpage; + + if (company_code == 0 || game_code == 0) { + return PFS_ERR_INVALID; + } + + file_size_in_pages = ROUND_UP_DIVIDE(file_size_in_bytes, BLOCKSIZE * PFS_ONE_PAGE); + + if (((ret = osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, file_no)) != 0) && + ret != PFS_ERR_INVALID) { + return ret; + } + + if (*file_no != -1) { + return PFS_ERR_EXIST; + } + + ret = osPfsFreeBlocks(pfs, &bytes); + + if (file_size_in_bytes > bytes) { + return PFS_DATA_FULL; + } + + if (file_size_in_pages == 0) { + return PFS_ERR_INVALID; + } + + if (((ret = osPfsFindFile(pfs, 0, 0, NULL, NULL, file_no)) != 0) && ret != PFS_ERR_INVALID) { + return ret; + } + + if (*file_no == -1) { + return PFS_DIR_FULL; + } + + for (bank = 0; bank < pfs->banks; bank++) { + ERRCK(__osPfsRWInode(pfs, &inode, PFS_READ, bank)); + ERRCK(__osPfsDeclearPage(pfs, &inode, file_size_in_pages, &start_page, bank, &decleared, &last_page)); + + if (start_page != -1) { + if (firsttime == 0) { + fpage.inode_t.page = start_page; + fpage.inode_t.bank = bank; + } else { + backup_inode.inode_page[old_last_page].inode_t.bank = bank; + backup_inode.inode_page[old_last_page].inode_t.page = start_page; + ERRCK(__osPfsRWInode(pfs, &backup_inode, PFS_WRITE, old_bank)); + } + + if (file_size_in_pages > decleared) { + bcopy(&inode, &backup_inode, sizeof(__OSInode)); + old_last_page = last_page; + old_bank = bank; + file_size_in_pages -= decleared; + firsttime++; + } else { + file_size_in_pages = 0; + ERRCK(__osPfsRWInode(pfs, &inode, PFS_WRITE, bank)); + break; + } + } + } + + if (file_size_in_pages > 0 || start_page == -1) { + return PFS_ERR_INCONSISTENT; + } + + dir.start_page = fpage; + dir.company_code = company_code; + dir.game_code = game_code; + dir.data_sum = 0; + + bcopy(game_name, dir.game_name, PFS_FILE_NAME_LEN); + bcopy(ext_name, dir.ext_name, PFS_FILE_EXT_LEN); + + ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + *file_no, (u8*)&dir, FALSE); + return ret; +} + +s32 __osPfsDeclearPage(OSPfs* pfs, __OSInode* inode, int file_size_in_pages, int* first_page, u8 bank, int* decleared, + int* last_page) { + int j; + int spage; + int old_page; + s32 ret = 0; + int offset = bank > 0 ? 1 : pfs->inode_start_page; + + for (j = offset; j < ARRLEN(inode->inode_page); j++) { + if (inode->inode_page[j].ipage == 3) { + break; + } + } + + if (j == ARRLEN(inode->inode_page)) { + *first_page = -1; + return ret; + } + + spage = j; + *decleared = 1; + old_page = j; + j++; + + while (file_size_in_pages > *decleared && j < ARRLEN(inode->inode_page)) { + if (inode->inode_page[j].ipage == 3) { + inode->inode_page[old_page].inode_t.bank = bank; + inode->inode_page[old_page].inode_t.page = j; + old_page = j; + (*decleared)++; + } + j++; + } + + *first_page = spage; + + if (j == ARRLEN(inode->inode_page) && file_size_in_pages > *decleared) { + *last_page = old_page; + } else { + inode->inode_page[old_page].ipage = 1; + *last_page = 0; + } + + return ret; +} + +#else + +static s32 __osClearPage(OSPfs *pfs, int page_num, u8 *data, u8 bank); + +s32 osPfsAllocateFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name, int file_size_in_bytes, + s32* file_no) { + int start_page; + int decleared; + int last_page; + int old_last_page = 0; + int j; + s32 ret = 0; + int file_size_in_pages; + __OSInode inode; + __OSInode backup_inode; + __OSDir dir; + u8 bank; + u8 old_bank = 0; + int firsttime = 0; + s32 bytes; + __OSInodeUnit fpage; + + if (company_code == 0 || game_code == 0) { + return PFS_ERR_INVALID; + } + + file_size_in_pages = ROUND_UP_DIVIDE(file_size_in_bytes, BLOCKSIZE * PFS_ONE_PAGE); + + if ((pfs->status & PFS_INITIALIZED) == FALSE) { + return PFS_ERR_INVALID; + } + + PFS_CHECK_ID(); + + if (((ret = osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, file_no)) != 0) && + ret != PFS_ERR_INVALID) { + return ret; + } + + if (*file_no != -1) { + return PFS_ERR_EXIST; + } + + ret = osPfsFreeBlocks(pfs, &bytes); + + if (file_size_in_bytes > bytes) { + return PFS_DATA_FULL; + } + + if (file_size_in_pages != 0) { + + if (((ret = osPfsFindFile(pfs, 0, 0, NULL, NULL, file_no)) != 0) && ret != PFS_ERR_INVALID) { + return ret; + } + + if (*file_no == -1) { + return PFS_DIR_FULL; + } + + for (bank = 0; bank < pfs->banks; bank++) { + ERRCK(__osPfsRWInode(pfs, &inode, PFS_READ, bank)); + ERRCK(__osPfsDeclearPage(pfs, &inode, file_size_in_pages, &start_page, bank, &decleared, &last_page)); + + if (start_page != -1) { + if (firsttime == 0) { + fpage.inode_t.page = start_page; + fpage.inode_t.bank = bank; + } else { + backup_inode.inode_page[old_last_page].inode_t.bank = bank; + backup_inode.inode_page[old_last_page].inode_t.page = start_page; + ERRCK(__osPfsRWInode(pfs, &backup_inode, PFS_WRITE, old_bank)); + } + + for (j = 0; j < ARRLEN(inode.inode_page); j++) { + backup_inode.inode_page[j].ipage = inode.inode_page[j].ipage; + } + old_last_page = last_page; + old_bank = bank; + firsttime++; + if (file_size_in_pages > decleared) { + file_size_in_pages = file_size_in_pages - decleared; + } else { + file_size_in_pages = 0; + break; + } + } + } + + if (file_size_in_pages > 0 || start_page == -1) { + return PFS_ERR_INCONSISTENT; + } + + backup_inode.inode_page[old_last_page].inode_t.bank = bank; + backup_inode.inode_page[old_last_page].inode_t.page = start_page; + ERRCK(__osPfsRWInode(pfs, &backup_inode, PFS_WRITE, old_bank)); + + dir.start_page = fpage; + dir.company_code = company_code; + dir.game_code = game_code; + dir.data_sum = 0; + + for (j = 0; j < ARRLEN(dir.game_name); j++) + dir.game_name[j] = *game_name++; + for (j = 0; j < ARRLEN(dir.ext_name); j++) + dir.ext_name[j] = *ext_name++; + + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + *file_no, (u8*)&dir, FALSE)); + return ret; + } else { + return PFS_ERR_INVALID; + } +} + +s32 __osPfsDeclearPage(OSPfs* pfs, __OSInode* inode, int file_size_in_pages, int* first_page, u8 bank, int* decleared, + int* last_page) { + int j; + int spage; + int old_page; + u8 tmp_data[BLOCKSIZE]; + int i; + s32 ret = 0; + int offset = bank > 0 ? 1 : pfs->inode_start_page; + + for (j = offset; j < ARRLEN(inode->inode_page); j++) { + if (inode->inode_page[j].ipage == 3) { + break; + } + } + + if (j == ARRLEN(inode->inode_page)) { + *first_page = -1; + return ret; + } + + for (i = 0; i < ARRLEN(tmp_data); i++) { + tmp_data[i] = 0; + } + + spage = j; + *decleared = 1; + old_page = j; + j++; + + while (file_size_in_pages > *decleared && j < ARRLEN(inode->inode_page)) { + if (inode->inode_page[j].ipage == 3) { + inode->inode_page[old_page].inode_t.bank = bank; + inode->inode_page[old_page].inode_t.page = j; + ERRCK(__osClearPage(pfs, old_page, (u8*)tmp_data, bank)); + old_page = j; + (*decleared)++; + } + j++; + } + + *first_page = spage; + + if (j == ARRLEN(inode->inode_page) && file_size_in_pages > *decleared) { + *last_page = old_page; + return ret; + } else { + inode->inode_page[old_page].ipage = 1; + ret = __osClearPage(pfs, old_page, (u8*)tmp_data, bank); + *last_page = 0; + return ret; + } +} + +static s32 __osClearPage(OSPfs *pfs, int page_no, u8 *data, u8 bank) +{ + int i; + s32 ret; + ret = 0; + pfs->activebank = bank; + ERRCK(__osPfsSelectBank(pfs)); + for (i = 0; i < PFS_ONE_PAGE; i++) { + ret = __osContRamWrite(pfs->queue, pfs->channel, page_no * PFS_ONE_PAGE + i, data, FALSE); + if (ret != 0) { + break; + } + } + pfs->activebank = 0; + ret = __osPfsSelectBank(pfs); + return ret; +} + +#endif + +#ifdef _DEBUG +s32 __osDumpInode(OSPfs* pfs) { + int j; + __OSInode inode; + s32 ret = 0; + __OSDir dir; + u8 bank; +#if BUILD_VERSION >= VERSION_J + u8 startbank = PFS_ID_BANK_256K; +#endif + + rmonPrintf("INODE:\n"); + +#if BUILD_VERSION >= VERSION_J + for (bank = startbank; bank < pfs->banks; bank++) { +#else + for (bank = 0; bank < pfs->banks; bank++) { +#endif + rmonPrintf("\nBank %d:\n", bank); + ret = __osPfsRWInode(pfs, &inode, PFS_READ, bank); + for (j = 0; j < PFS_INODE_SIZE_PER_PAGE; j++) { + rmonPrintf("%x ", inode.inode_page[j].ipage); + } + } + + rmonPrintf("dir_size %d %d\n", pfs->dir_size, pfs->inode_start_page); + + for (j = 0; j < pfs->dir_size; j++) { + __osContRamRead(pfs->queue, pfs->channel, (u16)(pfs->dir_table + (int)j), (u8*)&dir); + rmonPrintf("file %d game_code %d page %x c_code %d sum %d\n", j, dir.game_code, dir.start_page.ipage, + dir.company_code, dir.data_sum); + } + rmonPrintf("End of Dump\n"); + return ret; +} +#endif diff --git a/lib/src/io/pfschecker.c b/lib/src/io/pfschecker.c new file mode 100644 index 00000000..f692b452 --- /dev/null +++ b/lib/src/io/pfschecker.c @@ -0,0 +1,262 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CF530 */ + +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PRinternal/controller.h" + +s32 corrupted_init(OSPfs* pfs, __OSInodeCache* cache); +s32 corrupted(OSPfs* pfs, __OSInodeUnit fpage, __OSInodeCache* cache); + +#define CHECK_IPAGE(p) \ + (((p).ipage >= pfs->inode_start_page) && ((p).inode_t.bank < pfs->banks) && ((p).inode_t.page >= 0x01) && \ + ((p).inode_t.page < 0x80)) + +s32 osPfsChecker(OSPfs* pfs) { + int j; + s32 ret; + __OSInodeUnit next_page; + __OSInode checked_inode; + __OSInode tmp_inode; + __OSDir tmp_dir; + __OSInodeUnit file_next_node[16]; + __OSInodeCache cache; + int fixed = 0; + u8 bank; +#if BUILD_VERSION >= VERSION_J + u8 oldbank = 254; +#endif + s32 cc; + s32 cl; + int offset; + + ret = __osCheckId(pfs); + + if (ret == PFS_ERR_NEW_PACK) { + ret = __osGetId(pfs); + } + + if (ret != 0) { + return ret; + } + + ERRCK(corrupted_init(pfs, &cache)); + + for (j = 0; j < pfs->dir_size; j++) { + ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir)); + +#if BUILD_VERSION >= VERSION_J + if (tmp_dir.company_code != 0 || tmp_dir.game_code != 0) { + if (tmp_dir.company_code == 0 || tmp_dir.game_code == 0) { + cc = -1; + } else { + next_page = tmp_dir.start_page; + cl = cc = 0; + bank = 255; + + while (CHECK_IPAGE(next_page)) { + if (bank != next_page.inode_t.bank) { + bank = next_page.inode_t.bank; + + if (oldbank != bank) { + ret = __osPfsRWInode(pfs, &tmp_inode, PFS_READ, bank); + oldbank = bank; + } + + if (ret != 0 && ret != PFS_ERR_INCONSISTENT) { + return ret; + } + } + + if ((cc = corrupted(pfs, next_page, &cache) - cl) != 0) { + break; + } + + cl = 1; + next_page = tmp_inode.inode_page[next_page.inode_t.page]; + } + } + + if (cc != 0 || next_page.ipage != PFS_EOF) { + bzero(&tmp_dir, sizeof(__OSDir)); + + SET_ACTIVEBANK_TO_ZERO(); + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE)); + fixed++; + } + } +#else + if (tmp_dir.company_code != 0 && tmp_dir.game_code != 0) { + next_page = tmp_dir.start_page; + cl = cc = 0; + bank = 255; + + while (CHECK_IPAGE(next_page)) { + if (bank != next_page.inode_t.bank) { + bank = next_page.inode_t.bank; + ret = __osPfsRWInode(pfs, &tmp_inode, PFS_READ, bank); + if (ret != 0 && ret != PFS_ERR_INCONSISTENT) { + return ret; + } + } + + if ((cc = corrupted(pfs, next_page, &cache) - cl) != 0) { + break; + } + + cl = 1; + next_page = tmp_inode.inode_page[next_page.inode_t.page]; + } + + if (cc != 0 || next_page.ipage != PFS_EOF) { + tmp_dir.company_code = 0; + tmp_dir.game_code = 0; + tmp_dir.start_page.ipage = 0; + tmp_dir.status = DIR_STATUS_EMPTY; + tmp_dir.data_sum = 0; + + SET_ACTIVEBANK_TO_ZERO(); + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE)); + fixed++; + } + } else { + if (tmp_dir.company_code != 0 || tmp_dir.game_code != 0) { + tmp_dir.company_code = 0; + tmp_dir.game_code = 0; + tmp_dir.start_page.ipage = 0; + tmp_dir.status = DIR_STATUS_EMPTY; + tmp_dir.data_sum = 0; + + SET_ACTIVEBANK_TO_ZERO(); + ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE)); + fixed++; + } + } +#endif + } + for (j = 0; j < pfs->dir_size; j++) { + ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir)); + + if (tmp_dir.company_code != 0 && tmp_dir.game_code != 0 && + tmp_dir.start_page.ipage >= (u16)pfs->inode_start_page) { + file_next_node[j].ipage = tmp_dir.start_page.ipage; + } else { + file_next_node[j].ipage = 0; + } + } + + for (bank = 0; bank < pfs->banks; bank++) { + ret = __osPfsRWInode(pfs, &tmp_inode, PFS_READ, bank); + + if (ret != 0 && ret != PFS_ERR_INCONSISTENT) { + return ret; + } + + offset = (bank > 0) ? 1 : pfs->inode_start_page; + + for (j = 0; j < offset; j++) { + checked_inode.inode_page[j].ipage = tmp_inode.inode_page[j].ipage; + } + + for (; j < 128; j++) { + checked_inode.inode_page[j].ipage = PFS_PAGE_NOT_USED; + } + + for (j = 0; j < pfs->dir_size; j++) { + while (file_next_node[j].inode_t.bank == bank && file_next_node[j].ipage >= (u16)pfs->inode_start_page) { + u8 pp = file_next_node[j].inode_t.page; + file_next_node[j] = checked_inode.inode_page[pp] = tmp_inode.inode_page[pp]; + } + } + ERRCK(__osPfsRWInode(pfs, &checked_inode, PFS_WRITE, bank)); + } + + if (fixed) { + pfs->status |= PFS_CORRUPTED; + } else { + pfs->status &= ~PFS_CORRUPTED; + } + + return 0; +} + +s32 corrupted_init(OSPfs* pfs, __OSInodeCache* cache) { + int i; + int n; + int offset; + u8 bank; + __OSInodeUnit tpage; + __OSInode tmp_inode; + s32 ret; + + for (i = 0; i < PFS_INODE_DIST_MAP; i++) { + cache->map[i] = 0; + } + + cache->bank = -1; + for (bank = 0; bank < pfs->banks; bank++) { + offset = bank > 0 ? 1 : pfs->inode_start_page; + + ret = __osPfsRWInode(pfs, &tmp_inode, PFS_READ, bank); + + if (ret != 0 && ret != PFS_ERR_INCONSISTENT) { + return ret; + } + + for (i = offset; i < ARRLEN(tmp_inode.inode_page); i++) { + tpage = tmp_inode.inode_page[i]; + + if (tpage.ipage >= pfs->inode_start_page && tpage.inode_t.bank != bank) { +#if BUILD_VERSION >= VERSION_J + n = ((tpage.inode_t.page & 0x7F) / PFS_SECTOR_SIZE) + + ((tpage.inode_t.bank % PFS_BANK_LAPPED_BY) * BLOCKSIZE); +#else + n = ((tpage.inode_t.page) / PFS_SECTOR_SIZE) + + ((tpage.inode_t.bank % PFS_BANK_LAPPED_BY) * BLOCKSIZE); +#endif + cache->map[n] |= 1 << (bank % PFS_BANK_LAPPED_BY); + } + } + } + return 0; +} + +s32 corrupted(OSPfs* pfs, __OSInodeUnit fpage, __OSInodeCache* cache) { + int j; + int n; + int hit; + u8 bank; + int offset; + s32 ret; + + hit = 0; + ret = 0; + n = (fpage.inode_t.page / PFS_SECTOR_SIZE) + (fpage.inode_t.bank % PFS_BANK_LAPPED_BY) * BLOCKSIZE; + + for (bank = 0; bank < pfs->banks; bank++) { + offset = bank > 0 ? 1 : pfs->inode_start_page; + + if (bank == fpage.inode_t.bank || cache->map[n] & (1 << (bank % PFS_BANK_LAPPED_BY))) { + if (bank != cache->bank) { + ret = __osPfsRWInode(pfs, &cache->inode, PFS_READ, bank); + + if (ret != 0 && ret != PFS_ERR_INCONSISTENT) { + return ret; + } + + cache->bank = bank; + } + + for (j = offset; hit < 2 && (j < ARRLEN(cache->inode.inode_page)); j++) { + if (cache->inode.inode_page[j].ipage == fpage.ipage) { + hit++; + } + } + + if (hit >= 2) { + return PFS_ERR_NEW_PACK; + } + } + } + return hit; +} diff --git a/lib/src/os/osPfsDeleteFile.c b/lib/src/io/pfsdeletefile.c similarity index 54% rename from lib/src/os/osPfsDeleteFile.c rename to lib/src/io/pfsdeletefile.c index 016ce87d..7d34e74c 100644 --- a/lib/src/os/osPfsDeleteFile.c +++ b/lib/src/io/pfsdeletefile.c @@ -1,50 +1,70 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D0870 */ -#include "libultra_internal.h" -#include "controller.h" - -s32 osPfsDeleteFile(OSPfs *pfs, u16 company_code, u32 game_code, u8 *game_name, - u8 *ext_name) -{ +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PRinternal/controller.h" +s32 osPfsDeleteFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name) { s32 file_no; +#if BUILD_VERSION < VERSION_J int k; +#endif s32 ret; __OSInode inode; __OSDir dir; - u16 sum; +#if BUILD_VERSION < VERSION_J + u16 sum = 0; +#endif __OSInodeUnit last_page; u8 startpage; u8 bank; - sum = 0; - if (company_code == 0 || game_code == 0) - return PFS_ERR_INVALID; - PFS_CHECK_STATUS; - PFS_CHECK_ID; - SET_ACTIVEBANK_TO_ZERO; - ERRCK(osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, &file_no)); - if (file_no == -1) + if (company_code == 0 || game_code == 0) { return PFS_ERR_INVALID; + } + +#if BUILD_VERSION >= VERSION_J + ERRCK(osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, &file_no)); + SET_ACTIVEBANK_TO_ZERO(); +#else + PFS_CHECK_STATUS(); + PFS_CHECK_ID(); + SET_ACTIVEBANK_TO_ZERO(); + ERRCK(osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, &file_no)); + + if (file_no == -1) { + return PFS_ERR_INVALID; + } +#endif ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir)); startpage = dir.start_page.inode_t.page; - for (bank = dir.start_page.inode_t.bank; bank < pfs->banks;) - { - ERRCK(__osPfsRWInode(pfs, &inode, OS_READ, bank)); - ERRCK(__osPfsReleasePages(pfs, &inode, startpage, &sum, bank, &last_page, 1)); //TODO: magic constant - ERRCK(__osPfsRWInode(pfs, &inode, OS_WRITE, bank)); - if (last_page.ipage == PFS_EOF) + for (bank = dir.start_page.inode_t.bank; bank < pfs->banks;) { + ERRCK(__osPfsRWInode(pfs, &inode, PFS_READ, bank)); +#if BUILD_VERSION >= VERSION_J + ERRCK(__osPfsReleasePages(pfs, &inode, startpage, bank, &last_page)); +#else + ERRCK(__osPfsReleasePages(pfs, &inode, startpage, &sum, bank, &last_page, TRUE)); +#endif + ERRCK(__osPfsRWInode(pfs, &inode, PFS_WRITE, bank)); + + if (last_page.ipage == PFS_EOF) { break; + } + bank = last_page.inode_t.bank; startpage = last_page.inode_t.page; } - if (bank >= pfs->banks) + if (bank >= pfs->banks) { return PFS_ERR_INCONSISTENT; + } +#if BUILD_VERSION >= VERSION_J + bzero(&dir, sizeof(__OSDir)); +#else dir.game_code = 0; dir.company_code = 0; dir.start_page.ipage = 0; @@ -58,10 +78,35 @@ s32 osPfsDeleteFile(OSPfs *pfs, u16 company_code, u32 game_code, u8 *game_name, dir.ext_name[k] = 0; } dir.status = DIR_STATUS_EMPTY; +#endif + ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir, FALSE); return ret; } + +#if BUILD_VERSION >= VERSION_J + +s32 __osPfsReleasePages(OSPfs* pfs, __OSInode* inode, u8 start_page, u8 bank, __OSInodeUnit* last_page) { + __OSInodeUnit next_page; + __OSInodeUnit old_page; + s32 ret = 0; + + next_page.ipage = (bank << 8) + start_page; + + do { + old_page = next_page; + next_page = inode->inode_page[next_page.inode_t.page]; + inode->inode_page[old_page.inode_t.page].ipage = PFS_PAGE_NOT_USED; + } while (next_page.ipage >= pfs->inode_start_page && next_page.inode_t.bank == bank); + + *last_page = next_page; + + return ret; +} + +#else + s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u16 *sum, u8 bank, __OSInodeUnit *last_page, int flag) { __OSInodeUnit next_page; @@ -70,42 +115,45 @@ s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u16 *sum, u int offset; ret = 0; next_page = inode->inode_page[start_page]; - if (next_page.ipage != 1) - { - if (next_page.inode_t.bank > 0) - offset = 1; - else - offset = pfs->inode_start_page; + + if (next_page.ipage != 1) { + offset = (next_page.inode_t.bank > 0) ? 1 : pfs->inode_start_page; + } else { + offset = (bank > 0) ? 1 : pfs->inode_start_page; } - else - { - if (bank > 0) - offset = 1; - else - offset = pfs->inode_start_page; - } - if (next_page.inode_t.page < offset && next_page.ipage != 1) + + if (next_page.inode_t.page < offset && next_page.ipage != 1) { return PFS_ERR_INCONSISTENT; + } + *last_page = next_page; - if (flag == 1) //TODO: magic number - inode->inode_page[start_page].ipage = PFS_PAGE_NOT_USED; + + if (flag == TRUE) { + inode->inode_page[start_page].ipage = 3; + } ERRCK(__osBlockSum(pfs, start_page, sum, bank)); - if (next_page.ipage == 1) + + if (next_page.ipage == 1) { return 0; - while (next_page.ipage >= pfs->inode_start_page) - { + } + + while (next_page.ipage >= pfs->inode_start_page) { old_page = next_page; next_page = inode->inode_page[next_page.inode_t.page]; - inode->inode_page[old_page.inode_t.page].ipage = PFS_PAGE_NOT_USED; + inode->inode_page[old_page.inode_t.page].ipage = 3; ERRCK(__osBlockSum(pfs, old_page.inode_t.page, sum, bank)); - if (next_page.inode_t.bank != bank) + + if (next_page.inode_t.bank != bank) { break; + } } - //Removed the second check from libreultra to match - if (next_page.ipage >= pfs->inode_start_page /* && next_page.inode_t.bank == bank */) - inode->inode_page[next_page.inode_t.page].ipage = PFS_PAGE_NOT_USED; + + if (next_page.ipage >= pfs->inode_start_page) { + inode->inode_page[next_page.inode_t.page].ipage = 3; + } + *last_page = next_page; return 0; } @@ -132,3 +180,5 @@ s32 __osBlockSum(OSPfs *pfs, u8 page_no, u16 *sum, u8 bank) ret = __osPfsSelectBank(pfs); return ret; } + +#endif diff --git a/lib/src/io/pfsfilestate.c b/lib/src/io/pfsfilestate.c new file mode 100644 index 00000000..d89ec639 --- /dev/null +++ b/lib/src/io/pfsfilestate.c @@ -0,0 +1,116 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D0580 */ + +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PRinternal/controller.h" + +s32 osPfsFileState(OSPfs* pfs, s32 file_no, OSPfsState* state) { + s32 ret; + int pages; + __OSInode inode; + __OSDir dir; + __OSInodeUnit next_page; +#if BUILD_VERSION < VERSION_J + int j; +#endif + u8 bank; +#if BUILD_VERSION < VERSION_J + u8 start_page; +#endif + + if (file_no >= pfs->dir_size || file_no < 0) { + return PFS_ERR_INVALID; + } + + PFS_CHECK_STATUS(); +#if BUILD_VERSION >= VERSION_J + ERRCK(__osCheckId(pfs)); +#else + PFS_CHECK_ID(); +#endif + SET_ACTIVEBANK_TO_ZERO(); + + ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir)); + + if (dir.company_code == 0 || dir.game_code == 0) { + return PFS_ERR_INVALID; + } + +#if BUILD_VERSION >= VERSION_J + pages = 0; + next_page = dir.start_page; + bank = 0xFF; + + while (TRUE) { + if (next_page.ipage < pfs->inode_start_page) { + break; + } else if (next_page.inode_t.bank != bank) { + bank = next_page.inode_t.bank; + ERRCK(__osPfsRWInode(pfs, &inode, PFS_READ, bank)); + } + + pages++; + next_page = inode.inode_page[next_page.inode_t.page]; + } + + if (next_page.ipage != PFS_EOF) { + return PFS_ERR_INCONSISTENT; + } + + state->file_size = pages * (PFS_ONE_PAGE * BLOCKSIZE); + state->company_code = dir.company_code; + state->game_code = dir.game_code; + bcopy(&dir.game_name, state->game_name, PFS_FILE_NAME_LEN); + bcopy(&dir.ext_name, state->ext_name, PFS_FILE_EXT_LEN); + + ret = __osPfsGetStatus(pfs->queue, pfs->channel); + return ret; +#else + if (dir.start_page.ipage < pfs->inode_start_page) { + return PFS_ERR_INCONSISTENT; + } + + pages = 0; + start_page = dir.start_page.inode_t.page; + bank = dir.start_page.inode_t.bank; + + while (bank < pfs->banks) { + ERRCK(__osPfsRWInode(pfs, &inode, PFS_READ, bank)); + next_page = inode.inode_page[start_page]; + pages++; + + while (next_page.ipage >= pfs->inode_start_page) { + pages++; + next_page = inode.inode_page[next_page.inode_t.page]; + if (next_page.inode_t.bank != bank) { + bank = next_page.inode_t.bank; + start_page = next_page.inode_t.page; + break; + } + } + + if (next_page.ipage == PFS_EOF) { + break; + } + } + + if (next_page.ipage != PFS_EOF) { + return PFS_ERR_INCONSISTENT; + } + + state->file_size = pages * (PFS_ONE_PAGE * BLOCKSIZE); + state->company_code = dir.company_code; + state->game_code = dir.game_code; + + for (j = 0; j < ARRLEN(state->game_name); j++) { + state->game_name[j] = dir.game_name[j]; + } + + for (j = 0; j < ARRLEN(state->ext_name); j++) { + state->ext_name[j] = dir.ext_name[j]; + } + + return 0; +#endif +} diff --git a/lib/src/io/pfsfreeblocks.c b/lib/src/io/pfsfreeblocks.c new file mode 100644 index 00000000..b2453f33 --- /dev/null +++ b/lib/src/io/pfsfreeblocks.c @@ -0,0 +1,35 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CF3E0 */ + +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PRinternal/controller.h" + +s32 osPfsFreeBlocks(OSPfs* pfs, s32* bytes_not_used) { + int j; + int pages = 0; + __OSInode inode; + s32 ret = 0; + u8 bank; + int offset; + + PFS_CHECK_STATUS(); +#if BUILD_VERSION >= VERSION_J + ERRCK(__osCheckId(pfs)); +#else + PFS_CHECK_ID(); +#endif + for (bank = 0; bank < pfs->banks; bank++) { + ERRCK(__osPfsRWInode(pfs, &inode, PFS_READ, bank)); + offset = ((bank > 0) ? 1 : pfs->inode_start_page); + + for (j = offset; j < ARRLEN(inode.inode_page); j++) { + if (inode.inode_page[j].ipage == PFS_PAGE_NOT_USED) { + pages++; + } + } + } + + *bytes_not_used = pages * PFS_ONE_PAGE * BLOCKSIZE; + return 0; +} diff --git a/lib/src/os/osPfsInit.c b/lib/src/io/pfsinit.c similarity index 62% rename from lib/src/os/osPfsInit.c rename to lib/src/io/pfsinit.c index a91592aa..1453cbba 100644 --- a/lib/src/os/osPfsInit.c +++ b/lib/src/io/pfsinit.c @@ -1,24 +1,24 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CED20 */ -#include "macros.h" -#include "libultra_internal.h" -#include "controller.h" -#include "siint.h" +#include "PR/os_internal.h" +#include "PRinternal/controller.h" +#include "PRinternal/siint.h" + +s32 osPfsInit(OSMesgQueue* queue, OSPfs* pfs, int channel) { + s32 ret = 0; -s32 osPfsInit(OSMesgQueue *queue, OSPfs *pfs, int channel) { - s32 ret; - ret = 0; __osSiGetAccess(); ret = __osPfsGetStatus(queue, channel); __osSiRelAccess(); - if (ret != 0) + + if (ret != 0) { return ret; + } pfs->queue = queue; pfs->channel = channel; pfs->status = 0; - //pfs->activebank = -1; //Single difference between this an libreultra ERRCK(__osGetId(pfs)); ret = osPfsChecker(pfs); @@ -26,7 +26,6 @@ s32 osPfsInit(OSMesgQueue *queue, OSPfs *pfs, int channel) { return ret; } -//I would think this should be in it's own file, but it only works here s32 __osPfsGetStatus(OSMesgQueue *queue, int channel) { s32 ret; OSMesg dummy; @@ -44,15 +43,11 @@ s32 __osPfsGetStatus(OSMesgQueue *queue, int channel) { __osPfsGetInitData(&pattern, data); - if (data[channel].status & CONT_CARD_ON && data[channel].status & CONT_CARD_PULL) { + if (((data[channel].status & CONT_CARD_ON) != 0) && ((data[channel].status & CONT_CARD_PULL) != 0)) { return PFS_ERR_NEW_PACK; - } - - if (data[channel].errno || !(data[channel].status & CONT_CARD_ON)) { + } else if ((data[channel].errno != 0) || ((data[channel].status & CONT_CARD_ON) == 0)) { return PFS_ERR_NOPACK; - } - - if (data[channel].status & CONT_ADDR_CRC_ER) { + } else if ((data[channel].status & CONT_ADDR_CRC_ER) != 0) { return PFS_ERR_CONTRFAIL; } diff --git a/lib/src/io/pfsisplug.c b/lib/src/io/pfsisplug.c new file mode 100644 index 00000000..8315797f --- /dev/null +++ b/lib/src/io/pfsisplug.c @@ -0,0 +1,104 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CD290 */ + +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PRinternal/controller.h" +#include "PRinternal/siint.h" + +OSPifRam __osPfsPifRam; + +s32 osPfsIsPlug(OSMesgQueue* mq, u8* pattern) { + s32 ret = 0; + OSMesg msg; + u8 bitpattern; + OSContStatus contData[MAXCONTROLLERS]; + s32 channel; + u8 bits = 0; + s32 crcErrorCount = 3; + + __osSiGetAccess(); + + do { + __osPfsRequestData(CONT_CMD_REQUEST_STATUS); + + ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + osRecvMesg(mq, &msg, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, &msg, OS_MESG_BLOCK); + + __osPfsGetInitData(&bitpattern, &contData[0]); + + for (channel = 0; channel < __osMaxControllers; channel++) { + if ((contData[channel].status & CONT_ADDR_CRC_ER) == 0) { + crcErrorCount--; + break; + } + } + + if (channel == __osMaxControllers) { + crcErrorCount = 0; + } + } while (crcErrorCount > 0); + + for (channel = 0; channel < __osMaxControllers; channel++) { + if ((contData[channel].errno == 0) && ((contData[channel].status & CONT_CARD_ON) != 0)) { + bits |= (1 << channel); + } + } + __osSiRelAccess(); + *pattern = bits; + return ret; +} + +void __osPfsRequestData(u8 cmd) { + u8 *ptr; + __OSContRequesFormat requestformat; + int i; + + __osContLastCmd = cmd; + for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { + __osPfsPifRam.ramarray[i] = 0; + } + __osPfsPifRam.pifstatus = CONT_CMD_EXE; + ptr = (u8 *)&__osPfsPifRam; + 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++) { + *((__OSContRequesFormat*)ptr) = requestformat; + ptr += sizeof(__OSContRequesFormat); + } + + *ptr = CONT_CMD_END; +} + +void __osPfsGetInitData(u8* pattern, OSContStatus* data) { + u8* ptr; + __OSContRequesFormat requestformat; + int i; + u8 bits = 0; + + ptr = (u8*)&__osPfsPifRam; + + for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(requestformat), data++) { + requestformat = *((__OSContRequesFormat*)ptr); + data->errno = CHNL_ERR(requestformat); + + if (data->errno != 0) { + continue; + } + + data->type = ((requestformat.typel << 8) | requestformat.typeh); + data->status = requestformat.status; + bits |= (1 << i); + } + *pattern = bits; +} diff --git a/lib/src/io/pfsnumfiles.c b/lib/src/io/pfsnumfiles.c new file mode 100644 index 00000000..8c96ac69 --- /dev/null +++ b/lib/src/io/pfsnumfiles.c @@ -0,0 +1,37 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D0390 */ + +#include "PR/os_internal.h" +#include "PRinternal/controller.h" + +s32 osPfsNumFiles(OSPfs* pfs, s32* max_files, s32* files_used) { + int j; + s32 ret; + __OSDir dir; + int files = 0; + + PFS_CHECK_STATUS(); +#if BUILD_VERSION >= VERSION_J + ERRCK(__osCheckId(pfs)); +#else + PFS_CHECK_ID(); +#endif + SET_ACTIVEBANK_TO_ZERO(); + + for (j = 0; j < pfs->dir_size; j++) { + ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&dir)); + + if (dir.company_code != 0 && dir.game_code != 0) { + files++; + } + } + *files_used = files; + *max_files = pfs->dir_size; + +#if BUILD_VERSION >= VERSION_J + ret = __osPfsGetStatus(pfs->queue, pfs->channel); + return ret; +#else + return 0; +#endif +} diff --git a/lib/src/os/pfsreadwritefile.c b/lib/src/io/pfsreadwritefile.c similarity index 53% rename from lib/src/os/pfsreadwritefile.c rename to lib/src/io/pfsreadwritefile.c index edd54dbb..d6ed0081 100644 --- a/lib/src/os/pfsreadwritefile.c +++ b/lib/src/io/pfsreadwritefile.c @@ -1,66 +1,66 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CEEE0 */ -#include "libultra_internal.h" -#include "controller.h" +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PRinternal/controller.h" -static s32 __osPfsGetNextPage(OSPfs *pfs, u8 *bank, __OSInode *inode, __OSInodeUnit *page) { +#define CHECK_IPAGE(p) \ + (((p).ipage >= pfs->inode_start_page) && ((p).inode_t.bank < pfs->banks) && ((p).inode_t.page >= 0x01) && \ + ((p).inode_t.page < 0x80)) + +static s32 __osPfsGetNextPage(OSPfs* pfs, u8* bank, __OSInode* inode, __OSInodeUnit* page) { s32 ret; - if (*bank != page->inode_t.bank) { + if (page->inode_t.bank != *bank) { *bank = page->inode_t.bank; - ERRCK(__osPfsRWInode(pfs, inode, 0, *bank)); + ERRCK(__osPfsRWInode(pfs, inode, PFS_READ, *bank)); } *page = inode->inode_page[page->inode_t.page]; - if (page->ipage < pfs->inode_start_page || - page->inode_t.bank >= pfs->banks || - page->inode_t.page <= 0 || - page->inode_t.page >= ARRLEN(inode->inode_page)) { - if (page->ipage == 1) + + if (!CHECK_IPAGE(*page)) { + if (page->ipage == PFS_EOF) { return PFS_ERR_INVALID; + } + return PFS_ERR_INCONSISTENT; } - return 0; } - -s32 osPfsReadWriteFile(OSPfs *pfs, s32 file_no, u8 flag, int offset, int size_in_bytes, u8 *data_buffer) { +s32 osPfsReadWriteFile(OSPfs* pfs, s32 file_no, u8 flag, int offset, int size_in_bytes, u8* data_buffer) { s32 ret; __OSDir dir; __OSInode inode; __OSInodeUnit cur_page; int cur_block; int siz_block; - u8 *buffer; + u8* buffer; u8 bank; u16 blockno; - if (file_no >= pfs->dir_size || file_no < 0) - return PFS_ERR_INVALID; - if (size_in_bytes <= 0 || ((size_in_bytes & (BLOCKSIZE - 1)) != 0)) - return PFS_ERR_INVALID; - if (offset < 0 || ((offset & (BLOCKSIZE - 1)) != 0)) + if ((file_no >= (s32)pfs->dir_size) || (file_no < 0)) { return PFS_ERR_INVALID; + } - PFS_CHECK_STATUS; - PFS_CHECK_ID; - SET_ACTIVEBANK_TO_ZERO; + if ((size_in_bytes <= 0) || ((size_in_bytes % BLOCKSIZE) != 0)) { + return PFS_ERR_INVALID; + } + + if ((offset < 0) || ((offset % BLOCKSIZE) != 0)) { + return PFS_ERR_INVALID; + } + + PFS_CHECK_STATUS(); + PFS_CHECK_ID(); + SET_ACTIVEBANK_TO_ZERO(); ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir)); - /* - libreultra only - if (dir.company_code == 0 || dir.game_code == 0) - return PFS_ERR_INVALID; - */ - - if (dir.start_page.ipage < pfs->inode_start_page || - dir.start_page.inode_t.bank >= pfs->banks || - dir.start_page.inode_t.page <= 0 || - dir.start_page.inode_t.page >= ARRLEN(inode.inode_page)) { - - if ((dir.start_page.ipage == 1)) + if (!CHECK_IPAGE(dir.start_page)) { + if ((dir.start_page.ipage == PFS_EOF)) { return PFS_ERR_INVALID; + } + return PFS_ERR_INCONSISTENT; } @@ -68,11 +68,11 @@ s32 osPfsReadWriteFile(OSPfs *pfs, s32 file_no, u8 flag, int offset, int size_in return PFS_ERR_BAD_DATA; } - bank = -1; + bank = -1; cur_block = offset / BLOCKSIZE; cur_page = dir.start_page; - while (cur_block >= PFS_ONE_PAGE) { + while (cur_block >= PFS_ONE_PAGE) { ERRCK(__osPfsGetNextPage(pfs, &bank, &inode, &cur_page)); cur_block -= PFS_ONE_PAGE; } @@ -86,20 +86,21 @@ s32 osPfsReadWriteFile(OSPfs *pfs, s32 file_no, u8 flag, int offset, int size_in cur_block = 0; } - if (pfs->activebank != cur_page.inode_t.bank) { - pfs->activebank = cur_page.inode_t.bank; - ERRCK(__osPfsSelectBank(pfs)); + if (pfs->activebank != cur_page.inode_t.bank) { + ERRCK(SELECT_BANK(pfs, cur_page.inode_t.bank)); } blockno = cur_page.inode_t.page * PFS_ONE_PAGE + cur_block; - if (flag == OS_READ) + if (flag == OS_READ) { ret = __osContRamRead(pfs->queue, pfs->channel, blockno, buffer); - else + } else { ret = __osContRamWrite(pfs->queue, pfs->channel, blockno, buffer, FALSE); + } - if (ret != 0) + if (ret != 0) { return ret; + } buffer += BLOCKSIZE; cur_block++; siz_block--; @@ -107,11 +108,18 @@ s32 osPfsReadWriteFile(OSPfs *pfs, s32 file_no, u8 flag, int offset, int size_in if (flag == PFS_WRITE && (dir.status & DIR_STATUS_OCCUPIED) == 0) { dir.status |= DIR_STATUS_OCCUPIED; - pfs->activebank = 0; - ERRCK(__osPfsSelectBank(pfs)); +#if BUILD_VERSION >= VERSION_J + SET_ACTIVEBANK_TO_ZERO(); +#else + ERRCK(SELECT_BANK(pfs, 0)); +#endif ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir, FALSE)); } +#if BUILD_VERSION >= VERSION_J + ret = __osPfsGetStatus(pfs->queue, pfs->channel); + return ret; +#else return 0; - +#endif } diff --git a/lib/src/io/pfsreformat.c b/lib/src/io/pfsreformat.c new file mode 100644 index 00000000..62fe93be --- /dev/null +++ b/lib/src/io/pfsreformat.c @@ -0,0 +1,74 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CFF90 */ + +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PRinternal/controller.h" +#include "PRinternal/siint.h" + +s32 osPfsReFormat(OSPfs* pfs, OSMesgQueue* queue, int channel) { + int j; + int i; + __OSInode inode; + u8 tmp_data[32]; + u8* ptr; + s32 ret; + __osSiGetAccess(); + ret = __osPfsGetStatus(queue, channel); + + if (ret != 0) { + return ret; + } + + pfs->status ^= PFS_INITIALIZED; + pfs->queue = queue; + pfs->channel = channel; + __osSiRelAccess(); + ERRCK(__osGetId(pfs)); + + SET_ACTIVEBANK_TO_ZERO(); + + for (j = 0; j < ARRLEN(tmp_data); j++) { + tmp_data[j] = 0; + } + + for (j = 0; j < pfs->dir_size; j++) { + ERRCK(__osContRamWrite(queue, channel, pfs->dir_table + j, tmp_data, FALSE)); + } + + for (j = 0; j < pfs->inode_start_page; j++) { + inode.inode_page[j].ipage = 0; + } + + for (j = pfs->inode_start_page; j < ARRLEN(inode.inode_page); j++) { + inode.inode_page[j].ipage = 3; + } + + inode.inode_page[0].ipage = __osSumcalc((u8*)(inode.inode_page + pfs->inode_start_page), + (ARRLEN(inode.inode_page) - pfs->inode_start_page) * sizeof(__OSInodeUnit)); + ptr = (u8*)&inode; + + for (j = 0; j < PFS_ONE_PAGE; j++) { + ERRCK(__osContRamWrite(queue, channel, pfs->inode_table + j, ptr + j * BLOCKSIZE, FALSE)); + ERRCK(__osContRamWrite(queue, channel, pfs->minode_table + j, ptr + j * BLOCKSIZE, FALSE)); + } + + for (i = 1; i < pfs->banks; i++) { + for (j = 1; j < ARRLEN(inode.inode_page); j++) { + inode.inode_page[j].ipage = 3; + } + + inode.inode_page[0].ipage = + __osSumcalc((u8*)(inode.inode_page + 1), (ARRLEN(inode.inode_page) - 1) * sizeof(__OSInodeUnit)); + ptr = (u8*)&inode; + + for (j = 0; j < PFS_ONE_PAGE; j++) { + ERRCK( + __osContRamWrite(queue, channel, pfs->inode_table + i * PFS_ONE_PAGE + j, ptr + j * BLOCKSIZE, FALSE)); + ERRCK( + __osContRamWrite(queue, channel, pfs->minode_table + i * PFS_ONE_PAGE + j, ptr + j * BLOCKSIZE, FALSE)); + } + } + + return 0; +} diff --git a/lib/src/os/osPfsFindFile.c b/lib/src/io/pfssearchfile.c similarity index 69% rename from lib/src/os/osPfsFindFile.c rename to lib/src/io/pfssearchfile.c index bc1c1967..bc0a838c 100644 --- a/lib/src/os/osPfsFindFile.c +++ b/lib/src/io/pfssearchfile.c @@ -1,22 +1,35 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D0E80 */ -#include "libultra_internal.h" -#include "controller.h" +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PRinternal/controller.h" -s32 osPfsFindFile(OSPfs *pfs, u16 company_code, u32 game_code, u8 *game_name, u8 *ext_name, s32 *file_no) { +s32 osPfsFindFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name, u8* ext_name, s32* file_no) { s32 j; int i; __OSDir dir; - s32 ret; + s32 ret = 0; int fail; - ret = 0; - PFS_CHECK_ID; - + +#if BUILD_VERSION >= VERSION_J + if (!(pfs->status & PFS_INITIALIZED)) { + return PFS_ERR_INVALID; + } + ERRCK(__osCheckId(pfs)); +#else + PFS_CHECK_ID(); +#endif + for (j = 0; j < pfs->dir_size; j++) { ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&dir)); +#if BUILD_VERSION >= VERSION_J + ERRCK(__osPfsGetStatus(pfs->queue, pfs->channel)); +#endif + if ((dir.company_code == company_code) && dir.game_code == game_code) { fail = FALSE; + if (game_name != NULL) { for (i = 0; i < ARRLEN(dir.game_name); i++) { if (dir.game_name[i] != game_name[i]) { @@ -25,6 +38,7 @@ s32 osPfsFindFile(OSPfs *pfs, u16 company_code, u32 game_code, u8 *game_name, u8 } } } + if (ext_name != NULL && !fail) { for (i = 0; i < ARRLEN(dir.ext_name); i++) { if (dir.ext_name[i] != ext_name[i]) { @@ -33,14 +47,14 @@ s32 osPfsFindFile(OSPfs *pfs, u16 company_code, u32 game_code, u8 *game_name, u8 } } } + if (!fail) { *file_no = j; return ret; } } } - - *file_no = -1; + *file_no = -1; return PFS_ERR_INVALID; } diff --git a/lib/src/io/piacs.c b/lib/src/io/piacs.c new file mode 100644 index 00000000..b2f5e8e6 --- /dev/null +++ b/lib/src/io/piacs.c @@ -0,0 +1,29 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D2480 */ + +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include + +#define PI_Q_BUF_LEN 1 +u32 __osPiAccessQueueEnabled = 0; +static OSMesg piAccessBuf[PI_Q_BUF_LEN]; +OSMesgQueue __osPiAccessQueue ALIGNED(0x8); + +void __osPiCreateAccessQueue(void) { + __osPiAccessQueueEnabled = 1; + osCreateMesgQueue(&__osPiAccessQueue, piAccessBuf, PI_Q_BUF_LEN); + osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK); +} + +void __osPiGetAccess(void) { + OSMesg dummyMesg; + if (!__osPiAccessQueueEnabled) { + __osPiCreateAccessQueue(); + } + osRecvMesg(&__osPiAccessQueue, &dummyMesg, OS_MESG_BLOCK); +} + +void __osPiRelAccess(void) { + osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK); +} diff --git a/lib/src/io/pidma.c b/lib/src/io/pidma.c new file mode 100644 index 00000000..1468c649 --- /dev/null +++ b/lib/src/io/pidma.c @@ -0,0 +1,69 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C8F80 */ + +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PRinternal/piint.h" + +s32 osPiStartDma(OSIoMesg* mb, s32 priority, s32 direction, u32 devAddr, void* dramAddr, u32 size, OSMesgQueue* mq) { + register s32 ret; + if (!__osPiDevMgr.active) { +#ifdef _DEBUG + __osError(ERR_OSPISTARTDMA_PIMGR, 0); +#endif + return -1; + } + +#ifdef _DEBUG + if ((priority != OS_MESG_PRI_NORMAL) && (priority != OS_MESG_PRI_HIGH)) { + __osError(ERR_OSPISTARTDMA_PRI, 1, priority); + return -1; + } + + if ((direction != OS_READ) && (direction != OS_WRITE)) { + __osError(ERR_OSPISTARTDMA_DIR, 1, direction); + return -1; + } + + if (devAddr & 0x1) { + __osError(ERR_OSPISTARTDMA_DEVADDR, 1, devAddr); + return -1; + } + + if ((u32)dramAddr & 0x7) { + __osError(ERR_OSPISTARTDMA_ADDR, 1, dramAddr); + return -1; + } + + if (size & 0x1) { + __osError(ERR_OSPISTARTDMA_SIZE, 1, size); + return -1; + } + + if ((size == 0) || (size > (16 * 1024 * 1024))) { + __osError(ERR_OSPISTARTDMA_RANGE, 1, size); + return -1; + } +#endif + + if (direction == OS_READ) { + mb->hdr.type = OS_MESG_TYPE_DMAREAD; + } else { + mb->hdr.type = OS_MESG_TYPE_DMAWRITE; + } + + mb->hdr.pri = priority; + mb->hdr.retQueue = mq; + mb->dramAddr = dramAddr; + mb->devAddr = devAddr; + mb->size = size; + mb->piHandle = NULL; + + if (priority == OS_MESG_PRI_HIGH) { + ret = osJamMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); + } else { + ret = osSendMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); + } + + return ret; +} diff --git a/lib/src/io/pigetcmdq.c b/lib/src/io/pigetcmdq.c new file mode 100644 index 00000000..1424fd76 --- /dev/null +++ b/lib/src/io/pigetcmdq.c @@ -0,0 +1,13 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D37F0 */ + +#include "PR/os_internal.h" +#include "PRinternal/piint.h" + +OSMesgQueue* osPiGetCmdQueue(void) { + if (!__osPiDevMgr.active) { + return NULL; + } else { + return __osPiDevMgr.cmdQueue; + } +} diff --git a/lib/src/mips1/os/osCreatePiManager.c b/lib/src/io/pimgr.c similarity index 56% rename from lib/src/mips1/os/osCreatePiManager.c rename to lib/src/io/pimgr.c index c06d46fb..587ce3f7 100644 --- a/lib/src/mips1/os/osCreatePiManager.c +++ b/lib/src/io/pimgr.c @@ -1,33 +1,30 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C6000 */ -#include "types.h" -#include "libultra_internal.h" -#include "stacks.h" -#include "lib/src/os/piint.h" -#include "macros.h" +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PRinternal/piint.h" +#include "PR/rdb.h" static OSThread piThread ALIGNED(0x8); static STACK(piThreadStack, OS_PIM_STACKSIZE) ALIGNED(0x10); +#ifndef _FINALROM +static OSThread ramromThread ALIGNED(0x8); +static STACK(ramromThreadStack, 0x400) ALIGNED(0x10); +static OSMesgQueue getRamromQ ALIGNED(0x8); +static OSMesg getRamromBuf[1]; +static OSMesgQueue freeRamromQ ALIGNED(0x8); +static OSMesg freeRamromBuf[1]; +static void ramromMain(void*); +#endif + static OSMesgQueue piEventQueue ALIGNED(0x8); static OSMesg piEventBuf[1]; OSDevMgr __osPiDevMgr = { 0 }; -#ifndef RAREDIFFS -OSPiHandle* __osPiTable = NULL; -#if BUILD_VERSION >= VERSION_J -OSPiHandle __Dom1SpeedParam ALIGNED(0x8); -OSPiHandle __Dom2SpeedParam ALIGNED(0x8); -OSPiHandle* __osCurrentHandle[2] ALIGNED(0x8) = { &__Dom1SpeedParam, &__Dom2SpeedParam }; -#else -extern OSPiHandle CartRomHandle; -extern OSPiHandle LeoDiskHandle; -OSPiHandle* __osCurrentHandle[2] ALIGNED(0x8) = { &CartRomHandle, &LeoDiskHandle }; -#endif -#endif - void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt) { u32 savedMask; OSPri oldPri; @@ -69,9 +66,42 @@ void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgC __osPiDevMgr.edma = __osEPiRawStartDma; osCreateThread(&piThread, 0, __osDevMgrMain, &__osPiDevMgr, STACK_START(piThreadStack), pri); osStartThread(&piThread); + +#ifndef _FINALROM + osCreateThread(&ramromThread, 0, ramromMain, NULL, STACK_START(ramromThreadStack), (OSPri)pri - 1); + osStartThread(&ramromThread); +#endif __osRestoreInt(savedMask); if (oldPri != -1) { osSetThreadPri(NULL, oldPri); } } + +#ifndef _FINALROM +static void ramromMain(void* arg) { + u32 sent; + u8 tmp[3]; + + osCreateMesgQueue(&getRamromQ, getRamromBuf, 1); + osCreateMesgQueue(&freeRamromQ, freeRamromBuf, 1); + osSetEventMesg(OS_EVENT_RDB_REQ_RAMROM, &getRamromQ, NULL); + osSetEventMesg(OS_EVENT_RDB_FREE_RAMROM, &freeRamromQ, NULL); + + while (TRUE) { + osRecvMesg(&getRamromQ, NULL, OS_MESG_BLOCK); + + __osPiGetAccess(); + + sent = 0; + + while (sent < 1) { + sent += __osRdbSend(tmp, 1, RDB_TYPE_GtoH_RAMROM); + } + + osRecvMesg(&freeRamromQ, NULL, OS_MESG_BLOCK); + + __osPiRelAccess(); + } +} +#endif diff --git a/lib/src/io/pirawdma.c b/lib/src/io/pirawdma.c new file mode 100644 index 00000000..f0c22c61 --- /dev/null +++ b/lib/src/io/pirawdma.c @@ -0,0 +1,56 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D25a0 */ + +#include "PRinternal/piint.h" +#include "PR/ultraerror.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osPiRawStartDma(s32 direction, u32 devAddr, void* dramAddr, u32 size) { + register u32 stat; + +#ifdef _DEBUG + if ((direction != OS_READ) && (direction != OS_WRITE)) { + __osError(ERR_OSPIRAWSTARTDMA_DIR, 1, direction); + return -1; + } + + if (devAddr & 0x1) { + __osError(ERR_OSPIRAWSTARTDMA_DEVADDR, 1, devAddr); + return -1; + } + + if ((u32)dramAddr & 0x7) { + __osError(ERR_OSPIRAWSTARTDMA_ADDR, 1, dramAddr); + return -1; + } + + if (size & 0x1) { + __osError(ERR_OSPIRAWSTARTDMA_SIZE, 1, size); + return -1; + } + + if ((size == 0) || (size > (16 * 1024 * 1024))) { + __osError(ERR_OSPIRAWSTARTDMA_RANGE, 1, size); + return -1; + } +#endif + + 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/lib/src/io/pirawread.c b/lib/src/io/pirawread.c new file mode 100644 index 00000000..bd68ff69 --- /dev/null +++ b/lib/src/io/pirawread.c @@ -0,0 +1,27 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D4790 */ + +#include "PRinternal/piint.h" +#include "assert.h" +#include "PR/ultraerror.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osPiRawReadIo(u32 devAddr, u32* data) { + register u32 stat; + +#ifdef _DEBUG + if (devAddr & 0x3) { + __osError(ERR_OSPIRAWREADIO, 1, devAddr); + return -1; + } +#endif + + assert(data != NULL); + + WAIT_ON_IOBUSY(stat); + *data = IO_READ((u32)osRomBase | devAddr); + + return 0; +} diff --git a/lib/src/io/si.c b/lib/src/io/si.c new file mode 100644 index 00000000..1fd21153 --- /dev/null +++ b/lib/src/io/si.c @@ -0,0 +1,18 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D52C0 */ + +#include "PR/os_internal.h" +#include "PRinternal/siint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +int __osSiDeviceBusy(void) { + register u32 stat = IO_READ(SI_STATUS_REG); + + if (stat & (SI_STATUS_DMA_BUSY | SI_STATUS_RD_BUSY)) { + return TRUE; + } else { + return FALSE; + } +} diff --git a/lib/src/io/siacs.c b/lib/src/io/siacs.c new file mode 100644 index 00000000..5c3341b4 --- /dev/null +++ b/lib/src/io/siacs.c @@ -0,0 +1,29 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CD600 */ + +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include + +#define SI_Q_BUF_LEN 1 +static OSMesg siAccessBuf[SI_Q_BUF_LEN] ALIGNED(0x8); +OSMesgQueue __osSiAccessQueue ALIGNED(0x8); +u32 __osSiAccessQueueEnabled = 0; + +void __osSiCreateAccessQueue(void) { + __osSiAccessQueueEnabled = 1; + osCreateMesgQueue(&__osSiAccessQueue, siAccessBuf, SI_Q_BUF_LEN); + 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/lib/src/io/sirawdma.c b/lib/src/io/sirawdma.c new file mode 100644 index 00000000..de67059f --- /dev/null +++ b/lib/src/io/sirawdma.c @@ -0,0 +1,44 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CD6C0 */ + +#include "PR/os_internal.h" +#include "assert.h" +#include "PRinternal/siint.h" +#include + +#define PIF_RAM_SIZE (PIF_RAM_END + 1 - PIF_RAM_START) + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSiRawStartDma(s32 direction, void* dramAddr) { + assert(((u32)dramAddr & 0x3) == 0); + +#if BUILD_VERSION >= VERSION_J + if (IO_READ(SI_STATUS_REG) & (SI_STATUS_DMA_BUSY | SI_STATUS_RD_BUSY)) { + return -1; + } +#else + if (__osSiDeviceBusy()) { + return -1; + } +#endif + + if (direction == OS_WRITE) { + osWritebackDCache(dramAddr, PIF_RAM_SIZE); + } + + IO_WRITE(SI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); + + if (direction == OS_READ) { + IO_WRITE(SI_PIF_ADDR_RD64B_REG, PIF_RAM_START); + } else { + IO_WRITE(SI_PIF_ADDR_WR64B_REG, PIF_RAM_START); + } + + if (direction == OS_READ) { + osInvalDCache(dramAddr, PIF_RAM_SIZE); + } + + return 0; +} diff --git a/lib/src/io/sirawread.c b/lib/src/io/sirawread.c new file mode 100644 index 00000000..ee6d0dec --- /dev/null +++ b/lib/src/io/sirawread.c @@ -0,0 +1,21 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D4590 */ + +#include "PR/os_internal.h" +#include "assert.h" +#include "PRinternal/siint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSiRawReadIo(u32 devAddr, u32* data) { + assert((devAddr & 0x3) == 0); + assert(data != NULL); + + if (__osSiDeviceBusy()) { + return -1; + } + + *data = IO_READ(devAddr); + return 0; +} diff --git a/lib/src/os/__osSiRawWriteIo.c b/lib/src/io/sirawwrite.c similarity index 59% rename from lib/src/os/__osSiRawWriteIo.c rename to lib/src/io/sirawwrite.c index 877a5931..5b5deff6 100644 --- a/lib/src/os/__osSiRawWriteIo.c +++ b/lib/src/io/sirawwrite.c @@ -1,16 +1,20 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D45E0 */ -#include "types.h" -#include "siint.h" -#include "PR/rcp.h" +#include "PR/os_internal.h" +#include "PRinternal/siint.h" +#include "assert.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" s32 __osSiRawWriteIo(u32 devAddr, u32 data) { + assert((devAddr & 0x3) == 0); + if (__osSiDeviceBusy()) { return -1; } IO_WRITE(devAddr, data); - return 0; } diff --git a/lib/src/io/sp.c b/lib/src/io/sp.c new file mode 100644 index 00000000..12d85ac3 --- /dev/null +++ b/lib/src/io/sp.c @@ -0,0 +1,20 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D64D0 */ + +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/sptask.h" +#include "PRinternal/osint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +int __osSpDeviceBusy(void) { + register u32 stat = IO_READ(SP_STATUS_REG); + + if (stat & (SP_STATUS_DMA_BUSY | SP_STATUS_DMA_FULL | SP_STATUS_IO_FULL)) { + return TRUE; + } else { + return FALSE; + } +} diff --git a/lib/src/os/__osSpGetStatus.c b/lib/src/io/spgetstat.c similarity index 51% rename from lib/src/os/__osSpGetStatus.c rename to lib/src/io/spgetstat.c index 81e8e284..2120d63a 100644 --- a/lib/src/os/__osSpGetStatus.c +++ b/lib/src/io/spgetstat.c @@ -1,8 +1,12 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D63EC */ -#include "libultra_internal.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" -u32 __osSpGetStatus() { +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +u32 __osSpGetStatus(void) { return IO_READ(SP_STATUS_REG); } diff --git a/lib/src/io/sprawdma.c b/lib/src/io/sprawdma.c new file mode 100644 index 00000000..b674750e --- /dev/null +++ b/lib/src/io/sprawdma.c @@ -0,0 +1,31 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D6440 */ + +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PRinternal/osint.h" +#include "assert.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +s32 __osSpRawStartDma(s32 direction, u32 devAddr, void* dramAddr, u32 size) { + assert(((u32)devAddr & 0x7) == 0); + assert(((u32)dramAddr & 0x7) == 0); + assert(((u32)size & 0x7) == 0); + + 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/lib/src/io/spsetpc.c b/lib/src/io/spsetpc.c new file mode 100644 index 00000000..44a45b64 --- /dev/null +++ b/lib/src/io/spsetpc.c @@ -0,0 +1,18 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D63FC */ + +#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/lib/src/io/spsetstat.c b/lib/src/io/spsetstat.c new file mode 100644 index 00000000..4bfc7358 --- /dev/null +++ b/lib/src/io/spsetstat.c @@ -0,0 +1,12 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CD240 */ + +#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/lib/src/io/sptask.c b/lib/src/io/sptask.c new file mode 100644 index 00000000..38d4fd4d --- /dev/null +++ b/lib/src/io/sptask.c @@ -0,0 +1,82 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D1EF0 */ + +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/sptask.h" +#include "PR/rcp.h" +#include "PRinternal/osint.h" + +#if BUILD_VERSION < VERSION_J +#ident "$Revision: 1.4 $" +#endif + +#define _osVirtualToPhysical(ptr) \ + if (ptr != NULL) { \ + ptr = (void*)osVirtualToPhysical(ptr); \ + } (void)0 + +static OSTask tmp_task; + +static OSTask* _VirtualToPhysicalTask(OSTask* intp) { + OSTask* tp; + tp = &tmp_task; + bcopy(intp, tp, sizeof(OSTask)); + + _osVirtualToPhysical(tp->t.ucode); + _osVirtualToPhysical(tp->t.ucode_data); + _osVirtualToPhysical(tp->t.dram_stack); + _osVirtualToPhysical(tp->t.output_buff); + _osVirtualToPhysical(tp->t.output_buff_size); + _osVirtualToPhysical(tp->t.data_ptr); + _osVirtualToPhysical(tp->t.yield_data_ptr); + return tp; +} + +void osSpTaskLoad(OSTask* intp) { + OSTask* tp; + +#ifdef _DEBUG + if ((intp->t.dram_stack != 0x0) && ((u32)intp->t.dram_stack & 0xf)) { + __osError(ERR_OSSPTASKLOAD_DRAM, 1, intp->t.dram_stack); + return; + } + if ((intp->t.output_buff != 0x0) && ((u32)intp->t.output_buff & 0xf)) { + __osError(ERR_OSSPTASKLOAD_OUT, 1, intp->t.output_buff); + return; + } + if ((intp->t.output_buff_size != 0x0) && ((u32)intp->t.output_buff_size & 0xf)) { + __osError(ERR_OSSPTASKLOAD_OUTSIZE, 1, intp->t.output_buff_size); + return; + } + if ((intp->t.yield_data_ptr != 0x0) && ((u32)intp->t.yield_data_ptr & 0xf)) { + __osError(ERR_OSSPTASKLOAD_YIELD, 1, intp->t.yield_data_ptr); + return; + } +#endif + + tp = _VirtualToPhysicalTask(intp); + + if (tp->t.flags & OS_TASK_YIELDED) { + tp->t.ucode_data = tp->t.yield_data_ptr; + tp->t.ucode_data_size = tp->t.yield_data_size; + intp->t.flags &= ~OS_TASK_YIELDED; + } + + osWritebackDCache(tp, sizeof(OSTask)); + __osSpSetStatus(SP_CLR_YIELD | SP_CLR_YIELDED | SP_CLR_TASKDONE | SP_SET_INTR_BREAK); + + while (__osSpSetPc(SP_IMEM_START) == -1) {} + + while (__osSpRawStartDma(1, (SP_IMEM_START - sizeof(*tp)), tp, sizeof(OSTask)) == -1) {} + + while (__osSpDeviceBusy()) {} + + while (__osSpRawStartDma(1, SP_IMEM_START, tp->t.ucode_boot, tp->t.ucode_boot_size) == -1) {} +} + +void osSpTaskStartGo(OSTask* tp) { + while (__osSpDeviceBusy()) {} + + __osSpSetStatus(SP_SET_INTR_BREAK | SP_CLR_SSTEP | SP_CLR_BROKE | SP_CLR_HALT); +} diff --git a/lib/src/os/osSpTaskYield.c b/lib/src/io/sptaskyield.c similarity index 62% rename from lib/src/os/osSpTaskYield.c rename to lib/src/io/sptaskyield.c index a7d4460b..eebf93af 100644 --- a/lib/src/os/osSpTaskYield.c +++ b/lib/src/io/sptaskyield.c @@ -1,8 +1,9 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D2240 */ -#include "libultra_internal.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" void osSpTaskYield(void) { - __osSpSetStatus(SPSTATUS_SET_SIGNAL0); + __osSpSetStatus(SP_SET_YIELD); } diff --git a/lib/src/io/sptaskyielded.c b/lib/src/io/sptaskyielded.c new file mode 100644 index 00000000..088cd777 --- /dev/null +++ b/lib/src/io/sptaskyielded.c @@ -0,0 +1,21 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D1DF0 */ + +#include "PR/os_internal.h" +#include "PR/sptask.h" +#include "PR/rcp.h" + +OSYieldResult osSpTaskYielded(OSTask* tp) { + u32 status; + OSYieldResult result; + + status = __osSpGetStatus(); + result = (status & SP_STATUS_YIELDED) ? OS_TASK_YIELDED : 0; + + if (status & SP_STATUS_YIELD) { + tp->t.flags |= result; + tp->t.flags &= ~(OS_TASK_DP_WAIT); + } + + return result; +} diff --git a/lib/src/io/vi.c b/lib/src/io/vi.c new file mode 100644 index 00000000..725b6309 --- /dev/null +++ b/lib/src/io/vi.c @@ -0,0 +1,44 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D2B10 */ + +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PR/R4300.h" +#include "PR/rcp.h" +#include "PRinternal/viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +static __OSViContext vi[2] ALIGNED(0x8) = { 0 }; +__OSViContext* __osViCurr = &vi[0]; +__OSViContext* __osViNext = &vi[1]; +s32 osViClock = VI_NTSC_CLOCK; + +void __osViInit(void) { + bzero(vi, sizeof(vi)); + __osViCurr = &vi[0]; + __osViNext = &vi[1]; + __osViNext->retraceCount = 1; + __osViCurr->retraceCount = 1; + + if (osTvType == OS_TV_TYPE_PAL) { + __osViNext->modep = &osViModePalLan1; + osViClock = VI_PAL_CLOCK; + } else if (osTvType == OS_TV_TYPE_MPAL) { + __osViNext->modep = &osViModeMpalLan1; + osViClock = VI_MPAL_CLOCK; + } else { + __osViNext->modep = &osViModeNtscLan1; + osViClock = VI_NTSC_CLOCK; + } + + __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/lib/src/os/osViBlack.c b/lib/src/io/viblack.c similarity index 57% rename from lib/src/os/osViBlack.c rename to lib/src/io/viblack.c index e070a865..86656369 100644 --- a/lib/src/os/osViBlack.c +++ b/lib/src/io/viblack.c @@ -1,15 +1,20 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D1D10 */ -#include "libultra_internal.h" -#include "viint.h" +#include "PR/os_internal.h" +#include "PRinternal/viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" void osViBlack(u8 active) { - register u32 int_disabled = __osDisableInt(); + register u32 saveMask = __osDisableInt(); + if (active) { __osViNext->state |= VI_STATE_BLACK; } else { __osViNext->state &= ~VI_STATE_BLACK; } - __osRestoreInt(int_disabled); + + __osRestoreInt(saveMask); } diff --git a/lib/src/io/vigetcurrcontext.c b/lib/src/io/vigetcurrcontext.c new file mode 100644 index 00000000..d5478e24 --- /dev/null +++ b/lib/src/io/vigetcurrcontext.c @@ -0,0 +1,12 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D6080 */ + +#include "PR/os_internal.h" +#include "PRinternal/viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +__OSViContext* __osViGetCurrentContext(void) { + return __osViCurr; +} diff --git a/lib/src/io/vigetcurrframebuf.c b/lib/src/io/vigetcurrframebuf.c new file mode 100644 index 00000000..0ab9e1e4 --- /dev/null +++ b/lib/src/io/vigetcurrframebuf.c @@ -0,0 +1,23 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D1E70 */ + +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PRinternal/viint.h" + +void* osViGetCurrentFramebuffer(void) { + register u32 saveMask; + void* framep; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVIGETCURRENTFRAMEBUFFER, 0); + return NULL; + } +#endif + + saveMask = __osDisableInt(); + framep = __osViCurr->framep; + __osRestoreInt(saveMask); + return framep; +} diff --git a/lib/src/io/vigetnextframebuf.c b/lib/src/io/vigetnextframebuf.c new file mode 100644 index 00000000..c9628c07 --- /dev/null +++ b/lib/src/io/vigetnextframebuf.c @@ -0,0 +1,23 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D1EB0 */ + +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PRinternal/viint.h" + +void* osViGetNextFramebuffer(void) { + register u32 saveMask; + void* framep; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVIGETNEXTFRAMEBUFFER, 0); + return NULL; + } +#endif + + saveMask = __osDisableInt(); + framep = __osViNext->framep; + __osRestoreInt(saveMask); + return framep; +} diff --git a/lib/src/io/vimgr.c b/lib/src/io/vimgr.c new file mode 100644 index 00000000..7aef987b --- /dev/null +++ b/lib/src/io/vimgr.c @@ -0,0 +1,129 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D1990 */ + +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/rcp.h" +#include "PRinternal/viint.h" +#include "PRinternal/osint.h" + +OSDevMgr __osViDevMgr = { 0 }; +#if BUILD_VERSION >= VERSION_J +u32 __additional_scanline = 0; +#endif +static OSThread viThread; +static STACK(viThreadStack, OS_VIM_STACKSIZE) ALIGNED(0x10); +static OSMesgQueue viEventQueue ALIGNED(0x8); +static OSMesg viEventBuf[5] ALIGNED(0x8); +static OSIoMesg viRetraceMsg ALIGNED(0x8); +static OSIoMesg viCounterMsg ALIGNED(0x8); + +static void viMgrMain(void* arg); +void osCreateViManager(OSPri pri) { + u32 savedMask; + OSPri oldPri; + OSPri myPri; + +#ifdef _DEBUG + if ((pri < OS_PRIORITY_IDLE) || (pri > OS_PRIORITY_MAX)) { + __osError(ERR_OSCREATEVIMANAGER, 1, pri); + return; + } +#endif + + if (__osViDevMgr.active) { + return; + } + __osTimerServicesInit(); +#if BUILD_VERSION >= VERSION_J + __additional_scanline = 0; +#endif + 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, STACK_START(viThreadStack), pri); + __osViInit(); + osStartThread(&viThread); + __osRestoreInt(savedMask); + + if (oldPri != -1) { + osSetThreadPri(NULL, 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; + default: + break; + } + } +} diff --git a/lib/src/io/visetevent.c b/lib/src/io/visetevent.c new file mode 100644 index 00000000..954fad4e --- /dev/null +++ b/lib/src/io/visetevent.c @@ -0,0 +1,30 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D1D80 */ + +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "assert.h" +#include "PRinternal/viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViSetEvent(OSMesgQueue* mq, OSMesg m, u32 retraceCount) { + register u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVISETEVENT, 0); + return; + } + + assert(mq != NULL); +#endif + + saveMask = __osDisableInt(); + + __osViNext->msgq = mq; + __osViNext->msg = m; + __osViNext->retraceCount = retraceCount; + __osRestoreInt(saveMask); +} diff --git a/lib/src/io/visetmode.c b/lib/src/io/visetmode.c new file mode 100644 index 00000000..370ad36c --- /dev/null +++ b/lib/src/io/visetmode.c @@ -0,0 +1,30 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D1CA0 */ + +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "assert.h" +#include "PRinternal/viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViSetMode(OSViMode* modep) { + register u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVISETMODE, 0); + return; + } + + assert(modep != NULL); +#endif + + saveMask = __osDisableInt(); + + __osViNext->modep = modep; + __osViNext->state = VI_STATE_MODE_UPDATED; + __osViNext->control = __osViNext->modep->comRegs.ctrl; + __osRestoreInt(saveMask); +} diff --git a/lib/src/io/visetspecial.c b/lib/src/io/visetspecial.c new file mode 100644 index 00000000..48ccc4c9 --- /dev/null +++ b/lib/src/io/visetspecial.c @@ -0,0 +1,88 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D2260 */ + +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PR/rcp.h" +#include "PRinternal/viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +// This value was incorrectly calculated until being fixed in 2.0J +#if BUILD_VERSION >= VERSION_J +#define OS_VI_SPECIAL_MAX \ + (OS_VI_GAMMA_ON | OS_VI_GAMMA_OFF | OS_VI_GAMMA_DITHER_ON | OS_VI_GAMMA_DITHER_OFF | OS_VI_DIVOT_ON | \ + OS_VI_DIVOT_OFF | OS_VI_DITHER_FILTER_ON | OS_VI_DITHER_FILTER_OFF) +#else +#define OS_VI_SPECIAL_MAX OS_VI_DITHER_FILTER_OFF +#endif + +/** + * Configures VI "special features" to be applied on the next context swap. + * + * "Special features" refer to the mode bits in the Video Interface control register that enable effects such as gamma + * correction, gamma dither, dither filtering, anti-aliasing filtering and divot filtering. Configuring the same + * setting ON and OFF in the same call will result in OFF taking precedence. + * + * Any unrecognized bits will be ignored. Note that this is very intentional as in early revisions of retail N64 + * hardware setting bit 5 in the `features` field of OSViContext may cause physical damage to the console once it is + * fed to VI_CONTROL_REG on next context swap. + * + * @param func OS_VI_*_ON / OS_VI_*_OFF bits to enable or disable a setting. + */ +void osViSetSpecialFeatures(u32 func) { + register u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVISETSPECIAL_VIMGR, 0); + return; + } + + if ((func < OS_VI_GAMMA_ON) || (func > OS_VI_SPECIAL_MAX)) { + __osError(ERR_OSVISETSPECIAL_VALUE, 1, func); + return; + } +#endif + + 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/lib/src/io/viswapbuf.c b/lib/src/io/viswapbuf.c new file mode 100644 index 00000000..87657a98 --- /dev/null +++ b/lib/src/io/viswapbuf.c @@ -0,0 +1,34 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D2420 */ + +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "assert.h" +#include "PRinternal/viint.h" + +// TODO: this comes from a header +#ident "$Revision: 1.17 $" + +void osViSwapBuffer(void* frameBufPtr) { + u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSVISWAPBUFFER_VIMGR, 0); + return; + } + + assert(frameBufPtr != NULL); + + if ((u32)frameBufPtr & 0x3f) { + __osError(ERR_OSVISWAPBUFFER_ADDR, 1, frameBufPtr); + return; + } +#endif + + saveMask = __osDisableInt(); + + __osViNext->framep = frameBufPtr; + __osViNext->state |= VI_STATE_BUFFER_UPDATED; + __osRestoreInt(saveMask); +} diff --git a/lib/src/os/__osViSwapContext.c b/lib/src/io/viswapcontext.c similarity index 68% rename from lib/src/os/__osViSwapContext.c rename to lib/src/io/viswapcontext.c index 38b8e1b4..64493259 100644 --- a/lib/src/os/__osViSwapContext.c +++ b/lib/src/io/viswapcontext.c @@ -1,29 +1,21 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D6090 */ -#include "macros.h" -#include "libultra_internal.h" -#include "viint.h" +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PRinternal/viint.h" -//TODO: These variable declarations should really be elsewhere. -struct __osThreadTail -{ - OSThread *next; - OSPri priority; -} __osThreadTail; +// TODO: this comes from a header +#ident "$Revision: 1.17 $" -struct __osThreadTail __osThreadTail = {0, -1}; -OSThread *__osRunQueue = (OSThread *)&__osThreadTail; -OSThread *__osActiveQueue = (OSThread *)&__osThreadTail; - -OSThread *__osRunningThread = NULL; -OSThread *__osFaultedThread = NULL; - -void __osViSwapContext() { - register OSViMode *vm; - register __OSViContext *vc; +void __osViSwapContext(void) { + register OSViMode* vm; + register __OSViContext* vc; u32 origin; u32 hStart; +#if BUILD_VERSION >= VERSION_J + u32 vStart; +#endif u32 nomValue; u32 field; @@ -31,17 +23,16 @@ void __osViSwapContext() { vc = __osViNext; vm = vc->modep; - field = IO_READ(VI_CURRENT_REG) & 1; //field num + field = IO_READ(VI_CURRENT_REG) & 1; // field num origin = osVirtualToPhysical(vc->framep) + (vm->fldRegs[field].origin); - - if (vc->state & VI_STATE_XSCALE_UPDATED) { + 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) { + + 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; @@ -49,18 +40,21 @@ void __osViSwapContext() { vc->y.scale = vm->fldRegs[field].yScale; } +#if BUILD_VERSION >= VERSION_J + vStart = (vm->fldRegs[field].vStart - (__additional_scanline << VI_SUBPIXEL_SH)) + __additional_scanline; +#endif hStart = vm->comRegs.hStart; if (vc->state & VI_STATE_BLACK) { hStart = 0; } - - if (vc->state & VI_STATE_REPEATLINE) { + + if (vc->state & VI_STATE_REPEATLINE) { vc->y.scale = 0; origin = osVirtualToPhysical(vc->framep); } - - if (vc->state & VI_STATE_FADE) { + + 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); } @@ -72,7 +66,11 @@ void __osViSwapContext() { IO_WRITE(VI_H_SYNC_REG, vm->comRegs.hSync); IO_WRITE(VI_LEAP_REG, vm->comRegs.leap); IO_WRITE(VI_H_START_REG, hStart); +#if BUILD_VERSION >= VERSION_J + IO_WRITE(VI_V_START_REG, vStart); +#else IO_WRITE(VI_V_START_REG, vm->fldRegs[field].vStart); +#endif 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); diff --git a/lib/src/os/vitbl.c b/lib/src/io/vitbl.c similarity index 99% rename from lib/src/os/vitbl.c rename to lib/src/io/vitbl.c index 115c4f63..21f30d81 100644 --- a/lib/src/os/vitbl.c +++ b/lib/src/io/vitbl.c @@ -1,10 +1,9 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D1991 */ -// The RAM_POS above is just a hack to put it after osViMgr.c - -#include "libultra_internal.h" -#include "viint.h" +#include "PR/os.h" +#include "PR/rcp.h" +#include "PRinternal/viint.h" /* * Video Interface (VI) mode type @@ -82,7 +81,7 @@ #define OS_VI_BIT_NTSC 0x0400 #define OS_VI_BIT_PAL 0x0800 -OSViMode osViModeTable[42] = { +OSViMode osViModeTable[] = { {OS_VI_NTSC_LPN1, //type { //comRegs @@ -1743,6 +1742,3 @@ OSViMode osViModeMpalLan1 = { BURST(4, 2, 14, 0), // vBurst VINTR(2), // vIntr }}}; - -// This needs to be moved. -u32 __osPiAccessQueueEnabled = 0; diff --git a/lib/src/libc/ldiv.c b/lib/src/libc/ldiv.c index 3da42f4d..19992842 100644 --- a/lib/src/libc/ldiv.c +++ b/lib/src/libc/ldiv.c @@ -1,32 +1,35 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D7470 */ -#include +#include "os_version.h" +#include "stdlib.h" -ldiv_t ldiv(long num, long denom) -{ +// TODO: these come from headers +#ident "$Revision: 1.34 $" +#ident "$Revision: 1.5 $" + +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++; + + if (ret.quot < 0 && ret.rem > 0) { + ret.quot += 1; ret.rem -= denom; } return ret; } -lldiv_t lldiv(long long num, long long denom) -{ +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++; + + if (ret.quot < 0 && ret.rem > 0) { + ret.quot += 1; ret.rem -= denom; } diff --git a/lib/src/libc/ll.c b/lib/src/libc/ll.c index 687fcf56..00960742 100644 --- a/lib/src/libc/ll.c +++ b/lib/src/libc/ll.c @@ -1,55 +1,49 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CE730 */ -unsigned long long __ull_rshift(unsigned long long a0, unsigned long long a1) -{ +unsigned long long __ull_rshift(unsigned long long a0, unsigned long long a1) { return a0 >> a1; } -unsigned long long __ull_rem(unsigned long long a0, unsigned long long a1) -{ + +unsigned long long __ull_rem(unsigned long long a0, unsigned long long a1) { return a0 % a1; } -unsigned long long __ull_div(unsigned long long a0, unsigned long long a1) -{ + +unsigned long long __ull_div(unsigned long long a0, unsigned long long a1) { return a0 / a1; } -unsigned long long __ll_lshift(unsigned long long a0, unsigned long long a1) -{ +unsigned long long __ll_lshift(unsigned long long a0, unsigned long long a1) { return a0 << a1; } -long long __ll_rem(unsigned long long a0, long long a1) -{ +long long __ll_rem(unsigned long long a0, long long a1) { return a0 % a1; } -long long __ll_div(long long a0, long long a1) -{ +long long __ll_div(long long a0, long long a1) { return a0 / a1; } -unsigned long long __ll_mul(unsigned long long a0, unsigned long long a1) -{ +unsigned long long __ll_mul(unsigned long long a0, unsigned long long a1) { return a0 * a1; } -void __ull_divremi(unsigned long long *div, unsigned long long *rem, unsigned long long a2, unsigned short a3) -{ +void __ull_divremi(unsigned long long* div, unsigned long long* rem, unsigned long long a2, unsigned short a3) { *div = a2 / a3; - *rem = a2 % a3; -} -long long __ll_mod(long long a0, long long a1) -{ + *rem = a2 % a3; +} + +long long __ll_mod(long long a0, long long a1) { long long tmp = a0 % a1; - if ((tmp < 0 && a1 > 0) || (tmp > 0 && a1 < 0)) - { - tmp += a1; + + if ((tmp < 0 && a1 > 0) || (tmp > 0 && a1 < 0)) { + tmp += a1; } + return tmp; } - -long long __ll_rshift(long long a0, long long a1) -{ + +long long __ll_rshift(long long a0, long long a1) { return a0 >> a1; } diff --git a/lib/src/libc/llcvt.c b/lib/src/libc/llcvt.c index ca98a0c1..ec1f07a5 100644 --- a/lib/src/libc/llcvt.c +++ b/lib/src/libc/llcvt.c @@ -2,26 +2,33 @@ /* RAM_POS: 0x800C9B30 */ long long __d_to_ll(double d) { - return d; + return d; } + long long __f_to_ll(float f) { - return f; + return f; } + unsigned long long __d_to_ull(double d) { - return d; + return d; } + unsigned long long __f_to_ull(float f) { - return f; + return f; } + double __ll_to_d(long long s) { - return s; + return s; } + float __ll_to_f(long long s) { - return s; + return s; } + double __ull_to_d(unsigned long long u) { - return u; + return u; } + float __ull_to_f(unsigned long long u) { - return u; + return u; } diff --git a/lib/src/libc/rmonPrintf.c b/lib/src/libc/rmonPrintf.c index 39f898fc..95eb0142 100644 --- a/lib/src/libc/rmonPrintf.c +++ b/lib/src/libc/rmonPrintf.c @@ -10,7 +10,7 @@ /** * This gets called inside of _PrintF, but it is just a fake pointer returned */ -static char *is_proutSyncPrintf(UNUSED char *str, UNUSED const char *buf, UNUSED size_t n) { +static char *proutSyncPrintf(UNUSED char *str, UNUSED const char *buf, UNUSED size_t n) { return ((char *) 1); /* return a fake pointer so that it's not NULL */ } @@ -23,6 +23,6 @@ static char *is_proutSyncPrintf(UNUSED char *str, UNUSED const char *buf, UNUSED void rmonPrintf(const char *format, ...) { va_list args; va_start(args, format); - _Printf(is_proutSyncPrintf, NULL, format, args); + _Printf(proutSyncPrintf, NULL, format, args); va_end(args); } diff --git a/lib/src/libc/string.c b/lib/src/libc/string.c index 9d64e756..801b41b8 100644 --- a/lib/src/libc/string.c +++ b/lib/src/libc/string.c @@ -1,34 +1,39 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CE170 */ -#include "types.h" -#include "macros.h" +#include "PR/ultratypes.h" +#include "string.h" -void *memcpy(void *dst, const void *src, size_t size) { - u8 *_dst = dst; - const u8 *_src = src; - while (size > 0) { - *_dst++ = *_src++; - size--; +// TODO: this comes from a header +#ident "$Revision: 1.23 $" + +void* memcpy(void* s1, const void* s2, size_t n) { + char* su1 = (char*)s1; + const char* su2 = (const char*)s2; + while (n > 0) { + *su1 = *su2; + su1++; + su2++; + n--; } - return dst; + return (void*)s1; } -size_t strlen(const char *str) { - const u8 *ptr = (const u8 *) str; - while (*ptr) { - ptr++; +size_t strlen(const char* s) { + const char* sc = s; + while (*sc != 0) { + sc++; } - return (const char *) ptr - str; + return sc - s; } -char *strchr(const char *str, s32 ch) { - u8 c = ch; - while (*(u8 *)str != c) { - if (*(u8 *)str == 0) { +char* strchr(const char* s, int c) { + const char ch = c; + while (*s != ch) { + if (*s == 0) { return NULL; } - str++; + s++; } - return (char *) str; + return (char*)s; } diff --git a/lib/src/libc/xldtob.c b/lib/src/libc/xldtob.c index d049fb67..95a6a7f0 100644 --- a/lib/src/libc/xldtob.c +++ b/lib/src/libc/xldtob.c @@ -1,8 +1,312 @@ - /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D69A0 */ -#include "macros.h" +#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; + long lo = ldval; + + if ((gen -= 8) > 0) { + ldval = (ldval - lo) * 1e8; + } + + for (p += 8, j = 8; lo > 0 && --j >= 0;) { + ldiv_t qr; + 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) { + const 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 = (u16*)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"; + } + + if (code == 'f' || (code == 'g' || code == 'G') && xexp >= -4 && xexp < px->prec) { + xexp++; + if (code != 'f') { + if (((px->flags & 8) == 0) && nsig < px->prec) { + px->prec = nsig; + } + + if ((px->prec -= xexp) < 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); + 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++; + } + + 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; + } + + code = (code == 'g') ? 'e' : '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; + } + *p++ = (xexp / 100) + '0', xexp %= 100; + } + *p++ = (xexp / 10) + '0', xexp %= 10; + + *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; + } + } +} -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/_Genld.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/_Ldtob.s") diff --git a/lib/src/libc/xlitob.c b/lib/src/libc/xlitob.c index d98abcc7..e0eeca93 100644 --- a/lib/src/libc/xlitob.c +++ b/lib/src/libc/xlitob.c @@ -1,64 +1,61 @@ - /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D6700 */ -#include "macros.h" -#include "xprintf.h" #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 -extern char ldigs[]; -extern char udigs[]; +static char ldigs[] = "0123456789abcdef"; +static char udigs[] = "0123456789ABCDEF"; -void _Litob(printf_struct *args, char type) { +void _Litob(_Pft *args, char type) { char buff[BUFF_LEN]; const char *digs; s32 base; s32 i; - u64 us64val; + unsigned long long ullval; - if (type == 'X') { - digs = udigs; - } else { - digs = ldigs; - } + digs = (type == 'X') ? udigs : ldigs; base = (type == 'o') ? 8 : ((type != 'x' && type != 'X') ? 10 : 16); i = BUFF_LEN; - us64val = args->value.s64; + ullval = args->v.ll; - if ((type == 'd' || type == 'i') && args->value.s64 < 0) { - us64val = -us64val; + if ((type == 'd' || type == 'i') && args->v.ll < 0) { + ullval = -ullval; } - if (us64val != 0 || args->precision != 0) { - buff[--i] = digs[us64val % base]; + if (ullval != 0 || args->prec != 0) { + buff[--i] = digs[ullval % base]; } - args->value.s64 = us64val / base; + args->v.ll = ullval / base; - while (args->value.s64 > 0 && i > 0) { - lldiv_t qr = lldiv(args->value.s64, base); + while (args->v.ll > 0 && i > 0) { + lldiv_t qr = lldiv(args->v.ll, base); - args->value.s64 = qr.quot; + args->v.ll = qr.quot; buff[--i] = digs[qr.rem]; } - args->part2_len = BUFF_LEN - i; + args->n1 = BUFF_LEN - i; - memcpy(args->buff, buff + i, args->part2_len); + memcpy(args->s, buff + i, args->n1); - if (args->part2_len < args->precision) { - args->num_leading_zeros = args->precision - args->part2_len; + if (args->n1 < args->prec) { + args->nz0 = args->prec - args->n1; } - if (args->precision < 0 && (args->flags & (FLAGS_ZERO | FLAGS_MINUS)) == FLAGS_ZERO) { - i = args->width - args->n0 - args->num_leading_zeros - args->part2_len; - - if (i > 0) { - args->num_leading_zeros += i; + if (args->prec < 0 && (args->flags & (FLAGS_ZERO | FLAGS_MINUS)) == FLAGS_ZERO) { + if ((i = args->width - args->n0 - args->nz0 - args->n1) > 0) { + args->nz0 += i; } } } diff --git a/lib/src/libc/xprintf.c b/lib/src/libc/xprintf.c index bef41edc..b1fba1cf 100644 --- a/lib/src/libc/xprintf.c +++ b/lib/src/libc/xprintf.c @@ -1,212 +1,263 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D38A0 */ -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" -#include -#include -#include "xprintf.h" +#include "PRinternal/macros.h" +#include "string.h" +#include "stdarg.h" +#include "xstdio.h" -const char length_str[] = "hlL"; -const char flags_str[] = " +-#0"; -const u32 flags_arr[] = { FLAGS_SPACE, FLAGS_PLUS, FLAGS_MINUS, FLAGS_HASH, FLAGS_ZERO, 0 }; -char _spaces[] = " "; -char _zeroes[] = "00000000000000000000000000000000"; +// TODO: these come from headers +#ident "$Revision: 1.34 $" +#ident "$Revision: 1.5 $" +#ident "$Revision: 1.23 $" + +#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.nchar += (n); \ + else \ + return x.nchar; \ + } +static char spaces[] = " "; +static char zeroes[] = "00000000000000000000000000000000"; + +static void _Putfld(_Pft *pf, va_list *pap, char code, char *ac); + +int _Printf(outfun prout, char *arg, const char *fmt, va_list args) { + _Pft x; + + x.nchar = 0; -static void _Putfld(printf_struct *a0, va_list *args, u8 type, u8 *buff); -s32 _Printf(outfun prout, char *dst, const char *fmt, va_list args) { - printf_struct x; - const u8 *fmt_ptr; - u8 c; - const char *flag_index; - u8 ac[0x20]; // probably a buffer? - x.size = 0; while (TRUE) { - fmt_ptr = (u8 *) fmt; - while ((c = *fmt_ptr++) > 0) { + const char *s; + char c; + const char *t; + static const char fchar[] = {' ', '+', '-', '#', '0', '\0'}; + static const int fbit[] = {FLAGS_SPACE, FLAGS_PLUS, FLAGS_MINUS, FLAGS_HASH, FLAGS_ZERO, 0}; + char ac[32]; + s = fmt; + + while ((c = *s++) > 0) { if (c == '%') { - fmt_ptr--; + s--; break; } } - _PROUT(fmt, fmt_ptr - (u8 *) fmt); + + PUT(fmt, s - fmt); + if (c == 0) { - return x.size; + return x.nchar; } - fmt = (char *) ++fmt_ptr; - x.flags = 0; - for (; (flag_index = strchr(flags_str, *fmt_ptr)) != NULL; fmt_ptr++) { - x.flags |= flags_arr[flag_index - flags_str]; + + fmt = ++s; + + for (x.flags = 0; (t = strchr(fchar, *s)) != NULL; s++) { + x.flags |= fbit[t - fchar]; } - if (*fmt_ptr == '*') { - x.width = va_arg(args, s32); + + if (*s == '*') { + x.width = va_arg(args, int); + if (x.width < 0) { x.width = -x.width; x.flags |= FLAGS_MINUS; } - fmt_ptr++; - } else { - ATOI(x.width, fmt_ptr); - } - if (*fmt_ptr != '.') { - x.precision = -1; - } else { - fmt_ptr++; - if (*fmt_ptr == '*') { - x.precision = va_arg(args, s32); - fmt_ptr++; - } else { - ATOI(x.precision, fmt_ptr); + s++; + } else + ATOI(x.width, s); + + + if (*s != '.') { + x.prec = -1; + } else if (*++s == '*') { + x.prec = va_arg(args, int); + ++s; + } else + for (x.prec = 0; isdigit(*s); s++) { + if (x.prec < 999) + x.prec = x.prec * 10 + *s - '0'; } - } - if (strchr(length_str, *fmt_ptr) != NULL) { - x.length = *fmt_ptr++; - } else { - x.length = 0; + + + x.qual = strchr("hlL", *s) ? *s++ : '\0'; + + if (x.qual == 'l' && *s == 'l') { + x.qual = 'L'; + ++s; } - if (x.length == 'l' && *fmt_ptr == 'l') { - x.length = 'L'; - fmt_ptr++; + _Putfld(&x, &args, *s, ac); + x.width -= x.n0 + x.nz0 + x.n1 + x.nz1 + x.n2 + x.nz2; + + { + + if (!(x.flags & FLAGS_MINUS)) { + int i, j; + if (0 < (x.width)) + { + i, j = x.width; + for (; 0 < j; j -= i) + { + i = MAX_PAD < (unsigned int)j ? (int)MAX_PAD : j; + PUT(spaces, i); + } + } + } + + PUT(ac, x.n0); + PAD(zeroes, x.nz0) + + PUT(x.s, x.n1); + PAD(zeroes, x.nz1); + + PUT(x.s + x.n1, x.n2); + PAD(zeroes, x.nz2); + + if (x.flags & FLAGS_MINUS) { + PAD(spaces, x.width); + } } - _Putfld(&x, (va_list *)&args, *fmt_ptr, 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); - _PROUT((char *) ac, x.n0); - _PAD(_zeroes, x.num_leading_zeros); - _PROUT(x.buff, x.part2_len); - _PAD(_zeroes, x.num_mid_zeros); - _PROUT((char *) (&x.buff[x.part2_len]), x.part3_len) - _PAD(_zeroes, x.num_trailing_zeros); - if (x.flags & FLAGS_MINUS) - _PAD(_spaces, x.width); - fmt = (char *) fmt_ptr + 1; + fmt = s + 1; } + return 0; } -static void _Putfld(printf_struct *a0, va_list *args, u8 type, u8 *buff) { - a0->n0 = a0->num_leading_zeros = a0->part2_len = a0->num_mid_zeros = a0->part3_len = - a0->num_trailing_zeros = 0; +static void _Putfld(_Pft *x, va_list *args, char type, char *buff) { + x->n0 = x->nz0 = x->n1 = x->nz1 = x->n2 = + x->nz2 = 0; switch (type) { - case 'c': - buff[a0->n0++] = va_arg(*args, u32); + buff[x->n0++] = va_arg(*args, int); break; - case 'd': case 'i': - if (a0->length == 'l') { - a0->value.s64 = va_arg(*args, s32); - } else if (a0->length == 'L') { - a0->value.s64 = va_arg(*args, s64); + if (x->qual == 'l') { + x->v.ll = va_arg(*args, int); + } else if (x->qual == 'L') { + x->v.ll = va_arg(*args, s64); } else { - a0->value.s64 = va_arg(*args, s32); + x->v.ll = va_arg(*args, int); } - if (a0->length == 'h') { - a0->value.s64 = (s16) a0->value.s64; + if (x->qual == 'h') { + x->v.ll = (s16)x->v.ll; } - if (a0->value.s64 < 0) { - buff[a0->n0++] = '-'; - } else if (a0->flags & FLAGS_PLUS) { - buff[a0->n0++] = '+'; - } else if (a0->flags & FLAGS_SPACE) { - buff[a0->n0++] = ' '; + if (x->v.ll < 0) { + buff[x->n0++] = '-'; + } else if (x->flags & FLAGS_PLUS) { + buff[x->n0++] = '+'; + } else if (x->flags & FLAGS_SPACE) { + buff[x->n0++] = ' '; } - a0->buff = (char *) &buff[a0->n0]; + x->s = (char *)&buff[x->n0]; - _Litob(a0, type); + _Litob(x, type); break; - case 'x': case 'X': case 'u': case 'o': - if (a0->length == 'l') { - a0->value.s64 = va_arg(*args, s32); - } else if (a0->length == 'L') { - a0->value.s64 = va_arg(*args, s64); + if (x->qual == 'l') { + x->v.ll = va_arg(*args, int); + } else if (x->qual == 'L') { + x->v.ll = va_arg(*args, s64); } else { - a0->value.s64 = va_arg(*args, s32); + x->v.ll = va_arg(*args, int); } - if (a0->length == 'h') { - a0->value.s64 = (u16) a0->value.s64; - } else if (a0->length == 0) { - a0->value.s64 = (u32) a0->value.s64; + if (x->qual == 'h') { + x->v.ll = (u16)x->v.ll; + } else if (x->qual == 0) { + x->v.ll = (unsigned int)x->v.ll; } - if (a0->flags & FLAGS_HASH) { - buff[a0->n0++] = '0'; + if (x->flags & FLAGS_HASH) { + buff[x->n0++] = '0'; + if (type == 'x' || type == 'X') { - - buff[a0->n0++] = type; + buff[x->n0++] = type; } } - a0->buff = (char *) &buff[a0->n0]; - _Litob(a0, type); - break; + x->s = (char *)&buff[x->n0]; + _Litob(x, type); + break; case 'e': case 'f': case 'g': case 'E': case 'G': //... okay? - a0->value.f64 = a0->length == 'L' ? va_arg(*args, f64) : va_arg(*args, f64); + x->v.ld = x->qual == 'L' ? va_arg(*args, f64) : va_arg(*args, f64); - if (LDSIGN(a0->value.f64)) { - buff[a0->n0++] = '-'; - } else { - if (a0->flags & FLAGS_PLUS) { - buff[a0->n0++] = '+'; - } else if (a0->flags & FLAGS_SPACE) { - buff[a0->n0++] = ' '; - } - } + if (LDSIGN(x->v.ld)) + buff[x->n0++] = '-'; + else if (x->flags & FLAGS_PLUS) + buff[x->n0++] = '+'; + else if (x->flags & FLAGS_SPACE) + buff[x->n0++] = ' '; - a0->buff = (char *) &buff[a0->n0]; - _Ldtob(a0, type); + x->s = (char *)&buff[x->n0]; + _Ldtob(x, type); break; case 'n': - if (a0->length == 'h') { - *(va_arg(*args, u16 *)) = a0->size; - } else if (a0->length == 'l') { - *va_arg(*args, u32 *) = a0->size; - } else if (a0->length == 'L') { - *va_arg(*args, u64 *) = a0->size; + if (x->qual == 'h') { + *(va_arg(*args, u16 *)) = x->nchar; + } else if (x->qual == 'l') { + *va_arg(*args, unsigned int *) = x->nchar; + } else if (x->qual == 'L') { + *va_arg(*args, u64 *) = x->nchar; } else { - *va_arg(*args, u32 *) = a0->size; + *va_arg(*args, unsigned int *) = x->nchar; } - break; + break; case 'p': - a0->value.s64 = (long) va_arg(*args, void *); - a0->buff = (char *) &buff[a0->n0]; - _Litob(a0, 'x'); + x->v.ll = (long)va_arg(*args, void *); + x->s = (char *)&buff[x->n0]; + _Litob(x, 'x'); break; - case 's': - a0->buff = va_arg(*args, char *); - a0->part2_len = strlen(a0->buff); - if (a0->precision >= 0 && a0->part2_len > a0->precision) { - a0->part2_len = a0->precision; + x->s = va_arg(*args, char *); + x->n1 = strlen(x->s); + + if (x->prec >= 0 && x->prec < x->n1) { + x->n1 = x->prec; } + break; - case '%': - buff[a0->n0++] = '%'; + buff[x->n0++] = '%'; break; - default: - buff[a0->n0++] = type; + buff[x->n0++] = type; break; } } diff --git a/lib/src/libc/xstdio.h b/lib/src/libc/xstdio.h new file mode 100644 index 00000000..bd70de8a --- /dev/null +++ b/lib/src/libc/xstdio.h @@ -0,0 +1,37 @@ +#ifndef _XSTDIO_H +#define _XSTDIO_H +#include "PR/ultratypes.h" +#include "stdlib.h" +#include "stdarg.h" + +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/lib/src/mips1/al/alAuxBusPull.c b/lib/src/mips1/al/alAuxBusPull.c deleted file mode 100644 index 053e892a..00000000 --- a/lib/src/mips1/al/alAuxBusPull.c +++ /dev/null @@ -1,54 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x80065900 */ - -#include "alSynStartVoiceParams.h" - -#include "types.h" -#include "macros.h" -#include "audio_internal.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; - 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; - s32 i; - - switch (paramID) { - case AL_FILTER_ADD_SOURCE: - sources[m->sourceCount++] = (ALFilter *) param; - break; - case 0x11: - for (i = 0; i < m->sourceCount; i++) { - if ((ALFilter *) param == sources[i]) { - m->sourceCount--; - sources[i] = sources[m->sourceCount]; - } - } - break; - } - - return 0; - -} - -void func_80065A80(ALSynth *arg0, PVoice *arg1, s16 arg2) { - if (arg2 != arg1->unkDC) { - alAuxBusParam(&arg0->auxBus[arg1->unkDC], 17, &arg1->envmixer); - alAuxBusParam(&arg0->auxBus[arg2], 2, &arg1->envmixer); - arg1->unkDC = arg2; - } -} diff --git a/lib/src/mips1/al/alSynAllocFX.c b/lib/src/mips1/al/alSynAllocFX.c deleted file mode 100644 index ad9e2f5d..00000000 --- a/lib/src/mips1/al/alSynAllocFX.c +++ /dev/null @@ -1,16 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x80065860 */ - -#include "types.h" -#include "macros.h" -#include "audio_internal.h" - -ALFxRef *alSynAllocFX(ALSynth *s, s16 bus, ALSynConfig *c, ALHeap *hp) -{ - alFxNew(&s->auxBus[bus].fx[0], c, bus, 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/lib/src/mips1/al/alSynSetPan.c b/lib/src/mips1/al/alSynSetPan.c deleted file mode 100644 index a1f30663..00000000 --- a/lib/src/mips1/al/alSynSetPan.c +++ /dev/null @@ -1,29 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x80065B20 */ - -#include "alSynStartVoiceParams.h" - -#include "types.h" -#include "macros.h" -#include "audio_internal.h" - -ALParam *__allocParam(); - -void alSynSetPan(ALSynth *synth, ALVoice *v, u8 pan) { - ALParam *update; - ALFilter *f; - - if (v->pvoice) { - update = __allocParam(); - - if(update != NULL) { - update->delta = synth->paramSamples + v->pvoice->offset; - update->type = AL_FILTER_SET_PAN; - update->data.i = modify_panning(pan); - update->next = 0; - - f = v->pvoice->channelKnob; - (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); - } - } -} diff --git a/lib/src/mips1/al/alSynStartVoiceParams.c b/lib/src/mips1/al/alSynStartVoiceParams.c deleted file mode 100644 index 1eea9e40..00000000 --- a/lib/src/mips1/al/alSynStartVoiceParams.c +++ /dev/null @@ -1,51 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x80065BD0 */ - -#include "alSynStartVoiceParams.h" - -s16 gStereoPanMode = STEREO; - -void set_stereo_pan_mode(s32 panMode) { - gStereoPanMode = panMode; -} - -/* Unused. */ -s16 get_stereo_pan_mode(void) { - return gStereoPanMode; -} - -s32 modify_panning(s32 pan) { - switch(gStereoPanMode) { - case STEREO: - return pan; - case HEADPHONES: - pan = ((pan - 64) >> 1) + 64; - return pan; - case MONO: - default: - return 64; - } -} - -void alSynStartVoiceParams(ALSynth *s, ALVoice *v, ALWaveTable *w, f32 pitch, s16 vol, ALPan pan, u8 fxmix, ALMicroTime t) { - ALStartParamAlt *update; - ALFilter *f; - - if (v->pvoice) { - update = (ALStartParamAlt *)__allocParam(); - if (update != NULL) { - update->delta = s->paramSamples + v->pvoice->offset; - update->next = 0; - update->type = AL_FILTER_START_VOICE_ALT; - update->unity = v->unityPitch; - update->pan = modify_panning(pan); - update->volume = vol; - update->fxMix = fxmix; - update->pitch = pitch; - update->samples = __timeToSamples(s, t); - update->wave = w; - f = v->pvoice->channelKnob; - (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); - } - } -} diff --git a/lib/src/mips1/al/csplayer.c b/lib/src/mips1/al/csplayer.c deleted file mode 100644 index 8c6c3962..00000000 --- a/lib/src/mips1/al/csplayer.c +++ /dev/null @@ -1,852 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x80062290 */ - -#include "PR/os_exception.h" -#include "types.h" -#include "macros.h" -#include "audio_internal.h" -#include "seqp.h" -#include "cseqp.h" -#include "cseq.h" - -/************ .rodata ************/ - -const char D_800E6C20[] = "CSP: oh oh \n"; - -/*********************************/ - -void __CSPPostNextSeqEvent(ALCSPlayer *seqp); -void __CSPHandleNextSeqEvent(ALCSPlayer *seqp); -void __CSPHandleMetaMsg(ALCSPlayer *seqp, ALEvent *event); -void __CSPRepostEvent(ALEventQueue *evtq, ALEventListItem *item); -void __setUsptFromTempo(ALCSPlayer *seqp, f32 tempo); -void alCSeqNextEvent(ALCSeq *seq, ALEvent *event); -void __CSPHandleMIDIMsg(ALCSPlayer_Custom *seqp, ALEvent *event); -ALMicroTime __CSPVoiceHandler(void *node); -void __CSPHandleNextSeqEvent(ALCSPlayer *seqp); -void func_80065A80(ALSynth *arg0, PVoice *arg1, s16 arg2); - -/* - * Sequence Player public functions - */ -void alCSPNew(ALCSPlayer *seqp, ALSeqpConfig *c) -{ - s32 i; - ALEventListItem *items; - ALVoiceState *vs; - ALVoiceState *voices; - - ALHeap *hp = c->heap; - - /* - * initialize member variables - */ - seqp->bank = NULL; - seqp->target = NULL; - seqp->drvr = &alGlobals->drvr; - seqp->chanMask = 0xffff; - seqp->uspt = 488; - seqp->nextDelta = 0; - seqp->state = AL_STOPPED; - seqp->vol = 0x7FFF; /* full volume */ - seqp->frameTime = AL_USEC_PER_FRAME; /* should get this from driver */ - seqp->curTime = 0; - seqp->initOsc = c->initOsc; - seqp->updateOsc = c->updateOsc; - seqp->stopOsc = c->stopOsc; - seqp->unk71 = 0; - seqp->unk70 = c->unknown_0x10; - - seqp->nextEvent.type = AL_SEQP_API_EVT; /* this will start the voice handler "spinning" */ - - /* - * init the channel state - */ - seqp->maxChannels = c->maxChannels; - seqp->chanState = alHeapAlloc(hp, c->maxChannels, sizeof(ALChanState)+4); //TODO: ALChanState likely has some added values as well - __initChanState((void *) seqp); /* sct 11/6/95 */ - - /* - * init the voice state array - */ - voices = alHeapAlloc(hp, c->maxVoices, sizeof(ALVoiceState)); - seqp->vFreeList = 0; - for (i = 0; i < c->maxVoices; i++) { - vs = &voices[i]; - vs->next = seqp->vFreeList; - seqp->vFreeList = vs; - } - - seqp->vAllocHead = 0; - seqp->vAllocTail = 0; - - /* - * init the event queue - */ - items = alHeapAlloc(hp, c->maxEvents, sizeof(ALEventListItem)); - alEvtqNew(&seqp->evtq, items, c->maxEvents); - - - /* - * add ourselves to the driver - */ - seqp->node.next = NULL; - seqp->node.handler = __CSPVoiceHandler; - seqp->node.clientData = seqp; - alSynAddPlayer(&alGlobals->drvr, &seqp->node); -} - -/************************************************************* - * private routines or driver callback routines - *************************************************************/ -ALMicroTime __CSPVoiceHandler(void *node) -{ - ALCSPlayer_Custom *seqp = (ALCSPlayer_Custom *) node; - ALEvent evt; - ALVoice *voice; - ALMicroTime delta; - ALVoiceState *vs; - void *oscState; - f32 oscValue; - u8 chan; - - do { - switch (seqp->nextEvent.type) - { - case (AL_SEQ_REF_EVT): - __CSPHandleNextSeqEvent((void *) seqp); - break; - - case (AL_SEQP_API_EVT): - evt.type = AL_SEQP_API_EVT; - alEvtqPostEvent(&seqp->evtq, (ALEvent *) &evt, seqp->frameTime); - break; - - case (AL_NOTE_END_EVT): - voice = seqp->nextEvent.msg.note.voice; - - alSynStopVoice(seqp->drvr, voice); - alSynFreeVoice(seqp->drvr, voice); - vs = (ALVoiceState *) voice->clientPrivate; - if(vs->flags) - __seqpStopOsc((ALSeqPlayer *) seqp,vs); - __unmapVoice((ALSeqPlayer *) seqp, voice); - break; - - case (AL_SEQP_ENV_EVT): - voice = seqp->nextEvent.msg.vol.voice; - vs = (ALVoiceState *) voice->clientPrivate; - - if(vs->envPhase == AL_PHASE_ATTACK) - vs->envPhase = AL_PHASE_DECAY; - - delta = seqp->nextEvent.msg.vol.delta; - vs->envEndTime = seqp->curTime + delta; - vs->envGain = seqp->nextEvent.msg.vol.vol; - alSynSetVol(seqp->drvr, voice, __vsVol(vs, (ALSeqPlayer *) seqp), delta); - break; - - case (AL_TREM_OSC_EVT): - vs = seqp->nextEvent.msg.osc.vs; - oscState = seqp->nextEvent.msg.osc.oscState; - delta = (*seqp->updateOsc)(oscState,&oscValue); - vs->tremelo = (u8) oscValue; - alSynSetVol(seqp->drvr, &vs->voice, __vsVol(vs,(ALSeqPlayer *) seqp), - __vsDelta(vs,seqp->curTime)); - evt.type = AL_TREM_OSC_EVT; - evt.msg.osc.vs = vs; - evt.msg.osc.oscState = oscState; - alEvtqPostEvent(&seqp->evtq, &evt, delta); - break; - - case (AL_VIB_OSC_EVT): - vs = seqp->nextEvent.msg.osc.vs; - oscState = seqp->nextEvent.msg.osc.oscState; - chan = seqp->nextEvent.msg.osc.chan; - delta = (*seqp->updateOsc)(oscState,&oscValue); - vs->vibrato = oscValue; - alSynSetPitch(seqp->drvr, &vs->voice, vs->pitch * vs->vibrato - * seqp->chanState[chan].pitchBend); - evt.type = AL_VIB_OSC_EVT; - evt.msg.osc.vs = vs; - evt.msg.osc.oscState = oscState; - evt.msg.osc.chan = chan; - alEvtqPostEvent(&seqp->evtq, &evt, delta); - break; - - case (AL_SEQP_MIDI_EVT): - case (AL_CSP_NOTEOFF_EVT): /* nextEvent is a note off midi message */ - __CSPHandleMIDIMsg((void *) seqp, &seqp->nextEvent); - break; - - case (AL_SEQP_META_EVT): - __CSPHandleMetaMsg((void *) seqp, &seqp->nextEvent); - break; - - case (AL_SEQP_VOL_EVT): - seqp->vol = seqp->nextEvent.msg.spvol.vol; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - alSynSetVol(seqp->drvr, &vs->voice, - __vsVol(vs, (ALSeqPlayer *) seqp), - __vsDelta(vs, seqp->curTime)); - } - break; - - case (AL_SEQP_PLAY_EVT): - if (seqp->state != AL_PLAYING) - { - seqp->state = AL_PLAYING; - __CSPPostNextSeqEvent((void *) seqp); /* seqp must be AL_PLAYING before we call this routine. */ - } - break; - - case (AL_SEQP_STOP_EVT): - if ( seqp->state == AL_STOPPING ) - { - seqp->chanMask = 0xFFFF; - for (chan = 0; chan < seqp->maxChannels; chan++) - { - seqp->chanState[chan].fade = 0x7F; - seqp->chanState[chan].vol = seqp->chanState[chan].unk11; - } - - for (vs = seqp->vAllocHead; vs != 0; vs = seqp->vAllocHead) - { -#ifdef _DEBUG - __osError(ERR_ALCSPVNOTFREE, 2, vs->channel, vs->key); -#endif - alSynStopVoice(seqp->drvr, &vs->voice); - alSynFreeVoice(seqp->drvr, &vs->voice); - if(vs->flags) - __seqpStopOsc((ALSeqPlayer *) seqp,vs); - __unmapVoice((ALSeqPlayer *) seqp, &vs->voice); - } - seqp->state = AL_STOPPED; - - /* alEvtqFlush(&seqp->evtq); - Don't flush event queue - anymore. */ - /* sct 1/3/96 - Don't overwrite nextEvent with - AL_SEQP_API_EVT or set nextDelta to - AL_USEC_PER_FRAME since we're not stopping event - processing. */ - /* sct 1/3/96 - Don't return here since we keep - processing events as usual. */ - } - break; - - case (AL_SEQP_STOPPING_EVT): - if (seqp->state == AL_PLAYING) - { - /* sct 12/29/95 - Remove events associated with the - * stopping sequence. For compact sequence player, - * also remove all queued note off events since they - * are not contained in a compact sequence but are - * generated in response to note ons. Note that - * flushing AL_SEQP_MIDI_EVTs may flush events that - * were posted after the call to alSeqpStop, so the - * application must queue these events either when - * the player is fully stopped, or when it is - * playing. */ - alEvtqFlushType(&seqp->evtq, AL_SEQ_REF_EVT); - alEvtqFlushType(&seqp->evtq, AL_CSP_NOTEOFF_EVT); - alEvtqFlushType(&seqp->evtq, AL_SEQP_MIDI_EVT); - - /* sct 1/3/96 - Check to see which voices need to be - killed and release them. */ - /* Unkilled voices should have note end events - occurring prior to KILL_TIME. */ - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - if (__voiceNeedsNoteKill ((ALSeqPlayer *) seqp, &vs->voice, KILL_TIME)) - __seqpReleaseVoice((ALSeqPlayer *) seqp, &vs->voice, KILL_TIME); - } - - seqp->state = AL_STOPPING; - evt.type = AL_SEQP_STOP_EVT; - alEvtqPostEvent(&seqp->evtq, &evt, AL_EVTQ_END); - } - break; - - case (AL_SEQP_PRIORITY_EVT): - chan = seqp->nextEvent.msg.sppriority.chan; - seqp->chanState[chan].priority = seqp->nextEvent.msg.sppriority.priority; - break; - - case (AL_SEQP_SEQ_EVT): - -#ifdef _DEBUG - assert(seqp->state != AL_PLAYING); /* Must be done playing to change sequences. */ -#endif - - seqp->target = seqp->nextEvent.msg.spseq.seq; - //__setUsptFromTempo (seqp, 500000.0); - if (seqp->bank) - __initFromBank((ALSeqPlayer *) seqp, seqp->bank); - break; - - case (AL_SEQP_BANK_EVT): - -#ifdef _DEBUG - assert(seqp->state == AL_STOPPED); /* Must be fully stopped to change banks. */ -#endif - - seqp->bank = seqp->nextEvent.msg.spbank.bank; - __initFromBank((ALSeqPlayer *) seqp, seqp->bank); - break; - - /* sct 11/6/95 - these events should now be handled by __CSPHandleNextSeqEvent */ - case (AL_SEQ_END_EVT): - case (AL_TEMPO_EVT): - case (AL_SEQ_MIDI_EVT): - -#ifdef _DEBUG - assert(FALSE); -#endif - - break; - } - seqp->nextDelta = alEvtqNextEvent(&seqp->evtq, &seqp->nextEvent); - - } while (seqp->nextDelta == 0); - - /* - * assume that next callback won't be more than half an - * hour away - */ - seqp->curTime += seqp->nextDelta; /* sct 11/7/95 */ - return seqp->nextDelta; -} - -void __CSPPostNextSeqEvent(ALCSPlayer *seqp) -{ - ALEvent evt; - s32 deltaTicks; - - if (seqp->state != AL_PLAYING || seqp->target == NULL) - return; - - /* Get the next event time in ticks. */ - /* If false is returned, then there is no next delta (ie. end of sequence reached). */ - if (!__alCSeqNextDelta(seqp->target, &deltaTicks)) - return; - - evt.type = AL_SEQ_REF_EVT; - alEvtqPostEvent(&seqp->evtq, &evt, deltaTicks * seqp->uspt); -} - -void __CSPHandleNextSeqEvent(ALCSPlayer *seqp) -{ - ALEvent evt; - - if (seqp->target == NULL) - return; - - alCSeqNextEvent(seqp->target, &evt); - - switch (evt.type) - { - case AL_SEQ_MIDI_EVT: - __CSPHandleMIDIMsg((void *) seqp, &evt); - __CSPPostNextSeqEvent(seqp); - break; - - case AL_TEMPO_EVT: - __CSPHandleMetaMsg((void *) seqp, &evt); - __CSPPostNextSeqEvent(seqp); - break; - - case AL_SEQ_END_EVT: - seqp->state = AL_STOPPING; - evt.type = AL_SEQP_STOP_EVT; - alEvtqPostEvent(&seqp->evtq, &evt, AL_EVTQ_END); - break; - - case AL_TRACK_END: - case AL_CSP_LOOPSTART: - case AL_CSP_LOOPEND: - __CSPPostNextSeqEvent(seqp); - break; - } -} - -void __CSPHandleMIDIMsg(ALCSPlayer_Custom *seqp, ALEvent *event) -{ - ALVoiceState *vs; - s32 i; - s32 status; - u8 chan; - u8 byte1; - u8 byte2; - u8 fxmix; - ALVoice *voice; - ALMIDIEvent *midi = &event->msg.midi; - s16 vol; - ALEvent evt; - ALVoiceState *vstate; - ALFxRef fxref; - ALPan pan; - ALMicroTime deltaTime; - ALVoiceConfig config; - ALSound *sound; - u8 key; - u8 vel; - f32 pitch; - f32 oscValue; - s32 pad; - void *oscState; - ALInstrument *inst; - s32 bendVal; - s32 pad2; - s32 pad3; - f32 bendRatio; - - status = midi->status & AL_MIDI_StatusMask; - chan = midi->status & AL_MIDI_ChannelMask; - key = byte1 = midi->byte1; - vel = byte2 = midi->byte2; - - if (status == AL_MIDI_ChannelModeSelect) - { - if (key == 0x6A) - { - seqp->chanMask &= ~(1 << byte2); - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - if (vs->channel == byte2) - __seqpReleaseVoice((ALSeqPlayer *) seqp, &vs->voice, vs->sound->envelope->releaseTime); - } - return; - } - else if (key == 0x6C) - { - seqp->chanMask |= 1 << byte2; - return; - } - - } - if ((1 << chan) & seqp->chanMask) - { - } - else if ( - status != AL_MIDI_ProgramChange && - status != AL_MIDI_ControlChange && - status != AL_MIDI_PitchBendChange - ) - { - return; - } - - switch (status) - { - case (AL_MIDI_NoteOn): - /* a real note on */ - if (byte2 != 0) { - /* If we're not playing, don't process note ons. */ - if (seqp->state != AL_PLAYING) - { - break; - } - - // chan should be located at spCB - sound = __lookupSoundQuick((ALSeqPlayer*)seqp, byte1, byte2, chan); - ALFlagFailIf(!sound, seqp->debugFlags & NO_SOUND_ERR_MASK, ERR_ALSEQP_NO_SOUND); - - config.priority = seqp->chanState[chan].priority; - config.fxBus = 0; - config.unityPitch = 0; - - vstate = __mapVoice((ALSeqPlayer*)seqp, byte1, byte2, chan); - ALFlagFailIf(!vstate, seqp->debugFlags & NO_VOICE_ERR_MASK, ERR_ALSEQP_NO_VOICE); - - voice = &vstate->voice; - if (alSynAllocVoice(seqp->drvr, voice, &config)) - { - func_80065A80(seqp->drvr, voice->pvoice, 0); - } - - vstate->sound = sound; - vstate->envPhase = AL_PHASE_ATTACK; - vstate->phase = seqp->chanState[chan].sustain > AL_SUSTAIN ? AL_PHASE_SUSTAIN : AL_PHASE_NOTEON; - vstate->pitch = alCents2Ratio((s16)((byte1 - sound->keyMap->keyBase) * 100 + sound->keyMap->detune)); - vstate->envGain = sound->envelope->attackVolume; - vstate->envEndTime = seqp->curTime + sound->envelope->attackTime; - - /* - * setup tremelo and vibrato if active - */ - vstate->flags = 0; - inst = seqp->chanState[chan].instrument; - - oscValue = AL_VOL_FULL; /* set this as a default */ - if (inst->tremType) - { - if (seqp->initOsc) - { - deltaTime = (*seqp->initOsc)(&oscState,&oscValue,inst->tremType, inst->tremRate,inst->tremDepth,inst->tremDelay); - /* a deltaTime of zero means don't run osc */ - if (deltaTime != 0) - { - evt.type = AL_TREM_OSC_EVT; - evt.msg.osc.vs = vstate; - evt.msg.osc.oscState = oscState; - alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); - vstate->flags |= 0x01; /* set tremelo flag bit */ - } - } - } - - vstate->tremelo = oscValue; /* will default if not changed by initOsc */ - oscValue = 1; /* set this as a default */ - if (inst->vibType) - { - if (seqp->initOsc) - { - deltaTime = (*seqp->initOsc)(&oscState,&oscValue,inst->vibType, inst->vibRate,inst->vibDepth,inst->vibDelay); - /* a deltaTime of zero means don't run osc. */ - if (deltaTime != 0) - { - evt.type = AL_VIB_OSC_EVT; - evt.msg.osc.vs = vstate; - evt.msg.osc.oscState = oscState; - evt.msg.osc.chan = chan; - alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); - vstate->flags |= 0x02; /* set the vibrato flag bit */ - } - } - } - vstate->vibrato = oscValue; /* will default if not changed by initOsc */ - - /* - * calculate the note on parameters - */ - pitch = vstate->pitch * seqp->chanState[chan].pitchBend * vstate->vibrato; - fxmix = seqp->chanState[chan].fxmix; - pan = __vsPan(vstate, (ALSeqPlayer*)seqp); - vol = __vsVol(vstate, (ALSeqPlayer*)seqp); - deltaTime = sound->envelope->attackTime; - - alSynStartVoiceParams(seqp->drvr, voice, sound->wavetable, pitch, vol, pan, fxmix, deltaTime); - /* - * set up callbacks for envelope - */ - evt.type = AL_SEQP_ENV_EVT; - evt.msg.vol.voice = voice; - evt.msg.vol.vol = sound->envelope->decayVolume; - evt.msg.vol.delta = sound->envelope->decayTime; - - alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); - - if (midi->duration) - { - /* - * set up note off evt. if no duration don't do this - */ - evt.type = AL_CSP_NOTEOFF_EVT; - evt.msg.midi.status = chan | AL_MIDI_NoteOff; - evt.msg.midi.byte1 = byte1; - evt.msg.midi.byte2 = 0; /* not needed ? */ - deltaTime = seqp->uspt * midi->duration; - - /* max time would be about one hour ten minutes */ - alEvtqPostEvent(&seqp->evtq, &evt, deltaTime); - } - - break; - } - - /* - * NOTE: intentional fall-through for note on with zero - * velocity (Should never happen with compact midi sequence, - * but could happen with real time midi.) - */ - - case (AL_MIDI_NoteOff): - vstate = __lookupVoice((ALSeqPlayer*)seqp, byte1, chan); - ALFlagFailIf(!vstate, seqp->debugFlags & NOTE_OFF_ERR_MASK, ERR_ALSEQP_OFF_VOICE); - - if (vstate->phase == AL_PHASE_SUSTAIN) - { - vstate->phase = AL_PHASE_SUSTREL; - } - else - { - vstate->phase = AL_PHASE_RELEASE; - __seqpReleaseVoice((ALSeqPlayer*)seqp, &vstate->voice, vstate->sound->envelope->releaseTime); - } - - break; - case (AL_MIDI_PolyKeyPressure): - /* - * Aftertouch per byte1 (hardwired to volume). Note that - * aftertouch affects only notes that are already - * sounding. - */ - vstate = __lookupVoice((ALSeqPlayer*)seqp, byte1, chan); - ALFailIf(!vstate, ERR_ALSEQP_POLY_VOICE); - - vstate->velocity = byte2; - alSynSetVol(seqp->drvr, &vstate->voice, __vsVol(vstate, (ALSeqPlayer*)seqp), __vsDelta(vstate,seqp->curTime)); - break; - case (AL_MIDI_ChannelPressure): - /* - * Aftertouch per channel (hardwired to volume). Note that - * aftertouch affects only notes that are already - * sounding. - */ - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - if (vs->channel == chan) - { - vs->velocity = byte1; - alSynSetVol(seqp->drvr, &vs->voice, __vsVol(vs, (ALSeqPlayer*)seqp), __vsDelta(vs,seqp->curTime)); - } - } - break; - case (AL_MIDI_ControlChange): - switch (byte1) - { - case (AL_MIDI_PAN_CTRL): - seqp->chanState[chan].pan = byte2; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - if (vs->channel == chan) - { - pan = __vsPan(vs, (ALSeqPlayer*)seqp); - alSynSetPan(seqp->drvr, &vs->voice, pan); - } - } - break; - case (AL_MIDI_VOLUME_CTRL): - { - seqp->chanState[chan].unk11 = byte2; - seqp->chanState[chan].vol = ((f32)seqp->chanState[chan].fade * byte2) / 127.0f; - - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - if ((vs->channel == chan) && (vs->envPhase != AL_PHASE_RELEASE)) - { - vol = __vsVol(vs, (ALSeqPlayer*)seqp); - alSynSetVol(seqp->drvr, &vs->voice, vol, __vsDelta(vs,seqp->curTime)); - } - } - } - break; - case (8): - seqp->chanState[chan].fade = byte2; - seqp->chanState[chan].vol = (seqp->chanState[chan].unk11 * seqp->chanState[chan].fade) / 127.0f; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - if ((vs->channel == chan) && (vs->envPhase != AL_PHASE_RELEASE)) - { - vol = __vsVol(vs, (ALSeqPlayer*)seqp); - alSynSetVol(seqp->drvr, &vs->voice, vol, __vsDelta(vs,seqp->curTime)); - } - } - break; - case (AL_MIDI_PRIORITY_CTRL): - /* leave current voices where they are */ - seqp->chanState[chan].priority = byte2; - break; - case (AL_MIDI_SUSTAIN_CTRL): - seqp->chanState[chan].sustain = byte2; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - if (vs->channel != chan) - { - continue; - } - - if (vs->phase == AL_PHASE_RELEASE) - { - continue; - } - - if (byte2 > AL_SUSTAIN ) - { - /* sustain pedal down */ - if (vs->phase == AL_PHASE_NOTEON) - { - vs->phase = AL_PHASE_SUSTAIN; - } - } - else - { - /* sustain pedal up */ - if (vs->phase == AL_PHASE_SUSTAIN) - { - vs->phase = AL_PHASE_NOTEON; - } - else if (vs->phase == AL_PHASE_SUSTREL) - { - vs->phase = AL_PHASE_RELEASE; - __seqpReleaseVoice((ALSeqPlayer*)seqp, &vs->voice, vs->sound->envelope->releaseTime); - } - } - } - break; - case (AL_MIDI_FX1_CTRL): - seqp->chanState[chan].fxmix = byte2; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - if (vs->channel == chan) - { - alSynSetFXMix(seqp->drvr, &vs->voice, byte2); - } - } - break; - case (0x5F): - seqp->unk36 = byte2; - for (i = 0; i < seqp->maxChannels; i++) - { - if (seqp->chanState[i].fxmix < byte2) - { - seqp->chanState[i].fxmix = 0; - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - { - if (vs->channel == i) - { - alSynSetFXMix(seqp->drvr, &vs->voice, byte2); - } - } - } - } - break; - default: - break; - } - break; - case (AL_MIDI_ProgramChange): - if (byte1 < seqp->bank->instCount) - { - ALInstrument *inst = seqp->bank->instArray[byte1]; - __setInstChanState((ALSeqPlayer*)seqp, inst, chan); - } - else - { -#ifdef _DEBUG - __osError(ERR_ALSEQPINVALIDPROG, 2, byte1, seqp->bank->instCount); -#endif - } - break; - case (AL_MIDI_PitchBendChange): - { - /* get 14-bit unsigned midi value */ - bendVal = ( (byte2 << 7) + byte1) - 8192; - - /* calculate the corresponding ratio */ - bendRatio = alCents2Ratio((seqp->chanState[chan].bendRange * bendVal)/8192); - seqp->chanState[chan].pitchBend = bendRatio; - - for (vs = seqp->vAllocHead; vs != 0; vs = vs->next) - if (vs->channel == chan) - { - alSynSetPitch(seqp->drvr, &vs->voice, vs->pitch * bendRatio * vs->vibrato); - } - - } - break; - default: -#ifdef _DEBUG - __osError(ERR_ALSEQPUNKNOWNMIDI, 1, status); -#endif - break; - } -} - -void __CSPHandleMetaMsg(ALCSPlayer *seqp, ALEvent *event) -{ - ALTempoEvent *tevt = &event->msg.tempo; - s32 tempo; - s32 oldUspt; - u32 ticks; - ALMicroTime tempDelta,curDelta = 0; - ALEventListItem *thisNode,*nextNode,*firstTemp = 0; - - - if (event->msg.tempo.status == AL_MIDI_Meta) - { - if (event->msg.tempo.type == AL_MIDI_META_TEMPO) - { - oldUspt = seqp->uspt; - tempo = (tevt->byte1 << 16) | (tevt->byte2 << 8) | (tevt->byte3 << 0); - __setUsptFromTempo (seqp, (f32) tempo); /* sct 1/8/96 */ - - thisNode = (ALEventListItem *) seqp->evtq.allocList.next; - while(thisNode) - { - curDelta += thisNode->delta; - nextNode = (ALEventListItem *) thisNode->node.next; - if(thisNode->evt.type == AL_CSP_NOTEOFF_EVT) - { - alUnlink((ALLink *) thisNode); - - if(firstTemp) - alLink((ALLink *) thisNode,(ALLink *) firstTemp); - else - { - thisNode->node.next = 0; - thisNode->node.prev = 0; - firstTemp = thisNode; - } - tempDelta = curDelta; /* record the current delta */ - if(nextNode) /* don't do this if no nextNode */ - { - curDelta -= thisNode->delta; /* subtract out this delta */ - nextNode->delta += thisNode->delta; /* add it to next event */ - } - thisNode->delta = tempDelta; /* set this event delta from current */ - } - thisNode = nextNode; - } - - thisNode = firstTemp; - while(thisNode) - { - nextNode = (ALEventListItem *) thisNode->node.next; - ticks = thisNode->delta/oldUspt; - thisNode->delta = ticks * seqp->uspt; - __CSPRepostEvent(&seqp->evtq,thisNode); - thisNode = nextNode; - } - } - } -} - -void __CSPRepostEvent(ALEventQueue *evtq, ALEventListItem *item) -{ - OSIntMask mask; - ALLink *node; - ALEventListItem *nextItem; - - mask = osSetIntMask(OS_IM_NONE); - - for (node = &evtq->allocList; node != 0; node = node->next) - { - if (!node->next) /* end of the list */ - { - alLink((ALLink *)item, node); - break; - } - else - { - nextItem = (ALEventListItem *) node->next; - if (item->delta < nextItem->delta) - { - nextItem->delta -= item->delta; - alLink((ALLink *) item, node); - break; - } - item->delta -= nextItem->delta; - } - } - osSetIntMask(mask); -} - -void __setUsptFromTempo(ALCSPlayer *seqp, f32 tempo) -{ - if (seqp->target) - seqp->uspt = (s32) ((f32) tempo * seqp->target->qnpt); - else - seqp->uspt = 488; /* This is the initial value set by alSeqpNew. */ -} diff --git a/lib/src/os/__osResetGlobalIntMask.c b/lib/src/os/__osResetGlobalIntMask.c deleted file mode 100644 index fdf01e98..00000000 --- a/lib/src/os/__osResetGlobalIntMask.c +++ /dev/null @@ -1,16 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D6500 */ - -#include "libultra_internal.h" - -extern u32 __OSGlobalIntMask; - -void __osResetGlobalIntMask(OSHWIntr interrupt) { - register u32 saveMask = __osDisableInt(); - - //not sure about these constants, SR_IBIT3 is external level 3 INT0, which I think corresponds to the rcp - //os.h has several masks defined that end in 401 but non that are just 401 - __OSGlobalIntMask &= ~(interrupt & ~(SR_IBIT3 | SR_IE)); - - __osRestoreInt(saveMask); -} diff --git a/lib/src/os/__osSetHWIntrRoutine.c b/lib/src/os/__osSetHWIntrRoutine.c deleted file mode 100644 index 4fde9b8d..00000000 --- a/lib/src/os/__osSetHWIntrRoutine.c +++ /dev/null @@ -1,14 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D47DC */ - -#include "libultra_internal.h" - -//TODO: Figure out a better way to declare this. It's currently randomly declared in another file -extern s32 (*__osHwIntTable[])(void); - -void __osSetHWIntrRoutine(OSHWIntr interrupt, s32 (*handler)(void)) { - register u32 saveMask; - saveMask = __osDisableInt(); - __osHwIntTable[interrupt] = handler; - __osRestoreInt(saveMask); -} diff --git a/lib/src/os/__osSiRawReadIo.c b/lib/src/os/__osSiRawReadIo.c deleted file mode 100644 index 799831ad..00000000 --- a/lib/src/os/__osSiRawReadIo.c +++ /dev/null @@ -1,16 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D4590 */ - -#include "types.h" -#include "siint.h" -#include "PR/rcp.h" - -s32 __osSiRawReadIo(u32 devAddr, u32 *data) { - if (__osSiDeviceBusy()) { - return -1; - } - - *data = IO_READ(devAddr); - - return 0; -} diff --git a/lib/src/os/__osSiRawStartDma.c b/lib/src/os/__osSiRawStartDma.c deleted file mode 100644 index 81ef2412..00000000 --- a/lib/src/os/__osSiRawStartDma.c +++ /dev/null @@ -1,25 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CD6C0 */ - -#include "libultra_internal.h" -#include "siint.h" - -s32 __osSiRawStartDma(s32 direction, void *dramAddr) { - if (__osSiDeviceBusy()) - 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/lib/src/os/__osSpDeviceBusy.c b/lib/src/os/__osSpDeviceBusy.c deleted file mode 100644 index a9662071..00000000 --- a/lib/src/os/__osSpDeviceBusy.c +++ /dev/null @@ -1,11 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D64D0 */ - -#include "libultra_internal.h" - -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/lib/src/os/__osSpRawStartDma.c b/lib/src/os/__osSpRawStartDma.c deleted file mode 100644 index 0a3359fe..00000000 --- a/lib/src/os/__osSpRawStartDma.c +++ /dev/null @@ -1,17 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D6440 */ - -#include "libultra_internal.h" -#include "osint.h" - -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/lib/src/os/__osSpSetPc.c b/lib/src/os/__osSpSetPc.c deleted file mode 100644 index a18f4c55..00000000 --- a/lib/src/os/__osSpSetPc.c +++ /dev/null @@ -1,14 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D63FC */ - -#include "libultra_internal.h" - -s32 __osSpSetPc(u32 data) { - register u32 stat = IO_READ(SP_STATUS_REG); - if (!(stat & SP_STATUS_HALT)) - return -1; - else { - IO_WRITE(SP_PC_REG, data); - } - return 0; -} diff --git a/lib/src/os/__osSpSetStatus.c b/lib/src/os/__osSpSetStatus.c deleted file mode 100644 index 9355883a..00000000 --- a/lib/src/os/__osSpSetStatus.c +++ /dev/null @@ -1,10 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CD240 */ - -#include "types.h" -#include "macros.h" -#include "PR/rcp.h" - -void __osSpSetStatus(u32 status) { - IO_WRITE(SP_STATUS_REG, status); -} diff --git a/lib/src/os/__osViGetCurrentContext.c b/lib/src/os/__osViGetCurrentContext.c deleted file mode 100644 index fa33239a..00000000 --- a/lib/src/os/__osViGetCurrentContext.c +++ /dev/null @@ -1,9 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D6080 */ - -#include "libultra_internal.h" -#include "viint.h" - -__OSViContext *__osViGetCurrentContext(void){ - return __osViCurr; -} diff --git a/lib/src/os/contpfs.c b/lib/src/os/contpfs.c deleted file mode 100644 index c0360d78..00000000 --- a/lib/src/os/contpfs.c +++ /dev/null @@ -1,300 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D52EC */ -#include "macros.h" -#include "libultra_internal.h" -#include "controller.h" - -u16 __osSumcalc(u8 *ptr, int length) -{ - int i; - u32 sum; - u8 *tmp; - - sum = 0; - tmp = ptr; - for (i = 0; i < length; i++) - { - sum += *tmp++; - sum &= 0xffff; - } - return sum; -} -s32 __osIdCheckSum(u16 *ptr, u16 *csum, u16 *icsum) -{ - u16 data; - u32 j; - data = 0; - *icsum = 0; - *csum = *icsum; - for (j = 0; j < 28; j += 2) - { - //feels like this should be a compiler optimization not manual.. - //but it doesn't match and I'm pretty sure this is just -O1 - data = *(u16 *)((u8 *)ptr + j); - //data = ptr[j] - *csum += data; - *icsum += ~data; - } - return 0; -} -s32 __osRepairPackId(OSPfs *pfs, __OSPackId *badid, __OSPackId *newid) -{ - - s32 ret; - u8 temp[32]; - u8 comp[32]; - u8 mask; - int i; - int j; - u16 index[4]; - - ret = 0; - mask = 0; - SET_ACTIVEBANK_TO_ZERO; - newid->repaired = -1; - newid->random = osGetCount(); - newid->serial_mid = badid->serial_mid; - newid->serial_low = badid->serial_low; - for (j = 0; j < PFS_MAX_BANKS;) - { - pfs->activebank = j; - ERRCK(__osPfsSelectBank(pfs)) - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, (u8*)&temp)); //TODO: fix magic number - temp[0] = j | 0x80; - for (i = 1; i < ARRLEN(temp); i++) - { - - temp[i] = ~temp[i]; - } - - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, 0, (u8*)temp, FALSE)); //oddr 0, don't force - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, (u8*)&comp)); - - for (i = 0; i < ARRLEN(temp); i++) - { - if (comp[i] != temp[i]) - break; - } - if (i != ARRLEN(temp)) - break; - if (j > 0) - { - pfs->activebank = 0; - ERRCK(__osPfsSelectBank(pfs)); - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 0, (u8*)temp)); - if (temp[0] != 128) - break; //TODO: remove magic constant - } - j++; - } - pfs->activebank = 0; - ERRCK(__osPfsSelectBank(pfs)); - if (j > 0) - mask = 1; - else - mask = 0; - newid->deviceid = (badid->deviceid & (u16)~1) | 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 < ARRLEN(index); i++) - { - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, index[i], (u8*)newid, TRUE)); - } - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 1, (u8*)temp)); - for (i = 0; i < ARRLEN(temp); i++) - { - if (temp[i] != ((u8 *)newid)[i]) - return PFS_ERR_ID_FATAL; - } - return 0; -} - -s32 __osCheckPackId(OSPfs *pfs, __OSPackId *temp) -{ - u16 index[4]; - s32 ret; - u16 sum; - u16 isum; - int i; - int j; - - ret = 0; - SET_ACTIVEBANK_TO_ZERO; - index[0] = 1; - index[1] = 3; - index[2] = 4; - index[3] = 6; - for (i = 1; i < ARRLEN(index); i++) - { - ERRCK(__osContRamRead(pfs->queue, pfs->channel, index[i], (u8*)temp)); - __osIdCheckSum((u16 *)temp, &sum, &isum); - if (temp->checksum == sum && temp->inverted_checksum == isum) - break; - } - if (i == ARRLEN(index)) - return PFS_ERR_ID_FATAL; - - for (j = 0; j < ARRLEN(index); j++) - { - if (j != i) - { - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, index[j], (u8*)temp, TRUE)); - } - } - return 0; -} - -s32 __osGetId(OSPfs *pfs) -{ - int k; - u16 sum; - u16 isum; - u8 temp[32]; - __OSPackId newid; - s32 ret; - __OSPackId *id; - - SET_ACTIVEBANK_TO_ZERO; - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 1, (u8*)temp)); - __osIdCheckSum((u16*)temp, &sum, &isum); - id = (__OSPackId*)temp; - if (id->checksum != sum || id->inverted_checksum != isum) - { - ret = __osCheckPackId(pfs, id); - if (ret == PFS_ERR_ID_FATAL) - { - ERRCK(__osRepairPackId(pfs, id, &newid)); - id = &newid; - } - else if (ret != 0) - { - return ret; - } - } - if ((id->deviceid & 1) == 0) //TODO: remove magic constant - { - ERRCK(__osRepairPackId(pfs, id, &newid)); - id = &newid; - if ((id->deviceid & 1) == 0) - return PFS_ERR_DEVICE; - } - for (k = 0; k < ARRLEN(pfs->id); k++) - { - pfs->id[k] = ((u8 *)id)[k]; - } - pfs->version = id->version; - pfs->banks = id->banks; - pfs->inode_start_page = pfs->banks * 2 + 3; //TODO: loads of magic constants.. - pfs->dir_size = 16; - pfs->inode_table = 8; - pfs->minode_table = pfs->banks * PFS_ONE_PAGE + 8; - pfs->dir_table = pfs->minode_table + pfs->banks * PFS_ONE_PAGE; - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 7, pfs->label)); - return 0; -} - -s32 __osCheckId(OSPfs *pfs) -{ - int k; - u8 temp[32]; - s32 ret; - - SET_ACTIVEBANK_TO_ZERO; - ret = __osContRamRead(pfs->queue, pfs->channel, 1, (u8*)temp); - if (ret != 0) - { - if (ret != PFS_ERR_NEW_PACK) - return ret; - ERRCK(__osContRamRead(pfs->queue, pfs->channel, 1, (u8*)temp)); - } - - for (k = 0; k < ARRLEN(temp); k++) - { - if (pfs->id[k] != temp[k]) - return PFS_ERR_NEW_PACK; - } - - return 0; -} - -s32 __osPfsRWInode(OSPfs *pfs, __OSInode *inode, u8 flag, u8 bank) -{ - u8 sum; - int j; - s32 ret; - int offset; - u8 *addr; - - SET_ACTIVEBANK_TO_ZERO; - - if (bank > 0) - offset = 1; - else - offset = pfs->inode_start_page; - - if (flag == PFS_WRITE) - inode->inode_page[0].inode_t.page = __osSumcalc((u8*)&inode->inode_page[offset], (-offset) * 2 + 256); - - for (j = 0; j < 8; j++) - { - addr = ((u8 *)inode->inode_page + j * 32); //TODO: don't like this =/ //maybe &inode->inode_table[j*PFS_ONE_PAGE].ipage or something - if (flag == PFS_WRITE) - { - ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->inode_table + bank * 8 + j, addr, FALSE); - ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->minode_table + bank * 8 + j, addr, FALSE); - } - else - { - ret = __osContRamRead(pfs->queue, pfs->channel, pfs->inode_table + bank * 8 + j, addr); - } - if (ret != 0) - return ret; - } - if (flag == PFS_READ) - { - sum = __osSumcalc((u8*)&inode->inode_page[offset], (-offset) * 2 + 256); - if (sum != inode->inode_page[0].inode_t.page) - { - for (j = 0; j < PFS_ONE_PAGE; j++) - { - addr = ((u8 *)inode->inode_page + j * 32); - ret = __osContRamRead(pfs->queue, pfs->channel, pfs->minode_table + bank * PFS_ONE_PAGE + j, addr); - } - 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 * 32); - ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->inode_table + bank * PFS_ONE_PAGE + j, addr, FALSE); - } - } - else - { - for (j = 0; j < PFS_ONE_PAGE; j++) - { - addr = ((u8 *)inode->inode_page + j * 32); - ret = __osContRamWrite(pfs->queue, pfs->channel, pfs->minode_table + bank * PFS_ONE_PAGE + j, addr, FALSE); - } - } - } - return 0; -} - -s32 __osPfsSelectBank(OSPfs *pfs) -{ - u8 temp[BLOCKSIZE]; - int i; - s32 ret; - ret = 0; - for (i = 0; i < ARRLEN(temp); i++) - { - temp[i] = pfs->activebank; - } - ret = __osContRamWrite(pfs->queue, pfs->channel, 1024, (u8*)temp, FALSE); - return ret; -} diff --git a/lib/src/os/contramread.c b/lib/src/os/contramread.c deleted file mode 100644 index 872a93c7..00000000 --- a/lib/src/os/contramread.c +++ /dev/null @@ -1,90 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CDCA0 */ - -#include "libultra_internal.h" -#include "controller.h" -#include "siint.h" - -static void __osPackRamReadData(int channel, u16 address); -s32 __osContRamRead(OSMesgQueue *mq, int channel, u16 address, u8 *buffer) { - s32 ret; - int i; - u8 *ptr; - __OSContRamReadFormat ramreadformat; - int retry; - ret = 0; - ptr = (u8 *)&__osPfsPifRam; - retry = 2; - __osSiGetAccess(); - __osContLastCmd = CONT_CMD_READ_MEMPACK; - __osPackRamReadData(channel, address); - ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - do { - for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus - __osPfsPifRam.ramarray[i] = 0xFFU; - } - __osPfsPifRam.pifstatus = CONT_CMD_REQUEST_STATUS; - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - ptr = (u8 *)&__osPfsPifRam; - if (channel != 0) { - for (i = 0; i < channel; i++) { - ptr++; - } - } - ramreadformat = *(__OSContRamReadFormat *)ptr; - ret = CHNL_ERR(ramreadformat); - if (ret == 0) { - u8 c; - c = __osContDataCrc((u8*)&ramreadformat.data); - if (c != ramreadformat.datacrc) { - ret = __osPfsGetStatus(mq, channel); - if (ret != 0) { - __osSiRelAccess(); - return ret; - } - ret = PFS_ERR_CONTRFAIL; - } else { - for (i = 0; i < ARRLEN(ramreadformat.data); i++) { - *buffer++ = ramreadformat.data[i]; - } - } - } - if (ret != PFS_ERR_CONTRFAIL) - break; - } while (retry-- >= 0); - __osSiRelAccess(); - return ret; -} - -static void __osPackRamReadData(int channel, u16 address) { - u8 *ptr; - __OSContRamReadFormat ramreadformat; - int i; - - ptr = (u8 *)__osPfsPifRam.ramarray; - - for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus - __osPfsPifRam.ramarray[i] = 0; - } - - __osPfsPifRam.pifstatus = CONT_CMD_EXE; - ramreadformat.dummy = CONT_CMD_NOP; - ramreadformat.txsize = CONT_CMD_READ_MEMPACK_TX; - ramreadformat.rxsize = CONT_CMD_READ_MEMPACK_RX; - ramreadformat.cmd = CONT_CMD_READ_MEMPACK; - ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); - ramreadformat.datacrc = CONT_CMD_NOP; - for (i = 0; i < ARRLEN(ramreadformat.data); i++) { - ramreadformat.data[i] = CONT_CMD_NOP; - } - if (channel != 0) { - for (i = 0; i < channel; i++) { - *ptr++ = 0; - } - } - *(__OSContRamReadFormat *)ptr = ramreadformat; - ptr += sizeof(__OSContRamReadFormat); - ptr[0] = CONT_CMD_END; -} diff --git a/lib/src/os/contramwrite.c b/lib/src/os/contramwrite.c deleted file mode 100644 index 0462d816..00000000 --- a/lib/src/os/contramwrite.c +++ /dev/null @@ -1,92 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CD8F0 */ - -#include "libultra_internal.h" -#include "controller.h" -#include "siint.h" - -static void __osPackRamWriteData(int channel, u16 address, u8 *buffer); - -s32 __osContRamWrite(OSMesgQueue *mq, int channel, u16 address, u8 *buffer, int force) { - s32 ret; - int i; - u8 *ptr; - __OSContRamReadFormat ramreadformat; - int retry; - - ret = 0; - ptr = (u8 *)&__osPfsPifRam; - retry = 2; - if (force != 1 && address < 7 && address != 0) - return 0; - __osSiGetAccess(); - __osContLastCmd = CONT_CMD_WRITE_MEMPACK; - __osPackRamWriteData(channel, address, buffer); - ret = __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - do { - for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus - __osPfsPifRam.ramarray[i] = 0xFFU; - } - __osPfsPifRam.pifstatus = CONT_CMD_REQUEST_STATUS; - ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(mq, NULL, OS_MESG_BLOCK); - ptr = (u8 *)&__osPfsPifRam; - if (channel != 0) - for (i = 0; i < channel; i++) - ptr++; - - ramreadformat = *(__OSContRamReadFormat *)ptr; - - ret = CHNL_ERR(ramreadformat); - if (ret == 0) { - if (__osContDataCrc(buffer) != ramreadformat.datacrc) { - ret = __osPfsGetStatus(mq, channel); - if (ret != 0) { - __osSiRelAccess(); - return ret; - } - ret = PFS_ERR_CONTRFAIL; - } - } - if (ret != PFS_ERR_CONTRFAIL) - break; - } while ((retry-- >= 0)); - __osSiRelAccess(); - - return ret; -} - -static void __osPackRamWriteData(int channel, u16 address, u8 *buffer) { - u8 *ptr; - __OSContRamReadFormat ramreadformat; - int i; - - ptr = (u8 *)__osPfsPifRam.ramarray; - - for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { // also clear pifstatus - __osPfsPifRam.ramarray[i] = 0; - } - - __osPfsPifRam.pifstatus = CONT_CMD_EXE; - ramreadformat.dummy = CONT_CMD_NOP; - ramreadformat.txsize = CONT_CMD_WRITE_MEMPACK_TX; - ramreadformat.rxsize = CONT_CMD_WRITE_MEMPACK_RX; - ramreadformat.cmd = CONT_CMD_WRITE_MEMPACK; - ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); - ramreadformat.datacrc = CONT_CMD_NOP; - - for (i = 0; i < ARRLEN(ramreadformat.data); i++) { - ramreadformat.data[i] = *buffer++; - } - - if (channel != 0) { - for (i = 0; i < channel; i++) { - *ptr++ = 0; - } - } - - *(__OSContRamReadFormat *)ptr = ramreadformat; - ptr += sizeof(__OSContRamReadFormat); - ptr[0] = CONT_CMD_END; -} diff --git a/lib/src/os/controller.c b/lib/src/os/controller.c deleted file mode 100644 index 8f63ee80..00000000 --- a/lib/src/os/controller.c +++ /dev/null @@ -1,102 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CCC20 */ - -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" -#include "controller.h" -#include "siint.h" - -#define HALF_MIL_CYLCES 500000U -#define ONE_MIL_CYLCES 1000000U -#define HALF_A_SECOND HALF_MIL_CYLCES * osClockRate / ONE_MIL_CYLCES - -u32 __osContinitialized = 0; -ALIGNED16 OSPifRam __osContPifRam; -u8 __osContLastCmd; -u8 __osMaxControllers; -OSTimer __osEepromTimer; -OSMesgQueue __osEepromTimerQ; -OSMesg __osEepromTimerMsg; -s32 D_8012CDD4[2]; //Padding? Maybe osClockRate should be declared here? -ALIGNED16 OSPifRam __osPfsPifRam; -extern OSTime osClockRate; - -s32 osContInit(OSMesgQueue *mq, u8 *bitpattern, OSContStatus *data) { - OSMesg dummy; - u32 ret = 0; - OSTime t; - OSTimer mytimer; - OSMesgQueue timerMesgQueue; - - if (__osContinitialized) { - return ret; - } - __osContinitialized = TRUE; - t = osGetTime(); - if (HALF_A_SECOND > t) { - osCreateMesgQueue(&timerMesgQueue, &dummy, 1); - osSetTimer(&mytimer, HALF_A_SECOND - 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; - __OSContRequesFormat requestformat; - int i; - u8 bits; - bits = 0; - ptr = (u8 *)&__osContPifRam; - for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContRequesFormat), data++) { - requestformat = *(__OSContRequesFormat *)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; - __OSContRequesFormat 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++) { - *(__OSContRequesFormat *)ptr = requestformat; - ptr += sizeof(__OSContRequesFormat); - } - - ptr[0] = CONT_CMD_END; -} diff --git a/lib/src/os/crc.c b/lib/src/os/crc.c deleted file mode 100644 index a3f8e32e..00000000 --- a/lib/src/os/crc.c +++ /dev/null @@ -1,48 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CD770 */ - -#include "types.h" - -u8 __osContAddressCrc(u16 addr) { - u8 temp; - u8 temp2; - int i; - temp = 0; - for (i = 0; i < 16; i++) { - if (temp & 0x10) - temp2 = 21; - else - temp2 = 0; - - temp <<= 1; - temp |= (u8)((addr & 0x400) ? 1 : 0); - addr <<= 1; - temp ^= temp2; - } - - return temp & 0x1f; -} - -u8 __osContDataCrc(u8 *data) { - u8 temp; - u8 temp2; - int i; - int j; - temp = 0; - for (i = 0; i <= 32; i++, data++) { - for (j = 7; j >= 0; j--) { - if (temp & 0x80) - temp2 = 133; - else - temp2 = 0; - temp <<= 1; - if (i == 32) - temp &= -1; - else - temp |= ((*data & (1 << j)) ? 1 : 0); - temp ^= temp2; - } - } - - return temp; -} diff --git a/lib/src/os/createmesgqueue.c b/lib/src/os/createmesgqueue.c new file mode 100644 index 00000000..431d7220 --- /dev/null +++ b/lib/src/os/createmesgqueue.c @@ -0,0 +1,23 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C8820 */ + +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PRinternal/osint.h" + +void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msg, s32 msgCount) { + +#ifdef _DEBUG + if (msgCount <= 0) { + __osError(ERR_OSCREATEMESGQUEUE, 1, msgCount); + return; + } +#endif + + mq->mtqueue = (OSThread*)&__osThreadTail.next; + mq->fullqueue = (OSThread*)&__osThreadTail.next; + mq->validCount = 0; + mq->first = 0; + mq->msgCount = msgCount; + mq->msg = msg; +} diff --git a/lib/src/os/createthread.c b/lib/src/os/createthread.c new file mode 100644 index 00000000..1f7b7d7d --- /dev/null +++ b/lib/src/os/createthread.c @@ -0,0 +1,57 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C8850 */ + +#include "PR/os_internal.h" +#include "PR/R4300.h" +#include "PR/ultraerror.h" +#include "PRinternal/osint.h" + +extern __OSThreadprofile_s thprof[]; + +void osCreateThread(OSThread* t, OSId id, void (*entry)(void*), void* arg, void* sp, OSPri p) { + register u32 saveMask; + OSIntMask mask; + +#ifdef _DEBUG + if ((u32)sp & 0x7) { + __osError(ERR_OSCREATETHREAD_SP, 1, sp); + return; + } + + if ((p < OS_PRIORITY_IDLE) || (p > OS_PRIORITY_MAX)) { + __osError(ERR_OSCREATETHREAD_PRI, 1, p); + return; + } +#endif + + t->id = id; + t->priority = p; + t->next = NULL; + t->queue = NULL; + t->context.pc = (u32)entry; + t->context.a0 = (s64)(s32)arg; // Double cast gets rid of compiler warning + t->context.sp = (s64)(s32)sp - 16; + t->context.ra = (s64)(s32)__osCleanupThread; + mask = OS_IM_ALL; + t->context.sr = (mask & (SR_IMASK | SR_IE)) | SR_EXL; + t->context.rcp = (mask & RCP_IMASK) >> RCP_IMASKSHIFT; + t->context.fpcsr = FPCSR_FS | FPCSR_EV | FPCSR_RM_RN; + t->fp = 0; + t->state = OS_STATE_STOPPED; + t->flags = 0; + +#if BUILD_VERSION >= VERSION_K +#ifndef _FINALROM + if (id < THPROF_IDMAX) { + t->thprof = &thprof[id]; + } else { + t->thprof = &thprof[THPROF_IDMAX - 1]; + } +#endif +#endif + + saveMask = __osDisableInt(); + t->tlnext = __osActiveQueue; + __osActiveQueue = t; + __osRestoreInt(saveMask); +} diff --git a/lib/src/os/osDestroyThread.c b/lib/src/os/destroythread.c similarity index 74% rename from lib/src/os/osDestroyThread.c rename to lib/src/os/destroythread.c index a7b98d01..8808d55b 100644 --- a/lib/src/os/osDestroyThread.c +++ b/lib/src/os/destroythread.c @@ -1,18 +1,17 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D6600 */ -#include "macros.h" -#include "libultra_internal.h" -#include "osint.h" +#include "PR/os_internal.h" +#include "PRinternal/osint.h" -void osDestroyThread(OSThread *t) { +void osDestroyThread(OSThread* t) { register u32 saveMask; - register OSThread *pred; - register OSThread *succ; + register OSThread* pred; + register OSThread* succ; - saveMask = __osDisableInt(); + saveMask = __osDisableInt(); - if (t == NULL) { + if (t == NULL) { t = __osRunningThread; } else if (t->state != OS_STATE_STOPPED) { __osDequeueThread(t->queue, t); @@ -22,13 +21,12 @@ void osDestroyThread(OSThread *t) { __osActiveQueue = __osActiveQueue->tlnext; } else { pred = __osActiveQueue; - succ = pred->tlnext; + succ = pred->tlnext; while (succ != NULL) { if (succ == t) { pred->tlnext = t->tlnext; break; } - pred = succ; succ = pred->tlnext; } diff --git a/lib/src/os/dp.c b/lib/src/os/dp.c deleted file mode 100644 index 803e5f49..00000000 --- a/lib/src/os/dp.c +++ /dev/null @@ -1,13 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D6050 */ - -#include "macros.h" -#include "libultra_internal.h" - -int __osDpDeviceBusy(void) { - register u32 stat; - stat = IO_READ(DPC_STATUS_REG); - if (stat & DPC_STATUS_DMA_BUSY) - return 1; - return 0; -} diff --git a/lib/src/os/exceptasm.h b/lib/src/os/exceptasm.h new file mode 100644 index 00000000..0d7def56 --- /dev/null +++ b/lib/src/os/exceptasm.h @@ -0,0 +1,29 @@ +#ifndef _EXCEPTASM_H +#define _EXCEPTASM_H + +#include "PR/os_version.h" + +#define MESG(type) (type << 3) + +#define MQ_MTQUEUE 0 +#define MQ_FULLQUEUE 4 +#define MQ_VALIDCOUNT 8 +#define MQ_FIRST 12 +#define MQ_MSGCOUNT 16 +#define MQ_MSG 20 + +#define OS_EVENTSTATE_MESSAGE_QUEUE 0 +#define OS_EVENTSTATE_MESSAGE 4 + +/* __osHwInt struct member offsets */ +#define HWINTR_CALLBACK 0x00 +#define HWINTR_SP 0x04 + +/* __osHwInt struct size */ +#if BUILD_VERSION >= VERSION_J +#define HWINTR_SIZE 0x8 +#else +#define HWINTR_SIZE 0x4 +#endif + +#endif diff --git a/lib/src/os/osGetActiveQueue.c b/lib/src/os/getactivequeue.c similarity index 57% rename from lib/src/os/osGetActiveQueue.c rename to lib/src/os/getactivequeue.c index 7dc7f369..a95e4e8b 100644 --- a/lib/src/os/osGetActiveQueue.c +++ b/lib/src/os/getactivequeue.c @@ -1,9 +1,9 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D2470 */ -#include "libultra_internal.h" +#include "PR/os_internal.h" +#include "PRinternal/osint.h" -extern OSThread *__osActiveQueue; -OSThread *__osGetActiveQueue(void) { +OSThread* __osGetActiveQueue(void) { return __osActiveQueue; } diff --git a/lib/src/os/osGetThreadPri.c b/lib/src/os/getthreadpri.c similarity index 56% rename from lib/src/os/osGetThreadPri.c rename to lib/src/os/getthreadpri.c index 8526fa44..329dbf0d 100644 --- a/lib/src/os/osGetThreadPri.c +++ b/lib/src/os/getthreadpri.c @@ -1,11 +1,13 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D2540 */ -#include "libultra_internal.h" +#include "PR/os_internal.h" +#include "PRinternal/osint.h" -extern OSThread *__osRunningThread; -OSPri osGetThreadPri(OSThread *thread) { - if (thread == NULL) +OSPri osGetThreadPri(OSThread* thread) { + if (thread == NULL) { thread = __osRunningThread; + } + return thread->priority; } diff --git a/lib/src/os/osGetTime.c b/lib/src/os/gettime.c similarity index 61% rename from lib/src/os/osGetTime.c rename to lib/src/os/gettime.c index 6c4bfe31..84aff06e 100644 --- a/lib/src/os/osGetTime.c +++ b/lib/src/os/gettime.c @@ -1,16 +1,24 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D21B0 */ -#include "libultra_internal.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PRinternal/osint.h" +#include "PRinternal/viint.h" -extern OSTime __osCurrentTime; -extern u32 __osBaseCounter; - -OSTime osGetTime() { +OSTime osGetTime(void) { u32 tmptime; u32 elapseCount; OSTime currentCount; register u32 saveMask; + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSGETTIME, 0); + return 0; + } +#endif + saveMask = __osDisableInt(); tmptime = osGetCount(); elapseCount = tmptime - __osBaseCounter; diff --git a/lib/src/os/initialize.c b/lib/src/os/initialize.c new file mode 100644 index 00000000..dd0ab03e --- /dev/null +++ b/lib/src/os/initialize.c @@ -0,0 +1,247 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CC5A0 */ + +#include "PR/os_internal.h" +#include "PR/rcp.h" +#include "PR/os_version.h" +#include "PRinternal/piint.h" + +/* + * 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 + +typedef struct { + /* 0x0 */ unsigned int inst1; + /* 0x4 */ unsigned int inst2; + /* 0x8 */ unsigned int inst3; + /* 0xC */ unsigned int inst4; +} __osExceptionVector; +extern __osExceptionVector __osExceptionPreamble[]; + +extern OSPiHandle __Dom1SpeedParam; +extern OSPiHandle __Dom2SpeedParam; + +OSTime osClockRate = OS_CLOCK_RATE; +extern s32 osViClock; +extern s32 __osLeoInterrupt(void); +#include "PR/os_internal_exception.h" +u32 __osShutdown = 0; +u32 __OSGlobalIntMask = OS_IM_ALL; +s32 gLeoFound = FALSE; +#ifdef _FINALROM +u32 __osFinalrom; +#else +u32 __kmc_pt_mode; +#if BUILD_VERSION >= VERSION_K +void* __printfunc = NULL; +#endif +#endif + +#if BUILD_VERSION >= VERSION_K + +#define INITIALIZE_FUNC __osInitialize_common +#define SPEED_PARAM_FUNC __createSpeedParam +#else + +#define INITIALIZE_FUNC osInitialize +#define SPEED_PARAM_FUNC createSpeedParam +#if BUILD_VERSION >= VERSION_J +static void ptstart(void); +static void SPEED_PARAM_FUNC(void); +#endif +extern __osExceptionVector __ptExceptionPreamble[]; + +#endif + +#if BUILD_VERSION >= VERSION_K +void SPEED_PARAM_FUNC(void) { + __Dom1SpeedParam.type = DEVICE_TYPE_INIT; + __Dom1SpeedParam.latency = IO_READ(PI_BSD_DOM1_LAT_REG); + __Dom1SpeedParam.pulse = IO_READ(PI_BSD_DOM1_PWD_REG); + __Dom1SpeedParam.pageSize = IO_READ(PI_BSD_DOM1_PGS_REG); + __Dom1SpeedParam.relDuration = IO_READ(PI_BSD_DOM1_RLS_REG); + + __Dom2SpeedParam.type = DEVICE_TYPE_INIT; + __Dom2SpeedParam.latency = IO_READ(PI_BSD_DOM2_LAT_REG); + __Dom2SpeedParam.pulse = IO_READ(PI_BSD_DOM2_PWD_REG); + __Dom2SpeedParam.pageSize = IO_READ(PI_BSD_DOM2_PGS_REG); + __Dom2SpeedParam.relDuration = IO_READ(PI_BSD_DOM2_RLS_REG); +} +#endif + +void INITIALIZE_FUNC() { + u32 pifdata; +#if BUILD_VERSION < VERSION_K + u32 clock = 0; +#endif + u32 leostatus; + u32 pistatus; + +#ifdef _FINALROM + __osFinalrom = TRUE; +#endif + + __osSetSR(__osGetSR() | SR_CU1); // enable fpu + __osSetFpcCsr(FPCSR_FS | FPCSR_EV | FPCSR_RM_RN); // flush denorm to zero, enable invalid operation +#if BUILD_VERSION >= VERSION_K + __osSetWatchLo(0x4900000); +#endif + + while (__osSiRawReadIo(PIF_RAM_END - 3, &pifdata)) { // last byte of joychannel ram + ; + } + while (__osSiRawWriteIo(PIF_RAM_END - 3, pifdata | 8)) { + ; // todo: magic contant + } + *(__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)); +#if BUILD_VERSION >= VERSION_J + SPEED_PARAM_FUNC(); + osUnmapTLBAll(); + osMapTLBRdb(); +#else + osMapTLBRdb(); + osPiRawReadIo(4, &clock); // Read clock rate from the ROM header + clock &= ~0xf; + if (clock != 0) + { + osClockRate = clock; + } +#endif + osClockRate = osClockRate * 3 / 4; + + if (osResetType == 0) { // cold reset + bzero(osAppNMIBuffer, OS_APP_NMI_BUFSIZE); + } + + pistatus = IO_READ(PI_STATUS_REG); + while (pistatus & PI_STATUS_ERROR) { + pistatus = IO_READ(PI_STATUS_REG); + }; + if (!((leostatus = IO_READ(LEO_STATUS)) & LEO_STATUS_PRESENCE_MASK)) { + gLeoFound = TRUE; + __osSetHWIntrRoutine(1, __osLeoInterrupt); + } else { + gLeoFound = FALSE; + } + +#if BUILD_VERSION >= VERSION_J + // Wait until there are no RCP interrupts + if (__osGetCause() & CAUSE_IP5) { + while (TRUE) { + ; + } + } + + IO_WRITE(AI_CONTROL_REG, AI_CONTROL_DMA_ON); + IO_WRITE(AI_DACRATE_REG, AI_MAX_DAC_RATE - 1); + IO_WRITE(AI_BITRATE_REG, AI_MAX_BIT_RATE - 1); +#endif + +#if BUILD_VERSION < VERSION_K && !defined(_FINALROM) + if (!__kmc_pt_mode) { + int (*fnc)(); +#if BUILD_VERSION < VERSION_J + unsigned int c; + unsigned int c1; +#endif + unsigned int* src; + unsigned int* dst; + unsigned int monadr; + volatile unsigned int* mon; + volatile unsigned int* stat; + + stat = (unsigned*)0xbff08004; + mon = (unsigned*)0xBFF00000; + if (*mon != 0x4B4D4300) { + return; + } + + src = (unsigned*)__ptExceptionPreamble; + dst = (unsigned*)E_VEC; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + src += 2; + dst += 2; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + + osWritebackDCache(E_VEC, 0x24); + osInvalICache(E_VEC, 0x24); + + __kmc_pt_mode = TRUE; + + if ((*stat & 0x10) == 0) { + monadr = *(mon + 1); + if (monadr != 0xBFF00000) { + unsigned int* src; + unsigned int* dst = monadr | 0x20000000; + unsigned int ct = 0x2000 / 4; + + src = 0xBFF00000; + + while (ct != 0) { + *dst++ = *src++; + ct--; + } + } + fnc = monadr + 8; + fnc(0x4B4D4300, 0); + } + } +#endif +} + +#if !defined(_FINALROM) && BUILD_VERSION < VERSION_J +void ptstart(void) { + +} +#elif !defined(_FINALROM) && BUILD_VERSION < VERSION_K +static void ptstart(void) { + +} +#endif + +#if BUILD_VERSION >= VERSION_K +void __osInitialize_autodetect(void) { +#ifndef _FINALROM + if (__checkHardware_msp()) { + __osInitialize_msp(); + } else if (__checkHardware_kmc()) { + __osInitialize_kmc(); + } else if (__checkHardware_isv()) { + __osInitialize_isv(); + } else { + __osInitialize_emu(); + } +#endif +} +#elif BUILD_VERSION == VERSION_J +static void SPEED_PARAM_FUNC(void) { + __Dom1SpeedParam.type = DEVICE_TYPE_INIT; + __Dom1SpeedParam.latency = IO_READ(PI_BSD_DOM1_LAT_REG); + __Dom1SpeedParam.pulse = IO_READ(PI_BSD_DOM1_PWD_REG); + __Dom1SpeedParam.pageSize = IO_READ(PI_BSD_DOM1_PGS_REG); + __Dom1SpeedParam.relDuration = IO_READ(PI_BSD_DOM1_RLS_REG); + + __Dom2SpeedParam.type = DEVICE_TYPE_INIT; + __Dom2SpeedParam.latency = IO_READ(PI_BSD_DOM2_LAT_REG); + __Dom2SpeedParam.pulse = IO_READ(PI_BSD_DOM2_PWD_REG); + __Dom2SpeedParam.pageSize = IO_READ(PI_BSD_DOM2_PGS_REG); + __Dom2SpeedParam.relDuration = IO_READ(PI_BSD_DOM2_RLS_REG); +} +#endif diff --git a/lib/src/os/osJamMesg.c b/lib/src/os/jammesg.c similarity index 62% rename from lib/src/os/osJamMesg.c rename to lib/src/os/jammesg.c index e033215f..d0273a2a 100644 --- a/lib/src/os/osJamMesg.c +++ b/lib/src/os/jammesg.c @@ -1,20 +1,27 @@ - /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D36A0 */ -#include "libultra_internal.h" -#include "osint.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PRinternal/osint.h" -extern OSThread *__osRunningThread; +s32 osJamMesg(OSMesgQueue* mq, OSMesg msg, s32 flag) { + register u32 saveMask; + +#ifdef _DEBUG + if ((flag != OS_MESG_NOBLOCK) && (flag != OS_MESG_BLOCK)) { + __osError(ERR_OSJAMMESG, 1, flag); + return -1; + } +#endif + + saveMask = __osDisableInt(); -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 { + } else { __osRestoreInt(saveMask); return -1; } @@ -23,9 +30,11 @@ s32 osJamMesg(OSMesgQueue *mq, OSMesg msg, s32 flag) { 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/lib/src/os/osAiGetLength.c b/lib/src/os/osAiGetLength.c deleted file mode 100644 index 8f4f4728..00000000 --- a/lib/src/os/osAiGetLength.c +++ /dev/null @@ -1,15 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C8E20 */ - -#include "PR/rcp.h" - -/** - * This function (osAiGetLength) returns the number of bytes remaining in the current DMA buffer. - * Notes: - * For hardware version 1.0, the audio DMA length register is only 15-bit long and thus supports - * a maximum transfer size of 32 Kbytes. In the final release, this register is extended to - * 18 bits to support a transfer of 256 Kbytes. - */ -u32 osAiGetLength(void) { - return IO_READ(AI_LEN_REG); -} diff --git a/lib/src/os/osAiSetFrequency.c b/lib/src/os/osAiSetFrequency.c deleted file mode 100644 index 25188052..00000000 --- a/lib/src/os/osAiSetFrequency.c +++ /dev/null @@ -1,28 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C8600 */ - -#include "libultra_internal.h" - -extern s32 osViClock; -s32 osAiSetFrequency(u32 frequency) { - register u32 dacRate; - register u8 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/lib/src/os/osAiSetNextBuffer.c b/lib/src/os/osAiSetNextBuffer.c deleted file mode 100644 index 458a7a6b..00000000 --- a/lib/src/os/osAiSetNextBuffer.c +++ /dev/null @@ -1,39 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C8D70 */ - -#include "types.h" -#include "libultra_internal.h" -#include "osint.h" - -u8 hdwrBugFlag = 0; - -/** - * It is worth noting that a previous hardware bug has been fixed by a software - * patch in osAiSetNextBuffer. This bug occurred when the address of the end of the - * buffer specified by osAiSetNextBuffer was at a specific value. This value - * occurred when the following was true: - * - * (vaddr + nbytes) & 0x00003FFF == 0x00002000 - * - * (when the buffer ends with address of lower 14 bits 0x2000) In this case, the - * DMA transfer does not complete successfully. This can cause clicks and pops in - * the audio output. This bug no longer requires special handling by the application - * because it is now patched by osAiSetNextBuffer. - */ -s32 osAiSetNextBuffer(void *bufPtr, u32 size) { - char *bptr = bufPtr; - if (hdwrBugFlag != 0) - bptr -= 0x2000; - - if ((((u32)bufPtr + size) & 0x3fff) == 0x2000) - hdwrBugFlag = 1; - else - hdwrBugFlag = 0; - - if (__osAiDeviceBusy()) - return -1; - - IO_WRITE(AI_DRAM_ADDR_REG, osVirtualToPhysical(bptr)); - IO_WRITE(AI_LEN_REG, size); - return 0; -} diff --git a/lib/src/os/osCreateMesgQueue.c b/lib/src/os/osCreateMesgQueue.c deleted file mode 100644 index 066c3569..00000000 --- a/lib/src/os/osCreateMesgQueue.c +++ /dev/null @@ -1,15 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C8820 */ - -#include "libultra_internal.h" -#include "types.h" - -extern OSThread __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/lib/src/os/osCreateThread.c b/lib/src/os/osCreateThread.c deleted file mode 100644 index c4597315..00000000 --- a/lib/src/os/osCreateThread.c +++ /dev/null @@ -1,32 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C8850 */ - -#include "libultra_internal.h" -#include "PR/R4300.h" - -extern OSThread *__osActiveQueue; -void __osCleanupThread(void); - -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/lib/src/os/osDpSetNextBuffer.c b/lib/src/os/osDpSetNextBuffer.c deleted file mode 100644 index 1861bb8b..00000000 --- a/lib/src/os/osDpSetNextBuffer.c +++ /dev/null @@ -1,19 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D18E0 */ - -#include "libultra_internal.h" - -s32 __osDpDeviceBusy(void); -s32 osDpSetNextBuffer(void *bufPtr, u64 size) { - register u32 stat; - - if (__osDpDeviceBusy()) - return -1; - IO_WRITE(DPC_STATUS_REG, DPC_CLR_XBUS_DMEM_DMA); - do { - stat = IO_READ(DPC_STATUS_REG); - } while (stat & DPC_STATUS_XBUS_DMEM_DMA); - IO_WRITE(DPC_START_REG, osVirtualToPhysical(bufPtr)); - IO_WRITE(DPC_END_REG, osVirtualToPhysical(bufPtr) + size); - return 0; -} diff --git a/lib/src/os/osEPiRawWriteIo.c b/lib/src/os/osEPiRawWriteIo.c deleted file mode 100644 index cf7311a3..00000000 --- a/lib/src/os/osEPiRawWriteIo.c +++ /dev/null @@ -1,15 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D6560 */ - -#include "libultra_internal.h" -#include "piint.h" - -s32 osEPiRawWriteIo(OSPiHandle *pihandle, u32 devAddr, u32 data) { - register u32 stat = IO_READ(PI_STATUS_REG); - - while (stat & PI_STATUS_ERROR) - stat = IO_READ(PI_STATUS_REG); - - IO_WRITE(pihandle->baseAddress | devAddr, data); - return 0; -} diff --git a/lib/src/os/osEpiRawStartDma.c b/lib/src/os/osEpiRawStartDma.c deleted file mode 100644 index 067f0170..00000000 --- a/lib/src/os/osEpiRawStartDma.c +++ /dev/null @@ -1,31 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D2680 */ - -#include "libultra_internal.h" -#include "PR/rcp.h" - -s32 __osEPiRawStartDma(OSPiHandle *pihandle, s32 dir, u32 cart_addr, void *dram_addr, u32 size) { - register int status; - - status = IO_READ(PI_STATUS_REG); - - while (status & PI_STATUS_ERROR) { - status = IO_READ(PI_STATUS_REG); - } - - IO_WRITE(PI_DRAM_ADDR_REG, osVirtualToPhysical(dram_addr)); - IO_WRITE(PI_CART_ADDR_REG, K1_TO_PHYS(pihandle->baseAddress | cart_addr)); - - switch (dir) { - 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/lib/src/os/osInitialize.c b/lib/src/os/osInitialize.c deleted file mode 100644 index 4270e715..00000000 --- a/lib/src/os/osInitialize.c +++ /dev/null @@ -1,65 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CC5A0 */ - -#include "libultra_internal.h" -#include "viint.h" -#include "piint.h" - -typedef struct -{ - /* 0x0 */ unsigned int inst1; - /* 0x4 */ unsigned int inst2; - /* 0x8 */ unsigned int inst3; - /* 0xC */ unsigned int inst4; -} __osExceptionVector; -extern __osExceptionVector __osExceptionPreamble; - -OSTime osClockRate = OS_CLOCK_RATE; -u32 __osShutdown = 0; -u32 __OSGlobalIntMask = OS_IM_ALL; -s32 gLeoFound = FALSE; -u32 __osFinalrom; -s32 __osLeoInterrupt(void); - -extern s32 osViClock; //This is defined in another file somehow -extern u32 __osFinalrom; //This is defined in another file somehow -void osInitialize() { - u32 pifdata; - u32 clock = 0; - u32 leostatus; - u32 pistatus; - __osFinalrom = TRUE; - __osSetSR(__osGetSR() | SR_CU1); //enable fpu - __osSetFpcCsr(FPCSR_FS | FPCSR_EV); //flush denorm to zero, enable invalid operation - - while (__osSiRawReadIo(PIF_RAM_END - 3, &pifdata)) //last byte of joychannel ram - {;} - while (__osSiRawWriteIo(PIF_RAM_END - 3, pifdata | 8)) - {;} //todo: magic contant - *(__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)); - osMapTLBRdb(); - osPiRawReadIo(4, &clock); //TODO: remove magic constant; - clock &= ~0xf; //clear lower 4 bits - if (clock) { - osClockRate = clock; - } - osClockRate = osClockRate * 3 / 4; - if (osResetType == 0 /*cold reset */) { - bzero(osAppNmiBuffer, sizeof(osAppNmiBuffer)); - } - pistatus = IO_READ(PI_STATUS_REG); - while (pistatus & PI_STATUS_ERROR) { - pistatus = IO_READ(PI_STATUS_REG); - }; - if (!((leostatus = IO_READ(LEO_STATUS)) & LEO_STATUS_PRESENCE_MASK)) { - gLeoFound = TRUE; - __osSetHWIntrRoutine(1, __osLeoInterrupt); - } else { - gLeoFound = FALSE; - } -} diff --git a/lib/src/os/osMotor.c b/lib/src/os/osMotor.c deleted file mode 100644 index b21e8c59..00000000 --- a/lib/src/os/osMotor.c +++ /dev/null @@ -1,140 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x80071D30 */ - -#include "libultra_internal.h" -#include "controller.h" -#include "siint.h" - -#define MOTOR_RAM_ADDRESS 0x400 -#define MOTOR_DATA_ADDRESS 0x600 -#define MOTOR_DEFAULT_BANK 128 - -static void _MakeMotorData(int channel, u16 address, u8 *buffer, OSPifRam *mdata); -OSPifRam _MotorStopData[MAXCONTROLLERS]; -OSPifRam _MotorStartData[MAXCONTROLLERS]; -u8 _motorstopbuf[BLOCKSIZE]; -u8 _motorstartbuf[BLOCKSIZE]; -/* Official name: nosMotorStop */ -s32 osMotorStop(OSPfs *pfs) { - int i; - s32 ret; - u8 *ptr; - __OSContRamReadFormat ramreadformat; - - __osSiGetAccess(); - - __osContLastCmd = CONT_CMD_WRITE_MEMPACK; - __osSiRawStartDma(OS_WRITE, &_MotorStopData[pfs->channel]); - osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); - __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); - ptr = (u8 *)&__osPfsPifRam; - - if (pfs->channel != 0) - for (i = 0; i < pfs->channel; i++) - ptr++; - - ramreadformat = *(__OSContRamReadFormat *)ptr; - ret = CHNL_ERR(ramreadformat); - if (ret == 0 && ramreadformat.datacrc != 0) - ret = PFS_ERR_CONTRFAIL; - __osSiRelAccess(); - return ret; -} - -s32 osMotorStart(OSPfs *pfs) { - int i; - s32 ret; - u8 *ptr; - __OSContRamReadFormat ramreadformat; - - __osSiGetAccess(); - - __osContLastCmd = CONT_CMD_WRITE_MEMPACK; - __osSiRawStartDma(OS_WRITE, &_MotorStartData[pfs->channel]); - osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); - __osSiRawStartDma(OS_READ, &__osPfsPifRam); - osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); - ptr = (u8 *)&__osPfsPifRam; - - if (pfs->channel != 0) - for (i = 0; i < pfs->channel; i++) - ptr++; - - ramreadformat = *(__OSContRamReadFormat *)ptr; - ret = CHNL_ERR(ramreadformat); - if (ret == 0 && ramreadformat.datacrc != 0xEB) - ret = PFS_ERR_CONTRFAIL; - __osSiRelAccess(); - return ret; -} - -static void _MakeMotorData(int channel, u16 address, u8 *buffer, OSPifRam *mdata) { - u8 *ptr; - __OSContRamReadFormat ramreadformat; - int i; - - ptr = (u8 *)mdata->ramarray; - for (i = 0; i < ARRLEN(mdata->ramarray); i++) - mdata->ramarray[i] = 0; - mdata->pifstatus = CONT_CMD_EXE; - ramreadformat.dummy = CONT_CMD_NOP; - ramreadformat.txsize = CONT_CMD_WRITE_MEMPACK_TX; - ramreadformat.rxsize = CONT_CMD_WRITE_MEMPACK_RX; - ramreadformat.cmd = CONT_CMD_WRITE_MEMPACK; - - ramreadformat.address = (address << 0x5) | __osContAddressCrc(address); - ramreadformat.datacrc = CONT_CMD_NOP; - for (i = 0; i < ARRLEN(ramreadformat.data); i++) - ramreadformat.data[i] = *buffer++; - - if (channel != 0) { - for (i = 0; i < channel; i++) { - *ptr++ = 0; - } - } - *(__OSContRamReadFormat *)ptr = ramreadformat; - ptr += sizeof(__OSContRamReadFormat); - ptr[0] = CONT_CMD_END; -} - -/* Official name: nosMotorInit */ -s32 osMotorInit(OSMesgQueue *mq, OSPfs *pfs, int channel) { - int i; - s32 ret; - u8 temp[BLOCKSIZE]; - pfs->queue = mq; - pfs->channel = channel; - pfs->status = 0; - pfs->activebank = MOTOR_DEFAULT_BANK; - - for (i = 0; i < ARRLEN(temp); i++) - temp[i] = MOTOR_DEFAULT_BANK; - - ret = __osContRamWrite(mq, channel, MOTOR_RAM_ADDRESS, temp, FALSE); - - if (ret == PFS_ERR_NEW_PACK) - ret = __osContRamWrite(mq, channel, MOTOR_RAM_ADDRESS, temp, FALSE); - - if (ret != 0) - return ret; - - ret = __osContRamRead(mq, channel, MOTOR_RAM_ADDRESS, temp); - - if (ret != 0) - return ret; - - if (temp[ARRLEN(temp) - 1] != MOTOR_DEFAULT_BANK) { - return PFS_ERR_DEVICE; - } - - for (i = 0; i < ARRLEN(_motorstartbuf); i++) { - _motorstartbuf[i] = 1; - _motorstopbuf[i] = 0; - } - - _MakeMotorData(channel, MOTOR_DATA_ADDRESS, _motorstartbuf, &_MotorStartData[channel]); - _MakeMotorData(channel, MOTOR_DATA_ADDRESS, _motorstopbuf, &_MotorStopData[channel]); - - return 0; -} diff --git a/lib/src/os/osPfsChecker.c b/lib/src/os/osPfsChecker.c deleted file mode 100644 index bd57a283..00000000 --- a/lib/src/os/osPfsChecker.c +++ /dev/null @@ -1,191 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CF530 */ - -#include "libultra_internal.h" -#include "controller.h" - -s32 corrupted_init(OSPfs *pfs, __OSInodeCache *cache); -s32 corrupted(OSPfs *pfs, __OSInodeUnit fpage, __OSInodeCache *cache); - -s32 osPfsChecker(OSPfs *pfs) { - int j; //1156 - s32 ret; //1152 - __OSInodeUnit next_page; - __OSInode checked_inode; - __OSInode tmp_inode; //636 - __OSDir tmp_dir; - __OSInodeUnit file_next_node[16]; - __OSInodeCache cache; //56 - int fixed; //52 - u8 bank; //51 - s32 cc; //44 - s32 cl; //40 - int offset; //36 - - fixed = 0; - ret = __osCheckId(pfs); - if (ret == PFS_ERR_NEW_PACK) - ret = __osGetId(pfs); - if (ret != 0) - return ret; - ERRCK(corrupted_init(pfs, &cache)); - for (j = 0; j < pfs->dir_size; j++) { - ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir)); - if (tmp_dir.company_code != 0 && tmp_dir.game_code != 0) { - next_page = tmp_dir.start_page; - cc = 0; - cl = 0; - bank = 255; - while (next_page.ipage >= pfs->inode_start_page && - next_page.inode_t.bank < pfs->banks && - next_page.inode_t.page > 0 && - next_page.inode_t.page < 128) { - if (bank != next_page.inode_t.bank) { - bank = next_page.inode_t.bank; - ret = __osPfsRWInode(pfs, &tmp_inode, OS_READ, bank); - if (ret != 0 && ret != PFS_ERR_INCONSISTENT) - return ret; - } - cc = corrupted(pfs, next_page, &cache) - cl; - if (cc != 0) - break; - cl = 1; - next_page = tmp_inode.inode_page[next_page.inode_t.page]; - } - if (cc == 0 && next_page.ipage == 1) - continue; - - tmp_dir.company_code = 0; - tmp_dir.game_code = 0; - tmp_dir.start_page.ipage = 0; - tmp_dir.status = DIR_STATUS_EMPTY; - tmp_dir.data_sum = 0; - SET_ACTIVEBANK_TO_ZERO; - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE)); - fixed++; - } else { - if (tmp_dir.company_code == 0 && tmp_dir.game_code == 0) - continue; - tmp_dir.company_code = 0; - tmp_dir.game_code = 0; - tmp_dir.start_page.ipage = 0; - tmp_dir.status = DIR_STATUS_EMPTY; - tmp_dir.data_sum = 0; - - SET_ACTIVEBANK_TO_ZERO; - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir, FALSE)); - fixed++; - } - } - - for (j = 0; j < pfs->dir_size; j++) { - ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&tmp_dir)); - - if (tmp_dir.company_code != 0 && tmp_dir.game_code != 0 && - tmp_dir.start_page.ipage >= (u16)pfs->inode_start_page) { - file_next_node[j].ipage = tmp_dir.start_page.ipage; - } else { - file_next_node[j].ipage = 0; - } - } - - for (bank = 0; bank < pfs->banks; bank++) { - ret = __osPfsRWInode(pfs, &tmp_inode, 0, bank); - if (ret != 0 && ret != PFS_ERR_INCONSISTENT) - return ret; - if (bank > 0) { - offset = 1; - } else { - offset = pfs->inode_start_page; - } - for (j = 0; j < offset; j++) { - checked_inode.inode_page[j].ipage = tmp_inode.inode_page[j].ipage; - } - for (; j < 128; j++) { - checked_inode.inode_page[j].ipage = 3; - } - for (j = 0; j < pfs->dir_size; j++) { - while (file_next_node[j].inode_t.bank == bank && - file_next_node[j].ipage >= (u16)pfs->inode_start_page) { - u8 pp = file_next_node[j].inode_t.page; - file_next_node[j] = checked_inode.inode_page[pp] = tmp_inode.inode_page[pp]; - } - } - ERRCK(__osPfsRWInode(pfs, &checked_inode, OS_WRITE, bank)); - } - if (fixed) - pfs->status |= PFS_CORRUPTED; - else - pfs->status &= ~PFS_CORRUPTED; - - return 0; -} - -s32 corrupted_init(OSPfs *pfs, __OSInodeCache *cache) { - int i; - int n; - int offset; - u8 bank; - __OSInodeUnit tpage; - __OSInode tmp_inode; - s32 ret; - - for (i = 0; i < ARRLEN(cache->map); i++) - cache->map[i] = 0; - cache->bank = -1; - for (bank = 0; bank < pfs->banks; bank++) { - if (bank > 0) - offset = 1; - else - offset = pfs->inode_start_page; - - ret = __osPfsRWInode(pfs, &tmp_inode, OS_READ, bank); - if (ret != 0 && ret != PFS_ERR_INCONSISTENT) - return ret; - for (i = offset; i < ARRLEN(tmp_inode.inode_page); i++) { - tpage = tmp_inode.inode_page[i]; - if (tpage.ipage >= pfs->inode_start_page && tpage.inode_t.bank != bank) { - n = (tpage.inode_t.page / 4) + ((tpage.inode_t.bank % PFS_ONE_PAGE) * BLOCKSIZE); - cache->map[n] |= 1 << (bank % PFS_ONE_PAGE); - } - } - } - - return 0; -} - -s32 corrupted(OSPfs *pfs, __OSInodeUnit fpage, __OSInodeCache *cache) { - int j; - int n; - int hit; - u8 bank; - int offset; - s32 ret; - - hit = 0; - ret = 0; - n = (fpage.inode_t.page / 4) + (fpage.inode_t.bank % 8) * BLOCKSIZE; - for (bank = 0; bank < pfs->banks; bank++) { - if (bank > 0) - offset = 1; - else - offset = pfs->inode_start_page; - if (bank == fpage.inode_t.bank || cache->map[n] & (1 << (bank % 8))) { - if (bank != cache->bank) { - ret = __osPfsRWInode(pfs, &cache->inode, 0, bank); - if (ret != 0 && ret != PFS_ERR_INCONSISTENT) - return ret; - cache->bank = bank; - } - - for (j = offset; hit < 2 && (j < ARRLEN(cache->inode.inode_page)); j++) { - if (cache->inode.inode_page[j].ipage == fpage.ipage) - hit++; - } - if (1 < hit) - return PFS_ERR_NEW_PACK; - } - } - - return hit; -} diff --git a/lib/src/os/osPfsFileState.c b/lib/src/os/osPfsFileState.c deleted file mode 100644 index 960eae70..00000000 --- a/lib/src/os/osPfsFileState.c +++ /dev/null @@ -1,63 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D0580 */ - -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" -#include "controller.h" - -s32 osPfsFileState(OSPfs *pfs, s32 file_no, OSPfsState *state) -{ - s32 ret; - int pages; - __OSInode inode; - __OSDir dir; - __OSInodeUnit next_page; - int j; - u8 bank; - u8 start_page; - if (file_no >= pfs->dir_size || file_no < 0) - return PFS_ERR_INVALID; - PFS_CHECK_STATUS; - PFS_CHECK_ID; - SET_ACTIVEBANK_TO_ZERO; - - ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + file_no, (u8*)&dir)); - if (dir.company_code == 0 || dir.game_code == 0) - return PFS_ERR_INVALID; - if (dir.start_page.ipage < pfs->inode_start_page) - return PFS_ERR_INCONSISTENT; - pages = 0; - start_page = dir.start_page.inode_t.page; - bank = dir.start_page.inode_t.bank; - while (bank < pfs->banks) - { - ERRCK(__osPfsRWInode(pfs, &inode, OS_READ, bank)); - next_page = inode.inode_page[start_page]; - pages++; - while (next_page.ipage >= pfs->inode_start_page) - { - pages++; - next_page = inode.inode_page[next_page.inode_t.page]; - if (next_page.inode_t.bank != bank) - { - bank = next_page.inode_t.bank; - start_page = next_page.inode_t.page; - break; - } - } - if (next_page.ipage == PFS_EOF) - break; - } - if (next_page.ipage != PFS_EOF) - return PFS_ERR_INCONSISTENT; - - state->file_size = pages << PFS_ONE_PAGE; - state->company_code = dir.company_code; - state->game_code = dir.game_code; - for (j = 0; j < ARRLEN(state->game_name); j++) - state->game_name[j] = dir.game_name[j]; - for (j = 0; j < ARRLEN(state->ext_name); j++) - state->ext_name[j] = dir.ext_name[j]; - return 0; -} diff --git a/lib/src/os/osPfsFreeBlocks.c b/lib/src/os/osPfsFreeBlocks.c deleted file mode 100644 index fb1a77e7..00000000 --- a/lib/src/os/osPfsFreeBlocks.c +++ /dev/null @@ -1,31 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CF3E0 */ - -#include "libultra_internal.h" -#include "controller.h" - -s32 osPfsFreeBlocks(OSPfs *pfs, s32 *bytes_not_used) { - int j; - int pages; - __OSInode inode; - s32 ret; - u8 bank; - int offset; - pages = 0; - ret = 0; - PFS_CHECK_STATUS; - PFS_CHECK_ID; - for (bank = 0; bank < pfs->banks; bank++) { - ERRCK(__osPfsRWInode(pfs, &inode, OS_READ, bank)); - if (bank > 0) - offset = 1; - else - offset = pfs->inode_start_page; - for (j = offset; j < ARRLEN(inode.inode_page); j++) { - if (inode.inode_page[j].ipage == 3) - pages++; - } - } - *bytes_not_used = pages * PFS_ONE_PAGE * BLOCKSIZE; - return 0; -} diff --git a/lib/src/os/osPfsIsPlug.c b/lib/src/os/osPfsIsPlug.c deleted file mode 100644 index c90615f8..00000000 --- a/lib/src/os/osPfsIsPlug.c +++ /dev/null @@ -1,108 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CD290 */ - -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" -#include "controller.h" -#include "siint.h" - -void __osPfsGetInitData(u8 *pattern, OSContStatus *data); -void __osPfsRequestData(u8 cmd); - -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; - __OSContRequesFormat requestformat; - int i; - - __osContLastCmd = cmd; - //Also clear pifstatus - for (i = 0; i < ARRLEN(__osPfsPifRam.ramarray) + 1; i++) { - __osPfsPifRam.ramarray[i] = 0; - } - - __osPfsPifRam.pifstatus = CONT_CMD_EXE; - ptr = (u8 *)&__osPfsPifRam; - 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++) { - *(__OSContRequesFormat *)ptr = requestformat; - ptr += sizeof(__OSContRequesFormat); - } - - *ptr = CONT_CMD_END; -} - -void __osPfsGetInitData(u8 *pattern, OSContStatus *data) { - u8 *ptr; - __OSContRequesFormat requestformat; - int i; - u8 bits; - - bits = 0; - ptr = (u8 *)&__osPfsPifRam; - - for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(__OSContRequesFormat)) { - requestformat = *(__OSContRequesFormat *)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/lib/src/os/osPfsNumFiles.c b/lib/src/os/osPfsNumFiles.c deleted file mode 100644 index 9877c381..00000000 --- a/lib/src/os/osPfsNumFiles.c +++ /dev/null @@ -1,24 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D0390 */ - -#include "libultra_internal.h" -#include "controller.h" - -s32 osPfsNumFiles(OSPfs *pfs, s32 *max_files, s32 *files_used) { - int j; - s32 ret; - __OSDir dir; - int files; - files = 0; - PFS_CHECK_STATUS; - PFS_CHECK_ID; - SET_ACTIVEBANK_TO_ZERO; - for (j = 0; j < pfs->dir_size; j++) { - ERRCK(__osContRamRead(pfs->queue, pfs->channel, pfs->dir_table + j, (u8*)&dir)); - if (dir.company_code != 0 && dir.game_code != 0) - files++; - } - *files_used = files; - *max_files = pfs->dir_size; - return 0; -} diff --git a/lib/src/os/osPfsReFormat.c b/lib/src/os/osPfsReFormat.c deleted file mode 100644 index eb6a2702..00000000 --- a/lib/src/os/osPfsReFormat.c +++ /dev/null @@ -1,66 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CFF90 */ - -#include "libultra_internal.h" -#include "controller.h" -#include "siint.h" - -s32 osPfsReFormat(OSPfs *pfs, OSMesgQueue *queue, int channel) { - int j; - int i; - __OSInode inode; - u8 tmp_data[32]; - u8 *ptr; - s32 ret; - - __osSiGetAccess(); - ret = __osPfsGetStatus(queue, channel); - - if (ret != 0) { - //Single difference between this and libreultra - //__osSiRelAccess(); - return ret; - } - - pfs->status ^= PFS_INITIALIZED; - pfs->queue = queue; - pfs->channel = channel; - __osSiRelAccess(); - ERRCK(__osGetId(pfs)); - - SET_ACTIVEBANK_TO_ZERO; - for (j = 0; j < ARRLEN(tmp_data); j++) - tmp_data[j] = 0; - - for (j = 0; j < pfs->dir_size; j++) { - ERRCK(__osContRamWrite(queue, channel, pfs->dir_table + j, tmp_data, FALSE)); - } - - for (j = 0; j < pfs->inode_start_page; j++) - inode.inode_page[j].ipage = 0; - - for (j = pfs->inode_start_page; j < ARRLEN(inode.inode_page); j++) - inode.inode_page[j].ipage = 3; - - inode.inode_page[0].ipage = __osSumcalc((u8*)&inode.inode_page[pfs->inode_start_page], - sizeof(__OSInodeUnit) * -pfs->inode_start_page + sizeof(inode.inode_page)); - ptr = (u8 *)&inode; - - for (j = 0; j < PFS_ONE_PAGE; j++){ - ERRCK(__osContRamWrite(queue, channel, pfs->inode_table + j, ptr + j * BLOCKSIZE, FALSE)); - ERRCK(__osContRamWrite(queue, channel, pfs->minode_table + j, ptr + j * BLOCKSIZE, FALSE)); - } - - for (i = 1; i < pfs->banks; i++) { - for (j = 1; j < ARRLEN(inode.inode_page); j++) - inode.inode_page[j].ipage = 3; - inode.inode_page[0].ipage = __osSumcalc((u8*)&inode.inode_page[1], -sizeof(__OSInodeUnit) + sizeof(inode.inode_page)); - ptr = (u8 *)&inode; - for (j = 0; j < PFS_ONE_PAGE; j++) { - ERRCK(__osContRamWrite(queue, channel, pfs->inode_table + i * PFS_ONE_PAGE + j, ptr + j * BLOCKSIZE, FALSE)); - ERRCK(__osContRamWrite(queue, channel, pfs->minode_table + i * PFS_ONE_PAGE + j, ptr + j * BLOCKSIZE, FALSE)); - } - } - - return 0; -} diff --git a/lib/src/os/osPiGetCmdQueue.c b/lib/src/os/osPiGetCmdQueue.c deleted file mode 100644 index f7f3b705..00000000 --- a/lib/src/os/osPiGetCmdQueue.c +++ /dev/null @@ -1,12 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D37F0 */ - -#include "libultra_internal.h" - -extern OSDevMgr __osPiDevMgr; - -OSMesgQueue *osPiGetCmdQueue(void) { - if (!__osPiDevMgr.active) - return NULL; - return __osPiDevMgr.cmdQueue; -} diff --git a/lib/src/os/osPiRawReadIo.c b/lib/src/os/osPiRawReadIo.c deleted file mode 100644 index c49e8ef9..00000000 --- a/lib/src/os/osPiRawReadIo.c +++ /dev/null @@ -1,13 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D4790 */ - -#include "macros.h" -#include "libultra_internal.h" -#include "piint.h" - -s32 osPiRawReadIo(u32 devAddr, u32 *data) { - register u32 stat; - WAIT_ON_IOBUSY(stat); - *data = IO_READ((u32)osRomBase | devAddr); - return 0; -} diff --git a/lib/src/os/osPiRawStartDma.c b/lib/src/os/osPiRawStartDma.c deleted file mode 100644 index 042c2823..00000000 --- a/lib/src/os/osPiRawStartDma.c +++ /dev/null @@ -1,31 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D25a0 */ - -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" -#include "PR/rcp.h" - -s32 __osPiRawStartDma(s32 direction, u32 devAddr, void *dramAddr, u32 size) { - register int status; - status = IO_READ(PI_STATUS_REG); - while (status & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY | PI_STATUS_ERROR)) { - status = IO_READ(PI_STATUS_REG); - } - - IO_WRITE(PI_DRAM_ADDR_REG, osVirtualToPhysical(dramAddr)); - IO_WRITE(PI_CART_ADDR_REG, K1_TO_PHYS(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; - break; - } - return 0; -} diff --git a/lib/src/os/osPiStartDma.c b/lib/src/os/osPiStartDma.c deleted file mode 100644 index 7d13adcb..00000000 --- a/lib/src/os/osPiStartDma.c +++ /dev/null @@ -1,28 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C8F80 */ - -#include "libultra_internal.h" - -extern OSDevMgr __osPiDevMgr; - -s32 osPiStartDma(OSIoMesg *mb, s32 priority, s32 direction, u32 devAddr, void *dramAddr, u32 size, OSMesgQueue *mq) { - register s32 ret; - if (!__osPiDevMgr.active) - return -1; - if (direction == OS_READ) - mb->hdr.type = OS_MESG_TYPE_DMAREAD; - else - mb->hdr.type = OS_MESG_TYPE_DMAWRITE; - mb->hdr.pri = priority; - mb->hdr.retQueue = mq; - mb->dramAddr = dramAddr; - mb->devAddr = devAddr; - mb->size = size; - mb->piHandle = NULL; - if (priority == OS_MESG_PRI_HIGH) { - ret = osJamMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); - } else { - ret = osSendMesg(osPiGetCmdQueue(), (OSMesg)mb, OS_MESG_NOBLOCK); - } - return ret; -} diff --git a/lib/src/os/osSetEventMesg.c b/lib/src/os/osSetEventMesg.c deleted file mode 100644 index f5fdea3d..00000000 --- a/lib/src/os/osSetEventMesg.c +++ /dev/null @@ -1,20 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CCBB0 */ - -#include "libultra_internal.h" - -typedef struct __OSEventState { - OSMesgQueue *messageQueue; - OSMesg message; -} __OSEventState; - -__OSEventState __osEventStateTab[15]; //OS_NUM_EVENTS = 15 -void osSetEventMesg(OSEvent event, OSMesgQueue *mq, OSMesg msg) { - register u32 saveMask = __osDisableInt(); - __OSEventState *es; - - es = &__osEventStateTab[event]; - es->messageQueue = mq; - es->message = msg; - __osRestoreInt(saveMask); -} diff --git a/lib/src/os/osSetTime.c b/lib/src/os/osSetTime.c deleted file mode 100644 index c794f4ec..00000000 --- a/lib/src/os/osSetTime.c +++ /dev/null @@ -1,10 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CD260 */ - -#include "libultra_internal.h" - -extern OSTime __osCurrentTime; - -void osSetTime(OSTime time) { - __osCurrentTime = time; -} diff --git a/lib/src/os/osSetTimer.c b/lib/src/os/osSetTimer.c deleted file mode 100644 index ff3db096..00000000 --- a/lib/src/os/osSetTimer.c +++ /dev/null @@ -1,28 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D4DE0 */ - -#include "libultra_internal.h" - -extern OSTimer *__osTimerList; -OSTime __osInsertTimer(OSTimer *t); -void __osSetTimerIntr(OSTime tim); - -s32 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->remaining = value; - else - t->remaining = interval; - t->mq = mq; - t->msg = msg; - time = __osInsertTimer(t); - - if(__osTimerList->next == t) - __osSetTimerIntr(time); - - return 0; -} diff --git a/lib/src/os/osSpTaskYielded.c b/lib/src/os/osSpTaskYielded.c deleted file mode 100644 index d8f3105a..00000000 --- a/lib/src/os/osSpTaskYielded.c +++ /dev/null @@ -1,28 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D1DF0 */ - -#include "libultra_internal.h" -#include "viint.h" -#include "PR/sptask.h" - -__OSViContext vi[2] = {0}; -__OSViContext *__osViCurr = &vi[0]; -__OSViContext *__osViNext = &vi[1]; - -//TODO: This should be defined above osInitialize -s32 osViClock = VI_NTSC_CLOCK; - -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/lib/src/os/osTimer.c b/lib/src/os/osTimer.c deleted file mode 100644 index 62238420..00000000 --- a/lib/src/os/osTimer.c +++ /dev/null @@ -1,105 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D4EC0 */ - -#include "macros.h" -#include "libultra_internal.h" - -extern OSTimer __osBaseTimer; -OSTimer *__osTimerList = &__osBaseTimer; - -extern OSTime __osCurrentTime; -extern u32 __osBaseCounter; -extern u32 __osViIntrCount; -extern u32 __osTimerCounter; - - -OSTime __osInsertTimer(OSTimer *t); - -#ifdef NON_EQUIVALENT -//Seems to be a mismatch based on where __osCurrentTime is defined. -//Scratch proving that: https://decomp.me/scratch/OB3iP -void __osTimerServicesInit(void) { - __osCurrentTime = 0; - __osBaseCounter = 0; - __osViIntrCount = 0; - __osTimerList->prev = __osTimerList; - __osTimerList->next = __osTimerList->prev; - __osTimerList->remaining = 0; - __osTimerList->interval = __osTimerList->remaining; - __osTimerList->mq = NULL; - __osTimerList->msg = 0; -} -#else -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s") -#endif - -void __osSetTimerIntr(OSTime tim); -void __osSetCompare(u32); - -void __osTimerInterrupt(void) { - OSTimer *t; - u32 count; - u32 elapsed_cycles; - - if (__osTimerList->next == __osTimerList) - return; - while (1) { - t = __osTimerList->next; - if (t == __osTimerList){ - __osSetCompare(0); - __osTimerCounter = 0; - break; - } - count = osGetCount(); - elapsed_cycles = count - __osTimerCounter; - __osTimerCounter = count; - if (elapsed_cycles < t->remaining){ - t->remaining -= elapsed_cycles; - __osSetTimerIntr(t->remaining); - return; - } 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->remaining = t->interval; - __osInsertTimer(t); - } - } - } -} - -void __osSetTimerIntr(OSTime tim) { - OSTime NewTime; - u32 savedMask; - savedMask = __osDisableInt(); - __osTimerCounter = osGetCount(); - NewTime = tim + __osTimerCounter; - __osSetCompare(NewTime); - __osRestoreInt(savedMask); -} - -OSTime __osInsertTimer(OSTimer *t) { - OSTimer *timep; - OSTime tim; - u32 savedMask; - savedMask = __osDisableInt(); - for (timep = __osTimerList->next, tim = t->remaining; - timep != __osTimerList && tim > timep->remaining; - tim -= timep->remaining, timep = timep->next) { - ; - } - t->remaining = tim; - if (timep != __osTimerList) - timep->remaining -= tim; - t->next = timep; - t->prev = timep->prev; - timep->prev->next = t; - timep->prev = t; - __osRestoreInt(savedMask); - return tim; -} diff --git a/lib/src/os/osViGetCurrentFramebuffer.c b/lib/src/os/osViGetCurrentFramebuffer.c deleted file mode 100644 index 001a05a9..00000000 --- a/lib/src/os/osViGetCurrentFramebuffer.c +++ /dev/null @@ -1,15 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D1E70 */ - -#include "libultra_internal.h" -#include "viint.h" - -void *osViGetCurrentFramebuffer(void) { - register u32 saveMask; - void *framep; - - saveMask = __osDisableInt(); - framep = __osViCurr->framep; - __osRestoreInt(saveMask); - return framep; -} diff --git a/lib/src/os/osViGetNextFramebuffer.c b/lib/src/os/osViGetNextFramebuffer.c deleted file mode 100644 index da39319f..00000000 --- a/lib/src/os/osViGetNextFramebuffer.c +++ /dev/null @@ -1,15 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D1EB0 */ - -#include "libultra_internal.h" -#include "viint.h" - -void *osViGetNextFramebuffer(void) { - register u32 saveMask; - void *framep; - - saveMask = __osDisableInt(); - framep = __osViNext->framep; - __osRestoreInt(saveMask); - return framep; -} diff --git a/lib/src/os/osViMgr.c b/lib/src/os/osViMgr.c deleted file mode 100644 index 6b5e7c12..00000000 --- a/lib/src/os/osViMgr.c +++ /dev/null @@ -1,118 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D1990 */ - -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" -#include "viint.h" -#include "osint.h" - -extern OSTime __osCurrentTime; -extern u32 __osBaseCounter; -extern u32 __osViIntrCount; - -OSDevMgr __osViDevMgr = {0}; - -extern OSThread viThread; -extern OSMesgQueue viEventQueue; -extern OSMesg viEventBuf[5]; -extern OSIoMesg viRetraceMsg; -extern OSIoMesg viCounterMsg; -extern u64 gViMgrStack[0x20]; - -void viMgrMain(void *arg); - -void osCreateViManager(OSPri pri) { - u32 savedMask; - OSPri oldPri; - OSPri myPri; - if (__osViDevMgr.active == 0) { - __osTimerServicesInit(); - osCreateMesgQueue(&viEventQueue, viEventBuf, 5); - 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 = 1; - __osViDevMgr.thread = &viThread; - __osViDevMgr.cmdQueue = &viEventQueue; - __osViDevMgr.evtQueue = &viEventQueue; - __osViDevMgr.acsQueue = NULL; - __osViDevMgr.dma = NULL; - __osViDevMgr.edma = NULL; - osCreateThread(&viThread, 0, viMgrMain, &__osViDevMgr, &gViMgrStack[0x20], pri); - __osViInit(); - osStartThread(&viThread); - __osRestoreInt(savedMask); - if (oldPri != -1) { - osSetThreadPri(0, oldPri); - } - } -} - -#ifdef NON_EQUIVALENT -void __osTimerInterrupt(void); -//Fails due to how retrace is declared. Not sure how to fix it. -void viMgrMain(void *arg) { - __OSViContext *vc; - OSDevMgr *dm; - OSIoMesg *mesg; - static u16 retrace; - s32 first; - u32 count; - - mesg = NULL; - first = FALSE; - vc = __osViGetCurrentContext(); - retrace = vc->retraceCount; - - if (retrace == 0) - retrace = 1; - - dm = (OSDevMgr *)arg; - - while (TRUE) { - osRecvMesg(dm->evtQueue, (OSMesg *)&mesg, OS_MESG_BLOCK); - switch (mesg->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 = FALSE; - } - count = __osBaseCounter; - __osBaseCounter = osGetCount(); - count = __osBaseCounter - count; - __osCurrentTime = __osCurrentTime + count; - break; - - case OS_MESG_TYPE_COUNTER: - __osTimerInterrupt(); - break; - } - } -} -#else -GLOBAL_ASM("lib/asm/non_matchings/osViMgr_0D2590/viMgrMain.s") -#endif diff --git a/lib/src/os/osViSetEvent.c b/lib/src/os/osViSetEvent.c deleted file mode 100644 index 08dc6d0b..00000000 --- a/lib/src/os/osViSetEvent.c +++ /dev/null @@ -1,14 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D1D80 */ - -#include "libultra_internal.h" -#include "viint.h" - -void osViSetEvent(OSMesgQueue *mq, OSMesg m, u32 retraceCount) { - register u32 saveMask; - saveMask = __osDisableInt(); - __osViNext->msgq = mq; - __osViNext->msg = m; - __osViNext->retraceCount = retraceCount; - __osRestoreInt(saveMask); -} diff --git a/lib/src/os/osViSetMode.c b/lib/src/os/osViSetMode.c deleted file mode 100644 index c3c4d595..00000000 --- a/lib/src/os/osViSetMode.c +++ /dev/null @@ -1,14 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D1CA0 */ - -#include "libultra_internal.h" -#include "viint.h" - -void osViSetMode(OSViMode *modep) { - register u32 saveMask; - saveMask = __osDisableInt(); - __osViNext->modep = modep; - __osViNext->state = VI_STATE_01; - __osViNext->control = __osViNext->modep->comRegs.ctrl; - __osRestoreInt(saveMask); -} diff --git a/lib/src/os/osViSetSpecialFeatures.c b/lib/src/os/osViSetSpecialFeatures.c deleted file mode 100644 index d0596eb9..00000000 --- a/lib/src/os/osViSetSpecialFeatures.c +++ /dev/null @@ -1,39 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D2260 */ - -#include "libultra_internal.h" -#include "viint.h" - -void osViSetSpecialFeatures(u32 func) { - register u32 saveMask; - 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_08; - - __osRestoreInt(saveMask); -} diff --git a/lib/src/os/osViSwapBuffer.c b/lib/src/os/osViSwapBuffer.c deleted file mode 100644 index 7311c45b..00000000 --- a/lib/src/os/osViSwapBuffer.c +++ /dev/null @@ -1,12 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D2420 */ - -#include "libultra_internal.h" -#include "viint.h" - -void osViSwapBuffer(void *frameBufPtr) { - u32 saveMask = __osDisableInt(); - __osViNext->framep = frameBufPtr; - __osViNext->state |= VI_STATE_10; - __osRestoreInt(saveMask); -} diff --git a/lib/src/os/pfsallocatefile.c b/lib/src/os/pfsallocatefile.c deleted file mode 100644 index a5e4147a..00000000 --- a/lib/src/os/pfsallocatefile.c +++ /dev/null @@ -1,184 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D1040 */ - -#include "types.h" -#include "controller.h" - -static s32 __osClearPage(OSPfs *pfs, int page_no, u8 *data, u8 bank); -s32 osPfsAllocateFile(OSPfs *pfs, u16 company_code, u32 game_code, u8 *game_name, u8 *ext_name, int file_size_in_bytes, s32 *file_no) -{ - int start_page; - int decleared; - int last_page; - int old_last_page; - int j; - s32 ret; - int file_size_in_pages; - __OSInode inode; - __OSInode backup_inode; - __OSDir dir; - u8 bank; - u8 old_bank; - int firsttime; - s32 bytes; - __OSInodeUnit fpage; - - old_last_page = 0; - ret = 0; - old_bank = 0; - firsttime = 0; - - if (company_code == 0 || game_code == 0) - return PFS_ERR_INVALID; - - file_size_in_pages = (file_size_in_bytes + 255) / (BLOCKSIZE * PFS_ONE_PAGE); - if ((pfs->status & PFS_INITIALIZED) == FALSE) - return PFS_ERR_INVALID; - - PFS_CHECK_ID; - - ret = osPfsFindFile(pfs, company_code, game_code, game_name, ext_name, file_no); - if (ret != 0 && ret != PFS_ERR_INVALID) - return ret; - - if (*file_no != -1) - return PFS_ERR_EXIST; - - ret = osPfsFreeBlocks(pfs, &bytes); - if (file_size_in_bytes > bytes) - return PFS_DATA_FULL; - - if (file_size_in_pages != 0) - { - ret = osPfsFindFile(pfs, 0, 0, NULL, NULL, file_no); - if (ret != 0 && ret != PFS_ERR_INVALID) - return ret; - if (*file_no == -1) - return PFS_DIR_FULL; - - for (bank = 0; bank < pfs->banks; bank++) - { - ERRCK(__osPfsRWInode(pfs, &inode, OS_READ, bank)); - ERRCK(__osPfsDeclearPage(pfs, &inode, file_size_in_pages, &start_page, bank, &decleared, &last_page)); - if (start_page != -1) - { - if (firsttime == 0) - { - fpage.inode_t.page = start_page; - fpage.inode_t.bank = bank; - } - else - { - backup_inode.inode_page[old_last_page].inode_t.bank = bank; - backup_inode.inode_page[old_last_page].inode_t.page = start_page; - ERRCK(__osPfsRWInode(pfs, &backup_inode, OS_WRITE, old_bank)); - } - - for (j = 0; j < ARRLEN(inode.inode_page); j++) - backup_inode.inode_page[j].ipage = inode.inode_page[j].ipage; - old_last_page = last_page; - old_bank = bank; - firsttime++; - if (file_size_in_pages > decleared) - file_size_in_pages = file_size_in_pages - decleared; - else - { - file_size_in_pages = 0; - break; - } - } - } - if (file_size_in_pages > 0 || start_page == -1) - return PFS_ERR_INCONSISTENT; - - backup_inode.inode_page[old_last_page].inode_t.bank = bank; - backup_inode.inode_page[old_last_page].inode_t.page = start_page; - ERRCK(__osPfsRWInode(pfs, &backup_inode, OS_WRITE, old_bank)); - dir.start_page = fpage; - dir.company_code = company_code; - dir.game_code = game_code; - dir.data_sum = 0; - for (j = 0; j < ARRLEN(dir.game_name); j++) - dir.game_name[j] = *game_name++; - for (j = 0; j < ARRLEN(dir.ext_name); j++) - dir.ext_name[j] = *ext_name++; - ERRCK(__osContRamWrite(pfs->queue, pfs->channel, *file_no + pfs->dir_table, (u8*)&dir, FALSE)); - return ret; - } - return PFS_ERR_INVALID; -} - -s32 __osPfsDeclearPage(OSPfs *pfs, __OSInode *inode, int file_size_in_pages, int *first_page, u8 bank, int *decleared, int *last_page) -{ - int j; - int spage; - int old_page; - u8 tmp_data[BLOCKSIZE]; - int i; - s32 ret; - int offset; - - ret = 0; - if (bank > 0) - offset = 1; - else - offset = pfs->inode_start_page; - for (j = offset; j < ARRLEN(inode->inode_page); j++) - { - if (inode->inode_page[j].ipage == 3) - break; - } - if (j == ARRLEN(inode->inode_page)) - { - *first_page = -1; - return ret; - } - for (i = 0; i < ARRLEN(tmp_data); i++) - tmp_data[i] = 0; - spage = j; - *decleared = 1; - old_page = j++; - while (file_size_in_pages > *decleared && j < ARRLEN(inode->inode_page)) - { - if (inode->inode_page[j].ipage == 3) - { - inode->inode_page[old_page].inode_t.bank = bank; - inode->inode_page[old_page].inode_t.page = j; - ERRCK(__osClearPage(pfs, old_page, (u8*)tmp_data, bank)); - old_page = j; - (*decleared)++; - } - j++; - } - *first_page = spage; - if (j == ARRLEN(inode->inode_page)) - { - if (file_size_in_pages > *decleared) - { - *last_page = old_page; - return ret; - } - } - inode->inode_page[old_page].ipage = 1; - ret = __osClearPage(pfs, old_page, (u8*)tmp_data, bank); - *last_page = 0; - return ret; -} - -static s32 __osClearPage(OSPfs *pfs, int page_no, u8 *data, u8 bank) -{ - int i; - s32 ret; - ret = 0; - pfs->activebank = bank; - ERRCK(__osPfsSelectBank(pfs)); - for (i = 0; i < PFS_ONE_PAGE; i++) - { - ret = __osContRamWrite(pfs->queue, pfs->channel, page_no * PFS_ONE_PAGE + i, data, FALSE); - if (ret != 0) - break; - } - pfs->activebank = 0; - ret = __osPfsSelectBank(pfs); - return ret; -} diff --git a/lib/src/os/piacs.c b/lib/src/os/piacs.c deleted file mode 100644 index cd163c65..00000000 --- a/lib/src/os/piacs.c +++ /dev/null @@ -1,101 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D2480 */ - -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" - -#define PI_Q_BUF_LEN 1 -extern u32 __osPiAccessQueueEnabled; -extern OSMesg piAccessBuf[PI_Q_BUF_LEN]; -extern OSMesgQueue __osPiAccessQueue; -void __osPiCreateAccessQueue(void) { - __osPiAccessQueueEnabled = 1; - osCreateMesgQueue(&__osPiAccessQueue, piAccessBuf, PI_Q_BUF_LEN); - osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK); -} - -void __osPiGetAccess(void) { - OSMesg dummyMesg; - if (!__osPiAccessQueueEnabled) - __osPiCreateAccessQueue(); - osRecvMesg(&__osPiAccessQueue, &dummyMesg, OS_MESG_BLOCK); -} - -void __osPiRelAccess(void) { - osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK); -} - -/**********************************************************************/ - -// Please move these later! -#include "lib/src/gu/guint.h" -// Used with cosf - -/* coefficients for polynomial approximation of cos on +/- pi/2 */ - -const du P_cosf[] = -{ -{{0x3ff00000, 0x00000000}}, -{{0xbfc55554, 0xbc83656d}}, -{{0x3f8110ed, 0x3804c2a0}}, -{{0xbf29f6ff, 0xeea56814}}, -{{0x3ec5dbdf, 0x0e314bfe}}, -}; - -const du rpi_cosf = -{{0x3fd45f30, 0x6dc9c883}}; - -const du pihi_cosf = -{{0x400921fb, 0x50000000}}; - -const du pilo_cosf = -{{0x3e6110b4, 0x611a6263}}; - -const fu zero_cosf = {0x00000000}; - -const int COSF_FILE_PADDING[3] = { 0 }; - -// Used with sinf -/* coefficients for polynomial approximation of sin on +/- pi/2 */ - -const du P_sinf[] = -{ -{{0x3ff00000, 0x00000000}}, -{{0xbfc55554, 0xbc83656d}}, -{{0x3f8110ed, 0x3804c2a0}}, -{{0xbf29f6ff, 0xeea56814}}, -{{0x3ec5dbdf, 0x0e314bfe}}, -}; - -const du rpi_sinf = -{{0x3fd45f30, 0x6dc9c883}}; - -const du pihi_sinf = -{{0x400921fb, 0x50000000}}; - -const du pilo_sinf = -{{0x3e6110b4, 0x611a6263}}; - -const fu zero_sinf = {0x00000000}; - -const int SINF_FILE_PADDING[3] = { 0 }; - -// Used with _Litob -char ldigs[] = "0123456789abcdef"; // lowercase hex digits -char udigs[] = "0123456789ABCDEF"; // uppercase hex digits - -// Powers for _Ldtob -const double pows[] = {10e0L, 10e1L, 10e3L, 10e7L, 10e15L, 10e31L, 10e63L, 10e127L, 10e255L}; - -const char Ldtob_NaN[] = "NaN"; -const char Ldtob_Inf[] = "Inf"; - -//_Genld -const char _Genld_0_string[] = "0"; - -//_Ldtob -const double _Ldtob_1e8[] = {1.0e8}; - -//sinf and cosf - supposed to be defined by libm_vals.s -const fu __libm_qnan_f = { 0x7f810000 }; diff --git a/lib/src/os/osRecvMesg.c b/lib/src/os/recvmesg.c similarity index 58% rename from lib/src/os/osRecvMesg.c rename to lib/src/os/recvmesg.c index 5f77c9fa..41daef00 100644 --- a/lib/src/os/osRecvMesg.c +++ b/lib/src/os/recvmesg.c @@ -1,34 +1,43 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C8BB0 */ -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" -#include "osint.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PRinternal/osint.h" -extern OSThread *__osRunningThread; - -s32 osRecvMesg(OSMesgQueue *mq, OSMesg *msg, s32 flags) { +s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flags) { register u32 saveMask; + +#ifdef _DEBUG + if ((flags != OS_MESG_NOBLOCK) && (flags != OS_MESG_BLOCK)) { + __osError(ERR_OSRECVMESG, 1, flags); + return -1; + } +#endif + saveMask = __osDisableInt(); while (MQ_IS_EMPTY(mq)) { if (flags == OS_MESG_NOBLOCK) { __osRestoreInt(saveMask); return -1; + } else { + __osRunningThread->state = OS_STATE_WAITING; + __osEnqueueAndYield(&mq->mtqueue); } - __osRunningThread->state = OS_STATE_WAITING; - __osEnqueueAndYield(&mq->mtqueue); } if (msg != NULL) { *msg = mq->msg[mq->first]; } + mq->first = (mq->first + 1) % mq->msgCount; mq->validCount--; + if (mq->fullqueue->next != NULL) { osStartThread(__osPopThread(&mq->fullqueue)); } + __osRestoreInt(saveMask); return 0; } diff --git a/lib/src/os/resetglobalintmask.c b/lib/src/os/resetglobalintmask.c new file mode 100644 index 00000000..4b42dddd --- /dev/null +++ b/lib/src/os/resetglobalintmask.c @@ -0,0 +1,14 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D6500 */ + +#include "PR/os_internal.h" + +extern OSIntMask __OSGlobalIntMask; /* global interrupt mask */ + +void __osResetGlobalIntMask(OSHWIntr mask) { + register u32 saveMask = __osDisableInt(); + + __OSGlobalIntMask &= ~(mask & ~OS_IM_RCP); + + __osRestoreInt(saveMask); +} diff --git a/lib/src/os/osSendMesg.c b/lib/src/os/sendmesg.c similarity index 67% rename from lib/src/os/osSendMesg.c rename to lib/src/os/sendmesg.c index 2017a20f..77b9c716 100644 --- a/lib/src/os/osSendMesg.c +++ b/lib/src/os/sendmesg.c @@ -1,29 +1,41 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C8E30 */ -#include "libultra_internal.h" -#include "osint.h" -extern OSThread *__osRunningThread; -s32 osSendMesg(OSMesgQueue *mq, OSMesg msg, s32 flags) { +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PRinternal/osint.h" + +s32 osSendMesg(OSMesgQueue* mq, OSMesg msg, s32 flags) { register u32 saveMask; register s32 last; + +#ifdef _DEBUG + if ((flags != OS_MESG_NOBLOCK) && (flags != OS_MESG_BLOCK)) { + __osError(ERR_OSSENDMESG, 1, flags); + return -1; + } +#endif + saveMask = __osDisableInt(); + while (MQ_IS_FULL(mq)) { if (flags == OS_MESG_BLOCK) { __osRunningThread->state = OS_STATE_WAITING; __osEnqueueAndYield(&mq->fullqueue); - } - else { + } else { __osRestoreInt(saveMask); return -1; } } + last = (mq->first + mq->validCount) % mq->msgCount; mq->msg[last] = msg; mq->validCount++; + if (mq->mtqueue->next != NULL) { osStartThread(__osPopThread(&mq->mtqueue)); } + __osRestoreInt(saveMask); return 0; } diff --git a/lib/src/os/seteventmesg.c b/lib/src/os/seteventmesg.c new file mode 100644 index 00000000..3ce31d99 --- /dev/null +++ b/lib/src/os/seteventmesg.c @@ -0,0 +1,42 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CCBB0 */ + +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PRinternal/osint.h" + +__OSEventState __osEventStateTab[OS_NUM_EVENTS] ALIGNED(0x8); +#if BUILD_VERSION >= VERSION_J +u32 __osPreNMI = FALSE; +#endif + +void osSetEventMesg(OSEvent event, OSMesgQueue* mq, OSMesg msg) { + register u32 saveMask; + __OSEventState* es; + +#ifdef _DEBUG + if (event >= OS_NUM_EVENTS) { + __osError(ERR_OSSETEVENTMESG, 1, event); + return; + } +#endif + + saveMask = __osDisableInt(); + + es = &__osEventStateTab[event]; + + es->messageQueue = mq; + es->message = msg; + +#if BUILD_VERSION >= VERSION_J + if (event == OS_EVENT_PRENMI) { + if (__osShutdown && !__osPreNMI) { + osSendMesg(mq, msg, OS_MESG_NOBLOCK); + } + __osPreNMI = TRUE; + } +#endif + + __osRestoreInt(saveMask); +} diff --git a/lib/src/os/sethwinterrupt.c b/lib/src/os/sethwinterrupt.c new file mode 100644 index 00000000..b7dfb77a --- /dev/null +++ b/lib/src/os/sethwinterrupt.c @@ -0,0 +1,36 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D47DC */ + +#include "PR/os_internal.h" +#include + +// A stack frame was added to hardware interrupt handlers in 2.0J +#if BUILD_VERSION >= VERSION_J + +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); +} + +#else + +extern struct s32 (*__osHwIntTable[])(void); + +void __osSetHWIntrRoutine(OSHWIntr interrupt, s32 (*handler)(void)) { + register u32 saveMask = __osDisableInt(); + + __osHwIntTable[interrupt] = handler; + __osRestoreInt(saveMask); +} + +#endif diff --git a/lib/src/os/osSetThreadPri.c b/lib/src/os/setthreadpri.c similarity index 60% rename from lib/src/os/osSetThreadPri.c rename to lib/src/os/setthreadpri.c index 041d8e1b..755d421c 100644 --- a/lib/src/os/osSetThreadPri.c +++ b/lib/src/os/setthreadpri.c @@ -1,26 +1,39 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800CC840 */ -#include "libultra_internal.h" -#include "osint.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PRinternal/osint.h" -extern OSThread *__osRunningThread; -extern OSThread *__osRunQueue; +void osSetThreadPri(OSThread* t, OSPri pri) { + register u32 saveMask; -void osSetThreadPri(OSThread *t, OSPri pri) { - register u32 saveMask = __osDisableInt(); - if (t == NULL) +#ifdef _DEBUG + if ((pri < OS_PRIORITY_IDLE) || (pri > OS_PRIORITY_MAX)) { + __osError(ERR_OSSETTHREADPRI, 1, pri); + return; + } +#endif + + 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/lib/src/os/settime.c b/lib/src/os/settime.c new file mode 100644 index 00000000..8125b59e --- /dev/null +++ b/lib/src/os/settime.c @@ -0,0 +1,19 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800CD260 */ + +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PRinternal/osint.h" +#include "PRinternal/viint.h" + +void osSetTime(OSTime time) { + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSSETTIME, 0); + return; + } +#endif + + __osCurrentTime = time; +} diff --git a/lib/src/os/settimer.c b/lib/src/os/settimer.c new file mode 100644 index 00000000..dbad33e9 --- /dev/null +++ b/lib/src/os/settimer.c @@ -0,0 +1,59 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D4DE0 */ + +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PRinternal/osint.h" +#include "PRinternal/viint.h" + +int osSetTimer(OSTimer* t, OSTime countdown, OSTime interval, OSMesgQueue* mq, OSMesg msg) { + OSTime time; +#if BUILD_VERSION >= VERSION_K + OSTimer* next; + u32 count; + u32 value; + u32 saveMask; +#endif + +#ifdef _DEBUG + if (!__osViDevMgr.active) { + __osError(ERR_OSSETTIMER, 0); + return 0; + } +#endif + + t->next = NULL; + t->prev = NULL; + t->interval = interval; + t->value = (countdown != 0) ? countdown : interval; + t->mq = mq; + t->msg = msg; + +#if BUILD_VERSION >= VERSION_K + saveMask = __osDisableInt(); + if (__osTimerList->next == __osTimerList) { + + } else { + next = __osTimerList->next; + count = osGetCount(); + value = count - __osTimerCounter; + + if (value < next->value) { + next->value -= value; + } else { + next->value = 1; + } + } + + time = __osInsertTimer(t); + __osSetTimerIntr(__osTimerList->next->value); + __osRestoreInt(saveMask); +#else + time = __osInsertTimer(t); + if (__osTimerList->next == t) { + __osSetTimerIntr(time); + } +#endif + + return 0; +} diff --git a/lib/src/os/si.c b/lib/src/os/si.c deleted file mode 100644 index 2d627a7f..00000000 --- a/lib/src/os/si.c +++ /dev/null @@ -1,12 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D52C0 */ - -#include "libultra_internal.h" -#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/lib/src/os/siacs.c b/lib/src/os/siacs.c deleted file mode 100644 index 3a377c82..00000000 --- a/lib/src/os/siacs.c +++ /dev/null @@ -1,54 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800CD600 */ - -#include "libultra_internal.h" -#include "controller.h" -#include "src/memory.h" - -u32 __osSiAccessQueueEnabled = 0; - -// Ok, so I completely gave up on the rest of these bss variables. -// This is probably not the right place for them, but we can always -// fix that later. -#define SI_Q_BUF_LEN 1 -static OSMesg siAccessBuf[SI_Q_BUF_LEN]; -OSMesgQueue __osSiAccessQueue; -OSPifRam __osEepPifRam; -OSThread viThread; -u64 gViMgrStack[0x20]; -s32 viEventQueue[6]; -s32 viEventBuf[6]; -s32 viRetraceMsg[6]; -s32 viCounterMsg[6]; -u16 retrace; //Used in viMgrMain, but it's supposed to be static in that function -u16 D_8012D192; -s32 D_8012D194[2]; -OSTask tmp_task; //Supposed to be statically declared in sptask.c -#define PI_Q_BUF_LEN 1 -OSMesg piAccessBuf[PI_Q_BUF_LEN]; //Should be static, but this works for now -s32 __osPiAccessQueue[6]; -OSTimer __osBaseTimer; -OSTime __osCurrentTime; -s32 __osBaseCounter; -s32 __osViIntrCount; -u32 __osTimerCounter; -u32 D_8012D234[2]; -OSThread gInterruptedThread; -MemoryPoolSlot *gMainMemoryPool; - -void __osSiCreateAccessQueue(void) { - __osSiAccessQueueEnabled = 1; - osCreateMesgQueue(&__osSiAccessQueue, siAccessBuf, SI_Q_BUF_LEN); - 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/lib/src/os/sptask.c b/lib/src/os/sptask.c deleted file mode 100644 index 1c5f23c7..00000000 --- a/lib/src/os/sptask.c +++ /dev/null @@ -1,61 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D1EF0 */ - -#include "libultra_internal.h" -#include "viint.h" -#include "PR/sptask.h" -#include "osint.h" -#include "macros.h" - -#define _osVirtualToPhysical(ptr) \ - if (ptr != NULL) { \ - ptr = (void *)osVirtualToPhysical(ptr); \ - } - -extern OSTask tmp_task; -static OSTask *_VirtualToPhysicalTask(OSTask *intp) { - OSTask *tp; - tp = &tmp_task; - bcopy(intp, tp, sizeof(OSTask)); - - _osVirtualToPhysical(tp->t.ucode); - _osVirtualToPhysical(tp->t.ucode_data); - _osVirtualToPhysical(tp->t.dram_stack); - _osVirtualToPhysical(tp->t.output_buff); - _osVirtualToPhysical(tp->t.output_buff_size); - _osVirtualToPhysical(tp->t.data_ptr); - _osVirtualToPhysical(tp->t.yield_data_ptr); - return tp; -} - -void osSpTaskLoad(OSTask *intp) { - OSTask *tp; - tp = _VirtualToPhysicalTask(intp); - if (tp->t.flags & OS_TASK_YIELDED) { - tp->t.ucode_data = tp->t.yield_data_ptr; - tp->t.ucode_data_size = tp->t.yield_data_size; - intp->t.flags &= ~OS_TASK_YIELDED; - } - - osWritebackDCache(tp, sizeof(OSTask)); - __osSpSetStatus(SP_CLR_YIELD | SP_CLR_YIELDED | SP_CLR_TASKDONE | SP_SET_INTR_BREAK); - while (__osSpSetPc(SP_IMEM_START) == -1) - ; - - while (__osSpRawStartDma(OS_WRITE, (SP_IMEM_START - sizeof(*tp)), tp, - sizeof(OSTask)) == -1) - ; - - while (__osSpDeviceBusy()) - ; - - while (__osSpRawStartDma(OS_WRITE, SP_IMEM_START, tp->t.ucode_boot, - tp->t.ucode_boot_size) == -1) - ; -} - -void osSpTaskStartGo(UNUSED OSTask *tp) { - while (__osSpDeviceBusy()); - - __osSpSetStatus(SP_SET_INTR_BREAK | SP_CLR_SSTEP | SP_CLR_BROKE | SP_CLR_HALT); -} diff --git a/lib/src/os/osStartThread.c b/lib/src/os/startthread.c similarity index 64% rename from lib/src/os/osStartThread.c rename to lib/src/os/startthread.c index ca2cbb1b..e27ac39d 100644 --- a/lib/src/os/osStartThread.c +++ b/lib/src/os/startthread.c @@ -1,14 +1,13 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C89A0 */ -#include "libultra_internal.h" -#include "osint.h" +#include "PR/os_internal.h" +#include "PR/ultraerror.h" +#include "PRinternal/osint.h" -extern OSThread *__osRunningThread; -extern OSThread *__osRunQueue; - -void osStartThread(OSThread *t) { +void osStartThread(OSThread* t) { register u32 saveMask = __osDisableInt(); + switch (t->state) { case OS_STATE_WAITING: t->state = OS_STATE_RUNNABLE; @@ -18,22 +17,26 @@ void osStartThread(OSThread *t) { if (t->queue == NULL || t->queue == &__osRunQueue) { t->state = OS_STATE_RUNNABLE; __osEnqueueThread(&__osRunQueue, t); - } - else { + } else { t->state = OS_STATE_WAITING; __osEnqueueThread(t->queue, t); __osEnqueueThread(&__osRunQueue, __osPopThread(t->queue)); } break; +#ifdef _DEBUG + default: + __osError(ERR_OSSTARTTHREAD, 0); + __osRestoreInt(saveMask); + return; +#endif } + if (__osRunningThread == NULL) { __osDispatchThread(); + } else if (__osRunningThread->priority < __osRunQueue->priority) { + __osRunningThread->state = OS_STATE_RUNNABLE; + __osEnqueueAndYield(&__osRunQueue); } - else { - if (__osRunningThread->priority < __osRunQueue->priority) { - __osRunningThread->state = OS_STATE_RUNNABLE; - __osEnqueueAndYield(&__osRunQueue); - } - } + __osRestoreInt(saveMask); } diff --git a/lib/src/os/osStopThread.c b/lib/src/os/stopthread.c similarity index 71% rename from lib/src/os/osStopThread.c rename to lib/src/os/stopthread.c index d1b4aa68..2955c359 100644 --- a/lib/src/os/osStopThread.c +++ b/lib/src/os/stopthread.c @@ -1,20 +1,15 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C8AF0 */ -#include "libultra_internal.h" -#include "osint.h" +#include "PR/os_internal.h" +#include "PRinternal/osint.h" -extern OSThread *__osRunningThread; - -void osStopThread(OSThread *t) { +void osStopThread(OSThread* t) { register u32 saveMask = __osDisableInt(); register u16 state; - if (t == NULL) { - state = OS_STATE_RUNNING; - } - else { - state = t->state; - } + + state = (t == NULL) ? OS_STATE_RUNNING: t->state; + switch (state) { case OS_STATE_RUNNING: __osRunningThread->state = OS_STATE_STOPPED; @@ -26,5 +21,6 @@ void osStopThread(OSThread *t) { __osDequeueThread(t->queue, t); break; } + __osRestoreInt(saveMask); } diff --git a/lib/src/os/thread.c b/lib/src/os/thread.c index 2a9f9889..4226aa13 100644 --- a/lib/src/os/thread.c +++ b/lib/src/os/thread.c @@ -1,19 +1,31 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D2C70 */ -#include "libultra_internal.h" +#include "PR/os_internal.h" +#include "PRinternal/osint.h" -void __osDequeueThread(OSThread **queue, OSThread *t) { - register OSThread *pred; - register OSThread *succ; - pred = (OSThread *)queue; //this is actually legit.. - succ = pred->next; - while (succ != NULL) { - if (succ == t) { - pred->next = t->next; - return; - } - pred = succ; - succ = pred->next; - } +struct __osThreadTail __osThreadTail = { NULL, -1 }; +OSThread* __osRunQueue = (OSThread*)&__osThreadTail; +OSThread* __osActiveQueue = (OSThread*)&__osThreadTail; +OSThread* __osRunningThread = NULL; +OSThread* __osFaultedThread = NULL; + +void __osDequeueThread(register OSThread** queue, register OSThread* t) { + register OSThread* pred; + register OSThread* succ; + + pred = (OSThread*)queue; + succ = pred->next; + + while (succ != NULL) { + if (succ == t) { + pred->next = t->next; +#ifdef _DEBUG + t->next = NULL; +#endif + return; + } + pred = succ; + succ = pred->next; + } } diff --git a/lib/src/os/threadasm.h b/lib/src/os/threadasm.h new file mode 100644 index 00000000..dfd91b6f --- /dev/null +++ b/lib/src/os/threadasm.h @@ -0,0 +1,68 @@ +#ifndef _THREADASM_H_ +#define _THREADASM_H_ + +/* Offsets of members in the OSThread struct */ +#define THREAD_NEXT 0 +#define THREAD_PRI 4 +#define THREAD_QUEUE 8 +#define THREAD_TLNEXT 12 +#define THREAD_STATE 16 +#define THREAD_FLAGS 18 +#define THREAD_ID 20 +#define THREAD_FP 24 +#define THREAD_GP1 32 +#define THREAD_GP2 40 +#define THREAD_GP3 48 +#define THREAD_GP4 56 +#define THREAD_GP5 64 +#define THREAD_GP6 72 +#define THREAD_GP7 80 +#define THREAD_GP8 88 +#define THREAD_GP9 96 +#define THREAD_GP10 104 +#define THREAD_GP11 112 +#define THREAD_GP12 120 +#define THREAD_GP13 128 +#define THREAD_GP14 136 +#define THREAD_GP15 144 +#define THREAD_GP16 152 +#define THREAD_GP17 160 +#define THREAD_GP18 168 +#define THREAD_GP19 176 +#define THREAD_GP20 184 +#define THREAD_GP21 192 +#define THREAD_GP22 200 +#define THREAD_GP23 208 +#define THREAD_GP24 216 +#define THREAD_GP25 224 +/* k0 and k1 are reserved for the kernel */ +#define THREAD_GP28 232 +#define THREAD_GP29 240 +#define THREAD_GP30 248 +#define THREAD_GP31 256 +#define THREAD_LO 264 +#define THREAD_HI 272 +#define THREAD_SR 280 +#define THREAD_PC 284 +#define THREAD_CAUSE 288 +#define THREAD_BADVADDR 292 +#define THREAD_RCP 296 +#define THREAD_FPCSR 300 +#define THREAD_FP0 304 +#define THREAD_FP2 312 +#define THREAD_FP4 320 +#define THREAD_FP6 328 +#define THREAD_FP8 336 +#define THREAD_FP10 344 +#define THREAD_FP12 352 +#define THREAD_FP14 360 +#define THREAD_FP16 368 +#define THREAD_FP18 376 +#define THREAD_FP20 384 +#define THREAD_FP22 392 +#define THREAD_FP24 400 +#define THREAD_FP26 408 +#define THREAD_FP28 416 +#define THREAD_FP30 424 + +#endif diff --git a/lib/src/os/timerintr.c b/lib/src/os/timerintr.c new file mode 100644 index 00000000..6141002e --- /dev/null +++ b/lib/src/os/timerintr.c @@ -0,0 +1,144 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D4EC0 */ + +#include "PRinternal/macros.h" +#include "PR/os_internal.h" +#include "PRinternal/osint.h" + +OSTime __osCurrentTime; +u32 __osBaseCounter; +u32 __osViIntrCount; +u32 __osTimerCounter; +OSTimer __osBaseTimer; +OSTimer* __osTimerList = &__osBaseTimer; + +#ifndef _FINALROM +OSMesgQueue __osProfTimerQ ALIGNED(0x8); +OSProf* __osProfileList; +OSProf* __osProfileListEnd; +u32 __osProfileOverflowBin; +#endif + +void __osTimerServicesInit(void) { + __osCurrentTime = 0; + __osBaseCounter = 0; + __osViIntrCount = 0; + __osTimerList->next = __osTimerList->prev = __osTimerList; + __osTimerList->interval = __osTimerList->value = 0; + __osTimerList->mq = NULL; + __osTimerList->msg = 0; +} + +void __osTimerInterrupt(void) { + OSTimer* t; + u32 count; + u32 elapsed_cycles; + +#ifndef _FINALROM + u32 pc; + s32 offset; + OSProf* prof = __osProfileList; +#endif + + if (__osTimerList->next == __osTimerList) { + return; + } + for (;;) { + 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; + } + + t->prev->next = t->next; + t->next->prev = t->prev; + t->next = NULL; + t->prev = NULL; + + if (t->mq != NULL) { +#ifdef _FINALROM + osSendMesg(t->mq, t->msg, OS_MESG_NOBLOCK); + } +#else + if (t->mq != &__osProfTimerQ) { + osSendMesg(t->mq, t->msg, OS_MESG_NOBLOCK); + } else { + pc = __osRunQueue->context.pc; + for (prof = __osProfileList; prof < __osProfileListEnd; prof++) { + offset = pc - (u32)prof->text_start; + + if (offset >= 0) { + if ((s32)prof->text_end - (s32)pc > 0) { + (*(u16*)(u32)((offset >> 2) + prof->histo_base))++; + goto __ProfDone; + } + } + } + + __osProfileOverflowBin++; + } + } +#endif + + __ProfDone: + + if (t->interval != 0) { + t->value = t->interval; + __osInsertTimer(t); + } + } +} + +void __osSetTimerIntr(OSTime tim) { + OSTime NewTime; + u32 savedMask; + +#if BUILD_VERSION >= VERSION_K + if (tim < 468) { + tim = 468; + } +#endif + + savedMask = __osDisableInt(); + __osTimerCounter = osGetCount(); + NewTime = __osTimerCounter + tim; + __osSetCompare(NewTime); + __osRestoreInt(savedMask); +} + +OSTime __osInsertTimer(OSTimer* t) { + OSTimer* timep; + OSTime tim; + u32 savedMask = __osDisableInt(); + + timep = __osTimerList->next; + tim = t->value; + for (; timep != __osTimerList && tim > timep->value; timep = timep->next) { + tim -= timep->value; + } + + t->value = tim; + + if (timep != __osTimerList) { + timep->value -= tim; + } + + t->next = timep; + t->prev = timep->prev; + timep->prev->next = t; + timep->prev = t; + __osRestoreInt(savedMask); + return tim; +} diff --git a/lib/src/os/vi.c b/lib/src/os/vi.c deleted file mode 100644 index 8210ab19..00000000 --- a/lib/src/os/vi.c +++ /dev/null @@ -1,37 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D2B10 */ - -#include "libultra_internal.h" -#include "viint.h" -#include "video.h" - -extern OSViMode osViModeNtscLan1; -extern OSViMode osViModePalLan1; -extern OSViMode osViModeMpalLan1; -extern __OSViContext vi[2]; -extern __OSViContext *__osViCurr; -extern __OSViContext *__osViNext; -extern s32 osViClock; - -void __osViInit(void) { - bzero(vi, sizeof(vi)); - __osViCurr = &vi[0]; - __osViNext = &vi[1]; - __osViNext->retraceCount = 1; - __osViCurr->retraceCount = 1; - if (osTvType == OS_TV_TYPE_PAL) { - __osViNext->modep = &osViModePalLan1; - osViClock = VI_PAL_CLOCK; - } else if (osTvType == OS_TV_TYPE_MPAL) { - __osViNext->modep = &osViModeMpalLan1; - osViClock = VI_MPAL_CLOCK; - } else { - __osViNext->modep = &osViModeNtscLan1; - osViClock = VI_NTSC_CLOCK; - } - __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/lib/src/os/osVirtualToPhysical.c b/lib/src/os/virtualtophysical.c similarity index 70% rename from lib/src/os/osVirtualToPhysical.c rename to lib/src/os/virtualtophysical.c index c65c128f..02902bff 100644 --- a/lib/src/os/osVirtualToPhysical.c +++ b/lib/src/os/virtualtophysical.c @@ -1,10 +1,11 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C8CF0 */ -#include "libultra_internal.h" -#include "osint.h" +#include "PR/os_internal.h" +#include "PR/R4300.h" +#include "PRinternal/osint.h" -u32 osVirtualToPhysical(void *addr) { +u32 osVirtualToPhysical(void* addr) { if (IS_KSEG0(addr)) { return K0_TO_PHYS(addr); } else if (IS_KSEG1(addr)) { diff --git a/lib/src/os/osYieldThread.c b/lib/src/os/yieldthread.c similarity index 58% rename from lib/src/os/osYieldThread.c rename to lib/src/os/yieldthread.c index 7ac4e986..b9839d21 100644 --- a/lib/src/os/osYieldThread.c +++ b/lib/src/os/yieldthread.c @@ -1,18 +1,12 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800D65B0 */ -#include "macros.h" -#include "libultra_internal.h" -#include "viint.h" - -extern OSThread *__osRunningThread; -extern OSThread *__osRunQueue; - -extern void __osEnqueueAndYield(OSThread **); -extern void __osRestoreInt(u32); +#include "PR/os_internal.h" +#include "PRinternal/osint.h" void osYieldThread(void) { register u32 saveMask = __osDisableInt(); + __osRunningThread->state = OS_STATE_RUNNABLE; __osEnqueueAndYield(&__osRunQueue); __osRestoreInt(saveMask); diff --git a/lib/src/mips1/sc/sched.c b/lib/src/sc/sched.c similarity index 68% rename from lib/src/mips1/sc/sched.c rename to lib/src/sc/sched.c index 4ba4f51d..39faf9b3 100644 --- a/lib/src/mips1/sc/sched.c +++ b/lib/src/sc/sched.c @@ -1,12 +1,28 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x80079350 */ +/*==================================================================== + * + * 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 #include -#include "sched.h" -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" -#include "viint.h" +#include +// TODO: this comes from a header +#ident "$Revision: 1.17 $" /* * private typedefs and defines @@ -16,6 +32,39 @@ #define RSP_DONE_MSG 667 #define RDP_DONE_MSG 668 #define PRE_NMI_MSG 669 +#define SCHED_THREAD_ID 5 + +/* + * OSScTask state + */ +#define OS_SC_DP 0x0001 /* set if still needs dp */ +#define OS_SC_SP 0x0002 /* set if still needs sp */ +#define OS_SC_YIELD 0x0010 /* set if yield requested */ +#define OS_SC_YIELDED 0x0020 /* set if yield completed */ + +/* + * OSScTask->flags type identifier + */ +#define OS_SC_XBUS (OS_SC_SP | OS_SC_DP) +#define OS_SC_DRAM (OS_SC_SP | OS_SC_DP | OS_SC_DRAM_DLIST) +#define OS_SC_DP_XBUS (OS_SC_SP) +#define OS_SC_DP_DRAM (OS_SC_SP | OS_SC_DRAM_DLIST) +#define OS_SC_SP_XBUS (OS_SC_DP) +#define OS_SC_SP_DRAM (OS_SC_DP | OS_SC_DRAM_DLIST) + +/* + * private functions + */ +static void __scMain(void *arg); +static void __scHandleRetrace(OSSched *s); +static void __scHandleRSP(OSSched *s); +static void __scHandleRDP(OSSched *s); + +static void __scAppendList(OSSched *s, OSScTask *t); +OSScTask *__scTaskReady(OSScTask *t); +static s32 __scTaskComplete(OSSched *s,OSScTask *t); +static void __scExec(OSSched *sc, OSScTask *sp, OSScTask *dp); +static void __scYield(OSSched *s); /************ .data ************/ @@ -66,12 +115,28 @@ u32 gRSPAudTaskFlushTime; u32 gRSPAudTaskDoneTime; UNUSED s32 D_80126128[18]; -/*******************************/ +static s32 __scSchedule(OSSched *sc, OSScTask **sp, OSScTask **dp, + s32 availRCP); -static void __scMain(void *arg); -static s32 __scSchedule(OSSched *sc, OSScTask **sp, OSScTask **dp, s32 availRCP); -void osCreateScheduler(OSSched *sc, void *stack, OSPri priority, u8 mode, u8 numFields) { +/* +#define SC_LOGGING 1 +*/ + + +#ifdef SC_LOGGING +#define SC_LOG_LEN 32*1024 +static OSLog scLog; +static OSLog *l = &scLog; +static u32 logArray[SC_LOG_LEN/sizeof(u32)]; +#endif + +/*********************************************************************** + * Scheduler API + **********************************************************************/ +void osCreateScheduler(OSSched *sc, void *stack, OSPri priority, + u8 mode, u8 numFields) +{ sc->curRSPTask = 0; sc->curRDPTask = 0; sc->clientList = 0; @@ -83,7 +148,7 @@ void osCreateScheduler(OSSched *sc, void *stack, OSPri priority, u8 mode, u8 num sc->unkTask = 0; sc->retraceMsg.type = OS_SC_RETRACE_MSG; /* sent to apps */ sc->prenmiMsg.type = OS_SC_PRE_NMI_MSG; - + /* * Set up video manager, listen for Video, RSP, and RDP interrupts */ @@ -93,16 +158,24 @@ void osCreateScheduler(OSSched *sc, void *stack, OSPri priority, u8 mode, u8 num osCreateMesgQueue(&sc->interruptQ, sc->intBuf, OS_SC_MAX_MESGS); osCreateMesgQueue(&sc->cmdQ, sc->cmdMsgBuf, OS_SC_MAX_MESGS); osSetEventMesg(OS_EVENT_SP, &sc->interruptQ, (OSMesg)RSP_DONE_MSG); - osSetEventMesg(OS_EVENT_DP, &sc->interruptQ, (OSMesg)RDP_DONE_MSG); - osSetEventMesg(OS_EVENT_PRENMI, &sc->interruptQ, (OSMesg)PRE_NMI_MSG); + osSetEventMesg(OS_EVENT_DP, &sc->interruptQ, (OSMesg)RDP_DONE_MSG); + osSetEventMesg(OS_EVENT_PRENMI, &sc->interruptQ, (OSMesg)PRE_NMI_MSG); - osViSetEvent(&sc->interruptQ, (OSMesg)VIDEO_MSG, numFields); + osViSetEvent(&sc->interruptQ, (OSMesg)VIDEO_MSG, numFields); - osCreateThread(&sc->thread, 5, __scMain, (void *)sc, stack, priority); +#ifdef SC_LOGGING + osCreateLog(l, logArray, sizeof(logArray)); +#endif + + osCreateThread(&sc->thread, SCHED_THREAD_ID, __scMain, (void *)sc, stack, priority); osStartThread(&sc->thread); } -void osScAddClient(OSSched *sc, OSScClient *c, OSMesgQueue *msgQ, u8 id){ +/* + * Add a client to the scheduler. Clients receive messages at retrace time + */ +void osScAddClient(OSSched *sc, OSScClient *c, OSMesgQueue *msgQ, u8 id) +{ OSIntMask mask; mask = osSetIntMask(OS_IM_NONE); @@ -111,11 +184,12 @@ void osScAddClient(OSSched *sc, OSScClient *c, OSMesgQueue *msgQ, u8 id){ c->next = sc->clientList; c->id = id; sc->clientList = c; - + osSetIntMask(mask); } -void osScRemoveClient(OSSched *sc, OSScClient *c) { +void osScRemoveClient(OSSched *sc, OSScClient *c) +{ OSScClient *client = sc->clientList; OSScClient *prev = 0; OSIntMask mask; @@ -124,10 +198,10 @@ void osScRemoveClient(OSSched *sc, OSScClient *c) { while (client != 0) { if (client == c) { - if(prev) - prev->next = c->next; - else - sc->clientList = c->next; + if(prev) + prev->next = c->next; + else + sc->clientList = c->next; break; } prev = client; @@ -137,7 +211,8 @@ void osScRemoveClient(OSSched *sc, OSScClient *c) { osSetIntMask(mask); } -OSMesgQueue *osScGetCmdQ(OSSched *sc) { +OSMesgQueue *osScGetCmdQ(OSSched *sc) +{ return &sc->cmdQ; } @@ -154,46 +229,54 @@ UNUSED void scGetAudioTaskTimers(f32 *timer0, f32 *timer1, f32 *timer2) { *timer2 = gAudTaskTimer3; } -static void __scMain(void *arg) { +/*********************************************************************** + * Scheduler implementation + **********************************************************************/ +static void __scMain(void *arg) +{ OSMesg msg = NULL; OSSched *sc = (OSSched *)arg; OSScClient *client; s32 state = 0; - OSScTask *sp = 0; - OSScTask *dp = 0; - + OSScTask *sp = NULL; + OSScTask *dp = NULL; + while (1) { - + osRecvMesg(&sc->interruptQ, (OSMesg *)&msg, OS_MESG_BLOCK); +#ifdef SC_LOGGING + if (++count % 1024 == 0) + osFlushLog(l); +#endif + + switch ((int) msg) { - case (VIDEO_MSG): - __scHandleRetrace(sc); - break; + case (VIDEO_MSG): + __scHandleRetrace(sc); + break; - case (RSP_DONE_MSG): - __scHandleRSP(sc); - break; + case (RSP_DONE_MSG): + __scHandleRSP(sc); + break; - case (RDP_DONE_MSG): - __scHandleRDP(sc); - break; - - case (UNK_MSG): + case (RDP_DONE_MSG): + __scHandleRDP(sc); + break; + case (UNK_MSG): func_80079760(sc); break; - case (PRE_NMI_MSG): - /* - * notify audio and graphics threads to fade out - */ - for (client = sc->clientList; client != 0; client = client->next) { - osSendMesg(client->msgQ, (OSMesg) &sc->prenmiMsg, - OS_MESG_NOBLOCK); - }; - break; - - default: + case (PRE_NMI_MSG): + /* + * notify audio and graphics threads to fade out + */ + for (client = sc->clientList;client != 0;client = client->next) { + osSendMesg(client->msgQ, (OSMesg) &sc->prenmiMsg, + OS_MESG_NOBLOCK); + } + break; + default: __scAppendList(sc, (OSScTask *) msg); state = ((sc->curRSPTask == 0) << 1) | (sc->curRDPTask == 0); if (__scSchedule(sc, &sp, &dp, state) != state) @@ -318,12 +401,24 @@ void __scHandleRetrace(OSSched *sc) { } } -void __scHandleRSP(OSSched *sc) { +/* + * __scHandleRSP is called when an RSP task signals that it has + * finished or yielded (at the hosts request) + */ +void __scHandleRSP(OSSched *sc) +{ OSScTask *t, *sp = 0, *dp = 0; s32 state; + + assert(sc->curRSPTask); + t = sc->curRSPTask; - sc->curRSPTask = NULL; + sc->curRSPTask = 0; + +#ifdef SC_LOGGING + osLogEvent(l, 510, 3, t, t->state, t->flags); +#endif //Rare seems to have edited this function, most specifically here. //This should probably have all been behind a debug #ifdef as none of these values are used. @@ -356,11 +451,9 @@ void __scHandleRSP(OSSched *sc) { } } else { t->state &= ~OS_SC_NEEDS_RSP; - /* BEGIN TODO: This just feels wrong, but it matches */ do{} while(0); } if ((t->flags & OS_SC_TYPE_MASK) != OS_SC_XBUS){} - /* END TODO */ } else { t->state &= ~OS_SC_NEEDS_RSP; __scTaskComplete(sc, t); @@ -371,30 +464,50 @@ void __scHandleRSP(OSSched *sc) { __scExec(sc, sp, dp); } -void __scHandleRDP(OSSched *sc) { +/* + * __scHandleRDP is called when an RDP task signals that it has + * finished + */ +void __scHandleRDP(OSSched *sc) +{ OSScTask *t, *sp = 0, *dp = 0; s32 state; + + assert(sc->curRDPTask); + assert(sc->curRDPTask->list.t.type == M_GFXTASK); t = sc->curRDPTask; sc->curRDPTask = 0; + +#ifdef SC_LOGGING + osLogEvent(l, 515, 3, t, t->state, t->flags); +#endif t->state &= ~OS_SC_NEEDS_RDP; __scTaskComplete(sc, t); state = ((sc->curRSPTask == 0) << 1) | (sc->curRDPTask == 0); - if ( (__scSchedule(sc, &sp, &dp, state)) != state) + if ( (__scSchedule (sc, &sp, &dp, state)) != state) __scExec(sc, sp, dp); } +/* + * __scTaskReady checks to see if the graphics task is able to run + * based on the current state of the RCP. + */ +OSScTask *__scTaskReady(OSScTask *t) +{ -OSScTask *__scTaskReady(OSScTask *t) { if (t) { /* * If there is a pending swap bail out til later (next * retrace). */ - if (osViGetCurrentFramebuffer() != osViGetNextFramebuffer()) { + if ((osViGetCurrentFramebuffer()) != (osViGetNextFramebuffer())) { +#ifdef SC_LOGGING + osLogEvent(l, 513, 2, a, b); +#endif return 0; } @@ -436,72 +549,122 @@ s32 __scTaskComplete(OSSched *sc, OSScTask *t) { return 0; } -void __scAppendList(OSSched *sc, OSScTask *t) { +/* + * Place task on either the audio or graphics queue + */ +void __scAppendList(OSSched *sc, OSScTask *t) +{ long type = t->list.t.type; - + + assert ( (type == M_AUDTASK) || (type == M_GFXTASK)); + if (type == M_AUDTASK) { - if(sc->audioListTail) + if (sc->audioListTail) sc->audioListTail->next = t; else sc->audioListHead = t; - + sc->audioListTail = t; +#ifdef SC_LOGGING + osLogEvent(l, 506, 1, t); +#endif } else { - if(sc->gfxListTail) + if (sc->gfxListTail) sc->gfxListTail->next = t; else sc->gfxListHead = t; - - sc->gfxListTail = t; + + sc->gfxListTail = t; +#ifdef SC_LOGGING + osLogEvent(l, 507, 1, t); +#endif } - + t->next = NULL; - t->state = t->flags & OS_SC_RCP_MASK; + t->state = t->flags & OS_SC_RCP_MASK; } -void __scExec(OSSched *sc, OSScTask *sp, OSScTask *dp) { +/* + * + */ +void __scExec(OSSched *sc, OSScTask *sp, OSScTask *dp) +{ + +#ifdef SC_LOGGING + osLogEvent(l, 511, 2, sp, dp); +#endif + + assert(sc->curRSPTask == 0); + if (sp) { if (sp->list.t.type == M_AUDTASK) { osWritebackDCacheAll(); /* flush the cache */ gRSPAudTaskFlushTime = osGetCount(); + } - + sp->state &= ~(OS_SC_YIELD | OS_SC_YIELDED); +#ifndef _FINALROM + sp->startTime = osGetTime(); +#endif osSpTaskLoad(&sp->list); - osSpTaskStartGo(&sp->list); + osSpTaskStartGo(&sp->list); gCurRSPTaskCounter = 0; gCurRDPTaskCounter = 0; sc->curRSPTask = sp; - if (sp == dp) sc->curRDPTask = dp; } if (dp && (dp != sp)) { - osDpSetNextBuffer(dp->list.t.output_buff, *dp->list.t.output_buff_size); + assert(dp->list.t.output_buff); + +#ifdef SC_LOGGING + osLogEvent(l, 523, 3, dp, dp->list.t.output_buff, + (u32)*dp->list.t.output_buff_size); +#endif + + osDpSetNextBuffer(dp->list.t.output_buff, + *dp->list.t.output_buff_size); + sc->curRDPTask = dp; } } -void __scYield(OSSched *sc) { +static void __scYield(OSSched *sc) +{ + +#ifdef SC_LOGGING + osLogEvent(l, 503, 1, sc->curRSPTask ); +#endif + if (sc->curRSPTask->list.t.type == M_GFXTASK) { + +/* assert(sc->curRSPTask->state & OS_SC_YIELD);*/ + sc->curRSPTask->state |= OS_SC_YIELD; gYieldTime = osGetTime(); + osSpTaskYield(); - } + } else { +#ifdef SC_LOGGING + osLogEvent(l, 508, 1, sc->curRSPTask); +#endif + } } /* * Schedules the tasks to be run on the RCP */ -static s32 __scSchedule(OSSched *sc, OSScTask **sp, OSScTask **dp, s32 availRCP) { +s32 __scSchedule(OSSched *sc, OSScTask **sp, OSScTask **dp, s32 availRCP) +{ s32 avail = availRCP; OSScTask *gfx = sc->gfxListHead; OSScTask *audio = sc->audioListHead; #ifdef SC_LOGGING osLogEvent(l, 517, 3, *sp, *dp, availRCP); -#endif +#endif if (sc->doAudio && (avail & OS_SC_SP)) { @@ -514,47 +677,47 @@ static s32 __scSchedule(OSSched *sc, OSScTask **sp, OSScTask **dp, s32 availRCP) sc->doAudio = 0; sc->audioListHead = sc->audioListHead->next; if (sc->audioListHead == NULL) - sc->audioListTail = NULL; - } - } else { + sc->audioListTail = NULL; + } + } else { #ifdef SC_LOGGING osLogEvent(l, 520, 1, gfx); -#endif - if (__scTaskReady(gfx)) { +#endif + if (__scTaskReady(gfx)) { #ifdef SC_LOGGING osLogEvent(l, 522, 3, gfx, gfx->state, gfx->flags); -#endif +#endif switch (gfx->flags & OS_SC_TYPE_MASK) { case (OS_SC_XBUS): if (gfx->state & OS_SC_YIELDED) { #ifdef SC_LOGGING osLogEvent(l, 518, 0); -#endif +#endif /* can hit this if RDP finishes at yield req */ /* assert(gfx->state & OS_SC_DP); */ if (avail & OS_SC_SP) { /* if SP is available */ #ifdef SC_LOGGING osLogEvent(l, 519, 0); -#endif +#endif *sp = gfx; avail &= ~OS_SC_SP; - + if (gfx->state & OS_SC_DP) { /* if it needs DP */ *dp = gfx; avail &= ~OS_SC_DP; - if ((avail & OS_SC_DP) == 0) + if (avail & OS_SC_DP == 0) assert(sc->curRDPTask == gfx); - + } sc->gfxListHead = sc->gfxListHead->next; if (sc->gfxListHead == NULL) sc->gfxListTail = NULL; - - } + + } } else { if (avail == (OS_SC_SP | OS_SC_DP)) { *sp = *dp = gfx; @@ -564,9 +727,9 @@ static s32 __scSchedule(OSSched *sc, OSScTask **sp, OSScTask **dp, s32 availRCP) sc->gfxListTail = NULL; } } - + break; - + case (OS_SC_DRAM): case (OS_SC_DP_DRAM): case (OS_SC_DP_XBUS): @@ -576,7 +739,6 @@ static s32 __scSchedule(OSSched *sc, OSScTask **sp, OSScTask **dp, s32 availRCP) avail &= ~OS_SC_SP; } } - //This is else if in libreultra, and it's the only difference if (gfx->state & OS_SC_DP) { /* if needs DP */ if (avail & OS_SC_DP) { /* if DP available */ *dp = gfx; @@ -600,4 +762,5 @@ static s32 __scSchedule(OSSched *sc, OSScTask **sp, OSScTask **dp, s32 availRCP) avail = __scSchedule(sc, sp, dp, avail); return avail; + } diff --git a/src/asset_loading.c b/src/asset_loading.c index 460f66e8..552a41c8 100644 --- a/src/asset_loading.c +++ b/src/asset_loading.c @@ -3,6 +3,7 @@ #include "asset_loading.h" +#include "common.h" // #include "assets.h" #include "macros.h" #include "ultra64.h" diff --git a/src/asset_loading.h b/src/asset_loading.h index 579b7179..c96b50c4 100644 --- a/src/asset_loading.h +++ b/src/asset_loading.h @@ -11,5 +11,6 @@ s32 load_asset_to_address(u32 assetIndex, u32 address, s32 assetOffset, s32 size u8 *get_rom_offset_of_asset(u32 assetIndex, u32 assetOffset); s32 get_size_of_asset_section(u32 assetIndex); void dmacopy(u32 romOffset, u32 ramAddress, s32 numBytes); +void dmacopy_v1(u32 romOffset, u32 ramAddress, s32 numBytes); #endif diff --git a/src/audio.c b/src/audio.c index 2c56fd4b..efef8137 100644 --- a/src/audio.c +++ b/src/audio.c @@ -12,7 +12,7 @@ #include "audiomgr.h" #include "audiosfx.h" #include "sched.h" -#include "lib/src/mips1/al/seqchannel.h" +#include "lib/src/audio/seqchannel.h" /************ .data ************/ diff --git a/src/audio_assert.c b/src/audio_assert.c deleted file mode 100644 index cb3b41a7..00000000 --- a/src/audio_assert.c +++ /dev/null @@ -1,13 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800B6F30 */ - -#include "audio_assert.h" - -// Only called from two libultra funcs for some reason. -// This is likely an assert gone wrong. -// Called from alEnvMixerPull, and _pullSubFrame -// assert_stub("samples >= 0", "env.c", 104); -// assert_stub("samples <= AL_MAX_RSP_SAMPLES", "env.c", 105); -// assert_stub("source", "env.c", 373); -void assert_stub(UNUSED char *message, UNUSED char *fileName, UNUSED s32 lineNumber) { -} diff --git a/src/audio_assert.h b/src/audio_assert.h deleted file mode 100644 index 289fd655..00000000 --- a/src/audio_assert.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _AUDIO_ASSERT_H_ -#define _AUDIO_ASSERT_H_ - -#include "types.h" -#include "libultra_internal.h" -#include "macros.h" - -void assert_stub(UNUSED char *message, UNUSED char *fileName, UNUSED s32 lineNumber); - -#endif diff --git a/src/audio_spatial.c b/src/audio_spatial.c index 026c32f4..b07b7eb6 100644 --- a/src/audio_spatial.c +++ b/src/audio_spatial.c @@ -151,12 +151,12 @@ s32 func_800090C0(f32 arg0, f32 arg1, s32 arg2) { if (temp_v1 < arg2) { if (sp1C <= 1.0f) { - ret = 64 - ((sins(arg2 - temp_v1) / 1024) * (sp1C * 1)); + ret = 64 - ((sins_s16(arg2 - temp_v1) / 1024) * (sp1C * 1)); } else { ret = 64 - (sins_2(arg2 - temp_v1) / 1024); } } else if (sp1C <= 1.0f) { - ret = (sins(temp_v1 - arg2) / 1024) * (sp1C * 1) + 64; + ret = (sins_s16(temp_v1 - arg2) / 1024) * (sp1C * 1) + 64; } else { ret = (sins_2(temp_v1 - arg2) / 1024) + 64; } diff --git a/src/audio_vehicle.c b/src/audio_vehicle.c index e3cb3076..c250f3df 100644 --- a/src/audio_vehicle.c +++ b/src/audio_vehicle.c @@ -8,7 +8,7 @@ #include "audio_spatial.h" #include "audiosfx.h" #include "objects.h" -#include "controller.h" +#include "joypad.h" #include "racer.h" #include "PR/libaudio.h" #include "game_ui.h" diff --git a/src/audiomgr.h b/src/audiomgr.h index 9fefe24c..2c49a652 100644 --- a/src/audiomgr.h +++ b/src/audiomgr.h @@ -5,7 +5,7 @@ #include "macros.h" #include "audio_internal.h" #include "asset_enums.h" -#include "libultra_internal.h" +#include #include "sched.h" #define MAX_UPDATES 32 @@ -49,8 +49,6 @@ extern void alInit(ALGlobals *g, ALSynConfig *c); extern s8 rspF3DDKRBootStart[]; extern s8 rspF3DDKRDramStart[]; -extern s8 aspMainDataStart[]; -extern s8 aspMainTextStart[]; void audioStartThread(void); void audioStopThread(void); diff --git a/src/audiosfx.h b/src/audiosfx.h index 97f5f916..edfc251d 100644 --- a/src/audiosfx.h +++ b/src/audiosfx.h @@ -5,7 +5,7 @@ #include "macros.h" #include "audio_internal.h" #include "asset_enums.h" -#include "libultra_internal.h" +#include #include "sched.h" #include "structs.h" diff --git a/src/camera.c b/src/camera.c index a1cf2507..88e519eb 100644 --- a/src/camera.c +++ b/src/camera.c @@ -10,8 +10,8 @@ #include "lib/src/libc/rmonPrintf.h" #include "math_util.h" #include "weather.h" -#include "lib/src/os/piint.h" -#include "include/viint.h" +#include "PRinternal/piint.h" +#include "PRinternal/viint.h" /************ .rodata ************/ @@ -1058,7 +1058,7 @@ s32 render_sprite_billboard(Gfx **dlist, MatrixS **mtx, Vertex **vertexList, Obj sp44 = (diffX * cosY) + (diffZ * sineY); diffZ = (diffZ * cosY) - (diffX * sineY); tanY = arctan2_f(sp44, sqrtf((diffY * diffY) + (diffZ * diffZ))); - tanX = -sins(arctan2_f(sp44, diffZ)) >> 8; + tanX = -sins_s16(arctan2_f(sp44, diffZ)) >> 8; if (diffZ < 0.0f) { diffZ = -diffZ; tanX = 1 - tanX; diff --git a/src/camera.h b/src/camera.h index c61bd8c8..48d9b0f7 100644 --- a/src/camera.h +++ b/src/camera.h @@ -6,7 +6,7 @@ #include "structs.h" #include "f3ddkr.h" #include "menu.h" -#include "libultra_internal.h" +#include #include "libc/math.h" #define SCREEN_WIDTH 320 diff --git a/src/fade_transition.c b/src/fade_transition.c index bf7f704d..e226e363 100644 --- a/src/fade_transition.c +++ b/src/fade_transition.c @@ -8,10 +8,10 @@ #include "f3ddkr.h" #include "asset_enums.h" #include "memory.h" -#include "PR/libultra.h" #include "video.h" #include "textures_sprites.h" #include "math_util.h" +#include "PRinternal/viint.h" /************ .data ************/ diff --git a/src/font.h b/src/font.h index f72d0bb8..b687014a 100644 --- a/src/font.h +++ b/src/font.h @@ -3,14 +3,13 @@ #include "memory.h" #include "video.h" -#include "stacks.h" #include "asset_loading.h" #include "structs.h" #include "types.h" #include "macros.h" #include "asset_enums.h" -#include "libultra_internal.h" +#include #include "f3ddkr.h" #include "textures_sprites.h" @@ -147,6 +146,12 @@ typedef struct DialogueBoxBackground { DialogueBox *textBox; } DialogueBoxBackground; +typedef struct Asset46 { + s32 unk0; + s32 unk4; + u8 unk8; +} Asset46; + #define DIALOGUEBOXBACKGROUND_COUNT 8 #define DIALOGUETEXTELEMENT_COUNT 64 #define DIALOGUEBOXBACKGROUND_TOTAL_SIZE (sizeof(DialogueBoxBackground) * DIALOGUEBOXBACKGROUND_COUNT) @@ -182,4 +187,16 @@ void render_text_string(Gfx **dList, DialogueBoxBackground *box, char *text, Ali s32 get_text_width(char *text, s32 x, s32 font); void *render_dialogue_text(s32 dialogueBoxID, s32 posX, s32 posY, char *text, s32 number, s32 flags); +// Japanese Region exclusives +void func_800C6464_C7064(void); +void func_800C663C_C723C(void); +void func_800C6870_C7470(void); +void func_800C67F4_C73F4(void); +s32 func_800C68CC_C74CC(u16 arg0); +void func_800C6DD4_C79D4(Gfx *dlist, Asset46 *asset, s32 width, s32 height); +s32 func_800C7744_C8344(Gfx **dlist, u16 charIndex, s32 *outLeft, s32 *outTop, s32 *outRight, s32 *outBottom); +void func_800C7804_C8404(s32 arg0); +void func_800C7864_C8464(char *inString, char *outString); +void func_800C78E0_C84E0(void); + #endif diff --git a/src/game.c b/src/game.c index 4402cb5c..92dc7ecd 100644 --- a/src/game.c +++ b/src/game.c @@ -25,7 +25,7 @@ #include "objects.h" #include "camera.h" #include "save_data.h" -#include "rcp.h" +#include "rcp_dkr.h" #include "audiosfx.h" #include "audiomgr.h" #include "lights.h" @@ -43,7 +43,7 @@ #include "racer.h" #include "particles.h" #include "math_util.h" -#include "controller.h" +#include "joypad.h" #include "common.h" /************ .data ************/ diff --git a/src/game_text.c b/src/game_text.c index 100bfcb4..858e4c27 100644 --- a/src/game_text.c +++ b/src/game_text.c @@ -7,7 +7,8 @@ #include "objects.h" #include "racer.h" #include "game.h" -#include "controller.h" +#include "joypad.h" +#include "PRinternal/viint.h" /************ .data ************/ diff --git a/src/game_text.h b/src/game_text.h index 41c7825f..fb9038cf 100644 --- a/src/game_text.h +++ b/src/game_text.h @@ -7,7 +7,6 @@ #include "asset_enums.h" #include "memory.h" #include "font.h" -#include "PR/libultra.h" #define SET_TEXTBOX_BOUNDARY(leftVal, topVal, rightVal, bottomVal) \ textBox.left = leftVal; \ diff --git a/src/game_ui.c b/src/game_ui.c index a3471791..5f3736bd 100644 --- a/src/game_ui.c +++ b/src/game_ui.c @@ -17,11 +17,12 @@ #include "game_text.h" #include "object_models.h" #include "tracks.h" -#include "rcp.h" +#include "rcp_dkr.h" #include "audiosfx.h" #include "printf.h" #include "audio_spatial.h" -#include "controller.h" +#include "joypad.h" +#include "PRinternal/viint.h" /************ .data ************/ diff --git a/src/game_ui.h b/src/game_ui.h index 8ac2590c..e6a79c42 100644 --- a/src/game_ui.h +++ b/src/game_ui.h @@ -3,7 +3,7 @@ #include "types.h" #include "structs.h" -#include "libultra_internal.h" +#include #define HUD_ELEMENT_MODEL 0x0000 #define HUD_ELEMENT_OBJECT 0x4000 diff --git a/src/controller.c b/src/joypad.c similarity index 99% rename from src/controller.c rename to src/joypad.c index 4129e25c..57fb5d52 100644 --- a/src/controller.c +++ b/src/joypad.c @@ -1,7 +1,7 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x8006A100 */ -#include "controller.h" +#include "joypad.h" #include "game.h" s32 sNoControllerPluggedIn = diff --git a/src/controller.h b/src/joypad.h similarity index 90% rename from src/controller.h rename to src/joypad.h index 8af275d9..efa1500b 100644 --- a/src/controller.h +++ b/src/joypad.h @@ -1,10 +1,10 @@ -#ifndef _CONTROLLER_H_ -#define _CONTROLLER_H_ +#ifndef _JOYPAD_H_ +#define _JOYPAD_H_ #include "types.h" #include "macros.h" #include "structs.h" -#include "libultra_internal.h" +#include #define CONTROLLER_MISSING -1 #define CONTROLLER_EXISTS 0 diff --git a/src/main.h b/src/main.h index b0c0edf7..29157ce6 100644 --- a/src/main.h +++ b/src/main.h @@ -3,7 +3,7 @@ #include "types.h" #include "macros.h" -#include "libultra_internal.h" +#include void main(void); void thread1_main(void *); diff --git a/src/math_util.c b/src/math_util.c index 8611dff9..dd2bdb51 100644 --- a/src/math_util.c +++ b/src/math_util.c @@ -9,6 +9,7 @@ #include "structs.h" #include "game.h" #include "string.h" +#include "PR/os_internal_reg.h" extern s32 gIntDisFlag; extern s32 gCurrentRNGSeed; // Official Name: rngSeed @@ -279,12 +280,12 @@ void object_transform_to_matrix(Matrix mtx, ObjectTransform *trans) { f32 zRotCosine; f32 scale; - yRotSine = sins(trans->y_rotation) * 0.000015f; - yRotCosine = coss(trans->y_rotation) * 0.000015f; - xRotSine = sins(trans->x_rotation) * 0.000015f; - xRotCosine = coss(trans->x_rotation) * 0.000015f; - zRotSine = sins(trans->z_rotation) * 0.000015f; - zRotCosine = coss(trans->z_rotation) * 0.000015f; + yRotSine = sins_s16(trans->y_rotation) * 0.000015f; + yRotCosine = coss_s16(trans->y_rotation) * 0.000015f; + xRotSine = sins_s16(trans->x_rotation) * 0.000015f; + xRotCosine = coss_s16(trans->x_rotation) * 0.000015f; + zRotSine = sins_s16(trans->z_rotation) * 0.000015f; + zRotCosine = coss_s16(trans->z_rotation) * 0.000015f; scale = trans->scale * 0.000015f; mtx[0][0] = ((xRotSine * yRotSine * zRotSine) + (scale * yRotCosine)) * scale; @@ -340,12 +341,12 @@ void object_transform_to_matrix_2(Matrix mtx, ObjectTransform *trans) { f32 zRotCosine; f32 scale; - yRotCosine = coss(trans->y_rotation) * 0.000015f; - yRotSine = sins(trans->y_rotation) * 0.000015f; - xRotCosine = coss(trans->x_rotation) * 0.000015f; - xRotSine = sins(trans->x_rotation) * 0.000015f; - zRotCosine = coss(trans->z_rotation) * 0.000015f; - zRotSine = sins(trans->z_rotation) * 0.000015f; + yRotCosine = coss_s16(trans->y_rotation) * 0.000015f; + yRotSine = sins_s16(trans->y_rotation) * 0.000015f; + xRotCosine = coss_s16(trans->x_rotation) * 0.000015f; + xRotSine = sins_s16(trans->x_rotation) * 0.000015f; + zRotCosine = coss_s16(trans->z_rotation) * 0.000015f; + zRotSine = sins_s16(trans->z_rotation) * 0.000015f; scale = trans->scale * 0.000015f; @@ -376,8 +377,8 @@ GLOBAL_ASM("asm/math_util/func_80070058.s") void f32_matrix_from_rotation_and_scale(Matrix mtx, s32 angle, f32 arg2, f32 arg3) { f32 cosine, sine; - cosine = sins(angle) * 0.000015f; - sine = coss(angle) * 0.000015f; + cosine = sins_s16(angle) * 0.000015f; + sine = coss_s16(angle) * 0.000015f; mtx[0][0] = sine * arg2; mtx[0][1] = cosine * arg2; mtx[0][2] = 0; @@ -411,12 +412,12 @@ void s16_vec3_apply_object_rotation(ObjectTransform *trans, s16 *vec3Arg) { s32 temp_t4; s32 temp_t5; - yRotCosine = coss(trans->y_rotation); - yRotSine = sins(trans->y_rotation); - xRotCosine = coss(trans->x_rotation); - xRotSine = sins(trans->x_rotation); - zRotCosine = coss(trans->z_rotation); - zRotSine = sins(trans->z_rotation); + yRotCosine = coss_s16(trans->y_rotation); + yRotSine = sins_s16(trans->y_rotation); + xRotCosine = coss_s16(trans->x_rotation); + xRotSine = sins_s16(trans->x_rotation); + zRotCosine = coss_s16(trans->z_rotation); + zRotSine = sins_s16(trans->z_rotation); temp_t3 = ((vec3Arg[0] * yRotSine) - (vec3Arg[1] * yRotCosine)) >> 16; temp_t4 = ((vec3Arg[1] * yRotSine) + (vec3Arg[0] * yRotCosine)) >> 16; diff --git a/src/math_util.h b/src/math_util.h index 55c52a87..4c02632c 100644 --- a/src/math_util.h +++ b/src/math_util.h @@ -29,8 +29,8 @@ s16 arctan2_f(f32 y, f32 x); #endif f32 coss_f(s16 angle); f32 sins_f(s16 angle); -s32 coss(s16 angle); -s32 sins(s16 angle); +s32 coss_s16(s16 angle); +s32 sins_s16(s16 angle); s32 sins_2(s16 angle); void set_rng_seed(s32 num); void save_rng_seed(void); @@ -60,7 +60,18 @@ s32 atan2s(s32 xDelta, s32 zDelta); f32 area_triangle_2d(f32 x0, f32 z0, f32 x1, f32 z1, f32 x2, f32 z2); void dmacopy_doubleword(void *src, void *dst, s32 end); StackInfo *stack_pointer(void); +/** + * Zero out the interrupt mask. This stops this thread + * from being interrupted by others, letting you safely + * work with delicate areas in memory. Kind of like a mutex. + * Returns what the interrupt mask wask before. + * Official Name: disableInterrupts */ u32 interrupts_disable(void); +/** + * Set the interrupt mask to whichever flags were given. + * Required after zeroing them out, otherwise system + * operation won't work as normal. + * Official Name: enableInterrupts */ void interrupts_enable(u32 flags); #endif // MATH_UTIL_H diff --git a/src/memory.c b/src/memory.c index 7f57a37e..e7314904 100644 --- a/src/memory.c +++ b/src/memory.c @@ -4,7 +4,7 @@ #include "memory.h" #include "printf.h" #include "thread0_epc.h" -#include "controller.h" +#include "joypad.h" #include "math_util.h" /************ .bss ************/ diff --git a/src/memory.h b/src/memory.h index 850a1c4a..5d163a4d 100644 --- a/src/memory.h +++ b/src/memory.h @@ -88,6 +88,11 @@ typedef struct StackInfo { u32 sp; } StackInfo; +// This variable doesn't truly exist in memory. +// It's just defined as the end of BSS, and it's +// symbol needs to be in the undefined syms place. +extern MemoryPoolSlot gMainMemoryPool; + void mempool_init_main(void); MemoryPoolSlot *mempool_new_sub(s32 poolDataSize, s32 numSlots); void *mempool_alloc_safe(s32 size, u32 colourTag); diff --git a/src/memory_pool.c b/src/memory_pool.c new file mode 100644 index 00000000..1309ffd0 --- /dev/null +++ b/src/memory_pool.c @@ -0,0 +1,6 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x8012D3F0 */ + +// This is the end of BSS +#include "src/memory.h" +MemoryPoolSlot gMainMemoryPool; diff --git a/src/menu.c b/src/menu.c index c31ed50d..61db7073 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1,10 +1,10 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x8007F900 */ +#include "common.h" #include "menu.h" #include "memory.h" #include "fade_transition.h" - #include #include "asset_enums.h" #include "types.h" @@ -22,15 +22,16 @@ #include "thread30_track_loading.h" #include "objects.h" #include "game.h" -#include "rcp.h" +#include "rcp_dkr.h" #include "save_data.h" #include "object_functions.h" #include "audiosfx.h" #include "racer.h" #include "tracks.h" -#include "lib/src/mips1/al/alSynStartVoiceParams.h" -#include "controller.h" +#include "lib/src/audio/synstartvoiceparam.h" +#include "joypad.h" #include "math_util.h" +#include "PRinternal/viint.h" /** * @file Contains all the code used for every menu in the game. @@ -2510,7 +2511,7 @@ void menu_missing_controller(Gfx **dList, s32 updateRate) { set_text_colour(255, 255, 255, 0, 0xFF); set_text_background_colour(0, 0, 0, 0); posY = 208; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { posY = 234; } draw_text(dList, POS_CENTRED, posY, gMenuText[ASSET_MENU_TEXT_CONTROLLERNOTCONNECTED], ALIGN_MIDDLE_CENTER); @@ -2525,7 +2526,7 @@ void menu_logos_screen_init(void) { gMenuDelay = 0; sBootScreenTimer = 16.0f; bgdraw_fillcolour(0, 0, 0); - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { viewport_menu_set(0, 0, 38, SCREEN_WIDTH, SCREEN_HEIGHT - 16); set_viewport_properties(0, VIEWPORT_AUTO, VIEWPORT_AUTO, SCREEN_WIDTH, SCREEN_HEIGHT_PAL); } else { @@ -2544,7 +2545,7 @@ s32 menu_logo_screen_loop(s32 updateRate) { s32 yOffset; s32 yOffsetShadow; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { yOffset = 26; if (sBootScreenTimer < 2.6f && gMenuDelay == 0) { transition_begin(&gFadeLogoToTitleScreen); @@ -2786,7 +2787,7 @@ void render_title_screen(UNUSED s32 updateRate, f32 updateRateF) { } if (!is_controller_missing()) { i = 0; - posY = (osTvType == TV_TYPE_PAL) ? SCREEN_HEIGHT - 22 : SCREEN_HEIGHT - 48; + posY = (osTvType == OS_TV_TYPE_PAL) ? SCREEN_HEIGHT - 22 : SCREEN_HEIGHT - 48; set_text_font(ASSET_FONTS_FUNFONT); set_text_background_colour(0, 0, 0, 0); while (gTitleMenuStrings[i] != NULL) { @@ -2825,7 +2826,7 @@ s32 menu_title_screen_loop(s32 updateRate) { sp18 = get_active_camera_segment(); gOptionBlinkTimer = (gOptionBlinkTimer + updateRate) & 0x3F; menu_input(); - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { updateRateF = (f32) updateRate / 50.0f; } else { updateRateF = (f32) updateRate / 60.0f; @@ -3506,12 +3507,12 @@ void savemenu_render_element(SaveFileData *file, s32 x, s32 y) { break; } func_80080580(&sMenuCurrDisplayList, x - 160, 120 - y, 160, 64, 4, 4, colour, texture); - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { y += 12; } if (file->saveFileType == SAVE_FILE_TYPE_CPAK_SAVE || (file->saveFileType == SAVE_FILE_TYPE_CART_SAVE && gSavefileData[file->controllerIndex]->newGame == FALSE)) { - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { i = 134; } else { i = 120; @@ -3615,7 +3616,7 @@ void savemenu_render(UNUSED s32 updateRate) { ALIGN_MIDDLE_CENTER); if (drawLowerElements) { - temp = (osTvType == TV_TYPE_PAL) ? SCREEN_HEIGHT_HALF_PAL : SCREEN_HEIGHT_HALF; + temp = (osTvType == OS_TV_TYPE_PAL) ? SCREEN_HEIGHT_HALF_PAL : SCREEN_HEIGHT_HALF; temp += ((s32) (gOptionBlinkTimer & 0x1F) >> 1); for (scroll = 0; scroll < 2; scroll += 1, temp += 16) { @@ -4672,7 +4673,7 @@ s32 menu_boot_loop(s32 updateRate) { out = MENU_RESULT_CONTINUE; offsetY = SCREEN_HEIGHT_HALF; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { offsetY = SCREEN_HEIGHT_HALF_PAL; } @@ -4764,7 +4765,7 @@ void bootscreen_init_cpak(void) { gOpacityDecayTimer = 0; menu_asset_load(63); menu_init_arrow_textures(); - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { sControllerPakMenuNumberOfRows = 8; } else { sControllerPakMenuNumberOfRows = 7; @@ -4876,7 +4877,7 @@ void pakmenu_render(UNUSED s32 updateRate) { ALIGN_TOP_CENTER); // EXIT } if (gMenuStage != PAKMENU_CHOOSE && gCpakWriteTimer == 0) { - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { yPos = 134; } else { yPos = SCREEN_HEIGHT_HALF; @@ -5182,7 +5183,7 @@ void cheatmenu_render(UNUSED s32 updateRate) { i = 0; offsetY = 164; yPos = 16; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { yPos = 24; } @@ -5216,7 +5217,7 @@ void cheatmenu_render(UNUSED s32 updateRate) { ALIGN_MIDDLE_CENTER); //"All cheats have been deleted" } if (gMenuStage != CHEATMENU_CHOOSE) { - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { offsetY = SCREEN_HEIGHT_HALF + 14; } else { offsetY = SCREEN_HEIGHT_HALF; @@ -5527,7 +5528,7 @@ void menu_magic_codes_list_init(void) { menu_asset_load(63); menu_init_arrow_textures(); transition_begin(&sMenuTransitionFadeOut); - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { gNumOnscreenMagicCodes = 11; } else { gNumOnscreenMagicCodes = 10; @@ -5915,7 +5916,7 @@ void charselect_render_text(UNUSED s32 arg0) { ALIGN_MIDDLE_CENTER); if (gNumberOfReadyPlayers == gNumberOfActivePlayers && gNumberOfActivePlayers > 0) { yPos = 208; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { yPos = 234; } draw_text(&sMenuCurrDisplayList, SCREEN_WIDTH_HALF, yPos, "OK?", ALIGN_MIDDLE_CENTER); @@ -6440,7 +6441,7 @@ void gameselect_render(UNUSED s32 updateRate) { gGameSelectElements[((i ^ 0) * 2) + 3].filterBlendFactor = filterBlendFactor; } - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { gPostraceTextOffset = 12; gPostraceTimestampOffset = 0; } else { @@ -6633,7 +6634,7 @@ void fileselect_render(UNUSED s32 updateRate) { UNUSED s32 pad[3]; char trimmedFilename[4]; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { yPos = 12; } else { yPos = 0; @@ -7120,7 +7121,7 @@ s32 menu_file_select_loop(s32 updateRate) { gFileNew = TRUE; gIndexOfCurInputCharacter = 0; i = 0; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { i = 12; } filename_init(i + 187, gFileSelectButtons[gSaveFileIndex].x + gFileSelectElementPos[0], @@ -7728,7 +7729,7 @@ void trackmenu_render_2D(s32 x, s32 y, char *hubName, char *trackName, s32 rectO sp6C = 0; xTemp = x + 160; yTemp = gTrackSelectViewPortHalfY - y; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { sp6C = 12; } set_text_font(ASSET_FONTS_BIGFONT); @@ -7760,7 +7761,7 @@ void trackmenu_render_2D(s32 x, s32 y, char *hubName, char *trackName, s32 rectO (((gTrackSelectViewportY >> 2) + yTemp) > 0)) { sp58 = 1.25f; sp54 = 1.25f; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { sp54 *= 1.1; } temp = xTemp - 80; @@ -7786,7 +7787,7 @@ void trackmenu_render_2D(s32 x, s32 y, char *hubName, char *trackName, s32 rectO } gMenuImages[imageId].x = x; gMenuImages[imageId].y = y; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { gTrackSelectWoodFrameHeightScale = 1.2f; offsets = gTracksMenuArrowPositionsPAL; } else { @@ -8132,7 +8133,7 @@ void trackmenu_setup_render(UNUSED s32 updateRate) { filename.word = 0; // Set all 4 bytes as '\0'? sp74 = FALSE; settings = get_settings(); - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { regionOffset = 12; } if (gNumberOfActivePlayers == 2 && gTrackSelectCursorX < 4 && gMenuStage > TRACKMENU_CHOOSE) { @@ -8151,7 +8152,7 @@ void trackmenu_setup_render(UNUSED s32 updateRate) { } gMenuImages[sp84].x = 0.0f; gMenuImages[sp84].y = 0.0f; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { gTrackSelectWoodFrameHeightScale = 1.2f; } menu_element_render(sp84); @@ -8538,7 +8539,7 @@ void adventuretrack_render(UNUSED s32 updateRate, s32 arg1, s32 arg2) { filename = NULL; settings = get_settings(); yOffset = 0; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { yOffset = 12; } mapID = ((Settings4C *) ((u8 *) settings->unk4C + gTrackIdForPreview))->mapID; @@ -8852,7 +8853,7 @@ void pausemenu_render(UNUSED s32 updateRate) { } } temp = (gMenuOptionCap * 16) + 28; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { y = SCREEN_HEIGHT_HALF_PAL; } else { y = SCREEN_HEIGHT_HALF; @@ -9352,7 +9353,7 @@ void func_80094D28(UNUSED s32 updateRate) { } viewportULY = ((temp * viewportLRY) + 1) >> 1; temp = 192; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { temp = 218; } set_current_dialogue_box_coords(7, 0, temp - viewportULY - viewportULX - 4, SCREEN_WIDTH, @@ -9402,7 +9403,7 @@ void func_80094D28(UNUSED s32 updateRate) { if (get_game_mode() == GAMEMODE_INGAME && gNumberOfActivePlayers == 1) { if (gTrophyRaceWorldId == 0) { camEnableUserView(0, TRUE); - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { gTrackSelectWoodFrameHeightScale = 1.2f; } if (gMenuStage > 0) { @@ -9481,7 +9482,7 @@ s32 menu_postrace(Gfx **dList, MatrixS **matrices, Vertex **vertices, s32 update sMenuCurrHudMat = *matrices; sMenuCurrHudVerts = *vertices; settings = get_settings(); - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { textOffsetY = 26; timeOffsetY = 12; } else { @@ -9868,7 +9869,7 @@ void results_render(UNUSED s32 updateRate, f32 opacity) { settings = get_settings(); offsetY = 0; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { offsetY = 12; } set_ortho_matrix_view(&sMenuCurrDisplayList, &sMenuCurrHudMat); @@ -10553,7 +10554,7 @@ void trophyround_render(UNUSED s32 updateRate) { s8 *levelIds; levelIds = (s8 *) get_misc_asset(ASSET_MISC_TRACKS_MENU_IDS); - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { yPos = 18; } else { yPos = 0; @@ -10650,7 +10651,7 @@ void func_80098774(s32 isRankings) { racerIndex = (gRankingPlayerCount - 1); racerIndex <<= 1; yOffset = 240; - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { racerIndex += 16; yOffset = 264; } @@ -11172,7 +11173,7 @@ void ghostmenu_render(UNUSED s32 updateRate) { char textBuffer[64]; set_ortho_matrix_view(&sMenuCurrDisplayList, &sMenuCurrHudMat); - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { heightAdjust = 12; } else { heightAdjust = 0; @@ -11537,7 +11538,7 @@ void menu_credits_init(void) { D_80126BD8 = 0; D_80126BE0 = 0; bgdraw_fillcolour(0, 0, 0); - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { viewport_menu_set(0, 0, 38, SCREEN_WIDTH, 224); set_viewport_properties(0, VIEWPORT_AUTO, VIEWPORT_AUTO, SCREEN_WIDTH, SCREEN_HEIGHT_PAL); } else { @@ -11657,7 +11658,7 @@ s32 menu_credits_loop(s32 updateRate) { transition_begin(NULL); enable_new_screen_transitions(); } - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { credits_fade(0, 38, SCREEN_WIDTH, 186, gOpacityDecayTimer * 8); } else { credits_fade(0, 40, SCREEN_WIDTH, 156, gOpacityDecayTimer * 8); @@ -11673,8 +11674,8 @@ s32 menu_credits_loop(s32 updateRate) { temp_s4 = (var_s4 * 5) + 72; temp_s2 = (fb_size() >> 17) & 0x7FFF; // Truncated video height? Height / 2? for (i = 0; i < ARRAY_COUNT(gRacerPortraits); i++) { - texrect_draw(&sMenuCurrDisplayList, gRacerPortraits[i], ((sins(var_s5) * temp_s4) >> 16) + 140, - ((coss(var_s5) * temp_s4) >> 16) + (temp_s2 - 20), 255, 255, 255, 255); + texrect_draw(&sMenuCurrDisplayList, gRacerPortraits[i], ((sins_s16(var_s5) * temp_s4) >> 16) + 140, + ((coss_s16(var_s5) * temp_s4) >> 16) + (temp_s2 - 20), 255, 255, 255, 255); var_s5 += 0x1999; } reset_render_settings(&sMenuCurrDisplayList); @@ -11699,7 +11700,7 @@ s32 menu_credits_loop(s32 updateRate) { while ((gCreditsControlData[D_80126BC4] & 0xF000) == CREDITS_NO_FLAG) { D_80126BC4++; } - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { textPos = SCREEN_HEIGHT_HALF + 14; } else { textPos = SCREEN_HEIGHT_HALF; @@ -13072,7 +13073,7 @@ void dialogue_tt_gamestatus(void) { } settings = get_settings(); sprite_anim_off(TRUE); - if (osTvType == TV_TYPE_PAL) { + if (osTvType == OS_TV_TYPE_PAL) { y = 10; } else { y = 20; diff --git a/src/menu.h b/src/menu.h index 01d13061..bde9ce02 100644 --- a/src/menu.h +++ b/src/menu.h @@ -686,6 +686,9 @@ void func_80084854(void); void func_80098774(s32); void func_80094D28(UNUSED s32 updateRate); +void func_80082BC8_837C8(s32 dialogueBoxID, s32 xPos1, s32 yPos1, s32 xPos2, + s32 yPos2, char *text, AlignmentFlags alignment, s32 textColour, s32 alpha); + typedef enum MenuTextures { /* 0x00 */ TEXTURE_UNK_00, /* 0x01 */ TEXTURE_UNK_01, diff --git a/src/object_functions.c b/src/object_functions.c index 9e9a599e..1669e7d9 100644 --- a/src/object_functions.c +++ b/src/object_functions.c @@ -30,8 +30,9 @@ #include "object_models.h" #include "lib/src/libc/rmonPrintf.h" #include "collision.h" -#include "controller.h" +#include "joypad.h" #include "printf.h" +#include "PRinternal/viint.h" #include "common.h" /************ .data ************/ @@ -1603,7 +1604,7 @@ void obj_loop_fish(Object *fishObj, s32 updateRate) { } fish->unkFC = 1 - fish->unkFC; verts = &fish->vertices[fish->unkFC * 6]; - randNumber = sins(fish->unk106) >> 3; + randNumber = sins_s16(fish->unk106) >> 3; temp_s0_2 = (s32) (coss_f(randNumber) * 32); temp_t1 = (s32) (sins_f(randNumber) * 32); verts[4].x = (verts[2].x + temp_t1); @@ -6094,8 +6095,8 @@ void obj_loop_butterfly(Object *butterflyObj, s32 updateRate) { butterfly->unkFC = 1 - butterfly->unkFC; vertices = &butterfly->vertices[butterfly->unkFC * 6]; var_v1 = sp64 == 0 ? 7 : 8; - xPos = sins((butterflyObj->segment.animFrame << var_v1)) >> 10; - yPos = coss((butterflyObj->segment.animFrame << var_v1)) >> 10; + xPos = sins_s16((butterflyObj->segment.animFrame << var_v1)) >> 10; + yPos = coss_s16((butterflyObj->segment.animFrame << var_v1)) >> 10; if (xPos < 0) { xPos = -xPos; } diff --git a/src/objects.c b/src/objects.c index cb17d6a2..42ea4a5e 100644 --- a/src/objects.c +++ b/src/objects.c @@ -25,11 +25,12 @@ #include "lights.h" #include "game_ui.h" #include "audio_spatial.h" -#include "controller.h" +#include "joypad.h" #include "game_text.h" #include "audiosfx.h" #include "audio_vehicle.h" #include "vehicle_misc.h" +#include "PRinternal/viint.h" #define MAX_CHECKPOINTS 60 #define OBJECT_POOL_SIZE 0x15800 diff --git a/src/objects.h b/src/objects.h index 5c3eb580..ca6b7420 100644 --- a/src/objects.h +++ b/src/objects.h @@ -184,7 +184,7 @@ enum ObjectSpawnFlags { enum ContPakErrors { CONTPAK_ERROR_MISSING = -1, CONTPAK_ERROR_NONE, - CONTPAK_ERROR_UNKNOWN, + CONTPAK_ERROR_UNKNOWN, //Time trial ghost has reached its size limit? CONTPAK_ERROR_FULL, CONTPAK_ERROR_DAMAGED }; @@ -532,7 +532,7 @@ void func_80010994(s32 updateRate); void func_800159C8(Object *, Object *); void func_80011264(ObjectModel *, Object *); void func_800245F0(ObjectModel *, Object *, f32); //asm func in unknown_0251F0 -s32 object_animate(Object *obj); //asm func in unknown_062930 +s32 object_animate(Object *obj); s32 func_80014B50(s32 arg0, s32 arg1, f32 arg2, u32 arg3); s16 func_8001CD28(s32 arg0, s32 arg1, s32 arg2, s32 arg3); // NON MATCHING diff --git a/src/particles.h b/src/particles.h index ed1c7eeb..f233ba5f 100644 --- a/src/particles.h +++ b/src/particles.h @@ -3,7 +3,7 @@ #include "types.h" #include "structs.h" -#include "libultra_internal.h" +#include enum ObjectEmitterFlags { OBJ_EMIT_OFF, diff --git a/src/printf.c b/src/printf.c index 0a005c59..8711d2a9 100644 --- a/src/printf.c +++ b/src/printf.c @@ -8,7 +8,7 @@ #include "thread0_epc.h" #include "stdarg.h" #include "textures_sprites.h" -#include "rcp.h" +#include "rcp_dkr.h" /************ .data ************/ diff --git a/src/racer.c b/src/racer.c index 321e8ff0..c6f23775 100644 --- a/src/racer.c +++ b/src/racer.c @@ -26,8 +26,9 @@ #include "object_models.h" #include "audiosfx.h" #include "collision.h" -#include "controller.h" +#include "joypad.h" #include "particles.h" +#include "PRinternal/viint.h" #include "common.h" #define MAX_NUMBER_OF_GHOST_NODES 360 diff --git a/src/rcp.c b/src/rcp_dkr.c similarity index 99% rename from src/rcp.c rename to src/rcp_dkr.c index dae4cc7a..be77daa7 100644 --- a/src/rcp.c +++ b/src/rcp_dkr.c @@ -1,7 +1,7 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x80077450 */ -#include "rcp.h" +#include "rcp_dkr.h" #include "types.h" #include "structs.h" #include "macros.h" diff --git a/src/rcp.h b/src/rcp_dkr.h similarity index 96% rename from src/rcp.h rename to src/rcp_dkr.h index 5046bf48..a06cb7fc 100644 --- a/src/rcp.h +++ b/src/rcp_dkr.h @@ -1,11 +1,11 @@ -#ifndef _UNKNOWN_078050_H_ -#define _UNKNOWN_078050_H_ +#ifndef _RCP_DKR_H_ +#define _RCP_DKR_H_ #include "types.h" #include "structs.h" #include "f3ddkr.h" #include "sched.h" -#include "libultra_internal.h" +#include #include "game_ui.h" #include "video.h" diff --git a/src/save_data.c b/src/save_data.c index e47ce637..96f03122 100644 --- a/src/save_data.c +++ b/src/save_data.c @@ -4,7 +4,7 @@ #include "save_data.h" #include "common.h" #include "memory.h" -#include "PR/pfs.h" +#include "PR/os_pfs.h" #include "PR/os_cont.h" #include "macros.h" #include "structs.h" @@ -12,7 +12,9 @@ #include "objects.h" #include "game.h" #include "thread3_main.h" -#include "controller.h" +#include "joypad.h" +#include "PRinternal/viint.h" +#include "PR/os_motor.h" /************ .data ************/ diff --git a/src/save_data.h b/src/save_data.h index d9e697c0..c0f95295 100644 --- a/src/save_data.h +++ b/src/save_data.h @@ -3,8 +3,9 @@ #include "types.h" #include "structs.h" -#include "PR/pfs.h" +#include "PR/os_pfs.h" #include "PR/os_cont.h" +#include "common.h" #define GAMD 0x47414D44 // 'GAMD' ASCII - Game Data? #define TIMD 0x54494D44 // 'TIMD' ASCII - Time Data? @@ -30,7 +31,17 @@ #define EEP_COURSE_TIME_OFFSET (0x140 / sizeof(u64)) #define EEP_FLAP_SIZE (0xC0 / sizeof(u64)) #define EEP_COURSE_RECORD_SIZE (0xC0 / sizeof(u64)) + +#if REGION == REGION_JP +// The Save size constant seems to change depending on the file being compiled in JP? +#define SAVE_SIZE_MENU 0x400 #define SAVE_SIZE 0x200 +#define SAVE_FILE_BYTES 48 +#else +#define SAVE_SIZE_MENU 0x200 +#define SAVE_SIZE 0x200 +#define SAVE_FILE_BYTES 24 +#endif #define GHSS_SIZE 0x100 #define AS_BYTES(ptr) ((u8 *) ptr) @@ -178,5 +189,6 @@ SIDeviceStatus func_80074EB8(s32 controllerIndex, s16 levelId, s16 vehicleId, s1 SIDeviceStatus func_80075000(s32 controllerIndex, s16 levelId, s16 vehicleId, s16 ghostCharacterId, s16 ghostTime, s16 ghostNodeCount, unk80075000_body *ghostData); s32 func_800753D8(s32 controllerIndex, s32 worldId); +void rumble_enable(s32 enable); #endif diff --git a/src/stacks.h b/src/stacks.h index 06aeb1c4..74e6c6d9 100644 --- a/src/stacks.h +++ b/src/stacks.h @@ -3,9 +3,7 @@ #include "types.h" -#define OS_PIM_STACKSIZE 256 - -extern u8 D_8012A9B0[0x100]; +extern u8 D_80129AB0[0x100]; extern u16 D_80129BB0[512]; extern s32 gObjectStackTrace[3]; diff --git a/src/textures_sprites.h b/src/textures_sprites.h index b2536ff5..386cb78d 100644 --- a/src/textures_sprites.h +++ b/src/textures_sprites.h @@ -7,7 +7,7 @@ #include "structs.h" #include "macros.h" #include "memory.h" -#include "libultra_internal.h" +#include /** * First two entries are combine mode. @@ -124,6 +124,7 @@ s32 func_8007EF64(s16 arg0); void load_and_set_texture(Gfx **dlist, TextureHeader *texhead, s32 flags, s32 texOffset); void free_sprite(Sprite *sprite); void free_texture(TextureHeader *tex); +void func_8007BF34(Gfx **dlist, s32 flags); // There might be a file boundary here. void tex_animate_texture(TextureHeader *texture, u32 *triangleBatchInfoFlags, s32 *arg2, s32 updateRate); @@ -140,7 +141,6 @@ void func_8007F594(Gfx **dlist, u32 index, u32 primitiveColor, u32 environmentCo void func_8007CA68(s32 spriteID, s32 arg1, s32 *arg2, s32 *arg3, s32 *arg4); // Non Matching MemoryPoolSlot *func_8007C12C(s32 spriteID, s32 arg1); // Non Matching void tex_init_textures(void); // Non Matching -void func_8007BF34(Gfx **dlist, s32 flags); // Non Matching void load_blinking_lights_texture(Gfx **dlist, TextureHeader *texture_list, u32 flags, s32 texture_index); // Non Matching void build_tex_display_list(TextureHeader *tex, Gfx *dlist); // Non Matching diff --git a/src/thread0_epc.c b/src/thread0_epc.c index 58cc7f8e..b019890b 100644 --- a/src/thread0_epc.c +++ b/src/thread0_epc.c @@ -2,15 +2,17 @@ /* RAM_POS: 0x800B6F50 */ #include "thread0_epc.h" +#include "common.h" #include "types.h" #include "macros.h" #include "menu.h" #include "save_data.h" #include "printf.h" #include "objects.h" -#include "controller.h" +#include "joypad.h" #include "game.h" #include "stacks.h" +#include "PR/os_internal_thread.h" /************ .rodata ************/ diff --git a/src/thread0_epc.h b/src/thread0_epc.h index f2d1b58c..d24bdbcd 100644 --- a/src/thread0_epc.h +++ b/src/thread0_epc.h @@ -2,7 +2,7 @@ #define _THREAD0_EPC_H_ #include "types.h" -#include "libultra_internal.h" +#include #include "macros.h" /* Size: 0x1B0 bytes */ diff --git a/src/thread3_main.c b/src/thread3_main.c index f186c0e2..e3a59fc7 100644 --- a/src/thread3_main.c +++ b/src/thread3_main.c @@ -3,6 +3,7 @@ #include "thread3_main.h" +#include "common.h" #include #include #include @@ -25,7 +26,7 @@ #include "objects.h" #include "camera.h" #include "save_data.h" -#include "rcp.h" +#include "rcp_dkr.h" #include "audiosfx.h" #include "audiomgr.h" #include "lights.h" @@ -43,7 +44,9 @@ #include "racer.h" #include "particles.h" #include "math_util.h" -#include "controller.h" +#include "joypad.h" +#include "PRinternal/viint.h" +#include "font.h" /************ .rodata ************/ diff --git a/src/tracks.c b/src/tracks.c index 56ec319d..5a4a7c94 100644 --- a/src/tracks.c +++ b/src/tracks.c @@ -23,6 +23,7 @@ #include "math_util.h" #include "printf.h" #include "collision.h" +#include "PRinternal/viint.h" #include "common.h" // Maximum size for a level model is 522.5 KiB diff --git a/src/tracks.h b/src/tracks.h index 4cc07452..65562f70 100644 --- a/src/tracks.h +++ b/src/tracks.h @@ -211,5 +211,6 @@ void func_800B82B4(LevelModel *, LevelHeader *, s32); void func_80025510(s32); void func_8002C0C4(s32 modelId); void func_800304C8(Vec4f *arg0); +s32 func_80027184(f32 *arg0, f32 *arg1, f32 arg2, f32 arg3); #endif diff --git a/src/video.c b/src/video.c index 1e1df1f2..66bfe526 100644 --- a/src/video.c +++ b/src/video.c @@ -2,7 +2,7 @@ /* RAM_POS: 0x8007A310 */ #include "video.h" -#include "viint.h" +#include "PRinternal/viint.h" /************ .data ************/ diff --git a/src/video.h b/src/video.h index cb831852..40ac590f 100644 --- a/src/video.h +++ b/src/video.h @@ -4,7 +4,6 @@ #include "types.h" #include "macros.h" #include "memory.h" -#include "PR/libultra.h" #include "PR/os_message.h" #include "PR/os_vi.h" #include "sched.h" diff --git a/src/waves.c b/src/waves.c index 31db7dfb..633f5c5b 100644 --- a/src/waves.c +++ b/src/waves.c @@ -10,6 +10,7 @@ #include "objects.h" #include "tracks.h" #include "math_util.h" +#include "PRinternal/viint.h" /************ .data ************/ diff --git a/src/weather.c b/src/weather.c index 8c8fc3a2..1dee7991 100644 --- a/src/weather.c +++ b/src/weather.c @@ -12,6 +12,7 @@ #include "textures_sprites.h" #include "math_util.h" #include "objects.h" +#include "PRinternal/viint.h" #include "common.h" #define WEATHER_OVERRIDE_COUNT 16 @@ -353,9 +354,9 @@ void snow_init(void) { offset = 0; for (i = 0; i < gSnowGfx.size; i++) { - gSnowGfx.pos[i].x = coss(offset & 0xFFFF) << 3; + gSnowGfx.pos[i].x = coss_s16(offset & 0xFFFF) << 3; gSnowGfx.pos[i].y = 0xFFFC0000; - gSnowGfx.pos[i].z = sins(offset & 0xFFFF) << 1; + gSnowGfx.pos[i].z = sins_s16(offset & 0xFFFF) << 1; offset += step; } diff --git a/src/weather.h b/src/weather.h index 2760630f..44a8e5f0 100644 --- a/src/weather.h +++ b/src/weather.h @@ -1,5 +1,5 @@ -#ifndef _UNKNOWN_0ABDF0_H_ -#define _UNKNOWN_0ABDF0_H_ +#ifndef _WEATHER_H_ +#define _WEATHER_H_ #include "types.h" #include "textures_sprites.h" diff --git a/tools/dkr_assets_tool_src/prebuild/prebuild.cpp b/tools/dkr_assets_tool_src/prebuild/prebuild.cpp index 6f03b574..0bf2f631 100644 --- a/tools/dkr_assets_tool_src/prebuild/prebuild.cpp +++ b/tools/dkr_assets_tool_src/prebuild/prebuild.cpp @@ -110,16 +110,8 @@ void PreBuild::_get_code_files() { void PreBuild::_populate_filepaths() { _lateDataFiles = { - _buildLibSrc / "al/alCopy.o", - _buildLibSrc / "libc/xprintf.o", - _buildLibSrc / "os/osTimer.o", - _buildLibSrc / "os/piacs.o", }; _bssLibOrderFiles = { - _buildLibSrc / "os/osViMgr.o", - _buildLibSrc / "os/osSetEventMesg.o", - _buildLibSrc / "os/controller.o", - _buildLibSrc / "os/siacs.o", }; } @@ -305,7 +297,7 @@ void PreBuild::_generate_ld() { // .ucodeData section _write_ucode_data_section(ld); - ld.write_assignment("__BSS_SECTION_SIZE", "SIZEOF(.bss.noload) - 16"); + ld.write_assignment("__BSS_SECTION_SIZE", "SIZEOF(.bss.noload) - 32"); ld.write_newline(); // .bss.noload section diff --git a/tools/format.py b/tools/format.py index cd6d0f09..13e68900 100755 --- a/tools/format.py +++ b/tools/format.py @@ -29,7 +29,7 @@ APPLY_OPTS = "" # Compiler options used with Clang-Tidy # Normal warnings are disabled with -Wno-everything to focus only on tidying -INCLUDES = "-Iinclude -Isrc -Ibuild -I. -Ilib/src" +INCLUDES = "-Iinclude -Isrc -Ibuild -I. -Ilib/src -Iinclude/libc -Iinclude/PR -Iinclude/sys -Ilib/src -Ilib/src/audio -Ilib/src/debug -Ilib/src/gu -Ilib/src/libc -Ilib/src/os" DEFINES = "-D_LANGUAGE_C -DNON_MATCHING -D_MIPS_SZLONG=32 -DNON_EQUIVALENT" COMPILER_OPTS = f"-fno-builtin -std=gnu90 -m32 -Wno-everything {INCLUDES} {DEFINES}" diff --git a/tools/python/generate_ld.py b/tools/python/generate_ld.py deleted file mode 100644 index 91cc362e..00000000 --- a/tools/python/generate_ld.py +++ /dev/null @@ -1,262 +0,0 @@ -import re -import os -import sys -import os.path -import hashlib - -from file_util import FileUtil -from generate_assets import GenerateAssets - -VERSION = sys.argv[1] - -if VERSION != 'us_1.0': - print("generate_ld currently does not support " + sys.argv[1]) - sys.exit(0) - -ROOT_DIR = '.' -LD_NAME = ROOT_DIR + '/dkr.ld' -ASM_DIR = ROOT_DIR + '/asm' -SRC_DIR = ROOT_DIR + '/src' -LIB_ASM_DIR = ROOT_DIR + '/lib/asm' -LIB_SRC_DIR = ROOT_DIR + '/lib/src' -DATA_DIR = ROOT_DIR + '/data' -BUILD_DIR = 'build/' + VERSION - -LATE_DATA_FILES = [ - BUILD_DIR + '/lib/src/al/alCopy.o', - BUILD_DIR + '/lib/src/libc/xprintf.o', - BUILD_DIR + '/lib/src/os/osTimer.o', - BUILD_DIR + '/lib/src/os/piacs.o' -] - -BSS_LIB_ORDER_FILES = [ - BUILD_DIR + '/lib/src/os/osViMgr.o', - BUILD_DIR + '/lib/src/os/osSetEventMesg.o', - BUILD_DIR + '/lib/src/os/controller.o', - BUILD_DIR + '/lib/src/os/siacs.o' -] - -class GenerateLD: - def __init__(self, file): - print('\x1B[32mGenerating linker file: \x1B[0m', end='') - self.assets = GenerateAssets(ROOT_DIR, VERSION) - self.files = self.get_code_files() - self.indentLevel = 0 - self.file = file - self.gen_comment('linker script generated by generate_ld.py') - self.gen_comment('If you want to make any changes, then edit the generate_ld.py script!') - self.gen_newline() - self.gen_line('#include "config.h"') - self.gen_newline() - self.gen_line('OUTPUT_ARCH (mips)') - self.gen_newline() - self.gen_sections() - print('\x1B[33m New linker file created!\x1B[0m') - - def gen_sections(self): - self.gen_line('SECTIONS') - self.gen_open_block() - self.gen_line('romPos = 0x0;') - self.gen_boot_section() - self.gen_line('__FUNC_RAM_START = 0x80000400;') - self.gen_line('__FUNC_ROM_START = 0x00001000;') - self.gen_line('__RAM_TO_ROM = __FUNC_RAM_START - __FUNC_ROM_START;') - self.gen_newline() - self.gen_main_section() - self.gen_ucode_text_section() - self.gen_data_section() - self.gen_rodata_section() - self.gen_ucode_data_section() - self.gen_bss_section() - self.gen_assets_section() - self.gen_line('__ROM_END = romPos;') - self.gen_newline() - self.gen_discard() - self.gen_close_block() - - def gen_boot_section(self): - self.gen_line('.boot 0 : AT(romPos)') - self.gen_open_block() - self.gen_line(BUILD_DIR + '/asm/boot/rom_header.o(.text);') - self.gen_line(BUILD_DIR + '/asm/boot/rom_boot.o(.text);') - self.gen_close_block() - self.gen_line('romPos += SIZEOF(.boot);') - self.gen_newline() - - def gen_main_section(self): - self.gen_line('.main __FUNC_RAM_START : AT(romPos) SUBALIGN(16)') - self.gen_open_block() - for file in self.files: - condition = file[4] - if condition != None: - self.gen_line('#if ' + condition) - self.gen_line(file[0] + '(.text);') - if condition != None: - self.gen_line('#endif') - self.gen_close_block() - self.gen_line('romPos += SIZEOF(.main);') - self.gen_newline() - - def gen_ucode_text_section(self): - self.gen_line('.ucodeText . : AT(romPos)') - self.gen_open_block() - self.gen_line(BUILD_DIR + '/asm/assets/ucode_text.o(.text);') - self.gen_close_block() - self.gen_line('romPos += SIZEOF(.ucodeText);') - self.gen_newline() - - def gen_data_section(self): - self.gen_line('.data . : AT(romPos) SUBALIGN(16)') - self.gen_open_block() - for file in self.files: - condition = file[4] - if file[0] not in LATE_DATA_FILES: - if condition != None: - self.gen_line('#if ' + condition) - self.gen_line(file[0] + '(.data);') - if condition != None: - self.gen_line('#endif') - for file in LATE_DATA_FILES: - self.gen_line(file + '(.data);') - self.gen_close_block() - self.gen_line('romPos += SIZEOF(.data);') - self.gen_newline() - - def gen_rodata_section(self): - self.gen_line('.rodata . : AT(romPos) SUBALIGN(16)') - self.gen_open_block() - for file in self.files: - f = file[0] - condition = file[4] - if f not in LATE_DATA_FILES: - if condition != None: - self.gen_line('#if ' + condition) - self.gen_line(f + '(.rodata);') - fname = f[f.rindex('/')+1:f.rindex('.')] - testName = DATA_DIR + '/' + fname + '.rodata.s' - if FileUtil.does_file_exist(testName): - self.gen_line(BUILD_DIR + '/data/' + fname + '.rodata.o(.rodata);') - if condition != None: - self.gen_line('#endif') - for f in LATE_DATA_FILES: - self.gen_line(f + '(.rodata);') - fname = f[f.rindex('/')+1:f.rindex('.')] - testName = DATA_DIR + '/' + fname + '.rodata.s' - if FileUtil.does_file_exist(testName): - self.gen_line(BUILD_DIR + '/data/' + fname + '.rodata.o(.rodata);') - self.gen_close_block() - self.gen_line('romPos += SIZEOF(.rodata);') - self.gen_newline() - - def gen_ucode_data_section(self): - self.gen_line('.ucodeData . : AT(romPos)') - self.gen_open_block() - self.gen_line(BUILD_DIR + '/asm/assets/ucode_data.o(.text);') - self.gen_close_block() - self.gen_line('romPos += SIZEOF(.ucodeData);') - self.gen_newline() - - def gen_bss_section(self): - self.gen_line('__BSS_SECTION_SIZE = SIZEOF(.bss.noload) - 0x10;') - self.gen_newline() - self.gen_line('.bss.noload . (NOLOAD): SUBALIGN(4)') - self.gen_open_block() - for file in self.files: - condition = file[4] - if file[0] not in BSS_LIB_ORDER_FILES: - if condition != None: - self.gen_line('#if ' + condition) - self.gen_line(file[0] + '(.bss);') - if condition != None: - self.gen_line('#endif') - for file in BSS_LIB_ORDER_FILES: - self.gen_line(file + '(.bss);') - self.gen_close_block() - self.gen_newline() - - def gen_assets_section(self): - self.gen_line('__ASSETS_LUT_START = romPos;'); - self.gen_line('__ASSETS_LUT_END = __ASSETS_LUT_START + ' + hex((((self.assets.numAssets + 2) * 4) + 15) & 0xFFFFFFF0) + ';'); - self.gen_newline() - self.gen_line('.assets 0 : AT(romPos)') - self.gen_open_block() - self.gen_line(BUILD_DIR + '/asm/assets/assets.o(.text);') - self.gen_close_block() - self.gen_line('romPos += SIZEOF(.assets);') - self.gen_newline() - - def gen_discard(self): - self.gen_comment('Discard everything not specifically mentioned above.') - self.gen_line('/DISCARD/ :') - self.gen_open_block() - self.gen_line('*(*);') - self.gen_close_block() - - def increase_indent(self): - self.indentLevel += 1 - - def decrease_indent(self): - self.indentLevel -= 1 - - def gen_open_block(self): - self.gen_line('{') - self.increase_indent() - - def gen_close_block(self): - self.decrease_indent() - self.gen_line('}') - - def gen_line(self, text): - spaces = 4 * self.indentLevel - while spaces > 0: - self.file.write(' ') - spaces -= 1 - self.file.write(text) - self.gen_newline() - - def gen_comment(self, text): - spaces = 4 * self.indentLevel - while spaces > 0: - self.file.write(' ') - spaces -= 1 - self.file.write('/* ' + text + ' */') - self.gen_newline() - - def gen_newline(self): - self.file.write('\n') - - def append_files(self, files, extensions, directory, outputDir): - filenames = FileUtil.get_filenames_from_directory_recursive(directory, extensions) - regex = r'[\/][*]+\s*RAM_POS:\s*((?:0x)[0-9a-fA-F]+|(?:[Aa][Uu][Tt][Oo]))\s*(?:if\s*(.*))?\s*[*]+[\/]' - for filename in filenames: - with open(directory + '/' + filename, 'r') as inFile: - notDone = True - line = inFile.readline() - while line: - matches = re.match(regex, line) - if matches is None: - line = inFile.readline() - continue - matchedGroups = matches.groups() - ramPos = matchedGroups[0] - condition = matchedGroups[1] - if ramPos.lower() == 'auto': - ramPos = '800FFFF0' - files.append((outputDir + filename[:-2] + '.o', '', ramPos, 0, condition)) - break - - def get_code_files(self): - files = [] - self.append_files(files, ('.s',), ASM_DIR, BUILD_DIR + '/asm/') - self.append_files(files, ('.c',), SRC_DIR, BUILD_DIR + '/src/') - self.append_files(files, ('.s',), LIB_ASM_DIR, BUILD_DIR + '/lib/asm/') - self.append_files(files, ('.c',), LIB_SRC_DIR, BUILD_DIR + '/lib/src/') - files.sort(key = lambda x: (x[2], x[3])) # Sort tuples by RAM address and prioritize src files first. - return files - -# A nice side-effect of the ./assets// directory being "read-only" is that we can write a file to it, -# and then if it gets deleted we'll know if the assets have been updated. -if not os.path.exists('./dkr.ld') or not os.path.exists('./assets/' + VERSION + '/ignoreMe.txt'): - with open(LD_NAME, 'w') as ldFile: - GenerateLD(ldFile) - diff --git a/tools/python/m2ctx.py b/tools/python/m2ctx.py index bdc585e6..b0d33b83 100644 --- a/tools/python/m2ctx.py +++ b/tools/python/m2ctx.py @@ -16,7 +16,7 @@ ignoreFiles = ["include/sys/regdef.h"] search_folders = ["include/", "src/"] # Needed for StereoPanMode -includeFiles = ['lib/src/mips1/al/alSynStartVoiceParams.h'] +includeFiles = ['include/PR/libaudio.h'] hack_directives_into_singleline = ['DRAW_TABLE_ENTRY', 'DRAW_TABLE_GROUP'] diff --git a/undefined_syms.txt b/undefined_syms.txt index f6dd5085..e019268a 100755 --- a/undefined_syms.txt +++ b/undefined_syms.txt @@ -1,19 +1,65 @@ -osTvType = 0x80000300; -osRomBase = 0x80000308; -osResetType = 0x8000030C; -osCicId = 0x80000310; -osAppNmiBuffer = 0x8000031C; - - -SP_STATUS_REG = 0xA4040010; -VI_CURRENT_REG = 0xA4400010; -MI_INTR_REG = 0xA4300008; -MI_INTR_MASK_REG = 0xA430000C; -AI_STATUS_REG = 0xA450000C; -PI_STATUS_REG = 0xA4600010; -SI_STATUS_REG = 0xA4800018; - D_B0000574 = 0xB0000574; D_B0000578 = 0xB0000578; D_801299B0 = 0x801299B0; -gEpcInfo = 0x80129800; \ No newline at end of file +gEpcInfo = 0x80129800; + +/* Just libultra stuff below */ + +osTvType = 0x80000300; +osRomType = 0x80000304; +osRomBase = 0x80000308; +osResetType = 0x8000030C; +osCicId = 0x80000310; +osVersion = 0x80000314; +osMemSize = 0x80000318; +osAppNMIBuffer = 0x8000031C; +entrypoint = 0x80000400; + +SP_MEM_ADDR_REG = 0xA4040000; +SP_DRAM_ADDR_REG = 0xA4040004; +SP_RD_LEN_REG = 0xA4040008; +SP_WR_LEN_REG = 0xA404000C; +SP_STATUS_REG = 0xA4040010; +DPC_START_REG = 0xA4100000; +DPC_END_REG = 0xA4100004; +DPC_STATUS_REG = 0xA410000C; +MI_MODE_REG = 0xA4300000; +MI_INTR_REG = 0xA4300008; +MI_INTR_MASK_REG = 0xA430000C; +VI_STATUS_REG = 0xA4400000; +VI_DRAM_ADDR_REG = 0xA4400004; +VI_H_WIDTH_REG = 0xA4400008; +VI_V_INTR_REG = 0xA440000C; +VI_V_CURRENT_LINE_REG = 0xA4400010; +VI_TIMING_REG = 0xA4400014; +VI_V_SYNC_REG = 0xA4400018; +VI_H_SYNC_REG = 0xA440001C; +VI_H_SYNC_LEAP_REG = 0xA4400020; +VI_H_VIDEO_REG = 0xA4400024; +VI_V_VIDEO_REG = 0xA4400028; +VI_V_BURST_REG = 0xA440002C; +VI_X_SCALE_REG = 0xA4400030; +VI_Y_SCALE_REG = 0xA4400034; +AI_DRAM_ADDR_REG = 0xA4500000; +AI_LEN_REG = 0xA4500004; +AI_CONTROL_REG = 0xA4500008; +AI_STATUS_REG = 0xA450000C; +AI_DACRATE_REG = 0xA4500010; +AI_BITRATE_REG = 0xA4500014; +PI_DRAM_ADDR_REG = 0xA4600000; +PI_CART_ADDR_REG = 0xA4600004; +PI_RD_LEN_REG = 0xA4600008; +PI_WR_LEN_REG = 0xA460000C; +PI_STATUS_REG = 0xA4600010; +PI_BSD_DOM1_LAT_REG = 0xA4600014; +PI_BSD_DOM1_PWD_REG = 0xA4600018; +PI_BSD_DOM1_PGS_REG = 0xA460001C; +PI_BSD_DOM1_RLS_REG = 0xA4600020; +PI_BSD_DOM2_LAT_REG = 0xA4600024; +PI_BSD_DOM2_PWD_REG = 0xA4600028; +PI_BSD_DOM2_PGS_REG = 0xA460002C; +PI_BSD_DOM2_RLS_REG = 0xA4600030; +SI_DRAM_ADDR_REG = 0xA4800000; +SI_PIF_ADDR_RD64B_REG = 0xA4800004; +SI_PIF_ADDR_WR64B_REG = 0xA4800010; +SI_STATUS_REG = 0xA4800018; \ No newline at end of file