Permalink
Browse files

Also check OAM index when evaluating sprite priority

  • Loading branch information...
1 parent 0e86afa commit fb594a890002e48a7278b079607bfddf58ff75e6 @scottferg committed Oct 11, 2012
Showing with 21 additions and 13 deletions.
  1. +8 −8 anrom.go
  2. +13 −5 ppu.go
View
@@ -3,16 +3,16 @@ package main
type Anrom Rom
func (m *Anrom) Write(v Word, a int) {
- bank := int((v & 0x7) * 2)
+ bank := int((v & 0x7) * 2)
- if v & 0x10 == 0x10 {
- ppu.Nametables.SetMirroring(MirroringSingleUpper)
- } else {
- ppu.Nametables.SetMirroring(MirroringSingleLower)
- }
+ if v&0x10 == 0x10 {
+ ppu.Nametables.SetMirroring(MirroringSingleUpper)
+ } else {
+ ppu.Nametables.SetMirroring(MirroringSingleLower)
+ }
- WriteRamBank(m.RomBanks, bank, 0x8000, Size16k)
- WriteRamBank(m.RomBanks, bank+1, 0xC000, Size16k)
+ WriteRamBank(m.RomBanks, bank, 0x8000, Size16k)
+ WriteRamBank(m.RomBanks, bank+1, 0xC000, Size16k)
}
func (m *Anrom) Hook() {
View
@@ -24,8 +24,9 @@ type Flags struct {
}
type Pixel struct {
- Color uint32
- Value int
+ Color uint32
+ Value int
+ Pindex int
}
type Masks struct {
@@ -198,6 +199,7 @@ func (p *Ppu) raster() {
p.Framebuffer[(y*width)+x] = color
p.Palettebuffer[i].Value = 0
+ p.Palettebuffer[i].Pindex = -1
}
p.Output <- p.Framebuffer
@@ -668,6 +670,7 @@ func (p *Ppu) renderTileRow() {
p.Palettebuffer[fbRow] = Pixel{
PaletteRgb[palette%64],
int(pixel),
+ -1,
}
}
@@ -738,7 +741,7 @@ func (p *Ppu) evaluateScanlineSprites(line int) {
int(p.XCoordinates[i]),
ycoord,
p.sprPaletteEntry(uint(attrValue)),
- &p.Attributes[i], sprite0)
+ &p.Attributes[i], sprite0, i)
} else {
// 8x8 Sprite
s := p.sprPatternTableAddress(int(t))
@@ -748,7 +751,7 @@ func (p *Ppu) evaluateScanlineSprites(line int) {
int(p.XCoordinates[i]),
ycoord,
p.sprPaletteEntry(uint(attrValue)),
- &p.Attributes[i], i == 0)
+ &p.Attributes[i], i == 0, i)
}
spriteCount++
@@ -761,7 +764,7 @@ func (p *Ppu) evaluateScanlineSprites(line int) {
}
}
-func (p *Ppu) decodePatternTile(t []Word, x, y int, pal []Word, attr *Word, spZero bool) {
+func (p *Ppu) decodePatternTile(t []Word, x, y int, pal []Word, attr *Word, spZero bool, index int) {
var b uint
for b = 0; b < 8; b++ {
var xcoord int
@@ -805,11 +808,16 @@ func (p *Ppu) decodePatternTile(t []Word, x, y int, pal []Word, attr *Word, spZe
// Pixel is already rendered and priority
// 1 means show behind background
continue
+ } else if p.Palettebuffer[fbRow].Pindex > -1 && p.Palettebuffer[fbRow].Pindex < index {
+ // Pixel with a higher sprite priority (lower index)
+ // is already here, so don't render this pixel
+ continue
}
p.Palettebuffer[fbRow] = Pixel{
PaletteRgb[int(pal[pixel])%64],
int(pixel),
+ index,
}
}
}

0 comments on commit fb594a8

Please sign in to comment.