-
Notifications
You must be signed in to change notification settings - Fork 0
/
emu.go
123 lines (95 loc) · 2.41 KB
/
emu.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
package vcsgo
// Emulator exposes the public facing fns for an emulation session
type Emulator interface {
Step()
MakeSnapshot() []byte
LoadSnapshot([]byte) (Emulator, error)
Framebuffer() []byte
FlipRequested() bool
ReadSoundBuffer([]byte) []byte
GetSoundBufferUsed() int
SetInput(input Input)
SetDebugContinue(b bool)
GetTVFormat() TVFormat
SetDevMode(b bool)
InDevMode() bool
}
// TVFormat is for PAL/NTSC determination
type TVFormat byte
const (
// FormatNTSC represents NTSC 60fps games
FormatNTSC TVFormat = iota
// FormatPAL represents PAL 50fps games
FormatPAL
)
// Input covers all outside info sent to the Emulator
type Input struct {
// Keys is a bool array of keydown state
Keys [256]bool
ResetButton bool
SelectButton bool
TVBWSwitch bool
P0DifficultySwitch bool
P1DifficultySwitch bool
JoyP0 Joystick
JoyP1 Joystick
Paddle0 Paddle
Paddle1 Paddle
Paddle2 Paddle
Paddle3 Paddle
Keypad0 [12]bool
Keypad1 [12]bool
}
// Joystick represents the buttons on a joystick
type Joystick struct {
Up bool
Down bool
Left bool
Right bool
Button bool
}
// Paddle represents a paddle controller
type Paddle struct {
Button bool
// Position should range from -135 to +135
Position int16
}
func (emu *emuState) SetInput(input Input) {
emu.setInput(input)
}
// NewEmulator creates an emulation session
func NewEmulator(cart []byte, devMode bool) Emulator {
return newState(cart, devMode)
}
func (emu *emuState) MakeSnapshot() []byte {
return emu.makeSnapshot()
}
func (emu *emuState) LoadSnapshot(snapBytes []byte) (Emulator, error) {
return emu.loadSnapshot(snapBytes)
}
func (emu *emuState) Framebuffer() []byte {
return emu.framebuffer()
}
func (emu *emuState) SetDebugContinue(b bool) {
emu.DebugContinue = b
}
// FlipRequested indicates if a draw request is pending
// and clears it before returning
func (emu *emuState) FlipRequested() bool {
return emu.flipRequested()
}
func (emu *emuState) Step() {
emu.step()
}
func (emu *emuState) GetTVFormat() TVFormat {
return emu.TIA.TVFormat
}
// ReadSoundBuffer returns a 44100hz * 16bit * 2ch sound buffer.
// A pre-sized buffer must be provided, which is returned resized
// if the buffer was less full than the length requested.
func (emu *emuState) ReadSoundBuffer(toFill []byte) []byte {
return emu.APU.readSoundBuffer(toFill)
}
func (emu *emuState) GetSoundBufferUsed() int {
return int(emu.APU.buffer.size())
}