Skip to content

Commit

Permalink
Merge pull request pret#80 from RevoSucks/decompile_3640
Browse files Browse the repository at this point in the history
decompile 3640.c
  • Loading branch information
RevoSucks authored Sep 1, 2023
2 parents 6468d28 + 98baed6 commit cfb34ef
Show file tree
Hide file tree
Showing 10 changed files with 621 additions and 363 deletions.
3 changes: 0 additions & 3 deletions include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ extern s32 func_8005A990(OSPiHandle *);
// bcopy.s
extern void _bcopy(void *, void *, u32);

// 3640.s
extern void* func_80002AF8(s32, void*);

// 3A80.c
extern uintptr_t convert_addr_to_virt_addr(uintptr_t addr);
extern void func_80002F58(void);
Expand Down
10 changes: 10 additions & 0 deletions include/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,14 @@

#include "ultra64.h"

#define POOL_END_4MB 0x80400000
#define POOL_END_6MB 0x80600000

/*
* Dynamic heap with an indetermate amount of space. This pool can either end at 4MB or
* 6MB depending on osMemSize, which is really strange as it should be using the whole
* 8MB of the expansion pak.
*/
extern u8 gPool[1];

#endif
18 changes: 15 additions & 3 deletions splat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ segments:
- [0x1F70, bin, noppad_1F70] # Extra nop align like earlier. Weird
- [0x1F80, c, dp_intro] # dp intro code
- [0x28E0, c, memmap]
- [0x2EC0, c, memory]
- [0x3640, asm] #
- [0x2EC0, c, memory_main] # handles the main global pool
- [0x3640, c, memory] # memory_pool
- [0x3A80, c]
- [0x3FB0, asm] # PRES-JPEG decoder
- [0x5580, asm] # there's a split here according to PAL
Expand Down Expand Up @@ -325,6 +325,8 @@ segments:
- [0x68020, bin] # rest of rom part 1

# .data is somewhere in here
- [0x69790, .data, 3A80]
- [0x697A0, bin, rom_data_697A0]
- [0x6A1B0, .data, crash_screen]
- [0x6A3B0, .data, profiler]
- [0x6A3D0, .data, gb_tower]
Expand Down Expand Up @@ -416,7 +418,7 @@ segments:
- {vram: 0x8007F190, type: .bss, name: main}
- {vram: 0x80081900, type: .bss, name: rsp}
- {vram: 0x80083CA0, type: .bss, name: unk_bss}
- {vram: 0x800A6070, type: .bss, name: memory}
- {vram: 0x800A6070, type: .bss, name: memory_main}
- {vram: 0x800A60B0, type: .bss, name: unk_bss_4}
- {vram: 0x800A7320, type: .bss, name: controller}
- {vram: 0x800A7420, type: .bss, name: unk_bss_3}
Expand All @@ -429,6 +431,16 @@ segments:
- {vram: 0x80103950, type: .bss, name: libultra/io/vimgr}
- {vram: 0x80104b70, type: .bss, name: libultra/io/conteepread}
- [0x7F980]

- name: heap
type: code
bss_size: 0x0 # This heap extends to the end of RAM.
start: 0x7F980
vram: 0x80104BB0
subsegments:
# .bss
- {vram: 0x80104BB0, type: .bss, name: heap}
- [0x7F980]

# Probably the GB Tower Emulator. This fragment is built very strangely.
- name: fragment1
Expand Down
45 changes: 26 additions & 19 deletions src/3A80.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
#include "memmap.h"
#include "memory.h"

extern s32 D_80068B90;
extern u8 D_80104BB0[];
extern s32 D_800A60B0;
/**
* Based on the context of this variable's usage, it appears to be intended to
* be non-0 whenever the expansion RAM is in, however it is never initialized
* properly. It seems to serve as whereever the new start of memory will be
* located whenever plugged in, but its only functional with the debug profiler.
* It will, however, allocate a much bigger pool if set to non-0.
*/
s32 gExpansionRAMStart = FALSE;

extern struct MainPool **gMainPool; // gMainPool

