Permalink
Browse files

Separate MMC3 IRQ hook and MMC2 latch trigger

  • Loading branch information...
1 parent 2df5212 commit 105b45957acc597dc8b3ce9a0f8edf5372af98c9 @scottferg committed Oct 17, 2012
Showing with 41 additions and 20 deletions.
  1. +3 −1 anrom.go
  2. +3 −1 mmc1.go
  3. +3 −1 mmc2.go
  4. +3 −1 mmc3.go
  5. +12 −12 ppu.go
  6. +17 −4 rom.go
View
@@ -15,10 +15,12 @@ func (m *Anrom) Write(v Word, a int) {
WriteRamBank(m.RomBanks, bank+1, 0xC000, Size16k)
}
-func (m *Anrom) Hook(a int) {
+func (m *Anrom) Hook() {
// No hooks
}
+func (m *Anrom) LatchTrigger(a int) {}
+
func (m *Anrom) BatteryBacked() bool {
return m.Battery
}
View
@@ -50,10 +50,12 @@ func (m *Mmc1) Write(v Word, a int) {
}
}
-func (m *Mmc1) Hook(a int) {
+func (m *Mmc1) Hook() {
// Nothing to do
}
+func (m *Mmc1) LatchTrigger(a int) {}
+
func (m *Mmc1) BatteryBacked() bool {
return m.Battery
}
View
@@ -89,7 +89,9 @@ func (m *Mmc2) Write(v Word, a int) {
}
}
-func (m *Mmc2) Hook(a int) {
+func (m *Mmc2) Hook() {}
+
+func (m *Mmc2) LatchTrigger(a int) {
a &= 0x1FF0
switch {
View
@@ -301,7 +301,7 @@ func (m *Mmc3) Write1kVramBank(bank, dest int) {
WriteOffsetVramBank(m.VromBanks, b, dest, Size1k, offset)
}
-func (m *Mmc3) Hook(a int) {
+func (m *Mmc3) Hook() {
// A12 Rising Edge
if (ppu.Scanline > -1 && ppu.Scanline < 241) && (ppu.ShowBackground || ppu.ShowSprites) {
if m.IrqReset {
@@ -318,3 +318,5 @@ func (m *Mmc3) Hook(a int) {
}
}
}
+
+func (m *Mmc3) LatchTrigger(a int) {}
View
24 ppu.go
@@ -244,13 +244,7 @@ func (p *Ppu) Step() {
} else if p.Cycle == 260 {
if p.SpritePatternAddress == 0x1 && p.BackgroundPatternAddress == 0x0 {
if p.RunHook {
- rom.Hook(0)
- }
- }
- } else if p.Cycle == 324 {
- if p.SpritePatternAddress == 0x0 && p.BackgroundPatternAddress == 0x1 {
- if p.RunHook {
- rom.Hook(0)
+ rom.Hook()
}
}
}
@@ -261,6 +255,12 @@ func (p *Ppu) Step() {
p.clearStatus(StatusSprite0Hit)
p.clearStatus(StatusSpriteOverflow)
+ } else if p.Cycle == 260 {
+ if p.SpritePatternAddress == 0x1 && p.BackgroundPatternAddress == 0x0 {
+ if p.RunHook {
+ rom.Hook()
+ }
+ }
} else if p.Cycle == 304 {
// Copy scroll latch into VRAMADDR register
if p.ShowBackground || p.ShowSprites {
@@ -506,7 +506,7 @@ func (p *Ppu) WriteAddress(v Word) {
if p.VramAddress < 0x2000 {
// MMC2 latch trigger
- // rom.Hook(p.VramAddress)
+ rom.LatchTrigger(p.VramAddress)
}
p.checkA12RisingEdge()
@@ -523,7 +523,7 @@ func (p *Ppu) WriteData(v Word) {
} else {
p.Vram[p.VramAddress&0x3FFF] = v
// MMC2 latch trigger
- // rom.Hook(p.VramAddress)
+ rom.LatchTrigger(p.VramAddress)
}
p.incrementVramAddress()
@@ -543,7 +543,7 @@ func (p *Ppu) ReadData() (r Word, err error) {
if p.VramAddress < 0x2000 {
// MMC2 latch trigger
- // rom.Hook(p.VramAddress)
+ rom.LatchTrigger(p.VramAddress)
}
} else {
bufferAddress := p.VramAddress - 0x1000
@@ -563,7 +563,7 @@ func (p *Ppu) ReadData() (r Word, err error) {
if p.VramAddress < 0x2000 {
// MMC2 latch trigger
- // rom.Hook(p.VramAddress)
+ rom.LatchTrigger(p.VramAddress)
}
}
@@ -646,7 +646,7 @@ func (p *Ppu) renderTileRow() {
}
// MMC2 latch trigger
- // rom.Hook(p.VramAddress)
+ rom.LatchTrigger(p.VramAddress)
return uint16(p.Vram[t]), uint16(p.Vram[t+8]), attr
}
View
21 rom.go
@@ -16,7 +16,8 @@ const (
type Mapper interface {
Write(v Word, a int)
BatteryBacked() bool
- Hook(a int)
+ Hook()
+ LatchTrigger(a int)
}
// Nrom
@@ -62,7 +63,11 @@ func (m *Rom) Write(v Word, a int) {
// Nothing to do
}
-func (m *Rom) Hook(a int) {
+func (m *Rom) Hook() {
+ // No hooks
+}
+
+func (m *Rom) LatchTrigger(a int) {
// No hooks
}
@@ -74,7 +79,11 @@ func (m *Unrom) Write(v Word, a int) {
WriteRamBank(m.RomBanks, int(v&0x7), 0x8000, Size16k)
}
-func (m *Unrom) Hook(a int) {
+func (m *Unrom) Hook() {
+ // No hooks
+}
+
+func (m *Unrom) LatchTrigger(a int) {
// No hooks
}
@@ -88,7 +97,11 @@ func (m *Cnrom) Write(v Word, a int) {
WriteVramBank(m.VromBanks, bank+1, 0x1000, Size4k)
}
-func (m *Cnrom) Hook(a int) {
+func (m *Cnrom) Hook() {
+ // No hooks
+}
+
+func (m *Cnrom) LatchTrigger(a int) {
// No hooks
}

0 comments on commit 105b459

Please sign in to comment.