Mario Kart 64
Loading...
Searching...
No Matches
memory.c File Reference
#include <ultra64.h>
#include <PR/ultratypes.h>
#include <macros.h>
#include <common_structs.h>
#include <segments.h>
#include <decode.h>
#include "memory.h"
#include "main.h"
#include "code_800029B0.h"
#include "math_util.h"
#include "courses/courseTable.h"
#include "defines.h"
Include dependency graph for memory.c:

Data Structures

struct  UnkStr_802AA7C8
 

Functions

void * get_next_available_memory_addr (uintptr_t size)
 Returns the address of the next available memory location and updates the memory pointer to reference the next location of available memory based provided size to allocate.
 
uintptr_t set_segment_base_addr (s32 segment, void *addr)
 Stores the physical memory addr for segmented memory in gSegmentTable using the segment number as an index.
 
void * get_segment_base_addr (s32 segment)
 Returns the physical memory location of a segment.
 
void * segmented_to_virtual (const void *addr)
 converts an RSP segment + offset address to a normal memory address
 
void move_segment_table_to_dmem (void)
 
void initialize_memory_pool (uintptr_t poolStart, uintptr_t poolEnd)
 Sets the starting location for allocating memory and calculates pool size.
 
void * allocate_memory (size_t size)
 Allocates memory and adjusts gFreeMemorySize.
 
UNUSED void func_802A7D54 (s32 arg0, s32 arg1)
 
void * load_data (uintptr_t startAddr, uintptr_t endAddr)
 Allocate and DMA.
 
UNUSED void main_pool_init (uintptr_t start, uintptr_t end)
 
UNUSED void * main_pool_alloc (uintptr_t size, uintptr_t side)
 
UNUSED uintptr_t main_pool_free (void *addr)
 
UNUSED void * main_pool_realloc (void *addr, uintptr_t size)
 
UNUSED uintptr_t main_pool_available (void)
 
UNUSED uintptr_t main_pool_push_state (void)
 
UNUSED uintptr_t main_pool_pop_state (void)
 
UNUSED void * func_802A80B0 (u8 *dest, u8 *srcStart, u8 *srcEnd)
 
UNUSED void * load_segment (s32 segment, u8 *srcStart, u8 *srcEnd, u8 *side)
 
UNUSED void * func_802A8190 (s32 arg0, u8 *arg1)
 
UNUSED void func_802A81EC (void)
 
UNUSED struct AllocOnlyPoolalloc_only_pool_init (uintptr_t size, uintptr_t side)
 
UNUSED uintptr_t func_802A82AC (s32 arg0)
 
u8dma_compressed_vtx (u8 *start, u8 *end)
 Returns pointer to mio0 compressed Vtx.
 
UNUSED uintptr_t func_802A8348 (s32 arg0, s32 arg1, s32 arg2)
 
UNUSED u8func_802A841C (u8 *arg0, s32 arg1, s32 arg2)
 
u8dma_textures (u8 texture[], size_t arg1, size_t arg2)
 
uintptr_t MIO0_0F (u8 *arg0, uintptr_t arg1, uintptr_t arg2)
 
void func_802A86A8 (CourseVtx *data, u32 arg1)
 
void decompress_vtx (CourseVtx *arg0, u32 vertexCount)
 
UNUSED void func_802A8844 (void)
 
void unpack_lights (Gfx *arg0, UNUSED u8 *arg1, s8 arg2)
 
void unpack_displaylist (Gfx *arg0, u8 *args, UNUSED s8 opcode)
 
void unpack_end_displaylist (Gfx *arg0, UNUSED u8 *arg1, UNUSED s8 arg2)
 
void unpack_set_geometry_mode (Gfx *arg0, UNUSED u8 *arg1, UNUSED s8 arg2)
 
void unpack_clear_geometry_mode (Gfx *arg0, UNUSED u8 *arg1, UNUSED s8 arg2)
 
void unpack_cull_displaylist (Gfx *arg0, UNUSED u8 *arg1, UNUSED s8 arg2)
 
void unpack_combine_mode1 (Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2)
 
void unpack_combine_mode2 (Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2)
 
void unpack_combine_mode_shade (Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2)
 
void unpack_combine_mode4 (Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2)
 
void unpack_combine_mode5 (Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2)
 
void unpack_render_mode_opaque (Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2)
 
void unpack_render_mode_tex_edge (Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2)
 
void unpack_render_mode_translucent (Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2)
 
void unpack_render_mode_opaque_decal (Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2)
 
void unpack_render_mode_translucent_decal (Gfx *arg0, UNUSED u8 *arg1, UNUSED uintptr_t arg2)
 
