|
@@ -20,31 +20,75 @@
|
20
|
20
|
#include "banks.h"
|
21
|
21
|
#include "title_map.h"
|
22
|
22
|
#include "bg_map.h"
|
|
23
|
+#include "util.h"
|
23
|
24
|
#include "maps.h"
|
24
|
25
|
|
|
26
|
+#define POS_SCALE_BG 6
|
|
27
|
+
|
|
28
|
+// define this to disable mirrored map scaling support
|
|
29
|
+#define WRAP_BG // TODO
|
|
30
|
+
|
|
31
|
+#define bg_map_mapWidth (bg_map_WIDTH / bg_map_TILE_W)
|
|
32
|
+#define bg_map_mapHeight (bg_map_HEIGHT / bg_map_TILE_H)
|
|
33
|
+
|
|
34
|
+#define camera_max_x ((bg_map_mapWidth - DEVICE_SCREEN_WIDTH) * 8)
|
|
35
|
+#define camera_max_y ((bg_map_mapHeight - DEVICE_SCREEN_HEIGHT) * 8)
|
|
36
|
+
|
|
37
|
+#define set_bkg_sub_attr(x, y, w, h, attr, map_w) \
|
|
38
|
+ if (attr) \
|
|
39
|
+ set_bkg_submap_attributes(x, y, w, h, attr, map_w)
|
|
40
|
+
|
|
41
|
+#define set_bkg_sub(x, y, w, h, map, attr, map_w) \
|
|
42
|
+ set_bkg_submap(x, y, w, h, map, map_w); \
|
|
43
|
+ set_bkg_sub_attr(x, y, w, h, attr, map_w)
|
|
44
|
+
|
|
45
|
+// current unscaled ship position
|
|
46
|
+static uint16_t abs_x, abs_y;
|
|
47
|
+
|
|
48
|
+// current and old positions of the camera in pixels
|
|
49
|
+static uint16_t camera_x, camera_y, old_camera_x, old_camera_y;
|
|
50
|
+
|
|
51
|
+// current and old position of the map in tiles
|
|
52
|
+static uint8_t map_pos_x, map_pos_y, old_map_pos_x, old_map_pos_y;
|
|
53
|
+
|
25
|
54
|
void map_title(void) NONBANKED {
|
26
|
55
|
START_ROM_BANK(BANK(title_map));
|
|
56
|
+
|
27
|
57
|
set_bkg_palette(OAMF_CGB_PAL0, title_map_PALETTE_COUNT, title_map_palettes);
|
28
|
58
|
set_bkg_data(0, title_map_TILE_COUNT, title_map_tiles);
|
|
59
|
+
|
29
|
60
|
if (title_map_MAP_ATTRIBUTES != NULL) {
|
30
|
61
|
set_bkg_attributes(0, 0,
|
31
|
|
- title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H,
|
|
62
|
+ title_map_WIDTH / title_map_TILE_W,
|
|
63
|
+ title_map_HEIGHT / title_map_TILE_H,
|
32
|
64
|
title_map_MAP_ATTRIBUTES);
|
33
|
65
|
} else {
|
34
|
66
|
VBK_REG = VBK_ATTRIBUTES;
|
35
|
67
|
fill_bkg_rect(0, 0,
|
36
|
|
- title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H,
|
|
68
|
+ title_map_WIDTH / title_map_TILE_W,
|
|
69
|
+ title_map_HEIGHT / title_map_TILE_H,
|
37
|
70
|
0x00);
|
38
|
71
|
VBK_REG = VBK_TILES;
|
39
|
72
|
}
|
40
|
|
- set_bkg_tiles(0, 0, title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H, title_map_map);
|
|
73
|
+
|
|
74
|
+ set_bkg_tiles(0, 0,
|
|
75
|
+ title_map_WIDTH / title_map_TILE_W,
|
|
76
|
+ title_map_HEIGHT / title_map_TILE_H,
|
|
77
|
+ title_map_map);
|
|
78
|
+
|
41
|
79
|
END_ROM_BANK();
|
|
80
|
+
|
|
81
|
+ move_bkg(0, 0);
|
42
|
82
|
}
|
43
|
83
|
|
44
|
84
|
void map_game(void) NONBANKED {
|
45
|
85
|
START_ROM_BANK(BANK(bg_map));
|
|
86
|
+
|
46
|
87
|
set_bkg_palette(OAMF_CGB_PAL0, bg_map_PALETTE_COUNT, bg_map_palettes);
|
47
|
88
|
set_bkg_data(0, bg_map_TILE_COUNT, bg_map_tiles);
|
|
89
|
+
|
|
90
|
+#ifdef WRAP_BG
|
|
91
|
+
|
48
|
92
|
if (bg_map_MAP_ATTRIBUTES != NULL) {
|
49
|
93
|
set_bkg_attributes(0, 0,
|
50
|
94
|
bg_map_WIDTH / bg_map_TILE_W, bg_map_HEIGHT / bg_map_TILE_H,
|
|
@@ -57,5 +101,88 @@ void map_game(void) NONBANKED {
|
57
|
101
|
VBK_REG = VBK_TILES;
|
58
|
102
|
}
|
59
|
103
|
set_bkg_tiles(0, 0, bg_map_WIDTH / bg_map_TILE_W, bg_map_HEIGHT / bg_map_TILE_H, bg_map_map);
|
|
104
|
+
|
|
105
|
+#else // WRAP_BG
|
|
106
|
+
|
|
107
|
+ abs_x = 0;
|
|
108
|
+ abs_y = 0;
|
|
109
|
+
|
|
110
|
+ // Initial camera position in pixels set here.
|
|
111
|
+ camera_x = 0;
|
|
112
|
+ camera_y = 0;
|
|
113
|
+
|
|
114
|
+ // Enforce map limits on initial camera position
|
|
115
|
+ if (camera_x > camera_max_x) camera_x = camera_max_x;
|
|
116
|
+ if (camera_y > camera_max_y) camera_y = camera_max_y;
|
|
117
|
+ old_camera_x = camera_x; old_camera_y = camera_y;
|
|
118
|
+
|
|
119
|
+ map_pos_x = camera_x >> 3;
|
|
120
|
+ map_pos_y = camera_y >> 3;
|
|
121
|
+ old_map_pos_x = old_map_pos_y = 255;
|
|
122
|
+
|
|
123
|
+ move_bkg(camera_x, camera_y);
|
|
124
|
+
|
|
125
|
+ // Draw the initial map view for the whole screen
|
|
126
|
+ set_bkg_sub(map_pos_x, map_pos_y,
|
|
127
|
+ MIN(DEVICE_SCREEN_WIDTH + 1u, bg_map_mapWidth - map_pos_x),
|
|
128
|
+ MIN(DEVICE_SCREEN_HEIGHT + 1u, bg_map_mapHeight - map_pos_y),
|
|
129
|
+ bg_map_map, bg_map_MAP_ATTRIBUTES, bg_map_mapWidth);
|
|
130
|
+
|
|
131
|
+#endif // WRAP_BG
|
|
132
|
+
|
60
|
133
|
END_ROM_BANK();
|
61
|
134
|
}
|
|
135
|
+
|
|
136
|
+void map_move(int16_t delta_x, int16_t delta_y) NONBANKED {
|
|
137
|
+ abs_x += delta_x;
|
|
138
|
+ abs_y += delta_y;
|
|
139
|
+
|
|
140
|
+ camera_x = abs_x >> POS_SCALE_BG;
|
|
141
|
+ camera_y = abs_y >> POS_SCALE_BG;
|
|
142
|
+
|
|
143
|
+ // update hardware scroll position
|
|
144
|
+ move_bkg(camera_x, camera_y);
|
|
145
|
+
|
|
146
|
+#ifndef WRAP_BG
|
|
147
|
+
|
|
148
|
+ map_pos_y = (uint8_t)(camera_y >> 3u);
|
|
149
|
+ map_pos_x = (uint8_t)(camera_x >> 3u);
|
|
150
|
+
|
|
151
|
+ START_ROM_BANK(BANK(bg_map));
|
|
152
|
+
|
|
153
|
+ // up or down
|
|
154
|
+ if (map_pos_y != old_map_pos_y) {
|
|
155
|
+ if (camera_y < old_camera_y) {
|
|
156
|
+ set_bkg_sub(map_pos_x, map_pos_y,
|
|
157
|
+ MIN(DEVICE_SCREEN_WIDTH + 1, bg_map_mapWidth-map_pos_x), 1,
|
|
158
|
+ bg_map_map, bg_map_MAP_ATTRIBUTES, bg_map_mapWidth);
|
|
159
|
+ } else if ((bg_map_mapHeight - DEVICE_SCREEN_HEIGHT) > map_pos_y) {
|
|
160
|
+ set_bkg_sub(map_pos_x, map_pos_y + DEVICE_SCREEN_HEIGHT,
|
|
161
|
+ MIN(DEVICE_SCREEN_WIDTH + 1, bg_map_mapWidth-map_pos_x), 1,
|
|
162
|
+ bg_map_map, bg_map_MAP_ATTRIBUTES, bg_map_mapWidth);
|
|
163
|
+ }
|
|
164
|
+ old_map_pos_y = map_pos_y;
|
|
165
|
+ }
|
|
166
|
+
|
|
167
|
+ // left or right
|
|
168
|
+ if (map_pos_x != old_map_pos_x) {
|
|
169
|
+ if (camera_x < old_camera_x) {
|
|
170
|
+ set_bkg_sub(map_pos_x, map_pos_y,
|
|
171
|
+ 1, MIN(DEVICE_SCREEN_HEIGHT + 1, bg_map_mapHeight - map_pos_y),
|
|
172
|
+ bg_map_map, bg_map_MAP_ATTRIBUTES, bg_map_mapWidth);
|
|
173
|
+ } else if ((bg_map_mapWidth - DEVICE_SCREEN_WIDTH) > map_pos_x) {
|
|
174
|
+ set_bkg_sub(map_pos_x + DEVICE_SCREEN_WIDTH, map_pos_y,
|
|
175
|
+ 1, MIN(DEVICE_SCREEN_HEIGHT + 1, bg_map_mapHeight - map_pos_y),
|
|
176
|
+ bg_map_map, bg_map_MAP_ATTRIBUTES, bg_map_mapWidth);
|
|
177
|
+ }
|
|
178
|
+ old_map_pos_x = map_pos_x;
|
|
179
|
+ }
|
|
180
|
+
|
|
181
|
+ END_ROM_BANK();
|
|
182
|
+
|
|
183
|
+ // set old camera position to current camera position
|
|
184
|
+ old_camera_x = camera_x;
|
|
185
|
+ old_camera_y = camera_y;
|
|
186
|
+
|
|
187
|
+#endif // ! WRAP_BG
|
|
188
|
+}
|