Skip to content

Commit

Permalink
Also check OAM index when evaluating sprite priority
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Ferguson committed Oct 11, 2012
1 parent 0e86afa commit fb594a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
16 changes: 8 additions & 8 deletions anrom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
18 changes: 13 additions & 5 deletions ppu.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ type Flags struct {
}

type Pixel struct {
Color uint32
Value int
Color uint32
Value int
Pindex int
}

type Masks struct {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -668,6 +670,7 @@ func (p *Ppu) renderTileRow() {
p.Palettebuffer[fbRow] = Pixel{
PaletteRgb[palette%64],
int(pixel),
-1,
}
}

Expand Down Expand Up @@ -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))
Expand All @@ -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++
Expand All @@ -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
Expand Down Expand Up @@ -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,
}
}
}
Expand Down

0 comments on commit fb594a8

Please sign in to comment.