Skip to content

Commit

Permalink
Merge pull request #77 from RevoSucks/memory
Browse files Browse the repository at this point in the history
document and rename intro_loader to memory
  • Loading branch information
RevoSucks authored Aug 26, 2023
2 parents 232201f + a52534c commit a4420cd
Show file tree
Hide file tree
Showing 18 changed files with 520 additions and 442 deletions.
9 changes: 5 additions & 4 deletions include/functions.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _FUNCTIONS_H
#define _FUNCTIONS_H
#ifndef _FUNCTIONS_H_
#define _FUNCTIONS_H_

#include "ultra64.h"

Expand All @@ -12,10 +12,11 @@ extern void _bcopy(void *, void *, u32);
// 3640.s
extern void* func_80002AF8(s32, void*);

// 3A80.s
// 3A80.c
extern uintptr_t convert_addr_to_virt_addr(uintptr_t addr);
extern void func_80002F58(void);
extern void *func_80002FDC(s32);
extern void func_80003004(void *); // type unknown
extern void func_80003004(void *);

// 3FB0.s
extern void func_80003B30(void *, s32, s32, s32); // types unknown
Expand Down
2 changes: 1 addition & 1 deletion include/ultra64.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@

#include "ultra64/thread.h"

#include "functions.h"
#include "macros.h"
#include "functions.h"
#include "variables.h"

#endif
2 changes: 1 addition & 1 deletion splat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ segments:
- [0x1F70, bin, noppad_1F70] # Extra nop align like earlier. Weird
- [0x1F80, c, dp_intro] # dp intro code
- [0x28E0, c, memmap]
- [0x2EC0, c, intro_loader] # intro loader
- [0x2EC0, c, memory]
- [0x3640, asm] #
- [0x3A80, c]
- [0x3FB0, asm] # PRES-JPEG decoder
Expand Down
86 changes: 48 additions & 38 deletions src/3A80.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <ultra64.h>
#include "memmap.h"
#include "intro_loader.h"
#include "memory.h"

extern s32 D_80068B90;
extern u8 D_80104BB0[];
Expand All @@ -11,23 +11,33 @@ s32 func_80002A40(s32, s32);
void func_80002BD0(s32, void *); // type unknown
s32 func_80007A58(void);

