-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ports.java
88 lines (73 loc) · 2.12 KB
/
Ports.java
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
public final class Ports
{
EZ80 z80;
VDP vdp;
PSG psg;
Joystick joy;
public Ports(VDP vdp, PSG psg, Joystick joy) {
this.vdp = vdp;
this.psg = psg;
this.joy = joy;
}
public final int read(int port) {
port &= 0xFF;
int retval = 0xFF;
switch(port) {
case 0x7E: // H/V Counter FIXME: H Counter not implemented yet
case 0x7F:
if(vdp.scanline > 0xDA)
retval = vdp.scanline - 5;
else
retval = vdp.scanline;
break;
case 0xBE: // VDP Data Port
retval = vdp.data_port_read();
break;
case 0xBF: // VDP Control Port (mirrored at $BD)
case 0xBD:
retval = vdp.control_port_read();
break;
case 0xC0: // Joypad port 1
case 0xDC: // mirror at $DC
retval = joy.port1_read();
break;
case 0xC1: // Joypad port 2
case 0xDD: // mirror at $DD
retval = joy.port2_read();
break;
case 0xDE: // Unknown but often read ports
case 0xDF:
break;
default:
//System.out.println("PORTS READ: read from unknown port $" + Integer.toHexString(port).toUpperCase());
}
return (retval & 0xFF);
}
public final void write(int port, int value) {
//port &= 0xFF;
switch(port) {
case 0x3F: // Automatic nationalisation
if((value & 0x20) != 0) joy.byte2 |= 0x40; // Nationalisation bit 1
else joy.byte2 &= ~0x40;
if((value & 0x80) != 0) joy.byte2 |= 0x80; // Nationalisation bit 2
else joy.byte2 &= ~0x80;
break;
case 0x7E: // PSG port write (mirrored at $7F)
case 0x7F:
psg.write(value);
break;
case 0xBE: // VDP Data Port
vdp.data_port_write(value);
break;
case 0xBF: // VDP Control Port (mirrored at $BD)
case 0xBD:
vdp.control_port_write(value);
break;
case 0xDE: // Unknown but often written ports
case 0xDF:
break;
default:
//System.out.println("PORTS WRITE: write to unknown port $" + Integer.toHexString(port).toUpperCase());
}
}
}