Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
akatsuki105 committed Apr 13, 2021
1 parent f32b540 commit 7c67c19
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
7 changes: 4 additions & 3 deletions pkg/gba/apu.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ func (g *GBA) waveSample() int8 {
}

if samp >= 0 {
return samp * PSG_MAX / 7
return int8(int16(samp) * PSG_MAX / 7)
}
return samp * PSG_MIN / (-8)
return int8(int16(samp) * PSG_MIN / (-8))
}

func (g *GBA) noiseSample() int8 {
Expand Down Expand Up @@ -517,7 +517,8 @@ func (g *GBA) soundClock(cycles uint32) {
sampPcmL, sampPcmR := int16(0), int16(0)

cnth := uint16(g._getRAM(ram.SOUNDCNT_H)) // snd_pcm_vol
sampCh4, sampCh5 := (int16(fifoASamp)<<1)>>^(cnth&4), (int16(fifoBSamp)<<1)>>^(cnth&8)
volADiv, volBDiv := int16((cnth>>2)&0b1)+1, int16((cnth>>3)&0b1)+1
sampCh4, sampCh5 := int16(fifoASamp)/volADiv, int16(fifoBSamp)/volBDiv

// Left
if util.Bit(cnth, 9) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gba/dma.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (g *GBA) dmaTransferFifo(ch int) {
g.fifoBCopy()
}

switch (g.dma[ch].cnt() >> 7) & 0b11 {
switch (g.dma[ch].cnt() >> (16 + 7)) & 0b11 {
case 0:
g.dma[ch].setSrc(src + 4)
case 1:
Expand Down
16 changes: 11 additions & 5 deletions pkg/gba/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import (
"mettaur/pkg/util"
)

const (
SoundATimer = 10
SoundBTimer = 14
)

var (
wsN = [4]int{4, 3, 2, 8}
wsS0 = [2]int{2, 1}
Expand Down Expand Up @@ -136,7 +141,7 @@ func (ts *Timers) GetIO(offset uint32) uint32 {
ofs := offset % 4
switch ofs {
case 0:
return uint32(ts[idx].Count)
return uint32(ts[idx].Control)<<16 | uint32(ts[idx].Count)
case 1:
return uint32(ts[idx].Count >> 8)
case 2:
Expand Down Expand Up @@ -176,13 +181,13 @@ func (g *GBA) Tick() [4]bool {
overflow = ts[0].increment()
if overflow {
cnth := uint16(g._getRAM(ram.SOUNDCNT_H))
if (cnth>>10)&1 == 0 {
if (cnth>>SoundATimer)&1 == 0 {
g.fifoALoad()
if fifoALen <= 0x10 {
g.dmaTransferFifo(1)
}
}
if (cnth>>14)&1 == 0 {
if (cnth>>SoundBTimer)&1 == 0 {
g.fifoBLoad()
if fifoBLen <= 0x10 {
g.dmaTransferFifo(2)
Expand All @@ -197,6 +202,7 @@ func (g *GBA) Tick() [4]bool {

for i := 1; i < 4; i++ {
if !ts[i].enable() {
overflow = false
continue
}

Expand All @@ -215,13 +221,13 @@ func (g *GBA) Tick() [4]bool {
overflow = ts[i].increment()
if overflow {
cnth := uint16(g._getRAM(ram.SOUNDCNT_H))
if (cnth>>10)&1 == uint16(i) {
if (cnth>>SoundATimer)&1 == uint16(i) {
g.fifoALoad()
if fifoALen <= 0x10 {
g.dmaTransferFifo(1)
}
}
if (cnth>>14)&1 == uint16(i) {
if (cnth>>SoundBTimer)&1 == uint16(i) {
g.fifoBLoad()
if fifoBLen <= 0x10 {
g.dmaTransferFifo(2)
Expand Down

0 comments on commit 7c67c19

Please sign in to comment.