Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
akatsuki105 committed Apr 14, 2021
1 parent 14ab104 commit 6a4367c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
11 changes: 8 additions & 3 deletions pkg/gba/apu.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func isResetSoundChan(addr uint32) bool {
}
func (g *GBA) resetSoundChan(addr uint32, b byte) {
m := map[uint32]int{0x04000065: 0, 0x0400006d: 1, 0x04000075: 2, 0x0400007d: 3}
g._resetSoundChan(m[addr], b&0x80 != 0)
g._resetSoundChan(m[addr], util.Bit(b, 7))
}

const (
Expand Down Expand Up @@ -243,6 +243,11 @@ func (g *GBA) enableSoundChan(ch int, enable bool) {
g.RAM.IO[ram.IOOffset(ram.SOUNDCNT_X)] = cntx
}

func (g *GBA) isSoundMasterEnable() bool {
cntx := byte(g._getRAM(ram.SOUNDCNT_X))
return util.Bit(cntx, 7)
}

func (g *GBA) isSoundChanEnable(ch int) bool {
cntx := byte(g._getRAM(ram.SOUNDCNT_X))
return util.Bit(cntx, ch)
Expand Down Expand Up @@ -450,7 +455,7 @@ func (g *GBA) fifoACopy() {
}

for i := uint32(0); i < 4; i++ {
fifoA[fifoALen] = int8(byte(g._getRAM(ram.FIFO_A + i)))
fifoA[fifoALen] = int8(g.RAM.IO[ram.IOOffset(0x040000a0+i)])
fifoALen++
}
}
Expand All @@ -461,7 +466,7 @@ func (g *GBA) fifoBCopy() {
}

for i := uint32(0); i < 4; i++ {
fifoB[fifoBLen] = int8(byte(g._getRAM(ram.FIFO_B + i)))
fifoB[fifoBLen] = int8(g.RAM.IO[ram.IOOffset(0x040000a4+i)])
fifoBLen++
}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/gba/dma.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,14 @@ func (g *GBA) dmaTransfer(t dmaTiming) {
}

func (g *GBA) dmaTransferFifo(ch int) {
if !g.dma[ch].enabled() || g.dma[ch].timing() != dmaSpecial {
if !g.isSoundMasterEnable() || !g.dma[ch].enabled() || g.dma[ch].timing() != dmaSpecial {
return
}

// 32bit × 4 = 4 words
dst := g.dma[ch].dst()
for i := 0; i < 4; i++ {
src, dst := g.dma[ch].src(), g.dma[ch].dst()
src := g.dma[ch].src()
g.setRAM32(dst, g.getRAM32(src, true), true)

if ch == 1 {
Expand Down
26 changes: 14 additions & 12 deletions pkg/gba/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (ts *Timers) SetIO(offset uint32, b byte) {
case 0:
ts[idx].Reload = (ts[idx].Reload & 0xff00) | uint16(b)
case 1:
ts[idx].Reload = (ts[idx].Reload & 0x00ff) | (uint16(b) << 8)
ts[idx].Reload = (ts[idx].Reload & 0xff) | (uint16(b) << 8)
case 2:
previous := util.Bit(ts[idx].Control, 7)
ts[idx].Control = b
Expand Down Expand Up @@ -209,28 +209,30 @@ func (g *GBA) Tick() [4]bool {
countUp := false
if ts[i].cascade() {
countUp = overflow
overflow = false
} else {
if ts[i].Next > 0 {
ts[i].Next--
}
countUp = ts[i].Next == 0
}
overflow = false

if countUp {
overflow = ts[i].increment()
if overflow {
cnth := uint16(g._getRAM(ram.SOUNDCNT_H))
if (cnth>>SoundATimer)&1 == uint16(i) {
g.fifoALoad()
if fifoALen <= 0x10 {
g.dmaTransferFifo(1)
if i == 1 {
cnth := uint16(g._getRAM(ram.SOUNDCNT_H))
if (cnth>>SoundATimer)&1 == 1 {
g.fifoALoad()
if fifoALen <= 0x10 {
g.dmaTransferFifo(1)
}
}
}
if (cnth>>SoundBTimer)&1 == uint16(i) {
g.fifoBLoad()
if fifoBLen <= 0x10 {
g.dmaTransferFifo(2)
if (cnth>>SoundBTimer)&1 == 1 {
g.fifoBLoad()
if fifoBLen <= 0x10 {
g.dmaTransferFifo(2)
}
}
}

Expand Down

0 comments on commit 6a4367c

Please sign in to comment.