mirror of
https://github.com/ivanizag/izapple2.git
synced 2026-10-22 00:02:27 +00:00
A file dropped on the window went to drive 1 or drive 2 depending on the half it landed on. There was no way to know beforehand which drive was which or what each one had inserted, and no sign afterwards of where the file went. The machines with two Disk II cards have four drives and only the first two could be reached. F8 now shows a screen with one area per removable media drive, each with the name of its drive and the image it has inserted, or EMPTY, and the same screen appears for a moment after a drop with the drive that got the file marked. It is a text screen of 80 columns rendered the same way the help is, so SnapshotMessageGenerator takes the number of columns now. The drives register with a label and tell the media they have, so the frontends ask the machine with GetRemovableMediaDrives instead of assuming two. The name of the media is written by the emulation goroutine and read by the frontends, hence the atomic access. The new frontend/shared package holds what the frontends have in common and the emulator library has no place for: the composition of the screen and the mapping from a position to a drive. a2sdl reads the position of the pointer on the desktop when the file is dropped. The mouse motion events do not arrive while another application drags a file, so the last known position was stale and the file could land on the wrong drive. a2sdl3 shows the areas while the file is being dragged over the window, which is something only SDL3 reports. a2ebiten had no drag and drop at all, although the help it shows said otherwise. Ebitengine hides the paths of the files dropped, but it opens the real files and the handle tells the path back, so the images are loaded like on every other frontend, compressed files included.
108 lines
2.5 KiB
Go
108 lines
2.5 KiB
Go
package izapple2
|
|
|
|
import "fmt"
|
|
|
|
const (
|
|
// CommandToggleSpeed toggles cpu speed between full speed and actual Apple II speed
|
|
CommandToggleSpeed = iota + 1
|
|
// CommandShowSpeed toggles printinf the current freq in Mhz
|
|
CommandShowSpeed
|
|
// CommandDumpDebugInfo dumps useful info
|
|
CommandDumpDebugInfo
|
|
// CommandNextCharGenPage cycles the CharGen page if several
|
|
CommandNextCharGenPage
|
|
// CommandToggleCPUTrace toggle tracing of CPU execution
|
|
CommandToggleCPUTrace
|
|
// CommandKill stops the cpu execution loop
|
|
CommandKill
|
|
// CommandReset executes a 6502 reset
|
|
CommandReset
|
|
// CommandPauseUnpause allows the Pause button to freeze the emulator for a coffee break
|
|
CommandPauseUnpause
|
|
// CommandPause pauses the emulator
|
|
CommandPause
|
|
// CommandStart restarts the emulator
|
|
CommandStart
|
|
// CommandComplex for commands that use a struct with parameters
|
|
CommandComplex
|
|
)
|
|
|
|
type command interface {
|
|
getId() int
|
|
}
|
|
|
|
type commandSimple struct {
|
|
id int
|
|
}
|
|
|
|
type commandLoadDisk struct {
|
|
drive int
|
|
path string
|
|
}
|
|
|
|
func (c *commandSimple) getId() int {
|
|
return c.id
|
|
}
|
|
|
|
func (c *commandLoadDisk) getId() int {
|
|
return CommandComplex
|
|
}
|
|
|
|
func (a *Apple2) queueCommand(c command) {
|
|
a.commandChannel <- c
|
|
}
|
|
|
|
// SendCommand enqueues a command to the emulator thread
|
|
func (a *Apple2) SendCommand(commandId int) {
|
|
var c commandSimple
|
|
c.id = commandId
|
|
a.queueCommand(&c)
|
|
}
|
|
|
|
func (a *Apple2) SendLoadDisk(drive int, path string) {
|
|
var c commandLoadDisk
|
|
c.drive = drive
|
|
c.path = path
|
|
a.queueCommand(&c)
|
|
}
|
|
|
|
func (a *Apple2) executeCommand(command command) {
|
|
switch command.getId() {
|
|
case CommandToggleSpeed:
|
|
if a.cycleDurationNs == 0 {
|
|
// fmt.Println("Slow")
|
|
a.cycleDurationNs = 1000.0 / CPUClockMhz
|
|
} else {
|
|
// fmt.Println("Fast")
|
|
a.cycleDurationNs = 0
|
|
}
|
|
case CommandShowSpeed:
|
|
fmt.Printf("Freq: %f Mhz\n", a.GetCurrentFreqMHz())
|
|
case CommandDumpDebugInfo:
|
|
a.dumpDebugInfo()
|
|
case CommandNextCharGenPage:
|
|
a.cg.nextPage()
|
|
fmt.Printf("Chargen page %v\n", a.cg.page)
|
|
case CommandToggleCPUTrace:
|
|
a.cpuTrace = !a.cpuTrace
|
|
a.cpu.SetTrace(a.cpuTrace)
|
|
case CommandReset:
|
|
a.reset()
|
|
case CommandComplex:
|
|
switch t := command.(type) {
|
|
case *commandLoadDisk:
|
|
err := a.changeDisk(t.drive, t.path)
|
|
if err != nil {
|
|
fmt.Printf("Could no load file %v\n%v\n", t.path, err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func (a *Apple2) changeDisk(unit int, path string) error {
|
|
if unit >= 0 && unit < len(a.removableMediaDrives) {
|
|
return a.removableMediaDrives[unit].drive.insertDiskette(path)
|
|
}
|
|
return fmt.Errorf("unit %v not defined", unit)
|
|
}
|