Libultra headers and some decomp (#14)

* lib is ultra

* it just keeps going

* math names

* format
This commit is contained in:
petrie911 2023-10-29 16:19:30 -05:00 committed by GitHub
parent 854cadfa16
commit 4311c670c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 1185 additions and 262 deletions

View File

@ -25,6 +25,10 @@
"sf64math.h": "c",
"ultra64.h": "c",
"os_internal.h": "c",
"structs.h": "c"
"structs.h": "c",
"stdint.h": "c",
"xstdio.h": "c",
"controller.h": "c",
"os_version.h": "c"
},
}

View File

@ -187,23 +187,30 @@ $(shell mkdir -p $(BUILD_DIR)/linker_scripts/$(VERSION) $(BUILD_DIR)/linker_scri
# directory flags
# per-file flags
build/src/libultra/io/pidma.o: OPTFLAGS := -O1 -g0
build/src/main/1EB50.o: OPTFLAGS := -O1 -g0
build/src/libultra/206B0.o: OPTFLAGS := -O2 -g0
build/src/libultra/rmon/sprintf.o: OPTFLAGS := -O2 -g0
build/src/libultra/libc/string.o: OPTFLAGS := -O2 -g0
build/src/libultra/libc/ldiv.o: OPTFLAGS := -O2 -g0
build/src/libultra/rmon/xlitob.o: OPTFLAGS := -O2 -g0
build/src/libultra/2BDF0.o: OPTFLAGS := -O1 -g0
build/src/libultra/2C700.o: OPTFLAGS := -O1 -g0
build/src/libultra/2D300.o: OPTFLAGS := -O1 -g0
build/src/libultra/io/pidma.o: OPTFLAGS := -O1 -g0
build/src/main/1EB50.o: OPTFLAGS := -O1 -g0
build/src/libultra/os/stopthread.o: OPTFLAGS := -O1 -g0
build/src/libultra/gu/guSqrtf.o: OPTFLAGS := -O1 -g0
build/src/libultra/gu/ortho.o: OPTFLAGS := -O3 -g0
build/src/libultra/gu/lookat.o: OPTFLAGS := -O3 -g0
build/src/libultra/io/motor.o: OPTFLAGS := -O1 -g0
build/src/libultra/io/controller.o: OPTFLAGS := -O1 -g0
build/src/libultra/io/ai.o: OPTFLAGS := -O1 -g0
build/src/libultra/io/aigetlen.o: OPTFLAGS := -O1 -g0
build/src/libultra/io/aisetfreq.o: OPTFLAGS := -O1 -g0
build/src/libultra/libc/string.o: OPTFLAGS := -O2 -g0
build/src/libultra/libc/ldiv.o: OPTFLAGS := -O2 -g0
build/src/libultra/libc/ll.o: OPTFLAGS := -O1 -g0
build/src/libultra/libc/ll.o: MIPS_VERSION := -mips3 -32
build/src/libultra/rmon/xlitob.o: OPTFLAGS := -O2 -g0
# cc & asm-processor
CC := $(ASM_PROC) $(ASM_PROC_FLAGS) $(IDO) -- $(AS) $(ASFLAGS) --

View File

@ -1,21 +1,119 @@
#ifndef PR_CONTROLLER_H
#define PR_CONTROLLER_H
#ifndef _CONTROLLER_H
#define _CONTROLLER_H
#include "global.h"
#include "PR/os.h"
#include "PR/os_internal.h"
#include "PR/os_version.h"
#include "PR/rcp.h"
typedef struct {
/* 0x00 */ u8 align;
/* 0x01 */ u8 txsize;
/* 0x02 */ u8 rxsize;
/* 0x03 */ u8 poll;
/* 0x04 */ u8 typeh;
/* 0x05 */ u8 typel;
/* 0x06 */ u8 status;
/* 0x07 */ u8 align1;
} __OSContRequestHeader; // size = 0x8
//should go somewhere else but
#define ARRLEN(x) ((s32)(sizeof(x) / sizeof(x[0])))
#define CHNL_ERR(format) (((format).rxsize & CHNL_ERR_MASK) >> 4)
typedef struct
{
/* 0x0 */ u32 ramarray[15];
/* 0x3C */ u32 pifstatus;
} OSPifRam;
typedef struct
{
/* 0x0 */ u8 dummy;
/* 0x1 */ u8 txsize;
/* 0x2 */ u8 rxsize;
/* 0x3 */ u8 cmd;
/* 0x4 */ u16 button;
/* 0x6 */ s8 stick_x;
/* 0x7 */ s8 stick_y;
} __OSContReadFormat;
typedef struct
{
/* 0x0 */ u8 dummy;
/* 0x1 */ u8 txsize;
/* 0x2 */ u8 rxsize;
/* 0x3 */ u8 cmd;
/* 0x4 */ u8 typeh;
/* 0x5 */ u8 typel;
/* 0x6 */ u8 status;
/* 0x7 */ u8 dummy1;
} __OSContRequesFormat;
typedef struct
{
/* 0x0 */ u8 txsize;
/* 0x1 */ u8 rxsize;
/* 0x2 */ u8 cmd;
/* 0x3 */ u8 typeh;
/* 0x4 */ u8 typel;
/* 0x5 */ u8 status;
} __OSContRequesFormatShort;
typedef struct
{
/* 0x0 */ u8 dummy;
/* 0x1 */ u8 txsize;
/* 0x2 */ u8 rxsize;
/* 0x3 */ u8 cmd;
#if BUILD_VERSION >= VERSION_J
/* 0x4 */ u8 addrh;
/* 0x5 */ u8 addrl;
#else
/* 0x4 */ u16 address;
#endif
/* 0x6 */ u8 data[BLOCKSIZE];
/* 0x26 */ u8 datacrc;
} __OSContRamReadFormat;
typedef union {
/* 0x0 */ struct
{
/* 0x0 */ u8 bank;
/* 0x1 */ u8 page;
} inode_t;
/* 0x0 */ u16 ipage;
} __OSInodeUnit;
typedef struct
{
/* 0x0 */ u32 game_code;
/* 0x4 */ u16 company_code;
/* 0x6 */ __OSInodeUnit start_page;
/* 0x8 */ u8 status;
/* 0x9 */ s8 reserved;
/* 0xA */ u16 data_sum;
/* 0xC */ u8 ext_name[PFS_FILE_EXT_LEN];
/* 0x10 */ u8 game_name[PFS_FILE_NAME_LEN];
} __OSDir;
typedef struct
{
/* 0x0 */ __OSInodeUnit inode_page[128];
} __OSInode;
typedef struct
{
/* 0x0 */ u32 repaired;
/* 0x4 */ u32 random;
/* 0x8 */ u64 serial_mid;
/* 0x10 */ u64 serial_low;
/* 0x18 */ u16 deviceid;
/* 0x1A */ u8 banks;
/* 0x1B */ u8 version;
/* 0x1C */ u16 checksum;
/* 0x1E */ u16 inverted_checksum;
} __OSPackId;
typedef struct
{
/* 0x0 */ u8 txsize;
/* 0x1 */ u8 rxsize;
/* 0x2 */ u8 cmd;
/* 0x3 */ u8 address;
/* 0x4 */ u8 data[EEPROM_BLOCK_SIZE];
} __OSContEepromFormat;
// Joybus commands
//from: http://en64.shoutwiki.com/wiki/SI_Registers_Detailed#CONT_CMD_Usage
#define CONT_CMD_REQUEST_STATUS 0
#define CONT_CMD_READ_BUTTON 1
#define CONT_CMD_READ_PAK 2
@ -30,22 +128,163 @@ typedef struct {
#define CONT_CMD_CHANNEL_RESET 0xFD
#define CONT_CMD_RESET 0xFF
#define UNK(n) 500000 * (u64)(n) / 1000000
// Bytes transmitted for each joybus command
#define CONT_CMD_REQUEST_STATUS_TX 1
#define CONT_CMD_READ_BUTTON_TX 1
#define CONT_CMD_READ_PAK_TX 3
#define CONT_CMD_WRITE_PAK_TX 35
#define CONT_CMD_READ_EEPROM_TX 2
#define CONT_CMD_WRITE_EEPROM_TX 10
#define CONT_CMD_READ36_VOICE_TX 3
#define CONT_CMD_WRITE20_VOICE_TX 23
#define CONT_CMD_READ2_VOICE_TX 3
#define CONT_CMD_WRITE4_VOICE_TX 7
#define CONT_CMD_SWRITE_VOICE_TX 3
#define CONT_CMD_RESET_TX 1
// Bytes received for each joybus command
#define CONT_CMD_REQUEST_STATUS_RX 3
#define CONT_CMD_READ_BUTTON_RX 4
#define CONT_CMD_READ_PAK_RX 33
#define CONT_CMD_WRITE_PAK_RX 1
#define CONT_CMD_READ_EEPROM_RX 8
#define CONT_CMD_WRITE_EEPROM_RX 1
#define CONT_CMD_READ36_VOICE_RX 37
#define CONT_CMD_WRITE20_VOICE_RX 1
#define CONT_CMD_READ2_VOICE_RX 3
#define CONT_CMD_WRITE4_VOICE_RX 1
#define CONT_CMD_SWRITE_VOICE_RX 1
#define CONT_CMD_RESET_RX 3
#define CONT_CMD_NOP 0xff
#define CONT_CMD_END 0xfe //indicates end of a command
#define CONT_CMD_EXE 1 //set pif ram status byte to this to do a command
#define DIR_STATUS_EMPTY 0
#define DIR_STATUS_UNKNOWN 1
#define DIR_STATUS_OCCUPIED 2
// Controller accessory addresses
// https://github.com/joeldipops/TransferBoy/blob/master/docs/TransferPakReference.md
// Accesory detection
#define CONT_ADDR_DETECT 0x8000
// Rumble
#define CONT_ADDR_RUMBLE 0xC000
// Controller Pak
// Transfer Pak
#define CONT_ADDR_GB_POWER 0x8000 // Same as the detection address, but semantically different
#define CONT_ADDR_GB_BANK 0xA000
#define CONT_ADDR_GB_STATUS 0xB000
// Addresses sent to controller accessories are in blocks, not bytes
#define CONT_BLOCKS(x) ((x) / BLOCKSIZE)
// Block addresses of the above
#define CONT_BLOCK_DETECT CONT_BLOCKS(CONT_ADDR_DETECT)
#define CONT_BLOCK_RUMBLE CONT_BLOCKS(CONT_ADDR_RUMBLE)
#define CONT_BLOCK_GB_POWER CONT_BLOCKS(CONT_ADDR_GB_POWER)
#define CONT_BLOCK_GB_BANK CONT_BLOCKS(CONT_ADDR_GB_BANK)
#define CONT_BLOCK_GB_STATUS CONT_BLOCKS(CONT_ADDR_GB_STATUS)
// Transfer pak
#define GB_POWER_ON 0x84
#define GB_POWER_OFF 0xFE
typedef struct
{
u32 ramarray[15];
u32 pifstatus;
} OSPifRam;
/* 0x0 */ __OSInode inode;
/* 0x100 */ u8 bank;
/* 0x101 */ u8 map[PFS_INODE_DIST_MAP];
} __OSInodeCache;
extern s32 __osEepStatus(OSMesgQueue *, OSContStatus *);
u16 __osSumcalc(u8 *ptr, int length);
s32 __osIdCheckSum(u16 *ptr, u16 *csum, u16 *icsum);
s32 __osRepairPackId(OSPfs *pfs, __OSPackId *badid, __OSPackId *newid);
s32 __osCheckPackId(OSPfs *pfs, __OSPackId *temp);
s32 __osGetId(OSPfs *pfs);
s32 __osCheckId(OSPfs *pfs);
s32 __osPfsRWInode(OSPfs *pfs, __OSInode *inode, u8 flag, u8 bank);
#if BUILD_VERSION >= VERSION_J
s32 __osPfsSelectBank(OSPfs *pfs, u8 bank);
#else
s32 __osPfsSelectBank(OSPfs *pfs);
#endif
s32 __osPfsDeclearPage(OSPfs *pfs, __OSInode *inode, int file_size_in_pages, int *first_page, u8 bank, int *decleared, int *last_page);
#if BUILD_VERSION >= VERSION_J
s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u8 bank, __OSInodeUnit *last_page);
#else
s32 __osPfsReleasePages(OSPfs *pfs, __OSInode *inode, u8 start_page, u16 *sum, u8 bank, __OSInodeUnit *last_page, int flag);
#endif
s32 __osBlockSum(OSPfs *pfs, u8 page_no, u16 *sum, u8 bank);
s32 __osContRamRead(OSMesgQueue *mq, int channel, u16 address, u8 *buffer);
s32 __osContRamWrite(OSMesgQueue *mq, int channel, u16 address, u8 *buffer, int force);
void __osContGetInitData(u8 *pattern, OSContStatus *data);
void __osPackRequestData(u8 cmd);
void __osPfsRequestData(u8 cmd);
void __osPfsGetInitData(u8* pattern, OSContStatus* data);
u8 __osContAddressCrc(u16 addr);
u8 __osContDataCrc(u8 *data);
s32 __osPfsGetStatus(OSMesgQueue *queue, int channel);
extern u32 __osContinitialized;
extern u8 __osMaxControllers;
extern u8 __osContLastCmd;
extern OSPifRam __osContPifRam;
extern OSMesgQueue __osEepromTimerQ;
extern OSTimer __osEepromTimer;
extern OSMesg __osEepromTimerMsg;
extern OSMesgQueue __osEepromTimerQ;
extern OSPifRam __osEepPifRam;
extern OSPifRam __osContPifRam;
extern OSPifRam __osPfsPifRam;
extern u8 __osMaxControllers;
void __osPackRequestData(u8 poll);
void __osContGetInitData(u8* pattern, OSContStatus* data);
//some version of this almost certainly existed since there's plenty of times where it's used right before a return 0
#define ERRCK(fn) \
ret = fn; \
if (ret != 0) \
return ret
#if BUILD_VERSION >= VERSION_J
#define SELECT_BANK(pfs, bank) \
__osPfsSelectBank((pfs), (bank))
#define SET_ACTIVEBANK_TO_ZERO \
if (pfs->activebank != 0) \
{ \
ERRCK(__osPfsSelectBank(pfs, 0)); \
} (void)0
#else
#define SELECT_BANK(pfs, bank) \
(pfs->activebank = (bank), \
__osPfsSelectBank((pfs))) \
#define SET_ACTIVEBANK_TO_ZERO \
if (pfs->activebank != 0) \
{ \
pfs->activebank = 0; \
ERRCK(__osPfsSelectBank(pfs)); \
} (void)0
#endif
#define PFS_CHECK_ID \
if (__osCheckId(pfs) == PFS_ERR_NEW_PACK) \
return PFS_ERR_NEW_PACK
#define PFS_CHECK_STATUS \
if ((pfs->status & PFS_INITIALIZED) == 0) \
return PFS_ERR_INVALID
#define PFS_GET_STATUS \
__osSiGetAccess(); \
ret = __osPfsGetStatus(queue, channel); \
__osSiRelAccess(); \
if (ret != 0) \
return ret
#endif