void func_80003860(void);
s32 func_80002A40(s32, s32);
void func_80002BD0(s32, void *); // type unknown
s32 func_80007A58(void);

/*
/**
* Convert any valid address to its virtual (KSEG0) counterpart.
*/
uintptr_t convert_addr_to_virt_addr(uintptr_t addr) {
Expand Down Expand Up @@ -45,22 +50,24 @@ void HAL_Memcpy(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)) {
main_pool_init(&D_80104BB0, 0x80600000);
// Effectively, it checks if the expansion RAM is in. But why not just use all
// of it, or at least do the correct check of osMemSize == 0x800000?
if ((gExpansionRAMStart != 0) && ((u32) osMemSize > 0x600000U)) {
main_pool_init(&gPool, POOL_END_6MB);
} else {
main_pool_init(&D_80104BB0, 0x80400000);
D_80068B90 = 0;
main_pool_init(&gPool, POOL_END_4MB);
gExpansionRAMStart = 0;
}
func_80003860();
D_800A60B0 = func_80002A40(0x10000, 0);
gMainPool = mem_pool_try_init(0x10000, 0);
}

void *func_80002FDC(s32 arg0) {
return func_80002AF8(D_800A60B0, arg0);
void *func_80002FDC(s32 size) {
return mem_pool_alloc(gMainPool, size);
}

void func_80003004(void *arg0) {
func_80002BD0(D_800A60B0, arg0);
mem_pool_free(gMainPool, arg0);
}

void HAL_DrawRect(Gfx** dlist, s32 ulx, s32 lrx, u16 color) {
Expand All @@ -83,15 +90,15 @@ void HAL_DrawRect(Gfx** dlist, s32 ulx, s32 lrx, u16 color) {

void func_8000310C(Gfx** dlist) {
struct MainPool *pool = main_pool_get_pool();
s32 temp_s1 = main_pool_get_available() - D_80068B90;
s32 temp_s1 = main_pool_get_available() - gExpansionRAMStart;

if (temp_s1 >= 0)
{
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;
s32 sp40 = ((u32) ( K0_TO_PHYS(pool->listHeadR) - gExpansionRAMStart) >> 15) + base;
s32 sp3C = ((u32) ( K0_TO_PHYS(pool->end) - gExpansionRAMStart) >> 15) + base;

HAL_DrawRect(dlist, base, sp48, 0xFBCB);
HAL_DrawRect(dlist, sp48, sp44, 0xFFCB);
Expand All @@ -104,8 +111,8 @@ void func_8000310C(Gfx** dlist) {
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;
s32 sp2C = ((u32) ( K0_TO_PHYS(pool->listHeadR) - gExpansionRAMStart) >> 15) + base;
s32 sp28 = ((u32) ( K0_TO_PHYS(pool->end) - gExpansionRAMStart) >> 15) + base;
HAL_DrawRect(dlist, base, sp34, 0xFBCB);
HAL_DrawRect(dlist, sp34, sp2C, 0xFFCB);
HAL_DrawRect(dlist, sp2C, sp30, 0xF94B);
Expand Down
3 changes: 3 additions & 0 deletions src/heap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <ultra64.h>

u8 gPool[1]; // unk determinate size.
9 changes: 5 additions & 4 deletions src/libultra/io/conteepread.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

void __osPackEepReadData(u8 address);
OSPifRam __osEepPifRam;
s32 __osEepromRead16K;

#define CONT_RANGE_ERROR -1

Expand Down Expand Up @@ -37,12 +36,14 @@ s32 osEepromRead(OSMesgQueue *mq, u8 address, u8 *buffer)
// @bug: Should be > EEP16K_MAXBLOCKS
if (address >= EEP16K_MAXBLOCKS) {
ret = -1;
}
} else {
// __osEepromRead16K support seems to have been removed from this particular
// revision.
//__osEepromRead16K = -1;
}
break;
default:
if (1);
ret = CONT_NO_RESPONSE_ERROR;
break;
}
}

Expand Down
Loading

0 comments on commit cfb34ef

Please sign in to comment.