/
ports.go
53 lines (41 loc) · 902 Bytes
/
ports.go
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
package main
import "log"
type Ports struct {
vdp *Vdp
ppi *PPI
psg *PSG
}
func (self *Ports) ReadPort(address uint16) byte {
ad := byte(address & 0xFF)
switch {
case ad >= 0xa8 && ad <= 0xab:
return self.ppi.readPort(ad)
case ad >= 0xa0 && ad <= 0xa2:
return self.psg.readPort(ad)
case ad >= 0x98 && ad <= 0x9b:
return self.vdp.readPort(ad)
}
log.Printf("ReadPort: %02x\n", ad)
return 0
}
func (self *Ports) WritePort(address uint16, b byte) {
ad := byte(address & 0xFF)
switch {
case ad >= 0xa8 && ad <= 0xab:
self.ppi.writePort(ad, b)
return
case ad >= 0xa0 && ad <= 0xa2:
self.psg.writePort(ad, b)
return
case ad >= 0x90 && ad <= 0x91:
// Printer. Do nothing
return
case ad >= 0x98 && ad <= 0x9b:
self.vdp.writePort(ad, b)
return
case ad >= 0x00 && ad <= 0x01:
// MIDI / Sensor Kid
return
}
log.Printf("Writeport: %02x -> %02x\n", ad, b)
}