summaryrefslogtreecommitdiff
path: root/Edit-the-Town-Map.md
blob: 477e71cb18c7d7f859411cdad7eb512aa9bd7c6c (plain)
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
The Town Map is a bit tricky to edit: it's one of the only things in pokecrystal that still requires a hex editor. (Some free hex editors for Windows are [FlexHEX](http://www.flexhex.com/), [HxD](https://mh-nexus.de/en/hxd/), [Frhed](http://frhed.sourceforge.net/en/), or [wxHexEditor](https://www.wxhexeditor.org/).) This tutorial will explain how it works.


## Contents

1. [The tileset](#1-the-tileset)
2. [The color palettes](#2-the-color-palettes)
3. [The Johto and Kanto tilemaps](#3-the-johto-and-kanto-tilemaps)
4. [The landmarks](#4-the-landmarks)


## 1. The tileset

Like everything else on the GameBoy, the Town Map is composed of 8x8-pixel tiles. Its tile graphics are stored in [gfx/pokegear/town_map.png](../blob/master/gfx/pokegear/town_map.png):

![gfx/pokegear/town_map.png](screenshots/gfx-pokegear-town_map.png)

You can freely edit this image to change the tiles, but you can't make it larger. That's because all the available tileset space is taken up by Pokégear and font graphics. You can see this in [BGB](http://bgb.bircd.org/)'s VRAM viewer:

![Screenshot](screenshots/town-map-vram.png)

(If you want to add more tiles, there *are* those three unused blank ones on the right side of the tileset. You can also replace the two "-TO" tiles of "KANTO", since they're identical to the "JOHTO" ones.)


## 2. The color palettes

The tileset image is grayscale, but it's colorful in-game. The colors are defined in [gfx/pokegear/pokegear.pal](../blob/master/gfx/pokegear/pokegear.pal) and [gfx/pokegear/pokegear_f.pal](../blob/master/gfx/pokegear/pokegear_f.pal). Each file defines six palettes: for the gray border, the green-on-blue earth, the brown-on-green mountains, etc.

You can view the palette with BGB's VRAM viewer again:

![Screenshot](screenshots/town-map-palette-vram.png)

Anyway, [gfx/pokegear/town_map_palette_map.asm](../blob/master/gfx/pokegear/town_map_palette_map.asm) defines the correspondence between tiles and colors. For example, notice how the nine `MOUNTAIN` entries in that file correspond with the nine mountain tiles in [gfx/pokegear/town_map.png](../blob/master/gfx/pokegear/town_map.png).


## 3. The Johto and Kanto tilemaps

The two regions' maps are actually defined by [gfx/pokegear/johto.bin](../blob/master/gfx/pokegear/johto.bin) and [gfx/pokegear/kanto.bin](../blob/master/gfx/pokegear/kanto.bin). Each of those is a 361-byte binary tilemap: 20x18 bytes covering the entire screen, from top-left to bottom-right, with a $FF at the very end. The bytes are tile IDs, starting at 0. For example, $0A (10 in decimal) is the eleventh tile in the tilemap, the town or city icon. And if you look at where the $0A bytes are in johto.bin and kanto.bin, you'll notice they correspond to the locations of towns and cities.

If your hex editor supports coloring by value, that can make editing a lot easier. For example, here's [Hex Workshop](http://www.hexworkshop.com/) (not a free program) using a custom color map to highlight different tile IDs:

[![Screenshot](screenshots/hex-workshop-johto.png)](screenshots/hex-workshop-johto.png)

[![Screenshot](screenshots/hex-workshop-kanto.png)](screenshots/hex-workshop-kanto.png)

Clearly, those bytes represent these Town Maps:

![gfx/pokegear/johto.bin](screenshots/gfx-pokegear-johto.png)

![gfx/pokegear/kanto.bin](screenshots/gfx-pokegear-kanto.png)


## 4. The landmarks

Landmarks are defined in [data/maps/landmarks.asm](../blob/master/data/maps/landmarks.asm). Each one has an X coordinate, Y coordinate, and name. The coordinates are in pixels from the top-left corner of the 160x140-pixel screen. For example:

```
	landmark 140, 100, NewBarkTownName

...

NewBarkTownName:     db "NEW BARK¯TOWN@"
```

If you look at pixel coordinates (140, 100) in the Johto map above, you'll see it's in the middle of the New Bark Town icon:

![Screenshot](screenshots/ms-paint-johto.png)

Be careful, though! Currently pokecrystal defines the `landmark` macro like this:

```
landmark: MACRO
; x, y, name
	db \1 + 8, \2 + 16
	dw \3
ENDM
```

But versions older than July 18, 2018 define it like this:

```
landmark: MACRO
; x, y, name
	db \1, \2
	dw \3
ENDM
```

This means that older versions of pokecrystal have their landmark X coordinates increased by 8 and their Y coordinates by 16. For example, New Bark Town used to be at (148, 116).

If you're wondering why those offsets exist, it's because of how the GameBoy hardware works. From the [Pan Docs](http://bgb.bircd.org/pandocs.htm#vramspriteattributetableoam):

> **Byte0 - Y Position**  
> Specifies the sprites vertical position on the screen (minus 16).  
> An offscreen value (for example, Y=0 or Y>=160) hides the sprite.
> 
> **Byte1 - X Position**  
> Specifies the sprites horizontal position on the screen (minus 8).  
> An offscreen value (X=0 or X>=168) hides the sprite, but the sprite  
> still affects the priority ordering - a better way to hide a sprite is to set its Y-coordinate offscreen.

For more information on editing landmarks, see the tutorial on [how to add a new map and landmark](Add-a-new-map-and-landmark).