void unpack_tile_sync (Gfx *gfx, u8 *args, s8 opcode)
 
void unpack_tile_load_sync (Gfx *gfx, u8 *args, s8 opcode)
 
void unpack_texture_on (Gfx *arg0, UNUSED u8 *args, UNUSED s8 arg2)
 
void unpack_texture_off (Gfx *arg0, UNUSED u8 *args, UNUSED s8 arg2)
 
void unpack_vtx1 (Gfx *gfx, u8 *args, UNUSED s8 arg2)
 
void unpack_vtx2 (Gfx *gfx, u8 *args, s8 arg2)
 
void unpack_triangle (Gfx *gfx, u8 *args, UNUSED s8 arg2)
 
void unpack_quadrangle (Gfx *gfx, u8 *args, UNUSED s8 arg2)
 
void unpack_spline_3D (Gfx *gfx, u8 *arg1, UNUSED s8 arg2)
 
UNUSED void func_802A9AEC (void)
 
void displaylist_unpack (uintptr_t *data, uintptr_t finalDisplaylistOffset, u32 arg2)
 
void decompress_textures (u32 *arg0)
 
void * decompress_segments (u8 *start, u8 *end)
 
u8load_course (s32 courseId)
 Loads & DMAs course data. Vtx, textures, displaylists, etc.
 

Variables

s32 sGfxSeekPosition
 
s32 sPackedSeekPosition
 
uintptr_t sPoolFreeSpace
 
struct MainPoolBlocksPoolListHeadL
 
struct MainPoolBlocksPoolListHeadR
 
struct MainPoolStategMainPoolState = NULL
 
struct UnkStruct_802B8CD4 D_802B8CD4 [] = { 0 }
 
s32 D_802B8CE4 = 0
 
s32 memoryPadding [2]
 

Function Documentation

◆ alloc_only_pool_init()

UNUSED struct AllocOnlyPool * alloc_only_pool_init ( uintptr_t size,
uintptr_t side )
Here is the call graph for this function:

◆ allocate_memory()

void * allocate_memory ( size_t size)

Allocates memory and adjusts gFreeMemorySize.

Here is the caller graph for this function:

◆ decompress_segments()

void * decompress_segments ( u8 * start,
u8 * end )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decompress_textures()

void decompress_textures ( u32 * arg0)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decompress_vtx()

void decompress_vtx ( CourseVtx * arg0,
u32 vertexCount )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ displaylist_unpack()

void displaylist_unpack ( uintptr_t * data,
uintptr_t finalDisplaylistOffset,
u32 arg2 )

Unpacks course packed displaylists by iterating through each byte of the packed file. Each packed displaylist entry has an opcode and any number of arguments. The opcodes range from 0 to 87 which are used to run the relevant unpack function. The file pointer increments when arguments are used. This way, displaylist_unpack will always read an opcode and not an argument by accident.

Warning
opcodes that do not contain a definition in the switch are ignored. If an undefined opcode contained arguments the unpacker might try to unpack those arguments. This issue is prevented so long as the packed file adheres to correct opcodes and unpack code increments the file pointer the correct number of times.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dma_compressed_vtx()

u8 * dma_compressed_vtx ( u8 * start,
u8 * end )

Returns pointer to mio0 compressed Vtx.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dma_textures()

u8 * dma_textures ( u8 texture[],
size_t arg1,
size_t arg2 )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ func_802A7D54()

UNUSED void func_802A7D54 ( s32 arg0,
s32 arg1 )

◆ func_802A80B0()

UNUSED void * func_802A80B0 ( u8 * dest,
u8 * srcStart,
u8 * srcEnd )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ func_802A8190()

UNUSED void * func_802A8190 ( s32 arg0,
u8 * arg1 )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ func_802A81EC()

UNUSED void func_802A81EC ( void )
Here is the call graph for this function:

◆ func_802A82AC()

UNUSED uintptr_t func_802A82AC ( s32 arg0)

◆ func_802A8348()

UNUSED uintptr_t func_802A8348 ( s32 arg0,
s32 arg1,
s32 arg2 )
Here is the call graph for this function:

◆ func_802A841C()

UNUSED u8 * func_802A841C ( u8 * arg0,
s32 arg1,
s32 arg2 )
Here is the call graph for this function:

◆ func_802A86A8()

void func_802A86A8 ( CourseVtx * data,
u32 arg1 )
Here is the caller graph for this function:

◆ func_802A8844()

UNUSED void func_802A8844 ( void )

◆ func_802A9AEC()

UNUSED void func_802A9AEC ( void )

