Match most of crash.c (#68)

* Match start_crash_thread

* Match stop_active_app_threads_2

* Nearly match crash_thread_entry
This commit is contained in:
Ethan Lafrenais 2021-05-10 08:02:30 -04:00 committed by GitHub
parent a6c575f8f9
commit 9eeb8c9974
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 178 additions and 26 deletions

View File

@ -1,9 +1,139 @@
#include <PR/os_internal.h>
#include "common.h"
#include "crash.h"
#include "exception.h"
#include "video.h"
#pragma GLOBAL_ASM("asm/nonmatchings/crash/crash_thread_func.s")
// Length of gCrashMesgQueueBuffer
#define CRASH_MESG_QUEUE_BUFFER_LENGTH 1
#pragma GLOBAL_ASM("asm/nonmatchings/crash/crash_func.s")
typedef struct _UnkCrashStruct {
/*0x0*/ DLLInst* loadedDllList;
/*0x4*/ s32 loadedDllCount;
/*0x8*/ u8 unk0x8;
} UnkCrashStruct;
#pragma GLOBAL_ASM("asm/nonmatchings/crash/func_80037610.s")
extern UnkCrashStruct *D_80091770;
extern OSThread *D_80091774[2];
// Note: Unsure of actual stack size
extern u8 gCrashThreadStack[OS_MIN_STACKSIZE];
extern OSThread gCrashThread;
extern int D_800B3748;
extern OSMesg gCrashMesgQueueBuffer[1];
extern OSMesgQueue gCrashMesgQueue;
extern s16 D_800B3770;
OSSched *get_ossched(void);
void func_8003B6E0(OSSched *scheduler, int*, OSMesgQueue*, int);
void crash_thread_entry(void *arg);
void stop_active_app_threads_2();
void func_80037678();
#if 0
#pragma GLOBAL_ASM("asm/nonmatchings/crash/start_crash_thread.s")
#else
void start_crash_thread(OSSched* scheduler) {
s32 videoMode = 0xe;
if (osResetType == 1 && D_80091770->unk0x8 == 1) {
videoMode = 1;
}
func_8005D410(videoMode, scheduler, TRUE);
osCreateThread(
/*t*/ &gCrashThread,
/*id*/ CRASH_THREAD_ID,
/*entry*/ &crash_thread_entry,
/*arg*/ NULL,
/*sp*/ &gCrashThreadStack[OS_MIN_STACKSIZE],
/*pri*/ 0x80
);
osStartThread(&gCrashThread);
}
#endif
#if 1
#pragma GLOBAL_ASM("asm/nonmatchings/crash/crash_thread_entry.s")
#else
// Functionally equivalent, mainly regalloc
void crash_thread_entry(void *_) {
s16 *queueMesg;
OSSched *scheduler;
OSThread *stack0x20[2];
scheduler = get_ossched();
queueMesg = NULL;
stack0x20[0] = D_80091774[0];
stack0x20[1] = D_80091774[1];
osCreateMesgQueue(
&gCrashMesgQueue,
&gCrashMesgQueueBuffer[0],
CRASH_MESG_QUEUE_BUFFER_LENGTH
);
func_8003B6E0(scheduler, &D_800B3748, &gCrashMesgQueue, 3);
if (osResetType == 1 && D_80091770->unk0x8 == 1) {
D_800B3770 = 5;
osSendMesg(&gCrashMesgQueue, &D_800B3770, OS_MESG_NOBLOCK);
}
D_80091770->unk0x8 = 0;
osRecvMesg(&gCrashMesgQueue, (OSMesg)&queueMesg, OS_MESG_BLOCK);
if (*queueMesg == 4) {
stop_active_app_threads_2();
func_80037678();
// Halt
while (TRUE) { }
}
osViBlack(FALSE);
osViSwapBuffer(gFramebufferCurrent);
stop_active_app_threads();
check_video_mode_crash_and_clear_framebuffer();
some_crash_setter(D_80091770->loadedDllList, D_80091770->loadedDllCount);
some_crash_print(&stack0x20[0], 2, 0);
// Halt
while (TRUE) { }
}
#endif
#if 0
#pragma GLOBAL_ASM("asm/nonmatchings/crash/stop_active_app_threads_2.s")
#else
/**
* Stops all active application threads (those with priorities between 1 and OS_PRIORITY_APPMAX).
*
* Identical to stop_active_app_threads.
*/
void stop_active_app_threads_2() {
OSThread *thread = __osGetActiveQueue();
while (thread->priority != -1) {
if (thread->priority > OS_PRIORITY_IDLE &&
thread->priority <= OS_PRIORITY_APPMAX) {
osStopThread(thread);
}
thread = thread->tlnext;
}
}
#endif
#pragma GLOBAL_ASM("asm/nonmatchings/crash/func_80037678.s")

10
src/crash.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef _CRASH_H_
#define _CRASH_H_
#include "ultra64.h"
#define CRASH_THREAD_ID 0x64
void start_crash_thread(OSSched* scheduler);
#endif

View File

@ -5,7 +5,6 @@
void clear_framebuffer_current();
void pi_manager_entry(void *arg);
void stop_active_app_threads();
void crash_controller_getter();
void check_video_mode_crash_and_clear_framebuffer();
void some_crash_print(OSThread**, int, int);
@ -101,9 +100,6 @@ void pi_manager_entry(void *arg) {
#if 0
#pragma GLOBAL_ASM("asm/nonmatchings/exception/stop_active_app_threads.s")
#else
/**
* Stops all active application threads (those with priorities between 1 and OS_PRIORITY_APPMAX).
*/
void stop_active_app_threads() {
OSThread *thread;
@ -116,7 +112,7 @@ void stop_active_app_threads() {
}
thread = thread->tlnext;
};
}
}
#endif
@ -187,11 +183,6 @@ void _crash_copy_control_inputs() {
#if 0
#pragma GLOBAL_ASM("asm/nonmatchings/exception/check_video_mode_crash_and_clear_framebuffer.s")
#else
/**
* - Sets D_800937F0 to 0
* - Sets gSomeCrashVideoFlag if video mode is between 4-6
* - Clears the current framebuffer 100 times
*/
void check_video_mode_crash_and_clear_framebuffer() {
int i;

View File

@ -42,4 +42,18 @@ extern char *gCFileLabels[C_FILE_LABELS_LENGTH];
extern u8 gCFileLabelFlag;
extern s32 gSomeCFileInts[C_FILE_LABELS_LENGTH];
/**
* Stops all active application threads (those with priorities between 1 and OS_PRIORITY_APPMAX).
*/
void stop_active_app_threads();
void some_crash_print(OSThread**, int, int);
/**
* - Sets D_800937F0 to 0
* - Sets gSomeCrashVideoFlag if video mode is between 4-6
* - Clears the current framebuffer 100 times
*/
void check_video_mode_crash_and_clear_framebuffer();
#endif

View File

@ -1,5 +1,6 @@
#include "common.h"
#include <PR/sched.h>
#include "crash.h"
#include "input.h"
void func_8001440C(s32 arg0);
@ -67,7 +68,7 @@ void game_init(void)
D_800AE680 = D_800AE678[D_800B09C1];
gLastInsertedControllerIndex = init_controller_data();
start_controller_thread(&osscheduler_);
crash_thread_func(&osscheduler_);
start_crash_thread(&osscheduler_);
init_textures();
init_maps();
func_8001CD00();

View File

@ -168,6 +168,13 @@ extern s32 **D_800BCE18;
extern u8 D_800BCE20; // index of D_800BCE22?
extern u8 *D_800BCE22;
void func_8005D410(s32 videoMode, OSSched* scheduler, s32 someBool);
/**
* Returns gVideoMode.
*/
s32 get_video_mode();
/**
* Returns a video resolution encoded as 0xVVVV_HHHH.
*
@ -175,9 +182,4 @@ extern u8 *D_800BCE22;
*/
u32 get_some_resolution_encoded();
/**
* Returns gVideoMode.
*/
s32 get_video_mode();
#endif

View File

@ -187,7 +187,7 @@ add_object_to_array = 0x80030ef0; // type:func
TActor_getter = 0x800311e4; // type:func
objprint_func = 0x80034de0; // type:func
possible_romcopy = 0x8003734c; // type:func
crash_thread_func = 0x80037420; // type:func
start_crash_thread = 0x80037420; // type:func
create_3_megs_quues = 0x80037f1c; // type:func
three_more_mallocs = 0x8003a3b0; // type:func
osCreateScheduler = 0x8003b5b0; // type:func
@ -400,7 +400,7 @@ al_dame_sub = 0x80011ec8; // type:func
mainproc = 0x80013170; // type:func
func_initing_rumblepak = 0x80014558; // type:func
dbg_heap_print = 0x80017a24; // type:func
crash_func = 0x800374b0; // type:func
crash_thread_entry = 0x800374b0; // type:func
__scMain = 0x8003b820; // type:func
modify_vi_mode = 0x8005e080; // type:func
viMgrMain = 0x8005e380; // type:func
@ -620,8 +620,8 @@ ret1_800112d8 = 0x800112d8; // type:func
gContSnapshots = 0x800a7db8; // type:data size:0x4
get_masked_buttons_from_buffer = 0x80010c98; // type:func
gControllerThread = 0x800a7fd0; // type:data size:0x1b0
crash_thread = 0x800b3518; // type:data size:0x1b0
crash_thread_stack = 0x800b3510; // type:data size:0x4
gCrashThread = 0x800b3518; // type:data size:0x1b0
crash_thread_stack_start = 0x800b3510; // type:data size:0x4
gPiManagerThreadStack = 0x800beb10; // type:data size:0x1000
gPiManagerThread = 0x800bfb10; // type:data size:0x1b0
gPiManagerArray = 0x800bfd40; // type:data size:0x18
@ -642,7 +642,7 @@ gButtonReleases = 0x800a7fa8; // type:data size:0x8
get_button_presses = 0x80010d9c; // type:func
gNoControllers = 0x8008c8a0; // type:data size:0x4
status_reg_func_byte = 0x8008ca80; // type:data size:0x1
crash_mesgq = 0x800b3758; // type:data size:0x18
gCrashMesgQueue = 0x800b3758; // type:data size:0x18
DLLSIMPORTTAB = 0xb3b064dc; // type:data size:0x818
gLoadedDLLList = 0x800A7D10; // type:data size:0x4
gLoadedDLLCount = 0x800A7D14; // type:data size:0x4
@ -1145,4 +1145,7 @@ get_joystick_y_from_buffer = 0x800110CC; // type:func
swap_controller_port_0_and_1 = 0x80010C24; // type:func
handle_joystick_deadzone = 0x800111BC; // type:func
get_joystick_x = 0x80010F78; // type:func
get_joystick_y = 0x8001107C; // type:func
get_joystick_y = 0x8001107C; // type:func
gCrashMesgQueueBuffer = 0x800B3754; // type:data size:0x4
stop_active_app_threads_2 = 0x80037610; // type:func

View File

@ -26,4 +26,5 @@ D_8008C8A4 = 0x8008C8A4;
gControllerThreadStack = 0x800a8180;
gPiManagerThreadStack = 0x800beb10;
gLastJoyY = 0x800a7fb8;
gLastJoyX = 0x800a7fb4;
gLastJoyX = 0x800a7fb4;
gCrashThreadStack = 0x800B34C8;