forked from libretro/blueMSX-libretro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibretro.c
871 lines (723 loc) · 26.9 KB
/
libretro.c
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
#include "libretro.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <ctype.h>
#include "CommandLine.h"
#include "Properties.h"
#include "ArchFile.h"
#include "VideoRender.h"
#include "AudioMixer.h"
#include "Casette.h"
#include "PrinterIO.h"
#include "UartIO.h"
#include "MidiIO.h"
#include "Machine.h"
#include "Board.h"
#include "Emulator.h"
#include "FileHistory.h"
#include "Actions.h"
#include "Language.h"
#include "LaunchFile.h"
#include "ArchEvent.h"
#include "ArchSound.h"
#include "ArchNotifications.h"
#include "JoystickPort.h"
#include "InputEvent.h"
#include "R800.h"
retro_log_printf_t log_cb;
static retro_video_refresh_t video_cb;
static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb;
static retro_environment_t environ_cb;
static Properties* properties;
static Video* video;
static Mixer* mixer;
static uint16_t* image_buffer;
static unsigned image_buffer_base_width;
static unsigned image_buffer_current_width;
static unsigned image_buffer_height;
static int double_width;
static char msx_type[256];
static unsigned msx_vdp_synctype;
static bool msx_ym2413_enable;
void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; }
void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; }
#ifdef LOG_PERFORMANCE
static struct retro_perf_callback perf_cb;
#define RETRO_PERFORMANCE_INIT(name) static struct retro_perf_counter name = {#name}; if (!name.registered) perf_cb.perf_register(&(name))
#define RETRO_PERFORMANCE_START(name) perf_cb.perf_start(&(name))
#define RETRO_PERFORMANCE_STOP(name) perf_cb.perf_stop(&(name))
#else
#define RETRO_PERFORMANCE_INIT(name)
#define RETRO_PERFORMANCE_START(name)
#define RETRO_PERFORMANCE_STOP(name)
#endif
#define EC_KEYBOARD_KEYCOUNT 94
/* .dsk support */
enum{
MEDIA_TYPE_CART = 0,
MEDIA_TYPE_TAPE,
MEDIA_TYPE_DISK,
MEDIA_TYPE_OTHER
};
void lowerstring(char* str)
{
int i;
for (i=0; str[i]; i++)
{
str[i] = tolower(str[i]);
}
}
int getmediatype(const char* filename){
char workram[4096/*max path name length for all existing OSes*/];
strcpy(workram,filename);
lowerstring(workram);
const char* extension = workram + strlen(workram) - 4;
if(strcmp(extension,".dsk") == 0){
return MEDIA_TYPE_DISK;
}
else if(strcmp(extension,".cas") == 0){
return MEDIA_TYPE_TAPE;
}
else if(strcmp(extension,".rom") == 0){
return MEDIA_TYPE_CART;
}
else if(strcmp(extension,".mx1") == 0){
return MEDIA_TYPE_CART;
}
else if(strcmp(extension,".mx2") == 0){
return MEDIA_TYPE_CART;
}
return MEDIA_TYPE_OTHER;
}
/* end .dsk support */
/* .dsk swap support */
struct retro_disk_control_callback dskcb;
bool diskinserted = false;
//all the fake functions used to limit swapping to 1 disk drive
bool setdskeject(bool ejected){
diskinserted = !ejected;
return false;
}
bool getdskeject(){
return !diskinserted;
}
unsigned getdskindex(){
return 0;
}
bool setdskindex(unsigned index){
//fail on this one,only one disk slot
if(index != 0)return true;
return false;
}
unsigned getnumimages(){
return 1;
}
bool addimageindex(){
//fail on this one,only one disk slot
return true;
}
//this is the only real function,it will swap out the disk
bool replacedsk(unsigned index,const struct retro_game_info *info){
if(getmediatype(info->path) != MEDIA_TYPE_DISK)return true;//cant swap a cart or tape into a disk slot
bool failed = insertDiskette(properties, 0 /*drive*/, info->path /*fname*/, NULL /*inZipFile*/, 0 /*forceAutostart*/);
return failed;
}
void attachdiskswapinterface(){
//these functions are unused
dskcb.set_eject_state = setdskeject;
dskcb.get_eject_state = getdskeject;
dskcb.set_image_index = setdskindex;
dskcb.get_image_index = getdskindex;
dskcb.get_num_images = getnumimages;
dskcb.add_image_index = addimageindex;
//this is the only real function,it will swap out the disk
dskcb.replace_image_index = replacedsk;
environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE,&dskcb);
}
/* end .dsk swap support */
extern BoardInfo boardInfo;
#define MAX_PADS 2
static unsigned input_devices[MAX_PADS];
extern int eventMap[256];
static unsigned btn_map[EC_KEYCOUNT] =
{
RETROK_UNKNOWN, //EC_NONE 0
// ROW 0
RETROK_F1, //EC_F1 1
RETROK_F2, //EC_F2 2
RETROK_F3, //EC_F3 3
RETROK_F4, //EC_F4 4
RETROK_F5, //EC_F5 5
RETROK_END, //EC_STOP 6
RETROK_HOME, //EC_CLS 7
RETROK_PAGEUP, //EC_SELECT 8
RETROK_INSERT, //EC_INS 9
RETROK_DELETE, //EC_DEL 10
// ROW 1
RETROK_ESCAPE, //EC_ESC 11
RETROK_1, //EC_1 12
RETROK_2, //EC_2 13
RETROK_3, //EC_3 14
RETROK_4, //EC_4 15
RETROK_5, //EC_5 16
RETROK_6, //EC_6 17
RETROK_7, //EC_7 18
RETROK_8, //EC_8 19
RETROK_9, //EC_9 20
RETROK_0, //EC_0 21
RETROK_MINUS, //EC_NEG 22
RETROK_EQUALS, //EC_CIRCFLX 23
RETROK_UNKNOWN, //EC_BKSLASH 24
RETROK_BACKSPACE, //EC_BKSPACE 25
// ROW 2
RETROK_TAB, //EC_TAB 26
RETROK_q, //EC_Q 27
RETROK_w, //EC_W 28
RETROK_e, //EC_E 29
RETROK_r, //EC_R 30
RETROK_t, //EC_T 31
RETROK_y, //EC_Y 32
RETROK_u, //EC_U 33
RETROK_i, //EC_I 34
RETROK_o, //EC_O 35
RETROK_p, //EC_P 36
RETROK_LEFTBRACKET, //EC_AT 37
RETROK_RIGHTBRACKET, //EC_LBRACK 38
RETROK_RETURN, //EC_RETURN 39
// ROW 3
RETROK_LCTRL, //EC_CTRL 40
RETROK_a, //EC_A 41
RETROK_s, //EC_S 42
RETROK_d, //EC_D 43
RETROK_f, //EC_F 44
RETROK_g, //EC_G 45
RETROK_h, //EC_H 46
RETROK_j, //EC_J 47
RETROK_k, //EC_K 48
RETROK_l, //EC_L 49
RETROK_SEMICOLON, //EC_SEMICOL 50
RETROK_COLON, //EC_COLON 51
RETROK_BACKSLASH, //EC_RBRACK 52
// ROW 4
RETROK_LSHIFT, //EC_LSHIFT 53
RETROK_z, //EC_Z 54
RETROK_x, //EC_X 55
RETROK_c, //EC_C 56
RETROK_v, //EC_V 57
RETROK_b, //EC_B 58
RETROK_n, //EC_N 59
RETROK_m, //EC_M 60
RETROK_COMMA, //EC_COMMA 61
RETROK_PERIOD, //EC_PERIOD 62
RETROK_SLASH, //EC_DIV 63
RETROK_UNKNOWN, //EC_UNDSCRE 64
RETROK_RSHIFT, //EC_RSHIFT 65
// ROW 5
RETROK_CAPSLOCK, //EC_CAPS 66
RETROK_LALT, //EC_GRAPH 67
RETROK_UNKNOWN, //EC_TORIKE 68
RETROK_SPACE, //EC_SPACE 69
RETROK_UNKNOWN, //EC_JIKKOU 70
RETROK_UNKNOWN, //EC_CODE 71
RETROK_PAUSE, //EC_PAUSE 72
// ARROWS
RETROK_LEFT, //EC_LEFT 73
RETROK_UP, //EC_UP 74
RETROK_DOWN, //EC_DOWN 75
RETROK_RIGHT, //EC_RIGHT 76
// NUMERIC KEYBOARD
RETROK_KP7, //EC_NUM7 77
RETROK_KP8, //EC_NUM8 78
RETROK_KP9, //EC_NUM9 79
RETROK_KP_DIVIDE, //EC_NUMDIV 80
RETROK_KP4, //EC_NUM4 81
RETROK_KP5, //EC_NUM5 82
RETROK_KP6, //EC_NUM6 83
RETROK_KP_MULTIPLY, //EC_NUMMUL 84
RETROK_KP1, //EC_NUM1 85
RETROK_KP2, //EC_NUM2 86
RETROK_KP3, //EC_NUM3 87
RETROK_KP_MINUS, //EC_NUMSUB 88
RETROK_KP0, //EC_NUM0 89
RETROK_KP_ENTER, //EC_NUMPER 90
RETROK_KP_PERIOD, //EC_NUMCOM 91
RETROK_KP_PLUS, //EC_NUMADD 92
// SVI SPECIFIC KEYS
RETROK_PRINT, //EC_PRINT 93
RETROK_UNKNOWN,
RETROK_UNKNOWN,
RETROK_UNKNOWN,
RETROK_UNKNOWN,
RETROK_UNKNOWN,
RETROK_UNKNOWN,
RETRO_DEVICE_ID_JOYPAD_UP, //EC_JOY1_UP 100
RETRO_DEVICE_ID_JOYPAD_DOWN, //EC_JOY1_DOWN 101
RETRO_DEVICE_ID_JOYPAD_LEFT, //EC_JOY1_LEFT 102
RETRO_DEVICE_ID_JOYPAD_RIGHT, //EC_JOY1_RIGHT 103
RETRO_DEVICE_ID_JOYPAD_A, //EC_JOY1_BUTTON1 104
RETRO_DEVICE_ID_JOYPAD_B, //EC_JOY1_BUTTON2 105
RETRO_DEVICE_ID_JOYPAD_Y, //EC_JOY1_BUTTON3 106
RETRO_DEVICE_ID_JOYPAD_X, //EC_JOY1_BUTTON4 107
RETRO_DEVICE_ID_JOYPAD_START, //EC_JOY1_BUTTON5 108
RETRO_DEVICE_ID_JOYPAD_SELECT, //EC_JOY1_BUTTON6 109
RETRO_DEVICE_ID_JOYPAD_UP, //EC_JOY2_UP 110
RETRO_DEVICE_ID_JOYPAD_DOWN, //EC_JOY2_DOWN 111
RETRO_DEVICE_ID_JOYPAD_LEFT, //EC_JOY2_LEFT 112
RETRO_DEVICE_ID_JOYPAD_RIGHT, //EC_JOY2_RIGHT 113
RETRO_DEVICE_ID_JOYPAD_A, //EC_JOY2_BUTTON1 114
RETRO_DEVICE_ID_JOYPAD_B, //EC_JOY2_BUTTON2 115
RETRO_DEVICE_ID_JOYPAD_Y, //EC_JOY2_BUTTON3 116
RETRO_DEVICE_ID_JOYPAD_X, //EC_JOY2_BUTTON4 117
RETRO_DEVICE_ID_JOYPAD_START, //EC_JOY2_BUTTON5 118
RETRO_DEVICE_ID_JOYPAD_SELECT, //EC_JOY2_BUTTON6 119
RETROK_UNKNOWN, //EC_COLECO1_0 120
RETROK_UNKNOWN, //EC_COLECO1_1 121
RETROK_UNKNOWN, //EC_COLECO1_2 122
RETROK_UNKNOWN, //EC_COLECO1_3 123
RETROK_UNKNOWN, //EC_COLECO1_4 124
RETROK_UNKNOWN, //EC_COLECO1_5 125
RETROK_UNKNOWN, //EC_COLECO1_6 126
RETROK_UNKNOWN, //EC_COLECO1_7 127
RETROK_UNKNOWN, //EC_COLECO1_8 128
RETROK_UNKNOWN, //EC_COLECO1_9 129
RETROK_UNKNOWN, //EC_COLECO1_STAR 130
RETROK_UNKNOWN, //EC_COLECO1_HASH 131
RETROK_UNKNOWN, //EC_COLECO2_0 140
RETROK_UNKNOWN, //EC_COLECO2_1 141
RETROK_UNKNOWN, //EC_COLECO2_2 142
RETROK_UNKNOWN, //EC_COLECO2_3 143
RETROK_UNKNOWN, //EC_COLECO2_4 144
RETROK_UNKNOWN, //EC_COLECO2_5 145
RETROK_UNKNOWN, //EC_COLECO2_6 146
RETROK_UNKNOWN, //EC_COLECO2_7 147
RETROK_UNKNOWN, //EC_COLECO2_8 148
RETROK_UNKNOWN, //EC_COLECO2_9 149
RETROK_UNKNOWN, //EC_COLECO2_STAR 150
RETROK_UNKNOWN, //EC_COLECO2_HASH 151
};
void retro_get_system_info(struct retro_system_info *info)
{
info->library_name = "blueMSX";
#ifdef GIT_VERSION
info->library_version = "git" GIT_VERSION;
#else
info->library_version = "svn";
#endif
info->need_fullpath = true;
info->block_extract = false;
info->valid_extensions = "rom|ri|mx1|mx2|dsk|col|sg|sc|cas";
}
void retro_get_system_av_info(struct retro_system_av_info *info)
{
info->geometry.base_width = image_buffer_base_width ;
info->geometry.base_height = image_buffer_height ;
info->geometry.max_width = FB_MAX_LINE_WIDTH ;
info->geometry.max_height = FB_MAX_LINES ;
info->geometry.aspect_ratio = 0;
info->timing.fps = 60.0;
info->timing.sample_rate = 44100.0;
}
void init_input_descriptors(){
struct retro_input_descriptor desc[] = {
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Joy Left" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Joy Up" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Joy Down" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Joy Right" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Button 1" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Button 2" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Button 3" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Button 4" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
{ 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT,"Select" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Joy Left" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Joy Up" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Joy Down" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Joy Right" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "Button 1" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "Button 2" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Button 3" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "Button 4" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start" },
{ 1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT,"Select" },
{ 0, 0, 0, 0, NULL }
};
environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc);
}
void retro_init(void)
{
int i;
struct retro_log_callback log;
if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log))
log_cb = log.log;
else
log_cb = NULL;
#ifdef LOG_PERFORMANCE
environ_cb(RETRO_ENVIRONMENT_GET_PERF_INTERFACE, &perf_cb);
#endif
}
void retro_deinit(void)
{
#ifdef LOG_PERFORMANCE
perf_cb.perf_log();
#endif
}
void retro_set_environment(retro_environment_t cb)
{
environ_cb = cb;
static const struct retro_variable vars[] = {
{ "bluemsx_msxtype", "Machine Type (Restart); MSX2+|MSX2|MSXturboR|MSX" },
{ "bluemsx_vdp_synctype", "VDP Sync Type (Restart); Auto|50Hz|60Hz" },
{ "bluemsx_ym2413_enable", "Sound YM2413 Enable (Restart); enabled|disabled" },
{ NULL, NULL },
};
static const struct retro_controller_description port[] = {
{ "RetroPad", RETRO_DEVICE_JOYPAD },
{ "RetroKeyboard", RETRO_DEVICE_KEYBOARD },
};
static const struct retro_controller_info ports[] = {
{ port, 2 },
{ port, 2 },
{ NULL, 0 },
};
cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)ports);
}
void retro_set_controller_port_device(unsigned port, unsigned device)
{
switch (device)
{
case RETRO_DEVICE_JOYPAD:
input_devices[port] = RETRO_DEVICE_JOYPAD;
break;
case RETRO_DEVICE_KEYBOARD:
input_devices[port] = RETRO_DEVICE_KEYBOARD;
break;
default:
if (log_cb)
log_cb(RETRO_LOG_ERROR, "[libretro]: Invalid device, setting type to RETRO_DEVICE_KEYBOARD ...\n");
input_devices[port] = RETRO_DEVICE_KEYBOARD;
}
}
void retro_reset(void)
{
actionEmuResetSoft();
}
static void extract_directory(char *buf, const char *path, size_t size)
{
strncpy(buf, path, size - 1);
buf[size - 1] = '\0';
char *base = strrchr(buf, '/');
if (!base)
base = strrchr(buf, '\\');
if (base)
*base = '\0';
else
buf[0] = '\0';
}
static void check_variables(void)
{
struct retro_variable var;
var.key = "bluemsx_msxtype";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
strcpy(msx_type, var.value);
else
strcpy(msx_type, "MSX2+");
var.key = "bluemsx_vdp_synctype";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (!strcmp(var.value, "Auto"))
msx_vdp_synctype = P_VDP_SYNCAUTO;
else if (!strcmp(var.value, "50Hz"))
msx_vdp_synctype = P_VDP_SYNC50HZ;
else if (!strcmp(var.value, "60Hz"))
msx_vdp_synctype = P_VDP_SYNC60HZ;
}
else
msx_vdp_synctype = P_VDP_SYNCAUTO;
var.key = "bluemsx_ym2413_enable";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (!strcmp(var.value, "disabled"))
msx_ym2413_enable = false;
else if (!strcmp(var.value, "enabled"))
msx_ym2413_enable = true;
}
else
msx_ym2413_enable = true;
}
bool retro_load_game(const struct retro_game_info *info)
{
int i;
char properties_dir[256], machines_dir[256], mediadb_dir[256];
const char *dir = NULL;
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
#ifdef _WIN32
char slash = '\\';
#else
char slash = '/';
#endif
if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt))
{
if (log_cb)
log_cb(RETRO_LOG_INFO, "RGB565 is not supported.\n");
return false;
}
if (!info)
return false;
init_input_descriptors();
image_buffer = malloc(FB_MAX_LINE_WIDTH*FB_MAX_LINES*sizeof(uint16_t));
image_buffer_base_width = 272;
image_buffer_current_width = image_buffer_base_width;
image_buffer_height = 240;
double_width = 0;
input_devices[0] = RETRO_DEVICE_JOYPAD;
#if 0
for (i = 0; i < MAX_PADS; i++)
input_devices[i] = RETRO_DEVICE_JOYPAD;
#endif
check_variables();
if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir)
strcpy(properties_dir, dir);
else /* Fallback */
extract_directory(properties_dir, info->path, sizeof(properties_dir));
snprintf(machines_dir, sizeof(machines_dir), "%s%c%s", properties_dir, slash, "Machines");
snprintf(mediadb_dir, sizeof(mediadb_dir), "%s%c%s", properties_dir, slash, "Databases");
propertiesSetDirectory(properties_dir, properties_dir);
machineSetDirectory(machines_dir);
//boardSetDirectory(buffer);
mediaDbLoad(mediadb_dir);
//mediaDbCreateRomdb();
//mediaDbCreateDiskdb();
//mediaDbCreateCasdb();
properties = propCreate(1, EMU_LANG_ENGLISH, P_KBD_EUROPEAN, P_EMU_SYNCNONE, "");
strcpy(properties->joy1.type, "joystick");
properties->joy1.typeId = JOYSTICK_PORT_JOYSTICK;
properties->joy1.autofire = 0;
strcpy(properties->joy2.type, "joystick");
properties->joy2.typeId = JOYSTICK_PORT_JOYSTICK;
properties->joy2.autofire = 0;
properties->emulation.vdpSyncMode = msx_vdp_synctype;
properties->video.monitorType = P_VIDEO_PALNONE;
strcpy(properties->emulation.machineName, msx_type);
properties->sound.chip.enableYM2413 = msx_ym2413_enable;
mixer = mixerCreate();
emulatorInit(properties, mixer);
actionInit(video, properties, mixer);
langInit();
tapeSetReadOnly(properties->cassette.readOnly);
langSetLanguage(properties->language);
joystickPortSetType(0, properties->joy1.typeId);
joystickPortSetType(1, properties->joy2.typeId);
// printerIoSetType(properties->ports.Lpt.type, properties->ports.Lpt.fileName);
// uartIoSetType(properties->ports.Com.type, properties->ports.Com.fileName);
// midiIoSetMidiOutType(properties->sound.MidiOut.type, properties->sound.MidiOut.fileName);
// midiIoSetMidiInType(properties->sound.MidiIn.type, properties->sound.MidiIn.fileName);
// ykIoSetMidiInType(properties->sound.YkIn.type, properties->sound.YkIn.fileName);
emulatorRestartSound();
for (i = 0; i < MIXER_CHANNEL_TYPE_COUNT; i++)
{
mixerSetChannelTypeVolume(mixer, i, properties->sound.mixerChannel[i].volume);
mixerSetChannelTypePan(mixer, i, properties->sound.mixerChannel[i].pan);
mixerEnableChannelType(mixer, i, properties->sound.mixerChannel[i].enable);
}
mixerSetMasterVolume(mixer, properties->sound.masterVolume);
mixerEnableMaster(mixer, properties->sound.masterEnable);
mediaDbSetDefaultRomType(properties->cartridge.defaultType);
int mediatype = getmediatype(info->path);
switch(mediatype){
case MEDIA_TYPE_DISK:
strcpy(properties->media.disks[0].fileName , info->path);
attachdiskswapinterface();
break;
case MEDIA_TYPE_TAPE:
strcpy(properties->media.tapes[0].fileName , info->path);
break;
case MEDIA_TYPE_CART:
case MEDIA_TYPE_OTHER:
default:
strcpy(properties->media.carts[0].fileName , info->path);
break;
}
for (i = 0; i < PROP_MAX_CARTS; i++)
{
if (properties->media.carts[i].fileName[0])
insertCartridge(properties, i, properties->media.carts[i].fileName, properties->media.carts[i].fileNameInZip, properties->media.carts[i].type, -1);
updateExtendedRomName(i, properties->media.carts[i].fileName, properties->media.carts[i].fileNameInZip);
}
for (i = 0; i < PROP_MAX_DISKS; i++)
{
if (properties->media.disks[i].fileName[0])
insertDiskette(properties, i, properties->media.disks[i].fileName, properties->media.disks[i].fileNameInZip, -1);
updateExtendedDiskName(i, properties->media.disks[i].fileName, properties->media.disks[i].fileNameInZip);
}
for (i = 0; i < PROP_MAX_TAPES; i++)
{
if (properties->media.tapes[i].fileName[0])
insertCassette(properties, i, properties->media.tapes[i].fileName, properties->media.tapes[i].fileNameInZip, 0);
updateExtendedCasName(i, properties->media.tapes[i].fileName, properties->media.tapes[i].fileNameInZip);
}
{
Machine* machine = machineCreate(properties->emulation.machineName);
if (machine != NULL)
{
boardSetMachine(machine);
machineDestroy(machine);
}
else
return false;
}
boardSetFdcTimingEnable(properties->emulation.enableFdcTiming);
boardSetY8950Enable(properties->sound.chip.enableY8950);
boardSetYm2413Enable(properties->sound.chip.enableYM2413);
boardSetMoonsoundEnable(properties->sound.chip.enableMoonsound);
boardSetVideoAutodetect(properties->video.detectActiveMonitor);
emulatorStart(NULL);
return true;
}
void timerCallback_global(void* timer);
UInt8 archJoystickGetState(int joystickNo)
{
return ((eventMap[EC_JOY1_UP] << 0) |
(eventMap[EC_JOY1_DOWN] << 1) |
(eventMap[EC_JOY1_LEFT] << 2) |
(eventMap[EC_JOY1_RIGHT] << 3) |
(eventMap[EC_JOY1_BUTTON1] << 4) |
(eventMap[EC_JOY1_BUTTON2] << 5) |
(eventMap[EC_JOY1_BUTTON3] << 6) |
(eventMap[EC_JOY1_BUTTON4] << 7));
}
void retro_run(void)
{
int i,j;
bool updated = false;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
check_variables();
RETRO_PERFORMANCE_INIT(core_retro_run);
RETRO_PERFORMANCE_START(core_retro_run);
input_poll_cb();
#ifdef PSP
if(input_devices[0] == RETRO_DEVICE_JOYPAD)
for (j = EC_JOY1_UP; j <= (EC_JOY1_BUTTON6); j++)
eventMap[j] = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, btn_map[j]) ? 1 : 0;
else
{
eventMap[EC_LEFT] = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT) ? 1 : 0;
eventMap[EC_RIGHT] = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT) ? 1 : 0;
eventMap[EC_UP] = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP) ? 1 : 0;
eventMap[EC_DOWN] = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN) ? 1 : 0;
eventMap[EC_RETURN] = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A) ? 1 : 0;
eventMap[EC_SPACE] = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B) ? 1 : 0;
eventMap[EC_CTRL] = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X) ? 1 : 0;
eventMap[EC_GRAPH] = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y) ? 1 : 0;
}
#else
for (i = 0; i < MAX_PADS; i++)
{
switch (input_devices[i])
{
case RETRO_DEVICE_JOYPAD:
if (i == 0)
for (j = EC_JOY1_UP; j <= (EC_JOY1_BUTTON6); j++)
eventMap[j] = input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, btn_map[j]) ? 1 : 0;
else if (i == 1)
for (j = EC_JOY2_UP; j <= (EC_JOY2_BUTTON6); j++)
eventMap[j] = input_state_cb(i, RETRO_DEVICE_JOYPAD, 0, btn_map[j]) ? 1 : 0;
break;
case RETRO_DEVICE_KEYBOARD:
for (j = 0; j < EC_KEYBOARD_KEYCOUNT; j++)
eventMap[j] = input_state_cb(i, RETRO_DEVICE_KEYBOARD, 0, btn_map[j]) ? 1 : 0;
break;
}
}
#endif
((R800*)boardInfo.cpuRef)->terminate = 0;
boardInfo.run(boardInfo.cpuRef);
RETRO_PERFORMANCE_STOP(core_retro_run);
video_cb(image_buffer, image_buffer_current_width, image_buffer_height, image_buffer_current_width * sizeof(uint16_t));
}
// framebuffer
uint16_t* frameBufferGetLine(FrameBuffer* frameBuffer, int y) {
return (image_buffer + y * image_buffer_current_width);
}
FrameBuffer* frameBufferGetDrawFrame()
{
return (void*)image_buffer;
}
FrameBuffer* frameBufferFlipDrawFrame()
{
return (void*)image_buffer;
}
static int fbScanLine = 0;
void frameBufferSetScanline(int scanline)
{
fbScanLine = scanline;
}
int frameBufferGetScanline() {
return fbScanLine;
}
FrameBufferData* frameBufferDataCreate(int maxWidth, int maxHeight, int defaultHorizZoom)
{
return (void*)image_buffer;
}
FrameBufferData* frameBufferGetActive()
{
return (void*)image_buffer;
}
void frameBufferSetLineCount(FrameBuffer* frameBuffer, int val)
{
image_buffer_height = val;
}
int frameBufferGetLineCount(FrameBuffer* frameBuffer) {
return image_buffer_height;
}
int frameBufferGetMaxWidth(FrameBuffer* frameBuffer)
{
return FB_MAX_LINE_WIDTH;
}
int frameBufferGetDoubleWidth(FrameBuffer* frameBuffer, int y)
{
return double_width;
}
void frameBufferSetDoubleWidth(FrameBuffer* frameBuffer, int y, int val)
{
double_width = val;
image_buffer_current_width = double_width ? image_buffer_base_width * 2 : image_buffer_base_width;
}
//RetroArch stubs
void retro_set_audio_sample(retro_audio_sample_t unused){}
bool retro_load_game_special(unsigned a, const struct retro_game_info *b, size_t c){return false;}
void retro_unload_game(void)
{
if (image_buffer)
free(image_buffer);
image_buffer = NULL;
image_buffer_base_width = 0;
image_buffer_current_width = 0;
image_buffer_height = 0;
}
unsigned retro_get_region(void){return RETRO_REGION_NTSC;}
void *retro_get_memory_data(unsigned id){return NULL;}
size_t retro_get_memory_size(unsigned id){return 0;}
unsigned retro_api_version(void){return RETRO_API_VERSION;}
size_t retro_serialize_size(void){return 0;}
void retro_cheat_reset(void){}
void retro_cheat_set(unsigned a, bool b, const char * c){}
bool retro_serialize(void *data, size_t size){return false;}
bool retro_unserialize(const void *data, size_t size){return false;}
//Core stubs
int archPollEvent(){return 0;}
void frameBufferDataDestroy(FrameBufferData* frameData){}
void frameBufferSetActive(FrameBufferData* frameData){}
void frameBufferSetMixMode(FrameBufferMixMode mode, FrameBufferMixMode mask){}
void frameBufferClearDeinterlace(){}
void frameBufferSetInterlace(FrameBuffer* frameBuffer, int val){}
void archTrap(UInt8 value){}
void videoUpdateAll(Video* video, Properties* properties){}