#!/usr/bin/env python3

enumPrfix = "ENTR_SCENE_"
entranceScenes = [
    "ENTR_SCENE_MAYORS_RESIDENCE",
    "ENTR_SCENE_MAJORAS_LAIR",
    "ENTR_SCENE_MAGIC_HAGS_POTION_SHOP",
    "ENTR_SCENE_RANCH_HOUSE",
    "ENTR_SCENE_HONEY_AND_DARLINGS_SHOP",
    "ENTR_SCENE_BENEATH_THE_GRAVERYARD",
    "ENTR_SCENE_SOUTHERN_SWAMP_CLEARED",
    "ENTR_SCENE_CURIOSITY_SHOP",
    "ENTR_SCENE_UNSET_08",
    "ENTR_SCENE_UNSET_09",
    "ENTR_SCENE_GROTTOS",
    "ENTR_SCENE_UNSET_0B",
    "ENTR_SCENE_UNSET_0C",
    "ENTR_SCENE_UNSET_0D",
    "ENTR_SCENE_CUTSCENE",
    "ENTR_SCENE_UNSET_0F",
    "ENTR_SCENE_IKANA_CANYON",
    "ENTR_SCENE_PIRATES_FORTRESS",
    "ENTR_SCENE_MILK_BAR",
    "ENTR_SCENE_STONE_TOWER_TEMPLE",
    "ENTR_SCENE_TREASURE_CHEST_SHOP",
    "ENTR_SCENE_STONE_TOWER_TEMPLE_REVERSED",
    "ENTR_SCENE_CLOCK_TOWER_ROOFTOP",
    "ENTR_SCENE_OPENING_DUNGEON",
    "ENTR_SCENE_WOODFALL_TEMPLE",
    "ENTR_SCENE_PATH_TO_MOUNTAIN_VILLAGE",
    "ENTR_SCENE_IKANA_CASTLE",
    "ENTR_SCENE_DEKU_SCRUB_PLAYGROUND",
    "ENTR_SCENE_ODOLWAS_LAIR",
    "ENTR_SCENE_TOWN_SHOOTING_GALLERY",
    "ENTR_SCENE_SNOWHEAD_TEMPLE",
    "ENTR_SCENE_MILK_ROAD",
    "ENTR_SCENE_PIRATES_FORTRESS_INTERIOR",
    "ENTR_SCENE_SWAMP_SHOOTING_GALLERY",
    "ENTR_SCENE_PINNACLE_ROCK",
    "ENTR_SCENE_FAIRY_FOUNTAIN",
    "ENTR_SCENE_SWAMP_SPIDER_HOUSE",
    "ENTR_SCENE_OCEANSIDE_SPIDER_HOUSE",
    "ENTR_SCENE_ASTRAL_OBSERVATORY",
    "ENTR_SCENE_MOON_DEKU_TRIAL",
    "ENTR_SCENE_DEKU_PALACE",
    "ENTR_SCENE_MOUNTAIN_SMITHY",
    "ENTR_SCENE_TERMINA_FIELD",
    "ENTR_SCENE_POST_OFFICE",
    "ENTR_SCENE_MARINE_RESEARCH_LAB",
    "ENTR_SCENE_DAMPES_HOUSE",
    "ENTR_SCENE_UNSET_2E",
    "ENTR_SCENE_GORON_SHRINE",
    "ENTR_SCENE_ZORA_HALL",
    "ENTR_SCENE_TRADING_POST",
    "ENTR_SCENE_ROMANI_RANCH",
    "ENTR_SCENE_TWINMOLDS_LAIR",
    "ENTR_SCENE_GREAT_BAY_COAST",
    "ENTR_SCENE_ZORA_CAPE",
    "ENTR_SCENE_LOTTERY_SHOP",
    "ENTR_SCENE_UNSET_37",
    "ENTR_SCENE_PIRATES_FORTRESS_EXTERIOR",
    "ENTR_SCENE_FISHERMANS_HUT",
    "ENTR_SCENE_GORON_SHOP",
    "ENTR_SCENE_DEKU_KINGS_CHAMBER",
    "ENTR_SCENE_MOON_GORON_TRIAL",
    "ENTR_SCENE_ROAD_TO_SOUTHERN_SWAMP",
    "ENTR_SCENE_DOGGY_RACETRACK",
    "ENTR_SCENE_CUCCO_SHACK",
    "ENTR_SCENE_IKANA_GRAVEYARD",
    "ENTR_SCENE_GOHTS_LAIR",
    "ENTR_SCENE_SOUTHERN_SWAMP_POISONED",
    "ENTR_SCENE_WOODFALL",
    "ENTR_SCENE_MOON_ZORA_TRIAL",
    "ENTR_SCENE_GORON_VILLAGE_SPRING",
    "ENTR_SCENE_GREAT_BAY_TEMPLE",
    "ENTR_SCENE_WATERFALL_RAPIDS",
    "ENTR_SCENE_BENEATH_THE_WELL",
    "ENTR_SCENE_ZORA_HALL_ROOMS",
    "ENTR_SCENE_GORON_VILLAGE_WINTER",
    "ENTR_SCENE_GORON_GRAVERYARD",
    "ENTR_SCENE_SAKONS_HIDEOUT",
    "ENTR_SCENE_MOUNTAIN_VILLAGE_WINTER",
    "ENTR_SCENE_GHOST_HUT",
    "ENTR_SCENE_DEKU_SHRINE",
    "ENTR_SCENE_ROAD_TO_IKANA",
    "ENTR_SCENE_SWORDMANS_SCHOOL",
    "ENTR_SCENE_MUSIC_BOX_HOUSE",
    "ENTR_SCENE_IGOS_DU_IKANAS_LAIR",
    "ENTR_SCENE_TOURIST_INFORMATION",
    "ENTR_SCENE_STONE_TOWER",
    "ENTR_SCENE_STONE_TOWER_INVERTED",
    "ENTR_SCENE_MOUNTAIN_VILLAGE_SPRING",
    "ENTR_SCENE_PATH_TO_SNOWHEAD",
    "ENTR_SCENE_SNOWHEAD",
    "ENTR_SCENE_PATH_TO_GORON_VILLAGE_WINTER",
    "ENTR_SCENE_PATH_TO_GORON_VILLAGE_SPRING",
    "ENTR_SCENE_GYORGS_LAIR",
    "ENTR_SCENE_SECRET_SHRINE",
    "ENTR_SCENE_STOCK_POT_INN",
    "ENTR_SCENE_GREAT_BAY_CUTSCENE",
    "ENTR_SCENE_CLOCK_TOWER_INTERIOR",
    "ENTR_SCENE_WOODS_OF_MYSTERY",
    "ENTR_SCENE_LOST_WOODS",
    "ENTR_SCENE_MOON_LINK_TRIAL",
    "ENTR_SCENE_THE_MOON",
    "ENTR_SCENE_BOMB_SHOP",
    "ENTR_SCENE_GIANTS_CHAMBER",
    "ENTR_SCENE_GORMAN_TRACK",
    "ENTR_SCENE_GORON_RACETRACK",
    "ENTR_SCENE_EAST_CLOCK_TOWN",
    "ENTR_SCENE_WEST_CLOCK_TOWN",
    "ENTR_SCENE_NORTH_CLOCK_TOWN",
    "ENTR_SCENE_SOUTH_CLOCK_TOWN",
    "ENTR_SCENE_LAUNDRY_POOL",
    "ENTR_SCENE_MAX"
]

def macro(num):
    sceneIndex = (num >> 9) & 0x7F
    spawnIndex = (num >> 4) & 0x1F
    return f'ENTRANCE({entranceScenes[sceneIndex][len(enumPrfix):]}, {spawnIndex})'

if __name__ == "__main__":
    import sys

    if len(sys.argv) < 2:
        print(f'{sys.argv[0]} nextEntrance', file=sys.stderr)
        exit(1)
        
    nextEntrance = sys.argv[1]
    nextEntrance = int(nextEntrance, 16 if nextEntrance.startswith("0x") else 10)
    print(macro(nextEntrance))
