forked from libretro/libretro-atari800
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatari.c
1653 lines (1545 loc) · 43.6 KB
/
atari.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
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
/*
* atari.c - main high-level routines
*
* Copyright (c) 1995-1998 David Firth
* Copyright (c) 1998-2014 Atari800 development team (see DOC/CREDITS)
*
* This file is part of the Atari800 emulator project which emulates
* the Atari 400, 800, 800XL, 130XE, and 5200 8-bit computers.
*
* Atari800 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.
*
* Atari800 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 Atari800; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define _POSIX_C_SOURCE 199309L /* for nanosleep */
#include "afile.h"
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif
#ifdef __EMX__
#define INCL_DOS
#include <os2.h>
#endif
#ifdef __BEOS__
#include <OS.h>
#endif
#ifdef HAVE_LIBZ
#include <zlib.h>
#endif
#ifdef R_SERIAL
#include <sys/stat.h>
#endif
#ifdef SDL
#include <SDL.h>
#endif
#include "akey.h"
#include "antic.h"
#include "artifact.h"
#include "atari.h"
#include "binload.h"
#include "cartridge.h"
#include "cassette.h"
#include "cfg.h"
#include "cpu.h"
#include "devices.h"
#include "emuos.h"
#include "esc.h"
#include "gtia.h"
#include "input.h"
#include "log.h"
#include "memory.h"
#include "monitor.h"
#ifdef IDE
# include "ide.h"
#endif
#include "pia.h"
#include "platform.h"
#include "pokey.h"
#include "rtime.h"
#include "pbi.h"
#include "sio.h"
#include "sysrom.h"
#include "util.h"
#if !defined(BASIC) && !defined(CURSES_BASIC)
#include "colours.h"
#include "screen.h"
#endif
#ifndef BASIC
#include "statesav.h"
#ifndef __PLUS
#include "ui.h"
#endif
#endif /* BASIC */
#if defined(SOUND) && !defined(__PLUS)
#include "pokeysnd.h"
#include "sndsave.h"
#include "sound.h"
#endif
#ifdef R_IO_DEVICE
#include "rdevice.h"
#endif
#ifdef __PLUS
#ifdef _WX_
#include "export.h"
#else /* _WX_ */
#include "globals.h"
#include "macros.h"
#include "display_win.h"
#include "misc_win.h"
#include "registry.h"
#include "timing.h"
#include "FileService.h"
#include "Helpers.h"
#endif /* _WX_ */
#endif /* __PLUS */
#ifdef PBI_BB
#include "pbi_bb.h"
#endif
#if defined(PBI_XLD) || defined (VOICEBOX)
#include "votraxsnd.h"
#endif
#ifdef XEP80_EMULATION
#include "xep80.h"
#endif
#ifdef AF80
#include "af80.h"
#endif
#ifdef BIT3
#include "bit3.h"
#endif
#ifdef NTSC_FILTER
#include "filter_ntsc.h"
#endif
#ifdef VOICEBOX
#include "voicebox.h"
#endif
#if SUPPORTS_CHANGE_VIDEOMODE
#include "videomode.h"
#endif
#ifdef SDL
#include "sdl/init.h"
#endif
#ifdef DIRECTX
#include "win32\main.h"
#endif
#if defined(__LIBRETRO__)
extern const char *retro_system_directory;
#endif /* __LIBRETRO__ */
int Atari800_machine_type = Atari800_MACHINE_XLXE;
int Atari800_builtin_basic = TRUE;
int Atari800_keyboard_leds = FALSE;
int Atari800_f_keys = FALSE;
int Atari800_jumper;
int Atari800_builtin_game = FALSE;
int Atari800_keyboard_detached = FALSE;
int Atari800_tv_mode = Atari800_TV_PAL;
int Atari800_disable_basic = TRUE;
int Atari800_os_version = -1;
int verbose = FALSE;
int Atari800_display_screen = FALSE;
int Atari800_nframes = 0;
int Atari800_refresh_rate = 1;
int Atari800_collisions_in_skipped_frames = FALSE;
int Atari800_turbo = FALSE;
int Atari800_auto_frameskip = FALSE;
#ifdef BENCHMARK
static double benchmark_start_time;
#endif
int emuos_mode = 1; /* 0 = never use EmuOS, 1 = use EmuOS if real OS not available, 2 = always use EmuOS */
#ifdef HAVE_SIGNAL
volatile sig_atomic_t sigint_flag = FALSE;
static RETSIGTYPE sigint_handler(int num)
{
sigint_flag = TRUE;
/* Avoid restoring the original signal handler. */
signal(SIGINT, sigint_handler);
return;
}
#endif
void Atari800_SetMachineType(int type)
{
Atari800_machine_type = type;
if (Atari800_machine_type != Atari800_MACHINE_XLXE) {
Atari800_builtin_basic = FALSE;
Atari800_keyboard_leds = FALSE;
Atari800_f_keys = FALSE;
Atari800_jumper = FALSE;
Atari800_builtin_game = FALSE;
Atari800_keyboard_detached = FALSE;
}
}
void Atari800_UpdateKeyboardDetached(void)
{
if (Atari800_machine_type == Atari800_MACHINE_XLXE) {
GTIA_TRIG[2] = !Atari800_keyboard_detached;
if (Atari800_keyboard_detached && (GTIA_GRACTL & 4))
GTIA_TRIG_latch[2] = 0;
}
}
void Atari800_UpdateJumper(void)
{
if (Atari800_machine_type == Atari800_MACHINE_XLXE)
POKEY_POT_input[4] = Atari800_jumper ? 0 : 228;
}
void Atari800_Warmstart(void)
{
if (Atari800_machine_type == Atari800_MACHINE_800) {
/* A real Axlon homebanks on reset */
/* XXX: what does Mosaic do? */
if (MEMORY_axlon_num_banks > 0) MEMORY_PutByte(0xcfff, 0);
/* RESET key in 400/800 does not reset chips,
but only generates RNMI interrupt */
ANTIC_NMIST = 0x3f;
CPU_NMI();
}
else {
PBI_Reset();
PIA_Reset();
ANTIC_Reset();
/* CPU_Reset() must be after PIA_Reset(),
because Reset routine vector must be read from OS ROM */
CPU_Reset();
/* note: POKEY and GTIA have no Reset pin */
}
#ifdef __PLUS
HandleResetEvent();
#endif
}
void Atari800_Coldstart(void)
{
PBI_Reset();
PIA_Reset();
ANTIC_Reset();
/* CPU_Reset() must be after PIA_Reset(),
because Reset routine vector must be read from OS ROM */
CPU_Reset();
/* note: POKEY and GTIA have no Reset pin */
#ifdef __PLUS
HandleResetEvent();
#endif
/* reset cartridge to power-up state */
CARTRIDGE_ColdStart();
/* set Atari OS Coldstart flag */
MEMORY_dPutByte(0x244, 1);
/* handle Option key (disable BASIC in XL/XE)
and Start key (boot from cassette) */
GTIA_consol_override = 2;
#ifdef AF80
if (AF80_enabled) {
AF80_Reset();
AF80_InsertRightCartridge();
}
#endif
#ifdef BIT3
if (BIT3_enabled) {
BIT3_Reset();
}
#endif
}
int Atari800_LoadImage(const char *filename, UBYTE *buffer, int nbytes)
{
FILE *f;
int len;
f = fopen(filename, "rb");
if (f == NULL) {
Log_print("Error loading ROM image: %s", filename);
return FALSE;
}
len = fread(buffer, 1, nbytes, f);
fclose(f);
if (len != nbytes) {
Log_print("Error reading %s", filename);
return FALSE;
}
return TRUE;
}
#define COPY_EMUOS(padding) do { \
memset(MEMORY_os, 0, padding); \
memcpy(MEMORY_os + (padding), emuos_h, 0x2000); \
} while (0)
static int load_roms(void)
{
if (Atari800_machine_type != Atari800_MACHINE_5200 && emuos_mode == 2) {
COPY_EMUOS(Atari800_machine_type == Atari800_MACHINE_800 ? 0x800 : 0x2000);
Atari800_os_version = -1;
}
else {
int basic_ver, xegame_ver;
SYSROM_ChooseROMs(Atari800_machine_type, MEMORY_ram_size, Atari800_tv_mode, &Atari800_os_version, &basic_ver, &xegame_ver);
if (Atari800_os_version == -1
|| !Atari800_LoadImage(SYSROM_roms[Atari800_os_version].filename, MEMORY_os, SYSROM_roms[Atari800_os_version].size)) {
/* Missing OS ROM. */
Atari800_os_version = -1;
if (Atari800_machine_type != Atari800_MACHINE_5200 && emuos_mode == 1)
COPY_EMUOS(Atari800_machine_type == Atari800_MACHINE_800 ? 0x800 : 0x2000);
else
/* No OS ROM loaded. */
return FALSE;
}
else if (Atari800_machine_type != Atari800_MACHINE_5200) {
/* OS ROM found, try loading BASIC. */
MEMORY_have_basic = basic_ver != -1 && Atari800_LoadImage(SYSROM_roms[basic_ver].filename, MEMORY_basic, SYSROM_roms[basic_ver].size);
if (!MEMORY_have_basic)
/* Missing BASIC ROM. Don't fail when it happens. */
Atari800_builtin_basic = FALSE;
if (Atari800_builtin_game) {
/* Try loading built-in XEGS game. */
if (xegame_ver == -1
|| !Atari800_LoadImage(SYSROM_roms[xegame_ver].filename, MEMORY_xegame, SYSROM_roms[xegame_ver].size))
/* Missing XEGS game ROM. */
Atari800_builtin_game = FALSE;
}
}
}
MEMORY_xe_bank = 0;
return TRUE;
}
int Atari800_InitialiseMachine(void)
{
ESC_ClearAll();
if (!load_roms())
return FALSE;
Atari800_UpdateKeyboardDetached();
Atari800_UpdateJumper();
MEMORY_InitialiseMachine();
Devices_UpdatePatches();
return TRUE;
}
/* Initialise any modules before loading the config file. */
static void PreInitialise(void)
{
#if !defined(BASIC) && !defined(CURSES_BASIC)
Colours_PreInitialise();
#endif
#ifdef NTSC_FILTER
FILTER_NTSC_PreInitialise();
#endif
}
int Atari800_Initialise(int *argc, char *argv[])
{
int i, j;
const char *run_direct = NULL;
#ifndef BASIC
const char *state_file = NULL;
#endif
#ifdef __PLUS
/* Atari800Win PLus doesn't use configuration files,
it reads configuration from the Registry */
#ifndef _WX_
int bUpdateRegistry = (*argc > 1);
#endif
int bTapeFile = FALSE;
int nCartType = CARTRIDGE_main.type;
/* It is necessary because of the CARTRIDGE_ColdStart (there must not be the
registry-read value available at startup) */
CARTRIDGE_main.type = CARTRIDGE_NONE;
#ifndef _WX_
/* Print the time info in the "Log file" window */
Misc_PrintTime();
/* Force screen refreshing */
g_nTestVal = _GetRefreshRate() - 1;
g_ulAtariState = ATARI_UNINITIALIZED;
#endif /* _WX_ */
PreInitialise();
#else /* __PLUS */
const char *rtconfig_filename = NULL;
int got_config;
int help_only = FALSE;
PreInitialise();
if (*argc > 1) {
for (i = j = 1; i < *argc; i++) {
if (strcmp(argv[i], "-config") == 0) {
if (i + 1 < *argc)
rtconfig_filename = argv[++i];
else {
Log_print("Missing argument for '%s'", argv[i]);
return FALSE;
}
}
else if (strcmp(argv[i], "-v") == 0 ||
strcmp(argv[i], "-version") == 0 ||
strcmp(argv[i], "--version") == 0) {
printf("%s\n", Atari800_TITLE);
return FALSE;
}
else if (strcmp(argv[i], "--usage") == 0 ||
strcmp(argv[i], "--help") == 0) {
argv[j++] = "-help";
}
else if (strcmp(argv[i], "-verbose") == 0) {
verbose = TRUE;
}
else {
argv[j++] = argv[i];
}
}
*argc = j;
}
//LIBRETRO HACK
//#ifndef ANDROID
#if !defined(ANDROID) || defined(__LIBRETRO__)
got_config = CFG_LoadConfig(rtconfig_filename);
#else
got_config = TRUE; /* pretend we got a config file -- not needed in Android */
#endif
/* try to find ROM images if the configuration file is not found
or it does not specify some ROM paths (blank paths count as specified) */
//LIBRETRO HACK
//#ifndef ANDROID
#if !defined(ANDROID) || defined(__LIBRETRO__)
#if defined(__LIBRETRO__)
SYSROM_FindInDir(retro_system_directory, TRUE);
#endif
#if !defined(__PS3__) && !defined(__PSL1GHT__)
SYSROM_FindInDir(".", TRUE); /* current directory */
#endif
#if defined(unix) || defined(__unix__) || defined(__linux__)
SYSROM_FindInDir("/usr/share/atari800", TRUE);
#endif
#if defined(WIIU) && defined(__LIBRETRO__)
SYSROM_FindInDir("sd:/retroarch/cores/system/atari800", TRUE);
#endif
if (*argc > 0 && argv[0] != NULL) {
char atari800_exe_dir[FILENAME_MAX];
char atari800_exe_rom_dir[FILENAME_MAX];
/* the directory of the Atari800 program */
Util_splitpath(argv[0], atari800_exe_dir, NULL);
SYSROM_FindInDir(atari800_exe_dir, TRUE);
/* "rom" and "ROM" subdirectories of this directory */
Util_catpath(atari800_exe_rom_dir, atari800_exe_dir, "rom");
SYSROM_FindInDir(atari800_exe_rom_dir, TRUE);
/* skip "ROM" on systems that are known to be case-insensitive */
#if !defined(DJGPP) && !defined(HAVE_WINDOWS_H)
Util_catpath(atari800_exe_rom_dir, atari800_exe_dir, "ROM");
SYSROM_FindInDir(atari800_exe_rom_dir, TRUE);
#endif
}
#endif /* ANDROID */
/* finally if nothing is found, set some defaults to make
the configuration file easier to edit */
SYSROM_SetDefaults();
/* if no configuration file read, try to save one with the defaults */
if (!got_config)
CFG_WriteConfig();
#endif /* __PLUS */
for (i = j = 1; i < *argc; i++) {
if (strcmp(argv[i], "-atari") == 0) {
Atari800_machine_type = Atari800_MACHINE_800;
MEMORY_ram_size = 48;
Atari800_builtin_basic = FALSE;
Atari800_keyboard_leds = FALSE;
Atari800_f_keys = FALSE;
Atari800_jumper = FALSE;
Atari800_builtin_game = FALSE;
Atari800_keyboard_detached = FALSE;
}
else if (strcmp(argv[i], "-1200") == 0) {
Atari800_machine_type = Atari800_MACHINE_XLXE;
MEMORY_ram_size = 64;
Atari800_builtin_basic = FALSE;
Atari800_keyboard_leds = TRUE;
Atari800_f_keys = TRUE;
Atari800_jumper = FALSE;
Atari800_builtin_game = FALSE;
Atari800_keyboard_detached = FALSE;
}
else if (strcmp(argv[i], "-xl") == 0) {
Atari800_machine_type = Atari800_MACHINE_XLXE;
MEMORY_ram_size = 64;
Atari800_builtin_basic = TRUE;
Atari800_keyboard_leds = FALSE;
Atari800_f_keys = FALSE;
Atari800_jumper = FALSE;
Atari800_builtin_game = FALSE;
Atari800_keyboard_detached = FALSE;
}
else if (strcmp(argv[i], "-xe") == 0) {
Atari800_machine_type = Atari800_MACHINE_XLXE;
MEMORY_ram_size = 128;
Atari800_builtin_basic = TRUE;
Atari800_keyboard_leds = FALSE;
Atari800_f_keys = FALSE;
Atari800_jumper = FALSE;
Atari800_builtin_game = FALSE;
Atari800_keyboard_detached = FALSE;
}
else if (strcmp(argv[i], "-320xe") == 0) {
Atari800_machine_type = Atari800_MACHINE_XLXE;
MEMORY_ram_size = MEMORY_RAM_320_COMPY_SHOP;
Atari800_builtin_basic = TRUE;
Atari800_keyboard_leds = FALSE;
Atari800_f_keys = FALSE;
Atari800_jumper = FALSE;
Atari800_builtin_game = FALSE;
Atari800_keyboard_detached = FALSE;
}
else if (strcmp(argv[i], "-rambo") == 0) {
Atari800_machine_type = Atari800_MACHINE_XLXE;
MEMORY_ram_size = MEMORY_RAM_320_RAMBO;
Atari800_builtin_basic = TRUE;
Atari800_keyboard_leds = FALSE;
Atari800_f_keys = FALSE;
Atari800_jumper = FALSE;
Atari800_builtin_game = FALSE;
Atari800_keyboard_detached = FALSE;
}
else if (strcmp(argv[i], "-xegs") == 0) {
Atari800_machine_type = Atari800_MACHINE_XLXE;
MEMORY_ram_size = 64;
Atari800_builtin_basic = TRUE;
Atari800_keyboard_leds = FALSE;
Atari800_f_keys = FALSE;
Atari800_jumper = FALSE;
Atari800_builtin_game = TRUE;
}
else if (strcmp(argv[i], "-5200") == 0) {
Atari800_machine_type = Atari800_MACHINE_5200;
MEMORY_ram_size = 16;
Atari800_builtin_basic = FALSE;
Atari800_keyboard_leds = FALSE;
Atari800_f_keys = FALSE;
Atari800_jumper = FALSE;
Atari800_builtin_game = FALSE;
Atari800_keyboard_detached = FALSE;
}
else if (strcmp(argv[i], "-nobasic") == 0)
Atari800_disable_basic = TRUE;
else if (strcmp(argv[i], "-basic") == 0)
Atari800_disable_basic = FALSE;
else if (strcmp(argv[i], "-nopatch") == 0)
ESC_enable_sio_patch = FALSE;
else if (strcmp(argv[i], "-nopatchall") == 0)
ESC_enable_sio_patch = Devices_enable_h_patch = Devices_enable_p_patch = Devices_enable_r_patch = FALSE;
else if (strcmp(argv[i], "-pal") == 0)
Atari800_tv_mode = Atari800_TV_PAL;
else if (strcmp(argv[i], "-ntsc") == 0)
Atari800_tv_mode = Atari800_TV_NTSC;
else if (strcmp(argv[i], "-emuos") == 0)
emuos_mode = 2;
else if (strcmp(argv[i], "-c") == 0) {
if (Atari800_machine_type == Atari800_MACHINE_800)
MEMORY_ram_size = 52;
}
else if (strcmp(argv[i], "-axlon0f") == 0) {
MEMORY_axlon_0f_mirror = TRUE;
}
#ifdef STEREO_SOUND
else if (strcmp(argv[i], "-stereo") == 0) {
POKEYSND_stereo_enabled = TRUE;
}
else if (strcmp(argv[i], "-nostereo") == 0) {
POKEYSND_stereo_enabled = FALSE;
}
#endif /* STEREO_SOUND */
else if (strcmp(argv[i], "-turbo") == 0) {
Atari800_turbo = TRUE;
}
else {
/* parameters that take additional argument follow here */
int i_a = (i + 1 < *argc); /* is argument available? */
int a_m = FALSE; /* error, argument missing! */
if (strcmp(argv[i], "-run") == 0) {
if (i_a) run_direct = argv[++i]; else a_m = TRUE;
}
#ifdef R_IO_DEVICE
else if (strcmp(argv[i], "-rdevice") == 0) {
Devices_enable_r_patch = TRUE;
#ifdef R_SERIAL
if (i_a && i + 2 < *argc && *argv[i + 1] != '-') { /* optional serial device name */
struct stat statbuf;
if (! stat(argv[i + 1], &statbuf)) {
if (S_ISCHR(statbuf.st_mode)) { /* only accept devices as serial device */
Util_strlcpy(RDevice_serial_device, argv[++i], FILENAME_MAX);
RDevice_serial_enabled = TRUE;
}
}
}
#endif /* R_SERIAL */
}
#endif
else if (strcmp(argv[i], "-mosaic") == 0) {
if (i_a) {
int total_ram = Util_sscandec(argv[++i]);
MEMORY_mosaic_num_banks = (total_ram - 48)/4;
if ((total_ram - 48) % 4 != 0 || MEMORY_mosaic_num_banks >= 0x40 || MEMORY_mosaic_num_banks < 0) {
Log_print("Invalid Mosaic total RAM size");
return FALSE;
}
}
else a_m = TRUE;
}
else if (strcmp(argv[i], "-axlon") == 0) {
if (i_a) {
int total_ram = Util_sscandec(argv[++i]);
MEMORY_axlon_num_banks = ((total_ram) - 32) / 16;
if ((total_ram - 32) % 16 != 0 || (MEMORY_axlon_num_banks != 0 && MEMORY_axlon_num_banks != 8 && MEMORY_axlon_num_banks != 16 && MEMORY_axlon_num_banks != 32 && MEMORY_axlon_num_banks != 64 && MEMORY_axlon_num_banks != 128 && MEMORY_axlon_num_banks != 256)) {
Log_print("Invalid Axlon total RAM size");
return FALSE;
}
}
else a_m = TRUE;
}
else if (strcmp(argv[i], "-mapram") == 0)
MEMORY_enable_mapram = TRUE;
else if (strcmp(argv[i], "-no-mapram") == 0)
MEMORY_enable_mapram = FALSE;
#ifndef BASIC
/* The BASIC version does not support state files, because:
1. It has no ability to save state files, because of lack of UI.
2. It uses a simplified emulation, so the state files would be
incompatible with other versions.
3. statesav is not compiled in to make the executable smaller. */
else if (strcmp(argv[i], "-state") == 0) {
if (i_a) state_file = argv[++i]; else a_m = TRUE;
}
else if (strcmp(argv[i], "-refresh") == 0) {
if (i_a) {
Atari800_refresh_rate = Util_sscandec(argv[++i]);
if (Atari800_refresh_rate < 1) {
Log_print("Invalid refresh rate, using 1");
Atari800_refresh_rate = 1;
}
}
else
a_m = TRUE;
}
else if (strcmp(argv[i], "-autosave-config") == 0)
CFG_save_on_exit = TRUE;
else if (strcmp(argv[i], "-no-autosave-config") == 0)
CFG_save_on_exit = FALSE;
#endif /* BASIC */
else {
/* all options known to main module tried but none matched */
if (strcmp(argv[i], "-help") == 0) {
#ifndef __PLUS
help_only = TRUE;
Log_print("\t-config <file> Specify alternate configuration file");
#endif
Log_print("\t-autosave-config Automatically save configuration on emulator exit");
Log_print("\t-no-autosave-config");
Log_print("\t Disable automatic saving of configuration");
Log_print("\t-atari Emulate Atari 800");
Log_print("\t-1200 Emulate Atari 1200XL");
Log_print("\t-xl Emulate Atari 800XL");
Log_print("\t-xe Emulate Atari 130XE");
Log_print("\t-320xe Emulate Atari 320XE (Compy-Shop)");
Log_print("\t-rambo Emulate Atari 320XE (Rambo XL)");
Log_print("\t-xegs Emulate Atari XEGS");
Log_print("\t-5200 Emulate Atari 5200 Games System");
Log_print("\t-nobasic Turn off Atari BASIC ROM");
Log_print("\t-basic Turn on Atari BASIC ROM");
Log_print("\t-pal Enable PAL TV mode");
Log_print("\t-ntsc Enable NTSC TV mode");
Log_print("\t-run <file> Run Atari program (COM, EXE, XEX, BAS, LST)");
#ifndef BASIC
Log_print("\t-state <file> Load saved-state file");
Log_print("\t-refresh <rate> Specify screen refresh rate");
#endif
Log_print("\t-nopatch Don't patch SIO routine in OS");
Log_print("\t-nopatchall Don't patch OS at all, H: device won't work");
Log_print("\t-c Enable RAM between 0xc000 and 0xcfff in Atari 800");
Log_print("\t-axlon <n> Use Atari 800 Axlon memory expansion: <n> k total RAM");
Log_print("\t-axlon0f Use Axlon shadow at 0x0fc0-0x0fff");
Log_print("\t-mosaic <n> Use 400/800 Mosaic memory expansion: <n> k total RAM");
Log_print("\t-mapram Enable MapRAM for Atari XL/XE");
Log_print("\t-no-mapram Disable MapRAM");
#ifdef R_IO_DEVICE
Log_print("\t-rdevice [<dev>] Enable R: emulation (using serial device <dev>)");
#endif
Log_print("\t-turbo Run emulated Atari as fast as possible");
Log_print("\t-v Show version/release number");
}
/* copy this option for platform/module specific evaluation */
argv[j++] = argv[i];
}
/* this is the end of the additional argument check */
if (a_m) {
printf("Missing argument for '%s'\n", argv[i]);
return FALSE;
}
}
}
if (MEMORY_mosaic_num_banks > 0 && MEMORY_axlon_num_banks > 0) {
Log_print("Axlon and Mosaic RAM can not both be enabled, because they are incompatible");
return FALSE;
}
*argc = j;
/* Update machine feature variables. after reading from config file and/or
command-line options. */
Atari800_SetMachineType(Atari800_machine_type);
#ifdef SDL
if (!help_only) {
if (!SDL_INIT_Initialise())
return FALSE;
}
#endif /* SDL */
if (!SYSROM_Initialise(argc, argv)
#if !defined(BASIC) && !defined(CURSES_BASIC)
|| !Colours_Initialise(argc, argv)
|| !ARTIFACT_Initialise(argc, argv)
#endif
|| !Devices_Initialise(argc, argv)
|| !RTIME_Initialise(argc, argv)
#ifdef IDE
|| !IDE_Initialise(argc, argv)
#endif
|| !SIO_Initialise (argc, argv)
|| !CARTRIDGE_Initialise(argc, argv)
|| !CASSETTE_Initialise(argc, argv)
|| !PBI_Initialise(argc,argv)
#ifdef VOICEBOX
|| !VOICEBOX_Initialise(argc, argv)
#endif
#ifndef BASIC
|| !INPUT_Initialise(argc, argv)
#endif
#ifdef XEP80_EMULATION
|| !XEP80_Initialise(argc, argv)
#endif
#ifdef AF80
|| !AF80_Initialise(argc, argv)
#endif
#ifdef BIT3
|| !BIT3_Initialise(argc, argv)
#endif
#ifdef NTSC_FILTER
|| !FILTER_NTSC_Initialise(argc, argv)
#endif
#if SUPPORTS_CHANGE_VIDEOMODE
|| !VIDEOMODE_Initialise(argc, argv)
#endif
#ifndef DONT_DISPLAY
/* Platform Specific Initialisation */
|| !PLATFORM_Initialise(argc, argv)
#endif
#if !defined(BASIC) && !defined(CURSES_BASIC)
|| !Screen_Initialise(argc, argv)
#endif
/* Initialise Custom Chips */
|| !ANTIC_Initialise(argc, argv)
|| !GTIA_Initialise(argc, argv)
|| !PIA_Initialise(argc, argv)
|| !POKEY_Initialise(argc, argv)
) {
Atari800_ErrExit();
return FALSE;
}
#ifndef __PLUS
if (help_only) {
Atari800_ErrExit();
return FALSE;
}
#if SUPPORTS_CHANGE_VIDEOMODE
#ifndef DONT_DISPLAY
if (!VIDEOMODE_InitialiseDisplay()) {
Atari800_ErrExit();
return FALSE;
}
#endif
#endif
/* Configure Atari System */
Atari800_InitialiseMachine();
#else /* __PLUS */
if (!InitialiseMachine()) {
#ifndef _WX_
if (bUpdateRegistry)
WriteAtari800Registry();
#endif
return FALSE;
}
#endif /* __PLUS */
/* Auto-start files left on the command line */
j = 1; /* diskno */
for (i = 1; i < *argc; i++) {
if (j > 8) {
/* The remaining arguments are not necessary disk images, but ignore them... */
Log_print("Too many disk image filenames on the command line (max. 8).");
break;
}
switch (AFILE_OpenFile(argv[i], i == 1, j, FALSE)) {
case AFILE_ERROR:
Log_print("Error opening \"%s\"", argv[i]);
break;
case AFILE_ATR:
case AFILE_XFD:
case AFILE_ATR_GZ:
case AFILE_XFD_GZ:
case AFILE_DCM:
case AFILE_PRO:
j++;
break;
default:
break;
}
}
/* Install requested ROM cartridge */
if (CARTRIDGE_main.type == CARTRIDGE_UNKNOWN) {
#ifdef BASIC
Log_print("Raw cartridge images not supported in BASIC version!");
#else /* BASIC */
UI_is_active = TRUE;
CARTRIDGE_SetType(&CARTRIDGE_main, UI_SelectCartType(CARTRIDGE_main.size));
UI_is_active = FALSE;
#endif /* BASIC */
}
/* Install requested second ROM cartridge, if first is SpartaX */
if (CARTRIDGE_piggyback.type == CARTRIDGE_UNKNOWN) {
#ifdef BASIC
Log_print("Raw cartridge images not supported in BASIC version!");
#else /* BASIC */
UI_is_active = TRUE;
CARTRIDGE_SetType(&CARTRIDGE_piggyback, UI_SelectCartType(CARTRIDGE_piggyback.size));
UI_is_active = FALSE;
#endif /* BASIC */
}
#ifdef AF80
/* Insert Austin Franklin 80 column cartridge */
if (AF80_enabled) {
AF80_InsertRightCartridge();
}
#endif
/* Load Atari executable, if any */
if (run_direct != NULL)
BINLOAD_Loader(run_direct);
#ifndef BASIC
/* Load state file */
if (state_file != NULL) {
if (StateSav_ReadAtariState(state_file, "rb"))
/* Don't press Start nor Option */
GTIA_consol_override = 0;
}
#endif
#ifdef HAVE_SIGNAL
/* Install CTRL-C Handler */
signal(SIGINT, sigint_handler);
#endif
#ifdef __PLUS
#ifndef _WX_
/* Update the Registry if any parameters were specified */
if (bUpdateRegistry)
WriteAtari800Registry();
Timer_Start(FALSE);
#endif /* _WX_ */
g_ulAtariState &= ~ATARI_UNINITIALIZED;
#endif /* __PLUS */
#ifdef BENCHMARK
benchmark_start_time = Util_time();
#endif
#if defined (SOUND) && defined(SOUND_THIN_API)
if (Sound_enabled) {
/* Up to this point the Sound_enabled flag indicated that we _want_ to
enable sound. From now on, the flag will indicate whether audio
output is enabled and working. So, since the sound output was not
yet initiated, we set the flag accordingly. */
Sound_enabled = FALSE;
/* Don't worry, Sound_Setup() will set Sound_enabled back to TRUE if
it opens audio output successfully. But Sound_Setup() relies on the
flag being set if and only if audio output is active. */
if (Sound_Setup())
/* Start sound if opening audio output was successful. */
Sound_Continue();
}
#endif /* defined (SOUND) && defined(SOUND_THIN_API) */
return TRUE;
}
UNALIGNED_STAT_DEF(Screen_atari_write_long_stat)
UNALIGNED_STAT_DEF(pm_scanline_read_long_stat)
UNALIGNED_STAT_DEF(memory_read_word_stat)
UNALIGNED_STAT_DEF(memory_write_word_stat)
UNALIGNED_STAT_DEF(memory_read_aligned_word_stat)
UNALIGNED_STAT_DEF(memory_write_aligned_word_stat)
int Atari800_Exit(int run_monitor)
{
int restart;
#ifdef __PLUS
if (CPU_cim_encountered)
g_ulAtariState |= ATARI_CRASHED;
#endif
#ifdef STAT_UNALIGNED_WORDS
printf("(ptr&7) Screen_atari pm_scanline _____ memory ______ memory (aligned addr)\n");
printf(" 32-bit W 32-bit R 16-bit R 16-bit W 16-bit R 16-bit W\n");
{
unsigned int sums[6] = {0, 0, 0, 0, 0, 0};
int i;
for (i = 0; i < 8; i++) {
printf("%6d%12u%14u%11u%11u%11u%11u\n", i,
Screen_atari_write_long_stat[i], pm_scanline_read_long_stat[i],
memory_read_word_stat[i], memory_write_word_stat[i],
memory_read_aligned_word_stat[i], memory_write_aligned_word_stat[i]);
sums[0] += Screen_atari_write_long_stat[i];
sums[1] += pm_scanline_read_long_stat[i];
sums[2] += memory_read_word_stat[i];
sums[3] += memory_write_word_stat[i];
sums[4] += memory_read_aligned_word_stat[i];
sums[5] += memory_write_aligned_word_stat[i];
}
printf("total:%12u%14u%11u%11u%11u%11u\n",
sums[0], sums[1], sums[2], sums[3], sums[4], sums[5]);
}
#endif /* STAT_UNALIGNED_WORDS */
restart = PLATFORM_Exit(run_monitor);
#ifdef HAVE_SIGNAL
/* If a user pressed Ctrl+C in the monitor, avoid immediate return to it. */
sigint_flag = FALSE;
#endif /* HAVE_SIGNAL */
#ifndef __PLUS
if (!restart) {
/* We'd better save the configuration before calling the *_Exit() functions -
there's a danger that they might change some emulator settings. */
if (CFG_save_on_exit)
CFG_WriteConfig();
/* Cleanup functions, in reverse order as the init functions in
Atari800_Initialise(). */
#ifdef SOUND
Sound_Exit();
#endif
#if SUPPORTS_CHANGE_VIDEOMODE
VIDEOMODE_Exit();
#endif
#ifdef AF80
AF80_Exit();
#endif
#ifdef BIT3
BIT3_Exit();
#endif
#ifndef BASIC
INPUT_Exit(); /* finish event recording */
#endif
PBI_Exit();
CASSETTE_Exit(); /* Finish writing to the cassette file */
CARTRIDGE_Exit();
SIO_Exit(); /* umount disks, so temporary files are deleted */
#ifdef IDE
IDE_Exit();