texty: add -quit flag to control exit after binary

This commit is contained in:
Zellyn Hunter 2016-09-18 23:27:16 -04:00
parent 9f315748b3
commit cee7042faa
1 changed files with 10 additions and 4 deletions

View File

@ -85,7 +85,7 @@ func (p TextPlotter) OncePerFrame() {
// add a PCAction to quit if address 0 is called, clear the screen, // add a PCAction to quit if address 0 is called, clear the screen,
// call 0x6000, call 0, and dump the screen contents (minus trailing // call 0x6000, call 0, and dump the screen contents (minus trailing
// whitespace). // whitespace).
func RunEmulator(file string) error { func RunEmulator(file string, quit bool) error {
var options []goapple2.Option var options []goapple2.Option
if file != "" { if file != "" {
ColorFG = termbox.ColorDefault ColorFG = termbox.ColorDefault
@ -97,7 +97,7 @@ func RunEmulator(file string) error {
options = append(options, goapple2.WithRAM(0x6000, bytes)) options = append(options, goapple2.WithRAM(0x6000, bytes))
} }
rom := util.ReadRomOrDie("../data/roms/apple2+.rom", 12288) rom := util.ReadRomOrDie("../data/roms/apple2+.rom", 12288)
var charRom [2048]byte charRom := util.ReadSmallCharacterRomOrDie("../data/roms/apple2-chars.rom")
plotter := TextPlotter(0) plotter := TextPlotter(0)
a2 := goapple2.NewApple2(plotter, rom, charRom, options...) a2 := goapple2.NewApple2(plotter, rom, charRom, options...)
if err := termbox.Init(); err != nil { if err := termbox.Init(); err != nil {
@ -114,9 +114,14 @@ func RunEmulator(file string) error {
} }
go func() { go func() {
if file != "" { if file != "" {
for _, ch := range "HOME:CALL 24576:CALL 0" { for _, ch := range "HOME:CALL 24576" {
a2.Keypress(byte(ch)) a2.Keypress(byte(ch))
} }
if quit {
for _, ch := range ":CALL 0" {
a2.Keypress(byte(ch))
}
}
a2.Keypress(13) a2.Keypress(13)
} }
for { for {
@ -154,10 +159,11 @@ func dumpscreen(a2 *goapple2.Apple2) {
} }
var binfile = flag.String("binfile", "", "binary file to load at $6000 and CALL") var binfile = flag.String("binfile", "", "binary file to load at $6000 and CALL")
var quit = flag.Bool("quit", false, "quit after running binary")
func main() { func main() {
flag.Parse() flag.Parse()
if err := RunEmulator(*binfile); err != nil { if err := RunEmulator(*binfile, *quit); err != nil {
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
os.Exit(1) os.Exit(1)
} }