Welcome to Data Crystal's new home! Data Crystal is now part of the TCRF family (sort of).
The wiki has recently moved; please report any issues in Discord. Pardon the dust.

The Legend of Zelda: Ocarina of Time/RAM map

From Data Crystal
Jump to navigation Jump to search

Chip tiny.png The following article is a RAM map for The Legend of Zelda: Ocarina of Time.

Note: All addresses are for the Master Quest Debug version of the ROM.

Functions

The N64 functions and math functions were found with LFE unless otherwise noted.

Misc

0x800C5484
char * game_alloc(u32 z_gp, int siz, char * fn, int line);

Allocates memory
z_gp is 0x80212020
siz is the size of the block to be allocated
fn is the file (__FILE__)
line is the line (__LINE__)

OoT spawn functions

SpawnObject

0x80097C00
void ObjectSpawn(u32 const_1, u16 object_number);

Spawns an object
const_1 is 0x802237C4

ActorSpawn

0x80031F50
actor * ActorSpawn(u32 const_1, u32 const_2, int actor, f32 fx, f32 fy, f32 fz, u16 rx, u16 ry, u16 rz, int variable);

Spawns an actor
const_1 is 0x80213C44
const_2 is 0x80212020
Return value is a pointer to a loaded actor.

SpawnArea

0x800C0008
void SpawnArea(u32 const80212020, int scene_no, int entrance_no);

Spawns a specified scene
const80212020 is the super important global var
scene_no is the scene number to use
entrance_no is the start position to use.

OoT Text functions

buffer is a text object, 0x2C bytes as I recall. It's structure is still yet to be determined.

SetTextRGBA

0x800FB3AC
void SetTextRGBA(void * buffer, u8 r, u8 g, u8 b, u8 a);

Sets color of text to be drawn

SetTextXY

0x800FB41C
void SetTextXY(void * buffer, u16 x, u16 y);

Sets the position of text to be drawn

SetTextString

0x800FBCB4
void SetTextString(void * buffer, char * format, ...);

Sets the text string to be drawn

Math functions

absf

0x801067E0
float absf(float value);

Returns absolute value of a float
Not found with LFE, manually found

__sinf/fsin/sinf

0x80100290
float sinf(float angle);

Computes the sine of an angle in floating point

sins

0x80100450
float sins(unsigned short angle)

Computes the sine of an angle in fixed point

__cosf/fcos/cosf

0x80104610
float cosf(float angle);

Computes the cosine of an angle in floating point

coss

0x80104780
float coss(unsigned short angle);

Computes the cosine of an angle in fixed point

sqrtf

0x801031E0
float sqrtf (float value);

Computes the square root

N64 OS functions

osSendMesg

0x80003060
void osSendMesg(OSMesgQueue *mq, OSMesg msg, s32 flag);

Provides messaging and synchronization facilities

osStopThread

0x800031B0
void osStopThread(OSThread *t);

Suspends a given thread

osRecvMesg

0x80003280
s32 osRecvMesg(OSMesgQueue *mq, OSMesg *msg, s32 flag);

Provides messaging and synchronization facilities

osCreateThread

0x80004550
void osCreateThread(OSThread *t, OSId id, void (*entry)(void *),
               void *arg, void *sp, OSPri pri);

Registers a schedulable object

osWritebackDCache

0x800046C0
void osWritebackDCache(void *vaddr, s32 nbytes);

Writes back CPU data cache lines to physical memory

osVirtualToPhysical

0x80004DE0
u32 osVirtualToPhysical(void *vaddr)

Translates between CPU virtual address/physical memory address

osGetThreadId

0x80004F20
void osGetThreadId(OSThread *t);

Obtains the debugger identifier of a thread

osSetIntMask

0x80004F40
OSIntMask osSetIntMask(OSIntMask im);

Sets the enabled interrupt mask

osInvalICache

0x80006150
void osInvalICache(void *vaddr, s32 nbytes);

Invalidates CPU instruction cache

osCreateMesgQueue

0x800061D0
void osCreateMesgQueue(OSMesgQueue *mq, OSMesg *msg, s32 count);

Provides messaging and synchronization facilities

osInvalDCache

0x80006200
void osInvalDCache(void *vaddr, s32 nbytes);

Invalidates CPU data cache lines

osJamMesg

0x800062E0
void osJamMesg(OSMesgQueue *mq, OSMesg msg, s32 flag);

Provides messaging and synchronization facilities

osSetThreadPri

0x80006430
void osSetThreadPri(OSThread *t, OSPri pri);

Sets the priority of specified thread

osGetThreadPri

0x80006510
void osGetThreadPri(OSThread *t);

Gets the priority of specified thread

osGetTime

0x800069E0
OSTime osGetTime(void);

Gets the real time counter value

osGetCount

0x80006EA0
u32 osGetCount(void);

Returns CPU count register

__osSetCompare

0x80006F00 : 
void __osSetCompare(u32 value);

Internal routine to access to multiple MIPS R4300 registers

__osSetFpcCsr

0x80007A70
u32 __osSetFpcCsr(u32 value);

Sets the current value of the R4300 floating-point control/status register

__osGetFpcCsr

0x80007A80
u32 __osGetFpcCsr(void);

Returns the current value of the R4300 floating-point control/status register

osYieldThread

0x80007B40
void osYieldThread(void);

Yields the CPU and invokes the thread dispatcher

__osGetCause

0x80007B90
u32 __osGetCause(void);

Returns the current value of the MIPS R4300 Cause register that describes the cause of the most recent exception

