From e0440ca6d121a2edbce3ebc67a2df3f754fb5522 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sun, 19 Nov 2023 12:46:19 -0500 Subject: [PATCH 1/2] Add script to generate compile_commands.json For general use with clangd without requiring CMake, Ninja, etc. --- .gitignore | 2 ++ gen_compile_commands.py | 29 +++++++++++++++++++++++++++++ include/config.h | 2 -- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 gen_compile_commands.py diff --git a/.gitignore b/.gitignore index c5872bb896..916b6c5409 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,5 @@ prefabs.json .vscode/*.* *.js *.sym +.cache +compile_commands.json diff --git a/gen_compile_commands.py b/gen_compile_commands.py new file mode 100644 index 0000000000..f04b55be3b --- /dev/null +++ b/gen_compile_commands.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +import json +import pathlib + +commands = [] +working_dir = pathlib.Path().resolve() +agbcc = working_dir / 'tools/agbcc' +builddir = working_dir / 'build/firered' + + +class MyEncoder(json.JSONEncoder): + def default(self, o): + if isinstance(o, pathlib.PurePath): + return str(o) + return super().default(o) + +# c sources +for src in (working_dir / 'src').rglob('*.c'): + outfile = builddir / str(src.relative_to(working_dir).with_suffix('.o')) + commands.append({ + 'directory': working_dir, + 'arguments': ['arm-none-eabi-gcc', '-c', '-O2', '-g', '-std=c99', '-mcpu=arm7tdmi', '-mthumb', '-iquote' + str(working_dir / 'include'), '-I' + str(agbcc / 'include'), '-D__INTELLISENSE__', '-DFIRERED', '-DENGLISH', '-o', outfile, src], + 'file': src, + 'output': outfile + }) + +with open('compile_commands.json', 'w') as ofp: + json.dump(commands, ofp, cls=MyEncoder, indent=4) diff --git a/include/config.h b/include/config.h index 956858e2d6..5934633624 100644 --- a/include/config.h +++ b/include/config.h @@ -1,8 +1,6 @@ #ifndef GUARD_CONFIG_H #define GUARD_CONFIG_H -#include "global.h" - // In the Generation 3 games, Asserts were used in various debug builds. // Ruby/Sapphire and Emerald do not have these asserts while Fire Red // still has them in the ROM. This is because the developers forgot From ef2669cd57f028f023d3d28ba57f0e1b787a3fed Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sun, 19 Nov 2023 16:09:29 -0500 Subject: [PATCH 2/2] Use compiledb instead of custom script Also fixes some issues flagged by clangd --- .clangd | 4 ++++ gen_compile_commands.py | 29 ----------------------------- gen_compile_commands.sh | 7 +++++++ graphics_file_rules.mk | 10 +++++----- include/global.h | 2 +- install-devkitpro-pacman | 23 +++++++++++++++++++++++ src/battle_ai_switch_items.c | 2 +- src/battle_anim_utility_funcs.c | 2 +- src/battle_message.c | 2 +- src/menu_indicators.c | 12 ++++++------ src/metatile_behavior.c | 6 +++--- src/overworld.c | 2 +- 12 files changed, 53 insertions(+), 48 deletions(-) create mode 100644 .clangd delete mode 100644 gen_compile_commands.py create mode 100755 gen_compile_commands.sh create mode 100755 install-devkitpro-pacman diff --git a/.clangd b/.clangd new file mode 100644 index 0000000000..0cacf8bf89 --- /dev/null +++ b/.clangd @@ -0,0 +1,4 @@ +CompileFlags: + Remove: [-mthumb-interwork, -fhex-asm] + Add: [-mcpu=arm7tdmi, -Itools/agbcc/include, -iquoteinclude, -D__INTELLISENSE__, -DFIRERED, -DREVISION=0, -DENGLISH, -DMODERN=0, -Wno-deprecated-non-prototype, -Wno-unknown-escape-sequence, -Wno-pointer-sign, -Wno-constant-conversion, -Wno-gnu-folding-constant] + Compiler: /usr/bin/arm-none-eabi-gcc diff --git a/gen_compile_commands.py b/gen_compile_commands.py deleted file mode 100644 index f04b55be3b..0000000000 --- a/gen_compile_commands.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python - -import json -import pathlib - -commands = [] -working_dir = pathlib.Path().resolve() -agbcc = working_dir / 'tools/agbcc' -builddir = working_dir / 'build/firered' - - -class MyEncoder(json.JSONEncoder): - def default(self, o): - if isinstance(o, pathlib.PurePath): - return str(o) - return super().default(o) - -# c sources -for src in (working_dir / 'src').rglob('*.c'): - outfile = builddir / str(src.relative_to(working_dir).with_suffix('.o')) - commands.append({ - 'directory': working_dir, - 'arguments': ['arm-none-eabi-gcc', '-c', '-O2', '-g', '-std=c99', '-mcpu=arm7tdmi', '-mthumb', '-iquote' + str(working_dir / 'include'), '-I' + str(agbcc / 'include'), '-D__INTELLISENSE__', '-DFIRERED', '-DENGLISH', '-o', outfile, src], - 'file': src, - 'output': outfile - }) - -with open('compile_commands.json', 'w') as ofp: - json.dump(commands, ofp, cls=MyEncoder, indent=4) diff --git a/gen_compile_commands.sh b/gen_compile_commands.sh new file mode 100755 index 0000000000..1da3cccbc9 --- /dev/null +++ b/gen_compile_commands.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -euo pipefail + +which compiledb || { echo compiledb not found, please install using "pip install compiledb"; exit 1; } + +CC=arm-none-eabi-gcc CXX=arm-none-eabi-g++ compiledb make diff --git a/graphics_file_rules.mk b/graphics_file_rules.mk index 2b3f4ea837..d17d70647d 100644 --- a/graphics_file_rules.mk +++ b/graphics_file_rules.mk @@ -141,11 +141,11 @@ $(INTERFACEGFXDIR)/hp_numbers.4bpp: $(INTERFACEGFXDIR)/hp_bar_anim.4bpp \ $(INTERFACEGFXDIR)/numbers2.4bpp @cat $^ >$@ -$(UNUSEDGFXDIR)/redyellowgreen_frame.bin: $(UNUSEDGFXDIR)/red_frame.bin \ - $(UNUSEDGFXDIR)/yellow_frame.bin \ - $(UNUSEDGFXDIR)/green_frame.bin \ - $(UNUSEDGFXDIR)/blank_frame.bin - @cat $^ >$@ +# $(UNUSEDGFXDIR)/redyellowgreen_frame.bin: $(UNUSEDGFXDIR)/red_frame.bin \ +# $(UNUSEDGFXDIR)/yellow_frame.bin \ +# $(UNUSEDGFXDIR)/green_frame.bin \ +# $(UNUSEDGFXDIR)/blank_frame.bin +# @cat $^ >$@ $(UNUSEDGFXDIR)/color_frames.4bpp: %.4bpp: %.png $(GFX) $< $@ -num_tiles 353 -Wnum_tiles diff --git a/include/global.h b/include/global.h index ab42b113c6..99890296d5 100644 --- a/include/global.h +++ b/include/global.h @@ -74,7 +74,7 @@ #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) >= (b) ? (a) : (b)) -#if MODERN +#if MODERN || defined(__INTELLISENSE__) #define abs(x) (((x) < 0) ? -(x) : (x)) #endif diff --git a/install-devkitpro-pacman b/install-devkitpro-pacman new file mode 100755 index 0000000000..2604b03213 --- /dev/null +++ b/install-devkitpro-pacman @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +if ! [ $(id -u) = 0 ]; then + echo "Need root privilege to install!" + exit 1 +fi + +# ensure apt is set up to work with https sources +apt-get install apt-transport-https + +# Store devkitPro gpg key locally if we don't have it already +if ! [ -f /usr/local/share/keyring/devkitpro-pub.gpg ]; then + mkdir -p /usr/local/share/keyring/ + wget -O /usr/local/share/keyring/devkitpro-pub.gpg https://apt.devkitpro.org/devkitpro-pub.gpg +fi + +# Add the devkitPro apt repository if we don't have it set up already +if ! [ -f /etc/apt/sources.list.d/devkitpro.list ]; then + echo "deb [signed-by=/usr/local/share/keyring/devkitpro-pub.gpg] https://apt.devkitpro.org stable main" > /etc/apt/sources.list.d/devkitpro.list +fi + +# Finally install devkitPro pacman +apt-get update +apt-get install devkitpro-pacman diff --git a/src/battle_ai_switch_items.c b/src/battle_ai_switch_items.c index 73c013cfaa..4cd0329878 100644 --- a/src/battle_ai_switch_items.c +++ b/src/battle_ai_switch_items.c @@ -380,7 +380,7 @@ void AI_TrySwitchOrUseItem(void) } for (monToSwitchId = 0; monToSwitchId < PARTY_SIZE; ++monToSwitchId) { - if ((!GetMonData(&gEnemyParty[monToSwitchId], MON_DATA_HP) == 0) + if ((GetMonData(&gEnemyParty[monToSwitchId], MON_DATA_HP) != 0) && (monToSwitchId != gBattlerPartyIndexes[battlerIn1]) && (monToSwitchId != gBattlerPartyIndexes[battlerIn2]) && (monToSwitchId != *(gBattleStruct->monToSwitchIntoId + battlerIn1)) diff --git a/src/battle_anim_utility_funcs.c b/src/battle_anim_utility_funcs.c index 896c6411ac..0b9569be0a 100644 --- a/src/battle_anim_utility_funcs.c +++ b/src/battle_anim_utility_funcs.c @@ -491,7 +491,7 @@ static void StatsChangeAnimation_Step2(u8 taskId) } gBattle_BG1_X = 0; gBattle_BG1_Y = 0; - if (sAnimStatsChangeData->data[0] == 1) + if (sAnimStatsChangeData->data[0] == 1) { gBattle_BG1_X = 64; gTasks[taskId].data[1] = -3; diff --git a/src/battle_message.c b/src/battle_message.c index 9e6789c9c6..5ab90ed242 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -1778,7 +1778,7 @@ void BufferStringBattle(u16 stringId) u32 BattleStringExpandPlaceholdersToDisplayedString(const u8 *src) { - BattleStringExpandPlaceholders(src, gDisplayedStringBattle); + return BattleStringExpandPlaceholders(src, gDisplayedStringBattle); } static const u8 *TryGetStatusString(u8 *src) diff --git a/src/menu_indicators.c b/src/menu_indicators.c index 393a508678..7c926632d5 100644 --- a/src/menu_indicators.c +++ b/src/menu_indicators.c @@ -479,15 +479,15 @@ void ListMenuSetUpRedOutlineCursorSpriteOamTable(u16 rowWidth, u16 rowHeight, st s32 i, j, id = 0; subsprites[id] = sSubsprite_RedOutline1; - subsprites[id].x = 136; - subsprites[id].y = 136; + subsprites[id].x = -120; + subsprites[id].y = -120; id++; subsprites[id] = sSubsprite_RedOutline2; subsprites[id].x = rowWidth + 128; - subsprites[id].y = 136; + subsprites[id].y = -120; id++; subsprites[id] = sSubsprite_RedOutline7; - subsprites[id].x = 136; + subsprites[id].x = -120; subsprites[id].y = rowHeight + 128; id++; subsprites[id] = sSubsprite_RedOutline8; @@ -500,7 +500,7 @@ void ListMenuSetUpRedOutlineCursorSpriteOamTable(u16 rowWidth, u16 rowHeight, st { subsprites[id] = sSubsprite_RedOutline3; subsprites[id].x = i - 120; - subsprites[id].y = 136; + subsprites[id].y = -120; id++; subsprites[id] = sSubsprite_RedOutline6; @@ -514,7 +514,7 @@ void ListMenuSetUpRedOutlineCursorSpriteOamTable(u16 rowWidth, u16 rowHeight, st for (j = 8; j < rowHeight - 8; j += 8) { subsprites[id] = sSubsprite_RedOutline4; - subsprites[id].x = 136; + subsprites[id].x = -120; subsprites[id].y = j - 120; id++; subsprites[id] = sSubsprite_RedOutline5; diff --git a/src/metatile_behavior.c b/src/metatile_behavior.c index ce27366476..857d788aef 100644 --- a/src/metatile_behavior.c +++ b/src/metatile_behavior.c @@ -40,9 +40,9 @@ bool8 MetatileBehavior_IsJumpEast(u8 metatileBehavior) bool8 MetatileBehavior_IsJumpWest(u8 metatileBehavior) { if (metatileBehavior == MB_JUMP_WEST) - return TRUE; - else - return FALSE; + return TRUE; + else + return FALSE; } bool8 MetatileBehavior_IsJumpNorth(u8 metatileBehavior) diff --git a/src/overworld.c b/src/overworld.c index f3078c596a..969820fc6c 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -3540,7 +3540,7 @@ static void SpriteCB_LinkPlayer(struct Sprite *sprite) SetObjectSubpriorityByElevation(objEvent->previousElevation, sprite, 1); sprite->oam.priority = ElevationToPriority(objEvent->previousElevation); - if (!linkPlayerObjEvent->movementMode != MOVEMENT_MODE_FREE) + if (linkPlayerObjEvent->movementMode == MOVEMENT_MODE_FREE) StartSpriteAnim(sprite, GetFaceDirectionAnimNum(linkDirection(objEvent))); else StartSpriteAnimIfDifferent(sprite, GetMoveDirectionAnimNum(linkDirection(objEvent)));