OXYGENHUB
◆ main enhanced-x16-emulator / src / via.h
2.0 KiB · Objective-C · last changed chore(): initial commit 25 days ago source blame history raw
9120e874 Andy McCall 1
// Commander X16 Emulator
2
// Copyright (c) 2019 Michael Steil
3
// All rights reserved. License: 2-clause BSD
4
5
#ifndef VIA_H
6
#define VIA_H
7
8
#include <stdint.h>
9
#include <stdbool.h>
10
11
#ifdef __cplusplus
12
extern "C" {
13
#endif
14
15
void via1_init();
16
uint8_t via1_read(uint8_t reg, bool debug);
17
void via1_write(uint8_t reg, uint8_t value);
18
void via1_step(unsigned clocks);
19
bool via1_irq();
20
21
void via2_init();
22
uint8_t via2_read(uint8_t reg, bool debug);
23
void via2_write(uint8_t reg, uint8_t value);
24
void via2_step(unsigned clocks);
25
bool via2_irq();
26
27
// ─── Debugger accessor ───────────────────────────────────────────────────────
28
// Side-effect-free snapshot of one VIA's state. Safe to call every frame from
29
// the debugger while the emulation is running.
30
//
31
// Register index map (mirrors the MOS 6522 address decoding):
32
//   0=ORB/IRB  1=ORA/IRA  2=DDRB  3=DDRA
33
//   4=T1L      5=T1H      6=T1LL  7=T1LH
34
//   8=T2L      9=T2H(not stored, see timer_count)
35
//   10=SR      11=ACR     12=PCR  13=IFR  14=IER
36
//
37
// `which`: 0 = VIA1, 1 = VIA2.
38
39
typedef struct {
40
	// Whether VIA2 is fitted is a machine-configuration fact (has_via2 in
41
	// glue.h), not something this module knows -- and reaching for it here
42
	// would give via.c an external symbol it does not otherwise need, which
43
	// the standalone VIA tests link without. The caller decides.
44
	uint8_t  regs[15];         // raw register bytes (indices 0-14, see map above)
45
	uint16_t timer_count[2];   // live timer counter values (T1=0, T2=1)
46
	uint16_t timer_latch[2];   // T1 latch = (regs[7]<<8)|regs[6]; T2 latch low = regs[8]
47
	bool     timer_running[2]; // timer is actively counting
48
	bool     timer1_m1;        // T1 is in the special -1 state between underflow and reload
49
	bool     pb7_output;       // PB7 toggle output (used with T1 in one-shot/square-wave mode)
50
} via_debug_state_t;
51
52
void via_debug_get_state(int which, via_debug_state_t *out);
53
54
#ifdef __cplusplus
55
}
56
#endif
57
58
#endif