-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoptions_common.cpp
executable file
·250 lines (221 loc) · 6.5 KB
/
options_common.cpp
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
Portable ZX-Spectrum emulator.
Copyright (C) 2001-2010 SMT, Dexus, Alone Coder, deathsoft, djdron, scor
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "platform/platform.h"
#include "platform/io.h"
#include "tools/options.h"
#include "ui/ui.h"
#include "options_common.h"
namespace xPlatform
{
#if defined(USE_UI) || defined(USE_OPTIONS_COMMON)
struct eOptionState : public xOptions::eOptionB
{
eOptionState() { storeable = false; }
const char* SnapshotName() const
{
static char name[xIo::MAX_PATH_LEN];
strcpy(name, OpLastFile());
int l = strlen(name);
if(!l || name[l - 1] == '/' || name[l - 1] == '\\')
return NULL;
char* e = name + l;
while(e > name && *e != '.' && *e != '\\' && *e != '/')
--e;
if(*e != '.')
return NULL;
*e = '\0';
strcat(name, ".sna");
return name;
}
};
static struct eOptionSaveState : public eOptionState
{
virtual const char* Name() const { return "save state"; }
virtual void Change(bool next = true)
{
const char* name = SnapshotName();
if(name)
Handler()->OnSaveFile(name);
}
virtual int Order() const { return 1; }
} op_save_state;
static struct eOptionLoadState : public eOptionState
{
virtual const char* Name() const { return "load state"; }
virtual void Change(bool next = true)
{
const char* name = SnapshotName();
if(name)
Handler()->OnOpenFile(name);
}
virtual int Order() const { return 2; }
} op_load_state;
static struct eOptionTape : public xOptions::eOptionInt
{
eOptionTape() { storeable = false; }
virtual const char* Name() const { return "tape"; }
virtual const char** Values() const
{
static const char* values[] = { "n/a", "stop", "start", NULL };
return values;
}
virtual void Change(bool next = true)
{
switch(Handler()->OnAction(A_TAPE_TOGGLE))
{
case AR_TAPE_NOT_INSERTED: Set(0); break;
case AR_TAPE_STOPPED: Set(1); break;
case AR_TAPE_STARTED: Set(2); break;
default: break;
}
}
virtual int Order() const { return 40; }
} op_tape;
static struct eOptionSound : public xOptions::eOptionInt
{
eOptionSound() { Set(S_AY); }
virtual const char* Name() const { return "sound"; }
virtual const char** Values() const
{
static const char* values[] = { "beeper", "ay", "tape", NULL };
return values;
}
virtual void Change(bool next = true)
{
eOptionInt::Change(S_FIRST, S_LAST, next);
}
virtual int Order() const { return 20; }
} op_sound;
static struct eOptionVolume : public xOptions::eOptionInt
{
eOptionVolume() { Set(V_50); }
virtual const char* Name() const { return "volume"; }
virtual const char** Values() const
{
static const char* values[] = { "mute", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%", NULL };
return values;
}
virtual void Change(bool next = true)
{
eOptionInt::Change(V_FIRST, V_LAST, next);
}
virtual int Order() const { return 30; }
} op_volume;
static struct eOptionPause : public xOptions::eOptionBool
{
eOptionPause() { storeable = false; }
virtual const char* Name() const { return "pause"; }
virtual void Change(bool next = true)
{
eOptionBool::Change();
Handler()->VideoPaused(self);
}
virtual int Order() const { return 70; }
} op_pause;
eVolume OpVolume() { return (eVolume)(int)op_volume; }
void OpVolume(eVolume v) { op_volume.Set(v); }
eSound OpSound() { return (eSound)(int)op_sound; }
void OpSound(eSound s) { op_sound.Set(s); }
#else//USE_UI || USE_OPTIONS_COMMON
eVolume OpVolume() { return V_100; }
void OpVolume(eVolume v) {}
eSound OpSound() { return S_AY; }
void OpSound(eSound s) {}
#endif//USE_UI || USE_OPTIONS_COMMON
static struct eOptionJoy : public xOptions::eOptionInt
{
eOptionJoy() { Set(J_KEMPSTON); }
virtual const char* Name() const { return "joystick"; }
virtual const char** Values() const
{
static const char* values[] = { "kempston", "cursor", "qaop", "sinclair2", NULL };
return values;
}
virtual void Change(bool next = true)
{
eOptionInt::Change(J_FIRST, J_LAST, next);
}
virtual int Order() const { return 10; }
} op_joy;
static struct eOptionDrive : public xOptions::eOptionInt
{
eOptionDrive() { storeable = false; Set(D_A); }
virtual const char* Name() const { return "drive"; }
virtual const char** Values() const
{
static const char* values[] = { "A", "B", "C", "D", NULL };
return values;
}
virtual void Change(bool next = true)
{
eOptionInt::Change(D_FIRST, D_LAST, next);
}
virtual int Order() const { return 60; }
} op_drive;
static struct eOptionReset : public xOptions::eOptionB
{
eOptionReset() { storeable = false; }
virtual const char* Name() const { return "reset"; }
virtual void Change(bool next = true) { Handler()->OnAction(A_RESET); }
virtual int Order() const { return 80; }
} op_reset;
static struct eOptionQuit : public xOptions::eOptionBool
{
eOptionQuit() { storeable = false; }
virtual const char* Name() const { return "quit"; }
virtual int Order() const { return 100; }
virtual const char** Values() const { return NULL; }
} op_quit;
static struct eOptionLastFile : public xOptions::eOptionString
{
eOptionLastFile() { customizable = false; }
virtual const char* Name() const { return "last file"; }
} op_last_file;
const char* OpLastFile() { return op_last_file; }
const char* OpLastFolder()
{
static char lf[xIo::MAX_PATH_LEN];
strcpy(lf, OpLastFile());
char* n = lf;
char* n_end = n + strlen(n);
while(n_end > n && *n_end != '\\' && *n_end != '/')
--n_end;
if(*n_end == '\\' || *n_end == '/')
{
++n_end;
*n_end = '\0';
}
return lf;
}
void OpLastFile(const char* name) { op_last_file.Set(name); }
bool OpQuit() { return op_quit; }
void OpQuit(bool v) { op_quit.Set(v); }
eDrive OpDrive() { return (eDrive)(int)op_drive; }
void OpDrive(eDrive d) { op_drive.Set(d); }
eJoystick OpJoystick() { return (eJoystick)(int)op_joy; }
void OpJoystick(eJoystick v) { op_joy.Set(v); }
dword OpJoyKeyFlags()
{
switch(op_joy)
{
case J_KEMPSTON: return KF_KEMPSTON;
case J_CURSOR: return KF_CURSOR;
case J_QAOP: return KF_QAOP;
case J_SINCLAIR2: return KF_SINCLAIR2;
}
return KF_QAOP;
}
}
//namespace xPlatform