mirror of
https://github.com/freewilll/apple2-go.git
synced 2024-06-08 06:29:28 +00:00
Added some comments to the audio samples calculation
This commit is contained in:
parent
de7299a5ab
commit
94c6ecd97d
|
@ -53,7 +53,8 @@ func update(screen *ebiten.Image) error {
|
||||||
|
|
||||||
system.FrameCycles = 0
|
system.FrameCycles = 0
|
||||||
system.LastAudioCycles = 0
|
system.LastAudioCycles = 0
|
||||||
cpu.Run(*showInstructions, breakAddress, *disableFirmwareWait, system.CpuFrequency/60)
|
exitAtBreak := true
|
||||||
|
cpu.Run(*showInstructions, breakAddress, exitAtBreak, *disableFirmwareWait, system.CpuFrequency/60)
|
||||||
audio.ForwardToFrameCycle()
|
audio.ForwardToFrameCycle()
|
||||||
system.Cycles += system.FrameCycles
|
system.Cycles += system.FrameCycles
|
||||||
system.FrameCycles = 0
|
system.FrameCycles = 0
|
||||||
|
|
|
@ -20,11 +20,16 @@ func attenuate(sample int16) int16 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ForwardToFrameCycle() {
|
func ForwardToFrameCycle() {
|
||||||
ratio := float64(system.AudioSampleRate) / system.CpuFrequency
|
// 1023000/44100=23.19 cycles per audio sample
|
||||||
|
cyclesPerAudioSample := system.CpuFrequency / float64(system.AudioSampleRate)
|
||||||
|
|
||||||
samples := uint64(ratio * float64(system.FrameCycles-system.LastAudioCycles))
|
// Should be about 1023000/60=17050
|
||||||
var i uint64
|
elapsedCycles := system.FrameCycles - system.LastAudioCycles
|
||||||
for i = 0; i < samples; i++ {
|
|
||||||
|
// Should be about 17050/23.19=735 audio samples per frame
|
||||||
|
audioSamples := uint64(float64(elapsedCycles) / cyclesPerAudioSample)
|
||||||
|
|
||||||
|
for i := uint64(0); i < audioSamples; i++ {
|
||||||
b := attenuate(system.LastAudioValue)
|
b := attenuate(system.LastAudioValue)
|
||||||
system.AudioChannel <- b
|
system.AudioChannel <- b
|
||||||
}
|
}
|
||||||
|
|
63
bell_test.go
Normal file
63
bell_test.go
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"mos6502go/cpu"
|
||||||
|
"mos6502go/keyboard"
|
||||||
|
"mos6502go/mmu"
|
||||||
|
"mos6502go/system"
|
||||||
|
"mos6502go/video"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func testBellCycles(delay int) {
|
||||||
|
cpu.State.PC = 0x800
|
||||||
|
mmu.WriteMemory(0x800, 0xa9) // LDA #$xx
|
||||||
|
mmu.WriteMemory(0x801, uint8(delay))
|
||||||
|
mmu.WriteMemory(0x802, 0x20) // JSR $fca8
|
||||||
|
mmu.WriteMemory(0x803, 0xa8)
|
||||||
|
mmu.WriteMemory(0x804, 0xfc)
|
||||||
|
mmu.WriteMemory(0x805, 0x00) // Break address
|
||||||
|
|
||||||
|
system.FrameCycles = 0
|
||||||
|
showInstructions := false
|
||||||
|
breakAddress := uint16(0x805)
|
||||||
|
exitAtBreak := false
|
||||||
|
disableFirmwareWait := false
|
||||||
|
cpu.Run(showInstructions, &breakAddress, exitAtBreak, disableFirmwareWait, system.CpuFrequency*1000)
|
||||||
|
|
||||||
|
// See http://apple2.org.za/gswv/a2zine/GS.WorldView/Resources/USEFUL.TABLES/WAIT.DELAY.CR.txt
|
||||||
|
expectedCycles := (26 + 27*delay + 5*delay*delay) / 2
|
||||||
|
|
||||||
|
gotCycles := int(system.FrameCycles - 2)
|
||||||
|
fmt.Printf("Delay %3d ", delay)
|
||||||
|
if gotCycles == expectedCycles {
|
||||||
|
fmt.Println("OK")
|
||||||
|
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Failed expected %6d, got %6d\n", expectedCycles, gotCycles)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBell(t *testing.T) {
|
||||||
|
cpu.InitInstructionDecoder()
|
||||||
|
mmu.InitRAM()
|
||||||
|
mmu.InitApple2eROM()
|
||||||
|
mmu.InitIO()
|
||||||
|
cpu.Init()
|
||||||
|
keyboard.Init()
|
||||||
|
video.Init()
|
||||||
|
system.Init()
|
||||||
|
|
||||||
|
testBellCycles(1)
|
||||||
|
testBellCycles(2)
|
||||||
|
testBellCycles(3)
|
||||||
|
testBellCycles(4)
|
||||||
|
testBellCycles(12)
|
||||||
|
testBellCycles(0x10)
|
||||||
|
testBellCycles(0x20)
|
||||||
|
testBellCycles(0x40)
|
||||||
|
testBellCycles(0x80)
|
||||||
|
testBellCycles(0xc0)
|
||||||
|
testBellCycles(0xff)
|
||||||
|
}
|
12
cpu/cpu.go
12
cpu/cpu.go
|
@ -530,7 +530,7 @@ func nmi() {
|
||||||
system.FrameCycles += 7
|
system.FrameCycles += 7
|
||||||
}
|
}
|
||||||
|
|
||||||
func Run(showInstructions bool, breakAddress *uint16, disableFirmwareWait bool, wantedCycles uint64) {
|
func Run(showInstructions bool, breakAddress *uint16, exitAtBreak bool, disableFirmwareWait bool, wantedCycles uint64) {
|
||||||
system.FrameCycles = 0
|
system.FrameCycles = 0
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -568,9 +568,13 @@ func Run(showInstructions bool, breakAddress *uint16, disableFirmwareWait bool,
|
||||||
addressMode := OpCodes[opcode].AddressingMode.Mode
|
addressMode := OpCodes[opcode].AddressingMode.Mode
|
||||||
|
|
||||||
if breakAddress != nil && State.PC == *breakAddress {
|
if breakAddress != nil && State.PC == *breakAddress {
|
||||||
fmt.Printf("Break at $%04x\n", *breakAddress)
|
if exitAtBreak {
|
||||||
PrintInstruction(true)
|
fmt.Printf("Break at $%04x\n", *breakAddress)
|
||||||
os.Exit(0)
|
PrintInstruction(true)
|
||||||
|
os.Exit(0)
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch opcode {
|
switch opcode {
|
||||||
|
|
|
@ -73,7 +73,7 @@ func TestCPU(t *testing.T) {
|
||||||
|
|
||||||
keyboard.Init()
|
keyboard.Init()
|
||||||
|
|
||||||
cpu.Run(*showInstructions, breakAddress, false, 0)
|
cpu.Run(*showInstructions, breakAddress, true, false, 0)
|
||||||
fmt.Printf("Finished running %s\n\n", rom)
|
fmt.Printf("Finished running %s\n\n", rom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,10 @@ func TestDOS33Boot(t *testing.T) {
|
||||||
system.LastAudioCycles = 0
|
system.LastAudioCycles = 0
|
||||||
showInstructions := false
|
showInstructions := false
|
||||||
var breakAddress uint16
|
var breakAddress uint16
|
||||||
|
exitAtBreak := true
|
||||||
disableFirmwareWait := false
|
disableFirmwareWait := false
|
||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
cpu.Run(showInstructions, &breakAddress, disableFirmwareWait, system.CpuFrequency*1000)
|
cpu.Run(showInstructions, &breakAddress, exitAtBreak, disableFirmwareWait, system.CpuFrequency*1000)
|
||||||
|
|
||||||
elapsed := float64(time.Since(t0) / time.Millisecond)
|
elapsed := float64(time.Since(t0) / time.Millisecond)
|
||||||
fmt.Printf("CPU Cycles: %d\n", system.FrameCycles)
|
fmt.Printf("CPU Cycles: %d\n", system.FrameCycles)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user