View File

@ -641,6 +641,28 @@ typedef struct {
#define PFS_ERR_EXIST 9 /* file exists */
#define PFS_ERR_ID_FATAL 10 /* dead ram pack */
#define PFS_ERR_DEVICE 11 /* wrong device type*/
#define PFS_ERR_NO_GBCART 12 /* no gb cartridge (64GB-PAK) */
#define PFS_ERR_NEW_GBCART 13 /* gb cartridge may be changed */
/* Definition for bank */
#define PFS_ID_BANK_256K 0
#define PFS_ID_BANK_1M 4
#define PFS_BANKS_256K 1
#define PFS_WRITTEN 2
#define DEF_DIR_PAGES 2
#define PFS_ID_0AREA 1
#define PFS_ID_1AREA 3
#define PFS_ID_2AREA 4
#define PFS_ID_3AREA 6
#define PFS_LABEL_AREA 7
#define PFS_ID_PAGE PFS_ONE_PAGE * 0
#define PFS_BANK_LAPPED_BY 8 /* => u8 */
#define PFS_SECTOR_PER_BANK 32
#define PFS_INODE_DIST_MAP (PFS_BANK_LAPPED_BY * PFS_SECTOR_PER_BANK)
#define PFS_SECTOR_SIZE (PFS_INODE_SIZE_PER_PAGE/PFS_SECTOR_PER_BANK)
/* definition for EEPROM */

28
include/PR/os_version.h Normal file
View File

@ -0,0 +1,28 @@
/*---------------------------------------------------------------------*
Copyright (C) 1998 Nintendo.
$RCSfile: os_version.h,v $
$Revision: 1.2 $
$Date: 1999/06/17 01:33:01 $
*---------------------------------------------------------------------*/
#ifndef _OS_VERSION_H_
#define _OS_VERSION_H_
#define VERSION_D 1
#define VERSION_E 2
#define VERSION_F 3
#define VERSION_G 4
#define VERSION_H 5
#define VERSION_I 6
#define VERSION_J 7
#define VERSION_K 8
#define VERSION_L 9
#define BUILD_VERSION VERSION_H
#define OS_MAJOR_VERSION BUILD_VERSION_STRING /* major version */
#define OS_MINOR_VERSION 0 /* patch level */
#endif /* !_OS_VERSION_H_ */

View File

@ -3,22 +3,23 @@
#include "structs.h"
f32 func_80004E20(f32 arg0, f32 arg1);
void func_80004E4C(void);
f32 Math_ModF(f32 value, f32 mod);
void Rand_Init(void);
f32 Rand_ZeroOne(void);
void func_80004FC8(s32 arg0, s32 arg1, s32 arg2);
f32 func_80004FE8(void);
f32 func_80005100(f32 arg0, f32 arg1);
f32 func_80005320(f32 arg0, f32 arg1);
f32 func_800055DC(f32 arg0, s32 arg1);
void func_80005604(s32* arg0, s32* arg1, s32 arg2, s32 arg3, s32 arg4);
void func_80005E90(Matrix*, float, char);
void Rand_SetSeed(s32 seed1, s32 seed2, s32 seed3);
f32 Rand_ZeroOneSeeded(void);
f32 Math_Atan2F(f32 y, f32 x);
f32 Math_Atan2F_XY(f32 x, f32 y);
f32 Math_Atan2F_XYAlt(f32 x, f32 y);
f32 Math_PowF(f32 base, s32 exp);
void Math_MinMax(s32* min, s32* max, s32 val1, s32 val2, s32 val3);
void func_80005680(Matrix*, Matrix*);
void func_80005708(Matrix** mtx);
void func_80005740(Matrix** mtx);
void func_80005B00(Matrix*, f32, f32, f32, u8);
void func_80005C34(Matrix*, f32, f32, f32, s32);
void func_80005E90(Matrix*, float, char);
void func_80006A20(Matrix*, Vec3f*, Vec3f*);
void func_80006EB8(Gfx**);
void func_80006F20(void);
@ -40,12 +41,48 @@ void func_8001DC6C(s32, s32);
s32 func_8001EF10(void);
f32 func_8001FBE8(f32);
s32 vsprintf(char* dst, char* fmt, va_list args);
f32 func_8001FE60(f32);
f64 func_8001FE6C(f64);
s32 func_8001FE78(f32);
s32 func_8001FE88(f64);
f32 func_8001FE98(f32);
f64 func_8001FEA4(f64);
s32 func_8001FEB0(f32);
s32 func_8001FEC0(f64);
f32 func_8001FED0(f32);
f64 func_8001FEDC(f64);
s32 func_8001FEE8(f32);
s32 func_8001FEF8(f64);
f32 func_8001FF08(f32);
f64 func_8001FF14(f64);
s32 func_8001FF20(f32);
s32 func_8001FF30(f64);
f32 func_8001FF40(f32);
f64 func_8001FF5C(f64);
s32 func_8001FF7C(f32);
s32 func_8001FF9C(f64);
f32 func_8001FAE4(f32);
f32 func_8001FB04(f32);
f64 func_8001FB24(f64);
f32 func_8001FB58(f32);
f32 func_8001FB88(f32);
f32 func_8001FBA8(f32);
f32 func_8001FBC8(f32);
f32 Math_FAtanF(f32);
f32 Math_FAtan2F(f32, f32);
f32 Math_FAsinF(f32);
f32 Math_FAcosF(f32);
void func_800227A0(s32, OSMesgQueue*, OSMesg*, s32);
s32 func_80022B60(void);
f32 __sinf(f32);
f32 __cosf(f32);
s64 __ull_div(s64, s64);
s64 __ll_mul(s64, s64);
s64 __ll_rshift(s64, s64);

View File

@ -1,7 +1,9 @@
#ifndef GLOBAL_H
#define GLOBAL_H
#include "PR/xstdio.h"
#include "PR/os_internal.h"
#include "PR/controller.h"
#include "libultra/ultra64.h"
#include "libc/math.h"
#include "libc/stdarg.h"

58
include/osint.h Normal file
View File

@ -0,0 +1,58 @@
#ifndef _OSINT_H
#define _OSINT_H
#include "PR/os_internal.h"
typedef struct __OSEventState
{
OSMesgQueue *messageQueue;
OSMesg message;
} __OSEventState;
extern struct __osThreadTail
{
OSThread *next;
OSPri priority;
} __osThreadTail;
//maybe should be in exceptasm.h?
extern void __osEnqueueAndYield(OSThread **);
extern void __osDequeueThread(OSThread **, OSThread *);
extern void __osEnqueueThread(OSThread **, OSThread *);
extern OSThread *__osPopThread(OSThread **);
extern void __osDispatchThread(void);
extern void __osCleanupThread(void);
extern void __osSetTimerIntr(OSTime);
extern OSTime __osInsertTimer(OSTimer *);
extern void __osTimerInterrupt(void);
extern u32 __osProbeTLB(void *);
extern int __osSpDeviceBusy(void);
extern OSThread *__osRunningThread;
extern OSThread *__osActiveQueue;
extern OSThread *__osFaultedThread;
extern OSThread *__osRunQueue;
extern OSTimer *__osTimerList;
extern OSTimer __osBaseTimer;
extern OSTime __osCurrentTime;
extern u32 __osBaseCounter;
extern u32 __osViIntrCount;
extern u32 __osTimerCounter;
extern u32 __osShutdown;
extern OSMesgQueue __osProfTimerQ;
extern OSProf *__osProfileList;
extern OSProf *__osProfileListEnd;
extern u32 __osProfileOverflowBin;
extern __OSEventState __osEventStateTab[];
extern void __osTimerServicesInit(void);
extern s32 __osAiDeviceBusy(void);
extern int __osDpDeviceBusy(void);
#ifndef _FINALROM
extern void* __printfunc;
#endif
#endif

198
include/piint.h Normal file
View File

@ -0,0 +1,198 @@
#ifndef _PIINT_H_
#define _PIINT_H_
#include "PR/os_internal.h"
#include "PR/os_version.h"
#include "PR/rcp.h"
//https://github.com/LuigiBlood/64dd/wiki/Memory-Map
#define LEO_BASE_REG 0x05000000
#define LEO_CMD (LEO_BASE_REG + 0x508)
#define LEO_STATUS (LEO_BASE_REG + 0x508)
#define LEO_BM_CTL (LEO_BASE_REG + 0x510)
#define LEO_BM_STATUS (LEO_BASE_REG + 0x510)
#define LEO_SEQ_CTL (LEO_BASE_REG + 0x518)
#define LEO_SEQ_STATUS (LEO_BASE_REG + 0x518)
#define LEO_C2_BUFF (LEO_BASE_REG + 0x000) //C2 Sector Buffer
#define LEO_SECTOR_BUFF (LEO_BASE_REG + 0x400) //Data Sector Buffer
#define LEO_DATA (LEO_BASE_REG + 0x500) //Data
#define LEO_MISC_REG (LEO_BASE_REG + 0x504) //Misc Register
#define LEO_CUR_TK (LEO_BASE_REG + 0x50C) //Current Track
#define LEO_ERR_SECTOR (LEO_BASE_REG + 0x514) //Sector Error Status
#define LEO_CUR_SECTOR (LEO_BASE_REG + 0x51C) //Current Sector
#define LEO_HARD_RESET (LEO_BASE_REG + 0x520) //Hard Reset
#define LEO_C1_S0 (LEO_BASE_REG + 0x524) //C1
#define LEO_HOST_SECBYTE (LEO_BASE_REG + 0x528) //Sector Size (in bytes)
#define LEO_C1_S2 (LEO_BASE_REG + 0x52C) //C1
#define LEO_SEC_BYTE (LEO_BASE_REG + 0x530) //Sectors per Block, Full Size
#define LEO_C1_S4 (LEO_BASE_REG + 0x534) //C1
#define LEO_C1_S6 (LEO_BASE_REG + 0x538) //C1
#define LEO_CUR_ADDR (LEO_BASE_REG + 0x53C) //Current Address?
#define LEO_ID_REG (LEO_BASE_REG + 0x540) //ID
#define LEO_TEST_REG (LEO_BASE_REG + 0x544) //Test Read
#define LEO_TEST_PIN_SEL (LEO_BASE_REG + 0x548) //Test Write
#define LEO_RAM_ADDR (LEO_BASE_REG + 0x580) //Microsequencer RAM
#define LEO_STATUS_PRESENCE_MASK 0xFFFF
#define LEO_STATUS_DATA_REQUEST 0x40000000
#define LEO_STATUS_C2_TRANSFER 0x10000000
#define LEO_STATUS_BUFFER_MANAGER_ERROR 0x08000000
#define LEO_STATUS_BUFFER_MANAGER_INTERRUPT 0x04000000
#define LEO_STATUS_MECHANIC_INTERRUPT 0x02000000
#define LEO_STATUS_DISK_PRESENT 0x01000000
#define LEO_STATUS_BUSY_STATE 0x00800000
#define LEO_STATUS_RESET_STATE 0x00400000
#define LEO_STATUS_MOTOR_NOT_SPINNING 0x00100000
#define LEO_STATUS_HEAD_RETRACTED 0x00080000
#define LEO_STATUS_WRITE_PROTECT_ERROR 0x00040000
#define LEO_STATUS_MECHANIC_ERROR 0x00020000
#define LEO_STATUS_DISK_CHANGE 0x00010000
#define LEO_STATUS_MODE_MASK (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED)
#define LEO_STATUS_MODE_SLEEP (LEO_STATUS_MOTOR_NOT_SPINNING | LEO_STATUS_HEAD_RETRACTED)
#define LEO_STATUS_MODE_STANDBY (LEO_STATUS_HEAD_RETRACTED)
#define LEO_STATUS_MODE_ACTIVE 0
#define LEO_CUR_TK_INDEX_LOCK 0x60000000
#define LEO_BM_STATUS_RUNNING 0x80000000 //Running
#define LEO_BM_STATUS_ERROR 0x04000000 //Error
#define LEO_BM_STATUS_MICRO 0x02000000 //Micro Status?
#define LEO_BM_STATUS_BLOCK 0x01000000 //Block Transfer
#define LEO_BM_STATUS_C1CORRECTION 0x00800000 //C1 Correction
#define LEO_BM_STATUS_C1DOUBLE 0x00400000 //C1 Double
#define LEO_BM_STATUS_C1SINGLE 0x00200000 //C1 Single
#define LEO_BM_STATUS_C1ERROR 0x00010000 //C1 Error
#define LEO_BM_CTL_START 0x80000000 //Start Buffer Manager
#define LEO_BM_CTL_MODE 0x40000000 //Buffer Manager Mode
#define LEO_BM_CTL_IMASK 0x20000000 //BM Interrupt Mask
#define LEO_BM_CTL_RESET 0x10000000 //Buffer Manager Reset
#define LEO_BM_CTL_DISABLE_OR 0x08000000 //Disable OR Check?
#define LEO_BM_CTL_DISABLE_C1 0x04000000 //Disable C1 Correction
#define LEO_BM_CTL_BLOCK 0x02000000 //Block Transfer
#define LEO_BM_CTL_CLR_MECHANIC_INTR 0x01000000 //Mechanic Interrupt Reset
#define LEO_BM_CTL_CONTROL_MASK 0xFF000000
#define LEO_BM_CTL_SECTOR_MASK 0x00FF0000
#define LEO_BM_CTL_SECTOR_SHIFT 16
#define LEO_CMD_TYPE_0 0 //TODO: name
#define LEO_CMD_TYPE_1 1 //TODO: name
#define LEO_CMD_TYPE_2 2 //TODO: name
#define LEO_ERROR_GOOD 0
#define LEO_ERROR_4 4 //maybe busy?
#define LEO_ERROR_22 22 //
#define LEO_ERROR_23 23 //unrecovered read error?
#define LEO_ERROR_24 24 //no reference position found?
#define LEO_ERROR_29 29 //
extern OSDevMgr __osPiDevMgr;
extern OSPiHandle *__osCurrentHandle[];
extern OSPiHandle CartRomHandle;
extern OSPiHandle LeoDiskHandle;
extern OSMesgQueue __osPiAccessQueue;
extern u32 __osPiAccessQueueEnabled;
// These symbols were all renamed in 2.0J.
#if BUILD_VERSION < VERSION_J
#define __osEPiRawStartDma osEPiRawStartDma
#define __osEPiRawReadIo osEPiRawReadIo
#define __osEPiRawWriteIo osEPiRawWriteIo
#define __osPiRawStartDma osPiRawStartDma
#define __osPiRawWriteIo osPiRawWriteIo
#define __osPiRawReadIo osPiRawReadIo
#endif
int __osPiDeviceBusy(void);
void __osDevMgrMain(void *);
void __osPiCreateAccessQueue(void);
void __osPiRelAccess(void);
void __osPiGetAccess(void);
s32 __osPiRawStartDma(s32, u32 , void *, u32 );
s32 __osPiRawWriteIo(u32, u32);
s32 __osPiRawReadIo(u32, u32 *);
s32 __osEPiRawWriteIo(OSPiHandle *, u32 , u32);
s32 __osEPiRawReadIo(OSPiHandle *, u32 , u32 *);
s32 __osEPiRawStartDma(OSPiHandle *, s32 , u32 , void *, u32 );
OSMesgQueue *osPiGetCmdQueue(void);
#define WAIT_ON_IOBUSY(stat) \
{ \
stat = IO_READ(PI_STATUS_REG); \
while (stat & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)) \
stat = IO_READ(PI_STATUS_REG); \
} (void)0
#define UPDATE_REG(pihandle, reg, var) \
if (cHandle->var != pihandle->var) \
IO_WRITE(reg, pihandle->var)
#if BUILD_VERSION >= VERSION_J
#define EPI_SYNC(pihandle, stat, domain) \
\
WAIT_ON_IOBUSY(stat); \
\
domain = pihandle->domain; \
if (__osCurrentHandle[domain]->type != pihandle->type) \
{ \
OSPiHandle *cHandle = __osCurrentHandle[domain]; \
if (domain == PI_DOMAIN1) \
{ \
UPDATE_REG(pihandle, PI_BSD_DOM1_LAT_REG, latency); \
UPDATE_REG(pihandle, PI_BSD_DOM1_PGS_REG, pageSize); \
UPDATE_REG(pihandle, PI_BSD_DOM1_RLS_REG, relDuration); \
UPDATE_REG(pihandle, PI_BSD_DOM1_PWD_REG, pulse); \
} \
else \
{ \
UPDATE_REG(pihandle, PI_BSD_DOM2_LAT_REG, latency); \
UPDATE_REG(pihandle, PI_BSD_DOM2_PGS_REG, pageSize); \
UPDATE_REG(pihandle, PI_BSD_DOM2_RLS_REG, relDuration); \
UPDATE_REG(pihandle, PI_BSD_DOM2_PWD_REG, pulse); \
} \
cHandle->type = pihandle->type; \
cHandle->latency = pihandle->latency; \
cHandle->pageSize = pihandle->pageSize; \
cHandle->relDuration = pihandle->relDuration; \
cHandle->pulse = pihandle->pulse; \
}(void)0
#else
#define EPI_SYNC(pihandle, stat, domain) \
\
WAIT_ON_IOBUSY(stat); \
\
domain = pihandle->domain; \
if (__osCurrentHandle[domain] != pihandle) \
{ \
OSPiHandle *cHandle = __osCurrentHandle[domain]; \
if (domain == PI_DOMAIN1) \
{ \
UPDATE_REG(pihandle, PI_BSD_DOM1_LAT_REG, latency); \
UPDATE_REG(pihandle, PI_BSD_DOM1_PGS_REG, pageSize); \
UPDATE_REG(pihandle, PI_BSD_DOM1_RLS_REG, relDuration); \
UPDATE_REG(pihandle, PI_BSD_DOM1_PWD_REG, pulse); \
} \
else \
{ \
UPDATE_REG(pihandle, PI_BSD_DOM2_LAT_REG, latency); \
UPDATE_REG(pihandle, PI_BSD_DOM2_PGS_REG, pageSize); \
UPDATE_REG(pihandle, PI_BSD_DOM2_RLS_REG, relDuration); \
UPDATE_REG(pihandle, PI_BSD_DOM2_PWD_REG, pulse); \
} \
__osCurrentHandle[domain] = pihandle; \
}(void)0
#endif
#endif

15
include/siint.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef _SIINT_H
#define _SIINT_H
#include "PR/os_internal.h"
#include "PR/rcp.h"
extern s32 __osEepromRead16K;
extern u8 __osPfsInodeCacheBank;
void __osSiGetAccess(void);
void __osSiRelAccess(void);
int __osSiDeviceBusy(void);
void __osSiCreateAccessQueue(void);
#endif

View File

@ -1,6 +1,25 @@
bootproc = 0x80004DA8;
Rand_ZeroOne = 0x80004EB0;
D_800C90F0 = 0x800C90F0;
__libm_qnan_f = 0x800C9570;
Math_ModF = 0x80004E20;
Rand_Init = 0x80004E4C;
Rand_ZeroOne = 0x80004EB0;
Rand_SetSeed = 0x80004FC8;
Rand_ZeroOneSeeded = 0x80004FE8;
Math_Atan2F = 0x80005100;
Math_Atan2F_XY = 0x800051F8;
Math_Atan2F_XYAlt = 0x80005320;
Math_FactorialF = 0x800053C8;
Math_Factorial = 0x800054C8;
Math_PowF = 0x800055DC;
Math_MinMax = 0x80005604;
D_800C45E0 = 0x800C45E0;
Math_FAtanF = 0x8001FBE8;
Math_FAtan2F = 0x8001FD0C;
Math_FAsinF = 0x8001FE00;
Math_FAcosF = 0x8001FE30;
D_800D934C = 0x800D934C; // force_migration:True
D_800D503C = 0x800D503C; // force_migration:True

