Files
KataMario/src/game/crash_screen.c
T
+1 f3e61a31aa HackerSM64 v2.0.0
* buffers: refresh 15 and revert to base decomp

* behavior script

* color helper functions

* extended bounds

* egeo_layout

* fixed model ids

* camera conf improved

* message panel ucode small

* graph node

* level script

* mathutil updates

* mathutil updates (allow unused funcs)

* behaviors a - beta_fish

* Add librtc and fix some data declarations

* Move GRUCODE define to proper location in makefile

* Refresh 15

* extra

* Make ROM name smaller and change messages printed on build a bit

* Fix console (lol)

* Update UNF to latest master

* Make ucode load from .o's (and also fix Super3D)

* Fix crash with rumble + custom mario model

* graph node and mathutil

* removed behaviors

* Ldtob documentation

* _Putfld labeling

* area

* behavior actions

* camera

* debug updates

* bubbles

* envfx snow

* farcall helpers

* game init

* geo misc

* hud

* only check if VC on render init

* ingame menu

* revert goddard to base decomp

* insn disasm

* interaction documentation

* level geo

* level update defines

* macro special objects formatting changes

* main.h documentation

* map parser documentation & formatting

* airborne documentation

* mario actions automatic documentation

* mario actions cutscene documentation

* mario actions moving documentation and options

* mario actions object documentation and options

* mario stationary documentation

* mario submerged documentation

* mario misc documentation

* mario step: ledge grab fixes and documentation

* mario documentation

* memory.h documentation

* moving textures

* object behaviors

* object collision

* fix flamethrower bug

* object helpers

* object list processor documentation

* paintings

* platform displacement

* print / printf

* puppycam absf

* puppyprint updates and formatting changes

* rendering graph node performance optimizations

* rumble opt and doc

* hqvm back to ultrasm64

* save file documentation and unlock defines

* s2d engine

* reset various files to ultrasm64

* file select

* intro geo documentation

* screen transition documentation

* segment2.h

* shadow overhaul

* skybox refactor

* sound init: clean up define usage + documentation

* spawn object optimizations and documentation

* spawn sound cleanup

* sram to ultrasm64

* star select cleanup

* title screen cleanup

* dialogs / text

* rename stomp smoke

* stomp smoke -> small water splash

* updated README

* compilation flags

* optimized file positions + support function/data sections

* surface collision performance improvements

* surface load optimizations

* camera conf documentation

* Allow easier command for opening puppyprint debug

* Rearranged framebuffers & fixed puppyprint console printing

* Fix shadow scaling and shifting

* Fix SILHOUETTE, OBJECTS_REJ, and ucode loading, also clean up render phase system a bit.

* Fixed build with BETTER_HANGING off

* Clean up OBJECTS_REJ ifdefs

* Fix duplicate comment & graph render layers/flags bitmask

* Fixed build with BETTER_HANGING off

* Fix Fast64 importing by reverting sSegmentTable change

* Readded missing functions that caused build errors with Mario head enabled

* Fixed clang compilation issues

* Add INTER mode for geo_update_layer_transparency

* Fix build warnings

* bugfix: miscalculation in obj_turn_toward_object

* Some puppytech fixes

* Further Puppycamera fixes

* Fix BUGFIX_DIALOG_TIME_STOP

Fixes #136

* Fix sliding platform bparams

* Add LEGACY_SHADOW_IDS define for Fast64 compatibility

* Apply suggested changes

* Better find_in_bounds_yaw_wdw_bob_thi ifdef

* Fix build warnings for unused functions

* Fixed stale reference bug from obj_mark_for_deletion change

* Fixed incorrect digit for 100s #145

* Change groundpound-fix define and functionality to just disable bonking

* Fixed puppyroll #134

* Adjust height value for terrain angle to kick in

* fixed hi score flashing

