Permalink
Browse files

Fixed tests and added MMC1 mirroring swap tests

  • Loading branch information...
scottferg committed Sep 28, 2012
1 parent 647e133 commit 5a00befef0745febe47596c5b79f0e157116dd7a
Showing with 186 additions and 7 deletions.
  1. +2 −0 .gitignore
  2. +181 −0 mmc1_test.go
  3. +1 −0 ppu.go
  4. +2 −4 ppu_test.go
  5. +0 −3 rom.go
View
@@ -20,3 +20,5 @@ _cgo_export.*
_testmain.go
*.exe
+*.swp
+games/*
View
@@ -0,0 +1,181 @@
+package main
+
+import (
+ "testing"
+)
+
+var (
+ m *Mmc1
+)
+
+func verifyMirroredValue(a int, v Word, test *testing.T) {
+ if ppu.Nametables.readNametableData(a) != v {
+ test.Errorf("0x%X was 0x%X, expected 0x%X\n", a, ppu.Vram[0x2000], v)
+ }
+}
+
+func TestVerticalToHorizontal(test *testing.T) {
+ rom = &Mmc1{
+ RomBanks: make([][]Word, 16),
+ VromBanks: make([][]Word, 16),
+ PrgBankCount: 8,
+ ChrRomCount: 8,
+ BatteryBacked: false,
+ Data: make([]byte, 32),
+ PrgSwapBank: BankLower,
+ }
+
+ ppu.Init()
+
+ ppu.Nametables.SetMirroring(MirroringHorizontal)
+
+ if ppu.Nametables.Mirroring != MirroringHorizontal {
+ test.Errorf("Mirroring was not horizontal")
+ }
+
+ // Setup Vertical mirroring
+ Ram.Write(0x8000, 0x0)
+ Ram.Write(0x8000, 0x1)
+ Ram.Write(0x8000, 0x0)
+ Ram.Write(0x8000, 0x0)
+ Ram.Write(0x8000, 0x0)
+
+ if ppu.Nametables.Mirroring != MirroringVertical {
+ test.Errorf("Mirroring was not vertical")
+ }
+
+ ppu.VramAddress = 0x2000
+ ppu.WriteData(0x11)
+ ppu.VramAddress = 0x2110
+ ppu.WriteData(0x22)
+ ppu.VramAddress = 0x2220
+ ppu.WriteData(0x33)
+ ppu.VramAddress = 0x2330
+ ppu.WriteData(0x44)
+ ppu.VramAddress = 0x2338
+ ppu.WriteData(0x55)
+
+ verifyMirroredValue(0x2000, 0x11, test)
+ verifyMirroredValue(0x2800, 0x11, test)
+
+ verifyMirroredValue(0x2110, 0x22, test)
+ verifyMirroredValue(0x2910, 0x22, test)
+
+ verifyMirroredValue(0x2220, 0x33, test)
+ verifyMirroredValue(0x2A20, 0x33, test)
+
+ verifyMirroredValue(0x2330, 0x44, test)
+ verifyMirroredValue(0x2B30, 0x44, test)
+
+ verifyMirroredValue(0x2338, 0x55, test)
+ verifyMirroredValue(0x2B38, 0x55, test)
+
+ ppu.VramAddress = 0x2400
+ ppu.WriteData(0x11)
+ ppu.VramAddress = 0x2510
+ ppu.WriteData(0x22)
+ ppu.VramAddress = 0x2620
+ ppu.WriteData(0x33)
+ ppu.VramAddress = 0x2730
+ ppu.WriteData(0x44)
+ ppu.VramAddress = 0x2738
+ ppu.WriteData(0x55)
+
+ verifyMirroredValue(0x2400, 0x11, test)
+ verifyMirroredValue(0x2C00, 0x11, test)
+
+ verifyMirroredValue(0x2510, 0x22, test)
+ verifyMirroredValue(0x2D10, 0x22, test)
+
+ verifyMirroredValue(0x2620, 0x33, test)
+ verifyMirroredValue(0x2E20, 0x33, test)
+
+ verifyMirroredValue(0x2730, 0x44, test)
+ verifyMirroredValue(0x2F30, 0x44, test)
+
+ verifyMirroredValue(0x2738, 0x55, test)
+ verifyMirroredValue(0x2F38, 0x55, test)
+}
+
+func TestHorizontalToVertical(test *testing.T) {
+ rom = &Mmc1{
+ RomBanks: make([][]Word, 16),
+ VromBanks: make([][]Word, 16),
+ PrgBankCount: 8,
+ ChrRomCount: 8,
+ BatteryBacked: false,
+ Data: make([]byte, 32),
+ PrgSwapBank: BankLower,
+ }
+
+ ppu.Init()
+
+ ppu.Nametables.SetMirroring(MirroringVertical)
+
+ if ppu.Nametables.Mirroring != MirroringVertical {
+ test.Errorf("Mirroring was not vertical")
+ }
+
+ // Setup Vertical mirroring
+ Ram.Write(0x8000, 0x1)
+ Ram.Write(0x8000, 0x1)
+ Ram.Write(0x8000, 0x0)
+ Ram.Write(0x8000, 0x0)
+ Ram.Write(0x8000, 0x0)
+
+ if ppu.Nametables.Mirroring != MirroringHorizontal {
+ test.Errorf("Mirroring was not horizontal")
+ }
+
+ ppu.VramAddress = 0x2000
+ ppu.WriteData(0x11)
+ ppu.VramAddress = 0x2110
+ ppu.WriteData(0x22)
+ ppu.VramAddress = 0x2220
+ ppu.WriteData(0x33)
+ ppu.VramAddress = 0x2330
+ ppu.WriteData(0x44)
+ ppu.VramAddress = 0x2338
+ ppu.WriteData(0x55)
+
+ verifyMirroredValue(0x2000, 0x11, test)
+ verifyMirroredValue(0x2400, 0x11, test)
+
+ verifyMirroredValue(0x2110, 0x22, test)
+ verifyMirroredValue(0x2510, 0x22, test)
+
+ verifyMirroredValue(0x2220, 0x33, test)
+ verifyMirroredValue(0x2620, 0x33, test)
+
+ verifyMirroredValue(0x2330, 0x44, test)
+ verifyMirroredValue(0x2730, 0x44, test)
+
+ verifyMirroredValue(0x2338, 0x55, test)
+ verifyMirroredValue(0x2738, 0x55, test)
+
+ ppu.VramAddress = 0x2800
+ ppu.WriteData(0x11)
+ ppu.VramAddress = 0x2910
+ ppu.WriteData(0x22)
+ ppu.VramAddress = 0x2A20
+ ppu.WriteData(0x33)
+ ppu.VramAddress = 0x2B30
+ ppu.WriteData(0x44)
+ ppu.VramAddress = 0x2B38
+ ppu.WriteData(0x55)
+
+ verifyMirroredValue(0x2800, 0x11, test)
+ verifyMirroredValue(0x2C00, 0x11, test)
+
+ verifyMirroredValue(0x2910, 0x22, test)
+ verifyMirroredValue(0x2D10, 0x22, test)
+
+ verifyMirroredValue(0x2A20, 0x33, test)
+ verifyMirroredValue(0x2E20, 0x33, test)
+
+ verifyMirroredValue(0x2B30, 0x44, test)
+ verifyMirroredValue(0x2F30, 0x44, test)
+
+ verifyMirroredValue(0x2B38, 0x55, test)
+ verifyMirroredValue(0x2F38, 0x55, test)
+}
View
1 ppu.go
@@ -567,6 +567,7 @@ func (p *Ppu) renderTileRow() {
shift := p.AttributeShift[p.VramAddress&0x3FF]
attr := ((p.Nametables.readNametableData(attrAddr) >> shift) & 0x03) << 2
+ // fmt.Printf("Nametable: %d\n", (p.VramAddress&0xC00)>>10)
index := p.Nametables.readNametableData(p.VramAddress)
t := p.bgPatternTableAddress(index)
View
@@ -18,8 +18,7 @@ func TestVerticalNametableMirroring(test *testing.T) {
p = new(Ppu)
p.Init()
- p.Mirroring = MirroringVertical
- p.Nametables.Init()
+ p.Nametables.SetMirroring(MirroringVertical)
p.VramAddress = 0x2000
p.WriteData(0x11)
@@ -78,8 +77,7 @@ func TestHorizontalNametableMirroring(test *testing.T) {
p = new(Ppu)
p.Init()
- p.Mirroring = MirroringHorizontal
- ppu.Nametables.Init()
+ p.Nametables.SetMirroring(MirroringHorizontal)
p.VramAddress = 0x2000
p.WriteData(0x11)
View
3 rom.go
@@ -32,9 +32,6 @@ type Cnrom Rom
func WriteRamBank(rom [][]Word, bank, dest, size int) {
for i := 0; i < size; i++ {
- if (i+dest) == 0xC000 {
- fmt.Printf("Upper write from bank: %d\n", bank)
- }
Ram[i+dest] = rom[bank][i]
}
}

0 comments on commit 5a00bef

Please sign in to comment.