From 7dc95a0103af08c95c9093b6efa6c77af77a2538 Mon Sep 17 00:00:00 2001 From: aaaaaa123456789 Date: Sun, 13 Sep 2020 04:22:50 -0300 Subject: [PATCH] Undo PokeCodec's PRs This commit undoes most of PokeCodec's PRs after the debate in chat. Some harmless or completely superseded PRs have been left alone, as there is not much benefit in attempting to undo them. Reverts #1104, #1108, #1115, #1118, #1119, #1124, #1126, #1127, #1132, #1136, #1137, #1139, #1140, #1144, #1148, #1149, #1150, #1153, #1155, #1177, #1179, #1180, #1181, #1182 and #1183. --- Makefile | 2 +- berry_fix/asm/loader.s | 2 +- berry_fix/payload/include/gba/m4a_internal.h | 34 +- berry_fix/payload/src/flash.c | 2 +- constants/gba_constants.inc | 6 +- gflib/bg.c | 118 +-- gflib/text.c | 926 ++++++++++++++++--- gflib/text.h | 21 +- gflib/window.c | 38 +- include/AgbRfu_LinkManager.h | 4 +- include/battle.h | 22 +- include/battle_main.h | 3 +- include/battle_message.h | 2 +- include/battle_util.h | 13 - include/constants/battle.h | 2 +- include/constants/battle_pyramid.h | 10 + include/constants/rgb.h | 4 - include/gba/m4a_internal.h | 92 +- include/global.h | 2 +- include/list_menu.h | 4 +- include/pokemon.h | 12 +- include/pokenav.h | 2 +- libagbsyscall/libagbsyscall.s | 19 +- src/AgbRfu_LinkManager.c | 6 +- src/agb_flash.c | 26 +- src/apprentice.c | 4 +- src/battle_ai_script_commands.c | 2 +- src/battle_anim_bug.c | 38 +- src/battle_anim_dark.c | 2 + src/battle_anim_effects_1.c | 9 +- src/battle_anim_effects_3.c | 61 +- src/battle_anim_flying.c | 572 ++++++------ src/battle_anim_psychic.c | 2 +- src/battle_anim_utility_funcs.c | 2 +- src/battle_anim_water.c | 765 +++++++++++++-- src/battle_bg.c | 2 +- src/battle_controller_player.c | 74 +- src/battle_controller_safari.c | 10 +- src/battle_dome.c | 311 ++++++- src/battle_factory_screen.c | 54 +- src/battle_gfx_sfx_util.c | 15 +- src/battle_main.c | 866 +++++++++++++++-- src/battle_message.c | 2 +- src/battle_pyramid.c | 13 - src/battle_pyramid_bag.c | 26 +- src/battle_records.c | 4 +- src/battle_script_commands.c | 388 +++++++- src/battle_tower.c | 8 +- src/battle_transition.c | 7 +- src/battle_tv.c | 347 ++++++- src/battle_util.c | 623 +------------ src/berry.c | 2 +- src/berry_blender.c | 10 +- src/berry_crush.c | 71 +- src/berry_fix_program.c | 8 +- src/berry_tag_screen.c | 4 +- src/cable_club.c | 10 +- src/confetti_util.c | 6 +- src/contest.c | 44 +- src/contest_painting.c | 138 ++- src/contest_util.c | 373 +++++++- src/credits.c | 4 +- src/daycare.c | 6 +- src/decoration.c | 27 +- src/dewford_trend.c | 58 +- src/digit_obj_util.c | 2 +- src/diploma.c | 2 +- src/dodrio_berry_picking.c | 20 +- src/easy_chat.c | 82 +- src/ereader_screen.c | 10 +- src/event_object_movement.c | 102 +- src/evolution_scene.c | 8 +- src/faraway_island.c | 23 +- src/field_effect.c | 2 +- src/field_player_avatar.c | 10 +- src/field_special_scene.c | 2 +- src/fldeff_cut.c | 13 +- src/frontier_pass.c | 62 +- src/frontier_util.c | 245 ++++- src/hall_of_fame.c | 12 +- src/intro_credits_graphics.c | 4 +- src/item.c | 229 ++++- src/item_menu.c | 43 +- src/item_use.c | 6 +- src/link.c | 16 +- src/link_rfu_2.c | 83 +- src/link_rfu_3.c | 94 +- src/list_menu.c | 32 +- src/m4a.c | 111 ++- src/m4a_1.s | 466 +++++----- src/m4a_tables.c | 6 +- src/mail.c | 2 +- src/main.c | 20 +- src/main_menu.c | 16 +- src/match_call.c | 8 +- src/menu.c | 100 +- src/menu_helpers.c | 16 +- src/menu_specialized.c | 121 +-- src/mirage_tower.c | 161 +++- src/mon_markings.c | 8 +- src/move_relearner.c | 4 +- src/mystery_event_menu.c | 10 +- src/mystery_gift.c | 10 +- src/option_menu.c | 26 +- src/overworld.c | 19 +- src/party_menu.c | 26 +- src/player_pc.c | 28 +- src/pokeblock.c | 10 +- src/pokedex.c | 268 +++--- src/pokedex_area_screen.c | 4 +- src/pokemon.c | 61 +- src/pokemon_animation.c | 9 +- src/pokemon_jump.c | 8 +- src/pokemon_storage_system.c | 167 ++-- src/pokemon_summary_screen.c | 50 +- src/pokenav.c | 4 +- src/pokenav_conditions_1.c | 8 +- src/pokenav_conditions_3.c | 15 +- src/pokenav_main_menu.c | 181 +++- src/pokenav_match_call_1.c | 28 +- src/pokenav_match_call_2.c | 2 +- src/pokenav_menu_handler_1.c | 26 +- src/pokenav_region_map.c | 2 +- src/pokenav_ribbons_1.c | 12 +- src/pokenav_ribbons_2.c | 18 +- src/record_mixing.c | 46 +- src/region_map.c | 24 +- src/reset_rtc_screen.c | 16 +- src/save.c | 8 +- src/save_failed_screen.c | 6 +- src/scrcmd.c | 8 +- src/script.c | 6 +- src/script_menu.c | 2 +- src/secret_base.c | 8 +- src/shop.c | 8 +- src/slot_machine.c | 85 +- src/start_menu.c | 16 +- src/title_screen.c | 8 +- src/trade.c | 20 +- src/trainer_card.c | 8 +- src/trainer_hill.c | 68 +- src/trainer_see.c | 4 +- src/union_room.c | 24 +- src/union_room_chat.c | 26 +- src/unk_text_util_2.c | 10 +- src/walda_phrase.c | 4 +- src/wallclock.c | 8 +- src/wireless_communication_status_screen.c | 6 +- tools/gbagfx/gfx.c | 2 +- 149 files changed, 6786 insertions(+), 3108 deletions(-) diff --git a/Makefile b/Makefile index ca282d07e..99a93718b 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,7 @@ OBJ_DIR := build/emerald LIBPATH := -L ../../tools/agbcc/lib else CC1 = $(shell $(CC) --print-prog-name=cc1) -quiet -override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mcpu=arm7tdmi -fno-toplevel-reorder -Wno-pointer-to-int-cast +override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast ROM := pokeemerald_modern.gba OBJ_DIR := build/modern LIBPATH := -L "$(dir $(shell $(CC) -mthumb -print-file-name=libgcc.a))" -L "$(dir $(shell $(CC) -mthumb -print-file-name=libc.a))" diff --git a/berry_fix/asm/loader.s b/berry_fix/asm/loader.s index 24eb2df55..a78014078 100644 --- a/berry_fix/asm/loader.s +++ b/berry_fix/asm/loader.s @@ -109,7 +109,7 @@ _1a0: strh r1, [r0, 0xa] @ SIOMLT_SEND ldr r0, =_data_2f0 ldr r1, =gCode - svc 0x11 << 16 + swi 0x11 << 16 ldr lr, =gCode bx lr .pool diff --git a/berry_fix/payload/include/gba/m4a_internal.h b/berry_fix/payload/include/gba/m4a_internal.h index 494d31f93..339a0774e 100644 --- a/berry_fix/payload/include/gba/m4a_internal.h +++ b/berry_fix/payload/include/gba/m4a_internal.h @@ -100,12 +100,12 @@ struct CgbChannel u8 le; u8 sw; u32 fr; - u32 *wp; - u32 *cp; - void *tp; - void *pp; - void *np; - u32 d4[2]; + u32 wp; + u32 cp; + u32 tp; + u32 pp; + u32 np; + u8 d4[8]; }; struct MusicPlayerTrack; @@ -138,10 +138,10 @@ struct SoundChannel u32 fw; u32 freq; struct WaveData *wav; - s8 *cp; + u32 cp; struct MusicPlayerTrack *track; - void *pp; - void *np; + u32 pp; + u32 np; u32 d4; u16 xpi; u16 xpc; @@ -172,11 +172,11 @@ struct SoundInfo u8 pcmDmaPeriod; // number of V-blanks per PCM DMA u8 maxLines; u8 gap[3]; - u32 pcmSamplesPerVBlank; - u32 pcmFreq; - u32 divFreq; + s32 pcmSamplesPerVBlank; + s32 pcmFreq; + s32 divFreq; struct CgbChannel *cgbChans; - void (*func)(); + u32 func; u32 intp; void (*CgbSound)(void); void (*CgbOscOff)(u8); @@ -184,7 +184,7 @@ struct SoundInfo u32 MPlayJumpTable; u32 plynote; u32 ExtVolPit; - u32 gap2[4]; + u8 gap2[16]; struct SoundChannel chans[MAX_DIRECTSOUND_CHANNELS]; s8 pcmBuffer[PCM_DMA_BUF_SIZE * 2]; }; @@ -248,7 +248,7 @@ struct MusicPlayerTrack u8 key; u8 velocity; u8 runningStatus; - s8 keyM; + u8 keyM; u8 pitM; s8 keyShift; s8 keyShiftX; @@ -312,7 +312,7 @@ struct MusicPlayerInfo struct MusicPlayerTrack *tracks; struct ToneData *tone; u32 ident; - void (*func)(); + u32 func; u32 intp; }; @@ -447,7 +447,7 @@ void ply_tune(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_port(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_xcmd(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_endtie(struct MusicPlayerInfo *, struct MusicPlayerTrack *); -void ply_note(u8, struct MusicPlayerInfo *, struct MusicPlayerTrack *); +void ply_note(struct MusicPlayerInfo *, struct MusicPlayerTrack *); // extended sound command handler functions void ply_xxx(struct MusicPlayerInfo *, struct MusicPlayerTrack *); diff --git a/berry_fix/payload/src/flash.c b/berry_fix/payload/src/flash.c index 499a1f971..1f09d0b8f 100644 --- a/berry_fix/payload/src/flash.c +++ b/berry_fix/payload/src/flash.c @@ -296,7 +296,7 @@ u8 HandleWriteSectorNBytes(u8 sectorNum, u8 *data, u16 size) u8 TryWriteSector(u8 sectorNum, u8 *data) { - if (ProgramFlashSectorAndVerify(sectorNum, data)) // is damaged? + if (ProgramFlashSectorAndVerify(sectorNum, data) != 0) // is damaged? { SetSectorDamagedStatus(SECTOR_DAMAGED, sectorNum); // set damaged sector bits. return SAVE_STATUS_ERROR; diff --git a/constants/gba_constants.inc b/constants/gba_constants.inc index 13cbadf80..3ff857ee8 100644 --- a/constants/gba_constants.inc +++ b/constants/gba_constants.inc @@ -26,9 +26,9 @@ .set OAM, 0x7000000 - .set SOUND_INFO_PTR, IWRAM_END - 0x10 - .set INTR_CHECK, IWRAM_END - 0x8 - .set INTR_VECTOR, IWRAM_END - 0x4 + .set SOUND_INFO_PTR, 0x3007FF0 + .set INTR_CHECK, 0x3007FF8 + .set INTR_VECTOR, 0x3007FFC .set INTR_FLAG_VBLANK, 1 << 0 .set INTR_FLAG_HBLANK, 1 << 1 diff --git a/gflib/bg.c b/gflib/bg.c index 12c42d124..66dd81a25 100644 --- a/gflib/bg.c +++ b/gflib/bg.c @@ -34,8 +34,8 @@ struct BgConfig2 u32 unk_3:18; void* tilemap; - s32 bg_x; // Maybe unsigned, but game treats it as if it is signed a LOT. - s32 bg_y; // Same for this variable. + s32 bg_x; + s32 bg_y; }; static struct BgControl sGpuBgConfigs; @@ -621,15 +621,17 @@ s32 GetBgX(u8 bg) { if (IsInvalidBg32(bg)) return -1; - if (!GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) + else if (!GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) return -1; - return sGpuBgConfigs2[bg].bg_x; + else + return sGpuBgConfigs2[bg].bg_x; } s32 ChangeBgY(u8 bg, s32 value, u8 op) { u8 mode; - u16 temp1, temp2; + u16 temp1; + u16 temp2; if (IsInvalidBg32(bg) || !GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) { @@ -698,7 +700,8 @@ s32 ChangeBgY(u8 bg, s32 value, u8 op) s32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op) { u8 mode; - u16 temp1, temp2; + u16 temp1; + u16 temp2; if (IsInvalidBg32(bg) || !GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) { @@ -769,9 +772,10 @@ s32 GetBgY(u8 bg) { if (IsInvalidBg32(bg)) return -1; - if (!GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) + else if (!GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) return -1; - return sGpuBgConfigs2[bg].bg_y; + else + return sGpuBgConfigs2[bg].bg_y; } void SetBgAffine(u8 bg, s32 srcCenterX, s32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle) @@ -870,77 +874,81 @@ void* GetBgTilemapBuffer(u8 bg) { if (IsInvalidBg32(bg)) return NULL; - if (!GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) + else if (!GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE)) return NULL; - return sGpuBgConfigs2[bg].tilemap; + else + return sGpuBgConfigs2[bg].tilemap; } void CopyToBgTilemapBuffer(u8 bg, const void *src, u16 mode, u16 destOffset) { - if (IsInvalidBg32(bg) || IsTileMapOutsideWram(bg)) - return; - if (mode != 0) - CpuCopy16(src, (void *)(sGpuBgConfigs2[bg].tilemap + (destOffset * 2)), mode); - else - LZ77UnCompWram(src, (void *)(sGpuBgConfigs2[bg].tilemap + (destOffset * 2))); + if (!IsInvalidBg32(bg) && !IsTileMapOutsideWram(bg)) + { + if (mode != 0) + CpuCopy16(src, (void *)(sGpuBgConfigs2[bg].tilemap + (destOffset * 2)), mode); + else + LZ77UnCompWram(src, (void *)(sGpuBgConfigs2[bg].tilemap + (destOffset * 2))); + } } void CopyBgTilemapBufferToVram(u8 bg) { u16 sizeToLoad; - if (IsInvalidBg32(bg) || IsTileMapOutsideWram(bg)) - return; - - switch (GetBgType(bg)) + if (!IsInvalidBg32(bg) && !IsTileMapOutsideWram(bg)) { - case 0: - sizeToLoad = GetBgMetricTextMode(bg, 0) * 0x800; - break; - case 1: - sizeToLoad = GetBgMetricAffineMode(bg, 0) * 0x100; - break; - default: - sizeToLoad = 0; - break; + switch (GetBgType(bg)) + { + case 0: + sizeToLoad = GetBgMetricTextMode(bg, 0) * 0x800; + break; + case 1: + sizeToLoad = GetBgMetricAffineMode(bg, 0) * 0x100; + break; + default: + sizeToLoad = 0; + break; + } + LoadBgVram(bg, sGpuBgConfigs2[bg].tilemap, sizeToLoad, 0, 2); } - LoadBgVram(bg, sGpuBgConfigs2[bg].tilemap, sizeToLoad, 0, 2); } -void CopyToBgTilemapBufferRect(u8 bg, const void *src, u8 destX, u8 destY, u8 width, u8 height) +void CopyToBgTilemapBufferRect(u8 bg, const void* src, u8 destX, u8 destY, u8 width, u8 height) { - u16 destX16, destY16; + u16 destX16; + u16 destY16; u16 mode; - if (IsInvalidBg32(bg) || IsTileMapOutsideWram(bg)) - return; - switch (GetBgType(bg)) + if (!IsInvalidBg32(bg) && !IsTileMapOutsideWram(bg)) { - case 0: - { - const u16 *srcCopy = src; - for (destY16 = destY; destY16 < (destY + height); destY16++) + switch (GetBgType(bg)) { - for (destX16 = destX; destX16 < (destX + width); destX16++) - { - ((u16 *)sGpuBgConfigs2[bg].tilemap)[((destY16 * 0x20) + destX16)] = *srcCopy++; - } - } - break; - } - case 1: - { - const u8 *srcCopy = src; - mode = GetBgMetricAffineMode(bg, 0x1); - for (destY16 = destY; destY16 < (destY + height); destY16++) + case 0: { - for (destX16 = destX; destX16 < (destX + width); destX16++) + const u16 * srcCopy = src; + for (destY16 = destY; destY16 < (destY + height); destY16++) { - ((u8 *)sGpuBgConfigs2[bg].tilemap)[((destY16 * mode) + destX16)] = *srcCopy++; + for (destX16 = destX; destX16 < (destX + width); destX16++) + { + ((u16*)sGpuBgConfigs2[bg].tilemap)[((destY16 * 0x20) + destX16)] = *srcCopy++; + } } + break; + } + case 1: + { + const u8 * srcCopy = src; + mode = GetBgMetricAffineMode(bg, 0x1); + for (destY16 = destY; destY16 < (destY + height); destY16++) + { + for (destX16 = destX; destX16 < (destX + width); destX16++) + { + ((u8*)sGpuBgConfigs2[bg].tilemap)[((destY16 * mode) + destX16)] = *srcCopy++; + } + } + break; + } } - break; - } } } diff --git a/gflib/text.c b/gflib/text.c index 89b47ca21..5d407e5e4 100644 --- a/gflib/text.c +++ b/gflib/text.c @@ -21,7 +21,7 @@ static u16 gLastTextFgColor; static u16 gLastTextShadowColor; const struct FontInfo *gFonts; -bool8 gUnknown_03002F84; +u8 gUnknown_03002F84; struct Struct_03002F90 gUnknown_03002F90; TextFlags gTextFlags; @@ -154,7 +154,7 @@ u16 AddTextPrinterParameterized(u8 windowId, u8 fontId, const u8 *str, u8 x, u8 printerTemplate.currentY = y; printerTemplate.letterSpacing = gFonts[fontId].letterSpacing; printerTemplate.lineSpacing = gFonts[fontId].lineSpacing; - printerTemplate.style = gFonts[fontId].style; + printerTemplate.unk = gFonts[fontId].unk; printerTemplate.fgColor = gFonts[fontId].fgColor; printerTemplate.bgColor = gFonts[fontId].bgColor; printerTemplate.shadowColor = gFonts[fontId].shadowColor; @@ -205,7 +205,7 @@ bool16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u8 speed, voi CopyWindowToVram(gTempTextPrinter.printerTemplate.windowId, 2); gTextPrinters[printerTemplate->windowId].active = 0; } - gUnknown_03002F84 = FALSE; + gUnknown_03002F84 = 0; return TRUE; } @@ -213,7 +213,7 @@ void RunTextPrinters(void) { int i; - if (!gUnknown_03002F84) + if (gUnknown_03002F84 == 0) { for (i = 0; i < NUM_TEXT_PRINTERS; ++i) { @@ -451,52 +451,54 @@ u8 GetLastTextColor(u8 colorType) { switch (colorType) { - case COLOR_FOREGROUND: + case 0: return gLastTextFgColor; - case COLOR_BACKGROUND: + case 2: return gLastTextBgColor; - case COLOR_SHADOW: + case 1: return gLastTextShadowColor; default: return 0; } } -#define GLYPH_COPY(fromY_, toY_, fromX_, toX_, unk) \ - { \ - u32 i, j, *ptr, toY, fromX, toX, r5, bits; \ - u8 *dst; \ - j = fromX_; \ - i = fromY_; \ - ptr = unk; \ - toX = toX_; \ - toY = toY_; \ - fromX = fromX_; \ - \ - for (; i < toY; i++) \ - { \ - asm("":::"sl"); /* NONMATCHING */ \ - r5 = *(ptr++); \ - for (j = fromX; j < toX; j++) \ - { \ - const u32 toOrr = r5 & 0xF; \ - if (toOrr) \ - { \ - dst = windowTiles + ((j / 8) * 32) + ((j % 8) / 2) + ((i / 8) * widthOffset) + ((i % 8) * 4); \ - bits = ((j & 1) * 4); \ - *dst = (toOrr << bits) | (*dst & (0xF0 >> bits)); \ - } \ - r5 >>= 4; \ - } \ - } \ - } +#ifdef NONMATCHING + +#define GLYPH_COPY(fromY_, toY_, fromX_, toX_, unk) \ +{ \ + u32 i, j, *ptr, toY, fromX, toX, r5, toOrr, bits; \ + u8 *dst; \ + \ + j = fromX_; \ + i = fromY_; \ + ptr = unk; \ + toX = toX_; \ + toY = toY_; \ + fromX = fromX_; \ + \ + for (; i < toY; i++) \ + { \ + r5 = *(ptr++); \ + for (j = fromX; j < toX; j++) \ + { \ + toOrr = r5 & 0xF; \ + if (toOrr) \ + { \ + dst = windowTiles + ((j / 8) * 32) + ((j & 7) / 2) + ((i / 8) * widthOffset) + ((i & 7) * 4); \ + bits = ((j & 1) << 2); \ + *dst = ((toOrr << bits) | (*dst & (0xF0 >> bits))); \ + } \ + r5 >>= 4; \ + } \ + } \ +} void CopyGlyphToWindow(struct TextPrinter *textPrinter) { struct Window *win; struct WindowTemplate *winTempl; struct Struct_03002F90 *unkStruct; - u32 currX, currY, widthOffset; + u32 currX, widthOffset, currY; s32 r4, r0; u8 *windowTiles; @@ -504,12 +506,12 @@ void CopyGlyphToWindow(struct TextPrinter *textPrinter) winTempl = &win->window; r4 = (winTempl->width * 8) - textPrinter->printerTemplate.currentX; - if (r4 > gUnknown_03002F90.width) - r4 = gUnknown_03002F90.width; + if (r4 > gUnknown_03002F90.unk80) + r4 = gUnknown_03002F90.unk80; r0 = (winTempl->height * 8) - textPrinter->printerTemplate.currentY; - if (r0 > gUnknown_03002F90.height) - r0 = gUnknown_03002F90.height; + if (r0 > gUnknown_03002F90.unk81) + r0 = gUnknown_03002F90.unk81; currX = textPrinter->printerTemplate.currentX; currY = textPrinter->printerTemplate.currentY; @@ -517,9 +519,9 @@ void CopyGlyphToWindow(struct TextPrinter *textPrinter) windowTiles = win->tileData; widthOffset = winTempl->width * 32; - if (r4 < 9) + if (r4 <= 8) { - if (r0 < 9) + if (r0 <= 8) { GLYPH_COPY(currY, currY + r0, currX, currX + r4, unkStruct->unk0); } @@ -534,9 +536,9 @@ void CopyGlyphToWindow(struct TextPrinter *textPrinter) } else { - u32 temp; - if (r0 < 9) + if (r0 <= 8) { + u32 temp; GLYPH_COPY(currY, currY + r0, currX, currX + 8, unkStruct->unk0); temp = currX + 8; @@ -544,6 +546,7 @@ void CopyGlyphToWindow(struct TextPrinter *textPrinter) } else { + u32 temp; GLYPH_COPY(currY, currY + 8, currX, currX + 8, unkStruct->unk0); temp = currX + 8; @@ -560,6 +563,711 @@ void CopyGlyphToWindow(struct TextPrinter *textPrinter) } } } +#else +NAKED +void CopyGlyphToWindow(struct TextPrinter *x) +{ + asm("push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, #0x8C\n\ + add r3, r0, #0\n\ + ldrb r1, [r3, #0x4]\n\ + lsl r0, r1, #1\n\ + add r0, r1\n\ + lsl r0, #2\n\ + ldr r1, =gWindows\n\ + add r1, r0, r1\n\ + add r2, r1, #0\n\ + ldrb r7, [r1, #0x3]\n\ + lsl r0, r7, #3\n\ + ldrb r6, [r3, #0x8]\n\ + sub r4, r0, r6\n\ + ldr r5, =gUnknown_03002F90\n\ + add r0, r5, #0\n\ + add r0, #0x80\n\ + ldrb r0, [r0]\n\ + cmp r4, r0\n\ + ble _08004DD2\n\ + add r4, r0, #0\n\ +_08004DD2:\n\ + ldrb r0, [r1, #0x4]\n\ + lsl r0, #3\n\ + ldrb r3, [r3, #0x9]\n\ + sub r0, r3\n\ + add r1, r5, #0\n\ + add r1, #0x81\n\ + ldrb r1, [r1]\n\ + cmp r0, r1\n\ + ble _08004DE6\n\ + add r0, r1, #0\n\ +_08004DE6:\n\ + str r6, [sp]\n\ + mov r8, r3\n\ + add r3, r5, #0\n\ + ldr r2, [r2, #0x8]\n\ + mov r9, r2\n\ + lsl r1, r7, #5\n\ + str r1, [sp, #0x4]\n\ + cmp r4, #0x8\n\ + ble _08004DFA\n\ + b _08004F94\n\ +_08004DFA:\n\ + cmp r0, #0x8\n\ + bgt _08004E84\n\ + mov r1, r8\n\ + str r3, [sp, #0x8]\n\ + add r2, r6, #0\n\ + add r2, r4\n\ + mov r8, r2\n\ + add r0, r1, r0\n\ + str r0, [sp, #0xC]\n\ + str r6, [sp, #0x10]\n\ + cmp r1, r0\n\ + bcc _08004E14\n\ + b _080052AA\n\ +_08004E14:\n\ + ldr r3, [sp, #0x8]\n\ + ldm r3!, {r5}\n\ + str r3, [sp, #0x8]\n\ + ldr r4, [sp, #0x10]\n\ + add r0, r1, #0x1\n\ + mov r10, r0\n\ + cmp r4, r8\n\ + bcs _08004E72\n\ + mov r2, #0x7\n\ + mov r12, r2\n\ + lsr r0, r1, #3\n\ + ldr r2, [sp, #0x4]\n\ + add r3, r0, #0\n\ + mul r3, r2\n\ + add r7, r3, #0\n\ + mov r3, r12\n\ + and r1, r3\n\ + lsl r6, r1, #2\n\ +_08004E38:\n\ + add r3, r5, #0\n\ + mov r0, #0xF\n\ + and r3, r0\n\ + cmp r3, #0\n\ + beq _08004E6A\n\ + lsr r2, r4, #3\n\ + lsl r2, #5\n\ + add r2, r9\n\ + add r0, r4, #0\n\ + mov r1, r12\n\ + and r0, r1\n\ + lsr r0, #1\n\ + add r2, r0\n\ + add r2, r7\n\ + add r2, r6\n\ + mov r1, #0x1\n\ + and r1, r4\n\ + lsl r1, #2\n\ + lsl r3, r1\n\ + mov r0, #0xF0\n\ + asr r0, r1\n\ + ldrb r1, [r2]\n\ + and r0, r1\n\ + orr r3, r0\n\ + strb r3, [r2]\n\ +_08004E6A:\n\ + lsr r5, #4\n\ + add r4, #0x1\n\ + cmp r4, r8\n\ + bcc _08004E38\n\ +_08004E72:\n\ + mov r1, r10\n\ + ldr r2, [sp, #0xC]\n\ + cmp r1, r2\n\ + bcc _08004E14\n\ + b _080052AA\n\ + .pool\n\ +_08004E84:\n\ + mov r1, r8\n\ + str r3, [sp, #0x14]\n\ + ldr r3, [sp]\n\ + add r3, r4\n\ + mov r12, r3\n\ + add r2, r1, #0\n\ + add r2, #0x8\n\ + str r2, [sp, #0x18]\n\ + ldr r3, [sp]\n\ + str r3, [sp, #0x1C]\n\ + mov r2, r12\n\ + str r2, [sp, #0x74]\n\ + ldr r3, [sp, #0x18]\n\ + str r3, [sp, #0x88]\n\ + sub r0, #0x8\n\ + str r0, [sp, #0x80]\n\ + cmp r1, r3\n\ + bcs _08004F0E\n\ +_08004EA8:\n\ + ldr r0, [sp, #0x14]\n\ + ldm r0!, {r5}\n\ + str r0, [sp, #0x14]\n\ + ldr r4, [sp, #0x1C]\n\ + add r2, r1, #0x1\n\ + mov r8, r2\n\ + cmp r4, r12\n\ + bcs _08004F06\n\ + mov r3, #0x7\n\ + mov r10, r3\n\ + lsr r0, r1, #3\n\ + ldr r3, [sp, #0x4]\n\ + add r2, r0, #0\n\ + mul r2, r3\n\ + add r7, r2, #0\n\ + mov r0, r10\n\ + and r1, r0\n\ + lsl r6, r1, #2\n\ +_08004ECC:\n\ + add r3, r5, #0\n\ + mov r1, #0xF\n\ + and r3, r1\n\ + cmp r3, #0\n\ + beq _08004EFE\n\ + lsr r2, r4, #3\n\ + lsl r2, #5\n\ + add r2, r9\n\ + add r0, r4, #0\n\ + mov r1, r10\n\ + and r0, r1\n\ + lsr r0, #1\n\ + add r2, r0\n\ + add r2, r7\n\ + add r2, r6\n\ + mov r1, #0x1\n\ + and r1, r4\n\ + lsl r1, #2\n\ + lsl r3, r1\n\ + mov r0, #0xF0\n\ + asr r0, r1\n\ + ldrb r1, [r2]\n\ + and r0, r1\n\ + orr r3, r0\n\ + strb r3, [r2]\n\ +_08004EFE:\n\ + lsr r5, #4\n\ + add r4, #0x1\n\ + cmp r4, r12\n\ + bcc _08004ECC\n\ +_08004F06:\n\ + mov r1, r8\n\ + ldr r2, [sp, #0x18]\n\ + cmp r1, r2\n\ + bcc _08004EA8\n\ +_08004F0E:\n\ + ldr r1, [sp, #0x88]\n\ + ldr r3, =gUnknown_03002F90 + 0x40\n\ + str r3, [sp, #0x20]\n\ + ldr r0, [sp, #0x74]\n\ + mov r8, r0\n\ + ldr r2, [sp, #0x80]\n\ + add r2, r1, r2\n\ + str r2, [sp, #0x24]\n\ + ldr r3, [sp]\n\ + str r3, [sp, #0x28]\n\ + cmp r1, r2\n\ + bcc _08004F28\n\ + b _080052AA\n\ +_08004F28:\n\ + ldr r0, [sp, #0x20]\n\ + ldm r0!, {r5}\n\ + str r0, [sp, #0x20]\n\ + ldr r4, [sp, #0x28]\n\ + add r2, r1, #0x1\n\ + mov r10, r2\n\ + cmp r4, r8\n\ + bcs _08004F86\n\ + mov r3, #0x7\n\ + mov r12, r3\n\ + lsr r0, r1, #3\n\ + ldr r3, [sp, #0x4]\n\ + add r2, r0, #0\n\ + mul r2, r3\n\ + add r7, r2, #0\n\ + mov r0, r12\n\ + and r1, r0\n\ + lsl r6, r1, #2\n\ +_08004F4C:\n\ + add r3, r5, #0\n\ + mov r1, #0xF\n\ + and r3, r1\n\ + cmp r3, #0\n\ + beq _08004F7E\n\ + lsr r2, r4, #3\n\ + lsl r2, #5\n\ + add r2, r9\n\ + add r0, r4, #0\n\ + mov r1, r12\n\ + and r0, r1\n\ + lsr r0, #1\n\ + add r2, r0\n\ + add r2, r7\n\ + add r2, r6\n\ + mov r1, #0x1\n\ + and r1, r4\n\ + lsl r1, #2\n\ + lsl r3, r1\n\ + mov r0, #0xF0\n\ + asr r0, r1\n\ + ldrb r1, [r2]\n\ + and r0, r1\n\ + orr r3, r0\n\ + strb r3, [r2]\n\ +_08004F7E:\n\ + lsr r5, #4\n\ + add r4, #0x1\n\ + cmp r4, r8\n\ + bcc _08004F4C\n\ +_08004F86:\n\ + mov r1, r10\n\ + ldr r2, [sp, #0x24]\n\ + cmp r1, r2\n\ + bcc _08004F28\n\ + b _080052AA\n\ + .pool\n\ +_08004F94:\n\ + cmp r0, #0x8\n\ + ble _08004F9A\n\ + b _080050A4\n\ +_08004F9A:\n\ + mov r1, r8\n\ + str r3, [sp, #0x2C]\n\ + ldr r3, [sp]\n\ + add r3, #0x8\n\ + mov r12, r3\n\ + add r0, r8\n\ + str r0, [sp, #0x30]\n\ + ldr r0, [sp]\n\ + str r0, [sp, #0x34]\n\ + ldr r2, [sp, #0x30]\n\ + str r2, [sp, #0x78]\n\ + str r3, [sp, #0x84]\n\ + sub r4, #0x8\n\ + str r4, [sp, #0x7C]\n\ + cmp r8, r2\n\ + bcs _0800501C\n\ +_08004FBA:\n\ + ldr r0, [sp, #0x2C]\n\ + ldm r0!, {r5}\n\ + str r0, [sp, #0x2C]\n\ + ldr r4, [sp, #0x34]\n\ + add r2, r1, #0x1\n\ + mov r10, r2\n\ + cmp r4, r12\n\ + bcs _08005014\n\ + lsr r0, r1, #3\n\ + ldr r2, [sp, #0x4]\n\ + add r3, r0, #0\n\ + mul r3, r2\n\ + add r7, r3, #0\n\ + mov r3, #0x7\n\ + and r1, r3\n\ + lsl r6, r1, #2\n\ +_08004FDA:\n\ + add r3, r5, #0\n\ + mov r0, #0xF\n\ + and r3, r0\n\ + cmp r3, #0\n\ + beq _0800500C\n\ + lsr r2, r4, #3\n\ + lsl r2, #5\n\ + add r2, r9\n\ + add r0, r4, #0\n\ + mov r1, #0x7\n\ + and r0, r1\n\ + lsr r0, #1\n\ + add r2, r0\n\ + add r2, r7\n\ + add r2, r6\n\ + mov r1, #0x1\n\ + and r1, r4\n\ + lsl r1, #2\n\ + lsl r3, r1\n\ + mov r0, #0xF0\n\ + asr r0, r1\n\ + ldrb r1, [r2]\n\ + and r0, r1\n\ + orr r3, r0\n\ + strb r3, [r2]\n\ +_0800500C:\n\ + lsr r5, #4\n\ + add r4, #0x1\n\ + cmp r4, r12\n\ + bcc _08004FDA\n\ +_08005014:\n\ + mov r1, r10\n\ + ldr r2, [sp, #0x30]\n\ + cmp r1, r2\n\ + bcc _08004FBA\n\ +_0800501C:\n\ + mov r1, r8\n\ + ldr r3, =gUnknown_03002F90 + 0x20\n\ + str r3, [sp, #0x38]\n\ + ldr r0, [sp, #0x84]\n\ + ldr r2, [sp, #0x7C]\n\ + add r0, r2\n\ + mov r8, r0\n\ + ldr r3, [sp, #0x78]\n\ + str r3, [sp, #0x3C]\n\ + ldr r0, [sp, #0x84]\n\ + str r0, [sp, #0x40]\n\ + cmp r1, r3\n\ + bcc _08005038\n\ + b _080052AA\n\ +_08005038:\n\ + ldr r2, [sp, #0x38]\n\ + ldm r2!, {r5}\n\ + str r2, [sp, #0x38]\n\ + ldr r4, [sp, #0x40]\n\ + add r3, r1, #0x1\n\ + mov r10, r3\n\ + cmp r4, r8\n\ + bcs _08005096\n\ + mov r0, #0x7\n\ + mov r12, r0\n\ + lsr r0, r1, #3\n\ + ldr r3, [sp, #0x4]\n\ + add r2, r0, #0\n\ + mul r2, r3\n\ + add r7, r2, #0\n\ + mov r0, r12\n\ + and r1, r0\n\ + lsl r6, r1, #2\n\ +_0800505C:\n\ + add r3, r5, #0\n\ + mov r1, #0xF\n\ + and r3, r1\n\ + cmp r3, #0\n\ + beq _0800508E\n\ + lsr r2, r4, #3\n\ + lsl r2, #5\n\ + add r2, r9\n\ + add r0, r4, #0\n\ + mov r1, r12\n\ + and r0, r1\n\ + lsr r0, #1\n\ + add r2, r0\n\ + add r2, r7\n\ + add r2, r6\n\ + mov r1, #0x1\n\ + and r1, r4\n\ + lsl r1, #2\n\ + lsl r3, r1\n\ + mov r0, #0xF0\n\ + asr r0, r1\n\ + ldrb r1, [r2]\n\ + and r0, r1\n\ + orr r3, r0\n\ + strb r3, [r2]\n\ +_0800508E:\n\ + lsr r5, #4\n\ + add r4, #0x1\n\ + cmp r4, r8\n\ + bcc _0800505C\n\ +_08005096:\n\ + mov r1, r10\n\ + ldr r2, [sp, #0x3C]\n\ + cmp r1, r2\n\ + bcc _08005038\n\ + b _080052AA\n\ + .pool\n\ +_080050A4:\n\ + mov r1, r8\n\ + str r5, [sp, #0x44]\n\ + ldr r3, [sp]\n\ + add r3, #0x8\n\ + mov r12, r3\n\ + mov r2, r8\n\ + add r2, #0x8\n\ + str r2, [sp, #0x48]\n\ + ldr r3, [sp]\n\ + str r3, [sp, #0x4C]\n\ + str r2, [sp, #0x88]\n\ + sub r0, #0x8\n\ + str r0, [sp, #0x80]\n\ + mov r0, r12\n\ + str r0, [sp, #0x84]\n\ + sub r4, #0x8\n\ + str r4, [sp, #0x7C]\n\ + cmp r8, r2\n\ + bcs _0800512C\n\ +_080050CA:\n\ + ldr r2, [sp, #0x44]\n\ + ldm r2!, {r5}\n\ + str r2, [sp, #0x44]\n\ + ldr r4, [sp, #0x4C]\n\ + add r3, r1, #0x1\n\ + mov r10, r3\n\ + cmp r4, r12\n\ + bcs _08005124\n\ + lsr r0, r1, #3\n\ + ldr r3, [sp, #0x4]\n\ + add r2, r0, #0\n\ + mul r2, r3\n\ + add r7, r2, #0\n\ + mov r0, #0x7\n\ + and r1, r0\n\ + lsl r6, r1, #2\n\ +_080050EA:\n\ + add r3, r5, #0\n\ + mov r1, #0xF\n\ + and r3, r1\n\ + cmp r3, #0\n\ + beq _0800511C\n\ + lsr r2, r4, #3\n\ + lsl r2, #5\n\ + add r2, r9\n\ + add r0, r4, #0\n\ + mov r1, #0x7\n\ + and r0, r1\n\ + lsr r0, #1\n\ + add r2, r0\n\ + add r2, r7\n\ + add r2, r6\n\ + mov r1, #0x1\n\ + and r1, r4\n\ + lsl r1, #2\n\ + lsl r3, r1\n\ + mov r0, #0xF0\n\ + asr r0, r1\n\ + ldrb r1, [r2]\n\ + and r0, r1\n\ + orr r3, r0\n\ + strb r3, [r2]\n\ +_0800511C:\n\ + lsr r5, #4\n\ + add r4, #0x1\n\ + cmp r4, r12\n\ + bcc _080050EA\n\ +_08005124:\n\ + mov r1, r10\n\ + ldr r2, [sp, #0x48]\n\ + cmp r1, r2\n\ + bcc _080050CA\n\ +_0800512C:\n\ + mov r1, r8\n\ + ldr r3, =gUnknown_03002F90 + 0x20\n\ + str r3, [sp, #0x50]\n\ + ldr r0, [sp, #0x84]\n\ + ldr r2, [sp, #0x7C]\n\ + add r0, r2\n\ + mov r8, r0\n\ + ldr r3, [sp, #0x88]\n\ + str r3, [sp, #0x54]\n\ + ldr r0, [sp, #0x84]\n\ + str r0, [sp, #0x58]\n\ + cmp r1, r3\n\ + bcs _080051AC\n\ +_08005146:\n\ + ldr r2, [sp, #0x50]\n\ + ldm r2!, {r5}\n\ + str r2, [sp, #0x50]\n\ + ldr r4, [sp, #0x58]\n\ + add r3, r1, #0x1\n\ + mov r10, r3\n\ + cmp r4, r8\n\ + bcs _080051A4\n\ + mov r0, #0x7\n\ + mov r12, r0\n\ + lsr r0, r1, #3\n\ + ldr r3, [sp, #0x4]\n\ + add r2, r0, #0\n\ + mul r2, r3\n\ + add r7, r2, #0\n\ + mov r0, r12\n\ + and r1, r0\n\ + lsl r6, r1, #2\n\ +_0800516A:\n\ + add r3, r5, #0\n\ + mov r1, #0xF\n\ + and r3, r1\n\ + cmp r3, #0\n\ + beq _0800519C\n\ + lsr r2, r4, #3\n\ + lsl r2, #5\n\ + add r2, r9\n\ + add r0, r4, #0\n\ + mov r1, r12\n\ + and r0, r1\n\ + lsr r0, #1\n\ + add r2, r0\n\ + add r2, r7\n\ + add r2, r6\n\ + mov r1, #0x1\n\ + and r1, r4\n\ + lsl r1, #2\n\ + lsl r3, r1\n\ + mov r0, #0xF0\n\ + asr r0, r1\n\ + ldrb r1, [r2]\n\ + and r0, r1\n\ + orr r3, r0\n\ + strb r3, [r2]\n\ +_0800519C:\n\ + lsr r5, #4\n\ + add r4, #0x1\n\ + cmp r4, r8\n\ + bcc _0800516A\n\ +_080051A4:\n\ + mov r1, r10\n\ + ldr r2, [sp, #0x54]\n\ + cmp r1, r2\n\ + bcc _08005146\n\ +_080051AC:\n\ + ldr r1, [sp, #0x88]\n\ + ldr r3, =gUnknown_03002F90 + 0x40\n\ + str r3, [sp, #0x5C]\n\ + ldr r0, [sp, #0x84]\n\ + mov r8, r0\n\ + ldr r2, [sp, #0x80]\n\ + add r2, r1, r2\n\ + str r2, [sp, #0x60]\n\ + ldr r3, [sp]\n\ + str r3, [sp, #0x64]\n\ + cmp r1, r2\n\ + bcs _0800522A\n\ +_080051C4:\n\ + ldr r0, [sp, #0x5C]\n\ + ldm r0!, {r5}\n\ + str r0, [sp, #0x5C]\n\ + ldr r4, [sp, #0x64]\n\ + add r2, r1, #0x1\n\ + mov r10, r2\n\ + cmp r4, r8\n\ + bcs _08005222\n\ + mov r3, #0x7\n\ + mov r12, r3\n\ + lsr r0, r1, #3\n\ + ldr r3, [sp, #0x4]\n\ + add r2, r0, #0\n\ + mul r2, r3\n\ + add r7, r2, #0\n\ + mov r0, r12\n\ + and r1, r0\n\ + lsl r6, r1, #2\n\ +_080051E8:\n\ + add r3, r5, #0\n\ + mov r1, #0xF\n\ + and r3, r1\n\ + cmp r3, #0\n\ + beq _0800521A\n\ + lsr r2, r4, #3\n\ + lsl r2, #5\n\ + add r2, r9\n\ + add r0, r4, #0\n\ + mov r1, r12\n\ + and r0, r1\n\ + lsr r0, #1\n\ + add r2, r0\n\ + add r2, r7\n\ + add r2, r6\n\ + mov r1, #0x1\n\ + and r1, r4\n\ + lsl r1, #2\n\ + lsl r3, r1\n\ + mov r0, #0xF0\n\ + asr r0, r1\n\ + ldrb r1, [r2]\n\ + and r0, r1\n\ + orr r3, r0\n\ + strb r3, [r2]\n\ +_0800521A:\n\ + lsr r5, #4\n\ + add r4, #0x1\n\ + cmp r4, r8\n\ + bcc _080051E8\n\ +_08005222:\n\ + mov r1, r10\n\ + ldr r2, [sp, #0x60]\n\ + cmp r1, r2\n\ + bcc _080051C4\n\ +_0800522A:\n\ + ldr r4, [sp, #0x84]\n\ + ldr r1, [sp, #0x88]\n\ + ldr r3, =gUnknown_03002F90 + 0x60\n\ + str r3, [sp, #0x68]\n\ + ldr r0, [sp, #0x7C]\n\ + add r0, r4\n\ + mov r8, r0\n\ + ldr r2, [sp, #0x80]\n\ + add r2, r1, r2\n\ + str r2, [sp, #0x6C]\n\ + str r4, [sp, #0x70]\n\ + cmp r1, r2\n\ + bcs _080052AA\n\ +_08005244:\n\ + ldr r3, [sp, #0x68]\n\ + ldm r3!, {r5}\n\ + str r3, [sp, #0x68]\n\ + ldr r4, [sp, #0x70]\n\ + add r0, r1, #0x1\n\ + mov r10, r0\n\ + cmp r4, r8\n\ + bcs _080052A2\n\ + mov r2, #0x7\n\ + mov r12, r2\n\ + lsr r0, r1, #3\n\ + ldr r2, [sp, #0x4]\n\ + add r3, r0, #0\n\ + mul r3, r2\n\ + add r7, r3, #0\n\ + mov r3, r12\n\ + and r1, r3\n\ + lsl r6, r1, #2\n\ +_08005268:\n\ + add r3, r5, #0\n\ + mov r0, #0xF\n\ + and r3, r0\n\ + cmp r3, #0\n\ + beq _0800529A\n\ + lsr r2, r4, #3\n\ + lsl r2, #5\n\ + add r2, r9\n\ + add r0, r4, #0\n\ + mov r1, r12\n\ + and r0, r1\n\ + lsr r0, #1\n\ + add r2, r0\n\ + add r2, r7\n\ + add r2, r6\n\ + mov r1, #0x1\n\ + and r1, r4\n\ + lsl r1, #2\n\ + lsl r3, r1\n\ + mov r0, #0xF0\n\ + asr r0, r1\n\ + ldrb r1, [r2]\n\ + and r0, r1\n\ + orr r3, r0\n\ + strb r3, [r2]\n\ +_0800529A:\n\ + lsr r5, #4\n\ + add r4, #0x1\n\ + cmp r4, r8\n\ + bcc _08005268\n\ +_080052A2:\n\ + mov r1, r10\n\ + ldr r2, [sp, #0x6C]\n\ + cmp r1, r2\n\ + bcc _08005244\n\ +_080052AA:\n\ + add sp, #0x8C\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool"); +} +#endif // NONMATCHING + void ClearTextSpan(struct TextPrinter *textPrinter, u32 width) { struct Window *window; @@ -575,7 +1283,7 @@ void ClearTextSpan(struct TextPrinter *textPrinter, u32 width) pixels_data.height = window->window.height << 3; gUnk = &gUnknown_03002F90; - glyphHeight = &gUnk->height; + glyphHeight = &gUnk->unk81; FillBitmapRect4Bit( &pixels_data, @@ -591,7 +1299,7 @@ u16 Font0Func(struct TextPrinter *textPrinter) { struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); - if (!subStruct->hasGlyphIdBeenSet) + if (subStruct->hasGlyphIdBeenSet == FALSE) { subStruct->glyphId = 0; subStruct->hasGlyphIdBeenSet = TRUE; @@ -603,7 +1311,7 @@ u16 Font1Func(struct TextPrinter *textPrinter) { struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); - if (!subStruct->hasGlyphIdBeenSet) + if (subStruct->hasGlyphIdBeenSet == FALSE) { subStruct->glyphId = 1; subStruct->hasGlyphIdBeenSet = TRUE; @@ -615,7 +1323,7 @@ u16 Font2Func(struct TextPrinter *textPrinter) { struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); - if (!subStruct->hasGlyphIdBeenSet) + if (subStruct->hasGlyphIdBeenSet == FALSE) { subStruct->glyphId = 2; subStruct->hasGlyphIdBeenSet = TRUE; @@ -627,7 +1335,7 @@ u16 Font3Func(struct TextPrinter *textPrinter) { struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); - if (!subStruct->hasGlyphIdBeenSet) + if (subStruct->hasGlyphIdBeenSet == FALSE) { subStruct->glyphId = 3; subStruct->hasGlyphIdBeenSet = TRUE; @@ -639,7 +1347,7 @@ u16 Font4Func(struct TextPrinter *textPrinter) { struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); - if (!subStruct->hasGlyphIdBeenSet) + if (subStruct->hasGlyphIdBeenSet == FALSE) { subStruct->glyphId = 4; subStruct->hasGlyphIdBeenSet = TRUE; @@ -651,7 +1359,7 @@ u16 Font5Func(struct TextPrinter *textPrinter) { struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); - if (!subStruct->hasGlyphIdBeenSet) + if (subStruct->hasGlyphIdBeenSet == FALSE) { subStruct->glyphId = 5; subStruct->hasGlyphIdBeenSet = TRUE; @@ -663,7 +1371,7 @@ u16 Font7Func(struct TextPrinter *textPrinter) { struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); - if (!subStruct->hasGlyphIdBeenSet) + if (subStruct->hasGlyphIdBeenSet == FALSE) { subStruct->glyphId = 7; subStruct->hasGlyphIdBeenSet = TRUE; @@ -675,7 +1383,7 @@ u16 Font8Func(struct TextPrinter *textPrinter) { struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); - if (!subStruct->hasGlyphIdBeenSet) + if (subStruct->hasGlyphIdBeenSet == FALSE) { subStruct->glyphId = 8; subStruct->hasGlyphIdBeenSet = TRUE; @@ -687,7 +1395,7 @@ void TextPrinterInitDownArrowCounters(struct TextPrinter *textPrinter) { struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); - if (gTextFlags.autoScroll == TRUE) + if (gTextFlags.autoScroll == 1) { subStruct->autoScrollDelay = 0; } @@ -703,7 +1411,7 @@ void TextPrinterDrawDownArrow(struct TextPrinter *textPrinter) struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); const u8 *arrowTiles; - if (!gTextFlags.autoScroll) + if (gTextFlags.autoScroll == 0) { if (subStruct->downArrowDelay != 0) { @@ -779,14 +1487,14 @@ bool8 TextPrinterWaitAutoMode(struct TextPrinter *textPrinter) bool16 TextPrinterWaitWithDownArrow(struct TextPrinter *textPrinter) { bool8 result = FALSE; - if (gTextFlags.autoScroll) + if (gTextFlags.autoScroll != 0) { result = TextPrinterWaitAutoMode(textPrinter); } else { TextPrinterDrawDownArrow(textPrinter); - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { result = TRUE; PlaySE(SE_SELECT); @@ -798,14 +1506,17 @@ bool16 TextPrinterWaitWithDownArrow(struct TextPrinter *textPrinter) bool16 TextPrinterWait(struct TextPrinter *textPrinter) { bool16 result = FALSE; - if (gTextFlags.autoScroll) + if (gTextFlags.autoScroll != 0) { result = TextPrinterWaitAutoMode(textPrinter); } - else if (JOY_NEW(A_BUTTON | B_BUTTON)) + else { - result = TRUE; - PlaySE(SE_SELECT); + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) + { + result = TRUE; + PlaySE(SE_SELECT); + } } return result; } @@ -821,7 +1532,7 @@ void DrawDownArrow(u8 windowId, u16 x, u16 y, u8 bgColor, bool8 drawArrow, u8 *c else { FillWindowPixelRect(windowId, (bgColor << 4) | bgColor, x, y, 0x8, 0x10); - if (!drawArrow) + if (drawArrow == 0) { switch (gTextFlags.useAlternateDownArrow) { @@ -862,13 +1573,13 @@ u16 RenderText(struct TextPrinter *textPrinter) switch (textPrinter->state) { case 0: - if ((JOY_HELD(A_BUTTON | B_BUTTON)) && subStruct->hasPrintBeenSpedUp) + if ((gMain.heldKeys & (A_BUTTON | B_BUTTON)) && subStruct->hasPrintBeenSpedUp) textPrinter->delayCounter = 0; if (textPrinter->delayCounter && textPrinter->textSpeed) { textPrinter->delayCounter--; - if (gTextFlags.canABSpeedUpPrint && (JOY_NEW(A_BUTTON | B_BUTTON))) + if (gTextFlags.canABSpeedUpPrint && (gMain.newKeys & (A_BUTTON | B_BUTTON))) { subStruct->hasPrintBeenSpedUp = TRUE; textPrinter->delayCounter = 0; @@ -1013,10 +1724,10 @@ u16 RenderText(struct TextPrinter *textPrinter) textPrinter->minLetterSpacing = *textPrinter->printerTemplate.currentChar++; return 2; case EXT_CTRL_CODE_JPN: - textPrinter->japanese = TRUE; + textPrinter->japanese = 1; return 2; case EXT_CTRL_CODE_ENG: - textPrinter->japanese = FALSE; + textPrinter->japanese = 0; return 2; } break; @@ -1034,8 +1745,8 @@ u16 RenderText(struct TextPrinter *textPrinter) break; case CHAR_KEYPAD_ICON: currChar = *textPrinter->printerTemplate.currentChar++; - gUnknown_03002F90.width = DrawKeypadIcon(textPrinter->printerTemplate.windowId, currChar, textPrinter->printerTemplate.currentX, textPrinter->printerTemplate.currentY); - textPrinter->printerTemplate.currentX += gUnknown_03002F90.width + textPrinter->printerTemplate.letterSpacing; + gUnknown_03002F90.unk80 = DrawKeypadIcon(textPrinter->printerTemplate.windowId, currChar, textPrinter->printerTemplate.currentX, textPrinter->printerTemplate.currentY); + textPrinter->printerTemplate.currentX += gUnknown_03002F90.unk80 + textPrinter->printerTemplate.letterSpacing; return 0; case EOS: return 1; @@ -1069,18 +1780,21 @@ u16 RenderText(struct TextPrinter *textPrinter) if (textPrinter->minLetterSpacing) { - textPrinter->printerTemplate.currentX += gUnknown_03002F90.width; - width = textPrinter->minLetterSpacing - gUnknown_03002F90.width; + textPrinter->printerTemplate.currentX += gUnknown_03002F90.unk80; + width = textPrinter->minLetterSpacing - gUnknown_03002F90.unk80; if (width > 0) { ClearTextSpan(textPrinter, width); textPrinter->printerTemplate.currentX += width; } } - else if (textPrinter->japanese) - textPrinter->printerTemplate.currentX += (gUnknown_03002F90.width + textPrinter->printerTemplate.letterSpacing); else - textPrinter->printerTemplate.currentX += gUnknown_03002F90.width; + { + if (textPrinter->japanese) + textPrinter->printerTemplate.currentX += (gUnknown_03002F90.unk80 + textPrinter->printerTemplate.letterSpacing); + else + textPrinter->printerTemplate.currentX += gUnknown_03002F90.unk80; + } return 0; case 1: if (TextPrinterWait(textPrinter)) @@ -1566,7 +2280,7 @@ void SetDefaultFontsPointer(void) u8 GetFontAttribute(u8 fontId, u8 attributeId) { - u8 result = 0; + int result = 0; switch (attributeId) { case FONTATTR_MAX_LETTER_WIDTH: @@ -1581,8 +2295,8 @@ u8 GetFontAttribute(u8 fontId, u8 attributeId) case FONTATTR_LINE_SPACING: result = gFontInfos[fontId].lineSpacing; break; - case FONTATTR_STYLE: - result = gFontInfos[fontId].style; + case FONTATTR_UNKNOWN: + result = gFontInfos[fontId].unk; break; case FONTATTR_COLOR_FOREGROUND: result = gFontInfos[fontId].fgColor; @@ -1611,15 +2325,15 @@ void DecompressGlyphFont0(u16 glyphId, bool32 isJapanese) glyphs = gFont0JapaneseGlyphs + (0x100 * (glyphId >> 0x4)) + (0x8 * (glyphId & 0xF)); DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); DecompressGlyphTile(glyphs + 0x80, gUnknown_03002F90.unk40); // gUnknown_03002F90 + 0x40 - gUnknown_03002F90.width = 8; // gGlyphWidth - gUnknown_03002F90.height = 12; // gGlyphHeight + gUnknown_03002F90.unk80 = 8; // gGlyphWidth + gUnknown_03002F90.unk81 = 12; // gGlyphHeight } else { glyphs = gFont0LatinGlyphs + (0x20 * glyphId); - gUnknown_03002F90.width = gFont0LatinGlyphWidths[glyphId]; + gUnknown_03002F90.unk80 = gFont0LatinGlyphWidths[glyphId]; - if (gUnknown_03002F90.width <= 8) + if (gUnknown_03002F90.unk80 <= 8) { DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); DecompressGlyphTile(glyphs + 0x10, gUnknown_03002F90.unk40); @@ -1632,7 +2346,7 @@ void DecompressGlyphFont0(u16 glyphId, bool32 isJapanese) DecompressGlyphTile(glyphs + 0x18, gUnknown_03002F90.unk60); } - gUnknown_03002F90.height = 13; + gUnknown_03002F90.unk81 = 13; } } @@ -1654,15 +2368,15 @@ void DecompressGlyphFont7(u16 glyphId, bool32 isJapanese) glyphs = gFont1JapaneseGlyphs + (0x100 * (glyphId >> 0x4)) + (0x8 * (glyphId & (eff = 0xF))); // shh, no questions, only matching now DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); DecompressGlyphTile(glyphs + 0x80, gUnknown_03002F90.unk40); // gUnknown_03002F90 + 0x40 - gUnknown_03002F90.width = 8; // gGlyphWidth - gUnknown_03002F90.height = 15; // gGlyphHeight + gUnknown_03002F90.unk80 = 8; // gGlyphWidth + gUnknown_03002F90.unk81 = 15; // gGlyphHeight } else { glyphs = gFont7LatinGlyphs + (0x20 * glyphId); - gUnknown_03002F90.width = gFont7LatinGlyphWidths[glyphId]; + gUnknown_03002F90.unk80 = gFont7LatinGlyphWidths[glyphId]; - if (gUnknown_03002F90.width <= 8) + if (gUnknown_03002F90.unk80 <= 8) { DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); DecompressGlyphTile(glyphs + 0x10, gUnknown_03002F90.unk40); @@ -1675,7 +2389,7 @@ void DecompressGlyphFont7(u16 glyphId, bool32 isJapanese) DecompressGlyphTile(glyphs + 0x18, gUnknown_03002F90.unk60); } - gUnknown_03002F90.height = 15; + gUnknown_03002F90.unk81 = 15; } } @@ -1696,15 +2410,15 @@ void DecompressGlyphFont8(u16 glyphId, bool32 isJapanese) glyphs = gFont0JapaneseGlyphs + (0x100 * (glyphId >> 0x4)) + (0x8 * (glyphId & 0xF)); DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); DecompressGlyphTile(glyphs + 0x80, gUnknown_03002F90.unk40); // gUnknown_03002F90 + 0x40 - gUnknown_03002F90.width = 8; // gGlyphWidth - gUnknown_03002F90.height = 12; // gGlyphHeight + gUnknown_03002F90.unk80 = 8; // gGlyphWidth + gUnknown_03002F90.unk81 = 12; // gGlyphHeight } else { glyphs = gFont8LatinGlyphs + (0x20 * glyphId); - gUnknown_03002F90.width = gFont8LatinGlyphWidths[glyphId]; + gUnknown_03002F90.unk80 = gFont8LatinGlyphWidths[glyphId]; - if (gUnknown_03002F90.width <= 8) + if (gUnknown_03002F90.unk80 <= 8) { DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); DecompressGlyphTile(glyphs + 0x10, gUnknown_03002F90.unk40); @@ -1717,7 +2431,7 @@ void DecompressGlyphFont8(u16 glyphId, bool32 isJapanese) DecompressGlyphTile(glyphs + 0x18, gUnknown_03002F90.unk60); } - gUnknown_03002F90.height = 12; + gUnknown_03002F90.unk81 = 12; } } @@ -1737,18 +2451,18 @@ void DecompressGlyphFont2(u16 glyphId, bool32 isJapanese) { glyphs = gFont2JapaneseGlyphs + (0x100 * (glyphId >> 0x3)) + (0x10 * (glyphId & 0x7)); DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); - DecompressGlyphTile(glyphs + 0x8, gUnknown_03002F90.unk20); - DecompressGlyphTile(glyphs + 0x80, gUnknown_03002F90.unk40); - DecompressGlyphTile(glyphs + 0x88, gUnknown_03002F90.unk60); - gUnknown_03002F90.width = gFont2JapaneseGlyphWidths[glyphId]; // gGlyphWidth - gUnknown_03002F90.height = 14; // gGlyphHeight + DecompressGlyphTile(glyphs + 0x8, gUnknown_03002F90.unk20); // gUnknown_03002F90 + 0x40 + DecompressGlyphTile(glyphs + 0x80, gUnknown_03002F90.unk40); // gUnknown_03002F90 + 0x20 + DecompressGlyphTile(glyphs + 0x88, gUnknown_03002F90.unk60); // gUnknown_03002F90 + 0x60 + gUnknown_03002F90.unk80 = gFont2JapaneseGlyphWidths[glyphId]; // gGlyphWidth + gUnknown_03002F90.unk81 = 14; // gGlyphHeight } else { glyphs = gFont2LatinGlyphs + (0x20 * glyphId); - gUnknown_03002F90.width = gFont2LatinGlyphWidths[glyphId]; + gUnknown_03002F90.unk80 = gFont2LatinGlyphWidths[glyphId]; - if (gUnknown_03002F90.width <= 8) + if (gUnknown_03002F90.unk80 <= 8) { DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); DecompressGlyphTile(glyphs + 0x10, gUnknown_03002F90.unk40); @@ -1761,7 +2475,7 @@ void DecompressGlyphFont2(u16 glyphId, bool32 isJapanese) DecompressGlyphTile(glyphs + 0x18, gUnknown_03002F90.unk60); } - gUnknown_03002F90.height = 14; + gUnknown_03002F90.unk81 = 14; } } @@ -1783,15 +2497,15 @@ void DecompressGlyphFont1(u16 glyphId, bool32 isJapanese) glyphs = gFont1JapaneseGlyphs + (0x100 * (glyphId >> 0x4)) + (0x8 * (glyphId & (eff = 0xF))); // shh, no questions, only matching now DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); DecompressGlyphTile(glyphs + 0x80, gUnknown_03002F90.unk40); // gUnknown_03002F90 + 0x40 - gUnknown_03002F90.width = 8; // gGlyphWidth - gUnknown_03002F90.height = 15; // gGlyphHeight + gUnknown_03002F90.unk80 = 8; // gGlyphWidth + gUnknown_03002F90.unk81 = 15; // gGlyphHeight } else { glyphs = gFont1LatinGlyphs + (0x20 * glyphId); - gUnknown_03002F90.width = gFont1LatinGlyphWidths[glyphId]; + gUnknown_03002F90.unk80 = gFont1LatinGlyphWidths[glyphId]; - if (gUnknown_03002F90.width <= 8) + if (gUnknown_03002F90.unk80 <= 8) { DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); DecompressGlyphTile(glyphs + 0x10, gUnknown_03002F90.unk40); @@ -1804,7 +2518,7 @@ void DecompressGlyphFont1(u16 glyphId, bool32 isJapanese) DecompressGlyphTile(glyphs + 0x18, gUnknown_03002F90.unk60); } - gUnknown_03002F90.height = 15; + gUnknown_03002F90.unk81 = 15; } } @@ -1823,6 +2537,6 @@ void DecompressGlyphFont9(u16 glyphId) glyphs = gFont9JapaneseGlyphs + (0x100 * (glyphId >> 4)) + (0x8 * (glyphId & 0xF)); DecompressGlyphTile(glyphs, gUnknown_03002F90.unk0); DecompressGlyphTile(glyphs + 0x80, gUnknown_03002F90.unk40); - gUnknown_03002F90.width = 8; - gUnknown_03002F90.height = 12; + gUnknown_03002F90.unk80 = 8; + gUnknown_03002F90.unk81 = 12; } diff --git a/gflib/text.h b/gflib/text.h index 4cf5bc20b9..ba74cde6e 100644 --- a/gflib/text.h +++ b/gflib/text.h @@ -269,20 +269,13 @@ #define TEXT_SPEED_FF 0xFF -enum -{ - COLOR_FOREGROUND, - COLOR_SHADOW, - COLOR_BACKGROUND -}; - enum { FONTATTR_MAX_LETTER_WIDTH, FONTATTR_MAX_LETTER_HEIGHT, FONTATTR_LETTER_SPACING, FONTATTR_LINE_SPACING, - FONTATTR_STYLE, + FONTATTR_UNKNOWN, // dunno what this is yet FONTATTR_COLOR_FOREGROUND, FONTATTR_COLOR_BACKGROUND, FONTATTR_COLOR_SHADOW @@ -310,7 +303,7 @@ struct TextPrinterTemplate u8 currentY; u8 letterSpacing; u8 lineSpacing; - u8 style:4; // 0xC + u8 unk:4; // 0xC u8 fgColor:4; u8 bgColor:4; u8 shadowColor:4; @@ -329,7 +322,7 @@ struct TextPrinter u8 delayCounter; u8 scrollDistance; u8 minLetterSpacing; // 0x20 - bool8 japanese; + u8 japanese; }; struct FontInfo @@ -339,7 +332,7 @@ struct FontInfo u8 maxLetterHeight; u8 letterSpacing; u8 lineSpacing; - u8 style:4; //unused + u8 unk:4; u8 fgColor:4; u8 bgColor:4; u8 shadowColor:4; @@ -373,13 +366,13 @@ struct Struct_03002F90 u32 unk20[8]; u32 unk40[8]; u32 unk60[8]; - u8 width; - u8 height; + u8 unk80; + u8 unk81; }; extern TextFlags gTextFlags; -extern bool8 gUnknown_03002F84; +extern u8 gUnknown_03002F84; extern struct Struct_03002F90 gUnknown_03002F90; void SetFontsPointer(const struct FontInfo *fonts); diff --git a/gflib/window.c b/gflib/window.c index 0be59773c..7c87ea86d 100644 --- a/gflib/window.c +++ b/gflib/window.c @@ -30,18 +30,21 @@ static void nullsub_8(void) bool16 InitWindows(const struct WindowTemplate *templates) { - int i, j; - u8* allocatedTilemapBuffer; - u16 attrib; - int allocatedBaseBlock; + int i; + void *bgTilemapBuffer; + int j; u8 bgLayer; + u16 attrib; + u8* allocatedTilemapBuffer; + int allocatedBaseBlock; for (i = 0; i < 0x4; ++i) { - if (GetBgTilemapBuffer(i) != NULL) + bgTilemapBuffer = GetBgTilemapBuffer(i); + if (bgTilemapBuffer != NULL) gUnknown_03002F70[i] = nullsub_8; else - gUnknown_03002F70[i] = NULL; + gUnknown_03002F70[i] = bgTilemapBuffer; } for (i = 0; i < 0x20; ++i) @@ -564,19 +567,19 @@ u32 GetWindowAttribute(u8 windowId, u8 attributeId) switch (attributeId) { case WINDOW_BG: - return (u32)gWindows[windowId].window.bg; + return gWindows[windowId].window.bg; case WINDOW_TILEMAP_LEFT: - return (u32)gWindows[windowId].window.tilemapLeft; + return gWindows[windowId].window.tilemapLeft; case WINDOW_TILEMAP_TOP: - return (u32)gWindows[windowId].window.tilemapTop; + return gWindows[windowId].window.tilemapTop; case WINDOW_WIDTH: - return (u32)gWindows[windowId].window.width; + return gWindows[windowId].window.width; case WINDOW_HEIGHT: - return (u32)gWindows[windowId].window.height; + return gWindows[windowId].window.height; case WINDOW_PALETTE_NUM: - return (u32)gWindows[windowId].window.paletteNum; + return gWindows[windowId].window.paletteNum; case WINDOW_BASE_BLOCK: - return (u32)gWindows[windowId].window.baseBlock; + return gWindows[windowId].window.baseBlock; case WINDOW_TILE_DATA: return (u32)(gWindows[windowId].tileData); default: @@ -640,9 +643,12 @@ u16 AddWindow8Bit(const struct WindowTemplate *template) } return 0xFF; } - gWindows[windowId].tileData = memAddress; - gWindows[windowId].window = *template; - return windowId; + else + { + gWindows[windowId].tileData = memAddress; + gWindows[windowId].window = *template; + return windowId; + } } void FillWindowPixelBuffer8Bit(u8 windowId, u8 fillValue) diff --git a/include/AgbRfu_LinkManager.h b/include/AgbRfu_LinkManager.h index 4e1a879c2..d4ef13183 100644 --- a/include/AgbRfu_LinkManager.h +++ b/include/AgbRfu_LinkManager.h @@ -176,8 +176,8 @@ typedef struct linkManagerTag /* 0x024 */ VBL_TIMER nameAcceptTimer; /* 0x030 */ VBL_TIMER linkRecoveryTimer; /* 0x03c */ INIT_PARAM *init_param; - /* 0x040 */ void (*LMAN_callback)(u8 msg, u8 paramCount); - /* 0x044 */ void (*MSC_callback)(u16 REQ_commandID); + /* 0x040 */ void (*LMAN_callback)(u8, u8); + /* 0x044 */ void (*MSC_callback)(u16); } LINK_MANAGER; extern struct linkManagerTag lman; diff --git a/include/battle.h b/include/battle.h index 5a04c1eec..6dddfd197 100644 --- a/include/battle.h +++ b/include/battle.h @@ -124,22 +124,22 @@ struct ProtectStruct u32 flinchImmobility:1; u32 notFirstStrike:1; u32 palaceUnableToUseMove:1; - s32 physicalDmg; - s32 specialDmg; + u32 physicalDmg; + u32 specialDmg; u8 physicalBattlerId; u8 specialBattlerId; }; struct SpecialStatus { - u32 statLowered:1; - u32 lightningRodRedirected:1; - u32 restoredBattlerSprite: 1; - u32 intimidatedMon:1; - u32 traced:1; - u32 ppNotAffectedByPressure:1; - u32 flag40:1; - u32 focusBanded:1; + u8 statLowered:1; + u8 lightningRodRedirected:1; + u8 restoredBattlerSprite: 1; + u8 intimidatedMon:1; + u8 traced:1; + u8 ppNotAffectedByPressure:1; + u8 flag40:1; + u8 focusBanded:1; s32 dmg; s32 physicalDmg; s32 specialDmg; @@ -254,7 +254,7 @@ struct BattleResults u16 playerMon2Species; // 0x26 u16 caughtMonSpecies; // 0x28 u8 caughtMonNick[POKEMON_NAME_LENGTH + 1]; // 0x2A - u8 filler35; // 0x35 + u8 filler35[1]; // 0x35 u8 catchAttempts[11]; // 0x36 }; diff --git a/include/battle_main.h b/include/battle_main.h index 0176f7f24..890e47f39 100644 --- a/include/battle_main.h +++ b/include/battle_main.h @@ -73,6 +73,8 @@ void nullsub_20(void); void BeginBattleIntro(void); void SwitchInClearSetData(void); void FaintClearSetData(void); +void sub_803B3AC(void); // unused +void sub_803B598(void); // unused void BattleTurnPassed(void); u8 IsRunningFromBattleImpossible(void); void SwitchPartyOrder(u8 battlerId); @@ -81,7 +83,6 @@ u8 GetWhoStrikesFirst(u8 battlerId1, u8 battlerId2, bool8 ignoreChosenMoves); void RunBattleScriptCommands_PopCallbacksStack(void); void RunBattleScriptCommands(void); bool8 TryRunFromBattle(u8 battlerId); -void SpecialStatusesClear(void); extern struct UnknownPokemonStruct4 gMultiPartnerParty[MULTI_PARTY_SIZE]; diff --git a/include/battle_message.h b/include/battle_message.h index af090a06c..011a1cb0c 100644 --- a/include/battle_message.h +++ b/include/battle_message.h @@ -145,7 +145,7 @@ { \ textVar[0] = B_BUFF_PLACEHOLDER_BEGIN; \ textVar[1] = B_BUFF_STRING; \ - textVar[2] = (stringId & 0xFF); \ + textVar[2] = stringId; \ textVar[3] = (stringId & 0xFF00) >> 8; \ textVar[4] = B_BUFF_EOS; \ } diff --git a/include/battle_util.h b/include/battle_util.h index 81443f463..157ba8eb6 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -41,19 +41,6 @@ #define WEATHER_HAS_EFFECT ((!ABILITY_ON_FIELD(ABILITY_CLOUD_NINE) && !ABILITY_ON_FIELD(ABILITY_AIR_LOCK))) #define WEATHER_HAS_EFFECT2 ((!ABILITY_ON_FIELD2(ABILITY_CLOUD_NINE) && !ABILITY_ON_FIELD2(ABILITY_AIR_LOCK))) -void HandleAction_UseMove(void); -void HandleAction_Switch(void); -void HandleAction_UseItem(void); -void HandleAction_Run(void); -void HandleAction_WatchesCarefully(void); -void HandleAction_SafariZoneBallThrow(void); -void HandleAction_ThrowPokeblock(void); -void HandleAction_GoNear(void); -void HandleAction_SafariZoneRun(void); -void HandleAction_WallyBallThrow(void); -void HandleAction_TryFinish(void); -void HandleAction_NothingIsFainted(void); -void HandleAction_ActionFinished(void); u8 GetBattlerForBattleScript(u8 caseId); void PressurePPLose(u8 target, u8 attacker, u16 move); void PressurePPLoseOnUsingPerishSong(u8 attacker); diff --git a/include/constants/battle.h b/include/constants/battle.h index fa8f422c4..8b860e384 100644 --- a/include/constants/battle.h +++ b/include/constants/battle.h @@ -186,7 +186,7 @@ #define HITMARKER_x4000000 (1 << 26) #define HITMARKER_CHARGING (1 << 27) #define HITMARKER_FAINTED(battler) (gBitTable[battler] << 28) -#define HITMARKER_FAINTED2(battler) ((1 << 28) << battler) +#define HITMARKER_FAINTED2(battler) (1 << (28 + battler)) // Per-side statuses that affect an entire party #define SIDE_STATUS_REFLECT (1 << 0) diff --git a/include/constants/battle_pyramid.h b/include/constants/battle_pyramid.h index 378197a4d..004df7155 100644 --- a/include/constants/battle_pyramid.h +++ b/include/constants/battle_pyramid.h @@ -7,6 +7,16 @@ #define FLOOR_WALKABLE_METATILE 0x28D #define FLOOR_EXIT_METATILE 0x28E +#define HINT_EXIT_DIRECTION 0 +#define HINT_REMAINING_ITEMS 1 +#define HINT_REMAINING_TRAINERS 2 +#define HINT_EXIT_SHORT_REMAINING_TRAINERS 3 +#define HINT_EXIT_SHORT_REMAINING_ITEMS 4 +#define HINT_EXIT_MEDIUM_REMAINING_TRAINERS 5 +#define HINT_EXIT_MEDIUM_REMAINING_ITEMS 6 +#define HINT_EXIT_FAR_REMAINING_TRAINERS 7 +#define HINT_EXIT_FAR_REMAINING_ITEMS 8 + #define OBJ_TRAINERS 0 #define OBJ_ITEMS 1 diff --git a/include/constants/rgb.h b/include/constants/rgb.h index 1896250d2..80d951f4b 100644 --- a/include/constants/rgb.h +++ b/include/constants/rgb.h @@ -1,10 +1,6 @@ #ifndef GUARD_RGB_H #define GUARD_RGB_H -#define GET_R(color) ((color) & 0x1F) -#define GET_G(color) (((color) >> 5) & 0x1F) -#define GET_B(color) (((color) >> 10) & 0x1F) - #define RGB(r, g, b) ((r) | ((g) << 5) | ((b) << 10)) #define RGB2(r, g, b) (((b) << 10) | ((g) << 5) | (r)) #define _RGB(r, g, b) ((((b) & 0x1F) << 10) + (((g) & 0x1F) << 5) + ((r) & 0x1F)) diff --git a/include/gba/m4a_internal.h b/include/gba/m4a_internal.h index bdff1b865..e2836c6f6 100644 --- a/include/gba/m4a_internal.h +++ b/include/gba/m4a_internal.h @@ -140,13 +140,55 @@ struct SoundChannel struct WaveData *wav; u32 cp; struct MusicPlayerTrack *track; - void *pp; - void *np; - void *d4; + u32 pp; + u32 np; + u32 d4; u16 xpi; u16 xpc; }; +#define MAX_DIRECTSOUND_CHANNELS 12 + +#define PCM_DMA_BUF_SIZE 1584 // size of Direct Sound buffer + +struct SoundInfo +{ + // This field is normally equal to ID_NUMBER but it is set to other + // values during sensitive operations for locking purposes. + // This field should be volatile but isn't. This could potentially cause + // race conditions. + u32 ident; + + vu8 pcmDmaCounter; + + // Direct Sound + u8 reverb; + u8 maxChans; + u8 masterVolume; + u8 freq; + + u8 mode; + u8 c15; + u8 pcmDmaPeriod; // number of V-blanks per PCM DMA + u8 maxLines; + u8 gap[3]; + s32 pcmSamplesPerVBlank; + s32 pcmFreq; + s32 divFreq; + struct CgbChannel *cgbChans; + u32 func; + u32 intp; + void (*CgbSound)(void); + void (*CgbOscOff)(u8); + u32 (*MidiKeyToCgbFreq)(u8, u8, u8); + u32 MPlayJumpTable; + u32 plynote; + u32 ExtVolPit; + u8 gap2[16]; + struct SoundChannel chans[MAX_DIRECTSOUND_CHANNELS]; + s8 pcmBuffer[PCM_DMA_BUF_SIZE * 2]; +}; + struct SongHeader { u8 trackCount; @@ -270,7 +312,7 @@ struct MusicPlayerInfo struct MusicPlayerTrack *tracks; struct ToneData *tone; u32 ident; - void (*func)(); + u32 func; u32 intp; }; @@ -292,47 +334,7 @@ struct Song extern const struct MusicPlayer gMPlayTable[]; extern const struct Song gSongTable[]; -#define MAX_DIRECTSOUND_CHANNELS 12 -#define PCM_DMA_BUF_SIZE 1584 // size of Direct Sound buffer - -struct SoundInfo -{ - // This field is normally equal to ID_NUMBER but it is set to other - // values during sensitive operations for locking purposes. - // This field should be volatile but isn't. This could potentially cause - // race conditions. - u32 ident; - - vu8 pcmDmaCounter; - - // Direct Sound - u8 reverb; - u8 maxChans; - u8 masterVolume; - u8 freq; - - u8 mode; - u8 c15; - u8 pcmDmaPeriod; // number of V-blanks per PCM DMA - u8 maxLines; - u8 gap[3]; - s32 pcmSamplesPerVBlank; - s32 pcmFreq; - s32 divFreq; - struct CgbChannel *cgbChans; - void (*func)(); - u32 intp; - void (*CgbSound)(); - void (*CgbOscOff)(u8); - u32 (*MidiKeyToCgbFreq)(u8, u8, u8); - void (**MPlayJumpTable)(); - void (*plynote)(u8, struct MusicPlayerInfo *, struct MusicPlayerTrack *); - void (*ExtVolPit)(struct MusicPlayerInfo *, struct MusicPlayerTrack *); - u32 gap2[4]; - struct SoundChannel chans[MAX_DIRECTSOUND_CHANNELS]; - s8 pcmBuffer[PCM_DMA_BUF_SIZE * 2]; -}; extern u8 gMPlayMemAccArea[]; @@ -446,7 +448,7 @@ void ply_tune(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_port(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_xcmd(struct MusicPlayerInfo *, struct MusicPlayerTrack *); void ply_endtie(struct MusicPlayerInfo *, struct MusicPlayerTrack *); -void ply_note(u8, struct MusicPlayerInfo *, struct MusicPlayerTrack *); +void ply_note(struct MusicPlayerInfo *, struct MusicPlayerTrack *); // extended sound command handler functions void ply_xxx(struct MusicPlayerInfo *, struct MusicPlayerTrack *); diff --git a/include/global.h b/include/global.h index 8c5167041..08988eac7 100644 --- a/include/global.h +++ b/include/global.h @@ -99,7 +99,7 @@ #define T2_READ_PTR(ptr) (void*) T2_READ_32(ptr) // Macros for checking the joypad -#define TEST_BUTTON(field, button) ((field) & (button)) +#define TEST_BUTTON(field, button) ({(field) & (button);}) #define JOY_NEW(button) TEST_BUTTON(gMain.newKeys, button) #define JOY_HELD(button) TEST_BUTTON(gMain.heldKeys, button) #define JOY_HELD_RAW(button) TEST_BUTTON(gMain.heldKeysRaw, button) diff --git a/include/list_menu.h b/include/list_menu.h index 4697ba5aa..0a54a069a 100644 --- a/include/list_menu.h +++ b/include/list_menu.h @@ -24,7 +24,7 @@ struct ListMenu; struct ListMenuItem { const u8 *name; - u32 id; + s32 id; }; struct ListMenuTemplate @@ -98,7 +98,7 @@ struct CursorStruct extern struct ScrollArrowsTemplate gTempScrollArrowTemplate; extern struct ListMenuTemplate gMultiuseListMenuTemplate; -u32 DoMysteryGiftListMenu(const struct WindowTemplate *windowTemplate, const struct ListMenuTemplate *listMenuTemplate, u8 arg2, u16 tileNum, u16 palNum); +s32 DoMysteryGiftListMenu(const struct WindowTemplate *windowTemplate, const struct ListMenuTemplate *listMenuTemplate, u8 arg2, u16 tileNum, u16 palNum); u8 ListMenuInit(struct ListMenuTemplate *listMenuTemplate, u16 scrollOffset, u16 selectedRow); u8 ListMenuInitInRect(struct ListMenuTemplate *listMenuTemplate, struct ListMenuWindowRect *arg1, u16 scrollOffset, u16 selectedRow); s32 ListMenu_ProcessInput(u8 listTaskId); diff --git a/include/pokemon.h b/include/pokemon.h index 81c17f545..d75ec94f3 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -123,12 +123,12 @@ struct Pokemon struct Unknown_806F160_Struct { - u32 field_0_0:4; - u32 field_0_1:4; - u32 field_1:8; - u16 magic:8; - u32 size:4; - u16 field_3_1:4; + u8 field_0_0:4; + u8 field_0_1:4; + u8 field_1; + u8 magic; + u8 field_3_0:4; + u8 field_3_1:4; void *bytes; u8 **byteArrays; struct SpriteTemplate *templates; diff --git a/include/pokenav.h b/include/pokenav.h index ed4e5a906..ac916f3ba 100644 --- a/include/pokenav.h +++ b/include/pokenav.h @@ -313,7 +313,7 @@ bool32 WaitForHelpBar(void); void sub_81C78A0(void); bool32 MainMenuLoopedTaskIsBusy(void); void sub_81C7FDC(void); -void sub_81C79BC(const u16 *a0, const u16 *a1, int a2, int a3, int a4, u16 *palette); +void sub_81C79BC(const u16 *a0, const u16 *a1, u32 a2, u32 a3, u32 a4, u16 *a5); void sub_81C7B40(void); struct Sprite *PauseSpinningPokenavSprite(void); void ResumeSpinningPokenavSprite(void); diff --git a/libagbsyscall/libagbsyscall.s b/libagbsyscall/libagbsyscall.s index 0c90da9ed..00c40d08e 100644 --- a/libagbsyscall/libagbsyscall.s +++ b/libagbsyscall/libagbsyscall.s @@ -1,12 +1,9 @@ .include "../constants/gba_constants.inc" .include "../asm/macros/function.inc" - - .syntax unified .text .set SOFT_RESET_DIRECT_BUF, 0x03007FFA - .set USER_STACK, 0x03007F00 .set RESET_EX_WRAM_FLAG, 0x1 .ifdef NO_GRANULAR_AGBSYSCALL @@ -109,7 +106,7 @@ SoundDriverVSyncOn: thumb_func_start Mod Mod: svc #6 - adds r0, r1, #0 + mov r0, r1 bx lr thumb_func_end Mod .endif @@ -148,7 +145,7 @@ HuffUnComp: .endif .ifdef L_SoftResetExram - thumb_func_start SoftResetExram + arm_func_start SoftResetExram SoftResetExram: ldr r3, =REG_IME movs r2, #0 @@ -156,14 +153,14 @@ SoftResetExram: ldr r3, =SOFT_RESET_DIRECT_BUF movs r2, #1 strb r2, [r3, #0] - subs r3, #SOFT_RESET_DIRECT_BUF - USER_STACK + subs r3, #SOFT_RESET_DIRECT_BUF - 0x3007f00 mov sp, r3 movs r2, #RESET_EX_WRAM_FLAG bics r0, r2 svc #1 svc #0 .pool - thumb_func_end SoftResetExram + arm_func_end SoftResetExram .endif .ifdef L_MusicPlayerFadeOut @@ -234,7 +231,7 @@ DivArm: thumb_func_start ModArm ModArm: svc #7 - adds r0, r1, #0 + mov r0, r1 bx lr thumb_func_end ModArm .endif @@ -274,7 +271,7 @@ Diff8bitUnFilterWram: .ifdef L_MultiBoot thumb_func_start MultiBoot MultiBoot: - movs r1, #1 + mov r1, #1 svc #37 bx lr thumb_func_end MultiBoot @@ -329,7 +326,7 @@ SoftResetRom: ldr r3, =SOFT_RESET_DIRECT_BUF movs r2, #0 strb r2, [r3, #0] - subs r3, #SOFT_RESET_DIRECT_BUF - USER_STACK + sub r3, #SOFT_RESET_DIRECT_BUF - 0x3007f00 mov sp, r3 svc #1 svc #0 @@ -416,7 +413,7 @@ SoftReset: ldr r3, =REG_IME movs r2, #0 strb r2, [r3, #0] - ldr r1, =USER_STACK + ldr r1, =0x3007f00 mov sp, r1 svc #1 svc #0 diff --git a/src/AgbRfu_LinkManager.c b/src/AgbRfu_LinkManager.c index 42cc9aea3..e4127ee09 100644 --- a/src/AgbRfu_LinkManager.c +++ b/src/AgbRfu_LinkManager.c @@ -352,7 +352,7 @@ static bool8 rfu_LMAN_linkWatcher(u16 REQ_commandID) { for (i = 0; i < RFU_CHILD_MAX; i++) { - if (bm_linkLossSlot & (1 << i)) + if ((bm_linkLossSlot >> i) & 1) { lman.linkRecoveryTimer.active |= (1 << i); lman.linkRecoveryTimer.count[i] = lman.linkRecoveryTimer.count_max; @@ -396,7 +396,7 @@ static bool8 rfu_LMAN_linkWatcher(u16 REQ_commandID) bm_disconnectSlot = 0; for (i = 0; i < RFU_CHILD_MAX; i++) { - if ((lman.linkRecoveryTimer.active) & (1 << i) && lman.linkRecoveryTimer.count[i] && --lman.linkRecoveryTimer.count[i] == 0) + if ((lman.linkRecoveryTimer.active >> i) & 1 && lman.linkRecoveryTimer.count[i] && --lman.linkRecoveryTimer.count[i] == 0) { lman.linkRecoveryTimer.active &= ~(1 << i); bm_disconnectSlot |= (1 << i); @@ -918,7 +918,7 @@ static void rfu_LMAN_REQ_callback(u16 reqCommandId, u16 reqResult) { lman.reserveDisconnectSlot_flag = 0; lman.acceptCount = 0; - lman.acceptSlot_flag = 0; + lman.acceptSlot_flag = 0;; lman.parent_child = MODE_NEUTRAL; rfu_LMAN_managerChangeAgbClockMaster(); if (reqCommandId == ID_STOP_MODE_REQ) diff --git a/src/agb_flash.c b/src/agb_flash.c index f63f84509..6b9381c70 100644 --- a/src/agb_flash.c +++ b/src/agb_flash.c @@ -41,7 +41,7 @@ u16 ReadFlashId(void) u8 (*readFlash1)(u8 *); SetReadFlash1(readFlash1Buffer); - readFlash1 = (u8 (*)(u8 *))((uintptr_t)readFlash1Buffer + 1); + readFlash1 = (u8 (*)(u8 *))((s32)readFlash1Buffer + 1); // Enter ID mode. FLASH_WRITE(0x5555, 0xAA); @@ -113,12 +113,12 @@ void SetReadFlash1(u16 *dest) u16 *src; u16 i; - PollFlashStatus = (u8 (*)(u8 *))((uintptr_t)dest + 1); + PollFlashStatus = (u8 (*)(u8 *))((s32)dest + 1); src = (u16 *)ReadFlash1; - src = (u16 *)((uintptr_t)src ^ 1); + src = (u16 *)((s32)src ^ 1); - i = ((uintptr_t)SetReadFlash1 - (uintptr_t)ReadFlash1) >> 1; + i = ((s32)SetReadFlash1 - (s32)ReadFlash1) >> 1; while (i != 0) { @@ -154,10 +154,10 @@ void ReadFlash(u16 sectorNum, u32 offset, u8 *dest, u32 size) } funcSrc = (vu16 *)ReadFlash_Core; - funcSrc = (vu16 *)((uintptr_t)funcSrc ^ 1); + funcSrc = (vu16 *)((s32)funcSrc ^ 1); funcDest = readFlash_Core_Buffer; - i = ((uintptr_t)ReadFlash - (uintptr_t)ReadFlash_Core) >> 1; + i = ((s32)ReadFlash - (s32)ReadFlash_Core) >> 1; while (i != 0) { @@ -165,7 +165,7 @@ void ReadFlash(u16 sectorNum, u32 offset, u8 *dest, u32 size) i--; } - readFlash_Core = (void (*)(vu8 *, u8 *, u32))((uintptr_t)readFlash_Core_Buffer + 1); + readFlash_Core = (void (*)(vu8 *, u8 *, u32))((s32)readFlash_Core_Buffer + 1); src = FLASH_BASE + (sectorNum << gFlash->sector.shift) + offset; @@ -202,10 +202,10 @@ u32 VerifyFlashSector(u16 sectorNum, u8 *src) } funcSrc = (vu16 *)VerifyFlashSector_Core; - funcSrc = (vu16 *)((uintptr_t)funcSrc ^ 1); + funcSrc = (vu16 *)((s32)funcSrc ^ 1); funcDest = verifyFlashSector_Core_Buffer; - i = (u16)(((uintptr_t)VerifyFlashSector - (uintptr_t)VerifyFlashSector_Core) >> 1); + i = ((s32)VerifyFlashSector - (s32)VerifyFlashSector_Core) >> 1; while (i != 0) { @@ -213,7 +213,7 @@ u32 VerifyFlashSector(u16 sectorNum, u8 *src) i--; } - verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((uintptr_t)verifyFlashSector_Core_Buffer + 1); + verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((s32)verifyFlashSector_Core_Buffer + 1); tgt = FLASH_BASE + (sectorNum << gFlash->sector.shift); size = gFlash->sector.size; @@ -239,10 +239,10 @@ u32 VerifyFlashSectorNBytes(u16 sectorNum, u8 *src, u32 n) REG_WAITCNT = (REG_WAITCNT & ~WAITCNT_SRAM_MASK) | WAITCNT_SRAM_8; funcSrc = (vu16 *)VerifyFlashSector_Core; - funcSrc = (vu16 *)((uintptr_t)funcSrc ^ 1); + funcSrc = (vu16 *)((s32)funcSrc ^ 1); funcDest = verifyFlashSector_Core_Buffer; - i = ((uintptr_t)VerifyFlashSector - (uintptr_t)VerifyFlashSector_Core) >> 1; + i = ((s32)VerifyFlashSector - (s32)VerifyFlashSector_Core) >> 1; while (i != 0) { @@ -250,7 +250,7 @@ u32 VerifyFlashSectorNBytes(u16 sectorNum, u8 *src, u32 n) i--; } - verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((uintptr_t)verifyFlashSector_Core_Buffer + 1); + verifyFlashSector_Core = (u32 (*)(u8 *, u8 *, u32))((s32)verifyFlashSector_Core_Buffer + 1); tgt = FLASH_BASE + (sectorNum << gFlash->sector.shift); diff --git a/src/apprentice.c b/src/apprentice.c index 3dc33cad4..7f493a136 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -1297,13 +1297,13 @@ const u8 *GetApprenticeNameInLanguage(u32 apprenticeId, s32 language) // Functionally unused static void Task_SwitchToFollowupFuncAfterButtonPress(u8 taskId) { - if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON)) + if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) SwitchTaskToFollowupFunc(taskId); } static void Task_ExecuteFuncAfterButtonPress(u8 taskId) { - if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON)) + if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) { gApprenticeFunc = (void*)(u32)(((u16)gTasks[taskId].data[0] | (gTasks[taskId].data[1] << 16))); gApprenticeFunc(); diff --git a/src/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index 032e5f407..748e4729a 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -1299,7 +1299,7 @@ static void Cmd_count_usable_party_mons(void) if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { - u8 position; + u32 position; battlerOnField1 = gBattlerPartyIndexes[battlerId]; position = GetBattlerPosition(battlerId) ^ BIT_FLANK; battlerOnField2 = gBattlerPartyIndexes[GetBattlerAtPosition(position)]; diff --git a/src/battle_anim_bug.c b/src/battle_anim_bug.c index 5e8a8b2a7..ea3df8098 100644 --- a/src/battle_anim_bug.c +++ b/src/battle_anim_bug.c @@ -372,11 +372,14 @@ static void AnimTranslateStinger(struct Sprite *sprite) { gBattleAnimArgs[2] = -gBattleAnimArgs[2]; } - else if (GetBattlerSide(gBattleAnimAttacker)) + else { - gBattleAnimArgs[2] = -gBattleAnimArgs[2]; - gBattleAnimArgs[1] = -gBattleAnimArgs[1]; - gBattleAnimArgs[3] = -gBattleAnimArgs[3]; + if (GetBattlerSide(gBattleAnimAttacker)) + { + gBattleAnimArgs[2] = -gBattleAnimArgs[2]; + gBattleAnimArgs[1] = -gBattleAnimArgs[1]; + gBattleAnimArgs[3] = -gBattleAnimArgs[3]; + } } if (!IsContest() && GetBattlerSide(gBattleAnimAttacker) == GetBattlerSide(gBattleAnimTarget)) @@ -384,8 +387,13 @@ static void AnimTranslateStinger(struct Sprite *sprite) if (GetBattlerPosition(gBattleAnimTarget) == B_POSITION_PLAYER_LEFT || GetBattlerPosition(gBattleAnimTarget) == B_POSITION_OPPONENT_LEFT) { - gBattleAnimArgs[2] *= -1; - gBattleAnimArgs[0] *= -1; + s16 temp1, temp2; + + temp1 = gBattleAnimArgs[2]; + gBattleAnimArgs[2] = -temp1; + + temp2 = gBattleAnimArgs[0]; + gBattleAnimArgs[0] = -temp2; } } @@ -440,24 +448,28 @@ static void AnimMissileArc_Step(struct Sprite *sprite) else { s16 tempData[8]; - s16 xpos, ypos; + u16 *data = sprite->data; + u16 x1 = sprite->pos1.x; + s16 x2 = sprite->pos2.x; + u16 y1 = sprite->pos1.y; + s16 y2 = sprite->pos2.y; int i; for (i = 0; i < 8; i++) - tempData[i] = sprite->data[i]; + tempData[i] = data[i]; - xpos = sprite->pos1.x + sprite->pos2.x; - ypos = sprite->pos1.y + sprite->pos2.y; + x2 += x1; + y2 += y1; if (!TranslateAnimHorizontalArc(sprite)) { - u16 rotation = ArcTan2Neg(sprite->pos1.x + sprite->pos2.x - xpos, //Isn't this zero lol - sprite->pos1.y + sprite->pos2.y - ypos); + u16 rotation = ArcTan2Neg(sprite->pos1.x + sprite->pos2.x - x2, + sprite->pos1.y + sprite->pos2.y - y2); rotation += 0xC000; TrySetSpriteRotScale(sprite, FALSE, 0x100, 0x100, rotation); for (i = 0; i < 8; i++) - sprite->data[i] = tempData[i]; + data[i] = tempData[i]; } } } diff --git a/src/battle_anim_dark.c b/src/battle_anim_dark.c index 7253b5247..faa5884a5 100644 --- a/src/battle_anim_dark.c +++ b/src/battle_anim_dark.c @@ -635,6 +635,8 @@ void AnimTask_MoveTargetMementoShadow(u8 taskId) static void AnimTask_MoveTargetMementoShadow_Step(u8 taskId) { + u8 pos; + u16 i; struct Task *task = &gTasks[taskId]; switch (task->data[0]) diff --git a/src/battle_anim_effects_1.c b/src/battle_anim_effects_1.c index c8d43e12e..04bab2f85 100644 --- a/src/battle_anim_effects_1.c +++ b/src/battle_anim_effects_1.c @@ -3967,25 +3967,24 @@ static void AnimProtect(struct Sprite* sprite) static void AnimProtect_Step(struct Sprite *sprite) { - int i, savedPal; + int i, id, savedPal; sprite->data[5] += 96; sprite->pos2.x = -(sprite->data[5] >> 8); if (++sprite->data[1] > 1) { - int id; sprite->data[1] = 0; savedPal = gPlttBufferFaded[sprite->data[2] + 1]; i = 0; - do + while (i < 6) { id = sprite->data[2] + ++i; gPlttBufferFaded[id] = gPlttBufferFaded[id + 1]; - } while (i < 6); + } gPlttBufferFaded[sprite->data[2] + 7] = savedPal; } - if (sprite->data[7] > 6 && sprite->data[0] > 0 && ++sprite->data[6] > 1) + if (sprite->data[7] > 6 && sprite->data[0] >0 && ++sprite->data[6] > 1) { sprite->data[6] = 0; sprite->data[7] -= 1; diff --git a/src/battle_anim_effects_3.c b/src/battle_anim_effects_3.c index 58d335197..bad46f144 100755 --- a/src/battle_anim_effects_3.c +++ b/src/battle_anim_effects_3.c @@ -5003,11 +5003,11 @@ void AnimTask_GetReturnPowerLevel(u8 taskId) void AnimTask_SnatchOpposingMonMove(u8 taskId) { u8 spriteId, spriteId2; - u32 personality; - u32 otId; + int personality; + int otId; u16 species; u8 subpriority; - bool8 isBackPic; + u8 isBackPic; s16 x; switch (gTasks[taskId].data[0]) @@ -5035,34 +5035,37 @@ void AnimTask_SnatchOpposingMonMove(u8 taskId) otId = gContestResources->moveAnim->otId; species = gContestResources->moveAnim->species; subpriority = GetBattlerSpriteSubpriority(gBattleAnimAttacker); - isBackPic = FALSE; + isBackPic = 0; x = -32; } - else if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) - { - personality = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_PERSONALITY); - otId = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_OT_ID); - if (gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies == SPECIES_NONE) - species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES); - else - species = gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies; - - subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority + 1; - isBackPic = FALSE; - x = 272; - } else { - personality = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_PERSONALITY); - otId = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_OT_ID); - if (gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies == SPECIES_NONE) - species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES); - else - species = gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies; + if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_PLAYER) + { + personality = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_PERSONALITY); + otId = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_OT_ID); + if (gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies == SPECIES_NONE) + species = GetMonData(&gPlayerParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES); + else + species = gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies; - subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority - 1; - isBackPic = TRUE; - x = -32; + subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority + 1; + isBackPic = 0; + x = 272; + } + else + { + personality = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_PERSONALITY); + otId = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_OT_ID); + if (gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies == SPECIES_NONE) + species = GetMonData(&gEnemyParty[gBattlerPartyIndexes[gBattleAnimAttacker]], MON_DATA_SPECIES); + else + species = gBattleSpritesDataPtr->battlerData[gBattleAnimAttacker].transformSpecies; + + subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority - 1; + isBackPic = 1; + x = -32; + } } spriteId2 = sub_80A8394(species, isBackPic, 0, x, GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_Y), subpriority, personality, otId, gBattleAnimAttacker, 0); @@ -5089,7 +5092,7 @@ void AnimTask_SnatchOpposingMonMove(u8 taskId) if (x < GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_X)) { gTasks[taskId].data[14]++; - gBattleAnimArgs[7] = -1; + gBattleAnimArgs[7] = 0xFFFF; } } else @@ -5097,7 +5100,7 @@ void AnimTask_SnatchOpposingMonMove(u8 taskId) if (x > GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_X)) { gTasks[taskId].data[14]++; - gBattleAnimArgs[7] = -1; + gBattleAnimArgs[7] = 0xFFFF; } } } @@ -5135,7 +5138,7 @@ void AnimTask_SnatchOpposingMonMove(u8 taskId) gSprites[spriteId].pos2.x = 0; } - gTasks[taskId].data[1] &= 0xFF; + gTasks[taskId].data[1] = (u8)gTasks[taskId].data[1]; if (gSprites[spriteId].pos2.x == 0) DestroyAnimVisualTask(taskId); break; diff --git a/src/battle_anim_flying.c b/src/battle_anim_flying.c index fe94dc9a2..5179c1364 100644 --- a/src/battle_anim_flying.c +++ b/src/battle_anim_flying.c @@ -380,18 +380,21 @@ static void AnimTask_AnimateGustTornadoPalette_Step(u8 taskId) { u8 data2; u16 temp; + int i, base; if (gTasks[taskId].data[10]++ == gTasks[taskId].data[1]) { - int i, base; gTasks[taskId].data[10] = 0; data2 = gTasks[taskId].data[2]; temp = gPlttBufferFaded[16 * data2 + 0x108]; i = 7; base = data2 * 16; - for (; i > 0; --i) + do + { gPlttBufferFaded[base + 0x101 + i] = gPlttBufferFaded[base + 0x100 + i]; + i--; + } while (i > 0); gPlttBufferFaded[base + 0x101] = temp; } @@ -533,16 +536,17 @@ static void AnimFlyBallAttack_Step(struct Sprite *sprite) void DestroyAnimSpriteAfterTimer(struct Sprite *sprite) { - if (sprite->data[0]-- > 0) - return; - if (sprite->oam.affineMode & ST_OAM_AFFINE_ON_MASK) + if (sprite->data[0]-- <= 0) { - FreeOamMatrix(sprite->oam.matrixNum); - sprite->oam.affineMode = ST_OAM_AFFINE_OFF; - } + if (sprite->oam.affineMode & ST_OAM_AFFINE_ON_MASK) + { + FreeOamMatrix(sprite->oam.matrixNum); + sprite->oam.affineMode = ST_OAM_AFFINE_OFF; + } - DestroySprite(sprite); - gAnimVisualTaskCount--; + DestroySprite(sprite); + gAnimVisualTaskCount--; + } } struct FeatherDanceData @@ -563,41 +567,35 @@ struct FeatherDanceData u16 unkE_1:15; }; -#define ANIM_SWITCH(sprite) \ - { \ - (sprite)->hFlip ^= 1; \ - (sprite)->animNum = (sprite)->hFlip; \ - (sprite)->animBeginning = TRUE; \ - (sprite)->animEnded = FALSE; \ - } - static void AnimFallingFeather(struct Sprite *sprite) { - u8 battler, sinIndex; - u32 matrixNum; - s16 sinVal; + u8 battler, matrixNum, sinIndex; + s16 spriteCoord, sinVal; struct FeatherDanceData *data = (struct FeatherDanceData *)sprite->data; - battler = (gBattleAnimArgs[7] & 0x100) ? gBattleAnimAttacker : gBattleAnimTarget; + if (gBattleAnimArgs[7] & 0x100) + battler = gBattleAnimAttacker; + else + battler = gBattleAnimTarget; if (GetBattlerSide(battler) == B_SIDE_PLAYER) gBattleAnimArgs[0] = -gBattleAnimArgs[0]; sprite->pos1.x = GetBattlerSpriteCoord(battler, BATTLER_COORD_ATTR_HEIGHT) + gBattleAnimArgs[0]; - sinVal = GetBattlerSpriteCoord(battler, BATTLER_COORD_ATTR_WIDTH); - sprite->pos1.y = sinVal + gBattleAnimArgs[1]; + spriteCoord = GetBattlerSpriteCoord(battler, BATTLER_COORD_ATTR_WIDTH); + sprite->pos1.y = spriteCoord + gBattleAnimArgs[1]; - data->unk8 = (u16)(sprite->pos1.y) << 8; - data->unkE_1 = (u16)(sinVal + gBattleAnimArgs[6]); + data->unk8 = sprite->pos1.y << 8; + data->unkE_1 = spriteCoord + gBattleAnimArgs[6]; data->unk0_0c = 1; - data->unk2 = (u16)(gBattleAnimArgs[2] & 0xFF); - data->unkA = (u16)gBattleAnimArgs[2] >> 8; + data->unk2 = gBattleAnimArgs[2] & 0xFF; + data->unkA = (gBattleAnimArgs[2] >> 8) & 0xFF; data->unk4 = gBattleAnimArgs[3]; - data->unk6 = (u16)gBattleAnimArgs[4]; - *(u16 *)(data->unkC) = (u16)gBattleAnimArgs[5]; + data->unk6 = gBattleAnimArgs[4]; + *(u16*)(data->unkC) = gBattleAnimArgs[5]; - if (data->unk2 >= 64 && data->unk2 < 192) + if (data->unk2 >= 64 && data->unk2 <= 191) { if (!IsContest()) sprite->oam.priority = GetBattlerSpriteBGPriority(battler) + 1; @@ -608,7 +606,11 @@ static void AnimFallingFeather(struct Sprite *sprite) if (!(data->unk4 & 0x8000)) { - ANIM_SWITCH(sprite); + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + + sprite->animBeginning = 1; + sprite->animEnded = 0; } } else @@ -618,28 +620,42 @@ static void AnimFallingFeather(struct Sprite *sprite) if (data->unk4 & 0x8000) { - ANIM_SWITCH(sprite); + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + + sprite->animBeginning = 1; + sprite->animEnded = 0; } } - data->unk0_1 = data->unk2 / 64; - sprite->pos2.x = (gSineTable[data->unk2] * (s32)data->unkC[0]) >> 8; + data->unk0_1 = data->unk2 >> 6; + sprite->pos2.x = (gSineTable[data->unk2] * data->unkC[0]) >> 8; matrixNum = sprite->oam.matrixNum; sinIndex = (-sprite->pos2.x >> 1) + data->unkA; sinVal = gSineTable[sinIndex]; gOamMatrices[matrixNum].a = gOamMatrices[matrixNum].d = gSineTable[sinIndex + 64]; - gOamMatrices[matrixNum].b = sinVal; - gOamMatrices[matrixNum].c = -sinVal; + // The comparison below is completely pointless. 'sprite' is sure to be a valid pointer and + // both the 'if' and 'else' parts are exactly the same. + // The only reason for this is making sure the compiler generates the exact ASM. + if (sprite) + { + gOamMatrices[matrixNum].b = sinVal; + gOamMatrices[matrixNum].c = -sinVal; + } + else + { + gOamMatrices[matrixNum].b = sinVal; + gOamMatrices[matrixNum].c = -sinVal; + } sprite->callback = sub_810E520; } static void sub_810E520(struct Sprite *sprite) { - u8 sinIndex; - u32 matrixNum; + u8 matrixNum, sinIndex; s16 sinVal = 0; struct FeatherDanceData *data = (struct FeatherDanceData *)sprite->data; if (data->unk0_0a) @@ -649,226 +665,242 @@ static void sub_810E520(struct Sprite *sprite) data->unk0_0a = 0; data->unk1 = 0; } - return; } - - switch (data->unk2 / 64) - { - case 0: - if ((u8)data->unk0_1 == 1) // this must be cast to u8 - { - data->unk0_0d = 1; - data->unk0_0a = 1; - data->unk1 = 0; - } - else if ((u8)data->unk0_1 == 3) - { - data->unk0_0b ^= 1; - data->unk0_0a = 1; - data->unk1 = 0; - } - else if (data->unk0_0d) - { - ANIM_SWITCH(sprite); - if (data->unk0_0c) - { - if (!IsContest()) - { - if (!data->unkE_0) - { - sprite->oam.priority--; - data->unkE_0 ^= 1; - } - else - { - sprite->oam.priority++; - data->unkE_0 ^= 1; - } - } - else - { - if (!data->unkE_0) - { - sprite->subpriority -= 12; - data->unkE_0 ^= 1; - } - else - { - sprite->subpriority += 12; - data->unkE_0 ^= 1; - } - } - } - data->unk0_0d = 0; - } - data->unk0_1 = 0; - break; - case 1: - if ((u8)data->unk0_1 == 0) - { - data->unk0_0d = 1; - data->unk0_0a = 1; - data->unk1 = 0; - } - else if ((u8)data->unk0_1 == 2) - { - data->unk0_0a = 1; - data->unk1 = 0; - } - else if (data->unk0_0d) - { - ANIM_SWITCH(sprite); - if (data->unk0_0c) - { - if (!IsContest()) - { - if (!data->unkE_0) - { - sprite->oam.priority--; - data->unkE_0 ^= 1; - } - else - { - sprite->oam.priority++; - data->unkE_0 ^= 1; - } - } - else - { - if (!data->unkE_0) - { - sprite->subpriority -= 12; - data->unkE_0 ^= 1; - } - else - { - sprite->subpriority += 12; - data->unkE_0 ^= 1; - } - } - } - data->unk0_0d = 0; - } - data->unk0_1 = 1; - break; - case 2: - if ((u8)data->unk0_1 == 3) - { - data->unk0_0d = 1; - data->unk0_0a = 1; - data->unk1 = 0; - } - else if ((u8)data->unk0_1 == 1) - { - data->unk0_0a = 1; - data->unk1 = 0; - } - else if (data->unk0_0d) - { - ANIM_SWITCH(sprite); - if (data->unk0_0c) - { - if (!IsContest()) - { - if (!data->unkE_0) - { - sprite->oam.priority--; - data->unkE_0 ^= 1; - } - else - { - sprite->oam.priority++; - data->unkE_0 ^= 1; - } - } - else - { - if (!data->unkE_0) - { - sprite->subpriority -= 12; - data->unkE_0 ^= 1; - } - else - { - sprite->subpriority += 12; - data->unkE_0 ^= 1; - } - } - } - data->unk0_0d = 0; - } - data->unk0_1 = 2; - break; - case 3: - if ((u8)data->unk0_1 == 2) - { - data->unk0_0d = 1; - } - else if ((u8)data->unk0_1 == 0) - { - data->unk0_0b ^= 1; - data->unk0_0a = 1; - data->unk1 = 0; - } - else if (data->unk0_0d) - { - ANIM_SWITCH(sprite); - if (data->unk0_0c) - { - if (!IsContest()) - { - if (!data->unkE_0) - { - sprite->oam.priority--; - data->unkE_0 ^= 1; - } - else - { - sprite->oam.priority++; - data->unkE_0 ^= 1; - } - } - else - { - if (!data->unkE_0) - { - sprite->subpriority -= 12; - data->unkE_0 ^= 1; - } - else - { - sprite->subpriority += 12; - data->unkE_0 ^= 1; - } - } - } - data->unk0_0d = 0; - } - data->unk0_1 = 3; - break; - } - - sprite->pos2.x = ((s32)(data->unkC[data->unk0_0b]) * gSineTable[data->unk2]) >> 8; - matrixNum = sprite->oam.matrixNum; - - sinIndex = ((-sprite->pos2.x >> 1) + data->unkA); - sinVal = gSineTable[sinIndex]; - - gOamMatrices[matrixNum].a = gOamMatrices[matrixNum].d = gSineTable[sinIndex + 64]; - gOamMatrices[matrixNum].b = sinVal; - gOamMatrices[matrixNum].c = -sinVal; - - data->unk8 += data->unk6; - sprite->pos1.y = (s16)(data->unk8 >> 8); - if (data->unk4 & 0x8000) - data->unk2 = (data->unk2 - (data->unk4 & 0x7FFF)) & 0xFF; else - data->unk2 = (data->unk2 + (data->unk4 & 0x7FFF)) & 0xFF; - - if (sprite->pos1.y + sprite->pos2.y >= data->unkE_1) { - sprite->data[0] = 0; - sprite->callback = DestroyAnimSpriteAfterTimer; + switch (data->unk2 / 64) + { + case 0: + if (data->unk0_1 << 24 >> 24 == 1) // the shifts have to be here + { + data->unk0_0d = 1; + data->unk0_0a = 1; + data->unk1 = 0; + } + else if (data->unk0_1 << 24 >> 24 == 3) + { + data->unk0_0b ^= 1; + data->unk0_0a = 1; + data->unk1 = 0; + } + else if (data->unk0_0d) + { + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + sprite->animBeginning = TRUE; + sprite->animEnded = FALSE; + if (data->unk0_0c) + { + if (!IsContest()) + { + if (!data->unkE_0) + { + sprite->oam.priority--; + data->unkE_0 ^= 1; + } + else + { + sprite->oam.priority++; + data->unkE_0 ^= 1; + } + } + else + { + if (!data->unkE_0) + { + sprite->subpriority -= 12; + data->unkE_0 ^= 1; + } + else + { + sprite->subpriority += 12; + data->unkE_0 ^= 1; + } + } + } + data->unk0_0d = 0; + data->unk2; + } + data->unk0_1 = 0; + break; + case 1: + if (data->unk0_1 << 24 >> 24 == 0) + { + data->unk0_0d = 1; + data->unk0_0a = 1; + data->unk1 = 0; + } + else if (data->unk0_1 << 24 >> 24 == 2) + { + data->unk0_0a = 1; + data->unk1 = 0; + } + else if (data->unk0_0d) + { + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + sprite->animBeginning = TRUE; + sprite->animEnded = FALSE; + if (data->unk0_0c) + { + if (!IsContest()) + { + if (!data->unkE_0) + { + sprite->oam.priority--; + data->unkE_0 ^= 1; + } + else + { + sprite->oam.priority++; + data->unkE_0 ^= 1; + } + } + else + { + if (!data->unkE_0) + { + sprite->subpriority -= 12; + data->unkE_0 ^= 1; + } + else + { + sprite->subpriority += 12; + data->unkE_0 ^= 1; + } + } + } + data->unk0_0d = 0; + } + data->unk0_1 = 1; + break; + case 2: + if (data->unk0_1 << 24 >> 24 == 3) + { + data->unk0_0d = 1; + data->unk0_0a = 1; + data->unk1 = 0; + } + else if (data->unk0_1 << 24 >> 24 == 1) + { + data->unk0_0a = 1; + data->unk1 = 0; + } + else if (data->unk0_0d) + { + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + sprite->animBeginning = TRUE; + sprite->animEnded = FALSE; + if (data->unk0_0c) + { + if (!IsContest()) + { + if (!data->unkE_0) + { + sprite->oam.priority--; + data->unkE_0 ^= 1; + } + else + { + sprite->oam.priority++; + data->unkE_0 ^= 1; + } + } + else + { + if (!data->unkE_0) + { + sprite->subpriority -= 12; + data->unkE_0 ^= 1; + } + else + { + sprite->subpriority += 12; + data->unkE_0 ^= 1; + } + } + } + data->unk0_0d = 0; + } + data->unk0_1 = 2; + break; + case 3: + if (data->unk0_1 << 24 >> 24 == 2) + { + data->unk0_0d = 1; + } + else if (data->unk0_1 << 24 >> 24 == 0) + { + data->unk0_0b ^= 1; + data->unk0_0a = 1; + data->unk1 = 0; + } + else if (data->unk0_0d) + { + sprite->hFlip ^= 1; + sprite->animNum = sprite->hFlip; + sprite->animBeginning = TRUE; + sprite->animEnded = FALSE; + if (data->unk0_0c) + { + if (!IsContest()) + { + if (!data->unkE_0) + { + sprite->oam.priority--; + data->unkE_0 ^= 1; + } + else + { + sprite->oam.priority++; + data->unkE_0 ^= 1; + } + } + else + { + if (!data->unkE_0) + { + sprite->subpriority -= 12; + data->unkE_0 ^= 1; + } + else + { + sprite->subpriority += 12; + data->unkE_0 ^= 1; + } + } + } + data->unk0_0d = 0; + } + data->unk0_1 = 3; + break; + } + #ifndef NONMATCHING + asm("":::"r8"); + #endif + sprite->pos2.x = (data->unkC[data->unk0_0b] * gSineTable[data->unk2]) >> 8; + matrixNum = sprite->oam.matrixNum; + + sinIndex = (-sprite->pos2.x >> 1) + data->unkA; + sinVal = gSineTable[sinIndex]; + + gOamMatrices[matrixNum].a = gOamMatrices[matrixNum].d = gSineTable[sinIndex + 64]; + gOamMatrices[matrixNum].b = sinVal; + gOamMatrices[matrixNum].c = -sinVal; + + data->unk8 += data->unk6; + sprite->pos1.y = data->unk8 >> 8; + if (data->unk4 & 0x8000) + data->unk2 = (data->unk2 - (data->unk4 & 0x7FFF)) & 0xFF; + else + data->unk2 = (data->unk2 + (data->unk4 & 0x7FFF)) & 0xFF; + + if (sprite->pos1.y + sprite->pos2.y >= data->unkE_1) + { + sprite->data[0] = 0; + sprite->callback = DestroyAnimSpriteAfterTimer; + } } } @@ -912,20 +944,20 @@ static void sub_810EB40(struct Sprite *sprite) { sprite->pos2.x += sprite->data[1] >> 8; - if (sprite->data[0]++ == 5) + if (++sprite->data[0] == 6) { sprite->data[0] = 0; sprite->pos2.x = 0; StartSpriteAnim(sprite, 0); } - if (sprite->data[7]-- == 0) + if (--sprite->data[7] == -1) DestroyAnimSprite(sprite); } void AnimTask_DrillPeckHitSplats(u8 task) { - if ((gTasks[task].data[0] % 32) == 0) + if (!(gTasks[task].data[0] % 32)) { gAnimVisualTaskCount++; @@ -1028,8 +1060,8 @@ static void AnimDiveBall_Step2(struct Sprite *sprite) static void AnimDiveWaterSplash(struct Sprite *sprite) { - u8 matrixNum; - s32 t1, t2; + u32 matrixNum; + int t1, t2; switch (sprite->data[0]) { @@ -1051,7 +1083,7 @@ static void AnimDiveWaterSplash(struct Sprite *sprite) sprite->data[0]++; break; case 1: - if (sprite->data[2] < 12) + if (sprite->data[2] <= 11) sprite->data[1] -= 40; else sprite->data[1] += 40; @@ -1059,7 +1091,7 @@ static void AnimDiveWaterSplash(struct Sprite *sprite) sprite->data[2]++; TrySetSpriteRotScale(sprite, 0, 256, sprite->data[1], 0); - + matrixNum = sprite->oam.matrixNum; t1 = 15616; @@ -1083,8 +1115,8 @@ static void AnimDiveWaterSplash(struct Sprite *sprite) // Launches a water droplet away from the specified battler. Used by Astonish and Dive static void AnimSprayWaterDroplet(struct Sprite *sprite) { - const u16 v1 = Random2() & 0x1ff; - const u16 v2 = Random2() & 0x07f; + int v1 = 0x1ff & Random2(); + int v2 = 0x7f & Random2(); if (v1 % 2) sprite->data[0] = 736 + v1; @@ -1128,13 +1160,13 @@ static void AnimSprayWaterDroplet_Step(struct Sprite *sprite) sprite->pos2.y -= sprite->data[1] >> 8; } - sprite->data[0] -= 0; // Needed to Match + sprite->data[0] = sprite->data[0]; sprite->data[1] -= 32; if (sprite->data[0] < 0) sprite->data[0] = 0; - if (sprite->data[3]++ == 30) + if (++sprite->data[3] == 31) DestroyAnimSprite(sprite); } @@ -1180,7 +1212,7 @@ static void AnimSkyAttackBird(struct Sprite *sprite) sprite->data[7] = ((posy - sprite->pos1.y) << 4) / 12; rotation = ArcTan2Neg(posx - sprite->pos1.x, posy - sprite->pos1.y); - rotation -= 16384; + rotation += 49152; TrySetSpriteRotScale(sprite, 1, 0x100, 0x100, rotation); @@ -1204,12 +1236,12 @@ void unref_sub_810F184(u8 taskId) { if (gBattleAnimArgs[0] == 0) { - const u8 spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); + u8 spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); gSprites[spriteId].invisible = TRUE; } else { - const u8 spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); + u8 spriteId = GetAnimBattlerSpriteId(ANIM_ATTACKER); gSprites[spriteId].invisible = FALSE; } DestroyAnimVisualTask(taskId); diff --git a/src/battle_anim_psychic.c b/src/battle_anim_psychic.c index 3f451998c..0a07b9070 100644 --- a/src/battle_anim_psychic.c +++ b/src/battle_anim_psychic.c @@ -1101,7 +1101,7 @@ static void AnimTask_TransparentCloneGrowAndShrink_Step(u8 taskId) break; case 1: task->data[1] -= 4; - task->data[2] = 256 - (gSineTable[task->data[1]] >> 1); + task->data[2] = 256 - (gSineTable[task->data[1]] >> 1);; SetSpriteRotScale(task->data[15], task->data[2], task->data[2], 0); SetBattlerSpriteYOffsetFromOtherYScale(task->data[15], task->data[13]); if (task->data[1] == 0) diff --git a/src/battle_anim_utility_funcs.c b/src/battle_anim_utility_funcs.c index 9790cf9ea..af48ac3b9 100644 --- a/src/battle_anim_utility_funcs.c +++ b/src/battle_anim_utility_funcs.c @@ -569,7 +569,7 @@ static void sub_81172EC(u8 taskId) if (gTasks[taskId].data[12] == 0) { sub_80A477C(0); - gTasks[taskId].data[15]++; + gTasks[taskId].data[15]++;; } } break; diff --git a/src/battle_anim_water.c b/src/battle_anim_water.c index 12f37dbba..5810b6bdc 100644 --- a/src/battle_anim_water.c +++ b/src/battle_anim_water.c @@ -52,7 +52,7 @@ static void CreateWaterSpoutLaunchDroplets(struct Task*, u8); static void CreateWaterSpoutRainDroplet(struct Task*, u8); static void AnimTask_WaterSport_Step(u8); static void CreateWaterSportDroplet(struct Task*); -static void CreateWaterPulseRingBubbles(struct Sprite*, s32, s32); +static void CreateWaterPulseRingBubbles(struct Sprite*, int, int); // Both unused const u8 gUnknown_8593C80[] = INCBIN_U8("graphics/unknown/unknown_593C80.4bpp"); @@ -624,24 +624,98 @@ void AnimTask_RotateAuroraRingColors(u8 taskId) gTasks[taskId].func = AnimTask_RotateAuroraRingColors_Step; } +#ifdef NONMATCHING static void AnimTask_RotateAuroraRingColors_Step(u8 taskId) { int i; u16 palIndex; + u16 *palPtr1; + u16 *palPtr2; + u16 rgbBuffer; if (++gTasks[taskId].data[10] == 3) { - u16 tempPlt; gTasks[taskId].data[10] = 0; palIndex = gTasks[taskId].data[2] + 1; - tempPlt = gPlttBufferFaded[palIndex]; - for (i = 1; i < 8; i++) - gPlttBufferFaded[palIndex + i - 1] = gPlttBufferFaded[palIndex + i]; - gPlttBufferFaded[palIndex + 7] = tempPlt; + palPtr1 = &gPlttBufferFaded[palIndex]; + rgbBuffer = *palPtr1; + palPtr2 = &palPtr1[1]; + for (i = 0; i < 7; i++) + palPtr1[i] = palPtr2[i]; + gPlttBufferFaded[palIndex + 7] = rgbBuffer; } if (++gTasks[taskId].data[11] == gTasks[taskId].data[0]) DestroyAnimVisualTask(taskId); } +#else +NAKED +static void AnimTask_RotateAuroraRingColors_Step(u8 taskId) +{ + asm_unified("push {r4-r7,lr}\n\ + lsls r0, 24\n\ + lsrs r4, r0, 24\n\ + ldr r1, =gTasks\n\ + lsls r0, r4, 2\n\ + adds r0, r4\n\ + lsls r0, 3\n\ + adds r2, r0, r1\n\ + ldrh r0, [r2, 0x1C]\n\ + adds r0, 0x1\n\ + strh r0, [r2, 0x1C]\n\ + lsls r0, 16\n\ + asrs r0, 16\n\ + mov r12, r1\n\ + cmp r0, 0x3\n\ + bne _081075BE\n\ + movs r0, 0\n\ + strh r0, [r2, 0x1C]\n\ + ldrh r0, [r2, 0xC]\n\ + adds r0, 0x1\n\ + lsls r0, 16\n\ + lsrs r5, r0, 16\n\ + ldr r1, =gPlttBufferFaded\n\ + lsls r0, r5, 1\n\ + adds r0, r1\n\ + ldrh r6, [r0]\n\ + adds r7, r1, 0\n\ + adds r3, r0, 0x2\n\ + movs r1, 0x6\n\ + adds r2, r0, 0\n\ +_081075A8:\n\ + ldrh r0, [r3]\n\ + strh r0, [r2]\n\ + adds r3, 0x2\n\ + adds r2, 0x2\n\ + subs r1, 0x1\n\ + cmp r1, 0\n\ + bge _081075A8\n\ + adds r0, r5, 0x7\n\ + lsls r0, 1\n\ + adds r0, r7\n\ + strh r6, [r0]\n\ +_081075BE:\n\ + lsls r0, r4, 2\n\ + adds r0, r4\n\ + lsls r0, 3\n\ + add r0, r12\n\ + ldrh r1, [r0, 0x1E]\n\ + adds r1, 0x1\n\ + strh r1, [r0, 0x1E]\n\ + lsls r1, 16\n\ + asrs r1, 16\n\ + movs r2, 0x8\n\ + ldrsh r0, [r0, r2]\n\ + cmp r1, r0\n\ + bne _081075DE\n\ + adds r0, r4, 0\n\ + bl DestroyAnimVisualTask\n\ +_081075DE:\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool\n"); +} +#endif // For animating undulating beam attacks (e.g. Flamethrower, Hydro Pump, Signal Beam) static void AnimToTargetInSinWave(struct Sprite *sprite) @@ -748,7 +822,6 @@ static void AnimHydroCannonBeam(struct Sprite *sprite) if (GetBattlerPosition(gBattleAnimAttacker) == B_POSITION_PLAYER_LEFT || GetBattlerPosition(gBattleAnimAttacker) == B_POSITION_OPPONENT_LEFT) gBattleAnimArgs[0] *= -1; } - if ((gBattleAnimArgs[5] & 0xFF00) == 0) animType = TRUE; else @@ -794,25 +867,21 @@ static void AnimSmallBubblePair_Step(struct Sprite *sprite) sprite->pos2.x = Sin(sprite->data[0], 4); sprite->data[1] += 48; sprite->pos2.y = -(sprite->data[1] >> 8); - if (sprite->data[7]-- == 0) + if (--sprite->data[7] == -1) DestroyAnimSprite(sprite); } +#ifdef NONMATCHING void AnimTask_CreateSurfWave(u8 taskId) { struct BattleAnimBgData animBg; u8 taskId2; - u16 *x, *y; //These pointers are needed to match - x = &gBattle_BG1_X; - y = &gBattle_BG1_Y; - - SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL | BLDCNT_TGT1_BG1); - SetGpuReg(REG_OFFSET_BLDALPHA, (16 << 8)); + SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_ALL); + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(0, 16)); SetAnimBgAttribute(1, BG_ANIM_PRIORITY, 1); SetAnimBgAttribute(1, BG_ANIM_SCREEN_SIZE, 1); sub_80A6B30(&animBg); - if (!IsContest()) { SetAnimBgAttribute(1, BG_ANIM_CHAR_BASE_BLOCK, 1); @@ -837,30 +906,30 @@ void AnimTask_CreateSurfWave(u8 taskId) gTasks[taskId2].data[2] = 0x1000; if (IsContest()) { - *x = -80; - *y = -48; + gBattle_BG1_X = -80; + gBattle_BG1_Y = -48; gTasks[taskId].data[0] = 2; gTasks[taskId].data[1] = 1; gTasks[taskId2].data[3] = 0; } else if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_OPPONENT) { - *x = -224; - *y = 256; + gBattle_BG1_X = -224; + gBattle_BG1_Y = 256; gTasks[taskId].data[0] = 2; gTasks[taskId].data[1] = -1; gTasks[taskId2].data[3] = 1; } else { - *x = 0; - *y = -48; + gBattle_BG1_X = 0; + gBattle_BG1_Y = -48; gTasks[taskId].data[0] = -2; gTasks[taskId].data[1] = 1; gTasks[taskId2].data[3] = 0; } - SetGpuReg(REG_OFFSET_BG1HOFS, *x); - SetGpuReg(REG_OFFSET_BG1VOFS, *y); + SetGpuReg(REG_OFFSET_BG1HOFS, gBattle_BG1_X); + SetGpuReg(REG_OFFSET_BG1VOFS, gBattle_BG1_Y); if (gTasks[taskId2].data[3] == 0) { gTasks[taskId2].data[4] = 48; @@ -874,16 +943,245 @@ void AnimTask_CreateSurfWave(u8 taskId) gTasks[taskId].data[6] = 1; gTasks[taskId].func = AnimTask_CreateSurfWave_Step1; } +#else +NAKED +void AnimTask_CreateSurfWave(u8 taskId) +{ + asm_unified("push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0x10\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + mov r10, r0\n\ + ldr r1, =0x00003f42\n\ + movs r0, 0x50\n\ + bl SetGpuReg\n\ + movs r1, 0x80\n\ + lsls r1, 5\n\ + movs r0, 0x52\n\ + bl SetGpuReg\n\ + movs r0, 0x1\n\ + movs r1, 0x4\n\ + movs r2, 0x1\n\ + bl SetAnimBgAttribute\n\ + movs r0, 0x1\n\ + movs r1, 0\n\ + movs r2, 0x1\n\ + bl SetAnimBgAttribute\n\ + mov r0, sp\n\ + bl sub_80A6B30\n\ + bl IsContest\n\ + lsls r0, 24\n\ + cmp r0, 0\n\ + bne _081079E0\n\ + movs r0, 0x1\n\ + movs r1, 0x3\n\ + movs r2, 0x1\n\ + bl SetAnimBgAttribute\n\ + ldr r0, =gBattleAnimAttacker\n\ + ldrb r0, [r0]\n\ + bl GetBattlerSide\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + cmp r0, 0x1\n\ + bne _081079D0\n\ + mov r0, sp\n\ + ldrb r0, [r0, 0x9]\n\ + ldr r1, =gBattleAnimBgTilemap_SurfOpponent\n\ + bl AnimLoadCompressedBgTilemap\n\ + b _081079EA\n\ + .pool\n\ +_081079D0:\n\ + mov r0, sp\n\ + ldrb r0, [r0, 0x9]\n\ + ldr r1, =gBattleAnimBgTilemap_SurfPlayer\n\ + bl AnimLoadCompressedBgTilemap\n\ + b _081079EA\n\ + .pool\n\ +_081079E0:\n\ + ldr r1, =gBattleAnimBgTilemap_SurfContest\n\ + mov r0, sp\n\ + movs r2, 0x1\n\ + bl AnimLoadCompressedBgTilemapHandleContest\n\ +_081079EA:\n\ + mov r0, sp\n\ + ldrb r0, [r0, 0x9]\n\ + ldr r1, =gBattleAnimBgImage_Surf\n\ + mov r2, sp\n\ + ldrh r2, [r2, 0xA]\n\ + bl AnimLoadCompressedBgGfx\n\ + ldr r0, =gBattleAnimArgs\n\ + movs r1, 0\n\ + ldrsh r0, [r0, r1]\n\ + cmp r0, 0\n\ + bne _08107A24\n\ + ldr r0, =gBattleAnimBgPalette_Surf\n\ + mov r1, sp\n\ + ldrb r1, [r1, 0x8]\n\ + lsls r1, 4\n\ + movs r2, 0x20\n\ + bl LoadCompressedPalette\n\ + b _08107A32\n\ + .pool\n\ +_08107A24:\n\ + ldr r0, =gBattleAnimBackgroundImageMuddyWater_Pal\n\ + mov r1, sp\n\ + ldrb r1, [r1, 0x8]\n\ + lsls r1, 4\n\ + movs r2, 0x20\n\ + bl LoadCompressedPalette\n\ +_08107A32:\n\ + ldr r0, =AnimTask_SurfWaveScanlineEffect\n\ + ldr r4, =gTasks\n\ + mov r2, r10\n\ + lsls r5, r2, 2\n\ + adds r1, r5, r2\n\ + lsls r1, 3\n\ + adds r6, r1, r4\n\ + ldrb r1, [r6, 0x7]\n\ + adds r1, 0x1\n\ + lsls r1, 24\n\ + lsrs r1, 24\n\ + bl CreateTask\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + mov r8, r0\n\ + movs r0, 0\n\ + mov r9, r0\n\ + mov r1, r8\n\ + strh r1, [r6, 0x26]\n\ + mov r2, r8\n\ + lsls r0, r2, 2\n\ + add r0, r8\n\ + lsls r0, 3\n\ + adds r7, r0, r4\n\ + mov r0, r9\n\ + strh r0, [r7, 0x8]\n\ + movs r0, 0x80\n\ + lsls r0, 5\n\ + strh r0, [r7, 0xA]\n\ + strh r0, [r7, 0xC]\n\ + bl IsContest\n\ + lsls r0, 24\n\ + lsrs r4, r0, 24\n\ + cmp r4, 0\n\ + beq _08107AB4\n\ + ldr r1, =0x0000ffb0\n\ + adds r0, r1, 0\n\ + ldr r2, =gBattle_BG1_X\n\ + strh r0, [r2]\n\ + adds r1, 0x20\n\ + adds r0, r1, 0\n\ + ldr r2, =gBattle_BG1_Y\n\ + strh r0, [r2]\n\ + movs r0, 0x2\n\ + strh r0, [r6, 0x8]\n\ + movs r0, 0x1\n\ + strh r0, [r6, 0xA]\n\ + mov r0, r9\n\ + strh r0, [r7, 0xE]\n\ + b _08107B0E\n\ + .pool\n\ +_08107AB4:\n\ + ldr r0, =gBattleAnimAttacker\n\ + ldrb r0, [r0]\n\ + bl GetBattlerSide\n\ + lsls r0, 24\n\ + lsrs r1, r0, 24\n\ + cmp r1, 0x1\n\ + bne _08107AF8\n\ + ldr r2, =0x0000ff20\n\ + adds r0, r2, 0\n\ + ldr r2, =gBattle_BG1_X\n\ + strh r0, [r2]\n\ + movs r2, 0x80\n\ + lsls r2, 1\n\ + adds r0, r2, 0\n\ + ldr r2, =gBattle_BG1_Y\n\ + strh r0, [r2]\n\ + movs r0, 0x2\n\ + strh r0, [r6, 0x8]\n\ + ldr r0, =0x0000ffff\n\ + strh r0, [r6, 0xA]\n\ + strh r1, [r7, 0xE]\n\ + b _08107B0E\n\ + .pool\n\ +_08107AF8:\n\ + ldr r0, =gBattle_BG1_X\n\ + strh r4, [r0]\n\ + ldr r1, =0x0000ffd0\n\ + adds r0, r1, 0\n\ + ldr r2, =gBattle_BG1_Y\n\ + strh r0, [r2]\n\ + ldr r0, =0x0000fffe\n\ + strh r0, [r6, 0x8]\n\ + movs r0, 0x1\n\ + strh r0, [r6, 0xA]\n\ + strh r4, [r7, 0xE]\n\ +_08107B0E:\n\ + ldr r0, =gBattle_BG1_X\n\ + ldrh r1, [r0]\n\ + movs r0, 0x14\n\ + bl SetGpuReg\n\ + ldr r2, =gBattle_BG1_Y\n\ + ldrh r1, [r2]\n\ + movs r0, 0x16\n\ + bl SetGpuReg\n\ + ldr r1, =gTasks\n\ + mov r2, r8\n\ + lsls r0, r2, 2\n\ + add r0, r8\n\ + lsls r0, 3\n\ + adds r1, r0, r1\n\ + movs r2, 0xE\n\ + ldrsh r0, [r1, r2]\n\ + cmp r0, 0\n\ + bne _08107B54\n\ + movs r0, 0x30\n\ + strh r0, [r1, 0x10]\n\ + movs r0, 0x70\n\ + b _08107B58\n\ + .pool\n\ +_08107B54:\n\ + movs r0, 0\n\ + strh r0, [r1, 0x10]\n\ +_08107B58:\n\ + strh r0, [r1, 0x12]\n\ + ldr r1, =gTasks\n\ + mov r2, r10\n\ + adds r0, r5, r2\n\ + lsls r0, 3\n\ + adds r0, r1\n\ + movs r1, 0x1\n\ + strh r1, [r0, 0x14]\n\ + ldr r1, =AnimTask_CreateSurfWave_Step1\n\ + str r1, [r0]\n\ + add sp, 0x10\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool\n"); +} +#endif +#ifdef NONMATCHING static void AnimTask_CreateSurfWave_Step1(u8 taskId) { - u16 rgbBuffer; - u8 i; - u16 *BGptrX, *BGptrY; struct BattleAnimBgData animBg; - - BGptrX = &gBattle_BG1_X; - BGptrY = &gBattle_BG1_Y; + u8 i; + u16 rgbBuffer; + u16 *BGptrX = &gBattle_BG1_X; + u16 *BGptrY = &gBattle_BG1_Y; + s16 unkUse; + u32 palOffset; + u16 palNum; *BGptrX += gTasks[taskId].data[0]; *BGptrY += gTasks[taskId].data[1]; @@ -891,26 +1189,29 @@ static void AnimTask_CreateSurfWave_Step1(u8 taskId) gTasks[taskId].data[2] += gTasks[taskId].data[1]; if (++gTasks[taskId].data[5] == 4) { - rgbBuffer = gPlttBufferFaded[16 * animBg.paletteId + 7]; - for (i = 6; i != 0; i--) // i > 0 generates the exact same code in this context + rgbBuffer = gPlttBufferFaded[animBg.paletteId * 16 + 7]; + for (i = 6; i != 0; i--) { - gPlttBufferFaded[16 * animBg.paletteId + 1 + i] = gPlttBufferFaded[16 * animBg.paletteId + 1 + i - 1]; // 1 + i - 1 is needed to match for some bizarre reason + palNum = animBg.paletteId * 16; + palOffset = 1 + i; + gPlttBufferFaded[palNum + palOffset] = gPlttBufferFaded[palNum + palOffset - 1]; } - gPlttBufferFaded[16 * animBg.paletteId + 1] = rgbBuffer; + gPlttBufferFaded[animBg.paletteId * 16 + 1] = rgbBuffer; gTasks[taskId].data[5] = 0; } if (++gTasks[taskId].data[6] > 1) { gTasks[taskId].data[6] = 0; - if (++gTasks[taskId].data[3] < 14) + unkUse = ++gTasks[taskId].data[3]; + if (unkUse <= 13) { - gTasks[gTasks[taskId].data[15]].data[1] = (s16)((gTasks[taskId].data[3]) | ((16 - gTasks[taskId].data[3]) << 8)); + gTasks[gTasks[taskId].data[15]].data[1] = unkUse | ((16 - unkUse) * 256); gTasks[taskId].data[4]++; } if (gTasks[taskId].data[3] > 54) { - gTasks[taskId].data[4]--; - gTasks[gTasks[taskId].data[15]].data[1] = (s16)((gTasks[taskId].data[4]) | ((16 - gTasks[taskId].data[4]) << 8)); + unkUse = --gTasks[taskId].data[4]; + gTasks[gTasks[taskId].data[15]].data[1] = unkUse | ((16 - unkUse) * 256); } } if (!(gTasks[gTasks[taskId].data[15]].data[1] & 0x1F)) @@ -919,7 +1220,167 @@ static void AnimTask_CreateSurfWave_Step1(u8 taskId) gTasks[taskId].func = AnimTask_CreateSurfWave_Step2; } } - +#else +NAKED +static void AnimTask_CreateSurfWave_Step1(u8 taskId) +{ + asm_unified("push {r4-r7,lr}\n\ + sub sp, 0x10\n\ + lsls r0, 24\n\ + lsrs r5, r0, 24\n\ + ldr r1, =gBattle_BG1_X\n\ + ldr r2, =gBattle_BG1_Y\n\ + ldr r0, =gTasks\n\ + lsls r4, r5, 2\n\ + adds r4, r5\n\ + lsls r4, 3\n\ + adds r4, r0\n\ + ldrh r0, [r4, 0x8]\n\ + ldrh r3, [r1]\n\ + adds r0, r3\n\ + strh r0, [r1]\n\ + ldrh r0, [r4, 0xA]\n\ + ldrh r1, [r2]\n\ + adds r0, r1\n\ + strh r0, [r2]\n\ + mov r0, sp\n\ + bl sub_80A6B30\n\ + ldrh r0, [r4, 0xA]\n\ + ldrh r3, [r4, 0xC]\n\ + adds r0, r3\n\ + strh r0, [r4, 0xC]\n\ + ldrh r0, [r4, 0x12]\n\ + adds r0, 0x1\n\ + strh r0, [r4, 0x12]\n\ + lsls r0, 16\n\ + asrs r0, 16\n\ + cmp r0, 0x4\n\ + bne _08107C18\n\ + ldr r1, =gPlttBufferFaded\n\ + mov r0, sp\n\ + ldrb r0, [r0, 0x8]\n\ + lsls r0, 4\n\ + adds r0, 0x7\n\ + lsls r0, 1\n\ + adds r0, r1\n\ + ldrh r6, [r0]\n\ + movs r2, 0x6\n\ + adds r7, r1, 0\n\ + adds r3, r7, 0\n\ + mov r4, sp\n\ +_08107BDE:\n\ + ldrb r0, [r4, 0x8]\n\ + lsls r0, 4\n\ + adds r1, r2, 0x1\n\ + adds r0, r1\n\ + lsls r1, r0, 1\n\ + adds r1, r3\n\ + subs r0, 0x1\n\ + lsls r0, 1\n\ + adds r0, r3\n\ + ldrh r0, [r0]\n\ + strh r0, [r1]\n\ + subs r0, r2, 0x1\n\ + lsls r0, 24\n\ + lsrs r2, r0, 24\n\ + cmp r2, 0\n\ + bne _08107BDE\n\ + mov r0, sp\n\ + ldrb r0, [r0, 0x8]\n\ + lsls r0, 4\n\ + adds r0, 0x1\n\ + lsls r0, 1\n\ + adds r0, r7\n\ + strh r6, [r0]\n\ + ldr r1, =gTasks\n\ + lsls r0, r5, 2\n\ + adds r0, r5\n\ + lsls r0, 3\n\ + adds r0, r1\n\ + strh r2, [r0, 0x12]\n\ +_08107C18:\n\ + ldr r1, =gTasks\n\ + lsls r2, r5, 2\n\ + adds r0, r2, r5\n\ + lsls r0, 3\n\ + adds r3, r0, r1\n\ + ldrh r0, [r3, 0x14]\n\ + adds r0, 0x1\n\ + strh r0, [r3, 0x14]\n\ + lsls r0, 16\n\ + asrs r0, 16\n\ + adds r4, r1, 0\n\ + adds r6, r2, 0\n\ + cmp r0, 0x1\n\ + ble _08107C86\n\ + movs r0, 0\n\ + strh r0, [r3, 0x14]\n\ + ldrh r0, [r3, 0xE]\n\ + adds r2, r0, 0x1\n\ + strh r2, [r3, 0xE]\n\ + lsls r0, r2, 16\n\ + asrs r0, 16\n\ + cmp r0, 0xD\n\ + bgt _08107C62\n\ + movs r1, 0x26\n\ + ldrsh r0, [r3, r1]\n\ + lsls r1, r0, 2\n\ + adds r1, r0\n\ + lsls r1, 3\n\ + adds r1, r4\n\ + movs r0, 0x10\n\ + subs r0, r2\n\ + lsls r0, 8\n\ + orrs r2, r0\n\ + strh r2, [r1, 0xA]\n\ + ldrh r0, [r3, 0x10]\n\ + adds r0, 0x1\n\ + strh r0, [r3, 0x10]\n\ +_08107C62:\n\ + movs r1, 0xE\n\ + ldrsh r0, [r3, r1]\n\ + cmp r0, 0x36\n\ + ble _08107C86\n\ + ldrh r2, [r3, 0x10]\n\ + subs r2, 0x1\n\ + strh r2, [r3, 0x10]\n\ + movs r1, 0x26\n\ + ldrsh r0, [r3, r1]\n\ + lsls r1, r0, 2\n\ + adds r1, r0\n\ + lsls r1, 3\n\ + adds r1, r4\n\ + movs r0, 0x10\n\ + subs r0, r2\n\ + lsls r0, 8\n\ + orrs r2, r0\n\ + strh r2, [r1, 0xA]\n\ +_08107C86:\n\ + adds r0, r6, r5\n\ + lsls r0, 3\n\ + adds r2, r0, r4\n\ + movs r3, 0x26\n\ + ldrsh r1, [r2, r3]\n\ + lsls r0, r1, 2\n\ + adds r0, r1\n\ + lsls r0, 3\n\ + adds r0, r4\n\ + ldrh r0, [r0, 0xA]\n\ + movs r3, 0x1F\n\ + ands r3, r0\n\ + cmp r3, 0\n\ + bne _08107CA8\n\ + strh r3, [r2, 0x8]\n\ + ldr r0, =AnimTask_CreateSurfWave_Step2\n\ + str r0, [r2]\n\ +_08107CA8:\n\ + add sp, 0x10\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool\n"); +} +#endif static void AnimTask_CreateSurfWave_Step2(u8 taskId) { @@ -1543,50 +2004,216 @@ static void AnimWaterPulseRing_Step(struct Sprite *sprite) sprite->data[0]++; } -static void CreateWaterPulseRingBubbles(struct Sprite *sprite, s32 xDiff, s32 yDiff) +#ifdef NONMATCHING +static void CreateWaterPulseRingBubbles(struct Sprite *sprite, int xDiff, int yDiff) { - s16 combinedX, combinedY; - s16 i, something; - s16 unusedVar = 1; //unusedVar is needed to match - s16 somethingRandomX, somethingRandomY; + s16 something = sprite->data[0] / 2; + s16 combinedX = sprite->pos1.x + sprite->pos2.x; + s16 combinedY = sprite->pos1.y + sprite->pos2.y; + s16 randomSomethingY = yDiff + (Random2() % 10) - 5; + s16 randomSomethingX = -xDiff + (Random2() % 10) - 5; + s16 i; u8 spriteId; - something = sprite->data[0] / 2; - combinedX = sprite->pos1.x + sprite->pos2.x; - combinedY = sprite->pos1.y + sprite->pos2.y; - if (yDiff < 0) - unusedVar *= -1; //Needed to Match - somethingRandomY = yDiff + (Random2() % 10) - 5; - somethingRandomX = -xDiff + (Random2() % 10) - 5; - - for (i = 0; i < 1; i++) + for (i = 0; i <= 0; i++) { spriteId = CreateSprite(&gWaterPulseRingBubbleSpriteTemplate, combinedX, combinedY + something, 130); gSprites[spriteId].data[0] = 20; - gSprites[spriteId].data[1] = somethingRandomY; + gSprites[spriteId].data[1] = randomSomethingY; gSprites[spriteId].subpriority = GetBattlerSpriteSubpriority(gBattleAnimAttacker) - 1; - if (somethingRandomX < 0) - { - gSprites[spriteId].data[2] = -somethingRandomX; - } + if (randomSomethingX < 0) + gSprites[spriteId].data[2] = -randomSomethingX; else - { - gSprites[spriteId].data[2] = somethingRandomX; - } + gSprites[spriteId].data[2] = randomSomethingX; } - for (i = 0; i < 1; i++) + for (i = 0; i <= 0; i++) { spriteId = CreateSprite(&gWaterPulseRingBubbleSpriteTemplate, combinedX, combinedY - something, 130); gSprites[spriteId].data[0] = 20; - gSprites[spriteId].data[1] = somethingRandomY; + gSprites[spriteId].data[1] = randomSomethingY; gSprites[spriteId].subpriority = GetBattlerSpriteSubpriority(gBattleAnimAttacker) - 1; - if (somethingRandomX > 0) - { - gSprites[spriteId].data[2] = -somethingRandomX; - } + if (randomSomethingX > 0) + gSprites[spriteId].data[2] = -randomSomethingX; else - { - gSprites[spriteId].data[2] = somethingRandomX; - } + gSprites[spriteId].data[2] = randomSomethingX; } } +#else +NAKED +static void CreateWaterPulseRingBubbles(struct Sprite *sprite, int xDiff, int yDiff) +{ + asm_unified("push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0x18\n\ + adds r4, r1, 0\n\ + adds r5, r2, 0\n\ + movs r2, 0x2E\n\ + ldrsh r1, [r0, r2]\n\ + lsrs r2, r1, 31\n\ + adds r1, r2\n\ + lsls r1, 15\n\ + lsrs r1, 16\n\ + str r1, [sp]\n\ + ldrh r1, [r0, 0x24]\n\ + ldrh r3, [r0, 0x20]\n\ + adds r1, r3\n\ + lsls r1, 16\n\ + lsrs r1, 16\n\ + mov r8, r1\n\ + ldrh r1, [r0, 0x26]\n\ + ldrh r0, [r0, 0x22]\n\ + adds r1, r0\n\ + lsls r1, 16\n\ + lsrs r1, 16\n\ + mov r10, r1\n\ + bl Random2\n\ + lsls r0, 16\n\ + lsrs r0, 16\n\ + movs r1, 0xA\n\ + bl __umodsi3\n\ + adds r0, r5, r0\n\ + subs r0, 0x5\n\ + lsls r0, 16\n\ + lsrs r0, 16\n\ + mov r9, r0\n\ + bl Random2\n\ + negs r4, r4\n\ + lsls r0, 16\n\ + lsrs r0, 16\n\ + movs r1, 0xA\n\ + bl __umodsi3\n\ + adds r4, r0\n\ + subs r4, 0x5\n\ + lsls r4, 16\n\ + lsrs r7, r4, 16\n\ + movs r6, 0\n\ + mov r0, r8\n\ + lsls r0, 16\n\ + mov r8, r0\n\ + mov r1, r10\n\ + lsls r1, 16\n\ + str r1, [sp, 0xC]\n\ + ldr r2, [sp]\n\ + lsls r2, 16\n\ + str r2, [sp, 0x10]\n\ + asrs r1, 16\n\ + lsls r0, r7, 16\n\ + asrs r5, r0, 16\n\ + str r0, [sp, 0x14]\n\ + negs r3, r5\n\ + str r3, [sp, 0x4]\n\ + asrs r0, r2, 16\n\ + adds r1, r0\n\ + lsls r1, 16\n\ + mov r10, r1\n\ +_08108DE2:\n\ + ldr r0, =gWaterPulseRingBubbleSpriteTemplate\n\ + mov r2, r8\n\ + asrs r1, r2, 16\n\ + mov r3, r10\n\ + asrs r2, r3, 16\n\ + movs r3, 0x82\n\ + bl CreateSprite\n\ + lsls r0, 24\n\ + lsrs r2, r0, 24\n\ + ldr r1, =gSprites\n\ + lsls r0, r2, 4\n\ + adds r0, r2\n\ + lsls r0, 2\n\ + adds r4, r0, r1\n\ + movs r0, 0x14\n\ + strh r0, [r4, 0x2E]\n\ + mov r0, r9\n\ + strh r0, [r4, 0x30]\n\ + ldr r0, =gBattleAnimAttacker\n\ + ldrb r0, [r0]\n\ + bl GetBattlerSpriteSubpriority\n\ + subs r0, 0x1\n\ + adds r1, r4, 0\n\ + adds r1, 0x43\n\ + strb r0, [r1]\n\ + cmp r5, 0\n\ + bge _08108E30\n\ + mov r1, sp\n\ + ldrh r1, [r1, 0x4]\n\ + strh r1, [r4, 0x32]\n\ + b _08108E32\n\ + .pool\n\ +_08108E30:\n\ + strh r7, [r4, 0x32]\n\ +_08108E32:\n\ + lsls r0, r6, 16\n\ + movs r2, 0x80\n\ + lsls r2, 9\n\ + adds r0, r2\n\ + lsrs r6, r0, 16\n\ + cmp r0, 0\n\ + ble _08108DE2\n\ + movs r6, 0\n\ + ldr r3, [sp, 0xC]\n\ + asrs r1, r3, 16\n\ + ldr r0, [sp, 0x14]\n\ + asrs r5, r0, 16\n\ + negs r2, r5\n\ + str r2, [sp, 0x8]\n\ + ldr r3, [sp, 0x10]\n\ + asrs r0, r3, 16\n\ + subs r1, r0\n\ + lsls r1, 16\n\ + mov r10, r1\n\ +_08108E58:\n\ + ldr r0, =gWaterPulseRingBubbleSpriteTemplate\n\ + mov r2, r8\n\ + asrs r1, r2, 16\n\ + mov r3, r10\n\ + asrs r2, r3, 16\n\ + movs r3, 0x82\n\ + bl CreateSprite\n\ + lsls r0, 24\n\ + lsrs r2, r0, 24\n\ + ldr r1, =gSprites\n\ + lsls r0, r2, 4\n\ + adds r0, r2\n\ + lsls r0, 2\n\ + adds r4, r0, r1\n\ + movs r0, 0x14\n\ + strh r0, [r4, 0x2E]\n\ + mov r0, r9\n\ + strh r0, [r4, 0x30]\n\ + ldr r0, =gBattleAnimAttacker\n\ + ldrb r0, [r0]\n\ + bl GetBattlerSpriteSubpriority\n\ + subs r0, 0x1\n\ + adds r1, r4, 0\n\ + adds r1, 0x43\n\ + strb r0, [r1]\n\ + cmp r5, 0\n\ + ble _08108EA8\n\ + mov r1, sp\n\ + ldrh r1, [r1, 0x8]\n\ + strh r1, [r4, 0x32]\n\ + b _08108EAA\n\ + .pool\n\ +_08108EA8:\n\ + strh r7, [r4, 0x32]\n\ +_08108EAA:\n\ + lsls r0, r6, 16\n\ + movs r2, 0x80\n\ + lsls r2, 9\n\ + adds r0, r2\n\ + lsrs r6, r0, 16\n\ + cmp r0, 0\n\ + ble _08108E58\n\ + add sp, 0x18\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n"); +} +#endif diff --git a/src/battle_bg.c b/src/battle_bg.c index 6a0e4c10c..7c9b05b25 100644 --- a/src/battle_bg.c +++ b/src/battle_bg.c @@ -1126,7 +1126,7 @@ void DrawBattleEntryBackground(void) if (gBattleTypeFlags & BATTLE_TYPE_LINK) { LZDecompressVram(gUnknown_08D778F0, (void*)(BG_CHAR_ADDR(1))); - LZDecompressVram(gVsLettersGfx, (void*)(OBJ_VRAM0)); + LZDecompressVram(gVsLettersGfx, (void*)(VRAM + 0x10000)); LoadCompressedPalette(gUnknown_08D77AE4, 0x60, 0x20); SetBgAttribute(1, BG_ATTR_SCREENSIZE, 1); SetGpuReg(REG_OFFSET_BG1CNT, 0x5C04); diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 7c34efd44..d8005e808 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -240,12 +240,12 @@ static void HandleInputChooseAction(void) DoBounceEffect(gActiveBattler, BOUNCE_HEALTHBOX, 7, 1); DoBounceEffect(gActiveBattler, BOUNCE_MON, 7, 1); - if (JOY_REPEAT(DPAD_ANY) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) + if (gMain.newAndRepeatedKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) gPlayerDpadHoldFrames++; else gPlayerDpadHoldFrames = 0; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); @@ -266,7 +266,7 @@ static void HandleInputChooseAction(void) } PlayerBufferExecCompleted(); } - else if (JOY_NEW(DPAD_LEFT)) + else if (gMain.newKeys & DPAD_LEFT) { if (gActionSelectionCursor[gActiveBattler] & 1) // if is B_ACTION_USE_ITEM or B_ACTION_RUN { @@ -276,7 +276,7 @@ static void HandleInputChooseAction(void) ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); } } - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { if (!(gActionSelectionCursor[gActiveBattler] & 1)) // if is B_ACTION_USE_MOVE or B_ACTION_SWITCH { @@ -286,7 +286,7 @@ static void HandleInputChooseAction(void) ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); } } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (gActionSelectionCursor[gActiveBattler] & 2) // if is B_ACTION_SWITCH or B_ACTION_RUN { @@ -296,7 +296,7 @@ static void HandleInputChooseAction(void) ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); } } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (!(gActionSelectionCursor[gActiveBattler] & 2)) // if is B_ACTION_USE_MOVE or B_ACTION_USE_ITEM { @@ -306,7 +306,7 @@ static void HandleInputChooseAction(void) ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); } } - else if (JOY_NEW(B_BUTTON) || gPlayerDpadHoldFrames > 59) + else if (gMain.newKeys & B_BUTTON || gPlayerDpadHoldFrames > 59) { if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) && GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT @@ -326,7 +326,7 @@ static void HandleInputChooseAction(void) PlayerBufferExecCompleted(); } } - else if (JOY_NEW(START_BUTTON)) + else if (gMain.newKeys & START_BUTTON) { SwapHpBarsWithHpText(); } @@ -359,12 +359,12 @@ static void HandleInputChooseTarget(void) } while (i < gBattlersCount); } - if (JOY_HELD(DPAD_ANY) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) + if (gMain.heldKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) gPlayerDpadHoldFrames++; else gPlayerDpadHoldFrames = 0; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget; @@ -372,7 +372,7 @@ static void HandleInputChooseTarget(void) EndBounceEffect(gMultiUsePlayerCursor, BOUNCE_HEALTHBOX); PlayerBufferExecCompleted(); } - else if (JOY_NEW(B_BUTTON) || gPlayerDpadHoldFrames > 59) + else if (gMain.newKeys & B_BUTTON || gPlayerDpadHoldFrames > 59) { PlaySE(SE_SELECT); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget; @@ -381,7 +381,7 @@ static void HandleInputChooseTarget(void) DoBounceEffect(gActiveBattler, BOUNCE_MON, 7, 1); EndBounceEffect(gMultiUsePlayerCursor, BOUNCE_HEALTHBOX); } - else if (JOY_NEW(DPAD_LEFT | DPAD_UP)) + else if (gMain.newKeys & (DPAD_LEFT | DPAD_UP)) { PlaySE(SE_SELECT); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget; @@ -423,7 +423,7 @@ static void HandleInputChooseTarget(void) } while (i == 0); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_ShowAsMoveTarget; } - else if (JOY_NEW(DPAD_RIGHT | DPAD_DOWN)) + else if (gMain.newKeys & (DPAD_RIGHT | DPAD_DOWN)) { PlaySE(SE_SELECT); gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_HideAsMoveTarget; @@ -472,12 +472,12 @@ static void HandleInputChooseMove(void) bool32 canSelectTarget = FALSE; struct ChooseMoveStruct *moveInfo = (struct ChooseMoveStruct*)(&gBattleBufferA[gActiveBattler][4]); - if (JOY_HELD(DPAD_ANY) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) + if (gMain.heldKeys & DPAD_ANY && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) gPlayerDpadHoldFrames++; else gPlayerDpadHoldFrames = 0; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { u8 moveTarget; @@ -539,13 +539,13 @@ static void HandleInputChooseMove(void) gSprites[gBattlerSpriteIds[gMultiUsePlayerCursor]].callback = SpriteCb_ShowAsMoveTarget; } } - else if (JOY_NEW(B_BUTTON) || gPlayerDpadHoldFrames > 59) + else if (gMain.newKeys & B_BUTTON || gPlayerDpadHoldFrames > 59) { PlaySE(SE_SELECT); BtlController_EmitTwoReturnValues(1, 10, 0xFFFF); PlayerBufferExecCompleted(); } - else if (JOY_NEW(DPAD_LEFT)) + else if (gMain.newKeys & DPAD_LEFT) { if (gMoveSelectionCursor[gActiveBattler] & 1) { @@ -557,7 +557,7 @@ static void HandleInputChooseMove(void) MoveSelectionDisplayMoveType(); } } - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { if (!(gMoveSelectionCursor[gActiveBattler] & 1) && (gMoveSelectionCursor[gActiveBattler] ^ 1) < gNumberOfMovesToChoose) @@ -570,7 +570,7 @@ static void HandleInputChooseMove(void) MoveSelectionDisplayMoveType(); } } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (gMoveSelectionCursor[gActiveBattler] & 2) { @@ -582,7 +582,7 @@ static void HandleInputChooseMove(void) MoveSelectionDisplayMoveType(); } } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (!(gMoveSelectionCursor[gActiveBattler] & 2) && (gMoveSelectionCursor[gActiveBattler] ^ 2) < gNumberOfMovesToChoose) @@ -595,7 +595,7 @@ static void HandleInputChooseMove(void) MoveSelectionDisplayMoveType(); } } - else if (JOY_NEW(SELECT_BUTTON)) + else if (gMain.newKeys & SELECT_BUTTON) { if (gNumberOfMovesToChoose > 1 && !(gBattleTypeFlags & BATTLE_TYPE_LINK)) { @@ -617,26 +617,26 @@ u32 sub_8057FBC(void) // unused { u32 var = 0; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); var = 1; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); gBattle_BG0_X = 0; gBattle_BG0_Y = 0x140; var = 0xFF; } - if (JOY_NEW(DPAD_LEFT) && gMoveSelectionCursor[gActiveBattler] & 1) + if (gMain.newKeys & DPAD_LEFT && gMoveSelectionCursor[gActiveBattler] & 1) { MoveSelectionDestroyCursorAt(gMoveSelectionCursor[gActiveBattler]); gMoveSelectionCursor[gActiveBattler] ^= 1; PlaySE(SE_SELECT); MoveSelectionCreateCursorAt(gMoveSelectionCursor[gActiveBattler], 0); } - if (JOY_NEW(DPAD_RIGHT) && !(gMoveSelectionCursor[gActiveBattler] & 1) + if (gMain.newKeys & DPAD_RIGHT && !(gMoveSelectionCursor[gActiveBattler] & 1) && (gMoveSelectionCursor[gActiveBattler] ^ 1) < gNumberOfMovesToChoose) { MoveSelectionDestroyCursorAt(gMoveSelectionCursor[gActiveBattler]); @@ -644,14 +644,14 @@ u32 sub_8057FBC(void) // unused PlaySE(SE_SELECT); MoveSelectionCreateCursorAt(gMoveSelectionCursor[gActiveBattler], 0); } - if (JOY_NEW(DPAD_UP) && gMoveSelectionCursor[gActiveBattler] & 2) + if (gMain.newKeys & DPAD_UP && gMoveSelectionCursor[gActiveBattler] & 2) { MoveSelectionDestroyCursorAt(gMoveSelectionCursor[gActiveBattler]); gMoveSelectionCursor[gActiveBattler] ^= 2; PlaySE(SE_SELECT); MoveSelectionCreateCursorAt(gMoveSelectionCursor[gActiveBattler], 0); } - if (JOY_NEW(DPAD_DOWN) && !(gMoveSelectionCursor[gActiveBattler] & 2) + if (gMain.newKeys & DPAD_DOWN && !(gMoveSelectionCursor[gActiveBattler] & 2) && (gMoveSelectionCursor[gActiveBattler] ^ 2) < gNumberOfMovesToChoose) { MoveSelectionDestroyCursorAt(gMoveSelectionCursor[gActiveBattler]); @@ -669,7 +669,7 @@ static void HandleMoveSwitching(void) struct ChooseMoveStruct moveStruct; u8 totalPPBonuses; - if (JOY_NEW(A_BUTTON | SELECT_BUTTON)) + if (gMain.newKeys & (A_BUTTON | SELECT_BUTTON)) { PlaySE(SE_SELECT); @@ -763,7 +763,7 @@ static void HandleMoveSwitching(void) MoveSelectionDisplayPpNumber(); MoveSelectionDisplayMoveType(); } - else if (JOY_NEW(B_BUTTON | SELECT_BUTTON)) + else if (gMain.newKeys & (B_BUTTON | SELECT_BUTTON)) { PlaySE(SE_SELECT); MoveSelectionDestroyCursorAt(gMultiUsePlayerCursor); @@ -773,7 +773,7 @@ static void HandleMoveSwitching(void) MoveSelectionDisplayPpNumber(); MoveSelectionDisplayMoveType(); } - else if (JOY_NEW(DPAD_LEFT)) + else if (gMain.newKeys & DPAD_LEFT) { if (gMultiUsePlayerCursor & 1) { @@ -791,7 +791,7 @@ static void HandleMoveSwitching(void) MoveSelectionCreateCursorAt(gMultiUsePlayerCursor, 27); } } - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { if (!(gMultiUsePlayerCursor & 1) && (gMultiUsePlayerCursor ^ 1) < gNumberOfMovesToChoose) { @@ -809,7 +809,7 @@ static void HandleMoveSwitching(void) MoveSelectionCreateCursorAt(gMultiUsePlayerCursor, 27); } } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (gMultiUsePlayerCursor & 2) { @@ -827,7 +827,7 @@ static void HandleMoveSwitching(void) MoveSelectionCreateCursorAt(gMultiUsePlayerCursor, 27); } } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (!(gMultiUsePlayerCursor & 2) && (gMultiUsePlayerCursor ^ 2) < gNumberOfMovesToChoose) { @@ -1402,21 +1402,21 @@ static void DoHitAnimBlinkSpriteEffect(void) static void PlayerHandleUnknownYesNoInput(void) { - if (JOY_NEW(DPAD_UP) && gMultiUsePlayerCursor != 0) + if (gMain.newKeys & DPAD_UP && gMultiUsePlayerCursor != 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gMultiUsePlayerCursor); gMultiUsePlayerCursor = 0; BattleCreateYesNoCursorAt(0); } - if (JOY_NEW(DPAD_DOWN) && gMultiUsePlayerCursor == 0) + if (gMain.newKeys & DPAD_DOWN && gMultiUsePlayerCursor == 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gMultiUsePlayerCursor); gMultiUsePlayerCursor = 1; BattleCreateYesNoCursorAt(1); } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); PlaySE(SE_SELECT); @@ -1428,7 +1428,7 @@ static void PlayerHandleUnknownYesNoInput(void) PlayerBufferExecCompleted(); } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); PlaySE(SE_SELECT); diff --git a/src/battle_controller_safari.c b/src/battle_controller_safari.c index 9cb427e12..70e41cf8d 100644 --- a/src/battle_controller_safari.c +++ b/src/battle_controller_safari.c @@ -170,7 +170,7 @@ static void SafariBufferRunCommand(void) static void HandleInputChooseAction(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); @@ -191,7 +191,7 @@ static void HandleInputChooseAction(void) } SafariBufferExecCompleted(); } - else if (JOY_NEW(DPAD_LEFT)) + else if (gMain.newKeys & DPAD_LEFT) { if (gActionSelectionCursor[gActiveBattler] & 1) { @@ -201,7 +201,7 @@ static void HandleInputChooseAction(void) ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); } } - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { if (!(gActionSelectionCursor[gActiveBattler] & 1)) { @@ -211,7 +211,7 @@ static void HandleInputChooseAction(void) ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); } } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (gActionSelectionCursor[gActiveBattler] & 2) { @@ -221,7 +221,7 @@ static void HandleInputChooseAction(void) ActionSelectionCreateCursorAt(gActionSelectionCursor[gActiveBattler], 0); } } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (!(gActionSelectionCursor[gActiveBattler] & 2)) { diff --git a/src/battle_dome.c b/src/battle_dome.c index 2f6df5dca..f2abe39d2 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -2731,6 +2731,9 @@ static int SelectOpponentMonsFromParty(int *partyMovePoints, bool8 allowRandom) #define TYPE_x2 40 #define TYPE_x4 80 +// Functionally equivalent, while loop is impossible to match. +// arg2 is either 2, a personality, or an OTID +#ifdef NONMATCHING static int GetTypeEffectivenessPoints(int move, int targetSpecies, int arg2) { int defType1, defType2, defAbility, moveType; @@ -2759,15 +2762,13 @@ static int GetTypeEffectivenessPoints(int move, int targetSpecies, int arg2) i += 3; continue; } - if (TYPE_EFFECT_ATK_TYPE(i) == moveType) + else if (TYPE_EFFECT_ATK_TYPE(i) == moveType) { - // BUG: TYPE_x2 is not necessary and makes the condition always false if the ability is wonder guard. - if (TYPE_EFFECT_DEF_TYPE(i) == defType1) - if ((defAbility == ABILITY_WONDER_GUARD && TYPE_EFFECT_MULTIPLIER(i) == TYPE_x2) || defAbility != ABILITY_WONDER_GUARD) - typePower = typePower * TYPE_EFFECT_MULTIPLIER(i) / 10; - if (TYPE_EFFECT_DEF_TYPE(i) == defType2 && defType1 != defType2) - if ((defAbility == ABILITY_WONDER_GUARD && TYPE_EFFECT_MULTIPLIER(i) == TYPE_x2) || defAbility != ABILITY_WONDER_GUARD) - typePower = typePower * TYPE_EFFECT_MULTIPLIER(i) / 10; + // BUG: * 2 is not necessary and makes the condition always false if the ability is wonder guard. + if (TYPE_EFFECT_DEF_TYPE(i) == defType1 && (defAbility != ABILITY_WONDER_GUARD || TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_SUPER_EFFECTIVE * 2)) + typePower = (typePower * TYPE_EFFECT_MULTIPLIER(i)) / 10; + if (TYPE_EFFECT_DEF_TYPE(i) == defType2 && defType1 != defType2 && (defAbility != ABILITY_WONDER_GUARD || TYPE_EFFECT_MULTIPLIER(i) == TYPE_MUL_SUPER_EFFECTIVE * 2)) + typePower = (typePower * TYPE_EFFECT_MULTIPLIER(i)) / 10; } i += 3; } @@ -2778,10 +2779,10 @@ static int GetTypeEffectivenessPoints(int move, int targetSpecies, int arg2) case 0: switch (typePower) { - default: - case TYPE_x0: - case TYPE_x0_25: case TYPE_x0_50: + case TYPE_x0_25: + case TYPE_x0: + default: typePower = 0; break; case TYPE_x1: @@ -2798,19 +2799,19 @@ static int GetTypeEffectivenessPoints(int move, int targetSpecies, int arg2) case 1: switch (typePower) { - case TYPE_x0: - typePower = 8; + default: + case TYPE_x1: + typePower = 0; break; case TYPE_x0_25: typePower = 4; break; + case TYPE_x0: + typePower = 8; + break; case TYPE_x0_50: typePower = 2; break; - default: - case TYPE_x1: - typePower = 0; - break; case TYPE_x2: typePower = -2; break; @@ -2828,8 +2829,8 @@ static int GetTypeEffectivenessPoints(int move, int targetSpecies, int arg2) case TYPE_x0_25: typePower = -8; break; - default: case TYPE_x0_50: + default: typePower = 0; break; case TYPE_x1: @@ -2847,6 +2848,246 @@ static int GetTypeEffectivenessPoints(int move, int targetSpecies, int arg2) return typePower; } +#else +NAKED +static int GetTypeEffectivenessPoints(int move, int species, int arg2) +{ + asm_unified( + "push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0x8\n\ + adds r3, r0, 0\n\ + adds r4, r1, 0\n\ + str r2, [sp]\n\ + movs r6, 0\n\ + movs r2, 0x14\n\ + cmp r3, 0\n\ + beq _0818FFF0\n\ + ldr r0, =0x0000ffff\n\ + cmp r3, r0\n\ + beq _0818FFF0\n\ + ldr r0, =gBattleMoves\n\ + lsls r1, r3, 1\n\ + adds r1, r3\n\ + lsls r1, 2\n\ + adds r3, r1, r0\n\ + ldrb r0, [r3, 0x1]\n\ + cmp r0, 0\n\ + bne _0818FFFC\n\ +_0818FFF0:\n\ + movs r0, 0\n\ + b _08190156\n\ + .pool\n\ +_0818FFFC:\n\ + ldr r1, =gBaseStats\n\ + lsls r0, r4, 3\n\ + subs r0, r4\n\ + lsls r0, 2\n\ + adds r0, r1\n\ + ldrb r1, [r0, 0x6]\n\ + mov r10, r1\n\ + ldrb r1, [r0, 0x7]\n\ + mov r9, r1\n\ + ldrb r0, [r0, 0x16]\n\ + mov r8, r0\n\ + ldrb r3, [r3, 0x2]\n\ + str r3, [sp, 0x4]\n\ + cmp r0, 0x1A\n\ + bne _0819002C\n\ + cmp r3, 0x4\n\ + bne _0819002C\n\ + ldr r0, [sp]\n\ + cmp r0, 0x1\n\ + bne _081900AA\n\ + movs r2, 0x8\n\ + b _081900A4\n\ + .pool\n\ +_0819002C:\n\ + ldr r0, =gTypeEffectiveness\n\ + adds r1, r6, r0\n\ + ldrb r0, [r1]\n\ + ldr r7, =gTypeEffectiveness\n\ + cmp r0, 0xFF\n\ + beq _081900A4\n\ + adds r4, r1, 0\n\ +_0819003A:\n\ + ldrb r0, [r4]\n\ + cmp r0, 0xFE\n\ + beq _08190096\n\ + ldrb r0, [r4]\n\ + ldr r1, [sp, 0x4]\n\ + cmp r0, r1\n\ + bne _08190096\n\ + ldrb r0, [r4, 0x1]\n\ + adds r5, r6, 0x1\n\ + cmp r0, r10\n\ + bne _0819006C\n\ + adds r1, r6, 0x2\n\ + mov r0, r8\n\ + cmp r0, 0x19\n\ + bne _0819005E\n\ + ldrb r0, [r4, 0x2]\n\ + cmp r0, 0x28\n\ + bne _0819006C\n\ +_0819005E:\n\ + adds r0, r1, r7\n\ + ldrb r0, [r0]\n\ + muls r0, r2\n\ + movs r1, 0xA\n\ + bl __divsi3\n\ + adds r2, r0, 0\n\ +_0819006C:\n\ + adds r0, r5, r7\n\ + ldrb r0, [r0]\n\ + cmp r0, r9\n\ + bne _08190096\n\ + cmp r10, r9\n\ + beq _08190096\n\ + adds r1, r6, 0x2\n\ + mov r0, r8\n\ + cmp r0, 0x19\n\ + bne _08190088\n\ + adds r0, r1, r7\n\ + ldrb r0, [r0]\n\ + cmp r0, 0x28\n\ + bne _08190096\n\ +_08190088:\n\ + adds r0, r1, r7\n\ + ldrb r0, [r0]\n\ + muls r0, r2\n\ + movs r1, 0xA\n\ + bl __divsi3\n\ + adds r2, r0, 0\n\ +_08190096:\n\ + adds r4, 0x3\n\ + adds r6, 0x3\n\ + ldr r1, =gTypeEffectiveness\n\ + adds r0, r6, r1\n\ + ldrb r0, [r0]\n\ + cmp r0, 0xFF\n\ + bne _0819003A\n\ +_081900A4:\n\ + ldr r0, [sp]\n\ + cmp r0, 0x1\n\ + beq _081900E0\n\ +_081900AA:\n\ + ldr r1, [sp]\n\ + cmp r1, 0x1\n\ + bgt _081900BC\n\ + cmp r1, 0\n\ + beq _081900C4\n\ + b _08190154\n\ + .pool\n\ +_081900BC:\n\ + ldr r0, [sp]\n\ + cmp r0, 0x2\n\ + beq _08190114\n\ + b _08190154\n\ +_081900C4:\n\ + cmp r2, 0xA\n\ + beq _08190146\n\ + cmp r2, 0xA\n\ + ble _08190146\n\ + cmp r2, 0x28\n\ + beq _0819014A\n\ + cmp r2, 0x28\n\ + bgt _081900DA\n\ + cmp r2, 0x14\n\ + beq _08190104\n\ + b _08190146\n\ +_081900DA:\n\ + cmp r2, 0x50\n\ + bne _08190146\n\ + b _08190100\n\ +_081900E0:\n\ + cmp r2, 0xA\n\ + beq _08190104\n\ + cmp r2, 0xA\n\ + bgt _081900F2\n\ + cmp r2, 0\n\ + beq _08190100\n\ + cmp r2, 0x5\n\ + beq _0819014A\n\ + b _08190146\n\ +_081900F2:\n\ + cmp r2, 0x28\n\ + beq _08190108\n\ + cmp r2, 0x28\n\ + ble _08190146\n\ + cmp r2, 0x50\n\ + beq _0819010E\n\ + b _08190146\n\ +_08190100:\n\ + movs r2, 0x8\n\ + b _08190154\n\ +_08190104:\n\ + movs r2, 0x2\n\ + b _08190154\n\ +_08190108:\n\ + movs r2, 0x2\n\ + negs r2, r2\n\ + b _08190154\n\ +_0819010E:\n\ + movs r2, 0x4\n\ + negs r2, r2\n\ + b _08190154\n\ +_08190114:\n\ + cmp r2, 0xA\n\ + beq _08190146\n\ + cmp r2, 0xA\n\ + bgt _08190126\n\ + cmp r2, 0\n\ + beq _0819013A\n\ + cmp r2, 0x5\n\ + beq _08190140\n\ + b _08190146\n\ +_08190126:\n\ + cmp r2, 0x28\n\ + beq _0819014E\n\ + cmp r2, 0x28\n\ + bgt _08190134\n\ + cmp r2, 0x14\n\ + beq _0819014A\n\ + b _08190146\n\ +_08190134:\n\ + cmp r2, 0x50\n\ + beq _08190152\n\ + b _08190146\n\ +_0819013A:\n\ + movs r2, 0x10\n\ + negs r2, r2\n\ + b _08190154\n\ +_08190140:\n\ + movs r2, 0x8\n\ + negs r2, r2\n\ + b _08190154\n\ +_08190146:\n\ + movs r2, 0\n\ + b _08190154\n\ +_0819014A:\n\ + movs r2, 0x4\n\ + b _08190154\n\ +_0819014E:\n\ + movs r2, 0xC\n\ + b _08190154\n\ +_08190152:\n\ + movs r2, 0x14\n\ +_08190154:\n\ + adds r0, r2, 0\n\ +_08190156:\n\ + add sp, 0x8\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r1}\n\ + bx r1"); +} +#endif // NONMATCHING // Duplicate of GetFrontierTrainerFixedIvs // NOTE: In CreateDomeOpponentMon a tournament trainer ID (0-15) is passed instead, resulting in all IVs of 3 @@ -4111,7 +4352,7 @@ static u8 Task_GetInfoCardInput(u8 taskId) u8 tourneyId = sTourneyTreeTrainerIds[position]; u16 roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum; - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) input = INFOCARD_INPUT_AB; // Next opponent card cant scroll @@ -4122,7 +4363,7 @@ static u8 Task_GetInfoCardInput(u8 taskId) { // For trainer info cards, pos is 0 when on a trainer info card (not viewing that trainer's match progression) // Scrolling up/down from a trainer info card goes to other trainer info cards - if (JOY_NEW(DPAD_UP) && sInfoCard->pos == 0) + if (gMain.newKeys & DPAD_UP && sInfoCard->pos == 0) { if (position == 0) position = DOME_TOURNAMENT_TRAINERS_COUNT - 1; @@ -4130,7 +4371,7 @@ static u8 Task_GetInfoCardInput(u8 taskId) position--; input = TRAINERCARD_INPUT_UP; } - else if (JOY_NEW(DPAD_DOWN) && sInfoCard->pos == 0) + else if (gMain.newKeys & DPAD_DOWN && sInfoCard->pos == 0) { if (position == DOME_TOURNAMENT_TRAINERS_COUNT - 1) position = 0; @@ -4139,13 +4380,13 @@ static u8 Task_GetInfoCardInput(u8 taskId) input = TRAINERCARD_INPUT_DOWN; } // Scrolling left can only be done after scrolling right - else if (JOY_NEW(DPAD_LEFT) && sInfoCard->pos != 0) + else if (gMain.newKeys & DPAD_LEFT && sInfoCard->pos != 0) { sInfoCard->pos--; input = TRAINERCARD_INPUT_LEFT; } // Scrolling right from a trainer info card shows their match progression - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { // Can only scroll right from a trainer card until the round they were eliminated if (DOME_TRAINERS[tourneyId].isEliminated && sInfoCard->pos - 1 < DOME_TRAINERS[tourneyId].eliminatedAt) @@ -4173,7 +4414,7 @@ static u8 Task_GetInfoCardInput(u8 taskId) { // For match info cards, pos is 1 when on the match card, 0 when on the left trainer, and 1 when on the right trainer // Scrolling up/down from a match info card goes to the next/previous match - if (JOY_NEW(DPAD_UP) && sInfoCard->pos == 1) + if (gMain.newKeys & DPAD_UP && sInfoCard->pos == 1) { if (position == DOME_TOURNAMENT_TRAINERS_COUNT) position = sLastMatchCardNum[roundId]; @@ -4181,7 +4422,7 @@ static u8 Task_GetInfoCardInput(u8 taskId) position--; input = MATCHCARD_INPUT_UP; } - else if (JOY_NEW(DPAD_DOWN) && sInfoCard->pos == 1) + else if (gMain.newKeys & DPAD_DOWN && sInfoCard->pos == 1) { if (position == sLastMatchCardNum[roundId]) position = DOME_TOURNAMENT_TRAINERS_COUNT; @@ -4190,12 +4431,12 @@ static u8 Task_GetInfoCardInput(u8 taskId) input = MATCHCARD_INPUT_DOWN; } // Scrolling left/right from a match info card shows the trainer info card of the competitors for that match - else if (JOY_NEW(DPAD_LEFT) && sInfoCard->pos != 0) + else if (gMain.newKeys & DPAD_LEFT && sInfoCard->pos != 0) { input = MATCHCARD_INPUT_LEFT; sInfoCard->pos--; } - else if (JOY_NEW(DPAD_RIGHT) && (sInfoCard->pos == 0 || sInfoCard->pos == 1)) + else if (gMain.newKeys & DPAD_RIGHT && (sInfoCard->pos == 0 || sInfoCard->pos == 1)) { input = MATCHCARD_INPUT_RIGHT; sInfoCard->pos++; @@ -4305,7 +4546,7 @@ static void DisplayTrainerInfoOnCard(u8 flags, u8 trainerTourneyId) textPrinter.currentY = textPrinter.y; textPrinter.letterSpacing = 2; textPrinter.lineSpacing = 0; - textPrinter.style = 0; + textPrinter.unk = 0; textPrinter.fgColor = TEXT_DYNAMIC_COLOR_5; textPrinter.bgColor = TEXT_COLOR_TRANSPARENT; textPrinter.shadowColor = TEXT_DYNAMIC_COLOR_4; @@ -4838,7 +5079,7 @@ static void DisplayMatchInfoOnCard(u8 flags, u8 matchNo) textPrinter.currentY = textPrinter.y; textPrinter.letterSpacing = 0; textPrinter.lineSpacing = 0; - textPrinter.style = 0; + textPrinter.unk = 0; textPrinter.fgColor = TEXT_DYNAMIC_COLOR_5; textPrinter.bgColor = TEXT_COLOR_TRANSPARENT; textPrinter.shadowColor = TEXT_DYNAMIC_COLOR_4; @@ -5043,12 +5284,12 @@ static u8 UpdateTourneyTreeCursor(u8 taskId) int tourneyTreeCursorSpriteId = gTasks[taskId].data[1]; int roundId = gSaveBlock2Ptr->frontier.curChallengeBattleNum; - if (gMain.newKeys == B_BUTTON || (JOY_NEW(A_BUTTON) && tourneyTreeCursorSpriteId == TOURNEY_TREE_CLOSE_BUTTON)) + if (gMain.newKeys == B_BUTTON || (gMain.newKeys & A_BUTTON && tourneyTreeCursorSpriteId == TOURNEY_TREE_CLOSE_BUTTON)) { PlaySE(SE_SELECT); selection = TOURNEY_TREE_SELECTED_CLOSE; } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (tourneyTreeCursorSpriteId < DOME_TOURNAMENT_TRAINERS_COUNT) { @@ -5292,7 +5533,7 @@ static void Task_ShowTourneyTree(u8 taskId) gTasks[taskId].tState++; break; case 2: - sTilemapBuffer = AllocZeroed(BG_SCREEN_SIZE); + sTilemapBuffer = AllocZeroed(0x800); LZDecompressWram(gDomeTourneyLineMask_Tilemap, sTilemapBuffer); SetBgTilemapBuffer(1, sTilemapBuffer); CopyBgTilemapBufferToVram(1); @@ -5336,7 +5577,7 @@ static void Task_ShowTourneyTree(u8 taskId) textPrinter.lineSpacing = 0; textPrinter.currentX = GetStringCenterAlignXOffsetWithLetterSpacing(textPrinter.fontId, textPrinter.currentChar, 0x70, textPrinter.letterSpacing); textPrinter.currentY = 1; - textPrinter.style = 0; + textPrinter.unk = 0; textPrinter.fgColor = TEXT_DYNAMIC_COLOR_5; textPrinter.bgColor = TEXT_COLOR_TRANSPARENT; textPrinter.shadowColor = TEXT_DYNAMIC_COLOR_4; @@ -5517,7 +5758,7 @@ static void Task_HandleStaticTourneyTreeInput(u8 taskId) textPrinter.y = 0; textPrinter.letterSpacing = 2; textPrinter.lineSpacing = 0; - textPrinter.style = 0; + textPrinter.unk = 0; textPrinter.fgColor = TEXT_DYNAMIC_COLOR_2; textPrinter.bgColor = TEXT_COLOR_TRANSPARENT; textPrinter.shadowColor = TEXT_DYNAMIC_COLOR_4; @@ -5552,7 +5793,7 @@ static void Task_HandleStaticTourneyTreeInput(u8 taskId) gTasks[taskId].tState = STATE_WAIT_FOR_INPUT; break; case STATE_WAIT_FOR_INPUT: - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].tState = STATE_CLOSE_TOURNEY_TREE; diff --git a/src/battle_factory_screen.c b/src/battle_factory_screen.c index a3fa275c5..388881a1c 100644 --- a/src/battle_factory_screen.c +++ b/src/battle_factory_screen.c @@ -1478,7 +1478,7 @@ static void Task_HandleSelectionScreenYesNo(u8 taskId) gTasks[taskId].data[0] = 5; break; case 5: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (sFactorySelectScreen->yesNoCursorPos == 0) @@ -1496,7 +1496,7 @@ static void Task_HandleSelectionScreenYesNo(u8 taskId) gTasks[taskId].func = Task_HandleSelectionScreenChooseMons; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sub_819B958(4); @@ -1505,12 +1505,12 @@ static void Task_HandleSelectionScreenYesNo(u8 taskId) gTasks[taskId].data[0] = 1; gTasks[taskId].func = Task_HandleSelectionScreenChooseMons; } - else if (JOY_REPEAT(DPAD_UP)) + else if (gMain.newAndRepeatedKeys & DPAD_UP) { PlaySE(SE_SELECT); Select_UpdateYesNoCursorPosition(-1); } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { PlaySE(SE_SELECT); Select_UpdateYesNoCursorPosition(1); @@ -1538,7 +1538,7 @@ static void Task_HandleSelectionScreenMenu(u8 taskId) } break; case 3: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { u8 retVal; PlaySE(SE_SELECT); @@ -1565,7 +1565,7 @@ static void Task_HandleSelectionScreenMenu(u8 taskId) gTasks[taskId].func = Task_FromSelectScreenToSummaryScreen; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sub_819F3F8(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); @@ -1574,12 +1574,12 @@ static void Task_HandleSelectionScreenMenu(u8 taskId) gTasks[taskId].data[0] = 1; gTasks[taskId].func = Task_HandleSelectionScreenChooseMons; } - else if (JOY_REPEAT(DPAD_UP)) + else if (gMain.newAndRepeatedKeys & DPAD_UP) { PlaySE(SE_SELECT); Select_UpdateMenuCursorPosition(-1); } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { PlaySE(SE_SELECT); Select_UpdateMenuCursorPosition(1); @@ -1618,21 +1618,21 @@ static void Task_HandleSelectionScreenChooseMons(u8 taskId) } break; case 1: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); sFactorySelectScreen->unk2A2 = FALSE; gTasks[taskId].data[0] = 2; gTasks[taskId].func = Task_HandleSelectionScreenMenu; } - else if (JOY_REPEAT(DPAD_LEFT)) + else if (gMain.newAndRepeatedKeys & DPAD_LEFT) { PlaySE(SE_SELECT); Select_UpdateBallCursorPosition(-1); Select_PrintMonCategory(); Select_PrintMonSpecies(); } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { PlaySE(SE_SELECT); Select_UpdateBallCursorPosition(1); @@ -1641,7 +1641,7 @@ static void Task_HandleSelectionScreenChooseMons(u8 taskId) } break; case 11: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); sub_819F3F8(sFactorySelectScreen->unk294[1], &sFactorySelectScreen->unk2A0, FALSE); @@ -2361,7 +2361,7 @@ static void Task_HandleSwapScreenYesNo(u8 taskId) gTasks[taskId].data[0] = 5; break; case 5: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (sFactorySwapScreen->yesNoCursorPos == 0) @@ -2380,7 +2380,7 @@ static void Task_HandleSwapScreenYesNo(u8 taskId) gTasks[taskId].func = (void*)((hiPtr << 16) | loPtr); } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); gTasks[taskId].data[1] = 0; @@ -2389,12 +2389,12 @@ static void Task_HandleSwapScreenYesNo(u8 taskId) loPtr = gTasks[taskId].data[7]; gTasks[taskId].func = (void*)((hiPtr << 16) | loPtr); } - else if (JOY_REPEAT(DPAD_UP)) + else if (gMain.newAndRepeatedKeys & DPAD_UP) { PlaySE(SE_SELECT); Swap_UpdateYesNoCursorPosition(-1); } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { PlaySE(SE_SELECT); Swap_UpdateYesNoCursorPosition(1); @@ -2485,12 +2485,12 @@ static void Task_HandleSwapScreenMenu(u8 taskId) case 3: if (sFactorySwapScreen->unk30 != TRUE) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); Swap_RunMenuOptionFunc(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sub_819F3F8(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); @@ -2501,11 +2501,11 @@ static void Task_HandleSwapScreenMenu(u8 taskId) gTasks[taskId].data[5] = 1; gTasks[taskId].func = sub_819D770; } - else if (JOY_REPEAT(DPAD_UP)) + else if (gMain.newAndRepeatedKeys & DPAD_UP) { Swap_UpdateMenuCursorPosition(-1); } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { Swap_UpdateMenuCursorPosition(1); } @@ -2526,7 +2526,7 @@ static void Task_HandleSwapScreenChooseMons(u8 taskId) } break; case 1: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); sFactorySwapScreen->unk22 = FALSE; @@ -2534,7 +2534,7 @@ static void Task_HandleSwapScreenChooseMons(u8 taskId) sub_819EAC0(); Swap_RunActionFunc(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sFactorySwapScreen->unk22 = FALSE; @@ -2546,25 +2546,25 @@ static void Task_HandleSwapScreenChooseMons(u8 taskId) gTasks[taskId].data[5] = 0; gTasks[taskId].func = sub_819D588; } - else if (JOY_REPEAT(DPAD_LEFT)) + else if (gMain.newAndRepeatedKeys & DPAD_LEFT) { Swap_UpdateBallCursorPosition(-1); Swap_PrintMonCategory(); Swap_PrintMonSpecies(); } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { Swap_UpdateBallCursorPosition(1); Swap_PrintMonCategory(); Swap_PrintMonSpecies(); } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { Swap_UpdateActionCursorPosition(1); Swap_PrintMonCategory(); Swap_PrintMonSpecies(); } - else if (JOY_REPEAT(DPAD_UP)) + else if (gMain.newAndRepeatedKeys & DPAD_UP) { Swap_UpdateActionCursorPosition(-1); Swap_PrintMonCategory(); @@ -3929,7 +3929,7 @@ static void Task_SwapCantHaveSameMons(u8 taskId) gTasks[taskId].data[0]++; break; case 1: - if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON)) + if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sub_819F3F8(sFactorySwapScreen->unk2C, &sFactorySwapScreen->unk30, TRUE); diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index e3e63f0e8..83818798a 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -957,7 +957,7 @@ void HandleSpeciesGfxDataChange(u8 battlerAtk, u8 battlerDef, bool8 notTransform } src = gMonSpritesGfxPtr->sprites[position]; - dst = (void *)(OBJ_VRAM0 + gSprites[gBattlerSpriteIds[battlerAtk]].oam.tileNum * 32); + dst = (void *)(VRAM + 0x10000 + gSprites[gBattlerSpriteIds[battlerAtk]].oam.tileNum * 32); DmaCopy32(3, src, dst, 0x800); paletteOffset = 0x100 + battlerAtk * 16; lzPaletteData = GetMonSpritePalFromSpeciesAndPersonality(targetSpecies, otId, personalityValue); @@ -1014,12 +1014,15 @@ void BattleLoadSubstituteOrMonSpriteGfx(u8 battlerId, bool8 loadMonSprite) palOffset = (battlerId * 16) + 0x100; LoadCompressedPalette(gSubstituteDollPal, palOffset, 32); } - else if (!IsContest()) + else { - if (GetBattlerSide(battlerId) != B_SIDE_PLAYER) - BattleLoadOpponentMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[battlerId]], battlerId); - else - BattleLoadPlayerMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[battlerId]], battlerId); + if (!IsContest()) + { + if (GetBattlerSide(battlerId) != B_SIDE_PLAYER) + BattleLoadOpponentMonSpriteGfx(&gEnemyParty[gBattlerPartyIndexes[battlerId]], battlerId); + else + BattleLoadPlayerMonSpriteGfx(&gPlayerParty[gBattlerPartyIndexes[battlerId]], battlerId); + } } } diff --git a/src/battle_main.c b/src/battle_main.c index bf0fdc1aa..0c3e84c1e 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -11,7 +11,6 @@ #include "battle_scripts.h" #include "battle_setup.h" #include "battle_tower.h" -#include "battle_util.h" #include "berry.h" #include "bg.h" #include "data.h" @@ -67,6 +66,11 @@ extern struct MusicPlayerInfo gMPlayInfo_SE2; extern const struct BgTemplate gBattleBgTemplates[]; extern const struct WindowTemplate *const gBattleWindowTemplates[]; +extern const u8 *const gBattleScriptsForMoveEffects[]; +extern const u8 *const gBattlescriptsForBallThrow[]; +extern const u8 *const gBattlescriptsForRunningByItem[]; +extern const u8 *const gBattlescriptsForUsingItem[]; +extern const u8 *const gBattlescriptsForSafariActions[]; // this file's functions #if !defined(NONMATCHING) && MODERN @@ -95,6 +99,7 @@ static void SpriteCB_AnimFaintOpponent(struct Sprite *sprite); static void SpriteCb_BlinkVisible(struct Sprite *sprite); static void SpriteCallbackDummy_3(struct Sprite *sprite); static void oac_poke_ally_(struct Sprite *sprite); +static void SpecialStatusesClear(void); static void TurnValuesCleanUp(bool8 var0); static void SpriteCB_BounceEffect(struct Sprite *sprite); static void BattleStartClearSetData(void); @@ -127,7 +132,19 @@ static void HandleEndTurn_BattleLost(void); static void HandleEndTurn_RanFromBattle(void); static void HandleEndTurn_MonFled(void); static void HandleEndTurn_FinishBattle(void); - +static void HandleAction_UseMove(void); +static void HandleAction_Switch(void); +static void HandleAction_UseItem(void); +static void HandleAction_Run(void); +static void HandleAction_WatchesCarefully(void); +static void HandleAction_SafariZoneBallThrow(void); +static void HandleAction_ThrowPokeblock(void); +static void HandleAction_GoNear(void); +static void HandleAction_SafariZoneRun(void); +static void HandleAction_WallyBallThrow(void); +static void HandleAction_TryFinish(void); +static void HandleAction_NothingIsFainted(void); +static void HandleAction_ActionFinished(void); // EWRAM vars EWRAM_DATA u16 gBattle_BG0_X = 0; @@ -574,6 +591,10 @@ const u8 * const gStatusConditionStringsTable[7][2] = {gStatusConditionString_LoveJpn, gText_Love} }; +static const u8 sPkblToEscapeFactor[][3] = {{0, 0, 0}, {3, 5, 0}, {2, 3, 0}, {1, 2, 0}, {1, 1, 0}}; +static const u8 sGoNearCounterToCatchFactor[] = {4, 3, 2, 1}; +static const u8 sGoNearCounterToEscapeFactor[] = {4, 4, 4, 4}; + // code void CB2_InitBattle(void) { @@ -634,16 +655,19 @@ static void CB2_InitBattleInternal(void) gBattle_WIN0V = 0x5051; ScanlineEffect_Clear(); - for (i = 0; i < 80; i++) + i = 0; + while (i < 80) { gScanlineEffectRegBuffers[0][i] = 0xF0; gScanlineEffectRegBuffers[1][i] = 0xF0; + i++; } - for (; i < 160; i++) + while (i < 160) { gScanlineEffectRegBuffers[0][i] = 0xFF10; gScanlineEffectRegBuffers[1][i] = 0xFF10; + i++; } ScanlineEffect_SetParams(sIntroScanlineParams16Bit); @@ -770,7 +794,8 @@ static void SetPlayerBerryDataInBattleStruct(void) static void SetAllPlayersBerryData(void) { - s32 i, j; + s32 i; + s32 j; if (!(gBattleTypeFlags & BATTLE_TYPE_LINK)) { @@ -1829,7 +1854,7 @@ void BattleMainCB2(void) UpdatePaletteFade(); RunTasks(); - if (JOY_HELD(B_BUTTON) && gBattleTypeFlags & BATTLE_TYPE_RECORDED && sub_8186450()) + if (gMain.heldKeys & B_BUTTON && gBattleTypeFlags & BATTLE_TYPE_RECORDED && sub_8186450()) { gSpecialVar_Result = gBattleOutcome = B_OUTCOME_PLAYER_TELEPORTED; ResetPaletteFadeControl(); @@ -2485,7 +2510,7 @@ static void sub_803939C(void) } break; case 5: - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { if (gBattleCommunication[CURSOR_POSITION] != 0) { @@ -2495,7 +2520,7 @@ static void sub_803939C(void) BattleCreateYesNoCursorAt(0); } } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (gBattleCommunication[CURSOR_POSITION] == 0) { @@ -2505,7 +2530,7 @@ static void sub_803939C(void) BattleCreateYesNoCursorAt(1); } } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (gBattleCommunication[CURSOR_POSITION] == 0) @@ -2519,7 +2544,7 @@ static void sub_803939C(void) gBattleCommunication[MULTIUSE_STATE]++; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); gBattleCommunication[MULTIUSE_STATE]++; @@ -2686,7 +2711,8 @@ static void sub_80398BC(struct Sprite *sprite) // unused? static void sub_80398D0(struct Sprite *sprite) { - if (--sprite->data[4] == 0) + sprite->data[4]--; + if (sprite->data[4] == 0) { sprite->data[4] = 8; sprite->invisible ^= 1; @@ -3417,13 +3443,17 @@ static void BattleIntroDrawTrainersOrMonsSprites(void) } } - if ((gBattleTypeFlags & BATTLE_TYPE_MULTI) && (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT || GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT)) + if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { - BtlController_EmitDrawTrainerPic(0); - MarkBattlerForControllerExec(gActiveBattler); + if (GetBattlerPosition(gActiveBattler) == B_POSITION_PLAYER_RIGHT + || GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT) + { + BtlController_EmitDrawTrainerPic(0); + MarkBattlerForControllerExec(gActiveBattler); + } } - if ((gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS) && (GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT)) + if (gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS && GetBattlerPosition(gActiveBattler) == B_POSITION_OPPONENT_RIGHT) { BtlController_EmitDrawTrainerPic(0); MarkBattlerForControllerExec(gActiveBattler); @@ -3530,7 +3560,7 @@ static void BattleIntroPrintWildMonAttacked(void) static void BattleIntroPrintOpponentSendsOut(void) { - u8 position; + u32 position; if (gBattleControllerExecFlags) return; @@ -3553,7 +3583,7 @@ static void BattleIntroPrintOpponentSendsOut(void) static void BattleIntroOpponent2SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_OPPONENT_RIGHT; @@ -3579,26 +3609,22 @@ static void BattleIntroOpponent2SendsOutMonAnimation(void) gBattleMainFunc = BattleIntroRecordMonsToDex; } +#ifdef NONMATCHING static void BattleIntroOpponent1SendsOutMonAnimation(void) { - u8 position; + u32 position; - if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) + if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) + position = B_POSITION_OPPONENT_LEFT; + else if (gBattleTypeFlags & BATTLE_TYPE_x2000000) { - if (gBattleTypeFlags & BATTLE_TYPE_x2000000) - { - if (gBattleTypeFlags & BATTLE_TYPE_x80000000) - position = B_POSITION_OPPONENT_LEFT; - else - position = B_POSITION_PLAYER_LEFT; - } - else + if (gBattleTypeFlags & BATTLE_TYPE_x80000000) position = B_POSITION_OPPONENT_LEFT; + else + position = B_POSITION_PLAYER_LEFT; } else - { position = B_POSITION_OPPONENT_LEFT; - } if (gBattleControllerExecFlags) return; @@ -3619,6 +3645,92 @@ static void BattleIntroOpponent1SendsOutMonAnimation(void) gBattleMainFunc = BattleIntroRecordMonsToDex; } +#else +NAKED +static void BattleIntroOpponent1SendsOutMonAnimation(void) +{ + asm_unified( + "push {r4-r6,lr}\n\ + ldr r0, =gBattleTypeFlags\n\ + ldr r2, [r0]\n\ + movs r0, 0x80\n\ + lsls r0, 17\n\ + ands r0, r2\n\ + cmp r0, 0\n\ + beq _0803B298\n\ + movs r0, 0x80\n\ + lsls r0, 18\n\ + ands r0, r2\n\ + cmp r0, 0\n\ + beq _0803B298\n\ + movs r1, 0x80\n\ + lsls r1, 24\n\ + ands r1, r2\n\ + negs r0, r1\n\ + orrs r0, r1\n\ + lsrs r5, r0, 31\n\ + b _0803B29A\n\ + .pool\n\ +_0803B288:\n\ + ldr r1, =gBattleMainFunc\n\ + ldr r0, =BattleIntroOpponent2SendsOutMonAnimation\n\ + b _0803B2F0\n\ + .pool\n\ +_0803B298:\n\ + movs r5, 0x1\n\ +_0803B29A:\n\ + ldr r0, =gBattleControllerExecFlags\n\ + ldr r2, [r0]\n\ + cmp r2, 0\n\ + bne _0803B2F2\n\ + ldr r0, =gActiveBattler\n\ + strb r2, [r0]\n\ + ldr r1, =gBattlersCount\n\ + adds r4, r0, 0\n\ + ldrb r1, [r1]\n\ + cmp r2, r1\n\ + bcs _0803B2EC\n\ + adds r6, r4, 0\n\ +_0803B2B2:\n\ + ldrb r0, [r4]\n\ + bl GetBattlerPosition\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + cmp r0, r5\n\ + bne _0803B2D8\n\ + movs r0, 0\n\ + bl BtlController_EmitIntroTrainerBallThrow\n\ + ldrb r0, [r4]\n\ + bl MarkBattlerForControllerExec\n\ + ldr r0, =gBattleTypeFlags\n\ + ldr r0, [r0]\n\ + ldr r1, =0x00008040\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + bne _0803B288\n\ +_0803B2D8:\n\ + ldrb r0, [r6]\n\ + adds r0, 0x1\n\ + strb r0, [r6]\n\ + ldr r1, =gBattlersCount\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + ldr r4, =gActiveBattler\n\ + ldrb r1, [r1]\n\ + cmp r0, r1\n\ + bcc _0803B2B2\n\ +_0803B2EC:\n\ + ldr r1, =gBattleMainFunc\n\ + ldr r0, =BattleIntroRecordMonsToDex\n\ +_0803B2F0:\n\ + str r0, [r1]\n\ +_0803B2F2:\n\ + pop {r4-r6}\n\ + pop {r0}\n\ + bx r0\n\ + .pool"); +} +#endif // NONMATCHING static void BattleIntroRecordMonsToDex(void) { @@ -3640,7 +3752,7 @@ static void BattleIntroRecordMonsToDex(void) } } -static void sub_803B3AC(void) // unused +void sub_803B3AC(void) // unused { if (gBattleControllerExecFlags == 0) gBattleMainFunc = BattleIntroPrintPlayerSendsOut; @@ -3673,7 +3785,7 @@ static void BattleIntroPrintPlayerSendsOut(void) static void BattleIntroPlayer2SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_PLAYER_RIGHT; @@ -3705,7 +3817,7 @@ static void BattleIntroPlayer2SendsOutMonAnimation(void) static void BattleIntroPlayer1SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_PLAYER_LEFT; @@ -3743,7 +3855,7 @@ static void BattleIntroPlayer1SendsOutMonAnimation(void) gBattleMainFunc = TryDoEventsBeforeFirstTurn; } -static void sub_803B598(void) // unused +void sub_803B598(void) // unused { if (gBattleControllerExecFlags == 0) { @@ -3766,7 +3878,8 @@ static void sub_803B598(void) // unused static void TryDoEventsBeforeFirstTurn(void) { - s32 i, j; + s32 i; + s32 j; u8 effect = 0; if (gBattleControllerExecFlags) @@ -3956,7 +4069,11 @@ u8 IsRunningFromBattleImpossible(void) gPotentialItemEffectBattler = gActiveBattler; - if ((holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) || (gBattleTypeFlags & BATTLE_TYPE_LINK) || (gBattleMons[gActiveBattler].ability == ABILITY_RUN_AWAY)) + if (holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) + return 0; + if (gBattleTypeFlags & BATTLE_TYPE_LINK) + return 0; + if (gBattleMons[gActiveBattler].ability == ABILITY_RUN_AWAY) return 0; side = GetBattlerSide(gActiveBattler); @@ -4733,38 +4850,40 @@ static void SetActionsAndBattlersTurnOrder(void) gBattleStruct->focusPunchBattlerId = 0; return; } - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + else { - if (gChosenActionByBattler[gActiveBattler] == B_ACTION_USE_ITEM || gChosenActionByBattler[gActiveBattler] == B_ACTION_SWITCH) + for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) { - gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; - gBattlerByTurnOrder[turnOrderId] = gActiveBattler; - turnOrderId++; - } - } - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) - { - if (gChosenActionByBattler[gActiveBattler] != B_ACTION_USE_ITEM && gChosenActionByBattler[gActiveBattler] != B_ACTION_SWITCH) - { - gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; - gBattlerByTurnOrder[turnOrderId] = gActiveBattler; - turnOrderId++; - } - } - for (i = 0; i < gBattlersCount - 1; i++) - { - for (j = i + 1; j < gBattlersCount; j++) - { - u8 battler1 = gBattlerByTurnOrder[i]; - u8 battler2 = gBattlerByTurnOrder[j]; - - if (gActionsByTurnOrder[i] != B_ACTION_USE_ITEM - && gActionsByTurnOrder[j] != B_ACTION_USE_ITEM - && gActionsByTurnOrder[i] != B_ACTION_SWITCH - && gActionsByTurnOrder[j] != B_ACTION_SWITCH) + if (gChosenActionByBattler[gActiveBattler] == B_ACTION_USE_ITEM || gChosenActionByBattler[gActiveBattler] == B_ACTION_SWITCH) { - if (GetWhoStrikesFirst(battler1, battler2, FALSE)) - SwapTurnOrder(i, j); + gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; + gBattlerByTurnOrder[turnOrderId] = gActiveBattler; + turnOrderId++; + } + } + for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + { + if (gChosenActionByBattler[gActiveBattler] != B_ACTION_USE_ITEM && gChosenActionByBattler[gActiveBattler] != B_ACTION_SWITCH) + { + gActionsByTurnOrder[turnOrderId] = gChosenActionByBattler[gActiveBattler]; + gBattlerByTurnOrder[turnOrderId] = gActiveBattler; + turnOrderId++; + } + } + for (i = 0; i < gBattlersCount - 1; i++) + { + for (j = i + 1; j < gBattlersCount; j++) + { + u8 battler1 = gBattlerByTurnOrder[i]; + u8 battler2 = gBattlerByTurnOrder[j]; + if (gActionsByTurnOrder[i] != B_ACTION_USE_ITEM + && gActionsByTurnOrder[j] != B_ACTION_USE_ITEM + && gActionsByTurnOrder[i] != B_ACTION_SWITCH + && gActionsByTurnOrder[j] != B_ACTION_SWITCH) + { + if (GetWhoStrikesFirst(battler1, battler2, FALSE)) + SwapTurnOrder(i, j); + } } } } @@ -4810,7 +4929,7 @@ static void TurnValuesCleanUp(bool8 var0) gSideTimers[1].followmeTimer = 0; } -void SpecialStatusesClear(void) +static void SpecialStatusesClear(void) { for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) { @@ -4842,8 +4961,12 @@ static void CheckFocusPunch_ClearVarsBeforeTurnStarts(void) } TryClearRageStatuses(); - gCurrentTurnActionNumber = 0; //See comment underneath - gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; //Should be gActionsByTurnOrder[(gCurrentTurnActionNumber = 0)], but that doesn't match + gCurrentTurnActionNumber = 0; +{ + // something stupid needed to match + u8 zero; + gCurrentActionFuncId = gActionsByTurnOrder[(zero = 0)]; +} gDynamicBasePower = 0; gBattleStruct->dynamicMoveType = 0; gBattleMainFunc = RunTurnActionsFunctions; @@ -4866,10 +4989,13 @@ static void RunTurnActionsFunctions(void) gHitMarker &= ~(HITMARKER_x100000); gBattleMainFunc = sEndTurnFuncsTable[gBattleOutcome & 0x7F]; } - else if (gBattleStruct->savedTurnActionNumber != gCurrentTurnActionNumber) // action turn has been done, clear hitmarker bits for another battlerId + else { - gHitMarker &= ~(HITMARKER_NO_ATTACKSTRING); - gHitMarker &= ~(HITMARKER_UNABLE_TO_USE_MOVE); + if (gBattleStruct->savedTurnActionNumber != gCurrentTurnActionNumber) // action turn has been done, clear hitmarker bits for another battlerId + { + gHitMarker &= ~(HITMARKER_NO_ATTACKSTRING); + gHitMarker &= ~(HITMARKER_UNABLE_TO_USE_MOVE); + } } } @@ -4986,15 +5112,15 @@ static void HandleEndTurn_RanFromBattle(void) { switch (gProtectStructs[gBattlerAttacker].fleeFlag) { + default: + gBattlescriptCurrInstr = BattleScript_GotAwaySafely; + break; case 1: gBattlescriptCurrInstr = BattleScript_SmokeBallEscape; break; case 2: gBattlescriptCurrInstr = BattleScript_RanAwayUsingMonAbility; break; - default: - gBattlescriptCurrInstr = BattleScript_GotAwaySafely; - break; } } @@ -5078,7 +5204,10 @@ static void FreeResetData_ReturnToOvOrDoEvolutions(void) gBattleMainFunc = ReturnFromBattleToOverworld; return; } - gBattleMainFunc = TryEvolvePokemon; + else + { + gBattleMainFunc = TryEvolvePokemon; + } } FreeAllWindowBuffers(); @@ -5174,3 +5303,592 @@ void RunBattleScriptCommands(void) gBattleScriptingCommandsTable[gBattlescriptCurrInstr[0]](); } +static void HandleAction_UseMove(void) +{ + u8 side; + u8 var = 4; + + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + + if (*(&gBattleStruct->field_91) & gBitTable[gBattlerAttacker]) + { + gCurrentActionFuncId = B_ACTION_FINISHED; + return; + } + + gCritMultiplier = 1; + gBattleScripting.dmgMultiplier = 1; + gBattleStruct->atkCancellerTracker = 0; + gMoveResultFlags = 0; + gMultiHitCounter = 0; + gBattleCommunication[6] = 0; + gCurrMovePos = gChosenMovePos = *(gBattleStruct->chosenMovePositions + gBattlerAttacker); + + // choose move + if (gProtectStructs[gBattlerAttacker].noValidMoves) + { + gProtectStructs[gBattlerAttacker].noValidMoves = 0; + gCurrentMove = gChosenMove = MOVE_STRUGGLE; + gHitMarker |= HITMARKER_NO_PPDEDUCT; + *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(MOVE_STRUGGLE, 0); + } + else if (gBattleMons[gBattlerAttacker].status2 & STATUS2_MULTIPLETURNS || gBattleMons[gBattlerAttacker].status2 & STATUS2_RECHARGE) + { + gCurrentMove = gChosenMove = gLockedMoves[gBattlerAttacker]; + } + // encore forces you to use the same move + else if (gDisableStructs[gBattlerAttacker].encoredMove != MOVE_NONE + && gDisableStructs[gBattlerAttacker].encoredMove == gBattleMons[gBattlerAttacker].moves[gDisableStructs[gBattlerAttacker].encoredMovePos]) + { + gCurrentMove = gChosenMove = gDisableStructs[gBattlerAttacker].encoredMove; + gCurrMovePos = gChosenMovePos = gDisableStructs[gBattlerAttacker].encoredMovePos; + *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(gCurrentMove, 0); + } + // check if the encored move wasn't overwritten + else if (gDisableStructs[gBattlerAttacker].encoredMove != MOVE_NONE + && gDisableStructs[gBattlerAttacker].encoredMove != gBattleMons[gBattlerAttacker].moves[gDisableStructs[gBattlerAttacker].encoredMovePos]) + { + gCurrMovePos = gChosenMovePos = gDisableStructs[gBattlerAttacker].encoredMovePos; + gCurrentMove = gChosenMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; + gDisableStructs[gBattlerAttacker].encoredMove = MOVE_NONE; + gDisableStructs[gBattlerAttacker].encoredMovePos = 0; + gDisableStructs[gBattlerAttacker].encoreTimer = 0; + *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(gCurrentMove, 0); + } + else if (gBattleMons[gBattlerAttacker].moves[gCurrMovePos] != gChosenMoveByBattler[gBattlerAttacker]) + { + gCurrentMove = gChosenMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; + *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(gCurrentMove, 0); + } + else + { + gCurrentMove = gChosenMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; + } + + if (gBattleMons[gBattlerAttacker].hp != 0) + { + if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) + gBattleResults.lastUsedMovePlayer = gCurrentMove; + else + gBattleResults.lastUsedMoveOpponent = gCurrentMove; + } + + // choose target + side = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE; + if (gSideTimers[side].followmeTimer != 0 + && gBattleMoves[gCurrentMove].target == MOVE_TARGET_SELECTED + && GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gSideTimers[side].followmeTarget) + && gBattleMons[gSideTimers[side].followmeTarget].hp != 0) + { + gBattlerTarget = gSideTimers[side].followmeTarget; + } + else if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) + && gSideTimers[side].followmeTimer == 0 + && (gBattleMoves[gCurrentMove].power != 0 + || gBattleMoves[gCurrentMove].target != MOVE_TARGET_USER) + && gBattleMons[*(gBattleStruct->moveTarget + gBattlerAttacker)].ability != ABILITY_LIGHTNING_ROD + && gBattleMoves[gCurrentMove].type == TYPE_ELECTRIC) + { + side = GetBattlerSide(gBattlerAttacker); + for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + { + if (side != GetBattlerSide(gActiveBattler) + && *(gBattleStruct->moveTarget + gBattlerAttacker) != gActiveBattler + && gBattleMons[gActiveBattler].ability == ABILITY_LIGHTNING_ROD + && GetBattlerTurnOrderNum(gActiveBattler) < var) + { + var = GetBattlerTurnOrderNum(gActiveBattler); + } + } + if (var == 4) + { + if (gBattleMoves[gChosenMove].target & MOVE_TARGET_RANDOM) + { + if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) + { + if (Random() & 1) + gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); + else + gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); + } + else + { + if (Random() & 1) + gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + else + gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); + } + } + else + { + gBattlerTarget = *(gBattleStruct->moveTarget + gBattlerAttacker); + } + + if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) + { + if (GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) + { + gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); + } + else + { + gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_SIDE); + if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) + gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); + } + } + } + else + { + gActiveBattler = gBattlerByTurnOrder[var]; + RecordAbilityBattle(gActiveBattler, gBattleMons[gActiveBattler].ability); + gSpecialStatuses[gActiveBattler].lightningRodRedirected = 1; + gBattlerTarget = gActiveBattler; + } + } + else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE + && gBattleMoves[gChosenMove].target & MOVE_TARGET_RANDOM) + { + if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) + { + if (Random() & 1) + gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); + else + gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); + } + else + { + if (Random() & 1) + gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); + else + gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); + } + + if (gAbsentBattlerFlags & gBitTable[gBattlerTarget] + && GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) + { + gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); + } + } + else + { + gBattlerTarget = *(gBattleStruct->moveTarget + gBattlerAttacker); + if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) + { + if (GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) + { + gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); + } + else + { + gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_SIDE); + if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) + gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); + } + } + } + + // choose battlescript + if (gBattleTypeFlags & BATTLE_TYPE_PALACE + && gProtectStructs[gBattlerAttacker].palaceUnableToUseMove) + { + if (gBattleMons[gBattlerAttacker].hp == 0) + { + gCurrentActionFuncId = B_ACTION_FINISHED; + return; + } + else if (gPalaceSelectionBattleScripts[gBattlerAttacker] != NULL) + { + gBattleCommunication[MULTISTRING_CHOOSER] = 4; + gBattlescriptCurrInstr = gPalaceSelectionBattleScripts[gBattlerAttacker]; + gPalaceSelectionBattleScripts[gBattlerAttacker] = NULL; + } + else + { + gBattleCommunication[MULTISTRING_CHOOSER] = 4; + gBattlescriptCurrInstr = BattleScript_MoveUsedLoafingAround; + } + } + else + { + gBattlescriptCurrInstr = gBattleScriptsForMoveEffects[gBattleMoves[gCurrentMove].effect]; + } + + if (gBattleTypeFlags & BATTLE_TYPE_ARENA) + BattleArena_AddMindPoints(gBattlerAttacker); + + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; +} + +static void HandleAction_Switch(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + gActionSelectionCursor[gBattlerAttacker] = 0; + gMoveSelectionCursor[gBattlerAttacker] = 0; + + PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBattlerAttacker, *(gBattleStruct->field_58 + gBattlerAttacker)) + + gBattleScripting.battler = gBattlerAttacker; + gBattlescriptCurrInstr = BattleScript_ActionSwitch; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; + + if (gBattleResults.playerSwitchesCounter < 255) + gBattleResults.playerSwitchesCounter++; +} + +static void HandleAction_UseItem(void) +{ + gBattlerAttacker = gBattlerTarget = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); + gLastUsedItem = gBattleBufferB[gBattlerAttacker][1] | (gBattleBufferB[gBattlerAttacker][2] << 8); + + if (gLastUsedItem <= LAST_BALL) // is ball + { + gBattlescriptCurrInstr = gBattlescriptsForBallThrow[gLastUsedItem]; + } + else if (gLastUsedItem == ITEM_POKE_DOLL || gLastUsedItem == ITEM_FLUFFY_TAIL) + { + gBattlescriptCurrInstr = gBattlescriptsForRunningByItem[0]; + } + else if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) + { + gBattlescriptCurrInstr = gBattlescriptsForUsingItem[0]; + } + else + { + gBattleScripting.battler = gBattlerAttacker; + + switch (*(gBattleStruct->AI_itemType + (gBattlerAttacker >> 1))) + { + case AI_ITEM_FULL_RESTORE: + case AI_ITEM_HEAL_HP: + break; + case AI_ITEM_CURE_CONDITION: + gBattleCommunication[MULTISTRING_CHOOSER] = 0; + if (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1) + { + if (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 0x3E) + gBattleCommunication[MULTISTRING_CHOOSER] = 5; + } + else + { + while (!(*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1)) + { + *(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) >>= 1; + gBattleCommunication[MULTISTRING_CHOOSER]++; + } + } + break; + case AI_ITEM_X_STAT: + gBattleCommunication[MULTISTRING_CHOOSER] = 4; + if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 0x80) + { + gBattleCommunication[MULTISTRING_CHOOSER] = 5; + } + else + { + PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_ATK) + PREPARE_STRING_BUFFER(gBattleTextBuff2, CHAR_X) + + while (!((*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1))) & 1)) + { + *(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) >>= 1; + gBattleTextBuff1[2]++; + } + + gBattleScripting.animArg1 = gBattleTextBuff1[2] + 14; + gBattleScripting.animArg2 = 0; + } + break; + case AI_ITEM_GUARD_SPECS: + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) + gBattleCommunication[MULTISTRING_CHOOSER] = 2; + else + gBattleCommunication[MULTISTRING_CHOOSER] = 0; + break; + } + + gBattlescriptCurrInstr = gBattlescriptsForUsingItem[*(gBattleStruct->AI_itemType + gBattlerAttacker / 2)]; + } + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; +} + +bool8 TryRunFromBattle(u8 battler) +{ + bool8 effect = FALSE; + u8 holdEffect; + u8 pyramidMultiplier; + u8 speedVar; + + if (gBattleMons[battler].item == ITEM_ENIGMA_BERRY) + holdEffect = gEnigmaBerries[battler].holdEffect; + else + holdEffect = ItemId_GetHoldEffect(gBattleMons[battler].item); + + gPotentialItemEffectBattler = battler; + + if (holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) + { + gLastUsedItem = gBattleMons[battler].item; + gProtectStructs[battler].fleeFlag = 1; + effect++; + } + else if (gBattleMons[battler].ability == ABILITY_RUN_AWAY) + { + if (InBattlePyramid()) + { + gBattleStruct->runTries++; + pyramidMultiplier = GetPyramidRunMultiplier(); + speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); + if (speedVar > (Random() & 0xFF)) + { + gLastUsedAbility = ABILITY_RUN_AWAY; + gProtectStructs[battler].fleeFlag = 2; + effect++; + } + } + else + { + gLastUsedAbility = ABILITY_RUN_AWAY; + gProtectStructs[battler].fleeFlag = 2; + effect++; + } + } + else if (gBattleTypeFlags & (BATTLE_TYPE_FRONTIER | BATTLE_TYPE_TRAINER_HILL) && gBattleTypeFlags & BATTLE_TYPE_TRAINER) + { + effect++; + } + else + { + if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) + { + if (InBattlePyramid()) + { + pyramidMultiplier = GetPyramidRunMultiplier(); + speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); + if (speedVar > (Random() & 0xFF)) + effect++; + } + else if (gBattleMons[battler].speed < gBattleMons[BATTLE_OPPOSITE(battler)].speed) + { + speedVar = (gBattleMons[battler].speed * 128) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); + if (speedVar > (Random() & 0xFF)) + effect++; + } + else // same speed or faster + { + effect++; + } + } + + gBattleStruct->runTries++; + } + + if (effect) + { + gCurrentTurnActionNumber = gBattlersCount; + gBattleOutcome = B_OUTCOME_RAN; + } + + return effect; +} + +static void HandleAction_Run(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + + if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) + { + gCurrentTurnActionNumber = gBattlersCount; + + for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) + { + if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) + { + if (gChosenActionByBattler[gActiveBattler] == B_ACTION_RUN) + gBattleOutcome |= B_OUTCOME_LOST; + } + else + { + if (gChosenActionByBattler[gActiveBattler] == B_ACTION_RUN) + gBattleOutcome |= B_OUTCOME_WON; + } + } + + gBattleOutcome |= B_OUTCOME_LINK_BATTLE_RAN; + gSaveBlock2Ptr->frontier.disableRecordBattle = TRUE; + } + else + { + if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) + { + if (!TryRunFromBattle(gBattlerAttacker)) // failed to run away + { + ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); + gBattleCommunication[MULTISTRING_CHOOSER] = 3; + gBattlescriptCurrInstr = BattleScript_PrintFailedToRunString; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; + } + } + else + { + if (gBattleMons[gBattlerAttacker].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION)) + { + gBattleCommunication[MULTISTRING_CHOOSER] = 4; + gBattlescriptCurrInstr = BattleScript_PrintFailedToRunString; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; + } + else + { + gCurrentTurnActionNumber = gBattlersCount; + gBattleOutcome = B_OUTCOME_MON_FLED; + } + } + } +} + +static void HandleAction_WatchesCarefully(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + gBattlescriptCurrInstr = gBattlescriptsForSafariActions[0]; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; +} + +static void HandleAction_SafariZoneBallThrow(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + gNumSafariBalls--; + gLastUsedItem = ITEM_SAFARI_BALL; + gBattlescriptCurrInstr = gBattlescriptsForBallThrow[ITEM_SAFARI_BALL]; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; +} + +static void HandleAction_ThrowPokeblock(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + gBattleCommunication[MULTISTRING_CHOOSER] = gBattleBufferB[gBattlerAttacker][1] - 1; + gLastUsedItem = gBattleBufferB[gBattlerAttacker][2]; + + if (gBattleResults.pokeblockThrows < 0xFF) + gBattleResults.pokeblockThrows++; + if (gBattleStruct->safariPkblThrowCounter < 3) + gBattleStruct->safariPkblThrowCounter++; + if (gBattleStruct->safariEscapeFactor > 1) + { + if (gBattleStruct->safariEscapeFactor < sPkblToEscapeFactor[gBattleStruct->safariPkblThrowCounter][gBattleCommunication[MULTISTRING_CHOOSER]]) + gBattleStruct->safariEscapeFactor = 1; + else + gBattleStruct->safariEscapeFactor -= sPkblToEscapeFactor[gBattleStruct->safariPkblThrowCounter][gBattleCommunication[MULTISTRING_CHOOSER]]; + } + + gBattlescriptCurrInstr = gBattlescriptsForSafariActions[2]; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; +} + +static void HandleAction_GoNear(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + + gBattleStruct->safariCatchFactor += sGoNearCounterToCatchFactor[gBattleStruct->safariGoNearCounter]; + if (gBattleStruct->safariCatchFactor > 20) + gBattleStruct->safariCatchFactor = 20; + + gBattleStruct->safariEscapeFactor += sGoNearCounterToEscapeFactor[gBattleStruct->safariGoNearCounter]; + if (gBattleStruct->safariEscapeFactor > 20) + gBattleStruct->safariEscapeFactor = 20; + + if (gBattleStruct->safariGoNearCounter < 3) + { + gBattleStruct->safariGoNearCounter++; + gBattleCommunication[MULTISTRING_CHOOSER] = 0; + } + else + { + gBattleCommunication[MULTISTRING_CHOOSER] = 1; // Can't get closer. + } + gBattlescriptCurrInstr = gBattlescriptsForSafariActions[1]; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; +} + +static void HandleAction_SafariZoneRun(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + PlaySE(SE_FLEE); + gCurrentTurnActionNumber = gBattlersCount; + gBattleOutcome = B_OUTCOME_RAN; +} + +static void HandleAction_WallyBallThrow(void) +{ + gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; + gBattle_BG0_X = 0; + gBattle_BG0_Y = 0; + + PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBattlerAttacker, gBattlerPartyIndexes[gBattlerAttacker]) + + gBattlescriptCurrInstr = gBattlescriptsForSafariActions[3]; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; + gActionsByTurnOrder[1] = B_ACTION_FINISHED; +} + +static void HandleAction_TryFinish(void) +{ + if (!HandleFaintedMonActions()) + { + gBattleStruct->faintedActionsState = 0; + gCurrentActionFuncId = B_ACTION_FINISHED; + } +} + +static void HandleAction_NothingIsFainted(void) +{ + gCurrentTurnActionNumber++; + gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; + gHitMarker &= ~(HITMARKER_DESTINYBOND | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_ATTACKSTRING_PRINTED + | HITMARKER_NO_PPDEDUCT | HITMARKER_IGNORE_SAFEGUARD | HITMARKER_IGNORE_ON_AIR + | HITMARKER_IGNORE_UNDERGROUND | HITMARKER_IGNORE_UNDERWATER | HITMARKER_x100000 + | HITMARKER_OBEYS | HITMARKER_x10 | HITMARKER_SYNCHRONISE_EFFECT + | HITMARKER_CHARGING | HITMARKER_x4000000); +} + +static void HandleAction_ActionFinished(void) +{ + *(gBattleStruct->monToSwitchIntoId + gBattlerByTurnOrder[gCurrentTurnActionNumber]) = 6; + gCurrentTurnActionNumber++; + gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; + SpecialStatusesClear(); + gHitMarker &= ~(HITMARKER_DESTINYBOND | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_ATTACKSTRING_PRINTED + | HITMARKER_NO_PPDEDUCT | HITMARKER_IGNORE_SAFEGUARD | HITMARKER_IGNORE_ON_AIR + | HITMARKER_IGNORE_UNDERGROUND | HITMARKER_IGNORE_UNDERWATER | HITMARKER_x100000 + | HITMARKER_OBEYS | HITMARKER_x10 | HITMARKER_SYNCHRONISE_EFFECT + | HITMARKER_CHARGING | HITMARKER_x4000000); + + gCurrentMove = 0; + gBattleMoveDamage = 0; + gMoveResultFlags = 0; + gBattleScripting.animTurn = 0; + gBattleScripting.animTargetsHit = 0; + gLastLandedMoves[gBattlerAttacker] = 0; + gLastHitByType[gBattlerAttacker] = 0; + gBattleStruct->dynamicMoveType = 0; + gDynamicBasePower = 0; + gBattleScripting.moveendState = 0; + gBattleCommunication[3] = 0; + gBattleCommunication[4] = 0; + gBattleScripting.multihitMoveEffect = 0; + gBattleResources->battleScriptsStack->size = 0; +} + + diff --git a/src/battle_message.c b/src/battle_message.c index c004665d7..59ad0cee4 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -2995,7 +2995,7 @@ void BattlePutTextOnWindow(const u8 *text, u8 windowId) printerTemplate.currentY = printerTemplate.y; printerTemplate.letterSpacing = textInfo[windowId].letterSpacing; printerTemplate.lineSpacing = textInfo[windowId].lineSpacing; - printerTemplate.style = 0; + printerTemplate.unk = 0; printerTemplate.fgColor = textInfo[windowId].fgColor; printerTemplate.bgColor = textInfo[windowId].bgColor; printerTemplate.shadowColor = textInfo[windowId].shadowColor; diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index 9e881d3a3..b015f3e0e 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -523,19 +523,6 @@ static const u8 sTrainerTextGroups[50][2] = {FACILITY_CLASS_HIKER, 4}, }; -enum -{ - HINT_EXIT_DIRECTION, - HINT_REMAINING_ITEMS, - HINT_REMAINING_TRAINERS, - HINT_EXIT_SHORT_REMAINING_TRAINERS, - HINT_EXIT_SHORT_REMAINING_ITEMS, - HINT_EXIT_MEDIUM_REMAINING_TRAINERS, - HINT_EXIT_MEDIUM_REMAINING_ITEMS, - HINT_EXIT_FAR_REMAINING_TRAINERS, - HINT_EXIT_FAR_REMAINING_ITEMS, -}; - static const u8 *const sExitDirectionHintTexts1[] = { BattlePyramid_Text_ExitHintUp1, diff --git a/src/battle_pyramid_bag.c b/src/battle_pyramid_bag.c index 8fee57855..e038e71e1 100644 --- a/src/battle_pyramid_bag.c +++ b/src/battle_pyramid_bag.c @@ -839,7 +839,7 @@ static void Task_HandlePyramidBagInput(u8 taskId) s16 *data = gTasks[taskId].data; if (MenuHelpers_CallLinkSomething() != TRUE && !gPaletteFade.active) { - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { if (gPyramidBagCursorData.unk4 != 2) { @@ -965,7 +965,7 @@ static void HandleMenuActionInput(u8 taskId) if (MenuHelpers_CallLinkSomething() != TRUE) { s8 id = Menu_GetCursorPos(); - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { if (id > 0 && IsValidMenuAction(id - 2)) { @@ -973,7 +973,7 @@ static void HandleMenuActionInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_UP); } } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (id < gPyramidBagResources->menuActionsCount - 2 && IsValidMenuAction(id + 2)) { @@ -981,7 +981,7 @@ static void HandleMenuActionInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_DOWN); } } - else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) + else if (gMain.newKeys & DPAD_LEFT || GetLRKeysPressed() == MENU_L_PRESSED) { if (id & 1 && IsValidMenuAction(id - 1)) { @@ -989,7 +989,7 @@ static void HandleMenuActionInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_LEFT, MENU_CURSOR_DELTA_NONE); } } - else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) + else if (gMain.newKeys & DPAD_RIGHT || GetLRKeysPressed() == MENU_R_PRESSED) { if (!(id & 1) && IsValidMenuAction(id + 1)) { @@ -997,13 +997,13 @@ static void HandleMenuActionInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_RIGHT, MENU_CURSOR_DELTA_NONE); } } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (sMenuActions[gPyramidBagResources->menuActionIds[id]].func.void_u8 != NULL) sMenuActions[gPyramidBagResources->menuActionIds[id]].func.void_u8(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sMenuActions[ACTION_CANCEL].func.void_u8(taskId); @@ -1143,7 +1143,7 @@ static void sub_81C64B4(u8 taskId) { sub_81C645C(data[8]); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); ClearStdWindowAndFrameToTransparent(3, 0); @@ -1151,7 +1151,7 @@ static void sub_81C64B4(u8 taskId) ScheduleBgCopyTilemapToVram(1); sub_81C6350(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); ClearStdWindowAndFrameToTransparent(3, 0); @@ -1179,7 +1179,7 @@ static void sub_81C65CC(u8 taskId) u16 *scrollOffset = &gPyramidBagCursorData.scrollPosition; u16 *selectedRow = &gPyramidBagCursorData.cursorPosition; - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); RemovePyramidBagItem(gSpecialVar_ItemId, data[8]); @@ -1220,7 +1220,7 @@ static void sub_81C66AC(u8 taskId) static void sub_81C66EC(u8 taskId) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); Task_CloseBattlePyramidBagMessage(taskId); @@ -1277,7 +1277,7 @@ static void Task_ItemSwapHandleInput(u8 taskId) s16 *data = gTasks[taskId].data; if (MenuHelpers_CallLinkSomething() != TRUE) { - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { PlaySE(SE_SELECT); ListMenuGetScrollAndRow(data[0], &gPyramidBagCursorData.scrollPosition, &gPyramidBagCursorData.cursorPosition); @@ -1295,7 +1295,7 @@ static void Task_ItemSwapHandleInput(u8 taskId) break; case LIST_CANCEL: PlaySE(SE_SELECT); - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) PerformItemSwap(taskId); else sub_81C6A14(taskId); diff --git a/src/battle_records.c b/src/battle_records.c index a8b9ead14..c6363a6ed 100644 --- a/src/battle_records.c +++ b/src/battle_records.c @@ -356,7 +356,7 @@ static void Task_CloseTrainerHillRecordsOnButton(u8 taskId) { struct Task *task = &gTasks[taskId]; - if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON)) + if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); task->func = Task_BeginPaletteFade; @@ -485,7 +485,7 @@ static void CB2_ShowTrainerHillRecords(void) gMain.state++; break; case 2: - sTilemapBuffer = AllocZeroed(BG_SCREEN_SIZE); + sTilemapBuffer = AllocZeroed(0x800); ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sTrainerHillRecordsBgTemplates, ARRAY_COUNT(sTrainerHillRecordsBgTemplates)); SetBgTilemapBuffer(3, sTilemapBuffer); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index fca2b3879..9cff332ca 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3489,6 +3489,7 @@ static void Cmd_getexp(void) } } +#ifdef NONMATCHING static void Cmd_unknown_24(void) { u16 HP_count = 0; @@ -3520,9 +3521,7 @@ static void Cmd_unknown_24(void) if (HP_count == 0) gBattleOutcome |= B_OUTCOME_LOST; - HP_count = 0; - - for (i = 0; i < PARTY_SIZE; i++) + for (HP_count = 0, i = 0; i < PARTY_SIZE; i++) { if (GetMonData(&gEnemyParty[i], MON_DATA_SPECIES) && !GetMonData(&gEnemyParty[i], MON_DATA_IS_EGG) && (!(gBattleTypeFlags & BATTLE_TYPE_ARENA) || !(gBattleStruct->arenaLostOpponentMons & gBitTable[i]))) @@ -3536,31 +3535,33 @@ static void Cmd_unknown_24(void) if (gBattleOutcome == 0 && (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000))) { - s32 foundPlayer = 0, foundOpponent; - for (i = 0; i < gBattlersCount; i += 2) + s32 foundPlayer; + s32 foundOpponent; + + // Impossible to decompile loops. + for (foundPlayer = 0, i = 0; i < gBattlersCount; i += 2) { - if ((gHitMarker & HITMARKER_FAINTED2(i)) && (!gSpecialStatuses[i].flag40)) + if (HITMARKER_FAINTED2(i) & gHitMarker && !gSpecialStatuses[i].flag40) foundPlayer++; } - foundOpponent = 0; - for (i = 1; i < gBattlersCount; i += 2) + for (foundOpponent = 0, i = 1; i < gBattlersCount; i += 2) { - if ((gHitMarker & HITMARKER_FAINTED2(i)) && (!gSpecialStatuses[i].flag40)) + if (HITMARKER_FAINTED2(i) & gHitMarker && !gSpecialStatuses[i].flag40) foundOpponent++; } if (gBattleTypeFlags & BATTLE_TYPE_MULTI) { if (foundOpponent + foundPlayer > 1) - gBattlescriptCurrInstr = (u8*) T2_READ_32(gBattlescriptCurrInstr + 1); + gBattlescriptCurrInstr = T2_READ_PTR(gBattlescriptCurrInstr + 1); else gBattlescriptCurrInstr += 5; } else { if (foundOpponent != 0 && foundPlayer != 0) - gBattlescriptCurrInstr = (u8*) T2_READ_32(gBattlescriptCurrInstr + 1); + gBattlescriptCurrInstr = T2_READ_PTR(gBattlescriptCurrInstr + 1); else gBattlescriptCurrInstr += 5; } @@ -3570,6 +3571,301 @@ static void Cmd_unknown_24(void) gBattlescriptCurrInstr += 5; } } +#else +NAKED +static void Cmd_unknown_24(void) +{ + asm("\n\ + .syntax unified\n\ + push {r4-r7,lr}\n\ + mov r7, r8\n\ + push {r7}\n\ + movs r6, 0\n\ + ldr r0, =gBattleControllerExecFlags\n\ + ldr r0, [r0]\n\ + cmp r0, 0\n\ + beq _0804ACE2\n\ + b _0804AF22\n\ + _0804ACE2:\n\ + ldr r0, =gBattleTypeFlags\n\ + ldr r0, [r0]\n\ + movs r1, 0x80\n\ + lsls r1, 15\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + beq _0804AD48\n\ + ldr r0, =gPartnerTrainerId\n\ + ldrh r1, [r0]\n\ + ldr r0, =0x00000c03\n\ + cmp r1, r0\n\ + bne _0804AD48\n\ + movs r5, 0\n\ + _0804ACFC:\n\ + movs r0, 0x64\n\ + adds r1, r5, 0\n\ + muls r1, r0\n\ + ldr r0, =gPlayerParty\n\ + adds r4, r1, r0\n\ + adds r0, r4, 0\n\ + movs r1, 0xB\n\ + bl GetMonData\n\ + cmp r0, 0\n\ + beq _0804AD2C\n\ + adds r0, r4, 0\n\ + movs r1, 0x2D\n\ + bl GetMonData\n\ + cmp r0, 0\n\ + bne _0804AD2C\n\ + adds r0, r4, 0\n\ + movs r1, 0x39\n\ + bl GetMonData\n\ + adds r0, r6, r0\n\ + lsls r0, 16\n\ + lsrs r6, r0, 16\n\ + _0804AD2C:\n\ + adds r5, 0x1\n\ + cmp r5, 0x2\n\ + ble _0804ACFC\n\ + b _0804ADA8\n\ + .pool\n\ + _0804AD48:\n\ + movs r5, 0\n\ + _0804AD4A:\n\ + movs r0, 0x64\n\ + adds r1, r5, 0\n\ + muls r1, r0\n\ + ldr r0, =gPlayerParty\n\ + adds r4, r1, r0\n\ + adds r0, r4, 0\n\ + movs r1, 0xB\n\ + bl GetMonData\n\ + cmp r0, 0\n\ + beq _0804ADA2\n\ + adds r0, r4, 0\n\ + movs r1, 0x2D\n\ + bl GetMonData\n\ + cmp r0, 0\n\ + bne _0804ADA2\n\ + ldr r0, =gBattleTypeFlags\n\ + ldr r0, [r0]\n\ + movs r1, 0x80\n\ + lsls r1, 11\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + beq _0804AD94\n\ + ldr r0, =gBattleStruct\n\ + ldr r0, [r0]\n\ + movs r1, 0xA8\n\ + lsls r1, 2\n\ + adds r0, r1\n\ + ldrb r1, [r0]\n\ + ldr r2, =gBitTable\n\ + lsls r0, r5, 2\n\ + adds r0, r2\n\ + ldr r0, [r0]\n\ + ands r1, r0\n\ + cmp r1, 0\n\ + bne _0804ADA2\n\ + _0804AD94:\n\ + adds r0, r4, 0\n\ + movs r1, 0x39\n\ + bl GetMonData\n\ + adds r0, r6, r0\n\ + lsls r0, 16\n\ + lsrs r6, r0, 16\n\ + _0804ADA2:\n\ + adds r5, 0x1\n\ + cmp r5, 0x5\n\ + ble _0804AD4A\n\ + _0804ADA8:\n\ + cmp r6, 0\n\ + bne _0804ADB6\n\ + ldr r0, =gBattleOutcome\n\ + ldrb r1, [r0]\n\ + movs r2, 0x2\n\ + orrs r1, r2\n\ + strb r1, [r0]\n\ + _0804ADB6:\n\ + movs r6, 0\n\ + movs r5, 0\n\ + _0804ADBA:\n\ + movs r0, 0x64\n\ + adds r1, r5, 0\n\ + muls r1, r0\n\ + ldr r0, =gEnemyParty\n\ + adds r4, r1, r0\n\ + adds r0, r4, 0\n\ + movs r1, 0xB\n\ + bl GetMonData\n\ + cmp r0, 0\n\ + beq _0804AE10\n\ + adds r0, r4, 0\n\ + movs r1, 0x2D\n\ + bl GetMonData\n\ + cmp r0, 0\n\ + bne _0804AE10\n\ + ldr r0, =gBattleTypeFlags\n\ + ldr r0, [r0]\n\ + movs r1, 0x80\n\ + lsls r1, 11\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + beq _0804AE02\n\ + ldr r0, =gBattleStruct\n\ + ldr r0, [r0]\n\ + ldr r1, =0x000002a1\n\ + adds r0, r1\n\ + ldrb r1, [r0]\n\ + ldr r2, =gBitTable\n\ + lsls r0, r5, 2\n\ + adds r0, r2\n\ + ldr r0, [r0]\n\ + ands r1, r0\n\ + cmp r1, 0\n\ + bne _0804AE10\n\ + _0804AE02:\n\ + adds r0, r4, 0\n\ + movs r1, 0x39\n\ + bl GetMonData\n\ + adds r0, r6, r0\n\ + lsls r0, 16\n\ + lsrs r6, r0, 16\n\ + _0804AE10:\n\ + adds r5, 0x1\n\ + cmp r5, 0x5\n\ + ble _0804ADBA\n\ + ldr r2, =gBattleOutcome\n\ + cmp r6, 0\n\ + bne _0804AE24\n\ + ldrb r0, [r2]\n\ + movs r1, 0x1\n\ + orrs r0, r1\n\ + strb r0, [r2]\n\ + _0804AE24:\n\ + ldrb r0, [r2]\n\ + cmp r0, 0\n\ + bne _0804AF1A\n\ + ldr r0, =gBattleTypeFlags\n\ + ldr r1, [r0]\n\ + ldr r2, =0x02000002\n\ + ands r1, r2\n\ + mov r8, r0\n\ + cmp r1, 0\n\ + beq _0804AF1A\n\ + movs r3, 0\n\ + movs r5, 0\n\ + ldr r0, =gBattlersCount\n\ + ldrb r1, [r0]\n\ + mov r12, r0\n\ + ldr r7, =gBattlescriptCurrInstr\n\ + cmp r3, r1\n\ + bge _0804AE70\n\ + ldr r0, =gHitMarker\n\ + movs r6, 0x80\n\ + lsls r6, 21\n\ + ldr r4, [r0]\n\ + adds r2, r1, 0\n\ + ldr r1, =gSpecialStatuses\n\ + _0804AE54:\n\ + adds r0, r6, 0\n\ + lsls r0, r5\n\ + ands r0, r4\n\ + cmp r0, 0\n\ + beq _0804AE68\n\ + ldrb r0, [r1]\n\ + lsls r0, 25\n\ + cmp r0, 0\n\ + blt _0804AE68\n\ + adds r3, 0x1\n\ + _0804AE68:\n\ + adds r1, 0x28\n\ + adds r5, 0x2\n\ + cmp r5, r2\n\ + blt _0804AE54\n\ + _0804AE70:\n\ + movs r2, 0\n\ + movs r5, 0x1\n\ + mov r4, r12\n\ + ldrb r1, [r4]\n\ + cmp r5, r1\n\ + bge _0804AEAA\n\ + ldr r0, =gHitMarker\n\ + movs r4, 0x80\n\ + lsls r4, 21\n\ + mov r12, r4\n\ + ldr r6, [r0]\n\ + ldr r0, =gSpecialStatuses\n\ + adds r4, r1, 0\n\ + adds r1, r0, 0\n\ + adds r1, 0x14\n\ + _0804AE8E:\n\ + mov r0, r12\n\ + lsls r0, r5\n\ + ands r0, r6\n\ + cmp r0, 0\n\ + beq _0804AEA2\n\ + ldrb r0, [r1]\n\ + lsls r0, 25\n\ + cmp r0, 0\n\ + blt _0804AEA2\n\ + adds r2, 0x1\n\ + _0804AEA2:\n\ + adds r1, 0x28\n\ + adds r5, 0x2\n\ + cmp r5, r4\n\ + blt _0804AE8E\n\ + _0804AEAA:\n\ + mov r1, r8\n\ + ldr r0, [r1]\n\ + movs r1, 0x40\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + beq _0804AEF0\n\ + adds r0, r2, r3\n\ + cmp r0, 0x1\n\ + bgt _0804AEF8\n\ + b _0804AF12\n\ + .pool\n\ + _0804AEF0:\n\ + cmp r2, 0\n\ + beq _0804AF12\n\ + cmp r3, 0\n\ + beq _0804AF12\n\ + _0804AEF8:\n\ + ldr r2, [r7]\n\ + ldrb r1, [r2, 0x1]\n\ + ldrb r0, [r2, 0x2]\n\ + lsls r0, 8\n\ + adds r1, r0\n\ + ldrb r0, [r2, 0x3]\n\ + lsls r0, 16\n\ + adds r1, r0\n\ + ldrb r0, [r2, 0x4]\n\ + lsls r0, 24\n\ + adds r1, r0\n\ + str r1, [r7]\n\ + b _0804AF22\n\ + _0804AF12:\n\ + ldr r0, [r7]\n\ + adds r0, 0x5\n\ + str r0, [r7]\n\ + b _0804AF22\n\ + _0804AF1A:\n\ + ldr r1, =gBattlescriptCurrInstr\n\ + ldr r0, [r1]\n\ + adds r0, 0x5\n\ + str r0, [r1]\n\ + _0804AF22:\n\ + pop {r3}\n\ + mov r8, r3\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool\n\ + .syntax divided"); +} + +#endif // NONMATCHING static void MoveValuesCleanUp(void) { @@ -4661,10 +4957,8 @@ static void Cmd_jumpifcantswitch(void) || (gStatuses3[gActiveBattler] & STATUS3_ROOTED))) { gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 2); - return; } - - if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) + else if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER) { #ifndef NONMATCHING asm("":::"r5"); @@ -5362,21 +5656,21 @@ static void Cmd_yesnoboxlearnmove(void) BattleCreateYesNoCursorAt(0); break; case 1: - if (JOY_NEW(DPAD_UP) && gBattleCommunication[CURSOR_POSITION] != 0) + if (gMain.newKeys & DPAD_UP && gBattleCommunication[CURSOR_POSITION] != 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 0; BattleCreateYesNoCursorAt(0); } - if (JOY_NEW(DPAD_DOWN) && gBattleCommunication[CURSOR_POSITION] == 0) + if (gMain.newKeys & DPAD_DOWN && gBattleCommunication[CURSOR_POSITION] == 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 1; BattleCreateYesNoCursorAt(1); } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (gBattleCommunication[1] == 0) @@ -5390,7 +5684,7 @@ static void Cmd_yesnoboxlearnmove(void) gBattleScripting.learnMoveState = 5; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); gBattleScripting.learnMoveState = 5; @@ -5479,21 +5773,21 @@ static void Cmd_yesnoboxstoplearningmove(void) BattleCreateYesNoCursorAt(0); break; case 1: - if (JOY_NEW(DPAD_UP) && gBattleCommunication[CURSOR_POSITION] != 0) + if (gMain.newKeys & DPAD_UP && gBattleCommunication[CURSOR_POSITION] != 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 0; BattleCreateYesNoCursorAt(0); } - if (JOY_NEW(DPAD_DOWN) && gBattleCommunication[CURSOR_POSITION] == 0) + if (gMain.newKeys & DPAD_DOWN && gBattleCommunication[CURSOR_POSITION] == 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 1; BattleCreateYesNoCursorAt(1); } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); @@ -5504,7 +5798,7 @@ static void Cmd_yesnoboxstoplearningmove(void) HandleBattleWindow(0x18, 0x8, 0x1D, 0xD, WINDOW_CLEAR); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); gBattlescriptCurrInstr = T1_READ_PTR(gBattlescriptCurrInstr + 1); @@ -5537,8 +5831,8 @@ static void Cmd_hitanimation(void) static u32 GetTrainerMoneyToGive(u16 trainerId) { u32 i = 0; - u32 moneyReward; - u8 lastMonLevel = 0; + u32 lastMonLevel = 0; + u32 moneyReward = 0; if (trainerId == TRAINER_SECRET_BASE) { @@ -5774,28 +6068,28 @@ static void Cmd_yesnobox(void) BattleCreateYesNoCursorAt(0); break; case 1: - if (JOY_NEW(DPAD_UP) && gBattleCommunication[CURSOR_POSITION] != 0) + if (gMain.newKeys & DPAD_UP && gBattleCommunication[CURSOR_POSITION] != 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 0; BattleCreateYesNoCursorAt(0); } - if (JOY_NEW(DPAD_DOWN) && gBattleCommunication[CURSOR_POSITION] == 0) + if (gMain.newKeys & DPAD_DOWN && gBattleCommunication[CURSOR_POSITION] == 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 1; BattleCreateYesNoCursorAt(1); } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { gBattleCommunication[CURSOR_POSITION] = 1; PlaySE(SE_SELECT); HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); gBattlescriptCurrInstr++; } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); @@ -6038,7 +6332,7 @@ static void PutLevelAndGenderOnLvlUpBox(void) printerTemplate.currentY = 0; printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; - printerTemplate.style = 0; + printerTemplate.unk = 0; printerTemplate.fgColor = TEXT_COLOR_WHITE; printerTemplate.bgColor = TEXT_COLOR_TRANSPARENT; printerTemplate.shadowColor = TEXT_COLOR_DARK_GREY; @@ -7129,12 +7423,18 @@ static void Cmd_forcerandomswitch(void) s32 i; s32 battler1PartyId = 0; s32 battler2PartyId = 0; - s32 firstMonId; - s32 lastMonId = 0; // + 1 - s32 monsCount; + + #ifdef NONMATCHING + s32 lastMonId = 0; // + 1 + #else + register s32 lastMonId asm("r8") = 0; // + 1 + #endif // NONMATCHING + + s32 firstMonId = 0; + s32 monsCount = 0; struct Pokemon* party = NULL; s32 validMons = 0; - s32 minNeeded; + s32 minNeeded = 0; if ((gBattleTypeFlags & BATTLE_TYPE_TRAINER)) { @@ -7246,14 +7546,14 @@ static void Cmd_forcerandomswitch(void) { do { - do - { - i = Random() % monsCount; - i += firstMonId; - } while (i == battler2PartyId || i == battler1PartyId); - } while (GetMonData(&party[i], MON_DATA_SPECIES) == SPECIES_NONE + i = Random() % monsCount; + i += firstMonId; + } + while (i == battler2PartyId + || i == battler1PartyId + || GetMonData(&party[i], MON_DATA_SPECIES) == SPECIES_NONE || GetMonData(&party[i], MON_DATA_IS_EGG) == TRUE - || GetMonData(&party[i], MON_DATA_HP) == 0); // Should be one while loop, conjoined by an ||, but that doesn't match. Equivalent logic though + || GetMonData(&party[i], MON_DATA_HP) == 0); } *(gBattleStruct->monToSwitchIntoId + gBattlerTarget) = i; @@ -10072,21 +10372,21 @@ static void Cmd_trygivecaughtmonnick(void) BattleCreateYesNoCursorAt(0); break; case 1: - if (JOY_NEW(DPAD_UP) && gBattleCommunication[CURSOR_POSITION] != 0) + if (gMain.newKeys & DPAD_UP && gBattleCommunication[CURSOR_POSITION] != 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 0; BattleCreateYesNoCursorAt(0); } - if (JOY_NEW(DPAD_DOWN) && gBattleCommunication[CURSOR_POSITION] == 0) + if (gMain.newKeys & DPAD_DOWN && gBattleCommunication[CURSOR_POSITION] == 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(gBattleCommunication[CURSOR_POSITION]); gBattleCommunication[CURSOR_POSITION] = 1; BattleCreateYesNoCursorAt(1); } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (gBattleCommunication[CURSOR_POSITION] == 0) @@ -10099,7 +10399,7 @@ static void Cmd_trygivecaughtmonnick(void) gBattleCommunication[MULTIUSE_STATE] = 4; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); gBattleCommunication[MULTIUSE_STATE] = 4; diff --git a/src/battle_tower.c b/src/battle_tower.c index e0ff3fe26..0333c4397 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -1447,7 +1447,7 @@ u8 GetFrontierOpponentClass(u16 trainerId) } else if (trainerId == TRAINER_FRONTIER_BRAIN) { - return GetFrontierBrainTrainerClass(); // This sticks out like a sore thumb, but this is the only other way that matches. Maybe it SHOULD be assigned to ret, or all early returns. I don't know. + trainerClass = GetFrontierBrainTrainerClass(); } else if (trainerId == TRAINER_STEVEN_PARTNER) { @@ -1466,6 +1466,9 @@ u8 GetFrontierOpponentClass(u16 trainerId) else { trainerClass = gFacilityClassToTrainerClass[gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].facilityClass]; + #ifndef NONMATCHING + asm(""); + #endif } } else @@ -1477,6 +1480,9 @@ u8 GetFrontierOpponentClass(u16 trainerId) else { trainerClass = gFacilityClassToTrainerClass[gApprentices[gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id].facilityClass]; + #ifndef NONMATCHING + asm(""); + #endif } } diff --git a/src/battle_transition.c b/src/battle_transition.c index 4a9d26303..559279e74 100644 --- a/src/battle_transition.c +++ b/src/battle_transition.c @@ -3973,8 +3973,11 @@ static bool8 Phase2_FrontierLogoWave_Func4(struct Task *task) for (i = 0; i < 160; i++, var6 += var8) { - const u16 index = var6 >> 8; - gScanlineEffectRegBuffers[0][i] = sTransitionStructPtr->field_16 + Sin(index & 0xff, amplitude); + s16 index = var6 / 256; + #ifndef NONMATCHING + asm(""); + #endif + gScanlineEffectRegBuffers[0][i] = sTransitionStructPtr->field_16 + Sin(index, amplitude); } if (++task->tData3 == 101) diff --git a/src/battle_tv.c b/src/battle_tv.c index e3dec9a6c..c84ae827b 100644 --- a/src/battle_tv.c +++ b/src/battle_tv.c @@ -713,18 +713,20 @@ void BattleTv_SetDataBasedOnAnimation(u8 animationId) } } +#ifdef NONMATCHING +// for loop has an unused stack variable void TryPutLinkBattleTvShowOnAir(void) { - u16 playerBestSpecies = 0, opponentBestSpecies = 0, moveId = 0; - s16 sum = 0, playerBestSum = 0, opponentBestSum = SHRT_MAX; + u16 playerBestSpecies = 0, opponentBestSpecies = 0; + s16 playerBestSum = 0, opponentBestSum = SHRT_MAX; u8 playerBestMonId = 0, opponentBestMonId = 0; struct BattleTvMovePoints *movePoints = NULL; u8 countPlayer = 0, countOpponent = 0; - u16 species; + s16 sum = 0; + u16 species = 0; + u16 moveId = 0; s32 i, j; - int zero = 0, one = 1; // stupid variables needed to match. Feel free to get rid of them. - if (gBattleStruct->anyMonHasTransformed) return; @@ -746,7 +748,7 @@ void TryPutLinkBattleTvShowOnAir(void) if (species != SPECIES_NONE && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG, NULL)) { for (sum = 0, j = 0; j < MAX_MON_MOVES; j++) - sum += movePoints->points[zero][i * 4 + j]; + sum += movePoints->points[0][i * 4 + j]; if (playerBestSum < sum) { @@ -760,7 +762,7 @@ void TryPutLinkBattleTvShowOnAir(void) if (species != SPECIES_NONE && !GetMonData(&gEnemyParty[i], MON_DATA_IS_EGG, NULL)) { for (sum = 0, j = 0; j < MAX_MON_MOVES; j++) - sum += movePoints->points[one][i * 4 + j]; + sum += movePoints->points[1][i * 4 + j]; if (opponentBestSum == sum) { @@ -782,9 +784,9 @@ void TryPutLinkBattleTvShowOnAir(void) for (sum = 0, i = 0, j = 0; j < MAX_MON_MOVES; j++) { - if (sum < movePoints->points[zero][playerBestMonId * 4 + j]) + if (sum < movePoints->points[0][playerBestMonId * 4 + j]) { - sum = movePoints->points[zero][playerBestMonId * 4 + j]; + sum = movePoints->points[0][playerBestMonId * 4 + j]; i = j; } } @@ -808,6 +810,333 @@ void TryPutLinkBattleTvShowOnAir(void) } } +#else +NAKED +void TryPutLinkBattleTvShowOnAir(void) +{ + asm_unified( + "push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0x20\n\ + movs r0, 0\n\ + str r0, [sp]\n\ + movs r1, 0\n\ + str r1, [sp, 0x4]\n\ + movs r2, 0\n\ + str r2, [sp, 0x8]\n\ + ldr r3, =0x00007fff\n\ + str r3, [sp, 0xC]\n\ + movs r4, 0\n\ + str r4, [sp, 0x10]\n\ + movs r7, 0\n\ + str r7, [sp, 0x14]\n\ + mov r8, r0\n\ + ldr r0, =gBattleStruct\n\ + ldr r1, [r0]\n\ + adds r0, r1, 0\n\ + adds r0, 0xB3\n\ + ldrb r0, [r0]\n\ + cmp r0, 0\n\ + beq _0817E42A\n\ + b _0817E670\n\ +_0817E42A:\n\ + movs r2, 0xD2\n\ + lsls r2, 1\n\ + adds r2, r1\n\ + mov r10, r2\n\ + movs r6, 0\n\ +_0817E434:\n\ + movs r0, 0x64\n\ + adds r4, r6, 0\n\ + muls r4, r0\n\ + ldr r0, =gPlayerParty\n\ + adds r0, r4, r0\n\ + movs r1, 0xB\n\ + movs r2, 0\n\ + bl GetMonData\n\ + cmp r0, 0\n\ + beq _0817E454\n\ + mov r0, r8\n\ + adds r0, 0x1\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + mov r8, r0\n\ +_0817E454:\n\ + ldr r5, =gEnemyParty\n\ + adds r0, r4, r5\n\ + movs r1, 0xB\n\ + movs r2, 0\n\ + bl GetMonData\n\ + cmp r0, 0\n\ + beq _0817E46A\n\ + adds r0, r7, 0x1\n\ + lsls r0, 24\n\ + lsrs r7, r0, 24\n\ +_0817E46A:\n\ + adds r6, 0x1\n\ + cmp r6, 0x5\n\ + ble _0817E434\n\ + ldr r0, =gBattleTypeFlags\n\ + ldr r0, [r0]\n\ + movs r1, 0x2\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + bne _0817E47E\n\ + b _0817E670\n\ +_0817E47E:\n\ + cmp r8, r7\n\ + beq _0817E484\n\ + b _0817E670\n\ +_0817E484:\n\ + movs r6, 0\n\ + lsls r3, r6, 1\n\ + str r3, [sp, 0x18]\n\ + movs r4, 0x64\n\ + mov r8, r4\n\ +_0817E48E:\n\ + mov r1, r8\n\ + muls r1, r6\n\ + ldr r0, =gPlayerParty\n\ + adds r4, r1, r0\n\ + adds r0, r4, 0\n\ + movs r1, 0xB\n\ + movs r2, 0\n\ + bl GetMonData\n\ + lsls r0, 16\n\ + lsrs r7, r0, 16\n\ + adds r0, r6, 0x1\n\ + mov r9, r0\n\ + cmp r7, 0\n\ + beq _0817E4EE\n\ + adds r0, r4, 0\n\ + movs r1, 0x2D\n\ + movs r2, 0\n\ + bl GetMonData\n\ + cmp r0, 0\n\ + bne _0817E4EE\n\ + movs r4, 0\n\ + lsls r0, r6, 3\n\ + mov r2, r10\n\ + adds r1, r0, r2\n\ + movs r3, 0x3\n\ +_0817E4C4:\n\ + lsls r0, r4, 16\n\ + asrs r0, 16\n\ + ldrh r4, [r1]\n\ + adds r0, r4\n\ + lsls r0, 16\n\ + lsrs r4, r0, 16\n\ + adds r1, 0x2\n\ + subs r3, 0x1\n\ + cmp r3, 0\n\ + bge _0817E4C4\n\ + ldr r1, [sp, 0x8]\n\ + lsls r0, r1, 16\n\ + lsls r1, r4, 16\n\ + cmp r0, r1\n\ + bge _0817E4EE\n\ + lsls r0, r6, 24\n\ + lsrs r0, 24\n\ + str r0, [sp, 0x10]\n\ + lsrs r1, 16\n\ + str r1, [sp, 0x8]\n\ + str r7, [sp]\n\ +_0817E4EE:\n\ + mov r0, r8\n\ + muls r0, r6\n\ + ldr r2, =gEnemyParty\n\ + adds r4, r0, r2\n\ + adds r0, r4, 0\n\ + movs r1, 0xB\n\ + movs r2, 0\n\ + bl GetMonData\n\ + lsls r0, 16\n\ + lsrs r7, r0, 16\n\ + ldr r3, [sp, 0x8]\n\ + lsls r3, 16\n\ + str r3, [sp, 0x1C]\n\ + cmp r7, 0\n\ + beq _0817E5A0\n\ + adds r0, r4, 0\n\ + movs r1, 0x2D\n\ + movs r2, 0\n\ + bl GetMonData\n\ + cmp r0, 0\n\ + bne _0817E5A0\n\ + movs r4, 0\n\ + ldr r0, [sp, 0xC]\n\ + lsls r2, r0, 16\n\ + movs r3, 0x1\n\ + lsls r1, r3, 1\n\ + adds r1, 0x1\n\ + lsls r1, 4\n\ + lsls r0, r6, 3\n\ + adds r0, r1\n\ + mov r3, r10\n\ + adds r1, r0, r3\n\ + movs r3, 0x3\n\ +_0817E534:\n\ + lsls r0, r4, 16\n\ + asrs r0, 16\n\ + ldrh r4, [r1]\n\ + adds r0, r4\n\ + lsls r0, 16\n\ + lsrs r4, r0, 16\n\ + adds r1, 0x2\n\ + subs r3, 0x1\n\ + cmp r3, 0\n\ + bge _0817E534\n\ + asrs r1, r2, 16\n\ + lsls r5, r4, 16\n\ + asrs r0, r5, 16\n\ + cmp r1, r0\n\ + bne _0817E590\n\ + mov r0, r8\n\ + muls r0, r6\n\ + ldr r1, =gEnemyParty\n\ + adds r0, r1\n\ + movs r1, 0x19\n\ + movs r2, 0\n\ + bl GetMonData\n\ + adds r4, r0, 0\n\ + ldr r2, [sp, 0x14]\n\ + mov r0, r8\n\ + muls r0, r2\n\ + ldr r3, =gEnemyParty\n\ + adds r0, r3\n\ + movs r1, 0x19\n\ + movs r2, 0\n\ + bl GetMonData\n\ + cmp r4, r0\n\ + bls _0817E5A0\n\ + b _0817E594\n\ + .pool\n\ +_0817E590:\n\ + cmp r1, r0\n\ + ble _0817E5A0\n\ +_0817E594:\n\ + lsls r0, r6, 24\n\ + lsrs r0, 24\n\ + str r0, [sp, 0x14]\n\ + lsrs r5, 16\n\ + str r5, [sp, 0xC]\n\ + str r7, [sp, 0x4]\n\ +_0817E5A0:\n\ + mov r6, r9\n\ + cmp r6, 0x5\n\ + bgt _0817E5A8\n\ + b _0817E48E\n\ +_0817E5A8:\n\ + movs r4, 0\n\ + movs r6, 0\n\ + movs r3, 0\n\ + ldr r5, =gPlayerParty\n\ + ldr r7, [sp, 0x10]\n\ + lsls r0, r7, 3\n\ + mov r1, r10\n\ + adds r2, r0, r1\n\ +_0817E5B8:\n\ + lsls r0, r4, 16\n\ + asrs r0, 16\n\ + movs r7, 0\n\ + ldrsh r1, [r2, r7]\n\ + cmp r0, r1\n\ + bge _0817E5C8\n\ + ldrh r4, [r2]\n\ + adds r6, r3, 0\n\ +_0817E5C8:\n\ + adds r2, 0x2\n\ + adds r3, 0x1\n\ + cmp r3, 0x3\n\ + ble _0817E5B8\n\ + movs r0, 0x64\n\ + ldr r1, [sp, 0x10]\n\ + muls r0, r1\n\ + adds r0, r5\n\ + adds r1, r6, 0\n\ + adds r1, 0xD\n\ + movs r2, 0\n\ + bl GetMonData\n\ + lsls r0, 16\n\ + lsrs r4, r0, 16\n\ + ldr r2, [sp, 0x1C]\n\ + cmp r2, 0\n\ + beq _0817E670\n\ + cmp r4, 0\n\ + beq _0817E670\n\ + ldr r0, =gBattleTypeFlags\n\ + ldr r0, [r0]\n\ + movs r1, 0x40\n\ + ands r0, r1\n\ + cmp r0, 0\n\ + beq _0817E65C\n\ + ldr r3, [sp, 0x10]\n\ + cmp r3, 0x2\n\ + bhi _0817E620\n\ + ldr r0, =gBattleScripting\n\ + adds r0, 0x25\n\ + ldrb r0, [r0]\n\ + bl GetLinkTrainerFlankId\n\ + lsls r0, 16\n\ + cmp r0, 0\n\ + beq _0817E630\n\ + b _0817E670\n\ + .pool\n\ +_0817E620:\n\ + ldr r0, =gBattleScripting\n\ + adds r0, 0x25\n\ + ldrb r0, [r0]\n\ + bl GetLinkTrainerFlankId\n\ + lsls r0, 16\n\ + cmp r0, 0\n\ + beq _0817E670\n\ +_0817E630:\n\ + movs r3, 0\n\ + ldr r7, [sp, 0x14]\n\ + cmp r7, 0x2\n\ + bls _0817E63A\n\ + movs r3, 0x1\n\ +_0817E63A:\n\ + lsls r0, r3, 24\n\ + lsrs r0, 24\n\ + ldr r1, =gBattleScripting\n\ + adds r1, 0x25\n\ + ldrb r1, [r1]\n\ + bl sub_806EF84\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + adds r1, r4, 0\n\ + ldr r2, [sp]\n\ + ldr r3, [sp, 0x4]\n\ + bl PutBattleUpdateOnTheAir\n\ + b _0817E670\n\ + .pool\n\ +_0817E65C:\n\ + ldr r0, =gBattleScripting\n\ + adds r0, 0x25\n\ + ldrb r1, [r0]\n\ + movs r0, 0x1\n\ + eors r0, r1\n\ + adds r1, r4, 0\n\ + ldr r2, [sp]\n\ + ldr r3, [sp, 0x4]\n\ + bl PutBattleUpdateOnTheAir\n\ +_0817E670:\n\ + add sp, 0x20\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool"); +} +#endif + static void AddMovePoints(u8 caseId, u16 arg1, u8 arg2, u8 arg3) { struct BattleTvMovePoints *movePoints = &gBattleStruct->tvMovePoints; diff --git a/src/battle_util.c b/src/battle_util.c index eb3907157..699fd05bc 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1,19 +1,21 @@ #include "global.h" #include "battle.h" -#include "battle_util.h" #include "battle_anim.h" #include "pokemon.h" #include "item.h" #include "util.h" #include "battle_scripts.h" #include "random.h" +#include "text.h" #include "string_util.h" +#include "battle_message.h" #include "battle_ai_script_commands.h" #include "battle_controllers.h" #include "event_data.h" #include "link.h" #include "field_weather.h" #include "constants/abilities.h" +#include "constants/battle_anim.h" #include "constants/battle_move_effects.h" #include "constants/battle_script_commands.h" #include "constants/battle_string_ids.h" @@ -23,615 +25,6 @@ #include "constants/moves.h" #include "constants/species.h" #include "constants/weather.h" -#include "battle_arena.h" -#include "battle_pyramid.h" -#include "international_string_util.h" -#include "safari_zone.h" -#include "sound.h" -#include "task.h" -#include "trig.h" -#include "window.h" -#include "constants/songs.h" - -extern const u8 *const gBattleScriptsForMoveEffects[]; -extern const u8 *const gBattlescriptsForBallThrow[]; -extern const u8 *const gBattlescriptsForRunningByItem[]; -extern const u8 *const gBattlescriptsForUsingItem[]; -extern const u8 *const gBattlescriptsForSafariActions[]; - -static const u8 sPkblToEscapeFactor[][3] = {{0, 0, 0}, {3, 5, 0}, {2, 3, 0}, {1, 2, 0}, {1, 1, 0}}; -static const u8 sGoNearCounterToCatchFactor[] = {4, 3, 2, 1}; -static const u8 sGoNearCounterToEscapeFactor[] = {4, 4, 4, 4}; - -void HandleAction_UseMove(void) -{ - u8 side; - u8 var = 4; - - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - - if (*(&gBattleStruct->field_91) & gBitTable[gBattlerAttacker]) - { - gCurrentActionFuncId = B_ACTION_FINISHED; - return; - } - - gCritMultiplier = 1; - gBattleScripting.dmgMultiplier = 1; - gBattleStruct->atkCancellerTracker = 0; - gMoveResultFlags = 0; - gMultiHitCounter = 0; - gBattleCommunication[6] = 0; - gCurrMovePos = gChosenMovePos = *(gBattleStruct->chosenMovePositions + gBattlerAttacker); - - // choose move - if (gProtectStructs[gBattlerAttacker].noValidMoves) - { - gProtectStructs[gBattlerAttacker].noValidMoves = 0; - gCurrentMove = gChosenMove = MOVE_STRUGGLE; - gHitMarker |= HITMARKER_NO_PPDEDUCT; - *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(MOVE_STRUGGLE, 0); - } - else if (gBattleMons[gBattlerAttacker].status2 & STATUS2_MULTIPLETURNS || gBattleMons[gBattlerAttacker].status2 & STATUS2_RECHARGE) - { - gCurrentMove = gChosenMove = gLockedMoves[gBattlerAttacker]; - } - // encore forces you to use the same move - else if (gDisableStructs[gBattlerAttacker].encoredMove != MOVE_NONE - && gDisableStructs[gBattlerAttacker].encoredMove == gBattleMons[gBattlerAttacker].moves[gDisableStructs[gBattlerAttacker].encoredMovePos]) - { - gCurrentMove = gChosenMove = gDisableStructs[gBattlerAttacker].encoredMove; - gCurrMovePos = gChosenMovePos = gDisableStructs[gBattlerAttacker].encoredMovePos; - *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(gCurrentMove, 0); - } - // check if the encored move wasn't overwritten - else if (gDisableStructs[gBattlerAttacker].encoredMove != MOVE_NONE - && gDisableStructs[gBattlerAttacker].encoredMove != gBattleMons[gBattlerAttacker].moves[gDisableStructs[gBattlerAttacker].encoredMovePos]) - { - gCurrMovePos = gChosenMovePos = gDisableStructs[gBattlerAttacker].encoredMovePos; - gCurrentMove = gChosenMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; - gDisableStructs[gBattlerAttacker].encoredMove = MOVE_NONE; - gDisableStructs[gBattlerAttacker].encoredMovePos = 0; - gDisableStructs[gBattlerAttacker].encoreTimer = 0; - *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(gCurrentMove, 0); - } - else if (gBattleMons[gBattlerAttacker].moves[gCurrMovePos] != gChosenMoveByBattler[gBattlerAttacker]) - { - gCurrentMove = gChosenMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; - *(gBattleStruct->moveTarget + gBattlerAttacker) = GetMoveTarget(gCurrentMove, 0); - } - else - { - gCurrentMove = gChosenMove = gBattleMons[gBattlerAttacker].moves[gCurrMovePos]; - } - - if (gBattleMons[gBattlerAttacker].hp != 0) - { - if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) - gBattleResults.lastUsedMovePlayer = gCurrentMove; - else - gBattleResults.lastUsedMoveOpponent = gCurrentMove; - } - - // choose target - side = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE; - if (gSideTimers[side].followmeTimer != 0 - && gBattleMoves[gCurrentMove].target == MOVE_TARGET_SELECTED - && GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gSideTimers[side].followmeTarget) - && gBattleMons[gSideTimers[side].followmeTarget].hp != 0) - { - gBattlerTarget = gSideTimers[side].followmeTarget; - } - else if ((gBattleTypeFlags & BATTLE_TYPE_DOUBLE) - && gSideTimers[side].followmeTimer == 0 - && (gBattleMoves[gCurrentMove].power != 0 - || gBattleMoves[gCurrentMove].target != MOVE_TARGET_USER) - && gBattleMons[*(gBattleStruct->moveTarget + gBattlerAttacker)].ability != ABILITY_LIGHTNING_ROD - && gBattleMoves[gCurrentMove].type == TYPE_ELECTRIC) - { - side = GetBattlerSide(gBattlerAttacker); - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) - { - if (side != GetBattlerSide(gActiveBattler) - && *(gBattleStruct->moveTarget + gBattlerAttacker) != gActiveBattler - && gBattleMons[gActiveBattler].ability == ABILITY_LIGHTNING_ROD - && GetBattlerTurnOrderNum(gActiveBattler) < var) - { - var = GetBattlerTurnOrderNum(gActiveBattler); - } - } - if (var == 4) - { - if (gBattleMoves[gChosenMove].target & MOVE_TARGET_RANDOM) - { - if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) - { - if (Random() & 1) - gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); - else - gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); - } - else - { - if (Random() & 1) - gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - else - gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); - } - } - else - { - gBattlerTarget = *(gBattleStruct->moveTarget + gBattlerAttacker); - } - - if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) - { - if (GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) - { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); - } - else - { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_SIDE); - if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); - } - } - } - else - { - gActiveBattler = gBattlerByTurnOrder[var]; - RecordAbilityBattle(gActiveBattler, gBattleMons[gActiveBattler].ability); - gSpecialStatuses[gActiveBattler].lightningRodRedirected = 1; - gBattlerTarget = gActiveBattler; - } - } - else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE - && gBattleMoves[gChosenMove].target & MOVE_TARGET_RANDOM) - { - if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) - { - if (Random() & 1) - gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT); - else - gBattlerTarget = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT); - } - else - { - if (Random() & 1) - gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT); - else - gBattlerTarget = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT); - } - - if (gAbsentBattlerFlags & gBitTable[gBattlerTarget] - && GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) - { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); - } - } - else - { - gBattlerTarget = *(gBattleStruct->moveTarget + gBattlerAttacker); - if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) - { - if (GetBattlerSide(gBattlerAttacker) != GetBattlerSide(gBattlerTarget)) - { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); - } - else - { - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerAttacker) ^ BIT_SIDE); - if (gAbsentBattlerFlags & gBitTable[gBattlerTarget]) - gBattlerTarget = GetBattlerAtPosition(GetBattlerPosition(gBattlerTarget) ^ BIT_FLANK); - } - } - } - - // choose battlescript - if (gBattleTypeFlags & BATTLE_TYPE_PALACE - && gProtectStructs[gBattlerAttacker].palaceUnableToUseMove) - { - if (gBattleMons[gBattlerAttacker].hp == 0) - { - gCurrentActionFuncId = B_ACTION_FINISHED; - return; - } - else if (gPalaceSelectionBattleScripts[gBattlerAttacker] != NULL) - { - gBattleCommunication[MULTISTRING_CHOOSER] = 4; - gBattlescriptCurrInstr = gPalaceSelectionBattleScripts[gBattlerAttacker]; - gPalaceSelectionBattleScripts[gBattlerAttacker] = NULL; - } - else - { - gBattleCommunication[MULTISTRING_CHOOSER] = 4; - gBattlescriptCurrInstr = BattleScript_MoveUsedLoafingAround; - } - } - else - { - gBattlescriptCurrInstr = gBattleScriptsForMoveEffects[gBattleMoves[gCurrentMove].effect]; - } - - if (gBattleTypeFlags & BATTLE_TYPE_ARENA) - BattleArena_AddMindPoints(gBattlerAttacker); - - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -void HandleAction_Switch(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - gActionSelectionCursor[gBattlerAttacker] = 0; - gMoveSelectionCursor[gBattlerAttacker] = 0; - - PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBattlerAttacker, *(gBattleStruct->field_58 + gBattlerAttacker)) - - gBattleScripting.battler = gBattlerAttacker; - gBattlescriptCurrInstr = BattleScript_ActionSwitch; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; - - if (gBattleResults.playerSwitchesCounter < 255) - gBattleResults.playerSwitchesCounter++; -} - -void HandleAction_UseItem(void) -{ - gBattlerAttacker = gBattlerTarget = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - - ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); - - gLastUsedItem = gBattleBufferB[gBattlerAttacker][1] | (gBattleBufferB[gBattlerAttacker][2] << 8); - - if (gLastUsedItem <= LAST_BALL) // is ball - { - gBattlescriptCurrInstr = gBattlescriptsForBallThrow[gLastUsedItem]; - } - else if (gLastUsedItem == ITEM_POKE_DOLL || gLastUsedItem == ITEM_FLUFFY_TAIL) - { - gBattlescriptCurrInstr = gBattlescriptsForRunningByItem[0]; - } - else if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) - { - gBattlescriptCurrInstr = gBattlescriptsForUsingItem[0]; - } - else - { - gBattleScripting.battler = gBattlerAttacker; - - switch (*(gBattleStruct->AI_itemType + (gBattlerAttacker >> 1))) - { - case AI_ITEM_FULL_RESTORE: - case AI_ITEM_HEAL_HP: - break; - case AI_ITEM_CURE_CONDITION: - gBattleCommunication[MULTISTRING_CHOOSER] = 0; - if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 1) - { - if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 0x3E) - gBattleCommunication[MULTISTRING_CHOOSER] = 5; - } - else - { - do - { - *(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) >>= 1; - gBattleCommunication[MULTISTRING_CHOOSER]++; - } while (!(*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 1)); - } - break; - case AI_ITEM_X_STAT: - gBattleCommunication[MULTISTRING_CHOOSER] = 4; - if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 0x80) - { - gBattleCommunication[MULTISTRING_CHOOSER] = 5; - } - else - { - PREPARE_STAT_BUFFER(gBattleTextBuff1, STAT_ATK) - PREPARE_STRING_BUFFER(gBattleTextBuff2, CHAR_X) - - while (!((*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1))) & 1)) - { - *(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) >>= 1; - gBattleTextBuff1[2]++; - } - - gBattleScripting.animArg1 = gBattleTextBuff1[2] + 14; - gBattleScripting.animArg2 = 0; - } - break; - case AI_ITEM_GUARD_SPECS: - if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) - gBattleCommunication[MULTISTRING_CHOOSER] = 2; - else - gBattleCommunication[MULTISTRING_CHOOSER] = 0; - break; - } - - gBattlescriptCurrInstr = gBattlescriptsForUsingItem[*(gBattleStruct->AI_itemType + (gBattlerAttacker >> 1))]; - } - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -bool8 TryRunFromBattle(u8 battler) -{ - bool8 effect = FALSE; - u8 holdEffect; - u8 pyramidMultiplier; - u8 speedVar; - - if (gBattleMons[battler].item == ITEM_ENIGMA_BERRY) - holdEffect = gEnigmaBerries[battler].holdEffect; - else - holdEffect = ItemId_GetHoldEffect(gBattleMons[battler].item); - - gPotentialItemEffectBattler = battler; - - if (holdEffect == HOLD_EFFECT_CAN_ALWAYS_RUN) - { - gLastUsedItem = gBattleMons[battler].item; - gProtectStructs[battler].fleeFlag = 1; - effect++; - } - else if (gBattleMons[battler].ability == ABILITY_RUN_AWAY) - { - if (InBattlePyramid()) - { - gBattleStruct->runTries++; - pyramidMultiplier = GetPyramidRunMultiplier(); - speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); - if (speedVar > (Random() & 0xFF)) - { - gLastUsedAbility = ABILITY_RUN_AWAY; - gProtectStructs[battler].fleeFlag = 2; - effect++; - } - } - else - { - gLastUsedAbility = ABILITY_RUN_AWAY; - gProtectStructs[battler].fleeFlag = 2; - effect++; - } - } - else if (gBattleTypeFlags & (BATTLE_TYPE_FRONTIER | BATTLE_TYPE_TRAINER_HILL) && gBattleTypeFlags & BATTLE_TYPE_TRAINER) - { - effect++; - } - else - { - if (!(gBattleTypeFlags & BATTLE_TYPE_DOUBLE)) - { - if (InBattlePyramid()) - { - pyramidMultiplier = GetPyramidRunMultiplier(); - speedVar = (gBattleMons[battler].speed * pyramidMultiplier) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); - if (speedVar > (Random() & 0xFF)) - effect++; - } - else if (gBattleMons[battler].speed < gBattleMons[BATTLE_OPPOSITE(battler)].speed) - { - speedVar = (gBattleMons[battler].speed * 128) / (gBattleMons[BATTLE_OPPOSITE(battler)].speed) + (gBattleStruct->runTries * 30); - if (speedVar > (Random() & 0xFF)) - effect++; - } - else // same speed or faster - { - effect++; - } - } - - gBattleStruct->runTries++; - } - - if (effect) - { - gCurrentTurnActionNumber = gBattlersCount; - gBattleOutcome = B_OUTCOME_RAN; - } - - return effect; -} - -void HandleAction_Run(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - - if (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000)) - { - gCurrentTurnActionNumber = gBattlersCount; - - for (gActiveBattler = 0; gActiveBattler < gBattlersCount; gActiveBattler++) - { - if (GetBattlerSide(gActiveBattler) == B_SIDE_PLAYER) - { - if (gChosenActionByBattler[gActiveBattler] == B_ACTION_RUN) - gBattleOutcome |= B_OUTCOME_LOST; - } - else - { - if (gChosenActionByBattler[gActiveBattler] == B_ACTION_RUN) - gBattleOutcome |= B_OUTCOME_WON; - } - } - - gBattleOutcome |= B_OUTCOME_LINK_BATTLE_RAN; - gSaveBlock2Ptr->frontier.disableRecordBattle = TRUE; - } - else - { - if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER) - { - if (!TryRunFromBattle(gBattlerAttacker)) // failed to run away - { - ClearFuryCutterDestinyBondGrudge(gBattlerAttacker); - gBattleCommunication[MULTISTRING_CHOOSER] = 3; - gBattlescriptCurrInstr = BattleScript_PrintFailedToRunString; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; - } - } - else - { - if (gBattleMons[gBattlerAttacker].status2 & (STATUS2_WRAPPED | STATUS2_ESCAPE_PREVENTION)) - { - gBattleCommunication[MULTISTRING_CHOOSER] = 4; - gBattlescriptCurrInstr = BattleScript_PrintFailedToRunString; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; - } - else - { - gCurrentTurnActionNumber = gBattlersCount; - gBattleOutcome = B_OUTCOME_MON_FLED; - } - } - } -} - -void HandleAction_WatchesCarefully(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - gBattlescriptCurrInstr = gBattlescriptsForSafariActions[0]; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -void HandleAction_SafariZoneBallThrow(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - gNumSafariBalls--; - gLastUsedItem = ITEM_SAFARI_BALL; - gBattlescriptCurrInstr = gBattlescriptsForBallThrow[ITEM_SAFARI_BALL]; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -void HandleAction_ThrowPokeblock(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - gBattleCommunication[MULTISTRING_CHOOSER] = gBattleBufferB[gBattlerAttacker][1] - 1; - gLastUsedItem = gBattleBufferB[gBattlerAttacker][2]; - - if (gBattleResults.pokeblockThrows < 0xFF) - gBattleResults.pokeblockThrows++; - if (gBattleStruct->safariPkblThrowCounter < 3) - gBattleStruct->safariPkblThrowCounter++; - if (gBattleStruct->safariEscapeFactor > 1) - { - if (gBattleStruct->safariEscapeFactor < sPkblToEscapeFactor[gBattleStruct->safariPkblThrowCounter][gBattleCommunication[MULTISTRING_CHOOSER]]) - gBattleStruct->safariEscapeFactor = 1; - else - gBattleStruct->safariEscapeFactor -= sPkblToEscapeFactor[gBattleStruct->safariPkblThrowCounter][gBattleCommunication[MULTISTRING_CHOOSER]]; - } - - gBattlescriptCurrInstr = gBattlescriptsForSafariActions[2]; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -void HandleAction_GoNear(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - - gBattleStruct->safariCatchFactor += sGoNearCounterToCatchFactor[gBattleStruct->safariGoNearCounter]; - if (gBattleStruct->safariCatchFactor > 20) - gBattleStruct->safariCatchFactor = 20; - - gBattleStruct->safariEscapeFactor += sGoNearCounterToEscapeFactor[gBattleStruct->safariGoNearCounter]; - if (gBattleStruct->safariEscapeFactor > 20) - gBattleStruct->safariEscapeFactor = 20; - - if (gBattleStruct->safariGoNearCounter < 3) - { - gBattleStruct->safariGoNearCounter++; - gBattleCommunication[MULTISTRING_CHOOSER] = 0; - } - else - { - gBattleCommunication[MULTISTRING_CHOOSER] = 1; // Can't get closer. - } - gBattlescriptCurrInstr = gBattlescriptsForSafariActions[1]; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; -} - -void HandleAction_SafariZoneRun(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - PlaySE(SE_FLEE); - gCurrentTurnActionNumber = gBattlersCount; - gBattleOutcome = B_OUTCOME_RAN; -} - -void HandleAction_WallyBallThrow(void) -{ - gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; - gBattle_BG0_X = 0; - gBattle_BG0_Y = 0; - - PREPARE_MON_NICK_BUFFER(gBattleTextBuff1, gBattlerAttacker, gBattlerPartyIndexes[gBattlerAttacker]) - - gBattlescriptCurrInstr = gBattlescriptsForSafariActions[3]; - gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; - gActionsByTurnOrder[1] = B_ACTION_FINISHED; -} - -void HandleAction_TryFinish(void) -{ - if (!HandleFaintedMonActions()) - { - gBattleStruct->faintedActionsState = 0; - gCurrentActionFuncId = B_ACTION_FINISHED; - } -} - -void HandleAction_NothingIsFainted(void) -{ - gCurrentTurnActionNumber++; - gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; - gHitMarker &= ~(HITMARKER_DESTINYBOND | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_ATTACKSTRING_PRINTED - | HITMARKER_NO_PPDEDUCT | HITMARKER_IGNORE_SAFEGUARD | HITMARKER_IGNORE_ON_AIR - | HITMARKER_IGNORE_UNDERGROUND | HITMARKER_IGNORE_UNDERWATER | HITMARKER_x100000 - | HITMARKER_OBEYS | HITMARKER_x10 | HITMARKER_SYNCHRONISE_EFFECT - | HITMARKER_CHARGING | HITMARKER_x4000000); -} - -void HandleAction_ActionFinished(void) -{ - *(gBattleStruct->monToSwitchIntoId + gBattlerByTurnOrder[gCurrentTurnActionNumber]) = 6; - gCurrentTurnActionNumber++; - gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; - SpecialStatusesClear(); - gHitMarker &= ~(HITMARKER_DESTINYBOND | HITMARKER_IGNORE_SUBSTITUTE | HITMARKER_ATTACKSTRING_PRINTED - | HITMARKER_NO_PPDEDUCT | HITMARKER_IGNORE_SAFEGUARD | HITMARKER_IGNORE_ON_AIR - | HITMARKER_IGNORE_UNDERGROUND | HITMARKER_IGNORE_UNDERWATER | HITMARKER_x100000 - | HITMARKER_OBEYS | HITMARKER_x10 | HITMARKER_SYNCHRONISE_EFFECT - | HITMARKER_CHARGING | HITMARKER_x4000000); - - gCurrentMove = 0; - gBattleMoveDamage = 0; - gMoveResultFlags = 0; - gBattleScripting.animTurn = 0; - gBattleScripting.animTargetsHit = 0; - gLastLandedMoves[gBattlerAttacker] = 0; - gLastHitByType[gBattlerAttacker] = 0; - gBattleStruct->dynamicMoveType = 0; - gDynamicBasePower = 0; - gBattleScripting.moveendState = 0; - gBattleCommunication[3] = 0; - gBattleCommunication[4] = 0; - gBattleScripting.multihitMoveEffect = 0; - gBattleResources->battleScriptsStack->size = 0; -} // rom const data static const u16 sSoundMovesTable[] = @@ -2241,8 +1634,16 @@ bool8 HasNoMonsToSwitch(u8 battler, u8 partyIdBattlerOn1, u8 partyIdBattlerOn2) } else { + // FIXME: Compiler insists on moving r4 into r1 before doing the eor. + #ifndef NONMATCHING + register u32 var asm("r1"); + #else + u32 var; + #endif // NONMATCHING + party = gEnemyParty; - if (battler == 1) + var = battler ^ BIT_SIDE; + if (var == 0) id1 = 0; else id1 = 1; diff --git a/src/berry.c b/src/berry.c index d70e8c353..98264f37b 100644 --- a/src/berry.c +++ b/src/berry.c @@ -1331,7 +1331,7 @@ void ResetBerryTreeSparkleFlags(void) s16 bottom; int i; - GetCameraCoords((u16*)&cam_left, (u16*)&cam_top); + GetCameraCoords(&cam_left, &cam_top); left = cam_left; top = cam_top + 3; right = cam_left + 14; diff --git a/src/berry_blender.c b/src/berry_blender.c index 2cdb841ee..16ba42bd7 100644 --- a/src/berry_blender.c +++ b/src/berry_blender.c @@ -168,8 +168,8 @@ struct BerryBlender u16 progressBarValue; u16 maxProgressBarValue; u16 centerScale; - s16 bg_X; - s16 bg_Y; + u16 bg_X; + u16 bg_Y; u8 opponentTaskIds[BLENDER_MAX_PLAYERS - 1]; u8 perfectOpponents; // for debugging, NPCs will always hit Best u16 scores[BLENDER_MAX_PLAYERS][NUM_SCORE_TYPES]; @@ -3387,13 +3387,13 @@ static void RestoreBgCoord(s16* coord) // For "unshaking" the screen after ShakeBgCoordForHit is called static void RestoreBgCoords(void) { - RestoreBgCoord((s16 *)&sBerryBlender->bg_X); - RestoreBgCoord((s16 *)&sBerryBlender->bg_Y); + RestoreBgCoord(&sBerryBlender->bg_X); + RestoreBgCoord(&sBerryBlender->bg_Y); } static void BlenderLandShakeBgCoord(s16* coord, u16 timer) { - u8 strength; + s32 strength; if (timer < 10) strength = 16; diff --git a/src/berry_crush.c b/src/berry_crush.c index 2175d2abb..96b00ba2b 100755 --- a/src/berry_crush.c +++ b/src/berry_crush.c @@ -146,49 +146,38 @@ struct BerryCrushGame { MainCallback unk0; u32 (* unk4)(struct BerryCrushGame *, u8 *); - u8 unk8; u8 unk9; u8 unkA; u8 unkB; - u8 unkC; u8 unkD; - u8 unkE; u8 unkF; - u16 unk10; u16 unk12; u16 unk14; - u16 unk16; s16 unk18; s16 unk1A; - s32 unk1C; + int unk1C; s32 unk20; u8 unk24; - u8 unk25_0:1; u8 unk25_1:1; u8 unk25_2:1; u8 unk25_3:1; u8 unk25_4:1; u8 unk25_5:3; - u16 unk26; - u16 unk28; s16 unk2A; s16 unk2C; - s16 unk2E; s16 unk30; s16 unk32; s16 unk34; - u8 unk36[0xA]; - struct BerryCrushGame_40 unk40; struct BerryCrushGame_5C unk5C; union BerryCrushGame_68 unk68; @@ -215,7 +204,7 @@ void sub_8022524(struct BerryCrushGame_138 *, u16); void sub_8022B28(struct Sprite *); void sub_8022554(struct BerryCrushGame_138 *r0); void sub_8024578(struct BerryCrushGame *); -void sub_8024644(u8 *, u8, u8, u16, u8); +void sub_8024644(u8 *, u32, u32, u32, u32); static void sub_8022A20(struct Sprite *sprite); static u32 BerryCrushCommand_BeginNormalPaletteFade(struct BerryCrushGame *r6, u8 *r1); static u32 sub_8022CB0(struct BerryCrushGame *r4, u8 *r5); @@ -1676,7 +1665,7 @@ static void Task_ShowBerryCrushRankings(u8 taskId) CopyWindowToVram(data[1], 3); break; case 2: - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) break; else return; @@ -1997,29 +1986,29 @@ static u32 BerryCrushCommand_BeginNormalPaletteFade(struct BerryCrushGame *game, // byte 9: if TRUE, communicate on fade complete u16 color; - u32 selectedPals[2]; + u32 selectedPals; + selectedPals = ({ +#ifndef NONMATCHING + register u32 value asm("r2"); + register u32 b asm("r3"); +#else + u32 value; + u32 b; +#endif //NONMATCHING + value = params[0] << 0; + value |= (b = params[1] << 8); + value |= (b = params[2] << 16); + value |= (b = params[3] << 24); + value; + }); - selectedPals[0] = (u32)params[0]; - selectedPals[1] = (u32)params[1]; - selectedPals[1] <<= 8; - - selectedPals[0] |= selectedPals[1]; - selectedPals[1] = (u32)params[2]; - selectedPals[1] <<= 16; - - selectedPals[0] |= selectedPals[1]; - selectedPals[1] = (u32)params[3]; - selectedPals[1] <<= 24; - - selectedPals[0] |= selectedPals[1]; params[0] = params[9]; - color = params[8]; - color <<= 8; - color |= params[7]; + color = params[8] << 8; + color |= params[7] << 0; gPaletteFade.bufferTransferDisabled = FALSE; - BeginNormalPaletteFade(selectedPals[0], params[4], params[5], params[6], color); + BeginNormalPaletteFade(selectedPals, params[4], params[5], params[6], color); UpdatePaletteFade(); game->unkE = 2; return 0; @@ -2401,7 +2390,7 @@ void sub_802339C(struct BerryCrushGame *r4) } } } - if (r8 >= 2) + if (r8 > 1) { for (r7 = 0; r7 < r4->unk9; ++r7) { @@ -2509,9 +2498,9 @@ void sub_8023558(struct BerryCrushGame *r3) void sub_80236B8(struct BerryCrushGame *r5) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) r5->unk5C.unk02_2 = 1; - if (JOY_HELD(A_BUTTON)) + if (gMain.heldKeys & A_BUTTON) { if (r5->unk68.as_four_players.others[r5->unk8].unk4.as_hwords[5] < r5->unk28) ++r5->unk68.as_four_players.others[r5->unk8].unk4.as_hwords[5]; @@ -2591,7 +2580,6 @@ void sub_802385C(struct BerryCrushGame *r5) for (r4 = 0; r4 < r5->unk9; ++r4) r5->unk68.as_four_players.others[r4].unk4.as_2d_bytes[1][5] = 0; #endif - if ((gRecvCmds[0][0] & 0xFF00) != RFUCMD_SEND_PACKET || gRecvCmds[0][1] != 2) { @@ -2978,7 +2966,7 @@ static u32 sub_8024048(struct BerryCrushGame *r5, u8 *r6) --r5->unk138.unk0; return 0; } - if (!(JOY_NEW(A_BUTTON))) + if (!(gMain.newKeys & A_BUTTON)) return 0; PlaySE(SE_SELECT); sub_802222C(r5); @@ -3281,11 +3269,14 @@ static void BerryCrush_SetPaletteFadeParams(u8 *params, bool8 communicateAfter, params[9] = communicateAfter; } -void sub_8024644(u8 *r0, u8 r1, u8 r2, u16 r3, u8 r5) +void sub_8024644(u8 *r0, u32 r1, u32 r2, u32 r3, u32 r5) { + u8 sp[4]; + + 0[(u16 *)sp] = r3; r0[0] = r1; r0[1] = r2; - r0[2] = ((u8 *)&r3)[0]; - r0[3] = ((u8 *)&r3)[1]; + r0[2] = sp[0]; + r0[3] = sp[1]; r0[4] = r5; } diff --git a/src/berry_fix_program.c b/src/berry_fix_program.c index 4c4a010b2..dcc21d036 100644 --- a/src/berry_fix_program.c +++ b/src/berry_fix_program.c @@ -190,13 +190,13 @@ static void berry_fix_main(void) berry_fix_mb_manager->state = 1; break; case 1: - if (berry_fix_text_update(5) == 5 && (JOY_NEW(A_BUTTON))) + if (berry_fix_text_update(5) == 5 && (gMain.newKeys & A_BUTTON)) { berry_fix_mb_manager->state = 2; } break; case 2: - if (berry_fix_text_update(0) == 0 && (JOY_NEW(A_BUTTON))) + if (berry_fix_text_update(0) == 0 && (gMain.newKeys & A_BUTTON)) { berry_fix_mb_manager->state = 3; } @@ -235,13 +235,13 @@ static void berry_fix_main(void) } break; case 6: - if (berry_fix_text_update(3) == 3 && JOY_NEW(A_BUTTON)) + if (berry_fix_text_update(3) == 3 && gMain.newKeys & A_BUTTON) { DoSoftReset(); } break; case 7: - if (berry_fix_text_update(4) == 4 && JOY_NEW(A_BUTTON)) + if (berry_fix_text_update(4) == 4 && gMain.newKeys & A_BUTTON) { berry_fix_mb_manager->state = 1; } diff --git a/src/berry_tag_screen.c b/src/berry_tag_screen.c index 089228b17..e5c89bdb7 100644 --- a/src/berry_tag_screen.c +++ b/src/berry_tag_screen.c @@ -536,12 +536,12 @@ static void Task_HandleInput(u8 taskId) { if (!gPaletteFade.active) { - u16 arrowKeys = JOY_REPEAT(DPAD_ANY); + u16 arrowKeys = gMain.newAndRepeatedKeys & DPAD_ANY; if (arrowKeys == DPAD_UP) TryChangeDisplayedBerry(taskId, -1); else if (arrowKeys == DPAD_DOWN) TryChangeDisplayedBerry(taskId, 1); - else if (JOY_NEW(A_BUTTON | B_BUTTON)) + else if (gMain.newKeys & (A_BUTTON | B_BUTTON)) PrepareToCloseBerryTagScreen(taskId); } } diff --git a/src/cable_club.c b/src/cable_club.c index f02683c9d..93f87ec9b 100644 --- a/src/cable_club.c +++ b/src/cable_club.c @@ -163,7 +163,7 @@ static bool32 CheckLinkErrored(u8 taskId) static bool32 CheckLinkCanceledBeforeConnection(u8 taskId) { - if ((JOY_NEW(B_BUTTON)) + if ((gMain.newKeys & B_BUTTON) && IsLinkConnectionEstablished() == FALSE) { gLinkType = 0; @@ -178,7 +178,7 @@ static bool32 CheckLinkCanceled(u8 taskId) if (IsLinkConnectionEstablished()) SetSuppressLinkErrorMessage(TRUE); - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { gLinkType = 0; gTasks[taskId].func = Task_LinkupFailed; @@ -277,7 +277,7 @@ static void Task_LinkupAwaitConfirmation(u8 taskId) UpdateLinkPlayerCountDisplay(taskId, linkPlayerCount); - if (!(JOY_NEW(A_BUTTON))) + if (!(gMain.newKeys & A_BUTTON)) return; if (linkPlayerCount < tMinPlayers) @@ -304,12 +304,12 @@ static void Task_LinkupTryConfirmation(u8 taskId) ShowFieldAutoScrollMessage(gText_ConfirmLinkWhenPlayersReady); gTasks[taskId].func = Task_LinkupConfirmWhenReady; } - else if (JOY_HELD(B_BUTTON)) + else if (gMain.heldKeys & B_BUTTON) { ShowFieldAutoScrollMessage(gText_ConfirmLinkWhenPlayersReady); gTasks[taskId].func = Task_LinkupConfirmWhenReady; } - else if (JOY_HELD(A_BUTTON)) + else if (gMain.heldKeys & A_BUTTON) { PlaySE(SE_SELECT); CheckShouldAdvanceLinkState(); diff --git a/src/confetti_util.c b/src/confetti_util.c index 6d4770056..3bda3ab53 100644 --- a/src/confetti_util.c +++ b/src/confetti_util.c @@ -30,8 +30,10 @@ static void sub_81520A8(void *dest, u16 value, u8 left, u8 top, u8 width, u8 hei static void sub_8152134(void *dest, const u16 *src, u8 left, u8 top, u8 width, u8 height) // Unused. { - u8 i, j; - u8 x, y; + u8 i; + u8 j; + u8 x; + u8 y; const u16 *_src; for (i = 0, _src = src, y = top; i < height; i++) diff --git a/src/contest.c b/src/contest.c index 612d79562..b509c896a 100644 --- a/src/contest.c +++ b/src/contest.c @@ -999,6 +999,8 @@ void ResetLinkContestBoolean(void) static void SetupContestGpuRegs(void) { + u16 savedIme; + SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_1D_MAP); SetGpuReg(REG_OFFSET_BLDCNT, 0); SetGpuReg(REG_OFFSET_BLDALPHA, 0); @@ -1493,7 +1495,7 @@ static void Task_DisplayAppealNumberText(u8 taskId) static void Task_TryShowMoveSelectScreen(u8 taskId) { // Wait for button press to show move select screen - if ((JOY_NEW(A_BUTTON)) || (gMain.newKeys == B_BUTTON)) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys == B_BUTTON)) { PlaySE(SE_SELECT); if (!Contest_IsMonsTurnDisabled(gContestPlayerMonIndex)) @@ -1559,7 +1561,7 @@ static void Task_HandleMoveSelectInput(u8 taskId) numMoves++; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); gTasks[taskId].func = Task_SelectedMove; @@ -3408,7 +3410,8 @@ static void GetAllChosenMoves(void) static void RankContestants(void) { - s32 i, j; + s32 i; + s32 j; s16 arr[CONTESTANT_COUNT]; for (i = 0; i < CONTESTANT_COUNT; i++) @@ -3483,7 +3486,8 @@ static bool8 ContestantCanUseTurn(u8 contestant) { if (eContestantStatus[contestant].numTurnsSkipped != 0 || eContestantStatus[contestant].noMoreTurns) return FALSE; - return TRUE; + else + return TRUE; } static void SetContestantStatusesForNextRound(void) @@ -3537,7 +3541,8 @@ bool8 Contest_IsMonsTurnDisabled(u8 contestant) { if (eContestantStatus[contestant].numTurnsSkipped != 0 || eContestantStatus[contestant].noMoreTurns) return TRUE; - return FALSE; + else + return FALSE; } static void CalculateTotalPointsForContestant(u8 contestant) @@ -4137,12 +4142,12 @@ static u8 CreateContestantBoxBlinkSprites(u8 contestant) CpuFill32(0, gContestResources->boxBlinkTiles2 + 0x500, 0x300); RequestDma3Copy(gContestResources->boxBlinkTiles1, - (u8 *)(OBJ_VRAM0 + gSprites[spriteId1].oam.tileNum * 32), + (u8 *)(VRAM + 0x10000 + gSprites[spriteId1].oam.tileNum * 32), 0x800, 1); RequestDma3Copy(gContestResources->boxBlinkTiles2, - (u8 *)(OBJ_VRAM0 + gSprites[spriteId2].oam.tileNum * 32), + (u8 *)(VRAM + 0x10000 + gSprites[spriteId2].oam.tileNum * 32), 0x800, 1); @@ -4480,14 +4485,17 @@ static void CalculateAppealMoveImpact(u8 contestant) eContestantStatus[contestant].comboAppealBonus = eContestantStatus[contestant].baseAppeal * eContestantStatus[contestant].completedCombo; eContestantStatus[contestant].completedComboFlag = TRUE; // Redundant with completedCombo, used by AI } - else if (gContestMoves[eContestantStatus[contestant].currMove].comboStarterId != 0) - { - eContestantStatus[contestant].hasJudgesAttention = TRUE; - eContestantStatus[contestant].usedComboMove = TRUE; - } else { - eContestantStatus[contestant].hasJudgesAttention = FALSE; + if (gContestMoves[eContestantStatus[contestant].currMove].comboStarterId != 0) + { + eContestantStatus[contestant].hasJudgesAttention = TRUE; + eContestantStatus[contestant].usedComboMove = TRUE; + } + else + { + eContestantStatus[contestant].hasJudgesAttention = FALSE; + } } } if (eContestantStatus[contestant].repeatedMove) @@ -4728,8 +4736,8 @@ static void UpdateApplauseMeter(void) src = &gContestApplauseMeterGfx[64]; else src = gContestApplauseMeterGfx; - CpuCopy32(src, (void *)(OBJ_VRAM0 + (gSprites[eContest.applauseMeterSpriteId].oam.tileNum + 17 + i) * 32), 32); - CpuCopy32(src + 32, (void *)(OBJ_VRAM0 + (gSprites[eContest.applauseMeterSpriteId].oam.tileNum + 25 + i) * 32), 32); + CpuCopy32(src, (void *)(VRAM + 0x10000 + (gSprites[eContest.applauseMeterSpriteId].oam.tileNum + 17 + i) * 32), 32); + CpuCopy32(src + 32, (void *)(VRAM + 0x10000 + (gSprites[eContest.applauseMeterSpriteId].oam.tileNum + 25 + i) * 32), 32); if (eContest.applauseLevel > 4) StartApplauseOverflowAnimation(); @@ -5411,7 +5419,7 @@ static void Contest_PrintTextToBg0WindowStd(u32 windowId, const u8 *b) printerTemplate.currentY = 1; printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; - printerTemplate.style = 0; + printerTemplate.unk = 0; printerTemplate.fgColor = 15; printerTemplate.bgColor = 0; printerTemplate.shadowColor = 8; @@ -5434,7 +5442,7 @@ void Contest_PrintTextToBg0WindowAt(u32 windowId, u8 *currChar, s32 x, s32 y, s3 printerTemplate.currentY = y; printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; - printerTemplate.style = 0; + printerTemplate.unk = 0; printerTemplate.fgColor = 15; printerTemplate.bgColor = 0; printerTemplate.shadowColor = 8; @@ -5458,7 +5466,7 @@ static void Contest_StartTextPrinter(const u8 *currChar, bool32 b) printerTemplate.currentY = 1; printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; - printerTemplate.style = 0; + printerTemplate.unk = 0; printerTemplate.fgColor = 1; printerTemplate.bgColor = 0; printerTemplate.shadowColor = 8; diff --git a/src/contest_painting.c b/src/contest_painting.c index ceef8a902..5dd4a70a5 100644 --- a/src/contest_painting.c +++ b/src/contest_painting.c @@ -248,7 +248,7 @@ static void HoldContestPainting(void) gContestPaintingFadeCounter--; break; case 1: - if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON))) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON)) { gContestPaintingState++; BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB(0, 0, 0)); @@ -384,6 +384,8 @@ static void InitContestMonPixels(u16 species, u8 whichSprite) } } +#ifdef NONMATCHING +// functionally equivalent. static void _InitContestMonPixels(u8 *spriteGfx, u16 *palette, u16 (*destPixels)[64][64]) { u16 tileY, tileX, pixelY, pixelX; @@ -397,21 +399,125 @@ static void _InitContestMonPixels(u8 *spriteGfx, u16 *palette, u16 (*destPixels) { for (pixelX = 0; pixelX < 8; pixelX++) { - colorIndex = spriteGfx[((tileY * 8) + tileX) * 32 + (pixelY << 2) + (pixelX >> 1)]; + int offset = 32 * (8 * tileY + tileX) + (pixelY * 4 + pixelX / 2); + colorIndex = spriteGfx[offset]; if (pixelX & 1) colorIndex >>= 4; else - colorIndex &= 0xF; // %=16 works here too. Both match + colorIndex &= 0xF; - if (colorIndex == 0) // transparent pixel - (*destPixels)[tileY * 8 + pixelY][tileX * 8 + pixelX] = 0x8000; + if (colorIndex == 0) // transparent pixel + (*destPixels)[8 * tileY + pixelY][tileX * 8 + pixelX] = 0x8000; else - (*destPixels)[tileY * 8 + pixelY][tileX * 8 + pixelX] = palette[colorIndex]; + (*destPixels)[8 * tileY + pixelY][tileX * 8 + pixelX] = palette[colorIndex]; } } } } } +#else +NAKED +static void _InitContestMonPixels(u8 *spriteGfx, u16 *palette, u16 (*destPixels)[64][64]) +{ + asm_unified("\n\ + push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0xC\n\ + mov r10, r0\n\ + mov r9, r1\n\ + str r2, [sp]\n\ + movs r0, 0\n\ +_08130394:\n\ + movs r3, 0\n\ + adds r1, r0, 0x1\n\ + str r1, [sp, 0x4]\n\ + lsls r0, 3\n\ + str r0, [sp, 0x8]\n\ +_0813039E:\n\ + movs r1, 0\n\ + adds r2, r3, 0x1\n\ + mov r8, r2\n\ + ldr r7, [sp, 0x8]\n\ + adds r0, r7, r3\n\ + lsls r0, 5\n\ + mov r12, r0\n\ + lsls r4, r3, 3\n\ +_081303AE:\n\ + movs r3, 0\n\ + lsls r0, r1, 2\n\ + adds r6, r1, 0x1\n\ + mov r2, r12\n\ + adds r5, r2, r0\n\ + ldr r7, [sp, 0x8]\n\ + adds r0, r7, r1\n\ + lsls r0, 7\n\ + ldr r1, [sp]\n\ + adds r2, r0, r1\n\ +_081303C2:\n\ + lsrs r0, r3, 1\n\ + adds r0, r5, r0\n\ + add r0, r10\n\ + ldrb r1, [r0]\n\ + movs r0, 0x1\n\ + ands r0, r3\n\ + cmp r0, 0\n\ + beq _081303D6\n\ + lsrs r1, 4\n\ + b _081303DA\n\ +_081303D6:\n\ + movs r0, 0xF\n\ + ands r1, r0\n\ +_081303DA:\n\ + cmp r1, 0\n\ + bne _081303EC\n\ + adds r0, r4, r3\n\ + lsls r0, 1\n\ + adds r0, r2\n\ + movs r7, 0x80\n\ + lsls r7, 8\n\ + adds r1, r7, 0\n\ + b _081303F8\n\ +_081303EC:\n\ + adds r0, r4, r3\n\ + lsls r0, 1\n\ + adds r0, r2\n\ + lsls r1, 1\n\ + add r1, r9\n\ + ldrh r1, [r1]\n\ +_081303F8:\n\ + strh r1, [r0]\n\ + adds r0, r3, 0x1\n\ + lsls r0, 16\n\ + lsrs r3, r0, 16\n\ + cmp r3, 0x7\n\ + bls _081303C2\n\ + lsls r0, r6, 16\n\ + lsrs r1, r0, 16\n\ + cmp r1, 0x7\n\ + bls _081303AE\n\ + mov r1, r8\n\ + lsls r0, r1, 16\n\ + lsrs r3, r0, 16\n\ + cmp r3, 0x7\n\ + bls _0813039E\n\ + ldr r2, [sp, 0x4]\n\ + lsls r0, r2, 16\n\ + lsrs r0, 16\n\ + cmp r0, 0x7\n\ + bls _08130394\n\ + add sp, 0xC\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0"); +} +#endif #define VRAM_PICTURE_DATA(x, y) (((u16 *)(BG_SCREEN_ADDR(12)))[(y) * 32 + (x)]) @@ -501,20 +607,20 @@ static void LoadContestPaintingFrame(u8 contestWinnerId, bool8 arg1) static void InitPaintingMonOamData(u8 contestWinnerId) { + //Some hacks just to get the asm to match +#ifndef NONMATCHING + asm(""::"r"(contestWinnerId)); +#endif gMain.oamBuffer[0] = sContestPaintingMonOamData; gMain.oamBuffer[0].tileNum = 0; - if (contestWinnerId > 1) - { - gMain.oamBuffer[0].x = 88; - gMain.oamBuffer[0].y = 24; - } - else - { - gMain.oamBuffer[0].x = 88; // Duplicated Code - gMain.oamBuffer[0].y = 24; - } +#ifndef NONMATCHING + if (contestWinnerId) contestWinnerId = gMain.oamBuffer[0].tileNum; +#endif + + gMain.oamBuffer[0].x = 88; + gMain.oamBuffer[0].y = 24; } static u8 GetImageEffectForContestWinner(u8 contestWinnerId) diff --git a/src/contest_util.c b/src/contest_util.c index ae76eda6b..5b4e0a70a 100644 --- a/src/contest_util.c +++ b/src/contest_util.c @@ -1148,71 +1148,350 @@ static void TryCreateWirelessSprites(void) } } +// Functionally equivalent, the same except compiler generated variables from +// src are placed on different stack positions. + +#ifdef NONMATCHING static s32 DrawResultsTextWindow(const u8 *text, u8 spriteId) { + u8 *windowTilesPtr; u16 windowId; - s32 origWidth, strWidth; + int origWidth; + struct WindowTemplate windowTemplate; + int strWidth; u8 *spriteTilePtrs[4]; u8 *dst; + int i; + struct Sprite *sprite; + const u8 *src; // The culprit. - { - struct WindowTemplate windowTemplate; //It's important the lifetime of this struct ends after the clear - memset(&windowTemplate, 0, sizeof(windowTemplate)); - windowTemplate.width = 30; - windowTemplate.height = 2; - windowId = AddWindow(&windowTemplate); - FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); - } + memset(&windowTemplate, 0, sizeof(windowTemplate)); + windowTemplate.width = 30; + windowTemplate.height = 2; + windowId = AddWindow(&windowTemplate); + FillWindowPixelBuffer(windowId, PIXEL_FILL(1)); origWidth = GetStringWidth(1, text, 0); - if ((strWidth = (origWidth + 9) / 8) > 30) - strWidth = 30; + strWidth = (origWidth + 9) / 8; + if (strWidth > 30) + strWidth = 30; AddTextPrinterParameterized3(windowId, 1, (strWidth * 8 - origWidth) / 2, 1, sContestLinkTextColors, -1, text); + windowTilesPtr = (u8 *)(GetWindowAttribute(windowId, WINDOW_TILE_DATA)); + src = (u8 *)(sUnknown_0858D6D0); + sprite = &gSprites[spriteId]; + spriteTilePtrs[0] = (u8 *)(sprite->oam.tileNum * 32 + VRAM + 0x10000); + + for (i = 1; i < 4; i++) + spriteTilePtrs[i] = (void*)(gSprites[sprite->data[i - 1]].oam.tileNum * 32 + VRAM + 0x10000); + + for (i = 0; i < 4; i++) + CpuFill32(0, spriteTilePtrs[i], 0x400); + + dst = spriteTilePtrs[0]; + CpuCopy32(src, dst, 0x20); + CpuCopy32(src + 128, dst + 0x100, 0x20); + CpuCopy32(src + 128, dst + 0x200, 0x20); + CpuCopy32(src + 64, dst + 0x300, 0x20); + + for (i = 0; i < strWidth; i++) { - s32 i; - struct Sprite *sprite; - const u8 *src, *windowTilesPtr; - windowTilesPtr = (const u8 *)(GetWindowAttribute(windowId, WINDOW_TILE_DATA)); - src = sUnknown_0858D6D0; - - sprite = &gSprites[spriteId]; - spriteTilePtrs[0] = (u8 *)((OBJ_VRAM0) + sprite->oam.tileNum * 32); - - for (i = 1; i < 4; i++) - spriteTilePtrs[i] = (u8 *)((OBJ_VRAM0) + gSprites[sprite->data[i - 1]].oam.tileNum * 32); - - for (i = 0; i < 4; i++) - CpuFill32(0, spriteTilePtrs[i], 0x400); - - dst = spriteTilePtrs[0]; - CpuCopy32(src, dst, 0x20); - CpuCopy32(src + 128, dst + 0x100, 0x20); - CpuCopy32(src + 128, dst + 0x200, 0x20); - CpuCopy32(src + 64, dst + 0x300, 0x20); - - for (i = 0; i < strWidth; i++) - { - dst = &spriteTilePtrs[(i + 1) / 8][((i + 1) % 8) * 32]; - CpuCopy32(src + 192, dst, 0x20); - CpuCopy32(windowTilesPtr, dst + 0x100, 0x20); - CpuCopy32(windowTilesPtr + 960, dst + 0x200, 0x20); - CpuCopy32(src + 224, dst + 0x300, 0x20); - windowTilesPtr += 0x20; - } - dst = &spriteTilePtrs[(i + 1) / 8][((i + 1) % 8) * 32]; - CpuCopy32(src + 32, dst, 0x20); - CpuCopy32(src + 160, dst + 0x100, 0x20); - CpuCopy32(src + 160, dst + 0x200, 0x20); - CpuCopy32(src + 96, dst + 0x300, 0x20); + CpuCopy32(src + 192, dst, 0x20); + CpuCopy32(windowTilesPtr, dst + 0x100, 0x20); + CpuCopy32(windowTilesPtr + 960, dst + 0x200, 0x20); + CpuCopy32(src + 224, dst + 0x300, 0x20); + windowTilesPtr += 0x20; } + + dst = &spriteTilePtrs[(i + 1) / 8][((i + 1) % 8) * 32]; + CpuCopy32(src + 32, dst, 0x20); + CpuCopy32(src + 160, dst + 0x100, 0x20); + CpuCopy32(src + 160, dst + 0x200, 0x20); + CpuCopy32(src + 96, dst + 0x300, 0x20); RemoveWindow(windowId); return (240 - (strWidth + 2) * 8) / 2; } +#else +NAKED +static s32 DrawResultsTextWindow(const u8 *text, u8 spriteId) +{ + asm_unified( + "push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0x44\n\ + adds r5, r0, 0\n\ + lsls r1, 24\n\ + lsrs r7, r1, 24\n\ + add r4, sp, 0x20\n\ + adds r0, r4, 0\n\ + movs r1, 0\n\ + movs r2, 0x8\n\ + bl memset\n\ + movs r0, 0x1E\n\ + strb r0, [r4, 0x3]\n\ + movs r0, 0x2\n\ + strb r0, [r4, 0x4]\n\ + adds r0, r4, 0\n\ + bl AddWindow\n\ + lsls r6, r0, 24\n\ + lsrs r4, r6, 24\n\ + adds r0, r4, 0\n\ + movs r1, 0x11\n\ + bl FillWindowPixelBuffer\n\ + movs r0, 0x1\n\ + adds r1, r5, 0\n\ + movs r2, 0\n\ + bl GetStringWidth\n\ + adds r2, r0, 0\n\ + adds r2, 0x9\n\ + cmp r2, 0\n\ + bge _080F6BC4\n\ + adds r2, 0x7\n\ +_080F6BC4:\n\ + asrs r2, 3\n\ + mov r10, r2\n\ + cmp r2, 0x1E\n\ + ble _080F6BD0\n\ + movs r1, 0x1E\n\ + mov r10, r1\n\ +_080F6BD0:\n\ + mov r1, r10\n\ + lsls r2, r1, 3\n\ + subs r2, r0\n\ + lsrs r0, r2, 31\n\ + adds r2, r0\n\ + asrs r2, 1\n\ + lsls r2, 24\n\ + lsrs r2, 24\n\ + ldr r0, =sContestLinkTextColors\n\ + str r0, [sp]\n\ + movs r0, 0x1\n\ + negs r0, r0\n\ + str r0, [sp, 0x4]\n\ + str r5, [sp, 0x8]\n\ + adds r0, r4, 0\n\ + movs r1, 0x1\n\ + movs r3, 0x1\n\ + bl AddTextPrinterParameterized3\n\ + adds r0, r4, 0\n\ + movs r1, 0x7\n\ + bl GetWindowAttribute\n\ + mov r9, r0\n\ + ldr r2, =sUnknown_0858D6D0\n\ + mov r8, r2\n\ + lsls r1, r7, 4\n\ + adds r1, r7\n\ + lsls r1, 2\n\ + ldr r3, =gSprites\n\ + adds r1, r3\n\ + ldrh r0, [r1, 0x4]\n\ + lsls r0, 22\n\ + lsrs r0, 17\n\ + ldr r2, =0x06010000\n\ + adds r0, r2\n\ + str r0, [sp, 0xC]\n\ + str r6, [sp, 0x38]\n\ + mov r7, sp\n\ + adds r7, 0x1C\n\ + str r7, [sp, 0x2C]\n\ + mov r0, r10\n\ + adds r0, 0x2\n\ + str r0, [sp, 0x30]\n\ + movs r5, 0\n\ + add r7, sp, 0x10\n\ + mov r12, r7\n\ + adds r6, r1, 0\n\ + adds r6, 0x2E\n\ + movs r4, 0x2\n\ +_080F6C34:\n\ + adds r0, r6, r5\n\ + movs r7, 0\n\ + ldrsh r1, [r0, r7]\n\ + lsls r0, r1, 4\n\ + adds r0, r1\n\ + lsls r0, 2\n\ + adds r0, r3\n\ + ldrh r0, [r0, 0x4]\n\ + lsls r0, 22\n\ + lsrs r0, 17\n\ + adds r0, r2\n\ + mov r1, r12\n\ + adds r1, 0x4\n\ + mov r12, r1\n\ + subs r1, 0x4\n\ + stm r1!, {r0}\n\ + adds r5, 0x2\n\ + subs r4, 0x1\n\ + cmp r4, 0\n\ + bge _080F6C34\n\ + mov r7, r8\n\ + adds r7, 0x80\n\ + mov r2, r8\n\ + adds r2, 0x40\n\ + str r2, [sp, 0x28]\n\ + mov r0, r8\n\ + adds r0, 0x20\n\ + str r0, [sp, 0x3C]\n\ + mov r1, r8\n\ + adds r1, 0xA0\n\ + str r1, [sp, 0x40]\n\ + adds r2, 0x20\n\ + str r2, [sp, 0x34]\n\ + add r5, sp, 0xC\n\ + movs r6, 0\n\ + movs r4, 0x3\n\ +_080F6C7C:\n\ + str r6, [sp, 0x1C]\n\ + ldm r5!, {r1}\n\ + ldr r0, [sp, 0x2C]\n\ + ldr r2, =0x05000100\n\ + bl CpuSet\n\ + subs r4, 0x1\n\ + cmp r4, 0\n\ + bge _080F6C7C\n\ + ldr r5, [sp, 0xC]\n\ + ldr r6, =0x04000008\n\ + mov r0, r8\n\ + adds r1, r5, 0\n\ + adds r2, r6, 0\n\ + bl CpuSet\n\ + movs r0, 0x80\n\ + lsls r0, 1\n\ + adds r1, r5, r0\n\ + adds r0, r7, 0\n\ + adds r2, r6, 0\n\ + bl CpuSet\n\ + movs r2, 0x80\n\ + lsls r2, 2\n\ + adds r1, r5, r2\n\ + adds r0, r7, 0\n\ + adds r2, r6, 0\n\ + bl CpuSet\n\ + movs r7, 0xC0\n\ + lsls r7, 2\n\ + adds r1, r5, r7\n\ + ldr r0, [sp, 0x28]\n\ + adds r2, r6, 0\n\ + bl CpuSet\n\ + movs r4, 0\n\ + cmp r4, r10\n\ + bge _080F6D32\n\ + adds r7, r6, 0\n\ +_080F6CCE:\n\ + adds r6, r4, 0x1\n\ + adds r0, r6, 0\n\ + cmp r6, 0\n\ + bge _080F6CDA\n\ + adds r0, r4, 0\n\ + adds r0, 0x8\n\ +_080F6CDA:\n\ + asrs r0, 3\n\ + lsls r1, r0, 2\n\ + add r1, sp\n\ + adds r1, 0xC\n\ + lsls r0, 3\n\ + subs r0, r6, r0\n\ + lsls r0, 5\n\ + ldr r1, [r1]\n\ + adds r5, r1, r0\n\ + mov r0, r8\n\ + adds r0, 0xC0\n\ + adds r1, r5, 0\n\ + adds r2, r7, 0\n\ + bl CpuSet\n\ + movs r0, 0x80\n\ + lsls r0, 1\n\ + adds r1, r5, r0\n\ + mov r0, r9\n\ + adds r2, r7, 0\n\ + bl CpuSet\n\ + movs r0, 0xF0\n\ + lsls r0, 2\n\ + add r0, r9\n\ + movs r2, 0x80\n\ + lsls r2, 2\n\ + adds r1, r5, r2\n\ + adds r2, r7, 0\n\ + bl CpuSet\n\ + movs r0, 0xC0\n\ + lsls r0, 2\n\ + adds r1, r5, r0\n\ + mov r0, r8\n\ + adds r0, 0xE0\n\ + adds r2, r7, 0\n\ + bl CpuSet\n\ + movs r1, 0x20\n\ + add r9, r1\n\ + adds r4, r6, 0\n\ + cmp r4, r10\n\ + blt _080F6CCE\n\ +_080F6D32:\n\ + adds r2, r4, 0x1\n\ + adds r0, r2, 0\n\ + cmp r2, 0\n\ + bge _080F6D3E\n\ + adds r0, r4, 0\n\ + adds r0, 0x8\n\ +_080F6D3E:\n\ + asrs r0, 3\n\ + lsls r1, r0, 2\n\ + add r1, sp\n\ + adds r1, 0xC\n\ + lsls r0, 3\n\ + subs r0, r2, r0\n\ + lsls r0, 5\n\ + ldr r1, [r1]\n\ + adds r5, r1, r0\n\ + ldr r4, =0x04000008\n\ + ldr r0, [sp, 0x3C]\n\ + adds r1, r5, 0\n\ + adds r2, r4, 0\n\ + bl CpuSet\n\ + movs r2, 0x80\n\ + lsls r2, 1\n\ + adds r1, r5, r2\n\ + ldr r0, [sp, 0x40]\n\ + adds r2, r4, 0\n\ + bl CpuSet\n\ + movs r7, 0x80\n\ + lsls r7, 2\n\ + adds r1, r5, r7\n\ + ldr r0, [sp, 0x40]\n\ + adds r2, r4, 0\n\ + bl CpuSet\n\ + movs r0, 0xC0\n\ + lsls r0, 2\n\ + adds r1, r5, r0\n\ + ldr r0, [sp, 0x34]\n\ + adds r2, r4, 0\n\ + bl CpuSet\n\ + ldr r1, [sp, 0x38]\n\ + lsrs r0, r1, 24\n\ + bl RemoveWindow\n\ + ldr r2, [sp, 0x30]\n\ + lsls r1, r2, 3\n\ + movs r0, 0xF0\n\ + subs r0, r1\n\ + asrs r0, 1\n\ + add sp, 0x44\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r1}\n\ + bx r1\n\ + .pool"); +} +#endif // NONMATCHING + static void LoadContestResultSprites(void) { int i; @@ -1922,7 +2201,7 @@ static void AddContestTextPrinter(int windowId, u8 *str, int x) textPrinter.currentY = 2; textPrinter.letterSpacing = 0; textPrinter.lineSpacing = 0; - textPrinter.style = 0; + textPrinter.unk = 0; textPrinter.fgColor = 1; textPrinter.bgColor = 0; textPrinter.shadowColor = 8; diff --git a/src/credits.c b/src/credits.c index 86a659d5a..020221f30 100644 --- a/src/credits.c +++ b/src/credits.c @@ -1143,7 +1143,7 @@ static void CB2_RunCreditsSequence(void) RunTasks(); AnimateSprites(); - if ((JOY_HELD(B_BUTTON)) + if ((gMain.heldKeys & B_BUTTON) && gHasHallOfFameRecords != 0 && gTasks[gUnknown_0203BCE2].func == Task_ProgressCreditTasks) { @@ -1160,7 +1160,7 @@ static void sub_8175548(void) { ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sBackgroundTemplates, 1); - SetBgTilemapBuffer(0, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(0, AllocZeroed(0x800)); LoadPalette(gUnknown_085E56F0, 0x80, 0x40); InitWindows(sWindowTemplates); DeactivateAllTextPrinters(); diff --git a/src/daycare.c b/src/daycare.c index 69043a513..5d4480403 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -1186,7 +1186,7 @@ static void DaycareAddTextPrinter(u8 windowId, const u8 *text, u32 x, u32 y) printer.y = y; printer.currentX = x; printer.currentY = y; - printer.style = 0; + printer.unk = 0; gTextFlags.useAlternateDownArrow = 0; printer.letterSpacing = 0; printer.lineSpacing = 1; @@ -1237,7 +1237,7 @@ static void Task_HandleDaycareLevelMenuInput(u8 taskId) { u32 input = ListMenu_ProcessInput(gTasks[taskId].tMenuListTaskId); - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (input) { @@ -1255,7 +1255,7 @@ static void Task_HandleDaycareLevelMenuInput(u8 taskId) DestroyTask(taskId); EnableBothScriptContexts(); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { gSpecialVar_Result = DAYCARE_EXITED_LEVEL_MENU; DestroyListMenuTask(gTasks[taskId].tMenuListTaskId, NULL, NULL); diff --git a/src/decoration.c b/src/decoration.c index 22ae327f9..40cccbe5e 100644 --- a/src/decoration.c +++ b/src/decoration.c @@ -1147,7 +1147,7 @@ static void DontTossDecoration(u8 taskId) static void ReturnToDecorationItemsAfterInvalidSelection(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { ClearDialogWindowAndFrame(0, 0); AddDecorationWindow(WINDOW_DECORATION_CATEGORIES); @@ -1803,7 +1803,7 @@ static bool8 ApplyCursorMovement_IsInvalid(u8 taskId) static bool8 IsHoldingDirection(void) { - u16 heldKeys = JOY_HELD(DPAD_ANY); + u16 heldKeys = gMain.heldKeys & DPAD_ANY; if (heldKeys != DPAD_UP && heldKeys != DPAD_DOWN && heldKeys != DPAD_LEFT && heldKeys != DPAD_RIGHT) return FALSE; @@ -1827,14 +1827,13 @@ static void Task_SelectLocation(u8 taskId) sPlacePutAwayYesNoFunctions[tDecorationItemsMenuCommand].yesFunc(taskId); return; } - - if (tButton == B_BUTTON) + else if (tButton == B_BUTTON) { sPlacePutAwayYesNoFunctions[tDecorationItemsMenuCommand].noFunc(taskId); return; } - if ((JOY_HELD(DPAD_ANY)) == DPAD_UP) + if ((gMain.heldKeys & DPAD_ANY) == DPAD_UP) { sDecorationLastDirectionMoved = DIR_SOUTH; gSprites[sDecor_CameraSpriteObjectIdx1].data[2] = 0; @@ -1842,7 +1841,7 @@ static void Task_SelectLocation(u8 taskId) tCursorY--; } - if ((JOY_HELD(DPAD_ANY)) == DPAD_DOWN) + if ((gMain.heldKeys & DPAD_ANY) == DPAD_DOWN) { sDecorationLastDirectionMoved = DIR_NORTH; gSprites[sDecor_CameraSpriteObjectIdx1].data[2] = 0; @@ -1850,7 +1849,7 @@ static void Task_SelectLocation(u8 taskId) tCursorY++; } - if ((JOY_HELD(DPAD_ANY)) == DPAD_LEFT) + if ((gMain.heldKeys & DPAD_ANY) == DPAD_LEFT) { sDecorationLastDirectionMoved = DIR_WEST; gSprites[sDecor_CameraSpriteObjectIdx1].data[2] = -2; @@ -1858,7 +1857,7 @@ static void Task_SelectLocation(u8 taskId) tCursorX--; } - if ((JOY_HELD(DPAD_ANY)) == DPAD_RIGHT) + if ((gMain.heldKeys & DPAD_ANY) == DPAD_RIGHT) { sDecorationLastDirectionMoved = DIR_EAST; gSprites[sDecor_CameraSpriteObjectIdx1].data[2] = 2; @@ -1878,10 +1877,10 @@ static void Task_SelectLocation(u8 taskId) if (!tButton) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) tButton = A_BUTTON; - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) tButton = B_BUTTON; } } @@ -1896,7 +1895,7 @@ static void ContinueDecorating(u8 taskId) static void CantPlaceDecorationPrompt(u8 taskId) { - if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON)) + if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) ContinueDecorating(taskId); } @@ -1929,7 +1928,7 @@ static void CopyTile(u8 *dest, u16 tile) case BG_TILE_H_FLIP(0) >> 10: for (i = 0; i < 8; i++) { - dest[4 * i + 0] = (buffer[4 * (i + 1) - 1] >> 4) + ((buffer[4 * (i + 1) - 1] & 0x0F) << 4); + dest[4 * i] = (buffer[4 * (i + 1) - 1] >> 4) + ((buffer[4 * (i + 1) - 1] & 0x0F) << 4); dest[4 * i + 1] = (buffer[4 * (i + 1) - 2] >> 4) + ((buffer[4 * (i + 1) - 2] & 0x0F) << 4); dest[4 * i + 2] = (buffer[4 * (i + 1) - 3] >> 4) + ((buffer[4 * (i + 1) - 3] & 0x0F) << 4); dest[4 * i + 3] = (buffer[4 * (i + 1) - 4] >> 4) + ((buffer[4 * (i + 1) - 4] & 0x0F) << 4); @@ -1938,7 +1937,7 @@ static void CopyTile(u8 *dest, u16 tile) case BG_TILE_V_FLIP(0) >> 10: for (i = 0; i < 8; i++) { - dest[4 * i + 0] = buffer[4 * (7 - i) + 0]; + dest[4 * i] = buffer[4 * (7 - i)]; dest[4 * i + 1] = buffer[4 * (7 - i) + 1]; dest[4 * i + 2] = buffer[4 * (7 - i) + 2]; dest[4 * i + 3] = buffer[4 * (7 - i) + 3]; @@ -2387,7 +2386,7 @@ static void AttemptPutAwayDecoration_(u8 taskId) static void ContinuePuttingAwayDecorationsPrompt(u8 taskId) { - if (JOY_NEW(A_BUTTON) || JOY_NEW(B_BUTTON)) + if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) ContinuePuttingAwayDecorations(taskId); } diff --git a/src/dewford_trend.c b/src/dewford_trend.c index e0063ec1b..e3b98859c 100644 --- a/src/dewford_trend.c +++ b/src/dewford_trend.c @@ -219,22 +219,18 @@ void BufferTrendyPhraseString(void) ConvertEasyChatWordsToString(gStringVar1, s->words, 2, 1); } - void TrendyPhraseIsOld(void) { - u8 result = 0; + u16 result = 0; - do + if (gSaveBlock1Ptr->easyChatPairs[0].unk0_0 - gSaveBlock1Ptr->easyChatPairs[1].unk0_0 < 2) { - if (gSaveBlock1Ptr->easyChatPairs[0].unk0_0 - gSaveBlock1Ptr->easyChatPairs[1].unk0_0 > 1) - break; - if (gSaveBlock1Ptr->easyChatPairs[0].unk1_6) - break; - if (!gSaveBlock1Ptr->easyChatPairs[1].unk1_6) - break; - result = 1; - } while (0); - + #ifndef NONMATCHING + asm("":::"r2"); //Force the compiler to store address of gSaveBlock1 in r3 instead of r2 + #endif + if (!gSaveBlock1Ptr->easyChatPairs[0].unk1_6 && gSaveBlock1Ptr->easyChatPairs[1].unk1_6) + result = 1; + } gSpecialVar_Result = result; } @@ -249,46 +245,46 @@ static bool8 sub_8122A58(struct EasyChatPair *a, struct EasyChatPair *b, u8 c) { case 0: if (a->unk0_0 > b->unk0_0) - return TRUE; + return 1; if (a->unk0_0 < b->unk0_0) - return FALSE; + return 0; if (a->unk0_7 > b->unk0_7) - return TRUE; + return 1; if (a->unk0_7 < b->unk0_7) - return FALSE; + return 0; break; case 1: if (a->unk0_7 > b->unk0_7) - return TRUE; + return 1; if (a->unk0_7 < b->unk0_7) - return FALSE; + return 0; if (a->unk0_0 > b->unk0_0) - return TRUE; + return 1; if (a->unk0_0 < b->unk0_0) - return FALSE; + return 0; break; case 2: if (a->unk0_0 > b->unk0_0) - return TRUE; + return 1; if (a->unk0_0 < b->unk0_0) - return FALSE; + return 0; if (a->unk0_7 > b->unk0_7) - return TRUE; + return 1; if (a->unk0_7 < b->unk0_7) - return FALSE; + return 0; if (a->unk2 > b->unk2) - return TRUE; + return 1; if (a->unk2 < b->unk2) - return FALSE; + return 0; if (a->words[0] > b->words[0]) - return TRUE; + return 1; if (a->words[0] < b->words[0]) - return FALSE; + return 0; if (a->words[1] > b->words[1]) - return TRUE; + return 1; if (a->words[1] < b->words[1]) - return FALSE; - return TRUE; + return 0; + return 1; } return Random() & 1; } diff --git a/src/digit_obj_util.c b/src/digit_obj_util.c index f887dafb9..fe5d49e69 100644 --- a/src/digit_obj_util.c +++ b/src/digit_obj_util.c @@ -33,7 +33,7 @@ struct DigitPrinterAlloc }; // this file's functions -static u8 GetFirstOamId(u8 oamCount); +static u8 GetFirstOamId(u8 oamCount);; static void CopyWorkToOam(struct DigitPrinter *objWork); static void DrawNumObjsLeadingZeros(struct DigitPrinter *objWork, s32 num, bool32 sign); static void DrawNumObjsMinusInFront(struct DigitPrinter *objWork, s32 num, bool32 sign); diff --git a/src/diploma.c b/src/diploma.c index f243d09f9..7eb3b0e81 100644 --- a/src/diploma.c +++ b/src/diploma.c @@ -107,7 +107,7 @@ static void Task_DiplomaFadeIn(u8 taskId) static void Task_DiplomaWaitForKeyPress(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); gTasks[taskId].func = Task_DiplomaFadeOut; diff --git a/src/dodrio_berry_picking.c b/src/dodrio_berry_picking.c index 9cbc73c73..34f73126b 100644 --- a/src/dodrio_berry_picking.c +++ b/src/dodrio_berry_picking.c @@ -2355,19 +2355,19 @@ static void sub_8027554(void) { if (gUnknown_02022C98->unkB0[gUnknown_02022C98->multiplayerId] == 0) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { gUnknown_02022C98->unk31A0[gUnknown_02022C98->multiplayerId].unk2C.unk0 = 2; gUnknown_02022C98->unkB0[gUnknown_02022C98->multiplayerId] = 6; PlaySE(SE_M_CHARM); } - else if (JOY_NEW(DPAD_LEFT)) + else if (gMain.newKeys & DPAD_LEFT) { gUnknown_02022C98->unk31A0[gUnknown_02022C98->multiplayerId].unk2C.unk0 = 3; gUnknown_02022C98->unkB0[gUnknown_02022C98->multiplayerId] = 6; PlaySE(SE_M_CHARM); } - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { gUnknown_02022C98->unk31A0[gUnknown_02022C98->multiplayerId].unk2C.unk0 = 1; gUnknown_02022C98->unkB0[gUnknown_02022C98->multiplayerId] = 6; @@ -2653,7 +2653,7 @@ static void Task_ShowDodrioBerryPickingRecords(u8 taskId) data[0]++; break; case 2: - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { rbox_fill_rectangle(data[1]); CopyWindowToVram(data[1], 1); @@ -4266,7 +4266,7 @@ static void sub_802988C(void) gUnknown_02022CF8->state++; break; case 4: - if (++gUnknown_02022CF8->unk301C >= 30 && JOY_NEW(A_BUTTON)) + if (++gUnknown_02022CF8->unk301C >= 30 && gMain.newKeys & A_BUTTON) { gUnknown_02022CF8->unk301C = 0; PlaySE(SE_SELECT); @@ -4298,7 +4298,7 @@ static void sub_802988C(void) gUnknown_02022CF8->state++; break; case 8: - if (++gUnknown_02022CF8->unk301C >= 30 && JOY_NEW(A_BUTTON)) + if (++gUnknown_02022CF8->unk301C >= 30 && gMain.newKeys & A_BUTTON) { gUnknown_02022CF8->unk301C = 0; PlaySE(SE_SELECT); @@ -4358,7 +4358,7 @@ static void sub_802988C(void) gUnknown_02022CF8->state++; break; case 11: - if (++gUnknown_02022CF8->unk301C >= 30 && JOY_NEW(A_BUTTON)) + if (++gUnknown_02022CF8->unk301C >= 30 && gMain.newKeys & A_BUTTON) { gUnknown_02022CF8->unk301C = 0; PlaySE(SE_SELECT); @@ -4424,14 +4424,14 @@ static void sub_802A010(void) AddTextPrinterParameterized(gUnknown_02022CF8->unk3008[1], 1, gText_SelectorArrow2, 0, ((y - 1) * 16) + 1, -1, NULL); CopyWindowToVram(gUnknown_02022CF8->unk3008[1], 3); // Increment state only if A or B button have been pressed. - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (gUnknown_02022CF8->unk3020 == 0) gUnknown_02022CF8->unk3020 = 1; gUnknown_02022CF8->state++; } - else if (JOY_NEW(DPAD_UP | DPAD_DOWN)) + else if (gMain.newKeys & (DPAD_UP | DPAD_DOWN)) { PlaySE(SE_SELECT); switch (gUnknown_02022CF8->unk3020) @@ -4447,7 +4447,7 @@ static void sub_802A010(void) break; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); gUnknown_02022CF8->unk3020 = 2; diff --git a/src/easy_chat.c b/src/easy_chat.c index e08f0bb75..534215ecd 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -1523,7 +1523,7 @@ static u16 sub_811AB68(void) { do { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { sub_811BF78(); sEasyChatScreen->state = 2; @@ -1532,30 +1532,30 @@ static u16 sub_811AB68(void) sEasyChatScreen->unk_0c = 0; return 9; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return sub_811B150(); } - else if (JOY_NEW(START_BUTTON)) + else if (gMain.newKeys & START_BUTTON) { return sub_811B1B4(); } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { sEasyChatScreen->mainCursorRow--; break; } - else if (JOY_NEW(DPAD_LEFT)) + else if (gMain.newKeys & DPAD_LEFT) { sEasyChatScreen->mainCursorColumn--; break; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { sEasyChatScreen->mainCursorRow++; break; } - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { sEasyChatScreen->mainCursorColumn++; break; @@ -1595,7 +1595,7 @@ static u16 sub_811ACDC(void) { do { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (sEasyChatScreen->mainCursorColumn) { @@ -1610,30 +1610,30 @@ static u16 sub_811ACDC(void) } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { return sub_811B150(); } - if (JOY_NEW(START_BUTTON)) + else if (gMain.newKeys & START_BUTTON) { return sub_811B1B4(); } - if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { sEasyChatScreen->mainCursorRow--; break; } - if (JOY_NEW(DPAD_LEFT)) + else if (gMain.newKeys & DPAD_LEFT) { sEasyChatScreen->mainCursorColumn--; break; } - if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { sEasyChatScreen->mainCursorRow = 0; break; } - if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { sEasyChatScreen->mainCursorColumn++; break; @@ -1666,10 +1666,10 @@ static u16 sub_811ACDC(void) static u16 sub_811AE44(void) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) return sub_811B32C(); - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (sEasyChatScreen->unk_0a != -1) return sub_811B2B0(); @@ -1685,19 +1685,19 @@ static u16 sub_811AE44(void) } } - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) return sub_811B33C(); - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) return sub_811B528(2); - if (JOY_REPEAT(DPAD_DOWN)) + if (gMain.newAndRepeatedKeys & DPAD_DOWN) return sub_811B528(3); - if (JOY_REPEAT(DPAD_LEFT)) + if (gMain.newAndRepeatedKeys & DPAD_LEFT) return sub_811B528(1); - if (JOY_REPEAT(DPAD_RIGHT)) + if (gMain.newAndRepeatedKeys & DPAD_RIGHT) return sub_811B528(0); return 0; @@ -1705,31 +1705,31 @@ static u16 sub_811AE44(void) static u16 sub_811AF00(void) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { sEasyChatScreen->state = 2; return 14; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) return sub_811B394(); - if (JOY_NEW(START_BUTTON)) + if (gMain.newKeys & START_BUTTON) return sub_811B794(4); - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) return sub_811B794(5); - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) return sub_811B794(2); - if (JOY_REPEAT(DPAD_DOWN)) + if (gMain.newAndRepeatedKeys & DPAD_DOWN) return sub_811B794(3); - if (JOY_REPEAT(DPAD_LEFT)) + if (gMain.newAndRepeatedKeys & DPAD_LEFT) return sub_811B794(1); - if (JOY_REPEAT(DPAD_RIGHT)) + if (gMain.newAndRepeatedKeys & DPAD_RIGHT) return sub_811B794(0); return 0; @@ -1794,10 +1794,10 @@ static u16 sub_811B040(void) static u16 sub_811B08C(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) return 26; - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) return sub_811B150(); return 0; @@ -1805,7 +1805,7 @@ static u16 sub_811B08C(void) static u16 sub_811B0BC(void) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { sEasyChatScreen->state = sub_811B2A4(); return 7; @@ -2537,7 +2537,7 @@ u8 sub_811BBBC(void) return sEasyChatScreen->unk_0c; } -static void sub_811BBC8(s8 *arg0, s8 *arg1) +void sub_811BBC8(u8 *arg0, u8 *arg1) { *arg0 = sEasyChatScreen->unk_10; *arg1 = sEasyChatScreen->unk_11; @@ -4529,18 +4529,18 @@ static void sub_811E30C(void) x = var0 * 13; x = x * 8 + 28; y = var1 * 16 + 96; - sub_811E34C((u8)x, (u8)y); + sub_811E34C(x, y); } static void sub_811E34C(u8 x, u8 y) { - if (!sUnknown_0203A11C->unk2E4) - return; - - sUnknown_0203A11C->unk2E4->pos1.x = (s16)x; - sUnknown_0203A11C->unk2E4->pos1.y = (s16)y; - sUnknown_0203A11C->unk2E4->pos2.x = 0; - sUnknown_0203A11C->unk2E4->data[0] = 0; + if (sUnknown_0203A11C->unk2E4) + { + sUnknown_0203A11C->unk2E4->pos1.x = x; + sUnknown_0203A11C->unk2E4->pos1.y = y; + sUnknown_0203A11C->unk2E4->pos2.x = 0; + sUnknown_0203A11C->unk2E4->data[0] = 0; + } } static void sub_811E380(void) diff --git a/src/ereader_screen.c b/src/ereader_screen.c index 3f2cf3217..b4a9164b3 100755 --- a/src/ereader_screen.c +++ b/src/ereader_screen.c @@ -137,7 +137,7 @@ static u32 sub_81D4EE4(u8 *arg0, u16 *arg1) { *arg0 = 1; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { *arg0 = 0; return 1; @@ -158,7 +158,7 @@ static u32 sub_81D4EE4(u8 *arg0, u16 *arg1) *arg1 = 0; *arg0 = 3; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { *arg0 = 0; return 1; @@ -288,7 +288,7 @@ static void sub_81D5084(u8 taskId) OpenEReaderLink(); data->unk8 = 6; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { sub_81D505C(&data->unk0); PlaySE(SE_SELECT); @@ -296,7 +296,7 @@ static void sub_81D5084(u8 taskId) } break; case 6: - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); CloseLink(); @@ -436,7 +436,7 @@ static void sub_81D5084(u8 taskId) } break; case 19: - if (IsFanfareTaskInactive() && (JOY_NEW(A_BUTTON | B_BUTTON))) + if (IsFanfareTaskInactive() && (gMain.newKeys & (A_BUTTON | B_BUTTON))) data->unk8 = 26; break; case 23: diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 68f873446..29a9f6d0a 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1223,6 +1223,7 @@ static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template, objectEvent->movementType = template->movementType; objectEvent->localId = template->localId; objectEvent->mapNum = mapNum; + objectEvent++; objectEvent--; objectEvent->mapGroup = mapGroup; objectEvent->initialCoords.x = x; objectEvent->initialCoords.y = y; @@ -1235,11 +1236,13 @@ static u8 InitObjectEventStateFromTemplate(struct ObjectEventTemplate *template, objectEvent->range.as_nybbles.x = template->movementRangeX; objectEvent->range.as_nybbles.y = template->movementRangeY; objectEvent->trainerType = template->trainerType; - objectEvent->mapNum = mapNum; //redundant, but needed to match objectEvent->trainerRange_berryTreeId = template->trainerRange_berryTreeId; objectEvent->previousMovementDirection = gInitialMovementTypeFacingDirections[template->movementType]; SetObjectEventDirection(objectEvent, objectEvent->previousMovementDirection); SetObjectEventDynamicGraphicsId(objectEvent); +#ifndef NONMATCHING + asm("":::"r5", "r6"); +#endif if (gRangedMovementTypes[objectEvent->movementType]) { if (objectEvent->range.as_nybbles.x == 0) @@ -8216,13 +8219,15 @@ bool8 FreezeObjectEvent(struct ObjectEvent *objectEvent) { return TRUE; } - - objectEvent->frozen = 1; - objectEvent->spriteAnimPausedBackup = gSprites[objectEvent->spriteId].animPaused; - objectEvent->spriteAffineAnimPausedBackup = gSprites[objectEvent->spriteId].affineAnimPaused; - gSprites[objectEvent->spriteId].animPaused = 1; - gSprites[objectEvent->spriteId].affineAnimPaused = 1; - return FALSE; + else + { + objectEvent->frozen = 1; + objectEvent->spriteAnimPausedBackup = gSprites[objectEvent->spriteId].animPaused; + objectEvent->spriteAffineAnimPausedBackup = gSprites[objectEvent->spriteId].affineAnimPaused; + gSprites[objectEvent->spriteId].animPaused = 1; + gSprites[objectEvent->spriteId].affineAnimPaused = 1; + return FALSE; + } } void FreezeObjectEvents(void) @@ -8395,8 +8400,8 @@ bool8 sub_80976EC(struct Sprite *sprite) if (sprite->data[5] > 15) return TRUE; - - return FALSE; + else + return FALSE; } static const s8 sFigure8XOffsets[FIGURE_8_LENGTH] = { @@ -8476,15 +8481,15 @@ static bool8 AnimateSpriteInFigure8(struct Sprite *sprite) return finished; } -static const s8 gUnknown_0850E802[16] = { +static const s8 gUnknown_0850E802[] = { -4, -6, -8, -10, -11, -12, -12, -12, -11, -10, -9, -8, -6, -4, 0, 0 }; -static const s8 gUnknown_0850E812[16] = { +static const s8 gUnknown_0850E812[] = { 0, -2, -3, -4, -5, -6, -6, -6, -5, -5, -4, -3, -2, 0, 0, 0 }; -static const s8 gUnknown_0850E822[16] = { +static const s8 gUnknown_0850E822[] = { -2, -4, -6, -8, -9, -10, -10, -10, -9, -8, -6, -5, -3, -2, 0, 0 }; @@ -8507,11 +8512,23 @@ void sub_809783C(struct Sprite *sprite, u8 a2, u8 a3, u8 a4) sprite->data[6] = 0; } +static const s16 gUnknown_0850E840[] = { + 16, 16, 32, +}; + +static const u8 gUnknown_0850E846[] = { + 0, 0, 1, +}; + u8 sub_809785C(struct Sprite *sprite) { - s16 v5[] = {16, 16, 32}; - u8 v6[] = {0, 0, 1}; - u8 v2 = 0; + s16 v5[3]; + u8 v6[3]; + u8 v2; + + memcpy(v5, gUnknown_0850E840, 6); // TODO: get rid of memcpy + memcpy(v6, gUnknown_0850E846, 3); + v2 = 0; if (sprite->data[4]) Step1(sprite, sprite->data[3]); @@ -8532,11 +8549,23 @@ u8 sub_809785C(struct Sprite *sprite) return v2; } +static const s16 gUnknown_0850E84A[] = { + 32, 32, 64, +}; + +static const u8 gUnknown_0850E850[] = { + 1, 1, 2, +}; + u8 sub_80978E4(struct Sprite *sprite) { - s16 v5[] = {32, 32, 64}; - u8 v6[] = {1, 1, 2}; - u8 v2 = 0; + s16 v5[3]; + u8 v6[3]; + u8 v2; + + memcpy(v5, gUnknown_0850E84A, 6); + memcpy(v6, gUnknown_0850E850, 3); + v2 = 0; if (sprite->data[4] && !(sprite->data[6] & 1)) Step1(sprite, sprite->data[3]); @@ -8564,9 +8593,12 @@ static void SetMovementDelay(struct Sprite *sprite, s16 timer) static bool8 WaitForMovementDelay(struct Sprite *sprite) { - if (--sprite->data[3] == 0) + sprite->data[3]--; + + if (sprite->data[3] == 0) return TRUE; - return FALSE; + else + return FALSE; } void SetAndStartSpriteAnim(struct Sprite *sprite, u8 animNum, u8 animCmdIndex) @@ -8580,7 +8612,8 @@ bool8 SpriteAnimEnded(struct Sprite *sprite) { if (sprite->animEnded) return TRUE; - return FALSE; + else + return FALSE; } void UpdateObjectEventSpriteVisibility(struct Sprite *sprite, bool8 invisible) @@ -8759,14 +8792,14 @@ static void UpdateObjectEventSpritePosition(struct Sprite *sprite) { switch(sprite->tAnimNum) { - case 0: - break; case UNION_ROOM_SPAWN_IN: MoveUnionRoomObjectDown(sprite); break; case UNION_ROOM_SPAWN_OUT: MoveUnionRoomObjectUp(sprite); break; + case 0: + break; default: sprite->tAnimNum = 0; break; @@ -8835,18 +8868,21 @@ u8 (*const gMovementActionFuncs_FlyDown[])(struct ObjectEvent *, struct Sprite * u8 MovementAction_StoreAndLockAnim_Step0(struct ObjectEvent *objectEvent, struct Sprite *sprite) { - bool8 ableToStore = FALSE; + u32 one; + bool32 ableToStore = FALSE; if (gLockedAnimObjectEvents == NULL) { gLockedAnimObjectEvents = AllocZeroed(sizeof(struct LockedAnimObjectEvents)); gLockedAnimObjectEvents->objectEventIds[0] = objectEvent->localId; - gLockedAnimObjectEvents->count = 1; - ableToStore = TRUE; + // needed to match + gLockedAnimObjectEvents->count = (one = 1); + ableToStore = one; } else { - u8 i, firstFreeSlot; - bool8 found; + u8 i; + u8 firstFreeSlot; + bool32 found; for (firstFreeSlot = 16, found = FALSE, i = 0; i < 16; i++) { if (firstFreeSlot == 16 && gLockedAnimObjectEvents->objectEventIds[i] == 0) @@ -8879,7 +8915,7 @@ u8 MovementAction_StoreAndLockAnim_Step0(struct ObjectEvent *objectEvent, struct u8 MovementAction_FreeAndUnlockAnim_Step0(struct ObjectEvent *objectEvent, struct Sprite *sprite) { - bool8 ableToStore; + bool32 ableToStore; u8 index; sprite->data[2] = 1; @@ -8923,7 +8959,7 @@ void CreateLevitateMovementTask(struct ObjectEvent *objectEvent) u8 taskId = CreateTask(ApplyLevitateMovement, 0xFF); struct Task *task = &gTasks[taskId]; - StoreWordInTwoHalfwords((u16 *)&task->data[0], (u32)objectEvent); + StoreWordInTwoHalfwords(&task->data[0], (u32)objectEvent); objectEvent->warpArrowSpriteId = taskId; task->data[3] = 0xFFFF; } @@ -8934,7 +8970,7 @@ static void ApplyLevitateMovement(u8 taskId) struct Sprite *sprite; struct Task *task = &gTasks[taskId]; - LoadWordFromTwoHalfwords((u16 *)&task->data[0], (u32 *)&objectEvent); // load the map object pointer. + LoadWordFromTwoHalfwords(&task->data[0], (u32 *)&objectEvent); // load the map object pointer. sprite = &gSprites[objectEvent->spriteId]; if(!(task->data[2] & 0x3)) @@ -8951,7 +8987,7 @@ void DestroyExtraMovementTask(u8 taskId) struct ObjectEvent *objectEvent; struct Task *task = &gTasks[taskId]; - LoadWordFromTwoHalfwords((u16 *)&task->data[0], (u32 *)&objectEvent); // unused objectEvent + LoadWordFromTwoHalfwords(&task->data[0], (u32 *)&objectEvent); // unused objectEvent DestroyTask(taskId); } diff --git a/src/evolution_scene.c b/src/evolution_scene.c index 61065367c..41d4900f7 100644 --- a/src/evolution_scene.c +++ b/src/evolution_scene.c @@ -859,21 +859,21 @@ static void Task_EvolutionScene(u8 taskID) } break; case 4: - if (JOY_NEW(DPAD_UP) && sEvoCursorPos != 0) + if (gMain.newKeys & DPAD_UP && sEvoCursorPos != 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(sEvoCursorPos); sEvoCursorPos = 0; BattleCreateYesNoCursorAt(0); } - if (JOY_NEW(DPAD_DOWN) && sEvoCursorPos == 0) + if (gMain.newKeys & DPAD_DOWN && sEvoCursorPos == 0) { PlaySE(SE_SELECT); BattleDestroyYesNoCursorAt(sEvoCursorPos); sEvoCursorPos = 1; BattleCreateYesNoCursorAt(1); } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); PlaySE(SE_SELECT); @@ -889,7 +889,7 @@ static void Task_EvolutionScene(u8 taskID) BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { HandleBattleWindow(0x18, 8, 0x1D, 0xD, WINDOW_CLEAR); PlaySE(SE_SELECT); diff --git a/src/faraway_island.c b/src/faraway_island.c index 6bfa066c2..e3d8444c9 100755 --- a/src/faraway_island.c +++ b/src/faraway_island.c @@ -181,36 +181,40 @@ u32 GetMewMoveDirection(void) { if (ShouldMewMoveEast(mew, 1)) return GetRandomMewDirectionCandidate(2); - if (ShouldMewMoveWest(mew, 1)) + else if (ShouldMewMoveWest(mew, 1)) return GetRandomMewDirectionCandidate(2); - return DIR_NORTH; + else + return DIR_NORTH; } if (ShouldMewMoveSouth(mew, 0)) { if (ShouldMewMoveEast(mew, 1)) return GetRandomMewDirectionCandidate(2); - if (ShouldMewMoveWest(mew, 1)) + else if (ShouldMewMoveWest(mew, 1)) return GetRandomMewDirectionCandidate(2); - return DIR_SOUTH; + else + return DIR_SOUTH; } if (ShouldMewMoveEast(mew, 0)) { if (ShouldMewMoveNorth(mew, 1)) return GetRandomMewDirectionCandidate(2); - if (ShouldMewMoveSouth(mew, 1)) + else if (ShouldMewMoveSouth(mew, 1)) return GetRandomMewDirectionCandidate(2); - return DIR_EAST; + else + return DIR_EAST; } if (ShouldMewMoveWest(mew, 0)) { if (ShouldMewMoveNorth(mew, 1)) return GetRandomMewDirectionCandidate(2); - if (ShouldMewMoveSouth(mew, 1)) + else if (ShouldMewMoveSouth(mew, 1)) return GetRandomMewDirectionCandidate(2); - return DIR_WEST; + else + return DIR_WEST; } // If this point is reached, Mew cannot move without getting closer to the player @@ -311,7 +315,8 @@ static u8 GetValidMewMoveDirection(u8 ignoredDir) if (count > 1) return sMewDirectionCandidates[VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % count]; - return sMewDirectionCandidates[0]; + else + return sMewDirectionCandidates[0]; } void UpdateFarawayIslandStepCounter(void) diff --git a/src/field_effect.c b/src/field_effect.c index b64902c0e..41f1a899c 100644 --- a/src/field_effect.c +++ b/src/field_effect.c @@ -2597,7 +2597,7 @@ static void FieldMoveShowMonOutdoorsEffect_Init(struct Task *task) { task->data[11] = REG_WININ; task->data[12] = REG_WINOUT; - StoreWordInTwoHalfwords((u16 *)&task->data[13], (u32)gMain.vblankCallback); + StoreWordInTwoHalfwords(&task->data[13], (u32)gMain.vblankCallback); task->tWinHoriz = WIN_RANGE(DISPLAY_WIDTH, DISPLAY_WIDTH + 1); task->tWinVert = WIN_RANGE(DISPLAY_HEIGHT / 2, DISPLAY_HEIGHT / 2 + 1); task->tWinIn = WININ_WIN0_BG_ALL | WININ_WIN0_OBJ | WININ_WIN0_CLR; diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index e907af5b9..3d916e9d0 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -101,9 +101,9 @@ static void sub_808C280(struct ObjectEvent *); static void StartStrengthAnim(u8, u8); static void Task_PushBoulder(u8 taskId); -static bool8 PushBoulder_Start(struct Task *task, struct ObjectEvent *playerObject, struct ObjectEvent *strengthObject); -static bool8 PushBoulder_Move(struct Task *task, struct ObjectEvent *playerObject, struct ObjectEvent *strengthObject); -static bool8 PushBoulder_End(struct Task *task, struct ObjectEvent *playerObject, struct ObjectEvent *strengthObject); +static u8 PushBoulder_Start(struct Task *task, struct ObjectEvent *playerObject, struct ObjectEvent *strengthObject); +static u8 PushBoulder_Move(struct Task *task, struct ObjectEvent *playerObject, struct ObjectEvent *strengthObject); +static u8 PushBoulder_End(struct Task *task, struct ObjectEvent *playerObject, struct ObjectEvent *strengthObject); static void DoPlayerMatJump(void); static void DoPlayerAvatarSecretBaseMatJump(u8 taskId); @@ -1789,7 +1789,7 @@ static bool8 Fishing_ShowDots(struct Task *task) AlignFishingAnimationFrames(); task->tFrameCounter++; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { task->tStep = FISHING_NO_BITE; if (task->tRoundsPlayed != 0) @@ -1878,7 +1878,7 @@ static bool8 Fishing_WaitForA(struct Task *task) task->tFrameCounter++; if (task->tFrameCounter >= reelTimeouts[task->tFishingRod]) task->tStep = FISHING_GOT_AWAY; - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) task->tStep++; return FALSE; } diff --git a/src/field_special_scene.c b/src/field_special_scene.c index 6b41c5423..bd6c833af 100644 --- a/src/field_special_scene.c +++ b/src/field_special_scene.c @@ -280,7 +280,7 @@ void Task_HandlePorthole(u8 taskId) } break; case IDLE_CHECK: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) data[1] = 1; if (!ScriptMovement_IsObjectMovementFinished(OBJ_EVENT_ID_PLAYER, location->mapNum, location->mapGroup)) return; diff --git a/src/fldeff_cut.c b/src/fldeff_cut.c index 991617713..785f7b426 100644 --- a/src/fldeff_cut.c +++ b/src/fldeff_cut.c @@ -227,7 +227,9 @@ bool8 SetUpFieldMove_Cut(void) y = gPlayerFacingPosition.y + sHyperCutStruct[i].y; tileCuttable = TRUE; - for (j = 0; j < 2; ++j) { + j = 0; + do + { if (sHyperCutStruct[i].unk2[j] == 0) break; if (cutTiles[(u8)(sHyperCutStruct[i].unk2[j] - 1)] == FALSE) @@ -235,7 +237,7 @@ bool8 SetUpFieldMove_Cut(void) tileCuttable = FALSE; break; } - } + } while (++j <= 1); if (tileCuttable == TRUE) { @@ -251,8 +253,11 @@ bool8 SetUpFieldMove_Cut(void) sHyperCutTiles[tileArrayId] = TRUE; ret = TRUE; } - else if (MetatileBehavior_IsCuttableGrass(tileBehavior) == TRUE) - sHyperCutTiles[tileArrayId] = TRUE; + else + { + if (MetatileBehavior_IsCuttableGrass(tileBehavior) == TRUE) + sHyperCutTiles[tileArrayId] = TRUE; + } } } } diff --git a/src/frontier_pass.c b/src/frontier_pass.c index ac81c51e0..702f6c098 100644 --- a/src/frontier_pass.c +++ b/src/frontier_pass.c @@ -937,14 +937,14 @@ static void Task_HandleFrontierPassInput(u8 taskId) { u8 var = FALSE; // Reused, first informs whether the cursor moves, then used as the new cursor area. - if (JOY_HELD(DPAD_UP) && sPassGfx->cursorSprite->pos1.y >= 9) + if (gMain.heldKeys & DPAD_UP && sPassGfx->cursorSprite->pos1.y >= 9) { sPassGfx->cursorSprite->pos1.y -= 2; if (sPassGfx->cursorSprite->pos1.y <= 7) sPassGfx->cursorSprite->pos1.y = 2; var = TRUE; } - if (JOY_HELD(DPAD_DOWN) && sPassGfx->cursorSprite->pos1.y <= 135) + if (gMain.heldKeys & DPAD_DOWN && sPassGfx->cursorSprite->pos1.y <= 135) { sPassGfx->cursorSprite->pos1.y += 2; if (sPassGfx->cursorSprite->pos1.y >= 137) @@ -952,14 +952,14 @@ static void Task_HandleFrontierPassInput(u8 taskId) var = TRUE; } - if (JOY_HELD(DPAD_LEFT) && sPassGfx->cursorSprite->pos1.x >= 6) + if (gMain.heldKeys & DPAD_LEFT && sPassGfx->cursorSprite->pos1.x >= 6) { sPassGfx->cursorSprite->pos1.x -= 2; if (sPassGfx->cursorSprite->pos1.x <= 4) sPassGfx->cursorSprite->pos1.x = 5; var = TRUE; } - if (JOY_HELD(DPAD_RIGHT) && sPassGfx->cursorSprite->pos1.x <= 231) + if (gMain.heldKeys & DPAD_RIGHT && sPassGfx->cursorSprite->pos1.x <= 231) { sPassGfx->cursorSprite->pos1.x += 2; if (sPassGfx->cursorSprite->pos1.x >= 233) @@ -969,7 +969,7 @@ static void Task_HandleFrontierPassInput(u8 taskId) if (!var) // Cursor did not change. { - if (sPassData->cursorArea != CURSOR_AREA_NOTHING && JOY_NEW(A_BUTTON)) + if (sPassData->cursorArea != CURSOR_AREA_NOTHING && gMain.newKeys & A_BUTTON) { if (sPassData->cursorArea <= CURSOR_AREA_RECORD) // Map, Card, Record { @@ -986,7 +986,7 @@ static void Task_HandleFrontierPassInput(u8 taskId) } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_PC_OFF); SetMainCallback2(CB2_HideFrontierPass); @@ -1173,47 +1173,75 @@ static void sub_80C5F58(bool8 arg0, bool8 arg1) static void sub_80C6104(u8 cursorArea, u8 previousCursorArea) { + bool32 var; + switch (previousCursorArea) { case CURSOR_AREA_MAP: CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk24, 16, 3, 12, 7, 17); + var = TRUE; break; case CURSOR_AREA_CARD: CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk24 + 336, 16, 10, 12, 7, 17); + var = TRUE; break; case CURSOR_AREA_RECORD: - if (sPassData->hasBattleRecord) + if (!sPassData->hasBattleRecord) + { + var = FALSE; + } + else + { CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk28, 2, 10, 12, 3, 17); - else if (cursorArea == CURSOR_AREA_NOTHING || cursorArea > CURSOR_AREA_CANCEL) - return; + var = TRUE; + } break; case CURSOR_AREA_CANCEL: CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_08DE3350, 21, 0, 9, 2, 17); + var = TRUE; break; default: + var = FALSE; + break; + } + + if (!var) + { if (cursorArea == CURSOR_AREA_NOTHING || cursorArea > CURSOR_AREA_CANCEL) return; - break; } switch (cursorArea) { case CURSOR_AREA_MAP: CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk24 + 168, 16, 3, 12, 7, 17); + var = TRUE; break; case CURSOR_AREA_CARD: CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk24 + 504, 16, 10, 12, 7, 17); + var = TRUE; break; case CURSOR_AREA_RECORD: - if (sPassData->hasBattleRecord) - CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk28 + 72, 2, 10, 12, 3, 17); - else + if (!sPassData->hasBattleRecord) return; - break; // needed + + CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk28 + 72, 2, 10, 12, 3, 17); + var = TRUE; + break; case CURSOR_AREA_CANCEL: CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_08DE3374, 21, 0, 9, 2, 17); + var = TRUE; break; default: + var = FALSE; + break; + } + + if (!var) + { + #ifndef NONMATCHING + asm("":::"r4"); + #endif if (previousCursorArea == CURSOR_AREA_NOTHING || previousCursorArea > CURSOR_AREA_CANCEL) return; } @@ -1443,19 +1471,19 @@ static void Task_HandleFrontierMap(u8 taskId) break; return; case 1: - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_PC_OFF); data[0] = 4; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (sMapData->cursorPos >= NUM_FRONTIER_FACILITIES - 1) HandleFrontierMapCursorMove(0); else data[0] = 2; } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (sMapData->cursorPos == 0) HandleFrontierMapCursorMove(1); diff --git a/src/frontier_util.c b/src/frontier_util.c index a36e2ec9f..3e7fecb48 100644 --- a/src/frontier_util.c +++ b/src/frontier_util.c @@ -2486,6 +2486,7 @@ void SetFrontierBrainObjEventGfx_2(void) #define FRONTIER_BRAIN_OTID 61226 +#ifdef NONMATCHING void CreateFrontierBrainPokemon(void) { s32 i, j; @@ -2508,13 +2509,11 @@ void CreateFrontierBrainPokemon(void) { if (!(selectedMonBits & 1)) continue; + do { - do - { - j = Random32(); //Should be one while loop, but that doesn't match - } while (IsShinyOtIdPersonality(FRONTIER_BRAIN_OTID, j)); - } while (sFrontierBrainsMons[facility][symbol][i].nature != GetNatureFromPersonality(j)); + j = Random32(); + } while (IsShinyOtIdPersonality(FRONTIER_BRAIN_OTID, j) || sFrontierBrainsMons[facility][symbol][i].nature != GetNatureFromPersonality(j)); CreateMon(&gEnemyParty[monPartyId], sFrontierBrainsMons[facility][symbol][i].species, monLevel, @@ -2536,6 +2535,242 @@ void CreateFrontierBrainPokemon(void) monPartyId++; } } +#else +NAKED +void CreateFrontierBrainPokemon(void) +{ + asm_unified( + "push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0x44\n\ + ldr r0, =0x000040cf\n\ + bl VarGet\n\ + lsls r0, 16\n\ + lsrs r0, 16\n\ + str r0, [sp, 0x20]\n\ + bl GetFronterBrainSymbol\n\ + str r0, [sp, 0x24]\n\ + ldr r0, [sp, 0x20]\n\ + cmp r0, 0x1\n\ + bne _081A4E44\n\ + ldr r0, =0x000003fe\n\ + bl TrainerIdToDomeTournamentId\n\ + lsls r0, 16\n\ + lsrs r0, 16\n\ + bl GetDomeTrainerSelectedMons\n\ + adds r4, r0, 0\n\ + b _081A4E46\n\ + .pool\n\ +_081A4E44:\n\ + movs r4, 0x7\n\ +_081A4E46:\n\ + bl ZeroEnemyPartyMons\n\ + movs r1, 0\n\ + str r1, [sp, 0x18]\n\ + bl SetFacilityPtrsGetLevel\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + str r0, [sp, 0x1C]\n\ + movs r2, 0\n\ + str r2, [sp, 0x14]\n\ +_081A4E5C:\n\ + movs r0, 0x1\n\ + ands r0, r4\n\ + asrs r4, 1\n\ + str r4, [sp, 0x30]\n\ + ldr r3, [sp, 0x14]\n\ + adds r3, 0x1\n\ + str r3, [sp, 0x28]\n\ + cmp r0, 0\n\ + bne _081A4E70\n\ + b _081A4FC4\n\ +_081A4E70:\n\ + ldr r4, [sp, 0x14]\n\ + lsls r4, 2\n\ + mov r9, r4\n\ + ldr r0, [sp, 0x24]\n\ + lsls r0, 4\n\ + str r0, [sp, 0x38]\n\ + ldr r1, [sp, 0x20]\n\ + lsls r1, 4\n\ + str r1, [sp, 0x34]\n\ + ldr r2, [sp, 0x1C]\n\ + lsls r2, 24\n\ + str r2, [sp, 0x3C]\n\ + ldr r3, [sp, 0x18]\n\ + adds r3, 0x1\n\ + str r3, [sp, 0x2C]\n\ + ldr r0, [sp, 0x14]\n\ + add r0, r9\n\ + lsls r0, 2\n\ + mov r8, r0\n\ +_081A4E96:\n\ + bl Random\n\ + adds r4, r0, 0\n\ + bl Random\n\ + lsls r4, 16\n\ + lsrs r7, r4, 16\n\ + lsls r0, 16\n\ + orrs r7, r0\n\ + ldr r0, =0x0000ef2a\n\ + adds r1, r7, 0\n\ + bl IsShinyOtIdPersonality\n\ + lsls r0, 24\n\ + cmp r0, 0\n\ + bne _081A4E96\n\ + ldr r4, [sp, 0x38]\n\ + ldr r1, [sp, 0x24]\n\ + subs r0, r4, r1\n\ + lsls r5, r0, 2\n\ + mov r2, r8\n\ + adds r4, r2, r5\n\ + ldr r3, [sp, 0x34]\n\ + ldr r1, [sp, 0x20]\n\ + subs r0, r3, r1\n\ + lsls r6, r0, 3\n\ + adds r4, r6\n\ + ldr r2, =sFrontierBrainsMons\n\ + adds r4, r2\n\ + adds r0, r7, 0\n\ + bl GetNatureFromPersonality\n\ + ldrb r1, [r4, 0x5]\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + cmp r1, r0\n\ + bne _081A4E96\n\ + ldr r4, [sp, 0x18]\n\ + movs r0, 0x64\n\ + adds r3, r4, 0\n\ + muls r3, r0\n\ + mov r8, r3\n\ + ldr r1, =gEnemyParty\n\ + add r1, r8\n\ + mov r10, r1\n\ + ldr r4, [sp, 0x14]\n\ + add r4, r9\n\ + lsls r4, 2\n\ + adds r0, r4, r5\n\ + adds r0, r6\n\ + ldr r2, =sFrontierBrainsMons\n\ + adds r0, r2\n\ + ldrh r1, [r0]\n\ + ldr r3, [sp, 0x3C]\n\ + lsrs r2, r3, 24\n\ + ldrb r3, [r0, 0x4]\n\ + movs r0, 0x1\n\ + str r0, [sp]\n\ + str r7, [sp, 0x4]\n\ + str r0, [sp, 0x8]\n\ + ldr r0, =0x0000ef2a\n\ + str r0, [sp, 0xC]\n\ + mov r0, r10\n\ + bl CreateMon\n\ + ldr r0, =sFrontierBrainsMons\n\ + adds r5, r0\n\ + adds r5, r6, r5\n\ + adds r4, r5, r4\n\ + adds r4, 0x2\n\ + mov r0, r10\n\ + movs r1, 0xC\n\ + adds r2, r4, 0\n\ + bl SetMonData\n\ + movs r7, 0\n\ + mov r6, r8\n\ + ldr r3, =gEnemyParty\n\ +_081A4F32:\n\ + adds r1, r7, 0\n\ + adds r1, 0x1A\n\ + ldr r0, [sp, 0x14]\n\ + add r0, r9\n\ + lsls r4, r0, 2\n\ + adds r2, r5, r4\n\ + adds r0, r7, 0x6\n\ + adds r2, r0\n\ + adds r0, r6, r3\n\ + str r3, [sp, 0x40]\n\ + bl SetMonData\n\ + adds r7, 0x1\n\ + ldr r3, [sp, 0x40]\n\ + cmp r7, 0x5\n\ + ble _081A4F32\n\ + movs r1, 0xFF\n\ + add r0, sp, 0x10\n\ + strb r1, [r0]\n\ + movs r7, 0\n\ + ldr r1, [sp, 0x18]\n\ + movs r2, 0x64\n\ + adds r6, r1, 0\n\ + muls r6, r2\n\ + ldr r3, =sFrontierBrainsMons + 0xC\n\ + mov r8, r3\n\ + ldr r3, =gEnemyParty\n\ + adds r5, r4, 0\n\ +_081A4F6A:\n\ + ldr r4, [sp, 0x38]\n\ + ldr r0, [sp, 0x24]\n\ + subs r1, r4, r0\n\ + lsls r1, 2\n\ + adds r1, r5, r1\n\ + ldr r2, [sp, 0x34]\n\ + ldr r4, [sp, 0x20]\n\ + subs r0, r2, r4\n\ + lsls r0, 3\n\ + adds r1, r0\n\ + add r1, r8\n\ + ldrh r4, [r1]\n\ + lsls r2, r7, 24\n\ + lsrs r2, 24\n\ + adds r0, r6, r3\n\ + adds r1, r4, 0\n\ + str r3, [sp, 0x40]\n\ + bl SetMonMoveSlot\n\ + ldr r3, [sp, 0x40]\n\ + cmp r4, 0xDA\n\ + bne _081A4F9C\n\ + movs r1, 0\n\ + add r0, sp, 0x10\n\ + strb r1, [r0]\n\ +_081A4F9C:\n\ + adds r5, 0x2\n\ + adds r7, 0x1\n\ + cmp r7, 0x3\n\ + ble _081A4F6A\n\ + ldr r0, [sp, 0x18]\n\ + movs r1, 0x64\n\ + adds r4, r0, 0\n\ + muls r4, r1\n\ + ldr r0, =gEnemyParty\n\ + adds r4, r0\n\ + adds r0, r4, 0\n\ + movs r1, 0x20\n\ + add r2, sp, 0x10\n\ + bl SetMonData\n\ + adds r0, r4, 0\n\ + bl CalculateMonStats\n\ + ldr r2, [sp, 0x2C]\n\ + str r2, [sp, 0x18]\n\ +_081A4FC4:\n\ + ldr r4, [sp, 0x30]\n\ + ldr r3, [sp, 0x28]\n\ + str r3, [sp, 0x14]\n\ + cmp r3, 0x2\n\ + bgt _081A4FD0\n\ + b _081A4E5C\n\ +_081A4FD0:\n\ + add sp, 0x44\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool"); +} +#endif u16 GetFrontierBrainMonSpecies(u8 monId) { diff --git a/src/hall_of_fame.c b/src/hall_of_fame.c index a13543d6a..2b548dea2 100644 --- a/src/hall_of_fame.c +++ b/src/hall_of_fame.c @@ -730,7 +730,7 @@ static void Task_Hof_WaitAndPrintPlayerInfo(u8 taskId) static void Task_Hof_ExitOnKeyPressed(u8 taskId) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { FadeOutBGM(4); gTasks[taskId].func = Task_Hof_HandlePaletteOnExit; @@ -992,7 +992,7 @@ static void Task_HofPC_HandleInput(u8 taskId) { u16 i; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (gTasks[taskId].tCurrTeamNo != 0) // prepare another team to view { @@ -1020,7 +1020,7 @@ static void Task_HofPC_HandleInput(u8 taskId) gTasks[taskId].func = Task_HofPC_HandlePaletteOnExit; } } - else if (JOY_NEW(B_BUTTON)) // turn off hall of fame PC + else if (gMain.newKeys & B_BUTTON) // turn off hall of fame PC { if (IsCryPlayingOrClearCrySongs()) { @@ -1029,12 +1029,12 @@ static void Task_HofPC_HandleInput(u8 taskId) } gTasks[taskId].func = Task_HofPC_HandlePaletteOnExit; } - else if (JOY_NEW(DPAD_UP) && gTasks[taskId].tCurrMonId != 0) // change mon -1 + else if (gMain.newKeys & DPAD_UP && gTasks[taskId].tCurrMonId != 0) // change mon -1 { gTasks[taskId].tCurrMonId--; gTasks[taskId].func = Task_HofPC_PrintMonInfo; } - else if (JOY_NEW(DPAD_DOWN) && gTasks[taskId].tCurrMonId < gTasks[taskId].tMonNo - 1) // change mon +1 + else if (gMain.newKeys & DPAD_DOWN && gTasks[taskId].tCurrMonId < gTasks[taskId].tMonNo - 1) // change mon +1 { gTasks[taskId].tCurrMonId++; gTasks[taskId].func = Task_HofPC_PrintMonInfo; @@ -1098,7 +1098,7 @@ static void Task_HofPC_PrintDataIsCorrupted(u8 taskId) static void Task_HofPC_ExitOnButtonPress(u8 taskId) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) gTasks[taskId].func = Task_HofPC_HandlePaletteOnExit; } diff --git a/src/intro_credits_graphics.c b/src/intro_credits_graphics.c index 45cc24e5c..04e2216f6 100644 --- a/src/intro_credits_graphics.c +++ b/src/intro_credits_graphics.c @@ -824,7 +824,7 @@ void sub_817B1C8(u8 a) LZ77UnCompVram(gUnknown_085F1398, (void *)(BG_SCREEN_ADDR(6))); LoadPalette(&gUnknown_085F0CFC, 0, 96); LoadCompressedSpriteSheet(gUnknown_085F5064); - LZ77UnCompVram(gUnknown_085F16A8, (void *)(OBJ_VRAM0)); + LZ77UnCompVram(gUnknown_085F16A8, (void *)(VRAM + 0x10000)); LoadPalette(&gUnknown_085F1668, 256, 32); sub_817B76C(); break; @@ -834,7 +834,7 @@ void sub_817B1C8(u8 a) LZ77UnCompVram(gUnknown_085F1398, (void *)(BG_SCREEN_ADDR(6))); LoadPalette(&gUnknown_085F0D5C, 0, 96); LoadCompressedSpriteSheet(gUnknown_085F5064); - LZ77UnCompVram(gUnknown_085F16A8, (void *)(OBJ_VRAM0)); + LZ77UnCompVram(gUnknown_085F16A8, (void *)(VRAM + 0x10000)); LoadPalette(&gUnknown_085F1688, 256, 32); sub_817B76C(); break; diff --git a/src/item.c b/src/item.c index 290e7177c..5a77d363e 100644 --- a/src/item.c +++ b/src/item.c @@ -181,67 +181,222 @@ bool8 HasAtLeastOneBerry(void) return FALSE; } +#ifdef NONMATCHING +// Refuses to match. bool8 CheckBagHasSpace(u16 itemId, u16 count) { - u8 i, pocket; - u16 slotCapacity, ownedCount; + u8 i; if (ItemId_GetPocket(itemId) == POCKET_NONE) return FALSE; - if (InBattlePyramid() || (FlagGet(FLAG_STORING_ITEMS_IN_PYRAMID_BAG) == TRUE)) + if (InBattlePyramid() || FlagGet(FLAG_STORING_ITEMS_IN_PYRAMID_BAG) == TRUE) { return CheckPyramidBagHasSpace(itemId, count); } - - pocket = ItemId_GetPocket(itemId) - 1; - if (pocket != BERRIES_POCKET) - slotCapacity = MAX_BAG_ITEM_CAPACITY; else - slotCapacity = MAX_BERRY_CAPACITY; - - // Check space in any existing item slots that already contain this item - for (i = 0; i < gBagPockets[pocket].capacity; i++) { - if (gBagPockets[pocket].itemSlots[i].itemId == itemId) - { - ownedCount = GetBagItemQuantity(&gBagPockets[pocket].itemSlots[i].quantity); - if (ownedCount + count <= slotCapacity) - return TRUE; - if (pocket == TMHM_POCKET || pocket == BERRIES_POCKET) - return FALSE; - count -= (slotCapacity - ownedCount); - if (count == 0) - break; //Should just be "return TRUE", since setting count to 0 means all the remaining checks until return will be false anyway, but that doesn't match - } - } + u8 pocket; + u16 slotCapacity; + u16 ownedCount; - // Check space in empty item slots - if (count > 0) //if (count !=0) also works here; both match - { + pocket = ItemId_GetPocket(itemId) - 1; + if (pocket != BERRIES_POCKET) + slotCapacity = MAX_BAG_ITEM_CAPACITY; + else + slotCapacity = MAX_BERRY_CAPACITY; + + // Check space in any existing item slots that already contain this item for (i = 0; i < gBagPockets[pocket].capacity; i++) { - if (gBagPockets[pocket].itemSlots[i].itemId == 0) + if (gBagPockets[pocket].itemSlots[i].itemId == itemId) { - if (count > slotCapacity) + ownedCount = GetBagItemQuantity(&gBagPockets[pocket].itemSlots[i].quantity); + if (ownedCount + count <= slotCapacity) + return TRUE; + if (pocket == TMHM_POCKET || pocket == BERRIES_POCKET) + return FALSE; + count -= slotCapacity - ownedCount; + if (count == 0) + return TRUE; + } + } + + // Check space in empty item slots + if (count > 0) + { + for (i = 0; i < gBagPockets[pocket].capacity; i++) + { + if (gBagPockets[pocket].itemSlots[i].itemId == 0) { + if (count <= slotCapacity) + return TRUE; if (pocket == TMHM_POCKET || pocket == BERRIES_POCKET) return FALSE; count -= slotCapacity; } - else - { - count = 0; //Should just be "return TRUE", since setting count to 0 means all the remaining checks until return will be false anyway, but that doesn't match - break; - } } + if (count > 0) + return FALSE; // No more item slots. The bag is full } - if (count > 0) //if (count !=0) also works here; both match - return FALSE; // No more item slots. The bag is full - } - return TRUE; + return TRUE; + } } +#else +NAKED +bool8 CheckBagHasSpace(u16 itemId, u16 count) +{ + asm_unified( + "push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0x4\n\ + lsls r0, 16\n\ + lsrs r0, 16\n\ + mov r8, r0\n\ + lsls r1, 16\n\ + lsrs r5, r1, 16\n\ + bl ItemId_GetPocket\n\ + lsls r0, 24\n\ + cmp r0, 0\n\ + beq _080D6906\n\ + bl InBattlePyramid\n\ + lsls r0, 24\n\ + cmp r0, 0\n\ + bne _080D6838\n\ + ldr r0, =0x00004004\n\ + bl FlagGet\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + cmp r0, 0x1\n\ + bne _080D684C\n\ +_080D6838:\n\ + mov r0, r8\n\ + adds r1, r5, 0\n\ + bl CheckPyramidBagHasSpace\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + b _080D6916\n\ + .pool\n\ +_080D684C:\n\ + mov r0, r8\n\ + bl ItemId_GetPocket\n\ + subs r0, 0x1\n\ + lsls r0, 24\n\ + lsrs r2, r0, 24\n\ + ldr r7, =0x000003e7\n\ + cmp r2, 0x3\n\ + beq _080D6860\n\ + movs r7, 0x63\n\ +_080D6860:\n\ + movs r6, 0\n\ + ldr r1, =gBagPockets\n\ + lsls r4, r2, 3\n\ + adds r0, r4, r1\n\ + mov r9, r4\n\ + ldrb r0, [r0, 0x4]\n\ + cmp r6, r0\n\ + bcs _080D68BC\n\ + subs r0, r2, 0x2\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + mov r10, r0\n\ +_080D6878:\n\ + adds r0, r4, r1\n\ + ldr r1, [r0]\n\ + lsls r0, r6, 2\n\ + adds r1, r0, r1\n\ + ldrh r0, [r1]\n\ + cmp r0, r8\n\ + bne _080D68AC\n\ + adds r0, r1, 0x2\n\ + str r2, [sp]\n\ + bl GetBagItemQuantity\n\ + lsls r0, 16\n\ + lsrs r1, r0, 16\n\ + adds r0, r1, r5\n\ + ldr r2, [sp]\n\ + cmp r0, r7\n\ + ble _080D6914\n\ + mov r0, r10\n\ + cmp r0, 0x1\n\ + bls _080D6906\n\ + subs r0, r7, r1\n\ + subs r0, r5, r0\n\ + lsls r0, 16\n\ + lsrs r5, r0, 16\n\ + cmp r5, 0\n\ + beq _080D6914\n\ +_080D68AC:\n\ + adds r0, r6, 0x1\n\ + lsls r0, 24\n\ + lsrs r6, r0, 24\n\ + ldr r1, =gBagPockets\n\ + adds r0, r4, r1\n\ + ldrb r0, [r0, 0x4]\n\ + cmp r6, r0\n\ + bcc _080D6878\n\ +_080D68BC:\n\ + cmp r5, 0\n\ + beq _080D6914\n\ + movs r6, 0\n\ + ldr r3, =gBagPockets\n\ + mov r1, r9\n\ + adds r0, r1, r3\n\ + ldrb r0, [r0, 0x4]\n\ + cmp r6, r0\n\ + bcs _080D6902\n\ + adds r4, r3, 0\n\ + subs r0, r2, 0x2\n\ + lsls r0, 24\n\ + lsrs r2, r0, 24\n\ +_080D68D6:\n\ + adds r0, r1, r4\n\ + ldr r1, [r0]\n\ + lsls r0, r6, 2\n\ + adds r0, r1\n\ + ldrh r0, [r0]\n\ + cmp r0, 0\n\ + bne _080D68F2\n\ + cmp r5, r7\n\ + bls _080D6914\n\ + cmp r2, 0x1\n\ + bls _080D6906\n\ + subs r0, r5, r7\n\ + lsls r0, 16\n\ + lsrs r5, r0, 16\n\ +_080D68F2:\n\ + adds r0, r6, 0x1\n\ + lsls r0, 24\n\ + lsrs r6, r0, 24\n\ + mov r1, r9\n\ + adds r0, r1, r3\n\ + ldrb r0, [r0, 0x4]\n\ + cmp r6, r0\n\ + bcc _080D68D6\n\ +_080D6902:\n\ + cmp r5, 0\n\ + beq _080D6914\n\ +_080D6906:\n\ + movs r0, 0\n\ + b _080D6916\n\ + .pool\n\ +_080D6914:\n\ + movs r0, 0x1\n\ +_080D6916:\n\ + add sp, 0x4\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r1}\n\ + bx r1"); +} +#endif // NONMATCHING bool8 AddBagItem(u16 itemId, u16 count) { diff --git a/src/item_menu.c b/src/item_menu.c index d40c3a12c..ace2fd11e 100755 --- a/src/item_menu.c +++ b/src/item_menu.c @@ -628,6 +628,7 @@ void CB2_Bag(void) bool8 SetupBagMenu(void) { + u32 index; u8 taskId; switch (gMain.state) @@ -1166,7 +1167,7 @@ void Task_BagMenu_HandleInput(u8 taskId) SwitchBagPocket(taskId, MENU_CURSOR_DELTA_RIGHT, 0); return; default: - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { if (CanSwapItems() == TRUE) { @@ -1228,12 +1229,12 @@ static u8 GetSwitchBagPocketDirection(void) if (gBagMenu->pocketSwitchDisabled) return SWITCH_POCKET_NONE; LRKeys = GetLRKeysPressed(); - if (JOY_NEW(DPAD_LEFT) || LRKeys == MENU_L_PRESSED) + if ((gMain.newKeys & DPAD_LEFT) || LRKeys == MENU_L_PRESSED) { PlaySE(SE_SELECT); return SWITCH_POCKET_LEFT; } - if (JOY_NEW(DPAD_RIGHT) || LRKeys == MENU_R_PRESSED) + if ((gMain.newKeys & DPAD_RIGHT) || LRKeys == MENU_R_PRESSED) { PlaySE(SE_SELECT); return SWITCH_POCKET_RIGHT; @@ -1387,7 +1388,7 @@ static void Task_HandleSwappingItemsInput(u8 taskId) if (MenuHelpers_CallLinkSomething() != TRUE) { - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { PlaySE(SE_SELECT); ListMenuGetScrollAndRow(data[0], &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket], &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]); @@ -1405,7 +1406,7 @@ static void Task_HandleSwappingItemsInput(u8 taskId) break; case LIST_CANCEL: PlaySE(SE_SELECT); - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) sub_81AC498(taskId); else sub_81AC590(taskId); @@ -1644,7 +1645,7 @@ void Task_HandleOutOfBattleItemMenuInput(u8 taskId) if (MenuHelpers_CallLinkSomething() != TRUE) { s8 cursorPos = Menu_GetCursorPos(); - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { if (cursorPos > 0 && sub_81ACDFC(cursorPos - 2)) { @@ -1652,7 +1653,7 @@ void Task_HandleOutOfBattleItemMenuInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_UP); } } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (cursorPos < (gBagMenu->contextMenuNumItems - 2) && sub_81ACDFC(cursorPos + 2)) { @@ -1660,7 +1661,7 @@ void Task_HandleOutOfBattleItemMenuInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_DOWN); } } - else if ((JOY_NEW(DPAD_LEFT)) || GetLRKeysPressed() == MENU_L_PRESSED) + else if ((gMain.newKeys & DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) { if ((cursorPos & 1) && sub_81ACDFC(cursorPos - 1)) { @@ -1668,7 +1669,7 @@ void Task_HandleOutOfBattleItemMenuInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_LEFT, MENU_CURSOR_DELTA_NONE); } } - else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) + else if ((gMain.newKeys & DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) { if (!(cursorPos & 1) && sub_81ACDFC(cursorPos + 1)) { @@ -1676,12 +1677,12 @@ void Task_HandleOutOfBattleItemMenuInput(u8 taskId) ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_RIGHT, MENU_CURSOR_DELTA_NONE); } } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); sItemMenuActions[gBagMenu->contextMenuItemsPtr[cursorPos]].func.void_u8(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sItemMenuActions[ITEMMENUACTION_CANCEL].func.void_u8(taskId); @@ -1785,13 +1786,13 @@ void Task_ChooseHowManyToToss(u8 taskId) { PrintItemDepositAmount(gBagMenu->windowPointers[7], tItemCount); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); BagMenu_RemoveWindow(7); BagMenu_TossItems(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); BagMenu_RemoveWindow(7); @@ -1817,7 +1818,7 @@ void Task_ActuallyToss(u8 taskId) u16* scrollPos = &gBagPositionStruct.scrollPosition[gBagPositionStruct.pocket]; u16* cursorPos = &gBagPositionStruct.cursorPosition[gBagPositionStruct.pocket]; - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); RemoveBagItem(gSpecialVar_ItemId, tItemCount); @@ -1885,7 +1886,7 @@ static void BagMenu_PrintItemCantBeHeld(u8 taskId) void sub_81AD350(u8 taskId) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); BagMenu_InitListsMenu(taskId); @@ -2059,13 +2060,13 @@ static void Task_SellHowManyDialogueHandleInput(u8 taskId) { PrintItemSoldAmount(gBagMenu->windowPointers[8], tItemCount, (ItemId_GetPrice(gSpecialVar_ItemId) / 2) * tItemCount); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); BagMenu_RemoveWindow(8); DisplaySellItemPriceAndConfirm(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); BagMenu_PrintCursor_(data[0], 0); @@ -2107,7 +2108,7 @@ static void BagMenu_Sell_UpdateItemListAndMoney(u8 taskId) static void BagMenu_Sell_WaitForABPress(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); RemoveMoneyWindow(); @@ -2143,13 +2144,13 @@ static void Task_ChooseHowManyToDeposit(u8 taskId) { PrintItemDepositAmount(gBagMenu->windowPointers[7], tItemCount); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); BagMenu_RemoveWindow(7); BagMenu_TryDepositItem(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); BagMenu_PrintDescription(data[1]); @@ -2188,7 +2189,7 @@ static void BagMenu_Deposit_WaitForABPress(u8 taskId) { s16* data = gTasks[taskId].data; - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); BagMenu_PrintDescription(data[1]); diff --git a/src/item_use.c b/src/item_use.c index f9d1ff824..b1b90f3d5 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -721,7 +721,7 @@ static void ItemUseOnFieldCB_WailmerPailBerry(u8 taskId) static bool8 TryToWaterSudowoodo(void) { - s16 x, y; + u16 x, y; u8 z; u8 objId; GetXYCoordsOneStepInFrontOfPlayer(&x, &y); @@ -792,7 +792,7 @@ static void BootUpSoundTMHM(u8 taskId) static void Task_ShowTMHMContainedMessage(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { StringCopy(gStringVar1, gMoveNames[ItemIdToBattleMoveId(gSpecialVar_ItemId)]); StringExpandPlaceholders(gStringVar4, gText_TMHMContainedVar1); @@ -956,7 +956,7 @@ void ItemUseInBattle_PokeBall(u8 taskId) static void Task_CloseStatIncreaseMessage(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { if (!InBattlePyramid()) Task_FadeAndCloseBagMenu(taskId); diff --git a/src/link.c b/src/link.c index 9fd35a10b..cdaf58469 100644 --- a/src/link.c +++ b/src/link.c @@ -445,27 +445,27 @@ static void TestBlockTransfer(u8 nothing, u8 is, u8 used) static void LinkTestProcessKeyInput(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { gShouldAdvanceLinkState = 1; } - if (JOY_HELD(B_BUTTON)) + if (gMain.heldKeys & B_BUTTON) { InitBlockSend(gHeap + 0x4000, 0x00002004); } - if (JOY_NEW(L_BUTTON)) + if (gMain.newKeys & L_BUTTON) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB(2, 0, 0)); } - if (JOY_NEW(START_BUTTON)) + if (gMain.newKeys & START_BUTTON) { SetSuppressLinkErrorMessage(TRUE); } - if (JOY_NEW(R_BUTTON)) + if (gMain.newKeys & R_BUTTON) { TrySavingData(SAVE_LINK); } - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { SetCloseLinkCallback(); } @@ -1754,7 +1754,7 @@ static void CB2_PrintErrorMessage(void) { if (gWirelessCommType == 1) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_PIN); gWirelessCommType = 0; @@ -1764,7 +1764,7 @@ static void CB2_PrintErrorMessage(void) } else if (gWirelessCommType == 2) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { rfu_REQ_stopMode(); rfu_waitREQComplete(); diff --git a/src/link_rfu_2.c b/src/link_rfu_2.c index 41b28ec5f..6a2605c96 100644 --- a/src/link_rfu_2.c +++ b/src/link_rfu_2.c @@ -876,7 +876,8 @@ static void sub_800F498(u16 *a0, u8 *a1) static bool32 RfuProcessEnqueuedRecvBlock(void) { - u8 i, j; + u8 i; + u8 j; u8 sp00[MAX_RFU_PLAYERS * (2 * (CMD_LENGTH - 1))]; u8 sp48[2 * (CMD_LENGTH - 1)]; u8 status; @@ -922,7 +923,7 @@ static bool32 RfuProcessEnqueuedRecvBlock(void) static void HandleSendFailure(u8 unused, u32 flags) { - s32 i, j, temp; + s32 i, j; const u8 *r10 = Rfu.sendBlock.payload; for (i = 0; i < Rfu.sendBlock.count; i++) @@ -932,15 +933,14 @@ static void HandleSendFailure(u8 unused, u32 flags) sResendBlock16[0] = RFUCMD_0x8900 | i; for (j = 0; j < 7; j++) { - temp = j << 1; - sResendBlock16[j + 1] = (r10[i * 12 + temp + 1] << 8) | r10[i * 12 + temp]; + sResendBlock16[j + 1] = (r10[12 * i + (j << 1) + 1] << 8) | r10[12 * i + (j << 1) + 0]; } - for (j = 0; j < 7; j++) { - temp = j << 1; - sResendBlock8[temp + 1] = sResendBlock16[j] >> 8; - sResendBlock8[temp + 0] = sResendBlock16[j] & 0xff; + sResendBlock8[2 * j + 1] = sResendBlock16[j] >> 8; + sResendBlock8[2 * j + 0] = sResendBlock16[j]; + + j++;j--; // Needed to match; } RfuSendQueue_Enqueue(&Rfu.sendQueue, sResendBlock8); Rfu.sendBlock.failedFlags |= (1 << i); @@ -1024,7 +1024,8 @@ void Rfu_SetBerryBlenderLinkCallback(void) static void RfuHandleReceiveCommand(u8 unused) { - u16 i, j; + u16 i; + u16 j; for (i = 0; i < MAX_RFU_PLAYERS; i++) { @@ -1038,7 +1039,7 @@ static void RfuHandleReceiveCommand(u8 unused) if (gRfuLinkStatus->parentChild == MODE_CHILD) { Rfu.playerCount = gRecvCmds[i][1]; - Rfu.multiplayerId = sub_800F74C((u8 *)(&gRecvCmds[i][2])); + Rfu.multiplayerId = sub_800F74C((u8 *)(gRecvCmds[i] + 2)); } break; case RFUCMD_0x8800: @@ -1237,9 +1238,10 @@ void Rfu_SendPacket(void *data) bool32 Rfu_InitBlockSend(const u8 *src, size_t size) { bool8 r4; - if (Rfu.callback != NULL || gSendCmd[0] != 0) + if (Rfu.callback != NULL) + return FALSE; + if (gSendCmd[0] != 0) return FALSE; - if (Rfu.sendBlock.sending) { sRfuDebug.unk_83++; @@ -1417,12 +1419,16 @@ void Rfu_SetCloseLinkCallback(void) static void SendReadyExitStandbyUntilAllReady(void) { - u8 i, playerCount; + u8 playerCount; + u8 i; - if (GetMultiplayerId() != 0 && Rfu.recvQueue.count == 0 && Rfu.resendExitStandbyTimer > 60) + if (GetMultiplayerId() != 0) { - RfuPrepareSendBuffer(RFUCMD_READY_EXIT_STANDBY); - Rfu.resendExitStandbyTimer = 0; + if (Rfu.recvQueue.count == 0 && Rfu.resendExitStandbyTimer > 60) + { + RfuPrepareSendBuffer(RFUCMD_READY_EXIT_STANDBY); + Rfu.resendExitStandbyTimer = 0; + } } playerCount = GetLinkPlayerCount(); for (i = 0; i < playerCount; i++) @@ -1452,7 +1458,8 @@ static void LinkLeaderReadyToExitStandby(void) // RFU equivalent of LinkCB_Standby and LinkCB_StandbyForAll static void Rfu_LinkStandby(void) { - u8 i, playerCount; + u8 i; + u8 playerCount; if (GetMultiplayerId() != 0) { @@ -1548,27 +1555,27 @@ static bool8 CheckForLeavingGroupMembers(void) bool8 memberLeft = FALSE; for (i = 0; i < RFU_CHILD_MAX; i++) { - if (Rfu.partnerSendStatuses[i] == RFU_STATUS_JOIN_GROUP_OK - || Rfu.partnerSendStatuses[i] == RFU_STATUS_JOIN_GROUP_NO) + if (Rfu.partnerSendStatuses[i] < RFU_STATUS_JOIN_GROUP_OK + || Rfu.partnerSendStatuses[i] > RFU_STATUS_JOIN_GROUP_NO) { - continue; - } - - if (gRfuSlotStatusNI[i]->recv.state == SLOT_STATE_RECV_SUCCESS - || gRfuSlotStatusNI[i]->recv.state == SLOT_STATE_RECV_SUCCESS_AND_SENDSIDE_UNKNOWN) - { - if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_LEAVE_GROUP_NOTICE) + if (gRfuSlotStatusNI[i]->recv.state == SLOT_STATE_RECV_SUCCESS + || gRfuSlotStatusNI[i]->recv.state == SLOT_STATE_RECV_SUCCESS_AND_SENDSIDE_UNKNOWN) { - Rfu.partnerSendStatuses[i] = RFU_STATUS_LEAVE_GROUP; - Rfu.partnerRecvStatuses[i] = RFU_STATUS_10; - rfu_clearSlot(TYPE_NI_RECV, i); - rfu_NI_setSendData(1 << i, 8, &Rfu.partnerSendStatuses[i], 1); - memberLeft = TRUE; + if (Rfu.partnerRecvStatuses[i] == RFU_STATUS_LEAVE_GROUP_NOTICE) + { + Rfu.partnerSendStatuses[i] = RFU_STATUS_LEAVE_GROUP; + Rfu.partnerRecvStatuses[i] = RFU_STATUS_10; + rfu_clearSlot(TYPE_NI_RECV, i); + rfu_NI_setSendData(1 << i, 8, &Rfu.partnerSendStatuses[i], 1); + memberLeft = TRUE; + } + + } + else if (gRfuSlotStatusNI[Rfu.childSlot]->recv.state == SLOT_STATE_RECV_FAILED) + rfu_clearSlot(TYPE_NI_RECV, i); + { + } - } - else if (gRfuSlotStatusNI[Rfu.childSlot]->recv.state == SLOT_STATE_RECV_FAILED) - { - rfu_clearSlot(TYPE_NI_RECV, i); } } return memberLeft; @@ -2044,7 +2051,8 @@ void sub_80110B8(u32 a0) if ((r8 >> i) & 1) { child_sprite_genders |= ((0x80 | ((gLinkPlayers[Rfu.linkPlayerIdx[i]].gender & 1) << 3) | (gLinkPlayers[Rfu.linkPlayerIdx[i]].trainerId & 7)) << (numConnectedChildren << 3)); - if (++numConnectedChildren == a0 - 1) + numConnectedChildren++; + if (numConnectedChildren == a0 - 1) break; } } @@ -2089,7 +2097,8 @@ static void sub_80111FC(void) static void sub_801120C(u8 msg, u8 paramCount) { - u8 i, disconnectFlag = 0; + u8 i; + u8 disconnectFlag = 0; switch (msg) { case LMAN_MSG_INITIALIZE_COMPLETED: diff --git a/src/link_rfu_3.c b/src/link_rfu_3.c index 821b2d118..db1ba8b43 100644 --- a/src/link_rfu_3.c +++ b/src/link_rfu_3.c @@ -309,7 +309,8 @@ static const struct SpriteTemplate sWirelessStatusIndicatorSpriteTemplate = { void RfuRecvQueue_Reset(struct RfuRecvQueue *queue) { - s32 i, j; + s32 i; + s32 j; for (i = 0; i < RECV_QUEUE_NUM_SLOTS; i++) { @@ -326,7 +327,8 @@ void RfuRecvQueue_Reset(struct RfuRecvQueue *queue) void RfuSendQueue_Reset(struct RfuSendQueue *queue) { - s32 i, j; + s32 i; + s32 j; for (i = 0; i < SEND_QUEUE_NUM_SLOTS; i++) { @@ -343,7 +345,8 @@ void RfuSendQueue_Reset(struct RfuSendQueue *queue) static void RfuUnusedQueue_Reset(struct RfuUnusedQueue *queue) { - s32 i, j; + s32 i; + s32 j; for (i = 0; i < UNUSED_QUEUE_NUM_SLOTS; i++) { @@ -620,39 +623,105 @@ static void ASCIIToPkmnStr(u8 *pkmnStr, const u8 *asciiStr) pkmnStr[i] = EOS; } +#ifdef NONMATCHING static u8 GetConnectedChildStrength(u8 maxFlags) { u8 flagCount = 0; - u8 flags = gRfuLinkStatus->connSlotFlag; + u32 flags = gRfuLinkStatus->connSlotFlag; u8 i; if (gRfuLinkStatus->parentChild == MODE_PARENT) { - for (i = 0; i < RFU_CHILD_MAX; i++) + for (i = 0; i < 4; flags >>= 1, i++) { if (flags & 1) { if (maxFlags == flagCount + 1) - { return gRfuLinkStatus->strength[i]; - break; // This break is needed to match - } flagCount++; } - flags >>= 1; } } else { - for (i = 0; i < 4; i++) + for (i = 0; i < 4; flags >>= 1, i++) { if (flags & 1) return gRfuLinkStatus->strength[i]; - flags >>= 1; } } return 0; } +#else +NAKED +static u8 GetConnectedChildStrength(u8 maxFlags) +{ + asm_unified("\tpush {r4-r7,lr}\n" + "\tlsls r0, 24\n" + "\tlsrs r5, r0, 24\n" + "\tmovs r6, 0\n" + "\tldr r0, =gRfuLinkStatus\n" + "\tldr r4, [r0]\n" + "\tldrb r2, [r4, 0x2]\n" + "\tldrb r1, [r4]\n" + "\tadds r7, r0, 0\n" + "\tcmp r1, 0x1\n" + "\tbne _0800DD72\n" + "\tmovs r3, 0\n" + "\tands r1, r2\n" + "\tcmp r1, 0\n" + "\tbeq _0800DD4E\n" + "\tcmp r5, 0x1\n" + "\tbne _0800DD48\n" + "\tldrb r0, [r4, 0xA]\n" + "\tb _0800DD8C\n" + "\t.pool\n" + "_0800DD48:\n" + "\tadds r0, r6, 0x1\n" + "\tlsls r0, 24\n" + "\tlsrs r6, r0, 24\n" + "_0800DD4E:\n" + "\tlsrs r2, 1\n" + "\tadds r0, r3, 0x1\n" + "\tlsls r0, 24\n" + "\tlsrs r3, r0, 24\n" + "\tcmp r3, 0x3\n" + "\tbhi _0800DD8A\n" + "\tmovs r0, 0x1\n" + "\tands r0, r2\n" + "\tcmp r0, 0\n" + "\tbeq _0800DD4E\n" + "\tadds r0, r6, 0x1\n" + "\tcmp r5, r0\n" + "\tbne _0800DD48\n" + "_0800DD68:\n" + "\tldr r0, [r7]\n" + "\tadds r0, 0xA\n" + "\tadds r0, r3\n" + "\tldrb r0, [r0]\n" + "\tb _0800DD8C\n" + "_0800DD72:\n" + "\tmovs r3, 0\n" + "\tmovs r1, 0x1\n" + "_0800DD76:\n" + "\tadds r0, r2, 0\n" + "\tands r0, r1\n" + "\tcmp r0, 0\n" + "\tbne _0800DD68\n" + "\tlsrs r2, 1\n" + "\tadds r0, r3, 0x1\n" + "\tlsls r0, 24\n" + "\tlsrs r3, r0, 24\n" + "\tcmp r3, 0x3\n" + "\tbls _0800DD76\n" + "_0800DD8A:\n" + "\tmovs r0, 0\n" + "_0800DD8C:\n" + "\tpop {r4-r7}\n" + "\tpop {r1}\n" + "\tbx r1"); +} +#endif void InitHostRFUtgtGname(struct GFtgtGname *data, u8 activity, bool32 started, s32 child_sprite_genders) { @@ -922,7 +991,8 @@ void RecordMixTrainerNames(void) { if (gWirelessCommType != 0) { - s32 i, j; + s32 i; + s32 j; s32 nextSpace; s32 connectedTrainerRecordIndices[5]; struct TrainerNameRecord *newRecords = calloc(ARRAY_COUNT(gSaveBlock1Ptr->trainerNameRecords), sizeof(struct TrainerNameRecord)); diff --git a/src/list_menu.c b/src/list_menu.c index 7784dd338..e3c4e11d2 100644 --- a/src/list_menu.c +++ b/src/list_menu.c @@ -312,7 +312,7 @@ static void ListMenuDummyTask(u8 taskId) } -u32 DoMysteryGiftListMenu(const struct WindowTemplate *windowTemplate, const struct ListMenuTemplate *listMenuTemplate, u8 arg2, u16 tileNum, u16 palNum) +s32 DoMysteryGiftListMenu(const struct WindowTemplate *windowTemplate, const struct ListMenuTemplate *listMenuTemplate, u8 arg2, u16 tileNum, u16 palNum) { switch (sMysteryGiftLinkMenu.state) { @@ -335,11 +335,11 @@ u32 DoMysteryGiftListMenu(const struct WindowTemplate *windowTemplate, const str break; case 1: sMysteryGiftLinkMenu.currItemId = ListMenu_ProcessInput(sMysteryGiftLinkMenu.listTaskId); - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { sMysteryGiftLinkMenu.state = 2; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { sMysteryGiftLinkMenu.currItemId = LIST_CANCEL; sMysteryGiftLinkMenu.state = 2; @@ -410,20 +410,20 @@ s32 ListMenu_ProcessInput(u8 listTaskId) { struct ListMenu *list = (void*) gTasks[listTaskId].data; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { return list->template.items[list->scrollOffset + list->selectedRow].id; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return LIST_CANCEL; } - else if (JOY_REPEAT(DPAD_UP)) + else if (gMain.newAndRepeatedKeys & DPAD_UP) { ListMenuChangeSelection(list, TRUE, 1, FALSE); return LIST_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { ListMenuChangeSelection(list, TRUE, 1, TRUE); return LIST_NOTHING_CHOSEN; @@ -439,12 +439,12 @@ s32 ListMenu_ProcessInput(u8 listTaskId) rightButton = FALSE; break; case LIST_MULTIPLE_SCROLL_DPAD: - leftButton = JOY_REPEAT(DPAD_LEFT); - rightButton = JOY_REPEAT(DPAD_RIGHT); + leftButton = gMain.newAndRepeatedKeys & DPAD_LEFT; + rightButton = gMain.newAndRepeatedKeys & DPAD_RIGHT; break; case LIST_MULTIPLE_SCROLL_L_R: - leftButton = JOY_REPEAT(L_BUTTON); - rightButton = JOY_REPEAT(R_BUTTON); + leftButton = gMain.newAndRepeatedKeys & L_BUTTON; + rightButton = gMain.newAndRepeatedKeys & R_BUTTON; break; } @@ -1257,17 +1257,17 @@ void ListMenuSetUpRedOutlineCursorSpriteOamTable(u16 rowWidth, u16 rowHeight, st s32 i, j, id = 0; subsprites[id] = sSubsprite_RedOutline1; - subsprites[id].x = -120; - subsprites[id].y = -120; + subsprites[id].x = 136; + subsprites[id].y = 136; id++; subsprites[id] = sSubsprite_RedOutline2; subsprites[id].x = rowWidth + 128; - subsprites[id].y = -120; + subsprites[id].y = 136; id++; subsprites[id] = sSubsprite_RedOutline7; - subsprites[id].x = -120; + subsprites[id].x = 136; subsprites[id].y = rowHeight + 128; id++; @@ -1297,7 +1297,7 @@ void ListMenuSetUpRedOutlineCursorSpriteOamTable(u16 rowWidth, u16 rowHeight, st for (j = 8; j < rowHeight - 8; j += 8) { subsprites[id] = sSubsprite_RedOutline4; - subsprites[id].x = -120; + subsprites[id].x = 136; subsprites[id].y = j - 120; id++; diff --git a/src/m4a.c b/src/m4a.c index b8f9e21c1..11a4525ea 100644 --- a/src/m4a.c +++ b/src/m4a.c @@ -22,7 +22,8 @@ u8 gMPlayMemAccArea[0x10]; u32 MidiKeyToFreq(struct WaveData *wav, u8 key, u8 fineAdjust) { - u32 val1, val2; + u32 val1; + u32 val2; u32 fineAdjustShifted = fineAdjust << 24; if (key > 178) @@ -314,7 +315,7 @@ void MPlayExtender(struct CgbChannel *cgbChans) void MusicPlayerJumpTableCopy(void) { - asm("svc 0x2A"); + asm("swi 0x2A"); } void ClearChain(void *x) @@ -351,25 +352,25 @@ void SoundInit(struct SoundInfo *soundInfo) | SOUND_ALL_MIX_FULL; REG_SOUNDBIAS_H = (REG_SOUNDBIAS_H & 0x3F) | 0x40; - REG_DMA1SAD = (u32)soundInfo->pcmBuffer; - REG_DMA1DAD = (u32)®_FIFO_A; - REG_DMA2SAD = (u32)soundInfo->pcmBuffer + PCM_DMA_BUF_SIZE; - REG_DMA2DAD = (u32)®_FIFO_B; + REG_DMA1SAD = (s32)soundInfo->pcmBuffer; + REG_DMA1DAD = (s32)®_FIFO_A; + REG_DMA2SAD = (s32)soundInfo->pcmBuffer + PCM_DMA_BUF_SIZE; + REG_DMA2DAD = (s32)®_FIFO_B; SOUND_INFO_PTR = soundInfo; CpuFill32(0, soundInfo, sizeof(struct SoundInfo)); soundInfo->maxChans = 8; soundInfo->masterVolume = 15; - soundInfo->plynote = ply_note; + soundInfo->plynote = (u32)ply_note; soundInfo->CgbSound = DummyFunc; soundInfo->CgbOscOff = (void (*)(u8))DummyFunc; soundInfo->MidiKeyToCgbFreq = (u32 (*)(u8, u8, u8))DummyFunc; - soundInfo->ExtVolPit = (void (*)(struct MusicPlayerInfo *, struct MusicPlayerTrack *))DummyFunc; + soundInfo->ExtVolPit = (u32)DummyFunc; MPlayJumpTableCopy(gMPlayJumpTable); - soundInfo->MPlayJumpTable = (void (**)())gMPlayJumpTable; + soundInfo->MPlayJumpTable = (u32)gMPlayJumpTable; SampleFreqSet(SOUND_MODE_FREQ_13379); @@ -380,7 +381,7 @@ void SampleFreqSet(u32 freq) { struct SoundInfo *soundInfo = SOUND_INFO_PTR; - freq = (freq & SOUND_MODE_FREQ) >> SOUND_MODE_FREQ_SHIFT; + freq = (freq & 0xF0000) >> 16; soundInfo->freq = freq; soundInfo->pcmSamplesPerVBlank = gPcmSamplesPerVBlankTable[freq - 1]; soundInfo->pcmDmaPeriod = PCM_DMA_BUF_SIZE / soundInfo->pcmSamplesPerVBlank; @@ -431,9 +432,14 @@ void m4aSoundMode(u32 mode) soundInfo->maxChans = temp >> SOUND_MODE_MAXCHN_SHIFT; - for (temp = MAX_DIRECTSOUND_CHANNELS, chan = soundInfo->chans; temp != 0; temp--,chan++) + temp = MAX_DIRECTSOUND_CHANNELS; + chan = &soundInfo->chans[0]; + + while (temp != 0) { chan->status = 0; + temp--; + chan++; } } @@ -463,28 +469,37 @@ void m4aSoundMode(u32 mode) void SoundClear(void) { - s32 i; struct SoundInfo *soundInfo = SOUND_INFO_PTR; - struct SoundChannel *chan; + s32 i; + void *chan; if (soundInfo->ident != ID_NUMBER) return; soundInfo->ident++; - for (i = MAX_DIRECTSOUND_CHANNELS, chan = soundInfo->chans; i > 0; i--,chan++) + i = MAX_DIRECTSOUND_CHANNELS; + chan = &soundInfo->chans[0]; + + while (i > 0) { - chan->status = 0; + ((struct SoundChannel *)chan)->status = 0; + i--; + chan = (void *)((s32)chan + sizeof(struct SoundChannel)); } - chan = (struct SoundChannel *)soundInfo->cgbChans; + chan = soundInfo->cgbChans; if (chan) { - for (i=1; i<=4; i++,chan++) + i = 1; + + while (i <= 4) { soundInfo->CgbOscOff(i); - chan->status = 0; + ((struct CgbChannel *)chan)->sf = 0; + i++; + chan = (void *)((s32)chan + sizeof(struct CgbChannel)); } } @@ -495,20 +510,21 @@ void m4aSoundVSyncOff(void) { struct SoundInfo *soundInfo = SOUND_INFO_PTR; - if (soundInfo->ident < ID_NUMBER || soundInfo->ident > ID_NUMBER + 1) - return; - soundInfo->ident += 10; + if (soundInfo->ident >= ID_NUMBER && soundInfo->ident <= ID_NUMBER + 1) + { + soundInfo->ident += 10; - if (REG_DMA1CNT & (DMA_REPEAT << 16)) - REG_DMA1CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; + if (REG_DMA1CNT & (DMA_REPEAT << 16)) + REG_DMA1CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; - if (REG_DMA2CNT & (DMA_REPEAT << 16)) - REG_DMA2CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; + if (REG_DMA2CNT & (DMA_REPEAT << 16)) + REG_DMA2CNT = ((DMA_ENABLE | DMA_START_NOW | DMA_32BIT | DMA_SRC_INC | DMA_DEST_FIXED) << 16) | 4; - REG_DMA1CNT_H = DMA_32BIT; - REG_DMA2CNT_H = DMA_32BIT; + REG_DMA1CNT_H = DMA_32BIT; + REG_DMA2CNT_H = DMA_32BIT; - CpuFill32(0, soundInfo->pcmBuffer, sizeof(soundInfo->pcmBuffer)); + CpuFill32(0, soundInfo->pcmBuffer, sizeof(soundInfo->pcmBuffer)); + } } void m4aSoundVSyncOn(void) @@ -564,7 +580,7 @@ void MPlayOpen(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *track } soundInfo->intp = (u32)mplayInfo; - soundInfo->func = MPlayMain; + soundInfo->func = (u32)MPlayMain; soundInfo->ident = ID_NUMBER; mplayInfo->ident = ID_NUMBER; } @@ -598,21 +614,28 @@ void MPlayStart(struct MusicPlayerInfo *mplayInfo, struct SongHeader *songHeader mplayInfo->tempoC = 0; mplayInfo->fadeOI = 0; - for (i = 0, track = mplayInfo->tracks; i < songHeader->trackCount && i < mplayInfo->trackCount; i++, track++) + i = 0; + track = mplayInfo->tracks; + + while (i < songHeader->trackCount && i < mplayInfo->trackCount) { TrackStop(mplayInfo, track); track->flags = MPT_FLG_EXIST | MPT_FLG_START; track->chan = 0; track->cmdPtr = songHeader->part[i]; + i++; + track++; } - for (; i < mplayInfo->trackCount; i++, track++) + while (i < mplayInfo->trackCount) { TrackStop(mplayInfo, track); track->flags = 0; + i++; + track++; } - if (songHeader->reverb & SOUND_MODE_REVERB_SET) + if (songHeader->reverb & 0x80) m4aSoundMode(songHeader->reverb); mplayInfo->ident = ID_NUMBER; @@ -630,9 +653,14 @@ void m4aMPlayStop(struct MusicPlayerInfo *mplayInfo) mplayInfo->ident++; mplayInfo->status |= MUSICPLAYER_STATUS_PAUSE; - for (i = mplayInfo->trackCount, track = mplayInfo->tracks; i > 0; i--, track++) + i = mplayInfo->trackCount; + track = mplayInfo->tracks; + + while (i > 0) { TrackStop(mplayInfo, track); + i--; + track++; } mplayInfo->ident = ID_NUMBER; @@ -676,8 +704,10 @@ void FadeOutBody(struct MusicPlayerInfo *mplayInfo) if ((s16)(mplayInfo->fadeOV & mask) <= 0) { + i = mplayInfo->trackCount; + track = mplayInfo->tracks; - for (i = mplayInfo->trackCount, track = mplayInfo->tracks; i > 0; i--, track++) + while (i > 0) { u32 val; @@ -689,6 +719,9 @@ void FadeOutBody(struct MusicPlayerInfo *mplayInfo) if (!val) track->flags = 0; + + i--; + track++; } if (mplayInfo->fadeOV & TEMPORARY_FADE) @@ -701,7 +734,10 @@ void FadeOutBody(struct MusicPlayerInfo *mplayInfo) } } - for (i = mplayInfo->trackCount, track = mplayInfo->tracks; i > 0; i--, track++) + i = mplayInfo->trackCount; + track = mplayInfo->tracks; + + while (i > 0) { if (track->flags & MPT_FLG_EXIST) { @@ -710,6 +746,9 @@ void FadeOutBody(struct MusicPlayerInfo *mplayInfo) track->volX = (fadeOV >> FADE_VOL_SHIFT); track->flags |= MPT_FLG_VOLCHG; } + + i--; + track++; } } @@ -717,7 +756,7 @@ void TrkVolPitSet(struct MusicPlayerInfo *mplayInfo, struct MusicPlayerTrack *tr { if (track->flags & MPT_FLG_VOLSET) { - u32 x; + s32 x; s32 y; x = (u32)(track->vol * track->volX) >> 5; diff --git a/src/m4a_1.s b/src/m4a_1.s index 290404ad0..cab4ed174 100644 --- a/src/m4a_1.s +++ b/src/m4a_1.s @@ -22,13 +22,13 @@ SoundMain: ldr r0, lt_SOUND_INFO_PTR ldr r0, [r0] ldr r2, lt_ID_NUMBER - ldr r3, [r0, #o_SoundInfo_ident] + ldr r3, [r0, o_SoundInfo_ident] cmp r2, r3 beq SoundMain_1 bx lr @ Exit the function if ident doesn't match ID_NUMBER. SoundMain_1: adds r3, 1 - str r3, [r0, #o_SoundInfo_ident] + str r3, [r0, o_SoundInfo_ident] push {r4-r7,lr} mov r1, r8 mov r2, r9 @@ -36,7 +36,7 @@ SoundMain_1: mov r4, r11 push {r0-r4} sub sp, 0x18 - ldrb r1, [r0, #o_SoundInfo_maxLines] + ldrb r1, [r0, o_SoundInfo_maxLines] cmp r1, 0 @ if maxLines is 0, there is no maximum beq SoundMain_3 ldr r2, lt_REG_VCOUNT @@ -48,24 +48,24 @@ SoundMain_2: adds r1, r2 SoundMain_3: str r1, [sp, 0x14] - ldr r3, [r0, #o_SoundInfo_func] + ldr r3, [r0, o_SoundInfo_func] cmp r3, 0 beq SoundMain_4 - ldr r0, [r0, #o_SoundInfo_intp] + ldr r0, [r0, o_SoundInfo_intp] bl _081DD25E ldr r0, [sp, 0x18] SoundMain_4: - ldr r3, [r0, #o_SoundInfo_CgbSound] + ldr r3, [r0, o_SoundInfo_CgbSound] bl _081DD25E ldr r0, [sp, 0x18] - ldr r3, [r0, #o_SoundInfo_pcmSamplesPerVBlank] + ldr r3, [r0, o_SoundInfo_pcmSamplesPerVBlank] mov r8, r3 ldr r5, lt_o_SoundInfo_pcmBuffer adds r5, r0 - ldrb r4, [r0, #o_SoundInfo_pcmDmaCounter] + ldrb r4, [r0, o_SoundInfo_pcmDmaCounter] subs r7, r4, 1 bls SoundMain_5 - ldrb r1, [r0, #o_SoundInfo_pcmDmaPeriod] + ldrb r1, [r0, o_SoundInfo_pcmDmaPeriod] subs r1, r7 mov r2, r8 muls r2, r1 @@ -87,7 +87,7 @@ lt_PCM_DMA_BUF_SIZE: .word PCM_DMA_BUF_SIZE thumb_func_start SoundMainRAM SoundMainRAM: - ldrb r3, [r0, #o_SoundInfo_reverb] + ldrb r3, [r0, o_SoundInfo_reverb] cmp r3, 0 beq SoundMainRAM_NoReverb adr r1, SoundMainRAM_Reverb @@ -95,7 +95,7 @@ SoundMainRAM: .arm SoundMainRAM_Reverb: cmp r4, 0x2 - addeq r7, r0, #o_SoundInfo_pcmBuffer + addeq r7, r0, o_SoundInfo_pcmBuffer addne r7, r5, r8 mov r4, r8 _081DCEC4: @@ -145,14 +145,14 @@ SoundMainRAM_NoReverb_Loop: bgt SoundMainRAM_NoReverb_Loop _081DCF36: ldr r4, [sp, 0x18] - ldr r0, [r4, #o_SoundInfo_divFreq] + ldr r0, [r4, o_SoundInfo_divFreq] mov r12, r0 - ldrb r0, [r4, #o_SoundInfo_maxChans] - adds r4, #o_SoundInfo_chans + ldrb r0, [r4, o_SoundInfo_maxChans] + adds r4, o_SoundInfo_chans SoundMainRAM_ChanLoop: str r0, [sp, 0x4] - ldr r3, [r4, #o_SoundChannel_wav] + ldr r3, [r4, o_SoundChannel_wav] ldr r0, [sp, 0x14] cmp r0, 0 beq _081DCF60 @@ -169,7 +169,7 @@ _081DCF54: .pool _081DCF60: - ldrb r6, [r4, #o_SoundChannel_status] + ldrb r6, [r4, o_SoundChannel_status] movs r0, 0xC7 tst r0, r6 bne _081DCF6A @@ -182,99 +182,99 @@ _081DCF6A: tst r0, r6 bne _081DCFB0 movs r6, 0x3 - strb r6, [r4, #o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_status] adds r0, r3, 0 adds r0, 0x10 - ldr r1, [r4, #o_SoundChannel_ct] + ldr r1, [r4, o_SoundChannel_ct] adds r0, r1 - str r0, [r4, #o_SoundChannel_cp] + str r0, [r4, o_SoundChannel_cp] ldr r0, [r3, 0xC] subs r0, r1 - str r0, [r4, #o_SoundChannel_ct] + str r0, [r4, o_SoundChannel_ct] movs r5, 0 - strb r5, [r4, #o_SoundChannel_ev] - str r5, [r4, #o_SoundChannel_fw] + strb r5, [r4, o_SoundChannel_ev] + str r5, [r4, o_SoundChannel_fw] ldrb r2, [r3, 0x3] movs r0, 0xC0 tst r0, r2 beq _081DCFF8 movs r0, 0x10 orrs r6, r0 - strb r6, [r4, #o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_status] b _081DCFF8 _081DCFA0: - ldrb r5, [r4, #o_SoundChannel_ev] + ldrb r5, [r4, o_SoundChannel_ev] movs r0, 0x4 tst r0, r6 beq _081DCFB6 - ldrb r0, [r4, #o_SoundChannel_iel] + ldrb r0, [r4, o_SoundChannel_iel] subs r0, 1 - strb r0, [r4, #o_SoundChannel_iel] + strb r0, [r4, o_SoundChannel_iel] bhi _081DD006 _081DCFB0: movs r0, 0 - strb r0, [r4, #o_SoundChannel_status] + strb r0, [r4, o_SoundChannel_status] b _081DD240 _081DCFB6: movs r0, 0x40 tst r0, r6 beq _081DCFD6 - ldrb r0, [r4, #o_SoundChannel_release] + ldrb r0, [r4, o_SoundChannel_release] muls r5, r0 lsrs r5, 8 - ldrb r0, [r4, #o_SoundChannel_iev] + ldrb r0, [r4, o_SoundChannel_iev] cmp r5, r0 bhi _081DD006 _081DCFC8: - ldrb r5, [r4, #o_SoundChannel_iev] + ldrb r5, [r4, o_SoundChannel_iev] cmp r5, 0 beq _081DCFB0 movs r0, 0x4 orrs r6, r0 - strb r6, [r4, #o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_status] b _081DD006 _081DCFD6: movs r2, 0x3 ands r2, r6 cmp r2, 0x2 bne _081DCFF4 - ldrb r0, [r4, #o_SoundChannel_decay] + ldrb r0, [r4, o_SoundChannel_decay] muls r5, r0 lsrs r5, 8 - ldrb r0, [r4, #o_SoundChannel_sustain] + ldrb r0, [r4, o_SoundChannel_sustain] cmp r5, r0 bhi _081DD006 adds r5, r0, 0 beq _081DCFC8 subs r6, 0x1 - strb r6, [r4, #o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_status] b _081DD006 _081DCFF4: cmp r2, 0x3 bne _081DD006 _081DCFF8: - ldrb r0, [r4, #o_SoundChannel_attack] + ldrb r0, [r4, o_SoundChannel_attack] adds r5, r0 cmp r5, 0xFF bcc _081DD006 movs r5, 0xFF subs r6, 0x1 - strb r6, [r4, #o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_status] _081DD006: - strb r5, [r4, #o_SoundChannel_ev] + strb r5, [r4, o_SoundChannel_ev] ldr r0, [sp, 0x18] - ldrb r0, [r0, #o_SoundChannel_release] + ldrb r0, [r0, o_SoundChannel_release] adds r0, 0x1 muls r0, r5 lsrs r5, r0, 4 - ldrb r0, [r4, #o_SoundChannel_rightVolume] + ldrb r0, [r4, o_SoundChannel_rightVolume] muls r0, r5 lsrs r0, 8 - strb r0, [r4, #o_SoundChannel_er] - ldrb r0, [r4, #o_SoundChannel_leftVolume] + strb r0, [r4, o_SoundChannel_er] + ldrb r0, [r4, o_SoundChannel_leftVolume] muls r0, r5 lsrs r0, 8 - strb r0, [r4, #o_SoundChannel_el] + strb r0, [r4, o_SoundChannel_el] movs r0, 0x10 ands r0, r6 str r0, [sp, 0x10] @@ -289,17 +289,17 @@ _081DD006: str r0, [sp, 0x10] _081DD03A: ldr r5, [sp, 0x8] - ldr r2, [r4, #o_SoundChannel_ct] - ldr r3, [r4, #o_SoundChannel_cp] + ldr r2, [r4, o_SoundChannel_ct] + ldr r3, [r4, o_SoundChannel_cp] adr r0, _081DD044 bx r0 .arm _081DD044: str r8, [sp] - ldr r9, [r4, #o_SoundChannel_fw] - ldrb r10, [r4, #o_SoundChannel_er] - ldrb r11, [r4, #o_SoundChannel_el] - ldrb r0, [r4, #o_SoundChannel_type] + ldr r9, [r4, o_SoundChannel_fw] + ldrb r10, [r4, o_SoundChannel_er] + ldrb r11, [r4, o_SoundChannel_el] + ldrb r0, [r4, o_SoundChannel_type] tst r0, 0x30 beq _081DD068 bl sub_82DF49C @@ -307,7 +307,7 @@ _081DD044: _081DD068: mov r10, r10, lsl 16 mov r11, r11, lsl 16 - ldrb r0, [r4, #o_SoundChannel_type] + ldrb r0, [r4, o_SoundChannel_type] tst r0, 0x8 beq _081DD19C _081DD07C: @@ -383,7 +383,7 @@ _081DD164: ldrne r3, [sp, 0xC] bne _081DD118 _081DD174: - strb r2, [r4, #o_SoundChannel_status] + strb r2, [r4, o_SoundChannel_status] mov r0, r5, lsr 30 bic r5, r5, 0xC0000000 rsb r0, r0, 0x3 @@ -395,7 +395,7 @@ _081DD174: b _081DD234 _081DD19C: push {r4,r12} - ldr r1, [r4, #o_SoundChannel_freq] + ldr r1, [r4, o_SoundChannel_freq] mul r4, r12, r1 ldrsb r0, [r3] ldrsb r1, [r3, 0x1]! @@ -434,10 +434,10 @@ _081DD208: sub r3, r3, 0x1 pop {r4,r12} _081DD228: - str r9, [r4, #o_SoundChannel_fw] + str r9, [r4, o_SoundChannel_fw] _081DD22C: - str r2, [r4, #o_SoundChannel_ct] - str r3, [r4, #o_SoundChannel_cp] + str r2, [r4, o_SoundChannel_ct] + str r3, [r4, o_SoundChannel_cp] _081DD234: ldr r8, [sp] add r0, pc, 0x1 @@ -467,33 +467,33 @@ _081DD25E: arm_func_start sub_82DF49C sub_82DF49C: - ldr r6, [r4, #o_SoundChannel_wav] - ldrb r0, [r4, #o_SoundChannel_status] + ldr r6, [r4, o_SoundChannel_wav] + ldrb r0, [r4, o_SoundChannel_status] tst r0, 0x20 bne _081DD2B4 orr r0, r0, 0x20 - strb r0, [r4, #o_SoundChannel_status] - ldrb r0, [r4, #o_SoundChannel_type] + strb r0, [r4, o_SoundChannel_status] + ldrb r0, [r4, o_SoundChannel_type] tst r0, 0x10 beq _081DD29C ldr r1, [r6, 0xC] add r1, r1, r6, lsl 1 add r1, r1, 0x20 sub r3, r1, r3 - str r3, [r4, #o_SoundChannel_cp] + str r3, [r4, o_SoundChannel_cp] _081DD29C: ldrh r0, [r6] cmp r0, 0 beq _081DD2B4 sub r3, r3, r6 sub r3, r3, 0x10 - str r3, [r4, #o_SoundChannel_cp] + str r3, [r4, o_SoundChannel_cp] _081DD2B4: push {r8,r12,lr} mov r10, r10, lsl 16 mov r11, r11, lsl 16 - ldr r1, [r4, #o_SoundChannel_freq] - ldrb r0, [r4, #o_SoundChannel_type] + ldr r1, [r4, o_SoundChannel_freq] + ldrb r0, [r4, o_SoundChannel_type] tst r0, 0x8 movne r8, 0x800000 muleq r8, r12, r1 @@ -501,8 +501,8 @@ _081DD2B4: cmp r0, 0 beq _081DD468 mov r0, 0xFF000000 - str r0, [r4, #o_SoundChannel_xpi] - ldrb r0, [r4, #o_SoundChannel_type] + str r0, [r4, o_SoundChannel_xpi] + ldrb r0, [r4, o_SoundChannel_type] tst r0, 0x10 bne _081DD3C0 bl sub_82DF758 @@ -555,7 +555,7 @@ _081DD398: ldr r0, [sp, 0x1C] cmp r0, 0 beq _081DD4F4 - ldr r3, [r4, #o_SoundChannel_wav] + ldr r3, [r4, o_SoundChannel_wav] ldr r3, [r3, 0x8] rsb lr, r2, 0 _081DD3B0: @@ -612,7 +612,7 @@ _081DD440: add r3, r3, 0x2 b _081DD4F0 _081DD468: - ldrb r0, [r4, #o_SoundChannel_type] + ldrb r0, [r4, o_SoundChannel_type] tst r0, 0x10 beq _081DD4F0 ldrsb r0, [r3, -0x1]! @@ -653,7 +653,7 @@ _081DD4F0: pop {r8,r12,pc} _081DD4F4: mov r2, 0 - strb r2, [r4, #o_SoundChannel_status] + strb r2, [r4, o_SoundChannel_status] mov r0, r5, lsr 30 bic r5, r5, 0xC0000000 rsb r0, r0, 0x3 @@ -669,13 +669,13 @@ _081DD4F4: sub_82DF758: push {r0,r2,r5-r7,lr} mov r0, r3, lsr 6 - ldr r1, [r4, #o_SoundChannel_xpi] + ldr r1, [r4, o_SoundChannel_xpi] cmp r0, r1 beq _081DD594 - str r0, [r4, #o_SoundChannel_xpi] + str r0, [r4, o_SoundChannel_xpi] mov r1, 0x21 mul r2, r1, r0 - ldr r1, [r4, #o_SoundChannel_wav] + ldr r1, [r4, o_SoundChannel_wav] add r2, r2, r1 add r2, r2, 0x10 ldr r5, =gUnknown_03001300 @@ -749,7 +749,7 @@ _081DD5E2: ply_fine: push {r4,r5,lr} adds r5, r1, 0 - ldr r4, [r5, #o_MusicPlayerTrack_chan] + ldr r4, [r5, o_MusicPlayerTrack_chan] cmp r4, 0 beq ply_fine_done ply_fine_loop: @@ -830,7 +830,7 @@ _081DD64A: ply_goto: push {lr} ply_goto_1: - ldr r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r0, [r2, 0x3] lsls r0, 8 ldrb r3, [r2, 0x2] @@ -841,24 +841,24 @@ ply_goto_1: lsls r0, 8 bl ldrb_r3_r2 orrs r0, r3 - str r0, [r1, #o_MusicPlayerTrack_cmdPtr] + str r0, [r1, o_MusicPlayerTrack_cmdPtr] pop {r0} bx r0 thumb_func_end ply_goto thumb_func_start ply_patt ply_patt: - ldrb r2, [r1, #o_MusicPlayerTrack_patternLevel] + ldrb r2, [r1, o_MusicPlayerTrack_patternLevel] cmp r2, 3 bhs ply_patt_done lsls r2, 2 adds r3, r1, r2 - ldr r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] adds r2, 0x4 - str r2, [r3, #o_MusicPlayerTrack_patternStack] - ldrb r2, [r1, #o_MusicPlayerTrack_patternLevel] + str r2, [r3, o_MusicPlayerTrack_patternStack] + ldrb r2, [r1, o_MusicPlayerTrack_patternLevel] adds r2, 1 - strb r2, [r1, #o_MusicPlayerTrack_patternLevel] + strb r2, [r1, o_MusicPlayerTrack_patternLevel] b ply_goto ply_patt_done: b ply_fine @@ -866,15 +866,15 @@ ply_patt_done: thumb_func_start ply_pend ply_pend: - ldrb r2, [r1, #o_MusicPlayerTrack_patternLevel] + ldrb r2, [r1, o_MusicPlayerTrack_patternLevel] cmp r2, 0 beq ply_pend_done subs r2, 1 - strb r2, [r1, #o_MusicPlayerTrack_patternLevel] + strb r2, [r1, o_MusicPlayerTrack_patternLevel] lsls r2, 2 adds r3, r1, r2 - ldr r2, [r3, #o_MusicPlayerTrack_patternStack] - str r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r3, o_MusicPlayerTrack_patternStack] + str r2, [r1, o_MusicPlayerTrack_cmdPtr] ply_pend_done: bx lr thumb_func_end ply_pend @@ -882,17 +882,17 @@ ply_pend_done: thumb_func_start ply_rept ply_rept: push {lr} - ldr r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r3, [r2] cmp r3, 0 bne ply_rept_1 adds r2, 1 - str r2, [r1, #o_MusicPlayerTrack_cmdPtr] + str r2, [r1, o_MusicPlayerTrack_cmdPtr] b ply_goto_1 ply_rept_1: - ldrb r3, [r1, #o_MusicPlayerTrack_repN] + ldrb r3, [r1, o_MusicPlayerTrack_repN] adds r3, 1 - strb r3, [r1, #o_MusicPlayerTrack_repN] + strb r3, [r1, o_MusicPlayerTrack_repN] mov r12, r3 bl ld_r3_tp_adr_i cmp r12, r3 @@ -900,9 +900,9 @@ ply_rept_1: b ply_goto_1 ply_rept_2: movs r3, 0 - strb r3, [r1, #o_MusicPlayerTrack_repN] + strb r3, [r1, o_MusicPlayerTrack_repN] adds r2, 5 - str r2, [r1, #o_MusicPlayerTrack_cmdPtr] + str r2, [r1, o_MusicPlayerTrack_cmdPtr] pop {r0} bx r0 thumb_func_end ply_rept @@ -911,7 +911,7 @@ ply_rept_2: ply_prio: mov r12, lr bl ld_r3_tp_adr_i - strb r3, [r1, #o_MusicPlayerTrack_priority] + strb r3, [r1, o_MusicPlayerTrack_priority] bx r12 thumb_func_end ply_prio @@ -920,11 +920,11 @@ ply_tempo: mov r12, lr bl ld_r3_tp_adr_i lsls r3, 1 - strh r3, [r0, #o_MusicPlayerInfo_tempoD] - ldrh r2, [r0, #o_MusicPlayerInfo_tempoU] + strh r3, [r0, o_MusicPlayerInfo_tempoD] + ldrh r2, [r0, o_MusicPlayerInfo_tempoU] muls r3, r2 lsrs r3, 8 - strh r3, [r0, #o_MusicPlayerInfo_tempoI] + strh r3, [r0, o_MusicPlayerInfo_tempoI] bx r12 thumb_func_end ply_tempo @@ -932,35 +932,35 @@ ply_tempo: ply_keysh: mov r12, lr bl ld_r3_tp_adr_i - strb r3, [r1, #o_MusicPlayerTrack_keyShift] - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_keyShift] + ldrb r3, [r1, o_MusicPlayerTrack_flags] movs r2, 0xC orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 thumb_func_end ply_keysh thumb_func_start ply_voice ply_voice: mov r12, lr - ldr r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r3, [r2] adds r2, 1 - str r2, [r1, #o_MusicPlayerTrack_cmdPtr] + str r2, [r1, o_MusicPlayerTrack_cmdPtr] lsls r2, r3, 1 adds r2, r3 lsls r2, 2 - ldr r3, [r0, #o_MusicPlayerInfo_tone] + ldr r3, [r0, o_MusicPlayerInfo_tone] adds r2, r3 ldr r3, [r2] bl chk_adr_r2 - str r3, [r1, #o_MusicPlayerTrack_ToneData_type] + str r3, [r1, o_MusicPlayerTrack_ToneData_type] ldr r3, [r2, 0x4] bl chk_adr_r2 - str r3, [r1, #o_MusicPlayerTrack_ToneData_wav] + str r3, [r1, o_MusicPlayerTrack_ToneData_wav] ldr r3, [r2, 0x8] bl chk_adr_r2 - str r3, [r1, #o_MusicPlayerTrack_ToneData_attack] + str r3, [r1, o_MusicPlayerTrack_ToneData_attack] bx r12 thumb_func_end ply_voice @@ -968,11 +968,11 @@ ply_voice: ply_vol: mov r12, lr bl ld_r3_tp_adr_i - strb r3, [r1, #o_MusicPlayerTrack_vol] - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_vol] + ldrb r3, [r1, o_MusicPlayerTrack_flags] movs r2, 0x3 orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 thumb_func_end ply_vol @@ -981,11 +981,11 @@ ply_pan: mov r12, lr bl ld_r3_tp_adr_i subs r3, 0x40 - strb r3, [r1, #o_MusicPlayerTrack_pan] - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_pan] + ldrb r3, [r1, o_MusicPlayerTrack_flags] movs r2, 0x3 orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 thumb_func_end ply_pan @@ -994,11 +994,11 @@ ply_bend: mov r12, lr bl ld_r3_tp_adr_i subs r3, 0x40 - strb r3, [r1, #o_MusicPlayerTrack_bend] - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_bend] + ldrb r3, [r1, o_MusicPlayerTrack_flags] movs r2, 0xC orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 thumb_func_end ply_bend @@ -1006,11 +1006,11 @@ ply_bend: ply_bendr: mov r12, lr bl ld_r3_tp_adr_i - strb r3, [r1, #o_MusicPlayerTrack_bendRange] - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_bendRange] + ldrb r3, [r1, o_MusicPlayerTrack_flags] movs r2, 0xC orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 thumb_func_end ply_bendr @@ -1018,7 +1018,7 @@ ply_bendr: ply_lfodl: mov r12, lr bl ld_r3_tp_adr_i - strb r3, [r1, #o_MusicPlayerTrack_lfoDelay] + strb r3, [r1, o_MusicPlayerTrack_lfoDelay] bx r12 thumb_func_end ply_lfodl @@ -1026,14 +1026,14 @@ ply_lfodl: ply_modt: mov r12, lr bl ld_r3_tp_adr_i - ldrb r0, [r1, #o_MusicPlayerTrack_modT] + ldrb r0, [r1, o_MusicPlayerTrack_modT] cmp r0, r3 beq _081DD7AA - strb r3, [r1, #o_MusicPlayerTrack_modT] - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_modT] + ldrb r3, [r1, o_MusicPlayerTrack_flags] movs r2, 0xF orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] _081DD7AA: bx r12 thumb_func_end ply_modt @@ -1043,18 +1043,18 @@ ply_tune: mov r12, lr bl ld_r3_tp_adr_i subs r3, 0x40 - strb r3, [r1, #o_MusicPlayerTrack_tune] - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_tune] + ldrb r3, [r1, o_MusicPlayerTrack_flags] movs r2, 0xC orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] bx r12 thumb_func_end ply_tune thumb_func_start ply_port ply_port: mov r12, lr - ldr r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r3, [r2] adds r2, 1 ldr r0, =REG_SOUND1CNT_L @ sound register base address @@ -1072,20 +1072,20 @@ m4aSoundVSync: @ Exit the function if ident is not ID_NUMBER or ID_NUMBER+1. ldr r2, lt2_ID_NUMBER - ldr r3, [r0, #o_SoundInfo_ident] + ldr r3, [r0, o_SoundInfo_ident] subs r3, r2 cmp r3, 1 bhi m4aSoundVSync_Done @ Decrement the PCM DMA counter. If it reaches 0, we need to do a DMA. - ldrb r1, [r0, #o_SoundInfo_pcmDmaCounter] + ldrb r1, [r0, o_SoundInfo_pcmDmaCounter] subs r1, 1 - strb r1, [r0, #o_SoundInfo_pcmDmaCounter] + strb r1, [r0, o_SoundInfo_pcmDmaCounter] bgt m4aSoundVSync_Done @ Reload the PCM DMA counter. - ldrb r1, [r0, #o_SoundInfo_pcmDmaPeriod] - strb r1, [r0, #o_SoundInfo_pcmDmaCounter] + ldrb r1, [r0, o_SoundInfo_pcmDmaPeriod] + strb r1, [r0, o_SoundInfo_pcmDmaCounter] ldr r2, =REG_DMA1 @@ -1127,18 +1127,18 @@ m4aSoundVSync_Done: thumb_func_start MPlayMain MPlayMain: ldr r2, lt2_ID_NUMBER - ldr r3, [r0, #o_MusicPlayerInfo_ident] + ldr r3, [r0, o_MusicPlayerInfo_ident] cmp r2, r3 beq _081DD82E bx lr _081DD82E: adds r3, 0x1 - str r3, [r0, #o_MusicPlayerInfo_ident] + str r3, [r0, o_MusicPlayerInfo_ident] push {r0,lr} - ldr r3, [r0, #o_MusicPlayerInfo_func] + ldr r3, [r0, o_MusicPlayerInfo_func] cmp r3, 0 beq _081DD840 - ldr r0, [r0, #o_MusicPlayerInfo_intp] + ldr r0, [r0, o_MusicPlayerInfo_intp] bl call_r3 _081DD840: pop {r0} @@ -1149,7 +1149,7 @@ _081DD840: mov r7, r11 push {r4-r7} adds r7, r0, 0 - ldr r0, [r7, #o_MusicPlayerInfo_status] + ldr r0, [r7, o_MusicPlayerInfo_status] cmp r0, 0 bge _081DD858 b _081DDA6C @@ -1159,18 +1159,18 @@ _081DD858: mov r8, r0 adds r0, r7, 0 bl FadeOutBody - ldr r0, [r7, #o_MusicPlayerInfo_status] + ldr r0, [r7, o_MusicPlayerInfo_status] cmp r0, 0 bge _081DD86C b _081DDA6C _081DD86C: - ldrh r0, [r7, #o_MusicPlayerInfo_tempoC] - ldrh r1, [r7, #o_MusicPlayerInfo_tempoI] + ldrh r0, [r7, o_MusicPlayerInfo_tempoC] + ldrh r1, [r7, o_MusicPlayerInfo_tempoI] adds r0, r1 b _081DD9BC _081DD874: - ldrb r6, [r7, #o_MusicPlayerInfo_trackCount] - ldr r5, [r7, #o_MusicPlayerInfo_tracks] + ldrb r6, [r7, o_MusicPlayerInfo_trackCount] + ldr r5, [r7, o_MusicPlayerInfo_tracks] movs r3, 0x1 movs r4, 0 _081DD87C: @@ -1183,7 +1183,7 @@ _081DD886: mov r10, r3 orrs r4, r3 mov r11, r4 - ldr r4, [r5, #o_MusicPlayerTrack_chan] + ldr r4, [r5, o_MusicPlayerTrack_chan] cmp r4, 0 beq _081DD8BA _081DD892: @@ -1209,7 +1209,7 @@ _081DD8B4: cmp r4, 0 bne _081DD892 _081DD8BA: - ldrb r3, [r5, #o_MusicPlayerTrack_flags] + ldrb r3, [r5, o_MusicPlayerTrack_flags] movs r0, 0x40 tst r0, r3 beq _081DD938 @@ -1218,33 +1218,33 @@ _081DD8BA: movs r0, 0x80 strb r0, [r5] movs r0, 0x2 - strb r0, [r5, #o_MusicPlayerTrack_bendRange] + strb r0, [r5, o_MusicPlayerTrack_bendRange] movs r0, 0x40 - strb r0, [r5, #o_MusicPlayerTrack_volX] + strb r0, [r5, o_MusicPlayerTrack_volX] movs r0, 0x16 - strb r0, [r5, #o_MusicPlayerTrack_lfoSpeed] + strb r0, [r5, o_MusicPlayerTrack_lfoSpeed] movs r0, 0x1 adds r1, r5, 0x6 - strb r0, [r1, #o_MusicPlayerTrack_ToneData_type - 0x6] + strb r0, [r1, o_MusicPlayerTrack_ToneData_type - 0x6] b _081DD938 _081DD8E0: - ldr r2, [r5, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r5, o_MusicPlayerTrack_cmdPtr] ldrb r1, [r2] cmp r1, 0x80 bhs _081DD8EC - ldrb r1, [r5, #o_MusicPlayerTrack_runningStatus] + ldrb r1, [r5, o_MusicPlayerTrack_runningStatus] b _081DD8F6 _081DD8EC: adds r2, 0x1 - str r2, [r5, #o_MusicPlayerTrack_cmdPtr] + str r2, [r5, o_MusicPlayerTrack_cmdPtr] cmp r1, 0xBD bcc _081DD8F6 - strb r1, [r5, #o_MusicPlayerTrack_runningStatus] + strb r1, [r5, o_MusicPlayerTrack_runningStatus] _081DD8F6: cmp r1, 0xCF bcc _081DD90C mov r0, r8 - ldr r3, [r0, #o_SoundInfo_plynote] + ldr r3, [r0, o_SoundInfo_plynote] adds r0, r1, 0 subs r0, 0xCF adds r1, r7, 0 @@ -1256,15 +1256,15 @@ _081DD90C: bls _081DD92E adds r0, r1, 0 subs r0, 0xB1 - strb r0, [r7, #o_MusicPlayerInfo_cmd] + strb r0, [r7, o_MusicPlayerInfo_cmd] mov r3, r8 - ldr r3, [r3, #o_SoundInfo_MPlayJumpTable] + ldr r3, [r3, o_SoundInfo_MPlayJumpTable] lsls r0, 2 ldr r3, [r3, r0] adds r0, r7, 0 adds r1, r5, 0 bl call_r3 - ldrb r0, [r5, #o_MusicPlayerTrack_flags] + ldrb r0, [r5, o_MusicPlayerTrack_flags] cmp r0, 0 beq _081DD994 b _081DD938 @@ -1273,29 +1273,29 @@ _081DD92E: subs r1, 0x80 adds r1, r0 ldrb r0, [r1] - strb r0, [r5, #o_MusicPlayerTrack_wait] + strb r0, [r5, o_MusicPlayerTrack_wait] _081DD938: - ldrb r0, [r5, #o_MusicPlayerTrack_wait] + ldrb r0, [r5, o_MusicPlayerTrack_wait] cmp r0, 0 beq _081DD8E0 subs r0, 0x1 - strb r0, [r5, #o_MusicPlayerTrack_wait] - ldrb r1, [r5, #o_MusicPlayerTrack_lfoSpeed] + strb r0, [r5, o_MusicPlayerTrack_wait] + ldrb r1, [r5, o_MusicPlayerTrack_lfoSpeed] cmp r1, 0 beq _081DD994 - ldrb r0, [r5, #o_MusicPlayerTrack_mod] + ldrb r0, [r5, o_MusicPlayerTrack_mod] cmp r0, 0 beq _081DD994 - ldrb r0, [r5, #o_MusicPlayerTrack_lfoDelayC] + ldrb r0, [r5, o_MusicPlayerTrack_lfoDelayC] cmp r0, 0 beq _081DD95A subs r0, 0x1 - strb r0, [r5, #o_MusicPlayerTrack_lfoDelayC] + strb r0, [r5, o_MusicPlayerTrack_lfoDelayC] b _081DD994 _081DD95A: - ldrb r0, [r5, #o_MusicPlayerTrack_lfoSpeedC] + ldrb r0, [r5, o_MusicPlayerTrack_lfoSpeedC] adds r0, r1 - strb r0, [r5, #o_MusicPlayerTrack_lfoSpeedC] + strb r0, [r5, o_MusicPlayerTrack_lfoSpeedC] adds r1, r0, 0 subs r0, 0x40 lsls r0, 24 @@ -1307,16 +1307,16 @@ _081DD96E: movs r0, 0x80 subs r2, r0, r1 _081DD972: - ldrb r0, [r5, #o_MusicPlayerTrack_mod] + ldrb r0, [r5, o_MusicPlayerTrack_mod] muls r0, r2 asrs r2, r0, 6 - ldrb r0, [r5, #o_MusicPlayerTrack_modM] + ldrb r0, [r5, o_MusicPlayerTrack_modM] eors r0, r2 lsls r0, 24 beq _081DD994 - strb r2, [r5, #o_MusicPlayerTrack_modM] + strb r2, [r5, o_MusicPlayerTrack_modM] ldrb r0, [r5] - ldrb r1, [r5, #o_MusicPlayerTrack_modT] + ldrb r1, [r5, o_MusicPlayerTrack_modT] cmp r1, 0 bne _081DD98E movs r1, 0xC @@ -1325,7 +1325,7 @@ _081DD98E: movs r1, 0x3 _081DD990: orrs r0, r1 - strb r0, [r5, #o_MusicPlayerTrack_flags] + strb r0, [r5, o_MusicPlayerTrack_flags] _081DD994: mov r3, r10 mov r4, r11 @@ -1337,29 +1337,29 @@ _081DD998: lsls r3, 1 b _081DD87C _081DD9A4: - ldr r0, [r7, #o_MusicPlayerInfo_clock] + ldr r0, [r7, o_MusicPlayerInfo_clock] adds r0, 0x1 - str r0, [r7, #o_MusicPlayerInfo_clock] + str r0, [r7, o_MusicPlayerInfo_clock] cmp r4, 0 bne _081DD9B6 movs r0, 0x80 lsls r0, 24 - str r0, [r7, #o_MusicPlayerInfo_status] + str r0, [r7, o_MusicPlayerInfo_status] b _081DDA6C _081DD9B6: - str r4, [r7, #o_MusicPlayerInfo_status] - ldrh r0, [r7, #o_MusicPlayerInfo_tempoC] + str r4, [r7, o_MusicPlayerInfo_status] + ldrh r0, [r7, o_MusicPlayerInfo_tempoC] subs r0, 0x96 _081DD9BC: - strh r0, [r7, #o_MusicPlayerInfo_tempoC] + strh r0, [r7, o_MusicPlayerInfo_tempoC] cmp r0, 0x96 bcc _081DD9C4 b _081DD874 _081DD9C4: - ldrb r2, [r7, #o_MusicPlayerInfo_trackCount] - ldr r5, [r7, #o_MusicPlayerInfo_tracks] + ldrb r2, [r7, o_MusicPlayerInfo_trackCount] + ldr r5, [r7, o_MusicPlayerInfo_tracks] _081DD9C8: - ldrb r0, [r5, #o_MusicPlayerTrack_flags] + ldrb r0, [r5, o_MusicPlayerTrack_flags] movs r1, 0x80 tst r1, r0 beq _081DDA62 @@ -1370,11 +1370,11 @@ _081DD9C8: adds r0, r7, 0 adds r1, r5, 0 bl TrkVolPitSet - ldr r4, [r5, #o_MusicPlayerTrack_chan] + ldr r4, [r5, o_MusicPlayerTrack_chan] cmp r4, 0 beq _081DDA58 _081DD9E6: - ldrb r1, [r4, #o_SoundChannel_status] + ldrb r1, [r4, o_SoundChannel_status] movs r0, 0xC7 tst r0, r1 bne _081DD9F6 @@ -1382,26 +1382,26 @@ _081DD9E6: bl ClearChain b _081DDA52 _081DD9F6: - ldrb r0, [r4, #o_SoundChannel_type] + ldrb r0, [r4, o_SoundChannel_type] movs r6, 0x7 ands r6, r0 - ldrb r3, [r5, #o_MusicPlayerTrack_flags] + ldrb r3, [r5, o_MusicPlayerTrack_flags] movs r0, 0x3 tst r0, r3 beq _081DDA14 bl ChnVolSetAsm cmp r6, 0 beq _081DDA14 - ldrb r0, [r4, #o_CgbChannel_mo] + ldrb r0, [r4, o_CgbChannel_mo] movs r1, 0x1 orrs r0, r1 - strb r0, [r4, #o_CgbChannel_mo] + strb r0, [r4, o_CgbChannel_mo] _081DDA14: - ldrb r3, [r5, #o_MusicPlayerTrack_flags] + ldrb r3, [r5, o_MusicPlayerTrack_flags] movs r0, 0xC tst r0, r3 beq _081DDA52 - ldrb r1, [r4, #o_SoundChannel_ky] + ldrb r1, [r4, o_SoundChannel_ky] movs r0, 0x8 ldrsb r0, [r5, r0] adds r2, r1, r0 @@ -1411,32 +1411,32 @@ _081DDA28: cmp r6, 0 beq _081DDA46 mov r0, r8 - ldr r3, [r0, #o_SoundInfo_MidiKeyToCgbFreq] + ldr r3, [r0, o_SoundInfo_MidiKeyToCgbFreq] adds r1, r2, 0 - ldrb r2, [r5, #o_MusicPlayerTrack_pitM] + ldrb r2, [r5, o_MusicPlayerTrack_pitM] adds r0, r6, 0 bl call_r3 - str r0, [r4, #o_CgbChannel_fr] - ldrb r0, [r4, #o_CgbChannel_mo] + str r0, [r4, o_CgbChannel_fr] + ldrb r0, [r4, o_CgbChannel_mo] movs r1, 0x2 orrs r0, r1 - strb r0, [r4, #o_CgbChannel_mo] + strb r0, [r4, o_CgbChannel_mo] b _081DDA52 _081DDA46: adds r1, r2, 0 - ldrb r2, [r5, #o_MusicPlayerTrack_pitM] - ldr r0, [r4, #o_SoundChannel_wav] + ldrb r2, [r5, o_MusicPlayerTrack_pitM] + ldr r0, [r4, o_SoundChannel_wav] bl MidiKeyToFreq - str r0, [r4, #o_SoundChannel_freq] + str r0, [r4, o_SoundChannel_freq] _081DDA52: - ldr r4, [r4, #o_SoundChannel_np] + ldr r4, [r4, o_SoundChannel_np] cmp r4, 0 bne _081DD9E6 _081DDA58: - ldrb r0, [r5, #o_MusicPlayerTrack_flags] + ldrb r0, [r5, o_MusicPlayerTrack_flags] movs r1, 0xF0 ands r0, r1 - strb r0, [r5, #o_MusicPlayerTrack_flags] + strb r0, [r5, o_MusicPlayerTrack_flags] mov r2, r9 _081DDA62: subs r2, 0x1 @@ -1446,7 +1446,7 @@ _081DDA62: bgt _081DD9C8 _081DDA6C: ldr r0, lt2_ID_NUMBER - str r0, [r7, #o_MusicPlayerInfo_ident] + str r0, [r7, o_MusicPlayerInfo_ident] pop {r0-r7} mov r8, r0 mov r9, r1 @@ -1467,35 +1467,35 @@ lt2_ID_NUMBER: .word ID_NUMBER TrackStop: push {r4-r6,lr} adds r5, r1, 0 - ldrb r1, [r5, #o_MusicPlayerTrack_flags] + ldrb r1, [r5, o_MusicPlayerTrack_flags] movs r0, 0x80 tst r0, r1 beq TrackStop_Done - ldr r4, [r5, #o_MusicPlayerTrack_chan] + ldr r4, [r5, o_MusicPlayerTrack_chan] cmp r4, 0 beq TrackStop_3 movs r6, 0 TrackStop_Loop: - ldrb r0, [r4, #o_SoundChannel_status] + ldrb r0, [r4, o_SoundChannel_status] cmp r0, 0 beq TrackStop_2 - ldrb r0, [r4, #o_SoundChannel_type] + ldrb r0, [r4, o_SoundChannel_type] movs r3, 0x7 ands r0, r3 beq TrackStop_1 ldr r3, =SOUND_INFO_PTR ldr r3, [r3] - ldr r3, [r3, #o_SoundInfo_CgbOscOff] + ldr r3, [r3, o_SoundInfo_CgbOscOff] bl call_r3 TrackStop_1: - strb r6, [r4, #o_SoundChannel_status] + strb r6, [r4, o_SoundChannel_status] TrackStop_2: - str r6, [r4, #o_SoundChannel_track] - ldr r4, [r4, #o_SoundChannel_np] + str r6, [r4, o_SoundChannel_track] + ldr r4, [r4, o_SoundChannel_np] cmp r4, 0 bne TrackStop_Loop TrackStop_3: - str r4, [r5, #o_MusicPlayerTrack_chan] + str r4, [r5, o_MusicPlayerTrack_chan] TrackStop_Done: pop {r4-r6} pop {r0} @@ -1550,41 +1550,41 @@ ply_note: ldr r1, =gClockTable adds r0, r1 ldrb r0, [r0] - strb r0, [r5, #o_MusicPlayerTrack_gateTime] - ldr r3, [r5, #o_MusicPlayerTrack_cmdPtr] + strb r0, [r5, o_MusicPlayerTrack_gateTime] + ldr r3, [r5, o_MusicPlayerTrack_cmdPtr] ldrb r0, [r3] cmp r0, 0x80 bhs _081DDB46 - strb r0, [r5, #o_MusicPlayerTrack_key] + strb r0, [r5, o_MusicPlayerTrack_key] adds r3, 0x1 ldrb r0, [r3] cmp r0, 0x80 bhs _081DDB44 - strb r0, [r5, #o_MusicPlayerTrack_velocity] + strb r0, [r5, o_MusicPlayerTrack_velocity] adds r3, 0x1 ldrb r0, [r3] cmp r0, 0x80 bhs _081DDB44 - ldrb r1, [r5, #o_MusicPlayerTrack_gateTime] + ldrb r1, [r5, o_MusicPlayerTrack_gateTime] adds r1, r0 - strb r1, [r5, #o_MusicPlayerTrack_gateTime] + strb r1, [r5, o_MusicPlayerTrack_gateTime] adds r3, 0x1 _081DDB44: - str r3, [r5, #o_MusicPlayerTrack_cmdPtr] + str r3, [r5, o_MusicPlayerTrack_cmdPtr] _081DDB46: movs r0, 0 str r0, [sp, 0x14] adds r4, r5, 0 - adds r4, #o_MusicPlayerTrack_ToneData_type + adds r4, o_MusicPlayerTrack_ToneData_type ldrb r2, [r4] movs r0, TONEDATA_TYPE_RHY | TONEDATA_TYPE_SPL tst r0, r2 beq _081DDB98 - ldrb r3, [r5, #o_MusicPlayerTrack_key] + ldrb r3, [r5, o_MusicPlayerTrack_key] movs r0, TONEDATA_TYPE_SPL tst r0, r2 beq _081DDB66 - ldr r1, [r5, #o_MusicPlayerTrack_ToneData_keySplitTable] + ldr r1, [r5, o_MusicPlayerTrack_ToneData_keySplitTable] adds r1, r3 ldrb r0, [r1] b _081DDB68 @@ -1594,7 +1594,7 @@ _081DDB68: lsls r1, r0, 1 adds r1, r0 lsls r1, 2 - ldr r0, [r5, #o_MusicPlayerTrack_ToneData_wav] + ldr r0, [r5, o_MusicPlayerTrack_ToneData_wav] adds r1, r0 mov r9, r1 mov r6, r9 @@ -1787,7 +1787,7 @@ _081DDCBC: bl call_r3 b _081DDCDC _081DDCCE: - ldr r0, [r5, #o_MusicPlayerTrack_unk_3C] + ldr r0, [r5, o_MusicPlayerTrack_unk_3C] str r0, [r4, 0x18] ldrb r2, [r5, 0x9] adds r1, r3, 0 @@ -1816,37 +1816,37 @@ _081DDCEA: thumb_func_start ply_endtie ply_endtie: push {r4,r5} - ldr r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r3, [r2] cmp r3, 0x80 bhs _081DDD16 - strb r3, [r1, #o_MusicPlayerTrack_key] + strb r3, [r1, o_MusicPlayerTrack_key] adds r2, 0x1 - str r2, [r1, #o_MusicPlayerTrack_cmdPtr] + str r2, [r1, o_MusicPlayerTrack_cmdPtr] b _081DDD18 _081DDD16: - ldrb r3, [r1, #o_MusicPlayerTrack_key] + ldrb r3, [r1, o_MusicPlayerTrack_key] _081DDD18: - ldr r1, [r1, #o_MusicPlayerTrack_chan] + ldr r1, [r1, o_MusicPlayerTrack_chan] cmp r1, 0 beq _081DDD40 movs r4, 0x83 movs r5, 0x40 _081DDD22: - ldrb r2, [r1, #o_SoundChannel_status] + ldrb r2, [r1, o_SoundChannel_status] tst r2, r4 beq _081DDD3A tst r2, r5 bne _081DDD3A - ldrb r0, [r1, #o_SoundChannel_mk] + ldrb r0, [r1, o_SoundChannel_mk] cmp r0, r3 bne _081DDD3A movs r0, 0x40 orrs r2, r0 - strb r2, [r1, #o_SoundChannel_status] + strb r2, [r1, o_SoundChannel_status] b _081DDD40 _081DDD3A: - ldr r1, [r1, #o_SoundChannel_np] + ldr r1, [r1, o_SoundChannel_np] cmp r1, 0 bne _081DDD22 _081DDD40: @@ -1857,9 +1857,9 @@ _081DDD40: thumb_func_start clear_modM clear_modM: movs r2, 0 - strb r2, [r1, #o_MusicPlayerTrack_modM] - strb r2, [r1, #o_MusicPlayerTrack_lfoSpeedC] - ldrb r2, [r1, #o_MusicPlayerTrack_modT] + strb r2, [r1, o_MusicPlayerTrack_modM] + strb r2, [r1, o_MusicPlayerTrack_lfoSpeedC] + ldrb r2, [r1, o_MusicPlayerTrack_modT] cmp r2, 0 bne _081DDD54 movs r2, 0xC @@ -1867,17 +1867,17 @@ clear_modM: _081DDD54: movs r2, 0x3 _081DDD56: - ldrb r3, [r1, #o_MusicPlayerTrack_flags] + ldrb r3, [r1, o_MusicPlayerTrack_flags] orrs r3, r2 - strb r3, [r1, #o_MusicPlayerTrack_flags] + strb r3, [r1, o_MusicPlayerTrack_flags] bx lr thumb_func_end clear_modM thumb_func_start ld_r3_tp_adr_i ld_r3_tp_adr_i_unchecked: - ldr r2, [r1, #o_MusicPlayerTrack_cmdPtr] + ldr r2, [r1, o_MusicPlayerTrack_cmdPtr] adds r3, r2, 1 - str r3, [r1, #o_MusicPlayerTrack_cmdPtr] + str r3, [r1, o_MusicPlayerTrack_cmdPtr] ldrb r3, [r2] bx lr thumb_func_end ld_r3_tp_adr_i @@ -1886,7 +1886,7 @@ ld_r3_tp_adr_i_unchecked: ply_lfos: mov r12, lr bl ld_r3_tp_adr_i_unchecked - strb r3, [r1, #o_MusicPlayerTrack_lfoSpeed] + strb r3, [r1, o_MusicPlayerTrack_lfoSpeed] cmp r3, 0 bne _081DDD7C bl clear_modM @@ -1898,7 +1898,7 @@ _081DDD7C: ply_mod: mov r12, lr bl ld_r3_tp_adr_i_unchecked - strb r3, [r1, #o_MusicPlayerTrack_mod] + strb r3, [r1, o_MusicPlayerTrack_mod] cmp r3, 0 bne _081DDD90 bl clear_modM diff --git a/src/m4a_tables.c b/src/m4a_tables.c index dfd285b1f..9a4ea32e6 100644 --- a/src/m4a_tables.c +++ b/src/m4a_tables.c @@ -83,7 +83,7 @@ const u8 gScaleTable[] = 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, }; -const u32 gFreqTable[12] = +const u32 gFreqTable[] = { 2147483648u, 2275179671u, @@ -99,7 +99,7 @@ const u32 gFreqTable[12] = 4053909305u, }; -const u16 gPcmSamplesPerVBlankTable[12] = +const u16 gPcmSamplesPerVBlankTable[] = { 96, 132, @@ -130,7 +130,7 @@ const u8 gCgbScaleTable[] = 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, }; -const s16 gCgbFreqTable[12] = +const s16 gCgbFreqTable[] = { -2004, -1891, diff --git a/src/mail.c b/src/mail.c index 55bc9ed00..0fc62678a 100644 --- a/src/mail.c +++ b/src/mail.c @@ -525,7 +525,7 @@ static void CB2_WaitForPaletteExitOnKeyPress(void) static void CB2_ExitOnKeyPress(void) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); sMailRead->callback2 = CB2_ExitMailReadFreeVars; diff --git a/src/main.c b/src/main.c index b3b76b1fb..454fefc5c 100644 --- a/src/main.c +++ b/src/main.c @@ -81,6 +81,8 @@ void InitIntrHandlers(void); static void WaitForVBlank(void); void EnableVCountIntrAtLine150(void); +#define B_START_SELECT (B_BUTTON | START_BUTTON | SELECT_BUTTON) + void AgbMain() { #if MODERN @@ -134,11 +136,9 @@ void AgbMain() { ReadKeys(); - if (!gSoftResetDisabled - && JOY_HELD_RAW(A_BUTTON) - && JOY_HELD_RAW(B_BUTTON) - && JOY_HELD_RAW(START_BUTTON) - && JOY_HELD_RAW(SELECT_BUTTON)) //The reset key combo A + B + START + SELECT + if (gSoftResetDisabled == FALSE + && (gMain.heldKeysRaw & A_BUTTON) + && (gMain.heldKeysRaw & B_START_SELECT) == B_START_SELECT) { rfu_REQ_stopMode(); rfu_waitREQComplete(); @@ -262,7 +262,9 @@ static void ReadKeys(void) if (keyInput != 0 && gMain.heldKeys == keyInput) { - if (--gMain.keyRepeatCounter == 0) + gMain.keyRepeatCounter--; + + if (gMain.keyRepeatCounter == 0) { gMain.newAndRepeatedKeys = keyInput; gMain.keyRepeatCounter = gKeyRepeatContinueDelay; @@ -280,10 +282,10 @@ static void ReadKeys(void) // Remap L to A if the L=A option is enabled. if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) { - if (JOY_NEW(L_BUTTON)) + if (gMain.newKeys & L_BUTTON) gMain.newKeys |= A_BUTTON; - if (JOY_HELD(L_BUTTON)) + if (gMain.heldKeys & L_BUTTON) gMain.heldKeys |= A_BUTTON; } @@ -341,7 +343,7 @@ static void VBlankIntr(void) { if (gWirelessCommType != 0) RfuVSync(); - else if (!gLinkVSyncDisabled) + else if (gLinkVSyncDisabled == FALSE) LinkVSync(); gMain.vblankCounter1++; diff --git a/src/main_menu.c b/src/main_menu.c index e8403cdb1..f4bf37ce1 100644 --- a/src/main_menu.c +++ b/src/main_menu.c @@ -696,7 +696,7 @@ static void Task_MainMenuCheckSaveFile(u8 taskId) static void Task_WaitForSaveFileErrorWindow(u8 taskId) { RunTextPrinters(); - if (!IsTextPrinterActive(7) && (JOY_NEW(A_BUTTON))) + if (!IsTextPrinterActive(7) && (gMain.newKeys & A_BUTTON)) { ClearWindowTilemap(7); ClearMainMenuWindowTilemap(&sWindowTemplates_MainMenu[7]); @@ -731,7 +731,7 @@ static void Task_MainMenuCheckBattery(u8 taskId) static void Task_WaitForBatteryDryErrorWindow(u8 taskId) { RunTextPrinters(); - if (!IsTextPrinterActive(7) && (JOY_NEW(A_BUTTON))) + if (!IsTextPrinterActive(7) && (gMain.newKeys & A_BUTTON)) { ClearWindowTilemap(7); ClearMainMenuWindowTilemap(&sWindowTemplates_MainMenu[7]); @@ -887,14 +887,14 @@ static bool8 HandleMainMenuInput(u8 taskId) { s16* data = gTasks[taskId].data; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); IsWirelessAdapterConnected(); // why bother calling this here? debug? Task_HandleMainMenuAPressed will check too BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].func = Task_HandleMainMenuAPressed; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_WHITEALPHA); @@ -902,7 +902,7 @@ static bool8 HandleMainMenuInput(u8 taskId) SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(0, 160)); gTasks[taskId].func = Task_HandleMainMenuBPressed; } - else if ((JOY_NEW(DPAD_UP)) && tCurrItem > 0) + else if ((gMain.newKeys & DPAD_UP) && tCurrItem > 0) { if (tMenuType == HAS_MYSTERY_EVENTS && tIsScrolled == TRUE && tCurrItem == 1) { @@ -914,7 +914,7 @@ static bool8 HandleMainMenuInput(u8 taskId) sCurrItemAndOptionMenuCheck = tCurrItem; return TRUE; } - else if ((JOY_NEW(DPAD_DOWN)) && tCurrItem < tItemCount - 1) + else if ((gMain.newKeys & DPAD_DOWN) && tCurrItem < tItemCount - 1) { if (tMenuType == HAS_MYSTERY_EVENTS && tCurrItem == 3 && tIsScrolled == FALSE) { @@ -1151,7 +1151,7 @@ static void Task_DisplayMainMenuInvalidActionError(u8 taskId) gTasks[taskId].tCurrItem++; break; case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); @@ -1594,7 +1594,7 @@ static void Task_NewGameBirchSpeech_WaitForWhatsYourNameToPrint(u8 taskId) static void Task_NewGameBirchSpeech_WaitPressBeforeNameChoice(u8 taskId) { - if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON))) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON)) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); gTasks[taskId].func = Task_NewGameBirchSpeech_StartNamingScreen; diff --git a/src/match_call.c b/src/match_call.c index 1899eabf0..2b3f6df8d 100644 --- a/src/match_call.c +++ b/src/match_call.c @@ -1253,7 +1253,7 @@ static bool32 sub_81962D8(u8 taskId) static bool32 sub_8196330(u8 taskId) { s16 *taskData = gTasks[taskId].data; - if (!ExecuteMatchCallTextPrinter(taskData[2]) && !IsSEPlaying() && JOY_NEW(A_BUTTON | B_BUTTON)) + if (!ExecuteMatchCallTextPrinter(taskData[2]) && !IsSEPlaying() && gMain.newKeys & (A_BUTTON | B_BUTTON)) { FillWindowPixelBuffer(taskData[2], PIXEL_FILL(8)); CopyWindowToVram(taskData[2], 2); @@ -1335,7 +1335,7 @@ static void InitMatchCallTextPrinter(int windowId, const u8 *str) printerTemplate.currentY = 1; printerTemplate.letterSpacing = 0; printerTemplate.lineSpacing = 0; - printerTemplate.style = 0; + printerTemplate.unk = 0; printerTemplate.fgColor = 10; printerTemplate.bgColor = 8; printerTemplate.shadowColor = 14; @@ -1346,7 +1346,7 @@ static void InitMatchCallTextPrinter(int windowId, const u8 *str) static bool32 ExecuteMatchCallTextPrinter(int windowId) { - if (JOY_HELD(A_BUTTON)) + if (gMain.heldKeys & A_BUTTON) gTextFlags.canABSpeedUpPrint = 1; else gTextFlags.canABSpeedUpPrint = 0; @@ -1774,7 +1774,7 @@ static int GetNumOwnedBadges(void) static bool32 sub_8196D74(int matchCallId) { int dayCount; - u32 otId; + int otId; u16 easyChatWord; int numRematchTrainersFought; int var0, var1, var2; diff --git a/src/menu.c b/src/menu.c index 9c5dec024..f3334919c 100644 --- a/src/menu.c +++ b/src/menu.c @@ -180,7 +180,7 @@ u16 AddTextPrinterParameterized2(u8 windowId, u8 fontId, const u8 *str, u8 speed printer.currentY = 1; printer.letterSpacing = 0; printer.lineSpacing = 0; - printer.style = 0; + printer.unk = 0; printer.fgColor = fgColor; printer.bgColor = bgColor; printer.shadowColor = shadowColor; @@ -981,23 +981,23 @@ u8 Menu_GetCursorPos(void) s8 Menu_ProcessInput(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (!sMenu.APressMuted) PlaySE(SE_SELECT); return sMenu.cursorPos; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { PlaySE(SE_SELECT); Menu_MoveCursor(-1); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { PlaySE(SE_SELECT); Menu_MoveCursor(1); @@ -1011,23 +1011,23 @@ s8 Menu_ProcessInputNoWrap(void) { u8 oldPos = sMenu.cursorPos; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (!sMenu.APressMuted) PlaySE(SE_SELECT); return sMenu.cursorPos; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (oldPos != Menu_MoveCursorNoWrapAround(-1)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (oldPos != Menu_MoveCursorNoWrapAround(1)) PlaySE(SE_SELECT); @@ -1039,23 +1039,23 @@ s8 Menu_ProcessInputNoWrap(void) s8 ProcessMenuInput_other(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (!sMenu.APressMuted) PlaySE(SE_SELECT); return sMenu.cursorPos; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_UP) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_UP) { PlaySE(SE_SELECT); Menu_MoveCursor(-1); return MENU_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_DOWN) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_DOWN) { PlaySE(SE_SELECT); Menu_MoveCursor(1); @@ -1069,23 +1069,23 @@ s8 Menu_ProcessInputNoWrapAround_other(void) { u8 oldPos = sMenu.cursorPos; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (!sMenu.APressMuted) PlaySE(SE_SELECT); return sMenu.cursorPos; } - if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - if (JOY_REPEAT(DPAD_ANY) == DPAD_UP) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_UP) { if (oldPos != Menu_MoveCursorNoWrapAround(-1)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - if (JOY_REPEAT(DPAD_ANY) == DPAD_DOWN) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_DOWN) { if (oldPos != Menu_MoveCursorNoWrapAround(1)) PlaySE(SE_SELECT); @@ -1130,7 +1130,7 @@ void AddItemMenuActionTextPrinters(u8 windowId, u8 fontId, u8 left, u8 top, u8 l printer.fgColor = GetFontAttribute(fontId, FONTATTR_COLOR_FOREGROUND); printer.bgColor = GetFontAttribute(fontId, FONTATTR_COLOR_BACKGROUND); printer.shadowColor = GetFontAttribute(fontId, FONTATTR_COLOR_SHADOW); - printer.style = GetFontAttribute(fontId, FONTATTR_STYLE); + printer.unk = GetFontAttribute(fontId, FONTATTR_UNKNOWN); printer.letterSpacing = letterSpacing; printer.lineSpacing = GetFontAttribute(fontId, FONTATTR_LINE_SPACING); printer.x = left; @@ -1194,7 +1194,7 @@ void sub_8198AF8(const struct WindowTemplate *window, u8 fontId, u8 left, u8 top printer.fgColor = GetFontAttribute(fontId, FONTATTR_COLOR_FOREGROUND); printer.bgColor = GetFontAttribute(fontId, FONTATTR_COLOR_BACKGROUND); printer.shadowColor = GetFontAttribute(fontId, FONTATTR_COLOR_SHADOW); - printer.style = GetFontAttribute(fontId, FONTATTR_STYLE); + printer.unk = GetFontAttribute(fontId, FONTATTR_UNKNOWN); printer.letterSpacing = GetFontAttribute(fontId, FONTATTR_LETTER_SPACING); printer.lineSpacing = GetFontAttribute(fontId, FONTATTR_LINE_SPACING); @@ -1252,7 +1252,7 @@ void sub_8198DBC(u8 windowId, u8 fontId, u8 left, u8 top, u8 a4, u8 itemCount, u printer.fgColor = GetFontAttribute(fontId, FONTATTR_COLOR_FOREGROUND); printer.bgColor = GetFontAttribute(fontId, FONTATTR_COLOR_BACKGROUND); printer.shadowColor = GetFontAttribute(fontId, FONTATTR_COLOR_SHADOW); - printer.style = GetFontAttribute(fontId, FONTATTR_STYLE); + printer.unk = GetFontAttribute(fontId, FONTATTR_UNKNOWN); printer.letterSpacing = GetFontAttribute(fontId, FONTATTR_LETTER_SPACING); printer.lineSpacing = GetFontAttribute(fontId, FONTATTR_LINE_SPACING); @@ -1407,34 +1407,34 @@ u8 ChangeGridMenuCursorPosition(s8 deltaX, s8 deltaY) s8 sub_8199284(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); return sMenu.cursorPos; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_UP); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_DOWN); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) + else if (gMain.newKeys & DPAD_LEFT || GetLRKeysPressed() == MENU_L_PRESSED) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_LEFT, MENU_CURSOR_DELTA_NONE); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) + else if (gMain.newKeys & DPAD_RIGHT || GetLRKeysPressed() == MENU_R_PRESSED) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_RIGHT, MENU_CURSOR_DELTA_NONE); @@ -1448,34 +1448,34 @@ s8 Menu_ProcessInputGridLayout(void) { u8 oldPos = sMenu.cursorPos; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); return sMenu.cursorPos; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (oldPos != ChangeGridMenuCursorPosition(0, -1)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (oldPos != ChangeGridMenuCursorPosition(0, 1)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) + else if (gMain.newKeys & DPAD_LEFT || GetLRKeysPressed() == MENU_L_PRESSED) { if (oldPos != ChangeGridMenuCursorPosition(-1, 0)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) + else if (gMain.newKeys & DPAD_RIGHT || GetLRKeysPressed() == MENU_R_PRESSED) { if (oldPos != ChangeGridMenuCursorPosition(1, 0)) PlaySE(SE_SELECT); @@ -1487,34 +1487,34 @@ s8 Menu_ProcessInputGridLayout(void) s8 sub_81993D8(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); return sMenu.cursorPos; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_UP) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_UP) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_UP); return MENU_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_DOWN) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_DOWN) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_NONE, MENU_CURSOR_DELTA_DOWN); return MENU_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_LEFT || GetLRKeysPressedAndHeld() == MENU_L_PRESSED) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_LEFT || GetLRKeysPressedAndHeld() == MENU_L_PRESSED) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_LEFT, MENU_CURSOR_DELTA_NONE); return MENU_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_RIGHT || GetLRKeysPressedAndHeld() == MENU_R_PRESSED) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_RIGHT || GetLRKeysPressedAndHeld() == MENU_R_PRESSED) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_RIGHT, MENU_CURSOR_DELTA_NONE); @@ -1529,34 +1529,34 @@ s8 sub_8199484(void) { u8 oldPos = sMenu.cursorPos; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); return sMenu.cursorPos; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return MENU_B_PRESSED; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_UP) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_UP) { if (oldPos != ChangeGridMenuCursorPosition(0, -1)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_DOWN) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_DOWN) { if (oldPos != ChangeGridMenuCursorPosition(0, 1)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_LEFT || GetLRKeysPressedAndHeld() == MENU_L_PRESSED) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_LEFT || GetLRKeysPressedAndHeld() == MENU_L_PRESSED) { if (oldPos != ChangeGridMenuCursorPosition(-1, 0)) PlaySE(SE_SELECT); return MENU_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_RIGHT || GetLRKeysPressedAndHeld() == MENU_R_PRESSED) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_RIGHT || GetLRKeysPressedAndHeld() == MENU_R_PRESSED) { if (oldPos != ChangeGridMenuCursorPosition(1, 0)) PlaySE(SE_SELECT); @@ -1616,7 +1616,7 @@ void sub_81995E4(u8 windowId, u8 itemCount, const struct MenuAction *strs, const printer.fgColor = GetFontAttribute(1, FONTATTR_COLOR_FOREGROUND); printer.bgColor = GetFontAttribute(1, FONTATTR_COLOR_BACKGROUND); printer.shadowColor = GetFontAttribute(1, FONTATTR_COLOR_SHADOW); - printer.style = GetFontAttribute(1, FONTATTR_STYLE); + printer.unk = GetFontAttribute(1, FONTATTR_UNKNOWN); printer.letterSpacing = 0; printer.lineSpacing = 0; printer.x = 8; @@ -1650,7 +1650,7 @@ void CreateYesNoMenu(const struct WindowTemplate *window, u16 baseTileNum, u8 pa printer.fgColor = GetFontAttribute(1, FONTATTR_COLOR_FOREGROUND); printer.bgColor = GetFontAttribute(1, FONTATTR_COLOR_BACKGROUND); printer.shadowColor = GetFontAttribute(1, FONTATTR_COLOR_SHADOW); - printer.style = GetFontAttribute(1, FONTATTR_STYLE); + printer.unk = GetFontAttribute(1, FONTATTR_UNKNOWN); printer.letterSpacing = 0; printer.lineSpacing = 0; @@ -1681,7 +1681,7 @@ void sub_819983C(u8 windowId, u8 a4, u8 itemCount, u8 itemCount2, const struct M printer.fgColor = GetFontAttribute(1, FONTATTR_COLOR_FOREGROUND); printer.bgColor = GetFontAttribute(1, FONTATTR_COLOR_BACKGROUND); printer.shadowColor = GetFontAttribute(1, FONTATTR_COLOR_SHADOW); - printer.style = GetFontAttribute(1, FONTATTR_STYLE); + printer.unk = GetFontAttribute(1, FONTATTR_UNKNOWN); printer.letterSpacing = 0; printer.lineSpacing = 0; @@ -1949,7 +1949,7 @@ void AddTextPrinterParameterized3(u8 windowId, u8 fontId, u8 left, u8 top, const printer.currentY = printer.y; printer.letterSpacing = GetFontAttribute(fontId, 2); printer.lineSpacing = GetFontAttribute(fontId, 3); - printer.style = 0; + printer.unk = 0; printer.fgColor = color[1]; printer.bgColor = color[0]; printer.shadowColor = color[2]; @@ -1970,7 +1970,7 @@ void AddTextPrinterParameterized4(u8 windowId, u8 fontId, u8 left, u8 top, u8 le printer.currentY = printer.y; printer.letterSpacing = letterSpacing; printer.lineSpacing = lineSpacing; - printer.style = 0; + printer.unk = 0; printer.fgColor = color[1]; printer.bgColor = color[0]; printer.shadowColor = color[2]; @@ -1991,7 +1991,7 @@ void AddTextPrinterParameterized5(u8 windowId, u8 fontId, const u8 *str, u8 left printer.currentY = top; printer.letterSpacing = letterSpacing; printer.lineSpacing = lineSpacing; - printer.style = 0; + printer.unk = 0; printer.fgColor = GetFontAttribute(fontId, 5); printer.bgColor = GetFontAttribute(fontId, 6); diff --git a/src/menu_helpers.c b/src/menu_helpers.c index c80e52d27..69443d309 100644 --- a/src/menu_helpers.c +++ b/src/menu_helpers.c @@ -183,7 +183,7 @@ bool8 AdjustQuantityAccordingToDPadInput(s16 *arg0, u16 arg1) { s16 valBefore = (*arg0); - if (JOY_REPEAT(DPAD_ANY) == DPAD_UP) + if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_UP) { (*arg0)++; if ((*arg0) > arg1) @@ -199,7 +199,7 @@ bool8 AdjustQuantityAccordingToDPadInput(s16 *arg0, u16 arg1) return TRUE; } } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_DOWN) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_DOWN) { (*arg0)--; if ((*arg0) <= 0) @@ -215,7 +215,7 @@ bool8 AdjustQuantityAccordingToDPadInput(s16 *arg0, u16 arg1) return TRUE; } } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_RIGHT) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_RIGHT) { (*arg0) += 10; if ((*arg0) > arg1) @@ -231,7 +231,7 @@ bool8 AdjustQuantityAccordingToDPadInput(s16 *arg0, u16 arg1) return TRUE; } } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_LEFT) + else if ((gMain.newAndRepeatedKeys & DPAD_ANY) == DPAD_LEFT) { (*arg0) -= 10; if ((*arg0) <= 0) @@ -255,9 +255,9 @@ u8 GetLRKeysPressed(void) { if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { - if (JOY_NEW(L_BUTTON)) + if (gMain.newKeys & L_BUTTON) return MENU_L_PRESSED; - if (JOY_NEW(R_BUTTON)) + if (gMain.newKeys & R_BUTTON) return MENU_R_PRESSED; } @@ -268,9 +268,9 @@ u8 GetLRKeysPressedAndHeld(void) { if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { - if (JOY_REPEAT(L_BUTTON)) + if (gMain.newAndRepeatedKeys & L_BUTTON) return MENU_L_PRESSED; - if (JOY_REPEAT(R_BUTTON)) + if (gMain.newAndRepeatedKeys & R_BUTTON) return MENU_R_PRESSED; } diff --git a/src/menu_specialized.c b/src/menu_specialized.c index f9da20e11..a99c5c9d0 100644 --- a/src/menu_specialized.c +++ b/src/menu_specialized.c @@ -250,7 +250,7 @@ void sub_81D1D04(u8 a0) sUnknown_0203CF48[a0] = 0xFF; } -static u8 sub_81D1D34(u8 a0) // unused +static u8 sub_81D1D34(u8 a0) { return sUnknown_0203CF48[a0]; } @@ -894,73 +894,76 @@ static u8 *GetConditionMenuMonString(u8 *dst, u16 boxId, u16 monId) { return StringCopyPadded(dst, gText_EggNickname, 0, 12); } - GetBoxOrPartyMonData(boxId, monId, MON_DATA_NICKNAME, dst); - StringGetEnd10(dst); - species = GetBoxOrPartyMonData(boxId, monId, MON_DATA_SPECIES, NULL); - if (boxId == TOTAL_BOXES_COUNT) // Party mon. - { - level = GetMonData(&gPlayerParty[monId], MON_DATA_LEVEL); - gender = GetMonGender(&gPlayerParty[monId]); - } else { - // Needed to match, feel free to remove. - boxId++, boxId--; - monId++, monId--; + GetBoxOrPartyMonData(boxId, monId, MON_DATA_NICKNAME, dst); + StringGetEnd10(dst); + species = GetBoxOrPartyMonData(boxId, monId, MON_DATA_SPECIES, NULL); + if (boxId == TOTAL_BOXES_COUNT) // Party mon. + { + level = GetMonData(&gPlayerParty[monId], MON_DATA_LEVEL); + gender = GetMonGender(&gPlayerParty[monId]); + } + else + { + // Needed to match, feel free to remove. + boxId++;boxId--; + monId++;monId--; - boxMon = GetBoxedMonPtr(boxId, monId); - gender = GetBoxMonGender(boxMon); - level = GetLevelFromBoxMonExp(boxMon); - } + boxMon = GetBoxedMonPtr(boxId, monId); + gender = GetBoxMonGender(boxMon); + level = GetLevelFromBoxMonExp(boxMon); + } - if ((species == SPECIES_NIDORAN_F || species == SPECIES_NIDORAN_M) && !StringCompare(dst, gSpeciesNames[species])) - gender = MON_GENDERLESS; + if ((species == SPECIES_NIDORAN_F || species == SPECIES_NIDORAN_M) && !StringCompare(dst, gSpeciesNames[species])) + gender = MON_GENDERLESS; - for (str = dst; *str != EOS; str++) - ; + for (str = dst; *str != EOS; str++) + ; - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_SKIP; - *(str++) = 60; + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_SKIP; + *(str++) = 60; - switch (gender) - { - default: + switch (gender) + { + default: + *(str++) = CHAR_SPACE; + break; + case MON_MALE: + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_COLOR; + *(str++) = TEXT_COLOR_RED; + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_SHADOW; + *(str++) = TEXT_COLOR_LIGHT_RED; + *(str++) = CHAR_MALE; + break; + case MON_FEMALE: + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_COLOR; + *(str++) = TEXT_COLOR_GREEN; + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_SHADOW; + *(str++) = TEXT_COLOR_LIGHT_GREEN; + *(str++) = CHAR_FEMALE; + break; + } + + *(str++) = EXT_CTRL_CODE_BEGIN; + *(str++) = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; + *(str++) = TEXT_COLOR_BLUE; + *(str++) = TEXT_COLOR_TRANSPARENT; + *(str++) = TEXT_COLOR_LIGHT_BLUE; + *(str++) = CHAR_SLASH; + *(str++) = CHAR_EXTRA_SYMBOL; + *(str++) = CHAR_LV_2; + str = ConvertIntToDecimalStringN(str, level, STR_CONV_MODE_LEFT_ALIGN, 3); *(str++) = CHAR_SPACE; - break; - case MON_MALE: - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_COLOR; - *(str++) = TEXT_COLOR_RED; - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_SHADOW; - *(str++) = TEXT_COLOR_LIGHT_RED; - *(str++) = CHAR_MALE; - break; - case MON_FEMALE: - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_COLOR; - *(str++) = TEXT_COLOR_GREEN; - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_SHADOW; - *(str++) = TEXT_COLOR_LIGHT_GREEN; - *(str++) = CHAR_FEMALE; - break; + *str = EOS; + + return str; } - - *(str++) = EXT_CTRL_CODE_BEGIN; - *(str++) = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW; - *(str++) = TEXT_COLOR_BLUE; - *(str++) = TEXT_COLOR_TRANSPARENT; - *(str++) = TEXT_COLOR_LIGHT_BLUE; - *(str++) = CHAR_SLASH; - *(str++) = CHAR_EXTRA_SYMBOL; - *(str++) = CHAR_LV_2; - str = ConvertIntToDecimalStringN(str, level, STR_CONV_MODE_LEFT_ALIGN, 3); - *(str++) = CHAR_SPACE; - *str = EOS; - - return str; } // Buffers the string in src to dest up to n chars. If src is less than n chars, fill with spaces diff --git a/src/mirage_tower.c b/src/mirage_tower.c index 607083e26..9c791b33f 100644 --- a/src/mirage_tower.c +++ b/src/mirage_tower.c @@ -168,7 +168,7 @@ const struct PulseBlendSettings gMirageTowerPulseBlendSettings = { .numColors = 15, .delay = 5, .numFadeCycles = -1, - .maxBlendCoeff = -5, + .maxBlendCoeff = 11, .fadeType = 1, .restorePaletteOnUnload = FALSE, .unk7_7 = 1, @@ -412,9 +412,10 @@ void DoMirageTowerCeilingCrumble(void) static void WaitCeilingCrumble(u8 taskId) { - u16 *data = (u16 *)gTasks[taskId].data; + u16 *data = gTasks[taskId].data; + data[1]++; // Either wait 1000 frames, or until all 16 crumble sprites and the one screen-shake task are completed. - if (++data[1] == 1000 || data[0] == 17) + if (data[1] == 1000 || data[0] == 17) gTasks[taskId].func = FinishCeilingCrumbleTask; } @@ -690,7 +691,7 @@ static void DoFossilFallAndSink(u8 taskId) if (gSprites[sUnknown_0203CF0C->spriteId].callback != SpriteCallbackDummy) return; DestroySprite(&gSprites[sUnknown_0203CF0C->spriteId]); - FREE_AND_SET_NULL(sUnknown_0203CF0C->unkC); + FREE_AND_SET_NULL(sUnknown_0203CF0C->unkC);; FREE_AND_SET_NULL(sUnknown_0203CF0C->frameImage); FREE_AND_SET_NULL(sUnknown_0203CF0C->frameImageTiles); FREE_AND_SET_NULL(sUnknown_0203CF0C); @@ -723,40 +724,144 @@ static void sub_81BF248(struct Sprite *sprite) } } +#ifdef NONMATCHING static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e) { - u16 var, var2; - u8 r0, r5, r4, r2; - u8 r2_1, r4_1; - u8 b2, c2; + u8 r5, r4, r0, r2; + u16 var; - r4 = b / d; + r4 = r5 = b / d; gUnknown_030012A8[0] = r4; - r2 = b % d; + r0 = r2 = b % d; gUnknown_030012A8[1] = r2; - r4_1 = r4 & 7; - r2_1 = r2 & 7; + r4 &= 7; + r2 &= 7; + gUnknown_030012A8[2] = r4; + gUnknown_030012A8[3] = r2; - gUnknown_030012A8[2] = r4 & 7; //should be r4_1 but that doesn't match - gUnknown_030012A8[3] = r2 & 7; //should be r2_1 but that doesn't match - - r0 = r2 / 8; - r5 = r4 / 8; - - gUnknown_030012A8[4] = r2 / 8; //should just be r0, but that doesn't match - gUnknown_030012A8[5] = r4 / 8; //should be just r5 but that doesn't match - - var = (d / 8) * (r5 * 64) + (r0 * 64); + r0 /= 8; + r5 /= 8; + gUnknown_030012A8[4] = r0; + gUnknown_030012A8[5] = r5; + var = ((d / 8) * (r5 * 64)) + (r0 * 64); gUnknown_030012A8[6] = var; - var2 = var + ((r4_1 * 8) + r2_1); - var2 /= 2; - gUnknown_030012A8[7] = var + ((r4_1 * 8) + r2_1); // should be var2 with var2 being divided by 2 AFTER this assignment, but that doesn't match. + var += (r4 * 8) + r2; + gUnknown_030012A8[7] = var; - b2 = ((b % 2) ^ 1); - c2 = (c << (b2 << 2)) | (15 << (((b2 ^ 1) << 2))); - a[var2 + (e * 32)] &= c2; + // This part is non-matching. 99% sure it IS functionally equivalent, though. + b = (b & 1) ^ 1; + c = (c << ((b) << 2)) | (15 << ((b ^ 1) << 2)); + + a[(var / 2) + (e * 32)] &= c; } + +#else +NAKED +static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e) +{ + asm_unified( + "push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0x8\n\ + str r0, [sp]\n\ + mov r10, r1\n\ + adds r6, r2, 0\n\ + mov r8, r3\n\ + ldr r0, [sp, 0x28]\n\ + mov r9, r0\n\ + lsls r1, 16\n\ + lsrs r1, 16\n\ + mov r10, r1\n\ + lsls r6, 24\n\ + lsrs r6, 24\n\ + mov r0, r8\n\ + lsls r0, 24\n\ + mov r8, r0\n\ + lsrs r7, r0, 24\n\ + mov r1, r9\n\ + lsls r1, 24\n\ + lsrs r1, 24\n\ + mov r9, r1\n\ + mov r0, r10\n\ + adds r1, r7, 0\n\ + bl __divsi3\n\ + adds r5, r0, 0\n\ + lsls r5, 24\n\ + lsrs r4, r5, 24\n\ + ldr r3, =gUnknown_030012A8\n\ + strh r4, [r3]\n\ + mov r0, r10\n\ + adds r1, r7, 0\n\ + str r3, [sp, 0x4]\n\ + bl __modsi3\n\ + lsls r0, 24\n\ + lsrs r2, r0, 24\n\ + ldr r3, [sp, 0x4]\n\ + strh r2, [r3, 0x2]\n\ + movs r1, 0x7\n\ + ands r4, r1\n\ + ands r2, r1\n\ + strh r4, [r3, 0x4]\n\ + strh r2, [r3, 0x6]\n\ + lsrs r0, 27\n\ + lsrs r5, 27\n\ + strh r0, [r3, 0x8]\n\ + strh r5, [r3, 0xA]\n\ + mov r1, r8\n\ + lsrs r1, 27\n\ + lsls r1, 6\n\ + mov r8, r1\n\ + mov r1, r8\n\ + muls r1, r5\n\ + lsls r0, 6\n\ + adds r1, r0\n\ + lsls r1, 16\n\ + lsrs r1, 16\n\ + strh r1, [r3, 0xC]\n\ + lsls r4, 3\n\ + adds r4, r2\n\ + adds r1, r4\n\ + lsls r4, r1, 16\n\ + lsrs r4, 17\n\ + strh r1, [r3, 0xE]\n\ + movs r1, 0x1\n\ + mov r0, r10\n\ + ands r1, r0\n\ + movs r2, 0x1\n\ + eors r1, r2\n\ + lsls r0, r1, 2\n\ + lsls r6, r0\n\ + eors r1, r2\n\ + lsls r1, 2\n\ + movs r0, 0xF\n\ + lsls r0, r1\n\ + orrs r6, r0\n\ + lsls r6, 24\n\ + lsrs r6, 24\n\ + mov r1, r9\n\ + lsls r1, 5\n\ + mov r9, r1\n\ + add r9, r4\n\ + ldr r1, [sp]\n\ + add r1, r9\n\ + ldrb r0, [r1]\n\ + ands r6, r0\n\ + strb r6, [r1]\n\ + add sp, 0x8\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool"); +} +#endif // NONMATCHING diff --git a/src/mon_markings.c b/src/mon_markings.c index c2afdda83..db5df07e8 100644 --- a/src/mon_markings.c +++ b/src/mon_markings.c @@ -394,7 +394,7 @@ bool8 sub_811FBA4(void) { u16 i; - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { s8 pos; PlaySE(SE_SELECT); @@ -404,7 +404,7 @@ bool8 sub_811FBA4(void) return TRUE; } - if (JOY_NEW(DPAD_DOWN)) + if (gMain.newKeys & DPAD_DOWN) { s8 pos; PlaySE(SE_SELECT); @@ -414,7 +414,7 @@ bool8 sub_811FBA4(void) return TRUE; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); @@ -433,7 +433,7 @@ bool8 sub_811FBA4(void) return TRUE; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); return FALSE; diff --git a/src/move_relearner.c b/src/move_relearner.c index cd4da5835..3e7caf133 100644 --- a/src/move_relearner.c +++ b/src/move_relearner.c @@ -732,7 +732,7 @@ static void DoMoveRelearnerMain(void) } break; case MENU_STATE_WAIT_FOR_A_BUTTON: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); sMoveRelearnerStruct->state = MENU_STATE_FADE_AND_RETURN; @@ -778,7 +778,7 @@ static void HandleInput(bool8 showContest) switch (itemId) { case LIST_NOTHING_CHOSEN: - if (!(JOY_NEW(DPAD_LEFT | DPAD_RIGHT)) && !GetLRKeysPressed()) + if (!(gMain.newKeys & (DPAD_LEFT | DPAD_RIGHT)) && !GetLRKeysPressed()) { break; } diff --git a/src/mystery_event_menu.c b/src/mystery_event_menu.c index 00dcbf0e3..032cc3340 100644 --- a/src/mystery_event_menu.c +++ b/src/mystery_event_menu.c @@ -163,7 +163,7 @@ static void CB2_MysteryEventMenu(void) PrintMysteryMenuText(0, gText_PressAToLoadEvent, 1, 2, 1); gMain.state++; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); CloseLink(); @@ -177,7 +177,7 @@ static void CB2_MysteryEventMenu(void) case 5: if (GetLinkPlayerCount_2() == 2) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); CheckShouldAdvanceLinkState(); @@ -187,7 +187,7 @@ static void CB2_MysteryEventMenu(void) CopyWindowToVram(1, 3); gMain.state++; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); CloseLink(); @@ -227,7 +227,7 @@ static void CB2_MysteryEventMenu(void) } } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); CloseLink(); @@ -274,7 +274,7 @@ static void CB2_MysteryEventMenu(void) } break; case 14: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); gMain.state++; diff --git a/src/mystery_gift.c b/src/mystery_gift.c index a23f159b2..ca5ab1baf 100644 --- a/src/mystery_gift.c +++ b/src/mystery_gift.c @@ -561,7 +561,7 @@ bool32 MG_PrintTextOnWindow1AndWaitButton(u8 *textState, const u8 *str) goto inc; case 1: DrawDownArrow(1, 0xD0, 0x14, 1, FALSE, &sDownArrowCounterAndYCoordIdx[0], &sDownArrowCounterAndYCoordIdx[1]); - if (({JOY_NEW(A_BUTTON | B_BUTTON);})) + if (({gMain.newKeys & (A_BUTTON | B_BUTTON);})) { inc: (*textState)++; @@ -595,7 +595,7 @@ bool32 unref_HideDownArrowAndWaitButton(u8 * textState) { case 0: HideDownArrow(); - if (({JOY_NEW(A_BUTTON | B_BUTTON);})) + if (({gMain.newKeys & (A_BUTTON | B_BUTTON);})) { (*textState)++; } @@ -930,7 +930,7 @@ static bool32 mevent_save_game(u8 * state) (*state)++; break; case 3: - if (({JOY_NEW(A_BUTTON | B_BUTTON);})) + if (({gMain.newKeys & (A_BUTTON | B_BUTTON);})) { (*state)++; } @@ -1458,11 +1458,11 @@ void task00_mystery_gift(u8 taskId) case 20: if (data->IsCardOrNews == 0) { - if (({JOY_NEW(A_BUTTON);})) + if (({gMain.newKeys & A_BUTTON;})) { data->state = 21; } - if (({JOY_NEW(B_BUTTON);})) + if (({gMain.newKeys & B_BUTTON;})) { data->state = 27; } diff --git a/src/option_menu.c b/src/option_menu.c index b6440a89c..1cf0bad2e 100644 --- a/src/option_menu.c +++ b/src/option_menu.c @@ -271,16 +271,16 @@ static void Task_OptionMenuFadeIn(u8 taskId) static void Task_OptionMenuProcessInput(u8 taskId) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (gTasks[taskId].data[TD_MENUSELECTION] == MENUITEM_CANCEL) gTasks[taskId].func = Task_OptionMenuSave; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { gTasks[taskId].func = Task_OptionMenuSave; } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (gTasks[taskId].data[TD_MENUSELECTION] > 0) gTasks[taskId].data[TD_MENUSELECTION]--; @@ -288,7 +288,7 @@ static void Task_OptionMenuProcessInput(u8 taskId) gTasks[taskId].data[TD_MENUSELECTION] = MENUITEM_CANCEL; HighlightOptionMenuItem(gTasks[taskId].data[TD_MENUSELECTION]); } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (gTasks[taskId].data[TD_MENUSELECTION] < MENUITEM_CANCEL) gTasks[taskId].data[TD_MENUSELECTION]++; @@ -405,7 +405,7 @@ static void DrawOptionMenuChoice(const u8 *text, u8 x, u8 y, u8 style) static u8 TextSpeed_ProcessInput(u8 selection) { - if (JOY_NEW(DPAD_RIGHT)) + if (gMain.newKeys & DPAD_RIGHT) { if (selection <= 1) selection++; @@ -414,7 +414,7 @@ static u8 TextSpeed_ProcessInput(u8 selection) sArrowPressed = TRUE; } - if (JOY_NEW(DPAD_LEFT)) + if (gMain.newKeys & DPAD_LEFT) { if (selection != 0) selection--; @@ -451,7 +451,7 @@ static void TextSpeed_DrawChoices(u8 selection) static u8 BattleScene_ProcessInput(u8 selection) { - if (JOY_NEW(DPAD_LEFT | DPAD_RIGHT)) + if (gMain.newKeys & (DPAD_LEFT | DPAD_RIGHT)) { selection ^= 1; sArrowPressed = TRUE; @@ -474,7 +474,7 @@ static void BattleScene_DrawChoices(u8 selection) static u8 BattleStyle_ProcessInput(u8 selection) { - if (JOY_NEW(DPAD_LEFT | DPAD_RIGHT)) + if (gMain.newKeys & (DPAD_LEFT | DPAD_RIGHT)) { selection ^= 1; sArrowPressed = TRUE; @@ -497,7 +497,7 @@ static void BattleStyle_DrawChoices(u8 selection) static u8 Sound_ProcessInput(u8 selection) { - if (JOY_NEW(DPAD_LEFT | DPAD_RIGHT)) + if (gMain.newKeys & (DPAD_LEFT | DPAD_RIGHT)) { selection ^= 1; SetPokemonCryStereo(selection); @@ -521,7 +521,7 @@ static void Sound_DrawChoices(u8 selection) static u8 FrameType_ProcessInput(u8 selection) { - if (JOY_NEW(DPAD_RIGHT)) + if (gMain.newKeys & DPAD_RIGHT) { if (selection < WINDOW_FRAMES_COUNT - 1) selection++; @@ -532,7 +532,7 @@ static u8 FrameType_ProcessInput(u8 selection) LoadPalette(GetWindowFrameTilesPal(selection)->pal, 0x70, 0x20); sArrowPressed = TRUE; } - if (JOY_NEW(DPAD_LEFT)) + if (gMain.newKeys & DPAD_LEFT) { if (selection != 0) selection--; @@ -579,7 +579,7 @@ static void FrameType_DrawChoices(u8 selection) static u8 ButtonMode_ProcessInput(u8 selection) { - if (JOY_NEW(DPAD_RIGHT)) + if (gMain.newKeys & DPAD_RIGHT) { if (selection <= 1) selection++; @@ -588,7 +588,7 @@ static u8 ButtonMode_ProcessInput(u8 selection) sArrowPressed = TRUE; } - if (JOY_NEW(DPAD_LEFT)) + if (gMain.newKeys & DPAD_LEFT) { if (selection != 0) selection--; diff --git a/src/overworld.c b/src/overworld.c index 2d798f2ec..4bf5d4fab 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -2454,19 +2454,20 @@ static void UpdateHeldKeyCode(u16 key) static u16 KeyInterCB_ReadButtons(u32 key) { - if (JOY_HELD(DPAD_UP)) + if (gMain.heldKeys & DPAD_UP) return LINK_KEY_CODE_DPAD_UP; - if (JOY_HELD(DPAD_DOWN)) + else if (gMain.heldKeys & DPAD_DOWN) return LINK_KEY_CODE_DPAD_DOWN; - if (JOY_HELD(DPAD_LEFT)) + else if (gMain.heldKeys & DPAD_LEFT) return LINK_KEY_CODE_DPAD_LEFT; - if (JOY_HELD(DPAD_RIGHT)) + else if (gMain.heldKeys & DPAD_RIGHT) return LINK_KEY_CODE_DPAD_RIGHT; - if (JOY_NEW(START_BUTTON)) + else if (gMain.newKeys & START_BUTTON) return LINK_KEY_CODE_START_BUTTON; - if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) return LINK_KEY_CODE_A_BUTTON; - return LINK_KEY_CODE_EMPTY; + else + return LINK_KEY_CODE_EMPTY; } static u16 GetDirectionForDpadKey(u16 a1) @@ -2573,7 +2574,7 @@ static u16 sub_8087170(u32 keyOrPlayerId) { if (sPlayerTradingStates[keyOrPlayerId] == PLAYER_TRADING_STATE_UNK_2) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { SetKeyInterceptCallback(KeyInterCB_DoNothingAndKeepAlive); return LINK_KEY_CODE_UNK_7; @@ -3188,7 +3189,7 @@ static void SpriteCB_LinkPlayer(struct Sprite *sprite) SetObjectSubpriorityByZCoord(objEvent->previousElevation, sprite, 1); sprite->oam.priority = ZCoordToPriority(objEvent->previousElevation); - if (linkPlayerObjEvent->movementMode == MOVEMENT_MODE_FREE) + if (!linkPlayerObjEvent->movementMode != MOVEMENT_MODE_FREE) StartSpriteAnim(sprite, GetFaceDirectionAnimNum(objEvent->range.as_byte)); else StartSpriteAnimIfDifferent(sprite, GetMoveDirectionAnimNum(objEvent->range.as_byte)); diff --git a/src/party_menu.c b/src/party_menu.c index e509ef6e0..7f4697d7d 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -1411,7 +1411,7 @@ static u16 PartyMenuButtonHandler(s8 *slotPtr) break; } - if (JOY_NEW(START_BUTTON)) + if (gMain.newKeys & START_BUTTON) return 8; if (movementDir) @@ -1421,10 +1421,10 @@ static u16 PartyMenuButtonHandler(s8 *slotPtr) } // Pressed Cancel - if ((JOY_NEW(A_BUTTON)) && *slotPtr == PARTY_SIZE + 1) + if ((gMain.newKeys & A_BUTTON) && *slotPtr == PARTY_SIZE + 1) return 2; - return JOY_NEW(A_BUTTON | B_BUTTON); + return gMain.newKeys & (A_BUTTON | B_BUTTON); } static void UpdateCurrentPartySelection(s8 *slotPtr, s8 movementDir) @@ -1862,7 +1862,7 @@ u8 GetMonAilment(struct Pokemon *mon) static void SetPartyMonsAllowedInMinigame(void) { - s16 *ptr; + u16 *ptr; if (gPartyMenu.menuType == PARTY_MENU_TYPE_MINIGAME) { @@ -3765,7 +3765,7 @@ static u16 GetFieldMoveMonSpecies(void) static void Task_CancelAfterAorBPress(u8 taskId) { - if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON))) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON)) CursorCb_Cancel1(taskId); } @@ -4722,7 +4722,7 @@ static void Task_DoLearnedMoveFanfareAfterText(u8 taskId) static void Task_LearnNextMoveOrClosePartyMenu(u8 taskId) { - if (IsFanfareTaskInactive() && ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON)))) + if (IsFanfareTaskInactive() && ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON))) { if (gPartyMenu.learnMoveState == 1) Task_TryLearningNextMove(taskId); @@ -4931,7 +4931,7 @@ static void UpdateMonDisplayInfoAfterRareCandy(u8 slot, struct Pokemon *mon) static void Task_DisplayLevelUpStatsPg1(u8 taskId) { - if (WaitFanfare(FALSE) && IsPartyMenuTextPrinterActive() != TRUE && ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON)))) + if (WaitFanfare(FALSE) && IsPartyMenuTextPrinterActive() != TRUE && ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON))) { PlaySE(SE_SELECT); DisplayLevelUpStatsPg1(taskId); @@ -4941,7 +4941,7 @@ static void Task_DisplayLevelUpStatsPg1(u8 taskId) static void Task_DisplayLevelUpStatsPg2(u8 taskId) { - if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON))) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON)) { PlaySE(SE_SELECT); DisplayLevelUpStatsPg2(taskId); @@ -4951,9 +4951,9 @@ static void Task_DisplayLevelUpStatsPg2(u8 taskId) static void DisplayLevelUpStatsPg1(u8 taskId) { - u16 *arrayPtr = (u16*)sPartyMenuInternal->data; + s16 *arrayPtr = sPartyMenuInternal->data; - arrayPtr[12] = (u16)CreateLevelUpStatsWindow(); + arrayPtr[12] = CreateLevelUpStatsWindow(); DrawLevelUpWindowPg1(arrayPtr[12], arrayPtr, &arrayPtr[6], TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY, TEXT_COLOR_LIGHT_GREY); CopyWindowToVram(arrayPtr[12], 2); ScheduleBgCopyTilemapToVram(2); @@ -4961,7 +4961,7 @@ static void DisplayLevelUpStatsPg1(u8 taskId) static void DisplayLevelUpStatsPg2(u8 taskId) { - u16 *arrayPtr = (u16 *)sPartyMenuInternal->data; + s16 *arrayPtr = sPartyMenuInternal->data; DrawLevelUpWindowPg2(arrayPtr[12], &arrayPtr[6], TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY, TEXT_COLOR_LIGHT_GREY); CopyWindowToVram(arrayPtr[12], 2); @@ -4972,7 +4972,7 @@ static void Task_TryLearnNewMoves(u8 taskId) { u16 learnMove; - if (WaitFanfare(0) && ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON)))) + if (WaitFanfare(0) && ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON))) { RemoveLevelUpStatsWindow(); learnMove = MonTryLearningNewMove(&gPlayerParty[gPartyMenu.slotId], TRUE); @@ -5609,7 +5609,7 @@ static void Task_ValidateChosenHalfParty(u8 taskId) static void Task_ContinueChoosingHalfParty(u8 taskId) { - if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON))) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON)) { PlaySE(SE_SELECT); DisplayPartyMenuStdMessage(PARTY_MSG_CHOOSE_MON); diff --git a/src/player_pc.c b/src/player_pc.c index 238424ee3..fc0bd9f4c 100644 --- a/src/player_pc.c +++ b/src/player_pc.c @@ -327,7 +327,7 @@ void PlayerPC(void) static void InitPlayerPCMenu(u8 taskId) { - s16 *data; + u16 *data; struct WindowTemplate windowTemplate; data = gTasks[taskId].data; @@ -346,7 +346,7 @@ static void InitPlayerPCMenu(u8 taskId) static void PlayerPCProcessMenuInput(u8 taskId) { - s16 *data; + u16 *data; s8 inputOptionId; data = gTasks[taskId].data; @@ -435,7 +435,7 @@ static void PlayerPC_TurnOff(u8 taskId) static void InitItemStorageMenu(u8 taskId, u8 var) { - s16 *data; + u16 *data; struct WindowTemplate windowTemplate; data = gTasks[taskId].data; @@ -548,7 +548,7 @@ static void ItemStorage_Toss(u8 taskId) static void ItemStorage_WithdrawToss_Helper(u8 taskId, bool8 toss) { - s16 *data = gTasks[taskId].data; + u16 *data = gTasks[taskId].data; data[3] = toss; sub_816B4DC(taskId); @@ -581,9 +581,9 @@ static void ItemStorage_SetItemAndMailCount(u8 taskId) static void sub_816B4DC(u8 taskId) { - u16 *data = (u16 *)gTasks[taskId].data; + u16 *data = gTasks[taskId].data; - ClearStdWindowAndFrameToTransparent((u8)data[4], FALSE); + ClearStdWindowAndFrameToTransparent(data[4], FALSE); ClearWindowTilemap(data[4]); RemoveWindow(data[4]); ScheduleBgCopyTilemapToVram(0); @@ -1134,7 +1134,7 @@ static void ItemStorage_ProcessInput(u8 taskId) s32 id; data = gTasks[taskId].data; - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { ListMenuGetScrollAndRow(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); if ((playerPCItemPageInfo.itemsAbove + playerPCItemPageInfo.cursorPos) != (playerPCItemPageInfo.count - 1)) @@ -1212,7 +1212,7 @@ static void sub_816C4FC(u8 taskId) s32 id; data = gTasks[taskId].data; - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { ListMenuGetScrollAndRow(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); ItemStorage_DoItemSwap(taskId, FALSE); @@ -1227,7 +1227,7 @@ static void sub_816C4FC(u8 taskId) case LIST_NOTHING_CHOSEN: break; case LIST_CANCEL: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { ItemStorage_DoItemSwap(taskId, FALSE); } @@ -1332,7 +1332,7 @@ static void ItemStorage_HandleQuantityRolling(u8 taskId) sub_816C6BC(sub_816BC7C(4), data[2], STR_CONV_MODE_LEADING_ZEROS, 8, 1, 3); else { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); sub_816BCC4(4); @@ -1341,7 +1341,7 @@ static void ItemStorage_HandleQuantityRolling(u8 taskId) else ItemStorage_DoItemToss(taskId); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); sub_816BCC4(4); @@ -1380,7 +1380,7 @@ static void ItemStorage_DoItemToss(u8 taskId) data = gTasks[taskId].data; b = (playerPCItemPageInfo.cursorPos + playerPCItemPageInfo.itemsAbove); - if (ItemId_GetImportance(gSaveBlock1Ptr->pcItems[b].itemId) == 0) + if (!ItemId_GetImportance(gSaveBlock1Ptr->pcItems[b].itemId)) { CopyItemName(gSaveBlock1Ptr->pcItems[b].itemId, gStringVar1); ConvertIntToDecimalStringN(gStringVar2, data[2], STR_CONV_MODE_LEFT_ALIGN, 3); @@ -1412,7 +1412,7 @@ static void ItemStorage_HandleRemoveItem(u8 taskId) s16 *data; data = gTasks[taskId].data; - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { RemovePCItem((playerPCItemPageInfo.cursorPos + playerPCItemPageInfo.itemsAbove), data[2]); DestroyListMenuTask(data[5], &(playerPCItemPageInfo.itemsAbove), &(playerPCItemPageInfo.cursorPos)); @@ -1429,7 +1429,7 @@ static void ItemStorage_WaitPressHandleResumeProcessInput(u8 taskId) s16 *data; data = gTasks[taskId].data; - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { ItemStorage_PrintItemPcResponse(ItemStorage_GetItemPcResponse(gSaveBlock1Ptr->pcItems[(playerPCItemPageInfo.itemsAbove + playerPCItemPageInfo.cursorPos)].itemId)); ItemStorage_StartScrollIndicatorAndProcessInput(taskId); diff --git a/src/pokeblock.c b/src/pokeblock.c index b44112b88..11fe83240 100644 --- a/src/pokeblock.c +++ b/src/pokeblock.c @@ -430,7 +430,7 @@ static const struct ListMenuTemplate sPokeblockListMenuTemplate = // code void OpenPokeblockCase(u8 caseId, void (*callback)(void)) { - sPokeblockMenu = Alloc(sizeof(struct PokeblockMenuStruct)); + sPokeblockMenu = Alloc(sizeof(*sPokeblockMenu)); sPokeblockMenu->caseId = caseId; sPokeblockMenu->callbackOnUse = NULL; sPokeblockMenu->unkTaskId = 0xFF; @@ -984,7 +984,7 @@ static void Task_HandlePokeblockMenuInput(u8 taskId) if (!gPaletteFade.active && MenuHelpers_CallLinkSomething() != TRUE) { - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos); if (sSavedPokeblockData.lastItemPage + sSavedPokeblockData.lastItemPos != sPokeblockMenu->itemsNo - 1) @@ -1035,7 +1035,7 @@ static void Task_HandlePokeblocksSwapInput(u8 taskId) if (MenuHelpers_CallLinkSomething() == TRUE) return; - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { PlaySE(SE_SELECT); ListMenuGetScrollAndRow(data[0], &sSavedPokeblockData.lastItemPage, &sSavedPokeblockData.lastItemPos); @@ -1069,7 +1069,7 @@ static void Task_HandlePokeblocksSwapInput(u8 taskId) break; case LIST_CANCEL: // same id as STOW CASE field PlaySE(SE_SELECT); - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) HandlePokeblocksSwap(taskId, FALSE); else HandlePokeblocksSwap(taskId, TRUE); @@ -1193,7 +1193,7 @@ static void TossPokeblockChoice_Yes(u8 taskId) static void HandleErasePokeblock(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { s16 *data; u16 *lastPage, *lastPos; diff --git a/src/pokedex.c b/src/pokedex.c index d375a0afc..54f256509 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -172,16 +172,16 @@ struct PokedexView u16 ownCount; u16 monSpriteIds[MAX_MONS_ON_SCREEN]; u16 selectedMonSpriteId; - s16 pokeBallRotationStep; - s16 pokeBallRotationBackup; + u16 pokeBallRotationStep; + u16 pokeBallRotationBackup; u8 pokeBallRotation; u8 initialVOffset; u8 scrollTimer; u8 scrollDirection; s16 listVOffset; s16 listMovingVOffset; - s16 scrollMonIncrement; - s16 maxScrollTimer; + u16 scrollMonIncrement; + u16 maxScrollTimer; u16 scrollSpeed; u16 unkArr1[4]; // Cleared, never read u8 filler[8]; @@ -1673,7 +1673,7 @@ static void Task_HandlePokedexInput(u8 taskId) } else { - if ((JOY_NEW(A_BUTTON)) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) + if ((gMain.newKeys & A_BUTTON) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) { UpdateSelectedMonSpriteId(); BeginNormalPaletteFade(~(1 << (gSprites[sPokedexView->selectedMonSpriteId].oam.paletteNum + 16)), 0, 0, 0x10, RGB_BLACK); @@ -1682,7 +1682,7 @@ static void Task_HandlePokedexInput(u8 taskId) PlaySE(SE_PIN); FreeWindowAndBgBuffers(); } - else if (JOY_NEW(START_BUTTON)) + else if (gMain.newKeys & START_BUTTON) { sPokedexView->menuY = 0; sPokedexView->menuIsOpen = TRUE; @@ -1690,7 +1690,7 @@ static void Task_HandlePokedexInput(u8 taskId) gTasks[taskId].func = Task_HandlePokedexStartMenuInput; PlaySE(SE_SELECT); } - else if (JOY_NEW(SELECT_BUTTON)) + else if (gMain.newKeys & SELECT_BUTTON) { PlaySE(SE_SELECT); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); @@ -1704,7 +1704,7 @@ static void Task_HandlePokedexInput(u8 taskId) PlaySE(SE_PC_LOGIN); FreeWindowAndBgBuffers(); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].func = Task_ClosePokedex; @@ -1737,7 +1737,7 @@ static void Task_HandlePokedexStartMenuInput(u8 taskId) } else { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (sPokedexView->menuCursorPos) { @@ -1768,18 +1768,18 @@ static void Task_HandlePokedexStartMenuInput(u8 taskId) } //Exit menu when Start or B is pressed - if (JOY_NEW(START_BUTTON | B_BUTTON)) + if (gMain.newKeys & (START_BUTTON | B_BUTTON)) { sPokedexView->menuIsOpen = FALSE; gTasks[taskId].func = Task_HandlePokedexInput; PlaySE(SE_SELECT); } - else if ((JOY_REPEAT(DPAD_UP)) && sPokedexView->menuCursorPos != 0) + else if ((gMain.newAndRepeatedKeys & DPAD_UP) && sPokedexView->menuCursorPos != 0) { sPokedexView->menuCursorPos--; PlaySE(SE_SELECT); } - else if ((JOY_REPEAT(DPAD_DOWN)) && sPokedexView->menuCursorPos < 3) + else if ((gMain.newAndRepeatedKeys & DPAD_DOWN) && sPokedexView->menuCursorPos < 3) { sPokedexView->menuCursorPos++; PlaySE(SE_SELECT); @@ -1873,7 +1873,7 @@ static void Task_HandleSearchResultsInput(u8 taskId) } else { - if ((JOY_NEW(A_BUTTON)) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) + if ((gMain.newKeys & A_BUTTON) && sPokedexView->pokedexList[sPokedexView->selectedPokemon].seen) { u32 a; @@ -1885,7 +1885,7 @@ static void Task_HandleSearchResultsInput(u8 taskId) PlaySE(SE_PIN); FreeWindowAndBgBuffers(); } - else if (JOY_NEW(START_BUTTON)) + else if (gMain.newKeys & START_BUTTON) { sPokedexView->menuY = 0; sPokedexView->menuIsOpen = TRUE; @@ -1893,7 +1893,7 @@ static void Task_HandleSearchResultsInput(u8 taskId) gTasks[taskId].func = Task_HandleSearchResultsStartMenuInput; PlaySE(SE_SELECT); } - else if (JOY_NEW(SELECT_BUTTON)) + else if (gMain.newKeys & SELECT_BUTTON) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].tTaskId = LoadSearchMenu(); @@ -1902,7 +1902,7 @@ static void Task_HandleSearchResultsInput(u8 taskId) PlaySE(SE_PC_LOGIN); FreeWindowAndBgBuffers(); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); gTasks[taskId].func = Task_ReturnToPokedexFromSearchResults; @@ -1934,7 +1934,7 @@ static void Task_HandleSearchResultsStartMenuInput(u8 taskId) } else { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (sPokedexView->menuCursorPos) { @@ -1970,18 +1970,18 @@ static void Task_HandleSearchResultsStartMenuInput(u8 taskId) } //Exit menu when Start or B is pressed - if (JOY_NEW(START_BUTTON | B_BUTTON)) + if (gMain.newKeys & (START_BUTTON | B_BUTTON)) { sPokedexView->menuIsOpen = FALSE; gTasks[taskId].func = Task_HandleSearchResultsInput; PlaySE(SE_SELECT); } - else if ((JOY_REPEAT(DPAD_UP)) && sPokedexView->menuCursorPos) + else if ((gMain.newAndRepeatedKeys & DPAD_UP) && sPokedexView->menuCursorPos) { sPokedexView->menuCursorPos--; PlaySE(SE_SELECT); } - else if ((JOY_REPEAT(DPAD_DOWN)) && sPokedexView->menuCursorPos < 4) + else if ((gMain.newAndRepeatedKeys & DPAD_DOWN) && sPokedexView->menuCursorPos < 4) { sPokedexView->menuCursorPos++; PlaySE(SE_SELECT); @@ -2060,10 +2060,10 @@ static bool8 LoadPokedexListPage(u8 page) SetGpuReg(REG_OFFSET_BG2VOFS, sPokedexView->initialVOffset); ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sPokedex_BgTemplate, ARRAY_COUNT(sPokedex_BgTemplate)); - SetBgTilemapBuffer(3, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(2, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(1, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(0, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(3, AllocZeroed(0x800)); + SetBgTilemapBuffer(2, AllocZeroed(0x800)); + SetBgTilemapBuffer(1, AllocZeroed(0x800)); + SetBgTilemapBuffer(0, AllocZeroed(0x800)); DecompressAndLoadBgGfxUsingHeap(3, gPokedexMenu_Gfx, 0x2000, 0, 0); CopyToBgTilemapBuffer(1, gPokedexList_Tilemap, 0, 0); CopyToBgTilemapBuffer(3, gPokedexListUnderlay_Tilemap, 0, 0); @@ -2590,7 +2590,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) u16 startingPos; u8 scrollDir = 0; - if ((JOY_HELD(DPAD_UP)) && (selectedMon > 0)) + if ((gMain.heldKeys & DPAD_UP) && (selectedMon > 0)) { scrollDir = 1; selectedMon = GetNextPosition(1, selectedMon, 0, sPokedexView->pokemonListCount - 1); @@ -2598,7 +2598,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) CreateMonListEntry(1, selectedMon, ignored); PlaySE(SE_DEX_SCROLL); } - else if (JOY_HELD(DPAD_DOWN) && (selectedMon < sPokedexView->pokemonListCount - 1)) + else if ((gMain.heldKeys & DPAD_DOWN) && (selectedMon < sPokedexView->pokemonListCount - 1)) { scrollDir = 2; selectedMon = GetNextPosition(0, selectedMon, 0, sPokedexView->pokemonListCount - 1); @@ -2606,7 +2606,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) CreateMonListEntry(2, selectedMon, ignored); PlaySE(SE_DEX_SCROLL); } - else if (JOY_NEW(DPAD_LEFT) && (selectedMon > 0)) + else if ((gMain.newKeys & DPAD_LEFT) && (selectedMon > 0)) { startingPos = selectedMon; @@ -2617,7 +2617,7 @@ static u16 TryDoPokedexScroll(u16 selectedMon, u16 ignored) CreateMonSpritesAtPos(selectedMon, 0xE); PlaySE(SE_DEX_PAGE); } - else if ((JOY_NEW(DPAD_RIGHT)) && (selectedMon < sPokedexView->pokemonListCount - 1)) + else if ((gMain.newKeys & DPAD_RIGHT) && (selectedMon < sPokedexView->pokemonListCount - 1)) { startingPos = selectedMon; for (i = 0; i < 7; i++) @@ -2666,7 +2666,7 @@ static bool8 TryDoInfoScreenScroll(void) u16 nextPokemon; u16 selectedPokemon = sPokedexView->selectedPokemon; - if ((JOY_NEW(DPAD_UP)) && selectedPokemon) + if ((gMain.newKeys & DPAD_UP) && selectedPokemon) { nextPokemon = selectedPokemon; while (nextPokemon != 0) @@ -2689,7 +2689,7 @@ static bool8 TryDoInfoScreenScroll(void) return TRUE; } } - else if ((JOY_NEW(DPAD_DOWN)) && selectedPokemon < sPokedexView->pokemonListCount - 1) + else if ((gMain.newKeys & DPAD_DOWN) && selectedPokemon < sPokedexView->pokemonListCount - 1) { nextPokemon = selectedPokemon; while (nextPokemon < sPokedexView->pokemonListCount - 1) @@ -3186,10 +3186,10 @@ static u8 LoadInfoScreen(struct PokedexListItem* item, u8 monSpriteId) gTasks[taskId].data[5] = 255; ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sInfoScreen_BgTemplate, ARRAY_COUNT(sInfoScreen_BgTemplate)); - SetBgTilemapBuffer(3, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(2, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(1, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(0, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(3, AllocZeroed(0x800)); + SetBgTilemapBuffer(2, AllocZeroed(0x800)); + SetBgTilemapBuffer(1, AllocZeroed(0x800)); + SetBgTilemapBuffer(0, AllocZeroed(0x800)); InitWindows(sInfoScreen_WindowTemplates); DeactivateAllTextPrinters(); @@ -3356,14 +3356,14 @@ static void Task_HandleInfoScreenInput(u8 taskId) PlaySE(SE_DEX_SCROLL); return; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); gTasks[taskId].func = Task_ExitInfoScreen; PlaySE(SE_PC_OFF); return; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (sPokedexView->selectedScreen) { @@ -3400,8 +3400,8 @@ static void Task_HandleInfoScreenInput(u8 taskId) } return; } - if ((JOY_NEW(DPAD_LEFT) - || (JOY_NEW(L_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if (((gMain.newKeys & DPAD_LEFT) + || ((gMain.newKeys & L_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) && sPokedexView->selectedScreen > 0) { sPokedexView->selectedScreen--; @@ -3409,8 +3409,8 @@ static void Task_HandleInfoScreenInput(u8 taskId) PlaySE(SE_DEX_PAGE); return; } - if ((JOY_NEW(DPAD_RIGHT) - || (JOY_NEW(R_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if (((gMain.newKeys & DPAD_RIGHT) + || ((gMain.newKeys & R_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) && sPokedexView->selectedScreen < CANCEL_SCREEN) { sPokedexView->selectedScreen++; @@ -3630,7 +3630,7 @@ static void Task_HandleCryScreenInput(u8 taskId) else LoadPlayArrowPalette(FALSE); - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { LoadPlayArrowPalette(TRUE); CryScreenPlayButton(NationalPokedexNumToSpecies(sPokedexListItem->dexNum)); @@ -3638,7 +3638,7 @@ static void Task_HandleCryScreenInput(u8 taskId) } else if (!gPaletteFade.active) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { BeginNormalPaletteFade(0xFFFFFFEB, 0, 0, 0x10, RGB_BLACK); m4aMPlayContinue(&gMPlayInfo_BGM); @@ -3647,8 +3647,8 @@ static void Task_HandleCryScreenInput(u8 taskId) PlaySE(SE_PC_OFF); return; } - if ((JOY_NEW(DPAD_LEFT)) - || ((JOY_NEW(L_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if ((gMain.newKeys & DPAD_LEFT) + || ((gMain.newKeys & L_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) { BeginNormalPaletteFade(0xFFFFFFEB, 0, 0, 0x10, RGB_BLACK); m4aMPlayContinue(&gMPlayInfo_BGM); @@ -3657,8 +3657,8 @@ static void Task_HandleCryScreenInput(u8 taskId) PlaySE(SE_DEX_PAGE); return; } - if (JOY_NEW(DPAD_RIGHT) - || (JOY_NEW(R_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if ((gMain.newKeys & DPAD_RIGHT) + || ((gMain.newKeys & R_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) { if (!sPokedexListItem->owned) { @@ -3810,15 +3810,15 @@ static void Task_LoadSizeScreen(u8 taskId) static void Task_HandleSizeScreenInput(u8 taskId) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { BeginNormalPaletteFade(0xFFFFFFEB, 0, 0, 0x10, RGB_BLACK); sPokedexView->screenSwitchState = 1; gTasks[taskId].func = Task_SwitchScreensFromSizeScreen; PlaySE(SE_PC_OFF); } - else if ((JOY_NEW(DPAD_LEFT)) - || ((JOY_NEW(L_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + else if ((gMain.newKeys & DPAD_LEFT) + || ((gMain.newKeys & L_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) { BeginNormalPaletteFade(0xFFFFFFEB, 0, 0, 0x10, RGB_BLACK); sPokedexView->screenSwitchState = 2; @@ -3951,8 +3951,8 @@ static void Task_DisplayCaughtMonDexPage(u8 taskId) ResetOtherVideoRegisters(DISPCNT_BG0_ON); ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sNewEntryInfoScreen_BgTemplate, ARRAY_COUNT(sNewEntryInfoScreen_BgTemplate)); - SetBgTilemapBuffer(3, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(2, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(3, AllocZeroed(0x800)); + SetBgTilemapBuffer(2, AllocZeroed(0x800)); InitWindows(sNewEntryInfoScreen_WindowTemplates); DeactivateAllTextPrinters(); gTasks[taskId].tState = 1; @@ -4010,7 +4010,7 @@ static void Task_DisplayCaughtMonDexPage(u8 taskId) static void Task_HandleCaughtMonPageInput(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { BeginNormalPaletteFade(0x0000FFFF, 0, 0, 16, RGB_BLACK); gSprites[gTasks[taskId].tMonSpriteId].callback = SpriteCB_SlideCaughtMonToCenter; @@ -4167,18 +4167,21 @@ static void PrintMonHeight(u16 height, u8 left, u8 top) static void PrintMonWeight(u16 weight, u8 left, u8 top) { +#ifndef NONMATCHING + asm("":::"r9"); +{ +#endif u8 buffer[16]; - u8 i; bool8 output; + u8 i = 0; u32 lbs = (weight * 100000) / 4536; if (lbs % 10u >= 5) lbs += 10; - - i = 0; output = FALSE; - if ((buffer[i] = (lbs / 100000) + CHAR_0) == CHAR_0 && !output) + buffer[i] = (lbs / 100000) + CHAR_0; + if (buffer[i] == CHAR_0) { buffer[i++] = 0x77; } @@ -4189,7 +4192,8 @@ static void PrintMonWeight(u16 weight, u8 left, u8 top) } lbs %= 100000; - if ((buffer[i] = (lbs / 10000) + CHAR_0) == CHAR_0 && !output) + buffer[i] = (lbs / 10000) + CHAR_0; + if (buffer[i] == CHAR_0 && !output) { buffer[i++] = 0x77; } @@ -4200,13 +4204,13 @@ static void PrintMonWeight(u16 weight, u8 left, u8 top) } lbs %= 10000; - if ((buffer[i] = (lbs / 1000) + CHAR_0) == CHAR_0 && !output) + buffer[i] = (lbs / 1000) + CHAR_0; + if (buffer[i] == CHAR_0 && !output) { buffer[i++] = 0x77; } else { - output = TRUE; i++; } @@ -4222,6 +4226,9 @@ static void PrintMonWeight(u16 weight, u8 left, u8 top) buffer[i++] = CHAR_PERIOD; buffer[i++] = EOS; PrintInfoScreenText(buffer, left, top); +#ifndef NONMATCHING +} +#endif } const u8 *GetPokedexCategoryName(u16 dexNum) // unused @@ -4229,19 +4236,13 @@ const u8 *GetPokedexCategoryName(u16 dexNum) // unused return gPokedexEntries[dexNum].categoryName; } -enum -{ - HEIGHT, - WEIGHT, -}; - u16 GetPokedexHeightWeight(u16 dexNum, u8 data) { switch (data) { - case HEIGHT: + case 0: // height return gPokedexEntries[dexNum].height; - case WEIGHT: + case 1: // weight return gPokedexEntries[dexNum].weight; default: return 1; @@ -4819,10 +4820,10 @@ static void Task_LoadSearchMenu(u8 taskId) ResetOtherVideoRegisters(0); ResetBgsAndClearDma3BusyFlags(0); InitBgsFromTemplates(0, sSearchMenu_BgTemplate, ARRAY_COUNT(sSearchMenu_BgTemplate)); - SetBgTilemapBuffer(3, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(2, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(1, AllocZeroed(BG_SCREEN_SIZE)); - SetBgTilemapBuffer(0, AllocZeroed(BG_SCREEN_SIZE)); + SetBgTilemapBuffer(3, AllocZeroed(0x800)); + SetBgTilemapBuffer(2, AllocZeroed(0x800)); + SetBgTilemapBuffer(1, AllocZeroed(0x800)); + SetBgTilemapBuffer(0, AllocZeroed(0x800)); InitWindows(sSearchMenu_WindowTemplate); DeactivateAllTextPrinters(); PutWindowTilemap(0); @@ -4906,13 +4907,13 @@ static void Task_SwitchToSearchMenuTopBar(u8 taskId) static void Task_HandleSearchTopBarInput(u8 taskId) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_PC_OFF); gTasks[taskId].func = Task_ExitSearch; return; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (gTasks[taskId].tTopBarItem) { @@ -4933,7 +4934,7 @@ static void Task_HandleSearchTopBarInput(u8 taskId) } return; } - if ((JOY_NEW(DPAD_LEFT)) && gTasks[taskId].tTopBarItem > SEARCH_TOPBAR_SEARCH) + if ((gMain.newKeys & DPAD_LEFT) && gTasks[taskId].tTopBarItem > SEARCH_TOPBAR_SEARCH) { PlaySE(SE_DEX_PAGE); gTasks[taskId].tTopBarItem--; @@ -4941,7 +4942,7 @@ static void Task_HandleSearchTopBarInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if ((JOY_NEW(DPAD_RIGHT)) && gTasks[taskId].tTopBarItem < SEARCH_TOPBAR_CANCEL) + if ((gMain.newKeys & DPAD_RIGHT) && gTasks[taskId].tTopBarItem < SEARCH_TOPBAR_CANCEL) { PlaySE(SE_DEX_PAGE); gTasks[taskId].tTopBarItem++; @@ -4980,14 +4981,14 @@ static void Task_HandleSearchMenuInput(u8 taskId) movementMap = sSearchMovementMap_SearchNatDex; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_BALL); SetDefaultSearchModeAndOrder(taskId); gTasks[taskId].func = Task_SwitchToSearchMenuTopBar; return; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (gTasks[taskId].tMenuItem == SEARCH_OK) { @@ -5022,7 +5023,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) return; } - if ((JOY_NEW(DPAD_LEFT)) && movementMap[gTasks[taskId].tMenuItem][0] != 0xFF) + if ((gMain.newKeys & DPAD_LEFT) && movementMap[gTasks[taskId].tMenuItem][0] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][0]; @@ -5030,7 +5031,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if (JOY_NEW(DPAD_RIGHT) && movementMap[gTasks[taskId].tMenuItem][1] != 0xFF) + if ((gMain.newKeys & DPAD_RIGHT) && movementMap[gTasks[taskId].tMenuItem][1] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][1]; @@ -5038,7 +5039,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if ((JOY_NEW(DPAD_UP)) && movementMap[gTasks[taskId].tMenuItem][2] != 0xFF) + if ((gMain.newKeys & DPAD_UP) && movementMap[gTasks[taskId].tMenuItem][2] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][2]; @@ -5046,7 +5047,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if ((JOY_NEW(DPAD_DOWN)) && movementMap[gTasks[taskId].tMenuItem][3] != 0xFF) + if ((gMain.newKeys & DPAD_DOWN) && movementMap[gTasks[taskId].tMenuItem][3] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][3]; @@ -5090,7 +5091,7 @@ static void Task_WaitAndCompleteSearch(u8 taskId) static void Task_SearchCompleteWaitForInput(u8 taskId) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (sPokedexView->pokemonListCount != 0) { @@ -5116,9 +5117,9 @@ static void Task_SelectSearchMenuItem(u8 taskId) u16 *scrollOffset; DrawOrEraseSearchParameterBox(FALSE); - menuItem = (u16)gTasks[taskId].tMenuItem; - cursorPos = (u16*)&gTasks[taskId].data[sSearchOptions[menuItem].taskDataCursorPos]; - scrollOffset = (u16*)&gTasks[taskId].data[sSearchOptions[menuItem].taskDataScrollOffset]; + menuItem = gTasks[taskId].tMenuItem; + cursorPos = &gTasks[taskId].data[sSearchOptions[menuItem].taskDataCursorPos]; + scrollOffset = &gTasks[taskId].data[sSearchOptions[menuItem].taskDataScrollOffset]; gTasks[taskId].tCursorPos = *cursorPos; gTasks[taskId].tScrollOffset = *scrollOffset; PrintSearchParameterText(taskId); @@ -5143,7 +5144,7 @@ static void Task_HandleSearchParameterInput(u8 taskId) cursorPos = &gTasks[taskId].data[sSearchOptions[menuItem].taskDataCursorPos]; scrollOffset = &gTasks[taskId].data[sSearchOptions[menuItem].taskDataScrollOffset]; maxOption = sSearchOptions[menuItem].numOptions - 1; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_PIN); ClearSearchParameterBoxText(); @@ -5153,7 +5154,7 @@ static void Task_HandleSearchParameterInput(u8 taskId) CopyBgTilemapBufferToVram(3); return; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_BALL); ClearSearchParameterBoxText(); @@ -5166,7 +5167,7 @@ static void Task_HandleSearchParameterInput(u8 taskId) return; } moved = FALSE; - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { if (*cursorPos != 0) { @@ -5192,7 +5193,7 @@ static void Task_HandleSearchParameterInput(u8 taskId) } return; } - if (JOY_REPEAT(DPAD_DOWN)) + if (gMain.newAndRepeatedKeys & DPAD_DOWN) { if (*cursorPos < MAX_SEARCH_PARAM_CURSOR_POS && *cursorPos < maxOption) { @@ -5235,24 +5236,83 @@ static void Task_ExitSearchWaitForFade(u8 taskId) } } +#ifdef NONMATCHING +// This doesn't match because gcc flips the naming of the r7 and r6 +// registers. It also does one of the additions backwards. void SetSearchRectHighlight(u8 flags, u8 x, u8 y, u8 width) { - u16 i, temp; //This would have been better as a pointer but here we are - u32 ptr = (u32)GetBgTilemapBuffer(3); //This should be a pointer, but this only matches as a u32. + u16 i; + u16* ptr = GetBgTilemapBuffer(3); + u16* temp; for (i = 0; i < width; i++) { - temp = *(u16 *)(ptr + (y + 0) * 64 + (x + i) * 2); - temp &= 0x0fff; - temp |= (flags << 12); - *(u16 *)(ptr + (y + 0) * 64 + (x + i) * 2) = temp; + // This addition is supposed to be done in this order; however, + // gcc will always do it in ptr + (y * 32) order. + temp = (y * 32) + ptr; + temp[x + i] %= 0x1000; + temp[x + i] |= flags * 0x1000; - temp = *(u16 *)(ptr + (y + 1) * 64 + (x + i) * 2); - temp &= 0x0fff; - temp |= (flags << 12); - *(u16 *)(ptr + (y + 1) * 64 + (x + i) * 2) = temp; + temp[x + i + 32] %= 0x1000; + temp[x + i + 32] |= flags * 0x1000; } } +#else +NAKED +void SetSearchRectHighlight(u8 flags, u8 x, u8 y, u8 width) +{ + asm_unified( + "push {r4-r7,lr}\n\ + mov r7, r8\n\ + push {r7}\n\ + adds r4, r3, 0\n\ + lsls r0, 24\n\ + lsrs r6, r0, 24\n\ + lsls r1, 24\n\ + lsrs r1, 24\n\ + mov r8, r1\n\ + lsls r2, 24\n\ + lsrs r5, r2, 24\n\ + lsls r4, 24\n\ + lsrs r4, 24\n\ + movs r0, 0x3\n\ + bl GetBgTilemapBuffer\n\ + adds r2, r0, 0\n\ + movs r3, 0\n\ + cmp r3, r4\n\ + bcs _080C1DEC\n\ + lsls r0, r5, 6\n\ + adds r7, r0, r2\n\ + ldr r5, =0x00000fff\n\ + lsls r2, r6, 12\n\ +_080C1DC8:\n\ + mov r0, r8\n\ + adds r1, r0, r3\n\ + lsls r1, 1\n\ + adds r1, r7\n\ + ldrh r0, [r1]\n\ + ands r0, r5\n\ + orrs r0, r2\n\ + strh r0, [r1]\n\ + adds r1, 0x40\n\ + ldrh r0, [r1]\n\ + ands r0, r5\n\ + orrs r0, r2\n\ + strh r0, [r1]\n\ + adds r0, r3, 0x1\n\ + lsls r0, 16\n\ + lsrs r3, r0, 16\n\ + cmp r3, r4\n\ + bcc _080C1DC8\n\ +_080C1DEC:\n\ + pop {r3}\n\ + mov r8, r3\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool"); +} +#endif #define SEARCH_BG_SEARCH SEARCH_TOPBAR_SEARCH #define SEARCH_BG_SHIFT SEARCH_TOPBAR_SHIFT @@ -5452,8 +5512,8 @@ static void PrintSearchParameterText(u8 taskId) const struct SearchOptionText *texts = sSearchOptions[gTasks[taskId].tMenuItem].texts; const u16 *cursorPos = &gTasks[taskId].data[sSearchOptions[gTasks[taskId].tMenuItem].taskDataCursorPos]; const u16 *scrollOffset = &gTasks[taskId].data[sSearchOptions[gTasks[taskId].tMenuItem].taskDataScrollOffset]; - - u16 i, j; + u16 i; + u16 j; ClearSearchParameterBoxText(); @@ -5542,7 +5602,8 @@ static bool8 SearchParamCantScrollUp(u8 taskId) if (lastOption > MAX_SEARCH_PARAM_CURSOR_POS && *scrollOffset != 0) return FALSE; - return TRUE; + else + return TRUE; } static bool8 SearchParamCantScrollDown(u8 taskId) @@ -5553,7 +5614,8 @@ static bool8 SearchParamCantScrollDown(u8 taskId) if (lastOption > MAX_SEARCH_PARAM_CURSOR_POS && *scrollOffset < lastOption - MAX_SEARCH_PARAM_CURSOR_POS) return FALSE; - return TRUE; + else + return TRUE; } #define sTaskId data[0] diff --git a/src/pokedex_area_screen.c b/src/pokedex_area_screen.c index fdbd2f40c..8450f8530 100755 --- a/src/pokedex_area_screen.c +++ b/src/pokedex_area_screen.c @@ -724,12 +724,12 @@ static void Task_HandlePokedexAreaScreenInput(u8 taskId) return; break; case 1: - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { gTasks[taskId].data[1] = 1; PlaySE(SE_PC_OFF); } - else if (JOY_NEW(DPAD_RIGHT) || (JOY_NEW(R_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + else if (gMain.newKeys & DPAD_RIGHT || (gMain.newKeys & R_BUTTON && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) { gTasks[taskId].data[1] = 2; PlaySE(SE_DEX_PAGE); diff --git a/src/pokemon.c b/src/pokemon.c index a0e655d1e..188624d6a 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -70,7 +70,7 @@ EWRAM_DATA u8 gEnemyPartyCount = 0; EWRAM_DATA struct Pokemon gPlayerParty[PARTY_SIZE] = {0}; EWRAM_DATA struct Pokemon gEnemyParty[PARTY_SIZE] = {0}; EWRAM_DATA struct SpriteTemplate gMultiuseSpriteTemplate = {0}; -EWRAM_DATA struct Unknown_806F160_Struct *gUnknown_020249B4[2] = {NULL, NULL}; +EWRAM_DATA struct Unknown_806F160_Struct *gUnknown_020249B4[2] = {NULL}; // const rom data #include "data/battle_moves.h" @@ -5746,29 +5746,25 @@ u8 GetTrainerEncounterMusicId(u16 trainerOpponentId) u16 ModifyStatByNature(u8 nature, u16 n, u8 statIndex) { - u16 retVal; // Dont modify HP, Accuracy, or Evasion by nature if (statIndex <= STAT_HP || statIndex > NUM_NATURE_STATS) { - return n; + // Should just be "return n", but it wouldn't match without this. + u16 retVal = n; + retVal++; + retVal--; + return retVal; } switch (gNatureStatTable[nature][statIndex - 1]) { case 1: - retVal = n * 110; - retVal /= 100; - break; + return (u16)(n * 110) / 100; // NOTE: will overflow for n > 595 because the intermediate value is cast to u16 before the division. Fix by removing (u16) cast case -1: - retVal = n * 90; - retVal /= 100; - break; - default: - retVal = n; - break; + return (u16)(n * 90) / 100; // NOTE: will overflow for n > 728, see above } - return retVal; + return n; } #define IS_LEAGUE_BATTLE \ @@ -6808,16 +6804,19 @@ static bool8 ShouldSkipFriendshipChange(void) return FALSE; } -#define MAGIC_NUMBER 0xA3 +#define FORCE_SIGNED(x)(-(x * (-1))) static void sub_806F160(struct Unknown_806F160_Struct* structPtr) { u16 i, j; - for (i = 0; i < structPtr->field_0_0; i++) + for (i = 0; i < FORCE_SIGNED(structPtr->field_0_0); i++) { structPtr->templates[i] = gUnknown_08329D98[i]; for (j = 0; j < structPtr->field_1; j++) { + #ifndef NONMATCHING + asm(""); + #endif structPtr->frameImages[i * structPtr->field_1 + j].data = &structPtr->byteArrays[i][j * 0x800]; } structPtr->templates[i].images = &structPtr->frameImages[i * structPtr->field_1]; @@ -6827,7 +6826,7 @@ static void sub_806F160(struct Unknown_806F160_Struct* structPtr) static void sub_806F1FC(struct Unknown_806F160_Struct* structPtr) { u16 i, j; - for (i = 0; i < structPtr->field_0_0; i++) + for (i = 0; i < FORCE_SIGNED(structPtr->field_0_0); i++) { structPtr->templates[i] = gUnknown_08329F28; for (j = 0; j < structPtr->field_1; j++) @@ -6858,7 +6857,7 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1) structPtr->field_0_0 = 7; structPtr->field_0_1 = 7; structPtr->field_1 = 4; - structPtr->size = 1; + structPtr->field_3_0 = 1; structPtr->field_3_1 = 2; break; case 0: @@ -6866,12 +6865,12 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1) structPtr->field_0_0 = 4; structPtr->field_0_1 = 4; structPtr->field_1 = 4; - structPtr->size = 1; + structPtr->field_3_0 = 1; structPtr->field_3_1 = 0; break; } - structPtr->bytes = AllocZeroed(structPtr->size * 0x800 * 4 * structPtr->field_0_0); + structPtr->bytes = AllocZeroed(structPtr->field_3_0 * 0x800 * 4 * structPtr->field_0_0); structPtr->byteArrays = AllocZeroed(structPtr->field_0_0 * 32); if (structPtr->bytes == NULL || structPtr->byteArrays == NULL) { @@ -6879,8 +6878,8 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1) } else { - for (i = 0; i < structPtr->field_0_0; i++) - structPtr->byteArrays[i] = structPtr->bytes + (structPtr->size * (i << 0xD)); + for (i = 0; i < FORCE_SIGNED(structPtr->field_0_0); i++) + structPtr->byteArrays[i] = structPtr->bytes + (structPtr->field_3_0 * (i << 0xD)); } structPtr->templates = AllocZeroed(sizeof(struct SpriteTemplate) * structPtr->field_0_0); @@ -6899,8 +6898,8 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1) case 2: sub_806F1FC(structPtr); break; - case 1: case 0: + case 1: default: sub_806F160(structPtr); break; @@ -6929,7 +6928,7 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1) } else { - structPtr->magic = MAGIC_NUMBER; + structPtr->magic = 0xA3; gUnknown_020249B4[id] = structPtr; } @@ -6940,12 +6939,12 @@ void sub_806F47C(u8 id) { struct Unknown_806F160_Struct *structPtr; - id &= 1; + id %= 2; structPtr = gUnknown_020249B4[id]; if (structPtr == NULL) return; - if (structPtr->magic != MAGIC_NUMBER) + if (structPtr->magic != 0xA3) { memset(structPtr, 0, sizeof(struct Unknown_806F160_Struct)); } @@ -6969,13 +6968,15 @@ void sub_806F47C(u8 id) u8 *sub_806F4F8(u8 id, u8 arg1) { struct Unknown_806F160_Struct *structPtr = gUnknown_020249B4[id % 2]; - if (structPtr->magic != MAGIC_NUMBER) + if (structPtr->magic != 0xA3) { return NULL; } - - if (arg1 >= structPtr->field_0_0) - arg1 = 0; + else + { + if (arg1 >= FORCE_SIGNED(structPtr->field_0_0)) + arg1 = 0; - return structPtr->byteArrays[arg1]; + return structPtr->byteArrays[arg1]; + } } diff --git a/src/pokemon_animation.c b/src/pokemon_animation.c index e63a2cef1..37abb90e9 100644 --- a/src/pokemon_animation.c +++ b/src/pokemon_animation.c @@ -2884,10 +2884,13 @@ static void sub_8181C2C(struct Sprite *sprite) } else { + #ifndef NONMATCHING + register s32 var asm("r4") = sUnknown_03001240[sprite->data[0]].field_8; + #else + s32 var = sUnknown_03001240[sprite->data[0]].field_8; + #endif - const s16 var = sUnknown_03001240[sprite->data[0]].field_8; - - sprite->pos2.x = var * ((counter % 128) * 8) / 128 + 8 * -var; //Should be - 8 * var instead of + 8 * -var, but that doesn't match + sprite->pos2.x = (var << 3) * (counter % 128) / 128 - (sUnknown_03001240[sprite->data[0]].field_8 * 8); sprite->pos2.y = -(Sin(counter % 128, 8)); } diff --git a/src/pokemon_jump.c b/src/pokemon_jump.c index 84d869a1a..81f3a784f 100755 --- a/src/pokemon_jump.c +++ b/src/pokemon_jump.c @@ -406,7 +406,7 @@ void StartPokemonJump(u16 partyIndex, MainCallback callback) if (gReceivedRemoteLinkPlayers) { - gUnknown_02022CFC = Alloc(sizeof(struct PokemonJump1)); + gUnknown_02022CFC = Alloc(sizeof(*gUnknown_02022CFC)); if (gUnknown_02022CFC) { ResetTasks(); @@ -1245,7 +1245,7 @@ static bool32 sub_802B8CC(void) break; // fall through case 1: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { sub_802C164(); sub_802AE14(3); @@ -1336,7 +1336,7 @@ static bool32 sub_802BA58(void) case 2: case 5: gUnknown_02022CFC->unk3C++; - if (JOY_NEW(A_BUTTON | B_BUTTON) || gUnknown_02022CFC->unk3C > 180) + if (gMain.newKeys & (A_BUTTON | B_BUTTON) || gUnknown_02022CFC->unk3C > 180) { sub_802DA14(); gUnknown_02022CFC->unkA++; @@ -3922,7 +3922,7 @@ static void Task_ShowPokemonJumpRecords(u8 taskId) data[0]++; break; case 2: - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { rbox_fill_rectangle(data[1]); CopyWindowToVram(data[1], 1); diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index ae334504e..546f50dce 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -1756,10 +1756,10 @@ static void Task_PokemonStorageSystemPC(u8 taskId) { case MENU_NOTHING_CHOSEN: task->data[3] = task->data[1]; - if (JOY_NEW(DPAD_UP) && --task->data[3] < 0) + if (gMain.newKeys & DPAD_UP && --task->data[3] < 0) task->data[3] = 4; - if (JOY_NEW(DPAD_DOWN) && ++task->data[3] > 4) + if (gMain.newKeys & DPAD_DOWN && ++task->data[3] > 4) task->data[3] = 0; if (task->data[1] != task->data[3]) { @@ -1798,13 +1798,13 @@ static void Task_PokemonStorageSystemPC(u8 taskId) } break; case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, 1, gUnknown_085716C0[task->data[1]].desc, 0, NULL, 2, 1, 3); task->data[0] = 2; } - else if (JOY_NEW(DPAD_UP)) + else if (gMain.newKeys & DPAD_UP) { if (--task->data[1] < 0) task->data[1] = 4; @@ -1814,7 +1814,7 @@ static void Task_PokemonStorageSystemPC(u8 taskId) AddTextPrinterParameterized2(0, 1, gUnknown_085716C0[task->data[1]].desc, 0, NULL, 2, 1, 3); task->data[0] = 2; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { if (++task->data[1] > 3) task->data[1] = 0; @@ -1976,22 +1976,22 @@ static void sub_80C78E4(void) static u8 HandleBoxChooseSelectionInput(void) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); return 201; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); return gUnknown_02039D04->curBox; } - if (JOY_NEW(DPAD_LEFT)) + if (gMain.newKeys & DPAD_LEFT) { PlaySE(SE_SELECT); sub_80C7BB4(); } - else if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) { PlaySE(SE_SELECT); sub_80C7B80(); @@ -2157,7 +2157,7 @@ static void Cb2_EnterPSS(u8 boxOption) { ResetTasks(); sCurrentBoxOption = boxOption; - sPSSData = Alloc(sizeof(struct PokemonStorageSystemData)); + sPSSData = Alloc(sizeof(*sPSSData)); if (sPSSData == NULL) { SetMainCallback2(Cb2_ExitPSS); @@ -2177,7 +2177,7 @@ static void Cb2_EnterPSS(u8 boxOption) static void Cb2_ReturnToPSS(void) { ResetTasks(); - sPSSData = Alloc(sizeof(struct PokemonStorageSystemData)); + sPSSData = Alloc(sizeof(*sPSSData)); if (sPSSData == NULL) { SetMainCallback2(Cb2_ExitPSS); @@ -2393,7 +2393,7 @@ static void Cb_ReshowPSS(u8 taskId) } break; case 2: - if (!IsDma3ManagerBusyWithBgCopy() && JOY_NEW(A_BUTTON | B_BUTTON)) + if (!IsDma3ManagerBusyWithBgCopy() && gMain.newKeys & (A_BUTTON | B_BUTTON)) { ClearBottomWindow(); sPSSData->state++; @@ -2615,7 +2615,7 @@ static void Cb_MainPSS(u8 taskId) } break; case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); sPSSData->state = 0; @@ -2632,7 +2632,7 @@ static void Cb_MainPSS(u8 taskId) sPSSData->state = 6; break; case 6: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); @@ -2858,7 +2858,7 @@ static void Cb_OnSelectedMon(u8 taskId) sPSSData->state = 6; break; case 6: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); @@ -2943,7 +2943,7 @@ static void Cb_WithdrawMon(u8 taskId) } break; case 1: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); @@ -3034,7 +3034,7 @@ static void Cb_DepositMenu(u8 taskId) } break; case 4: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { PrintStorageActionText(PC_TEXT_DEPOSIT_IN_WHICH_BOX); sPSSData->state = 1; @@ -3095,14 +3095,14 @@ static void Cb_ReleaseMon(u8 taskId) sPSSData->state++; break; case 4: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { PrintStorageActionText(PC_TEXT_BYE_BYE); sPSSData->state++; } break; case 5: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); if (sInPartyMenu) @@ -3134,14 +3134,14 @@ static void Cb_ReleaseMon(u8 taskId) sPSSData->state++; break; case 9: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { PrintStorageActionText(PC_TEXT_SURPRISE); sPSSData->state++; } break; case 10: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); sub_80CC064(); @@ -3157,14 +3157,14 @@ static void Cb_ReleaseMon(u8 taskId) } break; case 12: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { PrintStorageActionText(PC_TEXT_WORRIED); sPSSData->state++; } break; case 13: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); @@ -3257,7 +3257,7 @@ static void Cb_GiveMovingItemToMon(u8 taskId) } break; case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); sPSSData->state++; @@ -3296,7 +3296,7 @@ static void Cb_ItemToBag(u8 taskId) } break; case 2: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); sub_80CE00C(); @@ -3309,7 +3309,7 @@ static void Cb_ItemToBag(u8 taskId) SetPSSCallback(Cb_MainPSS); break; case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); @@ -3349,7 +3349,7 @@ static void Cb_SwitchSelectedItem(u8 taskId) } break; case 3: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); sPSSData->state++; @@ -3388,7 +3388,7 @@ static void Cb_ShowItemInfo(u8 taskId) sPSSData->state++; break; case 4: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { PlaySE(SE_WIN_OPEN); sPSSData->state++; @@ -3438,7 +3438,7 @@ static void Cb_CloseBoxWhileHoldingItem(u8 taskId) } break; case 2: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); sPSSData->state = 5; @@ -3494,7 +3494,7 @@ static void Cb_PrintCantStoreMail(u8 taskId) sPSSData->state++; break; case 2: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); sPSSData->state++; @@ -3759,7 +3759,7 @@ static void Cb_OnCloseBoxPressed(u8 taskId) } break; case 1: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); @@ -3820,7 +3820,7 @@ static void Cb_OnBPressed(u8 taskId) } break; case 1: - if (JOY_NEW(A_BUTTON | B_BUTTON | DPAD_ANY)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON | DPAD_ANY)) { ClearBottomWindow(); SetPSSCallback(Cb_MainPSS); @@ -5462,7 +5462,7 @@ static void sub_80CCA3C(const void *tilemap, s8 direction, u8 arg2) if (direction == 0) return; - if (direction > 0) + else if (direction > 0) x *= 1, x += 0x14; // x * 1 is needed to match, but can be safely removed as it makes no functional difference else x -= 4; @@ -6940,7 +6940,7 @@ static u8 InBoxInput_Normal(void) sPSSData->field_CD3 = 0; sPSSData->field_CD7 = 0; - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { retVal = TRUE; if (sBoxCursorPosition >= IN_BOX_ROWS) @@ -6954,7 +6954,7 @@ static u8 InBoxInput_Normal(void) } break; } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { retVal = TRUE; cursorPosition += IN_BOX_ROWS; @@ -6968,7 +6968,7 @@ static u8 InBoxInput_Normal(void) } break; } - else if (JOY_REPEAT(DPAD_LEFT)) + else if (gMain.newAndRepeatedKeys & DPAD_LEFT) { retVal = TRUE; if (sBoxCursorPosition % IN_BOX_ROWS != 0) @@ -6982,7 +6982,7 @@ static u8 InBoxInput_Normal(void) } break; } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { retVal = TRUE; if ((sBoxCursorPosition + 1) % IN_BOX_ROWS != 0) @@ -6996,7 +6996,7 @@ static u8 InBoxInput_Normal(void) } break; } - else if (JOY_NEW(START_BUTTON)) + else if (gMain.newKeys & START_BUTTON) { retVal = TRUE; cursorArea = CURSOR_AREA_BOX; @@ -7004,7 +7004,7 @@ static u8 InBoxInput_Normal(void) break; } - if ((JOY_NEW(A_BUTTON)) && sub_80CFA5C()) + if ((gMain.newKeys & A_BUTTON) && sub_80CFA5C()) { if (!sCanOnlyMove) return 8; @@ -7038,18 +7038,18 @@ static u8 InBoxInput_Normal(void) } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) return 19; if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { - if (JOY_HELD(L_BUTTON)) + if (gMain.heldKeys & L_BUTTON) return 10; - if (JOY_HELD(R_BUTTON)) + if (gMain.heldKeys & R_BUTTON) return 9; } - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { sub_80CFDC4(); return 0; @@ -7067,9 +7067,9 @@ static u8 InBoxInput_Normal(void) static u8 InBoxInput_GrabbingMultiple(void) { - if (JOY_HELD(A_BUTTON)) + if (gMain.heldKeys & A_BUTTON) { - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { if (sBoxCursorPosition / IN_BOX_ROWS != 0) { @@ -7081,7 +7081,7 @@ static u8 InBoxInput_GrabbingMultiple(void) return 24; } } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { if (sBoxCursorPosition + IN_BOX_ROWS < IN_BOX_COUNT) { @@ -7093,7 +7093,7 @@ static u8 InBoxInput_GrabbingMultiple(void) return 24; } } - else if (JOY_REPEAT(DPAD_LEFT)) + else if (gMain.newAndRepeatedKeys & DPAD_LEFT) { if (sBoxCursorPosition % IN_BOX_ROWS != 0) { @@ -7105,7 +7105,7 @@ static u8 InBoxInput_GrabbingMultiple(void) return 24; } } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { if ((sBoxCursorPosition + 1) % IN_BOX_ROWS != 0) { @@ -7142,7 +7142,7 @@ static u8 InBoxInput_GrabbingMultiple(void) static u8 InBoxInput_MovingMultiple(void) { - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { if (sub_80D0580(0)) { @@ -7154,7 +7154,7 @@ static u8 InBoxInput_MovingMultiple(void) return 24; } } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { if (sub_80D0580(1)) { @@ -7166,7 +7166,7 @@ static u8 InBoxInput_MovingMultiple(void) return 24; } } - else if (JOY_REPEAT(DPAD_LEFT)) + else if (gMain.newAndRepeatedKeys & DPAD_LEFT) { if (sub_80D0580(2)) { @@ -7178,7 +7178,7 @@ static u8 InBoxInput_MovingMultiple(void) return 10; } } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { if (sub_80D0580(3)) { @@ -7190,7 +7190,7 @@ static u8 InBoxInput_MovingMultiple(void) return 9; } } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (sub_80D0BC0()) { @@ -7203,7 +7203,7 @@ static u8 InBoxInput_MovingMultiple(void) return 24; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return 24; } @@ -7211,9 +7211,9 @@ static u8 InBoxInput_MovingMultiple(void) { if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { - if (JOY_HELD(L_BUTTON)) + if (gMain.heldKeys & L_BUTTON) return 10; - if (JOY_HELD(R_BUTTON)) + if (gMain.heldKeys & R_BUTTON) return 9; } @@ -7238,7 +7238,7 @@ static u8 HandleInput_InParty(void) gotoBox = FALSE; retVal = 0; - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { if (--cursorPosition < 0) cursorPosition = PARTY_SIZE; @@ -7246,7 +7246,7 @@ static u8 HandleInput_InParty(void) retVal = 1; break; } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { if (++cursorPosition > PARTY_SIZE) cursorPosition = 0; @@ -7254,14 +7254,14 @@ static u8 HandleInput_InParty(void) retVal = 1; break; } - else if (JOY_REPEAT(DPAD_LEFT) && sBoxCursorPosition != 0) + else if (gMain.newAndRepeatedKeys & DPAD_LEFT && sBoxCursorPosition != 0) { retVal = 1; sPSSData->field_CD6 = sBoxCursorPosition; cursorPosition = 0; break; } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { if (sBoxCursorPosition == 0) { @@ -7277,7 +7277,7 @@ static u8 HandleInput_InParty(void) break; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (sBoxCursorPosition == PARTY_SIZE) { @@ -7313,7 +7313,7 @@ static u8 HandleInput_InParty(void) } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { if (sPSSData->boxOption == BOX_OPTION_DEPOSIT) return 19; @@ -7327,7 +7327,7 @@ static u8 HandleInput_InParty(void) cursorArea = CURSOR_AREA_IN_BOX; cursorPosition = 0; } - else if (JOY_NEW(SELECT_BUTTON)) + else if (gMain.newKeys & SELECT_BUTTON) { sub_80CFDC4(); return 0; @@ -7356,7 +7356,7 @@ static u8 HandleInput_OnBox(void) sPSSData->field_CD2 = 0; sPSSData->field_CD7 = 0; - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { retVal = 1; cursorArea = CURSOR_AREA_BUTTONS; @@ -7364,7 +7364,7 @@ static u8 HandleInput_OnBox(void) sPSSData->field_CD7 = 1; break; } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { retVal = 1; cursorArea = CURSOR_AREA_IN_BOX; @@ -7372,30 +7372,30 @@ static u8 HandleInput_OnBox(void) break; } - if (JOY_HELD(DPAD_LEFT)) + if (gMain.heldKeys & DPAD_LEFT) return 10; - if (JOY_HELD(DPAD_RIGHT)) + if (gMain.heldKeys & DPAD_RIGHT) return 9; if (gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR) { - if (JOY_HELD(L_BUTTON)) + if (gMain.heldKeys & L_BUTTON) return 10; - if (JOY_HELD(R_BUTTON)) + if (gMain.heldKeys & R_BUTTON) return 9; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { sub_80CD1A8(FALSE); AddBoxMenu(); return 7; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) return 19; - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { sub_80CFDC4(); return 0; @@ -7429,7 +7429,7 @@ static u8 HandleInput_OnButtons(void) sPSSData->field_CD2 = 0; sPSSData->field_CD7 = 0; - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { retVal = 1; cursorArea = CURSOR_AREA_IN_BOX; @@ -7441,8 +7441,7 @@ static u8 HandleInput_OnButtons(void) sPSSData->field_CD7 = 1; break; } - - if (JOY_REPEAT(DPAD_DOWN | START_BUTTON)) + else if (gMain.newAndRepeatedKeys & (DPAD_DOWN | START_BUTTON)) { retVal = 1; cursorArea = CURSOR_AREA_BOX; @@ -7451,14 +7450,14 @@ static u8 HandleInput_OnButtons(void) break; } - if (JOY_REPEAT(DPAD_LEFT)) + if (gMain.newAndRepeatedKeys & DPAD_LEFT) { retVal = 1; if (--cursorPosition < 0) cursorPosition = 1; break; } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { retVal = 1; if (++cursorPosition > 1) @@ -7466,12 +7465,12 @@ static u8 HandleInput_OnButtons(void) break; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) return (cursorPosition == 0) ? 5 : 4; - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) return 19; - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { sub_80CFDC4(); return 0; @@ -7920,23 +7919,23 @@ static s16 sub_80D00AC(void) do { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { textId = Menu_GetCursorPos(); break; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); textId = -1; } - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { PlaySE(SE_SELECT); Menu_MoveCursor(-1); } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { PlaySE(SE_SELECT); Menu_MoveCursor(1); diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c index bfd849229..d016c455c 100644 --- a/src/pokemon_summary_screen.c +++ b/src/pokemon_summary_screen.c @@ -1497,23 +1497,23 @@ static void Task_HandleInput(u8 taskId) { if (MenuHelpers_CallLinkSomething() != TRUE && !gPaletteFade.active) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { ChangeSummaryPokemon(taskId, -1); } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { ChangeSummaryPokemon(taskId, 1); } - else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) + else if ((gMain.newKeys & DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) { ChangePage(taskId, -1); } - else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) + else if ((gMain.newKeys & DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) { ChangePage(taskId, 1); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (sMonSummaryScreen->currPageIndex != PSS_PAGE_SKILLS) { @@ -1530,7 +1530,7 @@ static void Task_HandleInput(u8 taskId) } } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { StopPokemonAnimations(); PlaySE(SE_SELECT); @@ -1878,17 +1878,17 @@ static void Task_HandleInput_MoveSelect(u8 taskId) if (MenuHelpers_CallLinkSomething() != 1) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { data[0] = 4; ChangeSelectedMove(data, -1, &sMonSummaryScreen->firstMoveIndex); } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { data[0] = 4; ChangeSelectedMove(data, 1, &sMonSummaryScreen->firstMoveIndex); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (sMonSummaryScreen->lockMovesFlag == TRUE || (sMonSummaryScreen->newMove == MOVE_NONE && sMonSummaryScreen->firstMoveIndex == MAX_MON_MOVES)) @@ -1906,7 +1906,7 @@ static void Task_HandleInput_MoveSelect(u8 taskId) PlaySE(SE_FAILURE); } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); CloseMoveSelectMode(taskId); @@ -2018,24 +2018,24 @@ static void Task_HandleInput_MovePositionSwitch(u8 taskId) if (MenuHelpers_CallLinkSomething() != TRUE) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { data[0] = 3; ChangeSelectedMove(&data[0], -1, &sMonSummaryScreen->secondMoveIndex); } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { data[0] = 3; ChangeSelectedMove(&data[0], 1, &sMonSummaryScreen->secondMoveIndex); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (sMonSummaryScreen->firstMoveIndex == sMonSummaryScreen->secondMoveIndex) ExitMovePositionSwitchMode(taskId, FALSE); else ExitMovePositionSwitchMode(taskId, TRUE); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { ExitMovePositionSwitchMode(taskId, FALSE); } @@ -2161,25 +2161,25 @@ static void Task_HandleReplaceMoveInput(u8 taskId) { if (gPaletteFade.active != TRUE) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { data[0] = 4; ChangeSelectedMove(data, -1, &sMonSummaryScreen->firstMoveIndex); } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { data[0] = 4; ChangeSelectedMove(data, 1, &sMonSummaryScreen->firstMoveIndex); } - else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) + else if (gMain.newKeys & DPAD_LEFT || GetLRKeysPressed() == MENU_L_PRESSED) { ChangePage(taskId, -1); } - else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) + else if (gMain.newKeys & DPAD_RIGHT || GetLRKeysPressed() == MENU_R_PRESSED) { ChangePage(taskId, 1); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (CanReplaceMove() == TRUE) { @@ -2195,7 +2195,7 @@ static void Task_HandleReplaceMoveInput(u8 taskId) ShowCantForgetHMsWindow(taskId); } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { StopPokemonAnimations(); PlaySE(SE_SELECT); @@ -2235,7 +2235,7 @@ static void Task_HandleInputCantForgetHMsMoves(u8 taskId) u16 move; if (FuncIsActiveTask(Task_ShowPowerAccWindow) != 1) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { data[1] = 1; data[0] = 4; @@ -2243,7 +2243,7 @@ static void Task_HandleInputCantForgetHMsMoves(u8 taskId) data[1] = 0; gTasks[taskId].func = Task_HandleReplaceMoveInput; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { data[1] = 1; data[0] = 4; @@ -2251,7 +2251,7 @@ static void Task_HandleInputCantForgetHMsMoves(u8 taskId) data[1] = 0; gTasks[taskId].func = Task_HandleReplaceMoveInput; } - else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) + else if (gMain.newKeys & DPAD_LEFT || GetLRKeysPressed() == MENU_L_PRESSED) { if (sMonSummaryScreen->currPageIndex != PSS_PAGE_BATTLE_MOVES) { @@ -2265,7 +2265,7 @@ static void Task_HandleInputCantForgetHMsMoves(u8 taskId) HandleAppealJamTilemap(9, -2, move); } } - else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) + else if (gMain.newKeys & DPAD_RIGHT || GetLRKeysPressed() == MENU_R_PRESSED) { if (sMonSummaryScreen->currPageIndex != PSS_PAGE_CONTEST_MOVES) { @@ -2279,7 +2279,7 @@ static void Task_HandleInputCantForgetHMsMoves(u8 taskId) HandleAppealJamTilemap(9, -2, move); } } - else if (JOY_NEW(A_BUTTON | B_BUTTON)) + else if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { ClearWindowTilemap(PSS_LABEL_WINDOW_PORTRAIT_SPECIES); if (!gSprites[sMonSummaryScreen->spriteIds[SPRITE_ARR_ID_STATUS]].invisible) diff --git a/src/pokenav.c b/src/pokenav.c index 30dc001c3..8ea33575a 100644 --- a/src/pokenav.c +++ b/src/pokenav.c @@ -317,7 +317,7 @@ static void Task_RunLoopedTask_LinkMode(u8 taskId) void CB2_InitPokeNav(void) { - gPokenavResources = Alloc(sizeof(struct PokenavResources)); + gPokenavResources = Alloc(sizeof(*gPokenavResources)); if (gPokenavResources == NULL) { SetMainCallback2(CB2_ReturnToFieldWithOpenMenu); @@ -345,7 +345,7 @@ static void CB2_InitPokenavForTutorial(void) if (gPaletteFade.active) return; - gPokenavResources = Alloc(sizeof(struct PokenavResources)); + gPokenavResources = Alloc(sizeof(*gPokenavResources)); if (gPokenavResources == NULL) { SetMainCallback2(CB2_ReturnToFieldContinueScriptPlayMapMusic); diff --git a/src/pokenav_conditions_1.c b/src/pokenav_conditions_1.c index 488d40d13..1c7573a44 100644 --- a/src/pokenav_conditions_1.c +++ b/src/pokenav_conditions_1.c @@ -89,13 +89,13 @@ u32 sub_81CD08C(struct PokenavSub11 *structPtr) if (ret == 0) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); structPtr->unk6304 = sub_81CD19C; ret = 2; } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (structPtr->unk6300 == 0) { @@ -166,7 +166,7 @@ u8 sub_81CD1E4(struct PokenavSub11 *structPtr) struct PokenavSub18 *unkPtr = GetSubstructPtr(18); u8 ret = 0; - if (JOY_HELD(DPAD_UP)) + if (gMain.heldKeys & DPAD_UP) { if (structPtr->unk6300 == 0 || unkPtr->unk2 != 0) { @@ -174,7 +174,7 @@ u8 sub_81CD1E4(struct PokenavSub11 *structPtr) ret = sub_81CD258(1); } } - else if (JOY_HELD(DPAD_DOWN)) + else if (gMain.heldKeys & DPAD_DOWN) { if (structPtr->unk6300 == 0 || unkPtr->unk2 < unkPtr->unk0 - 1) { diff --git a/src/pokenav_conditions_3.c b/src/pokenav_conditions_3.c index 15b687a42..eea4aa397 100644 --- a/src/pokenav_conditions_3.c +++ b/src/pokenav_conditions_3.c @@ -170,28 +170,29 @@ static bool32 sub_81CF010(struct PokenavSub7 *structPtr) static u32 sub_81CF030(struct PokenavSub7 *structPtr) { - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) return 1; - if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) return 2; - if (JOY_NEW(DPAD_LEFT)) + else if (gMain.newKeys & DPAD_LEFT) return 3; - if (JOY_NEW(DPAD_RIGHT)) + else if (gMain.newKeys & DPAD_RIGHT) return 4; - if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { structPtr->unk1C = 0; structPtr->unk0 = sub_81CF0B0; return 5; } - if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { structPtr->unkPtr->unk2 = GetSelectedMatchCall(); structPtr->unk1C = 1; structPtr->unk0 = sub_81CF0B8; return 6; } - return 0; + else + return 0; } static u32 sub_81CF0B0(struct PokenavSub7 *structPtr) diff --git a/src/pokenav_main_menu.c b/src/pokenav_main_menu.c index f2b9b0dcc..0e2425d4e 100644 --- a/src/pokenav_main_menu.c +++ b/src/pokenav_main_menu.c @@ -436,10 +436,9 @@ static u32 LoopedTask_ScrollMenuHeaderUp(s32 a0) if (ChangeBgY(0, 384, 2) <= 0) { ChangeBgY(0, 0, 0); - return LT_FINISH; + return 4; } - - return LT_PAUSE; + return 2; } void CopyPaletteIntoBufferUnfaded(const u16 *palette, u32 bufferOffset, u32 size) @@ -459,9 +458,11 @@ void Pokenav_AllocAndLoadPalettes(const struct SpritePalette *palettes) { break; } - - index = (index * 16) + 0x100; - CopyPaletteIntoBufferUnfaded(current->data, index, 0x20); + else + { + index = (index * 16) + 0x100; + CopyPaletteIntoBufferUnfaded(current->data, index, 0x20); + } } } @@ -470,41 +471,139 @@ void sub_81C7990(u32 a0, u16 a1) CpuFill16(a1, gPlttBufferFaded + 0x100 + (a0 * 16), 16 * sizeof(u16)); } -void sub_81C79BC(const u16 *a0, const u16 *a1, int a2, int a3, int a4, u16 *palette) +NAKED +void sub_81C79BC(const u16 *a0, const u16 *a1, u32 a2, u32 a3, u32 a4, u16 *a5) { - - if (a4 == 0) - { - CpuCopy16(a0, palette, a2 * 2); - } - else if (a4 >= a3) - { - CpuCopy16(a1, palette, a2 * 2); - } - else - { - int r, g, b; - int r1, g1, b1; - while (a2--) - { - r = GET_R(*a0); - g = GET_G(*a0); - b = GET_B(*a0); - - r1 = ((((GET_R(*a1) << 8) - (r << 8)) / a3) * a4) >> 8; - g1 = ((((GET_G(*a1) << 8) - (g << 8)) / a3) * a4) >> 8; - b1 = ((((GET_B(*a1) << 8) - (b << 8)) / a3) * a4) >> 8; - - r = (r + r1) & 0x1F; //_RGB(r + r1, g + g1, b + b1); doesn't match; I have to assign the value of ((r + r1) & 0x1F) to r1 - g = (g + g1) & 0x1F; //See above - b = (b + b1) & 0x1F; //See above - - *palette = RGB2(r, g, b); //See above comment - - a0++, a1++; - palette++; - } - } + asm_unified( + "push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0xC\n\ + str r0, [sp]\n\ + str r1, [sp, 0x4]\n\ + mov r10, r2\n\ + str r3, [sp, 0x8]\n\ + ldr r0, [sp, 0x2C]\n\ + cmp r0, 0\n\ + bne _081C79E4\n\ + ldr r2, =0x001fffff\n\ + mov r1, r10\n\ + ands r2, r1\n\ + ldr r0, [sp]\n\ + b _081C79F4\n\ + .pool\n\ +_081C79E4:\n\ + ldr r2, [sp, 0x2C]\n\ + ldr r0, [sp, 0x8]\n\ + cmp r2, r0\n\ + blt _081C7A00\n\ + ldr r2, =0x001fffff\n\ + mov r1, r10\n\ + ands r2, r1\n\ + ldr r0, [sp, 0x4]\n\ +_081C79F4:\n\ + ldr r1, [sp, 0x30]\n\ + bl CpuSet\n\ + b _081C7AAE\n\ + .pool\n\ +_081C7A00:\n\ + movs r2, 0x1\n\ + negs r2, r2\n\ + add r10, r2\n\ + b _081C7AA6\n\ +_081C7A08:\n\ + ldr r1, [sp]\n\ + ldrh r0, [r1]\n\ + movs r2, 0x1F\n\ + mov r9, r2\n\ + mov r1, r9\n\ + ands r1, r0\n\ + mov r9, r1\n\ + lsls r0, 16\n\ + lsrs r2, r0, 21\n\ + movs r1, 0x1F\n\ + ands r1, r2\n\ + mov r8, r1\n\ + lsrs r7, r0, 26\n\ + movs r2, 0x1F\n\ + ands r7, r2\n\ + ldr r0, [sp, 0x4]\n\ + ldrh r4, [r0]\n\ + movs r0, 0x1F\n\ + ands r0, r4\n\ + mov r1, r9\n\ + subs r0, r1\n\ + lsls r0, 8\n\ + ldr r1, [sp, 0x8]\n\ + bl __divsi3\n\ + ldr r2, [sp, 0x2C]\n\ + adds r6, r0, 0\n\ + muls r6, r2\n\ + asrs r6, 8\n\ + lsls r4, 16\n\ + lsrs r0, r4, 21\n\ + movs r1, 0x1F\n\ + ands r0, r1\n\ + mov r2, r8\n\ + subs r0, r2\n\ + lsls r0, 8\n\ + ldr r1, [sp, 0x8]\n\ + bl __divsi3\n\ + ldr r1, [sp, 0x2C]\n\ + adds r5, r0, 0\n\ + muls r5, r1\n\ + asrs r5, 8\n\ + lsrs r4, 26\n\ + movs r2, 0x1F\n\ + ands r4, r2\n\ + subs r4, r7\n\ + lsls r4, 8\n\ + adds r0, r4, 0\n\ + ldr r1, [sp, 0x8]\n\ + bl __divsi3\n\ + ldr r1, [sp, 0x2C]\n\ + muls r0, r1\n\ + asrs r0, 8\n\ + add r6, r9\n\ + movs r2, 0x1F\n\ + ands r6, r2\n\ + add r5, r8\n\ + ands r5, r2\n\ + adds r0, r7, r0\n\ + ands r0, r2\n\ + lsls r0, 10\n\ + lsls r5, 5\n\ + orrs r0, r5\n\ + orrs r0, r6\n\ + ldr r1, [sp, 0x30]\n\ + strh r0, [r1]\n\ + ldr r2, [sp]\n\ + adds r2, 0x2\n\ + str r2, [sp]\n\ + ldr r0, [sp, 0x4]\n\ + adds r0, 0x2\n\ + str r0, [sp, 0x4]\n\ + adds r1, 0x2\n\ + str r1, [sp, 0x30]\n\ + movs r1, 0x1\n\ + negs r1, r1\n\ + add r10, r1\n\ +_081C7AA6:\n\ + movs r0, 0x1\n\ + negs r0, r0\n\ + cmp r10, r0\n\ + bne _081C7A08\n\ +_081C7AAE:\n\ + add sp, 0xC\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0"); } void PokenavFadeScreen(s32 fadeType) @@ -681,7 +780,7 @@ static void LoadLeftHeaderGfxForMenu(u32 menuGfxId) size = GetDecompressedDataSize(sPokenavMenuLeftHeaderSpriteSheets[menuGfxId].data); LoadPalette(&gPokenavLeftHeader_Pal[tag * 16], (IndexOfSpritePaletteTag(1) * 16) + 0x100, 0x20); LZ77UnCompWram(sPokenavMenuLeftHeaderSpriteSheets[menuGfxId].data, gDecompressionBuffer); - RequestDma3Copy(gDecompressionBuffer, (void *)OBJ_VRAM0 + (GetSpriteTileStartByTag(2) * 32), size, 1); + RequestDma3Copy(gDecompressionBuffer, (void *)VRAM + 0x10000 + (GetSpriteTileStartByTag(2) * 32), size, 1); structPtr->leftHeaderSprites[1]->oam.tileNum = GetSpriteTileStartByTag(2) + sPokenavMenuLeftHeaderSpriteSheets[menuGfxId].size; if (menuGfxId == POKENAV_GFX_MAP_MENU_ZOOMED_OUT || menuGfxId == POKENAV_GFX_MAP_MENU_ZOOMED_IN) diff --git a/src/pokenav_match_call_1.c b/src/pokenav_match_call_1.c index d919a4dbf..265259394 100755 --- a/src/pokenav_match_call_1.c +++ b/src/pokenav_match_call_1.c @@ -79,16 +79,16 @@ static u32 CB2_HandleMatchCallInput(struct Pokenav3Struct *state) { int selection; - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) return POKENAV_MC_FUNC_UP; - if (JOY_REPEAT(DPAD_DOWN)) + if (gMain.newAndRepeatedKeys & DPAD_DOWN) return POKENAV_MC_FUNC_DOWN; - if (JOY_REPEAT(DPAD_LEFT)) + if (gMain.newAndRepeatedKeys & DPAD_LEFT) return POKENAV_MC_FUNC_PG_UP; - if (JOY_REPEAT(DPAD_RIGHT)) + if (gMain.newAndRepeatedKeys & DPAD_RIGHT) return POKENAV_MC_FUNC_PG_DOWN; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { state->callback = CB2_HandleMatchCallOptionsInput; state->optionCursorPos = 0; @@ -108,7 +108,7 @@ static u32 CB2_HandleMatchCallInput(struct Pokenav3Struct *state) return POKENAV_MC_FUNC_SELECT; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { if (GetPokenavMode() != POKENAV_MODE_FORCE_CALL_READY) { @@ -132,19 +132,19 @@ static u32 GetExitMatchCallMenuId(struct Pokenav3Struct *state) static u32 CB2_HandleMatchCallOptionsInput(struct Pokenav3Struct *state) { - if ((JOY_NEW(DPAD_UP)) && state->optionCursorPos) + if ((gMain.newKeys & DPAD_UP) && state->optionCursorPos) { state->optionCursorPos--; return POKENAV_MC_FUNC_MOVE_OPTIONS_CURSOR; } - if ((JOY_NEW(DPAD_DOWN)) && state->optionCursorPos < state->maxOptionId) + if ((gMain.newKeys & DPAD_DOWN) && state->optionCursorPos < state->maxOptionId) { state->optionCursorPos++; return POKENAV_MC_FUNC_MOVE_OPTIONS_CURSOR; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (state->matchCallOptions[state->optionCursorPos]) { @@ -166,7 +166,7 @@ static u32 CB2_HandleMatchCallOptionsInput(struct Pokenav3Struct *state) } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { state->callback = CB2_HandleMatchCallInput; return POKENAV_MC_FUNC_CANCEL; @@ -177,12 +177,12 @@ static u32 CB2_HandleMatchCallOptionsInput(struct Pokenav3Struct *state) static u32 CB2_HandleCheckPageInput(struct Pokenav3Struct *state) { - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) return POKENAV_MC_FUNC_CHECK_PAGE_UP; - if (JOY_REPEAT(DPAD_DOWN)) + if (gMain.newAndRepeatedKeys & DPAD_DOWN) return POKENAV_MC_FUNC_CHECK_PAGE_DOWN; - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { state->callback = CB2_HandleMatchCallInput; return POKENAV_MC_FUNC_EXIT_CHECK_PAGE; @@ -193,7 +193,7 @@ static u32 CB2_HandleCheckPageInput(struct Pokenav3Struct *state) static u32 CB2_HandleCallInput(struct Pokenav3Struct *state) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { state->callback = CB2_HandleMatchCallInput; return POKENAV_MC_FUNC_10; diff --git a/src/pokenav_match_call_2.c b/src/pokenav_match_call_2.c index 424882670..60091577e 100755 --- a/src/pokenav_match_call_2.c +++ b/src/pokenav_match_call_2.c @@ -1126,7 +1126,7 @@ static void PrintMatchCallMessage(struct Pokenav4Struct *state) static bool32 WaitForMatchCallMessageText(struct Pokenav4Struct *state) { - if (JOY_HELD(A_BUTTON)) + if (gMain.heldKeys & A_BUTTON) gTextFlags.canABSpeedUpPrint = 1; else gTextFlags.canABSpeedUpPrint = 0; diff --git a/src/pokenav_menu_handler_1.c b/src/pokenav_menu_handler_1.c index 6002d731b..d8d8e1509 100644 --- a/src/pokenav_menu_handler_1.c +++ b/src/pokenav_menu_handler_1.c @@ -216,7 +216,7 @@ static u32 HandleMainMenuInput(struct Pokenav1Struct *state) if (UpdateMenuCursorPos(state)) return POKENAV_MENU_FUNC_MOVE_CURSOR; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (sMenuItems[state->menuType][state->cursorPos]) { @@ -251,7 +251,7 @@ static u32 HandleMainMenuInput(struct Pokenav1Struct *state) } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) return -1; return POKENAV_MENU_FUNC_NONE; @@ -263,7 +263,7 @@ static u32 HandleMainMenuInputTutorial(struct Pokenav1Struct *state) if (UpdateMenuCursorPos(state)) return POKENAV_MENU_FUNC_MOVE_CURSOR; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (sMenuItems[state->menuType][state->cursorPos] == POKENAV_MENUITEM_MATCH_CALL) { @@ -278,7 +278,7 @@ static u32 HandleMainMenuInputTutorial(struct Pokenav1Struct *state) } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { PlaySE(SE_FAILURE); return POKENAV_MENU_FUNC_NONE; @@ -293,7 +293,7 @@ static u32 HandleMainMenuInputEndTutorial(struct Pokenav1Struct *state) if (UpdateMenuCursorPos(state)) return POKENAV_MENU_FUNC_MOVE_CURSOR; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { u32 menuItem = sMenuItems[state->menuType][state->cursorPos]; if (menuItem != POKENAV_MENUITEM_MATCH_CALL && menuItem != POKENAV_MENUITEM_SWITCH_OFF) @@ -312,7 +312,7 @@ static u32 HandleMainMenuInputEndTutorial(struct Pokenav1Struct *state) return -1; } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { return -1; } @@ -329,7 +329,7 @@ static u32 HandleCantOpenRibbonsInput(struct Pokenav1Struct *state) return POKENAV_MENU_FUNC_MOVE_CURSOR; } - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { state->callback = GetMainMenuInputHandler(); return POKENAV_MENU_FUNC_RESHOW_DESCRIPTION; @@ -343,7 +343,7 @@ static u32 HandleConditionMenuInput(struct Pokenav1Struct *state) if (UpdateMenuCursorPos(state)) return POKENAV_MENU_FUNC_MOVE_CURSOR; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { switch (sMenuItems[state->menuType][state->cursorPos]) { @@ -363,7 +363,7 @@ static u32 HandleConditionMenuInput(struct Pokenav1Struct *state) return POKENAV_MENU_FUNC_RETURN_TO_MAIN; } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { if (state->cursorPos != sLastCursorPositions[state->menuType]) { @@ -387,7 +387,7 @@ static u32 HandleConditionSearchMenuInput(struct Pokenav1Struct *state) if (UpdateMenuCursorPos(state)) return POKENAV_MENU_FUNC_MOVE_CURSOR; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { u8 menuItem = sMenuItems[state->menuType][state->cursorPos]; if (menuItem != POKENAV_MENUITEM_CONDITION_SEARCH_CANCEL) @@ -404,7 +404,7 @@ static u32 HandleConditionSearchMenuInput(struct Pokenav1Struct *state) return POKENAV_MENU_FUNC_RETURN_TO_CONDITION; } } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { if (state->cursorPos != sLastCursorPositions[state->menuType]) { @@ -463,7 +463,7 @@ static void ReturnToConditionMenu(struct Pokenav1Struct *state) static bool32 UpdateMenuCursorPos(struct Pokenav1Struct *state) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { if (--state->cursorPos < 0) state->cursorPos = sLastCursorPositions[state->menuType]; @@ -471,7 +471,7 @@ static bool32 UpdateMenuCursorPos(struct Pokenav1Struct *state) state->currMenuItem = sMenuItems[state->menuType][state->cursorPos]; return TRUE; } - else if (JOY_NEW(DPAD_DOWN)) + else if (gMain.newKeys & DPAD_DOWN) { state->cursorPos++; if (state->cursorPos > sLastCursorPositions[state->menuType]) diff --git a/src/pokenav_region_map.c b/src/pokenav_region_map.c index 394b40907..e858fad4a 100755 --- a/src/pokenav_region_map.c +++ b/src/pokenav_region_map.c @@ -219,7 +219,7 @@ static u32 HandleRegionMapInput(struct Pokenav5Struct *state) static u32 HandleRegionMapInputZoomDisabled(struct Pokenav5Struct *state) { - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { state->callback = GetExitRegionMapMenuId; return POKENAV_MAP_FUNC_EXIT; diff --git a/src/pokenav_ribbons_1.c b/src/pokenav_ribbons_1.c index fd47b27ad..aad0053a8 100644 --- a/src/pokenav_ribbons_1.c +++ b/src/pokenav_ribbons_1.c @@ -162,21 +162,21 @@ static u32 sub_81CFA68(struct PokenavSub9 *structPtr) static u32 sub_81CFA88(struct PokenavSub9 *structPtr) { - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) return 1; - if (JOY_REPEAT(DPAD_DOWN)) + if (gMain.newAndRepeatedKeys & DPAD_DOWN) return 2; - if (JOY_NEW(DPAD_LEFT)) + if (gMain.newKeys & DPAD_LEFT) return 3; - if (JOY_NEW(DPAD_RIGHT)) + if (gMain.newKeys & DPAD_RIGHT) return 4; - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { structPtr->unk18 = 0; structPtr->unk0 = sub_81CFB08; return 5; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { structPtr->unk1C->unk2 = GetSelectedMatchCall(); structPtr->unk18 = 1; diff --git a/src/pokenav_ribbons_2.c b/src/pokenav_ribbons_2.c index 6eabc9b33..e5a89acad 100644 --- a/src/pokenav_ribbons_2.c +++ b/src/pokenav_ribbons_2.c @@ -188,26 +188,26 @@ void sub_81D04B8(void) u32 sub_81D04C4(struct PokenavSub13 *structPtr) { - if (JOY_REPEAT(DPAD_UP) && structPtr->field_8->unk2 != 0) + if (gMain.newAndRepeatedKeys & DPAD_UP && structPtr->field_8->unk2 != 0) { structPtr->field_8->unk2--; structPtr->field_C = 0; sub_81D0814(structPtr); return 1; } - if (JOY_REPEAT(DPAD_DOWN) && structPtr->field_8->unk2 < structPtr->field_8->unk0 - 1) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN && structPtr->field_8->unk2 < structPtr->field_8->unk0 - 1) { structPtr->field_8->unk2++; structPtr->field_C = 0; sub_81D0814(structPtr); return 1; } - if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { structPtr->field_98 = sub_81D0548; return 2; } - if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { structPtr->field_98 = sub_81D05D4; return 5; @@ -217,15 +217,15 @@ u32 sub_81D04C4(struct PokenavSub13 *structPtr) u32 sub_81D0548(struct PokenavSub13 *structPtr) { - if (JOY_REPEAT(DPAD_UP) && sub_81D05DC(structPtr)) + if (gMain.newAndRepeatedKeys & DPAD_UP && sub_81D05DC(structPtr)) return 3; - if (JOY_REPEAT(DPAD_DOWN) && sub_81D061C(structPtr)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN && sub_81D061C(structPtr)) return 3; - if (JOY_REPEAT(DPAD_LEFT) && sub_81D0664(structPtr)) + else if (gMain.newAndRepeatedKeys & DPAD_LEFT && sub_81D0664(structPtr)) return 3; - if (JOY_REPEAT(DPAD_RIGHT) && sub_81D0688(structPtr)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT && sub_81D0688(structPtr)) return 3; - if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { structPtr->field_98 = sub_81D04C4; return 4; diff --git a/src/record_mixing.c b/src/record_mixing.c index b12b71697..6c0a02d8c 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -713,18 +713,17 @@ static u8 sub_80E7A9C(struct DayCareMail *rmMail) return rmMail->message.itemId; } -static void ExchangeMail(struct RecordMixingDayCareMail *src, size_t recordSize, u8 (*idxs)[2], u8 which0, u8 which1) +static void sub_80E7AA4(struct RecordMixingDayCareMail *src, size_t recordSize, u8 (*idxs)[2], u8 which0, u8 which1) { struct DayCareMail buffer; struct RecordMixingDayCareMail *mail1; struct RecordMixingDayCareMail *mail2; mail1 = (void *)src + recordSize * idxs[which0][0]; - buffer = mail1->mail[idxs[which0][1]]; - + memcpy(&buffer, &mail1->mail[idxs[which0][1]], sizeof(struct DayCareMail)); mail2 = (void *)src + recordSize * idxs[which1][0]; - mail1->mail[idxs[which0][1]] = mail2->mail[idxs[which1][1]]; - mail2->mail[idxs[which1][1]] = buffer; + memcpy(&mail1->mail[idxs[which0][1]], &mail2->mail[idxs[which1][1]], sizeof(struct DayCareMail)); + memcpy(&mail2->mail[idxs[which1][1]], &buffer, sizeof(struct DayCareMail)); } static void sub_80E7B2C(const u8 *src) @@ -866,23 +865,28 @@ static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t r } else if (sp1c[i][0] == TRUE && sp1c[i][1] == TRUE) { - u8 mail1, mail2; + u32 var1, var2; sp24[j][0] = i; - mail1 = sub_80E7A9C(&_src->mail[0]); - mail2 = sub_80E7A9C(&_src->mail[1]); - if (!(mail1 || mail2) || (mail1 && mail2)) //Logical (not bitwise) XOR. Should be ((mail1 || mail2) && !(mail1 && mail2)), but that doesn't match. + var1 = sub_80E7A9C(&_src->mail[0]); + var2 = sub_80E7A9C(&_src->mail[1]); + if (!var1 && var2) { - sp24[j][1] = Random2() % 2; + #ifndef NONMATCHING + register u8 one asm("r0") = 1; // boo, a fakematch + sp24[j][1] = one; + #else + sp24[j][1] = 1; + #endif } - else if (mail1 && !mail2) + else if ((var1 && var2) || (!var1 && !var2)) + { + sp24[j][1] = Random2() % 2; + } + else if (var1 && !var2) { sp24[j][1] = 0; } - else if (!mail1 && mail2) - { - sp24[j][1] = 1; - } j++; } } @@ -897,27 +901,27 @@ static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t r switch (sp34) { case 2: - ExchangeMail(src, recordSize, sp24, 0, 1); + sub_80E7AA4(src, recordSize, sp24, 0, 1); break; case 3: which0 = gUnknown_0858CFB8[tableId][0]; which1 = gUnknown_0858CFB8[tableId][1]; - ExchangeMail(src, recordSize, sp24, which0, which1); + sub_80E7AA4(src, recordSize, sp24, which0, which1); break; case 4: ptr = sp24; which0 = gUnknown_0858CFBE[tableId][0]; which1 = gUnknown_0858CFBE[tableId][1]; - ExchangeMail(src, recordSize, ptr, which0, which1); + sub_80E7AA4(src, recordSize, ptr, which0, which1); which0 = gUnknown_0858CFBE[tableId][2]; which1 = gUnknown_0858CFBE[tableId][3]; - ExchangeMail(src, recordSize, ptr, which0, which1); + sub_80E7AA4(src, recordSize, ptr, which0, which1); break; } _src = (void *)src + which * recordSize; - gSaveBlock1Ptr->daycare.mons[0].mail = _src->mail[0]; - gSaveBlock1Ptr->daycare.mons[1].mail = _src->mail[1]; + memcpy(&gSaveBlock1Ptr->daycare.mons[0].mail, &_src->mail[0], sizeof(struct DayCareMail)); + memcpy(&gSaveBlock1Ptr->daycare.mons[1].mail, &_src->mail[1], sizeof(struct DayCareMail)); SeedRng(oldSeed); } diff --git a/src/region_map.c b/src/region_map.c index 49b21be07..3438ea3ed 100644 --- a/src/region_map.c +++ b/src/region_map.c @@ -651,31 +651,31 @@ static u8 ProcessRegionMapInput_Full(void) input = MAP_INPUT_NONE; gRegionMap->cursorDeltaX = 0; gRegionMap->cursorDeltaY = 0; - if (JOY_HELD(DPAD_UP) && gRegionMap->cursorPosY > MAPCURSOR_Y_MIN) + if (gMain.heldKeys & DPAD_UP && gRegionMap->cursorPosY > MAPCURSOR_Y_MIN) { gRegionMap->cursorDeltaY = -1; input = MAP_INPUT_MOVE_START; } - if (JOY_HELD(DPAD_DOWN) && gRegionMap->cursorPosY < MAPCURSOR_Y_MAX) + if (gMain.heldKeys & DPAD_DOWN && gRegionMap->cursorPosY < MAPCURSOR_Y_MAX) { gRegionMap->cursorDeltaY = +1; input = MAP_INPUT_MOVE_START; } - if (JOY_HELD(DPAD_LEFT) && gRegionMap->cursorPosX > MAPCURSOR_X_MIN) + if (gMain.heldKeys & DPAD_LEFT && gRegionMap->cursorPosX > MAPCURSOR_X_MIN) { gRegionMap->cursorDeltaX = -1; input = MAP_INPUT_MOVE_START; } - if (JOY_HELD(DPAD_RIGHT) && gRegionMap->cursorPosX < MAPCURSOR_X_MAX) + if (gMain.heldKeys & DPAD_RIGHT && gRegionMap->cursorPosX < MAPCURSOR_X_MAX) { gRegionMap->cursorDeltaX = +1; input = MAP_INPUT_MOVE_START; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { input = MAP_INPUT_A_BUTTON; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { input = MAP_INPUT_B_BUTTON; } @@ -730,31 +730,31 @@ static u8 ProcessRegionMapInput_Zoomed(void) input = MAP_INPUT_NONE; gRegionMap->zoomedCursorDeltaX = 0; gRegionMap->zoomedCursorDeltaY = 0; - if (JOY_HELD(DPAD_UP) && gRegionMap->scrollY > -0x34) + if (gMain.heldKeys & DPAD_UP && gRegionMap->scrollY > -0x34) { gRegionMap->zoomedCursorDeltaY = -1; input = MAP_INPUT_MOVE_START; } - if (JOY_HELD(DPAD_DOWN) && gRegionMap->scrollY < 0x3c) + if (gMain.heldKeys & DPAD_DOWN && gRegionMap->scrollY < 0x3c) { gRegionMap->zoomedCursorDeltaY = +1; input = MAP_INPUT_MOVE_START; } - if (JOY_HELD(DPAD_LEFT) && gRegionMap->scrollX > -0x2c) + if (gMain.heldKeys & DPAD_LEFT && gRegionMap->scrollX > -0x2c) { gRegionMap->zoomedCursorDeltaX = -1; input = MAP_INPUT_MOVE_START; } - if (JOY_HELD(DPAD_RIGHT) && gRegionMap->scrollX < 0xac) + if (gMain.heldKeys & DPAD_RIGHT && gRegionMap->scrollX < 0xac) { gRegionMap->zoomedCursorDeltaX = +1; input = MAP_INPUT_MOVE_START; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { input = MAP_INPUT_A_BUTTON; } - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { input = MAP_INPUT_B_BUTTON; } diff --git a/src/reset_rtc_screen.c b/src/reset_rtc_screen.c index d0e815816..204eb6733 100644 --- a/src/reset_rtc_screen.c +++ b/src/reset_rtc_screen.c @@ -380,7 +380,7 @@ static void Task_ResetRtc_1(u8 taskId) u8 selection = data[2]; const struct ResetRtcStruct *selectionInfo = &sUnknown_08510428[selection - 1]; - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { gTasks[taskId].func = Task_ResetRtc_2; data[1] = 0; @@ -389,7 +389,7 @@ static void Task_ResetRtc_1(u8 taskId) return; } - if (JOY_NEW(DPAD_RIGHT)) + if (gMain.newKeys & DPAD_RIGHT) { if (selectionInfo->right) { @@ -399,7 +399,7 @@ static void Task_ResetRtc_1(u8 taskId) } } - if (JOY_NEW(DPAD_LEFT)) + if (gMain.newKeys & DPAD_LEFT) { if (selectionInfo->left) { @@ -411,7 +411,7 @@ static void Task_ResetRtc_1(u8 taskId) if (selection == 5) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { gLocalTime.days = data[3]; gLocalTime.hours = data[4]; @@ -423,7 +423,7 @@ static void Task_ResetRtc_1(u8 taskId) data[2] = 6; } } - else if (MoveTimeUpDown(&data[selectionInfo->dataIndex], selectionInfo->minVal, selectionInfo->maxVal, JOY_REPEAT(DPAD_UP | DPAD_DOWN))) + else if (MoveTimeUpDown(&data[selectionInfo->dataIndex], selectionInfo->minVal, selectionInfo->maxVal, gMain.newAndRepeatedKeys & (DPAD_UP | DPAD_DOWN))) { PlaySE(SE_SELECT); PrintTime(data[8], 0, 1, data[3], data[4], data[5], data[6]); @@ -532,12 +532,12 @@ static void Task_ShowResetRtcPrompt(u8 taskId) ScheduleBgCopyTilemapToVram(0); data[0]++; case 1: - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { DestroyTask(taskId); DoSoftReset(); } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); DestroyTask(taskId); @@ -620,7 +620,7 @@ static void Task_ResetRtcScreen(u8 taskId) } data[0] = 5; case 5: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { BeginNormalPaletteFade(0xFFFFFFFF, 1, 0, 0x10, RGB_WHITEALPHA); data[0] = 6; diff --git a/src/save.c b/src/save.c index 0a2a4e799..3ae2f6fd5 100644 --- a/src/save.c +++ b/src/save.c @@ -13,7 +13,7 @@ #include "link.h" #include "constants/game_stat.h" -static u16 CalculateChecksum(const void *data, u16 size); +static u16 CalculateChecksum(void *data, u16 size); static bool8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section); static u8 GetSaveValidStatus(const struct SaveSectionLocation *location); static u8 sub_8152E10(u16 a1, const struct SaveSectionLocation *location); @@ -621,7 +621,7 @@ static bool8 DoReadFlashWholeSection(u8 sector, struct SaveSection *section) return TRUE; } -static u16 CalculateChecksum(const void *data, u16 size) +static u16 CalculateChecksum(void *data, u16 size) { u16 i; u32 checksum = 0; @@ -648,10 +648,12 @@ static void UpdateSaveAddresses(void) gRamSaveSectionLocations[i].size = sSaveSectionOffsets[i].size; } - for (; i <= SECTOR_ID_PKMN_STORAGE_END; i++) //i = SECTOR_ID_PKMN_STORAGE_START; in the initialization clause does not match + for (i = SECTOR_ID_PKMN_STORAGE_START; i <= SECTOR_ID_PKMN_STORAGE_END; i++) { gRamSaveSectionLocations[i].data = (void*)(gPokemonStoragePtr) + sSaveSectionOffsets[i].toAdd; gRamSaveSectionLocations[i].size = sSaveSectionOffsets[i].size; + + i++;i--; // needed to match } } diff --git a/src/save_failed_screen.c b/src/save_failed_screen.c index 9bf0e7ed4..a2a2acc8d 100644 --- a/src/save_failed_screen.c +++ b/src/save_failed_screen.c @@ -306,7 +306,7 @@ static void CB2_GameplayCannotBeContinued(void) { gSaveFailedClockInfo[CLOCK_RUNNING] = FALSE; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { FillWindowPixelBuffer(gSaveFailedWindowIds[TEXT_WIN_ID], PIXEL_FILL(1)); SaveFailedScreenTextPrint(gText_GamePlayCannotBeContinued, 1, 0); @@ -319,7 +319,7 @@ static void CB2_FadeAndReturnToTitleScreen(void) { gSaveFailedClockInfo[CLOCK_RUNNING] = FALSE; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK); SetVBlankCallback(VBlankCB); @@ -349,7 +349,7 @@ static void VBlankCB_UpdateClockGraphics(void) gMain.oamBuffer[0] = sClockOamData; gMain.oamBuffer[0].x = 112; - gMain.oamBuffer[0].y = (CLOCK_WIN_TOP + 1) * 8; + gMain.oamBuffer[0].y = (CLOCK_WIN_TOP + 1) * 8;; if (gSaveFailedClockInfo[CLOCK_RUNNING] != FALSE) { diff --git a/src/scrcmd.c b/src/scrcmd.c index 578e357fa..b71fa40ad 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -788,8 +788,8 @@ bool8 ScrCmd_warphole(struct ScriptContext *ctx) { u8 mapGroup = ScriptReadByte(ctx); u8 mapNum = ScriptReadByte(ctx); - s16 x; - s16 y; + u16 x; + u16 y; PlayerGetDestCoords(&x, &y); if (mapGroup == 0xFF && mapNum == 0xFF) @@ -1325,9 +1325,9 @@ bool8 ScrCmd_closemessage(struct ScriptContext *ctx) static bool8 WaitForAorBPress(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) return TRUE; - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) return TRUE; return FALSE; } diff --git a/src/script.c b/src/script.c index 889c25765..9ba1a7429 100644 --- a/src/script.c +++ b/src/script.c @@ -26,9 +26,9 @@ void InitScriptContext(struct ScriptContext *ctx, void *cmdTable, void *cmdTable s32 i; ctx->mode = 0; - ctx->scriptPtr = NULL; + ctx->scriptPtr = 0; ctx->stackDepth = 0; - ctx->nativePtr = NULL; + ctx->nativePtr = 0; ctx->cmdTable = cmdTable; ctx->cmdTableEnd = cmdTableEnd; @@ -55,7 +55,7 @@ void SetupNativeScript(struct ScriptContext *ctx, bool8 (*ptr)(void)) void StopScript(struct ScriptContext *ctx) { ctx->mode = 0; - ctx->scriptPtr = NULL; + ctx->scriptPtr = 0; } bool8 RunScriptCommand(struct ScriptContext *ctx) diff --git a/src/script_menu.c b/src/script_menu.c index 425cdc251..2b135e301 100644 --- a/src/script_menu.c +++ b/src/script_menu.c @@ -170,7 +170,7 @@ static void Task_HandleMultichoiceInput(u8 taskId) else selection = Menu_ProcessInput(); - if (JOY_NEW(DPAD_UP | DPAD_DOWN)) + if (gMain.newKeys & (DPAD_UP | DPAD_DOWN)) { DrawLinkServicesMultichoiceMenu(tMultichoiceId); } diff --git a/src/secret_base.c b/src/secret_base.c index 3f69e0419..83626710f 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -964,7 +964,7 @@ static void HandleRegistryMenuInput(u8 taskId) data = gTasks[taskId].data; input = ListMenu_ProcessInput(data[5]); - ListMenuGetScrollAndRow(data[5], (u16 *)&data[2], (u16 *)&data[1]); + ListMenuGetScrollAndRow(data[5], &data[2], &data[1]); switch (input) { case LIST_NOTHING_CHOSEN: @@ -1045,10 +1045,10 @@ void DeleteRegistry_Yes_Callback(u8 taskId) { s16 *data = gTasks[taskId].data; ClearDialogWindowAndFrame(0, 0); - DestroyListMenuTask((u8)data[5], (u16 *)&data[2], (u16 *)&data[1]); + DestroyListMenuTask(data[5], &data[2], &data[1]); gSaveBlock1Ptr->secretBases[data[4]].registryStatus = 0; BuildRegistryMenuItems(taskId); - sub_812225C((u16 *)&data[2], (u16 *)&data[1], (u16)data[3], (u16)data[0]); + sub_812225C(&data[2], &data[1], data[3], data[0]); FinalizeRegistryMenu(taskId); gTasks[taskId].func = HandleRegistryMenuInput; } @@ -1062,7 +1062,7 @@ static void DeleteRegistry_No(u8 taskId) { s16 *data = gTasks[taskId].data; ClearDialogWindowAndFrame(0, 0); - DestroyListMenuTask((u8)data[5], (u16 *)&data[2], (u16 *)&data[1]); + DestroyListMenuTask(data[5], &data[2], &data[1]); FinalizeRegistryMenu(taskId); gTasks[taskId].func = HandleRegistryMenuInput; } diff --git a/src/shop.c b/src/shop.c index 6e2e82a52..5cba2767d 100755 --- a/src/shop.c +++ b/src/shop.c @@ -1017,7 +1017,7 @@ static void Task_BuyHowManyDialogueHandleInput(u8 taskId) } else { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); ClearStdWindowAndFrameToTransparent(4, 0); @@ -1030,7 +1030,7 @@ static void Task_BuyHowManyDialogueHandleInput(u8 taskId) ConvertIntToDecimalStringN(gStringVar3, gShopDataPtr->totalCost, STR_CONV_MODE_LEFT_ALIGN, 6); BuyMenuDisplayMessage(taskId, gText_Var1AndYouWantedVar2, BuyMenuConfirmPurchase); } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { PlaySE(SE_SELECT); ClearStdWindowAndFrameToTransparent(4, 0); @@ -1106,7 +1106,7 @@ static void Task_ReturnToItemListAfterItemPurchase(u8 taskId) { s16 *data = gTasks[taskId].data; - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); if (tItemId == ITEM_POKE_BALL && tItemCount > 9 && AddBagItem(ITEM_PREMIER_BALL, 1) == TRUE) @@ -1122,7 +1122,7 @@ static void Task_ReturnToItemListAfterItemPurchase(u8 taskId) static void Task_ReturnToItemListAfterDecorationPurchase(u8 taskId) { - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { PlaySE(SE_SELECT); BuyMenuReturnToItemList(taskId); diff --git a/src/slot_machine.c b/src/slot_machine.c index cc001bcc9..285b110af 100644 --- a/src/slot_machine.c +++ b/src/slot_machine.c @@ -252,8 +252,8 @@ struct SlotMachine /*0x0E*/ s16 payout; /*0x10*/ s16 netCoinLoss; // coins lost to machine (but never goes below 0) /*0x12*/ s16 bet; - /*0x14*/ s16 reelTimePixelOffset; - /*0x16*/ s16 reelTimePosition; + /*0x14*/ s16 reeltimePixelOffset; + /*0x16*/ s16 reeltimePosition; /*0x18*/ s16 currReel; /*0x1A*/ s16 reelIncrement; // speed of reel /*0x1C*/ s16 reelPixelOffsets[NUM_REELS]; @@ -584,7 +584,7 @@ static const u16 *const sDigitalDisplay_Pal; static const s16 sInitialReelPositions[NUM_REELS][2]; static const u8 sLuckyFlagProbabilities_Top3[][6]; static const u8 sLuckyFlagProbabilities_NotTop3[][6]; -static const u8 sReelTimeProbabilities_UnluckyGame[][17]; +static const u8 sReeltimeProbabilities_UnluckyGame[][17]; static const u8 sReelTimeProbabilities_LuckyGame[][17]; static const u8 sSymToMatch[]; static const u8 sReelTimeTags[]; @@ -682,7 +682,7 @@ static const struct WindowTemplate sWindowTemplate_InfoBox = .baseBlock = 1 }; -static const u8 sColors_ReelTimeHelp[] = {TEXT_COLOR_LIGHT_GREY, TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY}; +static const u8 sColors_ReeltimeHelp[] = {TEXT_COLOR_LIGHT_GREY, TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GREY}; static bool8 (*const sSlotActions[])(struct Task *task) = { @@ -985,7 +985,7 @@ static void PlaySlotMachine_Internal(u8 slotMachineIndex, MainCallback exitCallb { struct Task *task = &gTasks[CreateTask(SlotMachineDummyTask, 0xFF)]; task->data[0] = slotMachineIndex; - StoreWordInTwoHalfwords((u16 *)&task->data[1], (intptr_t)exitCallback); + StoreWordInTwoHalfwords(&task->data[1], (intptr_t)exitCallback); } @@ -1744,13 +1744,13 @@ static u8 AttemptsAtLuckyFlags_NotTop3(void) static u8 GetReelTimeProbability(u8 reelTimeDraw) { - if (!sSlotMachine->luckyGame) - return sReelTimeProbabilities_UnluckyGame[reelTimeDraw][sSlotMachine->pikaPower]; - - return sReelTimeProbabilities_LuckyGame[reelTimeDraw][sSlotMachine->pikaPower]; + if (sSlotMachine->luckyGame == FALSE) + return sReeltimeProbabilities_UnluckyGame[reelTimeDraw][sSlotMachine->pikaPower]; + else + return sReelTimeProbabilities_LuckyGame[reelTimeDraw][sSlotMachine->pikaPower]; } -static void GetReelTimeDraw(void) +static void GetReeltimeDraw(void) { u8 rval; s16 reelTimeDraw; @@ -1773,13 +1773,15 @@ static bool8 ShouldReelTimeMachineExplode(u16 i) u16 rval = Random() & 0xff; if (rval < sReelTimeExplodeProbability[i]) return TRUE; - return FALSE; + else + return FALSE; } static u16 SlowReelSpeed(void) { u8 i = 0; - u8 rval, value; + u8 rval; + u8 value; if (sSlotMachine->netCoinLoss >= 300) i = 4; else if (sSlotMachine->netCoinLoss >= 250) @@ -1909,7 +1911,8 @@ static bool8 IsFinalTask_RunAwardPayoutActions(void) { if (FindTaskIdByFunc(RunAwardPayoutActions) == TAIL_SENTINEL) return TRUE; - return FALSE; + else + return FALSE; } static void RunAwardPayoutActions(u8 taskId) @@ -1942,7 +1945,7 @@ static bool8 AwardPayoutAction_GivePayoutToPlayer(struct Task *task) if (sSlotMachine->coins < MAX_COINS) sSlotMachine->coins++; task->data[1] = 8; - if (JOY_HELD(A_BUTTON)) + if (gMain.heldKeys & A_BUTTON) task->data[1] = 4; } if (IsFanfareTaskInactive() && JOY_NEW(START_BUTTON)) @@ -1997,7 +2000,7 @@ static u8 GetTag(u8 reel, s16 offset) static u8 GetNearbyReelTimeTag(s16 n) { - s16 newPosition = (sSlotMachine->reelTimePosition + n) % 6; + s16 newPosition = (sSlotMachine->reeltimePosition + n) % 6; if (newPosition < 0) newPosition += 6; return sReelTimeTags[newPosition]; @@ -2023,22 +2026,22 @@ s16 AdvanceSlotReelToNextTag(u8 reelIndex, s16 value) return offset; } -static void AdvanceReelTimeReel(s16 value) +static void AdvanceReeltimeReel(s16 value) { - sSlotMachine->reelTimePixelOffset += value; - sSlotMachine->reelTimePixelOffset %= 120; - sSlotMachine->reelTimePosition = 6 - sSlotMachine->reelTimePixelOffset / 20; + sSlotMachine->reeltimePixelOffset += value; + sSlotMachine->reeltimePixelOffset %= 120; + sSlotMachine->reeltimePosition = 6 - sSlotMachine->reeltimePixelOffset / 20; } -s16 AdvanceReelTimeReelToNextTag(s16 value) +s16 AdvanceReeltimeReelToNextTag(s16 value) { - s16 offset = sSlotMachine->reelTimePixelOffset % 20; + s16 offset = sSlotMachine->reeltimePixelOffset % 20; if (offset != 0) { if (offset < value) value = offset; - AdvanceReelTimeReel(value); - offset = sSlotMachine->reelTimePixelOffset % 20; + AdvanceReeltimeReel(value); + offset = sSlotMachine->reeltimePixelOffset % 20; } return offset; } @@ -3077,8 +3080,8 @@ static void Task_ReelTime(u8 taskId) static void ReelTime_Init(struct Task *task) { sSlotMachine->reelTimeSpinsLeft = 0; - sSlotMachine->reelTimePixelOffset = 0; - sSlotMachine->reelTimePosition = 0; + sSlotMachine->reeltimePixelOffset = 0; + sSlotMachine->reeltimePosition = 0; task->tState++; task->data[1] = 0; task->data[2] = 30; @@ -3093,7 +3096,7 @@ static void ReelTime_Init(struct Task *task) CreateReelTimeNumberSprites(); CreateReelTimeShadowSprites(); CreateReelTimeNumberGapSprite(); - GetReelTimeDraw(); + GetReeltimeDraw(); StopMapMusic(); PlayNewMapMusic(MUS_ROULETTE); } @@ -3116,12 +3119,12 @@ static void ReelTime_WindowEnter(struct Task *task) task->tState++; task->data[3] = 0; } - AdvanceReelTimeReel(task->data[4] >> 8); + AdvanceReeltimeReel(task->data[4] >> 8); } static void ReelTime_WaitStartPikachu(struct Task *task) { - AdvanceReelTimeReel(task->data[4] >> 8); + AdvanceReeltimeReel(task->data[4] >> 8); if (++task->data[5] >= 60) { task->tState++; @@ -3141,7 +3144,7 @@ static void ReelTime_PikachuSpeedUp1(struct Task *task) memcpy(reelTimeBoltDelays, sReelTimeBoltDelays, sizeof(sReelTimeBoltDelays)); memcpy(pikachuAuraFlashDelays, sPikachuAuraFlashDelays, sizeof(sPikachuAuraFlashDelays)); - AdvanceReelTimeReel(task->data[4] >> 8); + AdvanceReeltimeReel(task->data[4] >> 8); // gradually slow down the reel task->data[4] -= 4; i = 4 - (task->data[4] >> 8); @@ -3159,7 +3162,7 @@ static void ReelTime_PikachuSpeedUp1(struct Task *task) static void ReelTime_PikachuSpeedUp2(struct Task *task) { - AdvanceReelTimeReel(task->data[4] >> 8); + AdvanceReeltimeReel(task->data[4] >> 8); if (++task->data[5] >= 80) { task->tState++; @@ -3171,7 +3174,7 @@ static void ReelTime_PikachuSpeedUp2(struct Task *task) static void ReelTime_WaitReel(struct Task *task) { - AdvanceReelTimeReel(task->data[4] >> 8); + AdvanceReeltimeReel(task->data[4] >> 8); task->data[4] = (u8)task->data[4] + 0x80; if (++task->data[5] >= 80) { @@ -3182,7 +3185,7 @@ static void ReelTime_WaitReel(struct Task *task) static void ReelTime_CheckExplode(struct Task *task) { - AdvanceReelTimeReel(task->data[4] >> 8); + AdvanceReeltimeReel(task->data[4] >> 8); task->data[4] = (u8)task->data[4] + 0x40; if (++task->data[5] >= 40) { @@ -3206,19 +3209,19 @@ static void ReelTime_CheckExplode(struct Task *task) static void ReelTime_LandOnOutcome(struct Task *task) { - s16 reelTimePixelOffset = sSlotMachine->reelTimePixelOffset % 20; - if (reelTimePixelOffset) + s16 reeltimePixelOffset = sSlotMachine->reeltimePixelOffset % 20; + if (reeltimePixelOffset) { - reelTimePixelOffset = AdvanceReelTimeReelToNextTag(task->data[4] >> 8); + reeltimePixelOffset = AdvanceReeltimeReelToNextTag(task->data[4] >> 8); task->data[4] = (u8)task->data[4] + 0x40; } else if (GetNearbyReelTimeTag(1) != sSlotMachine->reelTimeDraw) { - AdvanceReelTimeReel(task->data[4] >> 8); - reelTimePixelOffset = sSlotMachine->reelTimePixelOffset % 20; + AdvanceReeltimeReel(task->data[4] >> 8); + reeltimePixelOffset = sSlotMachine->reeltimePixelOffset % 20; task->data[4] = (u8)task->data[4] + 0x40; } - if (reelTimePixelOffset == 0 && GetNearbyReelTimeTag(1) == sSlotMachine->reelTimeDraw) + if (reeltimePixelOffset == 0 && GetNearbyReelTimeTag(1) == sSlotMachine->reelTimeDraw) { task->data[4] = 0; // stop moving task->tState++; @@ -3441,7 +3444,7 @@ static void InfoBox_DrawWindow(struct Task *task) static void InfoBox_AddText(struct Task *task) { - AddTextPrinterParameterized3(1, 1, 2, 5, sColors_ReelTimeHelp, 0, gText_ReelTimeHelp); + AddTextPrinterParameterized3(1, 1, 2, 5, sColors_ReeltimeHelp, 0, gText_ReelTimeHelp); CopyWindowToVram(1, 3); BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB(0, 0, 0)); task->tState++; @@ -3771,7 +3774,7 @@ static void CreateReelTimeNumberSprites(void) static void SpriteCB_ReelTimeNumbers(struct Sprite *sprite) { - s16 r0 = (u16)(sSlotMachine->reelTimePixelOffset + sprite->data[7]); + s16 r0 = (u16)(sSlotMachine->reeltimePixelOffset + sprite->data[7]); r0 %= 40; sprite->pos1.y = r0 + 59; StartSpriteAnimIfDifferent(sprite, GetNearbyReelTimeTag(r0 / 20)); @@ -4827,7 +4830,7 @@ static const u8 sLuckyFlagProbabilities_NotTop3[][6] = { {40, 40, 35, 35, 40, 40} }; -static const u8 sReelTimeProbabilities_UnluckyGame[][17] = { +static const u8 sReeltimeProbabilities_UnluckyGame[][17] = { {243, 243, 243, 80, 80, 80, 80, 40, 40, 40, 40, 40, 40, 5, 5, 5, 5}, { 5, 5, 5, 150, 150, 150, 150, 130, 130, 130, 130, 130, 130, 100, 100, 100, 5}, { 4, 4, 4, 20, 20, 20, 20, 80, 80, 80, 80, 80, 80, 100, 100, 100, 40}, diff --git a/src/start_menu.c b/src/start_menu.c index fa51766e8..6a90946fe 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -462,7 +462,7 @@ static bool32 InitStartMenuStep(void) sInitStartMenuData[0]++; break; case 4: - if (PrintStartMenuActions((s8 *)&sInitStartMenuData[1], 2)) + if (PrintStartMenuActions(&sInitStartMenuData[1], 2)) sInitStartMenuData[0]++; break; case 5: @@ -550,19 +550,19 @@ void ShowStartMenu(void) static bool8 HandleStartMenuInput(void) { - if (JOY_NEW(DPAD_UP)) + if (gMain.newKeys & DPAD_UP) { PlaySE(SE_SELECT); sStartMenuCursorPos = Menu_MoveCursor(-1); } - if (JOY_NEW(DPAD_DOWN)) + if (gMain.newKeys & DPAD_DOWN) { PlaySE(SE_SELECT); sStartMenuCursorPos = Menu_MoveCursor(1); } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); if (sStartMenuItems[sCurrentStartMenuActions[sStartMenuCursorPos]].func.u8_void == StartMenuPokedexCallback) @@ -584,7 +584,7 @@ static bool8 HandleStartMenuInput(void) return FALSE; } - if (JOY_NEW(START_BUTTON | B_BUTTON)) + if (gMain.newKeys & (START_BUTTON | B_BUTTON)) { RemoveExtraStartMenuWindows(); HideStartMenu(); @@ -906,12 +906,12 @@ static bool8 SaveSuccesTimer(void) { sSaveDialogTimer--; - if (JOY_HELD(A_BUTTON)) + if (gMain.heldKeys & A_BUTTON) { PlaySE(SE_SELECT); return TRUE; } - if (sSaveDialogTimer == 0) + else if (sSaveDialogTimer == 0) { return TRUE; } @@ -925,7 +925,7 @@ static bool8 SaveErrorTimer(void) { sSaveDialogTimer--; } - else if (JOY_HELD(A_BUTTON)) + else if (gMain.heldKeys & A_BUTTON) { return TRUE; } diff --git a/src/title_screen.c b/src/title_screen.c index 1d6f90d74..108601685 100644 --- a/src/title_screen.c +++ b/src/title_screen.c @@ -727,24 +727,24 @@ static void Task_TitleScreenPhase2(u8 taskId) // Show Rayquaza silhouette and process main title screen input static void Task_TitleScreenPhase3(u8 taskId) { - if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(START_BUTTON))) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & START_BUTTON)) { FadeOutBGM(4); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_WHITEALPHA); SetMainCallback2(CB2_GoToMainMenu); } - else if (JOY_HELD(CLEAR_SAVE_BUTTON_COMBO) == CLEAR_SAVE_BUTTON_COMBO) + else if ((gMain.heldKeys & CLEAR_SAVE_BUTTON_COMBO) == CLEAR_SAVE_BUTTON_COMBO) { SetMainCallback2(CB2_GoToClearSaveDataScreen); } - else if (JOY_HELD(RESET_RTC_BUTTON_COMBO) == RESET_RTC_BUTTON_COMBO + else if ((gMain.heldKeys & RESET_RTC_BUTTON_COMBO) == RESET_RTC_BUTTON_COMBO && CanResetRTC() == TRUE) { FadeOutBGM(4); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); SetMainCallback2(CB2_GoToResetRtcScreen); } - else if (JOY_HELD(BERRY_UPDATE_BUTTON_COMBO) == BERRY_UPDATE_BUTTON_COMBO) + else if ((gMain.heldKeys & BERRY_UPDATE_BUTTON_COMBO) == BERRY_UPDATE_BUTTON_COMBO) { FadeOutBGM(4); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 0x10, RGB_BLACK); diff --git a/src/trade.c b/src/trade.c index 17aaba565..3072b8585 100644 --- a/src/trade.c +++ b/src/trade.c @@ -1353,24 +1353,24 @@ static void SetReadyToTrade(void) static void TradeMenuProcessInput(void) { - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { TradeMenuMoveCursor(&sTradeMenuData->cursorPosition, 0); } - else if (JOY_REPEAT(DPAD_DOWN)) + else if (gMain.newAndRepeatedKeys & DPAD_DOWN) { TradeMenuMoveCursor(&sTradeMenuData->cursorPosition, 1); } - else if (JOY_REPEAT(DPAD_LEFT)) + else if (gMain.newAndRepeatedKeys & DPAD_LEFT) { TradeMenuMoveCursor(&sTradeMenuData->cursorPosition, 2); } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { TradeMenuMoveCursor(&sTradeMenuData->cursorPosition, 3); } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); @@ -1451,7 +1451,7 @@ static void TradeMenuProcessInput_SelectedMon(void) static void ChooseMonAfterButtonPress(void) { - if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON))) + if ((gMain.newKeys & A_BUTTON) || (gMain.newKeys & B_BUTTON)) { PlaySE(SE_SELECT); TradeMenuChooseMon(); @@ -1626,7 +1626,7 @@ static void RedrawTradeMenuAfterPressA(void) { int i; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); rbox_fill_rectangle(0); @@ -1698,7 +1698,7 @@ static void LinkTradeWaitForQueue(void) static void PartnersMonWasInvalid(void) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { SetLinkData(LINKCMD_READY_CANCEL_TRADE, 0); sTradeMenuData->tradeMenuFunc = TRADEMENUFUNC_STANDBY; @@ -3728,7 +3728,7 @@ static bool8 AnimateTradeSequenceCable(void) { return TRUE; } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { sTradeData->state++; } @@ -4243,7 +4243,7 @@ static bool8 AnimateTradeSequenceWireless(void) { return TRUE; } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { sTradeData->state++; } diff --git a/src/trainer_card.c b/src/trainer_card.c index 2d9ec2b09..9d6838176 100755 --- a/src/trainer_card.c +++ b/src/trainer_card.c @@ -438,13 +438,13 @@ static void Task_TrainerCard(u8 taskId) DrawTrainerCardWindow(1); sData->timeColonNeedDraw = FALSE; } - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { FlipTrainerCard(); PlaySE(SE_RG_CARD_FLIP); sData->mainState = STATE_WAIT_FLIP_TO_BACK; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { if (gReceivedRemoteLinkPlayers && sData->isLink && InUnionRoom() == TRUE) { @@ -465,7 +465,7 @@ static void Task_TrainerCard(u8 taskId) } break; case STATE_HANDLE_INPUT_BACK: - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { if (gReceivedRemoteLinkPlayers && sData->isLink && InUnionRoom() == TRUE) { @@ -483,7 +483,7 @@ static void Task_TrainerCard(u8 taskId) PlaySE(SE_RG_CARD_FLIP); } } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { if (gReceivedRemoteLinkPlayers && sData->isLink && InUnionRoom() == TRUE) { diff --git a/src/trainer_hill.c b/src/trainer_hill.c index 14af7372f..c5aea14d9 100644 --- a/src/trainer_hill.c +++ b/src/trainer_hill.c @@ -356,7 +356,7 @@ static void SetUpDataStruct(void) { if (sHillData == NULL) { - sHillData = AllocZeroed(sizeof(struct TrHillStruct2)); + sHillData = AllocZeroed(sizeof(*sHillData)); sHillData->floorId = gMapHeader.mapLayoutId - LAYOUT_TRAINER_HILL_1F; CpuCopy32(sDataPerTag[gSaveBlock1Ptr->trainerHill.tag], &sHillData->tag, sizeof(sHillData->tag) + 4 * sizeof(struct TrHillFloor)); nullsub_2(); @@ -672,18 +672,70 @@ bool32 LoadTrainerHillFloorObjectEventScripts(void) return TRUE; } -static u16 sub_81D5F58(u8 floorId, u32 bit, u32 arg2, u32 arg3) +// Functionally equivalent. +#ifdef NONMATCHING +static u32 sub_81D5F58(u8 floorId, u32 bit, u32 arg2, u32 arg3) { - u8 var0; - u16 var1; - u16 var2; + u32 var0, var1, var2, var3; - var0 = (sHillData->floors[floorId].display.unk3A0[arg2] >> (15 - bit) & 1); - var1 = sHillData->floors[floorId].display.data[arg3 * arg2 + bit] + 0x200; + var0 = (sHillData->floors[floorId].display.unk3A0[arg2] >> (15 - bit)) & 1; + var1 = sHillData->floors[floorId].display.data[arg2 * arg3 + bit]; + var3 = 0x200; var2 = 0x3000; - return (((var0 << 10) & 0xc00) | var2) | (var1 & 0x3ff); + return ((var0 << 10) | var2) | (var1 | var3); } +#else +NAKED +static u32 sub_81D5F58(u8 floorId, u32 bit, u32 arg2, u32 arg3) +{ + asm_unified("\n\ + push {r4,r5,lr}\n\ + lsls r0, 24\n\ + lsrs r0, 24\n\ + ldr r4, =sHillData\n\ + ldr r4, [r4]\n\ + mov r12, r4\n\ + lsls r4, r2, 1\n\ + lsls r5, r0, 4\n\ + subs r5, r0\n\ + lsls r5, 3\n\ + subs r5, r0\n\ + lsls r5, 3\n\ + adds r4, r5\n\ + movs r0, 0xE8\n\ + lsls r0, 2\n\ + add r0, r12\n\ + adds r0, r4\n\ + ldrh r0, [r0]\n\ + movs r4, 0xF\n\ + subs r4, r1\n\ + asrs r0, r4\n\ + movs r4, 0x1\n\ + ands r0, r4\n\ + muls r2, r3\n\ + adds r2, r1\n\ + adds r2, r5\n\ + movs r1, 0xA8\n\ + lsls r1, 2\n\ + add r1, r12\n\ + adds r1, r2\n\ + ldrb r1, [r1]\n\ + movs r2, 0x80\n\ + lsls r2, 2\n\ + adds r3, r2, 0\n\ + movs r2, 0xC0\n\ + lsls r2, 6\n\ + lsls r0, 10\n\ + orrs r0, r2\n\ + orrs r1, r3\n\ + orrs r0, r1\n\ + pop {r4,r5}\n\ + pop {r1}\n\ + bx r1\n\ + .pool"); +} +#endif // NONMATCHING void GenerateTrainerHillFloorLayout(u16 *mapArg) { diff --git a/src/trainer_see.c b/src/trainer_see.c index c37f37262..4f4aaea08 100644 --- a/src/trainer_see.c +++ b/src/trainer_see.c @@ -603,7 +603,7 @@ static void sub_80B44C8(u8 taskId) struct ObjectEvent *objEvent; // another objEvent loaded into by loadword? - LoadWordFromTwoHalfwords((u16*)&task->data[1], (u32 *)&objEvent); + LoadWordFromTwoHalfwords(&task->data[1], (u32 *)&objEvent); if (!task->data[7]) { ObjectEventClearHeldMovement(objEvent); @@ -624,7 +624,7 @@ static void sub_80B44C8(u8 taskId) void sub_80B4578(struct ObjectEvent *var) { - StoreWordInTwoHalfwords((u16 *)&gTasks[CreateTask(sub_80B44C8, 0)].data[1], (u32)var); + StoreWordInTwoHalfwords(&gTasks[CreateTask(sub_80B44C8, 0)].data[1], (u32)var); } void EndTrainerApproach(void) diff --git a/src/union_room.c b/src/union_room.c index 05bd8cfb0..1bac3678c 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -445,7 +445,7 @@ static void Task_TryBecomeLinkLeader(u8 taskId) break; case LL_STATE_AWAIT_PLAYERS: Leader_SetStateIfMemberListChanged(data, LL_STATE_ACCEPT_NEW_MEMBER_PROMPT, LL_STATE_MEMBER_LEFT); - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { if (data->playerCount == 1) data->state = LL_STATE_SHUTDOWN_AND_FAIL; @@ -458,7 +458,7 @@ static void Task_TryBecomeLinkLeader(u8 taskId) && data->playerCount > GROUP_MIN(sPlayerActivityGroupSize) - 1 && GROUP_MAX(sPlayerActivityGroupSize) != 0 && sub_8012240() - && JOY_NEW(START_BUTTON)) + && gMain.newKeys & START_BUTTON) { data->state = LL_STATE_MEMBERS_OK_PROMPT; LinkRfu_StopManagerAndFinalizeSlots(); @@ -1005,7 +1005,7 @@ static void Task_TryJoinLinkGroup(u8 taskId) break; case 0: id = ListMenu_ProcessInput(data->listTaskId); - if (JOY_NEW(A_BUTTON) && id != -1) + if (gMain.newKeys & A_BUTTON && id != -1) { // this unused variable along with the assignment is needed to match u32 activity = data->field_0->arr[id].gname_uname.gname.activity; @@ -1032,7 +1032,7 @@ static void Task_TryJoinLinkGroup(u8 taskId) PlaySE(SE_WALL_HIT); } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { data->state = LG_STATE_CANCEL_CHOOSE_LEADER; } @@ -1135,7 +1135,7 @@ static void Task_TryJoinLinkGroup(u8 taskId) break; } - if (RfuGetStatus() == RFU_STATUS_OK && JOY_NEW(B_BUTTON)) + if (RfuGetStatus() == RFU_STATUS_OK && gMain.newKeys & B_BUTTON) data->state = LG_STATE_ASK_LEAVE_GROUP; break; case LG_STATE_ASK_LEAVE_GROUP: @@ -1889,7 +1889,7 @@ static void Task_MEvent_Leader(u8 taskId) break; case 4: Leader_SetStateIfMemberListChanged(data, 5, 6); - if (JOY_NEW(B_BUTTON)) + if (gMain.newKeys & B_BUTTON) { data->state = 13; DestroyWirelessStatusIndicatorSprite(); @@ -2104,7 +2104,7 @@ static void Task_CardOrNewsWithFriend(u8 taskId) break; case 0: id = ListMenu_ProcessInput(data->listTaskId); - if (JOY_NEW(A_BUTTON) && id != -1) + if (gMain.newKeys & A_BUTTON && id != -1) { // this unused variable along with the assignment is needed to match u32 unusedVar; @@ -2126,7 +2126,7 @@ static void Task_CardOrNewsWithFriend(u8 taskId) PlaySE(SE_WALL_HIT); } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { data->state = 6; } @@ -2289,7 +2289,7 @@ static void Task_CardOrNewsOverWireless(u8 taskId) } } } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { data->state = 6; data->refreshTimer = 0; @@ -2547,7 +2547,7 @@ static void Task_RunUnionRoom(u8 taskId) } else if (ScriptContext2_IsEnabled() != TRUE) { - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { if (TryInteractWithUnionRoomMember(uroom->field_0, &taskData[0], &taskData[1], uroom->spriteIds)) { @@ -2881,7 +2881,7 @@ static void Task_RunUnionRoom(u8 taskId) break; case UR_STATE_HANDLE_CONTACT_DATA: ReceiveUnionRoomActivityPacket(uroom); - if (UnionRoom_HandleContactFromOtherPlayer(uroom) && JOY_NEW(B_BUTTON)) + if (UnionRoom_HandleContactFromOtherPlayer(uroom) && gMain.newKeys & B_BUTTON) { sub_8011DE0(1); StringCopy(gStringVar4, sText_ChatEnded); @@ -3754,7 +3754,7 @@ static void UR_AddTextPrinterParameterized(u8 windowId, u8 fontId, const u8 *str printerTemplate.y = y; printerTemplate.currentX = x; printerTemplate.currentY = y; - printerTemplate.style = 0; + printerTemplate.unk = 0; gTextFlags.useAlternateDownArrow = FALSE; switch (colorIdx) diff --git a/src/union_room_chat.c b/src/union_room_chat.c index ed39d3acf..fd2a95791 100755 --- a/src/union_room_chat.c +++ b/src/union_room_chat.c @@ -1017,12 +1017,12 @@ static void Chat_HandleInput(void) switch (sChat->funcState) { case 0: - if (JOY_NEW(START_BUTTON)) + if (gMain.newKeys & START_BUTTON) { if (sChat->bufferCursorPos) SetChatFunction(CHAT_FUNC_SEND); } - else if (JOY_NEW(SELECT_BUTTON)) + else if (gMain.newKeys & SELECT_BUTTON) { SetChatFunction(CHAT_FUNC_SWITCH); } @@ -1039,14 +1039,14 @@ static void Chat_HandleInput(void) SetChatFunction(CHAT_FUNC_ASK_QUIT); } } - else if (JOY_NEW(A_BUTTON)) + else if (gMain.newKeys & A_BUTTON) { AppendTextToMessage(); StartDisplaySubtask(CHATDISPLAY_FUNC_UPDATE_MSG, 0); StartDisplaySubtask(CHATDISPLAY_FUNC_CURSOR_BLINK, 1); sChat->funcState = 1; } - else if (JOY_NEW(R_BUTTON)) + else if (gMain.newKeys & R_BUTTON) { if (sChat->currentPage != UNION_ROOM_KB_PAGE_REGISTER) { @@ -1100,7 +1100,7 @@ static void Chat_Switch(void) shouldSwitchPages = FALSE; break; case MENU_NOTHING_CHOSEN: - if (JOY_NEW(SELECT_BUTTON)) + if (gMain.newKeys & SELECT_BUTTON) { PlaySE(SE_SELECT); Menu_MoveCursor(1); @@ -1420,13 +1420,13 @@ static void Chat_Register(void) } break; case 1: - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { RegisterTextAtRow(); StartDisplaySubtask(CHATDISPLAY_FUNC_RETURN_TO_KB, 0); sChat->funcState = 3; } - else if (JOY_NEW(B_BUTTON)) + else if (gMain.newKeys & B_BUTTON) { StartDisplaySubtask(CHATDISPLAY_FUNC_CANCEL_REGISTER, 0); sChat->funcState = 4; @@ -1457,7 +1457,7 @@ static void Chat_Register(void) sChat->funcState = 6; break; case 6: - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) { StartDisplaySubtask(CHATDISPLAY_FUNC_DESTROY_YESNO, 0); sChat->funcState = 4; @@ -1591,7 +1591,7 @@ static bool32 HandleDPadInput(void) { do { - if (JOY_REPEAT(DPAD_UP)) + if (gMain.newAndRepeatedKeys & DPAD_UP) { if (sChat->currentRow > 0) sChat->currentRow--; @@ -1599,7 +1599,7 @@ static bool32 HandleDPadInput(void) sChat->currentRow = sKeyboardPageMaxRow[sChat->currentPage]; break; } - if (JOY_REPEAT(DPAD_DOWN)) + if (gMain.newAndRepeatedKeys & DPAD_DOWN) { if (sChat->currentRow < sKeyboardPageMaxRow[sChat->currentPage]) sChat->currentRow++; @@ -1609,7 +1609,7 @@ static bool32 HandleDPadInput(void) } if (sChat->currentPage != UNION_ROOM_KB_PAGE_REGISTER) { - if (JOY_REPEAT(DPAD_LEFT)) + if (gMain.newAndRepeatedKeys & DPAD_LEFT) { if (sChat->currentCol > 0) sChat->currentCol--; @@ -1617,7 +1617,7 @@ static bool32 HandleDPadInput(void) sChat->currentCol = 4; break; } - else if (JOY_REPEAT(DPAD_RIGHT)) + else if (gMain.newAndRepeatedKeys & DPAD_RIGHT) { if (sChat->currentCol < 4) sChat->currentCol++; @@ -2121,7 +2121,7 @@ static void Task_ReceiveChatMessage(u8 taskId) static bool8 TryAllocDisplay(void) { - sDisplay = Alloc(sizeof(struct UnionRoomChatDisplay)); + sDisplay = Alloc(sizeof(*sDisplay)); if (sDisplay && TryAllocSprites()) { ResetBgsAndClearDma3BusyFlags(0); diff --git a/src/unk_text_util_2.c b/src/unk_text_util_2.c index b92b34fbd..2ff8c6507 100644 --- a/src/unk_text_util_2.c +++ b/src/unk_text_util_2.c @@ -19,14 +19,14 @@ u16 Font6Func(struct TextPrinter *textPrinter) switch (textPrinter->state) { case 0: - if (JOY_HELD(A_BUTTON | B_BUTTON) && subStruct->hasPrintBeenSpedUp) + if (gMain.heldKeys & (A_BUTTON | B_BUTTON) && subStruct->hasPrintBeenSpedUp) { textPrinter->delayCounter = 0; } if (textPrinter->delayCounter && textPrinter->textSpeed) { textPrinter->delayCounter --; - if (gTextFlags.canABSpeedUpPrint && JOY_NEW(A_BUTTON | B_BUTTON)) + if (gTextFlags.canABSpeedUpPrint && gMain.newKeys & (A_BUTTON | B_BUTTON)) { subStruct->hasPrintBeenSpedUp = TRUE; textPrinter->delayCounter = 0; @@ -135,7 +135,7 @@ u16 Font6Func(struct TextPrinter *textPrinter) } DecompressGlyphFont6(char_); CopyGlyphToWindow(textPrinter); - textPrinter->printerTemplate.currentX += gUnknown_03002F90.width + textPrinter->printerTemplate.letterSpacing; + textPrinter->printerTemplate.currentX += gUnknown_03002F90.unk80 + textPrinter->printerTemplate.letterSpacing; return 0; case 1: if (TextPrinterWait(textPrinter)) @@ -210,8 +210,8 @@ static void DecompressGlyphFont6(u16 glyph) DecompressGlyphTile(glyphs + 0x8, (u16 *)(gUnknown_03002F90.unk20)); DecompressGlyphTile(glyphs + 0x80, (u16 *)(gUnknown_03002F90.unk40)); DecompressGlyphTile(glyphs + 0x88, (u16 *)(gUnknown_03002F90.unk60)); - gUnknown_03002F90.width = 0x10; - gUnknown_03002F90.height = 0x10; + gUnknown_03002F90.unk80 = 0x10; + gUnknown_03002F90.unk81 = 0x10; } u32 GetGlyphWidthFont6(u16 glyphId, bool32 isJapanese) diff --git a/src/walda_phrase.c b/src/walda_phrase.c index 2b11add76..4b617e3b8 100644 --- a/src/walda_phrase.c +++ b/src/walda_phrase.c @@ -118,8 +118,8 @@ static u8 GetLetterTableId(u8 letter) static bool32 TryCalculateWallpaper(u16* backgroundClr, u16 *foregroundClr, u8 *iconId, u8 *patternId, u16 trainerId, u8 *phrase) { s32 i; - u8 array[9]; - u8 charsByTableId[15]; + ALIGNED(2) u8 array[12]; + u8 charsByTableId[16]; u16 *ptr; if (StringLength(phrase) != 15) diff --git a/src/wallclock.c b/src/wallclock.c index c38dd99e3..bed04928e 100644 --- a/src/wallclock.c +++ b/src/wallclock.c @@ -795,7 +795,7 @@ static void Task_SetClock_HandleInput(u8 taskId) { gTasks[taskId].tMinuteHandAngle = gTasks[taskId].tMinutes * 6; gTasks[taskId].tHourHandAngle = (gTasks[taskId].tHours % 12) * 30 + (gTasks[taskId].tMinutes / 10) * 5; - if (JOY_NEW(A_BUTTON)) + if (gMain.newKeys & A_BUTTON) { gTasks[taskId].func = Task_SetClock_AskConfirm; } @@ -803,10 +803,10 @@ static void Task_SetClock_HandleInput(u8 taskId) { gTasks[taskId].tMoveDir = MOVE_NONE; - if (JOY_HELD(DPAD_LEFT)) + if (gMain.heldKeys & DPAD_LEFT) gTasks[taskId].tMoveDir = MOVE_BACKWARD; - if (JOY_HELD(DPAD_RIGHT)) + if (gMain.heldKeys & DPAD_RIGHT) gTasks[taskId].tMoveDir = MOVE_FORWARD; if (gTasks[taskId].tMoveDir != MOVE_NONE) @@ -878,7 +878,7 @@ static void Task_ViewClock_WaitFadeIn(u8 taskId) static void Task_ViewClock_HandleInput(u8 taskId) { InitClockWithRtc(taskId); - if (JOY_NEW(A_BUTTON | B_BUTTON)) + if (gMain.newKeys & (A_BUTTON | B_BUTTON)) gTasks[taskId].func = Task_ViewClock_FadeOut; } diff --git a/src/wireless_communication_status_screen.c b/src/wireless_communication_status_screen.c index 81fa16720..87b200f14 100644 --- a/src/wireless_communication_status_screen.c +++ b/src/wireless_communication_status_screen.c @@ -237,7 +237,7 @@ static void PrintHeaderTexts(void) FillWindowPixelBuffer(1, PIXEL_FILL(0)); FillWindowPixelBuffer(2, PIXEL_FILL(0)); WCSS_AddTextPrinterParameterized(0, 1, sHeaderTexts[0], GetStringCenterAlignXOffset(1, sHeaderTexts[0], 0xC0), 6, COLORMODE_GREEN); - for (i = 0; i < (int)ARRAY_COUNT(sHeaderTexts[0]) - 1; i++) + for (i = 0; i < (int)ARRAY_COUNT(*sHeaderTexts) - 1; i++) { WCSS_AddTextPrinterParameterized(1, 1, sHeaderTexts[i + 1], 0, 30 * i + 8, COLORMODE_WHITE_LGRAY); } @@ -362,12 +362,12 @@ static u32 CountPlayersInGroupAndGetActivity(struct UnkStruct_x20 * unk20, u32 * { if (group_players(i) == 0) { - k = 0; //Should just be 1 without the increment after the loop ends but that doesn't match. + k = 0; for (j = 0; j < RFU_CHILD_MAX; j++) { if (unk20->gname_uname.gname.child_sprite_gender[j] != 0) k++; } - k++; //See above comment. + k++; groupCounts[group_type(i)] += k; } else diff --git a/tools/gbagfx/gfx.c b/tools/gbagfx/gfx.c index 4e85953fd..8d959465f 100644 --- a/tools/gbagfx/gfx.c +++ b/tools/gbagfx/gfx.c @@ -282,7 +282,7 @@ static void HflipTile(unsigned char * tile, int bitDepth) for (i = 0; i < 8; i++) { SWAP_NYBBLES(&tile[4 * i + 0], &tile[4 * i + 3]); - SWAP_NYBBLES(&tile[4 * i + 1], &tile[4 * i + 2]); + SWAP_NYBBLES(&tile[4 * i + 1], &tile[4 * i + 2]);; } break; case 8: