Files
mm/src/boot_O2_g3/fault_drawer.c
T
Lucas Shaw dcf44596d2 Animation system updated, some more boot files decompiled (+6%), z_fcurve_data_skelanime decompiled (1 non-matching), some asm files split, etc (#89)
* Progress on various files

* gfxprint stuff

* split some rodata, add iconv for rodata string parsing

* z_std_dma rodata

* 2 nonmatchings in gfxprint

* mtxuty-cvt ok

* more

* match a function in idle.c

* progress

* Cleanup

* Rename BgPolygon to CollisionPoly

* progress

* some effect stuff

* more effect progress

* updates

* made suggested changes

* z_effect_soft_sprite_old_init mostly ok

* remove old effects enum

* gamealloc.c OK

* added more files

* motor.c almost done

* motor.c OK

* updates

* migration of two files

* listalloc.c oK

* z_fcurve_data_skelanime split

* z_fcurve_data_skelanime.c decompiled

* more files split

* z_malloc.c OK

* contpfs.c OK

* fault.c rodata migrated

* migrated fault_drawer rodata

* update

* update preprocess.py

* renamed functions in z_skelanime

* started z_skelanime cleanup

* like halfway through fixing z_skelanime

* animation system updated to meet oot standards

* remove unused animation structs

* rename matrix structs to fit oot

* Add -woff 712

* fix diff_settings.py because i accidentally broke it before

* fixed merge conflict, doesn't match though

* It matches now

* Updates

* Fixed warnings...added gcc code syntax checking

* Remove gcc check, added in Tharo's PR

* warnings fixed (i think)

* fixed all warnings i think

* ok

* not sure what to do

* Fix all warnings i think (z_en_a_keep needs some file cleanup thouguh)

* it matches if i do this

* remove comment

* accidentally put osPfsFreeBlocks in epilinkhandle.c

* memcmp -> bcmp

* change u32 size to size_t size, delete string.h because it caused unnecessary confusion with defining size_t twice

* format.sh

* MTXMODE_NEW and MTXMODE_APPLY to matrix functions

* Made suggested changes

* pragma sFaultDrawerFont instead of including in repo

* add some functions to functions.h

* Bss reordering fixed in z_collision_check...added hack to disasm.py

* Updated z_en_a_keep.c

* Missed suggestion in EnAObj_Destroy

* .

* update z_fcurve_Data_skelanime and z_skelanime with suggestions

* devmgr.c ok

* minor changes

* Addressed comments

* remove redundant file

* gfxp -> dlist in game.c

* updated actorfixer.py

* fixed warnings in z_malloc

* Change void* back to Actor*

* format

* Add the soft_sprit comments back

* Rename SV->Flex

* remove .common

* run format

* Update src/code/z_skelanime.c

* u32 channel

Co-authored-by: Lucas Shaw <lucas.shaw1123@gmail.com>
Co-authored-by: angie <angheloalf95@gmail.com>
Co-authored-by: Kenix3 <kenixwhisperwind@gmail.com>
2021-10-24 10:59:14 -04:00

187 lines
5.5 KiB
C

#include "global.h"
#include "vt.h"
extern const u32 sFaultDrawerFont[];
FaultDrawer* sFaultDrawContext = &sFaultDrawerStruct;
FaultDrawer sFaultDrawerDefault = {
(u16*)0x803DA800, // fb - TODO map out buffers in this region and avoid hard-coded pointer
SCREEN_WIDTH, // w
SCREEN_HEIGHT, // h
16, // yStart
223, // yEnd
22, // xStart
297, // xEnd
GPACK_RGBA5551(255, 255, 255, 255), // foreColor
GPACK_RGBA5551(0, 0, 0, 0), // backColor
22, // cursorX
16, // cursorY
(u32*)sFaultDrawerFont, // font
8, // charW
8, // charH
0, // charWPad
0, // charHPad
{
// printColors
GPACK_RGBA5551(0, 0, 0, 1),
GPACK_RGBA5551(255, 0, 0, 1),
GPACK_RGBA5551(0, 255, 0, 1),
GPACK_RGBA5551(255, 255, 0, 1),
GPACK_RGBA5551(0, 0, 255, 1),
GPACK_RGBA5551(255, 0, 255, 1),
GPACK_RGBA5551(0, 255, 255, 1),
GPACK_RGBA5551(255, 255, 255, 1),
GPACK_RGBA5551(120, 120, 120, 1),
GPACK_RGBA5551(176, 176, 176, 1),
},
0, // escCode
0, // osSyncPrintfEnabled
NULL, // inputCallback
};
#pragma GLOBAL_ASM("asm/non_matchings/boot/fault_drawer/sFaultDrawerFont.s")
void FaultDrawer_SetOsSyncPrintfEnabled(u32 enabled) {
sFaultDrawContext->osSyncPrintfEnabled = enabled;
}
void FaultDrawer_DrawRecImpl(s32 xStart, s32 yStart, s32 xEnd, s32 yEnd, u16 color) {
u16* fb;
s32 x, y;
s32 xDiff = sFaultDrawContext->w - xStart;
s32 yDiff = sFaultDrawContext->h - yStart;
s32 xSize = xEnd - xStart + 1;
s32 ySize = yEnd - yStart + 1;
if (xDiff > 0 && yDiff > 0) {
if (xDiff < xSize) {
xSize = xDiff;
}
if (yDiff < ySize) {
ySize = yDiff;
}
fb = sFaultDrawContext->fb + sFaultDrawContext->w * yStart + xStart;
for (y = 0; y < ySize; y++) {
for (x = 0; x < xSize; x++) {
*fb++ = color;
}
fb += sFaultDrawContext->w - xSize;
}
osWritebackDCacheAll();
}
}
#pragma GLOBAL_ASM("asm/non_matchings/boot/fault_drawer/FaultDrawer_DrawChar.s")
s32 FaultDrawer_ColorToPrintColor(u16 color) {
s32 i;
for (i = 0; i < 10; i++) {
if (color == sFaultDrawContext->printColors[i]) {
return i;
}
}
return -1;
}
void FaultDrawer_UpdatePrintColor() {
s32 idx;
if (sFaultDrawContext->osSyncPrintfEnabled) {
osSyncPrintf(VT_RST);
idx = FaultDrawer_ColorToPrintColor(sFaultDrawContext->foreColor);
if (idx >= 0 && idx < 8) {
osSyncPrintf(VT_SGR("3%d"), idx);
}
idx = FaultDrawer_ColorToPrintColor(sFaultDrawContext->backColor);
if (idx >= 0 && idx < 8) {
osSyncPrintf(VT_SGR("4%d"), idx);
}
}
}
void FaultDrawer_SetForeColor(u16 color) {
sFaultDrawContext->foreColor = color;
FaultDrawer_UpdatePrintColor();
}
void FaultDrawer_SetBackColor(u16 color) {
sFaultDrawContext->backColor = color;
FaultDrawer_UpdatePrintColor();
}
void FaultDrawer_SetFontColor(u16 color) {
FaultDrawer_SetForeColor(color | 1); // force alpha to be set
}
void FaultDrawer_SetCharPad(s8 padW, s8 padH) {
sFaultDrawContext->charWPad = padW;
sFaultDrawContext->charHPad = padH;
}
void FaultDrawer_SetCursor(s32 x, s32 y) {
if (sFaultDrawContext->osSyncPrintfEnabled) {
osSyncPrintf(VT_CUP("%d", "%d"),
(y - sFaultDrawContext->yStart) / (sFaultDrawContext->charH + sFaultDrawContext->charHPad),
(x - sFaultDrawContext->xStart) / (sFaultDrawContext->charW + sFaultDrawContext->charWPad));
}
sFaultDrawContext->cursorX = x;
sFaultDrawContext->cursorY = y;
}
void FaultDrawer_FillScreen() {
if (sFaultDrawContext->osSyncPrintfEnabled) {
osSyncPrintf(VT_CLS);
}
FaultDrawer_DrawRecImpl(sFaultDrawContext->xStart, sFaultDrawContext->yStart, sFaultDrawContext->xEnd,
sFaultDrawContext->yEnd, sFaultDrawContext->backColor | 1);
FaultDrawer_SetCursor(sFaultDrawContext->xStart, sFaultDrawContext->yStart);
}
#pragma GLOBAL_ASM("asm/non_matchings/boot/fault_drawer/FaultDrawer_FormatStringFunc.s")
const char D_80099080[] = "(null)";
void FaultDrawer_VPrintf(const char* str, char* args) { // va_list
_Printf((PrintCallback)FaultDrawer_FormatStringFunc, sFaultDrawContext, str, args);
}
void FaultDrawer_Printf(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
FaultDrawer_VPrintf(fmt, args);
va_end(args);
}
void FaultDrawer_DrawText(s32 x, s32 y, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
FaultDrawer_SetCursor(x, y);
FaultDrawer_VPrintf(fmt, args);
va_end(args);
}
void FaultDrawer_SetDrawerFB(void* fb, u16 w, u16 h) {
sFaultDrawContext->fb = (u16*)fb;
sFaultDrawContext->w = w;
sFaultDrawContext->h = h;
}
void FaultDrawer_SetInputCallback(void* callback) {
sFaultDrawContext->inputCallback = callback;
}
void FaultDrawer_Init() {
sFaultDrawContext = &sFaultDrawerStruct;
bcopy(&sFaultDrawerDefault, sFaultDrawContext, sizeof(FaultDrawer));
sFaultDrawContext->fb = (u16*)((osMemSize | 0x80000000) - 0x25800);
}