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#ifndef MOS6522_H
28#define MOS6522_H
29
30#include "exec/hwaddr.h"
31#include "hw/sysbus.h"
32#include "qom/object.h"
33
34#define MOS6522_NUM_REGS 16
35
36
37#define SR_CTRL 0x1c
38#define SR_EXT 0x0c
39#define SR_OUT 0x10
40
41
42#define IER_SET 0x80
43#define IER_CLR 0
44
45#define CA2_INT_BIT 0
46#define CA1_INT_BIT 1
47#define SR_INT_BIT 2
48#define CB2_INT_BIT 3
49#define CB1_INT_BIT 4
50#define T2_INT_BIT 5
51#define T1_INT_BIT 6
52
53#define CA2_INT BIT(CA2_INT_BIT)
54#define CA1_INT BIT(CA1_INT_BIT)
55#define SR_INT BIT(SR_INT_BIT)
56#define CB2_INT BIT(CB2_INT_BIT)
57#define CB1_INT BIT(CB1_INT_BIT)
58#define T2_INT BIT(T2_INT_BIT)
59#define T1_INT BIT(T1_INT_BIT)
60
61#define VIA_NUM_INTS 5
62
63
64#define T1MODE 0xc0
65#define T1MODE_CONT 0x40
66
67
68#define CB2_CTRL_MASK 0xe0
69#define CB2_CTRL_SHIFT 5
70#define CB1_CTRL_MASK 0x10
71#define CB1_CTRL_SHIFT 4
72#define CA2_CTRL_MASK 0x0e
73#define CA2_CTRL_SHIFT 1
74#define CA1_CTRL_MASK 0x1
75#define CA1_CTRL_SHIFT 0
76
77#define C2_POS 0x2
78#define C2_IND 0x1
79
80#define C1_POS 0x1
81
82
83#define VIA_REG_B 0x00
84#define VIA_REG_A 0x01
85#define VIA_REG_DIRB 0x02
86#define VIA_REG_DIRA 0x03
87#define VIA_REG_T1CL 0x04
88#define VIA_REG_T1CH 0x05
89#define VIA_REG_T1LL 0x06
90#define VIA_REG_T1LH 0x07
91#define VIA_REG_T2CL 0x08
92#define VIA_REG_T2CH 0x09
93#define VIA_REG_SR 0x0a
94#define VIA_REG_ACR 0x0b
95#define VIA_REG_PCR 0x0c
96#define VIA_REG_IFR 0x0d
97#define VIA_REG_IER 0x0e
98#define VIA_REG_ANH 0x0f
99
100
101
102
103
104typedef struct MOS6522Timer {
105 int index;
106 uint16_t latch;
107 uint16_t counter_value;
108 int64_t load_time;
109 int64_t next_irq_time;
110 uint64_t frequency;
111 QEMUTimer *timer;
112} MOS6522Timer;
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129struct MOS6522State {
130
131 SysBusDevice parent_obj;
132
133
134 MemoryRegion mem;
135
136 uint8_t b;
137 uint8_t a;
138 uint8_t dirb;
139 uint8_t dira;
140 uint8_t sr;
141 uint8_t acr;
142 uint8_t pcr;
143 uint8_t ifr;
144 uint8_t ier;
145
146 MOS6522Timer timers[2];
147 uint64_t frequency;
148
149 qemu_irq irq;
150 uint8_t last_irq_levels;
151};
152
153#define TYPE_MOS6522 "mos6522"
154OBJECT_DECLARE_TYPE(MOS6522State, MOS6522DeviceClass, MOS6522)
155
156struct MOS6522DeviceClass {
157 DeviceClass parent_class;
158
159 ResettablePhases parent_phases;
160 void (*portB_write)(MOS6522State *dev);
161 void (*portA_write)(MOS6522State *dev);
162
163 uint64_t (*get_timer1_counter_value)(MOS6522State *dev, MOS6522Timer *ti);
164 uint64_t (*get_timer2_counter_value)(MOS6522State *dev, MOS6522Timer *ti);
165 uint64_t (*get_timer1_load_time)(MOS6522State *dev, MOS6522Timer *ti);
166 uint64_t (*get_timer2_load_time)(MOS6522State *dev, MOS6522Timer *ti);
167};
168
169
170extern const VMStateDescription vmstate_mos6522;
171
172uint64_t mos6522_read(void *opaque, hwaddr addr, unsigned size);
173void mos6522_write(void *opaque, hwaddr addr, uint64_t val, unsigned size);
174
175void hmp_info_via(Monitor *mon, const QDict *qdict);
176
177#endif
178