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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
/*
espec - Sinclair Spectrum emulator
Copyright (C) 2003 Ian Cowburn (ianc@noddybox.demon.co.uk)
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 2 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-------------------------------------------------------------------------
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "SDL.h"
#include "z80.h"
#include "spec.h"
#include "gfx.h"
#include "gui.h"
#include "memmenu.h"
#include "config.h"
#include "kbbmp.h"
#include "exit.h"
#include "util.h"
/* ---------------------------------------- MACROS
*/
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
/* ---------------------------------------- STATICS
*/
static Uint32 white;
static Uint32 black;
static Uint32 grey;
/* ---------------------------------------- PRIVATE FUNCTIONS
*/
static void Usage(void)
{
fprintf(stderr,"usage: espec [-m] [-l tape_file] [-s tape_file]\n");
exit(EXIT_FAILURE);
}
/* ---------------------------------------- MAIN
*/
int main(int argc, char *argv[])
{
char tape_in[FILENAME_MAX]="";
char tape_out[FILENAME_MAX]="";
Z80 *z80;
SDL_Event *e;
int quit;
int trace;
int inital_menu;
int f;
ConfigRead();
trace=IConfig(CONF_TRACE);
z80=Z80Init(SPECPeek,SPECPoke,SPECReadPort,SPECWritePort,SPECDisPeek);
/* Z80SetLabels(z80,SPECGetLabel()); */
GFXInit();
SPECInit(z80);
white=GFXRGB(255,255,255);
grey=GFXRGB(128,128,128);
black=GFXRGB(0,0,0);
quit=FALSE;
/* Parse switches
*/
inital_menu=FALSE;
tape_in[0]=0;
tape_out[0]=0;
f=1;
while(f<argc && argv[f][0]=='-')
{
switch(argv[f][1])
{
case 'm':
inital_menu=TRUE;
break;
case 'l':
if (f>argc-2)
{
Usage();
}
strcpy(tape_in,argv[++f]);
break;
case 's':
if (f>argc-2)
{
Usage();
}
strcpy(tape_out,argv[++f]);
break;
default:
Usage();
break;
}
f++;
}
if (inital_menu)
{
quit=MemoryMenu(z80);
}
if (tape_in[0])
{
SPECMount(SPEC_TAPE_IN,tape_in);
}
if (tape_out[0])
{
SPECMount(SPEC_TAPE_IN,tape_out);
}
/* Main loop
*/
while(!quit)
{
const char *brk;
Z80SingleStep(z80);
if (trace)
{
DisplayState(z80);
GFXEndFrame(FALSE);
}
if ((brk=Break()))
{
GUIMessage(eMessageBox,"BREAKPOINT","%s",brk);
quit=MemoryMenu(z80);
}
while(!quit && (e=GFXGetKey()))
{
switch (e->key.keysym.sym)
{
case SDLK_ESCAPE:
if (e->key.state==SDL_PRESSED)
quit=GUIMessage(eYesNoBox,"QUIT","Sure?");
break;
case SDLK_F1:
if (e->key.state==SDL_PRESSED)
GUIMessage(eMessageBox,
"HELP",
"ESC - Quit \n"
"F1 - Help \n"
"F2 - About \n"
"F3 - View Spectrum keyboad \n"
"F4 - View mounted tapes \n"
"F8 - Select tape file for loading\n"
"F9 - Select tape file for saving \n"
"F10 - Close all open tape files \n"
"F11 - Memory Menu \n"
"F12 - Toggle onscreen trace ");
break;
case SDLK_F2:
if (e->key.state==SDL_PRESSED)
GUIMessage(eMessageBox,
"espec - ZX Spectrum Emulator",
"(c) 2004 Ian Cowburn\n"
" \n"
"This software comes with ABSOLUTELY \n"
"NO WARRANTY, and you are free to \n"
"to redistribute it under certain \n"
"conditions. See the supplied GNU \n"
"General Public License in LICENSE \n"
"for details. \n"
" \n"
"If you did not recieve a license, \n"
"vist www.gnu.org or wrote to: \n"
" \n"
"Free Software Foundation, Inc., \n"
"59 Temple Place, Suite 330, \n"
"Boston, MA 02111-1307 USA ");
break;
case SDLK_F3:
if (e->key.state==SDL_PRESSED)
{
GFXBitmap((GFX_WIDTH-KBBMP_WIDTH)/2,
(GFX_HEIGHT-KBBMP_HEIGHT)/2,
KBBMP_WIDTH, KBBMP_HEIGHT,
keyboard_bitmap);
GFXEndFrame(FALSE);
GFXWaitKey();
}
break;
case SDLK_F4:
if (e->key.state==SDL_PRESSED)
GUIMessage(eMessageBox,
"Mounted Tape Files",
"In: %-20.20s\nOut: %-20.20s",
tape_in[0] ? Basename(tape_in):"None",
tape_out[0] ? Basename(tape_out):"None");
break;
case SDLK_F8:
if (e->key.state==SDL_PRESSED)
{
if (GUIFileSelect("TAPE TO LOAD",TRUE,
tape_in[0] ?
Dirname(tape_in) :
SConfig(CONF_TAPEDIR),
tape_in))
{
SPECMount(SPEC_TAPE_IN,tape_in);
}
}
break;
case SDLK_F9:
if (e->key.state==SDL_PRESSED)
{
if (GUIFileSelect("TAPE TO SAVE",FALSE,
tape_out[0] ?
Dirname(tape_out) :
SConfig(CONF_TAPEDIR),
tape_out))
{
SPECMount(SPEC_TAPE_OUT,tape_out);
}
}
break;
case SDLK_F10:
if (e->key.state==SDL_PRESSED)
{
SPECUnmount(SPEC_TAPE_IN);
SPECUnmount(SPEC_TAPE_OUT);
}
break;
case SDLK_F11:
if (e->key.state==SDL_PRESSED)
quit=MemoryMenu(z80);
break;
case SDLK_F12:
if (e->key.state==SDL_PRESSED)
trace=!trace;
break;
default:
SPECKeyEvent(e);
break;
}
}
}
return EXIT_SUCCESS;
}
/* END OF FILE */
|