2018-05-08 18:32:55 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2018-05-08 21:18:49 +00:00
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten"
|
|
|
|
|
2018-05-08 18:32:55 +00:00
|
|
|
"mos6502go/cpu"
|
2018-05-09 14:41:20 +00:00
|
|
|
"mos6502go/keyboard"
|
2018-05-08 18:32:55 +00:00
|
|
|
"mos6502go/mmu"
|
2018-05-09 16:34:10 +00:00
|
|
|
"mos6502go/video"
|
2018-05-08 21:18:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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 disableBell *bool
|
2018-05-09 09:57:04 +00:00
|
|
|
var resetKeysDown bool
|
|
|
|
|
|
|
|
func reset() {
|
|
|
|
bootVector := 0xfffc
|
2018-05-09 16:43:39 +00:00
|
|
|
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
|
2018-05-09 09:57:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// checkResetKeys check ctrl-alt-R has been pressed. Releasing the R does a warm reset
|
|
|
|
func checkResetKeys() {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2018-05-08 21:18:49 +00:00
|
|
|
|
|
|
|
func update(screen *ebiten.Image) error {
|
2018-05-09 14:41:20 +00:00
|
|
|
keyboard.Poll()
|
2018-05-09 09:57:04 +00:00
|
|
|
checkResetKeys()
|
|
|
|
|
2018-05-09 16:43:39 +00:00
|
|
|
cpu.Run(*showInstructions, nil, *disableBell, 1024000/60)
|
|
|
|
return video.DrawTextScreen(screen)
|
2018-05-08 21:18:49 +00:00
|
|
|
}
|
|
|
|
|
2018-05-08 18:32:55 +00:00
|
|
|
func main() {
|
2018-05-08 21:18:49 +00:00
|
|
|
showInstructions = flag.Bool("show-instructions", false, "Show instructions code while running")
|
|
|
|
disableBell = flag.Bool("disable-bell", false, "Disable bell")
|
2018-05-08 18:32:55 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
2018-05-09 18:32:38 +00:00
|
|
|
cpu.InitInstructionDecoder()
|
2018-05-09 16:43:39 +00:00
|
|
|
mmu.InitRAM()
|
|
|
|
mmu.InitApple2eROM()
|
2018-05-08 18:32:55 +00:00
|
|
|
|
2018-05-09 16:43:39 +00:00
|
|
|
cpu.Init()
|
2018-05-09 14:41:20 +00:00
|
|
|
|
|
|
|
keyboard.Init()
|
2018-05-09 16:34:10 +00:00
|
|
|
video.Init()
|
2018-05-09 14:41:20 +00:00
|
|
|
|
2018-05-09 09:57:04 +00:00
|
|
|
reset()
|
2018-05-08 21:18:49 +00:00
|
|
|
|
|
|
|
ebiten.Run(update, 280*screenSizeFactor, 192*screenSizeFactor, 2, "Apple //e")
|
2018-05-08 18:32:55 +00:00
|
|
|
}
|