diff --git a/Makefile b/Makefile index b21ac0fa4..0035eb626 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 a995c70a1..4cbad1376 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,18 +451,18 @@ 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; } } -inline static void GLYPH_COPY(u8 *windowTiles, u32 widthOffset, u32 j, u32 i, u32 *ptr, s32 width, s32 height) // +inline static void GLYPH_COPY(u8 *windowTiles, u32 widthOffset, u32 j, u32 i, u32 *ptr, s32 width, s32 height) { u32 xAdd, yAdd, r5, bits, toOrr, dummyX; u8 *dst; @@ -570,7 +570,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; @@ -582,7 +582,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; @@ -594,7 +594,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; @@ -606,7 +606,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; @@ -618,7 +618,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; @@ -630,7 +630,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; @@ -642,7 +642,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; @@ -654,7 +654,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; @@ -666,7 +666,7 @@ void TextPrinterInitDownArrowCounters(struct TextPrinter *textPrinter) { struct TextPrinterSubStruct *subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields); - if (gTextFlags.autoScroll == TRUE) + if (gTextFlags.autoScroll == 1) { subStruct->autoScrollDelay = 0; } @@ -682,7 +682,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) { @@ -758,7 +758,7 @@ bool8 TextPrinterWaitAutoMode(struct TextPrinter *textPrinter) bool16 TextPrinterWaitWithDownArrow(struct TextPrinter *textPrinter) { bool8 result = FALSE; - if (gTextFlags.autoScroll) + if (gTextFlags.autoScroll != 0) { result = TextPrinterWaitAutoMode(textPrinter); } @@ -777,14 +777,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 (JOY_NEW(A_BUTTON | B_BUTTON)) + { + result = TRUE; + PlaySE(SE_SELECT); + } } return result; } @@ -800,7 +803,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) { @@ -992,10 +995,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; @@ -1056,10 +1059,13 @@ u16 RenderText(struct TextPrinter *textPrinter) 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.width + textPrinter->printerTemplate.letterSpacing); + else + textPrinter->printerTemplate.currentX += gUnknown_03002F90.width; + } return 0; case 1: if (TextPrinterWait(textPrinter)) @@ -1545,7 +1551,7 @@ void SetDefaultFontsPointer(void) u8 GetFontAttribute(u8 fontId, u8 attributeId) { - u8 result = 0; + int result = 0; switch (attributeId) { case FONTATTR_MAX_LETTER_WIDTH: @@ -1560,8 +1566,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; @@ -1591,7 +1597,7 @@ void DecompressGlyphFont0(u16 glyphId, bool32 isJapanese) 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.height = 12; // gGlyphHeight } else { @@ -1634,7 +1640,7 @@ void DecompressGlyphFont7(u16 glyphId, bool32 isJapanese) 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.height = 15; // gGlyphHeight } else { @@ -1676,7 +1682,7 @@ void DecompressGlyphFont8(u16 glyphId, bool32 isJapanese) 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.height = 12; // gGlyphHeight } else { @@ -1716,10 +1722,10 @@ 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 + 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.width = gFont2JapaneseGlyphWidths[glyphId]; // gGlyphWidth gUnknown_03002F90.height = 14; // gGlyphHeight } else @@ -1763,7 +1769,7 @@ void DecompressGlyphFont1(u16 glyphId, bool32 isJapanese) 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.height = 15; // gGlyphHeight } else { diff --git a/gflib/text.h b/gflib/text.h index 4cf5bc20b9..723a2fc0e 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; @@ -379,7 +372,7 @@ struct Struct_03002F90 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 e4b773089..8dad6bc25 100644 --- a/include/battle.h +++ b/include/battle.h @@ -124,8 +124,8 @@ struct ProtectStruct u32 flinchImmobility:1; u32 notFirstStrike:1; u32 palaceUnableToUseMove:1; - s32 physicalDmg; - s32 specialDmg; + u32 physicalDmg; + u32 specialDmg; u8 physicalBattlerId; u8 specialBattlerId; }; @@ -254,7 +254,7 @@ struct BattleResults u16 playerMon2Species; // 0x26 u16 caughtMonSpecies; // 0x28 u8 caughtMonNick[POKEMON_NAME_LENGTH + 1]; // 0x2A - u8 filler35; // 0x35 + u8 filler35; // 0x35 u8 catchAttempts[11]; // 0x36 }; 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/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/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 f5781bcb4..85166e0ec 100644 --- a/include/global.h +++ b/include/global.h @@ -98,7 +98,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..a956b9c40 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -127,8 +127,8 @@ struct Unknown_806F160_Struct u32 field_0_1:4; u32 field_1:8; u16 magic:8; - u32 size:4; - u16 field_3_1:4; + u32 field_3_0:4; + u32 field_3_1:4; void *bytes; u8 **byteArrays; struct SpriteTemplate *templates; 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..f6ebcc726 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); 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/battle_ai_script_commands.c b/src/battle_ai_script_commands.c index 1fd0642ad..4185f8017 100644 --- a/src/battle_ai_script_commands.c +++ b/src/battle_ai_script_commands.c @@ -1298,7 +1298,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..b8aba8976 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)) @@ -440,24 +443,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_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 abb3223e0..f57e2a4fc 100755 --- a/src/battle_anim_effects_3.c +++ b/src/battle_anim_effects_3.c @@ -5002,8 +5002,8 @@ 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; @@ -5037,31 +5037,34 @@ void AnimTask_SnatchOpposingMonMove(u8 taskId) isBackPic = FALSE; 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 = 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; + + subpriority = gSprites[GetAnimBattlerSpriteId(ANIM_TARGET)].subpriority - 1; + isBackPic = TRUE; + x = -32; + } } spriteId2 = sub_80A8394(species, isBackPic, 0, x, GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_Y), subpriority, personality, otId, gBattleAnimAttacker, 0); @@ -5088,7 +5091,7 @@ void AnimTask_SnatchOpposingMonMove(u8 taskId) if (x < GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_X)) { gTasks[taskId].data[14]++; - gBattleAnimArgs[7] = -1; + gBattleAnimArgs[7] = 0xFFFF; } } else @@ -5096,7 +5099,7 @@ void AnimTask_SnatchOpposingMonMove(u8 taskId) if (x > GetBattlerSpriteCoord(gBattleAnimTarget, BATTLER_COORD_X)) { gTasks[taskId].data[14]++; - gBattleAnimArgs[7] = -1; + gBattleAnimArgs[7] = 0xFFFF; } } } diff --git a/src/battle_anim_flying.c b/src/battle_anim_flying.c index fe94dc9a2..f8d47f4ec 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; 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,31 @@ 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]; + spriteCoord = gSineTable[sinIndex]; gOamMatrices[matrixNum].a = gOamMatrices[matrixNum].d = gSineTable[sinIndex + 64]; - gOamMatrices[matrixNum].b = sinVal; - gOamMatrices[matrixNum].c = -sinVal; + gOamMatrices[matrixNum].b = spriteCoord; + gOamMatrices[matrixNum].c = -spriteCoord; 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 +654,240 @@ 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 ((u8)data->unk0_1 == 1) //casts to u8 here are necessary for matching + { + 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) + { + 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 ((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) + { + 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 ((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) + { + 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 ((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) + { + 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; + } + + 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 = 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 +931,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 +1047,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 +1070,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 +1078,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 +1102,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 +1147,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); } @@ -1204,12 +1223,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_water.c b/src/battle_anim_water.c index 12f37dbba..2bb90e585 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"); @@ -631,13 +631,13 @@ static void AnimTask_RotateAuroraRingColors_Step(u8 taskId) if (++gTasks[taskId].data[10] == 3) { - u16 tempPlt; + u16 rgbBuffer; gTasks[taskId].data[10] = 0; palIndex = gTasks[taskId].data[2] + 1; - tempPlt = gPlttBufferFaded[palIndex]; + rgbBuffer = gPlttBufferFaded[palIndex]; for (i = 1; i < 8; i++) gPlttBufferFaded[palIndex + i - 1] = gPlttBufferFaded[palIndex + i]; - gPlttBufferFaded[palIndex + 7] = tempPlt; + gPlttBufferFaded[palIndex + 7] = rgbBuffer; } if (++gTasks[taskId].data[11] == gTasks[taskId].data[0]) DestroyAnimVisualTask(taskId); @@ -748,7 +748,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,7 +793,7 @@ 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); } @@ -802,17 +801,17 @@ void AnimTask_CreateSurfWave(u8 taskId) { struct BattleAnimBgData animBg; u8 taskId2; - u16 *x, *y; //These pointers are needed to match + u16 *x; + u16 *y; 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); @@ -877,13 +876,13 @@ void AnimTask_CreateSurfWave(u8 taskId) 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; + u32 palOffset; + u16 palNum; *BGptrX += gTasks[taskId].data[0]; *BGptrY += gTasks[taskId].data[1]; @@ -891,18 +890,18 @@ 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 + gPlttBufferFaded[animBg.paletteId * 16 + 1 + i] = gPlttBufferFaded[animBg.paletteId * 16 + 1 + i - 1]; // 1 + i - 1 is needed to match for some bizarre reason } - 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) + if (++gTasks[taskId].data[3] <= 13) { gTasks[gTasks[taskId].data[15]].data[1] = (s16)((gTasks[taskId].data[3]) | ((16 - gTasks[taskId].data[3]) << 8)); gTasks[taskId].data[4]++; @@ -920,7 +919,6 @@ static void AnimTask_CreateSurfWave_Step1(u8 taskId) } } - static void AnimTask_CreateSurfWave_Step2(u8 taskId) { u16 *BGptrX = &gBattle_BG1_X; @@ -1543,50 +1541,45 @@ static void AnimWaterPulseRing_Step(struct Sprite *sprite) sprite->data[0]++; } -static void CreateWaterPulseRingBubbles(struct Sprite *sprite, s32 xDiff, s32 yDiff) +static void CreateWaterPulseRingBubbles(struct Sprite *sprite, int xDiff, int yDiff) { - s16 combinedX, combinedY; - s16 i, something; + s16 combinedX; + s16 combinedY; + s16 i; + s16 something; s16 unusedVar = 1; //unusedVar is needed to match - s16 somethingRandomX, somethingRandomY; + s16 randomSomethingY; + s16 randomSomethingX; 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; + unusedVar *= -1; //Needed to match + randomSomethingY = yDiff + (Random2() % 10) - 5; + randomSomethingX = -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; } } 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_dome.c b/src/battle_dome.c index e504115a6..ce2f3cde6 100644 --- a/src/battle_dome.c +++ b/src/battle_dome.c @@ -2763,10 +2763,10 @@ static int GetTypeEffectivenessPoints(int move, int targetSpecies, int arg2) // 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; + 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; + typePower = (typePower * TYPE_EFFECT_MULTIPLIER(i)) / 10; } i += 3; } @@ -2777,10 +2777,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: @@ -2797,19 +2797,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; @@ -2827,8 +2827,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: @@ -4304,7 +4304,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; @@ -4837,7 +4837,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; @@ -5335,7 +5335,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; @@ -5516,7 +5516,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; diff --git a/src/battle_gfx_sfx_util.c b/src/battle_gfx_sfx_util.c index d044f2fbd..41cffec3d 100644 --- a/src/battle_gfx_sfx_util.c +++ b/src/battle_gfx_sfx_util.c @@ -956,7 +956,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); @@ -1013,12 +1013,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 bdde96be2..acc65008e 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -127,7 +127,6 @@ static void HandleEndTurn_RanFromBattle(void); static void HandleEndTurn_MonFled(void); static void HandleEndTurn_FinishBattle(void); - // EWRAM vars EWRAM_DATA u16 gBattle_BG0_X = 0; EWRAM_DATA u16 gBattle_BG0_Y = 0; @@ -633,16 +632,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); @@ -769,7 +771,8 @@ static void SetPlayerBerryDataInBattleStruct(void) static void SetAllPlayersBerryData(void) { - s32 i, j; + s32 i; + s32 j; if (!(gBattleTypeFlags & BATTLE_TYPE_LINK)) { @@ -2685,7 +2688,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; @@ -3416,13 +3420,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); @@ -3529,7 +3537,7 @@ static void BattleIntroPrintWildMonAttacked(void) static void BattleIntroPrintOpponentSendsOut(void) { - u8 position; + u32 position; if (gBattleControllerExecFlags) return; @@ -3552,7 +3560,7 @@ static void BattleIntroPrintOpponentSendsOut(void) static void BattleIntroOpponent2SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_OPPONENT_RIGHT; @@ -3580,7 +3588,7 @@ static void BattleIntroOpponent2SendsOutMonAnimation(void) static void BattleIntroOpponent1SendsOutMonAnimation(void) { - u8 position; + u32 position; if (gBattleTypeFlags & BATTLE_TYPE_RECORDED) { @@ -3595,9 +3603,7 @@ static void BattleIntroOpponent1SendsOutMonAnimation(void) position = B_POSITION_OPPONENT_LEFT; } else - { position = B_POSITION_OPPONENT_LEFT; - } if (gBattleControllerExecFlags) return; @@ -3639,7 +3645,7 @@ static void BattleIntroRecordMonsToDex(void) } } -static void sub_803B3AC(void) // unused +void sub_803B3AC(void) // unused { if (gBattleControllerExecFlags == 0) gBattleMainFunc = BattleIntroPrintPlayerSendsOut; @@ -3672,7 +3678,7 @@ static void BattleIntroPrintPlayerSendsOut(void) static void BattleIntroPlayer2SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_PLAYER_RIGHT; @@ -3704,7 +3710,7 @@ static void BattleIntroPlayer2SendsOutMonAnimation(void) static void BattleIntroPlayer1SendsOutMonAnimation(void) { - u8 position; + u32 position; if (!(gBattleTypeFlags & BATTLE_TYPE_RECORDED)) position = B_POSITION_PLAYER_LEFT; @@ -3742,7 +3748,7 @@ static void BattleIntroPlayer1SendsOutMonAnimation(void) gBattleMainFunc = TryDoEventsBeforeFirstTurn; } -static void sub_803B598(void) // unused +void sub_803B598(void) // unused { if (gBattleControllerExecFlags == 0) { @@ -3765,7 +3771,8 @@ static void sub_803B598(void) // unused static void TryDoEventsBeforeFirstTurn(void) { - s32 i, j; + s32 i; + s32 j; u8 effect = 0; if (gBattleControllerExecFlags) @@ -3955,7 +3962,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); @@ -4732,38 +4743,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); + } } } } @@ -4841,8 +4854,8 @@ 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; + gCurrentActionFuncId = gActionsByTurnOrder[gCurrentTurnActionNumber]; gDynamicBasePower = 0; gBattleStruct->dynamicMoveType = 0; gBattleMainFunc = RunTurnActionsFunctions; @@ -4865,10 +4878,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); + } } } @@ -4985,15 +5001,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; } } @@ -5077,7 +5093,10 @@ static void FreeResetData_ReturnToOvOrDoEvolutions(void) gBattleMainFunc = ReturnFromBattleToOverworld; return; } - gBattleMainFunc = TryEvolvePokemon; + else + { + gBattleMainFunc = TryEvolvePokemon; + } } FreeAllWindowBuffers(); @@ -5172,4 +5191,3 @@ void RunBattleScriptCommands(void) if (gBattleControllerExecFlags == 0) gBattleScriptingCommandsTable[gBattlescriptCurrInstr[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 203b572eb..1b220f145 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -522,19 +522,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_script_commands.c b/src/battle_script_commands.c index 3b77df294..d43ddd5a2 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3518,7 +3518,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++) @@ -3535,14 +3535,17 @@ static void Cmd_unknown_24(void) if (gBattleOutcome == 0 && (gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_x2000000))) { - s32 foundPlayer = 0, foundOpponent; + s32 foundPlayer = 0; + s32 foundOpponent; + for (i = 0; i < gBattlersCount; i += 2) { if ((gHitMarker & HITMARKER_FAINTED2(i)) && (!gSpecialStatuses[i].flag40)) foundPlayer++; } - + foundOpponent = 0; + for (i = 1; i < gBattlersCount; i += 2) { if ((gHitMarker & HITMARKER_FAINTED2(i)) && (!gSpecialStatuses[i].flag40)) @@ -3552,14 +3555,14 @@ static void Cmd_unknown_24(void) 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; } @@ -4660,10 +4663,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"); @@ -5536,8 +5537,8 @@ static void Cmd_hitanimation(void) static u32 GetTrainerMoneyToGive(u16 trainerId) { u32 i = 0; + u32 lastMonLevel = 0; u32 moneyReward; - u8 lastMonLevel = 0; if (trainerId == TRAINER_SECRET_BASE) { @@ -6037,7 +6038,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; @@ -7128,6 +7129,7 @@ static void Cmd_forcerandomswitch(void) s32 i; s32 battler1PartyId = 0; s32 battler2PartyId = 0; + s32 firstMonId; s32 lastMonId = 0; // + 1 s32 monsCount; @@ -7249,10 +7251,11 @@ static void Cmd_forcerandomswitch(void) { i = Random() % monsCount; i += firstMonId; - } while (i == battler2PartyId || i == battler1PartyId); + } + while (i == battler2PartyId || i == battler1PartyId); } while (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); //should be one while loop, but that doesn't match. } *(gBattleStruct->monToSwitchIntoId + gBattlerTarget) = i; diff --git a/src/battle_tower.c b/src/battle_tower.c index 046362105..b7d03a5bc 100644 --- a/src/battle_tower.c +++ b/src/battle_tower.c @@ -1446,7 +1446,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. + return GetFrontierBrainTrainerClass(); } else if (trainerId == TRAINER_STEVEN_PARTNER) { diff --git a/src/battle_transition.c b/src/battle_transition.c index 4a9d26303..496cc9e09 100644 --- a/src/battle_transition.c +++ b/src/battle_transition.c @@ -3973,7 +3973,7 @@ static bool8 Phase2_FrontierLogoWave_Func4(struct Task *task) for (i = 0; i < 160; i++, var6 += var8) { - const u16 index = var6 >> 8; + s16 index = var6 / 256; gScanlineEffectRegBuffers[0][i] = sTransitionStructPtr->field_16 + Sin(index & 0xff, amplitude); } diff --git a/src/battle_tv.c b/src/battle_tv.c index dea711609..7e311fdab 100644 --- a/src/battle_tv.c +++ b/src/battle_tv.c @@ -714,15 +714,16 @@ void BattleTv_SetDataBasedOnAnimation(u8 animationId) 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. + int zero = 0, one = 1; //needed for matching if (gBattleStruct->anyMonHasTransformed) return; diff --git a/src/battle_util.c b/src/battle_util.c index f98b088e0..7025f0e3f 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -1,19 +1,31 @@ #include "global.h" #include "battle.h" -#include "battle_util.h" #include "battle_anim.h" +#include "battle_arena.h" +#include "battle_pyramid.h" +#include "battle_util.h" #include "pokemon.h" +#include "international_string_util.h" #include "item.h" #include "util.h" #include "battle_scripts.h" #include "random.h" +#include "text.h" +#include "safari_zone.h" +#include "sound.h" +#include "sprite.h" #include "string_util.h" +#include "task.h" +#include "trig.h" +#include "window.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" @@ -21,16 +33,16 @@ #include "constants/hold_effects.h" #include "constants/items.h" #include "constants/moves.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" +#include "constants/species.h" +#include "constants/weather.h" + +/* +NOTE: The data and functions in this file up until (but not including) sSoundMovesTable +are actually part of battle_main.c. They needed to be moved to this file in order to +match the ROM; this is also why sSoundMovesTable's declaration is in the middle of +functions instead of at the top of the file with the other declarations. +*/ extern const u8 *const gBattleScriptsForMoveEffects[]; extern const u8 *const gBattlescriptsForBallThrow[]; @@ -282,9 +294,7 @@ 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 @@ -310,18 +320,18 @@ void HandleAction_UseItem(void) break; case AI_ITEM_CURE_CONDITION: gBattleCommunication[MULTISTRING_CHOOSER] = 0; - if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 1) + if (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1) { - if (*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 0x3E) + if (*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 0x3E) gBattleCommunication[MULTISTRING_CHOOSER] = 5; } else { - do + while (!(*(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) & 1)) { - *(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) >>= 1; + *(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) >>= 1; gBattleCommunication[MULTISTRING_CHOOSER]++; - } while (!(*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) & 1)); + } } break; case AI_ITEM_X_STAT: @@ -337,7 +347,7 @@ void HandleAction_UseItem(void) while (!((*(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1))) & 1)) { - *(gBattleStruct->AI_itemFlags + (gBattlerAttacker >> 1)) >>= 1; + *(gBattleStruct->AI_itemFlags + gBattlerAttacker / 2) >>= 1; gBattleTextBuff1[2]++; } @@ -353,7 +363,7 @@ void HandleAction_UseItem(void) break; } - gBattlescriptCurrInstr = gBattlescriptsForUsingItem[*(gBattleStruct->AI_itemType + (gBattlerAttacker >> 1))]; + gBattlescriptCurrInstr = gBattlescriptsForUsingItem[*(gBattleStruct->AI_itemType + gBattlerAttacker / 2)]; } gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; } 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..671d0ad2b 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); @@ -2401,7 +2390,7 @@ void sub_802339C(struct BerryCrushGame *r4) } } } - if (r8 >= 2) + if (r8 > 1) { for (r7 = 0; r7 < r4->unk9; ++r7) { @@ -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) { @@ -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/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 841224577..f775b01b4 100644 --- a/src/contest.c +++ b/src/contest.c @@ -950,39 +950,39 @@ const struct SpriteTemplate sSpriteTemplates_ContestantsTurnBlinkEffect[CONTESTA static const s8 gContestExcitementTable[CONTEST_CATEGORIES_COUNT][CONTEST_CATEGORIES_COUNT] = { - [CONTEST_CATEGORY_COOL] = { - [CONTEST_CATEGORY_COOL] = +1, - [CONTEST_CATEGORY_BEAUTY] = 0, - [CONTEST_CATEGORY_CUTE] = -1, - [CONTEST_CATEGORY_SMART] = -1, + [CONTEST_CATEGORY_COOL] = { + [CONTEST_CATEGORY_COOL] = +1, + [CONTEST_CATEGORY_BEAUTY] = 0, + [CONTEST_CATEGORY_CUTE] = -1, + [CONTEST_CATEGORY_SMART] = -1, [CONTEST_CATEGORY_TOUGH] = 0 }, - [CONTEST_CATEGORY_BEAUTY] = { - [CONTEST_CATEGORY_COOL] = 0, - [CONTEST_CATEGORY_BEAUTY] = +1, - [CONTEST_CATEGORY_CUTE] = 0, - [CONTEST_CATEGORY_SMART] = -1, + [CONTEST_CATEGORY_BEAUTY] = { + [CONTEST_CATEGORY_COOL] = 0, + [CONTEST_CATEGORY_BEAUTY] = +1, + [CONTEST_CATEGORY_CUTE] = 0, + [CONTEST_CATEGORY_SMART] = -1, [CONTEST_CATEGORY_TOUGH] = -1 }, [CONTEST_CATEGORY_CUTE] = { - [CONTEST_CATEGORY_COOL] = -1, - [CONTEST_CATEGORY_BEAUTY] = 0, - [CONTEST_CATEGORY_CUTE] = +1, - [CONTEST_CATEGORY_SMART] = 0, + [CONTEST_CATEGORY_COOL] = -1, + [CONTEST_CATEGORY_BEAUTY] = 0, + [CONTEST_CATEGORY_CUTE] = +1, + [CONTEST_CATEGORY_SMART] = 0, [CONTEST_CATEGORY_TOUGH] = -1 }, [CONTEST_CATEGORY_SMART] = { - [CONTEST_CATEGORY_COOL] = -1, - [CONTEST_CATEGORY_BEAUTY] = -1, - [CONTEST_CATEGORY_CUTE] = 0, - [CONTEST_CATEGORY_SMART] = +1, + [CONTEST_CATEGORY_COOL] = -1, + [CONTEST_CATEGORY_BEAUTY] = -1, + [CONTEST_CATEGORY_CUTE] = 0, + [CONTEST_CATEGORY_SMART] = +1, [CONTEST_CATEGORY_TOUGH] = 0 }, - [CONTEST_CATEGORY_TOUGH] = { - [CONTEST_CATEGORY_COOL] = 0, - [CONTEST_CATEGORY_BEAUTY] = -1, - [CONTEST_CATEGORY_CUTE] = -1, - [CONTEST_CATEGORY_SMART] = 0, + [CONTEST_CATEGORY_TOUGH] = { + [CONTEST_CATEGORY_COOL] = 0, + [CONTEST_CATEGORY_BEAUTY] = -1, + [CONTEST_CATEGORY_CUTE] = -1, + [CONTEST_CATEGORY_SMART] = 0, [CONTEST_CATEGORY_TOUGH] = +1 } }; @@ -3407,7 +3407,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++) @@ -3482,7 +3483,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) @@ -3536,7 +3538,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) @@ -4479,14 +4482,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) @@ -5009,7 +5015,7 @@ static void ShowHideNextTurnGfx(bool8 show) { if (eContestantStatus[i].turnOrderMod != 0 && show) { - CpuCopy32(GetTurnOrderNumberGfx(i), (void *)(VRAM + 0x10000 + (gSprites[eContestGfxState[i].nextTurnSpriteId].oam.tileNum + 6) * 32), 32); + CpuCopy32(GetTurnOrderNumberGfx(i), (void *)(OBJ_VRAM0 + (gSprites[eContestGfxState[i].nextTurnSpriteId].oam.tileNum + 6) * 32), 32); gSprites[eContestGfxState[i].nextTurnSpriteId].pos1.y = sNextTurnSpriteYPositions[gContestantTurnOrder[i]]; gSprites[eContestGfxState[i].nextTurnSpriteId].invisible = FALSE; } @@ -5410,7 +5416,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; @@ -5433,7 +5439,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; @@ -5457,7 +5463,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; @@ -6092,4 +6098,3 @@ void StripPlayerAndMonNamesForLinkContest(struct ContestPokemon *mon, s32 langua } } - diff --git a/src/contest_painting.c b/src/contest_painting.c index ceef8a902..8832b59e8 100644 --- a/src/contest_painting.c +++ b/src/contest_painting.c @@ -397,16 +397,16 @@ 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)]; + colorIndex = spriteGfx[32 * (tileY * 8 + tileX) + (pixelY << 2) + (pixelX >> 1)]; 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]; } } } @@ -501,7 +501,6 @@ static void LoadContestPaintingFrame(u8 contestWinnerId, bool8 arg1) static void InitPaintingMonOamData(u8 contestWinnerId) { - gMain.oamBuffer[0] = sContestPaintingMonOamData; gMain.oamBuffer[0].tileNum = 0; @@ -512,7 +511,7 @@ static void InitPaintingMonOamData(u8 contestWinnerId) } else { - gMain.oamBuffer[0].x = 88; // Duplicated Code + gMain.oamBuffer[0].x = 88; // Duplicated code gMain.oamBuffer[0].y = 24; } } diff --git a/src/contest_util.c b/src/contest_util.c index ae76eda6b..21408c673 100644 --- a/src/contest_util.c +++ b/src/contest_util.c @@ -1151,12 +1151,12 @@ static void TryCreateWirelessSprites(void) static s32 DrawResultsTextWindow(const u8 *text, u8 spriteId) { u16 windowId; - s32 origWidth, strWidth; + int origWidth; + int strWidth; u8 *spriteTilePtrs[4]; u8 *dst; - { - struct WindowTemplate windowTemplate; //It's important the lifetime of this struct ends after the clear + struct WindowTemplate windowTemplate; memset(&windowTemplate, 0, sizeof(windowTemplate)); windowTemplate.width = 30; windowTemplate.height = 2; @@ -1165,33 +1165,33 @@ static s32 DrawResultsTextWindow(const u8 *text, u8 spriteId) } 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); - { s32 i; struct Sprite *sprite; const u8 *src, *windowTilesPtr; - windowTilesPtr = (const u8 *)(GetWindowAttribute(windowId, WINDOW_TILE_DATA)); - src = sUnknown_0858D6D0; + windowTilesPtr = (u8 *)(GetWindowAttribute(windowId, WINDOW_TILE_DATA)); + src = (u8 *)(sUnknown_0858D6D0); sprite = &gSprites[spriteId]; - spriteTilePtrs[0] = (u8 *)((OBJ_VRAM0) + sprite->oam.tileNum * 32); + spriteTilePtrs[0] = (u8 *)(sprite->oam.tileNum * 32 + OBJ_VRAM0); for (i = 1; i < 4; i++) - spriteTilePtrs[i] = (u8 *)((OBJ_VRAM0) + gSprites[sprite->data[i - 1]].oam.tileNum * 32); - + spriteTilePtrs[i] = (void*)(gSprites[sprite->data[i - 1]].oam.tileNum * 32 + OBJ_VRAM0); + 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); - + CpuCopy32(src + 64, dst + 0x300, 0x20); + for (i = 0; i < strWidth; i++) { dst = &spriteTilePtrs[(i + 1) / 8][((i + 1) % 8) * 32]; @@ -1203,10 +1203,10 @@ static s32 DrawResultsTextWindow(const u8 *text, u8 spriteId) } dst = &spriteTilePtrs[(i + 1) / 8][((i + 1) % 8) * 32]; - CpuCopy32(src + 32, dst, 0x20); + 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 + 96, dst + 0x300, 0x20); } RemoveWindow(windowId); @@ -1922,7 +1922,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/daycare.c b/src/daycare.c index 31014bf7f..a438c8e85 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -1185,7 +1185,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; diff --git a/src/decoration.c b/src/decoration.c index 8a3f86dfd..74dbacdf9 100644 --- a/src/decoration.c +++ b/src/decoration.c @@ -1827,7 +1827,7 @@ static void Task_SelectLocation(u8 taskId) sPlacePutAwayYesNoFunctions[tDecorationItemsMenuCommand].yesFunc(taskId); return; } - + if (tButton == B_BUTTON) { sPlacePutAwayYesNoFunctions[tDecorationItemsMenuCommand].noFunc(taskId); diff --git a/src/dewford_trend.c b/src/dewford_trend.c index e0063ec1b..5c7e50f16 100644 --- a/src/dewford_trend.c +++ b/src/dewford_trend.c @@ -219,11 +219,10 @@ 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 > 1) @@ -234,7 +233,7 @@ void TrendyPhraseIsOld(void) break; result = 1; } while (0); - + gSpecialVar_Result = result; } @@ -249,46 +248,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/easy_chat.c b/src/easy_chat.c index 2e58dec0d..2590eea1a 100644 --- a/src/easy_chat.c +++ b/src/easy_chat.c @@ -1613,26 +1613,26 @@ static u16 sub_811ACDC(void) { return sub_811B150(); } - if (JOY_NEW(START_BUTTON)) + else if (JOY_NEW(START_BUTTON)) { return sub_811B1B4(); } - if (JOY_NEW(DPAD_UP)) + else if (JOY_NEW(DPAD_UP)) { sEasyChatScreen->mainCursorRow--; break; } - if (JOY_NEW(DPAD_LEFT)) + else if (JOY_NEW(DPAD_LEFT)) { sEasyChatScreen->mainCursorColumn--; break; } - if (JOY_NEW(DPAD_DOWN)) + else if (JOY_NEW(DPAD_DOWN)) { sEasyChatScreen->mainCursorRow = 0; break; } - if (JOY_NEW(DPAD_RIGHT)) + else if (JOY_NEW(DPAD_RIGHT)) { sEasyChatScreen->mainCursorColumn++; break; @@ -2536,7 +2536,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; @@ -4528,18 +4528,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/event_object_movement.c b/src/event_object_movement.c index 68f873446..6d89adea6 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1235,7 +1235,7 @@ 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->mapNum = mapNum; objectEvent->trainerRange_berryTreeId = template->trainerRange_berryTreeId; objectEvent->previousMovementDirection = gInitialMovementTypeFacingDirections[template->movementType]; SetObjectEventDirection(objectEvent, objectEvent->previousMovementDirection); @@ -8216,13 +8216,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 +8397,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 +8478,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 }; @@ -8564,9 +8566,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 +8585,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 +8765,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,7 +8841,7 @@ u8 (*const gMovementActionFuncs_FlyDown[])(struct ObjectEvent *, struct Sprite * u8 MovementAction_StoreAndLockAnim_Step0(struct ObjectEvent *objectEvent, struct Sprite *sprite) { - bool8 ableToStore = FALSE; + bool32 ableToStore = FALSE; if (gLockedAnimObjectEvents == NULL) { gLockedAnimObjectEvents = AllocZeroed(sizeof(struct LockedAnimObjectEvents)); @@ -8845,8 +8851,9 @@ u8 MovementAction_StoreAndLockAnim_Step0(struct ObjectEvent *objectEvent, struct } 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 +8886,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 +8930,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 +8941,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 +8958,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/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/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..1b8030149 100644 --- a/src/frontier_pass.c +++ b/src/frontier_pass.c @@ -1195,7 +1195,7 @@ static void sub_80C6104(u8 cursorArea, u8 previousCursorArea) return; break; } - + switch (cursorArea) { case CURSOR_AREA_MAP: @@ -1209,7 +1209,7 @@ static void sub_80C6104(u8 cursorArea, u8 previousCursorArea) CopyToBgTilemapBufferRect_ChangePalette(1, sPassGfx->unk28 + 72, 2, 10, 12, 3, 17); else return; - break; // needed + break; //needed to match case CURSOR_AREA_CANCEL: CopyToBgTilemapBufferRect_ChangePalette(1, gUnknown_08DE3374, 21, 0, 9, 2, 17); break; diff --git a/src/frontier_util.c b/src/frontier_util.c index d0dfa61f3..83c9341d5 100644 --- a/src/frontier_util.c +++ b/src/frontier_util.c @@ -2507,11 +2507,12 @@ void CreateFrontierBrainPokemon(void) { if (!(selectedMonBits & 1)) continue; + do { do { - j = Random32(); //Should be one while loop, but that doesn't match + j = Random32(); //should just be one while loop, but that doesn't match } while (IsShinyOtIdPersonality(FRONTIER_BRAIN_OTID, j)); } while (sFrontierBrainsMons[facility][symbol][i].nature != GetNatureFromPersonality(j)); CreateMon(&gEnemyParty[monPartyId], diff --git a/src/item.c b/src/item.c index 290e7177c..0b6366048 100644 --- a/src/item.c +++ b/src/item.c @@ -183,13 +183,15 @@ bool8 HasAtLeastOneBerry(void) bool8 CheckBagHasSpace(u16 itemId, u16 count) { - u8 i, pocket; - u16 slotCapacity, ownedCount; + u8 i; + u8 pocket; + u16 slotCapacity; + u16 ownedCount; 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); } @@ -212,12 +214,12 @@ bool8 CheckBagHasSpace(u16 itemId, u16 count) 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 + break; //should be return TRUE, but that doesn't match } } // Check space in empty item slots - if (count > 0) //if (count !=0) also works here; both match + if (count > 0) { for (i = 0; i < gBagPockets[pocket].capacity; i++) { @@ -231,12 +233,12 @@ bool8 CheckBagHasSpace(u16 itemId, u16 count) } 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 + count = 0; //should be return TRUE, but that doesn't match break; } } } - if (count > 0) //if (count !=0) also works here; both match + if (count > 0) return FALSE; // No more item slots. The bag is full } diff --git a/src/item_menu.c b/src/item_menu.c index c764f4e81..80035b945 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) @@ -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 ((JOY_NEW(DPAD_LEFT)) || LRKeys == MENU_L_PRESSED) { PlaySE(SE_SELECT); return SWITCH_POCKET_LEFT; } - if (JOY_NEW(DPAD_RIGHT) || LRKeys == MENU_R_PRESSED) + if ((JOY_NEW(DPAD_RIGHT)) || LRKeys == MENU_R_PRESSED) { PlaySE(SE_SELECT); return SWITCH_POCKET_RIGHT; @@ -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 ((JOY_NEW(DPAD_RIGHT)) || GetLRKeysPressed() == MENU_R_PRESSED) { if (!(cursorPos & 1) && sub_81ACDFC(cursorPos + 1)) { diff --git a/src/item_use.c b/src/item_use.c index f9d1ff824..9ab755a5e 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); diff --git a/src/link_rfu_2.c b/src/link_rfu_2.c index 3db24aaec..5e0ef0aa4 100644 --- a/src/link_rfu_2.c +++ b/src/link_rfu_2.c @@ -875,7 +875,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; @@ -932,14 +933,13 @@ static void HandleSendFailure(u8 unused, u32 flags) 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 + temp + 1] << 8) | r10[12 * i + temp + 0]; } - for (j = 0; j < 7; j++) { temp = j << 1; sResendBlock8[temp + 1] = sResendBlock16[j] >> 8; - sResendBlock8[temp + 0] = sResendBlock16[j] & 0xff; + sResendBlock8[temp + 0] = sResendBlock16[j]; } RfuSendQueue_Enqueue(&Rfu.sendQueue, sResendBlock8); Rfu.sendBlock.failedFlags |= (1 << i); @@ -1023,7 +1023,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++) { @@ -1037,7 +1038,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: @@ -1236,9 +1237,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++; @@ -1416,12 +1418,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++) @@ -1451,7 +1457,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) { @@ -1547,27 +1554,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; @@ -2043,7 +2050,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; } } @@ -2088,7 +2096,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..c6344f503 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++) { @@ -623,32 +626,30 @@ static void ASCIIToPkmnStr(u8 *pkmnStr, const u8 *asciiStr) 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 + break; } 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; @@ -922,7 +923,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..3e5642e4c 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) { @@ -439,12 +439,14 @@ s32 ListMenu_ProcessInput(u8 listTaskId) rightButton = FALSE; break; case LIST_MULTIPLE_SCROLL_DPAD: - leftButton = JOY_REPEAT(DPAD_LEFT); - rightButton = JOY_REPEAT(DPAD_RIGHT); + // note: JOY_REPEAT won't match here + 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); + // same as above + leftButton = gMain.newAndRepeatedKeys & L_BUTTON; + rightButton = gMain.newAndRepeatedKeys & R_BUTTON; break; } @@ -1257,17 +1259,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 +1299,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 2280fc74c..f061ba9b9 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,18 +614,25 @@ 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) @@ -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; @@ -663,7 +691,10 @@ void FadeOutBody(struct MusicPlayerInfo *mplayInfo) { if ((s16)(mplayInfo->fadeOV -= (4 << FADE_VOL_SHIFT)) <= 0) { - for (i = mplayInfo->trackCount, track = mplayInfo->tracks; i > 0; i--, track++) + i = mplayInfo->trackCount; + track = mplayInfo->tracks; + + while (i > 0) { u32 val; @@ -675,6 +706,9 @@ void FadeOutBody(struct MusicPlayerInfo *mplayInfo) if (!val) track->flags = 0; + + i--; + track++; } if (mplayInfo->fadeOV & TEMPORARY_FADE) @@ -687,7 +721,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) { @@ -696,6 +733,9 @@ void FadeOutBody(struct MusicPlayerInfo *mplayInfo) track->volX = (fadeOV >> FADE_VOL_SHIFT); track->flags |= MPT_FLG_VOLCHG; } + + i--; + track++; } } @@ -703,7 +743,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/main.c b/src/main.c index b3b76b1fb..ab0c23284 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; @@ -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/match_call.c b/src/match_call.c index 944d85b8f..a39739f76 100644 --- a/src/match_call.c +++ b/src/match_call.c @@ -1334,7 +1334,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; @@ -1773,7 +1773,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 457fc2bf2..dca8adc2d 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; @@ -1049,13 +1049,13 @@ s8 ProcessMenuInput_other(void) { return MENU_B_PRESSED; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_UP) + else if ((JOY_REPEAT(DPAD_ANY)) == DPAD_UP) { PlaySE(SE_SELECT); Menu_MoveCursor(-1); return MENU_NOTHING_CHOSEN; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_DOWN) + else if ((JOY_REPEAT(DPAD_ANY)) == DPAD_DOWN) { PlaySE(SE_SELECT); Menu_MoveCursor(1); @@ -1075,17 +1075,17 @@ s8 Menu_ProcessInputNoWrapAround_other(void) PlaySE(SE_SELECT); return sMenu.cursorPos; } - if (JOY_NEW(B_BUTTON)) + else if (JOY_NEW(B_BUTTON)) { return MENU_B_PRESSED; } - if (JOY_REPEAT(DPAD_ANY) == DPAD_UP) + else if (JOY_REPEAT(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 (JOY_REPEAT(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); @@ -1496,25 +1496,25 @@ s8 sub_81993D8(void) { return MENU_B_PRESSED; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_UP) + else if ((JOY_REPEAT(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 ((JOY_REPEAT(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 ((JOY_REPEAT(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 ((JOY_REPEAT(DPAD_ANY)) == DPAD_RIGHT || GetLRKeysPressedAndHeld() == MENU_R_PRESSED) { PlaySE(SE_SELECT); ChangeListMenuCursorPosition(MENU_CURSOR_DELTA_RIGHT, MENU_CURSOR_DELTA_NONE); @@ -1538,25 +1538,25 @@ s8 sub_8199484(void) { return MENU_B_PRESSED; } - else if (JOY_REPEAT(DPAD_ANY) == DPAD_UP) + else if ((JOY_REPEAT(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 ((JOY_REPEAT(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 ((JOY_REPEAT(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 ((JOY_REPEAT(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..b31d84a1e 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 ((JOY_REPEAT(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 ((JOY_REPEAT(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 ((JOY_REPEAT(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 ((JOY_REPEAT(DPAD_ANY)) == DPAD_LEFT) { (*arg0) -= 10; if ((*arg0) <= 0) diff --git a/src/menu_specialized.c b/src/menu_specialized.c index 0745ac6d5..1d317a1aa 100644 --- a/src/menu_specialized.c +++ b/src/menu_specialized.c @@ -249,7 +249,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]; } @@ -893,73 +893,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..ef7bf7228 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); @@ -725,8 +726,8 @@ static void sub_81BF248(struct Sprite *sprite) static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e) { + u8 r5, r4, r0, r2; u16 var, var2; - u8 r0, r5, r4, r2; u8 r2_1, r4_1; u8 b2, c2; @@ -738,25 +739,23 @@ static void sub_81BF2B8(u8* a, u16 b, u8 c, u8 d, u8 e) r4_1 = r4 & 7; r2_1 = r2 & 7; - - 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 - + gUnknown_030012A8[2] = r4 & 7; //should be using r4_1, but that doesn't match + gUnknown_030012A8[3] = r2 & 7; //" + 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 + + gUnknown_030012A8[4] = r2 / 8; //should be using r0, but that doesn't match + gUnknown_030012A8[5] = r4 / 8; //should be using r5, but that doesn't match 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. - + gUnknown_030012A8[7] = var + ((r4_1 * 8) + r2_1); //should be using var2 with var2 being divided afterwards, but that doesn't match + b2 = ((b % 2) ^ 1); - c2 = (c << (b2 << 2)) | (15 << (((b2 ^ 1) << 2))); + c2 = (c << (b2 << 2)) | 15 << (((b2 ^ 1) << 2)); a[var2 + (e * 32)] &= c2; } diff --git a/src/party_menu.c b/src/party_menu.c index 862302229..da0783d23 100755 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -1861,7 +1861,7 @@ u8 GetMonAilment(struct Pokemon *mon) static void SetPartyMonsAllowedInMinigame(void) { - s16 *ptr; + u16 *ptr; if (gPartyMenu.menuType == PARTY_MENU_TYPE_MINIGAME) { @@ -4953,9 +4953,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); @@ -4963,7 +4963,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); diff --git a/src/player_pc.c b/src/player_pc.c index 238424ee3..928aac706 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); @@ -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); diff --git a/src/pokeblock.c b/src/pokeblock.c index b44112b88..0bfb10632 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; diff --git a/src/pokedex.c b/src/pokedex.c index 803b6019c..516cef6a7 100644 --- a/src/pokedex.c +++ b/src/pokedex.c @@ -171,16 +171,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]; @@ -2597,7 +2597,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 ((JOY_HELD(DPAD_DOWN)) && (selectedMon < sPokedexView->pokemonListCount - 1)) { scrollDir = 2; selectedMon = GetNextPosition(0, selectedMon, 0, sPokedexView->pokemonListCount - 1); @@ -2605,7 +2605,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 ((JOY_NEW(DPAD_LEFT)) && (selectedMon > 0)) { startingPos = selectedMon; @@ -3399,8 +3399,8 @@ static void Task_HandleInfoScreenInput(u8 taskId) } return; } - if ((JOY_NEW(DPAD_LEFT) - || (JOY_NEW(L_BUTTON) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) + if (((JOY_NEW(DPAD_LEFT)) + || ((JOY_NEW(L_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) && sPokedexView->selectedScreen > 0) { sPokedexView->selectedScreen--; @@ -3408,8 +3408,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 (((JOY_NEW(DPAD_RIGHT)) + || ((JOY_NEW(R_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) && sPokedexView->selectedScreen < CANCEL_SCREEN) { sPokedexView->selectedScreen++; @@ -3656,8 +3656,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 ((JOY_NEW(DPAD_RIGHT)) + || ((JOY_NEW(R_BUTTON)) && gSaveBlock2Ptr->optionsButtonMode == OPTIONS_BUTTON_MODE_LR)) { if (!sPokedexListItem->owned) { @@ -4167,13 +4167,12 @@ static void PrintMonHeight(u16 height, u8 left, u8 top) static void PrintMonWeight(u16 weight, u8 left, u8 top) { u8 buffer[16]; - u8 i; bool8 output; + u8 i; u32 lbs = (weight * 100000) / 4536; if (lbs % 10u >= 5) lbs += 10; - i = 0; output = FALSE; @@ -4228,19 +4227,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; @@ -5029,7 +5022,7 @@ static void Task_HandleSearchMenuInput(u8 taskId) CopyWindowToVram(0, 2); CopyBgTilemapBufferToVram(3); } - if (JOY_NEW(DPAD_RIGHT) && movementMap[gTasks[taskId].tMenuItem][1] != 0xFF) + if ((JOY_NEW(DPAD_RIGHT)) && movementMap[gTasks[taskId].tMenuItem][1] != 0xFF) { PlaySE(SE_SELECT); gTasks[taskId].tMenuItem = movementMap[gTasks[taskId].tMenuItem][1]; @@ -5115,9 +5108,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); @@ -5236,8 +5229,9 @@ static void Task_ExitSearchWaitForFade(u8 taskId) 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 temp; //should be a pointer, but does not match as one + u32 ptr = (u32)GetBgTilemapBuffer(3); //same as above for (i = 0; i < width; i++) { @@ -5245,7 +5239,7 @@ void SetSearchRectHighlight(u8 flags, u8 x, u8 y, u8 width) temp &= 0x0fff; temp |= (flags << 12); *(u16 *)(ptr + (y + 0) * 64 + (x + i) * 2) = temp; - + temp = *(u16 *)(ptr + (y + 1) * 64 + (x + i) * 2); temp &= 0x0fff; temp |= (flags << 12); @@ -5451,8 +5445,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(); @@ -5541,7 +5535,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) @@ -5552,7 +5547,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/pokemon.c b/src/pokemon.c index 8767207d7..3621284d6 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -69,7 +69,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" @@ -5750,7 +5750,7 @@ u8 GetTrainerEncounterMusicId(u16 trainerOpponentId) u16 ModifyStatByNature(u8 nature, u16 n, u8 statIndex) { u16 retVal; - // Dont modify HP, Accuracy, or Evasion by nature + // Don't modify HP, Accuracy, or Evasion by nature if (statIndex <= STAT_HP || statIndex > NUM_NATURE_STATS) { return n; @@ -6811,8 +6811,6 @@ static bool8 ShouldSkipFriendshipChange(void) return FALSE; } -#define MAGIC_NUMBER 0xA3 - static void sub_806F160(struct Unknown_806F160_Struct* structPtr) { u16 i, j; @@ -6861,7 +6859,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: @@ -6869,12 +6867,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) { @@ -6883,7 +6881,7 @@ 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)); + structPtr->byteArrays[i] = structPtr->bytes + (structPtr->field_3_0 * (i << 0xD)); } structPtr->templates = AllocZeroed(sizeof(struct SpriteTemplate) * structPtr->field_0_0); @@ -6902,8 +6900,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; @@ -6932,7 +6930,7 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1) } else { - structPtr->magic = MAGIC_NUMBER; + structPtr->magic = 0xA3; gUnknown_020249B4[id] = structPtr; } @@ -6943,12 +6941,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)); } @@ -6972,13 +6970,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 >= 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 f69bccb99..bfcf77b5c 100644 --- a/src/pokemon_animation.c +++ b/src/pokemon_animation.c @@ -2883,10 +2883,9 @@ static void sub_8181C2C(struct Sprite *sprite) } else { + s32 var = sUnknown_03001240[sprite->data[0]].field_8; - 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 * ((counter % 128) * 8) / 128 + 8 * -var; sprite->pos2.y = -(Sin(counter % 128, 8)); } diff --git a/src/pokemon_jump.c b/src/pokemon_jump.c index b6c557cab..914752eb4 100755 --- a/src/pokemon_jump.c +++ b/src/pokemon_jump.c @@ -405,7 +405,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(); diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index 4db9fbf92..6efca2562 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -2156,7 +2156,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); @@ -2176,7 +2176,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); @@ -7440,7 +7440,7 @@ static u8 HandleInput_OnButtons(void) sPSSData->field_CD7 = 1; break; } - + if (JOY_REPEAT(DPAD_DOWN | START_BUTTON)) { retVal = 1; diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c index 012e133e6..ad037a5f5 100644 --- a/src/pokemon_summary_screen.c +++ b/src/pokemon_summary_screen.c @@ -1504,11 +1504,11 @@ static void Task_HandleInput(u8 taskId) { ChangeSummaryPokemon(taskId, 1); } - else if (JOY_NEW(DPAD_LEFT) || GetLRKeysPressed() == MENU_L_PRESSED) + else if ((JOY_NEW(DPAD_LEFT)) || GetLRKeysPressed() == MENU_L_PRESSED) { ChangePage(taskId, -1); } - else if (JOY_NEW(DPAD_RIGHT) || GetLRKeysPressed() == MENU_R_PRESSED) + else if ((JOY_NEW(DPAD_RIGHT)) || GetLRKeysPressed() == MENU_R_PRESSED) { ChangePage(taskId, 1); } diff --git a/src/pokenav.c b/src/pokenav.c index 9f9cf7dee..eac0c85b4 100644 --- a/src/pokenav.c +++ b/src/pokenav.c @@ -315,7 +315,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); @@ -343,7 +343,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_3.c b/src/pokenav_conditions_3.c index 196484df7..d02d844d0 100644 --- a/src/pokenav_conditions_3.c +++ b/src/pokenav_conditions_3.c @@ -184,26 +184,27 @@ static u32 HandleConditionSearchInput(struct PokenavSub7 *structPtr) { if (JOY_REPEAT(DPAD_UP)) return CONDITION_SEARCH_FUNC_MOVE_UP; - if (JOY_REPEAT(DPAD_DOWN)) + else if (JOY_REPEAT(DPAD_DOWN)) return CONDITION_SEARCH_FUNC_MOVE_DOWN; - if (JOY_NEW(DPAD_LEFT)) + else if (JOY_NEW(DPAD_LEFT)) return CONDITION_SEARCH_FUNC_PAGE_UP; - if (JOY_NEW(DPAD_RIGHT)) + else if (JOY_NEW(DPAD_RIGHT)) return CONDITION_SEARCH_FUNC_PAGE_DOWN; - if (JOY_NEW(B_BUTTON)) + else if (JOY_NEW(B_BUTTON)) { structPtr->isPartyCondition = 0; structPtr->callback = ReturnToConditionSearchList; return CONDITION_SEARCH_FUNC_EXIT; } - if (JOY_NEW(A_BUTTON)) + else if (JOY_NEW(A_BUTTON)) { structPtr->monList->currIndex = GetSelectedPokenavListIndex(); structPtr->isPartyCondition = 1; structPtr->callback = OpenConditionGraphFromSearchList; return CONDITION_SEARCH_FUNC_SELECT_MON; } - return CONDITION_SEARCH_FUNC_NONE; + else + return CONDITION_SEARCH_FUNC_NONE; } static u32 ReturnToConditionSearchList(struct PokenavSub7 *structPtr) diff --git a/src/pokenav_main_menu.c b/src/pokenav_main_menu.c index 806300539..009cf783f 100644 --- a/src/pokenav_main_menu.c +++ b/src/pokenav_main_menu.c @@ -438,7 +438,6 @@ static u32 LoopedTask_SlideMenuHeaderDown(s32 a0) ChangeBgY(0, 0, 0); return LT_FINISH; } - return LT_PAUSE; } @@ -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); + } } } diff --git a/src/pokenav_menu_handler_1.c b/src/pokenav_menu_handler_1.c index c8820ac38..4792756c1 100644 --- a/src/pokenav_menu_handler_1.c +++ b/src/pokenav_menu_handler_1.c @@ -32,53 +32,53 @@ static u32 (*GetMainMenuInputHandler(void))(struct Pokenav1Struct*); static void SetMenuInputHandler(struct Pokenav1Struct *state); // Number of entries - 1 for that menu type -static const u8 sLastCursorPositions[] = +static const u8 sLastCursorPositions[] = { - [POKENAV_MENU_TYPE_DEFAULT] = 2, - [POKENAV_MENU_TYPE_UNLOCK_MC] = 3, - [POKENAV_MENU_TYPE_UNLOCK_MC_RIBBONS] = 4, - [POKENAV_MENU_TYPE_CONDITION] = 2, + [POKENAV_MENU_TYPE_DEFAULT] = 2, + [POKENAV_MENU_TYPE_UNLOCK_MC] = 3, + [POKENAV_MENU_TYPE_UNLOCK_MC_RIBBONS] = 4, + [POKENAV_MENU_TYPE_CONDITION] = 2, [POKENAV_MENU_TYPE_CONDITION_SEARCH] = 5 }; static const u8 sMenuItems[][6] = { - [POKENAV_MENU_TYPE_DEFAULT] = - { - POKENAV_MENUITEM_MAP, - POKENAV_MENUITEM_CONDITION, + [POKENAV_MENU_TYPE_DEFAULT] = + { + POKENAV_MENUITEM_MAP, + POKENAV_MENUITEM_CONDITION, [2 ... 5] = POKENAV_MENUITEM_SWITCH_OFF }, - [POKENAV_MENU_TYPE_UNLOCK_MC] = - { - POKENAV_MENUITEM_MAP, - POKENAV_MENUITEM_CONDITION, - POKENAV_MENUITEM_MATCH_CALL, + [POKENAV_MENU_TYPE_UNLOCK_MC] = + { + POKENAV_MENUITEM_MAP, + POKENAV_MENUITEM_CONDITION, + POKENAV_MENUITEM_MATCH_CALL, [3 ... 5] = POKENAV_MENUITEM_SWITCH_OFF }, - [POKENAV_MENU_TYPE_UNLOCK_MC_RIBBONS] = - { - POKENAV_MENUITEM_MAP, - POKENAV_MENUITEM_CONDITION, - POKENAV_MENUITEM_MATCH_CALL, - POKENAV_MENUITEM_RIBBONS, + [POKENAV_MENU_TYPE_UNLOCK_MC_RIBBONS] = + { + POKENAV_MENUITEM_MAP, + POKENAV_MENUITEM_CONDITION, + POKENAV_MENUITEM_MATCH_CALL, + POKENAV_MENUITEM_RIBBONS, [4 ... 5] = POKENAV_MENUITEM_SWITCH_OFF }, - [POKENAV_MENU_TYPE_CONDITION] = - { - POKENAV_MENUITEM_CONDITION_PARTY, - POKENAV_MENUITEM_CONDITION_SEARCH, - POKENAV_MENUITEM_CONDITION_CANCEL, + [POKENAV_MENU_TYPE_CONDITION] = + { + POKENAV_MENUITEM_CONDITION_PARTY, + POKENAV_MENUITEM_CONDITION_SEARCH, + POKENAV_MENUITEM_CONDITION_CANCEL, [3 ... 5] = POKENAV_MENUITEM_SWITCH_OFF }, - [POKENAV_MENU_TYPE_CONDITION_SEARCH] = - { - POKENAV_MENUITEM_CONDITION_SEARCH_COOL, - POKENAV_MENUITEM_CONDITION_SEARCH_BEAUTY, - POKENAV_MENUITEM_CONDITION_SEARCH_CUTE, - POKENAV_MENUITEM_CONDITION_SEARCH_SMART, - POKENAV_MENUITEM_CONDITION_SEARCH_TOUGH, - POKENAV_MENUITEM_CONDITION_SEARCH_CANCEL + [POKENAV_MENU_TYPE_CONDITION_SEARCH] = + { + POKENAV_MENUITEM_CONDITION_SEARCH_COOL, + POKENAV_MENUITEM_CONDITION_SEARCH_BEAUTY, + POKENAV_MENUITEM_CONDITION_SEARCH_CUTE, + POKENAV_MENUITEM_CONDITION_SEARCH_SMART, + POKENAV_MENUITEM_CONDITION_SEARCH_TOUGH, + POKENAV_MENUITEM_CONDITION_SEARCH_CANCEL }, }; @@ -87,13 +87,13 @@ static u8 GetPokenavMainMenuType(void) u8 menuType = POKENAV_MENU_TYPE_DEFAULT; if (FlagGet(FLAG_ADDED_MATCH_CALL_TO_POKENAV)) - { + { menuType = POKENAV_MENU_TYPE_UNLOCK_MC; if (FlagGet(FLAG_SYS_RIBBON_GET)) menuType = POKENAV_MENU_TYPE_UNLOCK_MC_RIBBONS; } - + return menuType; } @@ -102,7 +102,7 @@ bool32 PokenavCallback_Init_MainMenuCursorOnMap(void) struct Pokenav1Struct *state = AllocSubstruct(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER, sizeof(struct Pokenav1Struct)); if (!state) return FALSE; - + state->menuType = GetPokenavMainMenuType(); state->cursorPos = POKENAV_MENUITEM_MAP; state->currMenuItem = POKENAV_MENUITEM_MAP; @@ -116,7 +116,7 @@ bool32 PokenavCallback_Init_MainMenuCursorOnMatchCall(void) struct Pokenav1Struct *state = AllocSubstruct(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER, sizeof(struct Pokenav1Struct)); if (!state) return FALSE; - + state->menuType = GetPokenavMainMenuType(); state->cursorPos = POKENAV_MENUITEM_MATCH_CALL; state->currMenuItem = POKENAV_MENUITEM_MATCH_CALL; @@ -130,7 +130,7 @@ bool32 PokenavCallback_Init_MainMenuCursorOnRibbons(void) struct Pokenav1Struct *state = AllocSubstruct(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER, sizeof(struct Pokenav1Struct)); if (!state) return FALSE; - + state->menuType = GetPokenavMainMenuType(); state->cursorPos = POKENAV_MENUITEM_RIBBONS; state->currMenuItem = POKENAV_MENUITEM_RIBBONS; @@ -143,7 +143,7 @@ bool32 PokenavCallback_Init_ConditionMenu(void) struct Pokenav1Struct *state = AllocSubstruct(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER, sizeof(struct Pokenav1Struct)); if (!state) return FALSE; - + state->menuType = POKENAV_MENU_TYPE_CONDITION; state->cursorPos = 0; //party state->currMenuItem = POKENAV_MENUITEM_CONDITION_PARTY; @@ -157,7 +157,7 @@ bool32 PokenavCallback_Init_ConditionSearchMenu(void) struct Pokenav1Struct *state = AllocSubstruct(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER, sizeof(struct Pokenav1Struct)); if (!state) return FALSE; - + state->menuType = POKENAV_MENU_TYPE_CONDITION_SEARCH; state->cursorPos = GetSelectedConditionSearch(); state->currMenuItem = state->cursorPos + POKENAV_MENUITEM_CONDITION_SEARCH_COOL; @@ -250,7 +250,7 @@ static u32 HandleMainMenuInput(struct Pokenav1Struct *state) return POKENAV_MENU_FUNC_EXIT; } } - + if (JOY_NEW(B_BUTTON)) return POKENAV_MENU_FUNC_EXIT; @@ -262,7 +262,7 @@ static u32 HandleMainMenuInputTutorial(struct Pokenav1Struct *state) { if (UpdateMenuCursorPos(state)) return POKENAV_MENU_FUNC_MOVE_CURSOR; - + if (JOY_NEW(A_BUTTON)) { if (sMenuItems[state->menuType][state->cursorPos] == POKENAV_MENUITEM_MATCH_CALL) @@ -277,13 +277,13 @@ static u32 HandleMainMenuInputTutorial(struct Pokenav1Struct *state) return POKENAV_MENU_FUNC_NONE; } } - + if (JOY_NEW(B_BUTTON)) { PlaySE(SE_FAILURE); return POKENAV_MENU_FUNC_NONE; } - + return POKENAV_MENU_FUNC_NONE; } @@ -292,7 +292,7 @@ static u32 HandleMainMenuInputEndTutorial(struct Pokenav1Struct *state) { if (UpdateMenuCursorPos(state)) return POKENAV_MENU_FUNC_MOVE_CURSOR; - + if (JOY_NEW(A_BUTTON)) { u32 menuItem = sMenuItems[state->menuType][state->cursorPos]; @@ -342,7 +342,7 @@ static u32 HandleConditionMenuInput(struct Pokenav1Struct *state) { if (UpdateMenuCursorPos(state)) return POKENAV_MENU_FUNC_MOVE_CURSOR; - + if (JOY_NEW(A_BUTTON)) { switch (sMenuItems[state->menuType][state->cursorPos]) @@ -386,7 +386,7 @@ static u32 HandleConditionSearchMenuInput(struct Pokenav1Struct *state) { if (UpdateMenuCursorPos(state)) return POKENAV_MENU_FUNC_MOVE_CURSOR; - + if (JOY_NEW(A_BUTTON)) { u8 menuItem = sMenuItems[state->menuType][state->cursorPos]; diff --git a/src/record_mixing.c b/src/record_mixing.c index 344c535a4..898459c0a 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -712,18 +712,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) @@ -865,22 +864,22 @@ 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) || (var1 && var2)) { sp24[j][1] = Random2() % 2; } - else if (mail1 && !mail2) + else if (var1 && !var2) { sp24[j][1] = 0; } - else if (!mail1 && mail2) + else if (!var1 && var2) { - sp24[j][1] = 1; + sp24[j][1] = 1; } j++; } @@ -896,27 +895,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/save.c b/src/save.c index 0a2a4e799..680f33de0 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,7 +648,7 @@ 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_END; i++) //setting i to SECTOR_ID_PKMN_STORAGE_START does not match { gRamSaveSectionLocations[i].data = (void*)(gPokemonStoragePtr) + sSaveSectionOffsets[i].toAdd; gRamSaveSectionLocations[i].size = sSaveSectionOffsets[i].size; diff --git a/src/scrcmd.c b/src/scrcmd.c index 578e357fa..ef0b3f86b 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) 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/secret_base.c b/src/secret_base.c index 0ee5cc740..8e0929593 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -963,7 +963,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: @@ -1044,10 +1044,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; } @@ -1061,7 +1061,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/slot_machine.c b/src/slot_machine.c index cc001bcc9..7cfd7d22e 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) @@ -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..35eb53475 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: diff --git a/src/trainer_hill.c b/src/trainer_hill.c index 1116051d3..18d56723c 100644 --- a/src/trainer_hill.c +++ b/src/trainer_hill.c @@ -355,7 +355,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(); 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 0f8aa042d..3e80ffe37 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -3753,7 +3753,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..75464529f 100755 --- a/src/union_room_chat.c +++ b/src/union_room_chat.c @@ -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/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/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