View File

@ -1,6 +1,9 @@
osContInit = 0x8001FFC0;
__osContGetInitData = 0x800201B8;
__osPackRequestData = 0x80020288;
osMotorStop = 0x80020920;
osMotorStart = 0x80020A88;
osMotorInit= 0x80020D70;
osRecvMesg = 0x800205E0;
osSendMesg = 0x80020720;
osContStartQuery = 0x80020870;
@ -78,6 +81,8 @@ __osPfsRequestData = 0x80026270;
__osPfsGetInitData = 0x8002636C;
__osContAddressCrc = 0x80026440;
__osContDataCrc = 0x800264F0;
__osContRamWrite = 0x800265C0;
__osContRamRead = 0x80026940;
guMtxF2L = 0x80026CD0;
guMtxIdentF = 0x80026DD0;
guMtxIdent = 0x80026E58;
@ -146,7 +151,6 @@ __osViNext = 0x800C7F44;
__osTimerList = 0x800C7F50;
ldigs = 0x800C7F80;
udigs = 0x800C7F94;
__libm_qnan_f = 0x800E9570;
__osRcpImTable = 0x800E95E0;
__osContPifRam = 0x80156620;
__osContLastCmd = 0x80156660;
@ -154,8 +158,12 @@ __osMaxControllers = 0x80156661;
__osEepromTimerQ = 0x80156688;
__osEepromTimerMsg = 0x801566A0;
__osEventStateTab = 0x801568F0;
__osPfsPifRam = 0x801594C0;
_MotorStopData = 0x801566B0;
_MotorStartData = 0x801567B0;
_motorstopbuf= 0x801568B0;
_motorstartbuf = 0x801568D0;
__osEepPifRam = 0x801793E0;
__osPfsPifRam = 0x801794C0;
__osCurrentTime = 0x80179520;
__osBaseCounter = 0x80179528;
__osViIntrCount = 0x8017952C;

