annotate blastem.c @ 1472:d2d637dbacfb segacd

Change load_rom into load_media with some interface changes in preparation for CD support
author Michael Pavone <pavone@retrodev.com>
date Sat, 21 Oct 2017 11:51:24 -0700
parents 4929325c3ce0
children 5dacaef602a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
467
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 464
diff changeset
1 /*
1018
dba8c630bdbf Update changelog and version number for 0.4.0 release
Michael Pavone <pavone@retrodev.com>
parents: 1017
diff changeset
2 Copyright 2013-2016 Michael Pavone
469
5f3344d0d42f Fix argument handling so that the rom filename does not need to be specified first
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
3 This file is part of BlastEm.
467
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 464
diff changeset
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 464
diff changeset
5 */
883
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
6 #include <stdio.h>
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
7 #include <stdlib.h>
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
8 #include <string.h>
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
9 #include <ctype.h>
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
10
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
11 #include "system.h"
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
12 #include "68kinst.h"
569
9b7fcf748be0 Rename x86_68k_options and m68k_to_x86.h to m68k_options and m68k_core.h respectively
Michael Pavone <pavone@retrodev.com>
parents: 565
diff changeset
13 #include "m68k_core.h"
260
625f8e4d5fd2 Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 215
diff changeset
14 #include "z80_to_x86.h"
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
15 #include "mem.h"
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16 #include "vdp.h"
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
17 #include "render.h"
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
18 #include "genesis.h"
515
1495179d6737 Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents: 510
diff changeset
19 #include "gdb_remote.h"
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 447
diff changeset
20 #include "gst.h"
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 488
diff changeset
21 #include "util.h"
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
22 #include "romdb.h"
832
0433fdd9ba66 Added a command line option to force BlastEm to not open a new terminal even if it detects that stdin/out are not terminals
Michael Pavone <pavone@retrodev.com>
parents: 819
diff changeset
23 #include "terminal.h"
883
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
24 #include "arena.h"
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
25 #include "config.h"
1423
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
26 #include "menu.h"
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
27
1459
34ebc6dab75c Update version number for nightly builds
Michael Pavone <pavone@retrodev.com>
parents: 1456
diff changeset
28 #define BLASTEM_VERSION "0.5.2-pre"
464
226ed16b1fb6 Added version flag
Mike Pavone <pavone@retrodev.com>
parents: 463
diff changeset
29
860
213c3b5160d0 Default to fullscreen on Android since windowed mode does not make sense there
Michael Pavone <pavone@retrodev.com>
parents: 846
diff changeset
30 #ifdef __ANDROID__
213c3b5160d0 Default to fullscreen on Android since windowed mode does not make sense there
Michael Pavone <pavone@retrodev.com>
parents: 846
diff changeset
31 #define FULLSCREEN_DEFAULT 1
213c3b5160d0 Default to fullscreen on Android since windowed mode does not make sense there
Michael Pavone <pavone@retrodev.com>
parents: 846
diff changeset
32 #else
213c3b5160d0 Default to fullscreen on Android since windowed mode does not make sense there
Michael Pavone <pavone@retrodev.com>
parents: 846
diff changeset
33 #define FULLSCREEN_DEFAULT 0
213c3b5160d0 Default to fullscreen on Android since windowed mode does not make sense there
Michael Pavone <pavone@retrodev.com>
parents: 846
diff changeset
34 #endif
213c3b5160d0 Default to fullscreen on Android since windowed mode does not make sense there
Michael Pavone <pavone@retrodev.com>
parents: 846
diff changeset
35
215
2b1c2c28b261 Added headless flag to avoid initializing SDL and opening a window when running tests.
Mike Pavone <pavone@retrodev.com>
parents: 211
diff changeset
36 int headless = 0;
505
b7b7a1cab44a The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents: 501
diff changeset
37 int exit_after = 0;
265
c6d12878ea93 Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 264
diff changeset
38 int z80_enabled = 1;
356
79e4b466e7d0 Get rid of debug puts and limit based on audio rather than frame rate by default.
Mike Pavone <pavone@retrodev.com>
parents: 354
diff changeset
39 int frame_limit = 0;
1428
2540c05520f2 New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents: 1423
diff changeset
40 uint8_t use_native_states = 1;
215
2b1c2c28b261 Added headless flag to avoid initializing SDL and opening a window when running tests.
Mike Pavone <pavone@retrodev.com>
parents: 211
diff changeset
41
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents: 425
diff changeset
42 tern_node * config;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents: 425
diff changeset
43
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
44 #define SMD_HEADER_SIZE 512
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
45 #define SMD_MAGIC1 0x03
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
46 #define SMD_MAGIC2 0xAA
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
47 #define SMD_MAGIC3 0xBB
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
48 #define SMD_BLOCK_SIZE 0x4000
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
49
1140
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
50 int load_smd_rom(long filesize, FILE * f, void **buffer)
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
51 {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
52 uint8_t block[SMD_BLOCK_SIZE];
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
53 filesize -= SMD_HEADER_SIZE;
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
54 fseek(f, SMD_HEADER_SIZE, SEEK_SET);
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
55
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
56 uint16_t *dst = *buffer = malloc(nearest_pow2(filesize));
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
57 int rom_size = filesize;
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
58 while (filesize > 0) {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
59 fread(block, 1, SMD_BLOCK_SIZE, f);
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
60 for (uint8_t *low = block, *high = (block+SMD_BLOCK_SIZE/2), *end = block+SMD_BLOCK_SIZE; high < end; high++, low++) {
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
61 *(dst++) = *low << 8 | *high;
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
62 }
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
63 filesize -= SMD_BLOCK_SIZE;
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
64 }
975
c6b19939da7b Fixed loading of SMD format ROMs
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
65 return rom_size;
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
66 }
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
67
1472
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
68 uint32_t load_media(char * filename, system_media *dst, system_type *stype)
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
69 {
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
70 uint8_t header[10];
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
71 FILE * f = fopen(filename, "rb");
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
72 if (!f) {
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
73 return 0;
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
74 }
776
cbf97d335444 Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents: 774
diff changeset
75 if (sizeof(header) != fread(header, 1, sizeof(header), f)) {
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 787
diff changeset
76 fatal_error("Error reading from %s\n", filename);
776
cbf97d335444 Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents: 774
diff changeset
77 }
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
78 fseek(f, 0, SEEK_END);
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
79 long filesize = ftell(f);
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
80 fseek(f, 0, SEEK_SET);
1472
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
81 uint32_t ret = 0;
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
82 if (header[1] == SMD_MAGIC1 && header[8] == SMD_MAGIC2 && header[9] == SMD_MAGIC3) {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
83 int i;
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
84 for (i = 3; i < 8; i++) {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
85 if (header[i] != 0) {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
86 break;
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
87 }
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
88 }
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
89 if (i == 8) {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
90 if (header[2]) {
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 787
diff changeset
91 fatal_error("%s is a split SMD ROM which is not currently supported", filename);
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
92 }
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
93 if (stype) {
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
94 *stype = SYSTEM_GENESIS;
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
95 }
1472
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
96 ret = load_smd_rom(filesize, f, &dst->buffer);
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
97 }
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
98 }
1472
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
99 if (!ret) {
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
100 dst->buffer = malloc(nearest_pow2(filesize));
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
101 if (filesize != fread(dst->buffer, 1, filesize, f)) {
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
102 fatal_error("Error reading from %s\n", filename);
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
103 }
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
104 ret = filesize;
776
cbf97d335444 Full support for Sega mapper when it comes to data. Code in remapped sections may not work reliably. SSF2 now works.
Michael Pavone <pavone@retrodev.com>
parents: 774
diff changeset
105 }
1472
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
106 dst->dir = path_dirname(filename);
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
107 dst->name = basename_no_extension(filename);
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
108 dst->extension = path_extension(filename);
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
109 dst->size = ret;
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
110 fclose(f);
1472
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
111 return ret;
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
112 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
113
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
114
186
02e25abe2dcd Cleanup VINT code and fix bug in which VINT cycle would be set incorrectly after a VDP control port write
Mike Pavone <pavone@retrodev.com>
parents: 185
diff changeset
115
198
209a37eed3e7 Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents: 197
diff changeset
116 int break_on_sync = 0;
955
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 953
diff changeset
117 char *save_state_path;
260
625f8e4d5fd2 Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 215
diff changeset
118
832
0433fdd9ba66 Added a command line option to force BlastEm to not open a new terminal even if it detects that stdin/out are not terminals
Michael Pavone <pavone@retrodev.com>
parents: 819
diff changeset
119
0433fdd9ba66 Added a command line option to force BlastEm to not open a new terminal even if it detects that stdin/out are not terminals
Michael Pavone <pavone@retrodev.com>
parents: 819
diff changeset
120
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
121
483
3e1573fa22cf Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents: 482
diff changeset
122
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
123 char * save_filename;
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
124 system_header *current_system;
1423
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
125 system_header *menu_system;
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
126 system_header *game_system;
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
127 void persist_save()
351
2f264d2a60c2 Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents: 346
diff changeset
128 {
1423
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
129 if (!game_system) {
1009
883fe974f72b Fix bug in which save RAM/EEPROM was not persisted correctly if the emulator is exited via the menu rather than the X button in the title bar
Michael Pavone <pavone@retrodev.com>
parents: 1008
diff changeset
130 return;
883fe974f72b Fix bug in which save RAM/EEPROM was not persisted correctly if the emulator is exited via the menu rather than the X button in the title bar
Michael Pavone <pavone@retrodev.com>
parents: 1008
diff changeset
131 }
1423
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
132 game_system->persist_save(game_system);
351
2f264d2a60c2 Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents: 346
diff changeset
133 }
2f264d2a60c2 Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents: 346
diff changeset
134
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
135 char *title;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
136 void update_title(char *rom_name)
340
58a085cfc6bd Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents: 338
diff changeset
137 {
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
138 if (title) {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
139 free(title);
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
140 title = NULL;
340
58a085cfc6bd Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents: 338
diff changeset
141 }
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
142 title = alloc_concat(rom_name, " - BlastEm");
874
b6842dfb8edf ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
143 render_update_caption(title);
340
58a085cfc6bd Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents: 338
diff changeset
144 }
58a085cfc6bd Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents: 338
diff changeset
145
1412
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
146 static char *get_save_dir(system_media *media)
955
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 953
diff changeset
147 {
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1295
diff changeset
148 char *savedir_template = tern_find_path(config, "ui\0save_path\0", TVAL_PTR).ptrval;
1295
96ad1b9bbb3a Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents: 1223
diff changeset
149 if (!savedir_template) {
96ad1b9bbb3a Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents: 1223
diff changeset
150 savedir_template = "$USERDATA/blastem/$ROMNAME";
96ad1b9bbb3a Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents: 1223
diff changeset
151 }
1412
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
152 tern_node *vars = tern_insert_ptr(NULL, "ROMNAME", media->name);
1295
96ad1b9bbb3a Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents: 1223
diff changeset
153 vars = tern_insert_ptr(vars, "HOME", get_home_dir());
96ad1b9bbb3a Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents: 1223
diff changeset
154 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir());
96ad1b9bbb3a Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents: 1223
diff changeset
155 vars = tern_insert_ptr(vars, "USERDATA", (char *)get_userdata_dir());
96ad1b9bbb3a Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents: 1223
diff changeset
156 char *save_dir = replace_vars(savedir_template, vars, 1);
96ad1b9bbb3a Make save directory configurable. Satisfies ticket:4
Michael Pavone <pavone@retrodev.com>
parents: 1223
diff changeset
157 tern_free(vars);
955
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 953
diff changeset
158 if (!ensure_dir_exists(save_dir)) {
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 953
diff changeset
159 warning("Failed to create save directory %s\n", save_dir);
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 953
diff changeset
160 }
1412
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
161 return save_dir;
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
162 }
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
163
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
164 void setup_saves(system_media *media, rom_info *info, system_header *context)
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
165 {
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
166 static uint8_t persist_save_registered;
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
167 char *save_dir = get_save_dir(info->is_save_lock_on ? media->chain : media);
1395
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1393
diff changeset
168 char const *parts[] = {save_dir, PATH_SEP, info->save_type == SAVE_I2C ? "save.eeprom" : info->save_type == SAVE_NOR ? "save.nor" : "save.sram"};
955
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 953
diff changeset
169 free(save_filename);
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 953
diff changeset
170 save_filename = alloc_concat_m(3, parts);
1412
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
171 if (info->is_save_lock_on) {
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
172 //initial save dir was calculated based on lock-on cartridge because that's where the save device is
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
173 //save directory used for save states should still be located in the normal place
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
174 free(save_dir);
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
175 save_dir = get_save_dir(media);
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
176 }
1428
2540c05520f2 New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents: 1423
diff changeset
177 if (use_native_states || context->type != SYSTEM_GENESIS) {
2540c05520f2 New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents: 1423
diff changeset
178 parts[2] = "quicksave.state";
2540c05520f2 New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents: 1423
diff changeset
179 } else {
2540c05520f2 New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents: 1423
diff changeset
180 parts[2] = "quicksave.gst";
2540c05520f2 New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents: 1423
diff changeset
181 }
955
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 953
diff changeset
182 free(save_state_path);
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 953
diff changeset
183 save_state_path = alloc_concat_m(3, parts);
956
f5550cdffe49 Saving the save directory in the rom_info struct didn't make sense. It should be in the console context.
Michael Pavone <pavone@retrodev.com>
parents: 955
diff changeset
184 context->save_dir = save_dir;
f5550cdffe49 Saving the save directory in the rom_info struct didn't make sense. It should be in the console context.
Michael Pavone <pavone@retrodev.com>
parents: 955
diff changeset
185 if (info->save_type != SAVE_NONE) {
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
186 context->load_save(context);
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
187 if (!persist_save_registered) {
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
188 atexit(persist_save);
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
189 persist_save_registered = 1;
956
f5550cdffe49 Saving the save directory in the rom_info struct didn't make sense. It should be in the console context.
Michael Pavone <pavone@retrodev.com>
parents: 955
diff changeset
190 }
f5550cdffe49 Saving the save directory in the rom_info struct didn't make sense. It should be in the console context.
Michael Pavone <pavone@retrodev.com>
parents: 955
diff changeset
191 }
955
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 953
diff changeset
192 }
229c23b3ab73 Switch to storing SRAM/EEPROM and save states in a per-game directory rather than next to the ROM (for SRAM/EEPROM) or in the current working directory (for save states)
Michael Pavone <pavone@retrodev.com>
parents: 953
diff changeset
193
1397
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
194 static void on_drag_drop(const char *filename)
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
195 {
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
196 if (current_system->next_rom) {
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
197 free(current_system->next_rom);
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
198 }
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
199 current_system->next_rom = strdup(filename);
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
200 current_system->request_exit(current_system);
1423
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
201 if (menu_system && menu_system->type == SYSTEM_GENESIS) {
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
202 genesis_context *gen = (genesis_context *)menu_system;
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
203 if (gen->extra) {
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
204 menu_context *menu = gen->extra;
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
205 menu->external_game_load = 1;
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
206 } else {
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
207 puts("No extra");
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
208 }
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
209 } else {
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
210 puts("no menu");
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
211 }
1397
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
212 }
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
213
1438
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
214 static system_media cart, lock_on;
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
215 void reload_media(void)
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
216 {
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
217 if (current_system->next_rom) {
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
218 free(current_system->next_rom);
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
219 }
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
220 char const *parts[] = {
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
221 cart.dir, PATH_SEP, cart.name, ".", cart.extension
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
222 };
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
223 char const **start = parts[0] ? parts : parts + 2;
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
224 int num_parts = parts[0] ? 5 : 3;
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
225 if (!parts[4]) {
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
226 num_parts--;
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
227 }
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
228 current_system->next_rom = alloc_concat_m(num_parts, start);
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
229 current_system->request_exit(current_system);
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
230 }
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
231
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
232 void lockon_media(char *lock_on_path)
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
233 {
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
234 reload_media();
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
235 cart.chain = &lock_on;
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
236 free(lock_on.dir);
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
237 free(lock_on.name);
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
238 free(lock_on.extension);
1472
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
239 load_media(lock_on_path, &lock_on, NULL);
1438
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
240 }
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
241
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
242 int main(int argc, char ** argv)
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
243 {
496
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 488
diff changeset
244 set_exe_str(argv[0]);
6fc71114d145 Extract function to determine executable directory from load_config so it can be used elsewhere
Mike Pavone <pavone@retrodev.com>
parents: 488
diff changeset
245 config = load_config();
184
ebcbdd1c4cc8 Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents: 166
diff changeset
246 int width = -1;
ebcbdd1c4cc8 Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents: 166
diff changeset
247 int height = -1;
ebcbdd1c4cc8 Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents: 166
diff changeset
248 int debug = 0;
1113
45db303fc705 Restore 68K address logging functionality
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
249 uint32_t opts = 0;
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
250 int loaded = 0;
1140
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
251 system_type stype = SYSTEM_UNKNOWN, force_stype = SYSTEM_UNKNOWN;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
252 uint8_t force_region = 0;
469
5f3344d0d42f Fix argument handling so that the rom filename does not need to be specified first
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
253 char * romfname = NULL;
425
8b3ae850d1c4 Forgot to null initialize the statfile pointer
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
254 char * statefile = NULL;
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
255 debugger_type dtype = DEBUGGER_NATIVE;
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
256 uint8_t start_in_debugger = 0;
860
213c3b5160d0 Default to fullscreen on Android since windowed mode does not make sense there
Michael Pavone <pavone@retrodev.com>
parents: 846
diff changeset
257 uint8_t fullscreen = FULLSCREEN_DEFAULT, use_gl = 1;
885
e3f5ec336432 Allow menu ROM to be debugged
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
258 uint8_t debug_target = 0;
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
259 for (int i = 1; i < argc; i++) {
184
ebcbdd1c4cc8 Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents: 166
diff changeset
260 if (argv[i][0] == '-') {
ebcbdd1c4cc8 Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents: 166
diff changeset
261 switch(argv[i][1]) {
505
b7b7a1cab44a The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents: 501
diff changeset
262 case 'b':
b7b7a1cab44a The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents: 501
diff changeset
263 i++;
b7b7a1cab44a The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents: 501
diff changeset
264 if (i >= argc) {
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 787
diff changeset
265 fatal_error("-b must be followed by a frame count\n");
505
b7b7a1cab44a The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents: 501
diff changeset
266 }
b7b7a1cab44a The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents: 501
diff changeset
267 headless = 1;
b7b7a1cab44a The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents: 501
diff changeset
268 exit_after = atoi(argv[i]);
b7b7a1cab44a The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents: 501
diff changeset
269 break;
184
ebcbdd1c4cc8 Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents: 166
diff changeset
270 case 'd':
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
271 start_in_debugger = 1;
885
e3f5ec336432 Allow menu ROM to be debugged
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
272 //allow debugging the menu
e3f5ec336432 Allow menu ROM to be debugged
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
273 if (argv[i][2] == 'm') {
e3f5ec336432 Allow menu ROM to be debugged
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
274 debug_target = 1;
e3f5ec336432 Allow menu ROM to be debugged
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
275 }
515
1495179d6737 Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents: 510
diff changeset
276 break;
1495179d6737 Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents: 510
diff changeset
277 case 'D':
1495179d6737 Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents: 510
diff changeset
278 gdb_remote_init();
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
279 dtype = DEBUGGER_GDB;
1164
21df13266e6a Restore functionality of the -D flag for GDB remote debugging
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
280 start_in_debugger = 1;
184
ebcbdd1c4cc8 Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents: 166
diff changeset
281 break;
338
5c34a9c39394 Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents: 336
diff changeset
282 case 'f':
860
213c3b5160d0 Default to fullscreen on Android since windowed mode does not make sense there
Michael Pavone <pavone@retrodev.com>
parents: 846
diff changeset
283 fullscreen = !fullscreen;
338
5c34a9c39394 Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents: 336
diff changeset
284 break;
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
285 case 'g':
501
e1355aa80f4d Use OpenGL by default. Add OpenGL switch to help text
Mike Pavone <pavone@retrodev.com>
parents: 496
diff changeset
286 use_gl = 0;
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
287 break;
197
7c227a8ec53d Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents: 195
diff changeset
288 case 'l':
1113
45db303fc705 Restore 68K address logging functionality
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
289 opts |= OPT_ADDRESS_LOG;
197
7c227a8ec53d Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents: 195
diff changeset
290 break;
464
226ed16b1fb6 Added version flag
Mike Pavone <pavone@retrodev.com>
parents: 463
diff changeset
291 case 'v':
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 787
diff changeset
292 info_message("blastem %s\n", BLASTEM_VERSION);
464
226ed16b1fb6 Added version flag
Mike Pavone <pavone@retrodev.com>
parents: 463
diff changeset
293 return 0;
226ed16b1fb6 Added version flag
Mike Pavone <pavone@retrodev.com>
parents: 463
diff changeset
294 break;
265
c6d12878ea93 Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 264
diff changeset
295 case 'n':
c6d12878ea93 Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 264
diff changeset
296 z80_enabled = 0;
c6d12878ea93 Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 264
diff changeset
297 break;
341
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
298 case 'r':
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
299 i++;
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
300 if (i >= argc) {
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 787
diff changeset
301 fatal_error("-r must be followed by region (J, U or E)\n");
341
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
302 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
303 force_region = translate_region_char(toupper(argv[i][0]));
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
304 if (!force_region) {
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 787
diff changeset
305 fatal_error("'%c' is not a valid region character for the -r option\n", argv[i][0]);
341
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
306 }
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
307 break;
1140
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
308 case 'm':
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
309 i++;
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
310 if (i >= argc) {
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
311 fatal_error("-r must be followed by a machine type (sms, gen or jag)\n");
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
312 }
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
313 if (!strcmp("sms", argv[i])) {
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
314 stype = force_stype = SYSTEM_SMS;
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
315 } else if (!strcmp("gen", argv[i])) {
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
316 stype = force_stype = SYSTEM_GENESIS;
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
317 } else if (!strcmp("jag", argv[i])) {
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
318 stype = force_stype = SYSTEM_JAGUAR;
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
319 } else {
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
320 fatal_error("Unrecognized machine type %s\n", argv[i]);
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
321 }
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
322 break;
424
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
323 case 's':
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
324 i++;
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
325 if (i >= argc) {
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 787
diff changeset
326 fatal_error("-s must be followed by a savestate filename\n");
424
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
327 }
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
328 statefile = argv[i];
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
329 break;
832
0433fdd9ba66 Added a command line option to force BlastEm to not open a new terminal even if it detects that stdin/out are not terminals
Michael Pavone <pavone@retrodev.com>
parents: 819
diff changeset
330 case 't':
0433fdd9ba66 Added a command line option to force BlastEm to not open a new terminal even if it detects that stdin/out are not terminals
Michael Pavone <pavone@retrodev.com>
parents: 819
diff changeset
331 force_no_terminal();
0433fdd9ba66 Added a command line option to force BlastEm to not open a new terminal even if it detects that stdin/out are not terminals
Michael Pavone <pavone@retrodev.com>
parents: 819
diff changeset
332 break;
407
c3abc4ada43d Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents: 405
diff changeset
333 case 'y':
1113
45db303fc705 Restore 68K address logging functionality
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
334 opts |= YM_OPT_WAVE_LOG;
407
c3abc4ada43d Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents: 405
diff changeset
335 break;
1016
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1009
diff changeset
336 case 'o': {
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1009
diff changeset
337 i++;
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1009
diff changeset
338 if (i >= argc) {
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1009
diff changeset
339 fatal_error("-o must be followed by a lock on cartridge filename\n");
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1009
diff changeset
340 }
1472
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
341 if (!load_media(argv[i], &lock_on, NULL)) {
1016
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1009
diff changeset
342 fatal_error("Failed to load lock on cartridge %s\n", argv[i]);
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1009
diff changeset
343 }
1140
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
344 cart.chain = &lock_on;
1016
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1009
diff changeset
345 break;
5fb64487b6e1 Very basic support for S&K lock-on. Needs more work for full functionality.
Michael Pavone <pavone@retrodev.com>
parents: 1009
diff changeset
346 }
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
347 case 'h':
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 787
diff changeset
348 info_message(
469
5f3344d0d42f Fix argument handling so that the rom filename does not need to be specified first
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
349 "Usage: blastem [OPTIONS] ROMFILE [WIDTH] [HEIGHT]\n"
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
350 "Options:\n"
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
351 " -h Print this help text\n"
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
352 " -r (J|U|E) Force region to Japan, US or Europe respectively\n"
1223
a477cc22a960 Fix indentation of -m option
Michael Pavone <pavone@retrodev.com>
parents: 1201
diff changeset
353 " -m MACHINE Force emulated machine type to MACHINE. Valid values are:\n"
1140
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
354 " sms - Sega Master System/Mark III\n"
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
355 " gen - Sega Genesis/Megadrive\n"
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
356 " jag - Atari Jaguar\n"
1017
216fa63749b3 Added documentation for lock-on support and a fullscreen config option.
Michael Pavone <pavone@retrodev.com>
parents: 1016
diff changeset
357 " -f Toggles fullscreen mode\n"
501
e1355aa80f4d Use OpenGL by default. Add OpenGL switch to help text
Mike Pavone <pavone@retrodev.com>
parents: 496
diff changeset
358 " -g Disable OpenGL rendering\n"
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
359 " -s FILE Load a GST format savestate from FILE\n"
1017
216fa63749b3 Added documentation for lock-on support and a fullscreen config option.
Michael Pavone <pavone@retrodev.com>
parents: 1016
diff changeset
360 " -o FILE Load FILE as a lock-on cartridge\n"
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
361 " -d Enter debugger on startup\n"
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
362 " -n Disable Z80\n"
501
e1355aa80f4d Use OpenGL by default. Add OpenGL switch to help text
Mike Pavone <pavone@retrodev.com>
parents: 496
diff changeset
363 " -v Display version number and exit\n"
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
364 " -l Log 68K code addresses (useful for assemblers)\n"
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
365 " -y Log individual YM-2612 channels to WAVE files\n"
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
366 );
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
367 return 0;
184
ebcbdd1c4cc8 Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents: 166
diff changeset
368 default:
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 787
diff changeset
369 fatal_error("Unrecognized switch %s\n", argv[i]);
184
ebcbdd1c4cc8 Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents: 166
diff changeset
370 }
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
371 } else if (!loaded) {
1472
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
372 if (!load_media(argv[i], &cart, stype == SYSTEM_UNKNOWN ? &stype : NULL)) {
792
724bbec47f86 Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents: 787
diff changeset
373 fatal_error("Failed to open %s for reading\n", argv[i]);
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
374 }
469
5f3344d0d42f Fix argument handling so that the rom filename does not need to be specified first
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
375 romfname = argv[i];
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
376 loaded = 1;
184
ebcbdd1c4cc8 Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents: 166
diff changeset
377 } else if (width < 0) {
ebcbdd1c4cc8 Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents: 166
diff changeset
378 width = atoi(argv[i]);
ebcbdd1c4cc8 Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents: 166
diff changeset
379 } else if (height < 0) {
ebcbdd1c4cc8 Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents: 166
diff changeset
380 height = atoi(argv[i]);
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
381 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
382 }
874
b6842dfb8edf ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
383 uint8_t menu = !loaded;
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
384 if (!loaded) {
874
b6842dfb8edf ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
385 //load menu
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1295
diff changeset
386 romfname = tern_find_path(config, "ui\0rom\0", TVAL_PTR).ptrval;
874
b6842dfb8edf ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
387 if (!romfname) {
b6842dfb8edf ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
388 romfname = "menu.bin";
b6842dfb8edf ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
389 }
1008
51885857c019 Removed assumptions that path separators are Unix style outside of Unix-only verions of functions
Michael Pavone <pavone@retrodev.com>
parents: 1002
diff changeset
390 if (is_absolute_path(romfname)) {
1472
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
391 if (!load_media(romfname, &cart, &stype)) {
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
392 fatal_error("Failed to open UI ROM %s for reading", romfname);
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
393 }
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
394 } else {
1140
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
395 cart.buffer = (uint16_t *)read_bundled_file(romfname, &cart.size);
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
396 if (!cart.buffer) {
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
397 fatal_error("Failed to open UI ROM %s for reading", romfname);
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
398 }
1140
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
399 uint32_t rom_size = nearest_pow2(cart.size);
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
400 if (rom_size > cart.size) {
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
401 cart.buffer = realloc(cart.buffer, rom_size);
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
402 cart.size = rom_size;
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
403 }
1472
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
404 cart.dir = path_dirname(romfname);
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
405 cart.name = basename_no_extension(romfname);
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
406 cart.extension = path_extension(romfname);
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
407 }
1140
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
408 //force system detection, value on command line is only for games not the menu
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
409 stype = detect_system_type(&cart);
861
4e394d9a7548 Added temporary hack for loading a fixed ROM path so that Android build is "useable" before UI is in place
Michael Pavone <pavone@retrodev.com>
parents: 860
diff changeset
410 loaded = 1;
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
411 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
412
1402
458df351af06 Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents: 1397
diff changeset
413 int def_width = 0, def_height = 0;
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1295
diff changeset
414 char *config_width = tern_find_path(config, "video\0width\0", TVAL_PTR).ptrval;
433
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
415 if (config_width) {
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
416 def_width = atoi(config_width);
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
417 }
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
418 if (!def_width) {
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
419 def_width = 640;
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
420 }
1402
458df351af06 Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents: 1397
diff changeset
421 char *config_height = tern_find_path(config, "video\0height\0", TVAL_PTR).ptrval;
458df351af06 Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents: 1397
diff changeset
422 if (config_height) {
458df351af06 Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents: 1397
diff changeset
423 def_height = atoi(config_height);
458df351af06 Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents: 1397
diff changeset
424 }
458df351af06 Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents: 1397
diff changeset
425 if (!def_height) {
458df351af06 Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents: 1397
diff changeset
426 def_height = -1;
458df351af06 Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents: 1397
diff changeset
427 }
458df351af06 Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents: 1397
diff changeset
428 width = width < 1 ? def_width : width;
458df351af06 Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents: 1397
diff changeset
429 height = height < 1 ? def_height : height;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
430
1326
071e761bcdcf Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents: 1295
diff changeset
431 char *config_fullscreen = tern_find_path(config, "video\0fullscreen\0", TVAL_PTR).ptrval;
1017
216fa63749b3 Added documentation for lock-on support and a fullscreen config option.
Michael Pavone <pavone@retrodev.com>
parents: 1016
diff changeset
432 if (config_fullscreen && !strcmp("on", config_fullscreen)) {
216fa63749b3 Added documentation for lock-on support and a fullscreen config option.
Michael Pavone <pavone@retrodev.com>
parents: 1016
diff changeset
433 fullscreen = !fullscreen;
216fa63749b3 Added documentation for lock-on support and a fullscreen config option.
Michael Pavone <pavone@retrodev.com>
parents: 1016
diff changeset
434 }
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 351
diff changeset
435 if (!headless) {
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
436 render_init(width, height, "BlastEm", fullscreen);
1397
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
437 render_set_drag_drop_handler(on_drag_drop);
342
13f994c88c34 Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents: 341
diff changeset
438 }
874
b6842dfb8edf ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
439
1140
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
440 if (stype == SYSTEM_UNKNOWN) {
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
441 stype = detect_system_type(&cart);
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
442 }
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
443 if (stype == SYSTEM_UNKNOWN) {
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
444 fatal_error("Failed to detect system type for %s\n", romfname);
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
445 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
446 rom_info info;
1140
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
447 current_system = alloc_config_system(stype, &cart, menu ? 0 : opts, force_region, &info);
1128
093c19f34dfd Detect failures to initialize a system context and report an error rather than crashing
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
448 if (!current_system) {
1140
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
449 fatal_error("Failed to configure emulated machine for %s\n", romfname);
1128
093c19f34dfd Detect failures to initialize a system context and report an error rather than crashing
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
450 }
1428
2540c05520f2 New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents: 1423
diff changeset
451 char *state_format = tern_find_path(config, "ui\0state_format\0", TVAL_PTR).ptrval;
2540c05520f2 New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents: 1423
diff changeset
452 if (state_format && !strcmp(state_format, "gst")) {
2540c05520f2 New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents: 1423
diff changeset
453 use_native_states = 0;
2540c05520f2 New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents: 1423
diff changeset
454 } else if (state_format && strcmp(state_format, "native")) {
2540c05520f2 New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents: 1423
diff changeset
455 warning("%s is not a valid value for the ui.state_format setting. Valid values are gst and native\n", state_format);
2540c05520f2 New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents: 1423
diff changeset
456 }
1412
909c72c4e5a1 Load SRAM/EEPROM from lock-on cart directory if the lock-on cart is the one with the save device
Michael Pavone <pavone@retrodev.com>
parents: 1402
diff changeset
457 setup_saves(&cart, &info, current_system);
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
458 update_title(info.name);
874
b6842dfb8edf ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
459 if (menu) {
1423
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
460 menu_system = current_system;
874
b6842dfb8edf ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
461 } else {
1423
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
462 game_system = current_system;
874
b6842dfb8edf ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
463 }
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
464
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
465 current_system->debugger_type = dtype;
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
466 current_system->enter_debugger = start_in_debugger && menu == debug_target;
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
467 current_system->start_context(current_system, menu ? NULL : statefile);
883
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
468 for(;;)
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
469 {
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
470 if (current_system->should_exit) {
949
5e4fb650de58 Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
471 break;
5e4fb650de58 Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
472 }
1397
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
473 if (current_system->next_rom) {
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
474 char *next_rom = current_system->next_rom;
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
475 current_system->next_rom = NULL;
1423
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
476 if (game_system) {
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
477 game_system->persist_save(game_system);
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
478 //swap to game context arena and mark all allocated pages in it free
1397
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
479 if (menu) {
1423
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
480 current_system->arena = set_current_arena(game_system->arena);
1397
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
481 }
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
482 mark_all_free();
1423
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
483 game_system->free_context(game_system);
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
484 } else {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
485 //start a new arena and save old one in suspended genesis context
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
486 current_system->arena = start_new_arena();
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
487 }
1438
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
488 free(cart.dir);
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
489 free(cart.name);
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
490 free(cart.extension);
1472
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
491 if (!load_media(next_rom, &cart, &stype)) {
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
492 fatal_error("Failed to open %s for reading\n", next_rom);
d2d637dbacfb Change load_rom into load_media with some interface changes in preparation for CD support
Michael Pavone <pavone@retrodev.com>
parents: 1460
diff changeset
493 }
1140
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
494 stype = force_stype;
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
495 if (stype == SYSTEM_UNKNOWN) {
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
496 stype = detect_system_type(&cart);
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
497 }
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
498 if (stype == SYSTEM_UNKNOWN) {
1397
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
499 fatal_error("Failed to detect system type for %s\n", next_rom);
1140
4490c9c12272 Detect system type from filename if header based methods fail. Allow overriding system type from command line.
Michael Pavone <pavone@retrodev.com>
parents: 1128
diff changeset
500 }
1397
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
501 //allocate new system context
1423
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
502 game_system = alloc_config_system(stype, &cart, opts,force_region, &info);
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
503 if (!game_system) {
1397
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
504 fatal_error("Failed to configure emulated machine for %s\n", next_rom);
1128
093c19f34dfd Detect failures to initialize a system context and report an error rather than crashing
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
505 }
1438
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
506 if (menu_system) {
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
507 menu_system->next_context = game_system;
e2bd03ed3190 Allow reloading current ROM with a hotkey (default F5) and allow locking on a cartridge via menu
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
508 }
1423
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
509 game_system->next_context = menu_system;
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
510 setup_saves(&cart, &info, game_system);
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1097
diff changeset
511 update_title(info.name);
1397
89eb967fed72 Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents: 1395
diff changeset
512 free(next_rom);
883
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
513 menu = 0;
1423
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
514 current_system = game_system;
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
515 current_system->debugger_type = dtype;
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
516 current_system->enter_debugger = start_in_debugger && menu == debug_target;
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
517 current_system->start_context(current_system, statefile);
1423
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
518 } else if (menu && game_system) {
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
519 current_system->arena = set_current_arena(game_system->arena);
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
520 current_system = game_system;
883
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
521 menu = 0;
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
522 current_system->resume_context(current_system);
1423
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
523 } else if (!menu && menu_system) {
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
524 current_system->arena = set_current_arena(menu_system->arena);
9a3e003bdcb3 Make drag and drop play nice with the menu
Michael Pavone <pavone@retrodev.com>
parents: 1412
diff changeset
525 current_system = menu_system;
883
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
526 menu = 1;
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1103
diff changeset
527 current_system->resume_context(current_system);
883
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
528 } else {
9f149f0e98b7 It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents: 875
diff changeset
529 break;
874
b6842dfb8edf ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
530 }
b6842dfb8edf ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
531 }
b6842dfb8edf ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents: 872
diff changeset
532
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
533 return 0;
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
534 }