#ifndef STONEHOLD_MAP_H #define STONEHOLD_MAP_H /* The 128x128 world map, one byte per tile, at MAP_ADDR ($4000-$7FFF). ** The linker places it (segment MAP in cfg/stonehold-64.cfg); see docs/memory-map.md. */ #define MAP_W 128u #define MAP_H 128u #define MAP_ADDR 0x4000u /* Tile byte. Each map byte is also the screen code it is drawn with, and its low nibble is ** its colour (colour RAM keeps only 4 bits), so draw_view copies bytes without a lookup (R3.3). ** bit 7 always 1 (game glyphs live at codes 128-255) ** bit 6 claimed by a dwarf ** bits 5-4 type: 00 floor, 01 soft rock, 10 hard rock ** bits 3-0 colour: the type's colour, or yellow (7) when marked for digging ** charset.c puts a glyph at every code used here; see docs/memory-map.md. */ #define TILE_FLOOR 0x8B /* type 0, dark grey (COLOR_GRAY1) */ #define TILE_SOFT 0x99 /* type 1, brown (COLOR_BROWN) */ #define TILE_HARD 0xAC /* type 2, grey (COLOR_GRAY2) */ #define TILE_CLAIMED 0x40 #define TILE_TYPE_MASK 0x30 #define TILE_TYPE_FLOOR 0x00 #define TILE_TYPE_SOFT 0x10 #define TILE_TYPE_HARD 0x20 #define TILE_COLOR_MASK 0x0F #define TILE_COLOR_MARKED 0x07 /* COLOR_YELLOW */ #define TILE_IS_ROCK(t) (((t) & TILE_TYPE_MASK) != TILE_TYPE_FLOOR) #define TILE_IS_HARD(t) (((t) & TILE_TYPE_MASK) == TILE_TYPE_HARD) #define TILE_IS_MARKED(t) (((t) & TILE_COLOR_MASK) == TILE_COLOR_MARKED) /* Marked version of rock tile t (claim flag kept). Only for rock tiles. */ #define TILE_MARK(t) ((unsigned char)(((t) & 0xF0) | TILE_COLOR_MARKED)) /* Unmarked, unclaimed version of rock tile t. */ #define TILE_UNMARK(t) ((unsigned char)(TILE_IS_HARD(t) ? TILE_HARD : TILE_SOFT)) /* Marked tiles drawn by charset.c: soft, hard, and both again with the claim bit. */ #define TILE_SOFT_MARKED 0x97 #define TILE_HARD_MARKED 0xA7 /* Address of tile (x, y) = MAP_ADDR + y*128 + x; x and y must be 0-127. ** Built from bytes (high = $40 + y/2, low = (y odd ? $80 : 0) + x) because a 16-bit ** shift by 7 is slow in cc65. */ #define MAP_PTR(x, y) ((unsigned char *)( \ ((unsigned)(unsigned char)((MAP_ADDR >> 8) + ((unsigned char)(y) >> 1)) << 8) | \ (unsigned char)((((unsigned char)(y) & 1) ? 0x80 : 0) | (unsigned char)(x)))) #define DWARF_COUNT 3 extern unsigned char map[MAP_W * MAP_H]; /* Results of map_generate(). */ extern unsigned map_seed; /* 1-65535 */ extern unsigned char map_start_x, map_start_y; /* centre of the starting cave */ extern unsigned char map_dwarf_x[DWARF_COUNT]; /* dwarf start tiles (floor) */ extern unsigned char map_dwarf_y[DWARF_COUNT]; /* A seed from the timers and the raster line at the moment of the call (never 0). */ unsigned map_random_seed(void); /* Fill map[] from seed: soft rock, hard-rock veins, caverns, starting cave near the centre. ** The same seed always gives the same map. Seed 0 is treated as 1. */ void map_generate(unsigned seed); #endif