Skip to content

Commit

Permalink
update document
Browse files Browse the repository at this point in the history
  • Loading branch information
akatsuki105 committed Apr 14, 2021
1 parent 29d5520 commit 15264d8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 41 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ $ ./build/darwin-amd64/mettaur XXXX.gba

## ToDo

- [ ] Sound
- [ ] Sound DMA
- [ ] Clear sound
- [ ] Window
- [ ] Mosaic
- [ ] Blend
Expand Down
64 changes: 24 additions & 40 deletions pkg/gba/apu.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,6 @@ import (
"github.com/hajimehoshi/oto"
)

var waveSamples byte
var wavePosition byte

var waveRAM [0x20]byte

func isSoundIO(addr uint32) bool {
return addr >= 0x04000060 && addr <= 0x04000081
}
func maskSoundIO(addr uint32, b byte) byte {
switch addr {
case 0x04000060:
return b & 0x7f
case 0x04000061, 0x04000064, 0x04000066, 0x04000067, 0x0400006c, 0x0400006e, 0x0400006f, 0x04000071, 0x04000072, 0x04000074, 0x04000076, 0x04000077, 0x04000078, 0x0400007a, 0x0400007b, 0x0400007e, 0x0400007f:
return 0
case 0x04000062, 0x04000068:
return b & 0xc0
case 0x04000065, 0x0400006d, 0x04000075, 0x0400007d:
return b & 0x40
case 0x04000070, 0x04000073:
return b & 0xe0
case 0x04000080:
return b & 0x77
}
return b
}

func isWaveRAM(addr uint32) bool {
return addr >= 0x04000090 && addr <= 0x0400009f
}

func isResetSoundChan(addr uint32) bool {
return addr == 0x04000065 || addr == 0x0400006d || addr == 0x04000075 || addr == 0x0400007d
}
func (g *GBA) resetSoundChan(addr uint32, b byte) {
m := map[uint32]int{0x04000065: 0, 0x0400006d: 1, 0x04000075: 2, 0x0400007d: 3}
g._resetSoundChan(m[addr], util.Bit(b, 7))
}

const (
CPU_FREQ_HZ = 16777216
SND_FREQUENCY = 32768
Expand All @@ -69,8 +31,10 @@ const (
SAMP_MIN = -0x200
)

var dutyLookUp = [4]float64{0.125, 0.25, 0.5, 0.75}
var dutyLookUpi = [4]float64{0.875, 0.75, 0.5, 0.25}
var waveSamples byte
var wavePosition byte

var waveRAM [0x20]byte

type APU struct {
context *oto.Context
Expand All @@ -87,6 +51,22 @@ type SoundChan struct {
envTime float64
}

func isSoundIO(addr uint32) bool {
return addr >= 0x04000060 && addr <= 0x04000081
}

func isWaveRAM(addr uint32) bool {
return addr >= 0x04000090 && addr <= 0x0400009f
}

func isResetSoundChan(addr uint32) bool {
return addr == 0x04000065 || addr == 0x0400006d || addr == 0x04000075 || addr == 0x0400007d
}
func (g *GBA) resetSoundChan(addr uint32, b byte) {
m := map[uint32]int{0x04000065: 0, 0x0400006d: 1, 0x04000075: 2, 0x0400007d: 3}
g._resetSoundChan(m[addr], util.Bit(b, 7))
}

func newAPU() *APU {
stream = make([]byte, STREAM_LEN)

Expand Down Expand Up @@ -116,6 +96,9 @@ func (g *GBA) playSound() {
}()
}

var dutyLookUp = [4]float64{0.125, 0.25, 0.5, 0.75}
var dutyLookUpi = [4]float64{0.875, 0.75, 0.5, 0.25}

func (g *GBA) squareSample(ch int) int8 {
if !g.isSoundChanEnable(ch) {
return 0
Expand Down Expand Up @@ -533,6 +516,7 @@ func (g *GBA) soundClock(cycles uint32) {
cnth := uint16(g._getRAM(ram.SOUNDCNT_H)) // snd_pcm_vol
volADiv, volBDiv := int16((cnth>>2)&0b1), int16((cnth>>3)&0b1)
sampCh4, sampCh5 := fifoASamp>>volADiv, fifoBSamp>>volBDiv
sampCh4, sampCh5 = 0, 0

// Left
if util.Bit(cnth, 9) {
Expand Down

0 comments on commit 15264d8

Please sign in to comment.