Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match iQue msg_draw_char #1131

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ extern s16 D_80073E08;
extern s16 D_80073E0A;
extern IMG_BIN ResetTilesImg[];

#ifdef SHIFT
#if defined(SHIFT) || VERSION_IQUE
#define shim_create_audio_system_obfuscated create_audio_system
#define shim_load_engine_data_obfuscated load_engine_data
#endif
Expand Down Expand Up @@ -154,14 +154,11 @@ void boot_main(void* data) {
nuGfxInit();
gGameStatusPtr->contBitPattern = nuContInit();

#if VERSION_IQUE
create_audio_system();
load_engine_data();
#else
#if !VERSION_IQUE
load_obfuscation_shims();
#endif
shim_create_audio_system_obfuscated();
shim_load_engine_data_obfuscated();
#endif

nuGfxFuncSet((NUGfxFunc) gfxRetrace_Callback);
nuGfxPreNMIFuncSet(gfxPreNMI_Callback);
Expand Down
46 changes: 23 additions & 23 deletions src/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,7 @@ s32 msg_get_print_char_width(s32 character, s32 charset, s32 variation, f32 msgS
}

#if VERSION_IQUE
if (character >= 0x5F && character<=0x8F) {
if (character >= MSG_CHAR_MULTIBYTE_FIRST && character <= MSG_CHAR_MULTIBYTE_LAST) {
charWidth = 16.0;
return charWidth * msgScale;
}
Expand Down Expand Up @@ -1930,7 +1930,7 @@ void get_msg_properties(s32 msgID, s32* height, s32* width, s32* maxLineChars, s
}

#if VERSION_IQUE
if (prevChar >= 0x5f && prevChar <= 0x8F) {
if (prevChar >= MSG_CHAR_MULTIBYTE_FIRST && prevChar <= MSG_CHAR_MULTIBYTE_LAST) {
break;
}
#endif
Expand Down Expand Up @@ -3692,9 +3692,6 @@ void msg_reset_gfx_state(void) {
gSPDisplayList(gMainGfxPos++, D_8014C500);
}

#if VERSION_IQUE && !defined(NON_MATCHING)
INCLUDE_ASM(s32, "msg", msg_draw_char);
#else
void msg_draw_char(MessagePrintState* printer, MessageDrawState* drawState, s32 charIndex, s32 palette, s32 posX, s32 posY) {
MessageCharset* messageCharset;
s32 fontVariant;
Expand All @@ -3708,18 +3705,19 @@ void msg_draw_char(MessagePrintState* printer, MessageDrawState* drawState, s32
s32 rightPosY;

f32 clipOffset;
s32 texOffsetX;
s32 texOffsetY;
s32 ulx, uly, lrx, lry;
s32 ulx, texOffsetX;
s32 uly, texOffsetY;
s32 lrx, lry;
s32 dsdx, dtdy;
s32 posX2, posY2;

#if VERSION_IQUE
if (charIndex == MSG_CHAR_ZH_RANK) {
load_font_data(charset_standard_OFFSET + 0x19F80, sizeof(D_801544A0[0]), D_801544A0[0]);
load_font_data(((u8 (*)[128])charset_standard_OFFSET)[charIndex], sizeof(D_801544A0[0]), D_801544A0[0]);
} else if (charIndex == MSG_CHAR_ZH_CHAPTER) {
load_font_data(charset_standard_OFFSET + 0x1A000, sizeof(D_801544A0[0]), D_801544A0[1]);
load_font_data(((u8 (*)[128])charset_standard_OFFSET)[charIndex], sizeof(D_801544A0[0]), D_801544A0[1]);
} else if (charIndex >= MSG_CHAR_ZH_START) {
load_font_data(charset_standard_OFFSET + charIndex, sizeof(D_801544A0[0]), D_801544A0[D_8014AD24]);
load_font_data(((u8 (*)[128])charset_standard_OFFSET)[charIndex], sizeof(D_801544A0[0]), D_801544A0[D_8014AD24]);
}
#endif

Expand All @@ -3731,34 +3729,37 @@ void msg_draw_char(MessagePrintState* printer, MessageDrawState* drawState, s32
clipUlx = drawState->clipX[0];
clipLrx = drawState->clipX[1];

rightPosX = posX + (s32)(drawState->charScale.x * messageCharset->texSize.x);
rightPosY = posY + (s32)(drawState->charScale.y * messageCharset->texSize.y);
posX2 = posX;
posY2 = posY;

rightPosX = posX2 + (s32)(drawState->charScale.x * messageCharset->texSize.x);
rightPosY = posY2 + (s32)(drawState->charScale.y * messageCharset->texSize.y);

if (posX >= clipLrx || posY >= clipLry || rightPosX <= clipUlx || rightPosY <= clipUly) {
if (posX2 >= clipLrx || posY2 >= clipLry || rightPosX <= clipUlx || rightPosY <= clipUly) {
return;
}

if (posX < clipUlx) {
clipOffset = abs(posX - clipUlx) / drawState->charScale.x;
if (posX2 < clipUlx) {
clipOffset = abs(posX2 - clipUlx) / drawState->charScale.x;
texOffsetX = (f32)((clipOffset + 0.5) * 32.0);
ulx = clipUlx;
} else {
texOffsetX = 0;
ulx = posX;
ulx = posX2;
}

if (posY < clipUly) {
if (!(printer->stateFlags & MSG_STATE_FLAG_400) || posY < 0) {
clipOffset = abs(posY - clipUly) / drawState->charScale.y;
if (posY2 < clipUly) {
if (!(printer->stateFlags & MSG_STATE_FLAG_400) || posY2 < 0) {
clipOffset = abs(posY2 - clipUly) / drawState->charScale.y;
texOffsetY = clipOffset * 32.0f;
uly = clipUly;
} else {
texOffsetY = 0;
uly = posY;
uly = posY2;
}
} else {
texOffsetY = 0;
uly = posY;
uly = posY2;
}

lrx = rightPosX;
Expand Down Expand Up @@ -3831,7 +3832,6 @@ void msg_draw_char(MessagePrintState* printer, MessageDrawState* drawState, s32
}
#endif
}
#endif

void msg_draw_prim_rect(u8 r, u8 g, u8 b, u8 a, u16 posX, u16 posY, u16 sizeX, u16 sizeY) {
u16 lrX = posX + sizeX;
Expand Down
8 changes: 3 additions & 5 deletions src/state_battle.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SHIFT_BSS s8 D_800A0900;
SHIFT_BSS s32 D_800A0904;
SHIFT_BSS s32 D_800A0908;

#ifdef SHIFT
#if defined(SHIFT) || VERSION_IQUE
#define shim_battle_heap_create_obfuscated battle_heap_create
#endif

Expand Down Expand Up @@ -60,12 +60,10 @@ void state_step_battle(void) {
gGameStatusPtr->isBattle = TRUE;
backup_map_collision_data();

#if VERSION_IQUE
battle_heap_create();
#else
#if !VERSION_IQUE
load_obfuscation_shims();
shim_battle_heap_create_obfuscated();
#endif
shim_battle_heap_create_obfuscated();

sfx_clear_env_sounds(0);

Expand Down
14 changes: 5 additions & 9 deletions src/world/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ typedef struct {
void fio_deserialize_state(void);
void load_map_hit_asset(void);

#ifdef SHIFT
#if defined(SHIFT) || VERSION_IQUE
#define shim_general_heap_create_obfuscated general_heap_create
#endif

Expand All @@ -84,12 +84,10 @@ void load_map_by_IDs(s16 areaID, s16 mapID, s16 loadType) {

gGameStatusPtr->playerSpriteSet = PLAYER_SPRITES_MARIO_WORLD;

#if VERSION_IQUE
general_heap_create();
#else
#if !VERSION_IQUE
load_obfuscation_shims();
shim_general_heap_create_obfuscated();
#endif
shim_general_heap_create_obfuscated();

#if VERSION_JP
reset_max_rumble_duration();
Expand Down Expand Up @@ -156,12 +154,10 @@ void load_map_by_IDs(s16 areaID, s16 mapID, s16 loadType) {
load_map_bg(wMapBgName);
}

#if VERSION_IQUE
general_heap_create();
#else
#if !VERSION_IQUE
load_obfuscation_shims();
shim_general_heap_create_obfuscated();
#endif
shim_general_heap_create_obfuscated();

sfx_clear_env_sounds(0);
clear_worker_list();
Expand Down
Loading
Loading