Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; (C)2021 Fox Cunning
- ; This code is licensed under MIT license
- ; (see https://opensource.org/licenses/MIT for details)
- ; -----------------------------------------------------------------------------
- ; Map data table:
- ; Byte 0 = ROM Bank, Byte 1 = Entrance Y, Byte 2 = Entrance X, Byte 3 = Flags (bits 5-7) / ID (bits 0-4)
- ; Flags: bit 7 = dungeon, bit 6 = no guards, bit 5 = continent
- ; ID for continents must be $00-$03, towns and castles $04-$1F
- ; Dungeons are handled separately and can have any ID even if it's the same as a non-dungeon map
- ; Map pointers table:
- ; Bytes 0-1 = Map data pointer, Bytes 2-3 = NPC data pointer
- ; 48 maps + 8 dungeons
- ; 8 town entrances + 2 castle entrances + 8 dungeon entrances per continent
- ; Continent indices: $00, $0B, $14, $1F
- TownAndCastleEntrances = $E872
- DungeonEntrances = $FB50
- ; Y = A = Tile ID
- *=$C427
- EntranceTile:
- cmp #$0D ; Castle tile ID
- beq _towns
- cmp #$0E ; Dungeon tile ID
- beq _dungeons
- ; #$0F = Town tile ID
- ; The town tile ID is used for the alternative grass tile in towns and castles,
- ; so make sure we are in a continent before trying to use it as an entrance
- _towns:
- ; Make sure this map is a continent
- lda _Map_Flags_ID
- cmp #$04
- bcc $C3FD ; No entrances from this map
- ; Prepare pointer
- ldy _Map_Flags_ID
- lda TownEntrancePointers,Y
- sta $29 ; Low byte
- lda #$E8 ; High byte always $E8
- sta $2A
- ldy #$00
- _entranceLoop:
- lda ($29),Y
- cmp _PartyX
- bne _nextEntrance
- iny
- lda ($29),Y
- cmp _PartyY
- bne _nextEntrance_1
- _entranceFound:
- ; New map index = current map Id + (Y / 2)
- tya
- lsr A
- clc
- adc _CurrentMapId
- sta _CurrentMapId
- asl A
- asl A
- tax
- ldy #$08
- lda MapDataTable+3,X ; Map flags
- jsr GetContinentFlag
- sty _Map_Flags
- and #$1F
- sta _Map_Flags_ID
- lda _PartyX
- sta $4C ; Save overworld party location
- lda _PartyY
- sta $4B ; Will be used when leaving a town/castle
- jmp RequestNewMap_Params
- _nextEntrance:
- iny
- _nextEntrance_1:
- iny
- cmp #$14
- bcc _townEntranceLoop
- jmp $C3FD ; No entrance found at these coordinates
- TownEntrancePointers:
- ; Low byte only: high byte is always $E8
- .byte $72, $7C, $86, $90
- _dungeons:
- ; Backup previous map (needed to set entry point)
- lda _CurrentMapId
- sta $4F
- ; Prepare pointer
- ldy _Map_Flags_ID
- lda DungeonEntrancePointers,Y
- sta $29 ; Low byte
- lda #$FB
- sta $2A ; High byte is always $FB
- ldy #$00
- _dungeonEntranceLoop:
- lda ($29),Y
- cmp _PartyX
- bne _nextDungeonEntrance
- iny
- lda ($29),Y
- cmp _PartyY
- bne _nextDungeonEntrance_1
- _dungeonEntranceFound:
- ; New map index = $28 + (Y / 2)
- tya
- lsr A
- clc
- adc #$28
- sta _CurrentMapId
- asl
- asl
- tax
- ldy #$09
- lda MapDataTable+3,X ; Map flags
- sty _Map_Flags
- and #$1F
- sta _Map_Flags_ID
- ; Don't bother saving the previous party location: it won't be used when
- ; leaving a dungeon map
- jmp RequestNewMap_Params
- _nextDungeonEntrance:
- iny
- _nextDungeonEntrance_1:
- iny
- cmp #$10
- bcc _dungeonEntranceLoop
- jmp $C3FD ; No entrance found at these coordinates
- DungeonEntrancePointers:
- ; Low byte only: high byte is always $FB
- .byte $50, $60, $70, $80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement