| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include "support/video_fixture.h" |
| 25 |
#include "support/harness.h" |
| 26 |
|
| 27 |
#include "video.h" |
| 28 |
|
| 29 |
#include <stdint.h> |
| 30 |
|
| 31 |
#define L0_CONFIG 0x0D |
| 32 |
#define L0_MAPBASE 0x0E |
| 33 |
#define L0_TILEBASE 0x0F |
| 34 |
#define L0_HSCROLL_L 0x10 |
| 35 |
#define L0_HSCROLL_H 0x11 |
| 36 |
#define L0_VSCROLL_L 0x12 |
| 37 |
#define L0_VSCROLL_H 0x13 |
| 38 |
|
| 39 |
|
| 40 |
#define LAYER_STRIDE 7 |
| 41 |
|
| 42 |
static uint8_t |
| 43 |
reg_of(unsigned layer, uint8_t l0_reg) |
| 44 |
{ |
| 45 |
return (uint8_t)(l0_reg + layer * LAYER_STRIDE); |
| 46 |
} |
| 47 |
|
| 48 |
static void |
| 49 |
write_layer(unsigned layer, uint8_t l0_reg, uint8_t value) |
| 50 |
{ |
| 51 |
video_write(reg_of(layer, l0_reg), value); |
| 52 |
} |
| 53 |
|
| 54 |
static uint8_t |
| 55 |
read_layer(unsigned layer, uint8_t l0_reg) |
| 56 |
{ |
| 57 |
return video_read(reg_of(layer, l0_reg), false); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
static void |
| 69 |
test_the_full_width_layer_registers_round_trip(void) |
| 70 |
{ |
| 71 |
static const uint8_t regs[] = { |
| 72 |
L0_CONFIG, L0_MAPBASE, L0_TILEBASE, L0_HSCROLL_L, L0_VSCROLL_L |
| 73 |
}; |
| 74 |
|
| 75 |
video_reset(); |
| 76 |
|
| 77 |
for (unsigned layer = 0; layer < 2; layer++) { |
| 78 |
for (unsigned i = 0; i < sizeof regs / sizeof regs[0]; i++) { |
| 79 |
|
| 80 |
|
| 81 |
const uint8_t v = (uint8_t)(0x9C + layer * 0x10 + i); |
| 82 |
|
| 83 |
write_layer(layer, regs[i], v); |
| 84 |
check_eq(read_layer(layer, regs[i]), v, "a layer register reports what was written"); |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
static void |
| 105 |
test_the_scroll_high_bytes_are_four_bits_wide(void) |
| 106 |
{ |
| 107 |
static const uint8_t highs[] = { L0_HSCROLL_H, L0_VSCROLL_H }; |
| 108 |
|
| 109 |
video_reset(); |
| 110 |
|
| 111 |
for (unsigned layer = 0; layer < 2; layer++) { |
| 112 |
for (unsigned i = 0; i < sizeof highs / sizeof highs[0]; i++) { |
| 113 |
write_layer(layer, highs[i], 0x0A); |
| 114 |
check_eq(read_layer(layer, highs[i]), 0x0A, "the low four bits are stored"); |
| 115 |
|
| 116 |
write_layer(layer, highs[i], 0xFF); |
| 117 |
check_divergent(read_layer(layer, highs[i]) == 0x0F, |
| 118 |
"the top four bits of a scroll high byte read as zero", |
| 119 |
"video.c:2733 and video.c:2741 return the stored byte whole; " |
| 120 |
"top.v:215 and top.v:217 read {4'b0, scroll[11:8]} and the write " |
| 121 |
"at top.v:392-400 takes only write_data[3:0]"); |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
static void |
| 129 |
test_the_two_layers_are_independent(void) |
| 130 |
{ |
| 131 |
video_reset(); |
| 132 |
|
| 133 |
write_layer(0, L0_CONFIG, 0x39); |
| 134 |
write_layer(1, L0_CONFIG, 0xC6); |
| 135 |
check_eq(read_layer(0, L0_CONFIG), 0x39, "layer 0 keeps its own config"); |
| 136 |
check_eq(read_layer(1, L0_CONFIG), 0xC6, "layer 1 keeps its own"); |
| 137 |
|
| 138 |
write_layer(0, L0_MAPBASE, 0x11); |
| 139 |
write_layer(1, L0_MAPBASE, 0x22); |
| 140 |
check_eq(read_layer(0, L0_MAPBASE), 0x11, "and its own map base"); |
| 141 |
check_eq(read_layer(1, L0_MAPBASE), 0x22, "separately from the other"); |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
static void |
| 148 |
set_both_layers(uint8_t config, uint8_t mapbase, uint8_t tilebase) |
| 149 |
{ |
| 150 |
for (unsigned layer = 0; layer < 2; layer++) { |
| 151 |
write_layer(layer, L0_CONFIG, config); |
| 152 |
write_layer(layer, L0_MAPBASE, mapbase); |
| 153 |
write_layer(layer, L0_TILEBASE, tilebase); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
static void |
| 163 |
test_mapbase_places_the_tilemap_at_512_byte_units(void) |
| 164 |
{ |
| 165 |
video_reset(); |
| 166 |
set_both_layers(0x00, 0x20, 0xFC); |
| 167 |
|
| 168 |
check(!video_is_tilemap_address(0x3FFF), "below the base is not tilemap"); |
| 169 |
check(video_is_tilemap_address(0x4000), "the base itself is"); |
| 170 |
check(video_is_tilemap_address(0x47FF), "and so is the last byte of a 32x32 map"); |
| 171 |
check(!video_is_tilemap_address(0x4800), "one past the end is not"); |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
set_both_layers(0x00, 0x21, 0xFC); |
| 176 |
check(video_is_tilemap_address(0x4200), "the next register value is 512 bytes further on"); |
| 177 |
check(!video_is_tilemap_address(0x41FF), "and the byte below it is outside"); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
static void |
| 190 |
test_the_map_extent_follows_width_and_height(void) |
| 191 |
{ |
| 192 |
video_reset(); |
| 193 |
|
| 194 |
for (unsigned mh = 0; mh < 4; mh++) { |
| 195 |
for (unsigned mw = 0; mw < 4; mw++) { |
| 196 |
const uint8_t config = (uint8_t)((mh << 6) | (mw << 4)); |
| 197 |
const uint32_t bytes = 2u << ((5 + mw) + (5 + mh)); |
| 198 |
|
| 199 |
set_both_layers(config, 0x00, 0xFC); |
| 200 |
|
| 201 |
check(video_is_tilemap_address((int)(bytes - 1)), |
| 202 |
"the last byte of the map is inside it"); |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
if (bytes < 0x20000u) { |
| 207 |
check(!video_is_tilemap_address((int)bytes), |
| 208 |
"and the byte after it is outside"); |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
static void |
| 229 |
test_tilebase_ignores_the_two_size_bits(void) |
| 230 |
{ |
| 231 |
video_reset(); |
| 232 |
set_both_layers(0x00, 0xF0, 0x00); |
| 233 |
check(video_is_tiledata_address(0x0000), "tile data starts at zero with base zero"); |
| 234 |
|
| 235 |
|
| 236 |
set_both_layers(0x00, 0xF0, 0x03); |
| 237 |
check(video_is_tiledata_address(0x0000), "the tile size bits do not move the base"); |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
set_both_layers(0x00, 0xF0, 0x04); |
| 242 |
check(!video_is_tiledata_address(0x07FF), "the first base step clears the 2K below it"); |
| 243 |
check(video_is_tiledata_address(0x0800), "and lands 2K up"); |
| 244 |
} |
| 245 |
|
| 246 |
int |
| 247 |
main(void) |
| 248 |
{ |
| 249 |
test_the_full_width_layer_registers_round_trip(); |
| 250 |
test_the_scroll_high_bytes_are_four_bits_wide(); |
| 251 |
test_the_two_layers_are_independent(); |
| 252 |
test_mapbase_places_the_tilemap_at_512_byte_units(); |
| 253 |
test_the_map_extent_follows_width_and_height(); |
| 254 |
test_tilebase_ignores_the_two_size_bits(); |
| 255 |
return x16_test_summary("vera_layer"); |
| 256 |
} |