This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMAIN.CPP
executable file
·323 lines (237 loc) · 5.42 KB
/
MAIN.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
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
//6502 nes emulator front end
//main platform independant
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <mem.h>
#include <malloc.h>
#include <direct.h>
#include "config.h"
#include "keyb.h"
#include "types.h"
#include "r2img.h"
#include "font.h"
#include "file.h"
#include "vol.h"
#include "mouse.h"
#include "message.h"
#include "dd.h"
#include "guivol.h"
#include "gui.h"
#include "uutimer.h"
#include "nesvideo.h"
#include "nessound.h"
#include "nes.h"
#include "timing.h"
#include "command.h"
#include "m6502\m6502.h"
#include "prof.h"
#include "sound.h"
char appname[]="NESticle";
char configfile[]="NESticle.cfg";
char palfile[]="NESticle.pal";
float version=0.2;
#ifdef WIN95
int SCREENX=640;
int SCREENY=480;
#else
int SCREENX=256;
int SCREENY=224;
#endif
anesprofile pf;
//config info
config *cfg;
//input devices
input *inputdevice[2];
inputdevicesettings *ids;
//sound sampling rate (default)
int SOUNDRATE=22050;
GUIVOL guivol;
int GUIVOL::size() {return sizeof(GUIVOL);}
FONT *font[16]; //fonts
COLORMAP *shadowmap; //shaded colormapping
volatile unsigned uu=1,su=1;
//buffer for messages
msgbuffer msg;
//root of a32
class ROOT *root=0;
//main root of gui tree
GUIroot *guiroot=0;
extern byte showcpuutilization;
extern int guienabled;
void enablegui();
void disablegui();
void togglegui();
int keyboard();
void initdefaultgui();
//create all the fonts and colors
void createfonts()
{
static byte fontcolor[8][2]=
{
{0xc6,0xd8}, //peach
{0xf,0}, //white
{6*16,0}, //green
{19,0}, //grey
{0,15}, //black
{0x21,0}, //red
{0xA3,0}, //pink
{0x82,0} //blue
};
for (int i=0; i<8; i++)
{
font[i]=guivol.font->duplicate();
font[i]->convertcolor((byte)0xca,fontcolor[i][0]);
font[i]->convertcolor((byte)0xdb,fontcolor[i][1]);
}
}
void initializenespalette();
//initialize
int initgame()
{
//set up keyboard handler
set_keyboard_func(keyboard);
//initialize input devices
ids=&cfg->ids; //copy over input settings
inputdevice[0]=newinputdevice(cfg->pinput[0]);
inputdevice[1]=newinputdevice(cfg->pinput[1]);
//load up graphics and shit
if (!guivol.read("gui.vol")) return -1;
//get palette
initializenespalette();
cfg->set(CFG_NOFILLEDDESKTOP,0); //force desktop to be drawn
//fixup pal to 8bit
for (int i=0; i<256; i++)
{
guivol.pal->c[i].r<<=2;
guivol.pal->c[i].g<<=2;
guivol.pal->c[i].b<<=2;
}
setpalette(guivol.pal);
//create fonts
createfonts();
//create root
root=new ROOT;
//create root of all GUI
new GUIroot(root);
initdefaultgui();
return 0;
}
void m_stop();
void terminategame()
{
m_stop();
freerom();
delete root;
guivol.free();
delete cfg;
}
void tickemu(); //tick emulation
void gametimer()
{
uu++;
input::refreshtimer();
inputdevice[0]->read();
inputdevice[1]->read();
if (CPURunning || (CPUpaused && (CPUtrace || CPUtickframe>0)))
{
tickemu();
if (CPUtickframe>0) CPUtickframe--;
}
}
int keyboard()
{
// if (kbscan==KB_ESC) {quitgame(); return 1;}
if (kbscan==KB_ESC) {togglegui(); return 1;}
if (input::refreshkeyboard(kbscan)) return 1; //dont add key to queue
if (kbscan&0x80) return 1; //release
char key=scan2ascii(kbscan);
// if (root && root->keyhit(kbscan,key)) enablegui();
if (root && root->keyhit(kbscan,key)) return 1;
if (key==' ' && nv)
{
if (guienabled) {disablegui(); ((GUImaximizebox *)nv->parent)->maximize();}
else {enablegui(); if (SCREENX>320) ((GUImaximizebox *)nv->parent)->restore();}
}
return 1;
}
void updatescreen()
{
pf.input_timer.enter();
input::refreshmain();
pf.input_timer.leave();
if (guienabled)
{
pf.gui_timer.enter();
//draw everything
root->draw(screen);
m.draw(screen); //draw cursor
pf.gui_timer.leave();
} else if (nv) nv->draw(screen);
pf.frames.inc();
su++;
pf.update();
if (showcpuutilization)
{
pf.gui_timer.enter();
pf.draw(SCREENX-60,50);
pf.gui_timer.leave();
}
if (cfg->get(CFG_SHOWFPS))
{
drawrect(screen,0,SCREENX-70+23,40-1,30,10);
font[3]->printf(SCREENX-70,40,"fps=%4.1f",pf.frames.getrate());
}
// font[0]->printf(SCREENX-150,80,"%X",m6502pc);
// font[0]->printf(SCREENX-150,80,"%d",blah);
//font[0]->printf(SCREENX-150,80,"%d %d",blah,blah2);
}
//------------------------------
// ROOT node
//------------------------------
ROOT::ROOT():GUIrect(0,0,0,SCREENX,SCREENY){}
ROOT::~ROOT() {}
void ROOT::resize(int xw,int yw)
{
if (guiroot) guiroot->resize(xw,yw);
if (nv && nv->maximized) nv->resize(xw,yw);
GUIrect::resize(xw,yw);
}
void ROOT::refresh(int r,void *c)
{for (GUIrect *g=child; g; g=g->next) g->refresh(r,c);};
//-----------------
int cmd_loadrom(char *p)
{
char s[128];
if (sscanf(p,"%s",s)<1) return 0;
loadrom(p);
return 1;
}
int cmd_runrom(char *p)
{
char s[128];
if (sscanf(p,"%s",s)<1) return 0;
loadrom(p);
if (nv)
{
disablegui();
((GUImaximizebox *)nv->parent)->maximize();
m_reset();
}
return 1;
}
void m_loadstate();
int cmd_restorerom(char *p)
{
char s[128];
if (sscanf(p,"%s",s)<1) return 0;
loadrom(p);
if (nv)
{
disablegui();
((GUImaximizebox *)nv->parent)->maximize();
m_loadstate();
if (!CPURunning) m_reset();
}
return 1;
}