decompile reset

This commit is contained in:
RevoSucks 2023-09-03 22:07:36 -04:00
parent dbdba6261a
commit 1ab38dff75
9 changed files with 180 additions and 14 deletions

View File

@ -20,9 +20,6 @@ extern void func_800052B4(void);
extern void func_800053B4(void *, s32); // types unknown
extern void func_80005328(void *); // types unknown
// 60A0.s
extern void func_800057C0(void);
// 6BC0.s
extern u32 func_80006314(s32, s32, s32, s32, s32); // types unknown

View File

@ -5,9 +5,11 @@
// thread pris
#define THREAD_PRI_IDLE_INIT 100
#define THREAD_PRI_RESET 30
// thread IDs
#define THREAD_ID_IDLE 1
#define THREAD_ID_RESET 21
#define POOL_END_4MB 0x80400000
#define POOL_END_6MB 0x80600000

View File

@ -41,7 +41,7 @@ segments:
- [0x3A80, c, util]
- [0x3FB0, asm] # PRES-JPEG decoder
- [0x5580, asm] # there's a split here according to PAL
- [0x60A0, asm] #
- [0x60A0, c, reset] # soft reset effect
- [0x6430, c, controller] # controller code
- [0x6A40, c]
- [0x6BC0, asm] #

View File

