diff --git a/asm/region_map.s b/asm/region_map.s index e6eca9691b..8a5dbbdaf7 100644 --- a/asm/region_map.s +++ b/asm/region_map.s @@ -5,411 +5,6 @@ .text - thumb_func_start sub_81238AC -sub_81238AC: @ 81238AC - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0xC - ldr r0, =gSaveBlock1Ptr - ldr r2, [r0] - movs r1, 0x4 - ldrsb r1, [r2, r1] - adds r3, r0, 0 - cmp r1, 0x19 - bne _081238DC - ldrb r0, [r2, 0x5] - subs r0, 0x29 - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x2 - bhi _081238DC - bl sub_8123C00 - b _08123BEC - .pool -_081238DC: - ldr r1, [r3] - movs r0, 0x4 - ldrsb r0, [r1, r0] - ldrb r1, [r1, 0x5] - lsls r1, 24 - asrs r1, 24 - bl get_map_light_level_by_bank_and_number - lsls r0, 24 - lsrs r0, 24 - subs r0, 0x1 - cmp r0, 0x8 - bhi _08123928 - lsls r0, 2 - ldr r1, =_08123904 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_08123904: - .4byte _08123928 - .4byte _08123928 - .4byte _08123928 - .4byte _0812396C - .4byte _08123928 - .4byte _08123928 - .4byte _0812396C - .4byte _08123A28 - .4byte _081239E4 -_08123928: - ldr r4, =gRegionMap - ldr r0, [r4] - ldr r3, =gMapHeader - ldrb r1, [r3, 0x14] - movs r2, 0 - strh r1, [r0] - adds r0, 0x7F - strb r2, [r0] - ldr r0, [r3] - ldrh r2, [r0] - ldrh r0, [r0, 0x4] - mov r9, r0 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldrh r6, [r0] - ldrh r3, [r0, 0x2] - ldr r1, [r4] - ldrh r0, [r1] - cmp r0, 0x45 - beq _08123956 - cmp r0, 0xCC - beq _08123956 - b _08123ABE -_08123956: - adds r1, 0x7F - movs r0, 0x1 - strb r0, [r1] - b _08123ABE - .pool -_0812396C: - ldr r2, =gMapHeader - ldrb r1, [r2, 0x1A] - movs r0, 0x2 - ands r0, r1 - cmp r0, 0 - beq _081239C8 - ldr r4, =gSaveBlock1Ptr - ldr r1, [r4] - adds r0, r1, 0 - adds r0, 0x24 - ldrb r0, [r0] - lsls r0, 24 - asrs r0, 24 - lsls r0, 16 - lsrs r0, 16 - adds r1, 0x25 - ldrb r1, [r1] - lsls r1, 24 - asrs r1, 24 - lsls r1, 16 - lsrs r1, 16 - bl get_mapheader_by_bank_and_number - adds r5, r0, 0 - ldr r0, =gRegionMap - ldr r0, [r0] - ldrb r1, [r5, 0x14] - strh r1, [r0] - adds r0, 0x7F - movs r1, 0x1 - strb r1, [r0] - ldr r0, [r5] - ldrh r2, [r0] - ldrh r0, [r0, 0x4] - mov r9, r0 - ldr r0, [r4] - ldrh r6, [r0, 0x28] - ldrh r3, [r0, 0x2A] - b _08123ABE - .pool -_081239C8: - ldr r0, =gRegionMap - ldr r0, [r0] - ldrb r1, [r2, 0x14] - strh r1, [r0] - adds r0, 0x7F - movs r1, 0x1 - strb r1, [r0] - movs r2, 0x1 - mov r9, r2 - movs r6, 0x1 - movs r3, 0x1 - b _08123ABE - .pool -_081239E4: - ldr r4, =gSaveBlock1Ptr - ldr r1, [r4] - movs r0, 0x14 - ldrsb r0, [r1, r0] - lsls r0, 16 - lsrs r0, 16 - ldrb r1, [r1, 0x15] - lsls r1, 24 - asrs r1, 24 - lsls r1, 16 - lsrs r1, 16 - bl get_mapheader_by_bank_and_number - adds r5, r0, 0 - ldr r0, =gRegionMap - ldr r0, [r0] - ldrb r1, [r5, 0x14] - strh r1, [r0] - adds r0, 0x7F - movs r1, 0x1 - strb r1, [r0] - ldr r0, [r5] - ldrh r2, [r0] - ldrh r0, [r0, 0x4] - mov r9, r0 - ldr r0, [r4] - ldrh r6, [r0, 0x18] - ldrh r3, [r0, 0x1A] - b _08123ABE - .pool -_08123A28: - ldr r4, =gRegionMap - ldr r0, [r4] - ldr r1, =gMapHeader - ldrb r1, [r1, 0x14] - strh r1, [r0] - cmp r1, 0x57 - beq _08123A64 - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - adds r7, r0, 0 - adds r7, 0x24 - movs r0, 0 - ldrsb r0, [r7, r0] - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x1 - ldrsb r1, [r7, r1] - lsls r1, 16 - lsrs r1, 16 - bl get_mapheader_by_bank_and_number - adds r5, r0, 0 - b _08123A8A - .pool -_08123A64: - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - adds r7, r0, 0 - adds r7, 0x14 - ldrb r0, [r0, 0x14] - lsls r0, 24 - asrs r0, 24 - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x1 - ldrsb r1, [r7, r1] - lsls r1, 16 - lsrs r1, 16 - bl get_mapheader_by_bank_and_number - adds r5, r0, 0 - ldr r1, [r4] - ldrb r0, [r5, 0x14] - strh r0, [r1] -_08123A8A: - ldr r4, =gRegionMap - ldr r0, [r4] - ldrb r0, [r0] - bl sub_8123F74 - adds r1, r0, 0 - cmp r1, 0 - beq _08123AAC - ldr r0, [r4] - adds r0, 0x7F - movs r1, 0x1 - b _08123AB0 - .pool -_08123AAC: - ldr r0, [r4] - adds r0, 0x7F -_08123AB0: - strb r1, [r0] - ldr r0, [r5] - ldrh r2, [r0] - ldrh r0, [r0, 0x4] - mov r9, r0 - ldrh r6, [r7, 0x4] - ldrh r3, [r7, 0x6] -_08123ABE: - str r6, [sp] - ldr r5, =gRegionMapEntries - ldr r4, =gRegionMap - ldr r0, [r4] - mov r10, r0 - ldrh r7, [r0] - lsls r0, r7, 3 - adds r0, r5 - str r0, [sp, 0x4] - ldrb r0, [r0, 0x2] - mov r8, r0 - adds r0, r2, 0 - mov r1, r8 - str r3, [sp, 0x8] - bl __divsi3 - lsls r0, 16 - lsrs r1, r0, 16 - ldr r3, [sp, 0x8] - cmp r1, 0 - bne _08123AEA - movs r1, 0x1 -_08123AEA: - adds r0, r6, 0 - str r3, [sp, 0x8] - bl __udivsi3 - lsls r0, 16 - lsrs r6, r0, 16 - ldr r3, [sp, 0x8] - cmp r6, r8 - bcc _08123B04 - mov r0, r8 - subs r0, 0x1 - lsls r0, 16 - lsrs r6, r0, 16 -_08123B04: - ldr r2, [sp, 0x4] - ldrb r4, [r2, 0x3] - mov r0, r9 - adds r1, r4, 0 - str r3, [sp, 0x8] - bl __divsi3 - lsls r0, 16 - lsrs r1, r0, 16 - ldr r3, [sp, 0x8] - cmp r1, 0 - bne _08123B1E - movs r1, 0x1 -_08123B1E: - adds r0, r3, 0 - bl __udivsi3 - lsls r0, 16 - lsrs r3, r0, 16 - cmp r3, r4 - bcc _08123B32 - subs r0, r4, 0x1 - lsls r0, 16 - lsrs r3, r0, 16 -_08123B32: - cmp r7, 0x29 - beq _08123B5E - cmp r7, 0x29 - bgt _08123B4C - cmp r7, 0x1D - beq _08123B56 - cmp r7, 0x24 - beq _08123B94 - b _08123BC6 - .pool -_08123B4C: - cmp r7, 0x33 - beq _08123B5E - cmp r7, 0xCC - beq _08123BB8 - b _08123BC6 -_08123B56: - cmp r3, 0 - beq _08123BC6 - movs r6, 0 - b _08123BC6 -_08123B5E: - movs r6, 0 - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - movs r2, 0 - ldrsh r0, [r1, r2] - cmp r0, 0x20 - ble _08123B6E - movs r6, 0x1 -_08123B6E: - cmp r0, 0x33 - ble _08123B78 - adds r0, r6, 0x1 - lsls r0, 16 - lsrs r6, r0, 16 -_08123B78: - movs r3, 0 - movs r2, 0x2 - ldrsh r0, [r1, r2] - cmp r0, 0x25 - ble _08123B84 - movs r3, 0x1 -_08123B84: - cmp r0, 0x38 - ble _08123BC6 - adds r0, r3, 0x1 - lsls r0, 16 - lsrs r3, r0, 16 - b _08123BC6 - .pool -_08123B94: - movs r6, 0 - ldr r0, [sp] - cmp r0, 0xE - bls _08123B9E - movs r6, 0x1 -_08123B9E: - ldr r2, [sp] - cmp r2, 0x1C - bls _08123BAA - adds r0, r6, 0x1 - lsls r0, 16 - lsrs r6, r0, 16 -_08123BAA: - ldr r0, [sp] - cmp r0, 0x36 - bls _08123BC6 - adds r0, r6, 0x1 - lsls r0, 16 - lsrs r6, r0, 16 - b _08123BC6 -_08123BB8: - mov r0, r10 - adds r0, 0x54 - mov r1, r10 - adds r1, 0x56 - bl sub_8123F30 - b _08123BEC -_08123BC6: - ldr r0, =gRegionMap - ldr r2, [r0] - ldrh r0, [r2] - lsls r0, 3 - adds r0, r5 - ldrb r0, [r0] - adds r0, r6, r0 - adds r0, 0x1 - adds r1, r2, 0 - adds r1, 0x54 - strh r0, [r1] - ldrh r0, [r2] - lsls r0, 3 - adds r0, r5 - ldrb r0, [r0, 0x1] - adds r0, r3, r0 - adds r0, 0x2 - adds r2, 0x56 - strh r0, [r2] -_08123BEC: - add sp, 0xC - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81238AC - thumb_func_start sub_8123C00 sub_8123C00: @ 8123C00 push {r4-r7,lr} diff --git a/include/overworld.h b/include/overworld.h index 5ac4cad29a..5a84e86dad 100644 --- a/include/overworld.h +++ b/include/overworld.h @@ -52,12 +52,13 @@ void Overworld_ChangeMusicTo(u16); bool32 is_c1_link_related_active(void); void strange_npc_table_clear(void); -const struct MapHeader *get_mapheader_by_bank_and_number(u8, u8); +const struct MapHeader *get_mapheader_by_bank_and_number(u16, u16); void FieldObjectMoveDestCoords(struct MapObject *, u32, s16 *, s16 *); void sub_8086230(void); void c2_exit_to_overworld_2_switch(void); bool32 sub_8087598(void); void c2_exit_to_overworld_1_continue_scripts_restart_music(void); void warp_in(void); +u8 get_map_light_level_by_bank_and_number(s8 mapGroup, s8 mapNum); #endif //GUARD_ROM4_H diff --git a/include/region_map.h b/include/region_map.h index b784e26ec3..3bb836fa11 100644 --- a/include/region_map.h +++ b/include/region_map.h @@ -267,7 +267,7 @@ struct RegionMap { /*0x07c*/ s8 cursorDeltaY; /*0x07d*/ bool8 needUpdateVideoRegs; /*0x07e*/ bool8 blinkPlayerIcon; - /*0x07f*/ bool8 unk_07f; + /*0x07f*/ bool8 playerIsInCave; /*0x080*/ u8 bgNum; /*0x081*/ u8 charBaseIdx; /*0x082*/ u8 mapBaseIdx; diff --git a/src/region_map.c b/src/region_map.c index b771d70280..30d5bc087a 100644 --- a/src/region_map.c +++ b/src/region_map.c @@ -6,6 +6,8 @@ #include "gpu_regs.h" #include "palette.h" #include "trig.h" +#include "map_constants.h" +#include "overworld.h" #include "region_map.h" #define MAP_WIDTH 28 @@ -21,6 +23,13 @@ struct UnkStruct_0203A148 { u8 filler_000[0xa74]; }; +struct RegionMapLocation +{ + u8 x, y; + u8 width, height; + const u8 *regionMapSectionId; +}; + // Static RAM declarations EWRAM_DATA struct RegionMap *gRegionMap = NULL; @@ -34,12 +43,15 @@ static u8 ProcessRegionMapInput_Zoomed(void); static u8 MoveRegionMapCursor_Zoomed(void); void CalcZoomScrollParams(s16 scrollX, s16 scrollY, s16 c, s16 d, u16 e, u16 f, u8 rotation); void UpdateRegionMapVideoRegs(void); -void sub_81238AC(void); -u8 get_flagnr_blue_points(u16 mapSecId); -u16 sub_8123EB4(u16 mapSecId); -void sub_8123FB0(void); u16 GetRegionMapSectionIdAt(u16 x, u16 y); void sub_812378C(s16 x, s16 y); +static void sub_81238AC(void); +u8 get_flagnr_blue_points(u16 mapSecId); +u16 sub_8123EB4(u16 mapSecId); +void sub_8123F30(u16 *x, u16 *y); +void sub_8123FB0(void); +void sub_8123C00(void); +bool32 sub_8123F74(u8 mapSecId); void sub_8124238(void); void sub_81243B0(void); void sub_81243DC(void); @@ -52,6 +64,7 @@ extern const u16 gUnknown_0859F73C[]; extern const u8 gUnknown_0859F77C[]; extern const u8 gUnknown_085A04E0[]; extern const u8 gUnknown_085A096C[]; +extern const struct RegionMapLocation gRegionMapEntries[]; // .text @@ -399,7 +412,9 @@ u8 sub_8123514(void) u8 r4; if (gRegionMap->unk_06e >= 16) + { return 0; + } gRegionMap->unk_06e ++; if (gRegionMap->unk_06e == 16) { @@ -421,14 +436,12 @@ u8 sub_8123514(void) gRegionMap->scrollX = gRegionMap->unk_03c >> 8; gRegionMap->scrollY = gRegionMap->unk_040 >> 8; gRegionMap->unk_04c += gRegionMap->unk_050; - if ((gRegionMap->unk_044 < 0 && gRegionMap->scrollX < gRegionMap->unk_060) - || (gRegionMap->unk_044 > 0 && gRegionMap->scrollX > gRegionMap->unk_060)) + if ((gRegionMap->unk_044 < 0 && gRegionMap->scrollX < gRegionMap->unk_060) || (gRegionMap->unk_044 > 0 && gRegionMap->scrollX > gRegionMap->unk_060)) { gRegionMap->scrollX = gRegionMap->unk_060; gRegionMap->unk_044 = 0; } - if ((gRegionMap->unk_048 < 0 && gRegionMap->scrollY < gRegionMap->unk_062) - || (gRegionMap->unk_048 > 0 && gRegionMap->scrollY > gRegionMap->unk_062)) + if ((gRegionMap->unk_048 < 0 && gRegionMap->scrollY < gRegionMap->unk_062) || (gRegionMap->unk_048 > 0 && gRegionMap->scrollY > gRegionMap->unk_062)) { gRegionMap->scrollY = gRegionMap->unk_062; gRegionMap->unk_048 = 0; @@ -522,3 +535,178 @@ u16 GetRegionMapSectionIdAt(u16 x, u16 y) x -= MAPCURSOR_X_MIN; return gUnknown_085A096C[x + y * MAP_WIDTH]; } + +static void sub_81238AC(void) +{ + const struct MapHeader *mapHeader; + u16 mapWidth; + u16 mapHeight; + u16 x; + u16 y; + u16 r1; + u16 r9; + struct WarpData *r4; + + if (gSaveBlock1Ptr->location.mapGroup == MAP_GROUP_SS_TIDAL_CORRIDOR + && (gSaveBlock1Ptr->location.mapNum == MAP_ID_SS_TIDAL_CORRIDOR + || gSaveBlock1Ptr->location.mapNum == MAP_ID_SS_TIDAL_LOWER_DECK + || gSaveBlock1Ptr->location.mapNum == MAP_ID_SS_TIDAL_ROOMS)) + { + sub_8123C00(); + return; + } + + switch (get_map_light_level_by_bank_and_number(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum)) + { + default: + case 1: + case 2: + case 3: + case 5: + case 6: + gRegionMap->mapSecId = gMapHeader.regionMapSectionId; + gRegionMap->playerIsInCave = FALSE; + mapWidth = gMapHeader.mapData->width; + mapHeight = gMapHeader.mapData->height; + x = gSaveBlock1Ptr->pos.x; + y = gSaveBlock1Ptr->pos.y; + if (gRegionMap->mapSecId == MAPSEC_UNDERWATER || gRegionMap->mapSecId == MAPSEC_UNDERWATER_MARINE_CAVE) + { + gRegionMap->playerIsInCave = TRUE; + } + break; + case 4: + case 7: + if (gMapHeader.flags & 0x02) + { + mapHeader = get_mapheader_by_bank_and_number(gSaveBlock1Ptr->warp4.mapGroup, gSaveBlock1Ptr->warp4.mapNum); + gRegionMap->mapSecId = mapHeader->regionMapSectionId; + gRegionMap->playerIsInCave = TRUE; + mapWidth = mapHeader->mapData->width; + mapHeight = mapHeader->mapData->height; + x = gSaveBlock1Ptr->warp4.x; + y = gSaveBlock1Ptr->warp4.y; + } + else + { + gRegionMap->mapSecId = gMapHeader.regionMapSectionId; + gRegionMap->playerIsInCave = TRUE; + mapWidth = 1; + mapHeight = 1; + x = 1; + y = 1; + } + break; + case 9: + mapHeader = get_mapheader_by_bank_and_number((u16)gSaveBlock1Ptr->warp2.mapGroup, (u16)gSaveBlock1Ptr->warp2.mapNum); + gRegionMap->mapSecId = mapHeader->regionMapSectionId; + gRegionMap->playerIsInCave = TRUE; + mapWidth = mapHeader->mapData->width; + mapHeight = mapHeader->mapData->height; + x = gSaveBlock1Ptr->warp2.x; + y = gSaveBlock1Ptr->warp2.y; + break; + case 8: + + gRegionMap->mapSecId = gMapHeader.regionMapSectionId; + if (gRegionMap->mapSecId != MAPSEC_NONE) + { + r4 = &gSaveBlock1Ptr->warp4; + mapHeader = get_mapheader_by_bank_and_number(r4->mapGroup, r4->mapNum); + } + else + { + r4 = &gSaveBlock1Ptr->warp2; + mapHeader = get_mapheader_by_bank_and_number(r4->mapGroup, r4->mapNum); + gRegionMap->mapSecId = mapHeader->regionMapSectionId; + } + if (sub_8123F74(gRegionMap->mapSecId)) + { + gRegionMap->playerIsInCave = TRUE; + } + else + { + gRegionMap->playerIsInCave = FALSE; + } + mapWidth = mapHeader->mapData->width; + mapHeight = mapHeader->mapData->height; + x = r4->x; + y = r4->y; + break; + } + + r9 = x; + + r1 = mapWidth / gRegionMapEntries[gRegionMap->mapSecId].width; + if (r1 == 0) + { + r1 = 1; + } + x /= r1; + if (x >= gRegionMapEntries[gRegionMap->mapSecId].width) + { + x = gRegionMapEntries[gRegionMap->mapSecId].width - 1; + } + + r1 = mapHeight / gRegionMapEntries[gRegionMap->mapSecId].height; + if (r1 == 0) + { + r1 = 1; + } + y /= r1; + if (y >= gRegionMapEntries[gRegionMap->mapSecId].height) + { + y = gRegionMapEntries[gRegionMap->mapSecId].height - 1; + } + + switch (gRegionMap->mapSecId) + { + case MAPSEC_ROUTE_114: + if (y != 0) + { + x = 0; + } + break; + case MAPSEC_ROUTE_126: + case MAPSEC_UNDERWATER_125: + x = 0; + if (gSaveBlock1Ptr->pos.x > 32) + { + x = 1; + } + if (gSaveBlock1Ptr->pos.x > 0x33) + { + x++; + } + y = 0; + if (gSaveBlock1Ptr->pos.y > 0x25) + { + y = 1; + } + if (gSaveBlock1Ptr->pos.y > 0x38) + { + y++; + } + break; + case MAPSEC_ROUTE_121: + x = 0; + if (r9 > 14) + { + x = 1; + } + if (r9 > 0x1C) + { + x++; + } + if (r9 > 0x36) + { + x++; + } + break; + case MAPSEC_UNDERWATER_MARINE_CAVE: + sub_8123F30(&gRegionMap->cursorPosX, &gRegionMap->cursorPosY); + return; + } + gRegionMap->cursorPosX = gRegionMapEntries[gRegionMap->mapSecId].x + x + MAPCURSOR_X_MIN; + gRegionMap->cursorPosY = gRegionMapEntries[gRegionMap->mapSecId].y + y + MAPCURSOR_Y_MIN; +}