* Remove menudata backup (#131)

Not considered important enough to keep

* Fix fread() build warning

* Add COURSE_NUM_TO_INDEX to save_file_get_star_flags check in bhv_unagi_init

* Fix approach_s16 return value

* Use boolean defines for oCapDoScaleVertically

* Make the door lock a part of the key door model to eliminate z-fighting, also reduce z fighting on numbered doors with AUTO_LOD enabled.

* Move flames to LAYER_TRANSPARENT_INTER

* Resolved some compiler warnings and added FALL_THROUGH define (#168)

* Address some more compiler warnings with different define toggles

* Remove unnecessary fallthrough attribute

* fixed geo_process_billboard floating point exception

* Allow water to face any direction

* Initialize focOffset so that BBH doesn't crash

* Removed superfluous RDP commands when switching microcodes which would override scissor

* Set OBJ_FLAG_DONT_CALC_COLL_DIST on bhvUkikiCage

* Fix rumble build

* Fixed UNLOCK_FPS strobing

* Update src/game/object_helpers.c

Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com>

* Update src/game/object_helpers.c

Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com>

* Fix LEGACY_SHADOW_IDS id conflict

* Use the vanilla default value for rotating fire bars if bparam2 is 0

* START_LEVEL safeguard

* Fix some drawing distance issues caused by AUTO_COLLISION_DISTANCE

* Fix rumble build

* Fixed spline poll code using the wrong values for keyframes

* Update readme with better credits

Better credits for individual contributors

* add arthur

* added falco and moose

* add fazana

* le funny typo

* added S2DEX engine to credits

* silhouette + axo + ratio

* remove specific callouts + add auto col distance

* Update data/behavior_data.c

Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com>

* Update data/behavior_data.c

Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com>

* Update data/behavior_data.c

Co-authored-by: thecozies <79979276+thecozies@users.noreply.github.com>

* Revert formatting changes to match vanilla decomp

* Re-implement Y buffer for find_ceil

* Re-implement POWER_STARS_HEAL for normal Power Stars

* Start level comment & exit course comment/collapse

* utilize reonucam technique for FAST_VERTICAL_CAMERA_MOVEMENT

* Fix "MAX_REFERENCED_WALLS" typo

* Allow stop_and_set_height_to_floor to work at any height if Mario is teleporting (#213)

* Revert stop_and_set_height_to_floor to vanilla

Fixes #208

* Fixed sAudioEnabled so that it disables audio CPU processing as well

* Fixed puppyprint debug RDP us calculations

* Renamed sAudioEnabled to gAudioEnabled

* Replaced mtxf_to_mtx_asm with an equivalent implementation that supports WORLD_SCALE

* Moved extended bounds and world scale configuration to a new config_world.h file

* Default all objects to non-rej (#227)

Fixes #221 (Default all objects to non-rej)

* Fix #221

* Fix VISUAL_DEBUG breaking/crashing when OBJECTS_REJ is disabled (#211)

* Fix VISUAL_DEBUG breaking/crashing when OBJECTS_REJ is disabled

* Change vtl decrement in visual_surface_display from 6 to 3

Fixes #207

* Make area in SL igloo wider to prevent a softlock (#233)

Fixes #210

* Fix coin formation coins being deleted if they spawn in the middle of a floor, also fix TTM slide coin position (#232)

Fixes #201

* Make UNLOCK_ALL apply to more things

* Fix wrong ifdef/ifndef in bhv_invisible_objects_under_bridge_init

* Change chain chomp load/unload distances depending on number of segments (#237)

Fixes #192

* added WATER_PLUNGE_UPWARP define

* Add reonucam patch (#239)

* added reonucam patch
Fixes #218

* Fix how shadows handle water/transparency/height (#228)

* Fix how shadows handle water/transparency/height

* Change shadow check for flying carpets from a level specific check to a oPlatformOnTrackType check

Fixes #179

* added reonucam credit

* delete unnecesary patches

* Apply suggested changes

* murdered more patches

* UNLOCK_ALL unlocks the cap boxes

* UNLOCK_ALL unlocks cap boxes (slightly more epic edition)

* revert ceil buffer

* Renamed HD_INTRO_TEXTURES define, separated intro floombas

* prevent double definition of floombas

* actually prevent floomba redefinition

* Develop/refactor  default defines (#242)

* Changed default config options

* Added build dir to includePaths for pngs

* disable NO_SLEEP by default

* Disable puppyprint by default

Sorry fazana 😔

* fix typos

* add comment about BETTER_REVERB console perf

* disable blue coin switch retry by default

* Update config_audio.h

Co-authored-by: Reonu <danileon95@gmail.com>
Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com>

* revert air step line to vanilla to fix bitfs scaling platform issue (#247)

Fixes #200

* Fix stuttering on thin slopes (#248)

* Fix stuttering on thin slopes

* Revert vec3f_find_ceil calls to vanilla

* Rename vec3f_find_ceil to find_mario_ceil

* Update src/engine/surface_collision.h

Fixes #249

* Swap static and dynamic surface checks back to vanilla order (#253)

* Swap static and dynamic surface checks back to vanilla order

* re-enable DISABLE_ALL config

Fixes #251 #252

* Fixed save and quitting while in widescreen (#257)

* Fixed save and quitting while in widescreen

* use define for the level

* all my homies hate ifdefs

* skip wall offsets < 0 (#255)

Fixes #255

* #264: Document non-stop stars' issues (#267)

* #264: Document non-stop stars' issues

* Update include/config/config_game.h

* nonstop vanilla comment

* derive margin_radius from radius after capping at 200 (#266)

Fixes #259

* Config cleanup/refactor (#269)

* Moved puppyprint define to graphics / rearranged some debug defines for ease of access

* Moved compatibility safeguards to config_safeguards.h

* spacing and comment formatting

* #272 Move GFX_POOL_SIZE to config_graphics.h

* disable EASIER_DIALOG_TRIGGER by default

* prevent redefining warnings

* small ifdef typo

* changed ifndef to undefs

Fixes #262
Fixes #272

* Improved movement config documentation related to turning around (#271)

Fixes #270

* rename CUSTOM_DEBUG, add comments (#275)

* Update README.md (#277)

* v2.0.0

Co-authored-by: CrashOveride95 <crashoveride953@gmail.com>
Co-authored-by: Arceveti <73617174+Arceveti@users.noreply.github.com>
Co-authored-by: n64 <n64>
Co-authored-by: Fazana <52551480+FazanaJ@users.noreply.github.com>
Co-authored-by: Mr-Wiseguy <mrwiseguyromhacking@gmail.com>
Co-authored-by: aglab2 <aglab3@gmail.com>
Co-authored-by: gheskett <gheskett@gmail.com>
Co-authored-by: Reonu <danileon95@gmail.com>
Co-authored-by: Axollyon <20480418+Axollyon@users.noreply.github.com>
Co-authored-by: Mr-Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com>
2021-12-30 16:57:51 +00:00

454 lines
14 KiB
C

#include <ultra64.h>
#include <PR/os_internal_error.h>
#include <stdarg.h>
#include <string.h>
#include "buffers/framebuffers.h"
#include "types.h"
#include "puppyprint.h"
#include "audio/external.h"
#include "farcall.h"
#include "game_init.h"
#include "main.h"
#include "debug.h"
#include "rumble_init.h"
#include "sm64.h"
#include "printf.h"
enum crashPages {
PAGE_CONTEXT,
#if PUPPYPRINT_DEBUG
PAGE_LOG,
#endif
PAGE_STACKTRACE,
PAGE_DISASM,
PAGE_ASSERTS,
PAGE_COUNT
};
u8 gCrashScreenCharToGlyph[128] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 41, -1, -1, -1, 43, -1, -1, 37, 38, -1, 42,
-1, 39, 44, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 36, -1, -1, -1, -1, 40, -1, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
};
// A height of seven pixels for each Character * nine rows of characters + one row unused.
u32 gCrashScreenFont[7 * 9 + 1] = {
#include "textures/crash_custom/crash_screen_font.ia1.inc.c"
};
u8 crashPage = 0;
u8 updateBuffer = TRUE;
char *gCauseDesc[18] = {
"Interrupt",
"TLB modification",
"TLB exception on load",
"TLB exception on store",
"Address error on load",
"Address error on store",
"Bus error on inst.",
"Bus error on data",
"Failed Assert: See Assert Page",
"Breakpoint exception",
"Reserved instruction",
"Coprocessor unusable",
"Arithmetic overflow",
"Trap exception",
"Virtual coherency on inst.",
"Floating point exception",
"Watchpoint exception",
"Virtual coherency on data",
};
char *gFpcsrDesc[6] = {
"Unimplemented operation", "Invalid operation", "Division by zero", "Overflow", "Underflow",
"Inexact operation",
};
extern u64 osClockRate;
extern far char *parse_map(u32 pc);
extern far void map_data_init(void);
extern far char *find_function_in_stack(u32 *sp);
struct {
OSThread thread;
u64 stack[0x800 / sizeof(u64)];
OSMesgQueue mesgQueue;
OSMesg mesg;
u16 *framebuffer;
u16 width;
u16 height;
} gCrashScreen;
void crash_screen_draw_rect(s32 x, s32 y, s32 w, s32 h) {
u16 *ptr;
s32 i, j;
ptr = gCrashScreen.framebuffer + gCrashScreen.width * y + x;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
// 0xe738 = 0b1110011100111000
*ptr = ((*ptr & 0xe738) >> 2) | 1;
ptr++;
}
ptr += gCrashScreen.width - w;
}
}
void crash_screen_draw_glyph(s32 x, s32 y, s32 glyph) {
const u32 *data;
u16 *ptr;
u32 bit;
u32 rowMask;
s32 i, j;
data = &gCrashScreenFont[glyph / 5 * 7];
ptr = gCrashScreen.framebuffer + gCrashScreen.width * y + x;
for (i = 0; i < 7; i++) {
bit = 0x80000000U >> ((glyph % 5) * 6);
rowMask = *data++;
for (j = 0; j < 6; j++) {
*ptr++ = (bit & rowMask) ? 0xffff : 1;
bit >>= 1;
}
ptr += gCrashScreen.width - 6;
}
}
static char *write_to_buf(char *buffer, const char *data, size_t size) {
return (char *) memcpy(buffer, data, size) + size;
}
void crash_screen_print(s32 x, s32 y, const char *fmt, ...) {
char *ptr;
u32 glyph;
s32 size;
char buf[0x108];
bzero(&buf, sizeof(buf));
va_list args;
va_start(args, fmt);
size = _Printf(write_to_buf, buf, fmt, args);
if (size > 0) {
ptr = buf;
while (*ptr) {
glyph = gCrashScreenCharToGlyph[*ptr & 0x7f];
if (glyph != 0xff) {
crash_screen_draw_glyph(x, y, glyph);
}
ptr++;
x += 6;
}
}
va_end(args);
}
void crash_screen_sleep(s32 ms) {
u64 cycles = ms * 1000LL * osClockRate / 1000000ULL;
osSetTime(0);
while (osGetTime() < cycles) { }
}
void crash_screen_print_float_reg(s32 x, s32 y, s32 regNum, void *addr) {
u32 bits = *(u32 *) addr;
s32 exponent = ((bits & 0x7f800000U) >> 0x17) - 0x7F;
if ((exponent >= -0x7E && exponent <= 0x7F) || bits == 0x0) {
crash_screen_print(x, y, "F%02d:%.3e", regNum, *(f32 *) addr);
} else {
crash_screen_print(x, y, "F%02d:%08XD", regNum, *(u32 *) addr);
}
}
void crash_screen_print_fpcsr(u32 fpcsr) {
s32 i;
u32 bit = BIT(17);
crash_screen_print(30, 155, "FPCSR:%08XH", fpcsr);
for (i = 0; i < 6; i++) {
if (fpcsr & bit) {
crash_screen_print(132, 155, "(%s)", gFpcsrDesc[i]);
return;
}
bit >>= 1;
}
}
void draw_crash_context(OSThread *thread, s32 cause) {
__OSThreadContext *tc = &thread->context;
crash_screen_draw_rect(15, 20, 270, 210);
crash_screen_print(30, 20, "THREAD:%d (%s)", thread->id, gCauseDesc[cause]);
crash_screen_print(30, 30, "PC:%08XH SR:%08XH VA:%08XH", tc->pc, tc->sr, tc->badvaddr);
osWritebackDCacheAll();
crash_screen_draw_rect(15, 45, 270, 185);
if ((u32)parse_map != MAP_PARSER_ADDRESS) {
char *fname = parse_map(tc->pc);
crash_screen_print(30, 40, "CRASH AT: %s", fname == NULL ? "UNKNOWN" : fname);
}
crash_screen_print(30, 50, "AT:%08XH V0:%08XH V1:%08XH", (u32) tc->at, (u32) tc->v0, (u32) tc->v1);
crash_screen_print(30, 60, "A0:%08XH A1:%08XH A2:%08XH", (u32) tc->a0, (u32) tc->a1, (u32) tc->a2);
crash_screen_print(30, 70, "A3:%08XH T0:%08XH T1:%08XH", (u32) tc->a3, (u32) tc->t0, (u32) tc->t1);
crash_screen_print(30, 80, "T2:%08XH T3:%08XH T4:%08XH", (u32) tc->t2, (u32) tc->t3, (u32) tc->t4);
crash_screen_print(30, 90, "T5:%08XH T6:%08XH T7:%08XH", (u32) tc->t5, (u32) tc->t6, (u32) tc->t7);
crash_screen_print(30, 100, "S0:%08XH S1:%08XH S2:%08XH", (u32) tc->s0, (u32) tc->s1, (u32) tc->s2);
crash_screen_print(30, 110, "S3:%08XH S4:%08XH S5:%08XH", (u32) tc->s3, (u32) tc->s4, (u32) tc->s5);
crash_screen_print(30, 120, "S6:%08XH S7:%08XH T8:%08XH", (u32) tc->s6, (u32) tc->s7, (u32) tc->t8);
crash_screen_print(30, 130, "T9:%08XH GP:%08XH SP:%08XH", (u32) tc->t9, (u32) tc->gp, (u32) tc->sp);
crash_screen_print(30, 140, "S8:%08XH RA:%08XH", (u32) tc->s8, (u32) tc->ra);
crash_screen_print_fpcsr(tc->fpcsr);
osWritebackDCacheAll();
crash_screen_print_float_reg( 30, 170, 0, &tc->fp0.f.f_even);
crash_screen_print_float_reg(120, 170, 2, &tc->fp2.f.f_even);
crash_screen_print_float_reg(210, 170, 4, &tc->fp4.f.f_even);
crash_screen_print_float_reg( 30, 180, 6, &tc->fp6.f.f_even);
crash_screen_print_float_reg(120, 180, 8, &tc->fp8.f.f_even);
crash_screen_print_float_reg(210, 180, 10, &tc->fp10.f.f_even);
crash_screen_print_float_reg( 30, 190, 12, &tc->fp12.f.f_even);
crash_screen_print_float_reg(120, 190, 14, &tc->fp14.f.f_even);
crash_screen_print_float_reg(210, 190, 16, &tc->fp16.f.f_even);
crash_screen_print_float_reg( 30, 200, 18, &tc->fp18.f.f_even);
crash_screen_print_float_reg(120, 200, 20, &tc->fp20.f.f_even);
crash_screen_print_float_reg(210, 200, 22, &tc->fp22.f.f_even);
crash_screen_print_float_reg( 30, 210, 24, &tc->fp24.f.f_even);
crash_screen_print_float_reg(120, 210, 26, &tc->fp26.f.f_even);
crash_screen_print_float_reg(210, 210, 28, &tc->fp28.f.f_even);
crash_screen_print_float_reg( 30, 220, 30, &tc->fp30.f.f_even);
}
#if PUPPYPRINT_DEBUG
void draw_crash_log(void) {
s32 i;
crash_screen_draw_rect(25, 20, 270, 210);
osWritebackDCacheAll();
#define LINE_HEIGHT (25 + ((LOG_BUFFER_SIZE - 1) * 10))
for (i = 0; i < LOG_BUFFER_SIZE; i++) {
crash_screen_print(30, (LINE_HEIGHT - (i * 10)), consoleLogTable[i]);
}
#undef LINE_HEIGHT
}
#endif
// prints any function pointers it finds in the stack format:
// SP address: function name
void draw_stacktrace(OSThread *thread, UNUSED s32 cause) {
__OSThreadContext *tc = &thread->context;
u32 temp_sp = (tc->sp + 0x14);
crash_screen_draw_rect(25, 20, 270, 210);
crash_screen_print(30, 25, "STACK TRACE FROM %08X:", temp_sp);
if ((u32) parse_map == MAP_PARSER_ADDRESS) {
crash_screen_print(30, 35, "CURRFUNC: NONE");
} else {
crash_screen_print(30, 35, "CURRFUNC: %s", parse_map(tc->pc));
}
osWritebackDCacheAll();
for (int i = 0; i < 18; i++) {
if ((u32) find_function_in_stack == MAP_PARSER_ADDRESS) {
crash_screen_print(30, (45 + (i * 10)), "STACK TRACE DISABLED");
break;
} else {
if ((u32) find_function_in_stack == MAP_PARSER_ADDRESS) {
return;
}
char *fname = find_function_in_stack(&temp_sp);
if ((fname == NULL) || ((*(u32*)temp_sp & 0x80000000) == 0)) {
crash_screen_print(30, (45 + (i * 10)), "%08X: UNKNOWN", temp_sp);
} else {
crash_screen_print(30, (45 + (i * 10)), "%08X: %s", temp_sp, fname);
}
}
}
}
extern char *insn_disasm(u32 insn, u32 isPC);
static u32 sProgramPosition = 0;
void draw_disasm(OSThread *thread) {
__OSThreadContext *tc = &thread->context;
// u32 insn = *(u32*)tc->pc;
crash_screen_draw_rect(25, 20, 270, 210);
if (sProgramPosition == 0) {
sProgramPosition = (tc->pc - 36);
}
crash_screen_print(30, 25, "DISASM %08X", sProgramPosition);
osWritebackDCacheAll();
for (int i = 0; i < 19; i++) {
u32 addr = (sProgramPosition + (i * 4));
u32 toDisasm = *(u32*)(addr);
crash_screen_print(30, (35 + (i * 10)), "%s", insn_disasm(toDisasm, (addr == tc->pc)));
}
osWritebackDCacheAll();
}
void draw_assert(UNUSED OSThread *thread) {
crash_screen_draw_rect(25, 20, 270, 210);
crash_screen_print(30, 25, "ASSERT PAGE");
if (__n64Assert_Filename != NULL) {
crash_screen_print(30, 35, "FILE: %s LINE %d", __n64Assert_Filename, __n64Assert_LineNum);
crash_screen_print(30, 55, "MESSAGE:");
crash_screen_print(30, 70, " %s", __n64Assert_Message);
} else {
crash_screen_print(30, 35, "no failed assert to report.");
}
osWritebackDCacheAll();
}
void draw_crash_screen(OSThread *thread) {
__OSThreadContext *tc = &thread->context;
s32 cause = ((tc->cause >> 2) & 0x1F);
if (cause == 23) { // EXC_WATCH
cause = 16;
}
if (cause == 31) { // EXC_VCED
cause = 17;
}
if (gPlayer1Controller->buttonPressed & R_TRIG) {
crashPage++;
updateBuffer = TRUE;
}
if (gPlayer1Controller->buttonPressed & (L_TRIG | Z_TRIG)) {
crashPage--;
updateBuffer = TRUE;
}
if (gPlayer1Controller->buttonDown & D_CBUTTONS) {
sProgramPosition += 4;
updateBuffer = TRUE;
}
if (gPlayer1Controller->buttonDown & U_CBUTTONS) {
sProgramPosition -= 4;
updateBuffer = TRUE;
}
if ((crashPage >= PAGE_COUNT) && (crashPage != 255)) {
crashPage = 0;
}
if (crashPage == 255) {
crashPage = (PAGE_COUNT - 1);
}
if (updateBuffer) {
crash_screen_draw_rect(25, 8, 270, 12);
crash_screen_print(30, 10, "Page:%02d L/Z: Left R: Right", crashPage);
switch (crashPage) {
case PAGE_CONTEXT: draw_crash_context(thread, cause); break;
#if PUPPYPRINT_DEBUG
case PAGE_LOG: draw_crash_log(); break;
#endif
case PAGE_STACKTRACE: draw_stacktrace(thread, cause); break;
case PAGE_DISASM: draw_disasm(thread); break;
case PAGE_ASSERTS: draw_assert(thread); break;
}
osWritebackDCacheAll();
osViBlack(FALSE);
osViSwapBuffer(gCrashScreen.framebuffer);
updateBuffer = FALSE;
}
}
OSThread *get_crashed_thread(void) {
OSThread *thread = __osGetCurrFaultedThread();
while (thread->priority != -1) {
if (thread->priority > OS_PRIORITY_IDLE && thread->priority < OS_PRIORITY_APPMAX
&& ((thread->flags & (BIT(0) | BIT(1))) != 0)) {
return thread;
}
thread = thread->tlnext;
}
return NULL;
}
extern u16 sRenderedFramebuffer;
extern void audio_signal_game_loop_tick(void);
extern void stop_sounds_in_continuous_banks(void);
extern void read_controller_inputs(s32 threadID);
extern struct SequenceQueueItem sBackgroundMusicQueue[6];
void thread2_crash_screen(UNUSED void *arg) {
OSMesg mesg;
OSThread *thread = NULL;
osSetEventMesg(OS_EVENT_CPU_BREAK, &gCrashScreen.mesgQueue, (OSMesg) 1);
osSetEventMesg(OS_EVENT_FAULT, &gCrashScreen.mesgQueue, (OSMesg) 2);
while (TRUE) {
#if PUPPYPRINT_DEBUG
OSTime first = osGetTime();
#endif
if (thread == NULL) {
osRecvMesg(&gCrashScreen.mesgQueue, &mesg, 1);
thread = get_crashed_thread();
gCrashScreen.framebuffer = (RGBA16 *) gFramebuffers[sRenderedFramebuffer];
if (thread) {
if ((u32) map_data_init != MAP_PARSER_ADDRESS) {
map_data_init();
}
gCrashScreen.thread.priority = 15;
stop_sounds_in_continuous_banks();
stop_background_music(sBackgroundMusicQueue[0].seqId);
audio_signal_game_loop_tick();
crash_screen_sleep(200);
play_sound(SOUND_MARIO_WAAAOOOW, gGlobalSoundSource);
audio_signal_game_loop_tick();
crash_screen_sleep(200);
continue;
}
} else {
if (gControllerBits) {
#if ENABLE_RUMBLE
block_until_rumble_pak_free();
#endif
osContStartReadData(&gSIEventMesgQueue);
}
read_controller_inputs(THREAD_2_CRASH_SCREEN);
draw_crash_screen(thread);
}
#if PUPPYPRINT_DEBUG
profiler_update(faultTime, first);
#endif
}
}
void crash_screen_init(void) {
gCrashScreen.framebuffer = (RGBA16 *) gFramebuffers[sRenderedFramebuffer];
gCrashScreen.width = SCREEN_WIDTH;
gCrashScreen.height = SCREEN_HEIGHT;
osCreateMesgQueue(&gCrashScreen.mesgQueue, &gCrashScreen.mesg, 1);
osCreateThread(&gCrashScreen.thread, THREAD_2_CRASH_SCREEN, thread2_crash_screen, NULL,
(u8 *) gCrashScreen.stack + sizeof(gCrashScreen.stack),
OS_PRIORITY_APPMAX
);
osStartThread(&gCrashScreen.thread);
}