uintptr_t func_80002E80(uintptr_t addr) {
uintptr_t retaddr = 0x00000000;
/*
* Convert any valid address to its virtual (KSEG0) counterpart.
*/
uintptr_t convert_addr_to_virt_addr(uintptr_t addr) {
uintptr_t retaddr = 0x00000000; // any invalid cases are treated as NULL return.

// convert physical (in installed memory range) to virtual.
if (addr < (size_t) osMemSize) {
retaddr = addr | 0x80000000;
// convert segmented to virtual.
} else if (addr < 0x10000000U) {
retaddr = Memmap_GetSegmentVaddr(addr);
// convert a fragment pre-relocated address to a post-relocated virtual address.
} else if ((addr >= 0x81000000U) && (addr < 0x90000000U)) { // is the address in fragment space? convert it to its post-relocated address.
retaddr = Memmap_GetFragmentVaddr(addr);
// pass-through addresses that are already virtual (in installed memory range)
} else if ((addr >= 0x80000000U) && (addr < (uintptr_t) (osMemSize + 0x80000000U))) {
retaddr = addr;
}

return retaddr;
}

// HAL memcpy?
void func_80002F28(u32* dest, u32* src, int size) {
/*
* Copy memory from one address to the other. (why is this function not in HAL_libc?)
*/
void HAL_Memcpy(u32* dest, u32* src, int size) {
while (size --> 0) {
*(dest++) = *(src++);
}
Expand All @@ -36,9 +46,9 @@ void func_80002F28(u32* dest, u32* src, int size) {
void func_80002F58(void) {
// wat? mem sizes are only ever 0x400000 or 0x800000. This check makes no sense.
if ((D_80068B90 != 0) && ((u32) osMemSize > 0x600000U)) {
func_800022C0(&D_80104BB0, 0x80600000);
main_pool_init(&D_80104BB0, 0x80600000);
} else {
func_800022C0(&D_80104BB0, 0x80400000);
main_pool_init(&D_80104BB0, 0x80400000);
D_80068B90 = 0;
}
func_80003860();
Expand All @@ -53,8 +63,7 @@ void func_80003004(void *arg0) {
func_80002BD0(D_800A60B0, arg0);
}

// HAL_DrawRect
void func_8000302C(Gfx** dlist, s32 ulx, s32 lrx, u16 color) {
void HAL_DrawRect(Gfx** dlist, s32 ulx, s32 lrx, u16 color) {
s32 uly = 0xF;
s32 lry = 0x11;
Gfx *gfx = *dlist;
Expand All @@ -72,48 +81,49 @@ void func_8000302C(Gfx** dlist, s32 ulx, s32 lrx, u16 color) {
*dlist = gfx;
}

void func_8000310C(Gfx** dlist)
{
struct Unk800A6070 * sp54 = func_80002A30();
s32 temp_s1 = func_80002764() - D_80068B90;
void func_8000310C(Gfx** dlist) {
struct MainPool *pool = main_pool_get_pool();
s32 temp_s1 = main_pool_get_available() - D_80068B90;

if (temp_s1 >= 0)
{
u32 coord = 0x1E;
s32 sp48 = ((u32) ( K0_TO_PHYS(sp54->unk20)) >> 0xF) + coord;
s32 sp44 = ((u32) ( K0_TO_PHYS(sp54->unk28)) >> 0xF) + coord;
s32 sp40 = ((u32) ( K0_TO_PHYS(sp54->unk2C) - D_80068B90) >> 0xF) + coord;
s32 sp3C = ((u32) ( K0_TO_PHYS(sp54->unk24) - D_80068B90) >> 0xF) + coord;

func_8000302C(dlist, coord, sp48, 0xFBCB);
func_8000302C(dlist, sp48, sp44, 0xFFCB);
func_8000302C(dlist, sp44, sp40, 0x2ABF);
func_8000302C(dlist, sp40, sp3C, 0xFFCB);
HAL_Printf(coord, 0x14, "MEM: +%XH (+%dK)", temp_s1, temp_s1 / 1024);
s32 base = 30;
s32 sp48 = ((u32) ( K0_TO_PHYS(pool->start)) >> 15) + base;
s32 sp44 = ((u32) ( K0_TO_PHYS(pool->listHeadL)) >> 15) + base;
s32 sp40 = ((u32) ( K0_TO_PHYS(pool->listHeadR) - D_80068B90) >> 15) + base;
s32 sp3C = ((u32) ( K0_TO_PHYS(pool->end) - D_80068B90) >> 15) + base;

HAL_DrawRect(dlist, base, sp48, 0xFBCB);
HAL_DrawRect(dlist, sp48, sp44, 0xFFCB);
HAL_DrawRect(dlist, sp44, sp40, 0x2ABF);
HAL_DrawRect(dlist, sp40, sp3C, 0xFFCB);
HAL_Printf(base, 0x14, "MEM: +%XH (+%dK)", temp_s1, temp_s1 / 1024);
}
else
{
u32 coord = 0x1E;
s32 sp34 = ((u32) ( K0_TO_PHYS(sp54->unk20)) >> 0xF) + coord;
s32 sp30 = ((u32) ( K0_TO_PHYS(sp54->unk28)) >> 0xF) + coord;
s32 sp2C = ((u32) ( K0_TO_PHYS(sp54->unk2C) - D_80068B90) >> 0xF) + coord;
s32 sp28 = ((u32) ( K0_TO_PHYS(sp54->unk24) - D_80068B90) >> 0xF) + coord;
func_8000302C(dlist, coord, sp34, 0xFBCB);
func_8000302C(dlist, sp34, sp2C, 0xFFCB);
func_8000302C(dlist, sp2C, sp30, 0xF94B);
func_8000302C(dlist, sp30, sp28, 0xFFCB);
HAL_Printf(coord, 0x14, "MEM: -%XH (-%dK)", -temp_s1, -temp_s1 / 1024);
s32 base = 30;
s32 sp34 = ((u32) ( K0_TO_PHYS(pool->start)) >> 15) + base;
s32 sp30 = ((u32) ( K0_TO_PHYS(pool->listHeadL)) >> 15) + base;
s32 sp2C = ((u32) ( K0_TO_PHYS(pool->listHeadR) - D_80068B90) >> 15) + base;
s32 sp28 = ((u32) ( K0_TO_PHYS(pool->end) - D_80068B90) >> 15) + base;
HAL_DrawRect(dlist, base, sp34, 0xFBCB);
HAL_DrawRect(dlist, sp34, sp2C, 0xFFCB);
HAL_DrawRect(dlist, sp2C, sp30, 0xF94B);
HAL_DrawRect(dlist, sp30, sp28, 0xFFCB);
HAL_Printf(base, 0x14, "MEM: -%XH (-%dK)", -temp_s1, -temp_s1 / 1024);
}
}

void func_8000330C(u64 * dest, u32 arg1) {
while( arg1 --> 0 ) {
/*
* Clear memory address area.
*/
void HAL_Memclear(u64* dest, u32 size) {
while( size --> 0 ) {
*(dest++) = -1;
}
}

s32 func_80003348(u64* arg0)
{
s32 func_80003348(u64* arg0) {
s32 ret = 0;

while (*(arg0++) == 0x8040000080400000)
Expand Down
19 changes: 8 additions & 11 deletions src/E1C0.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <PR/os_internal_reg.h>
#include "dp_intro.h"
#include "fragments.h"
#include "intro_loader.h"
#include "memory.h"
#include "dp_intro.h"

struct UnkInputStruct8000D738 {
Expand Down Expand Up @@ -40,17 +40,14 @@ void func_81206D9C(void);
void func_81206E64(void);
void func_81206F38(void);

// from 3A80.c
extern uintptr_t func_80002E80(uintptr_t addr);

void func_80005370(struct UnkStruct800AA660 *);
void func_80004454(u32, void *, void *);
char func_8000B318(char);
s32 func_800044F4(void *, void *, s32, s32);
s32 func_8000484C(s32, s32);

void func_8000D5C0(void* unused) {
void (*func)(void *) = func_80002E80(&func_81206F38);
void (*func)(void *) = convert_addr_to_virt_addr(&func_81206F38);

__osSetFpcCsr(0x01000C01);
func_80004CC0(D_800AA664, 0, 1);
Expand All @@ -66,8 +63,8 @@ void func_8000D5C0(void* unused) {
}

void func_8000D678(void *unused) {
void (*func1)(void *func) = func_80002E80(&func_81206D9C);
void (*func2)(void *func) = func_80002E80(&func_81206E64);
void (*func1)(void *func) = convert_addr_to_virt_addr(&func_81206D9C);
void (*func2)(void *func) = convert_addr_to_virt_addr(&func_81206E64);

__osSetFpcCsr(0x01000C01);
func_80004CC0(D_800AA660, 0, 1);
Expand All @@ -87,9 +84,9 @@ void func_8000D678(void *unused) {
void func_8000D738(struct UnkInputStruct8000D738* arg0) {
s32 temp_v0;

func_80002784(0x4742454D);
D_800AA660 = (void*)func_800025C4(0x2210, 0);
D_800AA664 = (void*)func_800025C4(0x21E0, 0);
main_pool_push_state('GBEM');
D_800AA660 = (void*)main_pool_alloc_node_no_func(0x2210, 0);
D_800AA664 = (void*)main_pool_alloc_node_no_func(0x21E0, 0);
func_80004454(((u32) ((u32) &fragment1_TEXT_START & 0x0FF00000) >> 0x14) - 0x10, &fragment1_ROM_START, &fragment1_ROM_END);
temp_v0 = func_800044F4(&D_3BA190, &D_3CB130, 1, 1);
D_800AA660->unk21FC = func_8000484C(temp_v0, 0);
Expand Down Expand Up @@ -118,5 +115,5 @@ void func_8000D8DC(struct UnkInputStruct8000D738* arg0) {
func_80005370(D_800AA664);
osDestroyThread(&D_800AA660->thread);
osDestroyThread(&D_800AA664->thread);
func_80002838(0x4742454D);
main_pool_pop_state('GBEM');
}
File renamed without changes.
19 changes: 8 additions & 11 deletions src/crash_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ u16 gCrashScreenUnlockInputs[] = {
};

void crash_screen_sleep(s32 ms) {
u64 cycles = (ms * 1000LL) * 3000ULL / 64ULL;
u64 cycles = OS_USEC_TO_CYCLES(ms * 1000LL); // why not just do OS_NSEC_TO_CYCLES and not multiply by 1000LL?

osSetTime(0);
while (osGetTime() < cycles) {
}
Expand Down Expand Up @@ -222,22 +223,18 @@ void crash_screen_print_fpr(s32 x, s32 y, s32 regNum, void *addr) {
}
}

void crash_screen_print_fpcsr(u32 value) {
void crash_screen_print_fpcsr(u32 fpcsr) {
s32 i;
u32 flag = 0x20000;
u32 bit = 1 << 17;

crash_screen_printf(30, 155, "FPCSR:%08XH", value);
crash_screen_printf(30, 155, "FPCSR:%08XH", fpcsr);

for (i = 0; i < 6;) {
if (value & flag) {
for (i = 0; i < 6; i++) {
if (fpcsr & bit) {
crash_screen_printf(132, 155, "(%s)", gFPCSRFaultCauses[i]);
break;

do {} while (0);
}

i++;
flag >>= 1;
bit >>= 1;
}
}

Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions src/hal_libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ size_t HAL_Strcmp(char* dest, char* src) {
* this value for every byte across a given specified size. Return the original
* pointer used.
*/
char* HAL_Memset(char* dest, s32 c, s32 nsize) {
char* HAL_Memset(char* dest, s32 c, u32 nsize) {
char* newDest = dest;

// While the size is not 0, keep decrementing. Oddly, HAL seems to have
// xor'd the result instead of checking the logical result.
while((nsize-- == 0) ^ 1) {
// While the size is not 0, keep decrementing.
while( nsize --> 0 ) {
*newDest++ = c;
}
return dest;
Expand Down
2 changes: 1 addition & 1 deletion include/hal_libc.h → src/hal_libc.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
char* HAL_Strcpy(char* dest, char* src);
char* HAL_Strcpy2(char *dest, char* src);
size_t HAL_Strcmp(char* dest, char* src);
char* HAL_Memset(char* dest, s32 c, s32 nsize);
char* HAL_Memset(char* dest, s32 c, u32 nsize);

#endif // _HAL_LIBC_
Loading

0 comments on commit a4420cd

Please sign in to comment.