View File

@ -1,25 +1,93 @@
#include "common.h"
#include "global.h"
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/206B0/func_8001FAB0.s")
f32 func_8001FAB0(f32 x) {
return __sinf(x) / __cosf(x);
}
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/206B0/func_8001FAE4.s")
f32 func_8001FAE4(f32 x) {
return func_8001FE60(x);
}
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/206B0/func_8001FB04.s")
f32 func_8001FB04(f32 x) {
return func_8001FE98(x);
}
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/206B0/func_8001FB24.s")
f64 func_8001FB24(f64 x) {
return (x < 0.0) ? -x : x;
}
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/206B0/func_8001FB58.s")
f32 func_8001FB58(f32 x) {
return (x < 0.0f) ? -x : x;
}
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/206B0/func_8001FB88.s")
f32 func_8001FB88(f32 x) {
return func_8001FF40(x);
}
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/206B0/func_8001FBA8.s")
f32 func_8001FBA8(f32 x) {
return func_8001FED0(x);
}
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/206B0/func_8001FBC8.s")
f32 func_8001FBC8(f32 x) {
return func_8001FF08(x);
}
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/206B0/func_8001FBE8.s")
f32 Math_FAtanF(f32 x) {
s32 sector;
s32 i;
f32 sq;
f32 conv = 0.0f;
f32 z;
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/206B0/func_8001FD0C.s")
if (x > 1.0f) {
sector = 1;
x = 1.0f / x;
} else if (x < -1.0f) {
sector = -1;
x = 1.0f / x;
} else {
sector = 0;
}
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/206B0/func_8001FE00.s")
sq = SQ(x);
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/206B0/func_8001FE30.s")
for (z = i = 24; i != 0; i--) {
conv = SQ(z) * sq / (2.0f * z + 1.0f + conv);
z -= 1.0f;
}
if (sector > 0) {
return M_PI / 2 - (x / (1.0f + conv));
} else if (sector < 0) {
return -M_PI / 2 - (x / (1.0f + conv));
} else {
return x / (1.0f + conv);
}
}
f32 Math_FAtan2F(f32 y, f32 x) {
if ((y == 0.0f) && (x == 0.0f)) {
return 0.0f;
}
if (x == 0.0f) {
if (y < 0.0f) {
return -M_PI / 2;
}
return M_PI / 2;
}
if (x < 0.0f) {
if (y < 0.0f) {
return -(M_PI - Math_FAtanF(fabs(y / x)));
}
return M_PI - Math_FAtanF(fabs(y / x));
}
return Math_FAtanF(y / x);
}
f32 Math_FAsinF(f32 x) {
return Math_FAtan2F(x, sqrtf(1 - SQ(x)));
}
f32 Math_FAcosF(f32 x) {
return M_PI / 2.0f - Math_FAsinF(x);
}

View File

