forked from tonioni/WinUAE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
devices.cpp
433 lines (400 loc) · 8.02 KB
/
devices.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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#include "sysconfig.h"
#include "sysdeps.h"
#include "devices.h"
#include "options.h"
#include "threaddep/thread.h"
#include "memory.h"
#include "audio.h"
#include "gfxboard.h"
#include "scsi.h"
#include "scsidev.h"
#include "sana2.h"
#include "clipboard.h"
#include "cpuboard.h"
#include "sndboard.h"
#include "statusline.h"
#include "uae/ppc.h"
#include "cd32_fmv.h"
#include "akiko.h"
#include "disk.h"
#include "cia.h"
#include "inputdevice.h"
#include "blkdev.h"
#include "parallel.h"
#include "autoconf.h"
#include "sampler.h"
#include "newcpu.h"
#include "blitter.h"
#include "xwin.h"
#include "custom.h"
#include "serial.h"
#include "bsdsocket.h"
#include "uaeserial.h"
#include "uaeresource.h"
#include "native2amiga.h"
#include "dongle.h"
#include "gensound.h"
#include "gui.h"
#include "savestate.h"
#include "uaeexe.h"
#include "uaenative.h"
#include "tabletlibrary.h"
#include "luascript.h"
#include "driveclick.h"
#include "x86.h"
#include "ethernet.h"
#include "drawing.h"
#include "videograb.h"
#include "rommgr.h"
#include "newcpu.h"
#ifdef RETROPLATFORM
#include "rp.h"
#endif
#define MAX_DEVICE_ITEMS 64
static void add_device_item(DEVICE_VOID *pp, int *cnt, DEVICE_VOID p)
{
for (int i = 0; i < *cnt; i++) {
if (pp[i] == p)
return;
}
if (*cnt >= MAX_DEVICE_ITEMS) {
return;
}
pp[(*cnt)++] = p;
}
static void execute_device_items(DEVICE_VOID *pp, int cnt)
{
for (int i = 0; i < cnt; i++) {
pp[i]();
}
}
static int device_configs_cnt;
static DEVICE_VOID device_configs[MAX_DEVICE_ITEMS];
static int device_vsync_pre_cnt;
static DEVICE_VOID device_vsyncs_pre[MAX_DEVICE_ITEMS];
static int device_vsync_post_cnt;
static DEVICE_VOID device_vsyncs_post[MAX_DEVICE_ITEMS];
static int device_hsync_cnt;
static DEVICE_VOID device_hsyncs[MAX_DEVICE_ITEMS];
static int device_rethink_cnt;
static DEVICE_VOID device_rethinks[MAX_DEVICE_ITEMS];
static int device_leave_cnt;
static DEVICE_VOID device_leaves[MAX_DEVICE_ITEMS];
static int device_resets_cnt;
static DEVICE_INT device_resets[MAX_DEVICE_ITEMS];
static bool device_reset_done[MAX_DEVICE_ITEMS];
static void reset_device_items(void)
{
device_configs_cnt = 0;
device_vsync_pre_cnt = 0;
device_vsync_post_cnt = 0;
device_hsync_cnt = 0;
device_rethink_cnt = 0;
device_resets_cnt = 0;
device_leave_cnt = 0;
memset(device_reset_done, 0, sizeof(device_reset_done));
}
void device_add_vsync_pre(DEVICE_VOID p)
{
add_device_item(device_vsyncs_pre, &device_vsync_pre_cnt, p);
}
void device_add_vsync_post(DEVICE_VOID p)
{
add_device_item(device_vsyncs_post, &device_vsync_post_cnt, p);
}
void device_add_hsync(DEVICE_VOID p)
{
add_device_item(device_hsyncs, &device_hsync_cnt, p);
}
void device_add_rethink(DEVICE_VOID p)
{
add_device_item(device_rethinks, &device_rethink_cnt, p);
}
void device_add_check_config(DEVICE_VOID p)
{
add_device_item(device_configs, &device_configs_cnt, p);
}
void device_add_exit(DEVICE_VOID p)
{
add_device_item(device_leaves, &device_leave_cnt, p);
}
void device_add_reset(DEVICE_INT p)
{
for (int i = 0; i < device_resets_cnt; i++) {
if (device_resets[i] == p)
return;
}
device_resets[device_resets_cnt++] = p;
}
void device_add_reset_imm(DEVICE_INT p)
{
for (int i = 0; i < device_resets_cnt; i++) {
if (device_resets[i] == p)
return;
}
device_reset_done[device_resets_cnt] = true;
device_resets[device_resets_cnt++] = p;
p(1);
}
void device_check_config(void)
{
execute_device_items(device_configs, device_configs_cnt);
check_prefs_changed_cd();
check_prefs_changed_audio();
check_prefs_changed_custom();
check_prefs_changed_cpu();
check_prefs_picasso();
}
void devices_reset_ext(int hardreset)
{
for (int i = 0; i < device_resets_cnt; i++) {
if (!device_reset_done[i]) {
device_resets[i](hardreset);
device_reset_done[i] = true;
}
}
}
void devices_reset(int hardreset)
{
memset(device_reset_done, 0, sizeof(device_reset_done));
// must be first
init_eventtab();
init_shm();
memory_reset();
DISK_reset();
CIA_reset();
a1000_reset();
#ifdef JIT
compemu_reset();
#endif
#ifdef WITH_PPC
uae_ppc_reset(is_hardreset());
#endif
native2amiga_reset();
#ifdef SCSIEMU
scsi_reset();
scsidev_reset();
scsidev_start_threads();
#endif
#ifdef GFXBOARD
gfxboard_reset ();
#endif
#ifdef DRIVESOUND
driveclick_reset();
#endif
ethernet_reset();
#ifdef FILESYS
filesys_prepare_reset();
filesys_reset();
#endif
#if defined (BSDSOCKET)
bsdlib_reset();
#endif
#ifdef FILESYS
filesys_start_threads();
hardfile_reset();
#endif
#ifdef UAESERIAL
uaeserialdev_reset();
uaeserialdev_start_threads();
#endif
#if defined (PARALLEL_PORT)
initparallel();
#endif
dongle_reset();
sampler_init();
device_func_reset();
#ifdef AUTOCONFIG
rtarea_reset();
#endif
#ifdef RETROPLATFORM
rp_reset();
#endif
uae_int_requested = 0;
}
void devices_vsync_pre(void)
{
audio_vsync();
blkdev_vsync();
CIA_vsync_prehandler();
inputdevice_vsync();
filesys_vsync();
sampler_vsync();
clipboard_vsync();
statusline_vsync();
execute_device_items(device_vsyncs_pre, device_vsync_pre_cnt);
}
void devices_vsync_post(void)
{
execute_device_items(device_vsyncs_post, device_vsync_post_cnt);
}
void devices_hsync(void)
{
DISK_hsync();
audio_hsync();
CIA_hsync_prehandler();
decide_blitter(-1);
serial_hsynchandler();
execute_device_items(device_hsyncs, device_hsync_cnt);
}
void devices_rethink_all(void func(void))
{
func();
}
void devices_rethink(void)
{
rethink_cias ();
execute_device_items(device_rethinks, device_rethink_cnt);
rethink_uae_int();
/* cpuboard_rethink must be last */
cpuboard_rethink();
}
void devices_update_sound(float clk, float syncadjust)
{
update_sound (clk);
update_sndboard_sound (clk / syncadjust);
update_cda_sound(clk / syncadjust);
x86_update_sound(clk / syncadjust);
}
void devices_update_sync(float svpos, float syncadjust)
{
cd32_fmv_set_sync(svpos, syncadjust);
}
void virtualdevice_free(void)
{
#ifdef WITH_PPC
// must be first
uae_ppc_free();
#endif
free_traps();
sampler_free();
inputdevice_close();
DISK_free();
dump_counts();
#ifdef SERIAL_PORT
serial_exit();
#endif
#ifdef AUTOCONFIG
expansion_cleanup();
#endif
#ifdef FILESYS
filesys_cleanup();
#endif
#ifdef BSDSOCKET
bsdlib_reset();
#endif
device_func_free();
#ifdef WITH_LUA
uae_lua_free();
#endif
gfxboard_free();
savestate_free();
memory_cleanup();
free_shm();
cfgfile_addcfgparam(0);
driveclick_free();
ethernet_enumerate_free();
rtarea_free();
execute_device_items(device_leaves, device_leave_cnt);
}
void do_leave_program (void)
{
virtualdevice_free();
graphics_leave();
close_sound();
if (! no_gui)
gui_exit();
#ifdef USE_SDL
SDL_Quit();
#endif
machdep_free();
}
void virtualdevice_init (void)
{
reset_device_items();
#ifdef CD32
akiko_init();
#endif
#ifdef AUTOCONFIG
rtarea_setup ();
#endif
#ifdef FILESYS
rtarea_init ();
uaeres_install ();
hardfile_install ();
#endif
#ifdef SCSIEMU
scsi_reset ();
scsidev_install ();
#endif
#ifdef SANA2
netdev_install ();
#endif
#ifdef UAESERIAL
uaeserialdev_install ();
#endif
#ifdef AUTOCONFIG
expansion_init ();
emulib_install ();
uaeexe_install ();
#endif
#ifdef FILESYS
filesys_install ();
#endif
#if defined (BSDSOCKET)
bsdlib_install ();
#endif
#ifdef WITH_UAENATIVE
uaenative_install ();
#endif
#ifdef WITH_TABLETLIBRARY
tabletlib_install ();
#endif
}
void devices_restore_start(void)
{
restore_cia_start();
restore_blkdev_start();
restore_blitter_start();
changed_prefs.bogomem.size = 0;
changed_prefs.chipmem.size = 0;
for (int i = 0; i < MAX_RAM_BOARDS; i++) {
changed_prefs.fastmem[i].size = 0;
changed_prefs.z3fastmem[i].size = 0;
}
changed_prefs.mbresmem_low.size = 0;
changed_prefs.mbresmem_high.size = 0;
restore_expansion_boards(NULL);
}
void devices_syncchange(void)
{
x86_bridge_sync_change();
}
void devices_pause(void)
{
#ifdef WITH_PPC
uae_ppc_pause(1);
#endif
blkdev_entergui();
#ifdef RETROPLATFORM
rp_pause(1);
#endif
pausevideograb(1);
ethernet_pause(1);
}
void devices_unpause(void)
{
blkdev_exitgui();
#ifdef RETROPLATFORM
rp_pause(0);
#endif
#ifdef WITH_PPC
uae_ppc_pause(0);
#endif
pausevideograb(0);
ethernet_pause(0);
}
void devices_unsafeperiod(void)
{
clipboard_unsafeperiod();
}