Beispiel #1
0
func typeProgram(a2 *goapple2.Apple2) {
	return
	lines := []string{
		"10 GR",
		"20 POKE -16302,0",
		"30 FOR Y=0 TO 47",
		"40 FOR X=0 TO 39",
		"50 COLOR=INT(RND(1)*16)",
		"60 PLOT X,Y",
		"70 NEXT",
		"80 NEXT",
		"RUN",
	}
	lines = []string{
		"10 HGR2",
		"20 FOR I = 0 to 7",
		"30 HCOLOR=7-I",
		"40 HPLOT I*10, 0 TO 191 + I*10, 191",
		"50 NEXT",
		"RUN",
	}
	for _, line := range lines {
		for _, ch := range line {
			a2.Keypress(byte(ch))
		}
		a2.Keypress(13)
	}
}
Beispiel #2
0
func ProcessEvents(events chan termbox.Event, a2 *goapple2.Apple2) bool {
	select {
	case ev := <-events:
		if ev.Type == termbox.EventKey && ev.Ch == '~' {
			return true
		}
		if ev.Type == termbox.EventKey {
			if key, err := termboxToAppleKeyboard(ev); err == nil {
				a2.Keypress(key)
			}
		}
	default:
	}

	return false
}
Beispiel #3
0
func ProcessEvents(events <-chan interface{}, a2 *goapple2.Apple2) (done bool) {
	select {
	case _event := <-events:
		switch e := _event.(type) {
		case sdl.QuitEvent:
			return true
		case sdl.KeyboardEvent:
			if e.Type == sdl.KEYDOWN {
				if e.Keysym.Sym == sdl.K_F1 {
					return true
				}
				if e.Keysym.Mod == sdl.KMOD_LCTRL && e.Keysym.Sym == sdl.K_LEFTBRACKET {
					return true
				}
				if key, err := sdlToAppleKeyboard(e.Keysym); err == nil {
					a2.Keypress(key)
				}
			}
		}
	default:
		// Nothing to do here
	}
	return false
}
Beispiel #4
0
// Run the emulator
func RunEmulator() {
	rom := util.ReadRomOrDie("../data/roms/apple2+.rom")
	// charRom = util.ReadFullCharacterRomOrDie("../data/roms/apple2char.rom")
	charRom := util.ReadSmallCharacterRomOrDie("../data/roms/apple2-chars.rom")
	screen, err := Init()
	if err != nil {
		panic(err)
	}
	var a2 *goapple2.Apple2
	oncePerFrame := func() {
		a2.Done = a2.Done || ProcessEvents(sdl.Events, a2)
		runtime.Gosched()
	}
	plotter := SdlPlotter{screen, oncePerFrame}
	a2 = goapple2.NewApple2(plotter, rom, charRom)

	intBasicRom := util.ReadRomOrDie("../data/roms/apple2.rom")
	firmwareCard, err := cards.NewFirmwareCard(intBasicRom, "Intbasic Firmware Card", 0, a2)
	if err != nil {
		panic(err)
	}
	if err := a2.AddCard(firmwareCard); err != nil {
		log.Fatal(err)
	}

	diskCardRom := util.ReadRomOrDie("../data/roms/Apple Disk II 16 Sector Interface Card ROM P5 - 341-0027.bin")
	diskCard, err := cards.NewDiskCard(diskCardRom, 6, a2)
	if err != nil {
		panic(err)
	}
	if err := a2.AddCard(diskCard); err != nil {
		log.Fatal(err)
	}
	// disk1, err := disk.DiskFromFile("../data/disks/spedtest.dsk", 0)
	// disk1, err := disk.DiskFromFile("../data/disks/dung_beetles.dsk", 0)
	disk1, err := disk.DiskFromFile("../data/disks/chivalry.dsk", 0)
	if err != nil {
		log.Fatal(err)
	}
	diskCard.LoadDisk(disk1, 0)

	steps := *steplimit

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	/*
			a2.AddPCAction(
				0xB940, goapple2.PCAction{Type: goapple2.ActionDumpMem, String: "0xB940-goa2.bin",
					Mask: cpu.FLAG_Z, Masked: cpu.FLAG_Z, Delay: 68})
		a2.AddPCAction(0xB7B5, goapple2.PCAction{Type: goapple2.ActionHere, String: "ENTER.RWTS"})
		a2.AddPCAction(0xB7BE, goapple2.PCAction{Type: goapple2.ActionHere, String: "ENTER.RWTS - Success"})
		a2.AddPCAction(0xB7C1, goapple2.PCAction{Type: goapple2.ActionHere, String: "ENTER.RWTS - Fail"})
		a2.AddPCAction(0xBD00, goapple2.PCAction{Type: goapple2.ActionHere, String: "RWTS"})
		a2.AddPCAction(0xBDAF, goapple2.PCAction{Type: goapple2.ActionHere, String: "RWTS Command"})
		// a2.AddPCAction(0xBE35, goapple2.PCAction{Type: goapple2.ActionHere, String: "RWTS READ.SECTOR call"})
		// a2.AddPCAction(0xBE38, goapple2.PCAction{Type: goapple2.ActionHere, String: "RWTS READ.SECTOR success"})

		a2.AddPCAction(0xBE46, goapple2.PCAction{Type: goapple2.ActionHere, String: "RWTS Success"})
		a2.AddPCAction(0xBE48, goapple2.PCAction{Type: goapple2.ActionHere, String: "RWTS Error"})

		a2.AddPCAction(0xBDAF, goapple2.PCAction{Type: goapple2.ActionDiskStatus})

		a2.AddPCAction(0xBDAF, goapple2.PCAction{Type: goapple2.ActionTrace, String: "on",
			Delay: 70})

		a2.AddPCAction(
			0xBE48, goapple2.PCAction{Type: goapple2.ActionSetLimit, String: "1"})

		a2.AddPCAction(
			0xBDAF, goapple2.PCAction{Type: goapple2.ActionDumpMem, String: "0xBDAF-goa2.bin", Delay: 68})
	*/
	_ = cpu.FLAG_Z

	// go typeProgram(a2)

	for !a2.Done {
		err := a2.Step()
		if err != nil {
			fmt.Println(err)
			break
		}
		// runtime.Gosched() // So the keyboard-reading goroutines can run
		if steps > 0 {
			steps--
			if steps == 0 {
				a2.Quit()
			}
		}
	}
	a2.Quit()
	sdl.Quit()
}