From cd9022f929525eca670bc17cca884f927d232be4 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Mon, 30 Oct 2017 21:14:52 -0400 Subject: [PATCH] sub_8123C00 --- asm/region_map.s | 163 ----------------------------------------------- include/rom6.h | 1 + src/region_map.c | 55 +++++++++++++++- 3 files changed, 55 insertions(+), 164 deletions(-) diff --git a/asm/region_map.s b/asm/region_map.s index 8a5dbbdaf7..9a2dc1700c 100644 --- a/asm/region_map.s +++ b/asm/region_map.s @@ -5,169 +5,6 @@ .text - thumb_func_start sub_8123C00 -sub_8123C00: @ 8123C00 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x8 - movs r7, 0 - movs r0, 0 - mov r8, r0 - mov r4, sp - adds r4, 0x1 - mov r5, sp - adds r5, 0x2 - add r6, sp, 0x4 - mov r0, sp - adds r1, r4, 0 - adds r2, r5, 0 - adds r3, r6, 0 - bl GetSSTidalLocation - lsls r0, 24 - lsrs r0, 24 - mov r10, r5 - cmp r0, 0x4 - bhi _08123C94 - lsls r0, 2 - ldr r1, =_08123C40 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_08123C40: - .4byte _08123C94 - .4byte _08123C54 - .4byte _08123C64 - .4byte _08123C74 - .4byte _08123C84 -_08123C54: - ldr r2, =gRegionMap - ldr r1, [r2] - movs r0, 0x8 - strh r0, [r1] - b _08123D10 - .pool -_08123C64: - ldr r2, =gRegionMap - ldr r1, [r2] - movs r0, 0xC - strh r0, [r1] - b _08123D10 - .pool -_08123C74: - ldr r2, =gRegionMap - ldr r1, [r2] - movs r0, 0x27 - strh r0, [r1] - b _08123D10 - .pool -_08123C84: - ldr r2, =gRegionMap - ldr r1, [r2] - movs r0, 0x2E - strh r0, [r1] - b _08123D10 - .pool -_08123C94: - mov r0, sp - ldrb r0, [r0] - ldrb r1, [r4] - bl get_mapheader_by_bank_and_number - ldr r1, =gRegionMap - mov r9, r1 - ldr r2, [r1] - ldrb r1, [r0, 0x14] - strh r1, [r2] - ldr r6, [r0] - ldr r1, =gRegionMapEntries - ldrh r0, [r2] - lsls r0, 3 - adds r5, r0, r1 - ldrb r4, [r5, 0x2] - ldr r0, [r6] - adds r1, r4, 0 - bl __divsi3 - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _08123CC6 - movs r1, 0x1 -_08123CC6: - mov r2, r10 - movs r3, 0 - ldrsh r0, [r2, r3] - bl __divsi3 - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - cmp r8, r4 - bcc _08123CE2 - subs r0, r4, 0x1 - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 -_08123CE2: - ldrb r4, [r5, 0x3] - ldr r0, [r6, 0x4] - adds r1, r4, 0 - bl __divsi3 - lsls r0, 16 - lsrs r1, r0, 16 - cmp r1, 0 - bne _08123CF6 - movs r1, 0x1 -_08123CF6: - mov r2, sp - movs r3, 0x4 - ldrsh r0, [r2, r3] - bl __divsi3 - lsls r0, 16 - lsrs r7, r0, 16 - mov r2, r9 - cmp r7, r4 - bcc _08123D10 - subs r0, r4, 0x1 - lsls r0, 16 - lsrs r7, r0, 16 -_08123D10: - ldr r0, [r2] - adds r0, 0x7F - movs r1, 0 - strb r1, [r0] - ldr r2, [r2] - ldr r3, =gRegionMapEntries - ldrh r0, [r2] - lsls r0, 3 - adds r0, r3 - ldrb r0, [r0] - add r0, r8 - adds r0, 0x1 - adds r1, r2, 0 - adds r1, 0x54 - strh r0, [r1] - ldrh r0, [r2] - lsls r0, 3 - adds r0, r3 - ldrb r0, [r0, 0x1] - adds r0, r7, r0 - adds r0, 0x2 - adds r2, 0x56 - strh r0, [r2] - add sp, 0x8 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_8123C00 - thumb_func_start get_flagnr_blue_points get_flagnr_blue_points: @ 8123D58 push {lr} diff --git a/include/rom6.h b/include/rom6.h index 0e9927855f..a42cc191a9 100644 --- a/include/rom6.h +++ b/include/rom6.h @@ -3,5 +3,6 @@ void sub_81357FC(u8, void(void)); u8 GetLeadMonIndex(void); +u8 GetSSTidalLocation(u8 *grp, u8 *num, s16 *x, s16 *y); #endif //GUARD_ROM6_H diff --git a/src/region_map.c b/src/region_map.c index 30d5bc087a..dd3654bee0 100644 --- a/src/region_map.c +++ b/src/region_map.c @@ -8,6 +8,7 @@ #include "trig.h" #include "map_constants.h" #include "overworld.h" +#include "rom6.h" #include "region_map.h" #define MAP_WIDTH 28 @@ -46,11 +47,11 @@ void UpdateRegionMapVideoRegs(void); u16 GetRegionMapSectionIdAt(u16 x, u16 y); void sub_812378C(s16 x, s16 y); static void sub_81238AC(void); +static void sub_8123C00(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); @@ -710,3 +711,55 @@ static void sub_81238AC(void) gRegionMap->cursorPosX = gRegionMapEntries[gRegionMap->mapSecId].x + x + MAPCURSOR_X_MIN; gRegionMap->cursorPosY = gRegionMapEntries[gRegionMap->mapSecId].y + y + MAPCURSOR_Y_MIN; } + +static void sub_8123C00(void) +{ + u16 y; + u16 x; + u8 mapGroup; + u8 mapNum; + u16 r1; + s16 sp2; + s16 sp4; + const struct MapHeader *mapHeader; + + y = 0; + x = 0; + switch (GetSSTidalLocation(&mapGroup, &mapNum, &sp2, &sp4)) + { + case 1: + gRegionMap->mapSecId = MAPSEC_SLATEPORT_CITY; + break; + case 2: + gRegionMap->mapSecId = MAPSEC_LILYCOVE_CITY; + break; + case 3: + gRegionMap->mapSecId = MAPSEC_ROUTE_124; + break; + case 4: + gRegionMap->mapSecId = MAPSEC_ROUTE_131; + break; + default: + case 0: + mapHeader = get_mapheader_by_bank_and_number(mapGroup, mapNum); + + gRegionMap->mapSecId = mapHeader->regionMapSectionId; + r1 = mapHeader->mapData->width / gRegionMapEntries[gRegionMap->mapSecId].width; + if (r1 == 0) + r1 = 1; + x = sp2 / r1; + if (x >= gRegionMapEntries[gRegionMap->mapSecId].width) + x = gRegionMapEntries[gRegionMap->mapSecId].width - 1; + + r1 = mapHeader->mapData->height / gRegionMapEntries[gRegionMap->mapSecId].height; + if (r1 == 0) + r1 = 1; + y = sp4 / r1; + if (y >= gRegionMapEntries[gRegionMap->mapSecId].height) + y = gRegionMapEntries[gRegionMap->mapSecId].height - 1; + break; + } + gRegionMap->playerIsInCave = FALSE; + gRegionMap->cursorPosX = gRegionMapEntries[gRegionMap->mapSecId].x + x + MAPCURSOR_X_MIN; + gRegionMap->cursorPosY = gRegionMapEntries[gRegionMap->mapSecId].y + y + MAPCURSOR_Y_MIN; +}