izapple2/apple2.go

102 lines
2.5 KiB
Go
Raw Normal View History

2020-10-03 21:38:26 +00:00
package izapple2
import (
2022-05-10 11:40:17 +00:00
"sync/atomic"
"github.com/ivanizag/iz6502"
)
2019-03-02 19:41:25 +00:00
// Apple2 represents all the components and state of the emulated machine
type Apple2 struct {
2024-01-06 20:48:23 +00:00
Name string
cpu *iz6502.State
mmu *memoryManager
io *ioC0Page
cg *CharacterGenerator
cards [8]Card
tracers []executionTracer
softVideoSwitch *SoftVideoSwitch
board string
isApple2e bool
2024-02-08 19:24:37 +00:00
isFourColors bool // An Apple II without the 6 color mod
2024-01-06 20:48:23 +00:00
commandChannel chan command
2023-04-04 16:35:13 +00:00
cycleDurationNs float64 // Current speed. Inverse of the cpu clock in Ghz
fastRequestsCounter int32
cycleBreakpoint uint64
breakPoint bool
profile bool
showSpeed bool
paused bool
forceCaps bool
removableMediaDrives []drive
}
2024-01-06 20:48:23 +00:00
// GetCards returns the array of inserted cards
func (a *Apple2) GetCards() [8]Card {
return a.cards
2021-04-02 18:39:37 +00:00
}
2024-01-06 20:48:23 +00:00
// SetKeyboardProvider attaches an external keyboard provider
func (a *Apple2) SetKeyboardProvider(kb KeyboardProvider) {
a.io.setKeyboardProvider(kb)
}
2024-01-06 20:48:23 +00:00
// SetSpeakerProvider attaches an external keyboard provider
func (a *Apple2) SetSpeakerProvider(s SpeakerProvider) {
a.io.setSpeakerProvider(s)
2022-05-10 11:40:17 +00:00
}
2019-10-19 18:31:18 +00:00
2024-01-06 20:48:23 +00:00
// SetJoysticksProvider attaches an external joysticks provider
func (a *Apple2) SetJoysticksProvider(j JoysticksProvider) {
a.io.setJoysticksProvider(j)
2019-04-13 18:29:31 +00:00
}
2024-01-06 20:48:23 +00:00
// SetMouseProvider attaches an external joysticks provider
func (a *Apple2) SetMouseProvider(m MouseProvider) {
a.io.setMouseProvider(m)
2020-10-27 23:43:33 +00:00
}
2020-03-14 02:29:12 +00:00
// IsPaused returns true when emulator is paused
func (a *Apple2) IsPaused() bool {
return a.paused
}
2022-05-10 11:40:17 +00:00
func (a *Apple2) GetCycles() uint64 {
return a.cpu.GetCycles()
}
// SetCycleBreakpoint sets a cycle number to pause the emulator. 0 to disable
func (a *Apple2) SetCycleBreakpoint(cycle uint64) {
a.cycleBreakpoint = cycle
a.breakPoint = false
}
func (a *Apple2) BreakPoint() bool {
return a.breakPoint
}
// IsProfiling returns true when profiling
func (a *Apple2) IsProfiling() bool {
return a.profile
}
// IsForceCaps returns true when all letters are forced to upper case
func (a *Apple2) IsForceCaps() bool {
return a.forceCaps
}
2022-05-10 11:40:17 +00:00
func (a *Apple2) RequestFastMode() {
// Note: if the fastMode is shorter than maxWaitDuration, there won't be any gain.
2024-01-06 20:48:23 +00:00
atomic.AddInt32(&a.fastRequestsCounter, 1)
}
2022-05-10 11:40:17 +00:00
func (a *Apple2) ReleaseFastMode() {
2024-01-06 20:48:23 +00:00
atomic.AddInt32(&a.fastRequestsCounter, -1)
2020-06-07 16:23:39 +00:00
}
2024-01-06 20:48:23 +00:00
func (a *Apple2) registerRemovableMediaDrive(d drive) {
a.removableMediaDrives = append(a.removableMediaDrives, d)
2019-05-18 21:40:59 +00:00
}