apple2-go/system/system.go
Will Angenent 8284073beb Added very basic audio processing
Every frame sends a bunch of audio samples in a channel. This channel is
consumed by the audio Read() function which is called asynchronously. There's
all kinds of timing issues where the audio/video are not aligned.

Issues:
- There's a large delay between the audio being produced and it being played
- Something with the timing is wrong. The first not of lemonade stand and the
  system beep are both incorrect. Changing the CPU frequency fixes it for one
  but not for the other. This means something must be wrong in the cycle
  counting.

Also added FPS display that can be toggled with ctrl-alt-F.
2018-05-14 10:49:24 +01:00

45 lines
1006 B
Go

package system
const (
CpuFrequency = 1024000
AudioSampleRate = 44100
)
var (
PendingInterrupt bool
PendingNMI bool
RunningTests bool
RunningFunctionalTests bool
RunningInterruptTests bool
Cycles uint64
FrameCycles uint64
AudioCycles uint64
AudioChannel chan uint16
LastAudioCycles uint64
LastAudioValue uint16
AudioAttenuationCounter uint64
)
func Init() {
Cycles = 0
AudioChannel = make(chan uint16, AudioSampleRate*4) // 1 second
LastAudioValue = 0x2000
}
// Handle a write to a magic test address that triggers an interrupt and/or an NMI
func WriteInterruptTestOpenCollector(address uint16, oldValue uint8, value uint8) {
oldInterrupt := (oldValue & 0x1) == 0x1
oldNMI := (oldValue & 0x2) == 0x2
interrupt := (value & 0x1) == 0x1
NMI := (value & 0x2) == 0x2
if oldInterrupt != interrupt {
PendingInterrupt = interrupt
}
if oldNMI != NMI {
PendingNMI = NMI
}
}