-
Notifications
You must be signed in to change notification settings - Fork 0
/
dma.go
executable file
·61 lines (48 loc) · 965 Bytes
/
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
package rp2ago3
import (
"github.com/nwidger/m65go2"
)
type DMA struct {
Memory m65go2.Memory
pending chan uint32
}
func NewDMA(memory m65go2.Memory) *DMA {
return &DMA{
Memory: memory,
pending: make(chan uint32, 1),
}
}
func (dma *DMA) PerformDMA() (cycles uint16) {
select {
case start := <-dma.pending:
end := uint32(start + 0x0100)
for address := start; address < end; address++ {
dma.Memory.Store(0x2004, dma.Memory.Fetch(uint16(address)))
}
cycles = 512
default:
cycles = 0
}
return
}
func (dma *DMA) Reset() {
dma.pending = make(chan uint32, 1)
}
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
}