You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.9KB

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

Powered by TurnKey Linux.