@ -1,6 +1,10 @@
#include "global.h"
#include "PR/controller.h"
extern s32 __osContinitialized;
#define USEC_TO_CYCLES(n, clock) ((n) * (u64) (clock) / 1000000)
s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data) {
OSMesg dummy;
s32 ret = 0;
@ -15,9 +19,9 @@ s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data) {
__osContinitialized = 1;
t = osGetTime();
if (t < UNK(osClockRate)) {
if (t < USEC_TO_CYCLES(500000, osClockRate)) {
osCreateMesgQueue(&timerMesgQueue, &dummy, 1);
osSetTimer(&mytimer, UNK(osClockRate) - t, 0, &timerMesgQueue, &dummy);
osSetTimer(&mytimer, USEC_TO_CYCLES(500000, osClockRate) - t, 0, &timerMesgQueue, &dummy);
osRecvMesg(&timerMesgQueue, &dummy, OS_MESG_BLOCK);
}
__osMaxControllers = 4;
@ -40,14 +44,14 @@ s32 osContInit(OSMesgQueue* mq, u8* bitpattern, OSContStatus* data) {
void __osContGetInitData(u8* pattern, OSContStatus* data) {
u8* ptr;
__OSContRequestHeader requestHeader;
__OSContRequesFormat requestHeader;
s32 i;
u8 bits;
bits = 0;
ptr = (u8*) __osContPifRam.ramarray;
for (i = 0; i < __osMaxControllers; i++, ptr += sizeof(requestHeader), data++) {
requestHeader = *(__OSContRequestHeader*) ptr;
requestHeader = *(__OSContRequesFormat*) ptr;
data->errno = (requestHeader.rxsize & 0xC0) >> 4;
if (data->errno == 0) {
data->type = requestHeader.typel << 8 | requestHeader.typeh;
@ -59,9 +63,9 @@ void __osContGetInitData(u8* pattern, OSContStatus* data) {
*pattern = bits;
}
void __osPackRequestData(u8 poll) {
void __osPackRequestData(u8 cmd) {
u8* ptr;
__OSContRequestHeader requestHeader;
__OSContRequesFormat requestHeader;
s32 i;
for (i = 0; i < 16; i++) {
@ -70,18 +74,18 @@ void __osPackRequestData(u8 poll) {
__osContPifRam.pifstatus = CONT_CMD_READ_BUTTON;
ptr = (u8*) __osContPifRam.ramarray;
requestHeader.align = 255;
requestHeader.txsize = 1;
requestHeader.rxsize = 3;
requestHeader.poll = poll;
requestHeader.typeh = 255;
requestHeader.typel = 255;
requestHeader.status = 255;
requestHeader.align1 = 255;
requestHeader.dummy = CONT_CMD_NOP;
requestHeader.txsize = CONT_CMD_RESET_TX;
requestHeader.rxsize = CONT_CMD_RESET_RX;
requestHeader.cmd = cmd;
requestHeader.typeh = CONT_CMD_NOP;
requestHeader.typel = CONT_CMD_NOP;
requestHeader.status = CONT_CMD_NOP;
requestHeader.dummy1 = CONT_CMD_NOP;
for (i = 0; i < __osMaxControllers; i++) {
*(__OSContRequestHeader*) ptr = requestHeader;
*(__OSContRequesFormat*) ptr = requestHeader;
ptr += sizeof(requestHeader);
}
*ptr = 254;
*ptr = CONT_CMD_END;
}

134
src/libultra/io/motor.c Normal file
View File

@ -0,0 +1,134 @@
#include "global.h"
#include "siint.h"
extern OSPifRam _MotorStopData[MAXCONTROLLERS];
extern OSPifRam _MotorStartData[MAXCONTROLLERS];
extern u8 _motorstopbuf[0x20];
extern u8 _motorstartbuf[0x20];
s32 osMotorStop(OSPfs* pfs) {
s32 i;
s32 ret;
u8* ptr = (u8*) &__osPfsPifRam;
__OSContRamReadFormat ramreadformat;
__osSiGetAccess();
__osContLastCmd = CONT_CMD_WRITE_PAK;
__osSiRawStartDma(OS_WRITE, &_MotorStopData[pfs->channel]);
osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK);
ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam);
osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK);
ptr = (u8*) &__osPfsPifRam;
if (pfs->channel != 0) {
for (i = 0; i < pfs->channel; i++) {
ptr++;
}
}
ramreadformat = *((__OSContRamReadFormat*) ptr);
ret = CHNL_ERR(ramreadformat);
if ((ret == 0) && (ramreadformat.datacrc != 0)) {
ret = PFS_ERR_CONTRFAIL;
}
__osSiRelAccess();
return ret;
}
s32 osMotorStart(OSPfs* pfs) {
s32 i;
s32 ret;
u8* ptr = (u8*) &__osPfsPifRam;
__OSContRamReadFormat ramreadformat;
__osSiGetAccess();
__osContLastCmd = CONT_CMD_WRITE_PAK;
__osSiRawStartDma(OS_WRITE, &_MotorStartData[pfs->channel]);
osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK);
ret = __osSiRawStartDma(OS_READ, &__osPfsPifRam);
osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK);
ptr = (u8*) &__osPfsPifRam;
if (pfs->channel != 0) {
for (i = 0; i < pfs->channel; i++) {
ptr++;
}
}
ramreadformat = *((__OSContRamReadFormat*) ptr);
ret = CHNL_ERR(ramreadformat);
if ((ret == 0) && (ramreadformat.datacrc != 0xEB)) {
ret = PFS_ERR_CONTRFAIL;
}
__osSiRelAccess();
return ret;
}
void func_80020BF4(s32 channel, u16 address, u8* buffer, OSPifRam* mdata) {
u8* ptr = mdata->ramarray;
__OSContRamReadFormat ramreadformat;
s32 i;
for (i = 0; i < ARRAY_COUNT(mdata->ramarray); i++) {
mdata->ramarray[i] = 0;
}
mdata->pifstatus = CONT_CMD_EXE;
ramreadformat.dummy = CONT_CMD_NOP;
ramreadformat.txsize = CONT_CMD_WRITE_PAK_TX;
ramreadformat.rxsize = CONT_CMD_WRITE_PAK_RX;
ramreadformat.cmd = CONT_CMD_WRITE_PAK;
ramreadformat.address = __osContAddressCrc(address) | (address << 5);
ramreadformat.datacrc = CONT_CMD_NOP;
for (i = 0; i < ARRAY_COUNT(ramreadformat.data); i++) {
ramreadformat.data[i] = *(buffer++);
}
if (channel != 0) {
for (i = 0; i < channel; i++) {
*(ptr++) = 0;
}
}
*((__OSContRamReadFormat*) ptr) = ramreadformat;
ptr += sizeof(__OSContRamReadFormat);
*ptr = CONT_CMD_END;
}
s32 osMotorInit(OSMesgQueue* mq, OSPfs* pfs, int channel) {
s32 i;
s32 ret;
u8 buffer[0x20];
pfs->queue = mq;
pfs->channel = channel;
pfs->status = 0;
pfs->activebank = 0x80;
for (i = 0; i < ARRAY_COUNT(buffer); i++) {
buffer[i] = 0x80;
}
ret = __osContRamWrite(mq, channel, CONT_BLOCK_DETECT, buffer, 0);
if (ret == PFS_ERR_NEW_PACK) {
ret = __osContRamWrite(mq, channel, CONT_BLOCK_DETECT, buffer, 0);
}
if (ret != 0) {
return ret;
}
ret = __osContRamRead(mq, channel, CONT_BLOCK_DETECT, buffer);
if (ret == PFS_ERR_NEW_PACK) {
ret = PFS_ERR_CONTRFAIL;
}
if (ret != 0) {
return ret;
}
if (buffer[0x1F] != 0x80) {
return 0xB;
}
for (i = 0; i < ARRAY_COUNT(_motorstartbuf); i++) {
_motorstartbuf[i] = 1;
_motorstopbuf[i] = 0;
}
func_80020BF4(channel, CONT_BLOCK_RUMBLE, _motorstartbuf, &_MotorStartData[channel]);
func_80020BF4(channel, CONT_BLOCK_RUMBLE, _motorstopbuf, &_MotorStopData[channel]);
return 0;
}

View File

@ -1,35 +1,20 @@
#include "common.h"
#include "global.h"
#include "osint.h"
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/osStopThread.s")
void osStopThread(OSThread* t) {
register u32 saveMask = __osDisableInt();
register u16 state = (t == NULL) ? OS_STATE_RUNNING : t->state;
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/func_8002E340.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/func_8002E364.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/func_8002E3A8.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/func_8002E3BC.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/func_8002E3E0.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/func_8002E4F8.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/func_8002E548.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/func_8002E5E0.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/func_8002E604.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/func_8002E628.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/func_8002E64C.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/func_8002E670.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/func_8002E694.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/func_8002E6B8.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/func_8002E6DC.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/libultra/os/stopthread/D_800C9A50.s")
switch (state) {
case OS_STATE_RUNNING:
__osRunningThread->state = 1;
__osEnqueueAndYield(NULL);
break;
case OS_STATE_RUNNABLE:
case OS_STATE_WAITING:
t->state = OS_STATE_STOPPED;
__osDequeueThread(t->queue, t);
break;
}
__osRestoreInt(saveMask);
}

View File

@ -0,0 +1,29 @@
#include "global.h"
void* proutSprintf(void* dst, const char* fmt, size_t size) {
return (void*) ((uintptr_t) memcpy(dst, fmt, size) + size);
}
s32 vsprintf(char* dst, char* fmt, va_list args) {
s32 ret = _Printf(proutSprintf, dst, fmt, args);
if (ret > -1) {
dst[ret] = 0;
}
return ret;
}
int sprintf(char* s, const char* fmt, ...) {
s32 ret;
va_list args;
va_start(args, fmt);
ret = _Printf(proutSprintf, s, fmt, args);
if (ret >= 0) {
s[ret] = 0;
}
va_end(args);
return ret;
}

View File

@ -2,31 +2,31 @@
#include "libc/string.h"
#include "libc/stdlib.h"
typedef struct {
/* 0x0 */ union {
/* 0x0 */ s64 ll;
/* 0x0 */ f64 ld;
} v;
/* 0x8 */ char* s;
/* 0xC */ s32 n0;
/* 0x10 */ s32 nz0;
/* 0x14 */ s32 n1;
/* 0x18 */ s32 nz1;
/* 0x1C */ s32 n2;
/* 0x20 */ s32 nz2;
/* 0x24 */ s32 prec;
/* 0x28 */ s32 width;
/* 0x2C */ size_t nchar;
/* 0x30 */ u32 flags;
/* 0x34 */ u8 qual;
} _Pft;
// typedef struct {
// /* 0x0 */ union {
// /* 0x0 */ s64 ll;
// /* 0x0 */ f64 ld;
// } v;
// /* 0x8 */ char* s;
// /* 0xC */ s32 n0;
// /* 0x10 */ s32 nz0;
// /* 0x14 */ s32 n1;
// /* 0x18 */ s32 nz1;
// /* 0x1C */ s32 n2;
// /* 0x20 */ s32 nz2;
// /* 0x24 */ s32 prec;
// /* 0x28 */ s32 width;
// /* 0x2C */ size_t nchar;
// /* 0x30 */ u32 flags;
// /* 0x34 */ u8 qual;
// } _Pft;
#define BUFF_LEN 0x18
#define FLAGS_SPACE 1
#define FLAGS_PLUS 2
#define FLAGS_MINUS 4
#define FLAGS_HASH 8
#define FLAGS_ZERO 16
// #define FLAGS_SPACE 1
// #define FLAGS_PLUS 2
// #define FLAGS_MINUS 4
// #define FLAGS_HASH 8
// #define FLAGS_ZERO 16
// Pending Data for import:
// u8 ldigs[] = "0123456789abcdef";

View File

@ -1,4 +1,4 @@
#include "common.h"
#include "global.h"
void func_8001EE60(void) {
}

View File

@ -1,31 +0,0 @@
#include "common.h"
s32 func_80023FC0(s32, s32, s32);
s32 func_800246D0(void*, s8*, s32, s32);
s32 func_8001F9E0(s32 arg0, s32 arg1, s32 arg2);
// matches with IDO 5.3/7.1 -O2 -g0
#ifdef NON_MATCHING
s32 func_8001F9E0(s32 arg0, s32 arg1, s32 arg2) {
return func_80023FC0(arg0, arg1, arg2) + arg2;
}
#else
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/205E0/func_8001F9E0.s")
#endif
// matches with IDO 5.3/7.1 -O2 -g0
#ifdef NON_MATCHING
s32 func_8001FA04(s8* arg0, s32 arg1, s32 arg2) {
s32 ret = func_800246D0(func_8001F9E0, arg0, arg1, arg2);
if (ret >= 0) {
arg0[ret] = 0;
}
return ret;
}
#else
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/205E0/func_8001FA04.s")
#endif
// https://decomp.me/scratch/Gt8dW close
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/205E0/func_8001FA54.s")

View File

@ -1,9 +0,0 @@
#include "common.h"
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/21520/func_80020920.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/21520/func_80020A88.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/21520/func_80020BF4.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/21520/func_80020D70.s")

View File

@ -1,9 +1,9 @@
#include "common.h"
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/271C0/func_800265C0.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/271C0/__osContRamWrite.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/271C0/func_800267C4.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/271C0/func_80026940.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/271C0/__osContRamRead.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/271C0/func_80026B5C.s")

View File

@ -1,4 +1,6 @@
#include "common.h"
#define _MIPS_SZLONG 32
#include "global.h"
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/2DF00/func_8002D300.s")

View File

@ -1,9 +1,7 @@
#include "common.h"
#include "global.h"
extern void func_8001FA04(void);
void func_80002E80(void) {
func_8001FA04();
s32 func_80002E80(char* dst, char* fmt, va_list args) {
return vsprintf(dst, fmt, args);
}
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/3A80/func_80002EA0.s")

View File

@ -7,123 +7,178 @@ extern s32 D_8013B3AC;
extern s32 D_8013B3B0;
extern s32 D_8013B3B4;
f32 func_80004E20(f32 arg0, f32 arg1) {
return arg0 - ((s32) (arg0 / arg1) * arg1);
f32 Math_ModF(f32 value, f32 mod) {
return value - ((s32) (value / mod) * mod);
}
void func_80004E4C(void) {
void Rand_Init(void) {
D_8013B3A4 = (s32) osGetTime() % 30000;
D_8013B3A8 = (s32) osGetTime() % 30000;
D_8013B3AC = (s32) osGetTime() % 30000;
}
f32 Rand_ZeroOne(void) {
D_8013B3A4 = (D_8013B3A4 * 0xAB) % 30269;
D_8013B3A8 = (D_8013B3A8 * 0xAC) % 30307;
D_8013B3AC = (D_8013B3AC * 0xAA) % 30323;
D_8013B3A4 = (D_8013B3A4 * 171) % 30269;
D_8013B3A8 = (D_8013B3A8 * 172) % 30307;
D_8013B3AC = (D_8013B3AC * 170) % 30323;
return fabsf(func_80004E20((D_8013B3A4 / 30269.0f) + (D_8013B3A8 / 30307.0f) + (D_8013B3AC / 30323.0f), 1.0f));
return fabsf(Math_ModF((D_8013B3A4 / 30269.0f) + (D_8013B3A8 / 30307.0f) + (D_8013B3AC / 30323.0f), 1.0f));
}
void func_80004FC8(s32 arg0, s32 arg1, s32 arg2) {
D_8013B3B0 = arg0;
D_8013B3B4 = arg1;
D_8013B3A0 = arg2;
void Rand_SetSeed(s32 seed1, s32 seed2, s32 seed3) {
D_8013B3B0 = seed1;
D_8013B3B4 = seed2;
D_8013B3A0 = seed3;
}
f32 func_80004FE8(void) {
D_8013B3B0 = (D_8013B3B0 * 0xAB) % 30269;
D_8013B3B4 = (D_8013B3B4 * 0xAC) % 30307;
D_8013B3A0 = (D_8013B3A0 * 0xAA) % 30323;
f32 Rand_ZeroOneSeeded(void) {
D_8013B3B0 = (D_8013B3B0 * 171) % 30269;
D_8013B3B4 = (D_8013B3B4 * 172) % 30307;
D_8013B3A0 = (D_8013B3A0 * 170) % 30323;
return fabsf(func_80004E20((D_8013B3B0 / 30269.0f) + (D_8013B3B4 / 30307.0f) + (D_8013B3A0 / 30323.0f), 1.0f));
return fabsf(Math_ModF((D_8013B3B0 / 30269.0f) + (D_8013B3B4 / 30307.0f) + (D_8013B3A0 / 30323.0f), 1.0f));
}
f32 func_80005100(f32 arg0, f32 arg1) {
if ((arg0 == 0.0f) && (arg1 == 0.0f)) {
f32 Math_Atan2F(f32 y, f32 x) {
if ((y == 0.0f) && (x == 0.0f)) {
return 0.0f;
}
if (arg1 == 0.0f) {
if (arg0 < 0.0f) {
if (x == 0.0f) {
if (y < 0.0f) {
return -M_PI / 2.0f;
} else {
return M_PI / 2.0f;
}
}
if (arg1 < 0.0f) {
if (arg0 < 0.0f) {
return -(M_PI - func_8001FBE8(fabs(arg0 / arg1)));
if (x < 0.0f) {
if (y < 0.0f) {
return -(M_PI - Math_FAtanF(fabs(y / x)));
} else {
return M_PI - func_8001FBE8(fabs(arg0 / arg1));
return M_PI - Math_FAtanF(fabs(y / x));
}
} else {
return func_8001FBE8(arg0 / arg1);
return Math_FAtanF(y / x);
}
}
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/5A20/func_800051F8.s")
f32 func_80005320(f32 arg0, f32 arg1) {
if ((arg0 == 0.0f) && (arg1 == 0.0f)) {
f32 Math_Atan2F_XY(f32 x, f32 y) {
if ((x == 0.0f) && (y == 0.0f)) {
return 0.0f;
}
if (arg0 == 0.0f) {
if (arg1 < 0.0f) {
if (x == 0.0f) {
if (y < 0.0f) {
return -M_PI / 2.0f;
} else {
return M_PI / 2.0f;
}
}
if (y == 0.0f) {
if (x > 0.0f) {
return 0.0f;
} else {
return M_PI;
}
}
if (x < 0.0f) {
if (y < 0.0f) {
return -(M_PI - Math_FAtanF(fabs(x / y)));
} else {
return M_PI - Math_FAtanF(fabs(x / y));
}
} else {
return Math_FAtanF(x / y);
}
}
f32 Math_Atan2F_XYAlt(f32 x, f32 y) {
if ((x == 0.0f) && (y == 0.0f)) {
return 0.0f;
}
if (x == 0.0f) {
if (y < 0.0f) {
return -M_PI / 2.0f;
}
return M_PI / 2.0f;
}
if (arg1 == 0.0f) {
if (y == 0.0f) {
return 0.0f;
}
return -func_8001FBE8(arg0 / arg1);
return -Math_FAtanF(x / y);
}
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/5A20/func_800053C8.s")
f32 Math_FactorialF(f32 n) {
f32 out = 1.0f;
s32 i;
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/5A20/func_800054C8.s")
f32 func_800055DC(f32 arg0, s32 arg1) {
f32 var_fv1 = 1.0f;
while (arg1 > 0) {
arg1--;
var_fv1 *= arg0;
for (i = (s32) n; i > 1; i--) {
out *= i;
}
return var_fv1;
return out;
}
void func_80005604(s32* arg0, s32* arg1, s32 arg2, s32 arg3, s32 arg4) {
if (arg2 < arg3) {
if (arg3 < arg4) {
*arg0 = arg2;
*arg1 = arg4;
return;
}
*arg1 = arg3;
extern f32 D_800C45E0[];
if (arg2 < arg4) {
*arg0 = arg2;
return;
}
*arg0 = arg4;
return;
}
f32 Math_Factorial(s32 n) {
f32 out;
s32 i;
if (arg2 < arg4) {
*arg0 = arg3;
*arg1 = arg4;
return;
}
*arg1 = arg2;
if (n > 12) {
out = 1.0f;
if (arg3 < arg4) {
*arg0 = arg3;
return;
for (i = n; i > 1; i--) {
out *= i;
}
*arg0 = arg4;
} else {
out = D_800C45E0[n];
}
return out;
}
f32 Math_PowF(f32 base, s32 exp) {
f32 out = 1.0f;
while (exp > 0) {
exp--;
out *= base;
}
return out;
}
void Math_MinMax(s32* min, s32* max, s32 val1, s32 val2, s32 val3) {
if (val1 < val2) {
if (val2 < val3) {
*min = val1;
*max = val3;
return;
}
*max = val2;
if (val1 < val3) {
*min = val1;
return;
}
*min = val3;
return;
}
if (val1 < val3) {
*min = val2;
*max = val3;
return;
}
*max = val1;
if (val2 < val3) {
*min = val2;
return;
}
*min = val3;
}

View File

@ -18,9 +18,9 @@ s32 func_8000716C(s32 arg0, u8* arg1) {
if (osEepromWrite(&D_800E2128, arg0, arg1)) {
return -1;
}
temp_ret = __ull_div(osClockRate, 0x3D09);
temp_ret_2 = __ll_mul(0x3A98, temp_ret);
temp_ret_3 = __ull_div(temp_ret_2, 0x40);
temp_ret = __ull_div(osClockRate, 15625);
temp_ret_2 = __ll_mul(15000, temp_ret);
temp_ret_3 = __ull_div(temp_ret_2, 64);
func_800070C8(temp_ret_3);
return 0;

25
src/main/math64.c Normal file
View File

@ -0,0 +1,25 @@
#include "common.h"
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/math64/func_8001FAB0.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/math64/func_8001FAE4.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/math64/func_8001FB04.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/math64/func_8001FB24.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/math64/func_8001FB58.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/math64/func_8001FB88.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/math64/func_8001FBA8.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/math64/func_8001FBC8.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/math64/Math_FAtanF.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/math64/Math_FAtan2F.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/math64/Math_FAsinF.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/math64/Math_FAcosF.s")

23
src/main/sf_2EFE0.c Normal file
View File

@ -0,0 +1,23 @@
#include "common.h"
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_2EFE0/func_8002E3E0.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_2EFE0/func_8002E4F8.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_2EFE0/func_8002E548.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_2EFE0/func_8002E5E0.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_2EFE0/func_8002E604.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_2EFE0/func_8002E628.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_2EFE0/func_8002E64C.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_2EFE0/func_8002E670.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_2EFE0/func_8002E694.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_2EFE0/func_8002E6B8.s")
#pragma GLOBAL_ASM("asm/us/nonmatchings/main/sf_2EFE0/func_8002E6DC.s")

View File

@ -1744,8 +1744,8 @@ s32 func_80091864(UnkStruct_func_80090A00* arg0) {
y = arg0->unk_114[5] - arg0->unk_000.pos.y;
z = arg0->unk_114[6] - arg0->unk_000.pos.z;
sp40 = func_8009F768(func_80005100(x, z));
sp44 = func_8009F768(func_80005100(y, sqrtf(SQ(x) + SQ(z))));
sp40 = func_8009F768(Math_Atan2F(x, z));
sp44 = func_8009F768(Math_Atan2F(y, sqrtf(SQ(x) + SQ(z))));
if ((func_800915FC(arg0) != 0) && (arg0->unk_050[4] == 0)) {
sp44 += 40.0f;

View File

@ -304,9 +304,9 @@ void func_80189208_EC18C8(void) {
D_8017855C = (s32) D_801B830C;
if ((D_801B86A4 < 2) && (D_801B9040 != 0)) {
D_801B86D8 = func_80005100(-D_801B9060, sqrtf((-D_801B905C * -D_801B905C) + (-D_801B9064 * -D_801B9064))) *
180.0f / M_PI;
D_801B86DC = (func_80005100(D_801B905C, D_801B9064) * 180.0f) / M_PI;
D_801B86D8 =
Math_Atan2F(-D_801B9060, sqrtf((-D_801B905C * -D_801B905C) + (-D_801B9064 * -D_801B9064))) * 180.0f / M_PI;
D_801B86DC = (Math_Atan2F(D_801B905C, D_801B9064) * 180.0f) / M_PI;
func_8009BC2C(&D_801B86C8, D_801B86D8, 0.1f, 100.0f, 0.0001f);
func_8009BC2C(&D_801B86CC, D_801B86DC, 0.1f, 100.0f, 0.0001f);

View File

@ -28,7 +28,8 @@ def get_c_file(directory):
def import_c_file(in_file):
in_file = os.path.relpath(in_file, root_dir)
cpp_command = ["gcc", "-E", "-P", "-Iinclude", "-Isrc", "-undef", "-D__sgi", "-D_LANGUAGE_C",
"-DNON_MATCHING", "-D_Static_assert(x, y)=", "-D__attribute__(x)=", in_file]
"-DNON_MATCHING", "-D_Static_assert(x, y)=", "-D__attribute__(x)=",
"-D_MIPS_SZLONG=32", in_file]
try:
return subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8")
except subprocess.CalledProcessError:

View File

@ -8,14 +8,14 @@
- [0x1050, textbin]
- [0x1270, textbin]
- [0x3440, c]
- [0x3A80, c]
- [0x41D0, c]
- [0x4650, c]
- [0x5A20, c] # -O2 -g3
- [0x6280, c] # -O2 -g3
- [0x7B20, c]
- [0x7D30, c]
- [0x3440, c, 3440]
- [0x3A80, c, 3A80]
- [0x41D0, c, 41D0]
- [0x4650, c, 4650]
- [0x5A20, c, 5A20] # -O2 -g3
- [0x6280, c, 6280] # -O2 -g3
- [0x7B20, c, 7B20]
- [0x7D30, c, 7D30]
- [0x7FC0, c, 7FC0]
- [0x8CC0, c, 8CC0]
- [0xC870, c, C870]
@ -23,13 +23,13 @@
- [0x12490, c, 12490]
- [0x14AA0, c, 14AA0]
- [0x17650, c, 17650] # Sound related
- [0x1EB50, c, 1EB50] # Sound related
- [0x1EB50, c, 1EB50] # Audio Thread
- [0x1FA60, c]
- [0x1FA70, hasm]
- [0x1FB10, hasm]
- [0x205E0, c]
- [0x206B0, c, ../libultra/206B0] # math64
- [0x20A60, hasm] # fp.text.s
- [0x205E0, c, ../libultra/rmon/sprintf]
- [0x206B0, c, math64] # math64
- [0x20A60, hasm, fp.text] # fp.text.s
# LIBULTRA
- [0x20BC0, c, ../libultra/io/controller]
@ -37,12 +37,12 @@
- [0x211E0, c, ../libultra/os/recvmesg]
- [0x21320, c, ../libultra/os/sendmesg]
- [0x21470, c, ../libultra/io/contquery]
- [0x21520, c]
- [0x21520, c, ../libultra/io/motor]
- [0x21B40, c, ../libultra/gu/perspective]
- [0x21DD0, c, ../libultra/gu/lookat]
- [0x22100, c, ../libultra/gu/ortho]
- [0x222C0, hasm, invalicache]
- [0x22340, hasm, invaldcache]
- [0x222C0, hasm, ../libultra/os/invalicache]
- [0x22340, hasm, ../libultra/os/invaldcache]
- [0x223F0, c, ../libultra/io/pidma]
- [0x22500, c, ../libultra/io/viblack]
- [0x22570, hasm, writebackdcacheall]
@ -149,8 +149,10 @@
- [0x2EDE0, c, ../libultra/2EDE0]
- [0x2EE30, c, ../libultra/2EE30]
- [0x2EE80, c, ../libultra/os/stopthread]
- [0x2EF40, hasm, ../libultra/rmon/rmonrcp]
# Game engine
- [0x2EFE0, c, sf_2EFE0]
- [0x2F300, c, sf_2F300]
- [0x36930, c, sf_36930]
- [0x43AC0, c, sf_43AC0]
@ -190,7 +192,7 @@
- [0xC9320, .rodata, 14AA0]
- [0xC99D0, .rodata, 17650]
- [0xC9CF0, .rodata, 1EB50]
- [0xC9F10, .rodata, ../libultra/206B0]
- [0xC9F10, .rodata, math64]
- [0xC9F30, .rodata, ../libultra/gu/perspective]
- [0xC9F40, .rodata, ../libultra/gu/sinf]
- [0xC9F90, .rodata, ../libultra/gu/cosf]
@ -201,7 +203,7 @@
- [0xCA180, .rodata, ../libultra/rmon/xldtob]
- [0xCA1E0, .rodata, ../libultra/2BDF0]
- [0xCA5A0, .rodata, 2DF00]
- [0xCA650, .rodata, ../libultra/os/stopthread]
- [0xCA650, rodata, ../libultra/rmon/rmonrcp]
# DATA - game engine
- [0xCA690, data, engine]