|
@@ -44,17 +44,18 @@ static_assert(bg_map_HEIGHT == 256, "bg_map needs to be 256x256");
|
44
|
44
|
#define camera_max_y ((bg_map_mapHeight - DEVICE_SCREEN_HEIGHT) * 8)
|
45
|
45
|
|
46
|
46
|
#define MAP_FLIP_NONE 0x00
|
47
|
|
-#define MAP_FLIP_X 0x01 //(0x20 | 0x01)
|
48
|
|
-#define MAP_FLIP_Y 0x02 //(0x40 | 0x02)
|
|
47
|
+#define MAP_FLIP_X (0x20)// | 0x01)
|
|
48
|
+#define MAP_FLIP_Y (0x40)// | 0x02)
|
|
49
|
+#define MAP_FLIP_XY (MAP_FLIP_X | MAP_FLIP_Y)
|
49
|
50
|
|
50
|
51
|
// current unscaled ship position
|
51
|
52
|
static uint16_t abs_x, abs_y;
|
52
|
53
|
|
53
|
54
|
// current and old positions of the camera in pixels
|
54
|
|
-static uint16_t camera_x, camera_y, old_camera_x, old_camera_y;
|
|
55
|
+static uint16_t old_camera_x, old_camera_y;
|
55
|
56
|
|
56
|
57
|
// current and old position of the map in tiles
|
57
|
|
-static uint8_t map_pos_x, map_pos_y, old_map_pos_x, old_map_pos_y;
|
|
58
|
+static uint8_t old_map_pos_x, old_map_pos_y;
|
58
|
59
|
|
59
|
60
|
void map_title(void) NONBANKED {
|
60
|
61
|
START_ROM_BANK(BANK(title_map)) {
|
|
@@ -105,15 +106,17 @@ static inline void set_bkg_sub(uint8_t x, uint8_t y,
|
105
|
106
|
const uint8_t *map, const uint8_t *attr,
|
106
|
107
|
uint8_t attr_val,
|
107
|
108
|
uint8_t map_w) {
|
108
|
|
- set_bkg_submap(x, y, w, h, map, map_w);
|
109
|
|
- set_bkg_sub_attr(x, y, w, h, attr, attr_val, map_w);
|
|
109
|
+ START_ROM_BANK(BANK(bg_map)) {
|
|
110
|
+ set_bkg_submap(x, y, w, h, map, map_w);
|
|
111
|
+ set_bkg_sub_attr(x, y, w, h, attr, attr_val, map_w);
|
|
112
|
+ } END_ROM_BANK
|
110
|
113
|
}
|
111
|
114
|
|
112
|
115
|
void map_game(void) NONBANKED {
|
113
|
116
|
START_ROM_BANK(BANK(bg_map)) {
|
114
|
|
-
|
115
|
117
|
set_bkg_palette(OAMF_CGB_PAL0, bg_map_PALETTE_COUNT, bg_map_palettes);
|
116
|
118
|
set_bkg_data(0, bg_map_TILE_COUNT, bg_map_tiles);
|
|
119
|
+ } END_ROM_BANK
|
117
|
120
|
|
118
|
121
|
#ifdef WRAP_BG
|
119
|
122
|
|
|
@@ -132,91 +135,92 @@ void map_game(void) NONBANKED {
|
132
|
135
|
|
133
|
136
|
#else // WRAP_BG
|
134
|
137
|
|
135
|
|
- abs_x = 0;
|
136
|
|
- abs_y = 0;
|
137
|
|
-
|
138
|
|
- // Initial camera position in pixels set here.
|
139
|
|
- camera_x = 0;
|
140
|
|
- camera_y = 0;
|
|
138
|
+ abs_x = 0;
|
|
139
|
+ abs_y = 0;
|
|
140
|
+ old_camera_x = 0;
|
|
141
|
+ old_camera_y = 0;
|
|
142
|
+ old_map_pos_x = 0;
|
|
143
|
+ old_map_pos_y = 0;
|
141
|
144
|
|
142
|
|
- // Enforce map limits on initial camera position
|
143
|
|
- if (camera_x > camera_max_x) camera_x = camera_max_x;
|
144
|
|
- if (camera_y > camera_max_y) camera_y = camera_max_y;
|
145
|
|
- old_camera_x = camera_x; old_camera_y = camera_y;
|
146
|
|
-
|
147
|
|
- map_pos_x = camera_x >> 3;
|
148
|
|
- map_pos_y = camera_y >> 3;
|
149
|
|
- old_map_pos_x = old_map_pos_y = 255;
|
150
|
|
-
|
151
|
|
- move_bkg(camera_x, camera_y);
|
|
145
|
+ move_bkg(0, 0);
|
152
|
146
|
|
153
|
|
- // Draw the initial map view for the whole screen
|
154
|
|
- set_bkg_sub(map_pos_x, map_pos_y,
|
155
|
|
- MIN(DEVICE_SCREEN_WIDTH + 1u, bg_map_mapWidth - map_pos_x),
|
156
|
|
- MIN(DEVICE_SCREEN_HEIGHT + 1u, bg_map_mapHeight - map_pos_y),
|
157
|
|
- bg_map_map, bg_map_MAP_ATTRIBUTES, MAP_FLIP_NONE, bg_map_mapWidth);
|
|
147
|
+ // Draw the initial map view for the whole screen
|
|
148
|
+ set_bkg_sub(0, 0,
|
|
149
|
+ MIN(DEVICE_SCREEN_WIDTH + 1u, bg_map_mapWidth),
|
|
150
|
+ MIN(DEVICE_SCREEN_HEIGHT + 1u, bg_map_mapHeight),
|
|
151
|
+ bg_map_map, bg_map_MAP_ATTRIBUTES, MAP_FLIP_NONE, bg_map_mapWidth);
|
158
|
152
|
|
159
|
153
|
#endif // WRAP_BG
|
|
154
|
+}
|
160
|
155
|
|
|
156
|
+static inline void set(uint8_t dst_x, uint8_t dst_y,
|
|
157
|
+ uint8_t src_x, uint8_t src_y,
|
|
158
|
+ uint8_t attr) {
|
|
159
|
+ START_ROM_BANK(BANK(bg_map)) {
|
|
160
|
+ set_bkg_tile_xy(dst_x, dst_y, bg_map_map[src_x + (src_y * (bg_map_WIDTH / bg_map_TILE_W))]);
|
|
161
|
+ set_bkg_attribute_xy(dst_x, dst_y, attr);
|
161
|
162
|
} END_ROM_BANK
|
162
|
163
|
}
|
163
|
164
|
|
164
|
165
|
void map_move(int16_t delta_x, int16_t delta_y) NONBANKED {
|
165
|
|
- // TODO
|
166
|
|
- if ((delta_x < 0) && (camera_x == 0)) delta_x = 0;
|
167
|
|
- if ((delta_x > 0) && (camera_x >= camera_max_x)) delta_x = 0;
|
168
|
|
- if ((delta_y < 0) && (camera_y == 0)) delta_y = 0;
|
169
|
|
- if ((delta_y > 0) && (camera_y >= camera_max_y)) delta_y = 0;
|
170
|
|
-
|
171
|
166
|
abs_x += delta_x;
|
172
|
167
|
abs_y += delta_y;
|
173
|
168
|
|
174
|
|
- camera_x = abs_x >> POS_SCALE_BG;
|
175
|
|
- camera_y = abs_y >> POS_SCALE_BG;
|
176
|
|
-
|
177
|
|
- // TODO
|
178
|
|
- if (camera_x > camera_max_x) camera_x = camera_max_x;
|
179
|
|
- if (camera_y > camera_max_y) camera_y = camera_max_y;
|
|
169
|
+ uint16_t camera_x = abs_x >> POS_SCALE_BG;
|
|
170
|
+ uint16_t camera_y = abs_y >> POS_SCALE_BG;
|
180
|
171
|
|
181
|
|
- // update hardware scroll position
|
182
|
172
|
move_bkg(camera_x, camera_y);
|
183
|
173
|
|
184
|
174
|
#ifndef WRAP_BG
|
185
|
175
|
|
186
|
|
- map_pos_y = (uint8_t)(camera_y >> 3u);
|
187
|
|
- map_pos_x = (uint8_t)(camera_x >> 3u);
|
188
|
|
-
|
189
|
|
- START_ROM_BANK(BANK(bg_map)) {
|
190
|
|
-
|
191
|
|
- // up or down
|
192
|
|
- if (map_pos_y != old_map_pos_y) {
|
193
|
|
- if (camera_y < old_camera_y) {
|
194
|
|
- set_bkg_sub(map_pos_x, map_pos_y,
|
195
|
|
- MIN(DEVICE_SCREEN_WIDTH + 1, bg_map_mapWidth - map_pos_x), 1,
|
196
|
|
- bg_map_map, bg_map_MAP_ATTRIBUTES, MAP_FLIP_Y, bg_map_mapWidth);
|
197
|
|
- } else if ((bg_map_mapHeight - DEVICE_SCREEN_HEIGHT) > map_pos_y) {
|
198
|
|
- set_bkg_sub(map_pos_x, map_pos_y + DEVICE_SCREEN_HEIGHT,
|
199
|
|
- MIN(DEVICE_SCREEN_WIDTH + 1, bg_map_mapWidth - map_pos_x), 1,
|
200
|
|
- bg_map_map, bg_map_MAP_ATTRIBUTES, MAP_FLIP_NONE, bg_map_mapWidth);
|
|
176
|
+ uint8_t map_pos_x = camera_x >> 3;
|
|
177
|
+ uint8_t map_pos_y = camera_y >> 3;
|
|
178
|
+
|
|
179
|
+ uint8_t is_flipped_x_left = (camera_x >> 4) & 0x01;
|
|
180
|
+ uint8_t is_flipped_x_right = ((camera_x >> 4) + DEVICE_SCREEN_WIDTH) & 0x01;
|
|
181
|
+ uint8_t is_flipped_y_top = (camera_y >> 4) & 0x01;
|
|
182
|
+ uint8_t is_flipped_y_bottom = ((camera_y >> 4) + DEVICE_SCREEN_HEIGHT) & 0x01;
|
|
183
|
+
|
|
184
|
+ if (map_pos_x != old_map_pos_x) {
|
|
185
|
+ old_map_pos_x = map_pos_x;
|
|
186
|
+
|
|
187
|
+ if (camera_x < old_camera_x) {
|
|
188
|
+ // moving left
|
|
189
|
+ set_bkg_sub(map_pos_x, map_pos_y,
|
|
190
|
+ 1, MIN(DEVICE_SCREEN_HEIGHT + 1, bg_map_mapHeight - map_pos_y),
|
|
191
|
+ bg_map_map, bg_map_MAP_ATTRIBUTES, MAP_FLIP_X, bg_map_mapWidth);
|
|
192
|
+ } else if ((bg_map_mapWidth - DEVICE_SCREEN_WIDTH) > map_pos_x) {
|
|
193
|
+ // moving right
|
|
194
|
+ /*
|
|
195
|
+ set_bkg_sub(map_pos_x + DEVICE_SCREEN_WIDTH, map_pos_y,
|
|
196
|
+ 1, MIN(DEVICE_SCREEN_HEIGHT + 1, bg_map_mapHeight - map_pos_y),
|
|
197
|
+ bg_map_map, bg_map_MAP_ATTRIBUTES, MAP_FLIP_NONE, bg_map_mapWidth);
|
|
198
|
+ */
|
|
199
|
+ for (uint8_t i = 0; i < DEVICE_SCREEN_HEIGHT; i++) {
|
|
200
|
+ uint8_t is_flipped_y = i & 0x01;
|
|
201
|
+ set(map_pos_x + DEVICE_SCREEN_WIDTH, map_pos_y,
|
|
202
|
+ is_flipped_x_right ? bg_map_mapWidth - map_pos_x : map_pos_x,
|
|
203
|
+ is_flipped_y ? bg_map_mapHeight - map_pos_y : map_pos_y,
|
|
204
|
+ is_flipped_y ? (is_flipped_x_right ? MAP_FLIP_XY : MAP_FLIP_Y) : (is_flipped_x_right ? MAP_FLIP_X : MAP_FLIP_NONE));
|
201
|
205
|
}
|
202
|
|
- old_map_pos_y = map_pos_y;
|
203
|
206
|
}
|
|
207
|
+ }
|
204
|
208
|
|
205
|
|
- // left or right
|
206
|
|
- if (map_pos_x != old_map_pos_x) {
|
207
|
|
- if (camera_x < old_camera_x) {
|
208
|
|
- set_bkg_sub(map_pos_x, map_pos_y,
|
209
|
|
- 1, MIN(DEVICE_SCREEN_HEIGHT + 1, bg_map_mapHeight - map_pos_y),
|
210
|
|
- bg_map_map, bg_map_MAP_ATTRIBUTES, MAP_FLIP_X, bg_map_mapWidth);
|
211
|
|
- } else if ((bg_map_mapWidth - DEVICE_SCREEN_WIDTH) > map_pos_x) {
|
212
|
|
- set_bkg_sub(map_pos_x + DEVICE_SCREEN_WIDTH, map_pos_y,
|
213
|
|
- 1, MIN(DEVICE_SCREEN_HEIGHT + 1, bg_map_mapHeight - map_pos_y),
|
214
|
|
- bg_map_map, bg_map_MAP_ATTRIBUTES, MAP_FLIP_NONE, bg_map_mapWidth);
|
215
|
|
- }
|
216
|
|
- old_map_pos_x = map_pos_x;
|
|
209
|
+ if (map_pos_y != old_map_pos_y) {
|
|
210
|
+ old_map_pos_y = map_pos_y;
|
|
211
|
+
|
|
212
|
+ if (camera_y < old_camera_y) {
|
|
213
|
+ // moving up
|
|
214
|
+ set_bkg_sub(map_pos_x, map_pos_y,
|
|
215
|
+ MIN(DEVICE_SCREEN_WIDTH + 1, bg_map_mapWidth - map_pos_x), 1,
|
|
216
|
+ bg_map_map, bg_map_MAP_ATTRIBUTES, MAP_FLIP_Y, bg_map_mapWidth);
|
|
217
|
+ } else if ((bg_map_mapHeight - DEVICE_SCREEN_HEIGHT) > map_pos_y) {
|
|
218
|
+ // moving down
|
|
219
|
+ set_bkg_sub(map_pos_x, map_pos_y + DEVICE_SCREEN_HEIGHT,
|
|
220
|
+ MIN(DEVICE_SCREEN_WIDTH + 1, bg_map_mapWidth - map_pos_x), 1,
|
|
221
|
+ bg_map_map, bg_map_MAP_ATTRIBUTES, MAP_FLIP_NONE, bg_map_mapWidth);
|
217
|
222
|
}
|
218
|
|
-
|
219
|
|
- } END_ROM_BANK
|
|
223
|
+ }
|
220
|
224
|
|
221
|
225
|
// set old camera position to current camera position
|
222
|
226
|
old_camera_x = camera_x;
|