OXYGENHUB
◆ rrdc-perf enhanced-x16-emulator / tests / support / fake_devices.h
2.2 KiB · Objective-C · last changed chore(): initial commit 25 days ago source blame history raw
9120e874 Andy McCall 1
// Recording stand-ins for the devices behind the I/O page, so memory.c can be
2
// linked and exercised without SDL, a ROM, or any real hardware model.
3
//
4
// This is the seam the debugger contract lives on. real_read6502() carries a
5
// debugOn flag down to every device, and the rule is that a debug read reports
6
// what is there without disturbing anything: no device state moved, no cycles
7
// spent. Nothing enforces that today, and it can break from either side -- a
8
// debugger path that forgets the flag, or a device that gains a side effect and
9
// ignores it.
10
//
11
// Each fake records what it was asked and, crucially, models a device that has
12
// something to lose: a real read advances `state`, standing in for VERA's
13
// address auto-increment or the VIA's read-to-clear interrupt flag. A debug
14
// read that moves `state` has broken the contract, and the test can say so
15
// without knowing anything about the device it is standing in for.
16
17
#ifndef X16_TEST_FAKE_DEVICES_H
18
#define X16_TEST_FAKE_DEVICES_H
19
20
#include <stdbool.h>
21
#include <stdint.h>
22
23
typedef enum {
24
	FAKE_VIA1,
25
	FAKE_VIA2,
26
	FAKE_VERA,
27
	FAKE_YM,
28
	FAKE_MIDI,
29
	FAKE_CART,
30
	FAKE_DEV_COUNT,
31
} fake_dev_t;
32
33
typedef struct {
34
	int     reads;        // every read, debug or not
35
	int     debug_reads;  // those that arrived with the flag set
36
	int     writes;
37
	uint8_t last_reg;
38
	uint8_t last_value;
39
40
	// Advanced by a real read only. A debug read must leave it alone.
41
	uint8_t state;
42
} fake_dev_log_t;
43
44
extern fake_dev_log_t fake_dev[FAKE_DEV_COUNT];
45
46
const char *fake_dev_name(fake_dev_t dev);
47
48
// Clear every log and every device's state. Also zeroes the CPU cycle counter,
49
// since "did this read cost anything?" is half of the contract.
50
void fake_devices_reset(void);
51
52
// Total device state across all fakes, for asserting that a sweep of the I/O
53
// page moved nothing.
54
uint32_t fake_devices_state_sum(void);
55
56
// Reads and writes seen by every fake since the last reset.
57
int fake_devices_total_reads(void);
58
int fake_devices_total_writes(void);
59
60
// YM_read_status() takes no debug flag, so the YM fake cannot tell a debug read
61
// from a real one and always advances. Tests that sweep the I/O page have to
62
// account for that rather than pretend otherwise.
63
#define FAKE_YM_IS_DEBUG_BLIND 1
64
65
#endif // X16_TEST_FAKE_DEVICES_H