◆ get_next_available_memory_addr()

void * get_next_available_memory_addr ( uintptr_t size)

Returns the address of the next available memory location and updates the memory pointer to reference the next location of available memory based provided size to allocate.

Parameters
sizeof memory to allocate.
Returns
Address of free memory
Here is the caller graph for this function:

◆ get_segment_base_addr()

void * get_segment_base_addr ( s32 segment)

Returns the physical memory location of a segment.

Parameters
permitssegment numbers from 0x0 to 0xF.

◆ initialize_memory_pool()

void initialize_memory_pool ( uintptr_t poolStart,
uintptr_t poolEnd )

Sets the starting location for allocating memory and calculates pool size.

Default memory size, 701.984 Kilobytes.

Here is the caller graph for this function:

◆ load_course()

u8 * load_course ( s32 courseId)

Loads & DMAs course data. Vtx, textures, displaylists, etc.

Parameters
courseId
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_data()

void * load_data ( uintptr_t startAddr,
uintptr_t endAddr )

Allocate and DMA.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_segment()

UNUSED void * load_segment ( s32 segment,
u8 * srcStart,
u8 * srcEnd,
u8 * side )
Here is the call graph for this function:

◆ main_pool_alloc()

UNUSED void * main_pool_alloc ( uintptr_t size,
uintptr_t side )

Allocate a block of memory from the pool of given size, and from the specified side of the pool (MEMORY_POOL_LEFT or MEMORY_POOL_RIGHT). If there is not enough space, return NULL.

Here is the caller graph for this function:

◆ main_pool_available()

UNUSED uintptr_t main_pool_available ( void )

◆ main_pool_free()

UNUSED uintptr_t main_pool_free ( void * addr)

Free a block of memory that was allocated from the pool. The block must be the most recently allocated block from its end of the pool, otherwise all newer blocks are freed as well. Return the amount of free space left in the pool.

Here is the caller graph for this function:

◆ main_pool_init()

UNUSED void main_pool_init ( uintptr_t start,
uintptr_t end )

◆ main_pool_pop_state()

UNUSED uintptr_t main_pool_pop_state ( void )

Restore pool state from a previous call to main_pool_push_state. Return the amount of free space left in the pool.

◆ main_pool_push_state()

UNUSED uintptr_t main_pool_push_state ( void )
Here is the call graph for this function:

◆ main_pool_realloc()

UNUSED void * main_pool_realloc ( void * addr,
uintptr_t size )
Here is the call graph for this function:

◆ MIO0_0F()

uintptr_t MIO0_0F ( u8 * arg0,
uintptr_t arg1,
uintptr_t arg2 )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ move_segment_table_to_dmem()

void move_segment_table_to_dmem ( void )
Here is the caller graph for this function:

◆ segmented_to_virtual()

void * segmented_to_virtual ( const void * addr)

converts an RSP segment + offset address to a normal memory address

Here is the caller graph for this function:

◆ set_segment_base_addr()

uintptr_t set_segment_base_addr ( s32 segment,
void * addr )

Stores the physical memory addr for segmented memory in gSegmentTable using the segment number as an index.

This function takes a segment number and a pointer to a memory address, and stores the address in the gSegmentTable array at the specified segment index. The stored address is truncated to a 29-bit value to ensure that it fits within the memory address. This allows converting between segmented memory and physical memory.

Parameters
segmentA segment number from 0x0 to 0xF to set the base address.
addrA pointer containing the physical memory address of the data.
Returns
The stored base address, truncated to a 29-bit value.
Here is the caller graph for this function:

◆ unpack_clear_geometry_mode()

void unpack_clear_geometry_mode ( Gfx * arg0,
UNUSED u8 * arg1,
UNUSED s8 arg2 )
Here is the caller graph for this function:

◆ unpack_combine_mode1()

void unpack_combine_mode1 ( Gfx * arg0,
UNUSED u8 * arg1,
UNUSED uintptr_t arg2 )
Here is the caller graph for this function:

◆ unpack_combine_mode2()

void unpack_combine_mode2 ( Gfx * arg0,
UNUSED u8 * arg1,
UNUSED uintptr_t arg2 )
Here is the caller graph for this function:

◆ unpack_combine_mode4()

void unpack_combine_mode4 ( Gfx * arg0,
UNUSED u8 * arg1,
UNUSED uintptr_t arg2 )
Here is the caller graph for this function:

◆ unpack_combine_mode5()

void unpack_combine_mode5 ( Gfx * arg0,
UNUSED u8 * arg1,
UNUSED uintptr_t arg2 )
Here is the caller graph for this function:

