-
Notifications
You must be signed in to change notification settings - Fork 0
/
via.c
60 lines (57 loc) · 1.66 KB
/
via.c
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "via.h"
#include "log.h"
#define VIA_LOG_READ(via, reg) debug("via@%04x read %s", via->address, reg)
#define VIA_LOG_WRITE(via, reg, value) debug("via@%04x write %s = %02x", via->address, reg, value)
uint8_t mm6502_via_read_callback(fake6502_context *context, uint16_t address, void *data)
{
mm6522_via *via = (mm6522_via *)data;
uint16_t reg = address - via->address;
uint8_t ret = 0;
switch(reg) {
case VIA_REG_RB:
VIA_LOG_READ(via, "IRB");
ret = via->registers.RB & via->registers.DDRB;
break;
case VIA_REG_RA:
VIA_LOG_READ(via, "IRA");
ret = via->registers.RA & via->registers.DDRA;
break;
case VIA_REG_DDRB:
VIA_LOG_READ(via, "DDRB");
ret = via->registers.DDRB;
case VIA_REG_DDRA:
VIA_LOG_READ(via, "DDRA");
ret = via->registers.DDRA;
break;
default:
warn("via@%04x register write %02x not implemented", via->address, address);
break;
}
return ret;
}
void mm6502_via_write_callback(fake6502_context *context, uint16_t address, uint8_t value, void *data)
{
mm6522_via *via = (mm6522_via *)data;
uint16_t reg = address - via->address;
switch(reg) {
case VIA_REG_RB:
VIA_LOG_WRITE(via, "ORB", value);
via->registers.RB = value & via->registers.DDRB;
break;
case VIA_REG_RA:
VIA_LOG_WRITE(via, "ORA", value);
via->registers.RA = value & via->registers.DDRA;
break;
case VIA_REG_DDRB:
VIA_LOG_WRITE(via, "DDRB", value);
via->registers.DDRB = value;
break;
case VIA_REG_DDRA:
VIA_LOG_WRITE(via, "DDRA", value);
via->registers.DDRA = value;
break;
default:
warn("via@%04x register write %02x not implemented", via->address, address);
break;
}
}