@ -116,8 +116,8 @@ void func_8000D3A8(void* unused) {
D_800A8478 = 0;
osCreateMesgQueue(&D_800A83A8[0].queue, &D_800A83A8[0].mesg, 1);
osCreateMesgQueue(&D_800A83A8[1].queue, &D_800A83A8[1].mesg, 1);
osSendMesg(&D_800A83A8[0].queue, (void*)0x444F4E45, 0);
osSendMesg(&D_800A83A8[1].queue, (void*)0x444F4E45, 0);
osSendMesg(&D_800A83A8[0].queue, (void*)'DONE', 0);
osSendMesg(&D_800A83A8[1].queue, (void*)'DONE', 0);
func_800373D8();
func_8004AF24(0);
func_8004AE90(3, 4);

View File

@ -247,7 +247,7 @@ void func_8000183C(UNUSED void* arg) {
profiler_log_thread5_time(UNK_EVENT_2);
func_8000152C(sp4C);
func_800015A8();
osSendMesg(&D_800846A4, (void*)0x444F4E45, 0);
osSendMesg(&D_800846A4, (void*)'DONE', 0);
}
}
@ -271,12 +271,15 @@ void func_800019C8(void) {
func_80003B30(&D_80084760, 0xB0000B70, 0xB0000C70, 0);
}
void func_80001AD4(u16 arg0) {
s32 i = 0x280;
u16* arr = (void*)(uintptr_t)D_80083CA0.unk9E0->unk8;
/**
* Write a specific color to a line on the framebuffer for a 640x480 resolution.
*/
void func_80001AD4(u16 color) {
s32 width = 640;
u16* buf = (void*)(uintptr_t)D_80083CA0.unk9E0->unk8;
while (i-- > 0) {
*(arr)++ = arg0;
while (width-- > 0) {
*(buf)++ = color;
}
osWritebackDCache((void*)(uintptr_t)D_80083CA0.unk9E0->unk8, 0x500);

View File

@ -3,6 +3,7 @@
#include "dp_intro.h"
#include "crash_screen.h"
#include "rsp.h"
#include "reset.h"
extern void func_8002B330(); // thread 6 function
@ -28,7 +29,7 @@ void Idle_ThreadEntry(UNUSED void* unused) {
func_800052B4();
func_8000D564();
func_800019C8();
func_800057C0();
SoftReset_CreateThread();
osCreateThread(&pThreads, 6, &func_8002B330, 0, &D_800818E0, 20);
osStartThread(&pThreads);
osSetThreadPri(NULL, 0);

145
src/reset.c Normal file
View File

@ -0,0 +1,145 @@
#include <ultra64.h>
#include "reset.h"
// this file handles the soft reset effect.
struct UnkStruct800A62E0 {
char filler0[0xA38];
s16 unkA38;
};
struct UnkStruct800A6D20 {
OSThread thread;
char filler1B0[0x5E0-0x1B0];
u32 unk5E0;
};
extern struct UnkStruct800A62E0 D_800A62E0;
extern struct UnkStruct800A6D20 D_800A6D20;
struct UnkStruct4 {
s32 unk0;
u16 unk4;
u16 unk6;
s32 unk8;
};
extern u32 gSoftResetLineNum;
extern s32 gSoftResetRed;
extern s32 gSoftResetGreen;
extern s32 gSoftResetBlue;
/**
* Perform the horizontal framebuffer wipe across 15 different lines for a
* screen with 320x240 resolution.
*/
void SoftReset_ClearLines320(u16 *buf) {
int i, j;
if (gSoftResetLineNum <= 15) {
// where is the framebuffer starting, based on the line number of the effect?
u16* ptr = buf + gSoftResetLineNum * 320;
// iterate over and clear the 15 lines of the next frame during the effect.
for (j = 0; j < 15; j++) {
for(i = 0; i < 320; i++) {
*ptr++ = 1;
}
ptr += (320*15); // move the framebuffer pointer to the next line to clear
// (down 15 lines).
}
osWritebackDCacheAll();
}
}
/**
* Perform the horizontal framebuffer wipe across 15 different lines for a
* screen with 640x480 resolution.
*/
void SoftReset_ClearLines640(u16 *buf) {
int i, j;
if (gSoftResetLineNum <= 15) {
// where is the framebuffer starting, based on the line number of the effect?
u16* ptr = buf + gSoftResetLineNum * (640*2);
// iterate over and clear the 15 lines of the next frame during the effect.
for (j = 0; j < 15; j++) {
for(i = 0; i < (640*2); i++) {
*ptr++ = 1;
}
ptr += ((640*2)*15); // move the framebuffer pointer to the next line to clear
// (down 15 lines).
}
osWritebackDCacheAll();
}
}
// not enough information to name this function. seems to get some unknown
// color from dp_intro.c and then only writes a single line to the framebuffer???
void func_8000559C(void) {
if (gSoftResetLineNum <= 15) {
if (gSoftResetLineNum == 0) {
u16 color = func_80001B2C();
// decoding a 5551 value back to the raw R/G/B values.
gSoftResetRed = (color >> 11) & 31; // masked red?
gSoftResetGreen = (color >> 6) & 31; // masked green?
gSoftResetBlue = (color >> 1) & 31; // masked blue?
}
// this function is supposed to only take 1 argument. huh?
// this function packs 3 values into a RGBA5551 format.
func_80001AD4(((((u32) (gSoftResetRed * (15 - gSoftResetLineNum)) >> 4) << 11) |
(((u32) (gSoftResetGreen * (15 - gSoftResetLineNum)) >> 4) << 6) |
(((u32) (gSoftResetBlue * (15 - gSoftResetLineNum)) >> 4) << 1) | 1) & 0xFFFF, gSoftResetLineNum);
}
}
/**
* Thread function for the soft reset function. This will run and stop until
* it gets a soft reset, and then proceed to handle the soft reset framebuffer
* effect.
*/
void SoftReset_Thread(void* unused) {
__osSetFpcCsr(0x01000C01);
func_80005328(&D_800A6D20.thread);
// thread loop
while(1) {
func_80004CF4(&D_800A6D20.thread); // hangs here until gets a soft reset.
if (D_800A62E0.unkA38 == 0) {
continue;
}
if ((u32) D_800A6D20.unk5E0 < 0x10U) {
struct UnkStruct4* temp_v0 = func_80001C58();
if (temp_v0 != NULL) {
if (temp_v0->unk4 == 320) {
SoftReset_ClearLines320(temp_v0->unk8);
} else {
SoftReset_ClearLines640(temp_v0->unk8);
}
} else if (func_80001B40() != 0) {
func_8000559C();
} else {
SoftReset_ClearLines320(osViGetCurrentFramebuffer());
}
D_800A6D20.unk5E0++;
continue;
}
if (D_800A6D20.unk5E0 != 0x10) {
continue;
}
osViBlack(1U);
osViSetYScale(1.0f);
D_800A6D20.unk5E0++;
}
}
/**
* Create the soft reset effect thread.
*/
void SoftReset_CreateThread(void) {
func_80004CC0(&D_800A6D20.thread, 2, 1);
D_800A6D20.unk5E0 = 0;
osCreateThread(&D_800A6D20.thread, THREAD_ID_RESET, SoftReset_Thread, NULL, &gSoftResetLineNum, THREAD_PRI_RESET);
osStartThread(&D_800A6D20.thread);
}

10
src/reset.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef _RESET_H_
#define _RESET_H_
void SoftReset_ClearLines320(u16 *buf);
void SoftReset_ClearLines640(u16 *buf);
void func_8000559C(void);
void SoftReset_Thread(void* unused);
void SoftReset_CreateThread(void);
#endif // _RESET_H_

View File

@ -599,4 +599,12 @@ gArctanTable = 0x8006E7F0;
gSineTable = 0x800697F0;
gCosineTable = 0x8006A7F0;
MathUtil_Random16 = 0x8000A4D4;
MathUtil_Random_ZeroOne = 0x8000A4F8;
MathUtil_Random_ZeroOne = 0x8000A4F8;
SoftReset_ClearLines320 = 0x800054A0;
SoftReset_ClearLines640 = 0x8000551C;
gSoftResetLineNum = 0x800A7300;
gSoftResetRed = 0x800A7308;
gSoftResetGreen = 0x800A730C;
gSoftResetBlue = 0x800A7310;
SoftReset_Thread = 0x80005674;
SoftReset_CreateThread = 0x800057C0;