/* Map view (R3). Tile bytes are translated through two 256-entry tables, so the ** marked/claimed flag bits need no special case when drawing. */ #include #include "charset.h" #include "map.h" #include "view.h" #define SCREEN ((unsigned char *)0x0400) #define COLRAM ((unsigned char *)0xD800) unsigned char tile_glyph[256]; unsigned char tile_color[256]; void view_init(void) { unsigned i = 0; unsigned char t; do { t = (unsigned char)i; if (t & TILE_MARKED) { tile_glyph[i] = GLYPH_MARKED; tile_color[i] = COLOR_YELLOW; } else switch (t & TILE_TYPE) { case TILE_FLOOR: tile_glyph[i] = GLYPH_FLOOR; tile_color[i] = COLOR_GRAY1; break; case TILE_HARD: tile_glyph[i] = GLYPH_ROCK_HARD; tile_color[i] = COLOR_GRAY2; break; default: tile_glyph[i] = GLYPH_ROCK_SOFT; tile_color[i] = COLOR_BROWN; break; } } while (++i < 256u); } void draw_view(unsigned char vx, unsigned char vy) { unsigned char row, col, t; const unsigned char *src; unsigned char *scr = SCREEN + VIEW_TOP * 40u; unsigned char *clr = COLRAM + VIEW_TOP * 40u; for (row = 0; row < VIEW_H; ++row) { src = MAP_PTR(vx, vy + row); /* Written with pointer increments: the indexed form (scr[col] = tile_glyph[t]) ** is miscompiled by cc65 V2.19 cc3c40c with -O (it indexes the table with the ** low byte of the screen address). M1.3 replaces this loop with assembly. */ for (col = 0; col < VIEW_W; ++col) { t = *src++; *scr++ = tile_glyph[t]; *clr++ = tile_color[t]; } } }