annotate blastem.c @ 1199:45c3415508e1

Update TODO list
author Michael Pavone <pavone@retrodev.com>
date Tue, 24 Jan 2017 23:45:30 -0800
parents f99650ff8e97
children aee2177a1630
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"
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
26
1190
f99650ff8e97 Update version number for preview build
Michael Pavone <pavone@retrodev.com>
parents: 1164
diff changeset
27 #define BLASTEM_VERSION "0.5.0-pre"
464
226ed16b1fb6 Added version flag
Mike Pavone <pavone@retrodev.com>
parents: 463
diff changeset
28
860
213c3b5160d0 Default to fullscreen on Android since windowed mode does not make sense there
Michael Pavone <pavone@retrodev.com>
parents: 846
diff changeset
29 #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
30 #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
31 #else
213c3b5160d0 Default to fullscreen on Android since windowed mode does not make sense there
Michael Pavone <pavone@retrodev.com>
parents: 846
diff changeset
32 #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
33 #endif
213c3b5160d0 Default to fullscreen on Android since windowed mode does not make sense there
Michael Pavone <pavone@retrodev.com>
parents: 846
diff changeset
34
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
35 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
36 int exit_after = 0;
265
c6d12878ea93 Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 264
diff changeset
37 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
38 int frame_limit = 0;
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
39
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents: 425
diff changeset
40 tern_node * config;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents: 425
diff changeset
41
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
42 #ifndef MIN
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
43 #define MIN(a,b) ((a) < (b) ? (a) : (b))
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
44 #endif
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
45
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
46 #define SMD_HEADER_SIZE 512
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
47 #define SMD_MAGIC1 0x03
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
48 #define SMD_MAGIC2 0xAA
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
49 #define SMD_MAGIC3 0xBB
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
50 #define SMD_BLOCK_SIZE 0x4000
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
51
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
52 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
53 {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
54 uint8_t block[SMD_BLOCK_SIZE];
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
55 filesize -= SMD_HEADER_SIZE;
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
56 fseek(f, SMD_HEADER_SIZE, SEEK_SET);
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
57
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
58 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
59 int rom_size = filesize;
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
60 while (filesize > 0) {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
61 fread(block, 1, SMD_BLOCK_SIZE, f);
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
62 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
63 *(dst++) = *low << 8 | *high;
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
64 }
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
65 filesize -= SMD_BLOCK_SIZE;
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
66 }
975
c6b19939da7b Fixed loading of SMD format ROMs
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
67 return rom_size;
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
68 }
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
69
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
70 uint32_t load_rom(char * filename, void **dst, system_type *stype)
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
71 {
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
72 uint8_t header[10];
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
73 FILE * f = fopen(filename, "rb");
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
74 if (!f) {
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
75 return 0;
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
76 }
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 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
78 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
79 }
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
80 fseek(f, 0, SEEK_END);
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
81 long filesize = ftell(f);
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
82 fseek(f, 0, SEEK_SET);
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
83 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
84 int i;
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
85 for (i = 3; i < 8; i++) {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
86 if (header[i] != 0) {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
87 break;
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 }
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
90 if (i == 8) {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
91 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
92 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
93 }
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
94 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
95 *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
96 }
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
97 return load_smd_rom(filesize, f, dst);
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
98 }
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
99 }
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
100 *dst = malloc(nearest_pow2(filesize));
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
101 if (filesize != fread(*dst, 1, filesize, 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
102 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
103 }
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
104 fclose(f);
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
105 return filesize;
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
106 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
107
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
108
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
109
198
209a37eed3e7 Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents: 197
diff changeset
110 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
111 char *save_state_path;
260
625f8e4d5fd2 Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 215
diff changeset
112
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
113
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
114
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
115
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
116
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
117 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
118 system_header *current_system;
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
119 system_header *menu_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
120 system_header *game_context;
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
121 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
122 {
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
123 if (!game_context) {
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
124 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
125 }
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
126 game_context->persist_save(game_context);
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
127 }
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
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
129 char *title;
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
130 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
131 {
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
132 if (title) {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
133 free(title);
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
134 title = NULL;
340
58a085cfc6bd Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents: 338
diff changeset
135 }
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
136 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
137 render_update_caption(title);
340
58a085cfc6bd Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents: 338
diff changeset
138 }
58a085cfc6bd Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents: 338
diff changeset
139
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
140 void setup_saves(char *fname, rom_info *info, system_header *context)
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
141 {
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
142 static uint8_t persist_save_registered;
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
143 char * barename = basename_no_extension(fname);
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
144 char const * parts[3] = {get_save_dir(), PATH_SEP, barename};
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
145 char *save_dir = alloc_concat_m(3, parts);
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
146 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
147 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
148 }
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
149 parts[0] = 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
150 parts[2] = info->save_type == SAVE_I2C ? "save.eeprom" : "save.sram";
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
151 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
152 save_filename = alloc_concat_m(3, parts);
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
153 //TODO: make quick save filename dependent on system type
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
154 parts[2] = "quicksave.gst";
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
155 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
156 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
157 context->save_dir = save_dir;
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 free(barename);
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
159 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
160 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
161 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
162 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
163 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
164 }
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
165 }
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
166 }
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
167
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
168 int main(int argc, char ** argv)
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
169 {
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
170 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
171 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
172 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
173 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
174 int debug = 0;
1113
45db303fc705 Restore 68K address logging functionality
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
175 uint32_t opts = 0;
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
176 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
177 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
178 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
179 char * romfname = NULL;
425
8b3ae850d1c4 Forgot to null initialize the statfile pointer
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
180 char * statefile = NULL;
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
181 system_media cart = {.chain = NULL}, lock_on;
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
182 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
183 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
184 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
185 uint8_t debug_target = 0;
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
186 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
187 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
188 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
189 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
190 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
191 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
192 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
193 }
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
194 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
195 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
196 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
197 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
198 start_in_debugger = 1;
885
e3f5ec336432 Allow menu ROM to be debugged
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
199 //allow debugging the menu
e3f5ec336432 Allow menu ROM to be debugged
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
200 if (argv[i][2] == 'm') {
e3f5ec336432 Allow menu ROM to be debugged
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
201 debug_target = 1;
e3f5ec336432 Allow menu ROM to be debugged
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
202 }
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
203 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
204 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
205 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
206 dtype = DEBUGGER_GDB;
1164
21df13266e6a Restore functionality of the -D flag for GDB remote debugging
Michael Pavone <pavone@retrodev.com>
parents: 1140
diff changeset
207 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
208 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
209 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
210 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
211 break;
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
212 case 'g':
501
e1355aa80f4d Use OpenGL by default. Add OpenGL switch to help text
Mike Pavone <pavone@retrodev.com>
parents: 496
diff changeset
213 use_gl = 0;
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
214 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
215 case 'l':
1113
45db303fc705 Restore 68K address logging functionality
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
216 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
217 break;
464
226ed16b1fb6 Added version flag
Mike Pavone <pavone@retrodev.com>
parents: 463
diff changeset
218 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
219 info_message("blastem %s\n", BLASTEM_VERSION);
464
226ed16b1fb6 Added version flag
Mike Pavone <pavone@retrodev.com>
parents: 463
diff changeset
220 return 0;
226ed16b1fb6 Added version flag
Mike Pavone <pavone@retrodev.com>
parents: 463
diff changeset
221 break;
265
c6d12878ea93 Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 264
diff changeset
222 case 'n':
c6d12878ea93 Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 264
diff changeset
223 z80_enabled = 0;
c6d12878ea93 Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 264
diff changeset
224 break;
341
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
225 case 'r':
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
226 i++;
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
227 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
228 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
229 }
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
230 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
231 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
232 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
233 }
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
234 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
235 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
236 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
237 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
238 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
239 }
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
240 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
241 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
242 } 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
243 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
244 } 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
245 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
246 } 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
247 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
248 }
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
249 break;
424
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
250 case 's':
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
251 i++;
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
252 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
253 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
254 }
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
255 statefile = argv[i];
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
256 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
257 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
258 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
259 break;
407
c3abc4ada43d Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents: 405
diff changeset
260 case 'y':
1113
45db303fc705 Restore 68K address logging functionality
Michael Pavone <pavone@retrodev.com>
parents: 1111
diff changeset
261 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
262 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
263 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
264 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
265 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
266 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
267 }
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
268 lock_on.size = load_rom(argv[i], &lock_on.buffer, NULL);
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
269 if (!lock_on.size) {
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
270 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
271 }
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
272 lock_on.extension = path_extension(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
273 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
274 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
275 }
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
276 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
277 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
278 "Usage: blastem [OPTIONS] ROMFILE [WIDTH] [HEIGHT]\n"
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
279 "Options:\n"
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
280 " -h Print this help text\n"
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
281 " -r (J|U|E) Force region to Japan, US or Europe respectively\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
282 " -m MACHINE Force emulated machine type to MACHINE. Valid values are:\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
283 " 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
284 " 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
285 " 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
286 " -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
287 " -g Disable OpenGL rendering\n"
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
288 " -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
289 " -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
290 " -d Enter debugger on startup\n"
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
291 " -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
292 " -v Display version number and exit\n"
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
293 " -l Log 68K code addresses (useful for assemblers)\n"
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
294 " -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
295 );
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
296 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
297 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
298 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
299 }
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
300 } else if (!loaded) {
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
301 if (!(cart.size = load_rom(argv[i], &cart.buffer, 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
302 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
303 }
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
304 cart.extension = path_extension(argv[i]);
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
305 romfname = argv[i];
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
306 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
307 } 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
308 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
309 } 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
310 height = atoi(argv[i]);
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
311 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
312 }
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
313 uint8_t menu = !loaded;
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
314 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
315 //load menu
948
f87522554d7b Allow changing the 68K clock divider in the config file
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
316 romfname = tern_find_path(config, "ui\0rom\0").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
317 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
318 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
319 }
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
320 if (is_absolute_path(romfname)) {
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
321 if (!(cart.size = load_rom(romfname, &cart.buffer, &stype))) {
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
322 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
323 }
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
324 } 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
325 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
326 if (!cart.buffer) {
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
327 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
328 }
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
329 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
330 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
331 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
332 cart.size = rom_size;
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
333 }
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
334 }
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
335 //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
336 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
337 cart.extension = path_extension(romfname);
872
7022ba865cfd Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents: 861
diff changeset
338
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
339 loaded = 1;
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
340 }
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
341
433
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
342 int def_width = 0;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
343 char *config_width = tern_find_path(config, "video\0width\0").ptrval;
433
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
344 if (config_width) {
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
345 def_width = atoi(config_width);
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
346 }
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
347 if (!def_width) {
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
348 def_width = 640;
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
349 }
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
350 width = width < 320 ? def_width : width;
184
ebcbdd1c4cc8 Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents: 166
diff changeset
351 height = height < 240 ? (width/320) * 240 : 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
352
1017
216fa63749b3 Added documentation for lock-on support and a fullscreen config option.
Michael Pavone <pavone@retrodev.com>
parents: 1016
diff changeset
353 char *config_fullscreen = tern_find_path(config, "video\0fullscreen\0").ptrval;
216fa63749b3 Added documentation for lock-on support and a fullscreen config option.
Michael Pavone <pavone@retrodev.com>
parents: 1016
diff changeset
354 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
355 fullscreen = !fullscreen;
216fa63749b3 Added documentation for lock-on support and a fullscreen config option.
Michael Pavone <pavone@retrodev.com>
parents: 1016
diff changeset
356 }
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 351
diff changeset
357 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
358 render_init(width, height, "BlastEm", fullscreen);
342
13f994c88c34 Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents: 341
diff changeset
359 }
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
360
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
361 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
362 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
363 }
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
364 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
365 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
366 }
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
367 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
368 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
369 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
370 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
371 }
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
372 setup_saves(romfname, &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
373 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
374 if (menu) {
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
375 menu_context = 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
376 } else {
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
377 game_context = 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
378 }
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
379
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
380 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
381 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
382 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
383 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
384 {
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
385 if (current_system->should_exit) {
949
5e4fb650de58 Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
386 break;
5e4fb650de58 Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
387 }
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
388 if (menu && menu_context->next_rom) {
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
389 if (game_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
390 game_context->persist_save(game_context);
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
391 //swap to game context arena and mark all allocated pages in it free
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
392 current_system->arena = set_current_arena(game_context->arena);
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
393 mark_all_free();
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
394 game_context->free_context(game_context);
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
395 } 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
396 //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
397 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
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 if (!(cart.size = load_rom(menu_context->next_rom, &cart.buffer, &stype))) {
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
400 fatal_error("Failed to open %s for reading\n", menu_context->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
401 }
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
402 cart.extension = path_extension(menu_context->next_rom);
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
403 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
404 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
405 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
406 }
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
407 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
408 fatal_error("Failed to detect system type for %s\n", menu_context->next_rom);
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 }
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
410 //allocate new genesis context
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
411 game_context = alloc_config_system(stype, &cart, 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
412 if (!game_context) {
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
413 fatal_error("Failed to configure emulated machine for %s\n", menu_context->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
414 }
957
1618d3676a35 Save state menu WIP
Michael Pavone <pavone@retrodev.com>
parents: 956
diff changeset
415 menu_context->next_context = game_context;
1618d3676a35 Save state menu WIP
Michael Pavone <pavone@retrodev.com>
parents: 956
diff changeset
416 game_context->next_context = menu_context;
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
417 setup_saves(menu_context->next_rom, &info, game_context);
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
418 update_title(info.name);
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
419 free(menu_context->next_rom);
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
420 menu_context->next_rom = NULL;
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
421 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
422 current_system = game_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
423 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
424 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
425 current_system->start_context(current_system, statefile);
949
5e4fb650de58 Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
426 } else if (menu && game_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
427 current_system->arena = set_current_arena(game_context->arena);
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
428 current_system = game_context;
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
429 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
430 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
431 } else if (!menu && menu_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
432 current_system->arena = set_current_arena(menu_context->arena);
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
433 current_system = menu_context;
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
434 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
435 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
436 } 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
437 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
438 }
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 }
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
440
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
441 return 0;
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
442 }