/
MBC.go
40 lines (31 loc) · 792 Bytes
/
MBC.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
package cartridge
import (
"io"
"github.com/djhworld/gomeboycolor/types"
)
type MemoryBankController interface {
Write(addr types.Word, value byte)
Read(addr types.Word) byte
SaveRam(writer io.Writer) error
LoadRam(reader io.Reader) error
switchROMBank(bank int)
switchRAMBank(bank int)
}
func populateROMBanks(rom []byte, noOfBanks int) [][]byte {
romBanks := make([][]byte, noOfBanks)
//ROM Bank 0 and 1 are the same
romBanks[0] = rom[0x4000:0x8000]
var chunk int = 0x4000
for i := 1; i < noOfBanks; i++ {
romBanks[i] = rom[chunk : chunk+0x4000]
chunk += 0x4000
}
return romBanks
}
func populateRAMBanks(noOfBanks int) [][]byte {
ramBanks := make([][]byte, noOfBanks)
for i := 0; i < noOfBanks; i++ {
ramBanks[i] = make([]byte, 0x2000)
}
return ramBanks
}