| 9120e874 Andy McCall |
1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#include "support/video_fixture.h" |
| 27 |
#include "support/harness.h" |
| 28 |
|
| 29 |
#include "video.h" |
| 30 |
|
| 31 |
#include <stdio.h> |
| 32 |
#include <string.h> |
| 33 |
|
| 34 |
#define VERA_ADDR_L 0x00 |
| 35 |
#define VERA_ADDR_M 0x01 |
| 36 |
#define VERA_ADDR_H 0x02 |
| 37 |
#define VERA_DATA0 0x03 |
| 38 |
#define VERA_DATA1 0x04 |
| 39 |
#define VERA_CTRL 0x05 |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#define KNOWN_MISMATCHES 13 |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
static bool |
| 53 |
reads_are_self_advancing(uint8_t reg) |
| 54 |
{ |
| 55 |
return reg == VERA_DATA0 || reg == VERA_DATA1; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
static void |
| 61 |
prime(void) |
| 62 |
{ |
| 63 |
video_reset(); |
| 64 |
|
| 65 |
|
| 66 |
video_write(VERA_CTRL, 0); |
| 67 |
video_write(VERA_ADDR_L, 0x00); |
| 68 |
video_write(VERA_ADDR_M, 0x10); |
| 69 |
video_write(VERA_ADDR_H, 0x10); |
| 70 |
for (unsigned i = 0; i < 64; i++) { |
| 71 |
video_write(VERA_DATA0, (uint8_t)(0x80 + i)); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
for (unsigned dcsel = 0; dcsel < 8; dcsel++) { |
| 76 |
video_write(VERA_CTRL, (uint8_t)(dcsel << 1)); |
| 77 |
for (uint8_t reg = 0x09; reg <= 0x0C; reg++) { |
| 78 |
|
| 79 |
|
| 80 |
if (dcsel == 5 && reg >= 0x0B) { |
| 81 |
continue; |
| 82 |
} |
| 83 |
video_write(reg, (uint8_t)(0x30 + dcsel * 4 + (reg - 0x09))); |
| 84 |
} |
| 85 |
} |
| 86 |
video_write(VERA_CTRL, 0); |
| 87 |
for (uint8_t reg = 0x0D; reg <= 0x1A; reg++) { |
| 88 |
video_write(reg, (uint8_t)(0x40 + reg)); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
static void |
| 99 |
test_debug_and_real_reads_agree(void) |
| 100 |
{ |
| 101 |
static const unsigned banks[] = {0, 1, 2, 3, 5, 6, 63}; |
| 102 |
|
| 103 |
unsigned mismatches = 0; |
| 104 |
char first[160]; |
| 105 |
first[0] = '\0'; |
| 106 |
|
| 107 |
for (unsigned b = 0; b < sizeof banks / sizeof banks[0]; b++) { |
| 108 |
for (uint8_t reg = 0x00; reg < 0x20; reg++) { |
| 109 |
if (reads_are_self_advancing(reg)) { |
| 110 |
continue; |
| 111 |
} |
| 112 |
|
| 113 |
prime(); |
| 114 |
video_write(VERA_CTRL, (uint8_t)(banks[b] << 1)); |
| 115 |
|
| 116 |
uint8_t as_debugger = video_read(reg, true); |
| 117 |
uint8_t as_machine = video_read(reg, false); |
| 118 |
|
| 119 |
if (as_debugger != as_machine) { |
| 120 |
mismatches++; |
| 121 |
if (first[0] == '\0') { |
| 122 |
snprintf(first, sizeof first, |
| 123 |
"$9F%02X with DCSEL %u: debugger sees 0x%02X, machine sees 0x%02X", |
| 124 |
reg + 0x20, banks[b], as_debugger, as_machine); |
| 125 |
} |
| 126 |
printf(" mismatch: $9F%02X DCSEL %u debug=0x%02X real=0x%02X\n", |
| 127 |
reg + 0x20, banks[b], as_debugger, as_machine); |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
if (mismatches != 0) { |
| 133 |
printf(" first: %s\n", first); |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
check_eq(mismatches, KNOWN_MISMATCHES, |
| 142 |
"the set of registers that disagree is unchanged"); |
| 143 |
|
| 144 |
check_divergent(mismatches == 0, |
| 145 |
"every VERA register reads the same to the debugger as to the machine", |
| 146 |
"13 registers differ, all $9F29-$9F2C in banks where the register is " |
| 147 |
"write-only or unmapped: video.c:2690 sends a debug read to the stored " |
| 148 |
"composer byte, while a real read returns the version string"); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
static void |
| 155 |
test_data_ports_report_the_same_byte(void) |
| 156 |
{ |
| 157 |
for (uint8_t port = VERA_DATA0; port <= VERA_DATA1; port++) { |
| 158 |
prime(); |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
uint8_t sel = (uint8_t)(port - VERA_DATA0); |
| 163 |
video_write(VERA_CTRL, sel); |
| 164 |
video_write(VERA_ADDR_L, 0x08); |
| 165 |
video_write(VERA_ADDR_M, 0x10); |
| 166 |
video_write(VERA_ADDR_H, 0x00); |
| 167 |
|
| 168 |
uint8_t as_debugger = video_read(port, true); |
| 169 |
uint8_t as_machine = video_read(port, false); |
| 170 |
|
| 171 |
check_eq(as_debugger, as_machine, "the data port reports the same byte to both"); |
| 172 |
check_eq(as_machine, 0x88u, "and it is the byte that was written there"); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
static void |
| 181 |
test_a_debug_read_still_moves_nothing(void) |
| 182 |
{ |
| 183 |
prime(); |
| 184 |
video_write(VERA_CTRL, 0); |
| 185 |
video_write(VERA_ADDR_L, 0x20); |
| 186 |
video_write(VERA_ADDR_M, 0x10); |
| 187 |
video_write(VERA_ADDR_H, 0x10); |
| 188 |
|
| 189 |
uint32_t before = video_get_address(0); |
| 190 |
video_read(VERA_DATA0, true); |
| 191 |
check_eq(video_get_address(0), before, "a debug read of the data port does not advance it"); |
| 192 |
|
| 193 |
video_read(VERA_DATA0, false); |
| 194 |
check_eq(video_get_address(0), before + 1, "while a real read does"); |
| 195 |
} |
| 196 |
|
| 197 |
int |
| 198 |
main(void) |
| 199 |
{ |
| 200 |
test_debug_and_real_reads_agree(); |
| 201 |
test_data_ports_report_the_same_byte(); |
| 202 |
test_a_debug_read_still_moves_nothing(); |
| 203 |
return x16_test_summary("vera_debug_read"); |
| 204 |
} |