osStartThread

0x80008FC0
void osStartThread(OSThread *t);

Starts or resumes a thread

osSpTaskYield

0x801014A0
void osSpTaskLoad(OSTask *task);

Requests that the SP"yield"

osStopTimer

0x80102330
void osStopTimer(OSTimer *timer);

Stops an interval or countdown timer

osDpGetStatus

0x801041C0
u32 osDpGetStatus(void);

Returns the hardware status of the display processor command status register

osDpSetStatus

0x801041D0
void osDpSetStatus(u32 status);

Updates the display processor command status register with status

osAiGetLength

0x80105C00
u32 osAiGetLength(void);

Returns the number of bytes remaining in the current DMA buffer

osWritebackDCacheAll

0x80106490
void osWritebackDCache(void *vaddr, s32 nbytes);

Writes back all cached locations to physical memory

Undocumented

0x8000AE50 : osViModeMpalLan1
0x80012160 : __osRcpImTable
0x80106470 : __osSpGetStatus
0x80106480 : __osSpSetStatus
0x80004300 : __osDequeueThread
0x800046A0 : __osSetSR
0x800046B0 : __osGetSR
0x80005040 : __osProbeTLB
0x80006EB0 : __osSetGlobalIntMask
0x80007220 : __osResetGlobalIntMask
0x80007AE0 : osMapTLBRdb

Other N64 functions

bzero/_bzero/blkclr/_blkclr

0x80004450
void bzero(void *dst, int length);

Zero-clears a byte string

bcmp/_bcmp

0x800068C0
int bcmp(const void *s1, const void *s2, int length);

Compares byte strings

bcopy/_bcopy

0x80006F10
void bcopy(const void *src,void *dst,int length);

Copies a byte string

guPerspectiveF

0x801010D0
void guPerspectiveF(
       float mf[4][4],
       u16 *perspNorm,
       float fovy,
       float aspect,
       float near,
       float far,
       float scale);

Creates a perspective projection matrix (floating point)

guPerspective

0x80101300
void guPerspective(
       Mtx *m,
       u16 *perspNorm,
       float fovy,
       float aspect,
       float near,
       float far,
       float scale);

Creates a perspective projection matrix (fixed point)

Undocumented

0x80003710 : __ull_rshift
0x8000373C : __ull_rem
0x80003778 : __ull_div
0x800037B4 : __ll_lshift
0x800037E0 : __ll_rem
0x8000381C : __ll_div
0x80003878 : __ll_mul
0x800038A8 : __ull_divremi
0x80003908 : __ll_mod
0x800039A4 : __ll_rshift
0x80007D00 : _Litob
0x80106550 : __d_to_ll
0x8010656C : __f_to_ll
0x80106588 : __d_to_ull
0x80106628 : __f_to_ull
0x801066C4 : __ll_to_d
0x801066DC : __ll_to_f
0x801066F4 : __ull_to_d
0x80106728 : __ull_to_f
0x8014B2D0 : __libm_qnan_f

Within code

0x8001CE60 - 0x80157D90 is code

801274A0(u32)[0x1A]	Jump table for map reading functions
80127520(u16)		Adult link object number
80127522(u16)		Child link object number
80127524(u32)		Number of objects
80127528(u32)[# objs]	Object table
801162A0		Actor Table

TODO: scene table, exit table, more functions

Relative to 80212020

80212020 is a very important address, it seems to be argument 0 for many functions, is the 'base' for many variables.

Distance/typ		Actual Addr	Description
---------------------------------------------------
000270(u32)		80212290	Camera pointer
001C30(u32)[2][12] 	80213C50	List of actors, organized by type. first word is number of actors of that type,
					second word is address of the first of those actors.
?(u32)			80213CE8	What actor the z-target arrow is over
?(u32)			80213CEC	What actor is being z-targeted
011CC8(u32)		80223CE8	Map pointer (points to current object set iirc? someone doublecheck)
011DEA(u8)		80223E0A	Current entrance number being used.
011DEB(u8)		80223E0B	Number of map actors (nulled after actors are spawned iirc)
011DF8(*actorList)[]	80223E18	Pointer to map actor list with position/rotation of stuff.
0117A4(?)		802237C4	Argument 0 for SpawnObject() (this address, not value at this address)


802120E0	u32 screen top
802120E4	u32 screen bottom
802120E8	u32 screen left
802120EC	u32 screen right
802120F0	f32 cam distance
802124F4	f32 fog distance
802124F8	f32 z distance
802124FC	f32 unknown camera variable - leave at 1.0

RAM segments

80166FA8(u32)[(number of segments)] Segment table, value|0x80000000 = ram addr

char * segments[8] = 0x80166FA8;

Example: Segment 0x6 would be pointed to at 0x80166FC0 ( 0x6 << 2 = 0x18 + 0x80166FA8 = 0x80166FC0 )
Note: the table is for the engine's reference only, so it is not reliable at all times, it is only updated when the game needs to update it, but not necessarily as the banks are updated. Also, it does not have banks 8 - 15.

Controller

typedef struct
{
    /* Buttons */
    u16 pad;
    
    /* Joystick */
    signed x : 8;
    signed y : 8;
} Controller; 
80166AF0	Player 1
80166B08	Player 2
80166B20	Player 3
80166B38	Player 4

Misc

8015E693 (s16?)		Magic amount
8015E6EE (s8?)		Bombs amount
80211174 (u16)		Make any Non-Zero value to "freeze" all actors
802120C4 (u16)		Current Scene number
802245B0 z64_actor_t	Link