| 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 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#include "support/fake_devices.h" |
| 36 |
#include "support/harness.h" |
| 37 |
|
| 38 |
#include "debug_core.h" |
| 39 |
#include "memory.h" |
| 40 |
|
| 41 |
#include <stdint.h> |
| 42 |
|
| 43 |
extern uint32_t clockticks6502; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
extern int fake_break_count; |
| 48 |
|
| 49 |
|
| 50 |
#define ADDR_SLOW_IO 0x9F41 |
| 51 |
#define ADDR_VERA 0x9F23 |
| 52 |
#define ADDR_RAM 0x0200 |
| 53 |
|
| 54 |
static void |
| 55 |
reset(void) |
| 56 |
{ |
| 57 |
fake_devices_reset(); |
| 58 |
debug_wp_clear_all(); |
| 59 |
fake_break_count = 0; |
| 60 |
} |
| 61 |
|
| 62 |
static void |
| 63 |
test_a_debug_write_spends_no_cycles(void) |
| 64 |
{ |
| 65 |
reset(); |
| 66 |
write6502(ADDR_SLOW_IO, 0, 0x42); |
| 67 |
check_eq(clockticks6502, 3, "the program's write to slow I/O spends three cycles"); |
| 68 |
|
| 69 |
reset(); |
| 70 |
debug_write6502(ADDR_SLOW_IO, 0, 0x42); |
| 71 |
check_eq(clockticks6502, 0, "the debugger's write to the same address spends none"); |
| 72 |
|
| 73 |
|
| 74 |
reset(); |
| 75 |
write6502(0x9FA0, 0, 0x42); |
| 76 |
check_eq(clockticks6502, 3, "and the same holds in the slow IO5-7 range"); |
| 77 |
|
| 78 |
reset(); |
| 79 |
debug_write6502(0x9FA0, 0, 0x42); |
| 80 |
check_eq(clockticks6502, 0, "where the debugger's write is also free"); |
| 81 |
|
| 82 |
|
| 83 |
reset(); |
| 84 |
write6502(ADDR_RAM, 0, 0x42); |
| 85 |
check_eq(clockticks6502, 0, "a write to plain RAM spends none either way"); |
| 86 |
} |
| 87 |
|
| 88 |
static void |
| 89 |
test_a_debug_write_reports_no_watchpoint(void) |
| 90 |
{ |
| 91 |
reset(); |
| 92 |
debug_wp_add_for(ADDR_RAM, 1, DEBUG_BANK_ANY, DEBUG_OWNER_CLI); |
| 93 |
|
| 94 |
write6502(ADDR_RAM, 0, 0x11); |
| 95 |
check_eq(fake_break_count, 1, "the program's store on a watched address breaks"); |
| 96 |
|
| 97 |
reset(); |
| 98 |
debug_wp_add_for(ADDR_RAM, 1, DEBUG_BANK_ANY, DEBUG_OWNER_CLI); |
| 99 |
|
| 100 |
debug_write6502(ADDR_RAM, 0, 0x22); |
| 101 |
check_eq(fake_break_count, 0, "the debugger's edit of the same address does not"); |
| 102 |
check_eq(read6502(ADDR_RAM, 0), 0x22, "and the byte is written regardless"); |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
static void |
| 107 |
test_a_debug_write_still_updates_the_machine(void) |
| 108 |
{ |
| 109 |
reset(); |
| 110 |
debug_write6502(ADDR_RAM, 0, 0x5A); |
| 111 |
check_eq(read6502(ADDR_RAM, 0), 0x5A, "a debug write to RAM is there afterwards"); |
| 112 |
|
| 113 |
reset(); |
| 114 |
debug_write6502(ADDR_VERA, 0, 0x42); |
| 115 |
check_eq(fake_dev[FAKE_VERA].writes, 1, "a debug write reaches the device"); |
| 116 |
check_eq(fake_dev[FAKE_VERA].last_value, 0x42, "carrying its value"); |
| 117 |
check_eq(fake_dev[FAKE_VERA].state, 1, "and moves it, because writing the port is the point"); |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
static void |
| 124 |
test_the_two_writes_leave_the_same_machine(void) |
| 125 |
{ |
| 126 |
reset(); |
| 127 |
write6502(ADDR_VERA, 0, 0x42); |
| 128 |
const uint32_t by_program = fake_devices_state_sum(); |
| 129 |
const int writes = fake_dev[FAKE_VERA].writes; |
| 130 |
const uint8_t value = fake_dev[FAKE_VERA].last_value; |
| 131 |
|
| 132 |
reset(); |
| 133 |
debug_write6502(ADDR_VERA, 0, 0x42); |
| 134 |
|
| 135 |
check_eq(fake_devices_state_sum(), by_program, "both writes leave identical device state"); |
| 136 |
check_eq(fake_dev[FAKE_VERA].writes, writes, "both are counted as a write"); |
| 137 |
check_eq(fake_dev[FAKE_VERA].last_value, value, "and both delivered the same byte"); |
| 138 |
} |
| 139 |
|
| 140 |
int |
| 141 |
main(void) |
| 142 |
{ |
| 143 |
test_a_debug_write_spends_no_cycles(); |
| 144 |
test_a_debug_write_reports_no_watchpoint(); |
| 145 |
test_a_debug_write_still_updates_the_machine(); |
| 146 |
test_the_two_writes_leave_the_same_machine(); |
| 147 |
return x16_test_summary("debug_write_path"); |
| 148 |
} |