annotate blastem.c @ 978:34b811ea1e7c

Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
author Michael Pavone <pavone@retrodev.com>
date Sat, 23 Apr 2016 18:14:01 -0700
parents c6b19939da7b
children 902c53d9c16f
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 /*
140af5509ce7 Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents: 464
diff changeset
2 Copyright 2013 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
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
11 #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
12 #include "m68k_core.h"
260
625f8e4d5fd2 Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 215
diff changeset
13 #include "z80_to_x86.h"
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
14 #include "mem.h"
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
15 #include "vdp.h"
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
16 #include "render.h"
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
17 #include "blastem.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
18 #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
19 #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
20 #include "util.h"
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
21 #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
22 #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
23 #include "arena.h"
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
24
815
1f3ddeaacaee Change version to 0.3.X so intermediate source builds do not get an inappropriate version number
Michael Pavone <pavone@retrodev.com>
parents: 808
diff changeset
25 #define BLASTEM_VERSION "0.3.X"
464
226ed16b1fb6 Added version flag
Mike Pavone <pavone@retrodev.com>
parents: 463
diff changeset
26
380
1c8d74f2ab0b Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents: 374
diff changeset
27 #define MCLKS_NTSC 53693175
1c8d74f2ab0b Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents: 374
diff changeset
28 #define MCLKS_PAL 53203395
1c8d74f2ab0b Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents: 374
diff changeset
29
948
f87522554d7b Allow changing the 68K clock divider in the config file
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
30 uint32_t MCLKS_PER_68K;
f87522554d7b Allow changing the 68K clock divider in the config file
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
31 #define MCLKS_PER_YM 7
260
625f8e4d5fd2 Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 215
diff changeset
32 #define MCLKS_PER_Z80 15
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 351
diff changeset
33 #define MCLKS_PER_PSG (MCLKS_PER_Z80*16)
785
0e5f14d9a579 Prep for 0.3.0 release
Michael Pavone <pavone@retrodev.com>
parents: 778
diff changeset
34 #define DEFAULT_SYNC_INTERVAL MCLKS_LINE
380
1c8d74f2ab0b Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents: 374
diff changeset
35
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
36 //TODO: Figure out the exact value for this
342
13f994c88c34 Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents: 341
diff changeset
37 #define LINES_NTSC 262
13f994c88c34 Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents: 341
diff changeset
38 #define LINES_PAL 312
13f994c88c34 Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents: 341
diff changeset
39
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
40 #define MAX_SOUND_CYCLES 100000
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
41
860
213c3b5160d0 Default to fullscreen on Android since windowed mode does not make sense there
Michael Pavone <pavone@retrodev.com>
parents: 846
diff changeset
42 #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
43 #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
44 #else
213c3b5160d0 Default to fullscreen on Android since windowed mode does not make sense there
Michael Pavone <pavone@retrodev.com>
parents: 846
diff changeset
45 #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
46 #endif
213c3b5160d0 Default to fullscreen on Android since windowed mode does not make sense there
Michael Pavone <pavone@retrodev.com>
parents: 846
diff changeset
47
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
48 uint16_t *cart;
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
49 uint16_t *ram;
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
50 uint8_t z80_ram[Z80_RAM_BYTES];
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
51
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
52 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
53 int exit_after = 0;
265
c6d12878ea93 Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 264
diff changeset
54 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
55 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
56
430
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents: 425
diff changeset
57 tern_node * config;
7f84090ab1cd Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents: 425
diff changeset
58
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
59 #ifndef MIN
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
60 #define MIN(a,b) ((a) < (b) ? (a) : (b))
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
61 #endif
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
62
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
63 #define SMD_HEADER_SIZE 512
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
64 #define SMD_MAGIC1 0x03
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
65 #define SMD_MAGIC2 0xAA
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
66 #define SMD_MAGIC3 0xBB
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
67 #define SMD_BLOCK_SIZE 0x4000
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 int load_smd_rom(long filesize, FILE * f)
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
70 {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
71 uint8_t block[SMD_BLOCK_SIZE];
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
72 filesize -= SMD_HEADER_SIZE;
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
73 fseek(f, SMD_HEADER_SIZE, SEEK_SET);
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
74
975
c6b19939da7b Fixed loading of SMD format ROMs
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
75 uint16_t * dst = cart = 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
76 int rom_size = filesize;
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
77 while (filesize > 0) {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
78 fread(block, 1, SMD_BLOCK_SIZE, f);
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
79 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
80 *(dst++) = *low << 8 | *high;
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
81 }
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
82 filesize -= SMD_BLOCK_SIZE;
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
83 }
975
c6b19939da7b Fixed loading of SMD format ROMs
Michael Pavone <pavone@retrodev.com>
parents: 971
diff changeset
84 return rom_size;
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
85 }
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
86
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
87 void byteswap_rom(int filesize)
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
88 {
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
89 for(unsigned short * cur = cart; cur - cart < filesize/2; ++cur)
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
90 {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
91 *cur = (*cur >> 8) | (*cur << 8);
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
92 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
93 }
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
94
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
95 int load_rom(char * filename)
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
96 {
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
97 uint8_t header[10];
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
98 FILE * f = fopen(filename, "rb");
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
99 if (!f) {
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
100 return 0;
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
101 }
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
102 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
103 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
104 }
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
105 fseek(f, 0, SEEK_END);
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
106 long filesize = ftell(f);
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
107 fseek(f, 0, SEEK_SET);
166
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
108 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
109 int i;
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
110 for (i = 3; i < 8; i++) {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
111 if (header[i] != 0) {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
112 break;
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
113 }
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
114 }
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
115 if (i == 8) {
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
116 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
117 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
118 }
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
119 return load_smd_rom(filesize, f);
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
120 }
97aa449706c2 Added SMD ROM support
Mike Pavone <pavone@retrodev.com>
parents: 158
diff changeset
121 }
777
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
122 cart = malloc(nearest_pow2(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
123 if (filesize != fread(cart, 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
124 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
125 }
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
126 fclose(f);
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
127 return filesize;
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
128 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
129
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
130 uint16_t read_dma_value(uint32_t address)
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
131 {
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
132 //addresses here are word addresses (i.e. bit 0 corresponds to A1), so no need to do div by 2
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
133 if (address < 0x200000) {
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
134 return cart[address];
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
135 } else if(address >= 0x700000) {
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
136 return ram[address & 0x7FFF];
918
2e465934bddc Allow DMA from cartridge ROM above the 4MB mark. Should probably use get_native_pointer for everyting, but want to check the performance implications
Michael Pavone <pavone@retrodev.com>
parents: 913
diff changeset
137 } else {
2e465934bddc Allow DMA from cartridge ROM above the 4MB mark. Should probably use get_native_pointer for everyting, but want to check the performance implications
Michael Pavone <pavone@retrodev.com>
parents: 913
diff changeset
138 uint16_t *ptr = get_native_pointer(address*2, (void **)genesis->m68k->mem_pointers, &genesis->m68k->options->gen);
2e465934bddc Allow DMA from cartridge ROM above the 4MB mark. Should probably use get_native_pointer for everyting, but want to check the performance implications
Michael Pavone <pavone@retrodev.com>
parents: 913
diff changeset
139 if (ptr) {
2e465934bddc Allow DMA from cartridge ROM above the 4MB mark. Should probably use get_native_pointer for everyting, but want to check the performance implications
Michael Pavone <pavone@retrodev.com>
parents: 913
diff changeset
140 return *ptr;
2e465934bddc Allow DMA from cartridge ROM above the 4MB mark. Should probably use get_native_pointer for everyting, but want to check the performance implications
Michael Pavone <pavone@retrodev.com>
parents: 913
diff changeset
141 }
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
142 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
143 //TODO: Figure out what happens when you try to DMA from weird adresses like IO or banked Z80 area
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
144 return 0;
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
145 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
146
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
147 void adjust_int_cycle(m68k_context * context, vdp_context * v_context)
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
148 {
717
22dbdf50d33c Small correction to VBLANK flag timing. Fixed some inconsistencies in interrupt timing calculation.
Michael Pavone <pavone@retrodev.com>
parents: 700
diff changeset
149 //static int old_int_cycle = CYCLE_NEVER;
696
0b2242bbc84a Added config option to allow specifying a max sync cycle smaller than the end of frame
Michael Pavone <pavone@retrodev.com>
parents: 695
diff changeset
150 genesis_context *gen = context->system;
0b2242bbc84a Added config option to allow specifying a max sync cycle smaller than the end of frame
Michael Pavone <pavone@retrodev.com>
parents: 695
diff changeset
151 if (context->sync_cycle - context->current_cycle > gen->max_cycles) {
0b2242bbc84a Added config option to allow specifying a max sync cycle smaller than the end of frame
Michael Pavone <pavone@retrodev.com>
parents: 695
diff changeset
152 context->sync_cycle = context->current_cycle + gen->max_cycles;
0b2242bbc84a Added config option to allow specifying a max sync cycle smaller than the end of frame
Michael Pavone <pavone@retrodev.com>
parents: 695
diff changeset
153 }
317
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
154 context->int_cycle = CYCLE_NEVER;
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
155 if ((context->status & 0x7) < 6) {
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
156 uint32_t next_vint = vdp_next_vint(v_context);
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
157 if (next_vint != CYCLE_NEVER) {
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
158 context->int_cycle = next_vint;
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
159 context->int_num = 6;
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
160 }
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
161 if ((context->status & 0x7) < 4) {
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
162 uint32_t next_hint = vdp_next_hint(v_context);
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
163 if (next_hint != CYCLE_NEVER) {
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
164 if (next_hint < context->int_cycle) {
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
165 context->int_cycle = next_hint;
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
166 context->int_num = 4;
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
167
317
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
168 }
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
169 }
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
170 }
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
171 }
846
98d7b6073163 Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents: 844
diff changeset
172 if (context->int_cycle > context->current_cycle) {
98d7b6073163 Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents: 844
diff changeset
173 context->int_pending = 0;
98d7b6073163 Implement interrupt latency. Fixes Sesame Street: Counting Cafe and gives accurate results in my test ROM
Michael Pavone <pavone@retrodev.com>
parents: 844
diff changeset
174 }
717
22dbdf50d33c Small correction to VBLANK flag timing. Fixed some inconsistencies in interrupt timing calculation.
Michael Pavone <pavone@retrodev.com>
parents: 700
diff changeset
175 /*if (context->int_cycle != old_int_cycle) {
22dbdf50d33c Small correction to VBLANK flag timing. Fixed some inconsistencies in interrupt timing calculation.
Michael Pavone <pavone@retrodev.com>
parents: 700
diff changeset
176 printf("int cycle changed to: %d, level: %d @ %d(%d), frame: %d, vcounter: %d, hslot: %d, mask: %d, hint_counter: %d\n", context->int_cycle, context->int_num, v_context->cycles, context->current_cycle, v_context->frame, v_context->vcounter, v_context->hslot, context->status & 0x7, v_context->hint_counter);
22dbdf50d33c Small correction to VBLANK flag timing. Fixed some inconsistencies in interrupt timing calculation.
Michael Pavone <pavone@retrodev.com>
parents: 700
diff changeset
177 old_int_cycle = context->int_cycle;
22dbdf50d33c Small correction to VBLANK flag timing. Fixed some inconsistencies in interrupt timing calculation.
Michael Pavone <pavone@retrodev.com>
parents: 700
diff changeset
178 }*/
317
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
179
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
180 context->target_cycle = context->int_cycle < context->sync_cycle ? context->int_cycle : context->sync_cycle;
872
7022ba865cfd Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents: 861
diff changeset
181 if (context->should_return) {
7022ba865cfd Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents: 861
diff changeset
182 context->target_cycle = context->current_cycle;
891
90d54ccf9557 Fix a bad interaction between the implementation of STOP and the way interrupt cycles are calculated. Prevent addition of refresh delays while VDP has the bus.
Michael Pavone <pavone@retrodev.com>
parents: 889
diff changeset
183 } else if (context->target_cycle < context->current_cycle) {
90d54ccf9557 Fix a bad interaction between the implementation of STOP and the way interrupt cycles are calculated. Prevent addition of refresh delays while VDP has the bus.
Michael Pavone <pavone@retrodev.com>
parents: 889
diff changeset
184 //Changes to SR can result in an interrupt cycle that's in the past
90d54ccf9557 Fix a bad interaction between the implementation of STOP and the way interrupt cycles are calculated. Prevent addition of refresh delays while VDP has the bus.
Michael Pavone <pavone@retrodev.com>
parents: 889
diff changeset
185 //This can cause issues with the implementation of STOP though
90d54ccf9557 Fix a bad interaction between the implementation of STOP and the way interrupt cycles are calculated. Prevent addition of refresh delays while VDP has the bus.
Michael Pavone <pavone@retrodev.com>
parents: 889
diff changeset
186 context->target_cycle = context->current_cycle;
872
7022ba865cfd Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents: 861
diff changeset
187 }
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
188 /*printf("Cyc: %d, Trgt: %d, Int Cyc: %d, Int: %d, Mask: %X, V: %d, H: %d, HICount: %d, HReg: %d, Line: %d\n",
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
189 context->current_cycle, context->target_cycle, context->int_cycle, context->int_num, (context->status & 0x7),
317
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
190 v_context->regs[REG_MODE_2] & 0x20, v_context->regs[REG_MODE_1] & 0x10, v_context->hint_counter, v_context->regs[REG_HINT], v_context->cycles / MCLKS_LINE);*/
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
191 }
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
192
198
209a37eed3e7 Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents: 197
diff changeset
193 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
194 char *save_state_path;
260
625f8e4d5fd2 Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 215
diff changeset
195
280
9ee64039ddeb Fix bank register update
Mike Pavone <pavone@retrodev.com>
parents: 279
diff changeset
196 //#define DO_DEBUG_PRINT
268
6c2d7e003a55 Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents: 266
diff changeset
197 #ifdef DO_DEBUG_PRINT
6c2d7e003a55 Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents: 266
diff changeset
198 #define dprintf printf
271
969ee17471c5 Protect debug prints for busreq/reset regs with appropriate macros
Mike Pavone <pavone@retrodev.com>
parents: 268
diff changeset
199 #define dputs puts
268
6c2d7e003a55 Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents: 266
diff changeset
200 #else
6c2d7e003a55 Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents: 266
diff changeset
201 #define dprintf
271
969ee17471c5 Protect debug prints for busreq/reset regs with appropriate macros
Mike Pavone <pavone@retrodev.com>
parents: 268
diff changeset
202 #define dputs
268
6c2d7e003a55 Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents: 266
diff changeset
203 #endif
6c2d7e003a55 Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents: 266
diff changeset
204
402
de2c085ce174 Assert z80 interrupt longer so that they are not missed when they should not be
Mike Pavone <pavone@retrodev.com>
parents: 398
diff changeset
205 #define Z80_VINT_DURATION 128
de2c085ce174 Assert z80 interrupt longer so that they are not missed when they should not be
Mike Pavone <pavone@retrodev.com>
parents: 398
diff changeset
206
668
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
207 void z80_next_int_pulse(z80_context * z_context)
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
208 {
682
Michael Pavone <pavone@retrodev.com>
parents: 680 559
diff changeset
209 genesis_context * gen = z_context->system;
668
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
210 z_context->int_pulse_start = vdp_next_vint_z80(gen->vdp);
670
f4f3e74b0ce6 Restore Z80 interrupt pulse duration and make a small improvement to debug print output
Michael Pavone <pavone@retrodev.com>
parents: 669
diff changeset
211 z_context->int_pulse_end = z_context->int_pulse_start + Z80_VINT_DURATION * MCLKS_PER_Z80;
682
Michael Pavone <pavone@retrodev.com>
parents: 680 559
diff changeset
212 }
668
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
213
268
6c2d7e003a55 Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents: 266
diff changeset
214 void sync_z80(z80_context * z_context, uint32_t mclks)
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
215 {
565
9324f721efa6 Add a separate flag/define for disabling the Z80 at compile time to ease refactoring
Michael Pavone <pavone@retrodev.com>
parents: 558
diff changeset
216 #ifndef NO_Z80
668
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
217 if (z80_enabled) {
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
218 z80_run(z_context, mclks);
548
a3afee2271ce Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents: 534
diff changeset
219 } else
a3afee2271ce Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents: 534
diff changeset
220 #endif
a3afee2271ce Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents: 534
diff changeset
221 {
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
222 z_context->current_cycle = mclks;
260
625f8e4d5fd2 Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 215
diff changeset
223 }
268
6c2d7e003a55 Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents: 266
diff changeset
224 }
380
1c8d74f2ab0b Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents: 374
diff changeset
225
1c8d74f2ab0b Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents: 374
diff changeset
226 void sync_sound(genesis_context * gen, uint32_t target)
1c8d74f2ab0b Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents: 374
diff changeset
227 {
1c8d74f2ab0b Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents: 374
diff changeset
228 //printf("YM | Cycle: %d, bpos: %d, PSG | Cycle: %d, bpos: %d\n", gen->ym->current_cycle, gen->ym->buffer_pos, gen->psg->cycles, gen->psg->buffer_pos * 2);
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
229 while (target > gen->psg->cycles && target - gen->psg->cycles > MAX_SOUND_CYCLES) {
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
230 uint32_t cur_target = gen->psg->cycles + MAX_SOUND_CYCLES;
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
231 //printf("Running PSG to cycle %d\n", cur_target);
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
232 psg_run(gen->psg, cur_target);
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
233 //printf("Running YM-2612 to cycle %d\n", cur_target);
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
234 ym_run(gen->ym, cur_target);
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
235 }
380
1c8d74f2ab0b Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents: 374
diff changeset
236 psg_run(gen->psg, target);
1c8d74f2ab0b Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents: 374
diff changeset
237 ym_run(gen->ym, target);
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
238
380
1c8d74f2ab0b Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents: 374
diff changeset
239 //printf("Target: %d, YM bufferpos: %d, PSG bufferpos: %d\n", target, gen->ym->buffer_pos, gen->psg->buffer_pos * 2);
1c8d74f2ab0b Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents: 374
diff changeset
240 }
1c8d74f2ab0b Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents: 374
diff changeset
241
978
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
242 uint32_t last_frame_num;
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
243
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
244 //My refresh emulation isn't currently good enough and causes more problems than it solves
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
245 #ifdef REFRESH_EMULATION
928
8bd82aead087 Minor adjustment to refresh interval to better match latest measurements
Michael Pavone <pavone@retrodev.com>
parents: 918
diff changeset
246 #define REFRESH_INTERVAL 128
889
2d1122123fe9 Approximation of refresh wait states
Michael Pavone <pavone@retrodev.com>
parents: 885
diff changeset
247 #define REFRESH_DELAY 2
2d1122123fe9 Approximation of refresh wait states
Michael Pavone <pavone@retrodev.com>
parents: 885
diff changeset
248 uint32_t last_sync_cycle;
2d1122123fe9 Approximation of refresh wait states
Michael Pavone <pavone@retrodev.com>
parents: 885
diff changeset
249 uint32_t refresh_counter;
978
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
250 #endif
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
251
268
6c2d7e003a55 Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents: 266
diff changeset
252 m68k_context * sync_components(m68k_context * context, uint32_t address)
6c2d7e003a55 Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents: 266
diff changeset
253 {
288
a8ee7934a1f8 Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents: 280
diff changeset
254 genesis_context * gen = context->system;
a8ee7934a1f8 Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents: 280
diff changeset
255 vdp_context * v_context = gen->vdp;
a8ee7934a1f8 Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents: 280
diff changeset
256 z80_context * z_context = gen->z80;
978
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
257 #ifdef REFRESH_EMULATION
889
2d1122123fe9 Approximation of refresh wait states
Michael Pavone <pavone@retrodev.com>
parents: 885
diff changeset
258 //lame estimation of refresh cycle delay
891
90d54ccf9557 Fix a bad interaction between the implementation of STOP and the way interrupt cycles are calculated. Prevent addition of refresh delays while VDP has the bus.
Michael Pavone <pavone@retrodev.com>
parents: 889
diff changeset
259 if (!gen->bus_busy) {
90d54ccf9557 Fix a bad interaction between the implementation of STOP and the way interrupt cycles are calculated. Prevent addition of refresh delays while VDP has the bus.
Michael Pavone <pavone@retrodev.com>
parents: 889
diff changeset
260 refresh_counter += context->current_cycle - last_sync_cycle;
90d54ccf9557 Fix a bad interaction between the implementation of STOP and the way interrupt cycles are calculated. Prevent addition of refresh delays while VDP has the bus.
Michael Pavone <pavone@retrodev.com>
parents: 889
diff changeset
261 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL));
90d54ccf9557 Fix a bad interaction between the implementation of STOP and the way interrupt cycles are calculated. Prevent addition of refresh delays while VDP has the bus.
Michael Pavone <pavone@retrodev.com>
parents: 889
diff changeset
262 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL);
90d54ccf9557 Fix a bad interaction between the implementation of STOP and the way interrupt cycles are calculated. Prevent addition of refresh delays while VDP has the bus.
Michael Pavone <pavone@retrodev.com>
parents: 889
diff changeset
263 }
978
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
264 #endif
889
2d1122123fe9 Approximation of refresh wait states
Michael Pavone <pavone@retrodev.com>
parents: 885
diff changeset
265
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
266 uint32_t mclks = context->current_cycle;
268
6c2d7e003a55 Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents: 266
diff changeset
267 sync_z80(z_context, mclks);
695
e1345921e481 Indentation fixup
Michael Pavone <pavone@retrodev.com>
parents: 693
diff changeset
268 sync_sound(gen, mclks);
697
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
269 vdp_run_context(v_context, mclks);
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
270 if (v_context->frame != last_frame_num) {
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
271 //printf("reached frame end %d | MCLK Cycles: %d, Target: %d, VDP cycles: %d, vcounter: %d, hslot: %d\n", last_frame_num, mclks, gen->frame_end, v_context->cycles, v_context->vcounter, v_context->hslot);
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
272 last_frame_num = v_context->frame;
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
273
697
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
274 if (!headless) {
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
275 break_on_sync |= wait_render_frame(v_context, frame_limit);
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
276 } else if(exit_after){
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
277 --exit_after;
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
278 if (!exit_after) {
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
279 exit(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
280 }
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
281 }
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
282
697
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
283 vdp_adjust_cycles(v_context, mclks);
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
284 io_adjust_cycles(gen->ports, context->current_cycle, mclks);
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
285 io_adjust_cycles(gen->ports+1, context->current_cycle, mclks);
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
286 io_adjust_cycles(gen->ports+2, context->current_cycle, mclks);
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
287 context->current_cycle -= mclks;
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
288 z80_adjust_cycles(z_context, mclks);
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
289 gen->ym->current_cycle -= mclks;
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
290 gen->psg->cycles -= mclks;
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
291 if (gen->ym->write_cycle != CYCLE_NEVER) {
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
292 gen->ym->write_cycle = gen->ym->write_cycle >= mclks ? gen->ym->write_cycle - mclks : 0;
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
293 }
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
294 }
700
72ab94527a8a Tiny cleanup
Michael Pavone <pavone@retrodev.com>
parents: 697
diff changeset
295 gen->frame_end = vdp_cycles_to_frame_end(v_context);
697
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
296 context->sync_cycle = gen->frame_end;
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
297 //printf("Set sync cycle to: %d @ %d, vcounter: %d, hslot: %d\n", context->sync_cycle, context->current_cycle, v_context->vcounter, v_context->hslot);
317
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
298 if (context->int_ack) {
718
eaba6789f316 Update vscroll latch implementation to be more in line with what Eke-Eke has observed. Revert the change to vdp_cycles_to_line because it breaks hints on line 0. H-Int timing is still a little messed up, but the previous change made things worse.
Michael Pavone <pavone@retrodev.com>
parents: 717
diff changeset
299 //printf("acknowledging %d @ %d:%d, vcounter: %d, hslot: %d\n", context->int_ack, context->current_cycle, v_context->cycles, v_context->vcounter, v_context->hslot);
953
08346262990b Remove the int number argument to vdp_int_ack since it is no longer used
Michael Pavone <pavone@retrodev.com>
parents: 951
diff changeset
300 vdp_int_ack(v_context);
317
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
301 context->int_ack = 0;
e5e8b48ad157 Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents: 290
diff changeset
302 }
961
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
303 if (!address && (break_on_sync || gen->save_state)) {
721
20be7d01e312 Better handling of savestate and debug break events with "uncooperative" games/demos
Michael Pavone <pavone@retrodev.com>
parents: 719
diff changeset
304 context->sync_cycle = context->current_cycle + 1;
20be7d01e312 Better handling of savestate and debug break events with "uncooperative" games/demos
Michael Pavone <pavone@retrodev.com>
parents: 719
diff changeset
305 }
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
306 adjust_int_cycle(context, v_context);
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 447
diff changeset
307 if (address) {
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 447
diff changeset
308 if (break_on_sync) {
695
e1345921e481 Indentation fixup
Michael Pavone <pavone@retrodev.com>
parents: 693
diff changeset
309 break_on_sync = 0;
e1345921e481 Indentation fixup
Michael Pavone <pavone@retrodev.com>
parents: 693
diff changeset
310 debugger(context, address);
e1345921e481 Indentation fixup
Michael Pavone <pavone@retrodev.com>
parents: 693
diff changeset
311 }
961
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
312 if (gen->save_state && (z_context->pc || (!z_context->reset && !z_context->busreq))) {
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
313 uint8_t slot = gen->save_state - 1;
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
314 gen->save_state = 0;
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
315 //advance Z80 core to the start of an instruction
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 447
diff changeset
316 while (!z_context->pc)
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 447
diff changeset
317 {
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
318 sync_z80(z_context, z_context->current_cycle + MCLKS_PER_Z80);
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 447
diff changeset
319 }
961
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
320 char *save_path;
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
321 if (slot == QUICK_SAVE_SLOT) {
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
322 save_path = save_state_path;
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
323 } else {
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
324 char slotname[] = "slot_0.gst";
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
325 slotname[5] = '0' + slot;
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
326 char const *parts[] = {gen->save_dir, "/", slotname};
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
327 save_path = alloc_concat_m(3, parts);
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
328 }
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
329 save_gst(gen, save_path, address);
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
330 printf("Saved state to %s\n", save_path);
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
331 if (slot != QUICK_SAVE_SLOT) {
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
332 free(save_path);
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
333 }
750995b587a0 Save State menu option is now fully functional. Load state sort of works, but is mostly broken.
Michael Pavone <pavone@retrodev.com>
parents: 957
diff changeset
334 } else if(gen->save_state) {
736
535e97bad27f Implement cycles being stolen from 68K when the Z80 accesses the bank area or VDP/PSG. Small fix to code that tries to get system into a consistent state for a savestate
Michael Pavone <pavone@retrodev.com>
parents: 721
diff changeset
335 context->sync_cycle = context->current_cycle + 1;
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 447
diff changeset
336 }
198
209a37eed3e7 Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents: 197
diff changeset
337 }
978
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
338 #ifdef REFRESH_EMULATION
889
2d1122123fe9 Approximation of refresh wait states
Michael Pavone <pavone@retrodev.com>
parents: 885
diff changeset
339 last_sync_cycle = context->current_cycle;
978
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
340 #endif
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
341 return context;
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
342 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
343
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
344 m68k_context * vdp_port_write(uint32_t vdp_port, m68k_context * context, uint16_t value)
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
345 {
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
346 if (vdp_port & 0x2700E0) {
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
347 fatal_error("machine freeze due to write to address %X\n", 0xC00000 | vdp_port);
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
348 }
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
349 vdp_port &= 0x1F;
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
350 //printf("vdp_port write: %X, value: %X, cycle: %d\n", vdp_port, value, context->current_cycle);
198
209a37eed3e7 Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents: 197
diff changeset
351 sync_components(context, 0);
508
b976c6d6e5fb Initial attempt at emulating extended bank area access delays when 68K bus is busy with VDP stuff. Also emulate the extra delay on the second access of a word-wide read to the bank area. Needs work as it seems to break stuff.
Michael Pavone <pavone@retrodev.com>
parents: 505
diff changeset
352 genesis_context * gen = context->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
353 vdp_context *v_context = gen->vdp;
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
354 if (vdp_port < 0x10) {
149
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
355 int blocked;
345
29d2ca563499 Don't sync the 68K clock to the VDP clock unless the 68K had to wait for the VDP. This unfortunately breaks the direct color DMA demos, but should be more correct overall.
Mike Pavone <pavone@retrodev.com>
parents: 344
diff changeset
356 uint32_t before_cycle = v_context->cycles;
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
357 if (vdp_port < 4) {
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
358
149
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
359 while (vdp_data_port_write(v_context, value) < 0) {
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
360 while(v_context->flags & FLAG_DMA_RUN) {
696
0b2242bbc84a Added config option to allow specifying a max sync cycle smaller than the end of frame
Michael Pavone <pavone@retrodev.com>
parents: 695
diff changeset
361 vdp_run_dma_done(v_context, gen->frame_end);
0b2242bbc84a Added config option to allow specifying a max sync cycle smaller than the end of frame
Michael Pavone <pavone@retrodev.com>
parents: 695
diff changeset
362 if (v_context->cycles >= gen->frame_end) {
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
363 context->current_cycle = v_context->cycles;
697
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
364 gen->bus_busy = 1;
534
c641006da28e Properly sync hardware when frame end is reached during DMA
Mike Pavone <pavone@retrodev.com>
parents: 531
diff changeset
365 sync_components(context, 0);
697
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
366 gen->bus_busy = 0;
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
367 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
368 }
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
369 //context->current_cycle = v_context->cycles;
149
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
370 }
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
371 } else if(vdp_port < 8) {
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
372 blocked = vdp_control_port_write(v_context, value);
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
373 if (blocked) {
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
374 while (blocked) {
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
375 while(v_context->flags & FLAG_DMA_RUN) {
696
0b2242bbc84a Added config option to allow specifying a max sync cycle smaller than the end of frame
Michael Pavone <pavone@retrodev.com>
parents: 695
diff changeset
376 vdp_run_dma_done(v_context, gen->frame_end);
0b2242bbc84a Added config option to allow specifying a max sync cycle smaller than the end of frame
Michael Pavone <pavone@retrodev.com>
parents: 695
diff changeset
377 if (v_context->cycles >= gen->frame_end) {
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
378 context->current_cycle = v_context->cycles;
697
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
379 gen->bus_busy = 1;
534
c641006da28e Properly sync hardware when frame end is reached during DMA
Mike Pavone <pavone@retrodev.com>
parents: 531
diff changeset
380 sync_components(context, 0);
697
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
381 gen->bus_busy = 0;
149
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
382 }
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
383 }
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
384 if (blocked < 0) {
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
385 blocked = vdp_control_port_write(v_context, value);
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
386 } else {
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
387 blocked = 0;
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
388 }
139e5dcd6aa3 Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents: 144
diff changeset
389 }
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
390 } else {
697
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
391 context->sync_cycle = gen->frame_end = vdp_cycles_to_frame_end(v_context);
7f96bd1cb1be Sync fixes and logging to fix more sync issues
Michael Pavone <pavone@retrodev.com>
parents: 696
diff changeset
392 //printf("Set sync cycle to: %d @ %d, vcounter: %d, hslot: %d\n", context->sync_cycle, context->current_cycle, v_context->vcounter, v_context->hslot);
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
393 adjust_int_cycle(context, v_context);
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
394 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
395 } else {
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
396 fatal_error("Illegal write to HV Counter port %X\n", vdp_port);
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
397 }
345
29d2ca563499 Don't sync the 68K clock to the VDP clock unless the 68K had to wait for the VDP. This unfortunately breaks the direct color DMA demos, but should be more correct overall.
Mike Pavone <pavone@retrodev.com>
parents: 344
diff changeset
398 if (v_context->cycles != before_cycle) {
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
399 //printf("68K paused for %d (%d) cycles at cycle %d (%d) for write\n", v_context->cycles - context->current_cycle, v_context->cycles - before_cycle, context->current_cycle, before_cycle);
978
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
400 context->current_cycle = v_context->cycles;
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
401 #ifdef REFRESH_EMULATION
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
402 last_sync_cycle = context->current_cycle;
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
403 #endif
680
4996369f1463 Some small synchronization improvements that do not seem to fix anything
Michael Pavone <pavone@retrodev.com>
parents: 679
diff changeset
404 //Lock the Z80 out of the bus until the VDP access is complete
4996369f1463 Some small synchronization improvements that do not seem to fix anything
Michael Pavone <pavone@retrodev.com>
parents: 679
diff changeset
405 gen->bus_busy = 1;
4996369f1463 Some small synchronization improvements that do not seem to fix anything
Michael Pavone <pavone@retrodev.com>
parents: 679
diff changeset
406 sync_z80(gen->z80, v_context->cycles);
4996369f1463 Some small synchronization improvements that do not seem to fix anything
Michael Pavone <pavone@retrodev.com>
parents: 679
diff changeset
407 gen->bus_busy = 0;
345
29d2ca563499 Don't sync the 68K clock to the VDP clock unless the 68K had to wait for the VDP. This unfortunately breaks the direct color DMA demos, but should be more correct overall.
Mike Pavone <pavone@retrodev.com>
parents: 344
diff changeset
408 }
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
409 } else if (vdp_port < 0x18) {
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 351
diff changeset
410 psg_write(gen->psg, value);
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
411 } else {
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
412 //TODO: Implement undocumented test register(s)
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
413 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
414 return context;
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
415 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
416
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
417 m68k_context * vdp_port_write_b(uint32_t vdp_port, m68k_context * context, uint8_t value)
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
418 {
357
fa7ea48be9a9 Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
419 return vdp_port_write(vdp_port, context, vdp_port < 0x10 ? value | value << 8 : ((vdp_port & 1) ? value : 0));
fa7ea48be9a9 Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
420 }
fa7ea48be9a9 Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
421
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
422 void * z80_vdp_port_write(uint32_t vdp_port, void * vcontext, uint8_t value)
357
fa7ea48be9a9 Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
423 {
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
424 z80_context * context = vcontext;
357
fa7ea48be9a9 Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
425 genesis_context * gen = context->system;
660
e7cae6d9aaa6 Add the 3 cycle delay back in to Z80 bank area access
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
426 vdp_port &= 0xFF;
358
9498cfa7f7c8 Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents: 357
diff changeset
427 if (vdp_port & 0xE0) {
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
428 fatal_error("machine freeze due to write to Z80 address %X\n", 0x7F00 | vdp_port);
358
9498cfa7f7c8 Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents: 357
diff changeset
429 }
9498cfa7f7c8 Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents: 357
diff changeset
430 if (vdp_port < 0x10) {
9498cfa7f7c8 Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents: 357
diff changeset
431 //These probably won't currently interact well with the 68K accessing the VDP
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
432 vdp_run_context(gen->vdp, context->current_cycle);
358
9498cfa7f7c8 Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents: 357
diff changeset
433 if (vdp_port < 4) {
9498cfa7f7c8 Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents: 357
diff changeset
434 vdp_data_port_write(gen->vdp, value << 8 | value);
9498cfa7f7c8 Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents: 357
diff changeset
435 } else if (vdp_port < 8) {
9498cfa7f7c8 Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents: 357
diff changeset
436 vdp_control_port_write(gen->vdp, value << 8 | value);
9498cfa7f7c8 Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents: 357
diff changeset
437 } else {
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
438 fatal_error("Illegal write to HV Counter port %X\n", vdp_port);
358
9498cfa7f7c8 Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents: 357
diff changeset
439 }
9498cfa7f7c8 Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents: 357
diff changeset
440 } else if (vdp_port < 0x18) {
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
441 sync_sound(gen, context->current_cycle);
358
9498cfa7f7c8 Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents: 357
diff changeset
442 psg_write(gen->psg, value);
9498cfa7f7c8 Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents: 357
diff changeset
443 } else {
470
541c1ae8abf3 Properly delay 68K on VDP reads. Dummy VDP test port implementation. Initial stab at handling undefined bits of VSRAM and CRAM.
Mike Pavone <pavone@retrodev.com>
parents: 469
diff changeset
444 vdp_test_port_write(gen->vdp, value);
358
9498cfa7f7c8 Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents: 357
diff changeset
445 }
357
fa7ea48be9a9 Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
446 return context;
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
447 }
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
448
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
449 uint16_t vdp_port_read(uint32_t vdp_port, m68k_context * context)
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
450 {
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
451 if (vdp_port & 0x2700E0) {
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
452 fatal_error("machine freeze due to read from address %X\n", 0xC00000 | vdp_port);
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
453 }
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
454 vdp_port &= 0x1F;
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
455 uint16_t value;
198
209a37eed3e7 Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents: 197
diff changeset
456 sync_components(context, 0);
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
457 genesis_context *gen = context->system;
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
458 vdp_context * v_context = gen->vdp;
470
541c1ae8abf3 Properly delay 68K on VDP reads. Dummy VDP test port implementation. Initial stab at handling undefined bits of VSRAM and CRAM.
Mike Pavone <pavone@retrodev.com>
parents: 469
diff changeset
459 uint32_t before_cycle = v_context->cycles;
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
460 if (vdp_port < 0x10) {
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
461 if (vdp_port < 4) {
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
462 value = vdp_data_port_read(v_context);
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
463 } else if(vdp_port < 8) {
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
464 value = vdp_control_port_read(v_context);
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
465 } else {
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
466 value = vdp_hv_counter_read(v_context);
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
467 //printf("HV Counter: %X at cycle %d\n", value, v_context->cycles);
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
468 }
470
541c1ae8abf3 Properly delay 68K on VDP reads. Dummy VDP test port implementation. Initial stab at handling undefined bits of VSRAM and CRAM.
Mike Pavone <pavone@retrodev.com>
parents: 469
diff changeset
469 } else if (vdp_port < 0x18){
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
470 fatal_error("Illegal read from PSG port %X\n", vdp_port);
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
471 } else {
470
541c1ae8abf3 Properly delay 68K on VDP reads. Dummy VDP test port implementation. Initial stab at handling undefined bits of VSRAM and CRAM.
Mike Pavone <pavone@retrodev.com>
parents: 469
diff changeset
472 value = vdp_test_port_read(v_context);
541c1ae8abf3 Properly delay 68K on VDP reads. Dummy VDP test port implementation. Initial stab at handling undefined bits of VSRAM and CRAM.
Mike Pavone <pavone@retrodev.com>
parents: 469
diff changeset
473 }
541c1ae8abf3 Properly delay 68K on VDP reads. Dummy VDP test port implementation. Initial stab at handling undefined bits of VSRAM and CRAM.
Mike Pavone <pavone@retrodev.com>
parents: 469
diff changeset
474 if (v_context->cycles != before_cycle) {
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
475 //printf("68K paused for %d (%d) cycles at cycle %d (%d) for read\n", v_context->cycles - context->current_cycle, v_context->cycles - before_cycle, context->current_cycle, before_cycle);
978
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
476 context->current_cycle = v_context->cycles;
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
477 #ifdef REFRES_EMULATION
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
478 last_sync_cycle = context->current_cycle;
34b811ea1e7c Disable refresh emulation with some ifdefs for now as it currently is not accurate enough to actually improve overall accuracy/compatibility and in fact makes things that work right on real hardware break
Michael Pavone <pavone@retrodev.com>
parents: 975
diff changeset
479 #endif
680
4996369f1463 Some small synchronization improvements that do not seem to fix anything
Michael Pavone <pavone@retrodev.com>
parents: 679
diff changeset
480 //Lock the Z80 out of the bus until the VDP access is complete
4996369f1463 Some small synchronization improvements that do not seem to fix anything
Michael Pavone <pavone@retrodev.com>
parents: 679
diff changeset
481 genesis_context *gen = context->system;
4996369f1463 Some small synchronization improvements that do not seem to fix anything
Michael Pavone <pavone@retrodev.com>
parents: 679
diff changeset
482 gen->bus_busy = 1;
4996369f1463 Some small synchronization improvements that do not seem to fix anything
Michael Pavone <pavone@retrodev.com>
parents: 679
diff changeset
483 sync_z80(gen->z80, v_context->cycles);
4996369f1463 Some small synchronization improvements that do not seem to fix anything
Michael Pavone <pavone@retrodev.com>
parents: 679
diff changeset
484 gen->bus_busy = 0;
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
485 }
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
486 return value;
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
487 }
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
488
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
489 uint8_t vdp_port_read_b(uint32_t vdp_port, m68k_context * context)
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
490 {
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
491 uint16_t value = vdp_port_read(vdp_port, context);
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
492 if (vdp_port & 1) {
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
493 return value;
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
494 } else {
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
495 return value >> 8;
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
496 }
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
497 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
498
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
499 uint8_t z80_vdp_port_read(uint32_t vdp_port, void * vcontext)
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
500 {
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
501 z80_context * context = vcontext;
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
502 if (vdp_port & 0xE0) {
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
503 fatal_error("machine freeze due to read from Z80 address %X\n", 0x7F00 | vdp_port);
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
504 }
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
505 genesis_context * gen = context->system;
736
535e97bad27f Implement cycles being stolen from 68K when the Z80 accesses the bank area or VDP/PSG. Small fix to code that tries to get system into a consistent state for a savestate
Michael Pavone <pavone@retrodev.com>
parents: 721
diff changeset
506 //VDP access goes over the 68K bus like a bank area access
535e97bad27f Implement cycles being stolen from 68K when the Z80 accesses the bank area or VDP/PSG. Small fix to code that tries to get system into a consistent state for a savestate
Michael Pavone <pavone@retrodev.com>
parents: 721
diff changeset
507 //typical delay from bus arbitration
535e97bad27f Implement cycles being stolen from 68K when the Z80 accesses the bank area or VDP/PSG. Small fix to code that tries to get system into a consistent state for a savestate
Michael Pavone <pavone@retrodev.com>
parents: 721
diff changeset
508 context->current_cycle += 3 * MCLKS_PER_Z80;
535e97bad27f Implement cycles being stolen from 68K when the Z80 accesses the bank area or VDP/PSG. Small fix to code that tries to get system into a consistent state for a savestate
Michael Pavone <pavone@retrodev.com>
parents: 721
diff changeset
509 //TODO: add cycle for an access right after a previous one
535e97bad27f Implement cycles being stolen from 68K when the Z80 accesses the bank area or VDP/PSG. Small fix to code that tries to get system into a consistent state for a savestate
Michael Pavone <pavone@retrodev.com>
parents: 721
diff changeset
510 //TODO: Below cycle time is an estimate based on the time between 68K !BG goes low and Z80 !MREQ goes high
535e97bad27f Implement cycles being stolen from 68K when the Z80 accesses the bank area or VDP/PSG. Small fix to code that tries to get system into a consistent state for a savestate
Michael Pavone <pavone@retrodev.com>
parents: 721
diff changeset
511 // Needs a new logic analyzer capture to get the actual delay on the 68K side
535e97bad27f Implement cycles being stolen from 68K when the Z80 accesses the bank area or VDP/PSG. Small fix to code that tries to get system into a consistent state for a savestate
Michael Pavone <pavone@retrodev.com>
parents: 721
diff changeset
512 gen->m68k->current_cycle += 8 * MCLKS_PER_68K;
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
513
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
514
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
515 vdp_port &= 0x1F;
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
516 uint16_t ret;
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
517 if (vdp_port < 0x10) {
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
518 //These probably won't currently interact well with the 68K accessing the VDP
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
519 vdp_run_context(gen->vdp, context->current_cycle);
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
520 if (vdp_port < 4) {
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
521 ret = vdp_data_port_read(gen->vdp);
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
522 } else if (vdp_port < 8) {
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
523 ret = vdp_control_port_read(gen->vdp);
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
524 } else {
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
525 fatal_error("Illegal write to HV Counter port %X\n", vdp_port);
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
526 }
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
527 } else {
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
528 //TODO: Figure out the correct value today
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
529 ret = 0xFFFF;
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
530 }
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
531 return vdp_port & 1 ? ret : ret >> 8;
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
532 }
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
533
279
6be6056735a9 Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents: 276
diff changeset
534 uint32_t zram_counter = 0;
6be6056735a9 Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents: 276
diff changeset
535
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
536 m68k_context * io_write(uint32_t location, m68k_context * context, uint8_t value)
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
537 {
288
a8ee7934a1f8 Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents: 280
diff changeset
538 genesis_context * gen = context->system;
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
539 if (location < 0x10000) {
844
74e161fe7d39 Small tweaks to timing of 68K/Z80 interactions based on latest tests
Michael Pavone <pavone@retrodev.com>
parents: 837
diff changeset
540 //Access to Z80 memory incurs a one 68K cycle wait state
74e161fe7d39 Small tweaks to timing of 68K/Z80 interactions based on latest tests
Michael Pavone <pavone@retrodev.com>
parents: 837
diff changeset
541 context->current_cycle += MCLKS_PER_68K;
668
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
542 if (!z80_enabled || z80_get_busack(gen->z80, context->current_cycle)) {
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
543 location &= 0x7FFF;
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
544 if (location < 0x4000) {
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
545 z80_ram[location & 0x1FFF] = value;
565
9324f721efa6 Add a separate flag/define for disabling the Z80 at compile time to ease refactoring
Michael Pavone <pavone@retrodev.com>
parents: 558
diff changeset
546 #ifndef NO_Z80
288
a8ee7934a1f8 Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents: 280
diff changeset
547 z80_handle_code_write(location & 0x1FFF, gen->z80);
548
a3afee2271ce Initial work on the x86-32 target
Michael Pavone <pavone@retrodev.com>
parents: 534
diff changeset
548 #endif
288
a8ee7934a1f8 Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents: 280
diff changeset
549 } else if (location < 0x6000) {
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
550 sync_sound(gen, context->current_cycle);
288
a8ee7934a1f8 Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents: 280
diff changeset
551 if (location & 1) {
a8ee7934a1f8 Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents: 280
diff changeset
552 ym_data_write(gen->ym, value);
a8ee7934a1f8 Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents: 280
diff changeset
553 } else if(location & 2) {
a8ee7934a1f8 Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents: 280
diff changeset
554 ym_address_write_part2(gen->ym, value);
a8ee7934a1f8 Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents: 280
diff changeset
555 } else {
a8ee7934a1f8 Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents: 280
diff changeset
556 ym_address_write_part1(gen->ym, value);
a8ee7934a1f8 Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents: 280
diff changeset
557 }
405
042c4ba4a838 Implement writes from 68K to Z80 bank register and make reads from port c control register return 0 again
Mike Pavone <pavone@retrodev.com>
parents: 404
diff changeset
558 } else if (location == 0x6000) {
042c4ba4a838 Implement writes from 68K to Z80 bank register and make reads from port c control register return 0 again
Mike Pavone <pavone@retrodev.com>
parents: 404
diff changeset
559 gen->z80->bank_reg = (gen->z80->bank_reg >> 1 | value << 8) & 0x1FF;
042c4ba4a838 Implement writes from 68K to Z80 bank register and make reads from port c control register return 0 again
Mike Pavone <pavone@retrodev.com>
parents: 404
diff changeset
560 if (gen->z80->bank_reg < 0x80) {
042c4ba4a838 Implement writes from 68K to Z80 bank register and make reads from port c control register return 0 again
Mike Pavone <pavone@retrodev.com>
parents: 404
diff changeset
561 gen->z80->mem_pointers[1] = (gen->z80->bank_reg << 15) + ((char *)gen->z80->mem_pointers[2]);
042c4ba4a838 Implement writes from 68K to Z80 bank register and make reads from port c control register return 0 again
Mike Pavone <pavone@retrodev.com>
parents: 404
diff changeset
562 } else {
042c4ba4a838 Implement writes from 68K to Z80 bank register and make reads from port c control register return 0 again
Mike Pavone <pavone@retrodev.com>
parents: 404
diff changeset
563 gen->z80->mem_pointers[1] = NULL;
042c4ba4a838 Implement writes from 68K to Z80 bank register and make reads from port c control register return 0 again
Mike Pavone <pavone@retrodev.com>
parents: 404
diff changeset
564 }
395
0b5f93358a93 Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents: 392
diff changeset
565 } else {
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
566 fatal_error("68K write to unhandled Z80 address %X\n", location);
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
567 }
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
568 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
569 } else {
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
570 location &= 0x1FFF;
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
571 if (location < 0x100) {
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
572 switch(location/2)
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
573 {
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
574 case 0x1:
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
575 io_data_write(gen->ports, value, context->current_cycle);
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
576 break;
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
577 case 0x2:
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
578 io_data_write(gen->ports+1, value, context->current_cycle);
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
579 break;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
580 case 0x3:
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
581 io_data_write(gen->ports+2, value, context->current_cycle);
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
582 break;
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
583 case 0x4:
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
584 gen->ports[0].control = value;
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
585 break;
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
586 case 0x5:
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
587 gen->ports[1].control = value;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
588 break;
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
589 case 0x6:
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
590 gen->ports[2].control = value;
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
591 break;
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
592 }
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
593 } else {
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
594 if (location == 0x1100) {
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
595 if (value & 1) {
271
969ee17471c5 Protect debug prints for busreq/reset regs with appropriate macros
Mike Pavone <pavone@retrodev.com>
parents: 268
diff changeset
596 dputs("bus requesting Z80");
668
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
597 if (z80_enabled) {
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
598 z80_assert_busreq(gen->z80, context->current_cycle);
677
687c1dd3bcb9 Fake busack when Z80 is disabled
Michael Pavone <pavone@retrodev.com>
parents: 672
diff changeset
599 } else {
687c1dd3bcb9 Fake busack when Z80 is disabled
Michael Pavone <pavone@retrodev.com>
parents: 672
diff changeset
600 gen->z80->busack = 1;
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
601 }
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
602 } else {
668
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
603 if (gen->z80->busreq) {
271
969ee17471c5 Protect debug prints for busreq/reset regs with appropriate macros
Mike Pavone <pavone@retrodev.com>
parents: 268
diff changeset
604 dputs("releasing z80 bus");
280
9ee64039ddeb Fix bank register update
Mike Pavone <pavone@retrodev.com>
parents: 279
diff changeset
605 #ifdef DO_DEBUG_PRINT
279
6be6056735a9 Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents: 276
diff changeset
606 char fname[20];
6be6056735a9 Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents: 276
diff changeset
607 sprintf(fname, "zram-%d", zram_counter++);
6be6056735a9 Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents: 276
diff changeset
608 FILE * f = fopen(fname, "wb");
6be6056735a9 Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents: 276
diff changeset
609 fwrite(z80_ram, 1, sizeof(z80_ram), f);
6be6056735a9 Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents: 276
diff changeset
610 fclose(f);
280
9ee64039ddeb Fix bank register update
Mike Pavone <pavone@retrodev.com>
parents: 279
diff changeset
611 #endif
260
625f8e4d5fd2 Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 215
diff changeset
612 }
668
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
613 if (z80_enabled) {
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
614 z80_clear_busreq(gen->z80, context->current_cycle);
677
687c1dd3bcb9 Fake busack when Z80 is disabled
Michael Pavone <pavone@retrodev.com>
parents: 672
diff changeset
615 } else {
687c1dd3bcb9 Fake busack when Z80 is disabled
Michael Pavone <pavone@retrodev.com>
parents: 672
diff changeset
616 gen->z80->busack = 0;
668
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
617 }
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
618 }
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
619 } else if (location == 0x1200) {
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
620 sync_z80(gen->z80, context->current_cycle);
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
621 if (value & 1) {
668
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
622 if (z80_enabled) {
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
623 z80_clear_reset(gen->z80, context->current_cycle);
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
624 } else {
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
625 gen->z80->reset = 0;
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
626 }
668
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
627 } else {
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
628 if (z80_enabled) {
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
629 z80_assert_reset(gen->z80, context->current_cycle);
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
630 } else {
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
631 gen->z80->reset = 1;
260
625f8e4d5fd2 Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 215
diff changeset
632 }
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
633 }
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
634 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
635 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
636 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
637 return context;
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
638 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
639
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
640 m68k_context * io_write_w(uint32_t location, m68k_context * context, uint16_t value)
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
641 {
404
88fa2ad53e64 Minor refactor of io_read functions to avoid duplication of logic between byte and word versions
Mike Pavone <pavone@retrodev.com>
parents: 402
diff changeset
642 if (location < 0x10000 || (location & 0x1FFF) >= 0x100) {
88fa2ad53e64 Minor refactor of io_read functions to avoid duplication of logic between byte and word versions
Mike Pavone <pavone@retrodev.com>
parents: 402
diff changeset
643 return io_write(location, context, value >> 8);
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
644 } else {
404
88fa2ad53e64 Minor refactor of io_read functions to avoid duplication of logic between byte and word versions
Mike Pavone <pavone@retrodev.com>
parents: 402
diff changeset
645 return io_write(location, context, value);
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
646 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
647 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
648
130
0bdbffa9fe90 Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents: 115
diff changeset
649 #define USA 0x80
0bdbffa9fe90 Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents: 115
diff changeset
650 #define JAP 0x00
0bdbffa9fe90 Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents: 115
diff changeset
651 #define EUR 0xC0
0bdbffa9fe90 Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents: 115
diff changeset
652 #define NO_DISK 0x20
0bdbffa9fe90 Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents: 115
diff changeset
653 uint8_t version_reg = NO_DISK | USA;
0bdbffa9fe90 Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents: 115
diff changeset
654
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
655 uint8_t io_read(uint32_t location, m68k_context * context)
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
656 {
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
657 uint8_t value;
288
a8ee7934a1f8 Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents: 280
diff changeset
658 genesis_context *gen = context->system;
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
659 if (location < 0x10000) {
844
74e161fe7d39 Small tweaks to timing of 68K/Z80 interactions based on latest tests
Michael Pavone <pavone@retrodev.com>
parents: 837
diff changeset
660 //Access to Z80 memory incurs a one 68K cycle wait state
74e161fe7d39 Small tweaks to timing of 68K/Z80 interactions based on latest tests
Michael Pavone <pavone@retrodev.com>
parents: 837
diff changeset
661 context->current_cycle += MCLKS_PER_68K;
668
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
662 if (!z80_enabled || z80_get_busack(gen->z80, context->current_cycle)) {
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
663 location &= 0x7FFF;
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
664 if (location < 0x4000) {
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
665 value = z80_ram[location & 0x1FFF];
288
a8ee7934a1f8 Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents: 280
diff changeset
666 } else if (location < 0x6000) {
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
667 sync_sound(gen, context->current_cycle);
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
668 value = ym_read_status(gen->ym);
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
669 } else {
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
670 value = 0xFF;
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
671 }
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
672 } else {
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
673 value = 0xFF;
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
674 }
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
675 } else {
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
676 location &= 0x1FFF;
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
677 if (location < 0x100) {
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
678 switch(location/2)
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
679 {
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
680 case 0x0:
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
681 //version bits should be 0 for now since we're not emulating TMSS
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
682 value = version_reg;
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
683 break;
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
684 case 0x1:
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
685 value = io_data_read(gen->ports, context->current_cycle);
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
686 break;
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
687 case 0x2:
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
688 value = io_data_read(gen->ports+1, context->current_cycle);
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
689 break;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
690 case 0x3:
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
691 value = io_data_read(gen->ports+2, context->current_cycle);
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
692 break;
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
693 case 0x4:
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
694 value = gen->ports[0].control;
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
695 break;
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
696 case 0x5:
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
697 value = gen->ports[1].control;
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
698 break;
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
699 case 0x6:
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
700 value = gen->ports[2].control;
405
042c4ba4a838 Implement writes from 68K to Z80 bank register and make reads from port c control register return 0 again
Mike Pavone <pavone@retrodev.com>
parents: 404
diff changeset
701 break;
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
702 default:
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
703 value = 0xFF;
153
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
704 }
42c031184e8a Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents: 149
diff changeset
705 } else {
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
706 if (location == 0x1100) {
677
687c1dd3bcb9 Fake busack when Z80 is disabled
Michael Pavone <pavone@retrodev.com>
parents: 672
diff changeset
707 value = z80_enabled ? !z80_get_busack(gen->z80, context->current_cycle) : !gen->z80->busack;
753
cee1275f5d08 Lame placeholder support for floating bus bits of IO hardware. Needs to be replaced with prefetch based values
Michael Pavone <pavone@retrodev.com>
parents: 752
diff changeset
708 //TODO: actual pre-fetch emulation
cee1275f5d08 Lame placeholder support for floating bus bits of IO hardware. Needs to be replaced with prefetch based values
Michael Pavone <pavone@retrodev.com>
parents: 752
diff changeset
709 value |= 0x4E;
668
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
710 dprintf("Byte read of BUSREQ returned %d @ %d (reset: %d)\n", value, context->current_cycle, gen->z80->reset);
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
711 } else if (location == 0x1200) {
668
5439ae7946ca Made the Z80 core more contained by refactoring some code in blastem.c into z80_to_x86.c
Michael Pavone <pavone@retrodev.com>
parents: 667
diff changeset
712 value = !gen->z80->reset;
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
713 } else {
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
714 value = 0xFF;
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
715 printf("Byte read of unknown IO location: %X\n", location);
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
716 }
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
717 }
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
718 }
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
719 return value;
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
720 }
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
721
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
722 uint16_t io_read_w(uint32_t location, m68k_context * context)
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
723 {
404
88fa2ad53e64 Minor refactor of io_read functions to avoid duplication of logic between byte and word versions
Mike Pavone <pavone@retrodev.com>
parents: 402
diff changeset
724 uint16_t value = io_read(location, context);
88fa2ad53e64 Minor refactor of io_read functions to avoid duplication of logic between byte and word versions
Mike Pavone <pavone@retrodev.com>
parents: 402
diff changeset
725 if (location < 0x10000 || (location & 0x1FFF) < 0x100) {
88fa2ad53e64 Minor refactor of io_read functions to avoid duplication of logic between byte and word versions
Mike Pavone <pavone@retrodev.com>
parents: 402
diff changeset
726 value = value | (value << 8);
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
727 } else {
404
88fa2ad53e64 Minor refactor of io_read functions to avoid duplication of logic between byte and word versions
Mike Pavone <pavone@retrodev.com>
parents: 402
diff changeset
728 value <<= 8;
753
cee1275f5d08 Lame placeholder support for floating bus bits of IO hardware. Needs to be replaced with prefetch based values
Michael Pavone <pavone@retrodev.com>
parents: 752
diff changeset
729 //TODO: actual pre-fetch emulation
cee1275f5d08 Lame placeholder support for floating bus bits of IO hardware. Needs to be replaced with prefetch based values
Michael Pavone <pavone@retrodev.com>
parents: 752
diff changeset
730 value |= 0x73;
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
731 }
343
467bfa17004a Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
732 return value;
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
733 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
734
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
735 void * z80_write_ym(uint32_t location, void * vcontext, uint8_t value)
290
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
736 {
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
737 z80_context * context = vcontext;
290
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
738 genesis_context * gen = context->system;
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
739 sync_sound(gen, context->current_cycle);
290
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
740 if (location & 1) {
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
741 ym_data_write(gen->ym, value);
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
742 } else if (location & 2) {
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
743 ym_address_write_part2(gen->ym, value);
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
744 } else {
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
745 ym_address_write_part1(gen->ym, value);
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
746 }
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
747 return context;
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
748 }
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
749
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
750 uint8_t z80_read_ym(uint32_t location, void * vcontext)
290
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
751 {
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
752 z80_context * context = vcontext;
290
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
753 genesis_context * gen = context->system;
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
754 sync_sound(gen, context->current_cycle);
290
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
755 return ym_read_status(gen->ym);
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
756 }
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
757
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
758 uint8_t z80_read_bank(uint32_t location, void * vcontext)
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
759 {
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
760 z80_context * context = vcontext;
672
18ef3b61e70b Restore emulation of Z80 being locked out of the 68K bus during DMA and the like
Michael Pavone <pavone@retrodev.com>
parents: 671
diff changeset
761 genesis_context *gen = context->system;
18ef3b61e70b Restore emulation of Z80 being locked out of the 68K bus during DMA and the like
Michael Pavone <pavone@retrodev.com>
parents: 671
diff changeset
762 if (gen->bus_busy) {
18ef3b61e70b Restore emulation of Z80 being locked out of the 68K bus during DMA and the like
Michael Pavone <pavone@retrodev.com>
parents: 671
diff changeset
763 context->current_cycle = context->sync_cycle;
18ef3b61e70b Restore emulation of Z80 being locked out of the 68K bus during DMA and the like
Michael Pavone <pavone@retrodev.com>
parents: 671
diff changeset
764 }
660
e7cae6d9aaa6 Add the 3 cycle delay back in to Z80 bank area access
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
765 //typical delay from bus arbitration
671
8ad39a2b0bce Fix bank area access delay for master clock change
Michael Pavone <pavone@retrodev.com>
parents: 670
diff changeset
766 context->current_cycle += 3 * MCLKS_PER_Z80;
672
18ef3b61e70b Restore emulation of Z80 being locked out of the 68K bus during DMA and the like
Michael Pavone <pavone@retrodev.com>
parents: 671
diff changeset
767 //TODO: add cycle for an access right after a previous one
736
535e97bad27f Implement cycles being stolen from 68K when the Z80 accesses the bank area or VDP/PSG. Small fix to code that tries to get system into a consistent state for a savestate
Michael Pavone <pavone@retrodev.com>
parents: 721
diff changeset
768 //TODO: Below cycle time is an estimate based on the time between 68K !BG goes low and Z80 !MREQ goes high
535e97bad27f Implement cycles being stolen from 68K when the Z80 accesses the bank area or VDP/PSG. Small fix to code that tries to get system into a consistent state for a savestate
Michael Pavone <pavone@retrodev.com>
parents: 721
diff changeset
769 // Needs a new logic analyzer capture to get the actual delay on the 68K side
535e97bad27f Implement cycles being stolen from 68K when the Z80 accesses the bank area or VDP/PSG. Small fix to code that tries to get system into a consistent state for a savestate
Michael Pavone <pavone@retrodev.com>
parents: 721
diff changeset
770 gen->m68k->current_cycle += 8 * MCLKS_PER_68K;
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
771
660
e7cae6d9aaa6 Add the 3 cycle delay back in to Z80 bank area access
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
772 location &= 0x7FFF;
e7cae6d9aaa6 Add the 3 cycle delay back in to Z80 bank area access
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
773 if (context->mem_pointers[1]) {
e7cae6d9aaa6 Add the 3 cycle delay back in to Z80 bank area access
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
774 return context->mem_pointers[1][location ^ 1];
e7cae6d9aaa6 Add the 3 cycle delay back in to Z80 bank area access
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
775 }
604
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
776 uint32_t address = context->bank_reg << 15 | location;
616
649db9397fa1 Add support for Z80 access to VDP via bank area
Michael Pavone <pavone@retrodev.com>
parents: 606
diff changeset
777 if (address >= 0xC00000 && address < 0xE00000) {
649db9397fa1 Add support for Z80 access to VDP via bank area
Michael Pavone <pavone@retrodev.com>
parents: 606
diff changeset
778 return z80_vdp_port_read(location & 0xFF, context);
649db9397fa1 Add support for Z80 access to VDP via bank area
Michael Pavone <pavone@retrodev.com>
parents: 606
diff changeset
779 } else {
660
e7cae6d9aaa6 Add the 3 cycle delay back in to Z80 bank area access
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
780 fprintf(stderr, "Unhandled read by Z80 from address %X through banked memory area (%X)\n", address, context->bank_reg << 15);
616
649db9397fa1 Add support for Z80 access to VDP via bank area
Michael Pavone <pavone@retrodev.com>
parents: 606
diff changeset
781 }
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
782 return 0;
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
783 }
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
784
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
785 void *z80_write_bank(uint32_t location, void * vcontext, uint8_t value)
290
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
786 {
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
787 z80_context * context = vcontext;
672
18ef3b61e70b Restore emulation of Z80 being locked out of the 68K bus during DMA and the like
Michael Pavone <pavone@retrodev.com>
parents: 671
diff changeset
788 genesis_context *gen = context->system;
18ef3b61e70b Restore emulation of Z80 being locked out of the 68K bus during DMA and the like
Michael Pavone <pavone@retrodev.com>
parents: 671
diff changeset
789 if (gen->bus_busy) {
18ef3b61e70b Restore emulation of Z80 being locked out of the 68K bus during DMA and the like
Michael Pavone <pavone@retrodev.com>
parents: 671
diff changeset
790 context->current_cycle = context->sync_cycle;
18ef3b61e70b Restore emulation of Z80 being locked out of the 68K bus during DMA and the like
Michael Pavone <pavone@retrodev.com>
parents: 671
diff changeset
791 }
660
e7cae6d9aaa6 Add the 3 cycle delay back in to Z80 bank area access
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
792 //typical delay from bus arbitration
671
8ad39a2b0bce Fix bank area access delay for master clock change
Michael Pavone <pavone@retrodev.com>
parents: 670
diff changeset
793 context->current_cycle += 3 * MCLKS_PER_Z80;
672
18ef3b61e70b Restore emulation of Z80 being locked out of the 68K bus during DMA and the like
Michael Pavone <pavone@retrodev.com>
parents: 671
diff changeset
794 //TODO: add cycle for an access right after a previous one
736
535e97bad27f Implement cycles being stolen from 68K when the Z80 accesses the bank area or VDP/PSG. Small fix to code that tries to get system into a consistent state for a savestate
Michael Pavone <pavone@retrodev.com>
parents: 721
diff changeset
795 //TODO: Below cycle time is an estimate based on the time between 68K !BG goes low and Z80 !MREQ goes high
535e97bad27f Implement cycles being stolen from 68K when the Z80 accesses the bank area or VDP/PSG. Small fix to code that tries to get system into a consistent state for a savestate
Michael Pavone <pavone@retrodev.com>
parents: 721
diff changeset
796 // Needs a new logic analyzer capture to get the actual delay on the 68K side
535e97bad27f Implement cycles being stolen from 68K when the Z80 accesses the bank area or VDP/PSG. Small fix to code that tries to get system into a consistent state for a savestate
Michael Pavone <pavone@retrodev.com>
parents: 721
diff changeset
797 gen->m68k->current_cycle += 8 * MCLKS_PER_68K;
672
18ef3b61e70b Restore emulation of Z80 being locked out of the 68K bus during DMA and the like
Michael Pavone <pavone@retrodev.com>
parents: 671
diff changeset
798
660
e7cae6d9aaa6 Add the 3 cycle delay back in to Z80 bank area access
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
799 location &= 0x7FFF;
604
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
800 uint32_t address = context->bank_reg << 15 | location;
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
801 if (address >= 0xE00000) {
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
802 address &= 0xFFFF;
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
803 ((uint8_t *)ram)[address ^ 1] = value;
616
649db9397fa1 Add support for Z80 access to VDP via bank area
Michael Pavone <pavone@retrodev.com>
parents: 606
diff changeset
804 } else if (address >= 0xC00000) {
649db9397fa1 Add support for Z80 access to VDP via bank area
Michael Pavone <pavone@retrodev.com>
parents: 606
diff changeset
805 z80_vdp_port_write(location & 0xFF, context, value);
604
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
806 } else {
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
807 fprintf(stderr, "Unhandled write by Z80 to address %X through banked memory area\n", address);
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
808 }
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
809 return context;
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
810 }
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
811
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
812 void *z80_write_bank_reg(uint32_t location, void * vcontext, uint8_t value)
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
813 {
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
814 z80_context * context = vcontext;
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
815
604
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
816 context->bank_reg = (context->bank_reg >> 1 | value << 8) & 0x1FF;
777
79b10b421d3c Support large flat-mapped ROMs like Bad Apple or that Mortal Kombat hack
Michael Pavone <pavone@retrodev.com>
parents: 776
diff changeset
817 if (context->bank_reg < 0x100) {
660
e7cae6d9aaa6 Add the 3 cycle delay back in to Z80 bank area access
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
818 genesis_context *gen = context->system;
e7cae6d9aaa6 Add the 3 cycle delay back in to Z80 bank area access
Michael Pavone <pavone@retrodev.com>
parents: 659
diff changeset
819 context->mem_pointers[1] = get_native_pointer(context->bank_reg << 15, (void **)gen->m68k->mem_pointers, &gen->m68k->options->gen);
604
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
820 } else {
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
821 context->mem_pointers[1] = NULL;
39d7d463ed5b Get Z80 banked access sort of working again
Michael Pavone <pavone@retrodev.com>
parents: 602
diff changeset
822 }
667
30ccf56842d6 All cycle counters are now based off the master clock. This seems to have messed up Z80 interrupt timing (music in Sonic 2 is too slow for instance), but things are generally working
Michael Pavone <pavone@retrodev.com>
parents: 661
diff changeset
823
592
4ff7bbb3943b Get rest of emulator compiling again with Z80 core enabled
Michael Pavone <pavone@retrodev.com>
parents: 590
diff changeset
824 return context;
290
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
825 }
171f97e70d85 Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents: 289
diff changeset
826
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
827 void set_speed_percent(genesis_context * context, uint32_t percent)
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
828 {
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
829 uint32_t old_clock = context->master_clock;
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
830 context->master_clock = ((uint64_t)context->normal_clock * (uint64_t)percent) / 100;
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
831 while (context->ym->current_cycle != context->psg->cycles) {
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
832 sync_sound(context, context->psg->cycles + MCLKS_PER_PSG);
424
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
833 }
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
834 ym_adjust_master_clock(context->ym, context->master_clock);
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
835 psg_adjust_master_clock(context->psg, context->master_clock);
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
836 }
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
837
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
838 char * save_filename;
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
839 genesis_context *genesis;
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
840 genesis_context *menu_context;
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
841 genesis_context *game_context;
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
842 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
843 {
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
844 FILE * f = fopen(save_filename, "wb");
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
845 if (!f) {
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
846 fprintf(stderr, "Failed to open %s file %s for writing\n", genesis->save_type == SAVE_I2C ? "EEPROM" : "SRAM", save_filename);
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
847 return;
2f264d2a60c2 Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents: 346
diff changeset
848 }
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
849 fwrite(genesis->save_storage, 1, genesis->save_size, f);
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
850 fclose(f);
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
851 printf("Saved %s to %s\n", genesis->save_type == SAVE_I2C ? "EEPROM" : "SRAM", save_filename);
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
852 }
2f264d2a60c2 Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents: 346
diff changeset
853
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
854 #ifndef NO_Z80
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
855 const memmap_chunk z80_map[] = {
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
856 { 0x0000, 0x4000, 0x1FFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, z80_ram, NULL, NULL, NULL, NULL },
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
857 { 0x8000, 0x10000, 0x7FFF, 0, 0, NULL, NULL, NULL, z80_read_bank, z80_write_bank},
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
858 { 0x4000, 0x6000, 0x0003, 0, 0, NULL, NULL, NULL, z80_read_ym, z80_write_ym},
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
859 { 0x6000, 0x6100, 0xFFFF, 0, 0, NULL, NULL, NULL, NULL, z80_write_bank_reg},
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
860 { 0x7F00, 0x8000, 0x00FF, 0, 0, NULL, NULL, NULL, z80_vdp_port_read, z80_vdp_port_write}
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
861 };
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
862 #endif
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
863
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
864 genesis_context *alloc_init_genesis(rom_info *rom, int fps, uint32_t ym_opts)
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
865 {
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
866 genesis_context *gen = calloc(1, sizeof(genesis_context));
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
867 gen->master_clock = gen->normal_clock = fps == 60 ? MCLKS_NTSC : MCLKS_PAL;
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
868
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
869 gen->vdp = malloc(sizeof(vdp_context));
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
870 init_vdp_context(gen->vdp, version_reg & 0x40);
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
871 gen->frame_end = vdp_cycles_to_frame_end(gen->vdp);
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
872 char * config_cycles = tern_find_path(config, "clocks\0max_cycles\0").ptrval;
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
873 gen->max_cycles = config_cycles ? atoi(config_cycles) : DEFAULT_SYNC_INTERVAL;
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
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
875 gen->ym = malloc(sizeof(ym2612_context));
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
876 ym_init(gen->ym, render_sample_rate(), gen->master_clock, MCLKS_PER_YM, render_audio_buffer(), ym_opts);
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
877
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
878 gen->psg = malloc(sizeof(psg_context));
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
879 psg_init(gen->psg, render_sample_rate(), gen->master_clock, MCLKS_PER_PSG, render_audio_buffer());
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
880
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
881 gen->z80 = calloc(1, sizeof(z80_context));
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
882 #ifndef NO_Z80
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
883 z80_options *z_opts = malloc(sizeof(z80_options));
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
884 init_z80_opts(z_opts, z80_map, 5, NULL, 0, MCLKS_PER_Z80);
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
885 init_z80_context(gen->z80, z_opts);
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
886 z80_assert_reset(gen->z80, 0);
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
887 #endif
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
888
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
889 gen->z80->system = gen;
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
890 gen->z80->mem_pointers[0] = z80_ram;
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
891 gen->z80->mem_pointers[1] = gen->z80->mem_pointers[2] = (uint8_t *)cart;
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
892
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
893 gen->cart = cart;
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
894 gen->work_ram = ram;
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
895 gen->zram = z80_ram;
971
e28f365605da Move mouse mode and capture state to emulation context so it persists properly when switching between the menu and the game
Michael Pavone <pavone@retrodev.com>
parents: 961
diff changeset
896 setup_io_devices(config, rom, gen);
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
897
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
898 gen->save_type = rom->save_type;
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
899 gen->save_type = rom->save_type;
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
900 if (gen->save_type != SAVE_NONE) {
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
901 gen->save_ram_mask = rom->save_mask;
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
902 gen->save_size = rom->save_size;
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
903 gen->save_storage = rom->save_buffer;
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
904 gen->eeprom_map = rom->eeprom_map;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
905 gen->num_eeprom = rom->num_eeprom;
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
906 if (gen->save_type == SAVE_I2C) {
770
a3b90f746dcf Broken EEPROM support
Michael Pavone <pavone@retrodev.com>
parents: 769
diff changeset
907 eeprom_init(&gen->eeprom, gen->save_storage, gen->save_size);
769
4638b88bc72d Initial work on I2C EEPROM implementation
Michael Pavone <pavone@retrodev.com>
parents: 767
diff changeset
908 }
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
909 } else {
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
910 gen->save_storage = NULL;
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
911 }
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
912
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
913 m68k_options *opts = malloc(sizeof(m68k_options));
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
914 init_m68k_opts(opts, rom->map, rom->map_chunks, MCLKS_PER_68K);
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
915 //TODO: make this configurable
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
916 opts->gen.flags |= M68K_OPT_BROKEN_READ_MODIFY;
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
917 gen->m68k = init_68k_context(opts);
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
918 gen->m68k->system = gen;
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
919
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
920 for (int i = 0; i < rom->map_chunks; i++)
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
921 {
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
922 if (rom->map[i].flags & MMAP_PTR_IDX) {
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
923 gen->m68k->mem_pointers[rom->map[i].ptr_index] = rom->map[i].buffer;
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
924 }
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
925 }
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
926
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
927 return gen;
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
928 }
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
929
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
930 void free_genesis(genesis_context *gen)
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
931 {
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
932 vdp_free(gen->vdp);
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
933 m68k_options_free(gen->m68k->options);
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
934 free(gen->m68k);
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
935 z80_options_free(gen->z80->options);
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
936 free(gen->z80);
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
937 ym_free(gen->ym);
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
938 psg_free(gen->psg);
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
939 free(gen->save_storage);
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
940 free(gen->save_dir);
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
941 }
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
942
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
943 void start_genesis(genesis_context *gen, char *statefile, uint8_t *debugger)
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
944 {
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
945
424
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
946 if (statefile) {
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
947 uint32_t pc = load_gst(gen, statefile);
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
948 if (!pc) {
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
949 fatal_error("Failed to load save state %s\n", statefile);
424
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
950 }
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 447
diff changeset
951 printf("Loaded %s\n", statefile);
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
952 if (debugger) {
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
953 insert_breakpoint(gen->m68k, pc, debugger);
424
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
954 }
451
b7c3b2d22858 Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents: 447
diff changeset
955 adjust_int_cycle(gen->m68k, gen->vdp);
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
956 start_68k_context(gen->m68k, pc);
424
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
957 } else {
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
958 if (debugger) {
752
296ddfcf0d43 Minor cleanup in init_run_cpu
Michael Pavone <pavone@retrodev.com>
parents: 736
diff changeset
959 uint32_t address = cart[2] << 16 | cart[3];
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
960 insert_breakpoint(gen->m68k, address, debugger);
424
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
961 }
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
962 m68k_reset(gen->m68k);
211
464513050c85 Small bit of cleanup
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
963 }
464513050c85 Small bit of cleanup
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
964 }
464513050c85 Small bit of cleanup
Mike Pavone <pavone@retrodev.com>
parents: 198
diff changeset
965
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
966 char *title;
340
58a085cfc6bd Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents: 338
diff changeset
967
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
968 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
969 {
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
970 if (title) {
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
971 free(title);
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
972 title = NULL;
340
58a085cfc6bd Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents: 338
diff changeset
973 }
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
974 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
975 render_update_caption(title);
340
58a085cfc6bd Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents: 338
diff changeset
976 }
58a085cfc6bd Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents: 338
diff changeset
977
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
978 void set_region(rom_info *info, uint8_t region)
341
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
979 {
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
980 if (!region) {
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
981 char * def_region = tern_find_ptr(config, "default_region");
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
982 if (def_region && (!info->regions || (info->regions & translate_region_char(toupper(*def_region))))) {
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
983 region = translate_region_char(toupper(*def_region));
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
984 } else {
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
985 region = info->regions;
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
986 }
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
987 }
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
988 if (region & REGION_E) {
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
989 version_reg = NO_DISK | EUR;
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
990 } else if (region & REGION_J) {
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
991 version_reg = NO_DISK | JAP;
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
992 } else {
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
993 version_reg = NO_DISK | USA;
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
994 }
341
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
995 }
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
996
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
997 void setup_saves(char *fname, rom_info *info, genesis_context *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
998 {
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
999 char * barename = basename_no_extension(fname);
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
1000 char const * parts[3] = {get_save_dir(), "/", barename};
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
1001 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
1002 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
1003 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
1004 }
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
1005 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
1006 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
1007 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
1008 save_filename = 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
1009 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
1010 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
1011 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
1012 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
1013 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
1014 if (info->save_type != SAVE_NONE) {
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
1015 FILE * f = fopen(save_filename, "rb");
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
1016 if (f) {
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
1017 uint32_t read = fread(context->save_storage, 1, info->save_size, f);
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
1018 fclose(f);
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
1019 if (read > 0) {
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
1020 printf("Loaded %s from %s\n", info->save_type == SAVE_I2C ? "EEPROM" : "SRAM", save_filename);
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
1021 }
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
1022 }
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
1023 atexit(persist_save);
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
1024 }
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
1025 }
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
1026
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1027 int main(int argc, char ** argv)
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1028 {
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
1029 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
1030 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
1031 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
1032 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
1033 int debug = 0;
407
c3abc4ada43d Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents: 405
diff changeset
1034 int ym_log = 0;
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1035 int loaded = 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
1036 uint8_t force_version = 0;
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
1037 char * romfname = NULL;
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
1038 FILE *address_log = NULL;
425
8b3ae850d1c4 Forgot to null initialize the statfile pointer
Mike Pavone <pavone@retrodev.com>
parents: 424
diff changeset
1039 char * statefile = NULL;
766
1b2f8280ba81 WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents: 765
diff changeset
1040 int rom_size;
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
1041 uint8_t * debuggerfun = NULL;
860
213c3b5160d0 Default to fullscreen on Android since windowed mode does not make sense there
Michael Pavone <pavone@retrodev.com>
parents: 846
diff changeset
1042 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
1043 uint8_t debug_target = 0;
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1044 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
1045 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
1046 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
1047 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
1048 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
1049 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
1050 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
1051 }
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
1052 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
1053 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
1054 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
1055 case 'd':
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
1056 debuggerfun = (uint8_t *)debugger;
885
e3f5ec336432 Allow menu ROM to be debugged
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
1057 //allow debugging the menu
e3f5ec336432 Allow menu ROM to be debugged
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
1058 if (argv[i][2] == 'm') {
e3f5ec336432 Allow menu ROM to be debugged
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
1059 debug_target = 1;
e3f5ec336432 Allow menu ROM to be debugged
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
1060 }
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
1061 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
1062 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
1063 gdb_remote_init();
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
1064 debuggerfun = (uint8_t *)gdb_debug_enter;
184
ebcbdd1c4cc8 Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents: 166
diff changeset
1065 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
1066 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
1067 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
1068 break;
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
1069 case 'g':
501
e1355aa80f4d Use OpenGL by default. Add OpenGL switch to help text
Mike Pavone <pavone@retrodev.com>
parents: 496
diff changeset
1070 use_gl = 0;
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
1071 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
1072 case 'l':
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
1073 address_log = fopen("address.log", "w");
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
1074 break;
464
226ed16b1fb6 Added version flag
Mike Pavone <pavone@retrodev.com>
parents: 463
diff changeset
1075 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
1076 info_message("blastem %s\n", BLASTEM_VERSION);
464
226ed16b1fb6 Added version flag
Mike Pavone <pavone@retrodev.com>
parents: 463
diff changeset
1077 return 0;
226ed16b1fb6 Added version flag
Mike Pavone <pavone@retrodev.com>
parents: 463
diff changeset
1078 break;
265
c6d12878ea93 Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 264
diff changeset
1079 case 'n':
c6d12878ea93 Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 264
diff changeset
1080 z80_enabled = 0;
c6d12878ea93 Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents: 264
diff changeset
1081 break;
341
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
1082 case 'r':
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
1083 i++;
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
1084 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
1085 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
1086 }
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1087 force_version = translate_region_char(toupper(argv[i][0]));
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1088 if (!force_version) {
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
1089 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
1090 }
6ad8e36de685 Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
1091 break;
424
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
1092 case 's':
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
1093 i++;
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
1094 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
1095 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
1096 }
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
1097 statefile = argv[i];
7e8e179116af Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents: 422
diff changeset
1098 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
1099 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
1100 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
1101 break;
407
c3abc4ada43d Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents: 405
diff changeset
1102 case 'y':
c3abc4ada43d Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents: 405
diff changeset
1103 ym_log = 1;
c3abc4ada43d Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents: 405
diff changeset
1104 break;
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1105 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
1106 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
1107 "Usage: blastem [OPTIONS] ROMFILE [WIDTH] [HEIGHT]\n"
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1108 "Options:\n"
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1109 " -h Print this help text\n"
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1110 " -r (J|U|E) Force region to Japan, US or Europe respectively\n"
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1111 " -f Start in fullscreen mode\n"
501
e1355aa80f4d Use OpenGL by default. Add OpenGL switch to help text
Mike Pavone <pavone@retrodev.com>
parents: 496
diff changeset
1112 " -g Disable OpenGL rendering\n"
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1113 " -s FILE Load a GST format savestate from FILE\n"
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1114 " -d Enter debugger on startup\n"
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1115 " -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
1116 " -v Display version number and exit\n"
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1117 " -l Log 68K code addresses (useful for assemblers)\n"
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1118 " -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
1119 );
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1120 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
1121 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
1122 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
1123 }
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1124 } else if (!loaded) {
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
1125 if (!(rom_size = load_rom(argv[i]))) {
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
1126 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
1127 }
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
1128 romfname = argv[i];
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1129 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
1130 } 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
1131 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
1132 } 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
1133 height = atoi(argv[i]);
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1134 }
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1135 }
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
1136 uint8_t menu = !loaded;
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1137 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
1138 //load menu
948
f87522554d7b Allow changing the 68K clock divider in the config file
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
1139 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
1140 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
1141 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
1142 }
875
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
1143 if (romfname[0] == '/') {
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
1144 if (!(rom_size = load_rom(romfname))) {
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
1145 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
1146 }
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
1147 } else {
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
1148 long fsize;
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
1149 cart = (uint16_t *)read_bundled_file(romfname, &fsize);
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
1150 if (!cart) {
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
1151 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
1152 }
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
1153 rom_size = nearest_pow2(fsize);
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
1154 if (rom_size > fsize) {
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
1155 cart = realloc(cart, rom_size);
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
1156 }
54ffba3768d6 Make menu stuff work on Android (theoretically)
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
1157 }
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
1158 //TODO: load relative to executable or from assets depending on platform
872
7022ba865cfd Initial work for allowing loading a ROM from menu
Michael Pavone <pavone@retrodev.com>
parents: 861
diff changeset
1159
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
1160 loaded = 1;
463
a1d298119153 Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents: 458
diff changeset
1161 }
948
f87522554d7b Allow changing the 68K clock divider in the config file
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
1162 char *m68k_divider = tern_find_path(config, "clocks\0m68k_divider\0").ptrval;
f87522554d7b Allow changing the 68K clock divider in the config file
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
1163 if (!m68k_divider) {
f87522554d7b Allow changing the 68K clock divider in the config file
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
1164 m68k_divider = "7";
f87522554d7b Allow changing the 68K clock divider in the config file
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
1165 }
f87522554d7b Allow changing the 68K clock divider in the config file
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
1166 MCLKS_PER_68K = atoi(m68k_divider);
f87522554d7b Allow changing the 68K clock divider in the config file
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
1167 if (!MCLKS_PER_68K) {
f87522554d7b Allow changing the 68K clock divider in the config file
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
1168 MCLKS_PER_68K = 7;
f87522554d7b Allow changing the 68K clock divider in the config file
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
1169 }
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
1170 ram = malloc(RAM_WORDS * sizeof(uint16_t));
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
1171 memmap_chunk base_map[] = {
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
1172 {0xE00000, 0x1000000, 0xFFFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, ram,
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
1173 NULL, NULL, NULL, 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
1174 {0xC00000, 0xE00000, 0x1FFFFF, 0, 0, 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
1175 (read_16_fun)vdp_port_read, (write_16_fun)vdp_port_write,
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
1176 (read_8_fun)vdp_port_read_b, (write_8_fun)vdp_port_write_b},
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
1177 {0xA00000, 0xA12000, 0x1FFFF, 0, 0, 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
1178 (read_16_fun)io_read_w, (write_16_fun)io_write_w,
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
1179 (read_8_fun)io_read, (write_8_fun)io_write}
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
1180 };
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
1181 tern_node *rom_db = load_rom_db();
767
ea525f600b1d SRAM detection from ROM header is no working correctly again
Michael Pavone <pavone@retrodev.com>
parents: 766
diff changeset
1182 rom_info info = configure_rom(rom_db, cart, rom_size, base_map, sizeof(base_map)/sizeof(base_map[0]));
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
1183 byteswap_rom(rom_size);
765
dc54387ee1cd Allow regions to be set in ROM DB. Prefer default region if it is one of the valid regions for the ROM.
Michael Pavone <pavone@retrodev.com>
parents: 764
diff changeset
1184 set_region(&info, force_version);
764
bb60259e8edf Initial work on ROM database
Michael Pavone <pavone@retrodev.com>
parents: 753
diff changeset
1185 update_title(info.name);
433
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
1186 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
1187 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
1188 if (config_width) {
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
1189 def_width = atoi(config_width);
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
1190 }
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
1191 if (!def_width) {
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
1192 def_width = 640;
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
1193 }
ed4d0017c041 Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents: 430
diff changeset
1194 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
1195 height = height < 240 ? (width/320) * 240 : height;
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 351
diff changeset
1196 uint32_t fps = 60;
342
13f994c88c34 Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents: 341
diff changeset
1197 if (version_reg & 0x40) {
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 351
diff changeset
1198 fps = 50;
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 351
diff changeset
1199 }
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 351
diff changeset
1200 if (!headless) {
719
019d27995e32 Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents: 718
diff changeset
1201 render_init(width, height, title, fps, 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
1202 }
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
1203
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
1204 genesis = alloc_init_genesis(&info, fps, (ym_log && !menu) ? YM_OPT_WAVE_LOG : 0);
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
1205 setup_saves(romfname, &info, genesis);
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
1206 if (menu) {
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
1207 menu_context = genesis;
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
1208 } else {
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
1209 genesis->m68k->options->address_log = address_log;
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
1210 game_context = genesis;
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
1211 }
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
1212
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1213 set_keybindings(genesis->ports);
885
e3f5ec336432 Allow menu ROM to be debugged
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
1214 start_genesis(genesis, menu ? NULL : statefile, menu == debug_target ? debuggerfun : NULL);
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
1215 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
1216 {
949
5e4fb650de58 Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
1217 if (genesis->should_exit) {
5e4fb650de58 Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
1218 break;
5e4fb650de58 Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
1219 }
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
1220 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
1221 if (game_context) {
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1222 if (game_context->save_type != SAVE_NONE) {
940
4f4f8385da8d Fix saving of SRAM/EEPROM when switching games in menu
Michael Pavone <pavone@retrodev.com>
parents: 939
diff changeset
1223 genesis = game_context;
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1224 persist_save();
940
4f4f8385da8d Fix saving of SRAM/EEPROM when switching games in menu
Michael Pavone <pavone@retrodev.com>
parents: 939
diff changeset
1225 genesis = menu_context;
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1226 }
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1227 free(game_context->cart);
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1228 base_map[0].buffer = ram = game_context->work_ram;
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1229 } else {
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1230 base_map[0].buffer = ram = malloc(RAM_WORDS * sizeof(uint16_t));
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1231 }
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1232 memset(ram, 0, RAM_WORDS * sizeof(uint16_t));
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
1233 if (!(rom_size = load_rom(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
1234 fatal_error("Failed to open %s for reading\n", 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
1235 }
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
1236 info = configure_rom(rom_db, cart, rom_size, base_map, sizeof(base_map)/sizeof(base_map[0]));
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
1237 byteswap_rom(rom_size);
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
1238 set_region(&info, force_version);
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
1239 update_title(info.name);
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
1240 if (!game_context) {
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
1241 //start a new arena and save old one in suspended genesis context
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
1242 genesis->arena = start_new_arena();
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
1243 } else {
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1244 genesis->arena = set_current_arena(game_context->arena);
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1245 mark_all_free();
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1246 free_genesis(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
1247 }
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1248 //allocate new genesis context
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1249 game_context = alloc_init_genesis(&info, fps, ym_log ? YM_OPT_WAVE_LOG : 0);
957
1618d3676a35 Save state menu WIP
Michael Pavone <pavone@retrodev.com>
parents: 956
diff changeset
1250 menu_context->next_context = game_context;
1618d3676a35 Save state menu WIP
Michael Pavone <pavone@retrodev.com>
parents: 956
diff changeset
1251 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
1252 setup_saves(menu_context->next_rom, &info, 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
1253 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
1254 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
1255 menu = 0;
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
1256 genesis = game_context;
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
1257 genesis->m68k->options->address_log = address_log;
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1258 map_all_bindings(genesis->ports);
885
e3f5ec336432 Allow menu ROM to be debugged
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
1259 start_genesis(genesis, statefile, menu == debug_target ? debuggerfun : NULL);
949
5e4fb650de58 Make Exit option in menu work
Michael Pavone <pavone@retrodev.com>
parents: 940
diff changeset
1260 } else if (menu && 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
1261 genesis->arena = set_current_arena(game_context->arena);
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
1262 genesis = game_context;
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
1263 cart = genesis->cart;
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
1264 ram = genesis->work_ram;
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
1265 menu = 0;
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1266 map_all_bindings(genesis->ports);
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
1267 resume_68k(genesis->m68k);
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
1268 } else if (!menu && menu_context) {
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
1269 genesis->arena = set_current_arena(menu_context->arena);
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
1270 genesis = menu_context;
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
1271 cart = genesis->cart;
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
1272 ram = genesis->work_ram;
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
1273 menu = 1;
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 883
diff changeset
1274 map_all_bindings(genesis->ports);
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
1275 resume_68k(genesis->m68k);
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
1276 } 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
1277 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
1278 }
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
1279 }
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
1280
88
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1281 return 0;
c339559f1d4f Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
1282 }