◆ unpack_combine_mode_shade()

void unpack_combine_mode_shade ( Gfx * arg0,
UNUSED u8 * arg1,
UNUSED uintptr_t arg2 )
Here is the caller graph for this function:

◆ unpack_cull_displaylist()

void unpack_cull_displaylist ( Gfx * arg0,
UNUSED u8 * arg1,
UNUSED s8 arg2 )
Here is the caller graph for this function:

◆ unpack_displaylist()

void unpack_displaylist ( Gfx * arg0,
u8 * args,
UNUSED s8 opcode )
Here is the caller graph for this function:

◆ unpack_end_displaylist()

void unpack_end_displaylist ( Gfx * arg0,
UNUSED u8 * arg1,
UNUSED s8 arg2 )
Here is the caller graph for this function:

◆ unpack_lights()

void unpack_lights ( Gfx * arg0,
UNUSED u8 * arg1,
s8 arg2 )
Here is the caller graph for this function:

◆ unpack_quadrangle()

void unpack_quadrangle ( Gfx * gfx,
u8 * args,
UNUSED s8 arg2 )
Here is the caller graph for this function:

◆ unpack_render_mode_opaque()

void unpack_render_mode_opaque ( Gfx * arg0,
UNUSED u8 * arg1,
UNUSED uintptr_t arg2 )
Here is the caller graph for this function:

◆ unpack_render_mode_opaque_decal()

void unpack_render_mode_opaque_decal ( Gfx * arg0,
UNUSED u8 * arg1,
UNUSED uintptr_t arg2 )
Here is the caller graph for this function:

◆ unpack_render_mode_tex_edge()

void unpack_render_mode_tex_edge ( Gfx * arg0,
UNUSED u8 * arg1,
UNUSED uintptr_t arg2 )
Here is the caller graph for this function:

◆ unpack_render_mode_translucent()

void unpack_render_mode_translucent ( Gfx * arg0,
UNUSED u8 * arg1,
UNUSED uintptr_t arg2 )
Here is the caller graph for this function:

◆ unpack_render_mode_translucent_decal()

void unpack_render_mode_translucent_decal ( Gfx * arg0,
UNUSED u8 * arg1,
UNUSED uintptr_t arg2 )
Here is the caller graph for this function:

◆ unpack_set_geometry_mode()

void unpack_set_geometry_mode ( Gfx * arg0,
UNUSED u8 * arg1,
UNUSED s8 arg2 )
Here is the caller graph for this function:

◆ unpack_spline_3D()

void unpack_spline_3D ( Gfx * gfx,
u8 * arg1,
UNUSED s8 arg2 )
Here is the caller graph for this function:

◆ unpack_texture_off()

void unpack_texture_off ( Gfx * arg0,
UNUSED u8 * args,
UNUSED s8 arg2 )
Here is the caller graph for this function:

◆ unpack_texture_on()

void unpack_texture_on ( Gfx * arg0,
UNUSED u8 * args,
UNUSED s8 arg2 )
Here is the caller graph for this function:

◆ unpack_tile_load_sync()

void unpack_tile_load_sync ( Gfx * gfx,
u8 * args,
s8 opcode )
Here is the caller graph for this function:

◆ unpack_tile_sync()

void unpack_tile_sync ( Gfx * gfx,
u8 * args,
s8 opcode )
Here is the caller graph for this function:

◆ unpack_triangle()

void unpack_triangle ( Gfx * gfx,
u8 * args,
UNUSED s8 arg2 )
Here is the caller graph for this function:

◆ unpack_vtx1()

void unpack_vtx1 ( Gfx * gfx,
u8 * args,
UNUSED s8 arg2 )
Here is the caller graph for this function:

◆ unpack_vtx2()

void unpack_vtx2 ( Gfx * gfx,
u8 * args,
s8 arg2 )
Here is the caller graph for this function:

Variable Documentation

◆ D_802B8CD4

struct UnkStruct_802B8CD4 D_802B8CD4[] = { 0 }

◆ D_802B8CE4

s32 D_802B8CE4 = 0

◆ gMainPoolState

struct MainPoolState* gMainPoolState = NULL

◆ memoryPadding

s32 memoryPadding[2]

◆ sGfxSeekPosition

s32 sGfxSeekPosition

◆ sPackedSeekPosition

s32 sPackedSeekPosition

◆ sPoolFreeSpace

uintptr_t sPoolFreeSpace

◆ sPoolListHeadL

struct MainPoolBlock* sPoolListHeadL

◆ sPoolListHeadR

struct MainPoolBlock* sPoolListHeadR