/
dma.go
executable file
·62 lines (48 loc) · 1 KB
/
dma.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
54
55
56
57
58
59
60
61
62
package rp2ago3
import "github.com/nwidger/nintengo/m65go2"
const NoPending uint32 = 0xffffffff
type DMA struct {
Memory m65go2.Memory `json:"-"`
Pending uint32
}
func NewDMA(memory m65go2.Memory) *DMA {
return &DMA{
Memory: memory,
Pending: NoPending,
}
}
func (dma *DMA) PerformDMA() (cycles uint16) {
if dma.Pending == NoPending {
cycles = 0
} else {
start := dma.Pending
end := uint32(start + 0x0100)
for address := start; address < end; address++ {
dma.Memory.Store(0x2004, dma.Memory.Fetch(uint16(address)))
}
cycles = 512
dma.Pending = NoPending
}
return
}
func (dma *DMA) Reset() {
dma.Pending = NoPending
}
func (dma *DMA) Mappings(which Mapping) (fetch, store []uint16) {
switch which {
case CPU:
store = []uint16{0x4014}
}
return
}
func (dma *DMA) Fetch(address uint16) (value uint8) {
// nothing to do
return
}
func (dma *DMA) Store(address uint16, value uint8) (oldValue uint8) {
switch address {
case 0x4014:
dma.Pending = uint32(value) << 8
}
return
}