A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 253 lines 5.8 kB view raw
1/* 2 * xrick/maps.c 3 * 4 * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). 5 * Copyright (C) 2008-2014 Pierluigi Vicinanza. 6 * All rights reserved. 7 * 8 * The use and distribution terms for this software are contained in the file 9 * named README, which can be found in the root of this distribution. By 10 * using this software in any fashion, you are agreeing to be bound by the 11 * terms of this license. 12 * 13 * You must not remove this notice, or any other, from this software. 14 */ 15 16/* 17 * NOTES 18 * 19 * A map is composed of submaps, which in turn are composed of rows of 20 * 0x20 tiles. map_map contains the tiles for the current portion of the 21 * current submap, i.e. a little bit more than what appear on the screen, 22 * but not the whole submap. 23 * 24 * map_frow is map_map top row within the submap. 25 * 26 * Submaps are stored as arrays of blocks, each block being a 4x4 tile 27 * array. map_submaps[].bnum points to the first block of the array. 28 * 29 * Before a submap can be played, it needs to be expanded from blocks 30 * to map_map. 31 */ 32 33#include "xrick/maps.h" 34 35#include "xrick/game.h" 36#include "xrick/debug.h" 37#include "xrick/control.h" 38#include "xrick/ents.h" 39#include "xrick/draw.h" 40#include "xrick/screens.h" 41#include "xrick/e_sbonus.h" 42 43/* 44 * global vars 45 */ 46U8 map_map[0x2C][0x20]; 47 48size_t map_nbr_maps = 0; 49map_t *map_maps = NULL; 50 51size_t map_nbr_submaps = 0; 52submap_t *map_submaps = NULL; 53 54size_t map_nbr_connect = 0; 55connect_t *map_connect = NULL; 56 57size_t map_nbr_blocks = 0; 58block_t *map_blocks = NULL; 59 60size_t map_nbr_marks = 0; 61mark_t *map_marks = NULL; 62 63size_t map_nbr_bnums = 0; 64U8 *map_bnums = NULL; 65 66size_t map_nbr_eflgc = 0; 67U8 *map_eflg_c = NULL; 68U8 map_eflg[0x100]; 69 70U8 map_frow; 71U8 map_tilesBank; 72 73 74/* 75 * prototypes 76 */ 77static void map_eflg_expand(U8); 78 79 80/* 81 * Fill in map_map with tile numbers by expanding blocks. 82 * 83 * add map_submaps[].bnum to map_frow to find out where to start from. 84 * We need to /4 map_frow to convert from tile rows to block rows, then 85 * we need to *8 to convert from block rows to block numbers (there 86 * are 8 blocks per block row). This is achieved by *2 then &0xfff8. 87 */ 88void 89map_expand(void) 90{ 91 U8 i, j, k, l; 92 U8 row, col; 93 U16 pbnum; 94 95 pbnum = map_submaps[game_submap].bnum + ((2 * map_frow) & 0xfff8); 96 row = col = 0; 97 98 for (i = 0; i < 0x0b; i++) { /* 0x0b rows of blocks */ 99 for (j = 0; j < 0x08; j++) { /* 0x08 blocks per row */ 100 for (k = 0, l = 0; k < 0x04; k++) { /* expand one block */ 101 map_map[row][col++] = map_blocks[map_bnums[pbnum]][l++]; 102 map_map[row][col++] = map_blocks[map_bnums[pbnum]][l++]; 103 map_map[row][col++] = map_blocks[map_bnums[pbnum]][l++]; 104 map_map[row][col] = map_blocks[map_bnums[pbnum]][l++]; 105 row += 1; col -= 3; 106 } 107 row -= 4; col += 4; 108 pbnum++; 109 } 110 row += 4; col = 0; 111 } 112} 113 114 115/* 116 * Initialize a new submap 117 * 118 * ASM 0cc3 119 */ 120void 121map_init(void) 122{ 123 /*sys_printf("xrick/map_init: map=%#04x submap=%#04x\n", g_map, game_submap);*/ 124#ifdef GFXPC 125 draw_filter = 0xffff; 126 map_tilesBank = 2 + map_submaps[game_submap].page; 127#endif 128#ifdef GFXST 129 map_tilesBank = 1 + map_submaps[game_submap].page; 130#endif 131 map_eflg_expand(map_submaps[game_submap].page << 4); 132 map_expand(); 133 ent_reset(); 134 ent_actvis(map_frow + MAP_ROW_SCRTOP, map_frow + MAP_ROW_SCRBOT); 135 ent_actvis(map_frow + MAP_ROW_HTTOP, map_frow + MAP_ROW_HTBOT); 136 ent_actvis(map_frow + MAP_ROW_HBTOP, map_frow + MAP_ROW_HBBOT); 137} 138 139 140/* 141 * Expand entity flags for this map 142 * 143 * ASM 1117 144 */ 145void 146map_eflg_expand(U8 offs) 147{ 148 U8 i, j, k; 149 150 for (i = 0, k = 0; i < 0x10; i++) { 151 j = map_eflg_c[offs + i++]; 152 while (j--) map_eflg[k++] = map_eflg_c[offs + i]; 153 } 154} 155 156 157/* 158 * Chain (sub)maps 159 * 160 * ASM 0c08 161 * return: true/next submap OK, false/map finished 162 */ 163bool 164map_chain(void) 165{ 166 U16 c, t; 167 168 game_chsm = false; 169 e_sbonus_counting = false; 170 171 /* find connection */ 172 c = map_submaps[game_submap].connect; 173 t = 3; 174 175 IFDEBUG_MAPS( 176 sys_printf("xrick/maps: chain submap=%#04x frow=%#04x .connect=%#04x %s\n", 177 game_submap, map_frow, c, 178 (game_dir == LEFT ? "-> left" : "-> right")); 179 ); 180 181 /* 182 * look for the first connector with compatible row number. if none 183 * found, then panic 184 */ 185 for (c = map_submaps[game_submap].connect ; ; c++) 186 { 187 if (map_connect[c].dir == 0xff) 188 { 189 sys_error("(map_chain) can not find connector\n"); 190 control_set(Control_EXIT); 191 return false; 192 } 193 if (map_connect[c].dir != game_dir) 194 { 195 continue; 196 } 197 t = (ent_ents[1].y >> 3) + map_frow - map_connect[c].rowout; 198 if (t < 3) 199 { 200 break; 201 } 202 } 203 204 /* got it */ 205 IFDEBUG_MAPS( 206 sys_printf("xrick/maps: chain frow=%#04x y=%#06x\n", 207 map_frow, ent_ents[1].y); 208 sys_printf("xrick/maps: chain connect=%#04x rowout=%#04x - ", 209 c, map_connect[c].rowout); 210 ); 211 212 if (map_connect[c].submap == 0xff) 213 { 214 /* no next submap - request next map */ 215 IFDEBUG_MAPS( 216 sys_printf("chain to next map\n"); 217 ); 218 return false; 219 } 220 else 221 { 222 /* next submap */ 223 IFDEBUG_MAPS( 224 sys_printf("chain to submap=%#04x rowin=%#04x\n", 225 map_connect[c].submap, map_connect[c].rowin); 226 ); 227 map_frow = map_frow - map_connect[c].rowout + map_connect[c].rowin; 228 game_submap = map_connect[c].submap; 229 IFDEBUG_MAPS( 230 sys_printf("xrick/maps: chain frow=%#04x\n", 231 map_frow); 232 ); 233 return true; 234 } 235} 236 237 238/* 239 * Reset all marks, i.e. make them all active again. 240 * 241 * ASM 0025 242 * 243 */ 244void 245map_resetMarks(void) 246{ 247 U16 i; 248 for (i = 0; i < map_nbr_marks; i++) 249 map_marks[i].ent &= ~MAP_MARK_NACT; 250} 251 252 253/* eof */