-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapper.go
46 lines (40 loc) · 883 Bytes
/
mapper.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
package main
import "fmt"
type Mapper interface {
Read(addr address) byte
Write(addr address, data byte)
}
func NewMapper(nes *Nes) Mapper {
switch nes.cartridge.mapperID {
case 0:
return NewMapperMMC0(nes)
case 1:
return NewMapperMMC1(nes)
case 3:
return NewMapper3(nes)
case 4:
return NewMapperMMC3(nes)
default:
panic(fmt.Sprintf("Unknown mapper: %d", nes.cartridge.mapperID))
}
}
const (
MirrorHorizontal = 0
MirrorVertical = 1
MirrorSingleA = 2
MirrorSingleB = 3
MirrorFour = 4
)
var MirrorLookup = [][4]int{
{0, 0, 1, 1},
{0, 1, 0, 1},
{0, 0, 0, 0},
{1, 1, 1, 1},
{0, 1, 2, 3},
}
// from nametable address in range 0x2000 to 0x2FFF to VRAM (0x0000 to 0x1000)
func TranslateVRamAddress(addr address, mirrorMode int) int {
addr -= 0x2000
bank := MirrorLookup[mirrorMode][addr/(0x400)]
return (bank * 0x400) + int(addr%0x400)
}