apple2-go/cmd/test-apple-iie-boot.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

110 lines
2.8 KiB
Go

package main
import (
"flag"
"fmt"
"github.com/hajimehoshi/ebiten"
"mos6502go/audio"
"mos6502go/cpu"
"mos6502go/keyboard"
"mos6502go/mmu"
"mos6502go/system"
"mos6502go/utils"
"mos6502go/video"
)
const (
screenSizeFactor = 1 // Factor by which the whole screen is resized
textVideoMemory = 0x400 // Base location of page 1 text video memory
flashFrames = 8 // Number of frames when FLASH mode is toggled
)
var showInstructions *bool
var disableFirmwareWait *bool
var resetKeysDown bool
var fpsKeysDown bool
var breakAddress *uint16
func reset() {
bootVector := 0xfffc
lsb := mmu.PageTable[bootVector>>8][bootVector&0xff] // TODO move readMemory to mmu
msb := mmu.PageTable[(bootVector+1)>>8][(bootVector+1)&0xff]
cpu.State.PC = uint16(lsb) + uint16(msb)<<8
}
// checkSpecialKeys checks
// - ctrl-alt-R has been pressed. Releasing the R does a warm reset
// - ctrl-alt-F has been pressed, toggling FPS display
func checkSpecialKeys() {
if ebiten.IsKeyPressed(ebiten.KeyControl) && ebiten.IsKeyPressed(ebiten.KeyAlt) && ebiten.IsKeyPressed(ebiten.KeyR) {
resetKeysDown = true
} else if ebiten.IsKeyPressed(ebiten.KeyControl) && ebiten.IsKeyPressed(ebiten.KeyAlt) && !ebiten.IsKeyPressed(ebiten.KeyR) && resetKeysDown {
resetKeysDown = false
reset()
} else {
resetKeysDown = false
}
if ebiten.IsKeyPressed(ebiten.KeyControl) && ebiten.IsKeyPressed(ebiten.KeyAlt) && ebiten.IsKeyPressed(ebiten.KeyF) {
fpsKeysDown = true
} else if ebiten.IsKeyPressed(ebiten.KeyControl) && ebiten.IsKeyPressed(ebiten.KeyAlt) && !ebiten.IsKeyPressed(ebiten.KeyF) && fpsKeysDown {
fpsKeysDown = false
video.ShowFPS = !video.ShowFPS
fmt.Println("Toggled")
} else {
fpsKeysDown = false
}
}
func update(screen *ebiten.Image) error {
keyboard.Poll()
checkSpecialKeys()
system.FrameCycles = 0
system.LastAudioCycles = 0
cpu.Run(*showInstructions, breakAddress, *disableFirmwareWait, system.CpuFrequency/60)
audio.ForwardToFrameCycle()
system.Cycles += system.FrameCycles
system.FrameCycles = 0
return video.DrawScreen(screen)
}
func main() {
showInstructions = flag.Bool("show-instructions", false, "Show instructions code while running")
disableFirmwareWait = flag.Bool("disable-wait", false, "Ignore JSRs to firmware wait at $FCA8")
breakAddressString := flag.String("break", "", "Break on address")
mute := flag.Bool("mute", false, "Mute sound")
diskImage := flag.String("image", "", "Disk Image")
flag.Parse()
breakAddress = utils.DecodeCmdLineAddress(breakAddressString)
ebiten.SetRunnableInBackground(true)
cpu.InitInstructionDecoder()
mmu.InitRAM()
mmu.InitApple2eROM()
mmu.InitIO()
if *diskImage != "" {
mmu.ReadDiskImage(*diskImage)
}
cpu.Init()
keyboard.Init()
video.Init()
audio.Init()
audio.Mute = *mute
system.Init()
reset()
ebiten.Run(update, 280*screenSizeFactor, 192*screenSizeFactor, 2, "Apple //e")
}