Skip to content

Maps that require Flash

Whatever-Man edited this page Apr 15, 2022 · 9 revisions

This tutorial is for how to edit which maps require FLASH to see in.

Contents

Location of original code

The location of where this is found is in home/overworld.asm. Credit goes to wrulfy on the pret Discord server for finding it.

Specifically it is under the WarpFound2:: section

Original code:

WarpFound2::
	ld a, [wNumberOfWarps]
	sub c
	ld [wWarpedFromWhichWarp], a ; save ID of used warp
	ld a, [wCurMap]
	ld [wWarpedFromWhichMap], a
	call CheckIfInOutsideMap
	jr nz, .indoorMaps
; this is for handling "outside" maps that can't have the 0xFF destination map
	ld a, [wCurMap]
	ld [wLastMap], a
	ld a, [wCurMapWidth]
	ld [wUnusedD366], a ; not read
	ldh a, [hWarpDestinationMap]
	ld [wCurMap], a
	cp ROCK_TUNNEL_1F
	jr nz, .notRockTunnel
	ld a, $06
	ld [wMapPalOffset], a
	call GBFadeOutToBlack
.notRockTunnel
	call PlayMapChangeSound
	jr .done

0. Understanding the code setup for what needs FLASH

What matters to us are the few lines at and after "cp ROCK_TUNNEL_1F" which are shown here below for simplification.

	cp ROCK_TUNNEL_1F
	jr nz, .notRockTunnel
	ld a, $06
	ld [wMapPalOffset], a
	call GBFadeOutToBlack
.notRockTunnel
	call PlayMapChangeSound
	jr .done

Now to understand, I'm going to separate it up even more.

When entering a new map, this line checks if the new map is ROCK_TUNNEL_1F or more simply maps\RockTunnel1F.blk

	cp ROCK_TUNNEL_1F

The next line gives a divergent destination based on if yes/no. "jr" means "Jump to close location". "nz" means "If equals zero", or in other words, "If not RockTunnel", since that is what we checked for. It translates to "If not ROCK_TUNNEL_1F, then go to the sub-section ".notRockTunnel"

	jr nz, .notRockTunnel

If it is sent to the sub-section ".notRockTunnel", then it jumps (jr) here.

.notRockTunnel

Based on if .notRockTunnel or ROCK_TUNNEL_1F, will load 2 separate states. Below is if it is a normal (no FLASH needed) map. Nothing fancy, just loads the new map normally.

	call PlayMapChangeSound

This is if it is meant to load a FLASH-required map. It is what sets up "needs FLASH to see".

	ld a, $06
	ld [wMapPalOffset], a
	call GBFadeOutToBlack

This is the termination of the entire action.

	jr .done

1. Prepping the code for additions

The problem with the original code is how it treats the default and the exception. Due to the exception being .notRockTunnel, that means the default is Rock Tunnel. Which is fine for only have a single FLASH-required location. But we want more than just that.

So first we are going to change the code to treat the default state as normal, and the exception to the rule as "needing FLASH".

The base step is to change the "if, then jump" line. What this will do is instead of a "not, then jump" we'll have a "yes, then jump" action.

-	jr nz, .notRockTunnel
+	jr n, .yesRockTunnel

Then we need to rename the jumped to location.

-.notRockTunnel
+.yesRockTunnel

Next we need to swap what is loaded via the default and the exception.

Default state:

-	ld a, $06
-	ld [wMapPalOffset], a
-	call GBFadeOutToBlack
+	call PlayMapChangeSound

Exception state:

-	call PlayMapChangeSound
+	ld a, $06
+	ld [wMapPalOffset], a
+	call GBFadeOutToBlack

So what the entire section we changed should look like is the following:

	cp ROCK_TUNNEL_1F
-	jr nz, .notRockTunnel        ; Old ; If no, then jump to exception
+	jr n, .yesRockTunnel         ; New ; If yes, then jump to exception. 
-	ld a, $06                    ; Old Normal ; needs FLASH
-	ld [wMapPalOffset], a        ; Old Normal ; needs FLASH
-	call GBFadeOutToBlack        ; Old Normal ; needs FLASH
+	call PlayMapChangeSound      ; New Normal ; no FLASH needed
-.notRockTunnel
+.yesRockTunnel
-	call PlayMapChangeSound      ; Old Exception ; no FLASH needed
+	ld a, $06                    ; New Exception ; needs FLASH
+	ld [wMapPalOffset], a        ; New Exception ; needs FLASH
+	call GBFadeOutToBlack        ; New Exception ; needs FLASH
	jr .done

Having made this change will have no discernible effect in game thus far. But we'll have prepped the code for easy addition of other maps to require FLASH.

2. Implementing a map

This is the easiest part. All we have to do is add in a new "check & jump" to the section.

For example, if I wanted to make the Power Plant require FLASH then I would need to create and insert the following.

	cp POWER_PLANT               ; Checks if POWER_PLANT
	jr n, .yesPowerPlant         ; If yes, then jump to .yesPowerPlant
.yesPowerPlant
	ld a, $06                    ; New Exception ; needs FLASH
	ld [wMapPalOffset], a        ; New Exception ; needs FLASH
	call GBFadeOutToBlack        ; New Exception ; needs FLASH

We just have to insert the check after the Rock Tunnel check and the jump location after the .yesRockTunnel location.

So the end result would be as follows:

	cp ROCK_TUNNEL_1F            ; Checks if ROCK_TUNNEL_1F
	jr n, .yesRockTunnel         ; If yes, then jump to .yesRockTunnel 
+	cp POWER_PLANT               ; Checks if POWER_PLANT
+	jr n, .yesPowerPlant         ; If yes, then jump to .yesPowerPlant
	call PlayMapChangeSound      ; New Normal ; no FLASH needed
.yesRockTunnel
	ld a, $06                    ; New Exception ; needs FLASH
	ld [wMapPalOffset], a        ; New Exception ; needs FLASH
	call GBFadeOutToBlack        ; New Exception ; needs FLASH
+.yesPowerPlant
+	ld a, $06                    ; New Exception ; needs FLASH
+	ld [wMapPalOffset], a        ; New Exception ; needs FLASH
+	call GBFadeOutToBlack        ; New Exception ; needs FLASH
	jr .done

3. Code cleanup

If you plan on adding a significant number of locations, changing a bit might be best to have a cleaner code. Renaming the exception for ease.

	cp ROCK_TUNNEL_1F            ; Checks if ROCK_TUNNEL_1F
-	jr nz, .notRockTunnel
+	jr n, .yesFlashNeeded        ; New exception name & condition
+	cp POWER_PLANT               ; Checks if POWER_PLANT
+	jr n, .yesFlashNeeded        ; New exception name & condition
-	ld a, $06
-	ld [wMapPalOffset], a
-	call GBFadeOutToBlack
+	call PlayMapChangeSound      ; New Normal ; no FLASH needed
-.notRockTunnel
+.yesFlashNeeded
-	call PlayMapChangeSound
+	ld a, $06                    ; New Exception ; needs FLASH
+	ld [wMapPalOffset], a        ; New Exception ; needs FLASH
+	call GBFadeOutToBlack        ; New Exception ; needs FLASH
	jr .done


Add as many location as you want, with the requirement being, it must be entered from the Overworld. 
Clone this wiki locally