forked from schellingb/dosbox-pure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dosbox_pure_libretro.cpp
3090 lines (2815 loc) · 132 KB
/
dosbox_pure_libretro.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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2020 Bernhard Schelling
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include "include/dosbox.h"
#include "include/setup.h"
#include "include/video.h"
#include "include/programs.h"
#include "include/control.h"
#include "include/pic.h"
#include "include/render.h"
#include "include/shell.h"
#include "include/keyboard.h"
#include "include/mouse.h"
#include "include/joystick.h"
#include "include/vga.h"
#include "include/bios.h"
#include "include/bios_disk.h"
#include "include/callback.h"
#include "include/regs.h"
#include "include/dbp_serialize.h"
#include "src/ints/int10.h"
#include "src/dos/drives.h"
#include "keyb2joypad.h"
#include "libretro-common/include/libretro.h"
#include <string>
#ifndef DBP_THREADS_CLASSES
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define THREAD_CC WINAPI
struct Thread { typedef DWORD RET_t; typedef RET_t (THREAD_CC *FUNC_t)(LPVOID); static void StartDetached(FUNC_t f, void* p = NULL) { HANDLE h = CreateThread(0,0,f,p,0,0); CloseHandle(h); } };
struct Mutex { Mutex() : h(CreateMutexA(0,0,0)) {} ~Mutex() { CloseHandle(h); } __inline void Lock() { WaitForSingleObject(h,INFINITE); } __inline void Unlock() { ReleaseMutex(h); } private:HANDLE h;Mutex(const Mutex&);Mutex& operator=(const Mutex&);};
static INLINE void sleep_ms(Bit32u ms) { Sleep(ms); }
#else
#include <pthread.h>
#define THREAD_CC
struct Thread { typedef void* RET_t; typedef RET_t (THREAD_CC *FUNC_t)(void*); static void StartDetached(FUNC_t f, void* p = NULL) { pthread_t h = 0; pthread_create(&h, NULL, f, p); } };
struct Mutex { Mutex() { pthread_mutex_init(&h,0); } ~Mutex() { pthread_mutex_destroy(&h); } __inline void Lock() { pthread_mutex_lock(&h); } __inline void Unlock() { pthread_mutex_unlock(&h); } private:pthread_mutex_t h;Mutex(const Mutex&);Mutex& operator=(const Mutex&);};
static void sleep_ms(Bit32u ms) { timespec req, rem; req.tv_sec = ms / 1000; req.tv_nsec = (ms % 1000) * 1000000ULL; while (nanosleep(&req, &rem)) req = rem; }
#endif
#endif
// RETROARCH AUDIO/VIDEO
#define DBP_DEFAULT_FPS 60.0f
#ifdef GEKKO // From RetroArch/config.def.h
#define DBP_DEFAULT_SAMPLERATE 44100.0
#define DBP_DEFAULT_SAMPLERATE_STRING "44100"
#elif defined(_3DS)
#define DBP_DEFAULT_SAMPLERATE 32730.0
#define DBP_DEFAULT_SAMPLERATE_STRING "32730"
#else
#define DBP_DEFAULT_SAMPLERATE 48000.0
#define DBP_DEFAULT_SAMPLERATE_STRING "48000"
#endif
static retro_system_av_info av_info;
// DOSBOX STATE
enum DBP_State : Bit8u { DBPSTATE_BOOT, DBPSTATE_EXITED, DBPSTATE_SHUTDOWN, DBPSTATE_WAIT_FIRST_FRAME, DBPSTATE_WAIT_FIRST_EVENTS, DBPSTATE_WAIT_FIRST_RUN, DBPSTATE_RUNNING };
enum DBP_SerializeMode : Bit8u { DBPSERIALIZE_DISABLED, DBPSERIALIZE_STATES, DBPSERIALIZE_REWIND };
static Mutex dbp_audiomutex;
static Mutex dbp_lockthreadmtx[2];
static std::string dbp_crash_message;
static std::string dbp_content_path;
static std::string dbp_content_name;
static retro_time_t dbp_boot_time;
static Bit32u dbp_lastmenuticks;
static Bit32u dbp_retro_activity;
static Bit32u dbp_wait_activity;
static Bit32u dbp_overload_count;
static DBP_State dbp_state;
static DBP_SerializeMode dbp_serializemode;
static char dbp_menu_time;
static bool dbp_timing_tamper;
static bool dbp_fast_forward;
static bool dbp_game_running;
static bool dbp_lockthreadstate;
// DOSBOX GFX
enum { DBP_BUFFER_COUNT = 2 };
static Bit8u dosbox_buffers[DBP_BUFFER_COUNT][SCALER_MAXWIDTH * SCALER_MAXHEIGHT * 4];
static Bit8u dosbox_buffers_last;
static Bit32u RDOSGFXwidth;
static Bit32u RDOSGFXheight;
static Bit32u RDOSGFXpitch;
static float RDOSGFXratio;
static void(*dbp_gfx_intercept)(Bit8u* buf);
// DOSBOX AUDIO
static uint8_t audioData[4096 * 4]; // mixer blocksize * 2 (96khz @ 30 fps max)
static retro_usec_t dbp_frame_time;
static std::vector<std::string> dbp_soundfonts;
// DOSBOX DISC MANAGEMENT
static std::vector<std::string> dbp_images;
static unsigned dbp_disk_image_index;
static bool dbp_disk_eject_state;
static char dbp_disk_mount_letter;
// DOSBOX INPUT
struct DBP_InputBind
{
uint8_t port, device, index, id;
const char* desc;
int16_t evt, meta, lastval;
};
enum DBP_Port_Device
{
DBP_DEVICE_Disabled = RETRO_DEVICE_NONE,
DBP_DEVICE_BindGenericKeyboard = RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD,0),
DBP_DEVICE_MouseLeftAnalog = RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD,1),
DBP_DEVICE_MouseRightAnalog = RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD,2),
DBP_DEVICE_Port1Default = RETRO_DEVICE_JOYPAD,
DBP_DEVICE_Port1BasicJoystick = RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD,4),
DBP_DEVICE_Port2BasicJoystick = RETRO_DEVICE_JOYPAD,
DBP_DEVICE_Port1ThrustMasterFlightStick = RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD,5),
DBP_DEVICE_Port1BothDOSJoysticks = RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD,6),
DBP_DEVICE_BindCustomKeyboard = RETRO_DEVICE_KEYBOARD,
DBP_DEVICE_Port1ForceGravisGamepad = RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD,7),
};
enum { DBP_MAX_PORTS = 8 };
static const char* DBP_KBDNAMES[] =
{
"None","1","2","3","4","5","6","7","8","9","0","Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M",
"F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12","Esc","Tab","Backspace","Enter","Space","Left-Alt","Right-Alt","Left-Ctrl","Right-Ctrl","Left-Shift","Right-Shift",
"Caps-Lock","Scroll-Lock","Num-Lock","Grave","Minus","Equals","Backslash","Left-Bracket","Right-Bracket","Semicolon","Quote","Period","Comma","Slash","Extra-Lt-Gt",
"Print-Screen","Pause","Insert","Home","Page-Up","Delete","End","Page-Down","Left","Up","Down","Right","NP-1","NP-2","NP-3","NP-4","NP-5","NP-6","NP-7","NP-8","NP-9","NP-0",
"NP-Divide","NP-Multiply","NP-Minus","NP-Plus","NP-Enter","NP-Period",""
};
static std::vector<DBP_InputBind> dbp_input_binds;
static DBP_Port_Device dbp_port_devices[DBP_MAX_PORTS];
static bool dbp_bind_unused, dbp_on_screen_keyboard;
static int16_t dbp_bind_mousewheel;
static float dbp_mouse_speed = 1, dbp_mouse_speed_x = 1;
static char dbp_auto_mapping_mode;
static Bit8u* dbp_auto_mapping;
static const char* dbp_auto_mapping_names;
static const char* dbp_auto_mapping_title;
// DOSBOX EVENTS
enum DBP_Event_Type
{
DBPET_SET_VARIABLE, DBPET_MOUNT,
_DBPET_EXT_MAX,
DBPET_UNMOUNT, DBPET_SET_FASTFORWARD, DBPET_LOCKTHREAD, DBPET_SHUTDOWN,
_DBPET_INPUT_FIRST,
DBPET_JOY1X, DBPET_JOY1Y, DBPET_JOY2X, DBPET_JOY2Y, DBPET_JOYMX, DBPET_JOYMY,
_DBPET_JOY_AXIS_MAX,
DBPET_MOUSEXY,
DBPET_MOUSEDOWN, DBPET_MOUSEUP,
DBPET_MOUSESETSPEED, DBPET_MOUSERESETSPEED,
DBPET_JOYHATSETBIT, DBPET_JOYHATUNSETBIT,
DBPET_JOY1DOWN, DBPET_JOY1UP,
DBPET_JOY2DOWN, DBPET_JOY2UP,
DBPET_KEYDOWN, DBPET_KEYUP,
DBPET_ONSCREENKEYBOARD,
DBPET_AXIS_TO_KEY,
#define DBP_IS_RELEASE_EVENT(EVT) ((EVT) >= DBPET_MOUSEUP && (EVT & 1))
#define DBP_KEYAXIS_MAKE(KEY1,KEY2) (((KEY1)<<7)|(KEY2))
#define DBP_KEYAXIS_GET(VAL, META) ((VAL) < 0 ? (int16_t)((META)>>7) : (int16_t)((META)&127))
_DBPET_MAX
};
struct DBP_Event
{
struct Ext { Section* section; std::string cmd; };
DBP_Event_Type type;
union { int val; int16_t xy[2]; Ext* ext; };
};
enum { DBP_EVENT_QUEUE_SIZE = 256, DBP_DOWN_BY_KEYBOARD = 128 };
static DBP_Event dbp_event_queue[DBP_EVENT_QUEUE_SIZE];
static int dbp_event_queue_write_cursor;
static int dbp_event_queue_read_cursor;
static int dbp_keys_down_count;
static unsigned char dbp_keys_down[KBD_LAST+1];
static unsigned short dbp_keymap_dos2retro[KBD_LAST];
static unsigned char dbp_keymap_retro2dos[RETROK_LAST];
static void(*dbp_input_intercept)(DBP_Event& evnt);
static void DBP_QueueEvent(DBP_Event& evt)
{
int cur = dbp_event_queue_write_cursor, next = ((cur + 1) % DBP_EVENT_QUEUE_SIZE);
if (next == dbp_event_queue_read_cursor)
{
// queue full, thread is probably busy (decompression?), try to collapse a duplicated event
dbp_event_queue_write_cursor = next; //stop event processing
for (int i = cur; (i = ((i + DBP_EVENT_QUEUE_SIZE - 1) % DBP_EVENT_QUEUE_SIZE)) != cur;)
{
DBP_Event ie = dbp_event_queue[i];
for (int j = i; j != cur; j = ((j + DBP_EVENT_QUEUE_SIZE - 1) % DBP_EVENT_QUEUE_SIZE))
{
DBP_Event je = (j == i ? evt : dbp_event_queue[j]);
if (je.type != ie.type) continue;
else if (ie.type >= DBPET_JOY1X && ie.type <= _DBPET_JOY_AXIS_MAX) ie.val += je.val;
else if (ie.type == DBPET_MOUSEXY) { ie.xy[0] += je.xy[0]; ie.xy[1] += je.xy[1]; }
else if (ie.ext != je.ext) continue;
cur = j;
goto remove_element_at_cur;
}
}
// Found nothing to remove, just blindly remove the last element
if (1)
{
//static const char* DBPETNAMES[] = { "SET_VARIABLE","MOUNT","_EXT_MAX","UNMOUNT","SET_FASTFORWARD","LOCKTHREAD","SHUTDOWN","_INPUT_FIRST","JOY1X","JOY1Y","JOY2X","JOY2Y","JOYMX","JOYMY","_JOY_AXIS_MAX","MOUSEXY","MOUSEDOWN","MOUSEUP","MOUSESETSPEED","MOUSERESETSPEED","JOYHATSETBIT","JOYHATUNSETBIT","JOY1DOWN","JOY1UP","JOY2DOWN","JOY2UP","KEYDOWN","KEYUP","AXIS_TO_KEY","ONSCREENKEYBOARD","_MAX" };
//for (next = cur; (cur = ((cur + DBP_EVENT_QUEUE_SIZE - 1) % DBP_EVENT_QUEUE_SIZE)) != next;)
//{
// fprintf(stderr, "EVT [%3d] - %20s (%2d) - %d\n", cur, DBPETNAMES[dbp_event_queue[cur].type], dbp_event_queue[cur].type, dbp_event_queue[cur].val);
//}
//fprintf(stderr, "EVT [ADD] - %20s (%2d) - %d\n", DBPETNAMES[evt.type], evt.type, evt.val);
DBP_ASSERT(false);
}
// remove element at cur and shift everything up to next one down
remove_element_at_cur:
next = ((next + DBP_EVENT_QUEUE_SIZE - 1) % DBP_EVENT_QUEUE_SIZE);
if (dbp_event_queue[cur].type <= _DBPET_EXT_MAX) { delete dbp_event_queue[cur].ext; dbp_event_queue[cur].ext = NULL; }
for (int n = cur; (n = ((n + 1) % DBP_EVENT_QUEUE_SIZE)) != next; cur = n)
dbp_event_queue[cur] = dbp_event_queue[n];
}
dbp_event_queue[cur] = evt;
dbp_event_queue_write_cursor = next;
}
static void DBP_QueueEvent(DBP_Event_Type type, int val)
{
switch (type)
{
case DBPET_KEYDOWN:
if (!val || ((++dbp_keys_down[val]) & 127) > 1) return;
dbp_keys_down_count++;
break;
case DBPET_KEYUP:
if (((dbp_keys_down[val]) & 127) == 0 || ((--dbp_keys_down[val]) & 127) > 0) return;
dbp_keys_down[val] = 0;
dbp_keys_down_count--;
break;
case DBPET_MOUSEDOWN: case DBPET_JOY1DOWN: case DBPET_JOY2DOWN: dbp_keys_down[KBD_LAST] = 1; break;
case DBPET_MOUSEUP: case DBPET_JOY1UP: case DBPET_JOY2UP: dbp_keys_down[KBD_LAST] = 0; break;
default:;
}
DBP_Event evt = { type, val };
DBP_QueueEvent(evt);
}
static void DBP_QueueEvent(DBP_Event_Type type, int16_t x, int16_t y)
{
DBP_Event evt = { type };
evt.xy[0] = x;
evt.xy[1] = y;
DBP_QueueEvent(evt);
}
static void DBP_QueueEvent(DBP_Event_Type type, std::string& swappable_cmd, Section* section = NULL)
{
DBP_Event evt = { type };
evt.ext = new DBP_Event::Ext();
evt.ext->section = section;
std::swap(evt.ext->cmd, swappable_cmd);
DBP_QueueEvent(evt);
}
// LIBRETRO CALLBACKS
static void retro_fallback_log(enum retro_log_level level, const char *fmt, ...)
{
(void)level;
va_list va;
va_start(va, fmt);
vfprintf(stderr, fmt, va);
va_end(va);
}
static retro_log_printf_t log_cb = retro_fallback_log;
static retro_perf_get_time_usec_t time_cb;
static retro_environment_t environ_cb;
static retro_video_refresh_t video_cb;
static retro_audio_sample_batch_t audio_batch_cb;
static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb;
// PERF FPS COUNTERS
//#define DBP_ENABLE_FPS_COUNTERS
#ifdef DBP_ENABLE_FPS_COUNTERS
static Bit32u dbp_lastfpstick, dbp_fpscount_retro, dbp_fpscount_gfxstart, dbp_fpscount_gfxend, dbp_fpscount_event;
#define DBP_FPSCOUNT(DBP_FPSCOUNT_VARNAME) DBP_FPSCOUNT_VARNAME++;
#else
#define DBP_FPSCOUNT(DBP_FPSCOUNT_VARNAME)
#endif
static void retro_notify(retro_log_level lvl, char const* format,...)
{
static char buf[1024];
va_list ap;
va_start(ap, format);
vsnprintf(buf, sizeof(buf), format, ap);
va_end(ap);
retro_message_ext msg;
msg.msg = buf;
msg.duration = 4000;
msg.priority = 0;
msg.level = lvl;
msg.target = RETRO_MESSAGE_TARGET_ALL;
msg.type = RETRO_MESSAGE_TYPE_NOTIFICATION;
if (!environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE_EXT, &msg)) log_cb(RETRO_LOG_ERROR, "%s", buf);
}
// ------------------------------------------------------------------------------
static void DBP_StartOnScreenKeyboard();
void DBP_DOSBOX_ForceShutdown(const Bitu = 0);
void DBP_DOSBOX_ResetTickTimer();
void DBP_DOSBOX_Unlock(bool unlock, int start_frame_skip = 0);
void DBP_CPU_ModifyCycles(const char* val);
void DBP_KEYBOARD_ReleaseKeys();
void DBP_CGA_SetModelAndComposite(bool new_model, Bitu new_comp_mode);
void DBP_Hercules_SetPalette(Bit8u pal);
Bit32u DBP_MIXER_GetFrequency();
Bit32u DBP_MIXER_DoneSamplesCount();
void MIXER_CallBack(void *userdata, uint8_t *stream, int len);
bool MSCDEX_HasDrive(char driveLetter);
int MSCDEX_AddDrive(char driveLetter, const char* physicalPath, Bit8u& subUnit);
int MSCDEX_RemoveDrive(char driveLetter);
void DBP_Crash(const char* msg)
{
log_cb(RETRO_LOG_WARN, "[DOSBOX] Crash: %s\n", msg);
dbp_crash_message = msg;
DBP_DOSBOX_ForceShutdown();
}
static Thread::RET_t THREAD_CC DBP_RunThreadDosBox(void*)
{
dbp_lockthreadmtx[1].Lock();
control->StartUp();
dbp_lockthreadmtx[1].Unlock();
dbp_state = DBPSTATE_EXITED;
return 0;
}
static void DBP_AppendImage(const char* entry, bool sorted)
{
// insert into image list ordered alphabetically, ignore already known images
size_t insert_index;
for (insert_index = 0; insert_index != dbp_images.size(); insert_index++)
{
if (dbp_images[insert_index] == entry) return;
if (sorted && dbp_images[insert_index] > entry) { break; }
}
dbp_images.insert(dbp_images.begin() + insert_index, entry);
}
static DOS_Drive* DBP_Mount(const char* path, bool is_boot, bool set_content_name)
{
const char *last_slash = strrchr(path, '/'), *last_bslash = strrchr(path, '\\');
const char *path_file = (last_slash && last_slash > last_bslash ? last_slash + 1 : (last_bslash ? last_bslash + 1 : path));
const char *ext = strrchr(path_file, '.');
if (!ext) return NULL;
// A drive letter can be specified either by naming the mount file '.<letter>.<extension>' or by loading a path with an added '#<letter>' suffix.
char letter = 0;
const char *fragment = strrchr(ext, '#');
const char *p_fra_drive = (fragment && fragment[1] ? fragment + 1 : NULL);
const char *p_dot_drive = (ext - path > 2 && ext[-2] == '.' ? ext - 1 : NULL);
if (p_fra_drive && (*p_fra_drive >= 'A' && *p_fra_drive <= 'Z')) letter = *p_fra_drive;
else if (p_fra_drive && (*p_fra_drive >= 'a' && *p_fra_drive <= 'z')) letter = *p_fra_drive - 0x20;
else if (p_dot_drive && (*p_dot_drive >= 'A' && *p_dot_drive <= 'Z')) letter = *p_dot_drive;
else if (p_dot_drive && (*p_dot_drive >= 'a' && *p_dot_drive <= 'z')) letter = *p_dot_drive - 0x20;
if (!is_boot && dbp_disk_mount_letter) letter = dbp_disk_mount_letter;
if (letter && Drives[letter-'A']) { DBP_ASSERT(0); return NULL; }
if (set_content_name)
{
dbp_content_path = path;
dbp_content_name = std::string(path_file, (p_dot_drive ? p_dot_drive - 1 : ext) - path_file);
}
std::string path_no_fragment;
if (fragment)
{
path_no_fragment = std::string(path, fragment - path);
ext = path_no_fragment.c_str() + (ext - path);
path_file = path_no_fragment.c_str() + (path_file - path);
path = path_no_fragment.c_str();
}
DOS_Drive* res = NULL;
Bit8u res_media_byte = 0;
if (!strcasecmp(ext, ".zip") || !strcasecmp(ext, ".dosz"))
{
FILE* zip_file_h = fopen_wrap(path, "rb");
if (!zip_file_h)
{
if (!is_boot) dbp_disk_eject_state = true;
retro_notify(RETRO_LOG_ERROR, "Unable to open %s file: %s", "ZIP", path);
return NULL;
}
res = new zipDrive(new rawFile(zip_file_h, false), true);
// Use zip filename as drive label, cut off at file extension, the first occurence of a ( or [ character or right white space.
char lbl[11+1], *lblend = lbl + (ext - path_file > 11 ? 11 : ext - path_file);
memcpy(lbl, path_file, lblend - lbl);
for (char* c = lblend; c > lbl; c--) { if (c == lblend || *c == '(' || *c == '[' || (*c <= ' ' && !c[1])) *c = '\0'; }
res->label.SetLabel(lbl, !(is_boot && (!letter || letter == 'C')), true);
if (is_boot && (!letter || letter == 'C')) return res;
if (!letter) letter = 'D';
if (letter > 'C')
{
Bit8u subUnit;
MSCDEX_AddDrive(letter, "", subUnit);
}
else if (letter < 'C')
{
res_media_byte = 0xF0; //floppy
}
}
else if (!strcasecmp(ext, ".img") || !strcasecmp(ext, ".ima") || !strcasecmp(ext, ".vhd"))
{
fatDrive* fat = new fatDrive(path, 512, 63, 16, 0, 0);
if (!fat->loadedDisk || !fat->created_successfully)
{
delete fat;
goto MOUNT_ISO;
}
bool is_hdd = fat->loadedDisk->hardDrive;
if (is_boot && is_hdd && (!letter || letter == 'C')) return fat;
if (!letter) letter = (is_hdd ? 'D' : 'A');
// Copied behavior from IMGMOUNT::Run, force obtaining the label and saving it in label
RealPt save_dta = dos.dta();
dos.dta(dos.tables.tempdta);
DOS_DTA dta(dos.dta());
dta.SetupSearch(255, DOS_ATTR_VOLUME, (char*)"*.*");
fat->FindFirst((char*)"", dta);
dos.dta(save_dta);
// Register with BIOS/CMOS
if (letter-'A' < MAX_DISK_IMAGES)
{
if (imageDiskList[letter-'A']) { DBP_ASSERT(0); delete imageDiskList[letter-'A']; }
imageDiskList[letter-'A'] = fat->loadedDisk;
}
// Because fatDrive::GetMediaByte is different than all others...
res_media_byte = (is_hdd ? 0xF8 : 0xF0);
res = fat;
}
else if (!strcasecmp(ext, ".iso") || !strcasecmp(ext, ".cue") || !strcasecmp(ext, ".ins"))
{
MOUNT_ISO:
int error = -1;
if (!letter) letter = 'D';
res = new isoDrive(letter, path, 0xF8, error);
if (error)
{
delete res;
if (!is_boot) dbp_disk_eject_state = true;
retro_notify(RETRO_LOG_ERROR, "Unable to open %s file: %s", "image", path);
return NULL;
}
}
else if (!strcasecmp(ext, ".exe") || !strcasecmp(ext, ".com") || !strcasecmp(ext, ".bat"))
{
if (!letter) letter = (is_boot ? 'C' : 'D');
res = new localDrive(std::string(path, path_file - path).c_str(), 512, 32, 32765, 16000, 0xF8);
res->label.SetLabel("PURE", false, true);
path = NULL; // don't treat as disk image
}
else if (!strcasecmp(ext, ".m3u") || !strcasecmp(ext, ".m3u8"))
{
FILE* m3u_file_h = fopen_wrap(path, "rb");
if (!m3u_file_h)
{
retro_notify(RETRO_LOG_ERROR, "Unable to open %s file: %s", "M3U", path);
return NULL;
}
fseek(m3u_file_h, 0, SEEK_END);
size_t m3u_file_size = ftell(m3u_file_h);
fseek(m3u_file_h, 0, SEEK_SET);
char* m3u = new char[m3u_file_size + 1];
if (!fread(m3u, m3u_file_size, 1, m3u_file_h)) { DBP_ASSERT(0); }
fclose(m3u_file_h);
m3u[m3u_file_size] = '\0';
for (char* p = m3u, *pEnd = p + m3u_file_size; p <= pEnd; p++)
{
if (*p <= ' ') continue;
char* m3u_line = (*p == '#' ? NULL : p);
while (*p != '\0' && *p != '\r' && *p != '\n') p++;
*p = '\0';
if (!m3u_line) continue;
size_t m3u_baselen = (m3u_line[0] == '\\' || m3u_line[0] == '/' || m3u_line[1] == ':' ? 0 : path_file - path);
std::string m3u_path = std::string(path, m3u_baselen) + m3u_line;
DBP_AppendImage(m3u_path.c_str(), false);
}
delete [] m3u;
return NULL;
}
if (res)
{
DBP_ASSERT(!Drives[letter-'A']);
Drives[letter-'A'] = res;
mem_writeb(Real2Phys(dos.tables.mediaid) + (letter-'A') * 9, (res_media_byte ? res_media_byte : res->GetMediaByte()));
if (path)
{
if (is_boot) DBP_AppendImage(path, false);
else dbp_disk_mount_letter = letter;
}
}
return NULL;
}
static void DBP_Shutdown()
{
if (dbp_state != DBPSTATE_EXITED && dbp_state != DBPSTATE_SHUTDOWN)
{
dbp_state = DBPSTATE_RUNNING;
DBP_QueueEvent(DBPET_SHUTDOWN, 0);
while (dbp_state != DBPSTATE_EXITED) sleep_ms(50);
}
if (!dbp_crash_message.empty())
{
retro_notify(RETRO_LOG_ERROR, "DOS crashed: %s", dbp_crash_message.c_str());
dbp_crash_message.clear();
}
if (control)
{
DBP_ASSERT(!first_shell); //should have been properly cleaned up
delete control;
control = NULL;
}
for (DBP_Event& e : dbp_event_queue)
{
if (e.type > _DBPET_EXT_MAX) continue;
delete e.ext;
e.ext = NULL;
}
dbp_event_queue_write_cursor = dbp_event_queue_read_cursor = 0;
dbp_state = DBPSTATE_SHUTDOWN;
}
static void DBP_LockThread(bool lock)
{
if (lock && !dbp_lockthreadstate)
{
dbp_lockthreadstate = true;
dbp_lockthreadmtx[0].Lock();
DBP_QueueEvent(DBPET_LOCKTHREAD, 0);
dbp_lockthreadmtx[1].Lock();
}
else if (!lock && dbp_lockthreadstate)
{
dbp_lockthreadmtx[0].Unlock();
dbp_lockthreadmtx[1].Unlock();
dbp_lockthreadstate = false;
}
}
Bit32u DBP_GetTicks()
{
return (Bit32u)((time_cb() - dbp_boot_time) / 1000);
}
void DBP_DelayTicks(Bit32u ms)
{
sleep_ms(ms);
}
void DBP_MidiDelay(Bit32u ms)
{
sleep_ms(ms);
}
void DBP_LockAudio()
{
dbp_audiomutex.Lock();
}
void DBP_UnlockAudio()
{
dbp_audiomutex.Unlock();
}
bool DBP_IsKeyDown(KBD_KEYS key)
{
return (dbp_keys_down[key] != 0);
}
bool DBP_IsShuttingDown()
{
return (!first_shell || first_shell->exit);
}
Bitu GFX_GetBestMode(Bitu flags)
{
return GFX_CAN_32 | GFX_RGBONLY | GFX_SCALING | GFX_HARDWARE;
}
Bitu GFX_GetRGB(Bit8u red, Bit8u green, Bit8u blue)
{
return (red << 16) | (green << 8) | (blue << 0);
}
Bitu GFX_SetSize(Bitu width, Bitu height, Bitu flags, double scalex, double scaley, GFX_CallBack_t cb)
{
// Make sure DOSbox is not using any scalers that would waste performance
DBP_ASSERT(render.src.width == width && render.src.height == height);
memset(dosbox_buffers, 0, sizeof(dosbox_buffers));
RDOSGFXwidth = (Bit32u)width;
RDOSGFXheight = (Bit32u)height;
RDOSGFXpitch = (Bit32u)width * 4;
RDOSGFXratio = (float)((width * scalex) / (height * scaley));
if (RDOSGFXratio < 1) RDOSGFXratio *= 2; //because render.src.dblw is not reliable
if (RDOSGFXratio > 2) RDOSGFXratio /= 2; //because render.src.dblh is not reliable
if (RDOSGFXwidth > SCALER_MAXWIDTH || RDOSGFXheight > SCALER_MAXHEIGHT) { DBP_ASSERT(false); return 0; }
//const char* VGAModeNames[] { "M_CGA2","M_CGA4","M_EGA","M_VGA","M_LIN4","M_LIN8","M_LIN15","M_LIN16","M_LIN32","M_TEXT","M_HERC_GFX","M_HERC_TEXT","M_CGA16","M_TANDY2","M_TANDY4","M_TANDY16","M_TANDY_TEXT","M_ERROR"};
//log_cb(RETRO_LOG_INFO, "[DOSBOX SIZE] Width: %u - Height: %u - Ratio: %f (%f) - DBLH: %d - DBLW: %d - BPP: %u - Mode: %s (%d)\n",
// RDOSGFXwidth, RDOSGFXheight, RDOSGFXratio, render.src.ratio, render.src.dblh, render.src.dblw, render.src.bpp, VGAModeNames[vga.mode], vga.mode);
return GFX_GetBestMode(0);
}
bool GFX_StartUpdate(Bit8u*& pixels, Bitu& pitch)
{
DBP_FPSCOUNT(dbp_fpscount_gfxstart)
pixels = dosbox_buffers[(dosbox_buffers_last + 1) % DBP_BUFFER_COUNT];
pitch = RDOSGFXpitch;
return true;
}
void GFX_EndUpdate(const Bit16u *changedLines)
{
if (!changedLines) return;
#ifdef DBP_ENABLE_FPS_COUNTERS
static Bit32u last_chk;
Bit32u chk = 0;
for (Bit32u *p = (Bit32u*)dosbox_buffers[(dosbox_buffers_last + 1) % DBP_BUFFER_COUNT], *pMax = p + RDOSGFXwidth * RDOSGFXheight; p != pMax; p++) chk = chk*65599 + *p;
if (last_chk != chk) { DBP_FPSCOUNT(dbp_fpscount_gfxend) last_chk = chk; }
#endif
if (dbp_gfx_intercept) dbp_gfx_intercept(dosbox_buffers[(dosbox_buffers_last + 1) % DBP_BUFFER_COUNT]);
dosbox_buffers_last = (dosbox_buffers_last + 1) % DBP_BUFFER_COUNT;
// Tell dosbox to draw the next frame completely, not just the scanlines that changed (could also issue GFX_CallBackRedraw)
render.scale.clearCache = true;
if (dbp_state == DBPSTATE_WAIT_FIRST_FRAME)
dbp_state = DBPSTATE_WAIT_FIRST_EVENTS;
// When pausing the frontend we need to make sure CycleAutoAdjust is only re-activated after normal rendering has resumed
extern bool CPU_SkipCycleAutoAdjust;
static bool reset_skip_cycle_auto_adjust;
static Bit32u last_retro_activity = (Bit32u)-1, repeat_frames;
if (dbp_timing_tamper && dbp_retro_activity == last_retro_activity)
{
repeat_frames = 0;
CPU_SkipCycleAutoAdjust = reset_skip_cycle_auto_adjust = true;
if (last_retro_activity == dbp_retro_activity && dbp_state == DBPSTATE_RUNNING && !first_shell->exit)
dbp_wait_activity = last_retro_activity;
}
else
{
last_retro_activity = dbp_retro_activity;
if (reset_skip_cycle_auto_adjust && repeat_frames++ > 3)
{
CPU_SkipCycleAutoAdjust = reset_skip_cycle_auto_adjust = false;
}
}
}
void GFX_Events()
{
// Some configuration modifications (like keyboard layout) can cause this to be called recursively
static bool GFX_EVENTS_RECURSIVE;
if (GFX_EVENTS_RECURSIVE) return;
GFX_EVENTS_RECURSIVE = true;
DBP_FPSCOUNT(dbp_fpscount_event)
static bool mouse_speed_up, mouse_speed_down;
static int mouse_joy_x, mouse_joy_y, hatbits;
bool wait_until_activity = !!dbp_wait_activity;
bool wait_until_run = (dbp_state == DBPSTATE_WAIT_FIRST_EVENTS);
check_new_events:
for (;dbp_event_queue_read_cursor != dbp_event_queue_write_cursor; dbp_event_queue_read_cursor = ((dbp_event_queue_read_cursor + 1) % DBP_EVENT_QUEUE_SIZE))
{
DBP_Event e = dbp_event_queue[dbp_event_queue_read_cursor];
if (dbp_input_intercept && e.type >= _DBPET_INPUT_FIRST)
{
dbp_input_intercept(e);
if (!DBP_IS_RELEASE_EVENT(e.type)) continue;
}
switch (e.type)
{
case DBPET_SET_VARIABLE:
bool MIDI_TSF_SwitchSF2(const char*);
if (!memcmp(e.ext->cmd.c_str(), "midiconfig=", 11) && MIDI_TSF_SwitchSF2(e.ext->cmd.c_str() + 11))
{
// Do the SF2 reload directly (otherwise midi output stops until dos program restart)
e.ext->section->HandleInputline(e.ext->cmd);
}
else if (!memcmp(e.ext->cmd.c_str(), "cycles=", 7))
{
// Set cycles value without Destroy/Init (because that can cause FPU overflow crashes)
DBP_CPU_ModifyCycles(e.ext->cmd.c_str() + 7);
e.ext->section->HandleInputline(e.ext->cmd);
}
else
{
e.ext->section->ExecuteDestroy(false);
e.ext->section->HandleInputline(e.ext->cmd);
e.ext->section->ExecuteInit(false);
}
delete e.ext;
dbp_event_queue[dbp_event_queue_read_cursor].ext = NULL;
break;
case DBPET_MOUNT:
if (!Drives['A'-'A'] && !Drives['D'-'A'])
DBP_Mount(e.ext->cmd.c_str(), false, false);
if (dbp_input_intercept) dbp_input_intercept(e);
delete e.ext;
dbp_event_queue[dbp_event_queue_read_cursor].ext = NULL;
break;
case DBPET_UNMOUNT:
if (dbp_disk_mount_letter && Drives[dbp_disk_mount_letter-'A'] && Drives[dbp_disk_mount_letter-'A']->UnMount() == 0)
{
Drives[dbp_disk_mount_letter-'A'] = 0;
mem_writeb(Real2Phys(dos.tables.mediaid)+(dbp_disk_mount_letter-'A')*9,0);
}
if (dbp_input_intercept) dbp_input_intercept(e);
break;
case DBPET_SET_FASTFORWARD:
DBP_DOSBOX_Unlock(!!e.val, 10);
break;
case DBPET_LOCKTHREAD:
dbp_lockthreadmtx[1].Unlock();
dbp_lockthreadmtx[0].Lock();
dbp_lockthreadmtx[1].Lock();
dbp_lockthreadmtx[0].Unlock();
break;
case DBPET_SHUTDOWN:
DBP_DOSBOX_ForceShutdown();
goto abort_gfx_events;
case DBPET_KEYDOWN: KEYBOARD_AddKey((KBD_KEYS)e.val, true); break;
case DBPET_KEYUP: KEYBOARD_AddKey((KBD_KEYS)e.val, false); break;
case DBPET_ONSCREENKEYBOARD:
DBP_StartOnScreenKeyboard();
break;
case DBPET_MOUSEXY:
{
float mx = e.xy[0]*dbp_mouse_speed*dbp_mouse_speed_x, my = e.xy[1]*dbp_mouse_speed; // good for 320x200?
Mouse_CursorMoved(mx, my, 0, 0, true);
break;
}
case DBPET_MOUSEDOWN: Mouse_ButtonPressed((Bit8u)e.val); break;
case DBPET_MOUSEUP: Mouse_ButtonReleased((Bit8u)e.val); break;
case DBPET_MOUSESETSPEED: (e.val < 0 ? mouse_speed_down : mouse_speed_up) = true; break;
case DBPET_MOUSERESETSPEED: (e.val < 0 ? mouse_speed_down : mouse_speed_up) = false; break;
case DBPET_JOY1X: JOYSTICK_Move_X(0, e.val/32768.f); break;
case DBPET_JOY1Y: JOYSTICK_Move_Y(0, e.val/32768.f); break;
case DBPET_JOY2X: JOYSTICK_Move_X(1, e.val/32768.f); break;
case DBPET_JOY2Y: JOYSTICK_Move_Y(1, e.val/32768.f); break;
case DBPET_JOYMX: mouse_joy_x = e.val; break;
case DBPET_JOYMY: mouse_joy_y = e.val; break;
case DBPET_JOY1DOWN: JOYSTICK_Button(0, (Bit8u)e.val, true); break;
case DBPET_JOY1UP: JOYSTICK_Button(0, (Bit8u)e.val, false); break;
case DBPET_JOY2DOWN: JOYSTICK_Button(1, (Bit8u)e.val, true); break;
case DBPET_JOY2UP: JOYSTICK_Button(1, (Bit8u)e.val, false); break;
case DBPET_JOYHATSETBIT: hatbits |= e.val; goto JOYSETHAT;
case DBPET_JOYHATUNSETBIT: hatbits &= ~e.val; goto JOYSETHAT;
JOYSETHAT:
JOYSTICK_Move_Y(1,
(hatbits == 1 ? 0.5f : //left
(hatbits == 2 ? 0.0f : //down
(hatbits == 4 ? -0.5f : //right
(hatbits == 8 ? -1.0f : //up
(hatbits == 3 ? (JOYSTICK_GetMove_Y(1) > 0.2f ? 0.0f : 0.5f) : //down-left
(hatbits == 6 ? (JOYSTICK_GetMove_Y(1) < -0.2f ? 0.0f : -0.5f) : //down-right
(hatbits == 9 ? (JOYSTICK_GetMove_Y(1) < 0.0f ? 0.5f : -1.0f) : //up-left
(hatbits == 12 ? (JOYSTICK_GetMove_Y(1) < -0.7f ? -0.5f : -1.0f) : //up-right
1.0f))))))))); //centered
break;
}
}
static Bit32u events_per_frame = (Bit32u)(1800 / DBP_DEFAULT_FPS);
static Bit32u measure_ticks, measure_last, event_calls;
if (wait_until_activity)
{
if (dbp_wait_activity == dbp_retro_activity && dbp_state == DBPSTATE_RUNNING && !first_shell->exit)
{
sleep_ms(1);
goto check_new_events;
}
dbp_wait_activity = 0;
measure_last = DBP_GetTicks();
measure_ticks = 1;
DBP_DOSBOX_ResetTickTimer();
}
if (wait_until_run)
{
if (dbp_state == DBPSTATE_WAIT_FIRST_EVENTS) dbp_state = DBPSTATE_WAIT_FIRST_RUN;
if (dbp_state == DBPSTATE_WAIT_FIRST_RUN && !first_shell->exit)
{
sleep_ms(1);
goto check_new_events;
}
DBP_DOSBOX_Unlock(dbp_fast_forward, 10); // also resets tick timer
}
// measure how often events are handled per frame to send joystick mouse movement at a fixed rate
if ((++measure_ticks & 0x3FF) == 1)
{
Bit32u measure_now = DBP_GetTicks(), measure_time = measure_now - measure_last;
measure_last = measure_now;
if (measure_ticks != 1)
{
// Now we know it takes [measure_time] for 0x400 event ticks
events_per_frame = (Bit32u)((0x400 * 1000) / (measure_time * render.src.fps) + .499f);
measure_ticks = 1;
}
}
if (event_calls++ > events_per_frame)
{
if ((mouse_joy_x || mouse_joy_y) && (abs(mouse_joy_x) > 5 || abs(mouse_joy_y) > 5))
{
float mx = mouse_joy_x*.0003f, my = mouse_joy_y*.0003f;
if (!mouse_speed_up && !mouse_speed_down) {}
else if (mouse_speed_up && mouse_speed_down) mx *= 5, my *= 5;
else if (mouse_speed_up) mx *= 2, my *= 2;
else if (mouse_speed_down) mx *= .5f, my *= .5f;
mx *= dbp_mouse_speed * dbp_mouse_speed_x;
my *= dbp_mouse_speed;
Mouse_CursorMoved(mx, my, 0, 0, true);
}
event_calls = 0;
}
abort_gfx_events:
GFX_EVENTS_RECURSIVE = false;
}
void GFX_SetTitle(Bit32s cycles, int frameskip, bool paused)
{
extern const char* RunningProgram;
dbp_game_running = (strcmp(RunningProgram, "DOSBOX") && strcmp(RunningProgram, "PUREMENU"));
log_cb(RETRO_LOG_INFO, "[DOSBOX STATUS] Program: %s - Cycles: %d - Frameskip: %d - Paused: %d\n", RunningProgram, cycles, frameskip, paused);
}
void GFX_ShowMsg(char const* format,...)
{
static char buf[1024];
va_list ap;
va_start(ap, format);
vsnprintf(buf, sizeof(buf), format, ap);
va_end(ap);
log_cb(RETRO_LOG_INFO, "[DOSBOX LOG] %s\n", buf);
}
void GFX_SetPalette(Bitu start,Bitu count,GFX_PalEntry * entries) { }
static void DBP_PureMenuProgram(Program** make)
{
static struct Menu* menu;
struct FakeBatch : BatchFile
{
int count;
std::string exe;
FakeBatch(std::string& _exe) : BatchFile(first_shell,"Z:\\AUTOEXEC.BAT","",""), count(0) { std::swap(exe, _exe); }
virtual bool ReadLine(char * line)
{
const char *p = exe.c_str(), *f = strrchr(p, '\\') + 1, *fext;
switch (count++)
{
case 0:
memcpy(line + 0, "@ :\n", 5);
line[1] = p[0];
break;
case 1:
memcpy(line + 0, "@cd ", 4);
memcpy(line + 4, p + 2, (f - (f == p + 3 ? 0 : 1) - p - 2));
memcpy(line + 4 + (f - (f == p + 3 ? 0 : 1) - p - 2), "\n", 2);
break;
case 2:
{
bool isbat = ((fext = strrchr(f, '.')) && !strcasecmp(fext, ".bat"));
int call_cmd_len = (isbat ? 5 : 0), flen = (int)strlen(f);
memcpy(line, "@", 1);
memcpy(line+1, "call ", call_cmd_len);
memcpy(line+call_cmd_len+1, f, flen);
memcpy(line+call_cmd_len+1+flen, "\n", 2);
break;
}
case 3:
memcpy(line, "@Z:PUREMENU -FINISH\n", 21);
delete this;
break;
}
return true;
}
};
struct Menu : Program
{
Menu() : result(0), sel(0), exe_count(0), fs_count(0), scroll(0), mousex(0), mousey(0), joyx(0), joyy(0), init_autosel(0), init_autoskip(0), autoskip(0),
have_autoboot(false), use_autoboot(false), multidrive(false), open_ticks(DBP_GetTicks()) { }
~Menu() {}
int result, sel, exe_count, fs_count, scroll, mousex, mousey, joyx, joyy, init_autosel, init_autoskip, autoskip;
bool have_autoboot, use_autoboot, multidrive;
Bit32u open_ticks;
std::vector<std::string> list;
enum
{
ATTR_HEADER = 0x0B, //cyan in color, white in hercules
ATTR_NORMAL = 0x0E, //yellow in color, white in hercules
ATTR_HIGHLIGHT = 0x78, //dark gray on gray in color, white on gray in hercules
ATTR_WHITE = 0x0F,
RESULT_LAUNCH = 1,
RESULT_COMMANDLINE = 2,
RESULT_SHUTDOWN = 3,
};
void RefreshFileList(bool initial_scan)
{
list.clear();
exe_count = fs_count = 0;
size_t old_images_size = dbp_images.size();
int old_sel = sel;
// Scan drive C first, any others after
sel = ('C'-'A');
DriveFileIterator(Drives[sel], FileIter, (Bitu)this);
if (fs_count)
{
for (int i = 0; i != fs_count; i++)
{
// Filter image files that have the same name as a cue file
const char *pEntry = list[i].c_str(), *pExt = strrchr(pEntry, '.');
if (!pExt || (strcasecmp(pExt, ".cue") && strcasecmp(pExt, ".ins"))) continue;
for (int j = fs_count; j--;)
{
if (i == j || strncasecmp(list[j].c_str(), pEntry, pExt - pEntry + 1)) continue;
list.erase(list.begin() + j);
if (i > j) i--;
fs_count--;
}
}
for (int i = 0; i != fs_count; i++)
DBP_AppendImage(list[i].c_str(), true);
}
if (initial_scan && !old_images_size && dbp_images.size())
{
dbp_disk_eject_state = false;
dbp_disk_image_index = 0;
DBP_Mount(dbp_images[0].c_str(), false, false);
}
for (sel = 0; sel != ('Z'-'A'); sel++)