From ee4171e860ece24acf0c468bcd6f0cfcef164dfd Mon Sep 17 00:00:00 2001 From: Pseurae Date: Sun, 6 Oct 2024 12:16:59 +0000 Subject: [PATCH] Fix issue with div/modulus, fix OW shadows on small sprites --- Makefile | 2 +- assembly/thumb.s | 17 +++++++++++++++-- include/debug.h | 8 -------- include/mini_printf.h | 4 ++-- linker.ld | 3 +-- src/debug.c | 13 ------------- src/event_object_movement.c | 10 +++++----- src/field_effect_helpers.c | 4 +--- src/mini_printf.c | 2 +- src/pokemon_menu.c | 10 ++++++++++ 10 files changed, 36 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index 9cf0f51..e2d00eb 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ ASM_OBJS := $(ASM_FILES:assembly/%.s=build/assembly/%.o) OBJ_FILES ?= $(SRC_OBJS) $(ASM_OBJS) -CFLAGS = -Wall -std=c99 -O2 -Iinclude -g -mlong-calls -mthumb -mno-thumb-interwork -march=armv4t -mcpu=arm7tdmi -mtune=arm7tdmi -x c -c -Wparentheses -Wno-unused -Werror +CFLAGS = -Wall -std=c99 -O2 -Iinclude -g -mlong-calls -mthumb -mthumb-interwork -specs=gba.specs -x c -c -Wparentheses -Wno-unused -Werror AS := $(PREFIX)as ASFLAGS := -mthumb -I assembly -I include diff --git a/assembly/thumb.s b/assembly/thumb.s index fa485f3..3883c60 100644 --- a/assembly/thumb.s +++ b/assembly/thumb.s @@ -1,6 +1,19 @@ -.global __aeabi_idivmod, __aeabi_uidivmod +.global __aeabi_idivmod, __aeabi_uidivmod, __aeabi_idiv, __aeabi_uidiv + +.force_thumb .thumb_func __aeabi_idivmod: +.force_thumb +.thumb_func __aeabi_uidivmod: -swi #6 +swi #0x6 +bx lr + +.force_thumb +.thumb_func +__aeabi_uidiv: +.force_thumb +.thumb_func +_aeabi_idiv: +swi #0x6 bx lr diff --git a/include/debug.h b/include/debug.h index 15adcc4..07f0e1f 100644 --- a/include/debug.h +++ b/include/debug.h @@ -11,14 +11,6 @@ bool32 MgbaOpen(void); void MgbaClose(void); void MgbaPrintf(s32 level, const char *pBuf, ...); -void MgbaAssert(const char *pFile, s32 nLine, const char *pExpression, bool32 nStopProgram); #define DebugPrintf(pBuf, ...) MgbaPrintf(MGBA_LOG_INFO, pBuf, ## __VA_ARGS__) -#define DebugAssert(pFile, nLine, pExpression, nStopProgram) MgbaAssert(pFile, nLine, pExpression, nStopProgram) #define DebugPrintfLevel(level, pBuf, ...) MgbaPrintf(level, pBuf, ## __VA_ARGS__) - -#define AGB_ASSERT(exp) (exp) ? ((void*)0) : DebugAssert(__FILE__, __LINE__, #exp, TRUE) -#define AGB_WARNING(exp) (exp) ? ((void*)0) : DebugAssert(__FILE__, __LINE__, #exp, FALSE) - -#define AGB_WARNING_EX(exp, file, line) (exp) ? ((void *)0) : DebugAssert(file, line, #exp, FALSE); -#define AGB_ASSERT_EX(exp, file, line) (exp) ? ((void *)0) : DebugAssert(file, line, #exp, TRUE); diff --git a/include/mini_printf.h b/include/mini_printf.h index 7f682c9..4f2e2e5 100644 --- a/include/mini_printf.h +++ b/include/mini_printf.h @@ -44,8 +44,8 @@ #else -s32 LONG_CALL mini_vsnprintf(char* buffer, u32 buffer_len, const char *fmt, va_list va); -s32 LONG_CALL mini_vpprintf(void* buf, const char *fmt, va_list va); +s32 mini_vsnprintf(char* buffer, u32 buffer_len, const char *fmt, va_list va); +s32 mini_vpprintf(void* buf, const char *fmt, va_list va); #endif #endif \ No newline at end of file diff --git a/linker.ld b/linker.ld index 398d956..a53aa7a 100644 --- a/linker.ld +++ b/linker.ld @@ -22,8 +22,7 @@ SECTIONS { .rodata : ALIGN(4) { - *(.rodata); - *(.rodata.str1.4); + *(.rodata*); } > rom = 0xff .script_data : diff --git a/src/debug.c b/src/debug.c index 8e79e30..171e599 100644 --- a/src/debug.c +++ b/src/debug.c @@ -31,16 +31,3 @@ void MgbaPrintf(s32 level, const char* ptr, ...) va_end(args); *REG_DEBUG_FLAGS = level | 0x100; } - -void MgbaAssert(const char *pFile, s32 nLine, const char *pExpression, bool32 nStopProgram) -{ - if (nStopProgram) - { - MgbaPrintf(MGBA_LOG_ERROR, "ASSERTION FAILED FILE=[%s] LINE=[%d] EXP=[%s]", pFile, nLine, pExpression); - __asm__(".hword 0xEFFF"); - } - else - { - MgbaPrintf(MGBA_LOG_WARN, "WARING FILE=[%s] LINE=[%d] EXP=[%s]", pFile, nLine, pExpression); - } -} diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 3f3bc46..61748f1 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -85,16 +85,16 @@ void GetGroundEffectFlags_Shadow(struct ObjectEvent *objEvent, u32 *flags) } } +#include "debug.h" + void GroundEffect_Shadow(struct ObjectEvent *objEvent, struct Sprite *sprite) { (void)sprite; // StartFieldEffectForObjectEvent(FLDEFF_SHADOW, objEvent); - // ObjectEventGetLocalIdAndMap( - // objEvent, &gFieldEffectArguments[0], &gFieldEffectArguments[1], &gFieldEffectArguments[2]); - gFieldEffectArguments[0] = objEvent->localId; - gFieldEffectArguments[1] = objEvent->mapNum; - gFieldEffectArguments[2] = objEvent->mapGroup; + ObjectEventGetLocalIdAndMap( + objEvent, &gFieldEffectArguments[0], &gFieldEffectArguments[1], &gFieldEffectArguments[2]); + gFieldEffectArguments[3] = objEvent->graphicsId; FldEff_Shadow_(); } diff --git a/src/field_effect_helpers.c b/src/field_effect_helpers.c index bec21f2..054e731 100644 --- a/src/field_effect_helpers.c +++ b/src/field_effect_helpers.c @@ -13,9 +13,7 @@ u32 FldEff_Shadow_(void) const struct ObjectEventGraphicsInfo *graphicsInfo; u8 spriteId; - objectEventId = - GetObjectEventIdByLocalIdAndMap(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); - graphicsInfo = GetObjectEventGraphicsInfo(gObjectEvents[objectEventId].graphicsId); + graphicsInfo = GetObjectEventGraphicsInfo(gFieldEffectArguments[3]); spriteId = CreateSpriteAtEnd( gFieldEffectObjectTemplatePointers[gShadowEffectTemplateIds[graphicsInfo->shadowSize]], 0, 0, 0x94); diff --git a/src/mini_printf.c b/src/mini_printf.c index 8159148..8a5fba4 100644 --- a/src/mini_printf.c +++ b/src/mini_printf.c @@ -33,9 +33,9 @@ */ #include "types.h" -#include "text.h" #include "mini_printf.h" #include "string_util.h" +#include "text.h" #ifndef NDEBUG diff --git a/src/pokemon_menu.c b/src/pokemon_menu.c index 47ff8e5..d2376e1 100644 --- a/src/pokemon_menu.c +++ b/src/pokemon_menu.c @@ -193,4 +193,14 @@ void BufferAlternateAbilityName(void) struct Pokemon *mon = &gPlayerParty[gSpecialVar_0x8004]; StringCopy(gStringVar1, gAbilityNames[GetAbilityBySpecies(GetMonData(mon, MON_DATA_SPECIES), !GetMonData(mon, MON_DATA_ALT_ABILITY))]); +} + +void CheckDivision(void) +{ + gSpecialVar_Result = gSpecialVar_0x8004 / gSpecialVar_0x8005; +} + +void CheckModulus(void) +{ + gSpecialVar_Result = gSpecialVar_0x8004 % gSpecialVar_0x8005; } \ No newline at end of file