2018-05-08 18:32:55 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2018-05-08 21:18:49 +00:00
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten"
|
|
|
|
"github.com/hajimehoshi/ebiten/ebitenutil"
|
|
|
|
|
2018-05-08 18:32:55 +00:00
|
|
|
"mos6502go/cpu"
|
|
|
|
"mos6502go/mmu"
|
2018-05-08 21:18:49 +00:00
|
|
|
"mos6502go/vid"
|
|
|
|
)
|
|
|
|
|
|
|
|
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 (
|
|
|
|
charMap *ebiten.Image
|
|
|
|
flashCounter int
|
|
|
|
flashOn bool
|
2018-05-08 18:32:55 +00:00
|
|
|
)
|
|
|
|
|
2018-05-08 21:18:49 +00:00
|
|
|
var cpuState cpu.State
|
|
|
|
var showInstructions *bool
|
|
|
|
var disableBell *bool
|
|
|
|
|
|
|
|
func update(screen *ebiten.Image) error {
|
|
|
|
cpu.Run(&cpuState, *showInstructions, nil, *disableBell, 1024000/60)
|
2018-05-09 09:27:43 +00:00
|
|
|
return vid.DrawTextScreen(cpuState.PageTable, screen, charMap)
|
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()
|
|
|
|
|
|
|
|
cpu.InitDisasm()
|
|
|
|
memory := mmu.InitRAM()
|
|
|
|
mmu.InitApple2eROM(memory)
|
|
|
|
|
2018-05-08 21:18:49 +00:00
|
|
|
cpuState.Memory = memory
|
2018-05-09 09:27:43 +00:00
|
|
|
cpuState.PageTable = &memory.PageTable
|
2018-05-08 21:18:49 +00:00
|
|
|
cpuState.Init()
|
2018-05-08 18:32:55 +00:00
|
|
|
|
|
|
|
bootVector := 0xfffc
|
2018-05-09 09:27:43 +00:00
|
|
|
lsb := cpuState.PageTable[bootVector>>8][bootVector&0xff] // TODO move readMemory to mmu
|
|
|
|
msb := cpuState.PageTable[(bootVector+1)>>8][(bootVector+1)&0xff]
|
2018-05-08 21:18:49 +00:00
|
|
|
cpuState.PC = uint16(lsb) + uint16(msb)<<8
|
|
|
|
|
|
|
|
var err error
|
|
|
|
charMap, _, err = ebitenutil.NewImageFromFile("./pr-latin1.png", ebiten.FilterNearest)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ebiten.Run(update, 280*screenSizeFactor, 192*screenSizeFactor, 2, "Apple //e")
|
2018-05-08 18:32:55 +00:00
|
|
|
}
|