diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..28df4e3d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "macros.h": "c", + "libultra_internal.h": "c" + } +} \ No newline at end of file diff --git a/Makefile b/Makefile index 313a817f..a71e0ccb 100755 --- a/Makefile +++ b/Makefile @@ -172,6 +172,22 @@ ALL_ASSETS_BUILT := $(ANIMATIONS_BUILT) $(AUDIO_BUILT) $(BILLBOARDS_BUILT) $(BIN $(BUILD_DIR)/lib/%.o: OPT_FLAGS := -O2 $(BUILD_DIR)/lib/%.o: MIPSISET := -mips2 +$(BUILD_DIR)/lib/src/unknown_0C91A0.o : OPT_FLAGS := -O1 +$(BUILD_DIR)/lib/src/unknown_0D29F0.o: OPT_FLAGS := -O1 +$(BUILD_DIR)/lib/src/osCreateThread.o : OPT_FLAGS := -O1 +$(BUILD_DIR)/lib/src/osGetThreadPri.o : OPT_FLAGS := -O1 +$(BUILD_DIR)/lib/src/osPiStartDma.o : OPT_FLAGS := -O1 +$(BUILD_DIR)/lib/src/osRecvMesg.o : OPT_FLAGS := -O1 +$(BUILD_DIR)/lib/src/osSendMesg.o : OPT_FLAGS := -O1 +$(BUILD_DIR)/lib/src/osSetTimer.o: OPT_FLAGS := -O1 +$(BUILD_DIR)/lib/src/osStopThread.o: OPT_FLAGS := -O1 +$(BUILD_DIR)/lib/src/osTimer.o: OPT_FLAGS := -O1 +$(BUILD_DIR)/lib/src/osViBlack.o: OPT_FLAGS := -O1 +$(BUILD_DIR)/lib/src/osViSwapBuffer.o : OPT_FLAGS := -O1 + + + + ######################## Targets ############################# @@ -189,6 +205,13 @@ else @echo "/build/ directory has already been deleted." endif +clean_lib: +ifneq ($(wildcard ./build/lib/.*),) + rm -r $(BUILD_DIR)/lib/src/*.o +else + @echo "/build/lib directory has already been deleted." +endif + $(BUILD_DIR): mkdir $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(LIB_DIRS) $(ASM_DIRS) $(SRC_DIRS) $(ASSETS_DIRS)) diff --git a/asm/non_matchings/unknown_07AF10/func_8007A98C.s b/asm/non_matchings/unknown_07AF10/func_8007A98C.s index adea8d87..76eefa3c 100644 --- a/asm/non_matchings/unknown_07AF10/func_8007A98C.s +++ b/asm/non_matchings/unknown_07AF10/func_8007A98C.s @@ -98,7 +98,7 @@ glabel func_8007A98C .L8007AAE8: /* 07B6E8 8007AAE8 3C048012 */ lui $a0, %hi(D_801262D8) # $a0, 0x8012 /* 07B6EC 8007AAEC 8C8462D8 */ lw $a0, %lo(D_801262D8)($a0) -/* 07B6F0 8007AAF0 0C034908 */ jal func_800D2420 +/* 07B6F0 8007AAF0 0C034908 */ jal osViSwapBuffer /* 07B6F4 8007AAF4 AFA30028 */ sw $v1, 0x28($sp) /* 07B6F8 8007AAF8 02402025 */ move $a0, $s2 /* 07B6FC 8007AAFC 00002825 */ move $a1, $zero diff --git a/asm/non_matchings/unknown_0B8920/func_800C6000.s b/asm/non_matchings/unknown_0B8920/func_800C6000.s index 3673d101..6b3d992e 100644 --- a/asm/non_matchings/unknown_0B8920/func_800C6000.s +++ b/asm/non_matchings/unknown_0B8920/func_800C6000.s @@ -1,8 +1,8 @@ glabel osCreatePiManager /* 0C6C00 800C6000 27BDFFD0 */ addiu $sp, $sp, -0x30 /* 0C6C04 800C6004 AFB00020 */ sw $s0, 0x20($sp) -/* 0C6C08 800C6008 3C10800E */ lui $s0, %hi(D_800E3740) # $s0, 0x800e -/* 0C6C0C 800C600C 26103740 */ addiu $s0, %lo(D_800E3740) # addiu $s0, $s0, 0x3740 +/* 0C6C08 800C6008 3C10800E */ lui $s0, %hi(__osPiDevMgr) # $s0, 0x800e +/* 0C6C0C 800C600C 26103740 */ addiu $s0, %lo(__osPiDevMgr) # addiu $s0, $s0, 0x3740 /* 0C6C10 800C6010 8E0E0000 */ lw $t6, ($s0) /* 0C6C14 800C6014 AFBF0024 */ sw $ra, 0x24($sp) /* 0C6C18 800C6018 AFA40030 */ sw $a0, 0x30($sp) diff --git a/asm/non_matchings/unknown_0B8920/osCreatePiManager.s b/asm/non_matchings/unknown_0B8920/osCreatePiManager.s index 3673d101..6b3d992e 100644 --- a/asm/non_matchings/unknown_0B8920/osCreatePiManager.s +++ b/asm/non_matchings/unknown_0B8920/osCreatePiManager.s @@ -1,8 +1,8 @@ glabel osCreatePiManager /* 0C6C00 800C6000 27BDFFD0 */ addiu $sp, $sp, -0x30 /* 0C6C04 800C6004 AFB00020 */ sw $s0, 0x20($sp) -/* 0C6C08 800C6008 3C10800E */ lui $s0, %hi(D_800E3740) # $s0, 0x800e -/* 0C6C0C 800C600C 26103740 */ addiu $s0, %lo(D_800E3740) # addiu $s0, $s0, 0x3740 +/* 0C6C08 800C6008 3C10800E */ lui $s0, %hi(__osPiDevMgr) # $s0, 0x800e +/* 0C6C0C 800C600C 26103740 */ addiu $s0, %lo(__osPiDevMgr) # addiu $s0, $s0, 0x3740 /* 0C6C10 800C6010 8E0E0000 */ lw $t6, ($s0) /* 0C6C14 800C6014 AFBF0024 */ sw $ra, 0x24($sp) /* 0C6C18 800C6018 AFA40030 */ sw $a0, 0x30($sp) diff --git a/data/dkr.data.s b/data/dkr.data.s index 3826207c..dde1465b 100644 --- a/data/dkr.data.s +++ b/data/dkr.data.s @@ -8084,7 +8084,7 @@ glabel D_800E3710 .word 0x00000000 .word 0x00000000 -glabel D_800E3740 +glabel __osPiDevMgr .word 0x00000000 .word 0x00000000 @@ -9252,7 +9252,7 @@ glabel D_800E4878 .word 0x02E6D354 .word 0x00000000 -glabel D_800E4880 +glabel __osThreadTail .word 0x00000000 .word 0xFFFFFFFF @@ -9262,7 +9262,7 @@ glabel D_800E4888 glabel D_800E488C .word 0x800E4880 -glabel D_800E4890 +glabel __osRunningThread .word 0x00000000 glabel D_800E4894 diff --git a/include/PR/R4300.h b/include/PR/R4300.h new file mode 100644 index 00000000..932694d3 --- /dev/null +++ b/include/PR/R4300.h @@ -0,0 +1,453 @@ +/************************************************************************** + * * + * 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.13 $ + * $Date: 1997/02/11 08:15:34 $ + * $Source: /disk6/Master/cvsmdev2/PR/include/R4300.h,v $ + * + **************************************************************************/ + +#ifndef __R4300_H__ +#define __R4300_H__ + +#include + +/* + * Segment base addresses and sizes + */ +#define KUBASE 0 +#define KUSIZE 0x80000000 +#define K0BASE 0x80000000 +#define K0SIZE 0x20000000 +#define K1BASE 0xA0000000 +#define K1SIZE 0x20000000 +#define K2BASE 0xC0000000 +#define K2SIZE 0x20000000 + +/* + * Exception vectors + */ +#define SIZE_EXCVEC 0x80 /* Size of an exc. vec */ +#define UT_VEC K0BASE /* utlbmiss vector */ +#define R_VEC (K1BASE+0x1fc00000) /* reset vector */ +#define XUT_VEC (K0BASE+0x80) /* extended address tlbmiss */ +#define ECC_VEC (K0BASE+0x100) /* Ecc exception vector */ +#define E_VEC (K0BASE+0x180) /* Gen. exception vector */ + +/* + * Address conversion macros + */ +#ifdef _LANGUAGE_ASSEMBLY + +#define K0_TO_K1(x) ((x)|0xA0000000) /* kseg0 to kseg1 */ +#define K1_TO_K0(x) ((x)&0x9FFFFFFF) /* kseg1 to kseg0 */ +#define K0_TO_PHYS(x) ((x)&0x1FFFFFFF) /* kseg0 to physical */ +#define K1_TO_PHYS(x) ((x)&0x1FFFFFFF) /* kseg1 to physical */ +#define KDM_TO_PHYS(x) ((x)&0x1FFFFFFF) /* direct mapped to physical */ +#define PHYS_TO_K0(x) ((x)|0x80000000) /* physical to kseg0 */ +#define PHYS_TO_K1(x) ((x)|0xA0000000) /* physical to kseg1 */ + +#else /* _LANGUAGE_C */ + +#define K0_TO_K1(x) ((u32)(x)|0xA0000000) /* kseg0 to kseg1 */ +#define K1_TO_K0(x) ((u32)(x)&0x9FFFFFFF) /* kseg1 to kseg0 */ +#define K0_TO_PHYS(x) ((u32)(x)&0x1FFFFFFF) /* kseg0 to physical */ +#define K1_TO_PHYS(x) ((u32)(x)&0x1FFFFFFF) /* kseg1 to physical */ +#define KDM_TO_PHYS(x) ((u32)(x)&0x1FFFFFFF) /* direct mapped to physical */ +#define PHYS_TO_K0(x) ((u32)(x)|0x80000000) /* physical to kseg0 */ +#define PHYS_TO_K1(x) ((u32)(x)|0xA0000000) /* physical to kseg1 */ + +#endif /* _LANGUAGE_ASSEMBLY */ + +/* + * Address predicates + */ +#define IS_KSEG0(x) ((u32)(x) >= K0BASE && (u32)(x) < K1BASE) +#define IS_KSEG1(x) ((u32)(x) >= K1BASE && (u32)(x) < K2BASE) +#define IS_KSEGDM(x) ((u32)(x) >= K0BASE && (u32)(x) < K2BASE) +#define IS_KSEG2(x) ((u32)(x) >= K2BASE && (u32)(x) < KPTE_SHDUBASE) +#define IS_KPTESEG(x) ((u32)(x) >= KPTE_SHDUBASE) +#define IS_KUSEG(x) ((u32)(x) < K0BASE) + +/* + * TLB size constants + */ + +#define NTLBENTRIES 31 /* entry 31 is reserved by rdb */ + +#define TLBHI_VPN2MASK 0xffffe000 +#define TLBHI_VPN2SHIFT 13 +#define TLBHI_PIDMASK 0xff +#define TLBHI_PIDSHIFT 0 +#define TLBHI_NPID 255 /* 255 to fit in 8 bits */ + +#define TLBLO_PFNMASK 0x3fffffc0 +#define TLBLO_PFNSHIFT 6 +#define TLBLO_CACHMASK 0x38 /* cache coherency algorithm */ +#define TLBLO_CACHSHIFT 3 +#define TLBLO_UNCACHED 0x10 /* not cached */ +#define TLBLO_NONCOHRNT 0x18 /* Cacheable non-coherent */ +#define TLBLO_EXLWR 0x28 /* Exclusive write */ +#define TLBLO_D 0x4 /* writeable */ +#define TLBLO_V 0x2 /* valid bit */ +#define TLBLO_G 0x1 /* global access bit */ + +#define TLBINX_PROBE 0x80000000 +#define TLBINX_INXMASK 0x3f +#define TLBINX_INXSHIFT 0 + +#define TLBRAND_RANDMASK 0x3f +#define TLBRAND_RANDSHIFT 0 + +#define TLBWIRED_WIREDMASK 0x3f + +#define TLBCTXT_BASEMASK 0xff800000 +#define TLBCTXT_BASESHIFT 23 +#define TLBCTXT_BASEBITS 9 + +#define TLBCTXT_VPNMASK 0x7ffff0 +#define TLBCTXT_VPNSHIFT 4 + +#define TLBPGMASK_4K 0x0 +#define TLBPGMASK_16K 0x6000 +#define TLBPGMASK_64K 0x1e000 + +/* + * Status register + */ +#define SR_CUMASK 0xf0000000 /* coproc usable bits */ + +#define SR_CU3 0x80000000 /* Coprocessor 3 usable */ +#define SR_CU2 0x40000000 /* Coprocessor 2 usable */ +#define SR_CU1 0x20000000 /* Coprocessor 1 usable */ +#define SR_CU0 0x10000000 /* Coprocessor 0 usable */ +#define SR_RP 0x08000000 /* Reduced power (quarter speed) */ +#define SR_FR 0x04000000 /* MIPS III FP register mode */ +#define SR_RE 0x02000000 /* Reverse endian */ +#define SR_ITS 0x01000000 /* Instruction trace support */ +#define SR_BEV 0x00400000 /* Use boot exception vectors */ +#define SR_TS 0x00200000 /* TLB shutdown */ +#define SR_SR 0x00100000 /* Soft reset occured */ +#define SR_CH 0x00040000 /* Cache hit for last 'cache' op */ +#define SR_CE 0x00020000 /* Create ECC */ +#define SR_DE 0x00010000 /* ECC of parity does not cause error */ + +/* + * Interrupt enable bits + * (NOTE: bits set to 1 enable the corresponding level interrupt) + */ +#define SR_IMASK 0x0000ff00 /* Interrupt mask */ +#define SR_IMASK8 0x00000000 /* mask level 8 */ +#define SR_IMASK7 0x00008000 /* mask level 7 */ +#define SR_IMASK6 0x0000c000 /* mask level 6 */ +#define SR_IMASK5 0x0000e000 /* mask level 5 */ +#define SR_IMASK4 0x0000f000 /* mask level 4 */ +#define SR_IMASK3 0x0000f800 /* mask level 3 */ +#define SR_IMASK2 0x0000fc00 /* mask level 2 */ +#define SR_IMASK1 0x0000fe00 /* mask level 1 */ +#define SR_IMASK0 0x0000ff00 /* mask level 0 */ + +#define SR_IBIT8 0x00008000 /* bit level 8 */ +#define SR_IBIT7 0x00004000 /* bit level 7 */ +#define SR_IBIT6 0x00002000 /* bit level 6 */ +#define SR_IBIT5 0x00001000 /* bit level 5 */ +#define SR_IBIT4 0x00000800 /* bit level 4 */ +#define SR_IBIT3 0x00000400 /* bit level 3 */ +#define SR_IBIT2 0x00000200 /* bit level 2 */ +#define SR_IBIT1 0x00000100 /* bit level 1 */ + +#define SR_IMASKSHIFT 8 + +#define SR_KX 0x00000080 /* extended-addr TLB vec in kernel */ +#define SR_SX 0x00000040 /* xtended-addr TLB vec supervisor */ +#define SR_UX 0x00000020 /* xtended-addr TLB vec in user mode */ +#define SR_KSU_MASK 0x00000018 /* mode mask */ +#define SR_KSU_USR 0x00000010 /* user mode */ +#define SR_KSU_SUP 0x00000008 /* supervisor mode */ +#define SR_KSU_KER 0x00000000 /* kernel mode */ +#define SR_ERL 0x00000004 /* Error level, 1=>cache error */ +#define SR_EXL 0x00000002 /* Exception level, 1=>exception */ +#define SR_IE 0x00000001 /* interrupt enable, 1=>enable */ + +/* + * Cause Register + */ +#define CAUSE_BD 0x80000000 /* Branch delay slot */ +#define CAUSE_CEMASK 0x30000000 /* coprocessor error */ +#define CAUSE_CESHIFT 28 + +/* Interrupt pending bits */ +#define CAUSE_IP8 0x00008000 /* External level 8 pending - COMPARE */ +#define CAUSE_IP7 0x00004000 /* External level 7 pending - INT4 */ +#define CAUSE_IP6 0x00002000 /* External level 6 pending - INT3 */ +#define CAUSE_IP5 0x00001000 /* External level 5 pending - INT2 */ +#define CAUSE_IP4 0x00000800 /* External level 4 pending - INT1 */ +#define CAUSE_IP3 0x00000400 /* External level 3 pending - INT0 */ +#define CAUSE_SW2 0x00000200 /* Software level 2 pending */ +#define CAUSE_SW1 0x00000100 /* Software level 1 pending */ + +#define CAUSE_IPMASK 0x0000FF00 /* Pending interrupt mask */ +#define CAUSE_IPSHIFT 8 + +#define CAUSE_EXCMASK 0x0000007C /* Cause code bits */ + +#define CAUSE_EXCSHIFT 2 + +/* Cause register exception codes */ + +#define EXC_CODE(x) ((x)<<2) + +/* Hardware exception codes */ +#define EXC_INT EXC_CODE(0) /* interrupt */ +#define EXC_MOD EXC_CODE(1) /* TLB mod */ +#define EXC_RMISS EXC_CODE(2) /* Read TLB Miss */ +#define EXC_WMISS EXC_CODE(3) /* Write TLB Miss */ +#define EXC_RADE EXC_CODE(4) /* Read Address Error */ +#define EXC_WADE EXC_CODE(5) /* Write Address Error */ +#define EXC_IBE EXC_CODE(6) /* Instruction Bus Error */ +#define EXC_DBE EXC_CODE(7) /* Data Bus Error */ +#define EXC_SYSCALL EXC_CODE(8) /* SYSCALL */ +#define EXC_BREAK EXC_CODE(9) /* BREAKpoint */ +#define EXC_II EXC_CODE(10) /* Illegal Instruction */ +#define EXC_CPU EXC_CODE(11) /* CoProcessor Unusable */ +#define EXC_OV EXC_CODE(12) /* OVerflow */ +#define EXC_TRAP EXC_CODE(13) /* Trap exception */ +#define EXC_VCEI EXC_CODE(14) /* Virt. Coherency on Inst. fetch */ +#define EXC_FPE EXC_CODE(15) /* Floating Point Exception */ +#define EXC_WATCH EXC_CODE(23) /* Watchpoint reference */ +#define EXC_VCED EXC_CODE(31) /* Virt. Coherency on data read */ + +/* C0_PRID Defines */ +#define C0_IMPMASK 0xff00 +#define C0_IMPSHIFT 8 +#define C0_REVMASK 0xff +#define C0_MAJREVMASK 0xf0 +#define C0_MAJREVSHIFT 4 +#define C0_MINREVMASK 0xf + +/* + * Coprocessor 0 operations + */ +#define C0_READI 0x1 /* read ITLB entry addressed by C0_INDEX */ +#define C0_WRITEI 0x2 /* write ITLB entry addressed by C0_INDEX */ +#define C0_WRITER 0x6 /* write ITLB entry addressed by C0_RAND */ +#define C0_PROBE 0x8 /* probe for ITLB entry addressed by TLBHI */ +#define C0_RFE 0x10 /* restore for exception */ + +/* + * 'cache' instruction definitions + */ + +/* Target cache */ +#define CACH_PI 0x0 /* specifies primary inst. cache */ +#define CACH_PD 0x1 /* primary data cache */ +#define CACH_SI 0x2 /* secondary instruction cache */ +#define CACH_SD 0x3 /* secondary data cache */ + +/* Cache operations */ +#define C_IINV 0x0 /* index invalidate (inst, 2nd inst) */ +#define C_IWBINV 0x0 /* index writeback inval (d, sd) */ +#define C_ILT 0x4 /* index load tag (all) */ +#define C_IST 0x8 /* index store tag (all) */ +#define C_CDX 0xc /* create dirty exclusive (d, sd) */ +#define C_HINV 0x10 /* hit invalidate (all) */ +#define C_HWBINV 0x14 /* hit writeback inv. (d, sd) */ +#define C_FILL 0x14 /* fill (i) */ +#define C_HWB 0x18 /* hit writeback (i, d, sd) */ +#define C_HSV 0x1c /* hit set virt. (si, sd) */ + +/* + * Cache size definitions + */ +#define ICACHE_SIZE 0x4000 /* 16K */ +#define ICACHE_LINESIZE 32 /* 8 words */ +#define ICACHE_LINEMASK (ICACHE_LINESIZE-1) + +#define DCACHE_SIZE 0x2000 /* 8K */ +#define DCACHE_LINESIZE 16 /* 4 words */ +#define DCACHE_LINEMASK (DCACHE_LINESIZE-1) + +/* + * C0_CONFIG register definitions + */ +#define CONFIG_CM 0x80000000 /* 1 == Master-Checker enabled */ +#define CONFIG_EC 0x70000000 /* System Clock ratio */ +#define CONFIG_EC_1_1 0x6 /* System Clock ratio 1 :1 */ +#define CONFIG_EC_3_2 0x7 /* System Clock ratio 1.5 :1 */ +#define CONFIG_EC_2_1 0x0 /* System Clock ratio 2 :1 */ +#define CONFIG_EC_3_1 0x1 /* System Clock ratio 3 :1 */ +#define CONFIG_EP 0x0f000000 /* Transmit Data Pattern */ +#define CONFIG_SB 0x00c00000 /* Secondary cache block size */ + +#define CONFIG_SS 0x00200000 /* Split scache: 0 == I&D combined */ +#define CONFIG_SW 0x00100000 /* scache port: 0==128, 1==64 */ +#define CONFIG_EW 0x000c0000 /* System Port width: 0==64, 1==32 */ +#define CONFIG_SC 0x00020000 /* 0 -> 2nd cache present */ +#define CONFIG_SM 0x00010000 /* 0 -> Dirty Shared Coherency enabled*/ +#define CONFIG_BE 0x00008000 /* Endian-ness: 1 --> BE */ +#define CONFIG_EM 0x00004000 /* 1 -> ECC mode, 0 -> parity */ +#define CONFIG_EB 0x00002000 /* Block order:1->sequent,0->subblock */ + +#define CONFIG_IC 0x00000e00 /* Primary Icache size */ +#define CONFIG_DC 0x000001c0 /* Primary Dcache size */ +#define CONFIG_IB 0x00000020 /* Icache block size */ +#define CONFIG_DB 0x00000010 /* Dcache block size */ +#define CONFIG_CU 0x00000008 /* Update on Store-conditional */ +#define CONFIG_K0 0x00000007 /* K0SEG Coherency algorithm */ + +#define CONFIG_UNCACHED 0x00000002 /* K0 is uncached */ +#define CONFIG_NONCOHRNT 0x00000003 +#define CONFIG_COHRNT_EXLWR 0x00000005 +#define CONFIG_SB_SHFT 22 /* shift SB to bit position 0 */ +#define CONFIG_IC_SHFT 9 /* shift IC to bit position 0 */ +#define CONFIG_DC_SHFT 6 /* shift DC to bit position 0 */ +#define CONFIG_BE_SHFT 15 /* shift BE to bit position 0 */ + +/* + * C0_TAGLO definitions for setting/getting cache states and physaddr bits + */ +#define SADDRMASK 0xFFFFE000 /* 31..13 -> scache paddr bits 35..17 */ +#define SVINDEXMASK 0x00000380 /* 9..7: prim virt index bits 14..12 */ +#define SSTATEMASK 0x00001c00 /* bits 12..10 hold scache line state */ +#define SINVALID 0x00000000 /* invalid --> 000 == state 0 */ +#define SCLEANEXCL 0x00001000 /* clean exclusive --> 100 == state 4 */ +#define SDIRTYEXCL 0x00001400 /* dirty exclusive --> 101 == state 5 */ +#define SECC_MASK 0x0000007f /* low 7 bits are ecc for the tag */ +#define SADDR_SHIFT 4 /* shift STagLo (31..13) to 35..17 */ + +#define PADDRMASK 0xFFFFFF00 /* PTagLo31..8->prim paddr bits35..12 */ +#define PADDR_SHIFT 4 /* roll bits 35..12 down to 31..8 */ +#define PSTATEMASK 0x00C0 /* bits 7..6 hold primary line state */ +#define PINVALID 0x0000 /* invalid --> 000 == state 0 */ +#define PCLEANEXCL 0x0080 /* clean exclusive --> 10 == state 2 */ +#define PDIRTYEXCL 0x00C0 /* dirty exclusive --> 11 == state 3 */ +#define PPARITY_MASK 0x0001 /* low bit is parity bit (even). */ + +/* + * C0_CACHE_ERR definitions. + */ +#define CACHERR_ER 0x80000000 /* 0: inst ref, 1: data ref */ +#define CACHERR_EC 0x40000000 /* 0: primary, 1: secondary */ +#define CACHERR_ED 0x20000000 /* 1: data error */ +#define CACHERR_ET 0x10000000 /* 1: tag error */ +#define CACHERR_ES 0x08000000 /* 1: external ref, e.g. snoop*/ +#define CACHERR_EE 0x04000000 /* error on SysAD bus */ +#define CACHERR_EB 0x02000000 /* complicated, see spec. */ +#define CACHERR_EI 0x01000000 /* complicated, see spec. */ +#define CACHERR_SIDX_MASK 0x003ffff8 /* secondary cache index */ +#define CACHERR_PIDX_MASK 0x00000007 /* primary cache index */ +#define CACHERR_PIDX_SHIFT 12 /* bits 2..0 are paddr14..12 */ + +/* R4000 family supports hardware watchpoints: + * C0_WATCHLO: + * bits 31..3 are bits 31..3 of physaddr to watch + * bit 2: reserved; must be written as 0. + * bit 1: when set causes a watchpoint trap on load accesses to paddr. + * bit 0: when set traps on stores to paddr; + * C0_WATCHHI + * bits 31..4 are reserved and must be written as zeros. + * bits 3..0 are bits 35..32 of the physaddr to watch + */ +#define WATCHLO_WTRAP 0x00000001 +#define WATCHLO_RTRAP 0x00000002 +#define WATCHLO_ADDRMASK 0xfffffff8 +#define WATCHLO_VALIDMASK 0xfffffffb +#define WATCHHI_VALIDMASK 0x0000000f + +/* + * Coprocessor 0 registers + */ +#ifdef _LANGUAGE_ASSEMBLY +#define C0_INX $0 +#define C0_RAND $1 +#define C0_ENTRYLO0 $2 +#define C0_ENTRYLO1 $3 +#define C0_CONTEXT $4 +#define C0_PAGEMASK $5 /* page mask */ +#define C0_WIRED $6 /* # wired entries in tlb */ +#define C0_BADVADDR $8 +#define C0_COUNT $9 /* free-running counter */ +#define C0_ENTRYHI $10 +#define C0_SR $12 +#define C0_CAUSE $13 +#define C0_EPC $14 +#define C0_PRID $15 /* revision identifier */ +#define C0_COMPARE $11 /* counter comparison reg. */ +#define C0_CONFIG $16 /* hardware configuration */ +#define C0_LLADDR $17 /* load linked address */ +#define C0_WATCHLO $18 /* watchpoint */ +#define C0_WATCHHI $19 /* watchpoint */ +#define C0_ECC $26 /* S-cache ECC and primary parity */ +#define C0_CACHE_ERR $27 /* cache error status */ +#define C0_TAGLO $28 /* cache operations */ +#define C0_TAGHI $29 /* cache operations */ +#define C0_ERROR_EPC $30 /* ECC error prg. counter */ + +# else /* ! _LANGUAGE_ASSEMBLY */ + +#define C0_INX 0 +#define C0_RAND 1 +#define C0_ENTRYLO0 2 +#define C0_ENTRYLO1 3 +#define C0_CONTEXT 4 +#define C0_PAGEMASK 5 /* page mask */ +#define C0_WIRED 6 /* # wired entries in tlb */ +#define C0_BADVADDR 8 +#define C0_COUNT 9 /* free-running counter */ +#define C0_ENTRYHI 10 +#define C0_SR 12 +#define C0_CAUSE 13 +#define C0_EPC 14 +#define C0_PRID 15 /* revision identifier */ +#define C0_COMPARE 11 /* counter comparison reg. */ +#define C0_CONFIG 16 /* hardware configuration */ +#define C0_LLADDR 17 /* load linked address */ +#define C0_WATCHLO 18 /* watchpoint */ +#define C0_WATCHHI 19 /* watchpoint */ +#define C0_ECC 26 /* S-cache ECC and primary parity */ +#define C0_CACHE_ERR 27 /* cache error status */ +#define C0_TAGLO 28 /* cache operations */ +#define C0_TAGHI 29 /* cache operations */ +#define C0_ERROR_EPC 30 /* ECC error prg. counter */ + +#endif /* _LANGUAGE_ASSEMBLY */ + +/* + * floating-point status register + */ +#define FPCSR_FS 0x01000000 /* flush denorm to zero */ +#define FPCSR_C 0x00800000 /* condition bit */ +#define FPCSR_CE 0x00020000 /* cause: unimplemented operation */ +#define FPCSR_CV 0x00010000 /* cause: invalid operation */ +#define FPCSR_CZ 0x00008000 /* cause: division by zero */ +#define FPCSR_CO 0x00004000 /* cause: overflow */ +#define FPCSR_CU 0x00002000 /* cause: underflow */ +#define FPCSR_CI 0x00001000 /* cause: inexact operation */ +#define FPCSR_EV 0x00000800 /* enable: invalid operation */ +#define FPCSR_EZ 0x00000400 /* enable: division by zero */ +#define FPCSR_EO 0x00000200 /* enable: overflow */ +#define FPCSR_EU 0x00000100 /* enable: underflow */ +#define FPCSR_EI 0x00000080 /* enable: inexact operation */ +#define FPCSR_FV 0x00000040 /* flag: invalid operation */ +#define FPCSR_FZ 0x00000020 /* flag: division by zero */ +#define FPCSR_FO 0x00000010 /* flag: overflow */ +#define FPCSR_FU 0x00000008 /* flag: underflow */ +#define FPCSR_FI 0x00000004 /* flag: inexact operation */ +#define FPCSR_RM_MASK 0x00000003 /* rounding mode mask */ +#define FPCSR_RM_RN 0x00000000 /* round to nearest */ +#define FPCSR_RM_RZ 0x00000001 /* round to zero */ +#define FPCSR_RM_RP 0x00000002 /* round to positive infinity */ +#define FPCSR_RM_RM 0x00000003 /* round to negative infinity */ + +#endif /* __R4300_H */ diff --git a/include/PR/abi.h b/include/PR/abi.h new file mode 100644 index 00000000..8545be3b --- /dev/null +++ b/include/PR/abi.h @@ -0,0 +1,622 @@ +#ifndef _ABI_H_ +#define _ABI_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.32 $ + * $Date: 1997/02/11 08:16:37 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/abi.h,v $ + * + **************************************************************************/ + +/* + * Header file for the Audio Binary Interface. + * This is included in the Media Binary Interface file + * mbi.h. + * + * This file follows the framework used for graphics. + * + */ + +/* 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_DMEMMOVE 10 +#define A_LOADADPCM 11 +#define A_MIXER 12 +#define A_INTERLEAVE 13 +#define A_POLEF 14 +#define A_SETLOOP 15 + +#define ACMD_SIZE 32 +/* + * Audio flags + */ + +#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 + +/* + * BEGIN C-specific section: (typedef's) + */ +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* + * Data Structures. + */ + +typedef struct { + 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; +} Apolef; + +typedef struct { + 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; +} Aclearbuff; + +typedef struct { + 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; +} Aloadbuff; + +typedef struct { + 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; +} Amixer; + +typedef struct { + 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; +} Aresample; + +typedef struct { + 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; +} Asavebuff; + +typedef struct { + 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; +} Asetbuff; + +typedef struct { + 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; +} Admemmove; + +typedef struct { + 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; +} Asetloop; + +/* + * Generic Acmd Packet + */ + +typedef struct { + uintptr_t w0; + uintptr_t 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 */ +} Acmd; + +/* + * ADPCM State + */ +typedef short ADPCM_STATE[16]; + +/* + * Pole filter state + */ +typedef short POLEF_STATE[4]; + +/* + * Resampler state + */ +typedef short RESAMPLE_STATE[16]; + +/* + * Resampler constants + */ +#define UNITY_PITCH 0x8000 +#define MAX_RATIO 1.99996 /* within .03 cents of +1 octave */ + +/* + * Enveloper/Mixer state + */ +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); \ +} + +/* + * 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); \ +} + +/* + * 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); \ +} + +/* + * 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); \ +} + +/* + * 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); \ +} + +/* + * 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); \ +} + +/* + * 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); \ +} + +// 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); \ +} + +/* + * 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); \ +} + +/* + * 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); \ +} + +/* + * 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); \ +} + +/* + * 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); \ +} + +/* + * 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); \ +} + +/* + * 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); \ +} + +/* + * 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); \ +} + +#endif /* _LANGUAGE_C */ + +#endif /* !_ABI_H_ */ diff --git a/include/PR/gbi.h b/include/PR/gbi.h new file mode 100644 index 00000000..e459bd3e --- /dev/null +++ b/include/PR/gbi.h @@ -0,0 +1,4718 @@ +/************************************************************************** + * * + * 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.141 $ + * $Date: 1999/09/03 03:43:08 $ + * $Source: /exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/gbi.h,v $ + * + **************************************************************************/ + +#ifndef _GBI_H_ +#define _GBI_H_ + +#include + +/* + * To use the F3DEX ucodes, define F3DEX_GBI before include this file. + * + * #define F3DEX_GBI + * #include + * + * or + * + * cc -c -DF3DEX_GBI -I.... foo.c + * + */ + +/************************************************************************** + * + * Graphics Binary Interface + * + **************************************************************************/ + +/* + * Graphics Commands, 'xxx' parts may be generated from ucode + * + * The command format is + * + * |00xxxxxx| = DMA 0,..,127 + * |10xxxxxx| = Immediate Mode -65,..,-128 + * |11xxxxxx| = RDP cmds -1,..,-64 + * + * Note: in order for the RSP microcode to process RDP commands opaquely, + * we need to further identify those RDP commands that need DRAM address + * "fixup". To do this, we have the dummy command G_RDP_ADDR_FIXUP, and + * all |RDP commands| less than this are commands with embedded DRAM + * addresses. Further, the format of these commands should be similar so + * only one fixup routine is needed. + * + * Further explanation: + * The names of the commands are somewhat misleading. Here is clarification: + * + * - a 'DMA' type command has a pointer to additional data and + * causes a DMA transfer to bring that into DMEM. + * + * - an 'Immediate' type command isn't really 'immediate', in the + * traditional sense. This just means that the entire command fits + * in the 64-bit word, and the ucode can execute it 'immediately' + * without additional memory transfers. + * + * - an 'RDP' command is identified as such because the RDP + * commands can be passed-thru the RSP and sent to the RDP + * directly. One further confusing thing, is that some 'DP' + * macros below actually generate immediate commands, not + * not direct DP commands. + * + * IMPLEMENTATION NOTE: + * There is another group of RDP commands that includes the triangle commands + * generated by the RSP code. These are the raw commands the rasterizer + * hardware chews on, with slope info, etc. They will follow the RDP + * ordering... + * + * IMPLEMENTATION NOTE: + * The RDP hardware has some of these bit patterns wired up. If the hardware + * changes, we must adjust this table, likewise we can't change/add things + * once the hardware is frozen. (actually, the RDP hardware only looks at + * the lower 6 bits of the command byte) + * + */ + +#ifdef F3DEX_GBI_2 +# ifndef F3DEX_GBI +# define F3DEX_GBI +# endif +#define G_NOOP 0x00 +#define G_RDPHALF_2 0xf1 +#define G_SETOTHERMODE_H 0xe3 +#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_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 */ + +/* DMA commands: */ +#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_RESERVED1 5 /* not implemeted */ +#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) +#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) +#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) +#define G_SPRITE2D_DRAW (G_IMMFIRST-2) + +/* RDP commands: */ +#define G_NOOP 0xc0 /* 0 */ + +#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_TEXRECTFLIP 0xe5 /* -27 */ +#define G_TEXRECT 0xe4 /* -28 */ + + +/* + * The following commands are the "generated" RDP commands; the user + * never sees them, the RSP microcode generates them. + * + * The layout of the bits is magical, to save work in the ucode. + * These id's are -56, -52, -54, -50, -55, -51, -53, -49, ... + * edge, shade, texture, zbuff bits: estz + */ +#define G_TRI_FILL 0xc8 /* fill triangle: 11001000 */ +#define G_TRI_SHADE 0xcc /* shade triangle: 11001100 */ +#define G_TRI_TXTR 0xca /* texture triangle: 11001010 */ +#define G_TRI_SHADE_TXTR 0xce /* shade, texture triangle: 11001110 */ +#define G_TRI_FILL_ZBUFF 0xc9 /* fill, zbuff triangle: 11001001 */ +#define G_TRI_SHADE_ZBUFF 0xcd /* shade, zbuff triangle: 11001101 */ +#define G_TRI_TXTR_ZBUFF 0xcb /* texture, zbuff triangle: 11001011 */ +#define G_TRI_SHADE_TXTR_ZBUFF 0xcf /* shade, txtr, zbuff trngl: 11001111 */ + +/* + * A TRI_FILL triangle is just the edges. You need to set the DP + * to use primcolor, in order to see anything. (it is NOT a triangle + * that gets rendered in 'fill mode'. Triangles can't be rendered + * in 'fill mode') + * + * A TRI_SHADE is a gouraud triangle that has colors interpolated. + * Flat-shaded triangles (from the software) are still gouraud shaded, + * it's just the colors are all the same and the deltas are 0. + * + * Other triangle types, and combinations are more obvious. + */ + +/* 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 + +/* + * HACK: + * This is a dreadful hack. For version 1.0 hardware, there are still + * some 'bowtie' hangs. This parameter can be increased to avoid + * the hangs. Every increase of 4 chops one scanline off of every + * triangle. Values of 4,8,12 should be sufficient to avoid any + * bowtie hang. + * + * Change this value, then recompile ALL of your program (including static + * display lists!) + * + * THIS WILL BE REMOVED FOR HARDWARE VERSION 2.0! + */ +#define BOWTIE_VAL 0 + + +/* gets added to RDP command, in order to test for addres fixup: */ +#define G_RDP_ADDR_FIXUP 3 /* |RDP cmds| <= this, do addr fixup */ +#ifdef _LANGUAGE_ASSEMBLY +#define G_RDP_TEXRECT_CHECK ((-1*G_TEXRECTFLIP)& 0xff) +#endif + +/* macros for command parsing: */ +#define GDMACMD(x) (x) +#define GIMMCMD(x) (G_IMMFIRST-(x)) +#define GRDPCMD(x) (0xff-(x)) + +#define G_DMACMDSIZ 128 +#define G_IMMCMDSIZ 64 +#define G_RDPCMDSIZ 64 + +/* + * Coordinate shift values, number of bits of fraction + */ +#define G_TEXTURE_IMAGE_FRAC 2 +#define G_TEXTURE_SCALE_FRAC 16 +#define G_SCALE_FRAC 8 +#define G_ROTATE_FRAC 16 + +/* + * Parameters to graphics commands + */ + +/* + * Data packing macros + */ + +/* + * Maximum z-buffer value, used to initialize the z-buffer. + * Note : this number is NOT the viewport z-scale constant. + * See the comment next to G_MAXZ for more info. + */ +#define G_MAXFBZ 0x3fff /* 3b exp, 11b mantissa */ + +#define GPACK_RGBA5551(r, g, b, a) ((((r)<<8) & 0xf800) | \ + (((g)<<3) & 0x7c0) | \ + (((b)>>2) & 0x3e) | ((a) & 0x1)) +#define GPACK_ZDZ(z, dz) ((z) << 2 | (dz)) + +/* + * 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 +#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 +#endif /* F3DEX_GBI_2 */ + +/* + * flags for G_SETGEOMETRYMODE + * (this rendering state is maintained in RSP) + * + * DO NOT USE THE LOW 8 BITS OF GEOMETRYMODE: + * The weird bit-ordering is for the micro-code: the lower byte + * can be OR'd in with G_TRI_SHADE (11001100) to construct + * the triangle command directly. Don't break it... + * + * DO NOT USE THE HIGH 8 BITS OF GEOMETRYMODE: + * The high byte is OR'd with 0x703 to form the clip code mask. + * If it is set to 0x04, this will cause near clipping to occur. + * If it is zero, near clipping will not occur. + * + * Further explanation: + * G_SHADE is necessary in order to see the color that you passed + * down with the vertex. If G_SHADE isn't set, you need to set the DP + * appropriately and use primcolor to see anything. + * + * G_SHADING_SMOOTH enabled means use all 3 colors of the triangle. + * If it is not set, then do 'flat shading', where only one vertex color + * is used (and all 3 vertices are set to that same color by the ucode) + * See the man page for gSP1Triangle(). + * + */ +#define G_ZBUFFER 0x00000001 +#define G_SHADE 0x00000004 /* enable Gouraud interp */ +/* rest of low byte reserved for setup ucode */ +#ifdef F3DEX_GBI_2 +# define G_TEXTURE_ENABLE 0x00000000 /* Ignored */ +# define G_SHADING_SMOOTH 0x00200000 /* flat or smooth shaded */ +# define G_CULL_FRONT 0x00000200 +# define G_CULL_BACK 0x00000400 +# define G_CULL_BOTH 0x00000600 /* To make code cleaner */ +#else +# define G_TEXTURE_ENABLE 0x00000002 /* Microcode use only */ +# define G_SHADING_SMOOTH 0x00000200 /* flat or smooth shaded */ +# define G_CULL_FRONT 0x00001000 +# define G_CULL_BACK 0x00002000 +# define G_CULL_BOTH 0x00003000 /* To make code cleaner */ +#endif +#define G_FOG 0x00010000 +#define G_LIGHTING 0x00020000 +#define G_TEXTURE_GEN 0x00040000 +#define G_TEXTURE_GEN_LINEAR 0x00080000 +#define G_LOD 0x00100000 /* NOT IMPLEMENTED */ +#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) +# define G_CLIPPING 0x00800000 +#else +# define G_CLIPPING 0x00000000 +#endif + +#ifdef _LANGUAGE_ASSEMBLY +#define G_FOG_H (G_FOG/0x10000) +#define G_LIGHTING_H (G_LIGHTING/0x10000) +#define G_TEXTURE_GEN_H (G_TEXTURE_GEN/0x10000) +#define G_TEXTURE_GEN_LINEAR_H (G_TEXTURE_GEN_LINEAR/0x10000) +#define G_LOD_H (G_LOD/0x10000) /* NOT IMPLEMENTED */ +#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) +# define G_CLIPPING_H (G_CLIPPING/0x10000) +#endif +#endif + +/* Need these defined for Sprite Microcode */ +#ifdef _LANGUAGE_ASSEMBLY +#define G_TX_LOADTILE 7 +#define G_TX_RENDERTILE 0 + +#define G_TX_NOMIRROR 0 +#define G_TX_WRAP 0 +#define G_TX_MIRROR 0x1 +#define G_TX_CLAMP 0x2 +#define G_TX_NOMASK 0 +#define G_TX_NOLOD 0 +#endif + +/* + * G_SETIMG fmt: set image formats + */ +#define G_IM_FMT_RGBA 0 +#define G_IM_FMT_YUV 1 +#define G_IM_FMT_CI 2 +#define G_IM_FMT_IA 3 +#define G_IM_FMT_I 4 + +/* + * G_SETIMG siz: set image pixel size + */ +#define G_IM_SIZ_4b 0 +#define G_IM_SIZ_8b 1 +#define G_IM_SIZ_16b 2 +#define G_IM_SIZ_32b 3 +#define G_IM_SIZ_DD 5 + +#define G_IM_SIZ_4b_BYTES 0 +#define G_IM_SIZ_4b_TILE_BYTES G_IM_SIZ_4b_BYTES +#define G_IM_SIZ_4b_LINE_BYTES G_IM_SIZ_4b_BYTES + +#define G_IM_SIZ_8b_BYTES 1 +#define G_IM_SIZ_8b_TILE_BYTES G_IM_SIZ_8b_BYTES +#define G_IM_SIZ_8b_LINE_BYTES G_IM_SIZ_8b_BYTES + +#define G_IM_SIZ_16b_BYTES 2 +#define G_IM_SIZ_16b_TILE_BYTES G_IM_SIZ_16b_BYTES +#define G_IM_SIZ_16b_LINE_BYTES G_IM_SIZ_16b_BYTES + +#define G_IM_SIZ_32b_BYTES 4 +#define G_IM_SIZ_32b_TILE_BYTES 2 +#define G_IM_SIZ_32b_LINE_BYTES 2 + +#define G_IM_SIZ_4b_LOAD_BLOCK G_IM_SIZ_16b +#define G_IM_SIZ_8b_LOAD_BLOCK G_IM_SIZ_16b +#define G_IM_SIZ_16b_LOAD_BLOCK G_IM_SIZ_16b +#define G_IM_SIZ_32b_LOAD_BLOCK G_IM_SIZ_32b + +#define G_IM_SIZ_4b_SHIFT 2 +#define G_IM_SIZ_8b_SHIFT 1 +#define G_IM_SIZ_16b_SHIFT 0 +#define G_IM_SIZ_32b_SHIFT 0 + +#define G_IM_SIZ_4b_INCR 3 +#define G_IM_SIZ_8b_INCR 1 +#define G_IM_SIZ_16b_INCR 0 +#define G_IM_SIZ_32b_INCR 0 + +/* + * 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 + +/* 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_LOD_FRACTION 0 +#define G_ACMUX_PRIM_LOD_FRAC 6 +#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 + +/* 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 +/* 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 + +/* 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 + +/* + * One-cycle color convert operation + */ +#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 + +/* 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_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 + +/* + * G_SETOTHERMODE_L sft: shift count + */ +#define G_MDSFT_ALPHACOMPARE 0 +#define G_MDSFT_ZSRCSEL 2 +#define G_MDSFT_RENDERMODE 3 +#define G_MDSFT_BLENDER 16 + +/* + * G_SETOTHERMODE_H sft: shift count + */ +#define G_MDSFT_BLENDMASK 0 /* unsupported */ +#define G_MDSFT_ALPHADITHER 4 +#define G_MDSFT_RGBDITHER 6 + +#define G_MDSFT_COMBKEY 8 +#define G_MDSFT_TEXTCONV 9 +#define G_MDSFT_TEXTFILT 12 +#define G_MDSFT_TEXTLUT 14 +#define G_MDSFT_TEXTLOD 16 +#define G_MDSFT_TEXTDETAIL 17 +#define G_MDSFT_TEXTPERSP 19 +#define G_MDSFT_CYCLETYPE 20 +#define G_MDSFT_COLORDITHER 22 /* unsupported in HW 2.0 */ +#define G_MDSFT_PIPELINE 23 + +/* G_SETOTHERMODE_H gPipelineMode */ +#define G_PM_1PRIMITIVE (1 << G_MDSFT_PIPELINE) +#define G_PM_NPRIMITIVE (0 << G_MDSFT_PIPELINE) + +/* G_SETOTHERMODE_H gSetCycleType */ +#define G_CYC_1CYCLE (0 << G_MDSFT_CYCLETYPE) +#define G_CYC_2CYCLE (1 << G_MDSFT_CYCLETYPE) +#define G_CYC_COPY (2 << G_MDSFT_CYCLETYPE) +#define G_CYC_FILL (3 << G_MDSFT_CYCLETYPE) + +/* G_SETOTHERMODE_H gSetTexturePersp */ +#define G_TP_NONE (0 << G_MDSFT_TEXTPERSP) +#define G_TP_PERSP (1 << G_MDSFT_TEXTPERSP) + +/* G_SETOTHERMODE_H gSetTextureDetail */ +#define G_TD_CLAMP (0 << G_MDSFT_TEXTDETAIL) +#define G_TD_SHARPEN (1 << G_MDSFT_TEXTDETAIL) +#define G_TD_DETAIL (2 << G_MDSFT_TEXTDETAIL) + +/* G_SETOTHERMODE_H gSetTextureLOD */ +#define G_TL_TILE (0 << G_MDSFT_TEXTLOD) +#define G_TL_LOD (1 << G_MDSFT_TEXTLOD) + +/* G_SETOTHERMODE_H gSetTextureLUT */ +#define G_TT_NONE (0 << G_MDSFT_TEXTLUT) +#define G_TT_RGBA16 (2 << G_MDSFT_TEXTLUT) +#define G_TT_IA16 (3 << G_MDSFT_TEXTLUT) + +/* G_SETOTHERMODE_H gSetTextureFilter */ +#define G_TF_POINT (0 << G_MDSFT_TEXTFILT) +#define G_TF_AVERAGE (3 << G_MDSFT_TEXTFILT) +#define G_TF_BILERP (2 << G_MDSFT_TEXTFILT) + +/* G_SETOTHERMODE_H gSetTextureConvert */ +#define G_TC_CONV (0 << G_MDSFT_TEXTCONV) +#define G_TC_FILTCONV (5 << G_MDSFT_TEXTCONV) +#define G_TC_FILT (6 << G_MDSFT_TEXTCONV) + +/* G_SETOTHERMODE_H gSetCombineKey */ +#define G_CK_NONE (0 << G_MDSFT_COMBKEY) +#define G_CK_KEY (1 << G_MDSFT_COMBKEY) + +/* G_SETOTHERMODE_H gSetColorDither */ +#define G_CD_MAGICSQ (0 << G_MDSFT_RGBDITHER) +#define G_CD_BAYER (1 << G_MDSFT_RGBDITHER) +#define G_CD_NOISE (2 << G_MDSFT_RGBDITHER) + +#ifndef _HW_VERSION_1 +#define G_CD_DISABLE (3 << G_MDSFT_RGBDITHER) +#define G_CD_ENABLE G_CD_NOISE /* HW 1.0 compatibility mode */ +#else +#define G_CD_ENABLE (1 << G_MDSFT_COLORDITHER) +#define G_CD_DISABLE (0 << G_MDSFT_COLORDITHER) +#endif + +/* G_SETOTHERMODE_H gSetAlphaDither */ +#define G_AD_PATTERN (0 << G_MDSFT_ALPHADITHER) +#define G_AD_NOTPATTERN (1 << G_MDSFT_ALPHADITHER) +#define G_AD_NOISE (2 << G_MDSFT_ALPHADITHER) +#define G_AD_DISABLE (3 << G_MDSFT_ALPHADITHER) + +/* G_SETOTHERMODE_L gSetAlphaCompare */ +#define G_AC_NONE (0 << G_MDSFT_ALPHACOMPARE) +#define G_AC_THRESHOLD (1 << G_MDSFT_ALPHACOMPARE) +#define G_AC_DITHER (3 << G_MDSFT_ALPHACOMPARE) + +/* G_SETOTHERMODE_L gSetDepthSource */ +#define G_ZS_PIXEL (0 << G_MDSFT_ZSRCSEL) +#define G_ZS_PRIM (1 << G_MDSFT_ZSRCSEL) + +/* G_SETOTHERMODE_L gSetRenderMode */ +#define AA_EN 0x8 +#define Z_CMP 0x10 +#define Z_UPD 0x20 +#define IM_RD 0x40 +#define CLR_ON_CVG 0x80 +#define CVG_DST_CLAMP 0 +#define CVG_DST_WRAP 0x100 +#define CVG_DST_FULL 0x200 +#define CVG_DST_SAVE 0x300 +#define ZMODE_OPA 0 +#define ZMODE_INTER 0x400 +#define ZMODE_XLU 0x800 +#define ZMODE_DEC 0xc00 +#define CVG_X_ALPHA 0x1000 +#define ALPHA_CVG_SEL 0x2000 +#define FORCE_BL 0x4000 +#define TEX_EDGE 0x0000 /* used to be 0x8000 */ + +#define G_BL_CLR_IN 0 +#define G_BL_CLR_MEM 1 +#define G_BL_CLR_BL 2 +#define G_BL_CLR_FOG 3 +#define G_BL_1MA 0 +#define G_BL_A_MEM 1 +#define G_BL_A_IN 0 +#define G_BL_A_FOG 1 +#define G_BL_A_SHADE 2 +#define G_BL_1 2 +#define G_BL_0 3 + +#define GBL_c1(m1a, m1b, m2a, m2b) \ + (m1a) << 30 | (m1b) << 26 | (m2a) << 22 | (m2b) << 18 +#define GBL_c2(m1a, m1b, m2a, m2b) \ + (m1a) << 28 | (m1b) << 24 | (m2a) << 20 | (m2b) << 16 + +#define RM_AA_ZB_OPA_SURF(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_RA_ZB_OPA_SURF(clk) \ + AA_EN | Z_CMP | Z_UPD | CVG_DST_CLAMP | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_ZB_XLU_SURF(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | \ + FORCE_BL | ZMODE_XLU | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_OPA_DECAL(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | ALPHA_CVG_SEL | \ + ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_RA_ZB_OPA_DECAL(clk) \ + AA_EN | Z_CMP | CVG_DST_WRAP | ALPHA_CVG_SEL | \ + ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_ZB_XLU_DECAL(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | \ + FORCE_BL | ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_OPA_INTER(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + ALPHA_CVG_SEL | ZMODE_INTER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_RA_ZB_OPA_INTER(clk) \ + AA_EN | Z_CMP | Z_UPD | CVG_DST_CLAMP | \ + ALPHA_CVG_SEL | ZMODE_INTER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_ZB_XLU_INTER(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | \ + FORCE_BL | ZMODE_INTER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_XLU_LINE(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_CLAMP | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | FORCE_BL | ZMODE_XLU | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_DEC_LINE(clk) \ + AA_EN | Z_CMP | IM_RD | CVG_DST_SAVE | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | FORCE_BL | ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_TEX_EDGE(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_ZB_TEX_INTER(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_INTER | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_ZB_SUB_SURF(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_ZB_PCL_SURF(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + ZMODE_OPA | G_AC_DITHER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_OPA_TERR(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_TEX_TERR(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_CLAMP | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_ZB_SUB_TERR(clk) \ + AA_EN | Z_CMP | Z_UPD | IM_RD | CVG_DST_FULL | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + + +#define RM_AA_OPA_SURF(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_RA_OPA_SURF(clk) \ + AA_EN | CVG_DST_CLAMP | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_XLU_SURF(clk) \ + AA_EN | IM_RD | CVG_DST_WRAP | CLR_ON_CVG | FORCE_BL | \ + ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_XLU_LINE(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | FORCE_BL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_DEC_LINE(clk) \ + AA_EN | IM_RD | CVG_DST_FULL | CVG_X_ALPHA | \ + ALPHA_CVG_SEL | FORCE_BL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_TEX_EDGE(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_SUB_SURF(clk) \ + AA_EN | IM_RD | CVG_DST_FULL | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_AA_PCL_SURF(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | \ + ZMODE_OPA | G_AC_DITHER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_OPA_TERR(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_TEX_TERR(clk) \ + AA_EN | IM_RD | CVG_DST_CLAMP | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_AA_SUB_TERR(clk) \ + AA_EN | IM_RD | CVG_DST_FULL | \ + ZMODE_OPA | ALPHA_CVG_SEL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + + +#define RM_ZB_OPA_SURF(clk) \ + Z_CMP | Z_UPD | CVG_DST_FULL | ALPHA_CVG_SEL | \ + ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_ZB_XLU_SURF(clk) \ + Z_CMP | IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_XLU | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_ZB_OPA_DECAL(clk) \ + Z_CMP | CVG_DST_FULL | ALPHA_CVG_SEL | ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_A_MEM) + +#define RM_ZB_XLU_DECAL(clk) \ + Z_CMP | IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_ZB_CLD_SURF(clk) \ + Z_CMP | IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_XLU | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_ZB_OVL_SURF(clk) \ + Z_CMP | IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_DEC | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_ZB_PCL_SURF(clk) \ + Z_CMP | Z_UPD | CVG_DST_FULL | ZMODE_OPA | \ + G_AC_DITHER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) + + +#define RM_OPA_SURF(clk) \ + CVG_DST_CLAMP | FORCE_BL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) + +#define RM_XLU_SURF(clk) \ + IM_RD | CVG_DST_FULL | FORCE_BL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_TEX_EDGE(clk) \ + CVG_DST_CLAMP | CVG_X_ALPHA | ALPHA_CVG_SEL | FORCE_BL |\ + ZMODE_OPA | TEX_EDGE | AA_EN | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) + +#define RM_CLD_SURF(clk) \ + IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define RM_PCL_SURF(clk) \ + CVG_DST_FULL | FORCE_BL | ZMODE_OPA | \ + G_AC_DITHER | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) + +#define RM_ADD(clk) \ + IM_RD | CVG_DST_SAVE | FORCE_BL | ZMODE_OPA | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_FOG, G_BL_CLR_MEM, G_BL_1) + +#define RM_NOOP(clk) \ + GBL_c##clk(0, 0, 0, 0) + +#define RM_VISCVG(clk) \ + IM_RD | FORCE_BL | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_0, G_BL_CLR_BL, G_BL_A_MEM) + +/* for rendering to an 8-bit framebuffer */ +#define RM_OPA_CI(clk) \ + 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) +#define G_RM_AA_ZB_OPA_SURF2 RM_AA_ZB_OPA_SURF(2) +#define G_RM_AA_ZB_XLU_SURF RM_AA_ZB_XLU_SURF(1) +#define G_RM_AA_ZB_XLU_SURF2 RM_AA_ZB_XLU_SURF(2) +#define G_RM_AA_ZB_OPA_DECAL RM_AA_ZB_OPA_DECAL(1) +#define G_RM_AA_ZB_OPA_DECAL2 RM_AA_ZB_OPA_DECAL(2) +#define G_RM_AA_ZB_XLU_DECAL RM_AA_ZB_XLU_DECAL(1) +#define G_RM_AA_ZB_XLU_DECAL2 RM_AA_ZB_XLU_DECAL(2) +#define G_RM_AA_ZB_OPA_INTER RM_AA_ZB_OPA_INTER(1) +#define G_RM_AA_ZB_OPA_INTER2 RM_AA_ZB_OPA_INTER(2) +#define G_RM_AA_ZB_XLU_INTER RM_AA_ZB_XLU_INTER(1) +#define G_RM_AA_ZB_XLU_INTER2 RM_AA_ZB_XLU_INTER(2) +#define G_RM_AA_ZB_XLU_LINE RM_AA_ZB_XLU_LINE(1) +#define G_RM_AA_ZB_XLU_LINE2 RM_AA_ZB_XLU_LINE(2) +#define G_RM_AA_ZB_DEC_LINE RM_AA_ZB_DEC_LINE(1) +#define G_RM_AA_ZB_DEC_LINE2 RM_AA_ZB_DEC_LINE(2) +#define G_RM_AA_ZB_TEX_EDGE RM_AA_ZB_TEX_EDGE(1) +#define G_RM_AA_ZB_TEX_EDGE2 RM_AA_ZB_TEX_EDGE(2) +#define G_RM_AA_ZB_TEX_INTER RM_AA_ZB_TEX_INTER(1) +#define G_RM_AA_ZB_TEX_INTER2 RM_AA_ZB_TEX_INTER(2) +#define G_RM_AA_ZB_SUB_SURF RM_AA_ZB_SUB_SURF(1) +#define G_RM_AA_ZB_SUB_SURF2 RM_AA_ZB_SUB_SURF(2) +#define G_RM_AA_ZB_PCL_SURF RM_AA_ZB_PCL_SURF(1) +#define G_RM_AA_ZB_PCL_SURF2 RM_AA_ZB_PCL_SURF(2) +#define G_RM_AA_ZB_OPA_TERR RM_AA_ZB_OPA_TERR(1) +#define G_RM_AA_ZB_OPA_TERR2 RM_AA_ZB_OPA_TERR(2) +#define G_RM_AA_ZB_TEX_TERR RM_AA_ZB_TEX_TERR(1) +#define G_RM_AA_ZB_TEX_TERR2 RM_AA_ZB_TEX_TERR(2) +#define G_RM_AA_ZB_SUB_TERR RM_AA_ZB_SUB_TERR(1) +#define G_RM_AA_ZB_SUB_TERR2 RM_AA_ZB_SUB_TERR(2) + +#define G_RM_RA_ZB_OPA_SURF RM_RA_ZB_OPA_SURF(1) +#define G_RM_RA_ZB_OPA_SURF2 RM_RA_ZB_OPA_SURF(2) +#define G_RM_RA_ZB_OPA_DECAL RM_RA_ZB_OPA_DECAL(1) +#define G_RM_RA_ZB_OPA_DECAL2 RM_RA_ZB_OPA_DECAL(2) +#define G_RM_RA_ZB_OPA_INTER RM_RA_ZB_OPA_INTER(1) +#define G_RM_RA_ZB_OPA_INTER2 RM_RA_ZB_OPA_INTER(2) + +#define G_RM_AA_OPA_SURF RM_AA_OPA_SURF(1) +#define G_RM_AA_OPA_SURF2 RM_AA_OPA_SURF(2) +#define G_RM_AA_XLU_SURF RM_AA_XLU_SURF(1) +#define G_RM_AA_XLU_SURF2 RM_AA_XLU_SURF(2) +#define G_RM_AA_XLU_LINE RM_AA_XLU_LINE(1) +#define G_RM_AA_XLU_LINE2 RM_AA_XLU_LINE(2) +#define G_RM_AA_DEC_LINE RM_AA_DEC_LINE(1) +#define G_RM_AA_DEC_LINE2 RM_AA_DEC_LINE(2) +#define G_RM_AA_TEX_EDGE RM_AA_TEX_EDGE(1) +#define G_RM_AA_TEX_EDGE2 RM_AA_TEX_EDGE(2) +#define G_RM_AA_SUB_SURF RM_AA_SUB_SURF(1) +#define G_RM_AA_SUB_SURF2 RM_AA_SUB_SURF(2) +#define G_RM_AA_PCL_SURF RM_AA_PCL_SURF(1) +#define G_RM_AA_PCL_SURF2 RM_AA_PCL_SURF(2) +#define G_RM_AA_OPA_TERR RM_AA_OPA_TERR(1) +#define G_RM_AA_OPA_TERR2 RM_AA_OPA_TERR(2) +#define G_RM_AA_TEX_TERR RM_AA_TEX_TERR(1) +#define G_RM_AA_TEX_TERR2 RM_AA_TEX_TERR(2) +#define G_RM_AA_SUB_TERR RM_AA_SUB_TERR(1) +#define G_RM_AA_SUB_TERR2 RM_AA_SUB_TERR(2) + +#define G_RM_RA_OPA_SURF RM_RA_OPA_SURF(1) +#define G_RM_RA_OPA_SURF2 RM_RA_OPA_SURF(2) + +#define G_RM_ZB_OPA_SURF RM_ZB_OPA_SURF(1) +#define G_RM_ZB_OPA_SURF2 RM_ZB_OPA_SURF(2) +#define G_RM_ZB_XLU_SURF RM_ZB_XLU_SURF(1) +#define G_RM_ZB_XLU_SURF2 RM_ZB_XLU_SURF(2) +#define G_RM_ZB_OPA_DECAL RM_ZB_OPA_DECAL(1) +#define G_RM_ZB_OPA_DECAL2 RM_ZB_OPA_DECAL(2) +#define G_RM_ZB_XLU_DECAL RM_ZB_XLU_DECAL(1) +#define G_RM_ZB_XLU_DECAL2 RM_ZB_XLU_DECAL(2) +#define G_RM_ZB_CLD_SURF RM_ZB_CLD_SURF(1) +#define G_RM_ZB_CLD_SURF2 RM_ZB_CLD_SURF(2) +#define G_RM_ZB_OVL_SURF RM_ZB_OVL_SURF(1) +#define G_RM_ZB_OVL_SURF2 RM_ZB_OVL_SURF(2) +#define G_RM_ZB_PCL_SURF RM_ZB_PCL_SURF(1) +#define G_RM_ZB_PCL_SURF2 RM_ZB_PCL_SURF(2) + +#define G_RM_OPA_SURF RM_OPA_SURF(1) +#define G_RM_OPA_SURF2 RM_OPA_SURF(2) +#define G_RM_XLU_SURF RM_XLU_SURF(1) +#define G_RM_XLU_SURF2 RM_XLU_SURF(2) +#define G_RM_CLD_SURF RM_CLD_SURF(1) +#define G_RM_CLD_SURF2 RM_CLD_SURF(2) +#define G_RM_TEX_EDGE RM_TEX_EDGE(1) +#define G_RM_TEX_EDGE2 RM_TEX_EDGE(2) +#define G_RM_PCL_SURF RM_PCL_SURF(1) +#define G_RM_PCL_SURF2 RM_PCL_SURF(2) +#define G_RM_ADD RM_ADD(1) +#define G_RM_ADD2 RM_ADD(2) +#define G_RM_NOOP RM_NOOP(1) +#define G_RM_NOOP2 RM_NOOP(2) +#define G_RM_VISCVG RM_VISCVG(1) +#define G_RM_VISCVG2 RM_VISCVG(2) +#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) +#define G_RM_PASS GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1) + +/* + * G_SETCONVERT: K0-5 + */ +#define G_CV_K0 175 +#define G_CV_K1 -43 +#define G_CV_K2 -89 +#define G_CV_K3 222 +#define G_CV_K4 114 +#define G_CV_K5 42 + +/* + * G_SETSCISSOR: interlace mode + */ +#define G_SC_NON_INTERLACE 0 +#define G_SC_ODD_INTERLACE 3 +#define G_SC_EVEN_INTERLACE 2 + +/* flags to inhibit pushing of the display list (on branch) */ +#define G_DL_PUSH 0x00 +#define G_DL_NOPUSH 0x01 + +/* + * BEGIN C-specific section: (typedef's) + */ +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/* + * Data Structures + * + * NOTE: + * The DMA transfer hardware requires 64-bit aligned, 64-bit multiple- + * sized transfers. This important hardware optimization is unfortunately + * reflected in the programming interface, with some structures + * padded and alignment enforced. + * + * Since structures are aligned to the boundary of the "worst-case" + * element, we can't depend on the C compiler to align things + * properly. + * + * 64-bit structure alignment is enforced by wrapping structures with + * unions that contain a dummy "long long int". Why this works is + * explained in the ANSI C Spec, or on page 186 of the second edition + * of K&R, "The C Programming Language". + * + * The price we pay for this is a little awkwardness referencing the + * structures through the union. There is no memory penalty, since + * all the structures are at least 64-bits the dummy alignment field + * does not increase the size of the union. + * + * Static initialization of these union structures works because + * the ANSI C spec states that static initialization for unions + * works by using the first union element. We put the dummy alignment + * field last for this reason. + * + * (it's possible a newer 64-bit compiler from MIPS might make this + * easier with a flag, but we can't wait for it...) + * + */ + +/* + * Vertex (set up for use with colors) + */ +typedef struct { + short ob[3]; /* x, y, z */ + unsigned short flag; + short tc[2]; /* texture coord */ + unsigned char cn[4]; /* color & alpha */ +} Vtx_t; + +/* + * Vertex (set up for use with normals) + */ +typedef struct { + short ob[3]; /* x, y, z */ + unsigned short flag; + short tc[2]; /* texture coord */ + signed char n[3]; /* normal */ + unsigned char a; /* alpha */ +} Vtx_tn; + +typedef union { + Vtx_t v; /* Use this one for colors */ + Vtx_tn n; /* Use this one for normals */ + long long int force_structure_alignment; +} Vtx; + +/* + * Sprite structure + */ + +typedef struct { + void *SourceImagePointer; + void *TlutPointer; + short Stride; + short SubImageWidth; + short SubImageHeight; + char SourceImageType; + char SourceImageBitSize; + short SourceImageOffsetS; + short SourceImageOffsetT; + /* 20 bytes for above */ + + /* padding to bring structure size to 64 bit allignment */ + char dummy[4]; + +} uSprite_t; + +typedef union { + uSprite_t s; + + /* Need to make sure this is 64 bit aligned */ + long long int force_structure_allignment[3]; +} uSprite; + +/* + * Triangle face + */ +typedef struct { + unsigned char flag; + unsigned char v[3]; +} Tri; + +/* + * 4x4 matrix, fixed point s15.16 format. + * 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 union { + Mtx_t m; + long long int force_structure_alignment; +} Mtx; + +/* + * Viewport + */ + +/* + * + * This magic value is the maximum INTEGER z-range of the hardware + * (there are also 16-bits of fraction, which are introduced during + * any transformations). This is not just a good idea, it's the law. + * Feeding the hardware eventual z-coordinates (after any transforms + * or scaling) bigger than this, will not work. + * + * This number is DIFFERENT than G_MAXFBZ, which is the maximum value + * you want to use to initialize the z-buffer. + * + * The reason these are different is mildly interesting, but too long + * to explain here. It is basically the result of optimizations in the + * hardware. A more generic API might hide this detail from the users, + * but we don't have the ucode to do that... + * + */ +#define G_MAXZ 0x03ff /* 10 bits of integer screen-Z precision */ + +/* + * The viewport structure elements have 2 bits of fraction, necessary + * to accomodate the sub-pixel positioning scaling for the hardware. + * This can also be exploited to handle odd-sized viewports. + * + * Accounting for these fractional bits, using the default projection + * and viewing matrices, the viewport structure is initialized thusly: + * + * (SCREEN_WD/2)*4, (SCREEN_HT/2)*4, G_MAXZ, 0, + * (SCREEN_WD/2)*4, (SCREEN_HT/2)*4, 0, 0, + */ +typedef struct { + short vscale[4]; /* scale, 2 bits fraction */ + short vtrans[4]; /* translate, 2 bits fraction */ + /* both the above arrays are padded to 64-bit boundary */ +} Vp_t; + +typedef union { + Vp_t vp; + long long int force_structure_alignment; +} Vp; + +/* + * MOVEMEM indices + * + * Each of these indexes an entry in a dmem table + * which points to a 1-4 word block of dmem in + * which to store a 1-4 word DMA. + * + */ +#ifdef F3DEX_GBI_2 +/* 0,4 are reserved by G_MTX */ +# define G_MV_MMTX 2 +# define G_MV_PMTX 6 +# define G_MV_VIEWPORT 8 +# define G_MV_LIGHT 10 +# define G_MV_POINT 12 +# define G_MV_MATRIX 14 /* NOTE: this is in moveword table */ +# define G_MVO_LOOKATX (0*24) +# define G_MVO_LOOKATY (1*24) +# define G_MVO_L0 (2*24) +# define G_MVO_L1 (3*24) +# define G_MVO_L2 (4*24) +# define G_MVO_L3 (5*24) +# define G_MVO_L4 (6*24) +# define G_MVO_L5 (7*24) +# define G_MVO_L6 (8*24) +# define G_MVO_L7 (9*24) +#else /* F3DEX_GBI_2 */ +# define G_MV_VIEWPORT 0x80 +# define G_MV_LOOKATY 0x82 +# define G_MV_LOOKATX 0x84 +# define G_MV_L0 0x86 +# define G_MV_L1 0x88 +# define G_MV_L2 0x8a +# define G_MV_L3 0x8c +# define G_MV_L4 0x8e +# define G_MV_L5 0x90 +# define G_MV_L6 0x92 +# define G_MV_L7 0x94 +# define G_MV_TXTATT 0x96 +# define G_MV_MATRIX_1 0x9e /* NOTE: this is in moveword table */ +# define G_MV_MATRIX_2 0x98 +# define G_MV_MATRIX_3 0x9a +# define G_MV_MATRIX_4 0x9c +#endif /* F3DEX_GBI_2 */ + +/* + * MOVEWORD indices + * + * Each of these indexes an entry in a dmem table + * which points to a word in dmem in dmem where + * an immediate word will be stored. + * + */ +#define G_MW_MATRIX 0x00 /* NOTE: also used by movemem */ +#define G_MW_NUMLIGHT 0x02 +#define G_MW_CLIP 0x04 +#define G_MW_SEGMENT 0x06 +#define G_MW_FOG 0x08 +#define G_MW_LIGHTCOL 0x0a +#ifdef F3DEX_GBI_2 +# define G_MW_FORCEMTX 0x0c +#else /* F3DEX_GBI_2 */ +# define G_MW_POINTS 0x0c +#endif /* F3DEX_GBI_2 */ +#define G_MW_PERSPNORM 0x0e + +/* + * These are offsets from the address in the dmem table + */ +#define G_MWO_NUMLIGHT 0x00 +#define G_MWO_CLIP_RNX 0x04 +#define G_MWO_CLIP_RNY 0x0c +#define G_MWO_CLIP_RPX 0x14 +#define G_MWO_CLIP_RPY 0x1c +#define G_MWO_SEGMENT_0 0x00 +#define G_MWO_SEGMENT_1 0x01 +#define G_MWO_SEGMENT_2 0x02 +#define G_MWO_SEGMENT_3 0x03 +#define G_MWO_SEGMENT_4 0x04 +#define G_MWO_SEGMENT_5 0x05 +#define G_MWO_SEGMENT_6 0x06 +#define G_MWO_SEGMENT_7 0x07 +#define G_MWO_SEGMENT_8 0x08 +#define G_MWO_SEGMENT_9 0x09 +#define G_MWO_SEGMENT_A 0x0a +#define G_MWO_SEGMENT_B 0x0b +#define G_MWO_SEGMENT_C 0x0c +#define G_MWO_SEGMENT_D 0x0d +#define G_MWO_SEGMENT_E 0x0e +#define G_MWO_SEGMENT_F 0x0f +#define G_MWO_FOG 0x00 +#define G_MWO_aLIGHT_1 0x00 +#define G_MWO_bLIGHT_1 0x04 +#ifdef F3DEX_GBI_2 +#define G_MWO_aLIGHT_2 0x18 +#define G_MWO_bLIGHT_2 0x1c +#define G_MWO_aLIGHT_3 0x30 +#define G_MWO_bLIGHT_3 0x34 +#define G_MWO_aLIGHT_4 0x48 +#define G_MWO_bLIGHT_4 0x4c +#define G_MWO_aLIGHT_5 0x60 +#define G_MWO_bLIGHT_5 0x64 +#define G_MWO_aLIGHT_6 0x78 +#define G_MWO_bLIGHT_6 0x7c +#define G_MWO_aLIGHT_7 0x90 +#define G_MWO_bLIGHT_7 0x94 +#define G_MWO_aLIGHT_8 0xa8 +#define G_MWO_bLIGHT_8 0xac +#else +#define G_MWO_aLIGHT_2 0x20 +#define G_MWO_bLIGHT_2 0x24 +#define G_MWO_aLIGHT_3 0x40 +#define G_MWO_bLIGHT_3 0x44 +#define G_MWO_aLIGHT_4 0x60 +#define G_MWO_bLIGHT_4 0x64 +#define G_MWO_aLIGHT_5 0x80 +#define G_MWO_bLIGHT_5 0x84 +#define G_MWO_aLIGHT_6 0xa0 +#define G_MWO_bLIGHT_6 0xa4 +#define G_MWO_aLIGHT_7 0xc0 +#define G_MWO_bLIGHT_7 0xc4 +#define G_MWO_aLIGHT_8 0xe0 +#define G_MWO_bLIGHT_8 0xe4 +#endif +#define G_MWO_MATRIX_XX_XY_I 0x00 +#define G_MWO_MATRIX_XZ_XW_I 0x04 +#define G_MWO_MATRIX_YX_YY_I 0x08 +#define G_MWO_MATRIX_YZ_YW_I 0x0c +#define G_MWO_MATRIX_ZX_ZY_I 0x10 +#define G_MWO_MATRIX_ZZ_ZW_I 0x14 +#define G_MWO_MATRIX_WX_WY_I 0x18 +#define G_MWO_MATRIX_WZ_WW_I 0x1c +#define G_MWO_MATRIX_XX_XY_F 0x20 +#define G_MWO_MATRIX_XZ_XW_F 0x24 +#define G_MWO_MATRIX_YX_YY_F 0x28 +#define G_MWO_MATRIX_YZ_YW_F 0x2c +#define G_MWO_MATRIX_ZX_ZY_F 0x30 +#define G_MWO_MATRIX_ZZ_ZW_F 0x34 +#define G_MWO_MATRIX_WX_WY_F 0x38 +#define G_MWO_MATRIX_WZ_WW_F 0x3c +#define G_MWO_POINT_RGBA 0x10 +#define G_MWO_POINT_ST 0x14 +#define G_MWO_POINT_XYSCREEN 0x18 +#define G_MWO_POINT_ZSCREEN 0x1c + +/* + * Light structure. + * + * Note: only directional (infinite) lights are currently supported. + * + * Note: the weird order is for the DMEM alignment benefit of + * the microcode. + * + */ + +typedef struct { + unsigned char col[3]; /* diffuse light value (rgba) */ + char pad1; + unsigned char colc[3]; /* copy of diffuse light value (rgba) */ + char pad2; + signed char dir[3]; /* direction of light (normalized) */ + char pad3; +} Light_t; + +typedef struct { + unsigned char col[3]; /* ambient light value (rgba) */ + char pad1; + unsigned char colc[3]; /* copy of ambient light value (rgba) */ + char pad2; +} Ambient_t; + +typedef struct { + int x1,y1,x2,y2; /* texture offsets for highlight 1/2 */ +} Hilite_t; + +typedef union { + Light_t l; + long long int force_structure_alignment[2]; +} Light; + +typedef union { + Ambient_t l; + long long int force_structure_alignment[1]; +} Ambient; + +typedef struct { + Ambient a; + Light l[7]; +} Lightsn; + +typedef struct { + Ambient a; + Light l[1]; +} Lights0; + +typedef struct { + Ambient a; + Light l[1]; +} Lights1; + +typedef struct { + Ambient a; + Light l[2]; +} Lights2; + +typedef struct { + Ambient a; + Light l[3]; +} Lights3; + +typedef struct { + Ambient a; + Light l[4]; +} Lights4; + +typedef struct { + Ambient a; + Light l[5]; +} Lights5; + +typedef struct { + Ambient a; + Light l[6]; +} Lights6; + +typedef struct { + Ambient a; + Light l[7]; +} Lights7; + +typedef struct { + Light l[2]; +} LookAt; + +typedef union { + Hilite_t h; + long int force_structure_alignment[4]; +} Hilite; + +#define gdSPDefLights0(ar,ag,ab) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ { 0, 0, 0},0,{ 0, 0, 0},0,{ 0, 0, 0},0}}} } +#define gdSPDefLights1(ar,ag,ab,r1,g1,b1,x1,y1,z1) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}} } +#define gdSPDefLights2(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ + {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}} } +#define gdSPDefLights3(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ + {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \ + {{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}} } +#define gdSPDefLights4(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ + {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \ + {{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \ + {{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}} } +#define gdSPDefLights5(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4,r5,g5,b5,x5,y5,z5) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ + {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \ + {{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \ + {{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}, \ + {{ {r5,g5,b5},0,{r5,g5,b5},0,{x5,y5,z5},0}}} } + + +#define gdSPDefLights6(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4,r5,g5,b5,x5,y5,z5,r6,g6,b6,x6,y6,z6) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ + {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \ + {{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \ + {{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}, \ + {{ {r5,g5,b5},0,{r5,g5,b5},0,{x5,y5,z5},0}}, \ + {{ {r6,g6,b6},0,{r6,g6,b6},0,{x6,y6,z6},0}}} } + + +#define gdSPDefLights7(ar,ag,ab,r1,g1,b1,x1,y1,z1,r2,g2,b2,x2,y2,z2,r3,g3,b3,x3,y3,z3,r4,g4,b4,x4,y4,z4,r5,g5,b5,x5,y5,z5,r6,g6,b6,x6,y6,z6,r7,g7,b7,x7,y7,z7) \ + { {{ {ar,ag,ab},0,{ar,ag,ab},0}}, \ + {{{ {r1,g1,b1},0,{r1,g1,b1},0,{x1,y1,z1},0}}, \ + {{ {r2,g2,b2},0,{r2,g2,b2},0,{x2,y2,z2},0}}, \ + {{ {r3,g3,b3},0,{r3,g3,b3},0,{x3,y3,z3},0}}, \ + {{ {r4,g4,b4},0,{r4,g4,b4},0,{x4,y4,z4},0}}, \ + {{ {r5,g5,b5},0,{r5,g5,b5},0,{x5,y5,z5},0}}, \ + {{ {r6,g6,b6},0,{r6,g6,b6},0,{x6,y6,z6},0}}, \ + {{ {r7,g7,b7},0,{r7,g7,b7},0,{x7,y7,z7},0}}} } + + +#define gdSPDefLookAt(rightx,righty,rightz,upx,upy,upz) \ + { {{ {{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 + */ +typedef struct { + int cmd:8; + unsigned int par:8; + unsigned int len:16; + uintptr_t addr; +} Gdma; + +/* + * Graphics Immediate Mode Packet types + */ +typedef struct { + int cmd:8; + int pad:24; + Tri tri; +} Gtri; + +typedef struct { + int cmd:8; + int pad1:24; + int pad2:24; + unsigned char param:8; +} Gpopmtx; + +/* + * typedef struct { + * int cmd:8; + * int pad0:24; + * int pad1:4; + * int number:4; + * int base:24; + * } Gsegment; + */ +typedef struct { + int cmd:8; + int pad0:8; + int mw_index:8; + int number:8; + int pad1:8; + int base:24; +} Gsegment; + +typedef struct { + int cmd:8; + int pad0:8; + int sft:8; + int len:8; + unsigned int data:32; +} GsetothermodeL; + +typedef struct { + int cmd:8; + int pad0:8; + int sft:8; + int len:8; + unsigned int data:32; +} GsetothermodeH; + +typedef struct { + unsigned char cmd; + unsigned char lodscale; + unsigned char tile; + unsigned char on; + unsigned short s; + unsigned short t; +} Gtexture; + +typedef struct { + int cmd:8; + int pad:24; + Tri line; +} Gline3D; + +typedef struct { + int cmd:8; + int pad1:24; + short int pad2; + short int scale; +} Gperspnorm; + + +/* + * RDP Packet types + */ +typedef struct { + int cmd:8; + unsigned int fmt:3; + unsigned int siz:2; + unsigned int pad:7; + unsigned int wd:12; /* really only 10 bits, extra */ + uintptr_t dram; /* to account for 1024 */ +} Gsetimg; + +typedef struct { + int cmd:8; + unsigned int muxs0:24; + unsigned int muxs1:32; +} Gsetcombine; + +typedef struct { + int cmd:8; + unsigned char pad; + unsigned char prim_min_level; + unsigned char prim_level; + unsigned long color; +} Gsetcolor; + +typedef struct { + int cmd:8; + int x0:10; + int x0frac:2; + int y0:10; + int y0frac:2; + unsigned int pad:8; + int x1:10; + int x1frac:2; + int y1:10; + int y1frac:2; +} Gfillrect; + +typedef struct { + int cmd:8; + unsigned int fmt:3; + unsigned int siz:2; + unsigned int pad0:1; + unsigned int line:9; + unsigned int tmem:9; + unsigned int pad1:5; + unsigned int tile:3; + unsigned int palette:4; + unsigned int ct:1; + unsigned int mt:1; + unsigned int maskt:4; + unsigned int shiftt:4; + unsigned int cs:1; + unsigned int ms:1; + unsigned int masks:4; + unsigned int shifts:4; +} Gsettile; + +typedef struct { + int cmd:8; + unsigned int sl:12; + unsigned int tl:12; + int pad:5; + unsigned int tile:3; + unsigned int sh:12; + unsigned int th:12; +} Gloadtile; + +typedef Gloadtile Gloadblock; + +typedef Gloadtile Gsettilesize; + +typedef Gloadtile Gloadtlut; + +typedef struct { + unsigned int cmd:8; /* command */ + unsigned int xl:12; /* X coordinate of upper left */ + unsigned int yl:12; /* Y coordinate of upper left */ + unsigned int pad1:5; /* Padding */ + unsigned int tile:3; /* Tile descriptor index */ + unsigned int xh:12; /* X coordinate of lower right */ + unsigned int yh:12; /* Y coordinate of lower right */ + unsigned int s:16; /* S texture coord at top left */ + unsigned int t:16; /* T texture coord at top left */ + unsigned int dsdx:16;/* Change in S per change in X */ + unsigned int dtdy:16;/* Change in T per change in Y */ +} Gtexrect; + +/* + * Textured rectangles are 128 bits not 64 bits + */ +typedef struct { + unsigned long w0; + unsigned long w1; + 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; +} 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; + Gpopmtx popmtx; + Gsegment segment; + GsetothermodeH setothermodeH; + GsetothermodeL setothermodeL; + Gtexture texture; + Gperspnorm perspnorm; + Gsetimg setimg; + Gsetcombine setcombine; + Gsetcolor setcolor; + Gfillrect fillrect; /* use for setscissor also */ + Gsettile settile; + Gloadtile loadtile; /* use for loadblock also, th is dxt */ + Gsettilesize settilesize; + Gloadtlut loadtlut; +#endif + long long int force_structure_alignment; +} Gfx; + +/* + * Macros to assemble the graphics display list + */ + +/* + * DMA macros + */ +#define gDma0p(pkt, c, s, l) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL((c), 24, 8) | _SHIFTL((l), 0, 24); \ + _g->words.w1 = (uintptr_t)(s); \ +} + +#define gsDma0p(c, s, l) \ +{{ \ + _SHIFTL((c), 24, 8) | _SHIFTL((l), 0, 24), (uintptr_t)(s) \ +}} + +#define gDma1p(pkt, c, s, l, p) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL((c), 24, 8) | _SHIFTL((p), 16, 8) | \ + _SHIFTL((l), 0, 16)); \ + _g->words.w1 = (uintptr_t)(s); \ +} + +#define gsDma1p(c, s, l, p) \ +{{ \ + (_SHIFTL((c), 24, 8) | _SHIFTL((p), 16, 8) | \ + _SHIFTL((l), 0, 16)), \ + (uintptr_t)(s) \ +}} + +#define gDma2p(pkt, c, adrs, len, idx, ofs) \ +{ \ + 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); \ +} +#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) \ +}} + +#define gSPNoOp(pkt) gDma0p(pkt, G_SPNOOP, 0, 0) +#define gsSPNoOp() gsDma0p(G_SPNOOP, 0, 0) + +#ifdef F3DEX_GBI_2 +# define gSPMatrix(pkt, m, p) \ + gDma2p((pkt),G_MTX,(m),sizeof(Mtx),(p)^G_MTX_PUSH,0) +# define gsSPMatrix(m, p) \ + gsDma2p( G_MTX,(m),sizeof(Mtx),(p)^G_MTX_PUSH,0) +#else /* F3DEX_GBI_2 */ +# define gSPMatrix(pkt, m, p) gDma1p(pkt, G_MTX, m, sizeof(Mtx), p) +# define gsSPMatrix(m, p) gsDma1p(G_MTX, m, sizeof(Mtx), p) +#endif /* F3DEX_GBI_2 */ + +#if defined(F3DEX_GBI_2) +/* + * F3DEX_GBI_2: G_VTX GBI format was changed. + * + * +--------+----+---+---+----+------+-+ + * G_VTX | cmd:8 |0000| n:8 |0000|v0+n:7|0| + * +-+---+--+----+---+---+----+------+-+ + * | |seg| address | + * +-+---+-----------------------------+ + */ +# define gSPVertex(pkt, v, n, v0) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = \ + _SHIFTL(G_VTX,24,8)|_SHIFTL((n),12,8)|_SHIFTL((v0)+(n),1,7); \ + _g->words.w1 = (uintptr_t)(v); \ +} +# define gsSPVertex(v, n, v0) \ +{{ \ + (_SHIFTL(G_VTX,24,8)|_SHIFTL((n),12,8)|_SHIFTL((v0)+(n),1,7)), \ + (uintptr_t)(v) \ +}} +#elif (defined(F3DEX_GBI)||defined(F3DLP_GBI)) +/* + * F3DEX_GBI: G_VTX GBI format was changed to support 64 vertice. + * + * +--------+--------+------+----------+ + * G_VTX | cmd:8 | v0:8 | n:6 |length:10 | + * +-+---+--+--------+------+----------+ + * | |seg| address | + * +-+---+-----------------------------+ + */ +# define gSPVertex(pkt, v, n, v0) \ + gDma1p((pkt),G_VTX,(v),((n)<<10)|(sizeof(Vtx)*(n)-1),(v0)*2) +# define gsSPVertex(v, n, v0) \ + gsDma1p(G_VTX,(v),((n)<<10)|(sizeof(Vtx)*(n)-1),(v0)*2) +#else +# define gSPVertex(pkt, v, n, v0) \ + gDma1p(pkt, G_VTX, v, sizeof(Vtx)*(n),((n)-1)<<4|(v0)) +# define gsSPVertex(v, n, v0) \ + gsDma1p(G_VTX, v, sizeof(Vtx)*(n), ((n)-1)<<4|(v0)) +#endif + + +#ifdef F3DEX_GBI_2 +# define gSPViewport(pkt, v) \ + gDma2p((pkt), G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT, 0) +# define gsSPViewport(v) \ + gsDma2p( G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT, 0) +#else /* F3DEX_GBI_2 */ +# define gSPViewport(pkt,v) \ + gDma1p((pkt), G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT) +# define gsSPViewport(v) \ + gsDma1p( G_MOVEMEM, (v), sizeof(Vp), G_MV_VIEWPORT) +#endif /* F3DEX_GBI_2 */ + +#define gSPDisplayList(pkt,dl) gDma1p(pkt,G_DL,dl,0,G_DL_PUSH) +#define gsSPDisplayList( dl) gsDma1p( G_DL,dl,0,G_DL_PUSH) + +#define gSPBranchList(pkt,dl) gDma1p(pkt,G_DL,dl,0,G_DL_NOPUSH) +#define gsSPBranchList( dl) gsDma1p( G_DL,dl,0,G_DL_NOPUSH) + +#define gSPSprite2DBase(pkt, s) gDma1p(pkt, G_SPRITE2D_BASE, s, sizeof(uSprite), 0) +#define gsSPSprite2DBase(s) gsDma1p(G_SPRITE2D_BASE, s, sizeof(uSprite), 0) + +/* + * RSP short command (no DMA required) macros + */ +#define gImmp0(pkt, c) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL((c), 24, 8); \ +} + +#define gsImmp0(c) \ +{{ \ + _SHIFTL((c), 24, 8) \ +}} + +#define gImmp1(pkt, c, p0) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL((c), 24, 8); \ + _g->words.w1 = (uintptr_t)(p0); \ +} + +#define gsImmp1(c, p0) \ +{{ \ + _SHIFTL((c), 24, 8), (uintptr_t)(p0) \ +}} + +#define gImmp2(pkt, c, p0, p1) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL((c), 24, 8); \ + _g->words.w1 = _SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8); \ +} + +#define gsImmp2(c, p0, p1) \ +{{ \ + _SHIFTL((c), 24, 8), _SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8)\ +}} + +#define gImmp3(pkt, c, p0, p1, p2) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL((c), 24, 8); \ + _g->words.w1 = (_SHIFTL((p0), 16, 16) | _SHIFTL((p1), 8, 8) | \ + _SHIFTL((p2), 0, 8)); \ +} + +#define gsImmp3(c, p0, p1, p2) \ +{{ \ + _SHIFTL((c), 24, 8), (_SHIFTL((p0), 16, 16) | \ + _SHIFTL((p1), 8, 8) | _SHIFTL((p2), 0, 8))\ +}} + +#define gImmp21(pkt, c, p0, p1, dat) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL((c), 24, 8) | _SHIFTL((p0), 8, 16) | \ + _SHIFTL((p1), 0, 8)); \ + _g->words.w1 = (uintptr_t) (dat); \ +} + +#define gsImmp21(c, p0, p1, dat) \ +{{ \ + _SHIFTL((c), 24, 8) | _SHIFTL((p0), 8, 16) | _SHIFTL((p1), 0, 8),\ + (uintptr_t) (dat) \ +}} + +#ifdef F3DEX_GBI_2 +#define gMoveWd(pkt, index, offset, data) \ + gDma1p((pkt), G_MOVEWORD, data, offset, index) +#define gsMoveWd( index, offset, data) \ + gsDma1p( G_MOVEWORD, data, offset, index) +#else /* F3DEX_GBI_2 */ +#define gMoveWd(pkt, index, offset, data) \ + gImmp21((pkt), G_MOVEWORD, offset, index, data) +#define gsMoveWd( index, offset, data) \ + gsImmp21( G_MOVEWORD, offset, index, data) +#endif /* F3DEX_GBI_2 */ + +/* Sprite immediate macros, there is also a sprite dma macro above */ + +#define gSPSprite2DScaleFlip(pkt, sx, sy, fx, fy) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SPRITE2D_SCALEFLIP, 24, 8) | \ + _SHIFTL((fx), 8, 8) | \ + _SHIFTL((fy), 0, 8)); \ + _g->words.w1 = (_SHIFTL((sx), 16, 16) | \ + _SHIFTL((sy), 0, 16)); \ +} + +#define gsSPSprite2DScaleFlip(sx, sy, fx, fy) \ +{{ \ + (_SHIFTL(G_SPRITE2D_SCALEFLIP, 24, 8) | \ + _SHIFTL((fx), 8, 8) | \ + _SHIFTL((fy), 0, 8)), \ + (_SHIFTL((sx), 16, 16) | \ + _SHIFTL((sy), 0, 16)) \ +}} + +#define gSPSprite2DDraw(pkt, px, py) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SPRITE2D_DRAW, 24, 8)); \ + _g->words.w1 = (_SHIFTL((px), 16, 16) | \ + _SHIFTL((py), 0, 16)); \ +} + +#define gsSPSprite2DDraw(px, py) \ +{{ \ + (_SHIFTL(G_SPRITE2D_DRAW, 24, 8)), \ + (_SHIFTL((px), 16, 16) | \ + _SHIFTL((py), 0, 16)) \ +}} + + +/* + * Note: the SP1Triangle() and line macros multiply the vertex indices + * by 10, this is an optimization for the microcode. + */ +#if (defined(F3DLP_GBI)||defined(F3DEX_GBI)) +# define __gsSP1Triangle_w1(v0, v1, v2) \ + (_SHIFTL((v0)*2,16,8)|_SHIFTL((v1)*2,8,8)|_SHIFTL((v2)*2,0,8)) +# define __gsSP1Triangle_w1f(v0, v1, v2, flag) \ + (((flag) == 0) ? __gsSP1Triangle_w1(v0, v1, v2): \ + ((flag) == 1) ? __gsSP1Triangle_w1(v1, v2, v0): \ + __gsSP1Triangle_w1(v2, v0, v1)) +# define __gsSPLine3D_w1(v0, v1, wd) \ + (_SHIFTL((v0)*2,16,8)|_SHIFT((v1)*2,8,8)|_SHIFT((wd),0,8)) +# define __gsSPLine3D_w1f(v0, v1, wd, flag) \ + (((flag) == 0) ? __gsSPLine3D_w1(v0, v1, wd): \ + __gsSPLine3D_w1(v1, v0, wd)) +# define __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag) \ + (((flag) == 0) ? __gsSP1Triangle_w1(v0, v1, v2): \ + ((flag) == 1) ? __gsSP1Triangle_w1(v1, v2, v3): \ + ((flag) == 2) ? __gsSP1Triangle_w1(v2, v3, v0): \ + __gsSP1Triangle_w1(v3, v0, v1)) +# define __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ + (((flag) == 0) ? __gsSP1Triangle_w1(v0, v2, v3): \ + ((flag) == 1) ? __gsSP1Triangle_w1(v1, v3, v0): \ + ((flag) == 2) ? __gsSP1Triangle_w1(v2, v0, v1): \ + __gsSP1Triangle_w1(v3, v1, v2)) +#else +# define __gsSP1Triangle_w1f(v0, v1, v2, flag) \ + (_SHIFTL((flag), 24,8)|_SHIFTL((v0)*10,16,8)| \ + _SHIFTL((v1)*10, 8,8)|_SHIFTL((v2)*10, 0,8)) +# define __gsSPLine3D_w1f(v0, v1, wd, flag) \ + (_SHIFTL((flag), 24,8)|_SHIFTL((v0)*10,16,8)| \ + _SHIFTL((v1)*10, 8,8)|_SHIFTL((wd), 0,8)) +#endif + +#ifdef F3DEX_GBI_2 +/*** + *** 1 Triangle + ***/ +#define gSP1Triangle(pkt, v0, v1, v2, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_TRI1, 24, 8)| \ + __gsSP1Triangle_w1f(v0, v1, v2, flag); \ + _g->words.w1 = 0; \ +} +#define gsSP1Triangle(v0, v1, v2, flag) \ +{{ \ + _SHIFTL(G_TRI1, 24, 8)|__gsSP1Triangle_w1f(v0, v1, v2, flag), \ + 0 \ +}} + +/*** + *** Line + ***/ +#define gSPLine3D(pkt, v0, v1, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8)| \ + __gsSPLine3D_w1f(v0, v1, 0, flag); \ + _g->words.w1 = 0; \ +} +#define gsSPLine3D(v0, v1, flag) \ +{{ \ + _SHIFTL(G_LINE3D, 24, 8)|__gsSPLine3D_w1f(v0, v1, 0, flag), \ + 0 \ +}} + +/*** + *** LineW + ***/ +/* these macros are the same as SPLine3D, except they have an + * additional parameter for width. The width is added to the "minimum" + * thickness, which is 1.5 pixels. The units for width are in + * half-pixel units, so a width of 1 translates to (.5 + 1.5) or + * a 2.0 pixels wide line. + */ +#define gSPLineW3D(pkt, v0, v1, wd, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8)| \ + __gsSPLine3D_w1f(v0, v1, wd, flag); \ + _g->words.w1 = 0; \ +} +#define gsSPLineW3D(v0, v1, wd, flag) \ +{{ \ + _SHIFTL(G_LINE3D, 24, 8)|__gsSPLine3D_w1f(v0, v1, wd, flag), \ + 0 \ +}} + +/*** + *** 1 Quadrangle + ***/ +#define gSP1Quadrangle(pkt, v0, v1, v2, v3, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_QUAD, 24, 8)| \ + __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)); \ + _g->words.w1 = __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag); \ +} + +#define gsSP1Quadrangle(v0, v1, v2, v3, flag) \ +{{ \ + (_SHIFTL(G_QUAD, 24, 8)| \ + __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)), \ + __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ +}} +#else /* F3DEX_GBI_2 */ + +/*** + *** 1 Triangle + ***/ +#define gSP1Triangle(pkt, v0, v1, v2, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_TRI1, 24, 8); \ + _g->words.w1 = __gsSP1Triangle_w1f(v0, v1, v2, flag); \ +} +#define gsSP1Triangle(v0, v1, v2, flag) \ +{{ \ + _SHIFTL(G_TRI1, 24, 8), \ + __gsSP1Triangle_w1f(v0, v1, v2, flag) \ +}} + +/*** + *** Line + ***/ +#define gSPLine3D(pkt, v0, v1, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8); \ + _g->words.w1 = __gsSPLine3D_w1f(v0, v1, 0, flag); \ +} +#define gsSPLine3D(v0, v1, flag) \ +{{ \ + _SHIFTL(G_LINE3D, 24, 8), \ + __gsSPLine3D_w1f(v0, v1, 0, flag) \ +}} + +/*** + *** LineW + ***/ +/* these macros are the same as SPLine3D, except they have an + * additional parameter for width. The width is added to the "minimum" + * thickness, which is 1.5 pixels. The units for width are in + * half-pixel units, so a width of 1 translates to (.5 + 1.5) or + * a 2.0 pixels wide line. + */ +#define gSPLineW3D(pkt, v0, v1, wd, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_LINE3D, 24, 8); \ + _g->words.w1 = __gsSPLine3D_w1f(v0, v1, wd, flag); \ +} +#define gsSPLineW3D(v0, v1, wd, flag) \ +{{ \ + _SHIFTL(G_LINE3D, 24, 8), \ + __gsSPLine3D_w1f(v0, v1, wd, flag) \ +}} + +/*** + *** 1 Quadrangle + ***/ +#define gSP1Quadrangle(pkt, v0, v1, v2, v3, flag) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TRI2, 24, 8)| \ + __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)); \ + _g->words.w1 = __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag); \ +} + +#define gsSP1Quadrangle(v0, v1, v2, v3, flag) \ +{{ \ + (_SHIFTL(G_TRI2, 24, 8)| \ + __gsSP1Quadrangle_w1f(v0, v1, v2, v3, flag)), \ + __gsSP1Quadrangle_w2f(v0, v1, v2, v3, flag) \ +}} +#endif /* F3DEX_GBI_2 */ + +#if (defined(F3DLP_GBI)||defined(F3DEX_GBI)) +/*** + *** 2 Triangles + ***/ +#define gSP2Triangles(pkt, v00, v01, v02, flag0, v10, v11, v12, flag1) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TRI2, 24, 8)| \ + __gsSP1Triangle_w1f(v00, v01, v02, flag0)); \ + _g->words.w1 = __gsSP1Triangle_w1f(v10, v11, v12, flag1); \ +} + +#define gsSP2Triangles(v00, v01, v02, flag0, v10, v11, v12, flag1) \ +{{ \ + (_SHIFTL(G_TRI2, 24, 8)| \ + __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)) +#define gSPCullDisplayList(pkt,vstart,vend) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_CULLDL, 24, 8) | \ + _SHIFTL((vstart)*2, 0, 16); \ + _g->words.w1 = _SHIFTL((vend)*2, 0, 16); \ +} + +#define gsSPCullDisplayList(vstart,vend) \ +{{ \ + _SHIFTL(G_CULLDL, 24, 8) | _SHIFTL((vstart)*2, 0, 16), \ + _SHIFTL((vend)*2, 0, 16) \ +}} + +#else +#define gSPCullDisplayList(pkt,vstart,vend) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_CULLDL, 24, 8) | \ + ((0x0f & (vstart))*40); \ + _g->words.w1 = (unsigned int)((0x0f & ((vend)+1))*40); \ +} + +#define gsSPCullDisplayList(vstart,vend) \ +{{ \ + _SHIFTL(G_CULLDL, 24, 8) | ((0x0f & (vstart))*40), \ + ((0x0f & ((vend)+1))*40) \ +}} +#endif + +#define gSPSegment(pkt, segment, base) \ + gMoveWd(pkt, G_MW_SEGMENT, (segment)*4, base) +#define gsSPSegment(segment, base) \ + gsMoveWd( G_MW_SEGMENT, (segment)*4, base) + +/* + * Clipping Macros + */ +#define FR_NEG_FRUSTRATIO_1 0x00000001 +#define FR_POS_FRUSTRATIO_1 0x0000ffff +#define FR_NEG_FRUSTRATIO_2 0x00000002 +#define FR_POS_FRUSTRATIO_2 0x0000fffe +#define FR_NEG_FRUSTRATIO_3 0x00000003 +#define FR_POS_FRUSTRATIO_3 0x0000fffd +#define FR_NEG_FRUSTRATIO_4 0x00000004 +#define FR_POS_FRUSTRATIO_4 0x0000fffc +#define FR_NEG_FRUSTRATIO_5 0x00000005 +#define FR_POS_FRUSTRATIO_5 0x0000fffb +#define FR_NEG_FRUSTRATIO_6 0x00000006 +#define FR_POS_FRUSTRATIO_6 0x0000fffa +/* + * r should be one of: FRUSTRATIO_1, FRUSTRATIO_2, FRUSTRATIO_3, ... FRUSTRATIO_6 + */ +#define gSPClipRatio(pkt, r) \ +{ \ + gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RNX, FR_NEG_##r); \ + gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RNY, FR_NEG_##r); \ + gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RPX, FR_POS_##r); \ + gMoveWd(pkt, G_MW_CLIP, G_MWO_CLIP_RPY, FR_POS_##r); \ +} + +#define gsSPClipRatio(r) \ + gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RNX, FR_NEG_##r), \ + gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RNY, FR_NEG_##r), \ + gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RPX, FR_POS_##r), \ + gsMoveWd(G_MW_CLIP, G_MWO_CLIP_RPY, FR_POS_##r) + +/* + * Insert values into Matrix + * + * where = element of matrix (byte offset) + * num = new element (32 bit value replacing 2 int or 2 frac matrix + * componants + */ +#ifdef F3DEX_GBI_2 +#define gSPInsertMatrix(pkt, where, num) \ + ERROR!! gSPInsertMatrix is no longer supported. +#define gsSPInsertMatrix(where, num) \ + ERROR!! gsSPInsertMatrix is no longer supported. +#else +#define gSPInsertMatrix(pkt, where, num) \ + gMoveWd(pkt, G_MW_MATRIX, where, num) +#define gsSPInsertMatrix(where, num) \ + gsMoveWd(G_MW_MATRIX, where, num) +#endif + +/* + * Load new matrix directly + * + * mptr = pointer to matrix + */ +#ifdef F3DEX_GBI_2 +#define gSPForceMatrix(pkt, mptr) \ +{ gDma2p((pkt),G_MOVEMEM,(mptr),sizeof(Mtx),G_MV_MATRIX,0); \ + gMoveWd((pkt), G_MW_FORCEMTX,0,0x00010000); \ +} +#define gsSPForceMatrix(mptr) \ + gsDma2p(G_MOVEMEM,(mptr),sizeof(Mtx),G_MV_MATRIX,0), \ + gsMoveWd(G_MW_FORCEMTX,0,0x00010000) + +#else /* F3DEX_GBI_2 */ +#define gSPForceMatrix(pkt, mptr) \ +{ \ + gDma1p(pkt, G_MOVEMEM, mptr, 16, G_MV_MATRIX_1); \ + gDma1p(pkt, G_MOVEMEM, (char *)(mptr)+16, 16, G_MV_MATRIX_2); \ + gDma1p(pkt, G_MOVEMEM, (char *)(mptr)+32, 16, G_MV_MATRIX_3); \ + gDma1p(pkt, G_MOVEMEM, (char *)(mptr)+48, 16, G_MV_MATRIX_4); \ +} +#define gsSPForceMatrix(mptr) \ + gsDma1p( G_MOVEMEM, mptr, 16, G_MV_MATRIX_1), \ + gsDma1p( G_MOVEMEM, (char *)(mptr)+16, 16, G_MV_MATRIX_2), \ + gsDma1p( G_MOVEMEM, (char *)(mptr)+32, 16, G_MV_MATRIX_3), \ + gsDma1p( G_MOVEMEM, (char *)(mptr)+48, 16, G_MV_MATRIX_4) +#endif /* F3DEX_GBI_2 */ + +/* + * Insert values into Points + * + * point = point number 0-15 + * where = which element of point to modify (byte offset into point) + * num = new value (32 bit) + */ +#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) +# define gSPModifyVertex(pkt, vtx, where, val) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = (_SHIFTL(G_MODIFYVTX,24,8)| \ + _SHIFTL((where),16,8)|_SHIFTL((vtx)*2,0,16)); \ + _g->words.w1 = (unsigned int)(val); \ +} +# define gsSPModifyVertex(vtx, where, val) \ +{{ \ + _SHIFTL(G_MODIFYVTX,24,8)| \ + _SHIFTL((where),16,8)|_SHIFTL((vtx)*2,0,16), \ + (unsigned int)(val) \ +}} +#else +# define gSPModifyVertex(pkt, vtx, where, val) \ + gMoveWd(pkt, G_MW_POINTS, (vtx)*40+(where), val) +# define gsSPModifyVertex(vtx, where, val) \ + gsMoveWd(G_MW_POINTS, (vtx)*40+(where), val) +#endif + +#if (defined(F3DEX_GBI)||defined(F3DLP_GBI)) +/* + * gSPBranchLessZ Branch DL if (vtx.z) less than or equal (zval). + * + * dl = DL branch to + * vtx = Vertex + * zval = Screen depth + * near = Near plane + * far = Far plane + * flag = G_BZ_PERSP or G_BZ_ORTHO + */ + +#define G_BZ_PERSP 0 +#define G_BZ_ORTHO 1 + +#define G_DEPTOZSrg(zval, near, far, flag, zmin, zmax) \ +(((unsigned int)FTOFIX32(((flag) == G_BZ_PERSP ? \ + (1.0f-(float)(near)/(float)(zval)) / \ + (1.0f-(float)(near)/(float)(far )) : \ + ((float)(zval) - (float)(near)) / \ + ((float)(far ) - (float)(near))))) * \ + (((int)((zmax) - (zmin)))&~1) + (int)FTOFIX32(zmin)) + +#define G_DEPTOZS(zval, near, far, flag) \ + G_DEPTOZSrg(zval, near, far, flag, 0, G_MAXZ) + +#define gSPBranchLessZrg(pkt, dl, vtx, zval, near, far, flag, zmin, zmax) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = _SHIFTL(G_RDPHALF_1,24,8); \ + _g->words.w1 = (uintptr_t)(dl); \ + _g = (Gfx *)(pkt); \ + _g->words.w0 = (_SHIFTL(G_BRANCH_Z,24,8)| \ + _SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12)); \ + _g->words.w1 = G_DEPTOZSrg(zval, near, far, flag, zmin, zmax); \ +} + +#define gsSPBranchLessZrg(dl, vtx, zval, near, far, flag, zmin, zmax) \ +{{ _SHIFTL(G_RDPHALF_1,24,8), \ + (uintptr_t)(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), }} + +#define gSPBranchLessZ(pkt, dl, vtx, zval, near, far, flag) \ + gSPBranchLessZrg(pkt, dl, vtx, zval, near, far, flag, 0, G_MAXZ) +#define gsSPBranchLessZ(dl, vtx, zval, near, far, flag) \ + gsSPBranchLessZrg(dl, vtx, zval, near, far, flag, 0, G_MAXZ) + +/* + * gSPBranchLessZraw Branch DL if (vtx.z) less than or equal (raw zval). + * + * dl = DL branch to + * vtx = Vertex + * zval = Raw value of screen depth + */ +#define gSPBranchLessZraw(pkt, dl, vtx, zval) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = _SHIFTL(G_RDPHALF_1,24,8); \ + _g->words.w1 = (uintptr_t)(dl); \ + _g = (Gfx *)(pkt); \ + _g->words.w0 = (_SHIFTL(G_BRANCH_Z,24,8)| \ + _SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12)); \ + _g->words.w1 = (unsigned int)(zval); \ +} + +#define gsSPBranchLessZraw(dl, vtx, zval) \ +{{ _SHIFTL(G_RDPHALF_1,24,8), \ + (uintptr_t)(dl), }}, \ +{{ _SHIFTL(G_BRANCH_Z,24,8)|_SHIFTL((vtx)*5,12,12)|_SHIFTL((vtx)*2,0,12),\ + (unsigned int)(zval), }} + +/* + * gSPLoadUcode RSP loads specified ucode. + * + * uc_start = ucode text section start + * uc_dstart = ucode data section start + */ +#define gSPLoadUcodeEx(pkt, uc_start, uc_dstart, uc_dsize) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = _SHIFTL(G_RDPHALF_1,24,8); \ + _g->words.w1 = (uintptr_t)(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); \ +} + +#define gsSPLoadUcodeEx(uc_start, uc_dstart, uc_dsize) \ +{{ _SHIFTL(G_RDPHALF_1,24,8), \ + (uintptr_t)(uc_dstart), }}, \ +{{ _SHIFTL(G_LOAD_UCODE,24,8)| \ + _SHIFTL((int)(uc_dsize)-1,0,16), \ + (uintptr_t)(uc_start), }} + +#define gSPLoadUcode(pkt, uc_start, uc_dstart) \ + gSPLoadUcodeEx((pkt), (uc_start), (uc_dstart), SP_UCODE_DATA_SIZE) +#define gsSPLoadUcode(uc_start, uc_dstart) \ + gsSPLoadUcodeEx((uc_start), (uc_dstart), SP_UCODE_DATA_SIZE) + +#define gSPLoadUcodeL(pkt, ucode) \ + gSPLoadUcode((pkt), OS_K0_TO_PHYSICAL(&##ucode##TextStart), \ + OS_K0_TO_PHYSICAL(&##ucode##DataStart)) +#define gsSPLoadUcodeL(ucode) \ + gsSPLoadUcode(OS_K0_TO_PHYSICAL(&##ucode##TextStart), \ + OS_K0_TO_PHYSICAL(&##ucode##DataStart)) +#endif + +#ifdef F3DEX_GBI_2 +/* + * gSPDma_io DMA to/from DMEM/IMEM for DEBUG. + */ +#define gSPDma_io(pkt, flag, dmem, dram, size) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = _SHIFTL(G_DMA_IO,24,8)|_SHIFTL((flag),23,1)| \ + _SHIFTL((dmem)/8,13,10)|_SHIFTL((size)-1,0,12); \ + _g->words.w1 = (uintptr_t)(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) \ +}} + +#define gSPDmaRead(pkt,dmem,dram,size) gSPDma_io((pkt),0,(dmem),(dram),(size)) +#define gsSPDmaRead(dmem,dram,size) gsSPDma_io(0,(dmem),(dram),(size)) +#define gSPDmaWrite(pkt,dmem,dram,size) gSPDma_io((pkt),1,(dmem),(dram),(size)) +#define gsSPDmaWrite(dmem,dram,size) gsSPDma_io(1,(dmem),(dram),(size)) +#endif + +/* + * Lighting Macros + */ +#ifdef F3DEX_GBI_2 +# define NUML(n) ((n)*24) +#else +# define NUML(n) (((n)+1)*32 + 0x80000000) +#endif +#define NUMLIGHTS_0 1 +#define NUMLIGHTS_1 1 +#define NUMLIGHTS_2 2 +#define NUMLIGHTS_3 3 +#define NUMLIGHTS_4 4 +#define NUMLIGHTS_5 5 +#define NUMLIGHTS_6 6 +#define NUMLIGHTS_7 7 +/* + * n should be one of: NUMLIGHTS_0, NUMLIGHTS_1, ..., NUMLIGHTS_7 + * NOTE: in addition to the number of directional lights specified, + * there is always 1 ambient light + */ +#define gSPNumLights(pkt, n) \ + gMoveWd(pkt, G_MW_NUMLIGHT, G_MWO_NUMLIGHT, NUML(n)) +#define gsSPNumLights(n) \ + gsMoveWd( G_MW_NUMLIGHT, G_MWO_NUMLIGHT, NUML(n)) + +#define LIGHT_1 1 +#define LIGHT_2 2 +#define LIGHT_3 3 +#define LIGHT_4 4 +#define LIGHT_5 5 +#define LIGHT_6 6 +#define LIGHT_7 7 +#define LIGHT_8 8 +/* + * l should point to a Light struct + * n should be one of: LIGHT_1, LIGHT_2, ..., LIGHT_8 + * NOTE: the highest numbered light is always the ambient light (eg if there are + * 3 directional lights defined: gsSPNumLights(NUMLIGHTS_3), then lights + * LIGHT_1 through LIGHT_3 will be the directional lights and light + * LIGHT_4 will be the ambient light. + */ +#ifdef F3DEX_GBI_2 +# define gSPLight(pkt, l, n) \ + gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,(n)*24+24) +# define gsSPLight(l, n) \ + gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,(n)*24+24) +#else /* F3DEX_GBI_2 */ +# define gSPLight(pkt, l, n) \ + gDma1p(pkt, G_MOVEMEM, l, sizeof(Light),((n)-1)*2+G_MV_L0) +# define gsSPLight(l, n) \ + gsDma1p( G_MOVEMEM, l, sizeof(Light),((n)-1)*2+G_MV_L0) +#endif /* F3DEX_GBI_2 */ + +/* + * gSPLightColor changes color of light without recalculating light direction + * col is a 32 bit word with r,g,b,a (alpha is ignored) + * n should be one of LIGHT_1, LIGHT_2, ..., LIGHT_8 + */ +#define gSPLightColor(pkt, n, col) \ +{ \ + gMoveWd(pkt, G_MW_LIGHTCOL, G_MWO_a##n, col); \ + gMoveWd(pkt, G_MW_LIGHTCOL, G_MWO_b##n, col); \ +} +#define gsSPLightColor(n, col) \ + gsMoveWd(G_MW_LIGHTCOL, G_MWO_a##n, col), \ + gsMoveWd(G_MW_LIGHTCOL, G_MWO_b##n, col) + +/* These macros use a structure "name" which is init'd with the gdSPDefLights macros*/ + +#define gSPSetLights0(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_0); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.a,2); \ +} +#define gsSPSetLights0(name) \ + gsSPNumLights(NUMLIGHTS_0), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.a,2) + +#define gSPSetLights1(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_1); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.a,2); \ +} +#define gsSPSetLights1(name) \ + gsSPNumLights(NUMLIGHTS_1), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.a,2) + +#define gSPSetLights2(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_2); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.l[1],2); \ + gSPLight(pkt,&name.a,3); \ +} +#define gsSPSetLights2(name) \ + gsSPNumLights(NUMLIGHTS_2), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.l[1],2), \ + gsSPLight(&name.a,3) + +#define gSPSetLights3(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_3); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.l[1],2); \ + gSPLight(pkt,&name.l[2],3); \ + gSPLight(pkt,&name.a,4); \ +} +#define gsSPSetLights3(name) \ + gsSPNumLights(NUMLIGHTS_3), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.l[1],2), \ + gsSPLight(&name.l[2],3), \ + gsSPLight(&name.a,4) + +#define gSPSetLights4(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_4); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.l[1],2); \ + gSPLight(pkt,&name.l[2],3); \ + gSPLight(pkt,&name.l[3],4); \ + gSPLight(pkt,&name.a,5); \ +} +#define gsSPSetLights4(name) \ + gsSPNumLights(NUMLIGHTS_4), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.l[1],2), \ + gsSPLight(&name.l[2],3), \ + gsSPLight(&name.l[3],4), \ + gsSPLight(&name.a,5) + +#define gSPSetLights5(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_5); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.l[1],2); \ + gSPLight(pkt,&name.l[2],3); \ + gSPLight(pkt,&name.l[3],4); \ + gSPLight(pkt,&name.l[4],5); \ + gSPLight(pkt,&name.a,6); \ +} + +#define gsSPSetLights5(name) \ + gsSPNumLights(NUMLIGHTS_5), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.l[1],2), \ + gsSPLight(&name.l[2],3), \ + gsSPLight(&name.l[3],4), \ + gsSPLight(&name.l[4],5), \ + gsSPLight(&name.a,6) + +#define gSPSetLights6(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_6); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.l[1],2); \ + gSPLight(pkt,&name.l[2],3); \ + gSPLight(pkt,&name.l[3],4); \ + gSPLight(pkt,&name.l[4],5); \ + gSPLight(pkt,&name.l[5],6); \ + gSPLight(pkt,&name.a,7); \ +} + +#define gsSPSetLights6(name) \ + gsSPNumLights(NUMLIGHTS_6), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.l[1],2), \ + gsSPLight(&name.l[2],3), \ + gsSPLight(&name.l[3],4), \ + gsSPLight(&name.l[4],5), \ + gsSPLight(&name.l[5],6), \ + gsSPLight(&name.a,7) + +#define gSPSetLights7(pkt,name) \ +{ \ + gSPNumLights(pkt,NUMLIGHTS_7); \ + gSPLight(pkt,&name.l[0],1); \ + gSPLight(pkt,&name.l[1],2); \ + gSPLight(pkt,&name.l[2],3); \ + gSPLight(pkt,&name.l[3],4); \ + gSPLight(pkt,&name.l[4],5); \ + gSPLight(pkt,&name.l[5],6); \ + gSPLight(pkt,&name.l[6],7); \ + gSPLight(pkt,&name.a,8); \ +} + +#define gsSPSetLights7(name) \ + gsSPNumLights(NUMLIGHTS_7), \ + gsSPLight(&name.l[0],1), \ + gsSPLight(&name.l[1],2), \ + gsSPLight(&name.l[2],3), \ + gsSPLight(&name.l[3],4), \ + gsSPLight(&name.l[4],5), \ + gsSPLight(&name.l[5],6), \ + gsSPLight(&name.l[6],7), \ + gsSPLight(&name.a,8) + +/* + * Reflection/Hiliting Macros + */ +#ifdef F3DEX_GBI_2 +# define gSPLookAtX(pkt, l) \ + gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATX) +# define gsSPLookAtX(l) \ + gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATX) +# define gSPLookAtY(pkt, l) \ + gDma2p((pkt),G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATY) +# define gsSPLookAtY(l) \ + gsDma2p( G_MOVEMEM,(l),sizeof(Light),G_MV_LIGHT,G_MVO_LOOKATY) +#else /* F3DEX_GBI_2 */ +# define gSPLookAtX(pkt, l) \ + gDma1p(pkt, G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATX) +# define gsSPLookAtX(l) \ + gsDma1p( G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATX) +# define gSPLookAtY(pkt, l) \ + gDma1p(pkt, G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATY) +# define gsSPLookAtY(l) \ + gsDma1p( G_MOVEMEM, l, sizeof(Light),G_MV_LOOKATY) +#endif /* F3DEX_GBI_2 */ + +#define gSPLookAt(pkt, la) \ +{ \ + gSPLookAtX(pkt,la) \ + gSPLookAtY(pkt,(char *)(la)+16) \ +} +#define gsSPLookAt(la) \ + gsSPLookAtX(la), \ + gsSPLookAtY((char *)(la)+16) + +#define gDPSetHilite1Tile(pkt, tile, hilite, width, height) \ + gDPSetTileSize(pkt, tile, (hilite)->h.x1 & 0xfff, (hilite)->h.y1 & 0xfff, \ + ((((width)-1)*4)+(hilite)->h.x1) & 0xfff, ((((height)-1)*4)+(hilite)->h.y1) & 0xfff) + +#define gDPSetHilite2Tile(pkt, tile, hilite, width, height) \ + gDPSetTileSize(pkt, tile, (hilite)->h.x2 & 0xfff, (hilite)->h.y2 & 0xfff, \ + ((((width)-1)*4)+(hilite)->h.x2) & 0xfff, ((((height)-1)*4)+(hilite)->h.y2) & 0xfff) + + +/* + * FOG macros + * fm = z multiplier + * fo = z offset + * FOG FORMULA: alpha(fog) = (eyespace z) * fm + fo CLAMPED 0 to 255 + * note: (eyespace z) ranges -1 to 1 + * + * Alternate method of setting fog: + * min, max: range 0 to 1000: 0=nearplane, 1000=farplane + * min is where fog begins (usually less than max and often 0) + * max is where fog is thickest (usually 1000) + * + */ +#define gSPFogFactor(pkt, fm, fo) \ + gMoveWd(pkt, G_MW_FOG, G_MWO_FOG, \ + (_SHIFTL(fm,16,16) | _SHIFTL(fo,0,16))) + +#define gsSPFogFactor(fm, fo) \ + gsMoveWd(G_MW_FOG, G_MWO_FOG, \ + (_SHIFTL(fm,16,16) | _SHIFTL(fo,0,16))) + +#define gSPFogPosition(pkt, min, max) \ + gMoveWd(pkt, G_MW_FOG, G_MWO_FOG, \ + (_SHIFTL((128000/((max)-(min))),16,16) | \ + _SHIFTL(((500-(min))*256/((max)-(min))),0,16))) + +#define gsSPFogPosition(min, max) \ + gsMoveWd(G_MW_FOG, G_MWO_FOG, \ + (_SHIFTL((128000/((max)-(min))),16,16) | \ + _SHIFTL(((500-(min))*256/((max)-(min))),0,16))) + +#ifdef F3DEX_GBI_2 +/* + * Macros to turn texture on/off + */ +# define gSPTexture(pkt, s, t, level, tile, on) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8) | \ + _SHIFTL(BOWTIE_VAL,16,8) | \ + _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | \ + _SHIFTL((on),1,7)); \ + _g->words.w1 = (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)); \ +} +# define gsSPTexture(s, t, level, tile, on) \ +{{ \ + (_SHIFTL(G_TEXTURE,24,8) | _SHIFTL(BOWTIE_VAL,16,8) | \ + _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | _SHIFTL((on),1,7)),\ + (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)) \ +}} +/* + * Different version of SPTexture macro, has an additional parameter + * which is currently reserved in the microcode. + */ +# define gSPTextureL(pkt, s, t, level, xparam, tile, on) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8) | \ + _SHIFTL((xparam),16,8) | \ + _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | \ + _SHIFTL((on),1,7)); \ + _g->words.w1 = (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)); \ +} +# define gsSPTextureL(s, t, level, xparam, tile, on) \ +{{ \ + (_SHIFTL(G_TEXTURE,24,8) | _SHIFTL((xparam),16,8) | \ + _SHIFTL((level),11,3) | _SHIFTL((tile),8,3) | _SHIFTL((on),1,7)),\ + (_SHIFTL((s),16,16) | _SHIFTL((t),0,16)) \ +}} +#else +/* + * Macros to turn texture on/off + */ +# define gSPTexture(pkt, s, t, level, tile, on) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL(BOWTIE_VAL,16,8)|\ + _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)| \ + _SHIFTL((on),0,8)); \ + _g->words.w1 = (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)); \ +} +# define gsSPTexture(s, t, level, tile, on) \ +{{ \ + (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL(BOWTIE_VAL,16,8)| \ + _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)|_SHIFTL((on),0,8)), \ + (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)) \ +}} +/* + * Different version of SPTexture macro, has an additional parameter + * which is currently reserved in the microcode. + */ +# define gSPTextureL(pkt, s, t, level, xparam, tile, on) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL((xparam),16,8)| \ + _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)| \ + _SHIFTL((on),0,8)); \ + _g->words.w1 = (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)); \ +} +# define gsSPTextureL(s, t, level, xparam, tile, on) \ +{{ \ + (_SHIFTL(G_TEXTURE,24,8)|_SHIFTL((xparam),16,8)| \ + _SHIFTL((level),11,3)|_SHIFTL((tile),8,3)|_SHIFTL((on),0,8)), \ + (_SHIFTL((s),16,16)|_SHIFTL((t),0,16)) \ +}} +#endif + +#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) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_RDPHALF_1, 24, 8); \ + _g->words.w1 = (s); \ +} +# define gsSPPerspNormalize(s) \ +{{ \ + _SHIFTL(G_RDPHALF_1, 24, 8), \ + (s) \ +}} +#endif + +#ifdef F3DEX_GBI_2 +# define gSPPopMatrixN(pkt, n, num) gDma2p((pkt),G_POPMTX,(num)*64,64,2,0) +# define gsSPPopMatrixN(n, num) gsDma2p( G_POPMTX,(num)*64,64,2,0) +# define gSPPopMatrix(pkt, n) gSPPopMatrixN((pkt), (n), 1) +# define gsSPPopMatrix(n) gsSPPopMatrixN( (n), 1) +#else /* F3DEX_GBI_2 */ +# define gSPPopMatrix(pkt, n) gImmp1(pkt, G_POPMTX, n) +# define gsSPPopMatrix(n) gsImmp1( G_POPMTX, n) +#endif /* F3DEX_GBI_2 */ + +#define gSPEndDisplayList(pkt) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_ENDDL, 24, 8); \ + _g->words.w1 = 0; \ +} + +#define gsSPEndDisplayList() \ +{{ \ + _SHIFTL(G_ENDDL, 24, 8), 0 \ +}} + +#ifdef F3DEX_GBI_2 +/* + * One gSPGeometryMode(pkt,c,s) GBI is equal to these two GBIs. + * + * gSPClearGeometryMode(pkt,c) + * gSPSetGeometryMode(pkt,s) + * + * gSPLoadGeometryMode(pkt, word) sets GeometryMode directly. + */ +#define gSPGeometryMode(pkt, c, s) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = _SHIFTL(G_GEOMETRYMODE,24,8)|_SHIFTL(~(u32)(c),0,24);\ + _g->words.w1 = (u32)(s); \ +} + +#define gsSPGeometryMode(c, s) \ +{{ \ + (_SHIFTL(G_GEOMETRYMODE,24,8)|_SHIFTL(~(u32)(c),0,24)),(u32)(s) \ +}} +#define gSPSetGeometryMode(pkt, word) gSPGeometryMode((pkt),0,(word)) +#define gsSPSetGeometryMode(word) gsSPGeometryMode(0,(word)) +#define gSPClearGeometryMode(pkt, word) gSPGeometryMode((pkt),(word),0) +#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) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETGEOMETRYMODE, 24, 8); \ + _g->words.w1 = (unsigned int)(word); \ +} + +#define gsSPSetGeometryMode(word) \ +{{ \ + _SHIFTL(G_SETGEOMETRYMODE, 24, 8), (unsigned int)(word) \ +}} + +#define gSPClearGeometryMode(pkt, word) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_CLEARGEOMETRYMODE, 24, 8); \ + _g->words.w1 = (unsigned int)(word); \ +} + +#define gsSPClearGeometryMode(word) \ +{{ \ + _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 +#define gSPSetOtherMode(pkt, cmd, sft, len, data) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + _g->words.w0 = (_SHIFTL(cmd,24,8)|_SHIFTL(32-(sft)-(len),8,8)| \ + _SHIFTL((len)-1,0,8)); \ + _g->words.w1 = (unsigned int)(data); \ +} + +#define gsSPSetOtherMode(cmd, sft, len, data) \ +{{ \ + _SHIFTL(cmd,24,8)|_SHIFTL(32-(sft)-(len),8,8)|_SHIFTL((len)-1,0,8), \ + (unsigned int)(data) \ +}} +#else +#define gSPSetOtherMode(pkt, cmd, sft, len, data) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(cmd, 24, 8) | _SHIFTL(sft, 8, 8) | \ + _SHIFTL(len, 0, 8)); \ + _g->words.w1 = (unsigned int)(data); \ +} + +#define gsSPSetOtherMode(cmd, sft, len, data) \ +{{ \ + _SHIFTL(cmd, 24, 8) | _SHIFTL(sft, 8, 8) | _SHIFTL(len, 0, 8), \ + (unsigned int)(data) \ +}} +#endif + +/* + * RDP setothermode register commands - register shadowed in RSP + */ +#define gDPPipelineMode(pkt, mode) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_PIPELINE, 1, mode) +#define gsDPPipelineMode(mode) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_PIPELINE, 1, mode) + +#define gDPSetCycleType(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_CYCLETYPE, 2, type) +#define gsDPSetCycleType(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_CYCLETYPE, 2, type) + +#define gDPSetTexturePersp(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTPERSP, 1, type) +#define gsDPSetTexturePersp(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTPERSP, 1, type) + +#define gDPSetTextureDetail(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTDETAIL, 2, type) +#define gsDPSetTextureDetail(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTDETAIL, 2, type) + +#define gDPSetTextureLOD(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTLOD, 1, type) +#define gsDPSetTextureLOD(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTLOD, 1, type) + +#define gDPSetTextureLUT(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTLUT, 2, type) +#define gsDPSetTextureLUT(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTLUT, 2, type) + +#define gDPSetTextureFilter(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTFILT, 2, type) +#define gsDPSetTextureFilter(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTFILT, 2, type) + +#define gDPSetTextureConvert(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_TEXTCONV, 3, type) +#define gsDPSetTextureConvert(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_TEXTCONV, 3, type) + +#define gDPSetCombineKey(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_COMBKEY, 1, type) +#define gsDPSetCombineKey(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_COMBKEY, 1, type) + +#ifndef _HW_VERSION_1 +#define gDPSetColorDither(pkt, mode) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_RGBDITHER, 2, mode) +#define gsDPSetColorDither(mode) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_RGBDITHER, 2, mode) +#else +#define gDPSetColorDither(pkt, mode) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_COLORDITHER, 1, mode) +#define gsDPSetColorDither(mode) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_COLORDITHER, 1, mode) +#endif + +#ifndef _HW_VERSION_1 +#define gDPSetAlphaDither(pkt, mode) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 2, mode) +#define gsDPSetAlphaDither(mode) \ + gsSPSetOtherMode(G_SETOTHERMODE_H, G_MDSFT_ALPHADITHER, 2, mode) +#endif + +/* 'blendmask' is not supported anymore. + * The bits are reserved for future use. + * Fri May 26 13:45:55 PDT 1995 + */ +#define gDPSetBlendMask(pkt, mask) gDPNoOp(pkt) +#define gsDPSetBlendMask(mask) gsDPNoOp() + +#define gDPSetAlphaCompare(pkt, type) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_L, G_MDSFT_ALPHACOMPARE, 2, type) +#define gsDPSetAlphaCompare(type) \ + gsSPSetOtherMode(G_SETOTHERMODE_L, G_MDSFT_ALPHACOMPARE, 2, type) + +#define gDPSetDepthSource(pkt, src) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_L, G_MDSFT_ZSRCSEL, 1, src) +#define gsDPSetDepthSource(src) \ + gsSPSetOtherMode(G_SETOTHERMODE_L, G_MDSFT_ZSRCSEL, 1, src) + +#define gDPSetRenderMode(pkt, c0, c1) \ + gSPSetOtherMode(pkt, G_SETOTHERMODE_L, G_MDSFT_RENDERMODE, 29, \ + (c0) | (c1)) +#define gsDPSetRenderMode(c0, c1) \ + gsSPSetOtherMode(G_SETOTHERMODE_L, G_MDSFT_RENDERMODE, 29, \ + (c0) | (c1)) + +#define gSetImage(pkt, cmd, fmt, siz, width, i) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _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); \ +} + +#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) \ +}} + +#define gDPSetColorImage(pkt, f, s, w, i) gSetImage(pkt, G_SETCIMG, f, s, w, i) +#define gsDPSetColorImage(f, s, w, i) gsSetImage(G_SETCIMG, f, s, w, i) + + +/* use these for new code */ +#define gDPSetDepthImage(pkt, i) gSetImage(pkt, G_SETZIMG, 0, 0, 1, i) +#define gsDPSetDepthImage(i) gsSetImage(G_SETZIMG, 0, 0, 1, i) +/* kept for compatibility */ +#define gDPSetMaskImage(pkt, i) gDPSetDepthImage(pkt, i) +#define gsDPSetMaskImage(i) gsDPSetDepthImage(i) + +#define gDPSetTextureImage(pkt, f, s, w, i) gSetImage(pkt, G_SETTIMG, f, s, w, i) +#define gsDPSetTextureImage(f, s, w, i) gsSetImage(G_SETTIMG, f, s, w, i) + +/* + * RDP macros + */ + +#define gDPSetCombine(pkt, muxs0, muxs1) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETCOMBINE, 24, 8) | _SHIFTL(muxs0, 0, 24);\ + _g->words.w1 = (unsigned int)(muxs1); \ +} + +#define gsDPSetCombine(muxs0, muxs1) \ +{{ \ + _SHIFTL(G_SETCOMBINE, 24, 8) | _SHIFTL(muxs0, 0, 24), \ + (unsigned int)(muxs1) \ +}} + +#define GCCc0w0(saRGB0, mRGB0, saA0, mA0) \ + (_SHIFTL((saRGB0), 20, 4) | _SHIFTL((mRGB0), 15, 5) | \ + _SHIFTL((saA0), 12, 3) | _SHIFTL((mA0), 9, 3)) + +#define GCCc1w0(saRGB1, mRGB1) \ + (_SHIFTL((saRGB1), 5, 4) | _SHIFTL((mRGB1), 0, 5)) + +#define GCCc0w1(sbRGB0, aRGB0, sbA0, aA0) \ + (_SHIFTL((sbRGB0), 28, 4) | _SHIFTL((aRGB0), 15, 3) | \ + _SHIFTL((sbA0), 12, 3) | _SHIFTL((aA0), 9, 3)) + +#define GCCc1w1(sbRGB1, saA1, mA1, aRGB1, sbA1, aA1) \ + (_SHIFTL((sbRGB1), 24, 4) | _SHIFTL((saA1), 21, 3) | \ + _SHIFTL((mA1), 18, 3) | _SHIFTL((aRGB1), 6, 3) | \ + _SHIFTL((sbA1), 3, 3) | _SHIFTL((aA1), 0, 3)) + +#define gDPSetCombineLERP(pkt, a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0, \ + a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETCOMBINE, 24, 8) | \ + _SHIFTL(GCCc0w0(G_CCMUX_##a0, G_CCMUX_##c0, \ + G_ACMUX_##Aa0, G_ACMUX_##Ac0) | \ + GCCc1w0(G_CCMUX_##a1, G_CCMUX_##c1), \ + 0, 24); \ + _g->words.w1 = (unsigned int)(GCCc0w1(G_CCMUX_##b0, \ + G_CCMUX_##d0, \ + G_ACMUX_##Ab0, \ + G_ACMUX_##Ad0) | \ + GCCc1w1(G_CCMUX_##b1, \ + G_ACMUX_##Aa1, \ + G_ACMUX_##Ac1, \ + G_CCMUX_##d1, \ + G_ACMUX_##Ab1, \ + G_ACMUX_##Ad1)); \ +} + +#define gsDPSetCombineLERP(a0, b0, c0, d0, Aa0, Ab0, Ac0, Ad0, \ + a1, b1, c1, d1, Aa1, Ab1, Ac1, Ad1) \ +{{ \ + _SHIFTL(G_SETCOMBINE, 24, 8) | \ + _SHIFTL(GCCc0w0(G_CCMUX_##a0, G_CCMUX_##c0, \ + G_ACMUX_##Aa0, G_ACMUX_##Ac0) | \ + GCCc1w0(G_CCMUX_##a1, G_CCMUX_##c1), 0, 24), \ + (unsigned int)(GCCc0w1(G_CCMUX_##b0, G_CCMUX_##d0, \ + G_ACMUX_##Ab0, G_ACMUX_##Ad0) | \ + GCCc1w1(G_CCMUX_##b1, G_ACMUX_##Aa1, \ + G_ACMUX_##Ac1, G_CCMUX_##d1, \ + G_ACMUX_##Ab1, G_ACMUX_##Ad1)) \ +}} + +/* + * SetCombineMode macros are NOT redunant. It allow the C preprocessor + * to substitute single parameter which includes commas in the token and + * rescan for higher parameter count macro substitution. + * + * eg. gsDPSetCombineMode(G_CC_MODULATE, G_CC_MODULATE) turns into + * gsDPSetCombineLERP(TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0, + * TEXEL0, 0, SHADE, 0, TEXEL0, 0, SHADE, 0) + */ + +#define gDPSetCombineMode(pkt, a, b) gDPSetCombineLERP(pkt, a, b) +#define gsDPSetCombineMode(a, b) gsDPSetCombineLERP(a, b) + +#define gDPSetColor(pkt, c, d) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(c, 24, 8); \ + _g->words.w1 = (unsigned int)(d); \ +} + +#define gsDPSetColor(c, d) \ +{{ \ + _SHIFTL(c, 24, 8), (unsigned int)(d) \ +}} + +#define DPRGBColor(pkt, cmd, r, g, b, a) \ + gDPSetColor(pkt, cmd, \ + (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | \ + _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8))) +#define sDPRGBColor(cmd, r, g, b, a) \ + gsDPSetColor(cmd, \ + (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | \ + _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8))) + +#define gDPSetEnvColor(pkt, r, g, b, a) \ + DPRGBColor(pkt, G_SETENVCOLOR, r,g,b,a) +#define gsDPSetEnvColor(r, g, b, a) \ + sDPRGBColor(G_SETENVCOLOR, r,g,b,a) +#define gDPSetBlendColor(pkt, r, g, b, a) \ + DPRGBColor(pkt, G_SETBLENDCOLOR, r,g,b,a) +#define gsDPSetBlendColor(r, g, b, a) \ + sDPRGBColor(G_SETBLENDCOLOR, r,g,b,a) +#define gDPSetFogColor(pkt, r, g, b, a) \ + DPRGBColor(pkt, G_SETFOGCOLOR, r,g,b,a) +#define gsDPSetFogColor(r, g, b, a) \ + sDPRGBColor(G_SETFOGCOLOR, r,g,b,a) +#define gDPSetFillColor(pkt, d) \ + gDPSetColor(pkt, G_SETFILLCOLOR, (d)) +#define gsDPSetFillColor(d) \ + gsDPSetColor(G_SETFILLCOLOR, (d)) + +#define gDPSetPrimDepth(pkt, z, dz) \ + gDPSetColor(pkt, G_SETPRIMDEPTH, \ + _SHIFTL(z, 16, 16) | _SHIFTL(dz, 0, 16)) +#define gsDPSetPrimDepth(z, dz) \ + gsDPSetColor(G_SETPRIMDEPTH, _SHIFTL(z, 16, 16) | \ + _SHIFTL(dz, 0, 16)) + +#define gDPSetPrimColor(pkt, m, l, r, g, b, a) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SETPRIMCOLOR, 24, 8) | \ + _SHIFTL(m, 8, 8) | _SHIFTL(l, 0, 8)); \ + _g->words.w1 = (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | \ + _SHIFTL(b, 8, 8) | _SHIFTL(a, 0, 8)); \ +} + +#define gsDPSetPrimColor(m, l, r, g, b, a) \ +{{ \ + (_SHIFTL(G_SETPRIMCOLOR, 24, 8) | _SHIFTL(m, 8, 8) | \ + _SHIFTL(l, 0, 8)), \ + (_SHIFTL(r, 24, 8) | _SHIFTL(g, 16, 8) | _SHIFTL(b, 8, 8) | \ + _SHIFTL(a, 0, 8)) \ +}} + +/* + * gDPSetOtherMode (This is for expert user.) + * + * This command makes all othermode parameters set. + * Do not use this command in the same DL with another g*SPSetOtherMode DLs. + * + * [Usage] + * gDPSetOtherMode(pkt, modeA, modeB) + * + * 'modeA' is described all parameters of GroupA GBI command. + * 'modeB' is also described all parameters of GroupB GBI command. + * + * GroupA: + * gDPPipelineMode, gDPSetCycleType, gSPSetTexturePersp, + * gDPSetTextureDetail, gDPSetTextureLOD, gDPSetTextureLUT, + * gDPSetTextureFilter, gDPSetTextureConvert, gDPSetCombineKey, + * gDPSetColorDither, gDPSetAlphaDither + * + * GroupB: + * gDPSetAlphaCompare, gDPSetDepthSource, gDPSetRenderMode + * + * Use 'OR' operation to get modeA and modeB. + * + * modeA = G_PM_* | G_CYC_* | G_TP_* | G_TD_* | G_TL_* | G_TT_* | G_TF_* + * G_TC_* | G_CK_* | G_CD_* | G_AD_*; + * + * modeB = G_AC_* | G_ZS_* | G_RM_* | G_RM_*2; + */ +#define gDPSetOtherMode(pkt, mode0, mode1) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_RDPSETOTHERMODE,24,8)|_SHIFTL(mode0,0,24);\ + _g->words.w1 = (unsigned int)(mode1); \ +} + +#define gsDPSetOtherMode(mode0, mode1) \ +{{ \ + _SHIFTL(G_RDPSETOTHERMODE,24,8)|_SHIFTL(mode0,0,24), \ + (unsigned int)(mode1) \ +}} + +/* + * Texturing macros + */ + +/* These are also defined defined above for Sprite Microcode */ + +#define G_TX_LOADTILE 7 +#define G_TX_RENDERTILE 0 + +#define G_TX_NOMIRROR 0 +#define G_TX_WRAP 0 +#define G_TX_MIRROR 0x1 +#define G_TX_CLAMP 0x2 +#define G_TX_NOMASK 0 +#define G_TX_NOLOD 0 + + +#ifndef MAX +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#endif + +#ifndef MIN +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif +/* + * Dxt is the inverse of the number of 64-bit words in a line of + * the texture being loaded using the load_block command. If + * there are any 1's to the right of the 11th fractional bit, + * dxt should be rounded up. The following macros accomplish + * this. The 4b macros are a special case since 4-bit textures + * are loaded as 8-bit textures. Dxt is fixed point 1.11. RJM + */ +#define G_TX_DXT_FRAC 11 + +/* + * For RCP 2.0, the maximum number of texels that can be loaded + * using a load_block command is 2048. In order to load the total + * 4kB of Tmem, change the texel size when loading to be G_IM_SIZ_16b, + * then change the tile to the proper texel size after the load. + * The g*DPLoadTextureBlock macros already do this, so this change + * will be transparent if you use these macros. If you use + * the g*DPLoadBlock macros directly, you will need to handle this + * tile manipulation yourself. RJM. + */ +#ifdef _HW_VERSION_1 +#define G_TX_LDBLK_MAX_TXL 4095 +#else +#define G_TX_LDBLK_MAX_TXL 2047 +#endif /* _HW_VERSION_1 */ + +#define TXL2WORDS(txls, b_txl) MAX(1, ((txls)*(b_txl)/8)) +#define CALC_DXT(width, b_txl) \ + (((1 << G_TX_DXT_FRAC) + TXL2WORDS(width, b_txl) - 1) / \ + TXL2WORDS(width, b_txl)) + +#define TXL2WORDS_4b(txls) MAX(1, ((txls)/16)) +#define CALC_DXT_4b(width) \ + (((1 << G_TX_DXT_FRAC) + TXL2WORDS_4b(width) - 1) / \ + TXL2WORDS_4b(width)) + +#define gDPLoadTileGeneric(pkt, c, tile, uls, ult, lrs, lrt) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(c, 24, 8) | _SHIFTL(uls, 12, 12) | \ + _SHIFTL(ult, 0, 12); \ + _g->words.w1 = _SHIFTL(tile, 24, 3) | _SHIFTL(lrs, 12, 12) | \ + _SHIFTL(lrt, 0, 12); \ +} + +#define gsDPLoadTileGeneric(c, tile, uls, ult, lrs, lrt) \ +{{ \ + _SHIFTL(c, 24, 8) | _SHIFTL(uls, 12, 12) | _SHIFTL(ult, 0, 12), \ + _SHIFTL(tile, 24, 3) | _SHIFTL(lrs, 12, 12) | _SHIFTL(lrt, 0, 12)\ +}} + +#define gDPSetTileSize(pkt, t, uls, ult, lrs, lrt) \ + gDPLoadTileGeneric(pkt, G_SETTILESIZE, t, uls, ult, lrs, lrt) +#define gsDPSetTileSize(t, uls, ult, lrs, lrt) \ + gsDPLoadTileGeneric(G_SETTILESIZE, t, uls, ult, lrs, lrt) +#define gDPLoadTile(pkt, t, uls, ult, lrs, lrt) \ + gDPLoadTileGeneric(pkt, G_LOADTILE, t, uls, ult, lrs, lrt) +#define gsDPLoadTile(t, uls, ult, lrs, lrt) \ + gsDPLoadTileGeneric(G_LOADTILE, t, uls, ult, lrs, lrt) + +#define gDPSetTile(pkt, fmt, siz, line, tmem, tile, palette, cmt, \ + maskt, shiftt, cms, masks, shifts) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETTILE, 24, 8) | _SHIFTL(fmt, 21, 3) |\ + _SHIFTL(siz, 19, 2) | _SHIFTL(line, 9, 9) | \ + _SHIFTL(tmem, 0, 9); \ + _g->words.w1 = _SHIFTL(tile, 24, 3) | _SHIFTL(palette, 20, 4) | \ + _SHIFTL(cmt, 18, 2) | _SHIFTL(maskt, 14, 4) | \ + _SHIFTL(shiftt, 10, 4) |_SHIFTL(cms, 8, 2) | \ + _SHIFTL(masks, 4, 4) | _SHIFTL(shifts, 0, 4); \ +} + +#define gsDPSetTile(fmt, siz, line, tmem, tile, palette, cmt, \ + maskt, shiftt, cms, masks, shifts) \ +{{ \ + (_SHIFTL(G_SETTILE, 24, 8) | _SHIFTL(fmt, 21, 3) | \ + _SHIFTL(siz, 19, 2) | _SHIFTL(line, 9, 9) | _SHIFTL(tmem, 0, 9)),\ + (_SHIFTL(tile, 24, 3) | _SHIFTL(palette, 20, 4) | \ + _SHIFTL(cmt, 18, 2) | _SHIFTL(maskt, 14, 4) | \ + _SHIFTL(shiftt, 10, 4) | _SHIFTL(cms, 8, 2) | \ + _SHIFTL(masks, 4, 4) | _SHIFTL(shifts, 0, 4)) \ +}} + +/* + * For RCP 2.0, the maximum number of texels that can be loaded + * using a load_block command is 2048. In order to load the total + * 4kB of Tmem, change the texel size when loading to be G_IM_SIZ_16b, + * then change the tile to the proper texel size after the load. + * The g*DPLoadTextureBlock macros already do this, so this change + * will be transparent if you use these macros. If you use + * the g*DPLoadBlock macros directly, you will need to handle this + * tile manipulation yourself. RJM. + */ +#define gDPLoadBlock(pkt, tile, uls, ult, lrs, dxt) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_LOADBLOCK, 24, 8) | \ + _SHIFTL(uls, 12, 12) | _SHIFTL(ult, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | \ + _SHIFTL((MIN(lrs,G_TX_LDBLK_MAX_TXL)), 12, 12) |\ + _SHIFTL(dxt, 0, 12)); \ +} + +#define gsDPLoadBlock(tile, uls, ult, lrs, dxt) \ +{{ \ + (_SHIFTL(G_LOADBLOCK, 24, 8) | _SHIFTL(uls, 12, 12) | \ + _SHIFTL(ult, 0, 12)), \ + (_SHIFTL(tile, 24, 3) | \ + _SHIFTL((MIN(lrs,G_TX_LDBLK_MAX_TXL)), 12, 12) | \ + _SHIFTL(dxt, 0, 12)) \ +}} + +#define gDPLoadTLUTCmd(pkt, tile, count) \ +{ \ + Gfx *_g = (Gfx *)pkt; \ + \ + _g->words.w0 = _SHIFTL(G_LOADTLUT, 24, 8); \ + _g->words.w1 = _SHIFTL((tile), 24, 3) | _SHIFTL((count), 14, 10);\ +} + +#define gsDPLoadTLUTCmd(tile, count) \ +{{ \ + _SHIFTL(G_LOADTLUT, 24, 8), \ + _SHIFTL((tile), 24, 3) | _SHIFTL((count), 14, 10) \ +}} + +#define gDPLoadTextureBlock(pkt, timg, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT) -1, \ + CALC_DXT(width, siz##_BYTES)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, \ + (((width) * siz##_LINE_BYTES)+7)>>3, 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +#define gDPLoadTextureBlockYuv(pkt, timg, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT) -1, \ + CALC_DXT(width, siz##_BYTES)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, \ + (((width) * 1)+7)>>3, 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* Load fix rww 27jun95 */ +/* The S at the end means odd lines are already word Swapped */ + +#define gDPLoadTextureBlockS(pkt, timg, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1,0); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, \ + (((width) * siz##_LINE_BYTES)+7)>>3, 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* + * Allow tmem address and render tile to be specified. + * The S at the end means odd lines are already word Swapped + */ +#define gDPLoadMultiBlockS(pkt, timg, tmem, rtile, fmt, siz, width, \ + height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1,0); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, \ + (((width) * siz##_LINE_BYTES)+7)>>3, tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + + +#define gDPLoadTextureBlockYuvS(pkt, timg, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1,0); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, \ + (((width) * 1)+7)>>3, 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* + * allows tmem address to be specified + */ +#define _gDPLoadTextureBlock(pkt, timg, tmem, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ + 0, cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ + CALC_DXT(width, siz##_BYTES)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width) * siz##_LINE_BYTES)+7)>>3, \ + tmem, G_TX_RENDERTILE, pal, cmt, \ + maskt, shiftt, cms, masks, shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* + * allows tmem address and render tile to be specified + */ +#define _gDPLoadTextureBlockTile(pkt, timg, tmem, rtile, fmt, siz, width, \ + height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0,\ + cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ + CALC_DXT(width, siz##_BYTES)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width) * siz##_LINE_BYTES)+7)>>3, \ + tmem, rtile, pal, cmt, \ + maskt, shiftt, cms, masks, shifts); \ + gDPSetTileSize(pkt, rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* + * allows tmem address and render tile to be specified + */ +#define gDPLoadMultiBlock(pkt, timg, tmem, rtile, fmt, siz, width, \ + height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz##_LOAD_BLOCK, 1, timg); \ + gDPSetTile(pkt, fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0,\ + cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ + CALC_DXT(width, siz##_BYTES)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, siz, (((width) * siz##_LINE_BYTES)+7)>>3, \ + tmem, rtile, pal, cmt, \ + maskt, shiftt, cms, masks, shifts); \ + gDPSetTileSize(pkt, rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +#define gsDPLoadTextureBlock(timg, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, 0, \ + G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, \ + masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ + CALC_DXT(width, siz##_BYTES)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, ((((width) * siz##_LINE_BYTES)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + +/* Here is the static form of the pre-swapped texture block loading */ +/* See gDPLoadTextureBlockS() for reference. Basically, just don't + calculate DxT, use 0 */ + +#define gsDPLoadTextureBlockS(timg, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, 0, G_TX_LOADTILE, 0 , \ + cmt, maskt,shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, 0 ),\ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, ((((width) * siz##_LINE_BYTES)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + +/* + * Allow tmem address to be specified + */ +#define _gsDPLoadTextureBlock(timg, tmem, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ + CALC_DXT(width, siz##_BYTES)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, \ + ((((width) * siz##_LINE_BYTES)+7)>>3), tmem, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + + +/* + * Allow tmem address and render_tile to be specified + */ +#define _gsDPLoadTextureBlockTile(timg, tmem, rtile, fmt, siz, width, \ + height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ + CALC_DXT(width, siz##_BYTES)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, \ + ((((width) * siz##_LINE_BYTES)+7)>>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + + +/* + * Allow tmem address and render_tile to be specified, useful when loading + * mutilple tiles at a time. + */ +#define gsDPLoadMultiBlock(timg, tmem, rtile, fmt, siz, width, \ + height, pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, \ + 0 , cmt, maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, \ + CALC_DXT(width, siz##_BYTES)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, \ + ((((width) * siz##_LINE_BYTES)+7)>>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + +/* + * Allows tmem and render tile to be specified. Useful when loading + * several tiles at a time. + * + * Here is the static form of the pre-swapped texture block loading + * See gDPLoadTextureBlockS() for reference. Basically, just don't + * calculate DxT, use 0 + */ + +#define gsDPLoadMultiBlockS(timg, tmem, rtile, fmt, siz, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, siz##_LOAD_BLOCK, 1, timg), \ + gsDPSetTile(fmt, siz##_LOAD_BLOCK, 0, tmem, G_TX_LOADTILE, 0 , \ + cmt, maskt,shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, \ + (((width)*(height) + siz##_INCR) >> siz##_SHIFT)-1, 0 ),\ + gsDPPipeSync(), \ + gsDPSetTile(fmt, siz, ((((width) * siz##_LINE_BYTES)+7)>>3), tmem,\ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + + +#define gDPLoadTextureBlock_4b(pkt, timg, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, \ + cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height)+3)>>2)-1, \ + CALC_DXT_4b(width)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* Load fix rww 27jun95 */ +/* The S at the end means odd lines are already word Swapped */ + +#define gDPLoadTextureBlock_4bS(pkt, timg, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0, \ + cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height)+3)>>2)-1, 0 ); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* + * 4-bit load block. Useful when loading multiple tiles + */ +#define gDPLoadMultiBlock_4b(pkt, timg, tmem, rtile, fmt, width, height,\ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, \ + cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height)+3)>>2)-1, \ + CALC_DXT_4b(width)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +/* + * 4-bit load block. Allows tmem and render tile to be specified. Useful when + * loading multiple tiles. The S means odd lines are already word swapped. + */ +#define gDPLoadMultiBlock_4bS(pkt, timg, tmem, rtile, fmt, width, height,\ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, \ + cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height)+3)>>2)-1, 0 ); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + + +#define _gDPLoadTextureBlock_4b(pkt, timg, tmem, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, G_IM_SIZ_16b, 1, timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0, \ + cmt, maskt, shiftt, cms, masks, shifts); \ + gDPLoadSync(pkt); \ + gDPLoadBlock(pkt, G_TX_LOADTILE, 0, 0, \ + (((width)*(height)+3)>>2)-1, \ + CALC_DXT_4b(width)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) \ +} + +#define gsDPLoadTextureBlock_4b(timg, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ + gsDPSetTile(fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0 , cmt, \ + maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1, \ + CALC_DXT_4b(width)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + +#define gsDPLoadTextureBlock_4bS(timg, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ + gsDPSetTile(fmt, G_IM_SIZ_16b, 0, 0, G_TX_LOADTILE, 0 , cmt, \ + maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1,0),\ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + +/* + * 4-bit load block. Allows tmem address and render tile to be specified. + * Useful when loading multiple tiles. + */ +#define gsDPLoadMultiBlock_4b(timg, tmem, rtile, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ + gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0 , cmt, \ + maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1, \ + CALC_DXT_4b(width)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + + +/* + * 4-bit load block. Allows tmem address and render tile to be specified. + * Useful when loading multiple tiles. S means odd lines are already swapped. + */ +#define gsDPLoadMultiBlock_4bS(timg, tmem, rtile, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ + gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0 , cmt, \ + maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1,0),\ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + + +/* + * Allows tmem address to be specified + */ +#define _gsDPLoadTextureBlock_4b(timg, tmem, fmt, width, height, \ + pal, cms, cmt, masks, maskt, shifts, shiftt) \ + \ + gsDPSetTextureImage(fmt, G_IM_SIZ_16b, 1, timg), \ + gsDPSetTile(fmt, G_IM_SIZ_16b, 0, tmem, G_TX_LOADTILE, 0 , cmt, \ + maskt, shiftt, cms, masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadBlock(G_TX_LOADTILE, 0, 0, (((width)*(height)+3)>>2)-1, \ + CALC_DXT_4b(width)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, ((((width)>>1)+7)>>3), tmem, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, 0, 0, \ + ((width)-1) << G_TEXTURE_IMAGE_FRAC, \ + ((height)-1) << G_TEXTURE_IMAGE_FRAC) + +#ifndef _HW_VERSION_1 + +#define gDPLoadTextureTile(pkt, timg, fmt, siz, width, height, \ + uls, ult, lrs, lrt, pal, \ + cms, cmt, masks, maskt, shifts, shiftt) \ +{ \ + gDPSetTextureImage(pkt, fmt, siz, width, timg); \ + gDPSetTile(pkt, fmt, siz, \ + (((((lrs)-(uls)+1) * siz##_TILE_BYTES)+7)>>3), 0, \ + G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPLoadSync(pkt); \ + gDPLoadTile( pkt, G_TX_LOADTILE, \ + (uls)<>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, \ + (uls)<>3), tmem, \ + G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPLoadSync(pkt); \ + gDPLoadTile( pkt, G_TX_LOADTILE, \ + (uls)<>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, rtile, \ + (uls)<>3), 0, \ + G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPLoadSync(), \ + gsDPLoadTile( G_TX_LOADTILE, \ + (uls)<>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks,\ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, \ + (uls)<>3), \ + tmem, G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, \ + masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadTile( G_TX_LOADTILE, \ + (uls)<>3), \ + tmem, rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, \ + (uls)<>1), timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_8b, \ + (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ + G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPLoadSync(pkt); \ + gDPLoadTile( pkt, G_TX_LOADTILE, \ + (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (ult)<<(G_TEXTURE_IMAGE_FRAC), \ + (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (lrt)<<(G_TEXTURE_IMAGE_FRAC)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, \ + (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, \ + masks, shifts); \ + gDPSetTileSize(pkt, G_TX_RENDERTILE, \ + (uls)<>1), timg); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_8b, \ + (((((lrs)-(uls)+1)>>1)+7)>>3), tmem, \ + G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPLoadSync(pkt); \ + gDPLoadTile( pkt, G_TX_LOADTILE, \ + (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (ult)<<(G_TEXTURE_IMAGE_FRAC), \ + (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (lrt)<<(G_TEXTURE_IMAGE_FRAC)); \ + gDPPipeSync(pkt); \ + gDPSetTile(pkt, fmt, G_IM_SIZ_4b, \ + (((((lrs)-(uls)+1)>>1)+7)>>3), tmem, \ + rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts); \ + gDPSetTileSize(pkt, rtile, \ + (uls)<>1), timg), \ + gsDPSetTile(fmt, G_IM_SIZ_8b, (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ + G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPLoadSync(), \ + gsDPLoadTile( G_TX_LOADTILE, \ + (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (ult)<<(G_TEXTURE_IMAGE_FRAC), \ + (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (lrt)<<(G_TEXTURE_IMAGE_FRAC)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, (((((lrs)-(uls)+1)>>1)+7)>>3), 0, \ + G_TX_RENDERTILE, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(G_TX_RENDERTILE, \ + (uls)<>1), timg), \ + gsDPSetTile(fmt, G_IM_SIZ_8b, (((((lrs)-(uls)+1)>>1)+7)>>3), \ + tmem, G_TX_LOADTILE, 0 , cmt, maskt, shiftt, cms, \ + masks, shifts), \ + gsDPLoadSync(), \ + gsDPLoadTile( G_TX_LOADTILE, \ + (uls)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (ult)<<(G_TEXTURE_IMAGE_FRAC), \ + (lrs)<<(G_TEXTURE_IMAGE_FRAC-1), \ + (lrt)<<(G_TEXTURE_IMAGE_FRAC)), \ + gsDPPipeSync(), \ + gsDPSetTile(fmt, G_IM_SIZ_4b, (((((lrs)-(uls)+1)>>1)+7)>>3), \ + tmem, rtile, pal, cmt, maskt, shiftt, cms, masks, \ + shifts), \ + gsDPSetTileSize(rtile, \ + (uls)<words.w0 = _SHIFTL(G_SETSCISSOR, 24, 8) | \ + _SHIFTL((int)((float)(ulx)*4.0F), 12, 12) | \ + _SHIFTL((int)((float)(uly)*4.0F), 0, 12); \ + _g->words.w1 = _SHIFTL(mode, 24, 2) | \ + _SHIFTL((int)((float)(lrx)*4.0F), 12, 12) | \ + _SHIFTL((int)((float)(lry)*4.0F), 0, 12); \ +} + + +#define gDPSetScissorFrac(pkt, mode, ulx, uly, lrx, lry) \ +{ \ + Gfx *_g = (Gfx *)pkt; \ + \ + _g->words.w0 = _SHIFTL(G_SETSCISSOR, 24, 8) | \ + _SHIFTL((int)((ulx)), 12, 12) | \ + _SHIFTL((int)((uly)), 0, 12); \ + _g->words.w1 = _SHIFTL(mode, 24, 2) | \ + _SHIFTL((int)((lrx)), 12, 12) | \ + _SHIFTL((int)((lry)), 0, 12); \ +} + +#define gsDPSetScissor(mode, ulx, uly, lrx, lry) \ +{{ \ + _SHIFTL(G_SETSCISSOR, 24, 8) | \ + _SHIFTL((int)((float)(ulx)*4.0F), 12, 12) | \ + _SHIFTL((int)((float)(uly)*4.0F), 0, 12), \ + _SHIFTL(mode, 24, 2) | \ + _SHIFTL((int)((float)(lrx)*4.0F), 12, 12) | \ + _SHIFTL((int)((float)(lry)*4.0F), 0, 12) \ +}} + +#define gsDPSetScissorFrac(mode, ulx, uly, lrx, lry) \ +{{ \ + _SHIFTL(G_SETSCISSOR, 24, 8) | \ + _SHIFTL((int)((ulx)), 12, 12) | \ + _SHIFTL((int)((uly)), 0, 12), \ + _SHIFTL(mode, 24, 2) | \ + _SHIFTL((int)(lrx), 12, 12) | \ + _SHIFTL((int)(lry), 0, 12) \ +}} + +/* Fraction never used in fill */ +#define gDPFillRectangle(pkt, ulx, uly, lrx, lry) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_FILLRECT, 24, 8) | \ + _SHIFTL((lrx), 14, 10) | _SHIFTL((lry), 2, 10));\ + _g->words.w1 = (_SHIFTL((ulx), 14, 10) | _SHIFTL((uly), 2, 10));\ +} + +#define gsDPFillRectangle(ulx, uly, lrx, lry) \ +{{ \ + (_SHIFTL(G_FILLRECT, 24, 8) | _SHIFTL((lrx), 14, 10) | \ + _SHIFTL((lry), 2, 10)), \ + (_SHIFTL((ulx), 14, 10) | _SHIFTL((uly), 2, 10)) \ +}} + +/* like gDPFillRectangle but accepts negative arguments */ +#define gDPScisFillRectangle(pkt, ulx, uly, lrx, lry) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_FILLRECT, 24, 8) | \ + _SHIFTL(MAX((lrx),0), 14, 10) | \ + _SHIFTL(MAX((lry),0), 2, 10)); \ + _g->words.w1 = (_SHIFTL(MAX((ulx),0), 14, 10) | \ + _SHIFTL(MAX((uly),0), 2, 10)); \ +} + +#define gDPSetConvert(pkt, k0, k1, k2, k3, k4, k5) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SETCONVERT, 24, 8) | \ + _SHIFTL(k0, 13, 9) | _SHIFTL(k1, 4, 9) | \ + _SHIFTR(k2, 5, 4)); \ + _g->words.w1 = (_SHIFTL(k2, 27, 5) | _SHIFTL(k3, 18, 9) | \ + _SHIFTL(k4, 9, 9) | _SHIFTL(k5, 0, 9)); \ +} + +#define gsDPSetConvert(k0, k1, k2, k3, k4, k5) \ +{{ \ + (_SHIFTL(G_SETCONVERT, 24, 8) | \ + _SHIFTL(k0, 13, 9) | _SHIFTL(k1, 4, 9) | _SHIFTR(k2, 5, 4)), \ + (_SHIFTL(k2, 27, 5) | _SHIFTL(k3, 18, 9) | _SHIFTL(k4, 9, 9) | \ + _SHIFTL(k5, 0, 9)) \ +}} + +#define gDPSetKeyR(pkt, cR, sR, wR) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(G_SETKEYR, 24, 8); \ + _g->words.w1 = (_SHIFTL(wR, 16, 12) | _SHIFTL(cR, 8, 8) | \ + _SHIFTL(sR, 0, 8)); \ +} + +#define gsDPSetKeyR(cR, sR, wR) \ +{{ \ + _SHIFTL(G_SETKEYR, 24, 8), \ + _SHIFTL(wR, 16, 12) | _SHIFTL(cR, 8, 8) | _SHIFTL(sR, 0, 8) \ +}} + +#define gDPSetKeyGB(pkt, cG, sG, wG, cB, sB, wB) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_SETKEYGB, 24, 8) | \ + _SHIFTL(wG, 12, 12) | _SHIFTL(wB, 0, 12)); \ + _g->words.w1 = (_SHIFTL(cG, 24, 8) | _SHIFTL(sG, 16, 8) | \ + _SHIFTL(cB, 8, 8) | _SHIFTL(sB, 0, 8)); \ +} + +#define gsDPSetKeyGB(cG, sG, wG, cB, sB, wB) \ +{{ \ + (_SHIFTL(G_SETKEYGB, 24, 8) | _SHIFTL(wG, 12, 12) | \ + _SHIFTL(wB, 0, 12)), \ + (_SHIFTL(cG, 24, 8) | _SHIFTL(sG, 16, 8) | _SHIFTL(cB, 8, 8) | \ + _SHIFTL(sB, 0, 8)) \ +}} + +#define gDPNoParam(pkt, cmd) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(cmd, 24, 8); \ + _g->words.w1 = 0; \ +} + +#define gsDPNoParam(cmd) \ +{{ \ + _SHIFTL(cmd, 24, 8), 0 \ +}} + +#define gDPParam(pkt, cmd, param) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = _SHIFTL(cmd, 24, 8); \ + _g->words.w1 = (param); \ +} + +#define gsDPParam(cmd, param) \ +{{ \ + _SHIFTL(cmd, 24, 8), (param) \ +}} + +/* Notice that textured rectangles are 128-bit commands, therefore + * gsDPTextureRectangle() should not be used in display lists + * under normal circumstances (use gsSPTextureRectangle()). + * That is also why there is no gDPTextureRectangle() macros. + */ +#define gsDPTextureRectangle(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)), \ +}}, \ +{{ \ + _SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16), \ + _SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16) \ +}} + +#define gDPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + if (pkt); \ + _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | \ + _SHIFTL(yh, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ + _SHIFTL(yl, 0, 12)); \ + _g ++; \ + _g->words.w0 = (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)); \ + _g->words.w1 = (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)); \ +} + +#define gsDPTextureRectangleFlip(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)), \ +}}, \ +{{ \ + _SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16), \ + _SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16) \ +}} + +#define gDPTextureRectangleFlip(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + if (pkt); \ + _g->words.w0 = (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) | \ + _SHIFTL(yh, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ + _SHIFTL(yl, 0, 12)); \ + _g ++; \ + _g->words.w0 = (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16)); \ + _g->words.w1 = (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16)); \ +} + +#ifdef F3D_OLD +# define gSPTextureRectangle(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy)\ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | \ + _SHIFTL(yh, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ + _SHIFTL(yl, 0, 12)); \ + gImmp1(pkt, G_RDPHALF_2, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))); \ + gImmp1(pkt, G_RDPHALF_CONT, (_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_2, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))), \ + gsImmp1(G_RDPHALF_CONT, (_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) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | \ + _SHIFTL(MAX((s16)(xh),0), 12, 12) | \ + _SHIFTL(MAX((s16)(yh),0), 0, 12)); \ + _g->words.w1 = (_SHIFTL((tile), 24, 3) | \ + _SHIFTL(MAX((s16)(xl),0), 12, 12) | \ + _SHIFTL(MAX((s16)(yl),0), 0, 12)); \ + gImmp1(pkt, G_RDPHALF_2, \ + (_SHIFTL(((s) - \ + (((s16)(xl) < 0) ? \ + (((s16)(dsdx) < 0) ? \ + (MAX((((s16)(xl)*(s16)(dsdx))>>7),0)) : \ + (MIN((((s16)(xl)*(s16)(dsdx))>>7),0))) : 0)), \ + 16, 16) | \ + _SHIFTL(((t) - \ + (((yl) < 0) ? \ + (((s16)(dtdy) < 0) ? \ + (MAX((((s16)(yl)*(s16)(dtdy))>>7),0)) : \ + (MIN((((s16)(yl)*(s16)(dtdy))>>7),0))) : 0)), \ + 0, 16))); \ + gImmp1(pkt, G_RDPHALF_CONT, (_SHIFTL((dsdx), 16, 16) | \ + _SHIFTL((dtdy), 0, 16))); \ +} + +# 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_2, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))), \ + gsImmp1(G_RDPHALF_CONT, (_SHIFTL(dsdx, 16, 16) | _SHIFTL(dtdy, 0, 16))) + +# define gSPTextureRectangleFlip(pkt, xl, yl, xh, yh, tile, s, t, dsdx, dtdy) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) |\ + _SHIFTL(yh, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ + _SHIFTL(yl, 0, 12)); \ + gImmp1(pkt, G_RDPHALF_2, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))); \ + 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)\ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | _SHIFTL(xh, 12, 12) | \ + _SHIFTL(yh, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ + _SHIFTL(yl, 0, 12)); \ + gImmp1(pkt, G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))); \ + 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) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXRECT, 24, 8) | \ + _SHIFTL(MAX((s16)(xh),0), 12, 12) | \ + _SHIFTL(MAX((s16)(yh),0), 0, 12)); \ + _g->words.w1 = (_SHIFTL((tile), 24, 3) | \ + _SHIFTL(MAX((s16)(xl),0), 12, 12) | \ + _SHIFTL(MAX((s16)(yl),0), 0, 12)); \ + gImmp1(pkt, G_RDPHALF_1, \ + (_SHIFTL(((s) - \ + (((s16)(xl) < 0) ? \ + (((s16)(dsdx) < 0) ? \ + (MAX((((s16)(xl)*(s16)(dsdx))>>7),0)) : \ + (MIN((((s16)(xl)*(s16)(dsdx))>>7),0))) : 0)), \ + 16, 16) | \ + _SHIFTL(((t) - \ + (((yl) < 0) ? \ + (((s16)(dtdy) < 0) ? \ + (MAX((((s16)(yl)*(s16)(dtdy))>>7),0)) : \ + (MIN((((s16)(yl)*(s16)(dtdy))>>7),0))) : 0)), \ + 0, 16))); \ + gImmp1(pkt, G_RDPHALF_2, (_SHIFTL((dsdx), 16, 16) | \ + _SHIFTL((dtdy), 0, 16))); \ +} + +# 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) \ +{ \ + Gfx *_g = (Gfx *)(pkt); \ + \ + _g->words.w0 = (_SHIFTL(G_TEXRECTFLIP, 24, 8) | _SHIFTL(xh, 12, 12) |\ + _SHIFTL(yh, 0, 12)); \ + _g->words.w1 = (_SHIFTL(tile, 24, 3) | _SHIFTL(xl, 12, 12) | \ + _SHIFTL(yl, 0, 12)); \ + gImmp1(pkt, G_RDPHALF_1, (_SHIFTL(s, 16, 16) | _SHIFTL(t, 0, 16))); \ + 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)) + +#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)); \ +} + +#define gDPFullSync(pkt) gDPNoParam(pkt, G_RDPFULLSYNC) +#define gsDPFullSync() gsDPNoParam(G_RDPFULLSYNC) +#define gDPTileSync(pkt) gDPNoParam(pkt, G_RDPTILESYNC) +#define gsDPTileSync() gsDPNoParam(G_RDPTILESYNC) +#define gDPPipeSync(pkt) gDPNoParam(pkt, G_RDPPIPESYNC) +#define gsDPPipeSync() gsDPNoParam(G_RDPPIPESYNC) +#define gDPLoadSync(pkt) gDPNoParam(pkt, G_RDPLOADSYNC) +#define gsDPLoadSync() gsDPNoParam(G_RDPLOADSYNC) +#define gDPNoOp(pkt) gDPNoParam(pkt, G_NOOP) +#define gsDPNoOp() gsDPNoParam(G_NOOP) +#define gDPNoOpTag(pkt, tag) gDPParam(pkt, G_NOOP, tag) +#define gsDPNoOpTag(tag) gsDPParam(G_NOOP, tag) + +#endif /* _LANGUAGE_C */ + + +#endif /* _GBI_H_ */ diff --git a/include/PR/gs2dex.h b/include/PR/gs2dex.h new file mode 100644 index 00000000..ced46855 --- /dev/null +++ b/include/PR/gs2dex.h @@ -0,0 +1,392 @@ +/*--------------------------------------------------------------------- + Copyright (C) 1997, Nintendo. + + File gs2dex.h + Coded by Yoshitaka Yasumoto. Jul 31, 1997. + Modified by + Comments Header file for S2DEX ucode. + + $Id: gs2dex.h,v 1.21 1998/05/28 00:14:49 has Exp $ + ---------------------------------------------------------------------*/ + +#ifndef _GS2DEX_H_ +#define _GS2DEX_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +/*===========================================================================* + * Macro + *===========================================================================*/ +#define GS_CALC_DXT(line) (((1<< G_TX_DXT_FRAC)-1)/(line)+1) +#define GS_PIX2TMEM(pix, siz) ((pix)>>(4-(siz))) +#define GS_PIX2DXT(pix, siz) GS_CALC_DXT(GS_PIX2TMEM((pix), (siz))) + +/*===========================================================================* + * Data structures for S2DEX microcode + *===========================================================================*/ + +/*---------------------------------------------------------------------------* + * Background + *---------------------------------------------------------------------------*/ +#define G_BGLT_LOADBLOCK 0x0033 +#define G_BGLT_LOADTILE 0xfff4 + +#define G_BG_FLAG_FLIPS 0x01 +#define G_BG_FLAG_FLIPT 0x10 + +/* Non scalable background plane */ +typedef struct { + u16 imageX; /* x-coordinate of upper-left position of texture (u10.5) */ + u16 imageW; /* width of the texture (u10.2) */ + s16 frameX; /* upper-left position of transferred frame (s10.2) */ + u16 frameW; /* width of transferred frame (u10.2) */ + + u16 imageY; /* y-coordinate of upper-left position of texture (u10.5) */ + u16 imageH; /* height of the texture (u10.2) */ + s16 frameY; /* upper-left position of transferred frame (s10.2) */ + u16 frameH; /* height of transferred frame (u10.2) */ + + u64 *imagePtr; /* texture source address on DRAM */ + u16 imageLoad; /* which to use, LoadBlock or LoadTile */ + u8 imageFmt; /* format of texel - G_IM_FMT_* */ + u8 imageSiz; /* size of texel - G_IM_SIZ_* */ + u16 imagePal; /* pallet number */ + u16 imageFlip; /* right & left image inversion (Inverted by G_BG_FLAG_FLIPS) */ + + /* The following is set in the initialization routine guS2DInitBg(). There is no need for the user to set it. */ + u16 tmemW; /* TMEM width and Word size of frame 1 line. + At LoadBlock, GS_PIX2TMEM(imageW/4,imageSiz) + At LoadTile GS_PIX2TMEM(frameW/4,imageSiz)+1 */ + u16 tmemH; /* height of TMEM loadable at a time (s13.2) 4 times value + When the normal texture, 512/tmemW*4 + When the CI texture, 256/tmemW*4 */ + u16 tmemLoadSH; /* SH value + At LoadBlock, tmemSize/2-1 + At LoadTile, tmemW*16-1 */ + u16 tmemLoadTH; /* TH value or Stride value + At LoadBlock, GS_CALC_DXT(tmemW) + At LoadTile, tmemH-1 */ + u16 tmemSizeW; /* skip value of imagePtr for image 1-line + At LoadBlock, tmemW*2 + At LoadTile, GS_PIX2TMEM(imageW/4,imageSiz)*2 */ + u16 tmemSize; /* skip value of imagePtr for 1-loading + = tmemSizeW*tmemH */ +} uObjBg_t; /* 40 bytes */ + +/* Scalable background plane */ +typedef struct { + u16 imageX; /* x-coordinate of upper-left position of texture (u10.5) */ + u16 imageW; /* width of texture (u10.2) */ + s16 frameX; /* upper-left position of transferred frame (s10.2) */ + u16 frameW; /* width of transferred frame (u10.2) */ + + u16 imageY; /* y-coordinate of upper-left position of texture (u10.5) */ + u16 imageH; /* height of texture (u10.2) */ + s16 frameY; /* upper-left position of transferred frame (s10.2) */ + u16 frameH; /* height of transferred frame (u10.2) */ + + u64 *imagePtr; /* texture source address on DRAM */ + u16 imageLoad; /* Which to use, LoadBlock or LoadTile? */ + u8 imageFmt; /* format of texel - G_IM_FMT_* */ + u8 imageSiz; /* size of texel - G_IM_SIZ_* */ + u16 imagePal; /* pallet number */ + u16 imageFlip; /* right & left image inversion (Inverted by G_BG_FLAG_FLIPS) */ + + u16 scaleW; /* scale value of X-direction (u5.10) */ + u16 scaleH; /* scale value of Y-direction (u5.10) */ + s32 imageYorig; /* start point of drawing on image (s20.5) */ + + u8 padding[4]; + +} uObjScaleBg_t; /* 40 bytes */ + +typedef union { + uObjBg_t b; + uObjScaleBg_t s; + long long int force_structure_alignment; +} uObjBg; + +/*---------------------------------------------------------------------------* + * 2D Objects + *---------------------------------------------------------------------------*/ +#define G_OBJ_FLAG_FLIPS 1<<0 /* inversion to S-direction */ +#define G_OBJ_FLAG_FLIPT 1<<4 /* nversion to T-direction */ + +typedef struct { + s16 objX; /* s10.2 OBJ x-coordinate of upper-left end */ + u16 scaleW; /* u5.10 Scaling of u5.10 width direction */ + u16 imageW; /* u10.5 width of u10.5 texture (length of S-direction) */ + u16 paddingX; /* Unused - Always 0 */ + s16 objY; /* s10.2 OBJ y-coordinate of s10.2 OBJ upper-left end */ + u16 scaleH; /* u5.10 Scaling of u5.10 height direction */ + u16 imageH; /* u10.5 height of u10.5 texture (length of T-direction) */ + u16 paddingY; /* Unused - Always 0 */ + u16 imageStride; /* folding width of texel (In units of 64bit word) */ + u16 imageAdrs; /* texture header position in TMEM (In units of 64bit word) */ + u8 imageFmt; /* format of texel - G_IM_FMT_* */ + u8 imageSiz; /* size of texel - G_IM_SIZ_* */ + u8 imagePal; /* pallet number (0-7) */ + u8 imageFlags; /* The display flag - G_OBJ_FLAG_FLIP* */ +} uObjSprite_t; /* 24 bytes */ + +typedef union { + uObjSprite_t s; + long long int force_structure_alignment; +} uObjSprite; + +/*---------------------------------------------------------------------------* + * 2D Matrix + *---------------------------------------------------------------------------*/ +typedef struct { + s32 A, B, C, D; /* s15.16 */ + s16 X, Y; /* s10.2 */ + u16 BaseScaleX; /* u5.10 */ + u16 BaseScaleY; /* u5.10 */ +} uObjMtx_t; /* 24 bytes */ + +typedef union { + uObjMtx_t m; + long long int force_structure_alignment; +} uObjMtx; + +typedef struct { + s16 X, Y; /* s10.2 */ + u16 BaseScaleX; /* u5.10 */ + u16 BaseScaleY; /* u5.10 */ +} uObjSubMtx_t; /* 8 bytes */ + +typedef union { + uObjSubMtx_t m; + long long int force_structure_alignment; +} uObjSubMtx; + +/*---------------------------------------------------------------------------* + * Loading into TMEM + *---------------------------------------------------------------------------*/ +#define G_OBJLT_TXTRBLOCK 0x00001033 +#define G_OBJLT_TXTRTILE 0x00fc1034 +#define G_OBJLT_TLUT 0x00000030 + +#define GS_TB_TSIZE(pix,siz) (GS_PIX2TMEM((pix),(siz))-1) +#define GS_TB_TLINE(pix,siz) (GS_CALC_DXT(GS_PIX2TMEM((pix),(siz)))) + +typedef struct { + u32 type; /* G_OBJLT_TXTRBLOCK divided into types */ + u64 *image; /* texture source address on DRAM */ + u16 tmem; /* loaded TMEM word address (8byteWORD) */ + u16 tsize; /* Texture size, Specified by macro GS_TB_TSIZE() */ + u16 tline; /* width of Texture 1-line, Specified by macro GS_TB_TLINE() */ + u16 sid; /* STATE ID Multipled by 4 (Either one of 0, 4, 8 and 12) */ + u32 flag; /* STATE flag */ + u32 mask; /* STATE mask */ +} uObjTxtrBlock_t; /* 24 bytes */ + +#define GS_TT_TWIDTH(pix,siz) ((GS_PIX2TMEM((pix), (siz))<<2)-1) +#define GS_TT_THEIGHT(pix,siz) (((pix)<<2)-1) + +typedef struct { + u32 type; /* G_OBJLT_TXTRTILE divided into types */ + u64 *image; /* texture source address on DRAM */ + u16 tmem; /* loaded TMEM word address (8byteWORD)*/ + u16 twidth; /* width of Texture (Specified by macro GS_TT_TWIDTH()) */ + u16 theight; /* height of Texture (Specified by macro GS_TT_THEIGHT()) */ + u16 sid; /* STATE ID Multipled by 4 (Either one of 0, 4, 8 and 12) */ + u32 flag; /* STATE flag */ + u32 mask; /* STATE mask */ +} uObjTxtrTile_t; /* 24 bytes */ + +#define GS_PAL_HEAD(head) ((head)+256) +#define GS_PAL_NUM(num) ((num)-1) + +typedef struct { + u32 type; /* G_OBJLT_TLUT divided into types */ + u64 *image; /* texture source address on DRAM */ + u16 phead; /* pallet number of load header (Between 256 and 511) */ + u16 pnum; /* loading pallet number -1 */ + u16 zero; /* Assign 0 all the time */ + u16 sid; /* STATE ID Multipled by 4 (Either one of 0, 4, 8 and 12)*/ + u32 flag; /* STATE flag */ + u32 mask; /* STATE mask */ +} uObjTxtrTLUT_t; /* 24 bytes */ + +typedef union { + uObjTxtrBlock_t block; + uObjTxtrTile_t tile; + uObjTxtrTLUT_t tlut; + long long int force_structure_alignment; +} uObjTxtr; + +/*---------------------------------------------------------------------------* + * Loading into TMEM & 2D Objects + *---------------------------------------------------------------------------*/ +typedef struct { + uObjTxtr txtr; + uObjSprite sprite; +} uObjTxSprite; /* 48 bytes */ + +/*===========================================================================* + * GBI Commands for S2DEX microcode + *===========================================================================*/ +/* GBI Header */ +#ifdef F3DEX_GBI_2 +#define G_OBJ_RECTANGLE_R 0xda +#define G_OBJ_MOVEMEM 0xdc +#define G_RDPHALF_0 0xe4 +#define G_OBJ_RECTANGLE 0x01 +#define G_OBJ_SPRITE 0x02 +#define G_SELECT_DL 0x04 +#define G_OBJ_LOADTXTR 0x05 +#define G_OBJ_LDTX_SPRITE 0x06 +#define G_OBJ_LDTX_RECT 0x07 +#define G_OBJ_LDTX_RECT_R 0x08 +#define G_BG_1CYC 0x09 +#define G_BG_COPY 0x0a +#define G_OBJ_RENDERMODE 0x0b +#else +#define G_BG_1CYC 0x01 +#define G_BG_COPY 0x02 +#define G_OBJ_RECTANGLE 0x03 +#define G_OBJ_SPRITE 0x04 +#define G_OBJ_MOVEMEM 0x05 +#define G_SELECT_DL 0xb0 +#define G_OBJ_RENDERMODE 0xb1 +#define G_OBJ_RECTANGLE_R 0xb2 +#define G_OBJ_LOADTXTR 0xc1 +#define G_OBJ_LDTX_SPRITE 0xc2 +#define G_OBJ_LDTX_RECT 0xc3 +#define G_OBJ_LDTX_RECT_R 0xc4 +#define G_RDPHALF_0 0xe4 +#endif + +/*---------------------------------------------------------------------------* + * Background wrapped screen + *---------------------------------------------------------------------------*/ +#define gSPBgRectangle(pkt, m, mptr) gDma0p((pkt),(m),(mptr),0) +#define gsSPBgRectangle(m, mptr) gsDma0p( (m),(mptr),0) +#define gSPBgRectCopy(pkt, mptr) gSPBgRectangle((pkt), G_BG_COPY, (mptr)) +#define gsSPBgRectCopy(mptr) gsSPBgRectangle( G_BG_COPY, (mptr)) +#define gSPBgRect1Cyc(pkt, mptr) gSPBgRectangle((pkt), G_BG_1CYC, (mptr)) +#define gsSPBgRect1Cyc(mptr) gsSPBgRectangle( G_BG_1CYC, (mptr)) + +/*---------------------------------------------------------------------------* + * 2D Objects + *---------------------------------------------------------------------------*/ +#define gSPObjSprite(pkt, mptr) gDma0p((pkt),G_OBJ_SPRITE, (mptr),0) +#define gsSPObjSprite(mptr) gsDma0p( G_OBJ_SPRITE, (mptr),0) +#define gSPObjRectangle(pkt, mptr) gDma0p((pkt),G_OBJ_RECTANGLE, (mptr),0) +#define gsSPObjRectangle(mptr) gsDma0p( G_OBJ_RECTANGLE, (mptr),0) +#define gSPObjRectangleR(pkt, mptr) gDma0p((pkt),G_OBJ_RECTANGLE_R,(mptr),0) +#define gsSPObjRectangleR(mptr) gsDma0p( G_OBJ_RECTANGLE_R,(mptr),0) + +/*---------------------------------------------------------------------------* + * 2D Matrix + *---------------------------------------------------------------------------*/ +#define gSPObjMatrix(pkt, mptr) gDma1p((pkt),G_OBJ_MOVEMEM,(mptr),0,23) +#define gsSPObjMatrix(mptr) gsDma1p( G_OBJ_MOVEMEM,(mptr),0,23) +#define gSPObjSubMatrix(pkt, mptr) gDma1p((pkt),G_OBJ_MOVEMEM,(mptr),2, 7) +#define gsSPObjSubMatrix(mptr) gsDma1p( G_OBJ_MOVEMEM,(mptr),2, 7) + +/*---------------------------------------------------------------------------* + * Loading into TMEM + *---------------------------------------------------------------------------*/ +#define gSPObjLoadTxtr(pkt, tptr) gDma0p((pkt),G_OBJ_LOADTXTR, (tptr),23) +#define gsSPObjLoadTxtr(tptr) gsDma0p( G_OBJ_LOADTXTR, (tptr),23) +#define gSPObjLoadTxSprite(pkt, tptr) gDma0p((pkt),G_OBJ_LDTX_SPRITE,(tptr),47) +#define gsSPObjLoadTxSprite(tptr) gsDma0p( G_OBJ_LDTX_SPRITE,(tptr),47) +#define gSPObjLoadTxRect(pkt, tptr) gDma0p((pkt),G_OBJ_LDTX_RECT, (tptr),47) +#define gsSPObjLoadTxRect(tptr) gsDma0p( G_OBJ_LDTX_RECT, (tptr),47) +#define gSPObjLoadTxRectR(pkt, tptr) gDma0p((pkt),G_OBJ_LDTX_RECT_R,(tptr),47) +#define gsSPObjLoadTxRectR(tptr) gsDma0p( G_OBJ_LDTX_RECT_R,(tptr),47) + +/*---------------------------------------------------------------------------* + * Select Display List + *---------------------------------------------------------------------------*/ +#define gSPSelectDL(pkt, mptr, sid, flag, mask) \ +{ gDma1p((pkt), G_RDPHALF_0, (flag), (u32)(mptr) & 0xffff, (sid)); \ + gDma1p((pkt), G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_PUSH); } +#define gsSPSelectDL(mptr, sid, flag, mask) \ +{ gsDma1p(G_RDPHALF_0, (flag), (u32)(mptr) & 0xffff, (sid)); \ + gsDma1p(G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_PUSH); } +#define gSPSelectBranchDL(pkt, mptr, sid, flag, mask) \ +{ gDma1p((pkt), G_RDPHALF_0, (flag), (u32)(mptr) & 0xffff, (sid)); \ + gDma1p((pkt), G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_NOPUSH); } +#define gsSPSelectBranchDL(mptr, sid, flag, mask) \ +{ gsDma1p(G_RDPHALF_0, (flag), (u32)(mptr) & 0xffff, (sid)); \ + gsDma1p(G_SELECT_DL, (mask), (u32)(mptr) >> 16, G_DL_NOPUSH); } + +/*---------------------------------------------------------------------------* + * Set general status + *---------------------------------------------------------------------------*/ +#define G_MW_GENSTAT 0x08 /* Note that it is the same value of G_MW_FOG */ + +#define gSPSetStatus(pkt, sid, val) \ + gMoveWd((pkt), G_MW_GENSTAT, (sid), (val)) +#define gsSPSetStatus(sid, val) \ + gsMoveWd( G_MW_GENSTAT, (sid), (val)) + +/*---------------------------------------------------------------------------* + * Set Object Render Mode + *---------------------------------------------------------------------------*/ +#define G_OBJRM_NOTXCLAMP 0x01 +#define G_OBJRM_XLU 0x02 /* Ignored */ +#define G_OBJRM_ANTIALIAS 0x04 /* Ignored */ +#define G_OBJRM_BILERP 0x08 +#define G_OBJRM_SHRINKSIZE_1 0x10 +#define G_OBJRM_SHRINKSIZE_2 0x20 +#define G_OBJRM_WIDEN 0x40 + +#define gSPObjRenderMode(pkt, mode) gImmp1((pkt),G_OBJ_RENDERMODE,(mode)) +#define gsSPObjRenderMode(mode) gsImmp1( G_OBJ_RENDERMODE,(mode)) + +/*===========================================================================* + * Render Mode Macro + *===========================================================================*/ +#define RM_RA_SPRITE(clk) \ + AA_EN | CVG_DST_CLAMP | \ + CVG_X_ALPHA | ALPHA_CVG_SEL | ZMODE_OPA | TEX_EDGE | \ + GBL_c##clk(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA) + +#define G_RM_SPRITE G_RM_OPA_SURF +#define G_RM_SPRITE2 G_RM_OPA_SURF2 +#define G_RM_RA_SPRITE RM_RA_SPRITE(1) +#define G_RM_RA_SPRITE2 RM_RA_SPRITE(2) +#define G_RM_AA_SPRITE G_RM_AA_TEX_TERR +#define G_RM_AA_SPRITE2 G_RM_AA_TEX_TERR2 +#define G_RM_XLU_SPRITE G_RM_XLU_SURF +#define G_RM_XLU_SPRITE2 G_RM_XLU_SURF2 +#define G_RM_AA_XLU_SPRITE G_RM_AA_XLU_SURF +#define G_RM_AA_XLU_SPRITE2 G_RM_AA_XLU_SURF2 + +/*===========================================================================* + * External functions + *===========================================================================*/ +extern u64 gspS2DEX_fifoTextStart[], gspS2DEX_fifoTextEnd[]; +extern u64 gspS2DEX_fifoDataStart[], gspS2DEX_fifoDataEnd[]; +extern u64 gspS2DEX_fifo_dTextStart[], gspS2DEX_fifo_dTextEnd[]; +extern u64 gspS2DEX_fifo_dDataStart[], gspS2DEX_fifo_dDataEnd[]; +extern u64 gspS2DEX2_fifoTextStart[], gspS2DEX2_fifoTextEnd[]; +extern u64 gspS2DEX2_fifoDataStart[], gspS2DEX2_fifoDataEnd[]; +extern u64 gspS2DEX2_xbusTextStart[], gspS2DEX2_xbusTextEnd[]; +extern u64 gspS2DEX2_xbusDataStart[], gspS2DEX2_xbusDataEnd[]; +extern void guS2DInitBg(uObjBg *); + +#ifdef F3DEX_GBI_2 +# define guS2DEmuBgRect1Cyc guS2D2EmuBgRect1Cyc /*Wrapper*/ +# define guS2DEmuSetScissor guS2D2EmuSetScissor /*Wrapper*/ + extern void guS2D2EmuSetScissor(u32, u32, u32, u32, u8); + extern void guS2D2EmuBgRect1Cyc(Gfx **, uObjBg *); +#else + extern void guS2DEmuSetScissor(u32, u32, u32, u32, u8); + extern void guS2DEmuBgRect1Cyc(Gfx **, uObjBg *); +#endif + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif +#endif /* _GS2DEX_H_ */ + +/*======== End of gs2dex.h ========*/ diff --git a/include/PR/gu.h b/include/PR/gu.h new file mode 100644 index 00000000..6527777d --- /dev/null +++ b/include/PR/gu.h @@ -0,0 +1,29 @@ +#ifndef _ULTRA64_GU_H_ +#define _ULTRA64_GU_H_ + +#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); +#endif diff --git a/include/PR/libaudio.h b/include/PR/libaudio.h new file mode 100644 index 00000000..c374a9ff --- /dev/null +++ b/include/PR/libaudio.h @@ -0,0 +1,21 @@ +#ifndef _ULTRA64_LIBAUDIO_H_ +#define _ULTRA64_LIBAUDIO_H_ + +#include "abi.h" + +typedef struct +{ + u8 *offset; + s32 len; +} ALSeqData; + +typedef struct +{ + s16 revision; + s16 seqCount; + ALSeqData seqArray[1]; +} ALSeqFile; + +void alSeqFileNew(ALSeqFile *f, u8 *base); + +#endif diff --git a/include/PR/libultra.h b/include/PR/libultra.h new file mode 100644 index 00000000..f0dab415 --- /dev/null +++ b/include/PR/libultra.h @@ -0,0 +1,18 @@ +#ifndef _LIBULTRA_H +#define _LIBULTRA_H + +#define TV_TYPE_NTSC 1 +#define TV_TYPE_PAL 0 +#define 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 new file mode 100644 index 00000000..fed3510f --- /dev/null +++ b/include/PR/mbi.h @@ -0,0 +1,100 @@ +#ifndef _MBI_H_ +#define _MBI_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.136 $ + * $Date: 1999/01/05 13:04:00 $ + * $Source: /hosts/gate3/exdisk2/cvs/N64OS/Master/cvsmdev2/PR/include/mbi.h,v $ + * + **************************************************************************/ + +/* + * Header file for the Media Binary Interface + * + * NOTE: This file is included by the RSP microcode, so any C-specific + * constructs must be bracketed by #ifdef _LANGUAGE_C + * + */ + + +/* + * the SHIFT macros are used to build display list commands, inserting + * bit-fields into a 32-bit word. They take a value, a shift amount, + * and a width. + * + * For the left shift, the lower bits of the value are masked, + * then shifted left. + * + * For the right shift, the value is shifted right, then the lower bits + * are masked. + * + * (NOTE: _SHIFTL(v, 0, 32) won't work, just use an assignment) + * + */ +#define _SHIFTL(v, s, w) \ + ((unsigned int) (((unsigned int)(v) & ((0x01 << (w)) - 1)) << (s))) +#define _SHIFTR(v, s, w) \ + ((unsigned int)(((unsigned int)(v) >> (s)) & ((0x01 << (w)) - 1))) + +#define _SHIFT _SHIFTL /* old, for compatibility only */ + +#define G_ON (1) +#define G_OFF (0) + +/************************************************************************** + * + * Graphics Binary Interface + * + **************************************************************************/ + +#include + +/************************************************************************** + * + * Audio Binary Interface + * + **************************************************************************/ + +#include + +/************************************************************************** + * + * Task list + * + **************************************************************************/ + +#define M_GFXTASK 1 +#define M_AUDTASK 2 +#define M_VIDTASK 3 +#define M_HVQTASK 6 +#define M_HVQMTASK 7 + +/************************************************************************** + * + * Segment macros and definitions + * + **************************************************************************/ + +#define NUM_SEGMENTS (16) +#define SEGMENT_OFFSET(a) ((unsigned int)(a) & 0x00ffffff) +#define SEGMENT_NUMBER(a) (((unsigned int)(a) << 4) >> 28) +#define SEGMENT_ADDR(num, off) (((num) << 24) + (off)) + +#ifndef NULL +#define NULL 0 +#endif + +#endif /* !_MBI_H_ */ diff --git a/include/PR/os_ai.h b/include/PR/os_ai.h new file mode 100644 index 00000000..f89d87cf --- /dev/null +++ b/include/PR/os_ai.h @@ -0,0 +1,92 @@ + +/*==================================================================== + * os_ai.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_ai.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:04 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_AI_H_ +#define _OS_AI_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Audio interface (Ai) */ +extern u32 osAiGetStatus(void); +extern u32 osAiGetLength(void); +extern s32 osAiSetFrequency(u32); +extern s32 osAiSetNextBuffer(void *, u32); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_AI_H_ */ diff --git a/include/PR/os_cache.h b/include/PR/os_cache.h new file mode 100644 index 00000000..93d53c5f --- /dev/null +++ b/include/PR/os_cache.h @@ -0,0 +1,96 @@ + +/*==================================================================== + * os_cache.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_cache.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:04 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_CACHE_H_ +#define _OS_CACHE_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +#define OS_DCACHE_ROUNDUP_ADDR(x) (void *)(((((u32)(x)+0xf)/0x10)*0x10)) +#define OS_DCACHE_ROUNDUP_SIZE(x) (u32)(((((u32)(x)+0xf)/0x10)*0x10)) + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Cache operations and macros */ + +extern void osInvalDCache(void *, size_t); +extern void osInvalICache(void *, size_t); +extern void osWritebackDCache(void *, size_t); +extern void osWritebackDCacheAll(void); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_CACHE_H_ */ diff --git a/include/PR/os_cont.h b/include/PR/os_cont.h new file mode 100644 index 00000000..2754f250 --- /dev/null +++ b/include/PR/os_cont.h @@ -0,0 +1,207 @@ + +/*==================================================================== + * os_cont.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_cont.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:05 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_CONT_H_ +#define _OS_CONT_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +/* + * Structure for controllers + */ + +typedef struct { + u16 type; /* Controller Type */ + u8 status; /* Controller status */ + u8 errno; +}OSContStatus; + +typedef struct { + u16 button; + s8 stick_x; /* -80 <= stick_x <= 80 */ + s8 stick_y; /* -80 <= stick_y <= 80 */ + u8 errno; +} OSContPad; + +typedef struct { + void *address; /* Ram pad Address: 11 bits */ + u8 databuffer[32]; /* address of the data buffer */ + u8 addressCrc; /* CRC code for address */ + u8 dataCrc; /* CRC code for data */ + u8 errno; +} OSContRamIo; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Controllers number + */ + +#ifndef _HW_VERSION_1 +#define MAXCONTROLLERS 4 +#else +#define MAXCONTROLLERS 6 +#endif + +/* controller errors */ +#define CONT_NO_RESPONSE_ERROR 0x8 +#define CONT_OVERRUN_ERROR 0x4 +#ifdef _HW_VERSION_1 +#define CONT_FRAME_ERROR 0x2 +#define CONT_COLLISION_ERROR 0x1 +#endif + +/* Controller type */ + +#define CONT_ABSOLUTE 0x0001 +#define CONT_RELATIVE 0x0002 +#define CONT_JOYPORT 0x0004 +#define CONT_EEPROM 0x8000 +#define CONT_EEP16K 0x4000 +#define CONT_TYPE_MASK 0x1f07 +#define CONT_TYPE_NORMAL 0x0005 +#define CONT_TYPE_MOUSE 0x0002 +#define CONT_TYPE_VOICE 0x0100 + +/* Controller status */ + +#define CONT_CARD_ON 0x01 +#define CONT_CARD_PULL 0x02 +#define CONT_ADDR_CRC_ER 0x04 +#define CONT_EEPROM_BUSY 0x80 + +/* Buttons */ + +#define CONT_A 0x8000 +#define CONT_B 0x4000 +#define CONT_G 0x2000 +#define CONT_START 0x1000 +#define CONT_UP 0x0800 +#define CONT_DOWN 0x0400 +#define CONT_LEFT 0x0200 +#define CONT_RIGHT 0x0100 +#define CONT_L 0x0020 +#define CONT_R 0x0010 +#define CONT_E 0x0008 +#define CONT_D 0x0004 +#define CONT_C 0x0002 +#define CONT_F 0x0001 + +/* Nintendo's official button names */ + +#define A_BUTTON CONT_A +#define B_BUTTON CONT_B +#define L_TRIG CONT_L +#define R_TRIG CONT_R +#define Z_TRIG CONT_G +#define START_BUTTON CONT_START +#define U_JPAD CONT_UP +#define L_JPAD CONT_LEFT +#define R_JPAD CONT_RIGHT +#define D_JPAD CONT_DOWN +#define U_CBUTTONS CONT_E +#define L_CBUTTONS CONT_C +#define R_CBUTTONS CONT_F +#define D_CBUTTONS CONT_D + +/* Controller error number */ + +#define CONT_ERR_NO_CONTROLLER PFS_ERR_NOPACK /* 1 */ +#define CONT_ERR_CONTRFAIL CONT_OVERRUN_ERROR /* 4 */ +#define CONT_ERR_INVALID PFS_ERR_INVALID /* 5 */ +#define CONT_ERR_DEVICE PFS_ERR_DEVICE /* 11 */ +#define CONT_ERR_NOT_READY 12 +#define CONT_ERR_VOICE_MEMORY 13 +#define CONT_ERR_VOICE_WORD 14 +#define CONT_ERR_VOICE_NO_RESPONSE 15 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Controller interface */ + +extern s32 osContInit(OSMesgQueue *, u8 *, OSContStatus *); +extern s32 osContReset(OSMesgQueue *, OSContStatus *); +extern s32 osContStartQuery(OSMesgQueue *); +extern s32 osContStartReadData(OSMesgQueue *); +#ifndef _HW_VERSION_1 +extern s32 osContSetCh(u8); +#endif +extern void osContGetQuery(OSContStatus *); +extern void osContGetReadData(OSContPad *); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_CONT_H_ */ diff --git a/include/PR/os_eeprom.h b/include/PR/os_eeprom.h new file mode 100644 index 00000000..b3bca814 --- /dev/null +++ b/include/PR/os_eeprom.h @@ -0,0 +1,107 @@ + +/*==================================================================== + * os_eeprom.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_eeprom.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:06 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_EEPROM_H_ +#define _OS_EEPROM_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include "os_message.h" + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* EEPROM TYPE */ + +#define EEPROM_TYPE_4K 0x01 +#define EEPROM_TYPE_16K 0x02 + +/* definition for EEPROM */ + +#define EEPROM_MAXBLOCKS 64 +#define EEP16K_MAXBLOCKS 256 +#define EEPROM_BLOCK_SIZE 8 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* EEPROM interface */ + +extern s32 osEepromProbe(OSMesgQueue *); +extern s32 osEepromRead(OSMesgQueue *, u8, u8 *); +extern s32 osEepromWrite(OSMesgQueue *, u8, u8 *); +extern s32 osEepromLongRead(OSMesgQueue *, u8, u8 *, int); +extern s32 osEepromLongWrite(OSMesgQueue *, u8, u8 *, int); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_EEPROM_H_ */ diff --git a/include/PR/os_exception.h b/include/PR/os_exception.h new file mode 100644 index 00000000..245e5e69 --- /dev/null +++ b/include/PR/os_exception.h @@ -0,0 +1,119 @@ + +/*==================================================================== + * os_exception.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_exception.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:07 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_EXCEPTION_H_ +#define _OS_EXCEPTION_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#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 */ + +/* 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 + + +#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); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_EXCEPTION_H_ */ diff --git a/include/PR/os_internal.h b/include/PR/os_internal.h new file mode 100644 index 00000000..a18e0367 --- /dev/null +++ b/include/PR/os_internal.h @@ -0,0 +1,18 @@ +#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 */ + +/* Variables */ + +//extern u64 osClockRate; + +/* Functions */ + +/*u32 __osProbeTLB(void *); +u32 __osDisableInt(void); +void __osRestoreInt(u32);*/ +OSThread *__osGetCurrFaultedThread(void); + +#endif diff --git a/include/PR/os_libc.h b/include/PR/os_libc.h new file mode 100644 index 00000000..94111c0b --- /dev/null +++ b/include/PR/os_libc.h @@ -0,0 +1,10 @@ +#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); + +#endif /* !_OS_LIBC_H_ */ diff --git a/include/PR/os_message.h b/include/PR/os_message.h new file mode 100644 index 00000000..191e1b1d --- /dev/null +++ b/include/PR/os_message.h @@ -0,0 +1,163 @@ +/*==================================================================== + * os_message.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_message.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:15 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_MESSAGE_H_ +#define _OS_MESSAGE_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef u32 OSEvent; + +/* + * Structure for message + */ +typedef void * OSMesg; + +/* + * Structure for message queue + */ +typedef struct OSMesgQueue_s { + OSThread *mtqueue; /* Queue to store threads blocked + on empty mailboxes (receive) */ + OSThread *fullqueue; /* Queue to store threads blocked + on full mailboxes (send) */ + s32 validCount; /* Contains number of valid message */ + s32 first; /* Points to first valid message */ + s32 msgCount; /* Contains total # of messages */ + OSMesg *msg; /* Points to message buffer array */ +} OSMesgQueue; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* Events */ +#ifdef _FINALROM +#define OS_NUM_EVENTS 15 +#else +#define OS_NUM_EVENTS 23 +#endif + +#define OS_EVENT_SW1 0 /* CPU SW1 interrupt */ +#define OS_EVENT_SW2 1 /* CPU SW2 interrupt */ +#define OS_EVENT_CART 2 /* Cartridge interrupt: used by rmon */ +#define OS_EVENT_COUNTER 3 /* Counter int: used by VI/Timer Mgr */ +#define OS_EVENT_SP 4 /* SP task done interrupt */ +#define OS_EVENT_SI 5 /* SI (controller) interrupt */ +#define OS_EVENT_AI 6 /* AI interrupt */ +#define OS_EVENT_VI 7 /* VI interrupt: used by VI/Timer Mgr */ +#define OS_EVENT_PI 8 /* PI interrupt: used by PI Manager */ +#define OS_EVENT_DP 9 /* DP full sync interrupt */ +#define OS_EVENT_CPU_BREAK 10 /* CPU breakpoint: used by rmon */ +#define OS_EVENT_SP_BREAK 11 /* SP breakpoint: used by rmon */ +#define OS_EVENT_FAULT 12 /* CPU fault event: used by rmon */ +#define OS_EVENT_THREADSTATUS 13 /* CPU thread status: used by rmon */ +#define OS_EVENT_PRENMI 14 /* Pre NMI interrupt */ +#ifndef _FINALROM +#define OS_EVENT_RDB_READ_DONE 15 /* RDB read ok event: used by rmon */ +#define OS_EVENT_RDB_LOG_DONE 16 /* read of log data complete */ +#define OS_EVENT_RDB_DATA_DONE 17 /* read of hostio data complete */ +#define OS_EVENT_RDB_REQ_RAMROM 18 /* host needs ramrom access */ +#define OS_EVENT_RDB_FREE_RAMROM 19 /* host is done with ramrom access */ +#define OS_EVENT_RDB_DBG_DONE 20 +#define OS_EVENT_RDB_FLUSH_PROF 21 +#define OS_EVENT_RDB_ACK_PROF 22 +#endif + +/* Flags to turn blocking on/off when sending/receiving message */ + +#define OS_MESG_NOBLOCK 0 +#define OS_MESG_BLOCK 1 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + +/* Get count of valid messages in queue */ +#define MQ_GET_COUNT(mq) ((mq)->validCount) + +/* Figure out if message queue is empty or full */ +#define MQ_IS_EMPTY(mq) (MQ_GET_COUNT(mq) == 0) +#define MQ_IS_FULL(mq) (MQ_GET_COUNT(mq) >= (mq)->msgCount) + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Message operations */ + +extern void osCreateMesgQueue(OSMesgQueue *, OSMesg *, s32); +extern s32 osSendMesg(OSMesgQueue *, OSMesg, s32); +extern s32 osJamMesg(OSMesgQueue *, OSMesg, s32); +extern s32 osRecvMesg(OSMesgQueue *, OSMesg *, s32); + +/* Event operations */ + +extern void osSetEventMesg(OSEvent, OSMesgQueue *, OSMesg); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_MESSAGE_H_ */ \ No newline at end of file diff --git a/include/PR/os_misc.h b/include/PR/os_misc.h new file mode 100644 index 00000000..f0a0818c --- /dev/null +++ b/include/PR/os_misc.h @@ -0,0 +1,9 @@ +#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_pi.h b/include/PR/os_pi.h new file mode 100644 index 00000000..e2e22644 --- /dev/null +++ b/include/PR/os_pi.h @@ -0,0 +1,96 @@ +#ifndef _ULTRA64_PI_H_ +#define _ULTRA64_PI_H_ + +/* Ultra64 Parallel Interface */ + +/* Types */ + +typedef struct { +#if !defined(VERSION_EU) && !defined(VERSION_SH) + u32 errStatus; +#endif + void *dramAddr; + void *C2Addr; + u32 sectorSize; + u32 C1ErrNum; + u32 C1ErrSector[4]; +} __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 unk10; //error status added moved to blockinfo +#endif + u32 bmCtlShadow; // 10 + u32 seqCtlShadow; // 14 + __OSBlockInfo block[2]; // 18 +} __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; +} OSPiHandle; + +typedef struct { + u8 type; + uintptr_t address; +} OSPiInfo; + +typedef struct { + u16 type; + u8 pri; + u8 status; + OSMesgQueue *retQueue; +} OSIoMesgHdr; + +typedef struct { + /*0x00*/ OSIoMesgHdr hdr; + /*0x08*/ void *dramAddr; + /*0x0C*/ uintptr_t devAddr; + /*0x10*/ size_t size; + OSPiHandle *piHandle; // from the official definition +} OSIoMesg; + +typedef struct { + s32 active; /* Status flag */ + OSThread *thread; /* Calling thread */ + OSMesgQueue *cmdQueue; /* Command queue */ + OSMesgQueue *evtQueue; /* Event queue */ + OSMesgQueue *acsQueue; /* Access queue */ + /* Raw DMA routine */ + s32 (*dma)(s32, u32, void *, u32); + s32 (*edma)(OSPiHandle *, s32, u32, void *, u32); +} OSDevMgr; + +/* Definitions */ + +#define OS_READ 0 // device -> RDRAM +#define OS_WRITE 1 // device <- RDRAM + +#define OS_MESG_PRI_NORMAL 0 +#define OS_MESG_PRI_HIGH 1 + +/* Functions */ + +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 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); +#endif diff --git a/include/PR/os_rdp.h b/include/PR/os_rdp.h new file mode 100644 index 00000000..6b3d288c --- /dev/null +++ b/include/PR/os_rdp.h @@ -0,0 +1,92 @@ + +/*==================================================================== + * os_rdp.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_rdp.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:16 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_RDP_H_ +#define _OS_RDP_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* Display processor interface (Dp) */ +extern u32 osDpGetStatus(void); +extern void osDpSetStatus(u32); +extern void osDpGetCounters(u32 *); +extern s32 osDpSetNextBuffer(void *, u64); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_RDP_H_ */ diff --git a/include/PR/os_thread.h b/include/PR/os_thread.h new file mode 100644 index 00000000..76e528b5 --- /dev/null +++ b/include/PR/os_thread.h @@ -0,0 +1,75 @@ +#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 + +/* Types */ + +typedef s32 OSPri; +typedef s32 OSId; + +typedef union +{ + struct {f32 f_odd; f32 f_even;} f; +} __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; + __OSfp fp0, fp2, fp4, fp6, fp8, fp10, fp12, fp14; + __OSfp fp16, fp18, fp20, fp22, fp24, fp26, fp28, fp30; +} __OSThreadContext; + +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; +} OSThread; + + +/* Functions */ + +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); + +#endif diff --git a/include/PR/os_time.h b/include/PR/os_time.h new file mode 100644 index 00000000..328e6015 --- /dev/null +++ b/include/PR/os_time.h @@ -0,0 +1,27 @@ +#ifndef _ULTRA64_TIME_H_ +#define _ULTRA64_TIME_H_ + +#include +#include + +/* Types */ + +typedef struct OSTimer_str +{ + struct OSTimer_str *next; + struct OSTimer_str *prev; + u64 interval; + u64 remaining; + OSMesgQueue *mq; + OSMesg *msg; +} OSTimer; + +typedef u64 OSTime; + +/* Functions */ + +OSTime osGetTime(void); +void osSetTime(OSTime time); +u32 osSetTimer(OSTimer *, OSTime, u64, OSMesgQueue *, OSMesg); + +#endif diff --git a/include/PR/os_tlb.h b/include/PR/os_tlb.h new file mode 100644 index 00000000..2cdd5c9c --- /dev/null +++ b/include/PR/os_tlb.h @@ -0,0 +1,107 @@ + +/*==================================================================== + * os_tlb.h + * + * Copyright 1995, Silicon Graphics, Inc. + * All Rights Reserved. + * + * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, + * Inc.; the contents of this file may not be disclosed to third + * parties, copied or duplicated in any form, in whole or in part, + * without the prior written permission of Silicon Graphics, Inc. + * + * RESTRICTED RIGHTS LEGEND: + * Use, duplication or disclosure by the Government is subject to + * restrictions as set forth in subdivision (c)(1)(ii) of the Rights + * in Technical Data and Computer Software clause at DFARS + * 252.227-7013, and/or in similar or successor clauses in the FAR, + * DOD or NASA FAR Supplement. Unpublished - rights reserved under the + * Copyright Laws of the United States. + *====================================================================*/ + +/*---------------------------------------------------------------------* + Copyright (C) 1998 Nintendo. (Originated by SGI) + + $RCSfile: os_tlb.h,v $ + $Revision: 1.1 $ + $Date: 1998/10/09 08:01:20 $ + *---------------------------------------------------------------------*/ + +#ifndef _OS_TLB_H_ +#define _OS_TLB_H_ + +#ifdef _LANGUAGE_C_PLUS_PLUS +extern "C" { +#endif + +#include + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Type definitions + * + */ + +typedef u32 OSPageMask; + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +/************************************************************************** + * + * Global definitions + * + */ + +/* + * Page size argument for TLB routines + */ +#define OS_PM_4K 0x0000000 +#define OS_PM_16K 0x0006000 +#define OS_PM_64K 0x001e000 +#define OS_PM_256K 0x007e000 +#define OS_PM_1M 0x01fe000 +#define OS_PM_4M 0x07fe000 +#define OS_PM_16M 0x1ffe000 + + +#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) + +/************************************************************************** + * + * Macro definitions + * + */ + + +/************************************************************************** + * + * Extern variables + * + */ + + +/************************************************************************** + * + * Function prototypes + * + */ + +/* TLB management routines */ + +extern void osMapTLB(s32, OSPageMask, void *, u32, u32, s32); +extern void osMapTLBRdb(void); +extern void osUnmapTLB(s32); +extern void osUnmapTLBAll(void); +extern void osSetTLBASID(s32); + + +#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ + +#ifdef _LANGUAGE_C_PLUS_PLUS +} +#endif + +#endif /* !_OS_TLB_H_ */ diff --git a/include/PR/os_vi.h b/include/PR/os_vi.h new file mode 100644 index 00000000..522bd1e0 --- /dev/null +++ b/include/PR/os_vi.h @@ -0,0 +1,114 @@ +#ifndef _ULTRA64_VI_H_ +#define _ULTRA64_VI_H_ + +/* Ultra64 Video Interface */ + + +/* 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 + +#define OS_VI_GAMMA 0x08 +#define OS_VI_GAMMA_DITHER 0x04 +#define OS_VI_DIVOT 0x10 +#define OS_VI_DITHER_FILTER 0x10000 +#define OS_VI_UNK200 0x200 +#define OS_VI_UNK100 0x100 + + +/* Types */ + +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; +} OSViFieldRegs; + +typedef struct +{ + u8 type; + OSViCommonRegs comRegs; + OSViFieldRegs fldRegs[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); + + +#define OS_VI_NTSC_LPN1 0 /* NTSC */ +#define OS_VI_NTSC_LPF1 1 +#define OS_VI_NTSC_LAN1 2 +#define OS_VI_NTSC_LAF1 3 +#define OS_VI_NTSC_LPN2 4 +#define OS_VI_NTSC_LPF2 5 +#define OS_VI_NTSC_LAN2 6 +#define OS_VI_NTSC_LAF2 7 +#define OS_VI_NTSC_HPN1 8 +#define OS_VI_NTSC_HPF1 9 +#define OS_VI_NTSC_HAN1 10 +#define OS_VI_NTSC_HAF1 11 +#define OS_VI_NTSC_HPN2 12 +#define OS_VI_NTSC_HPF2 13 + +#define OS_VI_PAL_LPN1 14 /* PAL */ +#define OS_VI_PAL_LPF1 15 +#define OS_VI_PAL_LAN1 16 +#define OS_VI_PAL_LAF1 17 +#define OS_VI_PAL_LPN2 18 +#define OS_VI_PAL_LPF2 19 +#define OS_VI_PAL_LAN2 20 +#define OS_VI_PAL_LAF2 21 +#define OS_VI_PAL_HPN1 22 +#define OS_VI_PAL_HPF1 23 +#define OS_VI_PAL_HAN1 24 +#define OS_VI_PAL_HAF1 25 +#define OS_VI_PAL_HPN2 26 +#define OS_VI_PAL_HPF2 27 + +extern OSViMode osViModeTable[]; /* Global VI mode table */ + + +#endif \ No newline at end of file diff --git a/include/PR/sptask.h b/include/PR/sptask.h new file mode 100644 index 00000000..8f23c1b2 --- /dev/null +++ b/include/PR/sptask.h @@ -0,0 +1,113 @@ +#ifndef _ULTRA64_SPTASK_H_ +#define _ULTRA64_SPTASK_H_ + +/* Task Types */ +#define M_GFXTASK 1 +#define M_AUDTASK 2 +#define M_VIDTASK 3 +#define M_HVQTASK 6 +#define M_HVQMTASK 7 + +#if (defined(F3DEX_GBI) || defined(F3DLP_GBI) || defined(F3DEX_GBI_2)) +#define OS_YIELD_DATA_SIZE 0xc00 +#else +#define OS_YIELD_DATA_SIZE 0x900 +#endif +#define OS_YIELD_AUDIO_SIZE 0x400 + +/* 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); + +#endif diff --git a/include/PR/ucode.h b/include/PR/ucode.h new file mode 100644 index 00000000..37fd1977 --- /dev/null +++ b/include/PR/ucode.h @@ -0,0 +1,23 @@ +#ifndef _ULTRA64_UCODE_H_ +#define _ULTRA64_UCODE_H_ + +#define SP_DRAM_STACK_SIZE8 0x400 +#define SP_UCODE_SIZE 0x1000 +#define SP_UCODE_DATA_SIZE 0x800 + +// 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[]; + +#endif diff --git a/include/PR/ultratypes.h b/include/PR/ultratypes.h new file mode 100644 index 00000000..04b872e3 --- /dev/null +++ b/include/PR/ultratypes.h @@ -0,0 +1,42 @@ +#ifndef _TYPES_H_ +#define _TYPES_H_ + +#ifndef NULL +#define NULL (void *)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 + +#endif diff --git a/include/hardware.h b/include/hardware.h index 48e0d0a9..d8c886a5 100644 --- a/include/hardware.h +++ b/include/hardware.h @@ -1,6 +1,7 @@ #ifndef _HARDWARE_H_ #define _HARDWARE_H_ -#include "types.h" +#include "libultra_internal.h" +//#include "types.h" #define HW_REG(reg, type) *(volatile type *)(u32*)(reg | 0xa0000000) diff --git a/include/libultra_internal.h b/include/libultra_internal.h new file mode 100644 index 00000000..d39c66d6 --- /dev/null +++ b/include/libultra_internal.h @@ -0,0 +1,5 @@ +#ifndef _LIBULTRA_INTERNAL_H_ +#define _LIBULTRA_INTERNAL_H_ +#include + +#endif diff --git a/include/types.h b/include/types.h index 566cd92f..04b872e3 100644 --- a/include/types.h +++ b/include/types.h @@ -1,21 +1,42 @@ #ifndef _TYPES_H_ #define _TYPES_H_ -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned int u32; -typedef unsigned long long u64; -typedef signed char s8; -typedef signed short s16; -typedef signed int s32; -typedef signed long long s64; -typedef float f32; -typedef double f64; - -typedef u32 size_t; - #ifndef NULL - #define NULL 0 +#define NULL (void *)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 + #endif diff --git a/include/ultra64.h b/include/ultra64.h new file mode 100644 index 00000000..b53e434a --- /dev/null +++ b/include/ultra64.h @@ -0,0 +1,34 @@ + +#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 + +#endif diff --git a/lib/asm/non_matchings/osCreateThread_0C9450/osCreateThread.s b/lib/asm/non_matchings/osCreateThread_0C9450/osCreateThread.s deleted file mode 100644 index e6a12776..00000000 --- a/lib/asm/non_matchings/osCreateThread_0C9450/osCreateThread.s +++ /dev/null @@ -1,87 +0,0 @@ -glabel osCreateThread -/* 0C9450 800C8850 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 0C9454 800C8854 AFA40028 */ sw $a0, 0x28($sp) -/* 0C9458 800C8858 AFA5002C */ sw $a1, 0x2c($sp) -/* 0C945C 800C885C 8FAE002C */ lw $t6, 0x2c($sp) -/* 0C9460 800C8860 8FAF0028 */ lw $t7, 0x28($sp) -/* 0C9464 800C8864 AFBF001C */ sw $ra, 0x1c($sp) -/* 0C9468 800C8868 AFA60030 */ sw $a2, 0x30($sp) -/* 0C946C 800C886C AFA70034 */ sw $a3, 0x34($sp) -/* 0C9470 800C8870 AFB00018 */ sw $s0, 0x18($sp) -/* 0C9474 800C8874 ADEE0014 */ sw $t6, 0x14($t7) -/* 0C9478 800C8878 8FB90028 */ lw $t9, 0x28($sp) -/* 0C947C 800C887C 8FB8003C */ lw $t8, 0x3c($sp) -/* 0C9480 800C8880 AF380004 */ sw $t8, 4($t9) -/* 0C9484 800C8884 8FA80028 */ lw $t0, 0x28($sp) -/* 0C9488 800C8888 AD000000 */ sw $zero, ($t0) -/* 0C948C 800C888C 8FA90028 */ lw $t1, 0x28($sp) -/* 0C9490 800C8890 AD200008 */ sw $zero, 8($t1) -/* 0C9494 800C8894 8FAB0028 */ lw $t3, 0x28($sp) -/* 0C9498 800C8898 8FAA0030 */ lw $t2, 0x30($sp) -/* 0C949C 800C889C AD6A011C */ sw $t2, 0x11c($t3) -/* 0C94A0 800C88A0 8FAC0034 */ lw $t4, 0x34($sp) -/* 0C94A4 800C88A4 8FAD0028 */ lw $t5, 0x28($sp) -/* 0C94A8 800C88A8 01807825 */ move $t7, $t4 -/* 0C94AC 800C88AC 000C77C3 */ sra $t6, $t4, 0x1f -/* 0C94B0 800C88B0 ADAE0038 */ sw $t6, 0x38($t5) -/* 0C94B4 800C88B4 ADAF003C */ sw $t7, 0x3c($t5) -/* 0C94B8 800C88B8 8FB80038 */ lw $t8, 0x38($sp) -/* 0C94BC 800C88BC 8FB90028 */ lw $t9, 0x28($sp) -/* 0C94C0 800C88C0 3C0C800D */ lui $t4, %hi(D_800D35A0) # $t4, 0x800d -/* 0C94C4 800C88C4 03004825 */ move $t1, $t8 -/* 0C94C8 800C88C8 2D210010 */ sltiu $at, $t1, 0x10 -/* 0C94CC 800C88CC 001847C3 */ sra $t0, $t8, 0x1f -/* 0C94D0 800C88D0 01015023 */ subu $t2, $t0, $at -/* 0C94D4 800C88D4 252BFFF0 */ addiu $t3, $t1, -0x10 -/* 0C94D8 800C88D8 AF2B00F4 */ sw $t3, 0xf4($t9) -/* 0C94DC 800C88DC AF2A00F0 */ sw $t2, 0xf0($t9) -/* 0C94E0 800C88E0 8FAD0028 */ lw $t5, 0x28($sp) -/* 0C94E4 800C88E4 258C35A0 */ addiu $t4, %lo(D_800D35A0) # addiu $t4, $t4, 0x35a0 -/* 0C94E8 800C88E8 01807825 */ move $t7, $t4 -/* 0C94EC 800C88EC 000C77C3 */ sra $t6, $t4, 0x1f -/* 0C94F0 800C88F0 ADAE0100 */ sw $t6, 0x100($t5) -/* 0C94F4 800C88F4 ADAF0104 */ sw $t7, 0x104($t5) -/* 0C94F8 800C88F8 8FA90028 */ lw $t1, 0x28($sp) -/* 0C94FC 800C88FC 3C18003F */ lui $t8, (0x003FFF01 >> 16) # lui $t8, 0x3f -/* 0C9500 800C8900 3718FF01 */ ori $t8, (0x003FFF01 & 0xFFFF) # ori $t8, $t8, 0xff01 -/* 0C9504 800C8904 AFB80020 */ sw $t8, 0x20($sp) -/* 0C9508 800C8908 3408FF03 */ li $t0, 65283 -/* 0C950C 800C890C AD280118 */ sw $t0, 0x118($t1) -/* 0C9510 800C8910 8FAA0020 */ lw $t2, 0x20($sp) -/* 0C9514 800C8914 8FAC0028 */ lw $t4, 0x28($sp) -/* 0C9518 800C8918 3C01003F */ lui $at, 0x3f -/* 0C951C 800C891C 01415824 */ and $t3, $t2, $at -/* 0C9520 800C8920 000BCC02 */ srl $t9, $t3, 0x10 -/* 0C9524 800C8924 AD990128 */ sw $t9, 0x128($t4) -/* 0C9528 800C8928 8FAF0028 */ lw $t7, 0x28($sp) -/* 0C952C 800C892C 3C0E0100 */ lui $t6, (0x01000800 >> 16) # lui $t6, 0x100 -/* 0C9530 800C8930 35CE0800 */ ori $t6, (0x01000800 & 0xFFFF) # ori $t6, $t6, 0x800 -/* 0C9534 800C8934 ADEE012C */ sw $t6, 0x12c($t7) -/* 0C9538 800C8938 8FAD0028 */ lw $t5, 0x28($sp) -/* 0C953C 800C893C 24180001 */ li $t8, 1 -/* 0C9540 800C8940 ADA00018 */ sw $zero, 0x18($t5) -/* 0C9544 800C8944 8FA80028 */ lw $t0, 0x28($sp) -/* 0C9548 800C8948 A5180010 */ sh $t8, 0x10($t0) -/* 0C954C 800C894C 8FA90028 */ lw $t1, 0x28($sp) -/* 0C9550 800C8950 0C034958 */ jal __osDisableInt -/* 0C9554 800C8954 A5200012 */ sh $zero, 0x12($t1) -/* 0C9558 800C8958 3C0A800E */ lui $t2, %hi(D_800E488C) # $t2, 0x800e -/* 0C955C 800C895C 8D4A488C */ lw $t2, %lo(D_800E488C)($t2) -/* 0C9560 800C8960 8FAB0028 */ lw $t3, 0x28($sp) -/* 0C9564 800C8964 00408025 */ move $s0, $v0 -/* 0C9568 800C8968 3C01800E */ lui $at, %hi(D_800E488C) # $at, 0x800e -/* 0C956C 800C896C AD6A000C */ sw $t2, 0xc($t3) -/* 0C9570 800C8970 8FB90028 */ lw $t9, 0x28($sp) -/* 0C9574 800C8974 02002025 */ move $a0, $s0 -/* 0C9578 800C8978 0C034960 */ jal __osRestoreInt -/* 0C957C 800C897C AC39488C */ sw $t9, %lo(D_800E488C)($at) -/* 0C9580 800C8980 8FBF001C */ lw $ra, 0x1c($sp) -/* 0C9584 800C8984 8FB00018 */ lw $s0, 0x18($sp) -/* 0C9588 800C8988 27BD0028 */ addiu $sp, $sp, 0x28 -/* 0C958C 800C898C 03E00008 */ jr $ra -/* 0C9590 800C8990 00000000 */ nop - -/* 0C9594 800C8994 00000000 */ nop -/* 0C9598 800C8998 00000000 */ nop -/* 0C959C 800C899C 00000000 */ nop - diff --git a/lib/asm/non_matchings/osSetTime_0CDE60/osSetTime.s b/lib/asm/non_matchings/osSetTime_0CDE60/osSetTime.s index 2c7d89a6..205807c6 100644 --- a/lib/asm/non_matchings/osSetTime_0CDE60/osSetTime.s +++ b/lib/asm/non_matchings/osSetTime_0CDE60/osSetTime.s @@ -2,9 +2,9 @@ glabel osSetTime /* 0CDE60 800CD260 AFA40000 */ sw $a0, ($sp) /* 0CDE64 800CD264 8FAE0000 */ lw $t6, ($sp) /* 0CDE68 800CD268 AFA50004 */ sw $a1, 4($sp) -/* 0CDE6C 800CD26C 3C018013 */ lui $at, %hi(D_8012D220) # $at, 0x8013 +/* 0CDE6C 800CD26C 3C018013 */ lui $at, %hi(__osCurrentTime) # $at, 0x8013 /* 0CDE70 800CD270 8FAF0004 */ lw $t7, 4($sp) -/* 0CDE74 800CD274 AC2ED220 */ sw $t6, %lo(D_8012D220)($at) +/* 0CDE74 800CD274 AC2ED220 */ sw $t6, %lo(__osCurrentTime)($at) /* 0CDE78 800CD278 3C018013 */ lui $at, 0x8013 /* 0CDE7C 800CD27C 03E00008 */ jr $ra /* 0CDE80 800CD280 AC2FD224 */ sw $t7, -0x2ddc($at) diff --git a/lib/asm/non_matchings/osStartThread_0C95A0/osStartThread.s b/lib/asm/non_matchings/osStartThread_0C95A0/osStartThread.s index bb0b1324..55ab7292 100644 --- a/lib/asm/non_matchings/osStartThread_0C95A0/osStartThread.s +++ b/lib/asm/non_matchings/osStartThread_0C95A0/osStartThread.s @@ -58,8 +58,8 @@ glabel osStartThread /* 0C9674 800C8A74 0C034CF3 */ jal __osEnqueueThread /* 0C9678 800C8A78 02202825 */ move $a1, $s1 .L800C8A7C: -/* 0C967C 800C8A7C 3C18800E */ lui $t8, %hi(D_800E4890) # $t8, 0x800e -/* 0C9680 800C8A80 8F184890 */ lw $t8, %lo(D_800E4890)($t8) +/* 0C967C 800C8A7C 3C18800E */ lui $t8, %hi(__osRunningThread) # $t8, 0x800e +/* 0C9680 800C8A80 8F184890 */ lw $t8, %lo(__osRunningThread)($t8) /* 0C9684 800C8A84 17000005 */ bnez $t8, .L800C8A9C /* 0C9688 800C8A88 00000000 */ nop /* 0C968C 800C8A8C 0C034D09 */ jal __osDispatchThread @@ -67,10 +67,10 @@ glabel osStartThread /* 0C9694 800C8A94 1000000F */ b .L800C8AD4 /* 0C9698 800C8A98 00000000 */ nop .L800C8A9C: -/* 0C969C 800C8A9C 3C19800E */ lui $t9, %hi(D_800E4890) # $t9, 0x800e +/* 0C969C 800C8A9C 3C19800E */ lui $t9, %hi(__osRunningThread) # $t9, 0x800e /* 0C96A0 800C8AA0 3C09800E */ lui $t1, %hi(D_800E4888) # $t1, 0x800e /* 0C96A4 800C8AA4 8D294888 */ lw $t1, %lo(D_800E4888)($t1) -/* 0C96A8 800C8AA8 8F394890 */ lw $t9, %lo(D_800E4890)($t9) +/* 0C96A8 800C8AA8 8F394890 */ lw $t9, %lo(__osRunningThread)($t9) /* 0C96AC 800C8AAC 8D2A0004 */ lw $t2, 4($t1) /* 0C96B0 800C8AB0 8F280004 */ lw $t0, 4($t9) /* 0C96B4 800C8AB4 010A082A */ slt $at, $t0, $t2 diff --git a/lib/asm/non_matchings/unknown_0C91A0/osCreateMesgQueue.s b/lib/asm/non_matchings/unknown_0C91A0/osCreateMesgQueue.s deleted file mode 100644 index 224b900c..00000000 --- a/lib/asm/non_matchings/unknown_0C91A0/osCreateMesgQueue.s +++ /dev/null @@ -1,15 +0,0 @@ -glabel osCreateMesgQueue -/* 0C9420 800C8820 3C0E800E */ lui $t6, %hi(D_800E4880) # $t6, 0x800e -/* 0C9424 800C8824 3C0F800E */ lui $t7, %hi(D_800E4880) # $t7, 0x800e -/* 0C9428 800C8828 25CE4880 */ addiu $t6, %lo(D_800E4880) # addiu $t6, $t6, 0x4880 -/* 0C942C 800C882C 25EF4880 */ addiu $t7, %lo(D_800E4880) # addiu $t7, $t7, 0x4880 -/* 0C9430 800C8830 AC8E0000 */ sw $t6, ($a0) -/* 0C9434 800C8834 AC8F0004 */ sw $t7, 4($a0) -/* 0C9438 800C8838 AC800008 */ sw $zero, 8($a0) -/* 0C943C 800C883C AC80000C */ sw $zero, 0xc($a0) -/* 0C9440 800C8840 AC860010 */ sw $a2, 0x10($a0) -/* 0C9444 800C8844 03E00008 */ jr $ra -/* 0C9448 800C8848 AC850014 */ sw $a1, 0x14($a0) - -/* 0C944C 800C884C 00000000 */ nop - diff --git a/lib/asm/non_matchings/unknown_0C96F0/osRecvMesg.s b/lib/asm/non_matchings/unknown_0C96F0/osRecvMesg.s deleted file mode 100644 index a908c24c..00000000 --- a/lib/asm/non_matchings/unknown_0C96F0/osRecvMesg.s +++ /dev/null @@ -1,91 +0,0 @@ -glabel osRecvMesg -/* 0C97B0 800C8BB0 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 0C97B4 800C8BB4 AFBF001C */ sw $ra, 0x1c($sp) -/* 0C97B8 800C8BB8 AFA40028 */ sw $a0, 0x28($sp) -/* 0C97BC 800C8BBC AFA5002C */ sw $a1, 0x2c($sp) -/* 0C97C0 800C8BC0 AFA60030 */ sw $a2, 0x30($sp) -/* 0C97C4 800C8BC4 AFB10018 */ sw $s1, 0x18($sp) -/* 0C97C8 800C8BC8 0C034958 */ jal __osDisableInt -/* 0C97CC 800C8BCC AFB00014 */ sw $s0, 0x14($sp) -/* 0C97D0 800C8BD0 8FAE0028 */ lw $t6, 0x28($sp) -/* 0C97D4 800C8BD4 00408025 */ move $s0, $v0 -/* 0C97D8 800C8BD8 8DCF0008 */ lw $t7, 8($t6) -/* 0C97DC 800C8BDC 15E00012 */ bnez $t7, .L800C8C28 -/* 0C97E0 800C8BE0 00000000 */ nop -.L800C8BE4: -/* 0C97E4 800C8BE4 8FB80030 */ lw $t8, 0x30($sp) -/* 0C97E8 800C8BE8 17000005 */ bnez $t8, .L800C8C00 -/* 0C97EC 800C8BEC 00000000 */ nop -/* 0C97F0 800C8BF0 0C034960 */ jal __osRestoreInt -/* 0C97F4 800C8BF4 02002025 */ move $a0, $s0 -/* 0C97F8 800C8BF8 10000036 */ b .L800C8CD4 -/* 0C97FC 800C8BFC 2402FFFF */ li $v0, -1 -.L800C8C00: -/* 0C9800 800C8C00 3C08800E */ lui $t0, %hi(D_800E4890) # $t0, 0x800e -/* 0C9804 800C8C04 8D084890 */ lw $t0, %lo(D_800E4890)($t0) -/* 0C9808 800C8C08 24190008 */ li $t9, 8 -/* 0C980C 800C8C0C A5190010 */ sh $t9, 0x10($t0) -/* 0C9810 800C8C10 0C034CB3 */ jal __osEnqueueAndYield -/* 0C9814 800C8C14 8FA40028 */ lw $a0, 0x28($sp) -/* 0C9818 800C8C18 8FA90028 */ lw $t1, 0x28($sp) -/* 0C981C 800C8C1C 8D2A0008 */ lw $t2, 8($t1) -/* 0C9820 800C8C20 1140FFF0 */ beqz $t2, .L800C8BE4 -/* 0C9824 800C8C24 00000000 */ nop -.L800C8C28: -/* 0C9828 800C8C28 8FAB002C */ lw $t3, 0x2c($sp) -/* 0C982C 800C8C2C 11600008 */ beqz $t3, .L800C8C50 -/* 0C9830 800C8C30 00000000 */ nop -/* 0C9834 800C8C34 8FAC0028 */ lw $t4, 0x28($sp) -/* 0C9838 800C8C38 8D8E000C */ lw $t6, 0xc($t4) -/* 0C983C 800C8C3C 8D8D0014 */ lw $t5, 0x14($t4) -/* 0C9840 800C8C40 000E7880 */ sll $t7, $t6, 2 -/* 0C9844 800C8C44 01AFC021 */ addu $t8, $t5, $t7 -/* 0C9848 800C8C48 8F190000 */ lw $t9, ($t8) -/* 0C984C 800C8C4C AD790000 */ sw $t9, ($t3) -.L800C8C50: -/* 0C9850 800C8C50 8FA80028 */ lw $t0, 0x28($sp) -/* 0C9854 800C8C54 8D09000C */ lw $t1, 0xc($t0) -/* 0C9858 800C8C58 8D0C0010 */ lw $t4, 0x10($t0) -/* 0C985C 800C8C5C 252A0001 */ addiu $t2, $t1, 1 -/* 0C9860 800C8C60 014C001A */ div $zero, $t2, $t4 -/* 0C9864 800C8C64 00007010 */ mfhi $t6 -/* 0C9868 800C8C68 AD0E000C */ sw $t6, 0xc($t0) -/* 0C986C 800C8C6C 8FAD0028 */ lw $t5, 0x28($sp) -/* 0C9870 800C8C70 15800002 */ bnez $t4, .L800C8C7C -/* 0C9874 800C8C74 00000000 */ nop -/* 0C9878 800C8C78 0007000D */ break 7 -.L800C8C7C: -/* 0C987C 800C8C7C 2401FFFF */ li $at, -1 -/* 0C9880 800C8C80 15810004 */ bne $t4, $at, .L800C8C94 -/* 0C9884 800C8C84 3C018000 */ lui $at, 0x8000 -/* 0C9888 800C8C88 15410002 */ bne $t2, $at, .L800C8C94 -/* 0C988C 800C8C8C 00000000 */ nop -/* 0C9890 800C8C90 0006000D */ break 6 -.L800C8C94: -/* 0C9894 800C8C94 8DAF0008 */ lw $t7, 8($t5) -/* 0C9898 800C8C98 25F8FFFF */ addiu $t8, $t7, -1 -/* 0C989C 800C8C9C ADB80008 */ sw $t8, 8($t5) -/* 0C98A0 800C8CA0 8FB90028 */ lw $t9, 0x28($sp) -/* 0C98A4 800C8CA4 8F2B0004 */ lw $t3, 4($t9) -/* 0C98A8 800C8CA8 8D690000 */ lw $t1, ($t3) -/* 0C98AC 800C8CAC 11200006 */ beqz $t1, .L800C8CC8 -/* 0C98B0 800C8CB0 00000000 */ nop -/* 0C98B4 800C8CB4 0C034D05 */ jal __osPopThread -/* 0C98B8 800C8CB8 27240004 */ addiu $a0, $t9, 4 -/* 0C98BC 800C8CBC 00408825 */ move $s1, $v0 -/* 0C98C0 800C8CC0 0C032268 */ jal osStartThread -/* 0C98C4 800C8CC4 02202025 */ move $a0, $s1 -.L800C8CC8: -/* 0C98C8 800C8CC8 0C034960 */ jal __osRestoreInt -/* 0C98CC 800C8CCC 02002025 */ move $a0, $s0 -/* 0C98D0 800C8CD0 00001025 */ move $v0, $zero -.L800C8CD4: -/* 0C98D4 800C8CD4 8FBF001C */ lw $ra, 0x1c($sp) -/* 0C98D8 800C8CD8 8FB00014 */ lw $s0, 0x14($sp) -/* 0C98DC 800C8CDC 8FB10018 */ lw $s1, 0x18($sp) -/* 0C98E0 800C8CE0 03E00008 */ jr $ra -/* 0C98E4 800C8CE4 27BD0028 */ addiu $sp, $sp, 0x28 - -/* 0C98E8 800C8CE8 00000000 */ nop -/* 0C98EC 800C8CEC 00000000 */ nop - diff --git a/lib/asm/non_matchings/unknown_0C96F0/osStopThread.s b/lib/asm/non_matchings/unknown_0C96F0/osStopThread.s deleted file mode 100644 index 1e60f7d4..00000000 --- a/lib/asm/non_matchings/unknown_0C96F0/osStopThread.s +++ /dev/null @@ -1,55 +0,0 @@ -glabel osStopThread -/* 0C96F0 800C8AF0 27BDFFC8 */ addiu $sp, $sp, -0x38 -/* 0C96F4 800C8AF4 AFBF0024 */ sw $ra, 0x24($sp) -/* 0C96F8 800C8AF8 AFA40038 */ sw $a0, 0x38($sp) -/* 0C96FC 800C8AFC AFB20020 */ sw $s2, 0x20($sp) -/* 0C9700 800C8B00 AFB1001C */ sw $s1, 0x1c($sp) -/* 0C9704 800C8B04 0C034958 */ jal __osDisableInt -/* 0C9708 800C8B08 AFB00018 */ sw $s0, 0x18($sp) -/* 0C970C 800C8B0C 8FAE0038 */ lw $t6, 0x38($sp) -/* 0C9710 800C8B10 00408025 */ move $s0, $v0 -/* 0C9714 800C8B14 15C00003 */ bnez $t6, .L800C8B24 -/* 0C9718 800C8B18 00000000 */ nop -/* 0C971C 800C8B1C 10000003 */ b .L800C8B2C -/* 0C9720 800C8B20 24110004 */ li $s1, 4 -.L800C8B24: -/* 0C9724 800C8B24 8FAF0038 */ lw $t7, 0x38($sp) -/* 0C9728 800C8B28 95F10010 */ lhu $s1, 0x10($t7) -.L800C8B2C: -/* 0C972C 800C8B2C 02209025 */ move $s2, $s1 -/* 0C9730 800C8B30 24010002 */ li $at, 2 -/* 0C9734 800C8B34 1241000F */ beq $s2, $at, .L800C8B74 -/* 0C9738 800C8B38 24010004 */ li $at, 4 -/* 0C973C 800C8B3C 12410005 */ beq $s2, $at, .L800C8B54 -/* 0C9740 800C8B40 24010008 */ li $at, 8 -/* 0C9744 800C8B44 1241000B */ beq $s2, $at, .L800C8B74 -/* 0C9748 800C8B48 00000000 */ nop -/* 0C974C 800C8B4C 10000010 */ b .L800C8B90 -/* 0C9750 800C8B50 00000000 */ nop -.L800C8B54: -/* 0C9754 800C8B54 3C19800E */ lui $t9, %hi(D_800E4890) # $t9, 0x800e -/* 0C9758 800C8B58 8F394890 */ lw $t9, %lo(D_800E4890)($t9) -/* 0C975C 800C8B5C 24180001 */ li $t8, 1 -/* 0C9760 800C8B60 00002025 */ move $a0, $zero -/* 0C9764 800C8B64 0C034CB3 */ jal __osEnqueueAndYield -/* 0C9768 800C8B68 A7380010 */ sh $t8, 0x10($t9) -/* 0C976C 800C8B6C 10000008 */ b .L800C8B90 -/* 0C9770 800C8B70 00000000 */ nop -.L800C8B74: -/* 0C9774 800C8B74 8FA90038 */ lw $t1, 0x38($sp) -/* 0C9778 800C8B78 24080001 */ li $t0, 1 -/* 0C977C 800C8B7C A5280010 */ sh $t0, 0x10($t1) -/* 0C9780 800C8B80 8FAA0038 */ lw $t2, 0x38($sp) -/* 0C9784 800C8B84 8D440008 */ lw $a0, 8($t2) -/* 0C9788 800C8B88 0C034B1C */ jal __osDequeueThread -/* 0C978C 800C8B8C 01402825 */ move $a1, $t2 -.L800C8B90: -/* 0C9790 800C8B90 0C034960 */ jal __osRestoreInt -/* 0C9794 800C8B94 02002025 */ move $a0, $s0 -/* 0C9798 800C8B98 8FBF0024 */ lw $ra, 0x24($sp) -/* 0C979C 800C8B9C 8FB00018 */ lw $s0, 0x18($sp) -/* 0C97A0 800C8BA0 8FB1001C */ lw $s1, 0x1c($sp) -/* 0C97A4 800C8BA4 8FB20020 */ lw $s2, 0x20($sp) -/* 0C97A8 800C8BA8 03E00008 */ jr $ra -/* 0C97AC 800C8BAC 27BD0038 */ addiu $sp, $sp, 0x38 - diff --git a/lib/asm/non_matchings/unknown_0C9A30/osSendMesg.s b/lib/asm/non_matchings/unknown_0C9A30/osSendMesg.s index 5e607dd4..cfeb9068 100644 --- a/lib/asm/non_matchings/unknown_0C9A30/osSendMesg.s +++ b/lib/asm/non_matchings/unknown_0C9A30/osSendMesg.s @@ -20,8 +20,8 @@ glabel osSendMesg /* 0C9A74 800C8E74 24010001 */ li $at, 1 /* 0C9A78 800C8E78 1721000A */ bne $t9, $at, .L800C8EA4 /* 0C9A7C 800C8E7C 00000000 */ nop -/* 0C9A80 800C8E80 3C09800E */ lui $t1, %hi(D_800E4890) # $t1, 0x800e -/* 0C9A84 800C8E84 8D294890 */ lw $t1, %lo(D_800E4890)($t1) +/* 0C9A80 800C8E80 3C09800E */ lui $t1, %hi(__osRunningThread) # $t1, 0x800e +/* 0C9A84 800C8E84 8D294890 */ lw $t1, %lo(__osRunningThread)($t1) /* 0C9A88 800C8E88 24080008 */ li $t0, 8 /* 0C9A8C 800C8E8C A5280010 */ sh $t0, 0x10($t1) /* 0C9A90 800C8E90 8FA40038 */ lw $a0, 0x38($sp) diff --git a/lib/asm/non_matchings/unknown_0C9B80/osPiStartDma.s b/lib/asm/non_matchings/unknown_0C9B80/osPiStartDma.s deleted file mode 100644 index 606c4d1e..00000000 --- a/lib/asm/non_matchings/unknown_0C9B80/osPiStartDma.s +++ /dev/null @@ -1,77 +0,0 @@ -glabel osPiStartDma -/* 0C9B80 800C8F80 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 0C9B84 800C8F84 3C0E800E */ lui $t6, %hi(D_800E3740) # $t6, 0x800e -/* 0C9B88 800C8F88 8DCE3740 */ lw $t6, %lo(D_800E3740)($t6) -/* 0C9B8C 800C8F8C AFBF001C */ sw $ra, 0x1c($sp) -/* 0C9B90 800C8F90 AFA40028 */ sw $a0, 0x28($sp) -/* 0C9B94 800C8F94 AFA5002C */ sw $a1, 0x2c($sp) -/* 0C9B98 800C8F98 AFA60030 */ sw $a2, 0x30($sp) -/* 0C9B9C 800C8F9C AFA70034 */ sw $a3, 0x34($sp) -/* 0C9BA0 800C8FA0 AFB10018 */ sw $s1, 0x18($sp) -/* 0C9BA4 800C8FA4 15C00003 */ bnez $t6, .L800C8FB4 -/* 0C9BA8 800C8FA8 AFB00014 */ sw $s0, 0x14($sp) -/* 0C9BAC 800C8FAC 10000032 */ b .L800C9078 -/* 0C9BB0 800C8FB0 2402FFFF */ li $v0, -1 -.L800C8FB4: -/* 0C9BB4 800C8FB4 8FAF0030 */ lw $t7, 0x30($sp) -/* 0C9BB8 800C8FB8 15E00005 */ bnez $t7, .L800C8FD0 -/* 0C9BBC 800C8FBC 00000000 */ nop -/* 0C9BC0 800C8FC0 8FB90028 */ lw $t9, 0x28($sp) -/* 0C9BC4 800C8FC4 2418000B */ li $t8, 11 -/* 0C9BC8 800C8FC8 10000004 */ b .L800C8FDC -/* 0C9BCC 800C8FCC A7380000 */ sh $t8, ($t9) -.L800C8FD0: -/* 0C9BD0 800C8FD0 8FA90028 */ lw $t1, 0x28($sp) -/* 0C9BD4 800C8FD4 2408000C */ li $t0, 12 -/* 0C9BD8 800C8FD8 A5280000 */ sh $t0, ($t1) -.L800C8FDC: -/* 0C9BDC 800C8FDC 8FAA002C */ lw $t2, 0x2c($sp) -/* 0C9BE0 800C8FE0 8FAB0028 */ lw $t3, 0x28($sp) -/* 0C9BE4 800C8FE4 24010001 */ li $at, 1 -/* 0C9BE8 800C8FE8 A16A0002 */ sb $t2, 2($t3) -/* 0C9BEC 800C8FEC 8FAD0028 */ lw $t5, 0x28($sp) -/* 0C9BF0 800C8FF0 8FAC0040 */ lw $t4, 0x40($sp) -/* 0C9BF4 800C8FF4 ADAC0004 */ sw $t4, 4($t5) -/* 0C9BF8 800C8FF8 8FAF0028 */ lw $t7, 0x28($sp) -/* 0C9BFC 800C8FFC 8FAE0038 */ lw $t6, 0x38($sp) -/* 0C9C00 800C9000 ADEE0008 */ sw $t6, 8($t7) -/* 0C9C04 800C9004 8FB90028 */ lw $t9, 0x28($sp) -/* 0C9C08 800C9008 8FB80034 */ lw $t8, 0x34($sp) -/* 0C9C0C 800C900C AF38000C */ sw $t8, 0xc($t9) -/* 0C9C10 800C9010 8FA90028 */ lw $t1, 0x28($sp) -/* 0C9C14 800C9014 8FA8003C */ lw $t0, 0x3c($sp) -/* 0C9C18 800C9018 AD280010 */ sw $t0, 0x10($t1) -/* 0C9C1C 800C901C 8FAA0028 */ lw $t2, 0x28($sp) -/* 0C9C20 800C9020 AD400014 */ sw $zero, 0x14($t2) -/* 0C9C24 800C9024 8FAB002C */ lw $t3, 0x2c($sp) -/* 0C9C28 800C9028 1561000A */ bne $t3, $at, .L800C9054 -/* 0C9C2C 800C902C 00000000 */ nop -/* 0C9C30 800C9030 0C034DFC */ jal osPiGetCmdQueue -/* 0C9C34 800C9034 00000000 */ nop -/* 0C9C38 800C9038 00408825 */ move $s1, $v0 -/* 0C9C3C 800C903C 02202025 */ move $a0, $s1 -/* 0C9C40 800C9040 8FA50028 */ lw $a1, 0x28($sp) -/* 0C9C44 800C9044 0C034DA8 */ jal osJamMesg -/* 0C9C48 800C9048 00003025 */ move $a2, $zero -/* 0C9C4C 800C904C 10000009 */ b .L800C9074 -/* 0C9C50 800C9050 00408025 */ move $s0, $v0 -.L800C9054: -/* 0C9C54 800C9054 0C034DFC */ jal osPiGetCmdQueue -/* 0C9C58 800C9058 00000000 */ nop -/* 0C9C5C 800C905C 00408825 */ move $s1, $v0 -/* 0C9C60 800C9060 02202025 */ move $a0, $s1 -/* 0C9C64 800C9064 8FA50028 */ lw $a1, 0x28($sp) -/* 0C9C68 800C9068 0C03238C */ jal osSendMesg -/* 0C9C6C 800C906C 00003025 */ move $a2, $zero -/* 0C9C70 800C9070 00408025 */ move $s0, $v0 -.L800C9074: -/* 0C9C74 800C9074 02001025 */ move $v0, $s0 -.L800C9078: -/* 0C9C78 800C9078 8FBF001C */ lw $ra, 0x1c($sp) -/* 0C9C7C 800C907C 8FB00014 */ lw $s0, 0x14($sp) -/* 0C9C80 800C9080 8FB10018 */ lw $s1, 0x18($sp) -/* 0C9C84 800C9084 03E00008 */ jr $ra -/* 0C9C88 800C9088 27BD0028 */ addiu $sp, $sp, 0x28 - -/* 0C9C8C 800C908C 00000000 */ nop - diff --git a/lib/asm/non_matchings/unknown_0CCF90/osSetThreadPri.s b/lib/asm/non_matchings/unknown_0CCF90/osSetThreadPri.s index 9c636908..f628e67e 100644 --- a/lib/asm/non_matchings/unknown_0CCF90/osSetThreadPri.s +++ b/lib/asm/non_matchings/unknown_0CCF90/osSetThreadPri.s @@ -9,8 +9,8 @@ glabel osSetThreadPri /* 0CD45C 800CC85C 00408025 */ move $s0, $v0 /* 0CD460 800CC860 15C00004 */ bnez $t6, .L800CC874 /* 0CD464 800CC864 00000000 */ nop -/* 0CD468 800CC868 3C0F800E */ lui $t7, %hi(D_800E4890) # $t7, 0x800e -/* 0CD46C 800CC86C 8DEF4890 */ lw $t7, %lo(D_800E4890)($t7) +/* 0CD468 800CC868 3C0F800E */ lui $t7, %hi(__osRunningThread) # $t7, 0x800e +/* 0CD46C 800CC86C 8DEF4890 */ lw $t7, %lo(__osRunningThread)($t7) /* 0CD470 800CC870 AFAF0028 */ sw $t7, 0x28($sp) .L800CC874: /* 0CD474 800CC874 8FB80028 */ lw $t8, 0x28($sp) @@ -19,8 +19,8 @@ glabel osSetThreadPri /* 0CD480 800CC880 13280020 */ beq $t9, $t0, .L800CC904 /* 0CD484 800CC884 00000000 */ nop /* 0CD488 800CC888 AF080004 */ sw $t0, 4($t8) -/* 0CD48C 800CC88C 3C0A800E */ lui $t2, %hi(D_800E4890) # $t2, 0x800e -/* 0CD490 800CC890 8D4A4890 */ lw $t2, %lo(D_800E4890)($t2) +/* 0CD48C 800CC88C 3C0A800E */ lui $t2, %hi(__osRunningThread) # $t2, 0x800e +/* 0CD490 800CC890 8D4A4890 */ lw $t2, %lo(__osRunningThread)($t2) /* 0CD494 800CC894 8FA90028 */ lw $t1, 0x28($sp) /* 0CD498 800CC898 112A000C */ beq $t1, $t2, .L800CC8CC /* 0CD49C 800CC89C 00000000 */ nop @@ -36,10 +36,10 @@ glabel osSetThreadPri /* 0CD4C4 800CC8C4 0C034CF3 */ jal __osEnqueueThread /* 0CD4C8 800CC8C8 01802825 */ move $a1, $t4 .L800CC8CC: -/* 0CD4CC 800CC8CC 3C0D800E */ lui $t5, %hi(D_800E4890) # $t5, 0x800e +/* 0CD4CC 800CC8CC 3C0D800E */ lui $t5, %hi(__osRunningThread) # $t5, 0x800e /* 0CD4D0 800CC8D0 3C0F800E */ lui $t7, %hi(D_800E4888) # $t7, 0x800e /* 0CD4D4 800CC8D4 8DEF4888 */ lw $t7, %lo(D_800E4888)($t7) -/* 0CD4D8 800CC8D8 8DAD4890 */ lw $t5, %lo(D_800E4890)($t5) +/* 0CD4D8 800CC8D8 8DAD4890 */ lw $t5, %lo(__osRunningThread)($t5) /* 0CD4DC 800CC8DC 8DF90004 */ lw $t9, 4($t7) /* 0CD4E0 800CC8E0 8DAE0004 */ lw $t6, 4($t5) /* 0CD4E4 800CC8E4 01D9082A */ slt $at, $t6, $t9 diff --git a/lib/asm/non_matchings/unknown_0D2590/viMgrMain.s b/lib/asm/non_matchings/unknown_0D2590/viMgrMain.s index 34ef350b..7c902d6c 100644 --- a/lib/asm/non_matchings/unknown_0D2590/viMgrMain.s +++ b/lib/asm/non_matchings/unknown_0D2590/viMgrMain.s @@ -22,10 +22,10 @@ glabel viMgrMain /* 0D2758 800D1B58 A423D190 */ sh $v1, %lo(D_8012D190)($at) .L800D1B5C: /* 0D275C 800D1B5C 3C138013 */ lui $s3, %hi(D_8012D22C) # $s3, 0x8013 -/* 0D2760 800D1B60 3C128013 */ lui $s2, %hi(D_8012D228) # $s2, 0x8013 -/* 0D2764 800D1B64 3C118013 */ lui $s1, %hi(D_8012D220) # $s1, 0x8013 -/* 0D2768 800D1B68 2631D220 */ addiu $s1, %lo(D_8012D220) # addiu $s1, $s1, -0x2de0 -/* 0D276C 800D1B6C 2652D228 */ addiu $s2, %lo(D_8012D228) # addiu $s2, $s2, -0x2dd8 +/* 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(D_8012D22C) # addiu $s3, $s3, -0x2dd4 /* 0D2774 800D1B74 2415000D */ li $s5, 13 /* 0D2778 800D1B78 27B40044 */ addiu $s4, $sp, 0x44 diff --git a/lib/asm/non_matchings/unknown_0D2910/osViBlack.s b/lib/asm/non_matchings/unknown_0D2910/osViBlack.s deleted file mode 100644 index 70d01d8c..00000000 --- a/lib/asm/non_matchings/unknown_0D2910/osViBlack.s +++ /dev/null @@ -1,32 +0,0 @@ -glabel osViBlack -/* 0D2910 800D1D10 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 0D2914 800D1D14 AFBF001C */ sw $ra, 0x1c($sp) -/* 0D2918 800D1D18 AFA40028 */ sw $a0, 0x28($sp) -/* 0D291C 800D1D1C 0C034958 */ jal __osDisableInt -/* 0D2920 800D1D20 AFB00018 */ sw $s0, 0x18($sp) -/* 0D2924 800D1D24 93AE002B */ lbu $t6, 0x2b($sp) -/* 0D2928 800D1D28 00408025 */ move $s0, $v0 -/* 0D292C 800D1D2C 11C00007 */ beqz $t6, .L800D1D4C -/* 0D2930 800D1D30 00000000 */ nop -/* 0D2934 800D1D34 3C0F800E */ lui $t7, %hi(D_800E4874) # $t7, 0x800e -/* 0D2938 800D1D38 8DEF4874 */ lw $t7, %lo(D_800E4874)($t7) -/* 0D293C 800D1D3C 95F80000 */ lhu $t8, ($t7) -/* 0D2940 800D1D40 37190020 */ ori $t9, $t8, 0x20 -/* 0D2944 800D1D44 10000007 */ b .L800D1D64 -/* 0D2948 800D1D48 A5F90000 */ sh $t9, ($t7) -.L800D1D4C: -/* 0D294C 800D1D4C 3C08800E */ lui $t0, %hi(D_800E4874) # $t0, 0x800e -/* 0D2950 800D1D50 8D084874 */ lw $t0, %lo(D_800E4874)($t0) -/* 0D2954 800D1D54 2401FFDF */ li $at, -33 -/* 0D2958 800D1D58 95090000 */ lhu $t1, ($t0) -/* 0D295C 800D1D5C 01215024 */ and $t2, $t1, $at -/* 0D2960 800D1D60 A50A0000 */ sh $t2, ($t0) -.L800D1D64: -/* 0D2964 800D1D64 0C034960 */ jal __osRestoreInt -/* 0D2968 800D1D68 02002025 */ move $a0, $s0 -/* 0D296C 800D1D6C 8FBF001C */ lw $ra, 0x1c($sp) -/* 0D2970 800D1D70 8FB00018 */ lw $s0, 0x18($sp) -/* 0D2974 800D1D74 27BD0028 */ addiu $sp, $sp, 0x28 -/* 0D2978 800D1D78 03E00008 */ jr $ra -/* 0D297C 800D1D7C 00000000 */ nop - diff --git a/lib/asm/non_matchings/unknown_0D29F0/osGetTime.s b/lib/asm/non_matchings/unknown_0D29F0/osGetTime.s deleted file mode 100644 index be636839..00000000 --- a/lib/asm/non_matchings/unknown_0D29F0/osGetTime.s +++ /dev/null @@ -1,39 +0,0 @@ -glabel osGetTime -/* 0D2DB0 800D21B0 27BDFFC8 */ addiu $sp, $sp, -0x38 -/* 0D2DB4 800D21B4 AFBF001C */ sw $ra, 0x1c($sp) -/* 0D2DB8 800D21B8 0C034958 */ jal __osDisableInt -/* 0D2DBC 800D21BC AFB00018 */ sw $s0, 0x18($sp) -/* 0D2DC0 800D21C0 0C031E34 */ jal osGetCount -/* 0D2DC4 800D21C4 00408025 */ move $s0, $v0 -/* 0D2DC8 800D21C8 AFA20034 */ sw $v0, 0x34($sp) -/* 0D2DCC 800D21CC 3C0F8013 */ lui $t7, %hi(D_8012D228) # $t7, 0x8013 -/* 0D2DD0 800D21D0 8DEFD228 */ lw $t7, %lo(D_8012D228)($t7) -/* 0D2DD4 800D21D4 8FAE0034 */ lw $t6, 0x34($sp) -/* 0D2DD8 800D21D8 3C088013 */ lui $t0, %hi(D_8012D220) # $t0, 0x8013 -/* 0D2DDC 800D21DC 3C098013 */ lui $t1, %hi(D_8012D224) # $t1, 0x8013 -/* 0D2DE0 800D21E0 8D29D224 */ lw $t1, %lo(D_8012D224)($t1) -/* 0D2DE4 800D21E4 8D08D220 */ lw $t0, %lo(D_8012D220)($t0) -/* 0D2DE8 800D21E8 01CFC023 */ subu $t8, $t6, $t7 -/* 0D2DEC 800D21EC AFB80030 */ sw $t8, 0x30($sp) -/* 0D2DF0 800D21F0 02002025 */ move $a0, $s0 -/* 0D2DF4 800D21F4 AFA9002C */ sw $t1, 0x2c($sp) -/* 0D2DF8 800D21F8 0C034960 */ jal __osRestoreInt -/* 0D2DFC 800D21FC AFA80028 */ sw $t0, 0x28($sp) -/* 0D2E00 800D2200 8FB90030 */ lw $t9, 0x30($sp) -/* 0D2E04 800D2204 8FAD002C */ lw $t5, 0x2c($sp) -/* 0D2E08 800D2208 8FBF001C */ lw $ra, 0x1c($sp) -/* 0D2E0C 800D220C 03205825 */ move $t3, $t9 -/* 0D2E10 800D2210 016D1821 */ addu $v1, $t3, $t5 -/* 0D2E14 800D2214 8FAC0028 */ lw $t4, 0x28($sp) -/* 0D2E18 800D2218 240A0000 */ li $t2, 0 -/* 0D2E1C 800D221C 006D082B */ sltu $at, $v1, $t5 -/* 0D2E20 800D2220 002A1021 */ addu $v0, $at, $t2 -/* 0D2E24 800D2224 8FB00018 */ lw $s0, 0x18($sp) -/* 0D2E28 800D2228 27BD0038 */ addiu $sp, $sp, 0x38 -/* 0D2E2C 800D222C 03E00008 */ jr $ra -/* 0D2E30 800D2230 004C1021 */ addu $v0, $v0, $t4 - -/* 0D2E34 800D2234 00000000 */ nop -/* 0D2E38 800D2238 00000000 */ nop -/* 0D2E3C 800D223C 00000000 */ nop - diff --git a/lib/asm/non_matchings/unknown_0D3020/__osDispatchThread.s b/lib/asm/non_matchings/unknown_0D3020/__osDispatchThread.s index 96bbc3a1..814e9466 100644 --- a/lib/asm/non_matchings/unknown_0D3020/__osDispatchThread.s +++ b/lib/asm/non_matchings/unknown_0D3020/__osDispatchThread.s @@ -2,8 +2,8 @@ glabel __osDispatchThread /* 0D4024 800D3424 3C04800E */ lui $a0, %hi(D_800E4888) # $a0, 0x800e /* 0D4028 800D3428 0C034D05 */ jal __osPopThread /* 0D402C 800D342C 24844888 */ addiu $a0, %lo(D_800E4888) # addiu $a0, $a0, 0x4888 -/* 0D4030 800D3430 3C01800E */ lui $at, %hi(D_800E4890) # $at, 0x800e -/* 0D4034 800D3434 AC224890 */ sw $v0, %lo(D_800E4890)($at) +/* 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 diff --git a/lib/asm/non_matchings/unknown_0D3020/__osEnqueueAndYield.s b/lib/asm/non_matchings/unknown_0D3020/__osEnqueueAndYield.s index 9d529a80..c3d42941 100644 --- a/lib/asm/non_matchings/unknown_0D3020/__osEnqueueAndYield.s +++ b/lib/asm/non_matchings/unknown_0D3020/__osEnqueueAndYield.s @@ -1,6 +1,6 @@ glabel __osEnqueueAndYield -/* 0D3ECC 800D32CC 3C05800E */ lui $a1, %hi(D_800E4890) # $a1, 0x800e -/* 0D3ED0 800D32D0 8CA54890 */ lw $a1, %lo(D_800E4890)($a1) +/* 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 diff --git a/lib/asm/non_matchings/unknown_0D3020/__osException.s b/lib/asm/non_matchings/unknown_0D3020/__osException.s index 90bceb58..29841890 100644 --- a/lib/asm/non_matchings/unknown_0D3020/__osException.s +++ b/lib/asm/non_matchings/unknown_0D3020/__osException.s @@ -13,8 +13,8 @@ glabel __osException /* 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(D_800E4890) # $k0, 0x800e -/* 0D38FC 800D2CFC 8F5A4890 */ lw $k0, %lo(D_800E4890)($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) diff --git a/lib/asm/non_matchings/unknown_0D3020/__osTimerInterrupt.s b/lib/asm/non_matchings/unknown_0D3020/__osTimerInterrupt.s deleted file mode 100644 index dfb9802b..00000000 --- a/lib/asm/non_matchings/unknown_0D3020/__osTimerInterrupt.s +++ /dev/null @@ -1,103 +0,0 @@ -glabel __osTimerInterrupt -/* 0D5B4C 800D4F4C 3C0E800E */ lui $t6, %hi(D_800E4910) # $t6, 0x800e -/* 0D5B50 800D4F50 8DCE4910 */ lw $t6, %lo(D_800E4910)($t6) -/* 0D5B54 800D4F54 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 0D5B58 800D4F58 AFBF0014 */ sw $ra, 0x14($sp) -/* 0D5B5C 800D4F5C 8DCF0000 */ lw $t7, ($t6) -/* 0D5B60 800D4F60 11EE0054 */ beq $t7, $t6, .L800D50B4 -/* 0D5B64 800D4F64 00000000 */ nop -.L800D4F68: -/* 0D5B68 800D4F68 3C18800E */ lui $t8, %hi(D_800E4910) # $t8, 0x800e -/* 0D5B6C 800D4F6C 8F184910 */ lw $t8, %lo(D_800E4910)($t8) -/* 0D5B70 800D4F70 8F190000 */ lw $t9, ($t8) -/* 0D5B74 800D4F74 17380006 */ bne $t9, $t8, .L800D4F90 -/* 0D5B78 800D4F78 AFB90024 */ sw $t9, 0x24($sp) -/* 0D5B7C 800D4F7C 0C035D18 */ jal __osSetCompare -/* 0D5B80 800D4F80 00002025 */ move $a0, $zero -/* 0D5B84 800D4F84 3C018013 */ lui $at, %hi(D_8012D230) # $at, 0x8013 -/* 0D5B88 800D4F88 1000004A */ b .L800D50B4 -/* 0D5B8C 800D4F8C AC20D230 */ sw $zero, %lo(D_8012D230)($at) -.L800D4F90: -/* 0D5B90 800D4F90 0C031E34 */ jal osGetCount -/* 0D5B94 800D4F94 00000000 */ nop -/* 0D5B98 800D4F98 AFA20020 */ sw $v0, 0x20($sp) -/* 0D5B9C 800D4F9C 3C098013 */ lui $t1, %hi(D_8012D230) # $t1, 0x8013 -/* 0D5BA0 800D4FA0 8D29D230 */ lw $t1, %lo(D_8012D230)($t1) -/* 0D5BA4 800D4FA4 8FA80020 */ lw $t0, 0x20($sp) -/* 0D5BA8 800D4FA8 8FAF0024 */ lw $t7, 0x24($sp) -/* 0D5BAC 800D4FAC 3C018013 */ lui $at, %hi(D_8012D230) # $at, 0x8013 -/* 0D5BB0 800D4FB0 01095023 */ subu $t2, $t0, $t1 -/* 0D5BB4 800D4FB4 AFAA001C */ sw $t2, 0x1c($sp) -/* 0D5BB8 800D4FB8 AC28D230 */ sw $t0, %lo(D_8012D230)($at) -/* 0D5BBC 800D4FBC 8DEE0010 */ lw $t6, 0x10($t7) -/* 0D5BC0 800D4FC0 8FAB001C */ lw $t3, 0x1c($sp) -/* 0D5BC4 800D4FC4 240C0000 */ li $t4, 0 -/* 0D5BC8 800D4FC8 01E0C825 */ move $t9, $t7 -/* 0D5BCC 800D4FCC 01CC082B */ sltu $at, $t6, $t4 -/* 0D5BD0 800D4FD0 8DEF0014 */ lw $t7, 0x14($t7) -/* 0D5BD4 800D4FD4 14200016 */ bnez $at, .L800D5030 -/* 0D5BD8 800D4FD8 01606825 */ move $t5, $t3 -/* 0D5BDC 800D4FDC 018E082B */ sltu $at, $t4, $t6 -/* 0D5BE0 800D4FE0 14200003 */ bnez $at, .L800D4FF0 -/* 0D5BE4 800D4FE4 01AF082B */ sltu $at, $t5, $t7 -/* 0D5BE8 800D4FE8 10200011 */ beqz $at, .L800D5030 -/* 0D5BEC 800D4FEC 00000000 */ nop -.L800D4FF0: -/* 0D5BF0 800D4FF0 27380010 */ addiu $t8, $t9, 0x10 -/* 0D5BF4 800D4FF4 AFB80018 */ sw $t8, 0x18($sp) -/* 0D5BF8 800D4FF8 8F2B0014 */ lw $t3, 0x14($t9) -/* 0D5BFC 800D4FFC 8F2A0010 */ lw $t2, 0x10($t9) -/* 0D5C00 800D5000 016D082B */ sltu $at, $t3, $t5 -/* 0D5C04 800D5004 014C4023 */ subu $t0, $t2, $t4 -/* 0D5C08 800D5008 01014023 */ subu $t0, $t0, $at -/* 0D5C0C 800D500C 016D4823 */ subu $t1, $t3, $t5 -/* 0D5C10 800D5010 AF290014 */ sw $t1, 0x14($t9) -/* 0D5C14 800D5014 AF280010 */ sw $t0, 0x10($t9) -/* 0D5C18 800D5018 8FAE0024 */ lw $t6, 0x24($sp) -/* 0D5C1C 800D501C 8DC40010 */ lw $a0, 0x10($t6) -/* 0D5C20 800D5020 0C035431 */ jal __osSetTimerIntr -/* 0D5C24 800D5024 8DC50014 */ lw $a1, 0x14($t6) -/* 0D5C28 800D5028 10000022 */ b .L800D50B4 -/* 0D5C2C 800D502C 00000000 */ nop -.L800D5030: -/* 0D5C30 800D5030 8FAF0024 */ lw $t7, 0x24($sp) -/* 0D5C34 800D5034 8DF80000 */ lw $t8, ($t7) -/* 0D5C38 800D5038 8DEA0004 */ lw $t2, 4($t7) -/* 0D5C3C 800D503C AD580000 */ sw $t8, ($t2) -/* 0D5C40 800D5040 8FAB0024 */ lw $t3, 0x24($sp) -/* 0D5C44 800D5044 8D6C0004 */ lw $t4, 4($t3) -/* 0D5C48 800D5048 8D6D0000 */ lw $t5, ($t3) -/* 0D5C4C 800D504C ADAC0004 */ sw $t4, 4($t5) -/* 0D5C50 800D5050 8FA80024 */ lw $t0, 0x24($sp) -/* 0D5C54 800D5054 AD000000 */ sw $zero, ($t0) -/* 0D5C58 800D5058 8FA90024 */ lw $t1, 0x24($sp) -/* 0D5C5C 800D505C AD200004 */ sw $zero, 4($t1) -/* 0D5C60 800D5060 8FB90024 */ lw $t9, 0x24($sp) -/* 0D5C64 800D5064 8F2E0018 */ lw $t6, 0x18($t9) -/* 0D5C68 800D5068 11C00005 */ beqz $t6, .L800D5080 -/* 0D5C6C 800D506C 00000000 */ nop -/* 0D5C70 800D5070 01C02025 */ move $a0, $t6 -/* 0D5C74 800D5074 8F25001C */ lw $a1, 0x1c($t9) -/* 0D5C78 800D5078 0C03238C */ jal osSendMesg -/* 0D5C7C 800D507C 00003025 */ move $a2, $zero -.L800D5080: -/* 0D5C80 800D5080 8FAF0024 */ lw $t7, 0x24($sp) -/* 0D5C84 800D5084 8DF80008 */ lw $t8, 8($t7) -/* 0D5C88 800D5088 8DF9000C */ lw $t9, 0xc($t7) -/* 0D5C8C 800D508C 17000003 */ bnez $t8, .L800D509C -/* 0D5C90 800D5090 00000000 */ nop -/* 0D5C94 800D5094 1320FFB4 */ beqz $t9, .L800D4F68 -/* 0D5C98 800D5098 00000000 */ nop -.L800D509C: -/* 0D5C9C 800D509C ADF80010 */ sw $t8, 0x10($t7) -/* 0D5CA0 800D50A0 ADF90014 */ sw $t9, 0x14($t7) -/* 0D5CA4 800D50A4 0C03544E */ jal __osInsertTimer -/* 0D5CA8 800D50A8 8FA40024 */ lw $a0, 0x24($sp) -/* 0D5CAC 800D50AC 1000FFAE */ b .L800D4F68 -/* 0D5CB0 800D50B0 00000000 */ nop -.L800D50B4: -/* 0D5CB4 800D50B4 8FBF0014 */ lw $ra, 0x14($sp) -/* 0D5CB8 800D50B8 27BD0028 */ addiu $sp, $sp, 0x28 -/* 0D5CBC 800D50BC 03E00008 */ jr $ra -/* 0D5CC0 800D50C0 00000000 */ nop - diff --git a/lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s b/lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s index 060b944b..7795e85c 100644 --- a/lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s +++ b/lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s @@ -1,13 +1,13 @@ glabel __osTimerServicesInit -/* 0D5AC0 800D4EC0 3C018013 */ lui $at, %hi(D_8012D220) # $at, 0x8013 +/* 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(D_8012D224)($at) -/* 0D5AD0 800D4ED0 AC2ED220 */ sw $t6, %lo(D_8012D220)($at) -/* 0D5AD4 800D4ED4 3C018013 */ lui $at, %hi(D_8012D228) # $at, 0x8013 +/* 0D5AD0 800D4ED0 AC2ED220 */ sw $t6, %lo(__osCurrentTime)($at) +/* 0D5AD4 800D4ED4 3C018013 */ lui $at, %hi(__osBaseCounter) # $at, 0x8013 /* 0D5AD8 800D4ED8 3C18800E */ lui $t8, %hi(D_800E4910) # $t8, 0x800e /* 0D5ADC 800D4EDC 8F184910 */ lw $t8, %lo(D_800E4910)($t8) -/* 0D5AE0 800D4EE0 AC20D228 */ sw $zero, %lo(D_8012D228)($at) +/* 0D5AE0 800D4EE0 AC20D228 */ sw $zero, %lo(__osBaseCounter)($at) /* 0D5AE4 800D4EE4 3C018013 */ lui $at, %hi(D_8012D22C) # $at, 0x8013 /* 0D5AE8 800D4EE8 AC20D22C */ sw $zero, %lo(D_8012D22C)($at) /* 0D5AEC 800D4EEC 3C19800E */ lui $t9, %hi(D_800E4910) # $t9, 0x800e diff --git a/lib/asm/non_matchings/unknown_0D3020/func_800D2420.s b/lib/asm/non_matchings/unknown_0D3020/func_800D2420.s deleted file mode 100644 index 28de7bf4..00000000 --- a/lib/asm/non_matchings/unknown_0D3020/func_800D2420.s +++ /dev/null @@ -1,22 +0,0 @@ -glabel func_800D2420 -/* 0D3020 800D2420 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 0D3024 800D2424 AFBF0014 */ sw $ra, 0x14($sp) -/* 0D3028 800D2428 0C034958 */ jal __osDisableInt -/* 0D302C 800D242C AFA40020 */ sw $a0, 0x20($sp) -/* 0D3030 800D2430 3C0F800E */ lui $t7, %hi(D_800E4874) # $t7, 0x800e -/* 0D3034 800D2434 8DEF4874 */ lw $t7, %lo(D_800E4874)($t7) -/* 0D3038 800D2438 8FAE0020 */ lw $t6, 0x20($sp) -/* 0D303C 800D243C AFA2001C */ sw $v0, 0x1c($sp) -/* 0D3040 800D2440 3C18800E */ lui $t8, %hi(D_800E4874) # $t8, 0x800e -/* 0D3044 800D2444 ADEE0004 */ sw $t6, 4($t7) -/* 0D3048 800D2448 8F184874 */ lw $t8, %lo(D_800E4874)($t8) -/* 0D304C 800D244C 97190000 */ lhu $t9, ($t8) -/* 0D3050 800D2450 37280010 */ ori $t0, $t9, 0x10 -/* 0D3054 800D2454 A7080000 */ sh $t0, ($t8) -/* 0D3058 800D2458 0C034960 */ jal __osRestoreInt -/* 0D305C 800D245C 8FA4001C */ lw $a0, 0x1c($sp) -/* 0D3060 800D2460 8FBF0014 */ lw $ra, 0x14($sp) -/* 0D3064 800D2464 27BD0020 */ addiu $sp, $sp, 0x20 -/* 0D3068 800D2468 03E00008 */ jr $ra -/* 0D306C 800D246C 00000000 */ nop - diff --git a/lib/asm/non_matchings/unknown_0D3020/func_800D65B0.s b/lib/asm/non_matchings/unknown_0D3020/func_800D65B0.s index a4f18f4e..22f7ad3d 100644 --- a/lib/asm/non_matchings/unknown_0D3020/func_800D65B0.s +++ b/lib/asm/non_matchings/unknown_0D3020/func_800D65B0.s @@ -3,8 +3,8 @@ glabel func_800D65B0 /* 0D71B4 800D65B4 AFBF001C */ sw $ra, 0x1c($sp) /* 0D71B8 800D65B8 0C034958 */ jal __osDisableInt /* 0D71BC 800D65BC AFB00018 */ sw $s0, 0x18($sp) -/* 0D71C0 800D65C0 3C0F800E */ lui $t7, %hi(D_800E4890) # $t7, 0x800e -/* 0D71C4 800D65C4 8DEF4890 */ lw $t7, %lo(D_800E4890)($t7) +/* 0D71C0 800D65C0 3C0F800E */ lui $t7, %hi(__osRunningThread) # $t7, 0x800e +/* 0D71C4 800D65C4 8DEF4890 */ lw $t7, %lo(__osRunningThread)($t7) /* 0D71C8 800D65C8 240E0002 */ li $t6, 2 /* 0D71CC 800D65CC 3C04800E */ lui $a0, %hi(D_800E4888) # $a0, 0x800e /* 0D71D0 800D65D0 00408025 */ move $s0, $v0 diff --git a/lib/asm/non_matchings/unknown_0D3020/guMtxF2L.s b/lib/asm/non_matchings/unknown_0D3020/guMtxF2L.s deleted file mode 100644 index d21fd55f..00000000 --- a/lib/asm/non_matchings/unknown_0D3020/guMtxF2L.s +++ /dev/null @@ -1,69 +0,0 @@ -glabel guMtxF2L -/* 0D5440 800D4840 3C014780 */ li $at, 0x47800000 # 65536.000000 -/* 0D5444 800D4844 44810000 */ mtc1 $at, $f0 -/* 0D5448 800D4848 00A01025 */ move $v0, $a1 -/* 0D544C 800D484C 24A30020 */ addiu $v1, $a1, 0x20 -/* 0D5450 800D4850 00003025 */ move $a2, $zero -/* 0D5454 800D4854 00803825 */ move $a3, $a0 -/* 0D5458 800D4858 240C0004 */ li $t4, 4 -/* 0D545C 800D485C 240B0002 */ li $t3, 2 -/* 0D5460 800D4860 3C0AFFFF */ lui $t2, 0xffff -.L800D4864: -/* 0D5464 800D4864 00002025 */ move $a0, $zero -/* 0D5468 800D4868 00E04025 */ move $t0, $a3 -/* 0D546C 800D486C C50E0004 */ lwc1 $f14, 4($t0) -/* 0D5470 800D4870 24840001 */ addiu $a0, $a0, 1 -/* 0D5474 800D4874 C5120000 */ lwc1 $f18, ($t0) -/* 0D5478 800D4878 46007402 */ mul.s $f16, $f14, $f0 -/* 0D547C 800D487C 108B0019 */ beq $a0, $t3, .L800D48E4 -/* 0D5480 800D4880 00000000 */ nop -.L800D4884: -/* 0D5484 800D4884 46009382 */ mul.s $f14, $f18, $f0 -/* 0D5488 800D4888 24840001 */ addiu $a0, $a0, 1 -/* 0D548C 800D488C 24420004 */ addiu $v0, $v0, 4 -/* 0D5490 800D4890 24630004 */ addiu $v1, $v1, 4 -/* 0D5494 800D4894 25080008 */ addiu $t0, $t0, 8 -/* 0D5498 800D4898 4600830D */ trunc.w.s $f12, $f16 -/* 0D549C 800D489C 4600738D */ trunc.w.s $f14, $f14 -/* 0D54A0 800D48A0 44096000 */ mfc1 $t1, $f12 -/* 0D54A4 800D48A4 44057000 */ mfc1 $a1, $f14 -/* 0D54A8 800D48A8 0009CC03 */ sra $t9, $t1, 0x10 -/* 0D54AC 800D48AC 332DFFFF */ andi $t5, $t9, 0xffff -/* 0D54B0 800D48B0 00AAC024 */ and $t8, $a1, $t2 -/* 0D54B4 800D48B4 030D7025 */ or $t6, $t8, $t5 -/* 0D54B8 800D48B8 00057C00 */ sll $t7, $a1, 0x10 -/* 0D54BC 800D48BC 01EAC824 */ and $t9, $t7, $t2 -/* 0D54C0 800D48C0 AC4EFFFC */ sw $t6, -4($v0) -/* 0D54C4 800D48C4 3138FFFF */ andi $t8, $t1, 0xffff -/* 0D54C8 800D48C8 03386825 */ or $t5, $t9, $t8 -/* 0D54CC 800D48CC AC6DFFFC */ sw $t5, -4($v1) -/* 0D54D0 800D48D0 C50E0004 */ lwc1 $f14, 4($t0) -/* 0D54D4 800D48D4 C5120000 */ lwc1 $f18, ($t0) -/* 0D54D8 800D48D8 46007402 */ mul.s $f16, $f14, $f0 -/* 0D54DC 800D48DC 148BFFE9 */ bne $a0, $t3, .L800D4884 -/* 0D54E0 800D48E0 00000000 */ nop -.L800D48E4: -/* 0D54E4 800D48E4 46009382 */ mul.s $f14, $f18, $f0 -/* 0D54E8 800D48E8 25080008 */ addiu $t0, $t0, 8 -/* 0D54EC 800D48EC 24420004 */ addiu $v0, $v0, 4 -/* 0D54F0 800D48F0 24630004 */ addiu $v1, $v1, 4 -/* 0D54F4 800D48F4 4600830D */ trunc.w.s $f12, $f16 -/* 0D54F8 800D48F8 4600738D */ trunc.w.s $f14, $f14 -/* 0D54FC 800D48FC 44096000 */ mfc1 $t1, $f12 -/* 0D5500 800D4900 44057000 */ mfc1 $a1, $f14 -/* 0D5504 800D4904 0009CC03 */ sra $t9, $t1, 0x10 -/* 0D5508 800D4908 332DFFFF */ andi $t5, $t9, 0xffff -/* 0D550C 800D490C 00AAC024 */ and $t8, $a1, $t2 -/* 0D5510 800D4910 030D7025 */ or $t6, $t8, $t5 -/* 0D5514 800D4914 00057C00 */ sll $t7, $a1, 0x10 -/* 0D5518 800D4918 01EAC824 */ and $t9, $t7, $t2 -/* 0D551C 800D491C 3138FFFF */ andi $t8, $t1, 0xffff -/* 0D5520 800D4920 AC4EFFFC */ sw $t6, -4($v0) -/* 0D5524 800D4924 03386825 */ or $t5, $t9, $t8 -/* 0D5528 800D4928 AC6DFFFC */ sw $t5, -4($v1) -/* 0D552C 800D492C 24C60001 */ addiu $a2, $a2, 1 -/* 0D5530 800D4930 14CCFFCC */ bne $a2, $t4, .L800D4864 -/* 0D5534 800D4934 24E70010 */ addiu $a3, $a3, 0x10 -/* 0D5538 800D4938 03E00008 */ jr $ra -/* 0D553C 800D493C 00000000 */ nop - diff --git a/lib/asm/non_matchings/unknown_0D3020/guMtxIdentF.s b/lib/asm/non_matchings/unknown_0D3020/guMtxIdentF.s deleted file mode 100644 index 923119af..00000000 --- a/lib/asm/non_matchings/unknown_0D3020/guMtxIdentF.s +++ /dev/null @@ -1,103 +0,0 @@ -glabel guMtxIdentF -/* 0D5540 800D4940 3C013F80 */ li $at, 0x3F800000 # 1.000000 -/* 0D5544 800D4944 00801825 */ move $v1, $a0 -/* 0D5548 800D4948 44810000 */ mtc1 $at, $f0 -/* 0D554C 800D494C 44801000 */ mtc1 $zero, $f2 -/* 0D5550 800D4950 24040001 */ li $a0, 1 -/* 0D5554 800D4954 00001025 */ move $v0, $zero -/* 0D5558 800D4958 24070004 */ li $a3, 4 -/* 0D555C 800D495C 24060003 */ li $a2, 3 -/* 0D5560 800D4960 24050002 */ li $a1, 2 -.L800D4964: -/* 0D5564 800D4964 54400004 */ bnezl $v0, .L800D4978 -/* 0D5568 800D4968 E4620000 */ swc1 $f2, ($v1) -/* 0D556C 800D496C 10000002 */ b .L800D4978 -/* 0D5570 800D4970 E4600000 */ swc1 $f0, ($v1) -/* 0D5574 800D4974 E4620000 */ swc1 $f2, ($v1) -.L800D4978: -/* 0D5578 800D4978 54440004 */ bnel $v0, $a0, .L800D498C -/* 0D557C 800D497C E4620004 */ swc1 $f2, 4($v1) -/* 0D5580 800D4980 10000002 */ b .L800D498C -/* 0D5584 800D4984 E4600004 */ swc1 $f0, 4($v1) -/* 0D5588 800D4988 E4620004 */ swc1 $f2, 4($v1) -.L800D498C: -/* 0D558C 800D498C 54450004 */ bnel $v0, $a1, .L800D49A0 -/* 0D5590 800D4990 E4620008 */ swc1 $f2, 8($v1) -/* 0D5594 800D4994 10000002 */ b .L800D49A0 -/* 0D5598 800D4998 E4600008 */ swc1 $f0, 8($v1) -/* 0D559C 800D499C E4620008 */ swc1 $f2, 8($v1) -.L800D49A0: -/* 0D55A0 800D49A0 54460004 */ bnel $v0, $a2, .L800D49B4 -/* 0D55A4 800D49A4 E462000C */ swc1 $f2, 0xc($v1) -/* 0D55A8 800D49A8 10000002 */ b .L800D49B4 -/* 0D55AC 800D49AC E460000C */ swc1 $f0, 0xc($v1) -/* 0D55B0 800D49B0 E462000C */ swc1 $f2, 0xc($v1) -.L800D49B4: -/* 0D55B4 800D49B4 24420001 */ addiu $v0, $v0, 1 -/* 0D55B8 800D49B8 1447FFEA */ bne $v0, $a3, .L800D4964 -/* 0D55BC 800D49BC 24630010 */ addiu $v1, $v1, 0x10 -/* 0D55C0 800D49C0 03E00008 */ jr $ra -/* 0D55C4 800D49C4 00000000 */ nop - -/* 0D55C8 800D49C8 27BDFFA8 */ addiu $sp, $sp, -0x58 -/* 0D55CC 800D49CC AFBF0014 */ sw $ra, 0x14($sp) -/* 0D55D0 800D49D0 AFA40058 */ sw $a0, 0x58($sp) -/* 0D55D4 800D49D4 0C035250 */ jal guMtxIdentF -/* 0D55D8 800D49D8 27A40018 */ addiu $a0, $sp, 0x18 -/* 0D55DC 800D49DC 27A40018 */ addiu $a0, $sp, 0x18 -/* 0D55E0 800D49E0 0C035210 */ jal guMtxF2L -/* 0D55E4 800D49E4 8FA50058 */ lw $a1, 0x58($sp) -/* 0D55E8 800D49E8 8FBF0014 */ lw $ra, 0x14($sp) -/* 0D55EC 800D49EC 27BD0058 */ addiu $sp, $sp, 0x58 -/* 0D55F0 800D49F0 03E00008 */ jr $ra -/* 0D55F4 800D49F4 00000000 */ nop - -/* 0D55F8 800D49F8 3C014780 */ li $at, 0x47800000 # 65536.000000 -/* 0D55FC 800D49FC 44810000 */ mtc1 $at, $f0 -/* 0D5600 800D4A00 27BDFFF0 */ addiu $sp, $sp, -0x10 -/* 0D5604 800D4A04 00A01025 */ move $v0, $a1 -/* 0D5608 800D4A08 24A30020 */ addiu $v1, $a1, 0x20 -/* 0D560C 800D4A0C 00003025 */ move $a2, $zero -/* 0D5610 800D4A10 00804025 */ move $t0, $a0 -/* 0D5614 800D4A14 240C0004 */ li $t4, 4 -/* 0D5618 800D4A18 240B0002 */ li $t3, 2 -/* 0D561C 800D4A1C 3C0AFFFF */ lui $t2, 0xffff -.L800D4A20: -/* 0D5620 800D4A20 00002025 */ move $a0, $zero -/* 0D5624 800D4A24 01004825 */ move $t1, $t0 -.L800D4A28: -/* 0D5628 800D4A28 8C6E0000 */ lw $t6, ($v1) -/* 0D562C 800D4A2C 8C590000 */ lw $t9, ($v0) -/* 0D5630 800D4A30 24840001 */ addiu $a0, $a0, 1 -/* 0D5634 800D4A34 000E7C02 */ srl $t7, $t6, 0x10 -/* 0D5638 800D4A38 31F8FFFF */ andi $t8, $t7, 0xffff -/* 0D563C 800D4A3C 032A6824 */ and $t5, $t9, $t2 -/* 0D5640 800D4A40 030D7025 */ or $t6, $t8, $t5 -/* 0D5644 800D4A44 AFAE0004 */ sw $t6, 4($sp) -/* 0D5648 800D4A48 8C6F0000 */ lw $t7, ($v1) -/* 0D564C 800D4A4C 8C580000 */ lw $t8, ($v0) -/* 0D5650 800D4A50 8FA50004 */ lw $a1, 4($sp) -/* 0D5654 800D4A54 31F9FFFF */ andi $t9, $t7, 0xffff -/* 0D5658 800D4A58 00186C00 */ sll $t5, $t8, 0x10 -/* 0D565C 800D4A5C 44859000 */ mtc1 $a1, $f18 -/* 0D5660 800D4A60 01AA7024 */ and $t6, $t5, $t2 -/* 0D5664 800D4A64 032E3825 */ or $a3, $t9, $t6 -/* 0D5668 800D4A68 468094A0 */ cvt.s.w $f18, $f18 -/* 0D566C 800D4A6C 44878000 */ mtc1 $a3, $f16 -/* 0D5670 800D4A70 AFA70000 */ sw $a3, ($sp) -/* 0D5674 800D4A74 24420004 */ addiu $v0, $v0, 4 -/* 0D5678 800D4A78 24630004 */ addiu $v1, $v1, 4 -/* 0D567C 800D4A7C 46808420 */ cvt.s.w $f16, $f16 -/* 0D5680 800D4A80 25290008 */ addiu $t1, $t1, 8 -/* 0D5684 800D4A84 46009483 */ div.s $f18, $f18, $f0 -/* 0D5688 800D4A88 46008403 */ div.s $f16, $f16, $f0 -/* 0D568C 800D4A8C E532FFF8 */ swc1 $f18, -8($t1) -/* 0D5690 800D4A90 148BFFE5 */ bne $a0, $t3, .L800D4A28 -/* 0D5694 800D4A94 E530FFFC */ swc1 $f16, -4($t1) -/* 0D5698 800D4A98 24C60001 */ addiu $a2, $a2, 1 -/* 0D569C 800D4A9C 14CCFFE0 */ bne $a2, $t4, .L800D4A20 -/* 0D56A0 800D4AA0 25080010 */ addiu $t0, $t0, 0x10 -/* 0D56A4 800D4AA4 03E00008 */ jr $ra -/* 0D56A8 800D4AA8 27BD0010 */ addiu $sp, $sp, 0x10 - -/* 0D56AC 800D4AAC 00000000 */ nop diff --git a/lib/asm/non_matchings/unknown_0D3020/osDestroyThread.s b/lib/asm/non_matchings/unknown_0D3020/osDestroyThread.s index d8701c24..6a4ebe8e 100644 --- a/lib/asm/non_matchings/unknown_0D3020/osDestroyThread.s +++ b/lib/asm/non_matchings/unknown_0D3020/osDestroyThread.s @@ -10,8 +10,8 @@ glabel osDestroyThread /* 0D7220 800D6620 00408025 */ move $s0, $v0 /* 0D7224 800D6624 15C00005 */ bnez $t6, .L800D663C /* 0D7228 800D6628 00000000 */ nop -/* 0D722C 800D662C 3C0F800E */ lui $t7, %hi(D_800E4890) # $t7, 0x800e -/* 0D7230 800D6630 8DEF4890 */ lw $t7, %lo(D_800E4890)($t7) +/* 0D722C 800D662C 3C0F800E */ lui $t7, %hi(__osRunningThread) # $t7, 0x800e +/* 0D7230 800D6630 8DEF4890 */ lw $t7, %lo(__osRunningThread)($t7) /* 0D7234 800D6634 10000009 */ b .L800D665C /* 0D7238 800D6638 AFAF0038 */ sw $t7, 0x38($sp) .L800D663C: @@ -52,8 +52,8 @@ glabel osDestroyThread /* 0D72B4 800D66B4 1640FFF7 */ bnez $s2, .L800D6694 /* 0D72B8 800D66B8 00000000 */ nop .L800D66BC: -/* 0D72BC 800D66BC 3C0E800E */ lui $t6, %hi(D_800E4890) # $t6, 0x800e -/* 0D72C0 800D66C0 8DCE4890 */ lw $t6, %lo(D_800E4890)($t6) +/* 0D72BC 800D66BC 3C0E800E */ lui $t6, %hi(__osRunningThread) # $t6, 0x800e +/* 0D72C0 800D66C0 8DCE4890 */ lw $t6, %lo(__osRunningThread)($t6) /* 0D72C4 800D66C4 8FAD0038 */ lw $t5, 0x38($sp) /* 0D72C8 800D66C8 15AE0003 */ bne $t5, $t6, .L800D66D8 /* 0D72CC 800D66CC 00000000 */ nop diff --git a/lib/asm/non_matchings/unknown_0D3020/osGetThreadPri.s b/lib/asm/non_matchings/unknown_0D3020/osGetThreadPri.s deleted file mode 100644 index ee5d1184..00000000 --- a/lib/asm/non_matchings/unknown_0D3020/osGetThreadPri.s +++ /dev/null @@ -1,11 +0,0 @@ -glabel osGetThreadPri -/* 0D3140 800D2540 14800003 */ bnez $a0, .L800D2550 -/* 0D3144 800D2544 00000000 */ nop -/* 0D3148 800D2548 3C04800E */ lui $a0, %hi(D_800E4890) # $a0, 0x800e -/* 0D314C 800D254C 8C844890 */ lw $a0, %lo(D_800E4890)($a0) -.L800D2550: -/* 0D3150 800D2550 03E00008 */ jr $ra -/* 0D3154 800D2554 8C820004 */ lw $v0, 4($a0) - -/* 0D3158 800D2558 00000000 */ nop -/* 0D315C 800D255C 00000000 */ nop diff --git a/lib/asm/non_matchings/unknown_0D3020/osJamMesg.s b/lib/asm/non_matchings/unknown_0D3020/osJamMesg.s index 2ec1074f..ac5e04a3 100644 --- a/lib/asm/non_matchings/unknown_0D3020/osJamMesg.s +++ b/lib/asm/non_matchings/unknown_0D3020/osJamMesg.s @@ -19,8 +19,8 @@ glabel osJamMesg /* 0D42E0 800D36E0 24010001 */ li $at, 1 /* 0D42E4 800D36E4 1721000A */ bne $t9, $at, .L800D3710 /* 0D42E8 800D36E8 00000000 */ nop -/* 0D42EC 800D36EC 3C09800E */ lui $t1, %hi(D_800E4890) # $t1, 0x800e -/* 0D42F0 800D36F0 8D294890 */ lw $t1, %lo(D_800E4890)($t1) +/* 0D42EC 800D36EC 3C09800E */ lui $t1, %hi(__osRunningThread) # $t1, 0x800e +/* 0D42F0 800D36F0 8D294890 */ lw $t1, %lo(__osRunningThread)($t1) /* 0D42F4 800D36F4 24080008 */ li $t0, 8 /* 0D42F8 800D36F8 A5280010 */ sh $t0, 0x10($t1) /* 0D42FC 800D36FC 8FA40028 */ lw $a0, 0x28($sp) diff --git a/lib/asm/non_matchings/unknown_0D3020/osPiGetCmdQueue.s b/lib/asm/non_matchings/unknown_0D3020/osPiGetCmdQueue.s index 6bf02b29..f10ad9b1 100644 --- a/lib/asm/non_matchings/unknown_0D3020/osPiGetCmdQueue.s +++ b/lib/asm/non_matchings/unknown_0D3020/osPiGetCmdQueue.s @@ -1,6 +1,6 @@ glabel osPiGetCmdQueue -/* 0D43F0 800D37F0 3C0E800E */ lui $t6, %hi(D_800E3740) # $t6, 0x800e -/* 0D43F4 800D37F4 8DCE3740 */ lw $t6, %lo(D_800E3740)($t6) +/* 0D43F0 800D37F0 3C0E800E */ lui $t6, %hi(__osPiDevMgr) # $t6, 0x800e +/* 0D43F4 800D37F4 8DCE3740 */ lw $t6, %lo(__osPiDevMgr)($t6) /* 0D43F8 800D37F8 15C00003 */ bnez $t6, .L800D3808 /* 0D43FC 800D37FC 00000000 */ nop /* 0D4400 800D3800 03E00008 */ jr $ra diff --git a/lib/src/guMtxUtil.c b/lib/src/guMtxUtil.c new file mode 100644 index 00000000..5979d8e1 --- /dev/null +++ b/lib/src/guMtxUtil.c @@ -0,0 +1,64 @@ +/* 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; + } + } +} \ No newline at end of file diff --git a/lib/src/osCreateThread.c b/lib/src/osCreateThread.c index 18b578f6..fa41adc0 100644 --- a/lib/src/osCreateThread.c +++ b/lib/src/osCreateThread.c @@ -3,5 +3,35 @@ #include "types.h" #include "macros.h" +#include "libultra_internal.h" +#include "PR/R4300.h" -GLOBAL_ASM("lib/asm/non_matchings/osCreateThread_0C9450/osCreateThread.s") +//GLOBAL_ASM("lib/asm/non_matchings/osCreateThread_0C9450/osCreateThread.s") + +extern OSThread *D_800E488C; //__osActiveQueue; +void D_800D35A0(void); //__osCleanupThread + +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)D_800D35A0; + 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 = D_800E488C; + D_800E488C = t; + __osRestoreInt(saveMask); +} \ No newline at end of file diff --git a/lib/src/osGetThreadPri.c b/lib/src/osGetThreadPri.c new file mode 100644 index 00000000..86124f0e --- /dev/null +++ b/lib/src/osGetThreadPri.c @@ -0,0 +1,12 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D2540 */ + +#include "libultra_internal.h" + +extern OSThread *__osRunningThread; +OSPri osGetThreadPri(OSThread *thread) +{ + if (thread == NULL) + thread = __osRunningThread; + return thread->priority; +} \ No newline at end of file diff --git a/lib/src/osPiStartDma.c b/lib/src/osPiStartDma.c new file mode 100644 index 00000000..40626262 --- /dev/null +++ b/lib/src/osPiStartDma.c @@ -0,0 +1,32 @@ +/* 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; //__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 = 11; + else + mb->hdr.type = 12; + 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; +} \ No newline at end of file diff --git a/lib/src/osRecvMesg.c b/lib/src/osRecvMesg.c new file mode 100644 index 00000000..08e28a7f --- /dev/null +++ b/lib/src/osRecvMesg.c @@ -0,0 +1,39 @@ +/* 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" + +extern OSThread *__osRunningThread; + +//GLOBAL_ASM("lib/asm/non_matchings/unknown_0C96F0/osRecvMesg.s") +s32 osRecvMesg(OSMesgQueue *mq, OSMesg *msg, s32 flags) +{ + register u32 saveMask; + saveMask = __osDisableInt(); + + while (MQ_IS_EMPTY(mq)) + { + if (flags == OS_MESG_NOBLOCK) + { + __osRestoreInt(saveMask); + return -1; + } + __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; +} \ No newline at end of file diff --git a/lib/src/osSendMesg.c b/lib/src/osSendMesg.c new file mode 100644 index 00000000..32a3eb97 --- /dev/null +++ b/lib/src/osSendMesg.c @@ -0,0 +1,34 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C8E30 */ +#include "libultra_internal.h" + + +extern OSThread *__osRunningThread; +s32 osSendMesg(OSMesgQueue *mq, OSMesg msg, s32 flags) +{ + register u32 saveMask; + register s32 last; + saveMask = __osDisableInt(); + while (MQ_IS_FULL(mq)) + { + if (flags == OS_MESG_BLOCK) + { + __osRunningThread->state = OS_STATE_WAITING; + __osEnqueueAndYield(&mq->fullqueue); + } + 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; +} \ No newline at end of file diff --git a/lib/src/osSetTimer.c b/lib/src/osSetTimer.c new file mode 100644 index 00000000..34620e4d --- /dev/null +++ b/lib/src/osSetTimer.c @@ -0,0 +1,28 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D4DE0 */ + +#include "macros.h" + +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osSetTimer.s") + + +/*#include "libultra_internal.h" + +extern OSTimer *D_800E4910; + +u32 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 = (OSTime) __osInsertTimer(t); + if(D_800E4910->next == t) { + __osSetTimerIntr(time); + } + return 0; +}*/ \ No newline at end of file diff --git a/lib/src/osStopThread.c b/lib/src/osStopThread.c new file mode 100644 index 00000000..4d445397 --- /dev/null +++ b/lib/src/osStopThread.c @@ -0,0 +1,33 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800C8AF0 */ + +#include "libultra_internal.h" + +extern OSThread *__osRunningThread; + +void osStopThread(OSThread *t) +{ + register u32 saveMask = __osDisableInt(); + register u16 state; + if (t == NULL) + { + state = OS_STATE_RUNNING; + } + else + { + state = t->state; + } + switch (state) + { + case OS_STATE_RUNNING: + __osRunningThread->state = OS_STATE_STOPPED; + __osEnqueueAndYield(NULL); + break; + case OS_STATE_RUNNABLE: + case OS_STATE_WAITING: + t->state = OS_STATE_STOPPED; + __osDequeueThread(t->queue, t); + break; + } + __osRestoreInt(saveMask); +} \ No newline at end of file diff --git a/lib/src/osTimer.c b/lib/src/osTimer.c new file mode 100644 index 00000000..dc3937b5 --- /dev/null +++ b/lib/src/osTimer.c @@ -0,0 +1,105 @@ +/* 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 *D_800E4910; +extern OSTime __osCurrentTime; +extern u32 __osBaseCounter; +extern u32 D_8012D22C; +extern u32 D_8012D230; + + +OSTime __osInsertTimer(OSTimer *t); + +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s") +/*void __osTimerServicesInit(void) +{ + //D_8012D224 = 0; + __osCurrentTime = 0; + __osBaseCounter = 0; + D_8012D22C = 0; + D_800E4910->prev = D_800E4910; + D_800E4910->next = D_800E4910->prev; + D_800E4910->remaining = 0; + D_800E4910->interval = D_800E4910->remaining; + D_800E4910->mq = NULL; + D_800E4910->msg = 0; +}*/ + +void __osTimerInterrupt(void) +{ + OSTimer *t; + u32 count; + u32 elapsed_cycles; + + if (D_800E4910->next == D_800E4910) + return; + while (1){ + t = D_800E4910->next; + if (t == D_800E4910){ + __osSetCompare(0); + D_8012D230 = 0; + break; + } + count = osGetCount(); + elapsed_cycles = count - D_8012D230; + D_8012D230 = 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); + } + } + } +} + +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSetTimerIntr.s") +/*void __osSetTimerIntr(OSTime tim) +{ + OSTime NewTime; + u32 savedMask; + savedMask = __osDisableInt(); + D_8012D230 = osGetCount(); + NewTime = tim + D_8012D230; + __osSetCompare(NewTime); + __osRestoreInt(savedMask); +}*/ + + + +OSTime __osInsertTimer(OSTimer *t) +{ + OSTimer *timep; + OSTime tim; + u32 savedMask; + savedMask = __osDisableInt(); + for (timep = D_800E4910->next, tim = t->remaining; + timep != D_800E4910 && tim > timep->remaining; + tim -= timep->remaining, timep = timep->next) + { + ; + } + t->remaining = tim; + if (timep != D_800E4910) + timep->remaining -= tim; + t->next = timep; + t->prev = timep->prev; + timep->prev->next = t; + timep->prev = t; + __osRestoreInt(savedMask); + return tim; +} \ No newline at end of file diff --git a/lib/src/osViBlack.c b/lib/src/osViBlack.c new file mode 100644 index 00000000..0d823012 --- /dev/null +++ b/lib/src/osViBlack.c @@ -0,0 +1,16 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D1D10 */ + +#include "libultra_internal.h" + +extern OSViContext *D_800E4874; +// TODO: name magic constants +void osViBlack(u8 active) { + register u32 int_disabled = __osDisableInt(); + if (active) { + D_800E4874->unk00 |= 0x20; + } else { + D_800E4874->unk00 &= ~0x20; + } + __osRestoreInt(int_disabled); +} diff --git a/lib/src/osViSwapBuffer.c b/lib/src/osViSwapBuffer.c new file mode 100644 index 00000000..a0086baa --- /dev/null +++ b/lib/src/osViSwapBuffer.c @@ -0,0 +1,13 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D2420 */ + +#include "libultra_internal.h" + +extern OSViContext* D_800E4874; + +void osViSwapBuffer(void* frameBufPtr){ + u32 saveMask = __osDisableInt(); + D_800E4874->buffer = frameBufPtr; + D_800E4874->unk00 |= 0x10; + __osRestoreInt(saveMask); +} \ No newline at end of file diff --git a/lib/src/unknown_0C91A0.c b/lib/src/unknown_0C91A0.c index 593d5caf..a8275a73 100644 --- a/lib/src/unknown_0C91A0.c +++ b/lib/src/unknown_0C91A0.c @@ -1,6 +1,7 @@ /* The comment below is needed for this file to be picked up by generate_ld */ /* RAM_POS: 0x800C85A0 */ +#include "libultra_internal.h" #include "types.h" #include "macros.h" @@ -11,4 +12,14 @@ GLOBAL_ASM("lib/asm/non_matchings/unknown_0C91A0/func_800C8760.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0C91A0/func_800C8790.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0C91A0/func_800C87B4.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0C91A0/func_800C87EC.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0C91A0/osCreateMesgQueue.s") + +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; +} \ No newline at end of file diff --git a/lib/src/unknown_0C96F0.c b/lib/src/unknown_0C96F0.c deleted file mode 100644 index 48aa4f28..00000000 --- a/lib/src/unknown_0C96F0.c +++ /dev/null @@ -1,8 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C8AF0 */ - -#include "types.h" -#include "macros.h" - -GLOBAL_ASM("lib/asm/non_matchings/unknown_0C96F0/osStopThread.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0C96F0/osRecvMesg.s") diff --git a/lib/src/unknown_0C9A30.c b/lib/src/unknown_0C9A30.c deleted file mode 100644 index e3a0acac..00000000 --- a/lib/src/unknown_0C9A30.c +++ /dev/null @@ -1,7 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C8E30 */ - -#include "types.h" -#include "macros.h" - -GLOBAL_ASM("lib/asm/non_matchings/unknown_0C9A30/osSendMesg.s") diff --git a/lib/src/unknown_0C9B80.c b/lib/src/unknown_0C9B80.c deleted file mode 100644 index 4fa010b9..00000000 --- a/lib/src/unknown_0C9B80.c +++ /dev/null @@ -1,7 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800C8F80 */ - -#include "types.h" -#include "macros.h" - -GLOBAL_ASM("lib/asm/non_matchings/unknown_0C9B80/osPiStartDma.s") diff --git a/lib/src/unknown_0D2910.c b/lib/src/unknown_0D2910.c deleted file mode 100644 index 4b6c4e29..00000000 --- a/lib/src/unknown_0D2910.c +++ /dev/null @@ -1,7 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D1D10 */ - -#include "types.h" -#include "macros.h" - -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D2910/osViBlack.s") diff --git a/lib/src/unknown_0D29F0.c b/lib/src/unknown_0D29F0.c index 0b356a7e..750a4cfc 100644 --- a/lib/src/unknown_0D29F0.c +++ b/lib/src/unknown_0D29F0.c @@ -3,6 +3,10 @@ #include "types.h" #include "macros.h" +#include "libultra_internal.h" + +extern OSTime __osCurrentTime;//__osCurrentTime +extern u32 __osBaseCounter; //__osBaseCounter GLOBAL_ASM("lib/asm/non_matchings/unknown_0D29F0/func_800D1DF0.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D29F0/func_800D1E70.s") @@ -10,4 +14,17 @@ GLOBAL_ASM("lib/asm/non_matchings/unknown_0D29F0/func_800D1EB0.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D29F0/_VirtualToPhysicalTask.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D29F0/osSpTaskLoad.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D29F0/osSpTaskStartGo.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D29F0/osGetTime.s") + +OSTime osGetTime() +{ + u32 tmptime; + u32 elapseCount; + OSTime currentCount; + register u32 saveMask; + saveMask = __osDisableInt(); + tmptime = osGetCount(); + elapseCount = tmptime - __osBaseCounter; + currentCount = __osCurrentTime; + __osRestoreInt(saveMask); + return currentCount + elapseCount; +} diff --git a/lib/src/unknown_0D3020.c b/lib/src/unknown_0D3020.c index b48a656c..a1ec6b87 100644 --- a/lib/src/unknown_0D3020.c +++ b/lib/src/unknown_0D3020.c @@ -1,78 +1,9 @@ /* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x800D2420 */ +/* RAM_POS: 0x800D2470 */ #include "types.h" #include "macros.h" -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D2420.s") + GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D2470.s") GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osPiCreateAccessQueue.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osGetThreadPri.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osDisableInt.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osRestoreInt.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/D_800D25A0.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/D_800D2680.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/D_800D2760.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osViInit.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D2C60.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osDequeueThread.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osExceptionPreamble.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osException.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/send_mesg.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osEnqueueAndYield.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osEnqueueThread.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osPopThread.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osDispatchThread.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/D_800D35A0.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osProbeTLB.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D3670.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osJamMesg.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osPiGetCmdQueue.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D3820.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/_Putfld.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/_Printf.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSetSR.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osGetSR.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSetFpcCsr.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSiRawReadIo.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSiRawWriteIo.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osWritebackDCache.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osWritebackICache.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osMapTLBRdb.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osPiRawWriteIo.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D47F0.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/guMtxF2L.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/guMtxIdentF.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/cosf.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/sinf.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osSetTimer.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osTimerServicesInit.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osTimerInterrupt.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSetTimerIntr.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osInsertTimer.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSiDeviceBusy.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSumcalc.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osIdCheckSum.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osRepairPackId.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osCheckPackId.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osGetId.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osCheckId.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osPfsRWInode.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osPfsSelectBank.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osDpDeviceBusy.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osViGetCurrentContext.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osViSwapContext.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D63F0.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSpSetPc.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSpRawStartDma.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSpDeviceBusy.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D6500.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D6560.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D65B0.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osDestroyThread.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/_Litob.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/_Genld.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/_Ldtob.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSetCompare.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/lldiv.s") -GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/ldiv.s") diff --git a/lib/src/unknown_0D3160.c b/lib/src/unknown_0D3160.c new file mode 100644 index 00000000..8a8d2217 --- /dev/null +++ b/lib/src/unknown_0D3160.c @@ -0,0 +1,39 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D2560 */ + +#include "types.h" +#include "macros.h" + +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osDisableInt.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osRestoreInt.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/D_800D25A0.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/D_800D2680.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/D_800D2760.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osViInit.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D2C60.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osDequeueThread.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osExceptionPreamble.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osException.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/send_mesg.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osEnqueueAndYield.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osEnqueueThread.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osPopThread.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osDispatchThread.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/D_800D35A0.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osProbeTLB.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D3670.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osJamMesg.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osPiGetCmdQueue.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D3820.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/_Putfld.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/_Printf.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSetSR.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osGetSR.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSetFpcCsr.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSiRawReadIo.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSiRawWriteIo.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osWritebackDCache.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osWritebackICache.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osMapTLBRdb.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osPiRawWriteIo.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D47F0.s") diff --git a/lib/src/unknown_0D56B0.c b/lib/src/unknown_0D56B0.c new file mode 100644 index 00000000..6bf4a972 --- /dev/null +++ b/lib/src/unknown_0D56B0.c @@ -0,0 +1,8 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D4AB0 */ + +#include "types.h" +#include "macros.h" + +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/cosf.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/sinf.s") \ No newline at end of file diff --git a/lib/src/unknown_0D5EC0.c b/lib/src/unknown_0D5EC0.c new file mode 100644 index 00000000..a626a551 --- /dev/null +++ b/lib/src/unknown_0D5EC0.c @@ -0,0 +1,31 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x800D52C0 */ + +#include "macros.h" + +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSiDeviceBusy.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSumcalc.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osIdCheckSum.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osRepairPackId.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osCheckPackId.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osGetId.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osCheckId.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osPfsRWInode.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osPfsSelectBank.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osDpDeviceBusy.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osViGetCurrentContext.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osViSwapContext.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D63F0.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSpSetPc.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSpRawStartDma.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSpDeviceBusy.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D6500.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D6560.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/func_800D65B0.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/osDestroyThread.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/_Litob.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/_Genld.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/_Ldtob.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/__osSetCompare.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/lldiv.s") +GLOBAL_ASM("lib/asm/non_matchings/unknown_0D3020/ldiv.s") \ No newline at end of file diff --git a/undefined_syms.txt b/undefined_syms.txt index 8c1cd0d9..b5ccb334 100755 --- a/undefined_syms.txt +++ b/undefined_syms.txt @@ -753,7 +753,7 @@ D_800E3690 = 0x800E3690; D_800E36E8 = 0x800E36E8; D_800E36EC = 0x800E36EC; D_800E3710 = 0x800E3710; -D_800E3740 = 0x800E3740; +__osPiDevMgr = 0x800E3740; D_800E3748 = 0x800E3748; D_800E3760 = 0x800E3760; D_800E3764 = 0x800E3764; @@ -785,10 +785,10 @@ D_800E4810 = 0x800E4810; D_800E4870 = 0x800E4870; D_800E4874 = 0x800E4874; D_800E4878 = 0x800E4878; -D_800E4880 = 0x800E4880; +__osThreadTail = 0x800E4880; D_800E4888 = 0x800E4888; D_800E488C = 0x800E488C; -D_800E4890 = 0x800E4890; +__osRunningThread = 0x800E4890; D_800E4894 = 0x800E4894; D_800E48C0 = 0x800E48C0; D_800E48E4 = 0x800E48E4; @@ -2832,9 +2832,9 @@ D_8012D190 = 0x8012D190; D_8012D1A0 = 0x8012D1A0; D_8012D1E0 = 0x8012D1E0; D_8012D1E8 = 0x8012D1E8; -D_8012D220 = 0x8012D220; +__osCurrentTime = 0x8012D220; D_8012D224 = 0x8012D224; -D_8012D228 = 0x8012D228; +__osBaseCounter = 0x8012D228; D_8012D22C = 0x8012D22C; D_8012D230 = 0x8012D230; D_8012D240 = 0x8012D240;