1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
[This tutorial](Edit-the-Town-Map) describes how to edit the Town Map with [Tilemap Studio](https://github.com/Rangi42/tilemap-studio). However, you're limited to using 48 different tiles, which is not enough for more detailed maps. Here we'll see how to use at least 33 more tiles for designing Town Maps.
[This alternate tutorial](Expand-the-Town-Map-tileset-Alternate) shows another way to do the same thing. It's more involved, but allows the Town Map tiles to be consecutive before the Pokégear tiles.
## Contents
1. [Combine the Town Map and Pokégear graphics](#1-combine-the-town-map-and-pokégear-graphics)
2. [Move the "extra" font graphics and use their space](#2-move-the-extra-font-graphics-and-use-their-space)
## 1. Combine the Town Map and Pokégear graphics
The Pokégear graphics are right after the Town Map graphics in VRAM, and they have a couple of unused tiles. Plus [gfx/pokegear/town_map_palette_map.asm](../blob/master/gfx/pokegear/town_map_palette_map.asm) already assigns palettes to them both. It's fairly simple to combine them into a single tileset.
First, edit [gfx/pokegear/town_map.png](../blob/master/gfx/pokegear/town_map.png), appending the [gfx/pokegear/pokegear.png](../blob/master/gfx/pokegear/pokegear.png) tiles to it:

You can then delete [gfx/pokegear/pokegear.png](../blob/master/gfx/pokegear/pokegear.png).
Then edit [main.asm](../blob/master/main.asm):
```diff
SECTION "bank77_2", ROMX
INCLUDE "engine/rtc/print_hours_mins.asm"
INCLUDE "engine/events/diploma.asm"
INCLUDE "engine/pokedex/pokedex_3.asm"
INCLUDE "engine/events/catch_tutorial_input.asm"
INCLUDE "engine/pokegear/townmap_convertlinebreakcharacters.asm"
-
-PokegearGFX:
-INCBIN "gfx/pokegear/pokegear.2bpp.lz"
-
INCLUDE "engine/pokemon/european_mail.asm"
```
Edit the [Makefile](../blob/master/Makefile):
```diff
-gfx/pokegear/pokegear.2bpp: rgbgfx += -x2
```
Edit [gfx/pokegear/town_map_palette_map.asm](../blob/master/gfx/pokegear/town_map_palette_map.asm):
```diff
-; gfx/pokegear/pokegear.png
```
(Removing the Makefile rule and the comment won't really do anything, but it avoids confusion from mentioning a file that we just deleted.)
And edit [engine/pokegear/pokegear.asm](../blob/master/engine/pokegear/pokegear.asm):
```diff
Pokegear_LoadGFX:
call ClearVBank1
ld hl, TownMapGFX
ld de, vTiles2
ld a, BANK(TownMapGFX)
call FarDecompress
- ld hl, PokegearGFX
- ld de, vTiles2 tile $30
- ld a, BANK(PokegearGFX)
- call FarDecompress
ld hl, PokegearSpritesGFX
ld de, vTiles0
ld a, BANK(PokegearSpritesGFX)
call Decompress
...
```
```diff
LoadTownMapGFX:
ld hl, TownMapGFX
ld de, vTiles2
- lb bc, BANK(TownMapGFX), 48
+ lb bc, BANK(TownMapGFX), 96
call DecompressRequest2bpp
ret
```
Now the whole set of 96 tiles gets loaded at once, but there's one flaw. The Pokédex area map only ever loaded the Town Map graphics; it skipped the Pokégear graphics because it used that space for the Pokédex's own graphics. Now that we're treating the Pokégear tiles as just extra Town Map tiles, we need to reload the Pokédex tiles when we close the Area map.
Edit [engine/pokedex/pokedex.asm](../blob/master/engine/pokedex/pokedex.asm):
```diff
DexEntryScreen_MenuActionJumptable:
dw Pokedex_Page
dw .Area
dw .Cry
dw .Print
.Area:
...
ld a, [wDexCurLocation]
ld e, a
predef Pokedex_GetArea
call Pokedex_BlackOutBG
+ call Pokedex_LoadGFX
+ call Pokedex_LoadAnyFootprint
call DelayFrame
...
```
Now we can use tile IDs $30–$5F for the Town Map, not just $00–$2F. Most of them are needed for the Pokégear, but the last two bottom-right blank tiles, $5E and $5F, are unused. Tile $5D is also blank, but it's used once in the Radio Card, so if you overwrite it with graphics for the Town Map, you'll have to replace the byte `5D` with `7F` in [gfx/pokegear/radio.tilemap.rle](../blob/master/gfx/pokegear/radio.tilemap.rle). (You can open \*.tilemap.rle files in Tilemap Studio with the "Pokégear card" format, or use a hex editor.)
Two or three extra tiles isn't much of an advantage; we'd have to simplify the Pokégear graphics to make room for Town Map ones. That *is* possible: some tiles could be eliminated (like the embossed border tiles used only by the Radio Card), and any tile that's just black and white can be moved into [gfx/font/font.png](../blob/master/gfx/font/font.png) and [gfx/font/font_inversed.png](../blob/master/gfx/font/font_inversed.png). However, we'd then have to thoroughly update the gfx/pokegear/\*.tilemap.rle files, and track down all the places in the source code that refer to changed tile IDs, which can be tedious. Luckily there's a more efficient solution.
## 2. Move the "extra" font graphics and use their space
Tiles $00–$2F are the original Town Map graphics, $30–5F are the Pokégear graphics, $60–7E are some "extra" font graphics, $7F is the space character, and $80–$FF are the standard font graphics. We can see how they're laid out in [BGB](http://bgb.bircd.org/)'s VRAM viewer:

Those extra font graphics also take up space that could be used for overworld map tilesets. [**This tutorial**](Expand-tilesets-from-192-to-255-tiles) explains how to expand map tilesets from 192 to 255 tiles, and part of that involves moving the extra font graphcs from tiles $60–7E to within the standard font tile space, $80–FF. (Tile $7F stays as the space character.)
If you haven't followed the 192-to-255-tile tutorial yet, you don't actually have to do the whole thing. Steps 1–5 and 9–10 explain how to move the extra font tiles out of the $60–$7E space, and steps 6–8 explain how to repurpose that space for map tilesets. So if all you care about is the Town Map, you can skip steps 6–8. However, I recommend following the whole tutorial anyway, because if you care about graphics enough to be redesigning the Town Map, you'll probably end up pushing the limits of what 192 map tiles can do.
Anyway, after we combine the Town Map and Pokégear graphics, *and* move the extra font tiles by following [**this tutorial**](Expand-tilesets-from-192-to-255-tiles), then the VRAM looks like this:

Let's enable those 31 tiles for use in the Town Map.
First, edit [gfx/pokegear/town_map.png](../blob/master/gfx/pokegear/town_map.png), adding another two rows of empty tiles:

Note that the bottom-right tile $7F is the space character, so it should stay blank.
Then edit [gfx/pokegear/town_map_palette_map.asm](../blob/master/gfx/pokegear/town_map_palette_map.asm):
```diff
; gfx/pokegear/town_map.png
townmappals EARTH, EARTH, EARTH, MOUNTAIN, MOUNTAIN, MOUNTAIN, BORDER, BORDER
townmappals EARTH, EARTH, CITY, EARTH, POI, POI_MTN, POI, POI_MTN
townmappals EARTH, EARTH, EARTH, MOUNTAIN, MOUNTAIN, MOUNTAIN, BORDER, BORDER
townmappals EARTH, EARTH, BORDER, EARTH, EARTH, BORDER, BORDER, BORDER
townmappals EARTH, EARTH, EARTH, MOUNTAIN, MOUNTAIN, MOUNTAIN, BORDER, BORDER
townmappals BORDER, BORDER, BORDER, BORDER, BORDER, BORDER, BORDER, BORDER
townmappals BORDER, BORDER, BORDER, BORDER, POI, POI, POI, BORDER
townmappals BORDER, BORDER, BORDER, BORDER, BORDER, BORDER, BORDER, BORDER
townmappals CITY, CITY, CITY, CITY, CITY, CITY, CITY, CITY
townmappals CITY, CITY, CITY, CITY, CITY, CITY, CITY, BORDER
townmappals CITY, CITY, CITY, CITY, CITY, CITY, CITY, CITY
townmappals BORDER, BORDER, BORDER, BORDER, BORDER, BORDER, BORDER, BORDER
+ townmappals BORDER, BORDER, BORDER, BORDER, BORDER, BORDER, BORDER, BORDER
+ townmappals BORDER, BORDER, BORDER, BORDER, BORDER, BORDER, BORDER, BORDER
+ townmappals BORDER, BORDER, BORDER, BORDER, BORDER, BORDER, BORDER, BORDER
+ townmappals BORDER, BORDER, BORDER, BORDER, BORDER, BORDER, BORDER, BORDER
```
And edit [engine/pokegear/pokegear.asm](../blob/master/engine/pokegear/pokegear.asm):
```diff
TownMapPals:
; Assign palettes based on tile ids
hlcoord 0, 0
decoord 0, 0, wAttrmap
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
.loop
; Current tile
ld a, [hli]
push hl
-; The palette map covers tiles $00 to $5f; $60 and above use palette 0
- cp $60
+; The palette map covers tiles $00 to $7e; $7f and above use palette 0
+ cp $7f
jr nc, .pal0
...
```
```diff
LoadTownMapGFX:
ld hl, TownMapGFX
ld de, vTiles2
- lb bc, BANK(TownMapGFX), 96
+ lb bc, BANK(TownMapGFX), 127
call DecompressRequest2bpp
ret
```
Now we're done! With extra tiles and custom colors, your project can have a really unique Town Map:

(Example Town Maps: FRLG-style Kanto by Rangi, HGSS-style Johto from [Polished Crystal](https://github.com/Rangi42/polishedcrystal), RSE-style Hoenn by SaveState, DPPt-style Sinnoh by SaveState, Unova by JaceDeane, and Invar by Wasabi_Raptor for [Brass](https://github.com/WasabiRaptor/pokebrass).)
|