summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcus Huderle <huderlem@gmail.com>2018-04-12 12:30:41 -0700
committerGitHub <noreply@github.com>2018-04-12 12:30:41 -0700
commitcff12d7907f03a8fe939be854555c2e6353bcab8 (patch)
tree9003393ec7c964e42c39b09b871ea1e252b7372c /src
parenta5cd6e8ef4717aad4a055d5acb6ef250e359fc45 (diff)
parentac7d69eb6e491541837455a2fba0ee63586c6191 (diff)
Merge pull request #234 from KDSKardabox/master
Port map_obj_lock, map_name_popup, rom6 & script_movement
Diffstat (limited to 'src')
-rwxr-xr-xsrc/item_use.c4
-rw-r--r--src/map_name_popup.c474
-rw-r--r--src/map_obj_lock.c187
-rw-r--r--src/pokemon_summary_screen.c86
-rw-r--r--src/rom6.c209
-rw-r--r--src/script_movement.c233
6 files changed, 1115 insertions, 78 deletions
diff --git a/src/item_use.c b/src/item_use.c
index 3b6b286b7..80b33220e 100755
--- a/src/item_use.c
+++ b/src/item_use.c
@@ -912,7 +912,7 @@ void re_escape_rope(u8 taskId)
DisplayItemMessageOnField(taskId, gStringVar4, task08_080A1C44);
}
-bool8 sub_80FE314(void)
+bool8 CanUseEscapeRopeOnCurrMap(void)
{
if (gMapHeader.flags & 2)
return TRUE;
@@ -922,7 +922,7 @@ bool8 sub_80FE314(void)
void ItemUseOutOfBattle_EscapeRope(u8 taskId)
{
- if (sub_80FE314() == TRUE)
+ if (CanUseEscapeRopeOnCurrMap() == TRUE)
{
gUnknown_0203A0F4 = re_escape_rope;
SetUpItemUseOnFieldCallback(taskId);
diff --git a/src/map_name_popup.c b/src/map_name_popup.c
new file mode 100644
index 000000000..59b1622eb
--- /dev/null
+++ b/src/map_name_popup.c
@@ -0,0 +1,474 @@
+#include "global.h"
+#include "constants/region_map_sections.h"
+#include "constants/weather.h"
+#include "bg.h"
+#include "event_data.h"
+#include "gpu_regs.h"
+#include "international_string_util.h"
+#include "menu.h"
+#include "map_name_popup.h"
+#include "palette.h"
+#include "region_map.h"
+#include "rom_818CFC8.h"
+#include "start_menu.h"
+#include "string_util.h"
+#include "task.h"
+#include "text.h"
+
+
+// enums
+enum MapPopUp_Themes
+{
+ MAPPOPUP_THEME_WOOD,
+ MAPPOPUP_THEME_MARBLE,
+ MAPPOPUP_THEME_STONE,
+ MAPPOPUP_THEME_BRICK,
+ MAPPOPUP_THEME_UNDERWATER,
+ MAPPOPUP_THEME_STONE2,
+};
+
+// static functions
+static void Task_MapNamePopUpWindow(u8 taskId);
+static void ShowMapNamePopUpWindow(void);
+static void LoadMapNamePopUpWindowBg(void);
+
+// EWRAM
+static EWRAM_DATA u8 mapNamePopupTaskId = 0;
+
+// .rodata
+static const u8 gMapPopUp_Table[][960] =
+{
+ INCBIN_U8("graphics/interface/map_popup/wood.4bpp"),
+ INCBIN_U8("graphics/interface/map_popup/marble.4bpp"),
+ INCBIN_U8("graphics/interface/map_popup/stone.4bpp"),
+ INCBIN_U8("graphics/interface/map_popup/brick.4bpp"),
+ INCBIN_U8("graphics/interface/map_popup/underwater.4bpp"),
+ INCBIN_U8("graphics/interface/map_popup/stone2.4bpp"),
+};
+
+static const u8 gMapPopUp_Outline_Table[][960] =
+{
+ INCBIN_U8("graphics/interface/map_popup/wood_outline.4bpp"),
+ INCBIN_U8("graphics/interface/map_popup/marble_outline.4bpp"),
+ INCBIN_U8("graphics/interface/map_popup/stone_outline.4bpp"),
+ INCBIN_U8("graphics/interface/map_popup/brick_outline.4bpp"),
+ INCBIN_U8("graphics/interface/map_popup/underwater_outline.4bpp"),
+ INCBIN_U8("graphics/interface/map_popup/stone2_outline.4bpp"),
+};
+
+static const u16 gMapPopUp_Palette_Table[][16] =
+{
+ INCBIN_U16("graphics/interface/map_popup/wood.gbapal"),
+ INCBIN_U16("graphics/interface/map_popup/marble_outline.gbapal"),
+ INCBIN_U16("graphics/interface/map_popup/stone_outline.gbapal"),
+ INCBIN_U16("graphics/interface/map_popup/brick_outline.gbapal"),
+ INCBIN_U16("graphics/interface/map_popup/underwater_outline.gbapal"),
+ INCBIN_U16("graphics/interface/map_popup/stone2_outline.gbapal"),
+};
+
+static const u16 gUnknown_0857F444[16] = INCBIN_U16("graphics/interface/map_popup/857F444.gbapal");
+
+static const u8 gRegionMapSectionId_To_PopUpThemeIdMapping[] =
+{
+ MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD,
+ MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_BRICK,
+ MAPPOPUP_THEME_MARBLE, MAPPOPUP_THEME_MARBLE, MAPPOPUP_THEME_MARBLE, MAPPOPUP_THEME_BRICK,
+ MAPPOPUP_THEME_MARBLE, MAPPOPUP_THEME_BRICK, MAPPOPUP_THEME_MARBLE, MAPPOPUP_THEME_BRICK,
+ MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD,
+ MAPPOPUP_THEME_UNDERWATER, MAPPOPUP_THEME_UNDERWATER, MAPPOPUP_THEME_UNDERWATER, MAPPOPUP_THEME_UNDERWATER,
+ MAPPOPUP_THEME_UNDERWATER, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD,
+ MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD,
+ MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD,
+ MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_UNDERWATER, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_UNDERWATER,
+ MAPPOPUP_THEME_UNDERWATER, MAPPOPUP_THEME_UNDERWATER, MAPPOPUP_THEME_UNDERWATER, MAPPOPUP_THEME_UNDERWATER,
+ MAPPOPUP_THEME_UNDERWATER, MAPPOPUP_THEME_UNDERWATER, MAPPOPUP_THEME_UNDERWATER, MAPPOPUP_THEME_UNDERWATER,
+ MAPPOPUP_THEME_UNDERWATER, MAPPOPUP_THEME_UNDERWATER, MAPPOPUP_THEME_STONE2, MAPPOPUP_THEME_STONE2,
+ MAPPOPUP_THEME_STONE2, MAPPOPUP_THEME_STONE2, MAPPOPUP_THEME_STONE2, MAPPOPUP_THEME_STONE,
+ MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_MARBLE, MAPPOPUP_THEME_WOOD,
+ MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_MARBLE, MAPPOPUP_THEME_STONE,
+ MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE,
+ MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE2, MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_WOOD,
+ MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE,
+ MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE2,
+ MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE,
+ MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_MARBLE,
+ MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_WOOD,
+ MAPPOPUP_THEME_WOOD, MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE2,
+ MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE2, MAPPOPUP_THEME_STONE2, MAPPOPUP_THEME_STONE2,
+ MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_STONE, MAPPOPUP_THEME_MARBLE
+};
+
+static const u8 gText_PyramidFloor1[] = _("PYRAMID FLOOR 1");
+static const u8 gText_PyramidFloor2[] = _("PYRAMID FLOOR 2");
+static const u8 gText_PyramidFloor3[] = _("PYRAMID FLOOR 3");
+static const u8 gText_PyramidFloor4[] = _("PYRAMID FLOOR 4");
+static const u8 gText_PyramidFloor5[] = _("PYRAMID FLOOR 5");
+static const u8 gText_PyramidFloor6[] = _("PYRAMID FLOOR 6");
+static const u8 gText_PyramidFloor7[] = _("PYRAMID FLOOR 7");
+static const u8 gText_Pyramid[] = _("PYRAMID");
+
+static const u8 * const gBattlePyramid_MapHeaderStrings[] =
+{
+ gText_PyramidFloor1,
+ gText_PyramidFloor2,
+ gText_PyramidFloor3,
+ gText_PyramidFloor4,
+ gText_PyramidFloor5,
+ gText_PyramidFloor6,
+ gText_PyramidFloor7,
+ gText_Pyramid,
+};
+
+// text
+bool8 sub_80D47D4(void)
+{
+ HideStartMenu();
+ ShowMapNamePopup();
+ return 1;
+}
+
+void ShowMapNamePopup(void)
+{
+ if (FlagGet(FLAG_SPECIAL_FLAG_0x4000) != TRUE)
+ {
+ if (!FuncIsActiveTask(Task_MapNamePopUpWindow))
+ {
+ mapNamePopupTaskId = CreateTask(Task_MapNamePopUpWindow, 90);
+ SetGpuReg(REG_OFFSET_BG0VOFS, 40);
+ gTasks[mapNamePopupTaskId].data[0] = 6;
+ gTasks[mapNamePopupTaskId].data[2] = 40;
+ }
+ else
+ {
+ if (gTasks[mapNamePopupTaskId].data[0] != 2)
+ gTasks[mapNamePopupTaskId].data[0] = 2;
+ gTasks[mapNamePopupTaskId].data[3] = 1;
+ }
+ }
+}
+
+static void Task_MapNamePopUpWindow(u8 taskId)
+{
+ struct Task *task = &gTasks[taskId];
+
+ switch (task->data[0])
+ {
+ case 6:
+ task->data[4]++;
+ if (task->data[4] > 30)
+ {
+ task->data[0] = 0;
+ task->data[4] = 0;
+ ShowMapNamePopUpWindow();
+ }
+ break;
+ case 0:
+ task->data[2] -= 2;
+ if (task->data[2] <= 0 )
+ {
+ task->data[2] = 0;
+ task->data[0] = 1;
+ gTasks[mapNamePopupTaskId].data[1] = 0;
+ }
+ break;
+ case 1:
+ task->data[1]++;
+ if (task->data[1] > 120 )
+ {
+ task->data[1] = 0;
+ task->data[0] = 2;
+ }
+ break;
+ case 2:
+ task->data[2] += 2;
+ if (task->data[2] > 39)
+ {
+ task->data[2] = 40;
+ if (task->data[3])
+ {
+ task->data[0] = 6;
+ task->data[4] = 0;
+ task->data[3] = 0;
+ }
+ else
+ {
+ task->data[0] = 4;
+ return;
+ }
+ }
+ break;
+ case 4:
+ sub_819746C(GetMapNamePopUpWindowId(), TRUE);
+ task->data[0] = 5;
+ break;
+ case 5:
+ HideMapNamePopUpWindow();
+ return;
+ }
+ SetGpuReg(REG_OFFSET_BG0VOFS, task->data[2]);
+}
+
+void HideMapNamePopUpWindow(void)
+{
+ if (FuncIsActiveTask(Task_MapNamePopUpWindow))
+ {
+ sub_819746C(GetMapNamePopUpWindowId(), TRUE);
+ RemoveMapNamePopUpWindow();
+ SetGpuReg_ForcedBlank(REG_OFFSET_BG0VOFS, 0);
+ DestroyTask(mapNamePopupTaskId);
+ }
+}
+
+static void ShowMapNamePopUpWindow(void)
+{
+ u8 mapDisplayHeader[24];
+ u8 *withoutPrefixPtr;
+ u8 x;
+ const u8* mapDisplayHeaderSource;
+
+ if(InBattlePyramid())
+ {
+ if(gMapHeader.mapDataId == 0x17A)
+ {
+ withoutPrefixPtr = &(mapDisplayHeader[3]);
+ mapDisplayHeaderSource = gBattlePyramid_MapHeaderStrings[7];
+ }
+ else
+ {
+ withoutPrefixPtr = &(mapDisplayHeader[3]);
+ mapDisplayHeaderSource = gBattlePyramid_MapHeaderStrings[gSaveBlock2Ptr->battlePyramidWildHeaderId];
+ }
+ StringCopy(withoutPrefixPtr, mapDisplayHeaderSource);
+ }
+ else
+ {
+ withoutPrefixPtr = &(mapDisplayHeader[3]);
+ GetMapName(withoutPrefixPtr, gMapHeader.regionMapSectionId, 0);
+ }
+ AddMapNamePopUpWindow();
+ LoadMapNamePopUpWindowBg();
+ x = GetStringCenterAlignXOffset(7, withoutPrefixPtr, 80);
+ mapDisplayHeader[0] = EXT_CTRL_CODE_BEGIN;
+ mapDisplayHeader[1] = EXT_CTRL_CODE_HIGHLIGHT;
+ mapDisplayHeader[2] = TEXT_COLOR_TRANSPARENT;
+ PrintTextOnWindow(GetMapNamePopUpWindowId(), 7, mapDisplayHeader, x, 3, 0xFF, NULL);
+ CopyWindowToVram(GetMapNamePopUpWindowId(), 3);
+}
+
+#ifdef NONMATCHING
+static void sub_80D4A78(u8 bg, u8 x, u8 y, u8 deltaX, u8 deltaY, u8 unused)
+{
+ s32 i;
+
+ for(i=0; i<=11; i++)
+ {
+ FillBgTilemapBufferRect(bg, 0x21D + i, x + i - 1, y - 1, 1, 1, 0xE);
+ }
+ FillBgTilemapBufferRect(bg, 0x229 + i, x - 1, y, 1, 1, 0xE);
+ FillBgTilemapBufferRect(bg, 0x22A + i, deltaX + x, y, 1, 1, 0xE);
+ FillBgTilemapBufferRect(bg, 0x22B + i, x - 1, y + 1 , 1, 1, 0xE);
+ FillBgTilemapBufferRect(bg, 0x22C + i, deltaX + x, y + 1, 1, 1, 0xE);
+ FillBgTilemapBufferRect(bg, 0x22D + i, x - 1, y + 2, 1, 1, 0xE);
+ FillBgTilemapBufferRect(bg, 0x22E + i, deltaX + x, y + 2, 1, 1, 0xE);
+ for(i=0; i<=11; i++)
+ {
+ FillBgTilemapBufferRect(bg, 0x22F + i, x + i - 1, y + deltaY, 1, 1, 0xE);
+ }
+}
+#else
+ASM_DIRECT
+static void sub_80D4A78(u8 bg, u8 x, u8 y, u8 deltaX, u8 deltaY, u8 unused)
+{
+ asm("\n\
+ .syntax unified\n\
+ push {r4-r7,lr}\n\
+ mov r7, r10\n\
+ mov r6, r9\n\
+ mov r5, r8\n\
+ push {r5-r7}\n\
+ sub sp, 0x1C\n\
+ ldr r4, [sp, 0x3C]\n\
+ lsls r0, 24\n\
+ lsrs r7, r0, 24\n\
+ lsls r1, 24\n\
+ lsrs r1, 24\n\
+ mov r10, r1\n\
+ lsls r2, 24\n\
+ lsls r3, 24\n\
+ lsrs r3, 24\n\
+ str r3, [sp, 0x10]\n\
+ lsls r4, 24\n\
+ lsrs r4, 24\n\
+ str r4, [sp, 0x14]\n\
+ movs r5, 0\n\
+ lsls r0, r1, 24\n\
+ asrs r1, r0, 24\n\
+ lsrs r3, r2, 24\n\
+ str r3, [sp, 0xC]\n\
+ movs r6, 0xFF\n\
+ lsls r6, 24\n\
+ adds r6, r2\n\
+ mov r8, r6\n\
+ str r0, [sp, 0x18]\n\
+ subs r4, r1, 0x1\n\
+ _080D4AB4:\n\
+ ldr r0, =0x0000021d\n\
+ adds r1, r5, r0\n\
+ lsls r1, 16\n\
+ lsrs r1, 16\n\
+ lsls r2, r4, 24\n\
+ lsrs r2, 24\n\
+ movs r3, 0x1\n\
+ str r3, [sp]\n\
+ str r3, [sp, 0x4]\n\
+ movs r6, 0xE\n\
+ mov r9, r6\n\
+ str r6, [sp, 0x8]\n\
+ adds r0, r7, 0\n\
+ mov r6, r8\n\
+ lsrs r3, r6, 24\n\
+ bl FillBgTilemapBufferRect\n\
+ adds r4, 0x1\n\
+ adds r5, 0x1\n\
+ cmp r5, 0xB\n\
+ ble _080D4AB4\n\
+ ldr r1, =0x00000229\n\
+ movs r0, 0x1\n\
+ negs r0, r0\n\
+ add r0, r10\n\
+ lsls r0, 24\n\
+ lsrs r0, 24\n\
+ mov r8, r0\n\
+ movs r5, 0x1\n\
+ str r5, [sp]\n\
+ str r5, [sp, 0x4]\n\
+ mov r2, r9\n\
+ str r2, [sp, 0x8]\n\
+ adds r0, r7, 0\n\
+ mov r2, r8\n\
+ ldr r3, [sp, 0xC]\n\
+ bl FillBgTilemapBufferRect\n\
+ ldr r1, =0x0000022a\n\
+ ldr r6, [sp, 0x10]\n\
+ add r6, r10\n\
+ lsls r6, 24\n\
+ lsrs r6, 24\n\
+ str r5, [sp]\n\
+ str r5, [sp, 0x4]\n\
+ mov r3, r9\n\
+ str r3, [sp, 0x8]\n\
+ adds r0, r7, 0\n\
+ adds r2, r6, 0\n\
+ ldr r3, [sp, 0xC]\n\
+ bl FillBgTilemapBufferRect\n\
+ ldr r1, =0x0000022b\n\
+ ldr r4, [sp, 0xC]\n\
+ adds r4, 0x1\n\
+ lsls r4, 24\n\
+ lsrs r4, 24\n\
+ str r5, [sp]\n\
+ str r5, [sp, 0x4]\n\
+ mov r0, r9\n\
+ str r0, [sp, 0x8]\n\
+ adds r0, r7, 0\n\
+ mov r2, r8\n\
+ adds r3, r4, 0\n\
+ bl FillBgTilemapBufferRect\n\
+ movs r1, 0x8B\n\
+ lsls r1, 2\n\
+ str r5, [sp]\n\
+ str r5, [sp, 0x4]\n\
+ mov r2, r9\n\
+ str r2, [sp, 0x8]\n\
+ adds r0, r7, 0\n\
+ adds r2, r6, 0\n\
+ adds r3, r4, 0\n\
+ bl FillBgTilemapBufferRect\n\
+ ldr r1, =0x0000022d\n\
+ ldr r4, [sp, 0xC]\n\
+ adds r4, 0x2\n\
+ lsls r4, 24\n\
+ lsrs r4, 24\n\
+ str r5, [sp]\n\
+ str r5, [sp, 0x4]\n\
+ mov r3, r9\n\
+ str r3, [sp, 0x8]\n\
+ adds r0, r7, 0\n\
+ mov r2, r8\n\
+ adds r3, r4, 0\n\
+ bl FillBgTilemapBufferRect\n\
+ ldr r1, =0x0000022e\n\
+ str r5, [sp]\n\
+ str r5, [sp, 0x4]\n\
+ mov r0, r9\n\
+ str r0, [sp, 0x8]\n\
+ adds r0, r7, 0\n\
+ adds r2, r6, 0\n\
+ adds r3, r4, 0\n\
+ bl FillBgTilemapBufferRect\n\
+ movs r5, 0\n\
+ ldr r1, [sp, 0xC]\n\
+ ldr r2, [sp, 0x14]\n\
+ adds r0, r1, r2\n\
+ lsls r4, r0, 24\n\
+ movs r6, 0x1\n\
+ _080D4B8A:\n\
+ ldr r3, =0x0000022f\n\
+ adds r1, r5, r3\n\
+ lsls r1, 16\n\
+ lsrs r1, 16\n\
+ subs r0, r5, 0x1\n\
+ ldr r3, [sp, 0x18]\n\
+ asrs r2, r3, 24\n\
+ adds r2, r0\n\
+ lsls r2, 24\n\
+ lsrs r2, 24\n\
+ str r6, [sp]\n\
+ str r6, [sp, 0x4]\n\
+ movs r0, 0xE\n\
+ str r0, [sp, 0x8]\n\
+ adds r0, r7, 0\n\
+ lsrs r3, r4, 24\n\
+ bl FillBgTilemapBufferRect\n\
+ adds r5, 0x1\n\
+ cmp r5, 0xB\n\
+ ble _080D4B8A\n\
+ add sp, 0x1C\n\
+ pop {r3-r5}\n\
+ mov r8, r3\n\
+ mov r9, r4\n\
+ mov r10, r5\n\
+ pop {r4-r7}\n\
+ pop {r0}\n\
+ bx r0\n\
+ .pool\n\
+ .syntax divided");
+}
+#endif // NONMATCHING
+
+static void LoadMapNamePopUpWindowBg(void)
+{
+ u8 popupWindowId;
+ u16 regionMapSectionId;
+ u8 popUpThemeId;
+
+ popupWindowId = GetMapNamePopUpWindowId();
+ regionMapSectionId = gMapHeader.regionMapSectionId;
+ if(regionMapSectionId > MAPSEC_DYNAMIC)
+ {
+ if(regionMapSectionId > MAPSEC_SPECIAL_AREA)
+ regionMapSectionId -= (MAPSEC_SPECIAL_AREA - MAPSEC_DYNAMIC);
+ else
+ regionMapSectionId = 0; //discard kanto region sections
+ }
+ popUpThemeId = gRegionMapSectionId_To_PopUpThemeIdMapping[regionMapSectionId];
+
+ LoadBgTiles(GetWindowAttribute(popupWindowId, 0), &(gMapPopUp_Outline_Table[popUpThemeId][0]), 0x400, 0x21D);
+ CallWindowFunction(popupWindowId, sub_80D4A78);
+ PutWindowTilemap(popupWindowId);
+ if(gMapHeader.weather == WEATHER_BUBBLES)
+ LoadPalette(&gUnknown_0857F444, 0xE0, 0x20);
+ else
+ LoadPalette(&(gMapPopUp_Palette_Table[popUpThemeId][0]), 0xE0, 0x20);
+ BlitBitmapToWindow(popupWindowId, &(gMapPopUp_Table[popUpThemeId][0]), 0, 0, 80, 24);
+}
diff --git a/src/map_obj_lock.c b/src/map_obj_lock.c
new file mode 100644
index 000000000..688d0594d
--- /dev/null
+++ b/src/map_obj_lock.c
@@ -0,0 +1,187 @@
+#include "global.h"
+#include "event_data.h"
+#include "field_map_obj.h"
+#include "field_map_obj_helpers.h"
+#include "field_player_avatar.h"
+#include "map_obj_lock.h"
+#include "script_movement.h"
+#include "task.h"
+#include "trainer_see.h"
+
+bool8 walkrun_is_standing_still(void)
+{
+ if (gPlayerAvatar.tileTransitionState == T_TILE_TRANSITION)
+ return FALSE;
+ else
+ return TRUE;
+}
+
+static void sub_80983A4(u8 taskId)
+{
+ if (walkrun_is_standing_still())
+ {
+ sub_808B864();
+ DestroyTask(taskId);
+ }
+}
+
+bool8 sub_80983C4(void)
+{
+ if (FuncIsActiveTask(sub_80983A4))
+ {
+ return FALSE;
+ }
+ else
+ {
+ sub_808BCF4();
+ return TRUE;
+ }
+}
+
+
+void ScriptFreezeMapObjects(void)
+{
+ FreezeMapObjects();
+ CreateTask(sub_80983A4, 80);
+}
+
+static void sub_8098400(u8 taskId)
+{
+ struct Task *task = &gTasks[taskId];
+
+ if (!task->data[0] && walkrun_is_standing_still() == TRUE)
+ {
+ sub_808B864();
+ task->data[0] = 1;
+ }
+ if (!task->data[1] && !gMapObjects[gSelectedMapObject].mapobj_bit_1)
+ {
+ FreezeMapObject(&gMapObjects[gSelectedMapObject]);
+ task->data[1] = 1;
+ }
+ if (task->data[0] && task->data[1])
+ DestroyTask(taskId);
+}
+
+bool8 sub_809847C(void)
+{
+ if (FuncIsActiveTask(sub_8098400))
+ {
+ return FALSE;
+ }
+ else
+ {
+ sub_808BCF4();
+ return TRUE;
+ }
+}
+
+void LockSelectedMapObject(void)
+{
+ u8 taskId;
+ FreezeMapObjectsExceptOne(gSelectedMapObject);
+ taskId = CreateTask(sub_8098400, 80);
+ if (!gMapObjects[gSelectedMapObject].mapobj_bit_1)
+ {
+ FreezeMapObject(&gMapObjects[gSelectedMapObject]);
+ gTasks[taskId].data[1] = 1;
+ }
+}
+
+void sub_80984F4(void)
+{
+ u8 objectId = GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0);
+ FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[objectId]);
+ sub_80D338C();
+ UnfreezeMapObjects();
+}
+
+void sub_8098524(void)
+{
+ u8 objectId;
+
+ if (gMapObjects[gSelectedMapObject].active)
+ FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[gSelectedMapObject]);
+ objectId = GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0);
+ FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[objectId]);
+ sub_80D338C();
+ UnfreezeMapObjects();
+}
+
+void sub_8098574(void)
+{
+ FieldObjectFaceOppositeDirection(&gMapObjects[gSelectedMapObject], gSpecialVar_Facing);
+}
+
+void sub_809859C(void)
+{
+ FieldObjectClearAnimIfSpecialAnimActive(&gMapObjects[gSelectedMapObject]);
+}
+
+static void sub_80985BC(u8 taskId)
+{
+ struct Task *task = &gTasks[taskId];
+ u8 mapObjectId = task->data[2];
+
+ if (!task->data[0] && walkrun_is_standing_still() == TRUE)
+ {
+ sub_808B864();
+ task->data[0] = 1;
+ }
+ if (!task->data[1] && !gMapObjects[mapObjectId].mapobj_bit_1)
+ {
+ FreezeMapObject(&gMapObjects[mapObjectId]);
+ task->data[1] = 1;
+ }
+ if (task->data[0] && task->data[1])
+ DestroyTask(taskId);
+}
+
+void sub_8098630(void)
+{
+ u8 trainerObjectId1, trainerObjectId2, taskId;
+ trainerObjectId1 = GetChosenApproachingTrainerMapObjectId(0);
+ if(gNoOfApproachingTrainers == 2)
+ {
+ trainerObjectId2 = GetChosenApproachingTrainerMapObjectId(1);
+ sub_8098074(trainerObjectId1, trainerObjectId2);
+ taskId = CreateTask(sub_80985BC, 80);
+ gTasks[taskId].data[2] = trainerObjectId1;
+ if(!gMapObjects[trainerObjectId1].mapobj_bit_1)
+ {
+ FreezeMapObject(&gMapObjects[trainerObjectId1]);
+ gTasks[taskId].data[1] = 1;
+ }
+ taskId = CreateTask(sub_80985BC, 81);
+ gTasks[taskId].data[2] = trainerObjectId2;
+ if(!gMapObjects[trainerObjectId2].mapobj_bit_1)
+ {
+ FreezeMapObject(&gMapObjects[trainerObjectId2]);
+ gTasks[taskId].data[1] = 1;
+ }
+ }
+ else
+ {
+ FreezeMapObjectsExceptOne(trainerObjectId1);
+ taskId = CreateTask(sub_80985BC, 80);
+ gTasks[taskId].data[2] = trainerObjectId1;
+ if(!gMapObjects[trainerObjectId1].mapobj_bit_1)
+ {
+ FreezeMapObject(&gMapObjects[trainerObjectId1]);
+ gTasks[taskId].data[1] = 1;
+ }
+ }
+}
+
+bool8 sub_8098734(void)
+{
+ if (FuncIsActiveTask(sub_80985BC))
+ {
+ return FALSE;
+ }
+ else
+ {
+ sub_808BCF4();
+ return TRUE;
+ }
+}
diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c
index 834ca6f7d..e7fcce629 100644
--- a/src/pokemon_summary_screen.c
+++ b/src/pokemon_summary_screen.c
@@ -2776,93 +2776,27 @@ void sub_81C2C38(u8 a)
schedule_bg_copy_tilemap_to_vram(0);
}
-
-
-#ifdef NONMATCHING
u8 sub_81C2D2C(struct WindowTemplate *template, u8 a)
{
- u8 *r4 = gUnknown_0203CF1C->unk40CB;
- if (r4[a] == 0xFF)
+ u8 *windowIdPtr = &(gUnknown_0203CF1C->unk40CB[a]);
+ if (*windowIdPtr == 0xFF)
{
- r4[a] = AddWindow(&template[a]);
- FillWindowPixelBuffer(r4[a], 0);
+ *windowIdPtr = AddWindow(&template[a]);
+ FillWindowPixelBuffer(*windowIdPtr, 0);
}
- return r4[a];
-}
-#else
-ASM_DIRECT
-u8 sub_81C2D2C(struct WindowTemplate *template, u8 a)
-{
- asm(".syntax unified\n\
- push {r4,lr}\n\
- adds r3, r0, 0\n\
- lsls r1, 24\n\
- lsrs r2, r1, 24\n\
- ldr r0, =gUnknown_0203CF1C\n\
- ldr r4, =0x000040cb\n\
- adds r1, r2, r4\n\
- ldr r0, [r0]\n\
- adds r4, r0, r1\n\
- ldrb r0, [r4]\n\
- cmp r0, 0xFF\n\
- bne _081C2D56\n\
- lsls r0, r2, 3\n\
- adds r0, r3, r0\n\
- bl AddWindow\n\
- strb r0, [r4]\n\
- ldrb r0, [r4]\n\
- movs r1, 0\n\
- bl FillWindowPixelBuffer\n\
-_081C2D56:\n\
- ldrb r0, [r4]\n\
- pop {r4}\n\
- pop {r1}\n\
- bx r1\n\
- .pool\n\
- .syntax divided\n");
+ return *windowIdPtr;
}
-#endif
-#ifdef NONMATCHING
void sub_81C2D68(u8 a)
{
- u8 *r4 = gUnknown_0203CF1C->unk40CB;
- if (r4[a] != 0xFF)
+ u8 *windowIdPtr = &(gUnknown_0203CF1C->unk40CB[a]);
+ if (*windowIdPtr != 0xFF)
{
- ClearWindowTilemap(r4[a]);
- RemoveWindow(r4[a]);
- r4[a] = 0xFF;
+ ClearWindowTilemap(*windowIdPtr);
+ RemoveWindow(*windowIdPtr);
+ *windowIdPtr = 0xFF;
}
}
-#else
-ASM_DIRECT
-void sub_81C2D68(u8 a)
-{
- asm(".syntax unified\n\
- push {r4,lr}\n\
- lsls r0, 24\n\
- lsrs r0, 24\n\
- ldr r1, =gUnknown_0203CF1C\n\
- ldr r2, =0x000040cb\n\
- adds r0, r2\n\
- ldr r1, [r1]\n\
- adds r4, r1, r0\n\
- ldrb r0, [r4]\n\
- cmp r0, 0xFF\n\
- beq _081C2D8C\n\
- bl ClearWindowTilemap\n\
- ldrb r0, [r4]\n\
- bl RemoveWindow\n\
- movs r0, 0xFF\n\
- strb r0, [r4]\n\
-_081C2D8C:\n\
- pop {r4}\n\
- pop {r0}\n\
- bx r0\n\
- .pool\n\
- .syntax divided\n");
-}
-#endif
void sub_81C2D9C(u8 a)
{
diff --git a/src/rom6.c b/src/rom6.c
new file mode 100644
index 000000000..4a5c506b6
--- /dev/null
+++ b/src/rom6.c
@@ -0,0 +1,209 @@
+#include "global.h"
+#include "constants/map_objects.h"
+#include "constants/songs.h"
+#include "rom6.h"
+#include "braille_puzzles.h"
+#include "event_data.h"
+#include "event_scripts.h"
+#include "field_effect.h"
+#include "field_map_obj.h"
+#include "field_player_avatar.h"
+#include "item_use.h"
+#include "party_menu.h"
+#include "overworld.h"
+#include "script.h"
+#include "sound.h"
+#include "sprite.h"
+#include "task.h"
+
+// static functions
+static void task08_080C9820(u8 taskId);
+static void sub_8135578(u8 taskId);
+static void sub_813552C(u8 taskId);
+static void sub_813561C(u8 taskId);
+static void sub_81356C4(void);
+static void sub_8135714(void);
+static void hm2_dig(void);
+static void sub_8135780(void);
+
+// extern RAM loc
+extern struct MapPosition gUnknown_0203AB40;
+
+// text
+bool8 npc_before_player_of_type(u8 a)
+{
+ u8 mapObjId;
+
+ GetXYCoordsOneStepInFrontOfPlayer(&gUnknown_0203AB40.x, &gUnknown_0203AB40.y);
+ gUnknown_0203AB40.height = PlayerGetZCoord();
+ mapObjId = GetFieldObjectIdByXYZ(gUnknown_0203AB40.x, gUnknown_0203AB40.y, gUnknown_0203AB40.height);
+ if (gMapObjects[mapObjId].graphicsId != a)
+ {
+ return FALSE;
+ }
+ else
+ {
+ gSpecialVar_LastTalked = gMapObjects[mapObjId].localId;
+ return TRUE;
+ }
+}
+
+u8 oei_task_add(void)
+{
+ GetXYCoordsOneStepInFrontOfPlayer(&gUnknown_0203AB40.x, &gUnknown_0203AB40.y);
+ return CreateTask(task08_080C9820, 8);
+}
+
+static void task08_080C9820(u8 taskId)
+{
+ u8 mapObjId;
+
+ ScriptContext2_Enable();
+ gPlayerAvatar.preventStep = TRUE;
+ mapObjId = gPlayerAvatar.mapObjectId;
+ if (!FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(&gMapObjects[mapObjId])
+ || FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[mapObjId]))
+ {
+ if (gMapHeader.mapType == MAP_TYPE_UNDERWATER)
+ {
+ FieldEffectStart(FLDEFF_FIELD_MOVE_SHOW_MON_INIT);
+ gTasks[taskId].func = sub_8135578;
+ }
+ else
+ {
+ sub_808C114();
+ FieldObjectSetSpecialAnim(&gMapObjects[mapObjId], 0x39);
+ gTasks[taskId].func = sub_813552C;
+ }
+ }
+}
+
+static void sub_813552C(u8 taskId)
+{
+ if (FieldObjectCheckIfSpecialAnimFinishedOrInactive(&gMapObjects[gPlayerAvatar.mapObjectId]) == TRUE)
+ {
+ FieldEffectStart(FLDEFF_FIELD_MOVE_SHOW_MON_INIT);
+ gTasks[taskId].func = sub_8135578;
+ }
+}
+
+static void sub_8135578(u8 taskId)
+{
+ if (!FieldEffectActiveListContains(6))
+ {
+ gFieldEffectArguments[1] = player_get_direction_lower_nybble();
+ if (gFieldEffectArguments[1] == 1)
+ gFieldEffectArguments[2] = 0;
+ if (gFieldEffectArguments[1] == 2)
+ gFieldEffectArguments[2] = 1;
+ if (gFieldEffectArguments[1] == 3)
+ gFieldEffectArguments[2] = 2;
+ if (gFieldEffectArguments[1] == 4)
+ gFieldEffectArguments[2] = 3;
+ FieldObjectSetGraphicsId(&gMapObjects[gPlayerAvatar.mapObjectId], GetPlayerAvatarGraphicsIdByCurrentState());
+ StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], gFieldEffectArguments[2]);
+ FieldEffectActiveListRemove(6);
+ gTasks[taskId].func = sub_813561C;
+ }
+}
+
+static void sub_813561C(u8 taskId)
+{
+ void (*func)(void) = (void (*)(void))(((u16)gTasks[taskId].data[8] << 16) | (u16)gTasks[taskId].data[9]);
+
+ func();
+ gPlayerAvatar.preventStep = FALSE;
+ DestroyTask(taskId);
+}
+
+bool8 SetUpFieldMove_RockSmash(void)
+{
+ if(ShouldDoBrailleStrengthEffect())
+ {
+ gSpecialVar_Result = GetCursorSelectionMonId();
+ gUnknown_03005DB0 = FieldCallback_Teleport;
+ gUnknown_0203CEEC = sub_8179834;
+ return TRUE;
+ }
+ else if (npc_before_player_of_type(0x56) == TRUE)
+ {
+ gUnknown_03005DB0 = FieldCallback_Teleport;
+ gUnknown_0203CEEC = sub_81356C4;
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+static void sub_81356C4(void)
+{
+ gFieldEffectArguments[0] = GetCursorSelectionMonId();
+ ScriptContext1_SetupScript(Route111_EventScript_2907F0);
+}
+
+bool8 FldEff_UseRockSmash(void)
+{
+ u8 taskId = oei_task_add();
+
+ gTasks[taskId].data[8] = (u32)sub_8135714 >> 16;
+ gTasks[taskId].data[9] = (u32)sub_8135714;
+ IncrementGameStat(GAME_STAT_USED_ROCK_SMASH);
+ return FALSE;
+}
+
+static void sub_8135714(void)
+{
+ PlaySE(SE_W088);
+ FieldEffectActiveListRemove(FLDEFF_USE_ROCK_SMASH);
+ EnableBothScriptContexts();
+}
+
+bool8 SetUpFieldMove_Dig(void)
+{
+ if (CanUseEscapeRopeOnCurrMap() == TRUE)
+ {
+ gUnknown_03005DB0 = FieldCallback_Teleport;
+ gUnknown_0203CEEC = hm2_dig;
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+static void hm2_dig(void)
+{
+ Overworld_ResetStateAfterDigEscRope();
+ FieldEffectStart(FLDEFF_USE_DIG);
+ gFieldEffectArguments[0] = GetCursorSelectionMonId();
+}
+
+bool8 FldEff_UseDig(void)
+{
+ u8 taskId = oei_task_add();
+
+ gTasks[taskId].data[8] = (u32)sub_8135780 >> 16;
+ gTasks[taskId].data[9] = (u32)sub_8135780;
+ if (!ShouldDoBrailleDigEffect())
+ SetPlayerAvatarTransitionFlags(1);
+ return FALSE;
+}
+
+static void sub_8135780(void)
+{
+ u8 taskId;
+
+ FieldEffectActiveListRemove(FLDEFF_USE_DIG);
+ if (ShouldDoBrailleDigEffect())
+ {
+ DoBrailleDigEffect();
+ }
+ else
+ {
+ taskId = CreateTask(task08_080A1C44, 8);
+ gTasks[taskId].data[0] = 0;
+ }
+}
diff --git a/src/script_movement.c b/src/script_movement.c
new file mode 100644
index 000000000..bbeb0eedc
--- /dev/null
+++ b/src/script_movement.c
@@ -0,0 +1,233 @@
+#include "global.h"
+#include "script_movement.h"
+#include "field_map_obj.h"
+#include "field_map_obj_helpers.h"
+#include "task.h"
+#include "util.h"
+
+// static functions
+static void sub_80D33AC(u8);
+static u8 sub_80D33F4(void);
+static bool8 sub_80D3408(u8, u8, const u8 *);
+static u8 sub_80D3474(u8, u8);
+static bool8 sub_80D3584(u8, u8);
+static void sub_80D35DC(u8, u8, u8, const u8 *);
+static void UnfreezeObjects(u8);
+static void sub_80D3660(u8);
+static void sub_80A2490(u8, u8, u8, const u8 *);
+
+// EWRAM_DATA
+static EWRAM_DATA const u8 *gUnknown_02039D90[16] = {0};
+
+// text
+bool8 ScriptMovement_StartObjectMovementScript(u8 localId, u8 mapNum, u8 mapGroup, const u8 *movementScript)
+{
+ u8 mapObjId;
+
+ if (TryGetFieldObjectIdByLocalIdAndMap(localId, mapNum, mapGroup, &mapObjId))
+ return TRUE;
+ if (!FuncIsActiveTask(sub_80D3660))
+ sub_80D33AC(50);
+ return sub_80D3408(sub_80D33F4(), mapObjId, movementScript);
+}
+
+bool8 ScriptMovement_IsObjectMovementFinished(u8 localId, u8 mapNum, u8 mapBank)
+{
+ u8 mapObjId;
+ u8 r4;
+ u8 r1;
+
+ if (TryGetFieldObjectIdByLocalIdAndMap(localId, mapNum, mapBank, &mapObjId))
+ return TRUE;
+ r4 = sub_80D33F4();
+ r1 = sub_80D3474(r4, mapObjId);
+ if (r1 == 16)
+ return TRUE;
+ return sub_80D3584(r4, r1);
+}
+
+void sub_80D338C(void)
+{
+ u8 taskId;
+
+ taskId = sub_80D33F4();
+ if (taskId != 0xFF)
+ {
+ UnfreezeObjects(taskId);
+ DestroyTask(taskId);
+ }
+}
+
+
+static void sub_80D33AC(u8 priority)
+{
+ u8 taskId;
+ u8 i;
+
+ taskId = CreateTask(sub_80D3660, priority);
+ for (i = 1; i < 16; i++)
+ gTasks[taskId].data[i] = 0xFFFF;
+}
+
+static u8 sub_80D33F4(void)
+{
+ return FindTaskIdByFunc(sub_80D3660);
+}
+
+static bool8 sub_80D3408(u8 taskId, u8 mapObjId, const u8 *movementScript)
+{
+ u8 r4;
+
+ r4 = sub_80D3474(taskId, mapObjId);
+ if (r4 != 16)
+ {
+ if (sub_80D3584(taskId, r4) == 0)
+ {
+ return TRUE;
+ }
+ else
+ {
+ sub_80D35DC(taskId, r4, mapObjId, movementScript);
+ return FALSE;
+ }
+ }
+ r4 = sub_80D3474(taskId, 0xFF);
+ if (r4 == 16)
+ {
+ return TRUE;
+ }
+ else
+ {
+ sub_80D35DC(taskId, r4, mapObjId, movementScript);
+ return FALSE;
+ }
+}
+
+static u8 sub_80D3474(u8 taskId, u8 b)
+{
+ u8 *ptr;
+ u8 i;
+
+ ptr = (u8 *)&gTasks[taskId].data[1];
+ for (i = 0; i < 16; i++, ptr++)
+ {
+ if (*ptr == b)
+ return i;
+ }
+ return 16;
+}
+
+static void sub_80D34B0(u8 taskId, u8 b, u8 **c)
+{
+ u8 i;
+
+ *c = (u8 *)&gTasks[taskId].data[1];
+ for (i = 0; i < b; i++, (*c)++)
+ ;
+}
+
+static void sub_80D34E4(u8 taskId, u8 b, u8 c)
+{
+ u8 *ptr;
+
+ sub_80D34B0(taskId, b, &ptr);
+ *ptr = c; //what is this supposed to do?
+}
+
+static void sub_80D3508(u8 taskId, u8 b, u8 *c)
+{
+ u8 *ptr;
+
+ sub_80D34B0(taskId, b, &ptr);
+ *c = *ptr;
+}
+
+static void sub_80D352C(u8 a, u8 b)
+{
+ u16 var = ~gBitTable[b];
+
+ gTasks[a].data[0] &= var;
+}
+
+static void sub_80D355C(u8 taskId, u8 b)
+{
+ gTasks[taskId].data[0] |= gBitTable[b];
+}
+
+static bool8 sub_80D3584(u8 taskId, u8 b)
+{
+ u16 var = (u16)gTasks[taskId].data[0] & gBitTable[b];
+
+ if (var != 0)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+static void npc_obj_offscreen_culling_and_flag_update(u8 a, const u8 *movementScript)
+{
+ gUnknown_02039D90[a] = movementScript;
+}
+
+static const u8 *sub_80D35CC(u8 a)
+{
+ return gUnknown_02039D90[a];
+}
+
+static void sub_80D35DC(u8 taskId, u8 b, u8 mapObjId, const u8 *movementScript)
+{
+ sub_80D352C(taskId, b);
+ npc_obj_offscreen_culling_and_flag_update(b, movementScript);
+ sub_80D34E4(taskId, b, mapObjId);
+}
+
+static void UnfreezeObjects(u8 taskId)
+{
+ u8 *pMapObjId;
+ u8 i;
+
+ pMapObjId = (u8 *)&gTasks[taskId].data[1];
+ for (i = 0; i < 16; i++, pMapObjId++)
+ {
+ if (*pMapObjId != 0xFF)
+ npc_sync_anim_pause_bits(&gMapObjects[*pMapObjId]);
+ }
+}
+
+static void sub_80D3660(u8 taskId)
+{
+ u8 i;
+ u8 var;
+
+ for (i = 0; i < 16; i++)
+ {
+ sub_80D3508(taskId, i, &var);
+ if (var != 0xFF)
+ sub_80A2490(taskId, i, var, sub_80D35CC(i));
+ }
+}
+
+static void sub_80A2490(u8 taskId, u8 b, u8 mapObjId, const u8 *d)
+{
+ u8 var;
+
+ if (FieldObjectIsSpecialAnimActive(&gMapObjects[mapObjId])
+ && !FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[mapObjId]))
+ return;
+
+ var = *d;
+ if (var == 0xFE)
+ {
+ sub_80D355C(taskId, b);
+ FreezeMapObject(&gMapObjects[mapObjId]);
+ }
+ else
+ {
+ if (!FieldObjectSetSpecialAnim(&gMapObjects[mapObjId], var))
+ {
+ d++;
+ npc_obj_offscreen_culling_and_flag_update(b, d);
+ }
+ }
+}
+