-
Notifications
You must be signed in to change notification settings - Fork 125
/
Emulatrix_SegaGenesis.htm
executable file
·871 lines (752 loc) · 36.5 KB
/
Emulatrix_SegaGenesis.htm
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Emulatrix</title>
<link rel="stylesheet" href="Emulatrix.css">
</head>
<body>
<script>
var container_width;
var container_height;
var download_running = false;
var download_Checker;
var download_Filename;
var download_LastSize = -1;
var download_LastSizeRepeated = 0;
var upload_running = false;
var upload_Checker;
var upload_OrigSize = -1;
var upload_OrigSizeRepeated = 0;
var loading_Checker;
var settings_file = "";
var settings_Checker;
function loadRomIntoVD()
{
// GETTING THE ROM FILE CONTENT
var dataView = new Uint8Array(parent.ROMDATA);
// CREATING THE ROM FILE IN THE VIRTUAL DRIVE
FS.createDataFile("/", "game.bin", dataView, true, false);
// CREATING THE FOLDERS IN THE VIRTUAL DRIVE IN ORDER TO SAVE THE CONFIG FILE
FS.createFolder("/home/web_user", "retroarch", true, true);
FS.createFolder("/home/web_user/retroarch", "userdata", true, true);
// SETTING THE VARIABLE FOR EMPTY VALUE IN THE CONFIG FILE. USING RETROARCH WEB IN MAC HAS A BUG THAT
// ANY NULL KEY IS FIRED AS THE COMMAND KEY. THAT'S WHY IS SCROLL_BACK INSTEAD OF NUL. THERE IS
// ANOTHER BUG IN MAC WITH THE COMMAND KEY, THAT IS FIRED AS THE TURBO BUTTON, NO MATTER THE CONFIG.
var emptyValue = "scroll_lock";
// SETTING THE DEFAULT FOLDER WHEN BROWSING THE VIRTUAL DRIVE
settings_file += "rgui_browser_directory = /\n";
// SETTING THE KEY FOR THE START BUTTON
settings_file += "input_player1_start = enter\n";
// SETTING THE KEYS FOR THE BUTTONS A, B, C
settings_file += "input_player1_y = a\n";
settings_file += "input_player1_b = s\n";
settings_file += "input_player1_a = d\n";
// SETTING THE KEYS FOR THE BUTTONS X, Y, Z
settings_file += "input_player1_l = q\n";
settings_file += "input_player1_x = w\n";
settings_file += "input_player1_r = e\n";
// SETTING THE KEY FOR SOUND TOGGLE
settings_file += "input_audio_mute = f9\n";
// SETTING THE KEY FOR RELOADING THE GAME
settings_file += "input_reset = f10\n";
// SETTING THE KEYS FOR UNWANTED FUNCTIONS
settings_file += "input_toggle_fast_forward = " + emptyValue + "\n";
settings_file += "input_hold_fast_forward = " + emptyValue + "\n";
settings_file += "input_toggle_slowmotion = " + emptyValue + "\n";
settings_file += "input_hold_slowmotion = " + emptyValue + "\n";
settings_file += "input_save_state = " + emptyValue + "\n";
settings_file += "input_load_state = " + emptyValue + "\n";
settings_file += "input_toggle_fullscreen = " + emptyValue + "\n";
settings_file += "input_exit_emulator = " + emptyValue + "\n";
settings_file += "input_state_slot_increase = " + emptyValue + "\n";
settings_file += "input_state_slot_decrease = " + emptyValue + "\n";
settings_file += "input_rewind = " + emptyValue + "\n";
settings_file += "input_movie_record_toggle = " + emptyValue + "\n";
settings_file += "input_pause_toggle = " + emptyValue + "\n";
settings_file += "input_frame_advance = " + emptyValue + "\n";
settings_file += "input_shader_next = " + emptyValue + "\n";
settings_file += "input_shader_prev = " + emptyValue + "\n";
settings_file += "input_cheat_index_plus = " + emptyValue + "\n";
settings_file += "input_cheat_index_minus = " + emptyValue + "\n";
settings_file += "input_cheat_toggle = " + emptyValue + "\n";
settings_file += "input_screenshot = " + emptyValue + "\n";
settings_file += "input_osk_toggle = " + emptyValue + "\n";
settings_file += "input_netplay_game_watch = " + emptyValue + "\n";
//settings_file += "input_enable_hotkey = " + emptyValue + "\n";
settings_file += "input_volume_up = " + emptyValue + "\n";
settings_file += "input_volume_down = " + emptyValue + "\n";
settings_file += "input_overlay_next = " + emptyValue + "\n";
settings_file += "input_disk_eject_toggle = " + emptyValue + "\n";
settings_file += "input_disk_next = " + emptyValue + "\n";
settings_file += "input_disk_prev = " + emptyValue + "\n";
settings_file += "input_grab_mouse_toggle = " + emptyValue + "\n";
settings_file += "input_game_focus_toggle = " + emptyValue + "\n";
settings_file += "input_menu_toggle = " + emptyValue + "\n";
settings_file += "input_recording_toggle = " + emptyValue + "\n";
settings_file += "input_streaming_toggle = " + emptyValue + "\n";
// PLAYER 1
settings_file += "input_player1_l2 = " + emptyValue + "\n";
settings_file += "input_player1_l3 = " + emptyValue + "\n";
settings_file += "input_player1_r2 = " + emptyValue + "\n";
settings_file += "input_player1_r3 = " + emptyValue + "\n";
settings_file += "input_player1_l_x_plus = " + emptyValue + "\n";
settings_file += "input_player1_l_x_minus = " + emptyValue + "\n";
settings_file += "input_player1_l_y_plus = " + emptyValue + "\n";
settings_file += "input_player1_l_y_minus = " + emptyValue + "\n";
settings_file += "input_player1_r_x_plus = " + emptyValue + "\n";
settings_file += "input_player1_r_x_minus = " + emptyValue + "\n";
settings_file += "input_player1_r_y_plus = " + emptyValue + "\n";
settings_file += "input_player1_r_y_minus = " + emptyValue + "\n";
settings_file += "input_player1_gun_trigger = " + emptyValue + "\n";
settings_file += "input_player1_gun_trigger_axis = " + emptyValue + "\n";
settings_file += "input_player1_gun_trigger_btn = " + emptyValue + "\n";
settings_file += "input_player1_gun_trigger_mbtn = " + emptyValue + "\n";
settings_file += "input_player1_gun_offscreen_shot = " + emptyValue + "\n";
settings_file += "input_player1_gun_aux_a = " + emptyValue + "\n";
settings_file += "input_player1_gun_aux_b = " + emptyValue + "\n";
settings_file += "input_player1_gun_aux_c = " + emptyValue + "\n";
settings_file += "input_player1_gun_start = " + emptyValue + "\n";
settings_file += "input_player1_gun_select = " + emptyValue + "\n";
settings_file += "input_player1_gun_dpad_up = " + emptyValue + "\n";
settings_file += "input_player1_gun_dpad_down = " + emptyValue + "\n";
settings_file += "input_player1_gun_dpad_left = " + emptyValue + "\n";
settings_file += "input_player1_gun_dpad_right = " + emptyValue + "\n";
settings_file += "input_player1_turbo = " + emptyValue + "\n";
// PLAYER 2
settings_file += "input_player2_up = " + emptyValue + "\n";
settings_file += "input_player2_down = " + emptyValue + "\n";
settings_file += "input_player2_left = " + emptyValue + "\n";
settings_file += "input_player2_right = " + emptyValue + "\n";
settings_file += "input_player2_start = " + emptyValue + "\n";
settings_file += "input_player2_select = " + emptyValue + "\n";
settings_file += "input_player2_a = " + emptyValue + "\n";
settings_file += "input_player2_b = " + emptyValue + "\n";
settings_file += "input_player2_x = " + emptyValue + "\n";
settings_file += "input_player2_y = " + emptyValue + "\n";
settings_file += "input_player2_l = " + emptyValue + "\n";
settings_file += "input_player2_l2 = " + emptyValue + "\n";
settings_file += "input_player2_l3 = " + emptyValue + "\n";
settings_file += "input_player2_r = " + emptyValue + "\n";
settings_file += "input_player2_r2 = " + emptyValue + "\n";
settings_file += "input_player2_r3 = " + emptyValue + "\n";
settings_file += "input_player2_l_x_plus = " + emptyValue + "\n";
settings_file += "input_player2_l_x_minus = " + emptyValue + "\n";
settings_file += "input_player2_l_y_plus = " + emptyValue + "\n";
settings_file += "input_player2_l_y_minus = " + emptyValue + "\n";
settings_file += "input_player2_r_x_plus = " + emptyValue + "\n";
settings_file += "input_player2_r_x_minus = " + emptyValue + "\n";
settings_file += "input_player2_r_y_plus = " + emptyValue + "\n";
settings_file += "input_player2_r_y_minus = " + emptyValue + "\n";
settings_file += "input_player2_gun_trigger = " + emptyValue + "\n";
settings_file += "input_player2_gun_trigger_axis = " + emptyValue + "\n";
settings_file += "input_player2_gun_trigger_btn = " + emptyValue + "\n";
settings_file += "input_player2_gun_trigger_mbtn = " + emptyValue + "\n";
settings_file += "input_player2_gun_offscreen_shot = " + emptyValue + "\n";
settings_file += "input_player2_gun_aux_a = " + emptyValue + "\n";
settings_file += "input_player2_gun_aux_b = " + emptyValue + "\n";
settings_file += "input_player2_gun_aux_c = " + emptyValue + "\n";
settings_file += "input_player2_gun_start = " + emptyValue + "\n";
settings_file += "input_player2_gun_select = " + emptyValue + "\n";
settings_file += "input_player2_gun_dpad_up = " + emptyValue + "\n";
settings_file += "input_player2_gun_dpad_down = " + emptyValue + "\n";
settings_file += "input_player2_gun_dpad_left = " + emptyValue + "\n";
settings_file += "input_player2_gun_dpad_right = " + emptyValue + "\n";
settings_file += "input_player2_turbo = " + emptyValue + "\n";
// PLAYER 3
settings_file += "input_player3_up = " + emptyValue + "\n";
settings_file += "input_player3_down = " + emptyValue + "\n";
settings_file += "input_player3_left = " + emptyValue + "\n";
settings_file += "input_player3_right = " + emptyValue + "\n";
settings_file += "input_player3_start = " + emptyValue + "\n";
settings_file += "input_player3_select = " + emptyValue + "\n";
settings_file += "input_player3_a = " + emptyValue + "\n";
settings_file += "input_player3_b = " + emptyValue + "\n";
settings_file += "input_player3_x = " + emptyValue + "\n";
settings_file += "input_player3_y = " + emptyValue + "\n";
settings_file += "input_player3_l = " + emptyValue + "\n";
settings_file += "input_player3_l2 = " + emptyValue + "\n";
settings_file += "input_player3_l3 = " + emptyValue + "\n";
settings_file += "input_player3_r = " + emptyValue + "\n";
settings_file += "input_player3_r2 = " + emptyValue + "\n";
settings_file += "input_player3_r3 = " + emptyValue + "\n";
settings_file += "input_player3_l_x_plus = " + emptyValue + "\n";
settings_file += "input_player3_l_x_minus = " + emptyValue + "\n";
settings_file += "input_player3_l_y_plus = " + emptyValue + "\n";
settings_file += "input_player3_l_y_minus = " + emptyValue + "\n";
settings_file += "input_player3_r_x_plus = " + emptyValue + "\n";
settings_file += "input_player3_r_x_minus = " + emptyValue + "\n";
settings_file += "input_player3_r_y_plus = " + emptyValue + "\n";
settings_file += "input_player3_r_y_minus = " + emptyValue + "\n";
settings_file += "input_player3_gun_trigger = " + emptyValue + "\n";
settings_file += "input_player3_gun_trigger_axis = " + emptyValue + "\n";
settings_file += "input_player3_gun_trigger_btn = " + emptyValue + "\n";
settings_file += "input_player3_gun_trigger_mbtn = " + emptyValue + "\n";
settings_file += "input_player3_gun_offscreen_shot = " + emptyValue + "\n";
settings_file += "input_player3_gun_aux_a = " + emptyValue + "\n";
settings_file += "input_player3_gun_aux_b = " + emptyValue + "\n";
settings_file += "input_player3_gun_aux_c = " + emptyValue + "\n";
settings_file += "input_player3_gun_start = " + emptyValue + "\n";
settings_file += "input_player3_gun_select = " + emptyValue + "\n";
settings_file += "input_player3_gun_dpad_up = " + emptyValue + "\n";
settings_file += "input_player3_gun_dpad_down = " + emptyValue + "\n";
settings_file += "input_player3_gun_dpad_left = " + emptyValue + "\n";
settings_file += "input_player3_gun_dpad_right = " + emptyValue + "\n";
settings_file += "input_player3_turbo = " + emptyValue + "\n";
// PLAYER 4
settings_file += "input_player4_up = " + emptyValue + "\n";
settings_file += "input_player4_down = " + emptyValue + "\n";
settings_file += "input_player4_left = " + emptyValue + "\n";
settings_file += "input_player4_right = " + emptyValue + "\n";
settings_file += "input_player4_start = " + emptyValue + "\n";
settings_file += "input_player4_select = " + emptyValue + "\n";
settings_file += "input_player4_a = " + emptyValue + "\n";
settings_file += "input_player4_b = " + emptyValue + "\n";
settings_file += "input_player4_x = " + emptyValue + "\n";
settings_file += "input_player4_y = " + emptyValue + "\n";
settings_file += "input_player4_l = " + emptyValue + "\n";
settings_file += "input_player4_l2 = " + emptyValue + "\n";
settings_file += "input_player4_l3 = " + emptyValue + "\n";
settings_file += "input_player4_r = " + emptyValue + "\n";
settings_file += "input_player4_r2 = " + emptyValue + "\n";
settings_file += "input_player4_r3 = " + emptyValue + "\n";
settings_file += "input_player4_l_x_plus = " + emptyValue + "\n";
settings_file += "input_player4_l_x_minus = " + emptyValue + "\n";
settings_file += "input_player4_l_y_plus = " + emptyValue + "\n";
settings_file += "input_player4_l_y_minus = " + emptyValue + "\n";
settings_file += "input_player4_r_x_plus = " + emptyValue + "\n";
settings_file += "input_player4_r_x_minus = " + emptyValue + "\n";
settings_file += "input_player4_r_y_plus = " + emptyValue + "\n";
settings_file += "input_player4_r_y_minus = " + emptyValue + "\n";
settings_file += "input_player4_gun_trigger = " + emptyValue + "\n";
settings_file += "input_player4_gun_trigger_axis = " + emptyValue + "\n";
settings_file += "input_player4_gun_trigger_btn = " + emptyValue + "\n";
settings_file += "input_player4_gun_trigger_mbtn = " + emptyValue + "\n";
settings_file += "input_player4_gun_offscreen_shot = " + emptyValue + "\n";
settings_file += "input_player4_gun_aux_a = " + emptyValue + "\n";
settings_file += "input_player4_gun_aux_b = " + emptyValue + "\n";
settings_file += "input_player4_gun_aux_c = " + emptyValue + "\n";
settings_file += "input_player4_gun_start = " + emptyValue + "\n";
settings_file += "input_player4_gun_select = " + emptyValue + "\n";
settings_file += "input_player4_gun_dpad_up = " + emptyValue + "\n";
settings_file += "input_player4_gun_dpad_down = " + emptyValue + "\n";
settings_file += "input_player4_gun_dpad_left = " + emptyValue + "\n";
settings_file += "input_player4_gun_dpad_right = " + emptyValue + "\n";
settings_file += "input_player4_turbo = " + emptyValue + "\n";
// PLAYER 5
settings_file += "input_player5_up = " + emptyValue + "\n";
settings_file += "input_player5_down = " + emptyValue + "\n";
settings_file += "input_player5_left = " + emptyValue + "\n";
settings_file += "input_player5_right = " + emptyValue + "\n";
settings_file += "input_player5_start = " + emptyValue + "\n";
settings_file += "input_player5_select = " + emptyValue + "\n";
settings_file += "input_player5_a = " + emptyValue + "\n";
settings_file += "input_player5_b = " + emptyValue + "\n";
settings_file += "input_player5_x = " + emptyValue + "\n";
settings_file += "input_player5_y = " + emptyValue + "\n";
settings_file += "input_player5_l = " + emptyValue + "\n";
settings_file += "input_player5_l2 = " + emptyValue + "\n";
settings_file += "input_player5_l3 = " + emptyValue + "\n";
settings_file += "input_player5_r = " + emptyValue + "\n";
settings_file += "input_player5_r2 = " + emptyValue + "\n";
settings_file += "input_player5_r3 = " + emptyValue + "\n";
settings_file += "input_player5_l_x_plus = " + emptyValue + "\n";
settings_file += "input_player5_l_x_minus = " + emptyValue + "\n";
settings_file += "input_player5_l_y_plus = " + emptyValue + "\n";
settings_file += "input_player5_l_y_minus = " + emptyValue + "\n";
settings_file += "input_player5_r_x_plus = " + emptyValue + "\n";
settings_file += "input_player5_r_x_minus = " + emptyValue + "\n";
settings_file += "input_player5_r_y_plus = " + emptyValue + "\n";
settings_file += "input_player5_r_y_minus = " + emptyValue + "\n";
settings_file += "input_player5_gun_trigger = " + emptyValue + "\n";
settings_file += "input_player5_gun_trigger_axis = " + emptyValue + "\n";
settings_file += "input_player5_gun_trigger_btn = " + emptyValue + "\n";
settings_file += "input_player5_gun_trigger_mbtn = " + emptyValue + "\n";
settings_file += "input_player5_gun_offscreen_shot = " + emptyValue + "\n";
settings_file += "input_player5_gun_aux_a = " + emptyValue + "\n";
settings_file += "input_player5_gun_aux_b = " + emptyValue + "\n";
settings_file += "input_player5_gun_aux_c = " + emptyValue + "\n";
settings_file += "input_player5_gun_start = " + emptyValue + "\n";
settings_file += "input_player5_gun_select = " + emptyValue + "\n";
settings_file += "input_player5_gun_dpad_up = " + emptyValue + "\n";
settings_file += "input_player5_gun_dpad_down = " + emptyValue + "\n";
settings_file += "input_player5_gun_dpad_left = " + emptyValue + "\n";
settings_file += "input_player5_gun_dpad_right = " + emptyValue + "\n";
settings_file += "input_player5_turbo = " + emptyValue + "\n";
// SETTING THE VIDEO CONFIGURATION
container_width = document.getElementById("container").offsetWidth;
container_height = document.getElementById("container").offsetHeight;
settings_file += "video_vsync = true\n";
settings_file += "video_scale = 1\n";
settings_file += "video_window_x = " + container_width + "\n";
settings_file += "video_window_y = " + container_height + "\n";
settings_file += "aspect_ratio_index = 23\n";
settings_file += "custom_viewport_width = " + container_width + "\n";
settings_file += "custom_viewport_height = " + container_height + "\n";
settings_file += "custom_viewport_x = 0\n";
settings_file += "custom_viewport_y = 0\n";
// SETTING THE AUDIO LATENCY
settings_file += "audio_latency = 128\n";
// HIDING THE NOTIFICATION MESSAGES
settings_file += "video_message_pos_x = -100\n";
settings_file += "video_message_pos_y = -100\n";
settings_file += "menu_enable_widgets = false\n";
// CREATING THE FILE WITH THE CONFIGURATION
FS.createDataFile("/home/web_user/retroarch/userdata", "retroarch.cfg", settings_file, true, true);
// WAITING A PRUDENTIAL TIME FOR THE RETROARCH.CFG FILE TO BE CREATED
settings_Checker = setInterval(checkSettingsFile, 1000);
}
function checkSettingsFile()
{
// SETTING THE VARIABLE TO KNOW IF THE EMULATOR MUST START
var mustStart = false;
try
{
// TRYING TO READ THE SETTINGS FILE
var myTempFile = FS.readFile("/home/web_user/retroarch/userdata/retroarch.cfg");
// CHECKING IF THE SETTINGS FILE HAS DATA
if (myTempFile.length==settings_file.length)
{
// SETTING THAT THE EMULATOR MUST START
mustStart = true;
}
}
catch(err)
{
}
// CHECKING IF THE EMULATOR MUST START
if (mustStart==true)
{
// DISABLING THE SETTINGS FILE CHECKER
clearInterval(settings_Checker);
// WAITING 1500 MS
setTimeout(function()
{
// STARTING THE EMULATOR
startEmulator();
},1500);
}
}
function startEmulator()
{
// RUNNING THE EMULATOR WITH THE SELECTED ROM
Module.callMain(["-v","/game.bin"]);
// RESIZING THE CANVAS
document.getElementById("canvas").width = container_width;
document.getElementById("canvas").height = container_height;
// RESIZING THE CANVAS AFTER 500 MS (WORKAROUND FOR OLD/SLOW DEVICES)
setTimeout(function(){resizeEmulatorCanvas()},500);
// RESIZING THE CANVAS AFTER 1000 MS (WORKAROUND FOR OLD/SLOW DEVICES)
setTimeout(function(){resizeEmulatorCanvas()},1000);
// RESIZING THE CANVAS AFTER 1500 MS (WORKAROUND FOR OLD/SLOW DEVICES)
setTimeout(function(){resizeEmulatorCanvas()},1500);
}
function resizeEmulatorCanvas()
{
try
{
// GETTING THE CONTAINER WIDTH
container_width = document.getElementById("container").offsetWidth;
// GETTING THE CONTAINER HEIGHT
container_height = document.getElementById("container").offsetHeight;
// UPDATING THE CANVAS SIZE
Module.setCanvasSize(container_width,container_height,true);
}
catch(err)
{
}
}
function toggleSound(GAME_SOUND_ENABLED)
{
try
{
// CHECKING IF THE EMULATOR IS NOT STARTED AND PREVENTING TO GO ANY FURTHER IF THAT'S THE CASE
if (Emulator_started==false){return}
// RESUMING THE EMULATION
Emulator_running = true;
// UPDATING THE SOUND STATUS ACCORDING THE USER SETTING
Emulator_soundEnabled = GAME_SOUND_ENABLED;
}
catch(err)
{
}
}
function reloadROM()
{
try
{
// CHECKING IF THE EMULATOR IS NOT STARTED AND PREVENTING TO GO ANY FURTHER IF THAT'S THE CASE
if (Emulator_started==false){return}
// RESUMING THE EMULATION
Emulator_running = true;
// PRESSING THE F10 KEY
sendVirtualKey("keydown","F10");
// WAITING 50 MS
setTimeout(function()
{
// RELEASING THE F10 KEY
sendVirtualKey("keyup","F10");
}, 50);
}
catch(err)
{
}
}
function downloadROMState()
{
try
{
// CHECKING IF THE EMULATOR IS NOT STARTED AND PREVENTING TO GO ANY FURTHER IF THAT'S THE CASE
if (Emulator_started==false){return}
// RESUMING THE EMULATION
Emulator_running = true;
// CHECKING IF THE DOWNLOADING AND UPLOADING PROCESS ARE NOT RUNNING
if (download_running==false && upload_running==false)
{
// SETTING THE DOWNLOADING PROCESS AS TRUE
download_running = true;
// SAVING THE STATE (TAKES A LOT OF SECONDS IN SOME CASES, EMSCRIPTED + LIBRETRO RELATED ISSUE)
Module._cmd_save_state();
// GETTING THE ROM FILENAME WITHOUT THE EXTENSION
download_Filename = parent.ROMNAME.replace(/\.[^/.]+$/, "");
// SETTING THE DEFAULT VALUES FOR THE VARIABLES THAT WILL CHECK THE DOWNLOADING PROCESS
download_LastSize = -1;
download_LastSizeRepeated = 0;
// RESTORING THE ORIGINAL LABEL TEXT
document.getElementsByClassName("gui_saving")[0].innerHTML = parent.STRING_SAVING;
// SHOWING THE 'SAVING, PLEASE WAIT...' LABEL
document.getElementsByClassName("gui_saving")[0].style.display = "block";
// STARTING THE TASK THAT WILL DOWNLOAD THE ROMSTATE AS A FILE
download_Checker = setInterval(download_CheckerCron, 1000);
}
}
catch(err)
{
}
}
function download_CheckerCron()
{
try
{
// TRYING TO READ THE ROMSTATE FILE
var myTempFile = FS.readFile("/home/web_user/retroarch/userdata/states/game.state");
// THE ROMSTATE FILE IS GOING TO BE WRITTEN WITH AN ASYNCHRONOUS TASK THAT WE CAN'T HANDLE IN ANY WAY.
// THIS IS THE REASON WHY WE NEED TO CHECK IF THE FILESIZE IS THE SAME AFTER SEVERAL CHECKINGS.
// CHECKING THE ROMSTATE FILE SIZE
if (myTempFile.length==download_LastSize)
{
// CHECKING IF THE EMULATOR IS RUNNING
if (Emulator_running==true)
{
// IF IT IS THE SAME, WE ADD 1 TO THE VARIABLE THAT WE USE FOR CHECKING THIS
download_LastSizeRepeated = download_LastSizeRepeated + 1;
}
}
else
{
// IF THE FILE SIZE IS NOT THE SAME, WE UPDATE A VARIABLE WITH THE LAST FILE SIZE THAT WE GOT
download_LastSize = myTempFile.length;
}
// IF THE FILE SIZE IS THE SAME AFTER SEVERAL CHECKINGS
if (download_LastSizeRepeated>parent.STATE_CHECK_TIMES)
{
// SETTING THE DEFAULT VALUES FOR THE VARIABLES THAT WE USED FOR CHECKING
download_LastSize = -1;
download_LastSizeRepeated = 0;
// DELETING THE ROMSTATE FILE FROM THE FS
FS.unlink("/home/web_user/retroarch/userdata/states/game.state");
// DOWNLOADING THE ROMSTATE AS A FILE
download_Blob(myTempFile, download_Filename + ".state", "application/octet-stream");
// UPDATING THE LABEL TEXT IN ORDER TO TELL THE USER THAT A FILE WAS DOWNLOADED
document.getElementsByClassName("gui_saving")[0].innerHTML = parent.STRING_SAVED;
// SETTING THE DOWNLOAD PROCESS AS FALSE
download_running = false;
// WAITING 3000 MS
setTimeout(function()
{
// CHECKING IF THE LABEL MUST BE HIDDEN
if (download_running==false)
{
// HIDING THE LABEL
document.getElementsByClassName("gui_saving")[0].style.display = "none";
// RESTORING THE ORIGINAL LABEL TEXT
document.getElementsByClassName("gui_saving")[0].innerHTML = parent.STRING_SAVING;
}
}, 3000);
// DISABLING THE DOWNLOADING TASK
clearInterval(download_Checker);
}
}
catch(err)
{
}
}
function download_Blob(data, fileName, mimeType)
{
// CREATING A BLOB OBJECT WITH THE FILENAME AND DATA
var blob = new Blob([data], {type: mimeType});
// CREATING A URL WITH THE BLOB OBJECT
var url = window.URL.createObjectURL(blob);
// DOWNLOADING THE CONTENT FROM THAT URL
download_URL(url, fileName);
}
function download_URL(data, fileName)
{
// CREATING A CLICKEABLE LINK
var a = document.createElement("a");
// SETTING THE LINK DESTINATION
a.href = data;
// SETTING THE FILENAME FOR THE DOWNLOAD
a.download = fileName;
// ADDING THE LINK TO THE DOCUMENT BODY
document.body.appendChild(a);
// HIDING THE LINK
a.style = "display: none";
// CLICKING ON THE LINK
a.click();
// REMOVING THE LINK
a.remove();
}
function uploadROMState()
{
try
{
// CHECKING IF THE EMULATOR IS NOT STARTED AND PREVENTING TO GO ANY FURTHER IF THAT'S THE CASE
if (Emulator_started==false){return}
// RESUMING THE EMULATION
Emulator_running = true;
// CHECKING IF THE UPLOADING AND DOWNLOADING PROCESS ARE NOT RUNNING
if (upload_running==false && download_running==false)
{
// HIDING THE 'SAVING, PLEASE WAIT...' LABEL
document.getElementsByClassName("gui_saving")[0].style.display = "none";
// ALLOWING THE USER TO SELECT THE ROMSTATE FILE FROM THE COMPUTER OR MOBILE DEVICE
document.getElementById("fileupload_uploader").click();
}
}
catch(err)
{
}
}
function upload_getFile(files)
{
try
{
// GETTING THE FILE EXTENSION
var extension = files[0].name.split(".").pop().toLowerCase();
// CHECKING THE FILE EXTENSION
if (extension=="state")
{
// SETTING THE UPLOADING PROCESS AS TRUE
upload_running = true;
// CREATING THE FILE READER
var filereader = new FileReader();
// GETTING THE FILENAME
filereader.file_name = files[0].name;
// SETTING THAT WILL HAPPEN WHEN THE FILE IS READ
filereader.onload = function()
{
// CHECKING IF THERE IS A PREVIOUS ROMSTATE FILE CREATED, IF SO, IT IS DELETED
try
{
// TRYING TO READ THE ROMSTATE FILE
var myTempFile = FS.readFile("/home/web_user/retroarch/userdata/states/game.state");
// DELETING THE ROMSTATE FILE
FS.unlink("/home/web_user/retroarch/userdata/states/game.state");
}
catch(err)
{
}
// GETTING THE DATA FOR THE ROMSTATE FILE
var dataView = new Uint8Array(this.result);
// CREATING THE ROMSTATE FILE
FS.createDataFile("/home/web_user/retroarch/userdata/states","game.state",dataView,true,true);
// SETTING THE DEFAULT VALUES FOR THE VARIABLES THAT WILL CHECK THE UPLOADING PROCESS
upload_OrigSize = dataView.length;
upload_OrigSizeRepeated = 0;
// CLEARING THE SELECTED FILE VALUE
document.getElementById("fileupload_uploader").value = null;
// SHOWING THE 'LOADING, PLEASE WAIT...' LABEL
document.getElementsByClassName("gui_loading")[0].style.display = "block";
// STARTING THE TASK THAT WILL UPLOAD THE ROMSTATE FILE
upload_Checker = setInterval(upload_CheckerCron, 1000);
};
// READING THE SELECTED FILE
filereader.readAsArrayBuffer(files[0]);
}
}
catch(err)
{
}
}
function upload_CheckerCron()
{
try
{
// TRYING TO READ THE ROMSTATE FILE
var myTempFile = FS.readFile("/home/web_user/retroarch/userdata/states/game.state");
// THE ROMSTATE FILE IS GOING TO BE WRITTEN WITH AN ASYNCHRONOUS TASK THAT WE CAN'T HANDLE IN ANY WAY.
// THIS IS THE REASON WHY WE NEED TO CHECK IF THE FILESIZE IS THE SAME AFTER SEVERAL CHECKINGS.
// CHECKING THE ROMSTATE FILE SIZE
if (myTempFile.length==upload_OrigSize)
{
// IF IT IS THE SAME, WE ADD 1 TO THE VARIABLE THAT WE USE FOR CHECKING THIS
upload_OrigSizeRepeated = upload_OrigSizeRepeated + 1;
}
// IF THE FILE SIZE IS THE SAME AFTER SEVERAL CHECKINGS
if (upload_OrigSizeRepeated>parent.STATE_CHECK_TIMES)
{
// SETTING THE DEFAULT VALUES FOR THE VARIABLES THAT WE USED FOR CHECKING
upload_OrigSize = -1;
upload_OrigSizeRepeated = 0;
// SETTING THE UPLOAD PROCESS AS FALSE
upload_running = false;
// LOADING THE STATE (TAKES A LOT OF SECONDS IN SOME CASES, EMSCRIPTED + LIBRETRO RELATED ISSUE)
Module._cmd_load_state();
// HIDING THE 'LOADING, PLEASE WAIT...' LABEL
document.getElementsByClassName("gui_loading")[0].style.display = "none";
// DISABLING THE UPLOADING TASK
clearInterval(upload_Checker);
}
}
catch(err)
{
}
}
function loadingChecker()
{
try
{
// CHECKING IF THE EMULATOR WAS STARTED
if (Emulator_started==true)
{
// HIDING THE LOADING ICON AND TEXT
document.getElementsByClassName("gui_pleasewait_title")[0].style.display = "none";
document.getElementsByClassName("pleasewait")[0].style.display = "none";
// DISABLING THE LOADING CHECKER
clearInterval(loading_Checker);
}
}
catch(err)
{
}
}
function checkControls()
{
// UPDATING THE SOUND STATUS ACCORDING TO THE USER SETTING
try{Emulator_soundEnabled = parent.getSoundStatus()}catch(err){Emulator_soundEnabled = true;}
// NOTIFYING TO THE PARENT THAT THE EMULATOR IS ALREADY RUNNING AND THAT
// IT CAN SHOW THE ACTION BUTTONS (STATES HANDLER, RESTART, SOUND, ETC.)
parent.enableControls();
// CHECKING IF IT IS A MOBILE DEVICE AND THAT THE MOBILE CONTROLS MUST BE DISPLAYED
if (isMobileDevice()==true && parent.mobileControlsVisible()==true)
{
// SHOWING THE VIRTUAL BUTTONS AND ASSIGNING TOUCHING EVENTS TO EACH ONE OF THEM
document.getElementsByClassName("gui_segagenesis_keystart")[0].style.display = "block";
document.getElementsByClassName("gui_segagenesis_keystart")[0].addEventListener("touchstart",function(event){sendVirtualKey("keydown","Enter")});
document.getElementsByClassName("gui_segagenesis_keystart")[0].addEventListener("touchend",function(event){sendVirtualKey("keyup","Enter")});
document.getElementsByClassName("gui_segagenesis_keya")[0].style.display = "block";
document.getElementsByClassName("gui_segagenesis_keya")[0].addEventListener("touchstart",function(event){sendVirtualKey("keydown","KeyA")});
document.getElementsByClassName("gui_segagenesis_keya")[0].addEventListener("touchend",function(event){sendVirtualKey("keyup","KeyA")});
document.getElementsByClassName("gui_segagenesis_keyb")[0].style.display = "block";
document.getElementsByClassName("gui_segagenesis_keyb")[0].addEventListener("touchstart",function(event){sendVirtualKey("keydown","KeyS")});
document.getElementsByClassName("gui_segagenesis_keyb")[0].addEventListener("touchend",function(event){sendVirtualKey("keyup","KeyS")});
document.getElementsByClassName("gui_segagenesis_keyc")[0].style.display = "block";
document.getElementsByClassName("gui_segagenesis_keyc")[0].addEventListener("touchstart",function(event){sendVirtualKey("keydown","KeyD")});
document.getElementsByClassName("gui_segagenesis_keyc")[0].addEventListener("touchend",function(event){sendVirtualKey("keyup","KeyD")});
document.getElementsByClassName("gui_segagenesis_keyx")[0].style.display = "block";
document.getElementsByClassName("gui_segagenesis_keyx")[0].addEventListener("touchstart",function(event){sendVirtualKey("keydown","KeyQ")});
document.getElementsByClassName("gui_segagenesis_keyx")[0].addEventListener("touchend",function(event){sendVirtualKey("keyup","KeyQ")});
document.getElementsByClassName("gui_segagenesis_keyy")[0].style.display = "block";
document.getElementsByClassName("gui_segagenesis_keyy")[0].addEventListener("touchstart",function(event){sendVirtualKey("keydown","KeyW")});
document.getElementsByClassName("gui_segagenesis_keyy")[0].addEventListener("touchend",function(event){sendVirtualKey("keyup","KeyW")});
document.getElementsByClassName("gui_segagenesis_keyz")[0].style.display = "block";
document.getElementsByClassName("gui_segagenesis_keyz")[0].addEventListener("touchstart",function(event){sendVirtualKey("keydown","KeyE")});
document.getElementsByClassName("gui_segagenesis_keyz")[0].addEventListener("touchend",function(event){sendVirtualKey("keyup","KeyE")});
// SHOWING THE VIRTUAL JOYSTICK
document.getElementsByClassName("gui_joystick")[0].style.display = "block";
showVirtualJoystick();
}
}
function hideMouse()
{
document.getElementsByTagName("body")[0].className = "gui_mouse_hidden";
}
function showMouse()
{
document.getElementsByTagName("body")[0].className = "gui_mouse_visible";
}
window.addEventListener("blur", function()
{
try
{
// PAUSING THE EMULATION
Emulator_running = false;
}
catch(err)
{
}
});
window.addEventListener("focus", function()
{
try
{
// RESUMING THE EMULATION
Emulator_running = true;
}
catch(err)
{
}
});
window.addEventListener("resize", function()
{
// RESIZING CANVAS IF THE WINDOW HAS BEEN RESIZED
resizeEmulatorCanvas();
});
window.addEventListener("load", function()
{
// SHOWING THE CANVAS CONTAINER
document.getElementById("container").style.display="block";
// STARTING THE FILE SYSTEM AFTER 1000 MS
setTimeout(function(){startFileSystem()},1000);
// LOADING THE ROM AFTER 2000 MS
setTimeout(function(){loadRomIntoVD()},2000);
// CHECKING WHEN THE EMULATOR IS RUNNING IN ORDER TO HIDE THE LOADING ICON AND TEXT
loading_Checker = setInterval(loadingChecker, 500);
// SETTING FUNCTIONS THAT WILL BE CALLED WHEN THE USER CLICKS, DOUBLE CLICKS OR MOVES THE MOUSE IN ORDER TO SHOW THE SYSTEM ICONS
document.addEventListener("click", parent.goBackButtonResetIncrement, false);
document.addEventListener("dblclick", parent.goBackButtonResetIncrement, false);
document.addEventListener("mousemove", parent.goBackButtonResetIncrement, false);
});
window.onerror = function (msg, url, lineNo, columnNo, error)
{
// SOMETIMES THE LIBRETRO TAKES TOO MUCH TIME TO LOAD AND MAY THROUGH AN ERROR.
// THE CODE BELOW GIVES ANOTHER TRY TO RUN THE EMULATOR WITH THE SELECTED ROM.
// WAITING 5000 MS
setTimeout(function()
{
// RUNS THE EMULATOR WITH THE SELECTED ROM
Module.callMain(["-v","/game.bin"]);
// RESIZES THE CANVAS
document.getElementById("canvas").width = container_width;
document.getElementById("canvas").height = container_height;
}, 5000);
return true;
}
</script>
<div class="gui_pleasewait_title"><script>document.write(parent.STRING_STARTINGEMULATOR);</script></div><div class="pleasewait"><div class="lds-spinner"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div></div>
<div id="container"><canvas id="canvas" oncontextmenu="event.preventDefault()"></canvas></div>
<div class="gui_joystick" id="joyDiv"></div>
<div class="gui_segagenesis_keystart" oncontextmenu="return false;">START</div>
<div class="gui_segagenesis_keya" oncontextmenu="return false;">A</div>
<div class="gui_segagenesis_keyb" oncontextmenu="return false;">B</div>
<div class="gui_segagenesis_keyc" oncontextmenu="return false;">C</div>
<div class="gui_segagenesis_keyx" oncontextmenu="return false;">X</div>
<div class="gui_segagenesis_keyy" oncontextmenu="return false;">Y</div>
<div class="gui_segagenesis_keyz" oncontextmenu="return false;">Z</div>
<div class="gui_loading"><script>document.write(parent.STRING_LOADING);</script></div>
<div class="gui_saving"><script>document.write(parent.STRING_SAVING);</script></div>
<input type="file" class="fileupload_uploader" id="fileupload_uploader" onchange="upload_getFile(event.target.files);">
<script src="Emulatrix_SegaGenesis.js"></script>
</body>
</html>