-
Notifications
You must be signed in to change notification settings - Fork 9
/
apple2.go
128 lines (103 loc) · 3 KB
/
apple2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package izapple2
import (
"sync/atomic"
"github.com/ivanizag/iz6502"
"github.com/ivanizag/izapple2/screen"
)
// Apple2 represents all the components and state of the emulated machine
type Apple2 struct {
Name string
cpu *iz6502.State
mmu *memoryManager
io *ioC0Page
video screen.VideoSource
cg *CharacterGenerator
cards [8]Card
tracers []executionTracer
softVideoSwitch *SoftVideoSwitch
board string
isApple2e bool
hasLowerCase bool
isFourColors bool // An Apple II without the 6 color mod
usesMouse bool
commandChannel chan command
dmaActive bool
dmaSlot int
cycles uint64
cycleDurationNs float64 // Current speed. Inverse of the cpu clock in Ghz
fastRequestsCounter int32
cycleBreakpoint uint64
breakPoint bool
profile bool
paused bool
cpuTrace bool
forceCaps bool
removableMediaDrives []drive
currentFreqMHz float64
}
// GetCards returns the array of inserted cards
func (a *Apple2) GetCards() [8]Card {
return a.cards
}
// SetKeyboardProvider attaches an external keyboard provider
func (a *Apple2) SetKeyboardProvider(kb KeyboardProvider) {
a.io.setKeyboardProvider(kb)
}
// SetSpeakerProvider attaches an external keyboard provider
func (a *Apple2) SetSpeakerProvider(s SpeakerProvider) {
a.io.setSpeakerProvider(s)
}
// SetJoysticksProvider attaches an external joysticks provider
func (a *Apple2) SetJoysticksProvider(j JoysticksProvider) {
a.io.setJoysticksProvider(j)
}
// SetMouseProvider attaches an external joysticks provider
func (a *Apple2) SetMouseProvider(m MouseProvider) {
a.io.setMouseProvider(m)
}
// UsesMouse returns true when the emulator uses the mouse
func (a *Apple2) UsesMouse() bool {
return a.usesMouse
}
// IsPaused returns true when emulator is paused
func (a *Apple2) IsPaused() bool {
return a.paused
}
func (a *Apple2) GetCycles() uint64 {
return a.cycles
}
func (a *Apple2) GetCurrentFreqMHz() float64 {
return a.currentFreqMHz
}
// 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
}
func (a *Apple2) GetCgPageInfo() (int, int) {
return a.cg.getPage(), a.cg.getPages()
}
func (a *Apple2) RequestFastMode() {
// Note: if the fastMode is shorter than maxWaitDuration, there won't be any gain.
atomic.AddInt32(&a.fastRequestsCounter, 1)
}
func (a *Apple2) ReleaseFastMode() {
atomic.AddInt32(&a.fastRequestsCounter, -1)
}
func (a *Apple2) registerRemovableMediaDrive(d drive) {
a.removableMediaDrives = append(a.removableMediaDrives, d)
}
func (a *Apple2) GetVideoSource() screen.VideoSource {
return a.video
}