Mercurial > repos > blastem
annotate genesis.c @ 2386:9f178feb3cb0
Prefix most hex-formatted values output by debugger with $ for consistency with number literal parsing
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 21 Nov 2023 21:35:14 -0800 |
parents | 03e6ac327ba0 |
children | 664c3e749428 |
rev | line source |
---|---|
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 /* |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 Copyright 2013-2016 Michael Pavone |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 This file is part of BlastEm. |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
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. |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 */ |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "genesis.h" |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
7 #include "segacd.h" |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include "blastem.h" |
1414
d94855080529
Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
9 #include "nor.h" |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include <stdlib.h> |
1188
448ce87b87fc
Fix missing include that prevented building Windows version
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
11 #include <ctype.h> |
1204
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
12 #include <time.h> |
1220
1e7977460d18
Add mising include in genesis.c so the Windows build works again
Michael Pavone <pavone@retrodev.com>
parents:
1215
diff
changeset
|
13 #include <string.h> |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 #include "render.h" |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 #include "gst.h" |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 #include "util.h" |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
17 #include "debug.h" |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
18 #include "gdb_remote.h" |
1478
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1471
diff
changeset
|
19 #include "saves.h" |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
20 #include "bindings.h" |
1610 | 21 #include "jcart.h" |
1901
5433252329fb
Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents:
1889
diff
changeset
|
22 #include "config.h" |
1946 | 23 #include "event_log.h" |
2083
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
24 #include "paths.h" |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 #define MCLKS_NTSC 53693175 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 #define MCLKS_PAL 53203395 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 uint32_t MCLKS_PER_68K; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 #define MCLKS_PER_YM 7 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 #define MCLKS_PER_Z80 15 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 #define MCLKS_PER_PSG (MCLKS_PER_Z80*16) |
1291
f17fe0d00626
Adjust Z80 interrupt pulse duration to match hardware measurements
Michael Pavone <pavone@retrodev.com>
parents:
1288
diff
changeset
|
32 #define Z80_INT_PULSE_MCLKS 2573 //measured value is ~171.5 Z80 clocks |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 #define DEFAULT_SYNC_INTERVAL MCLKS_LINE |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 #define DEFAULT_LOWPASS_CUTOFF 3390 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 //TODO: Figure out the exact value for this |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 #define LINES_NTSC 262 |
1556
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
38 #define LINES_PAL 313 |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 |
1688
395f684c5379
Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
40 #ifdef IS_LIB |
1927
9fd4bedc1a31
Update libretro target to use render_audio shared audio code
Mike Pavone <pavone@retrodev.com>
parents:
1915
diff
changeset
|
41 #define MAX_SOUND_CYCLES (MCLKS_PER_YM*NUM_OPERATORS*6*4) |
1688
395f684c5379
Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
42 #else |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
43 #define MAX_SOUND_CYCLES 100000 |
1688
395f684c5379
Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
44 #endif |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
46 #ifdef NEW_CORE |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
47 #define Z80_CYCLE cycles |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
48 #define Z80_OPTS opts |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
49 #define z80_handle_code_write(...) |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
50 #else |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
51 #define Z80_CYCLE current_cycle |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
52 #define Z80_OPTS options |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
53 #endif |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
54 |
1946 | 55 void genesis_serialize(genesis_context *gen, serialize_buffer *buf, uint32_t m68k_pc, uint8_t all) |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
56 { |
1946 | 57 if (all) { |
58 start_section(buf, SECTION_68000); | |
59 m68k_serialize(gen->m68k, m68k_pc, buf); | |
60 end_section(buf); | |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
61 |
1946 | 62 start_section(buf, SECTION_Z80); |
63 z80_serialize(gen->z80, buf); | |
64 end_section(buf); | |
65 } | |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
66 |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
67 start_section(buf, SECTION_VDP); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
68 vdp_serialize(gen->vdp, buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
69 end_section(buf); |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
70 |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
71 start_section(buf, SECTION_YM2612); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
72 ym_serialize(gen->ym, buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
73 end_section(buf); |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
74 |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
75 start_section(buf, SECTION_PSG); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
76 psg_serialize(gen->psg, buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
77 end_section(buf); |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
78 |
1946 | 79 if (all) { |
80 start_section(buf, SECTION_GEN_BUS_ARBITER); | |
81 save_int8(buf, gen->z80->reset); | |
82 save_int8(buf, gen->z80->busreq); | |
83 save_int16(buf, gen->z80_bank_reg); | |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
84 //I think the refresh logic may technically be part of the VDP, but whatever |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
85 save_int32(buf, gen->last_sync_cycle); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
86 save_int32(buf, gen->refresh_counter); |
1946 | 87 end_section(buf); |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
88 |
1946 | 89 start_section(buf, SECTION_SEGA_IO_1); |
90 io_serialize(gen->io.ports, buf); | |
91 end_section(buf); | |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
92 |
1946 | 93 start_section(buf, SECTION_SEGA_IO_2); |
94 io_serialize(gen->io.ports + 1, buf); | |
95 end_section(buf); | |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
96 |
1946 | 97 start_section(buf, SECTION_SEGA_IO_EXT); |
98 io_serialize(gen->io.ports + 2, buf); | |
99 end_section(buf); | |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
100 |
1946 | 101 start_section(buf, SECTION_MAIN_RAM); |
102 save_int8(buf, RAM_WORDS * 2 / 1024); | |
103 save_buffer16(buf, gen->work_ram, RAM_WORDS); | |
104 end_section(buf); | |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
105 |
1946 | 106 start_section(buf, SECTION_SOUND_RAM); |
107 save_int8(buf, Z80_RAM_BYTES / 1024); | |
108 save_buffer8(buf, gen->zram, Z80_RAM_BYTES); | |
109 end_section(buf); | |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
110 |
2039
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
111 if (gen->version_reg & 0xF) { |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
112 //only save TMSS info if it's present |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
113 //that will allow a state saved on a model lacking TMSS |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
114 //to be loaded on a model that has it |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
115 start_section(buf, SECTION_TMSS); |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
116 save_int8(buf, gen->tmss); |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
117 save_buffer16(buf, gen->tmss_lock, 2); |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
118 end_section(buf); |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
119 } |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
120 |
1946 | 121 cart_serialize(&gen->header, buf); |
122 } | |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
123 if (gen->expansion) { |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
124 segacd_context *cd = gen->expansion; |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
125 segacd_serialize(cd, buf, all); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
126 } |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
127 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
128 |
1690
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
129 static uint8_t *serialize(system_header *sys, size_t *size_out) |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
130 { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
131 genesis_context *gen = (genesis_context *)sys; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
132 uint32_t address; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
133 if (gen->m68k->resume_pc) { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
134 gen->m68k->target_cycle = gen->m68k->current_cycle; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
135 gen->header.save_state = SERIALIZE_SLOT+1; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
136 resume_68k(gen->m68k); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
137 if (size_out) { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
138 *size_out = gen->serialize_size; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
139 } |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
140 return gen->serialize_tmp; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
141 } else { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
142 serialize_buffer state; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
143 init_serialize(&state); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
144 uint32_t address = read_word(4, (void **)gen->m68k->mem_pointers, &gen->m68k->options->gen, gen->m68k) << 16; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
145 address |= read_word(6, (void **)gen->m68k->mem_pointers, &gen->m68k->options->gen, gen->m68k); |
1946 | 146 genesis_serialize(gen, &state, address, 1); |
1690
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
147 if (size_out) { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
148 *size_out = state.size; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
149 } |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
150 return state.data; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
151 } |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
152 } |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
153 |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
154 static void ram_deserialize(deserialize_buffer *buf, void *vgen) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
155 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
156 genesis_context *gen = vgen; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
157 uint32_t ram_size = load_int8(buf) * 1024 / 2; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
158 if (ram_size > RAM_WORDS) { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
159 fatal_error("State has a RAM size of %d bytes", ram_size * 2); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
160 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
161 load_buffer16(buf, gen->work_ram, ram_size); |
1452
f284ad74afe1
Make initial bank register state stored in bank_regs match what is put in to mem_pointers for the sega/SSF2 mapper. Invalidate RAM code ranges on RAM deserialization
Michael Pavone <pavone@retrodev.com>
parents:
1449
diff
changeset
|
162 m68k_invalidate_code_range(gen->m68k, 0xE00000, 0x1000000); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
163 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
164 |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
165 static void zram_deserialize(deserialize_buffer *buf, void *vgen) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
166 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
167 genesis_context *gen = vgen; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
168 uint32_t ram_size = load_int8(buf) * 1024; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
169 if (ram_size > Z80_RAM_BYTES) { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
170 fatal_error("State has a Z80 RAM size of %d bytes", ram_size); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
171 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
172 load_buffer8(buf, gen->zram, ram_size); |
1452
f284ad74afe1
Make initial bank register state stored in bank_regs match what is put in to mem_pointers for the sega/SSF2 mapper. Invalidate RAM code ranges on RAM deserialization
Michael Pavone <pavone@retrodev.com>
parents:
1449
diff
changeset
|
173 z80_invalidate_code_range(gen->z80, 0, 0x4000); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
174 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
175 |
1445
349d50930c03
Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1444
diff
changeset
|
176 static void update_z80_bank_pointer(genesis_context *gen) |
349d50930c03
Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1444
diff
changeset
|
177 { |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
178 if (gen->z80_bank_reg < 0x140) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
179 gen->z80->mem_pointers[1] = get_native_pointer(gen->z80_bank_reg << 15, (void **)gen->m68k->mem_pointers, &gen->m68k->options->gen); |
1445
349d50930c03
Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1444
diff
changeset
|
180 } else { |
349d50930c03
Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1444
diff
changeset
|
181 gen->z80->mem_pointers[1] = NULL; |
349d50930c03
Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1444
diff
changeset
|
182 } |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
183 z80_invalidate_code_range(gen->z80, 0x8000, 0xFFFF); |
1445
349d50930c03
Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1444
diff
changeset
|
184 } |
349d50930c03
Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1444
diff
changeset
|
185 |
1440
7d4483944d4d
Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
Michael Pavone <pavone@retrodev.com>
parents:
1433
diff
changeset
|
186 static void bus_arbiter_deserialize(deserialize_buffer *buf, void *vgen) |
7d4483944d4d
Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
Michael Pavone <pavone@retrodev.com>
parents:
1433
diff
changeset
|
187 { |
7d4483944d4d
Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
Michael Pavone <pavone@retrodev.com>
parents:
1433
diff
changeset
|
188 genesis_context *gen = vgen; |
7d4483944d4d
Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
Michael Pavone <pavone@retrodev.com>
parents:
1433
diff
changeset
|
189 gen->z80->reset = load_int8(buf); |
7d4483944d4d
Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
Michael Pavone <pavone@retrodev.com>
parents:
1433
diff
changeset
|
190 gen->z80->busreq = load_int8(buf); |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
191 gen->z80_bank_reg = load_int16(buf) & 0x1FF; |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
192 if ((buf->size - buf->cur_pos) >= 2 * sizeof(uint32_t)) { |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
193 gen->last_sync_cycle = load_int32(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
194 gen->refresh_counter = load_int32(buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
195 } else { |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
196 //save state is from an older version of BlastEm that lacks these fields |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
197 //set them to reasonable values |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
198 gen->last_sync_cycle = gen->m68k->current_cycle; |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
199 gen->refresh_counter = 0; |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
200 } |
1440
7d4483944d4d
Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
Michael Pavone <pavone@retrodev.com>
parents:
1433
diff
changeset
|
201 } |
7d4483944d4d
Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
Michael Pavone <pavone@retrodev.com>
parents:
1433
diff
changeset
|
202 |
2039
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
203 static void tmss_deserialize(deserialize_buffer *buf, void *vgen) |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
204 { |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
205 genesis_context *gen = vgen; |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
206 gen->tmss = load_int8(buf); |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
207 load_buffer16(buf, gen->tmss_lock, 2); |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
208 } |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
209 |
1636
d2775a242dc6
Make sure M68K sync and target cycles are updated after loading a savestate. Fixes an issue in which loading a savestate would result in things being unresponsive until emulation cycle caught up to whatever the pre-state load sync cycle was
Mike Pavone <pavone@retrodev.com>
parents:
1631
diff
changeset
|
210 static void adjust_int_cycle(m68k_context * context, vdp_context * v_context); |
2039
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
211 static void check_tmss_lock(genesis_context *gen); |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
212 static void toggle_tmss_rom(genesis_context *gen); |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
213 #include "m68k_internal.h" //needed for get_native_address_trans, should be eliminated once handling of PC is cleaned up |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
214 void genesis_deserialize(deserialize_buffer *buf, genesis_context *gen) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
215 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
216 register_section_handler(buf, (section_handler){.fun = m68k_deserialize, .data = gen->m68k}, SECTION_68000); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
217 register_section_handler(buf, (section_handler){.fun = z80_deserialize, .data = gen->z80}, SECTION_Z80); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
218 register_section_handler(buf, (section_handler){.fun = vdp_deserialize, .data = gen->vdp}, SECTION_VDP); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
219 register_section_handler(buf, (section_handler){.fun = ym_deserialize, .data = gen->ym}, SECTION_YM2612); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
220 register_section_handler(buf, (section_handler){.fun = psg_deserialize, .data = gen->psg}, SECTION_PSG); |
1440
7d4483944d4d
Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
Michael Pavone <pavone@retrodev.com>
parents:
1433
diff
changeset
|
221 register_section_handler(buf, (section_handler){.fun = bus_arbiter_deserialize, .data = gen}, SECTION_GEN_BUS_ARBITER); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
222 register_section_handler(buf, (section_handler){.fun = io_deserialize, .data = gen->io.ports}, SECTION_SEGA_IO_1); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
223 register_section_handler(buf, (section_handler){.fun = io_deserialize, .data = gen->io.ports + 1}, SECTION_SEGA_IO_2); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
224 register_section_handler(buf, (section_handler){.fun = io_deserialize, .data = gen->io.ports + 2}, SECTION_SEGA_IO_EXT); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
225 register_section_handler(buf, (section_handler){.fun = ram_deserialize, .data = gen}, SECTION_MAIN_RAM); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
226 register_section_handler(buf, (section_handler){.fun = zram_deserialize, .data = gen}, SECTION_SOUND_RAM); |
1444
14a2834d010c
Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1440
diff
changeset
|
227 register_section_handler(buf, (section_handler){.fun = cart_deserialize, .data = gen}, SECTION_MAPPER); |
2039
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
228 register_section_handler(buf, (section_handler){.fun = tmss_deserialize, .data = gen}, SECTION_TMSS); |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
229 if (gen->expansion) { |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
230 segacd_context *cd = gen->expansion; |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
231 segacd_register_section_handlers(cd, buf); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
232 } |
2039
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
233 uint8_t tmss_old = gen->tmss; |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
234 gen->tmss = 0xFF; |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
235 while (buf->cur_pos < buf->size) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
236 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
237 load_section(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
238 } |
2039
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
239 if (gen->version_reg & 0xF) { |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
240 if (gen->tmss == 0xFF) { |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
241 //state lacked a TMSS section, assume that the game ROM is mapped in |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
242 //and that the VDP is unlocked |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
243 gen->tmss_lock[0] = 0x5345; |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
244 gen->tmss_lock[1] = 0x4741; |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
245 gen->tmss = 1; |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
246 } |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
247 if (gen->tmss != tmss_old) { |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
248 toggle_tmss_rom(gen); |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
249 } |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
250 check_tmss_lock(gen); |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
251 } |
1445
349d50930c03
Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1444
diff
changeset
|
252 update_z80_bank_pointer(gen); |
1636
d2775a242dc6
Make sure M68K sync and target cycles are updated after loading a savestate. Fixes an issue in which loading a savestate would result in things being unresponsive until emulation cycle caught up to whatever the pre-state load sync cycle was
Mike Pavone <pavone@retrodev.com>
parents:
1631
diff
changeset
|
253 adjust_int_cycle(gen->m68k, gen->vdp); |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
254 //HACK: Fix this once PC/IR is represented in a better way in 68K core |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
255 //Would be better for this hack to live in side the 68K core itself, but it's better to do it |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
256 //after RAM has been loaded to avoid any unnecessary retranslation |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
257 gen->m68k->resume_pc = get_native_address_trans(gen->m68k, gen->m68k->last_prefetch_address); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
258 if (gen->expansion) { |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
259 segacd_context *cd = gen->expansion; |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
260 cd->m68k->resume_pc = get_native_address_trans(cd->m68k, cd->m68k->last_prefetch_address); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
261 } |
1690
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
262 free(buf->handlers); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
263 buf->handlers = NULL; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
264 } |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
265 |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
266 static void deserialize(system_header *sys, uint8_t *data, size_t size) |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
267 { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
268 genesis_context *gen = (genesis_context *)sys; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
269 deserialize_buffer buffer; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
270 init_deserialize(&buffer, data, size); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
271 genesis_deserialize(&buffer, gen); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
272 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
273 |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 uint16_t read_dma_value(uint32_t address) |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 { |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
276 genesis_context *genesis = (genesis_context *)current_system; |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
277 address *= 2; |
1420
975b5b7eaa77
Fix DMA from byte-wide SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1416
diff
changeset
|
278 //TODO: Figure out what happens when you try to DMA from weird adresses like IO or banked Z80 area |
975b5b7eaa77
Fix DMA from byte-wide SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1416
diff
changeset
|
279 if ((address >= 0xA00000 && address < 0xB00000) || (address >= 0xC00000 && address <= 0xE00000)) { |
975b5b7eaa77
Fix DMA from byte-wide SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1416
diff
changeset
|
280 return 0; |
975b5b7eaa77
Fix DMA from byte-wide SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1416
diff
changeset
|
281 } |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
282 if (genesis->expansion) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
283 segacd_context *cd = genesis->expansion; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
284 uint32_t word_ram = cd->base + 0x200000; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
285 uint32_t word_ram_end = cd->base + 0x240000; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
286 if (address >= word_ram && address < word_ram_end) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
287 //FIXME: first word should just be garbage |
2336
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
288 if (!cd->has_vdp_dma_value) { |
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
289 cd->vdp_dma_value = read_word(genesis->m68k->last_prefetch_address, (void **)genesis->m68k->mem_pointers, &genesis->m68k->options->gen, genesis->m68k); |
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
290 cd->has_vdp_dma_value = 1; |
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
291 } |
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
292 uint16_t ret = cd->vdp_dma_value; |
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
293 cd->vdp_dma_value = read_word(address, (void **)genesis->m68k->mem_pointers, &genesis->m68k->options->gen, genesis->m68k); |
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
294 return ret; |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
295 } |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
296 } |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
297 |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
298 return read_word(address, (void **)genesis->m68k->mem_pointers, &genesis->m68k->options->gen, genesis->m68k); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
300 |
2336
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
301 void vdp_dma_started(void) |
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
302 { |
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
303 genesis_context *genesis = (genesis_context *)current_system; |
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
304 if (genesis->expansion) { |
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
305 segacd_context *cd = genesis->expansion; |
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
306 cd->has_vdp_dma_value = 0; |
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
307 } |
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
308 } |
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
309 |
83f5529086c5
Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents:
2335
diff
changeset
|
310 |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
311 static uint16_t get_open_bus_value(system_header *system) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
312 { |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
313 genesis_context *genesis = (genesis_context *)system; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
314 return read_dma_value(genesis->m68k->last_prefetch_address/2); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
315 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
317 static void adjust_int_cycle(m68k_context * context, vdp_context * v_context) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 //static int old_int_cycle = CYCLE_NEVER; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 genesis_context *gen = context->system; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
321 if (context->sync_cycle - context->current_cycle > gen->max_cycles) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
322 context->sync_cycle = context->current_cycle + gen->max_cycles; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
323 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
324 context->int_cycle = CYCLE_NEVER; |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
325 uint8_t mask = context->status & 0x7; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
326 if (mask < 6) { |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
327 uint32_t next_vint = vdp_next_vint(v_context); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
328 if (next_vint != CYCLE_NEVER) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
329 context->int_cycle = next_vint; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
330 context->int_num = 6; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
331 } |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
332 if (mask < 4) { |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
333 uint32_t next_hint = vdp_next_hint(v_context); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 if (next_hint != CYCLE_NEVER) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
335 next_hint = next_hint < context->current_cycle ? context->current_cycle : next_hint; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
336 if (next_hint < context->int_cycle) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
337 context->int_cycle = next_hint; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
338 context->int_num = 4; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
339 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
340 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
341 } |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
342 if (mask < 2 && (v_context->regs[REG_MODE_3] & BIT_EINT_EN)) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
343 uint32_t next_eint_port0 = io_next_interrupt(gen->io.ports, context->current_cycle); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
344 uint32_t next_eint_port1 = io_next_interrupt(gen->io.ports + 1, context->current_cycle); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
345 uint32_t next_eint_port2 = io_next_interrupt(gen->io.ports + 2, context->current_cycle); |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
346 uint32_t next_eint = next_eint_port0 < next_eint_port1 |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
347 ? (next_eint_port0 < next_eint_port2 ? next_eint_port0 : next_eint_port2) |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
348 : (next_eint_port1 < next_eint_port2 ? next_eint_port1 : next_eint_port2); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
349 if (next_eint != CYCLE_NEVER) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
350 next_eint = next_eint < context->current_cycle ? context->current_cycle : next_eint; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
351 if (next_eint < context->int_cycle) { |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
352 context->int_cycle = next_eint; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
353 context->int_num = 2; |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
354 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
355 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
356 } |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
357 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
358 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
359 if (context->int_cycle > context->current_cycle && context->int_pending == INT_PENDING_SR_CHANGE) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
360 context->int_pending = INT_PENDING_NONE; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
361 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
362 /*if (context->int_cycle != old_int_cycle) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
363 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); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
364 old_int_cycle = context->int_cycle; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
365 }*/ |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
366 |
1304
5b90d7669eee
Fix exit trace mode edge case. Call do_sync if trace mode bit is changed in eori sr
Michael Pavone <pavone@retrodev.com>
parents:
1303
diff
changeset
|
367 if (context->status & M68K_STATUS_TRACE || context->trace_pending) { |
1303
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1291
diff
changeset
|
368 context->target_cycle = context->current_cycle; |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1291
diff
changeset
|
369 return; |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1291
diff
changeset
|
370 } |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
371 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
372 context->target_cycle = context->int_cycle < context->sync_cycle ? context->int_cycle : context->sync_cycle; |
1998
0740d90812ee
Enter debugger when a VDP data port read would cause a CPU lockup
Mike Pavone <pavone@retrodev.com>
parents:
1987
diff
changeset
|
373 if (context->should_return || gen->header.enter_debugger) { |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
374 context->target_cycle = context->current_cycle; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
375 } else if (context->target_cycle < context->current_cycle) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
376 //Changes to SR can result in an interrupt cycle that's in the past |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
377 //This can cause issues with the implementation of STOP though |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
378 context->target_cycle = context->current_cycle; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
379 } |
1364
30123ca5856c
Added some code to try and prevent Z80 accesses and refresh cycles from screwing up interrupt latency more than on hardware
Michael Pavone <pavone@retrodev.com>
parents:
1348
diff
changeset
|
380 if (context->target_cycle == context->int_cycle) { |
30123ca5856c
Added some code to try and prevent Z80 accesses and refresh cycles from screwing up interrupt latency more than on hardware
Michael Pavone <pavone@retrodev.com>
parents:
1348
diff
changeset
|
381 //Currently delays from Z80 access and refresh are applied only when we sync |
30123ca5856c
Added some code to try and prevent Z80 accesses and refresh cycles from screwing up interrupt latency more than on hardware
Michael Pavone <pavone@retrodev.com>
parents:
1348
diff
changeset
|
382 //this can cause extra latency when it comes to interrupts |
30123ca5856c
Added some code to try and prevent Z80 accesses and refresh cycles from screwing up interrupt latency more than on hardware
Michael Pavone <pavone@retrodev.com>
parents:
1348
diff
changeset
|
383 //to prevent this code forces some extra synchronization in the period immediately before an interrupt |
30123ca5856c
Added some code to try and prevent Z80 accesses and refresh cycles from screwing up interrupt latency more than on hardware
Michael Pavone <pavone@retrodev.com>
parents:
1348
diff
changeset
|
384 if ((context->target_cycle - context->current_cycle) > gen->int_latency_prev1) { |
30123ca5856c
Added some code to try and prevent Z80 accesses and refresh cycles from screwing up interrupt latency more than on hardware
Michael Pavone <pavone@retrodev.com>
parents:
1348
diff
changeset
|
385 context->target_cycle = context->sync_cycle = context->int_cycle - gen->int_latency_prev1; |
30123ca5856c
Added some code to try and prevent Z80 accesses and refresh cycles from screwing up interrupt latency more than on hardware
Michael Pavone <pavone@retrodev.com>
parents:
1348
diff
changeset
|
386 } else if ((context->target_cycle - context->current_cycle) > gen->int_latency_prev2) { |
30123ca5856c
Added some code to try and prevent Z80 accesses and refresh cycles from screwing up interrupt latency more than on hardware
Michael Pavone <pavone@retrodev.com>
parents:
1348
diff
changeset
|
387 context->target_cycle = context->sync_cycle = context->int_cycle - gen->int_latency_prev2; |
30123ca5856c
Added some code to try and prevent Z80 accesses and refresh cycles from screwing up interrupt latency more than on hardware
Michael Pavone <pavone@retrodev.com>
parents:
1348
diff
changeset
|
388 } else { |
30123ca5856c
Added some code to try and prevent Z80 accesses and refresh cycles from screwing up interrupt latency more than on hardware
Michael Pavone <pavone@retrodev.com>
parents:
1348
diff
changeset
|
389 context->target_cycle = context->sync_cycle = context->current_cycle; |
30123ca5856c
Added some code to try and prevent Z80 accesses and refresh cycles from screwing up interrupt latency more than on hardware
Michael Pavone <pavone@retrodev.com>
parents:
1348
diff
changeset
|
390 } |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
391 |
1364
30123ca5856c
Added some code to try and prevent Z80 accesses and refresh cycles from screwing up interrupt latency more than on hardware
Michael Pavone <pavone@retrodev.com>
parents:
1348
diff
changeset
|
392 } |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
393 /*printf("Cyc: %d, Trgt: %d, Int Cyc: %d, Int: %d, Mask: %X, V: %d, H: %d, HICount: %d, HReg: %d, Line: %d\n", |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
394 context->current_cycle, context->target_cycle, context->int_cycle, context->int_num, (context->status & 0x7), |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
395 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);*/ |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
396 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
397 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
398 //#define DO_DEBUG_PRINT |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
399 #ifdef DO_DEBUG_PRINT |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
400 #define dprintf printf |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
401 #define dputs puts |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
402 #else |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 #define dprintf |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
404 #define dputs |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
405 #endif |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
406 |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
407 static void z80_next_int_pulse(z80_context * z_context) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 { |
1108
87114df913ec
Fix Z80 interrupt pulse duration. Fixes inconsistent music playback speed in Sonic 2 introduced in 0.4.1
Michael Pavone <pavone@retrodev.com>
parents:
1105
diff
changeset
|
409 genesis_context * gen = z_context->system; |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
410 #ifdef NEW_CORE |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
411 z_context->int_cycle = vdp_next_vint_z80(gen->vdp); |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
412 z_context->int_end_cycle = z_context->int_cycle + Z80_INT_PULSE_MCLKS; |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
413 z_context->int_value = 0xFF; |
1766
1dc718581aac
Fix Z80 interrupts in Gen/MD mode when using new core. Disable CPU debug log in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1753
diff
changeset
|
414 z80_sync_cycle(z_context, z_context->sync_cycle); |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
415 #else |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
416 z_context->int_pulse_start = vdp_next_vint_z80(gen->vdp); |
1291
f17fe0d00626
Adjust Z80 interrupt pulse duration to match hardware measurements
Michael Pavone <pavone@retrodev.com>
parents:
1288
diff
changeset
|
417 z_context->int_pulse_end = z_context->int_pulse_start + Z80_INT_PULSE_MCLKS; |
1471
2e6320d261ff
Implemented Z80 IM 2 and attempted correct intack cycle delay
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
418 z_context->im2_vector = 0xFF; |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
419 #endif |
1108
87114df913ec
Fix Z80 interrupt pulse duration. Fixes inconsistent music playback speed in Sonic 2 introduced in 0.4.1
Michael Pavone <pavone@retrodev.com>
parents:
1105
diff
changeset
|
420 } |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 |
2184
408fb8a7e990
Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2179
diff
changeset
|
422 static void sync_z80(genesis_context *gen, uint32_t mclks) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
423 { |
2184
408fb8a7e990
Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2179
diff
changeset
|
424 z80_context *z_context = gen->z80; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 #ifndef NO_Z80 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 if (z80_enabled) { |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
427 #ifdef NEW_CORE |
1766
1dc718581aac
Fix Z80 interrupts in Gen/MD mode when using new core. Disable CPU debug log in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1753
diff
changeset
|
428 if (z_context->int_cycle == 0xFFFFFFFFU) { |
1dc718581aac
Fix Z80 interrupts in Gen/MD mode when using new core. Disable CPU debug log in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1753
diff
changeset
|
429 z80_next_int_pulse(z_context); |
1dc718581aac
Fix Z80 interrupts in Gen/MD mode when using new core. Disable CPU debug log in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1753
diff
changeset
|
430 } |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
431 #endif |
2184
408fb8a7e990
Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2179
diff
changeset
|
432 if (gen->enter_z80_debugger && !z_context->reset && !z_context->busack) { |
408fb8a7e990
Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2179
diff
changeset
|
433 while (!z_context->pc) { |
408fb8a7e990
Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2179
diff
changeset
|
434 z80_run(z_context, z_context->current_cycle + 4); |
408fb8a7e990
Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2179
diff
changeset
|
435 } |
408fb8a7e990
Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2179
diff
changeset
|
436 gen->enter_z80_debugger = 0; |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2286
diff
changeset
|
437 #ifndef IS_LIB |
2184
408fb8a7e990
Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2179
diff
changeset
|
438 zdebugger(z_context, z_context->pc); |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2286
diff
changeset
|
439 #endif |
2184
408fb8a7e990
Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2179
diff
changeset
|
440 } |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
441 z80_run(z_context, mclks); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
442 } else |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
443 #endif |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
444 { |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
445 z_context->Z80_CYCLE = mclks; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
446 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
447 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
448 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
449 static void sync_sound(genesis_context * gen, uint32_t target) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
450 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
451 //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); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
452 while (target > gen->psg->cycles && target - gen->psg->cycles > MAX_SOUND_CYCLES) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
453 uint32_t cur_target = gen->psg->cycles + MAX_SOUND_CYCLES; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
454 //printf("Running PSG to cycle %d\n", cur_target); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
455 psg_run(gen->psg, cur_target); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
456 //printf("Running YM-2612 to cycle %d\n", cur_target); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
457 ym_run(gen->ym, cur_target); |
2080 | 458 if (gen->expansion) { |
459 scd_run(gen->expansion, gen_cycle_to_scd(cur_target, gen)); | |
460 } | |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
461 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
462 psg_run(gen->psg, target); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
463 ym_run(gen->ym, target); |
2080 | 464 if (gen->expansion) { |
465 scd_run(gen->expansion, gen_cycle_to_scd(target, gen)); | |
466 } | |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
467 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
468 //printf("Target: %d, YM bufferpos: %d, PSG bufferpos: %d\n", target, gen->ym->buffer_pos, gen->psg->buffer_pos * 2); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
469 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
470 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
471 #define REFRESH_INTERVAL 128 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
472 #define REFRESH_DELAY 2 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
473 |
2350
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
474 void gen_update_refresh(m68k_context *context) |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
475 { |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
476 uint32_t interval = MCLKS_PER_68K * REFRESH_INTERVAL; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
477 genesis_context *gen = context->system; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
478 gen->refresh_counter += context->current_cycle - gen->last_sync_cycle; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
479 gen->last_sync_cycle = context->current_cycle; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
480 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (gen->refresh_counter / interval); |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
481 gen->refresh_counter = gen->refresh_counter % interval; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
482 } |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
483 |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
484 void gen_update_refresh_free_access(m68k_context *context) |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
485 { |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
486 genesis_context *gen = context->system; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
487 uint32_t before = context->current_cycle - 4*MCLKS_PER_68K; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
488 if (before < gen->last_sync_cycle) { |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
489 return; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
490 } |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
491 //Add refresh delays for any accesses that happened beofre the current one |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
492 gen->refresh_counter += before - gen->last_sync_cycle; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
493 uint32_t interval = MCLKS_PER_68K * REFRESH_INTERVAL; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
494 uint32_t delay = REFRESH_DELAY * MCLKS_PER_68K * (gen->refresh_counter / interval); |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
495 if (delay) { |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
496 //To avoid the extra cycles being absorbed in the refresh free update below, we need to update again |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
497 gen->refresh_counter = gen->refresh_counter % interval; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
498 gen->refresh_counter += delay; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
499 delay += REFRESH_DELAY * MCLKS_PER_68K * (gen->refresh_counter / interval); |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
500 context->current_cycle += delay; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
501 } |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
502 gen->last_sync_cycle = context->current_cycle; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
503 //advance refresh counter for the current access, but don't generate delays |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
504 gen->refresh_counter += 4*MCLKS_PER_68K; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
505 gen->refresh_counter = gen->refresh_counter % interval; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
506 } |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
507 |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
508 void gen_update_refresh_no_wait(m68k_context *context) |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
509 { |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
510 uint32_t interval = MCLKS_PER_68K * REFRESH_INTERVAL; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
511 genesis_context *gen = context->system; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
512 gen->refresh_counter += context->current_cycle - gen->last_sync_cycle; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
513 gen->last_sync_cycle = context->current_cycle; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
514 gen->refresh_counter = gen->refresh_counter % interval; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
515 } |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
516 |
1170
9170fc4d9835
Don't adjust cycles every frame. Only when we start getting close to UINT_MAX. Don't adjust all the way down to zero when we do adjust. Shouldn't fix anything, but may make debugging current issues easier.
Michael Pavone <pavone@retrodev.com>
parents:
1165
diff
changeset
|
517 #include <limits.h> |
9170fc4d9835
Don't adjust cycles every frame. Only when we start getting close to UINT_MAX. Don't adjust all the way down to zero when we do adjust. Shouldn't fix anything, but may make debugging current issues easier.
Michael Pavone <pavone@retrodev.com>
parents:
1165
diff
changeset
|
518 #define ADJUST_BUFFER (8*MCLKS_LINE*313) |
9170fc4d9835
Don't adjust cycles every frame. Only when we start getting close to UINT_MAX. Don't adjust all the way down to zero when we do adjust. Shouldn't fix anything, but may make debugging current issues easier.
Michael Pavone <pavone@retrodev.com>
parents:
1165
diff
changeset
|
519 #define MAX_NO_ADJUST (UINT_MAX-ADJUST_BUFFER) |
9170fc4d9835
Don't adjust cycles every frame. Only when we start getting close to UINT_MAX. Don't adjust all the way down to zero when we do adjust. Shouldn't fix anything, but may make debugging current issues easier.
Michael Pavone <pavone@retrodev.com>
parents:
1165
diff
changeset
|
520 |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
521 static m68k_context *sync_components(m68k_context * context, uint32_t address) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
522 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
523 genesis_context * gen = context->system; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
524 vdp_context * v_context = gen->vdp; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
525 z80_context * z_context = gen->z80; |
2350
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
526 if (gen->bus_busy) { |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
527 gen_update_refresh_no_wait(context); |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
528 } else { |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
529 gen_update_refresh(context); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
530 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
531 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
532 uint32_t mclks = context->current_cycle; |
2184
408fb8a7e990
Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2179
diff
changeset
|
533 sync_z80(gen, mclks); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
534 sync_sound(gen, mclks); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
535 vdp_run_context(v_context, mclks); |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
536 io_run(gen->io.ports, mclks); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
537 io_run(gen->io.ports + 1, mclks); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
538 io_run(gen->io.ports + 2, mclks); |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
539 if (gen->expansion) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
540 scd_run(gen->expansion, gen_cycle_to_scd(mclks, gen)); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
541 } |
1556
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
542 if (mclks >= gen->reset_cycle) { |
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
543 gen->reset_requested = 1; |
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
544 context->should_return = 1; |
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
545 gen->reset_cycle = CYCLE_NEVER; |
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
546 } |
1971
80920c21bb52
Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
Michael Pavone <pavone@retrodev.com>
parents:
1954
diff
changeset
|
547 if (v_context->frame != gen->last_frame) { |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2286
diff
changeset
|
548 #ifndef IS_LIB |
2243
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
549 if (gen->ym->scope) { |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
550 scope_render(gen->ym->scope); |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
551 } |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2286
diff
changeset
|
552 #endif |
1971
80920c21bb52
Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
Michael Pavone <pavone@retrodev.com>
parents:
1954
diff
changeset
|
553 //printf("reached frame end %d | MCLK Cycles: %d, Target: %d, VDP cycles: %d, vcounter: %d, hslot: %d\n", gen->last_frame, mclks, gen->frame_end, v_context->cycles, v_context->vcounter, v_context->hslot); |
2179
9a8dd4ba2753
Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2164
diff
changeset
|
554 uint32_t elapsed = v_context->frame - gen->last_frame; |
1971
80920c21bb52
Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
Michael Pavone <pavone@retrodev.com>
parents:
1954
diff
changeset
|
555 gen->last_frame = v_context->frame; |
80920c21bb52
Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
Michael Pavone <pavone@retrodev.com>
parents:
1954
diff
changeset
|
556 event_flush(mclks); |
80920c21bb52
Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
Michael Pavone <pavone@retrodev.com>
parents:
1954
diff
changeset
|
557 gen->last_flush_cycle = mclks; |
2179
9a8dd4ba2753
Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2164
diff
changeset
|
558 if (gen->header.enter_debugger_frames) { |
9a8dd4ba2753
Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2164
diff
changeset
|
559 if (elapsed >= gen->header.enter_debugger_frames) { |
9a8dd4ba2753
Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2164
diff
changeset
|
560 gen->header.enter_debugger_frames = 0; |
9a8dd4ba2753
Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2164
diff
changeset
|
561 gen->header.enter_debugger = 1; |
9a8dd4ba2753
Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2164
diff
changeset
|
562 } else { |
9a8dd4ba2753
Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2164
diff
changeset
|
563 gen->header.enter_debugger_frames -= elapsed; |
9a8dd4ba2753
Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2164
diff
changeset
|
564 } |
9a8dd4ba2753
Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2164
diff
changeset
|
565 } |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
566 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
567 if(exit_after){ |
2179
9a8dd4ba2753
Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2164
diff
changeset
|
568 if (elapsed >= exit_after) { |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
569 exit(0); |
2179
9a8dd4ba2753
Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2164
diff
changeset
|
570 } else { |
9a8dd4ba2753
Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2164
diff
changeset
|
571 exit_after -= elapsed; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
572 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
573 } |
1170
9170fc4d9835
Don't adjust cycles every frame. Only when we start getting close to UINT_MAX. Don't adjust all the way down to zero when we do adjust. Shouldn't fix anything, but may make debugging current issues easier.
Michael Pavone <pavone@retrodev.com>
parents:
1165
diff
changeset
|
574 if (context->current_cycle > MAX_NO_ADJUST) { |
9170fc4d9835
Don't adjust cycles every frame. Only when we start getting close to UINT_MAX. Don't adjust all the way down to zero when we do adjust. Shouldn't fix anything, but may make debugging current issues easier.
Michael Pavone <pavone@retrodev.com>
parents:
1165
diff
changeset
|
575 uint32_t deduction = mclks - ADJUST_BUFFER; |
9170fc4d9835
Don't adjust cycles every frame. Only when we start getting close to UINT_MAX. Don't adjust all the way down to zero when we do adjust. Shouldn't fix anything, but may make debugging current issues easier.
Michael Pavone <pavone@retrodev.com>
parents:
1165
diff
changeset
|
576 vdp_adjust_cycles(v_context, deduction); |
9170fc4d9835
Don't adjust cycles every frame. Only when we start getting close to UINT_MAX. Don't adjust all the way down to zero when we do adjust. Shouldn't fix anything, but may make debugging current issues easier.
Michael Pavone <pavone@retrodev.com>
parents:
1165
diff
changeset
|
577 io_adjust_cycles(gen->io.ports, context->current_cycle, deduction); |
9170fc4d9835
Don't adjust cycles every frame. Only when we start getting close to UINT_MAX. Don't adjust all the way down to zero when we do adjust. Shouldn't fix anything, but may make debugging current issues easier.
Michael Pavone <pavone@retrodev.com>
parents:
1165
diff
changeset
|
578 io_adjust_cycles(gen->io.ports+1, context->current_cycle, deduction); |
9170fc4d9835
Don't adjust cycles every frame. Only when we start getting close to UINT_MAX. Don't adjust all the way down to zero when we do adjust. Shouldn't fix anything, but may make debugging current issues easier.
Michael Pavone <pavone@retrodev.com>
parents:
1165
diff
changeset
|
579 io_adjust_cycles(gen->io.ports+2, context->current_cycle, deduction); |
1610 | 580 if (gen->mapper_type == MAPPER_JCART) { |
581 jcart_adjust_cycles(gen, deduction); | |
582 } | |
1170
9170fc4d9835
Don't adjust cycles every frame. Only when we start getting close to UINT_MAX. Don't adjust all the way down to zero when we do adjust. Shouldn't fix anything, but may make debugging current issues easier.
Michael Pavone <pavone@retrodev.com>
parents:
1165
diff
changeset
|
583 context->current_cycle -= deduction; |
9170fc4d9835
Don't adjust cycles every frame. Only when we start getting close to UINT_MAX. Don't adjust all the way down to zero when we do adjust. Shouldn't fix anything, but may make debugging current issues easier.
Michael Pavone <pavone@retrodev.com>
parents:
1165
diff
changeset
|
584 z80_adjust_cycles(z_context, deduction); |
1902
32a3aa7b4a45
Fix YM2612 busy flag timing
Michael Pavone <pavone@retrodev.com>
parents:
1901
diff
changeset
|
585 ym_adjust_cycles(gen->ym, deduction); |
1909
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
586 if (gen->ym->vgm) { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
587 vgm_adjust_cycles(gen->ym->vgm, deduction); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
588 } |
1170
9170fc4d9835
Don't adjust cycles every frame. Only when we start getting close to UINT_MAX. Don't adjust all the way down to zero when we do adjust. Shouldn't fix anything, but may make debugging current issues easier.
Michael Pavone <pavone@retrodev.com>
parents:
1165
diff
changeset
|
589 gen->psg->cycles -= deduction; |
1556
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
590 if (gen->reset_cycle != CYCLE_NEVER) { |
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
591 gen->reset_cycle -= deduction; |
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
592 } |
1946 | 593 event_cycle_adjust(mclks, deduction); |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
594 if (gen->expansion) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
595 scd_adjust_cycle(gen->expansion, deduction); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
596 } |
1971
80920c21bb52
Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
Michael Pavone <pavone@retrodev.com>
parents:
1954
diff
changeset
|
597 gen->last_flush_cycle -= deduction; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
598 } |
1971
80920c21bb52
Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
Michael Pavone <pavone@retrodev.com>
parents:
1954
diff
changeset
|
599 } else if (mclks - gen->last_flush_cycle > gen->soft_flush_cycles) { |
80920c21bb52
Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
Michael Pavone <pavone@retrodev.com>
parents:
1954
diff
changeset
|
600 event_soft_flush(mclks); |
80920c21bb52
Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
Michael Pavone <pavone@retrodev.com>
parents:
1954
diff
changeset
|
601 gen->last_flush_cycle = mclks; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
602 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
603 gen->frame_end = vdp_cycles_to_frame_end(v_context); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
604 context->sync_cycle = gen->frame_end; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
605 //printf("Set sync cycle to: %d @ %d, vcounter: %d, hslot: %d\n", context->sync_cycle, context->current_cycle, v_context->vcounter, v_context->hslot); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
606 if (!address && (gen->header.enter_debugger || gen->header.save_state)) { |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
607 context->sync_cycle = context->current_cycle + 1; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
608 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
609 adjust_int_cycle(context, v_context); |
1556
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
610 if (gen->reset_cycle < context->target_cycle) { |
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
611 context->target_cycle = gen->reset_cycle; |
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
612 } |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
613 if (address) { |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
614 if (gen->header.enter_debugger) { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
615 gen->header.enter_debugger = 0; |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2286
diff
changeset
|
616 #ifndef IS_LIB |
2033
894bf99a13f1
Make ui.enter_debuger respect which debuger is active
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
617 if (gen->header.debugger_type == DEBUGGER_NATIVE) { |
894bf99a13f1
Make ui.enter_debuger respect which debuger is active
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
618 debugger(context, address); |
894bf99a13f1
Make ui.enter_debuger respect which debuger is active
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
619 } else { |
894bf99a13f1
Make ui.enter_debuger respect which debuger is active
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
620 gdb_debug_enter(context, address); |
894bf99a13f1
Make ui.enter_debuger respect which debuger is active
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
621 } |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2286
diff
changeset
|
622 #endif |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
623 } |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
624 #ifdef NEW_CORE |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
625 if (gen->header.save_state) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
626 #else |
1440
7d4483944d4d
Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
Michael Pavone <pavone@retrodev.com>
parents:
1433
diff
changeset
|
627 if (gen->header.save_state && (z_context->pc || !z_context->native_pc || z_context->reset || !z_context->busreq)) { |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
628 #endif |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
629 uint8_t slot = gen->header.save_state - 1; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
630 gen->header.save_state = 0; |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
631 #ifndef NEW_CORE |
1440
7d4483944d4d
Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
Michael Pavone <pavone@retrodev.com>
parents:
1433
diff
changeset
|
632 if (z_context->native_pc && !z_context->reset) { |
7d4483944d4d
Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
Michael Pavone <pavone@retrodev.com>
parents:
1433
diff
changeset
|
633 //advance Z80 core to the start of an instruction |
7d4483944d4d
Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
Michael Pavone <pavone@retrodev.com>
parents:
1433
diff
changeset
|
634 while (!z_context->pc) |
7d4483944d4d
Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
Michael Pavone <pavone@retrodev.com>
parents:
1433
diff
changeset
|
635 { |
2184
408fb8a7e990
Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2179
diff
changeset
|
636 sync_z80(gen, z_context->current_cycle + MCLKS_PER_Z80); |
1440
7d4483944d4d
Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
Michael Pavone <pavone@retrodev.com>
parents:
1433
diff
changeset
|
637 } |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
638 } |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
639 #endif |
1946 | 640 char *save_path = slot >= SERIALIZE_SLOT ? NULL : get_slot_name(&gen->header, slot, use_native_states ? "state" : "gst"); |
641 if (use_native_states || slot >= SERIALIZE_SLOT) { | |
1428
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
642 serialize_buffer state; |
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
643 init_serialize(&state); |
1946 | 644 genesis_serialize(gen, &state, address, slot != EVENTLOG_SLOT); |
1690
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
645 if (slot == SERIALIZE_SLOT) { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
646 gen->serialize_tmp = state.data; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
647 gen->serialize_size = state.size; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
648 context->sync_cycle = context->current_cycle; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
649 context->should_return = 1; |
1946 | 650 } else if (slot == EVENTLOG_SLOT) { |
651 event_state(context->current_cycle, &state); | |
1690
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
652 } else { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
653 save_to_file(&state, save_path); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
654 free(state.data); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
655 } |
1428
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
656 } else { |
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
657 save_gst(gen, save_path, address); |
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
658 } |
1849
6b5147f08846
Don't print out a message when saving a state to the serialization pseudo-slot
Michael Pavone <pavone@retrodev.com>
parents:
1848
diff
changeset
|
659 if (slot != SERIALIZE_SLOT) { |
6b5147f08846
Don't print out a message when saving a state to the serialization pseudo-slot
Michael Pavone <pavone@retrodev.com>
parents:
1848
diff
changeset
|
660 debug_message("Saved state to %s\n", save_path); |
6b5147f08846
Don't print out a message when saving a state to the serialization pseudo-slot
Michael Pavone <pavone@retrodev.com>
parents:
1848
diff
changeset
|
661 } |
1478
da1dce39e846
Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents:
1471
diff
changeset
|
662 free(save_path); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
663 } else if(gen->header.save_state) { |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
664 context->sync_cycle = context->current_cycle + 1; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
665 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
666 } |
2350
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
667 return context; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
668 } |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
669 |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
670 static m68k_context *int_ack(m68k_context *context) |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
671 { |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
672 genesis_context * gen = context->system; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
673 vdp_context * v_context = gen->vdp; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
674 //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); |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
675 vdp_run_context(v_context, context->current_cycle); |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
676 vdp_int_ack(v_context); |
2354
a773b8f09292
Remove old refresh hack that is causing VDPFifoTesting to have a failed test
Michael Pavone <pavone@retrodev.com>
parents:
2350
diff
changeset
|
677 |
2350
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
678 //the Genesis responds to these exclusively with !VPA which means its a slow |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
679 //6800 operation. documentation says these can take between 10 and 19 cycles. |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
680 //actual results measurements seem to suggest it's actually between 9 and 18 |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
681 //Base 68K core has added 4 cycles for a normal int ack cycle already |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
682 //We add 5 + the current cycle count (in 68K cycles) mod 10 to simulate the |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
683 //additional variable delay from the use of the 6800 cycle |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
684 uint32_t cycle_count = context->current_cycle / context->options->gen.clock_divider; |
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
685 context->current_cycle += 5 + (cycle_count % 10); |
2354
a773b8f09292
Remove old refresh hack that is causing VDPFifoTesting to have a failed test
Michael Pavone <pavone@retrodev.com>
parents:
2350
diff
changeset
|
686 |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
687 return context; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
688 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
689 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
690 static m68k_context * vdp_port_write(uint32_t vdp_port, m68k_context * context, uint16_t value) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
691 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
692 if (vdp_port & 0x2700E0) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
693 fatal_error("machine freeze due to write to address %X\n", 0xC00000 | vdp_port); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
694 } |
2037
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
695 genesis_context * gen = context->system; |
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
696 if (!gen->vdp_unlocked) { |
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
697 fatal_error("machine freeze due to VDP write to %X without TMSS unlock\n", 0xC00000 | vdp_port); |
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
698 } |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
699 vdp_port &= 0x1F; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
700 //printf("vdp_port write: %X, value: %X, cycle: %d\n", vdp_port, value, context->current_cycle); |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
701 |
1372
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
702 //do refresh check here so we can avoid adding a penalty for a refresh that happens during a VDP access |
2350
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
703 gen_update_refresh_free_access(context); |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
704 |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
705 sync_components(context, 0); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
706 vdp_context *v_context = gen->vdp; |
1374
8f404b1fa572
Go back to resetting the refresh counter after a DMA. Probably not quite correct as it is probably reset on VDP triggered refresh, but this is close enough for now given the general limitations with my refresh code. VDP FIFO Testing seems to be passing 100% reliably again (was occassionally failing still with the last commit)
Michael Pavone <pavone@retrodev.com>
parents:
1373
diff
changeset
|
707 uint32_t before_cycle = v_context->cycles; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
708 if (vdp_port < 0x10) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
709 int blocked; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
710 if (vdp_port < 4) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
711 while (vdp_data_port_write(v_context, value) < 0) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
712 while(v_context->flags & FLAG_DMA_RUN) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
713 vdp_run_dma_done(v_context, gen->frame_end); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
714 if (v_context->cycles >= gen->frame_end) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
715 uint32_t cycle_diff = v_context->cycles - context->current_cycle; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
716 uint32_t m68k_cycle_diff = (cycle_diff / MCLKS_PER_68K) * MCLKS_PER_68K; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
717 if (m68k_cycle_diff < cycle_diff) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
718 m68k_cycle_diff += MCLKS_PER_68K; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
719 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
720 context->current_cycle += m68k_cycle_diff; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
721 gen->bus_busy = 1; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
722 sync_components(context, 0); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
723 gen->bus_busy = 0; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
724 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
725 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
726 //context->current_cycle = v_context->cycles; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
727 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
728 } else if(vdp_port < 8) { |
1371
5b20840711c1
Remove HINT_FUDGE and make a small adjustment to how VDP syncs with rest of system instead. Worse results on CRAM dot issue, but much less of a hack
Michael Pavone <pavone@retrodev.com>
parents:
1364
diff
changeset
|
729 vdp_run_context_full(v_context, context->current_cycle); |
1373
7cfc9d532e34
Fixed regression from VDP sync changes. Direct color DMA demos are now achieving stable sync again
Michael Pavone <pavone@retrodev.com>
parents:
1372
diff
changeset
|
730 before_cycle = v_context->cycles; |
2227
eaaf28af3c94
Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents:
2194
diff
changeset
|
731 blocked = vdp_control_port_write(v_context, value, context->current_cycle); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
732 if (blocked) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
733 while (blocked) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
734 while(v_context->flags & FLAG_DMA_RUN) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
735 vdp_run_dma_done(v_context, gen->frame_end); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
736 if (v_context->cycles >= gen->frame_end) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
737 uint32_t cycle_diff = v_context->cycles - context->current_cycle; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
738 uint32_t m68k_cycle_diff = (cycle_diff / MCLKS_PER_68K) * MCLKS_PER_68K; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
739 if (m68k_cycle_diff < cycle_diff) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
740 m68k_cycle_diff += MCLKS_PER_68K; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
741 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
742 context->current_cycle += m68k_cycle_diff; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
743 gen->bus_busy = 1; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
744 sync_components(context, 0); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
745 gen->bus_busy = 0; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
746 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
747 } |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
748 |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
749 if (blocked < 0) { |
2227
eaaf28af3c94
Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents:
2194
diff
changeset
|
750 blocked = vdp_control_port_write(v_context, value, context->current_cycle); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
751 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
752 blocked = 0; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
753 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
754 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
755 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
756 context->sync_cycle = gen->frame_end = vdp_cycles_to_frame_end(v_context); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
757 //printf("Set sync cycle to: %d @ %d, vcounter: %d, hslot: %d\n", context->sync_cycle, context->current_cycle, v_context->vcounter, v_context->hslot); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
758 adjust_int_cycle(context, v_context); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
759 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
760 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
761 fatal_error("Illegal write to HV Counter port %X\n", vdp_port); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
762 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
763 if (v_context->cycles != before_cycle) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
764 //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); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
765 uint32_t cycle_diff = v_context->cycles - context->current_cycle; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
766 uint32_t m68k_cycle_diff = (cycle_diff / MCLKS_PER_68K) * MCLKS_PER_68K; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
767 if (m68k_cycle_diff < cycle_diff) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
768 m68k_cycle_diff += MCLKS_PER_68K; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
769 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
770 context->current_cycle += m68k_cycle_diff; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
771 //Lock the Z80 out of the bus until the VDP access is complete |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
772 gen->bus_busy = 1; |
2184
408fb8a7e990
Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2179
diff
changeset
|
773 sync_z80(gen, v_context->cycles); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
774 gen->bus_busy = 0; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
775 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
776 } else if (vdp_port < 0x18) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
777 psg_write(gen->psg, value); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
778 } else { |
1318
bfdd450e7dea
Initial work on handling the 128KB VRAM mode bit and some basic prep work for VDP test register support
Michael Pavone <pavone@retrodev.com>
parents:
1316
diff
changeset
|
779 vdp_test_port_write(gen->vdp, value); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
780 } |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
781 |
1372
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
782 //refresh may have happened while we were waiting on the VDP, |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
783 //so advance refresh_counter but don't add any delays |
2354
a773b8f09292
Remove old refresh hack that is causing VDPFifoTesting to have a failed test
Michael Pavone <pavone@retrodev.com>
parents:
2350
diff
changeset
|
784 gen_update_refresh_no_wait(context); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
785 return context; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
786 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
787 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
788 static m68k_context * vdp_port_write_b(uint32_t vdp_port, m68k_context * context, uint8_t value) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
789 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
790 return vdp_port_write(vdp_port, context, vdp_port < 0x10 ? value | value << 8 : ((vdp_port & 1) ? value : 0)); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
791 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
792 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
793 static void * z80_vdp_port_write(uint32_t vdp_port, void * vcontext, uint8_t value) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
794 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
795 z80_context * context = vcontext; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
796 genesis_context * gen = context->system; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
797 vdp_port &= 0xFF; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
798 if (vdp_port & 0xE0) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
799 fatal_error("machine freeze due to write to Z80 address %X\n", 0x7F00 | vdp_port); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
800 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
801 if (vdp_port < 0x10) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
802 //These probably won't currently interact well with the 68K accessing the VDP |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
803 if (vdp_port < 4) { |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
804 vdp_run_context(gen->vdp, context->Z80_CYCLE); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
805 vdp_data_port_write(gen->vdp, value << 8 | value); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
806 } else if (vdp_port < 8) { |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
807 vdp_run_context_full(gen->vdp, context->Z80_CYCLE); |
2227
eaaf28af3c94
Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents:
2194
diff
changeset
|
808 vdp_control_port_write(gen->vdp, value << 8 | value, context->Z80_CYCLE); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
809 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
810 fatal_error("Illegal write to HV Counter port %X\n", vdp_port); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
811 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
812 } else if (vdp_port < 0x18) { |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
813 sync_sound(gen, context->Z80_CYCLE); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
814 psg_write(gen->psg, value); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
815 } else { |
2327
9dd27530c570
Fix Z80 access to VDP debug register
Michael Pavone <pavone@retrodev.com>
parents:
2302
diff
changeset
|
816 vdp_test_port_write(gen->vdp, value << 8 | value); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
817 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
818 return context; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
819 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
820 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
821 static uint16_t vdp_port_read(uint32_t vdp_port, m68k_context * context) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
822 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
823 if (vdp_port & 0x2700E0) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
824 fatal_error("machine freeze due to read from address %X\n", 0xC00000 | vdp_port); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
825 } |
2037
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
826 genesis_context *gen = context->system; |
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
827 if (!gen->vdp_unlocked) { |
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
828 fatal_error("machine freeze due to VDP read from %X without TMSS unlock\n", 0xC00000 | vdp_port); |
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
829 } |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
830 vdp_port &= 0x1F; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
831 uint16_t value; |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
832 |
1372
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
833 //do refresh check here so we can avoid adding a penalty for a refresh that happens during a VDP access |
2350
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
834 gen_update_refresh_free_access(context); |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
835 |
2021
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
836 sync_components(context, 0); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
837 vdp_context * v_context = gen->vdp; |
2227
eaaf28af3c94
Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents:
2194
diff
changeset
|
838 uint32_t before_cycle = context->current_cycle; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
839 if (vdp_port < 0x10) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
840 if (vdp_port < 4) { |
2227
eaaf28af3c94
Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents:
2194
diff
changeset
|
841 value = vdp_data_port_read(v_context, &context->current_cycle, MCLKS_PER_68K); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
842 } else if(vdp_port < 8) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
843 value = vdp_control_port_read(v_context); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
844 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
845 value = vdp_hv_counter_read(v_context); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
846 //printf("HV Counter: %X at cycle %d\n", value, v_context->cycles); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
847 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
848 } else if (vdp_port < 0x18){ |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
849 fatal_error("Illegal read from PSG port %X\n", vdp_port); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
850 } else { |
1869
dc94354eab66
Fix accuracy bugs used by Novedicus to detect BlastEm/Exodus
Michael Pavone <pavone@retrodev.com>
parents:
1849
diff
changeset
|
851 value = get_open_bus_value(&gen->header); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
852 } |
2227
eaaf28af3c94
Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents:
2194
diff
changeset
|
853 if (context->current_cycle != before_cycle) { |
2021
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
854 //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); |
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
855 //Lock the Z80 out of the bus until the VDP access is complete |
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
856 genesis_context *gen = context->system; |
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
857 gen->bus_busy = 1; |
2227
eaaf28af3c94
Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents:
2194
diff
changeset
|
858 sync_z80(gen, context->current_cycle); |
2021
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
859 gen->bus_busy = 0; |
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
860 } |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
861 |
1372
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
862 //refresh may have happened while we were waiting on the VDP, |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
863 //so advance refresh_counter but don't add any delays |
2350
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
864 gen_update_refresh_no_wait(context); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
865 return value; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
866 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
867 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
868 static uint8_t vdp_port_read_b(uint32_t vdp_port, m68k_context * context) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
869 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
870 uint16_t value = vdp_port_read(vdp_port, context); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
871 if (vdp_port & 1) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
872 return value; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
873 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
874 return value >> 8; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
875 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
876 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
877 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
878 static uint8_t z80_vdp_port_read(uint32_t vdp_port, void * vcontext) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
879 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
880 z80_context * context = vcontext; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
881 if (vdp_port & 0xE0) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
882 fatal_error("machine freeze due to read from Z80 address %X\n", 0x7F00 | vdp_port); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
883 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
884 genesis_context * gen = context->system; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
885 //VDP access goes over the 68K bus like a bank area access |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
886 //typical delay from bus arbitration |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
887 context->Z80_CYCLE += 3 * MCLKS_PER_Z80; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
888 //TODO: add cycle for an access right after a previous one |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
889 //TODO: Below cycle time is an estimate based on the time between 68K !BG goes low and Z80 !MREQ goes high |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
890 // Needs a new logic analyzer capture to get the actual delay on the 68K side |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
891 gen->m68k->current_cycle += 8 * MCLKS_PER_68K; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
892 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
893 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
894 vdp_port &= 0x1F; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
895 uint16_t ret; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
896 if (vdp_port < 0x10) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
897 //These probably won't currently interact well with the 68K accessing the VDP |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
898 vdp_run_context(gen->vdp, context->Z80_CYCLE); |
2227
eaaf28af3c94
Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents:
2194
diff
changeset
|
899 uint32_t before = context->Z80_CYCLE; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
900 if (vdp_port < 4) { |
2227
eaaf28af3c94
Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents:
2194
diff
changeset
|
901 ret = vdp_data_port_read(gen->vdp, &context->Z80_CYCLE, MCLKS_PER_Z80); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
902 } else if (vdp_port < 8) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
903 ret = vdp_control_port_read(gen->vdp); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
904 } else { |
1316
3185438e0134
Fix copy pasta error in handling of Z80 VDP port reads. HV counter reads are not illegal writes =P. Fixes immediate exit in Overdrive II, though other problems remain
Michael Pavone <pavone@retrodev.com>
parents:
1309
diff
changeset
|
905 ret = vdp_hv_counter_read(gen->vdp); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
906 } |
2227
eaaf28af3c94
Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents:
2194
diff
changeset
|
907 if (context->Z80_CYCLE != before) { |
eaaf28af3c94
Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents:
2194
diff
changeset
|
908 gen->m68k->current_cycle += context->Z80_CYCLE - before; |
eaaf28af3c94
Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents:
2194
diff
changeset
|
909 } |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
910 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
911 //TODO: Figure out the correct value today |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
912 ret = 0xFFFF; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
913 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
914 return vdp_port & 1 ? ret : ret >> 8; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
915 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
916 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
917 //TODO: Move this inside the system context |
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
918 static uint32_t zram_counter = 0; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
919 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
920 static m68k_context * io_write(uint32_t location, m68k_context * context, uint8_t value) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
921 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
922 genesis_context * gen = context->system; |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
923 |
2012
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
924 //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access |
2350
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
925 gen_update_refresh_free_access(context); |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
926 |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
927 if (location < 0x10000) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
928 //Access to Z80 memory incurs a one 68K cycle wait state |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
929 context->current_cycle += MCLKS_PER_68K; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
930 if (!z80_enabled || z80_get_busack(gen->z80, context->current_cycle)) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
931 location &= 0x7FFF; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
932 if (location < 0x4000) { |
1104
4224980a5f84
Fix the previous WIP commit. Quick tests suggests things are no more broken than before now.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
933 gen->zram[location & 0x1FFF] = value; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
934 #ifndef NO_Z80 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
935 z80_handle_code_write(location & 0x1FFF, gen->z80); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
936 #endif |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
937 } else if (location < 0x6000) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
938 sync_sound(gen, context->current_cycle); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
939 if (location & 1) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
940 ym_data_write(gen->ym, value); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
941 } else if(location & 2) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
942 ym_address_write_part2(gen->ym, value); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
943 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
944 ym_address_write_part1(gen->ym, value); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
945 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
946 } else if (location == 0x6000) { |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
947 gen->z80_bank_reg = (gen->z80_bank_reg >> 1 | value << 8) & 0x1FF; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
948 if (gen->z80_bank_reg < 0x80) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
949 gen->z80->mem_pointers[1] = (gen->z80_bank_reg << 15) + ((char *)gen->z80->mem_pointers[2]); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
950 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
951 gen->z80->mem_pointers[1] = NULL; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
952 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
953 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
954 fatal_error("68K write to unhandled Z80 address %X\n", location); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
955 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
956 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
957 } else { |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
958 if (location < 0x10100) { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
959 switch(location >> 1 & 0xFF) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
960 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
961 case 0x1: |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
962 io_data_write(gen->io.ports, value, context->current_cycle); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
963 break; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
964 case 0x2: |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
965 io_data_write(gen->io.ports+1, value, context->current_cycle); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
966 break; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
967 case 0x3: |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
968 io_data_write(gen->io.ports+2, value, context->current_cycle); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
969 break; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
970 case 0x4: |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1333
diff
changeset
|
971 io_control_write(gen->io.ports, value, context->current_cycle); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
972 break; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
973 case 0x5: |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1333
diff
changeset
|
974 io_control_write(gen->io.ports+1, value, context->current_cycle); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
975 break; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
976 case 0x6: |
1348
040c5600e2d9
Implemented slow rise time of IO pins set as inputs, but not driven by device. Fixes input in Decap Attack and possibly other games with buggy controller code
Michael Pavone <pavone@retrodev.com>
parents:
1333
diff
changeset
|
977 io_control_write(gen->io.ports+2, value, context->current_cycle); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
978 break; |
1215
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
979 case 0x7: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
980 io_tx_write(gen->io.ports, value, context->current_cycle); |
1215
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
981 break; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
982 case 0x8: |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
983 case 0xB: |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
984 case 0xE: |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
985 //serial input port is not writeable |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
986 break; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
987 case 0x9: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
988 io_sctrl_write(gen->io.ports, value, context->current_cycle); |
1215
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
989 gen->io.ports[0].serial_ctrl = value; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
990 break; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
991 case 0xA: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
992 io_tx_write(gen->io.ports + 1, value, context->current_cycle); |
1215
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
993 break; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
994 case 0xC: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
995 io_sctrl_write(gen->io.ports + 1, value, context->current_cycle); |
1215
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
996 break; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
997 case 0xD: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
998 io_tx_write(gen->io.ports + 2, value, context->current_cycle); |
1215
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
999 break; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1000 case 0xF: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
1001 io_sctrl_write(gen->io.ports + 2, value, context->current_cycle); |
1215
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1002 break; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1003 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1004 } else { |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1005 uint32_t masked = location & 0xFFF00; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1006 if (masked == 0x11100) { |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1007 if (value & 1) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1008 dputs("bus requesting Z80"); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1009 if (z80_enabled) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1010 z80_assert_busreq(gen->z80, context->current_cycle); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1011 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1012 gen->z80->busack = 1; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1013 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1014 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1015 if (gen->z80->busreq) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1016 dputs("releasing z80 bus"); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1017 #ifdef DO_DEBUG_PRINT |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1018 char fname[20]; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1019 sprintf(fname, "zram-%d", zram_counter++); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1020 FILE * f = fopen(fname, "wb"); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1021 fwrite(z80_ram, 1, sizeof(z80_ram), f); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1022 fclose(f); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1023 #endif |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1024 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1025 if (z80_enabled) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1026 z80_clear_busreq(gen->z80, context->current_cycle); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1027 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1028 gen->z80->busack = 0; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1029 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1030 } |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1031 } else if (masked == 0x11200) { |
2184
408fb8a7e990
Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents:
2179
diff
changeset
|
1032 sync_z80(gen, context->current_cycle); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1033 if (value & 1) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1034 if (z80_enabled) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1035 z80_clear_reset(gen->z80, context->current_cycle); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1036 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1037 gen->z80->reset = 0; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1038 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1039 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1040 if (z80_enabled) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1041 z80_assert_reset(gen->z80, context->current_cycle); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1042 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1043 gen->z80->reset = 1; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1044 } |
1308
1b3fe6e03e7b
Reset YM2612 whenver the Z80 is reset. Fixes issue with stuck notes in Fantastic Dizzy and Kid Chameleon
Michael Pavone <pavone@retrodev.com>
parents:
1304
diff
changeset
|
1045 ym_reset(gen->ym); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1046 } |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1047 } else if (masked != 0x11300 && masked != 0x11000) { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1048 fatal_error("Machine freeze due to unmapped write to address %X\n", location | 0xA00000); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1049 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1050 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1051 } |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1052 |
2012
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
1053 //no refresh delays during IO access |
2350
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
1054 gen_update_refresh_no_wait(context); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1055 return context; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1056 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1057 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1058 static m68k_context * io_write_w(uint32_t location, m68k_context * context, uint16_t value) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1059 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1060 if (location < 0x10000 || (location & 0x1FFF) >= 0x100) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1061 return io_write(location, context, value >> 8); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1062 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1063 return io_write(location, context, value); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1064 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1065 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1066 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1067 #define FOREIGN 0x80 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1068 #define HZ50 0x40 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1069 #define USA FOREIGN |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1070 #define JAP 0x00 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1071 #define EUR (HZ50|FOREIGN) |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1072 #define NO_DISK 0x20 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1073 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1074 static uint8_t io_read(uint32_t location, m68k_context * context) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1075 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1076 uint8_t value; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1077 genesis_context *gen = context->system; |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1078 |
2012
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
1079 //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access |
2350
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
1080 gen_update_refresh_free_access(context); |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1081 |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1082 if (location < 0x10000) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1083 //Access to Z80 memory incurs a one 68K cycle wait state |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1084 context->current_cycle += MCLKS_PER_68K; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1085 if (!z80_enabled || z80_get_busack(gen->z80, context->current_cycle)) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1086 location &= 0x7FFF; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1087 if (location < 0x4000) { |
1104
4224980a5f84
Fix the previous WIP commit. Quick tests suggests things are no more broken than before now.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1088 value = gen->zram[location & 0x1FFF]; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1089 } else if (location < 0x6000) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1090 sync_sound(gen, context->current_cycle); |
1904
8312e574100a
Implement selectable YM2612/YM3834 invalid status port behavior
Michael Pavone <pavone@retrodev.com>
parents:
1902
diff
changeset
|
1091 value = ym_read_status(gen->ym, context->current_cycle, location); |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1092 } else if (location < 0x7F00) { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1093 value = 0xFF; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1094 } else { |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1095 fatal_error("Machine freeze due to read of Z80 VDP memory window by 68K: %X\n", location | 0xA00000); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1096 value = 0xFF; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1097 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1098 } else { |
1914
5b94e0e7c5a5
Reading from Z80 bus when Z80 is not bus requested should return open bus. Fixes regression in Metal Sonic Rebooted
Michael Pavone <pavone@retrodev.com>
parents:
1909
diff
changeset
|
1099 uint16_t word = get_open_bus_value(&gen->header); |
5b94e0e7c5a5
Reading from Z80 bus when Z80 is not bus requested should return open bus. Fixes regression in Metal Sonic Rebooted
Michael Pavone <pavone@retrodev.com>
parents:
1909
diff
changeset
|
1100 value = location & 1 ? word : word >> 8; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1101 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1102 } else { |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1103 if (location < 0x10100) { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1104 switch(location >> 1 & 0xFF) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1105 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1106 case 0x0: |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1107 //version bits should be 0 for now since we're not emulating TMSS |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1108 value = gen->version_reg; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1109 break; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1110 case 0x1: |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1111 value = io_data_read(gen->io.ports, context->current_cycle); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1112 break; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1113 case 0x2: |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1114 value = io_data_read(gen->io.ports+1, context->current_cycle); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1115 break; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1116 case 0x3: |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1117 value = io_data_read(gen->io.ports+2, context->current_cycle); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1118 break; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1119 case 0x4: |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1120 value = gen->io.ports[0].control; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1121 break; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1122 case 0x5: |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1123 value = gen->io.ports[1].control; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1124 break; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1125 case 0x6: |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1126 value = gen->io.ports[2].control; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1127 break; |
1215
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1128 case 0x7: |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1129 value = gen->io.ports[0].serial_out; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1130 break; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1131 case 0x8: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
1132 value = io_rx_read(gen->io.ports, context->current_cycle); |
1215
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1133 break; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1134 case 0x9: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
1135 value = io_sctrl_read(gen->io.ports, context->current_cycle); |
1215
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1136 break; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1137 case 0xA: |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1138 value = gen->io.ports[1].serial_out; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1139 break; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1140 case 0xB: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
1141 value = io_rx_read(gen->io.ports + 1, context->current_cycle); |
1215
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1142 break; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1143 case 0xC: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
1144 value = io_sctrl_read(gen->io.ports, context->current_cycle); |
1215
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1145 break; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1146 case 0xD: |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1147 value = gen->io.ports[2].serial_out; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1148 break; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1149 case 0xE: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
1150 value = io_rx_read(gen->io.ports + 1, context->current_cycle); |
1215
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1151 break; |
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1152 case 0xF: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
1153 value = io_sctrl_read(gen->io.ports, context->current_cycle); |
1215
cf69a179aeaf
Basic implementation of serial IO registers, but without actual serial IO support. Needed to run a certain software check cartridge that is floating around.
Michael Pavone <pavone@retrodev.com>
parents:
1208
diff
changeset
|
1154 break; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1155 default: |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1156 value = get_open_bus_value(&gen->header) >> 8; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1157 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1158 } else { |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1159 uint32_t masked = location & 0xFFF00; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1160 if (masked == 0x11100) { |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1161 value = z80_enabled ? !z80_get_busack(gen->z80, context->current_cycle) : !gen->z80->busack; |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
1162 value |= (get_open_bus_value(&gen->header) >> 8) & 0xFE; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1163 dprintf("Byte read of BUSREQ returned %d @ %d (reset: %d)\n", value, context->current_cycle, gen->z80->reset); |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1164 } else if (masked == 0x11200) { |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1165 value = !gen->z80->reset; |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1166 } else if (masked == 0x11300 || masked == 0x11000) { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1167 //A11300 is apparently completely unused |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1168 //A11000 is the memory control register which I am assuming is write only |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1169 value = get_open_bus_value(&gen->header) >> 8; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1170 } else { |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1171 location |= 0xA00000; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1172 fatal_error("Machine freeze due to read of unmapped IO location %X\n", location); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1173 value = 0xFF; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1174 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1175 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1176 } |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1177 |
2012
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
1178 //no refresh delays during IO access |
2350
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
1179 gen_update_refresh_no_wait(context); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1180 return value; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1181 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1182 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1183 static uint16_t io_read_w(uint32_t location, m68k_context * context) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1184 { |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
1185 genesis_context *gen = context->system; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1186 uint16_t value = io_read(location, context); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1187 if (location < 0x10000 || (location & 0x1FFF) < 0x100) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1188 value = value | (value << 8); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1189 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1190 value <<= 8; |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
1191 value |= get_open_bus_value(&gen->header) & 0xFF; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1192 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1193 return value; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1194 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1195 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1196 static void * z80_write_ym(uint32_t location, void * vcontext, uint8_t value) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1197 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1198 z80_context * context = vcontext; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1199 genesis_context * gen = context->system; |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
1200 sync_sound(gen, context->Z80_CYCLE); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1201 if (location & 1) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1202 ym_data_write(gen->ym, value); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1203 } else if (location & 2) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1204 ym_address_write_part2(gen->ym, value); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1205 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1206 ym_address_write_part1(gen->ym, value); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1207 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1208 return context; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1209 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1210 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1211 static uint8_t z80_read_ym(uint32_t location, void * vcontext) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1212 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1213 z80_context * context = vcontext; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1214 genesis_context * gen = context->system; |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
1215 sync_sound(gen, context->Z80_CYCLE); |
1904
8312e574100a
Implement selectable YM2612/YM3834 invalid status port behavior
Michael Pavone <pavone@retrodev.com>
parents:
1902
diff
changeset
|
1216 return ym_read_status(gen->ym, context->Z80_CYCLE, location); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1217 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1218 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1219 static uint8_t z80_read_bank(uint32_t location, void * vcontext) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1220 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1221 z80_context * context = vcontext; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1222 genesis_context *gen = context->system; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1223 if (gen->bus_busy) { |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
1224 context->Z80_CYCLE = gen->m68k->current_cycle; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1225 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1226 //typical delay from bus arbitration |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
1227 context->Z80_CYCLE += 3 * MCLKS_PER_Z80; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1228 //TODO: add cycle for an access right after a previous one |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1229 //TODO: Below cycle time is an estimate based on the time between 68K !BG goes low and Z80 !MREQ goes high |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1230 // Needs a new logic analyzer capture to get the actual delay on the 68K side |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1231 gen->m68k->current_cycle += 8 * MCLKS_PER_68K; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1232 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1233 location &= 0x7FFF; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1234 if (context->mem_pointers[1]) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1235 return context->mem_pointers[1][location ^ 1]; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1236 } |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
1237 uint32_t address = gen->z80_bank_reg << 15 | location; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1238 if (address >= 0xC00000 && address < 0xE00000) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1239 return z80_vdp_port_read(location & 0xFF, context); |
1869
dc94354eab66
Fix accuracy bugs used by Novedicus to detect BlastEm/Exodus
Michael Pavone <pavone@retrodev.com>
parents:
1849
diff
changeset
|
1240 } else if (address >= 0xA10000 && address <= 0xA10001) { |
dc94354eab66
Fix accuracy bugs used by Novedicus to detect BlastEm/Exodus
Michael Pavone <pavone@retrodev.com>
parents:
1849
diff
changeset
|
1241 //Apparently version reg can be read through Z80 banked area |
dc94354eab66
Fix accuracy bugs used by Novedicus to detect BlastEm/Exodus
Michael Pavone <pavone@retrodev.com>
parents:
1849
diff
changeset
|
1242 //TODO: Check rest of IO region addresses |
dc94354eab66
Fix accuracy bugs used by Novedicus to detect BlastEm/Exodus
Michael Pavone <pavone@retrodev.com>
parents:
1849
diff
changeset
|
1243 return gen->version_reg; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1244 } else { |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
1245 fprintf(stderr, "Unhandled read by Z80 from address %X through banked memory area (%X)\n", address, gen->z80_bank_reg << 15); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1246 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1247 return 0; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1248 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1249 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1250 static void *z80_write_bank(uint32_t location, void * vcontext, uint8_t value) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1251 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1252 z80_context * context = vcontext; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1253 genesis_context *gen = context->system; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1254 if (gen->bus_busy) { |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
1255 context->Z80_CYCLE = gen->m68k->current_cycle; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1256 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1257 //typical delay from bus arbitration |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
1258 context->Z80_CYCLE += 3 * MCLKS_PER_Z80; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1259 //TODO: add cycle for an access right after a previous one |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1260 //TODO: Below cycle time is an estimate based on the time between 68K !BG goes low and Z80 !MREQ goes high |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1261 // Needs a new logic analyzer capture to get the actual delay on the 68K side |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1262 gen->m68k->current_cycle += 8 * MCLKS_PER_68K; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1263 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1264 location &= 0x7FFF; |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
1265 uint32_t address = gen->z80_bank_reg << 15 | location; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1266 if (address >= 0xE00000) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1267 address &= 0xFFFF; |
1104
4224980a5f84
Fix the previous WIP commit. Quick tests suggests things are no more broken than before now.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1268 ((uint8_t *)gen->work_ram)[address ^ 1] = value; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1269 } else if (address >= 0xC00000) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1270 z80_vdp_port_write(location & 0xFF, context, value); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1271 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1272 fprintf(stderr, "Unhandled write by Z80 to address %X through banked memory area\n", address); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1273 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1274 return context; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1275 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1276 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1277 static void *z80_write_bank_reg(uint32_t location, void * vcontext, uint8_t value) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1278 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1279 z80_context * context = vcontext; |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
1280 genesis_context *gen = context->system; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1281 |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
1282 gen->z80_bank_reg = (gen->z80_bank_reg >> 1 | value << 8) & 0x1FF; |
1445
349d50930c03
Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1444
diff
changeset
|
1283 update_z80_bank_pointer(context->system); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1284 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1285 return context; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1286 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1287 |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1288 static uint16_t unused_read(uint32_t location, void *vcontext) |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1289 { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1290 m68k_context *context = vcontext; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1291 genesis_context *gen = context->system; |
2228
0db9dc6a9020
Some minor refresh emulation improvements
Michael Pavone <pavone@retrodev.com>
parents:
2227
diff
changeset
|
1292 if (location >= 0x800000) { |
0db9dc6a9020
Some minor refresh emulation improvements
Michael Pavone <pavone@retrodev.com>
parents:
2227
diff
changeset
|
1293 //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1294 gen->refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - gen->last_sync_cycle; |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1295 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (gen->refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL)); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1296 gen->refresh_counter += 4*MCLKS_PER_68K; |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1297 gen->refresh_counter = gen->refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1298 gen->last_sync_cycle = context->current_cycle; |
2228
0db9dc6a9020
Some minor refresh emulation improvements
Michael Pavone <pavone@retrodev.com>
parents:
2227
diff
changeset
|
1299 } |
0db9dc6a9020
Some minor refresh emulation improvements
Michael Pavone <pavone@retrodev.com>
parents:
2227
diff
changeset
|
1300 |
1987
71732f2f6f42
Fix handling of unmapped reads/writes to the cart/expansion port region
Mike Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
1301 if (location < 0x800000 || (location >= 0xA13000 && location < 0xA13100) || (location >= 0xA12000 && location < 0xA12100)) { |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1302 //Only called if the cart/exp doesn't have a more specific handler for this region |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1303 return get_open_bus_value(&gen->header); |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1304 } else if (location == 0xA14000 || location == 0xA14002) { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1305 if (gen->version_reg & 0xF) { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1306 return gen->tmss_lock[location >> 1 & 1]; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1307 } else { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1308 fatal_error("Machine freeze due to read from TMSS lock when TMSS is not present %X\n", location); |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1309 return 0xFFFF; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1310 } |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1311 } else if (location == 0xA14100) { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1312 if (gen->version_reg & 0xF) { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1313 return get_open_bus_value(&gen->header); |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1314 } else { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1315 fatal_error("Machine freeze due to read from TMSS control when TMSS is not present %X\n", location); |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1316 return 0xFFFF; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1317 } |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1318 } else { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1319 fatal_error("Machine freeze due to unmapped read from %X\n", location); |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1320 return 0xFFFF; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1321 } |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1322 } |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1323 |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1324 static uint8_t unused_read_b(uint32_t location, void *vcontext) |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1325 { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1326 uint16_t v = unused_read(location & 0xFFFFFE, vcontext); |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1327 if (location & 1) { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1328 return v; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1329 } else { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1330 return v >> 8; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1331 } |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1332 } |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1333 |
2037
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
1334 static void check_tmss_lock(genesis_context *gen) |
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
1335 { |
2039
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
1336 gen->vdp_unlocked = gen->tmss_lock[0] == 0x5345 && gen->tmss_lock[1] == 0x4741; |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
1337 } |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
1338 |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
1339 static void toggle_tmss_rom(genesis_context *gen) |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
1340 { |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
1341 m68k_context *context = gen->m68k; |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
1342 for (int i = 0; i < NUM_MEM_AREAS; i++) |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
1343 { |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
1344 uint16_t *tmp = context->mem_pointers[i]; |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
1345 context->mem_pointers[i] = gen->tmss_pointers[i]; |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
1346 gen->tmss_pointers[i] = tmp; |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
1347 } |
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
1348 m68k_invalidate_code_range(context, 0, 0x400000); |
2037
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
1349 } |
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
1350 |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1351 static void *unused_write(uint32_t location, void *vcontext, uint16_t value) |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1352 { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1353 m68k_context *context = vcontext; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1354 genesis_context *gen = context->system; |
2228
0db9dc6a9020
Some minor refresh emulation improvements
Michael Pavone <pavone@retrodev.com>
parents:
2227
diff
changeset
|
1355 if (location >= 0x800000) { |
0db9dc6a9020
Some minor refresh emulation improvements
Michael Pavone <pavone@retrodev.com>
parents:
2227
diff
changeset
|
1356 //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1357 gen->refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - gen->last_sync_cycle; |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1358 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (gen->refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL)); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1359 gen->refresh_counter += 4*MCLKS_PER_68K; |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1360 gen->refresh_counter = gen->refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); |
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1361 gen->last_sync_cycle = context->current_cycle; |
2228
0db9dc6a9020
Some minor refresh emulation improvements
Michael Pavone <pavone@retrodev.com>
parents:
2227
diff
changeset
|
1362 } |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1363 |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1364 uint8_t has_tmss = gen->version_reg & 0xF; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1365 if (has_tmss && (location == 0xA14000 || location == 0xA14002)) { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1366 gen->tmss_lock[location >> 1 & 1] = value; |
2037
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
1367 check_tmss_lock(gen); |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1368 } else if (has_tmss && location == 0xA14100) { |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1369 value &= 1; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1370 if (gen->tmss != value) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1371 gen->tmss = value; |
2039
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
1372 toggle_tmss_rom(gen); |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1373 } |
1987
71732f2f6f42
Fix handling of unmapped reads/writes to the cart/expansion port region
Mike Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
1374 } else if (location < 0x800000 || (location >= 0xA13000 && location < 0xA13100) || (location >= 0xA12000 && location < 0xA12100)) { |
71732f2f6f42
Fix handling of unmapped reads/writes to the cart/expansion port region
Mike Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
1375 //these writes are ignored when no relevant hardware is present |
71732f2f6f42
Fix handling of unmapped reads/writes to the cart/expansion port region
Mike Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
1376 } else { |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1377 fatal_error("Machine freeze due to unmapped write to %X\n", location); |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1378 } |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1379 return vcontext; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1380 } |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1381 |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1382 static void *unused_write_b(uint32_t location, void *vcontext, uint8_t value) |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1383 { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1384 m68k_context *context = vcontext; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1385 genesis_context *gen = context->system; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1386 uint8_t has_tmss = gen->version_reg & 0xF; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1387 if (has_tmss && location >= 0xA14000 && location <= 0xA14003) { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1388 uint32_t offset = location >> 1 & 1; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1389 if (location & 1) { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1390 gen->tmss_lock[offset] &= 0xFF00; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1391 gen->tmss_lock[offset] |= value; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1392 } else { |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1393 gen->tmss_lock[offset] &= 0xFF; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1394 gen->tmss_lock[offset] |= value << 8; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1395 } |
2037
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
1396 check_tmss_lock(gen); |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1397 } else if (has_tmss && (location == 0xA14100 || location == 0xA14101)) { |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1398 if (location & 1) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1399 value &= 1; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1400 if (gen->tmss != value) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1401 gen->tmss = value; |
2039
3b8e29ef1145
Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents:
2037
diff
changeset
|
1402 toggle_tmss_rom(gen); |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1403 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1404 } |
1987
71732f2f6f42
Fix handling of unmapped reads/writes to the cart/expansion port region
Mike Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
1405 } else if (location < 0x800000 || (location >= 0xA13000 && location < 0xA13100) || (location >= 0xA12000 && location < 0xA12100)) { |
71732f2f6f42
Fix handling of unmapped reads/writes to the cart/expansion port region
Mike Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
1406 //these writes are ignored when no relevant hardware is present |
71732f2f6f42
Fix handling of unmapped reads/writes to the cart/expansion port region
Mike Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
1407 } else { |
1907
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1408 fatal_error("Machine freeze due to unmapped byte write to %X\n", location); |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1409 } |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1410 return vcontext; |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1411 } |
b021ca0bc375
Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents:
1906
diff
changeset
|
1412 |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1413 static void set_speed_percent(system_header * system, uint32_t percent) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1414 { |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1415 genesis_context *context = (genesis_context *)system; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1416 uint32_t old_clock = context->master_clock; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1417 context->master_clock = ((uint64_t)context->normal_clock * (uint64_t)percent) / 100; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1418 while (context->ym->current_cycle != context->psg->cycles) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1419 sync_sound(context, context->psg->cycles + MCLKS_PER_PSG); |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1420 } |
2278
5a21bc0ec583
Implement turbo/slo mo for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2277
diff
changeset
|
1421 if (context->expansion) { |
5a21bc0ec583
Implement turbo/slo mo for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2277
diff
changeset
|
1422 segacd_context *cd = context->expansion; |
5a21bc0ec583
Implement turbo/slo mo for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2277
diff
changeset
|
1423 segacd_set_speed_percent(cd, percent); |
5a21bc0ec583
Implement turbo/slo mo for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2277
diff
changeset
|
1424 } |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1425 ym_adjust_master_clock(context->ym, context->master_clock); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1426 psg_adjust_master_clock(context->psg, context->master_clock); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1427 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1428 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1429 void set_region(genesis_context *gen, rom_info *info, uint8_t region) |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1430 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1431 if (!region) { |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1318
diff
changeset
|
1432 char * def_region = tern_find_path_default(config, "system\0default_region\0", (tern_val){.ptrval = "U"}, TVAL_PTR).ptrval; |
1204
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
1433 if (!info->regions || (info->regions & translate_region_char(toupper(*def_region)))) { |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1434 region = translate_region_char(toupper(*def_region)); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1435 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1436 region = info->regions; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1437 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1438 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1439 if (region & REGION_E) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1440 gen->version_reg = NO_DISK | EUR; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1441 } else if (region & REGION_J) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1442 gen->version_reg = NO_DISK | JAP; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1443 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1444 gen->version_reg = NO_DISK | USA; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1445 } |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
1446 |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1447 if (region & HZ50) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1448 gen->normal_clock = MCLKS_PAL; |
1971
80920c21bb52
Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
Michael Pavone <pavone@retrodev.com>
parents:
1954
diff
changeset
|
1449 gen->soft_flush_cycles = MCLKS_LINE * 262 / 3 + 2; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1450 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1451 gen->normal_clock = MCLKS_NTSC; |
1971
80920c21bb52
Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
Michael Pavone <pavone@retrodev.com>
parents:
1954
diff
changeset
|
1452 gen->soft_flush_cycles = MCLKS_LINE * 313 / 3 + 2; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1453 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1454 gen->master_clock = gen->normal_clock; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1455 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1456 |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1457 static uint8_t load_state(system_header *system, uint8_t slot) |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1458 { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1459 genesis_context *gen = (genesis_context *)system; |
1479
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1460 char *statepath = get_slot_name(system, slot, "state"); |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1461 deserialize_buffer state; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1462 uint32_t pc = 0; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1463 uint8_t ret; |
1479
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1464 if (!gen->m68k->resume_pc) { |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1465 system->delayed_load_slot = slot + 1; |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1466 gen->m68k->should_return = 1; |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1467 ret = get_modification_time(statepath) != 0; |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1468 if (!ret) { |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1469 strcpy(statepath + strlen(statepath)-strlen("state"), "gst"); |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1470 ret = get_modification_time(statepath) != 0; |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1471 } |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1472 goto done; |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1473 } |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1474 if (load_from_file(&state, statepath)) { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1475 genesis_deserialize(&state, gen); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1476 free(state.data); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1477 ret = 1; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1478 } else { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1479 strcpy(statepath + strlen(statepath)-strlen("state"), "gst"); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1480 pc = load_gst(gen, statepath); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1481 ret = pc != 0; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1482 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1483 if (ret) { |
2280
9ead0fe69d9b
Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2278
diff
changeset
|
1484 debug_message("Loaded state from %s\n", statepath); |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1485 } |
1479
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1486 done: |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1487 free(statepath); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1488 return ret; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1489 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1490 |
1479
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1491 static void handle_reset_requests(genesis_context *gen) |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1492 { |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1493 while (gen->reset_requested || gen->header.delayed_load_slot) |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1494 { |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1495 if (gen->reset_requested) { |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1496 gen->reset_requested = 0; |
1556
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
1497 gen->m68k->should_return = 0; |
1479
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1498 z80_assert_reset(gen->z80, gen->m68k->current_cycle); |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1499 z80_clear_busreq(gen->z80, gen->m68k->current_cycle); |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1500 ym_reset(gen->ym); |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1501 //Is there any sort of VDP reset? |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1502 m68k_reset(gen->m68k); |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1503 } |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1504 if (gen->header.delayed_load_slot) { |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1505 load_state(&gen->header, gen->header.delayed_load_slot - 1); |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1506 gen->header.delayed_load_slot = 0; |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1507 resume_68k(gen->m68k); |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1508 } |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1509 } |
1980
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1971
diff
changeset
|
1510 if (gen->header.force_release || render_should_release_on_exit()) { |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1927
diff
changeset
|
1511 bindings_release_capture(); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1927
diff
changeset
|
1512 vdp_release_framebuffer(gen->vdp); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1927
diff
changeset
|
1513 render_pause_source(gen->ym->audio); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1927
diff
changeset
|
1514 render_pause_source(gen->psg->audio); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1927
diff
changeset
|
1515 } |
1479
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1516 } |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1517 |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1518 static void start_genesis(system_header *system, char *statefile) |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1519 { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1520 genesis_context *gen = (genesis_context *)system; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1521 if (statefile) { |
1428
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1522 //first try loading as a native format savestate |
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1523 deserialize_buffer state; |
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1524 uint32_t pc; |
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1525 if (load_from_file(&state, statefile)) { |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
1526 genesis_deserialize(&state, gen); |
1428
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1527 free(state.data); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
1528 //HACK |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
1529 pc = gen->m68k->last_prefetch_address; |
1428
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1530 } else { |
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1531 pc = load_gst(gen, statefile); |
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1532 if (!pc) { |
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1533 fatal_error("Failed to load save state %s\n", statefile); |
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
1534 } |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1535 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1536 printf("Loaded %s\n", statefile); |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1537 if (gen->header.enter_debugger) { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1538 gen->header.enter_debugger = 0; |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2286
diff
changeset
|
1539 #ifndef IS_LIB |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1540 insert_breakpoint(gen->m68k, pc, gen->header.debugger_type == DEBUGGER_NATIVE ? debugger : gdb_debug_enter); |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2286
diff
changeset
|
1541 #endif |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1542 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1543 adjust_int_cycle(gen->m68k, gen->vdp); |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1544 start_68k_context(gen->m68k, pc); |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1545 } else { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1546 if (gen->header.enter_debugger) { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1547 gen->header.enter_debugger = 0; |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2286
diff
changeset
|
1548 #ifndef IS_LIB |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
1549 uint32_t address = read_word(4, (void **)gen->m68k->mem_pointers, &gen->m68k->options->gen, gen->m68k) << 16 |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
1550 | read_word(6, (void **)gen->m68k->mem_pointers, &gen->m68k->options->gen, gen->m68k); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1551 insert_breakpoint(gen->m68k, address, gen->header.debugger_type == DEBUGGER_NATIVE ? debugger : gdb_debug_enter); |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2286
diff
changeset
|
1552 #endif |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1553 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1554 m68k_reset(gen->m68k); |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1555 } |
1208
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
1556 handle_reset_requests(gen); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
1557 return; |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1558 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1559 |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1560 static void resume_genesis(system_header *system) |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1561 { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1562 genesis_context *gen = (genesis_context *)system; |
1980
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1971
diff
changeset
|
1563 if (gen->header.force_release || render_should_release_on_exit()) { |
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1971
diff
changeset
|
1564 gen->header.force_release = 0; |
1932
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1927
diff
changeset
|
1565 render_set_video_standard((gen->version_reg & HZ50) ? VID_PAL : VID_NTSC); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1927
diff
changeset
|
1566 bindings_reacquire_capture(); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1927
diff
changeset
|
1567 vdp_reacquire_framebuffer(gen->vdp); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1927
diff
changeset
|
1568 render_resume_source(gen->ym->audio); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1927
diff
changeset
|
1569 render_resume_source(gen->psg->audio); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1927
diff
changeset
|
1570 } |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1571 resume_68k(gen->m68k); |
1208
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
1572 handle_reset_requests(gen); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1573 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1574 |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1575 static void inc_debug_mode(system_header *system) |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1576 { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1577 genesis_context *gen = (genesis_context *)system; |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1610
diff
changeset
|
1578 vdp_inc_debug_mode(gen->vdp); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1579 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1580 |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1581 static void request_exit(system_header *system) |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1582 { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1583 genesis_context *gen = (genesis_context *)system; |
1688
395f684c5379
Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
1584 gen->m68k->target_cycle = gen->m68k->current_cycle; |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1585 gen->m68k->should_return = 1; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1586 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1587 |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1588 static void persist_save(system_header *system) |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1589 { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1590 genesis_context *gen = (genesis_context *)system; |
2083
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1591 FILE *f; |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1592 if (gen->expansion) { |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1593 segacd_context *cd = gen->expansion; |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1594 char *bram_name = path_append(system->save_dir, "internal.bram"); |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1595 f = fopen(bram_name, "wb"); |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1596 if (f) { |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1597 fwrite(cd->bram, 1, 8 * 1024, f); |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1598 fclose(f); |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1599 printf("Saved internal BRAM to %s\n", bram_name); |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1600 } |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1601 free(bram_name); |
2281
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1602 if (cd->bram_cart_id < 8) { |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1603 bram_name = path_append(system->save_dir, "cart.bram"); |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1604 f = fopen(bram_name, "wb"); |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1605 if (f) { |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1606 long configured_size = 0x2000 << cd->bram_cart_id; |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1607 fwrite(cd->bram_cart, 1, configured_size, f); |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1608 fclose(f); |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1609 printf("Saved BRAM cart to %s\n", bram_name); |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1610 } |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1611 free(bram_name); |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1612 } |
2083
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1613 } |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1614 if (gen->save_type == SAVE_NONE) { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1615 return; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1616 } |
2083
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1617 f = fopen(save_filename, "wb"); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1618 if (!f) { |
1395
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1377
diff
changeset
|
1619 fprintf(stderr, "Failed to open %s file %s for writing\n", save_type_name(gen->save_type), save_filename); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1620 return; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1621 } |
1848
ef3d368d59b0
16-bit wide save RAM is stored in memory byteswapped for performance reasons, but saving it to disc that way isn't great. Swap before save/after load to fix
Michael Pavone <pavone@retrodev.com>
parents:
1798
diff
changeset
|
1622 if (gen->save_type == RAM_FLAG_BOTH) { |
ef3d368d59b0
16-bit wide save RAM is stored in memory byteswapped for performance reasons, but saving it to disc that way isn't great. Swap before save/after load to fix
Michael Pavone <pavone@retrodev.com>
parents:
1798
diff
changeset
|
1623 byteswap_rom(gen->save_size, (uint16_t *)gen->save_storage); |
ef3d368d59b0
16-bit wide save RAM is stored in memory byteswapped for performance reasons, but saving it to disc that way isn't great. Swap before save/after load to fix
Michael Pavone <pavone@retrodev.com>
parents:
1798
diff
changeset
|
1624 } |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1625 fwrite(gen->save_storage, 1, gen->save_size, f); |
1848
ef3d368d59b0
16-bit wide save RAM is stored in memory byteswapped for performance reasons, but saving it to disc that way isn't great. Swap before save/after load to fix
Michael Pavone <pavone@retrodev.com>
parents:
1798
diff
changeset
|
1626 if (gen->save_type == RAM_FLAG_BOTH) { |
ef3d368d59b0
16-bit wide save RAM is stored in memory byteswapped for performance reasons, but saving it to disc that way isn't great. Swap before save/after load to fix
Michael Pavone <pavone@retrodev.com>
parents:
1798
diff
changeset
|
1627 byteswap_rom(gen->save_size, (uint16_t *)gen->save_storage); |
ef3d368d59b0
16-bit wide save RAM is stored in memory byteswapped for performance reasons, but saving it to disc that way isn't great. Swap before save/after load to fix
Michael Pavone <pavone@retrodev.com>
parents:
1798
diff
changeset
|
1628 } |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1629 fclose(f); |
1395
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1377
diff
changeset
|
1630 printf("Saved %s to %s\n", save_type_name(gen->save_type), save_filename); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1631 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1632 |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1633 static void load_save(system_header *system) |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1634 { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1635 genesis_context *gen = (genesis_context *)system; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1636 FILE * f = fopen(save_filename, "rb"); |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1637 if (f) { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1638 uint32_t read = fread(gen->save_storage, 1, gen->save_size, f); |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1639 fclose(f); |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1640 if (read > 0) { |
1848
ef3d368d59b0
16-bit wide save RAM is stored in memory byteswapped for performance reasons, but saving it to disc that way isn't great. Swap before save/after load to fix
Michael Pavone <pavone@retrodev.com>
parents:
1798
diff
changeset
|
1641 if (gen->save_type == RAM_FLAG_BOTH) { |
ef3d368d59b0
16-bit wide save RAM is stored in memory byteswapped for performance reasons, but saving it to disc that way isn't great. Swap before save/after load to fix
Michael Pavone <pavone@retrodev.com>
parents:
1798
diff
changeset
|
1642 byteswap_rom(gen->save_size, (uint16_t *)gen->save_storage); |
ef3d368d59b0
16-bit wide save RAM is stored in memory byteswapped for performance reasons, but saving it to disc that way isn't great. Swap before save/after load to fix
Michael Pavone <pavone@retrodev.com>
parents:
1798
diff
changeset
|
1643 } |
1395
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1377
diff
changeset
|
1644 printf("Loaded %s from %s\n", save_type_name(gen->save_type), save_filename); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1645 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1646 } |
2083
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1647 if (gen->expansion) { |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1648 segacd_context *cd = gen->expansion; |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1649 char *bram_name = path_append(system->save_dir, "internal.bram"); |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1650 f = fopen(bram_name, "rb"); |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1651 if (f) { |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1652 uint32_t read = fread(cd->bram, 1, 8 * 1024, f); |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1653 fclose(f); |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1654 if (read > 0) { |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1655 printf("Loaded internal BRAM from %s\n", bram_name); |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1656 } |
2335
c05b7c5e6f11
Automatically format Sega CD backup RAM
Michael Pavone <pavone@retrodev.com>
parents:
2327
diff
changeset
|
1657 } else { |
c05b7c5e6f11
Automatically format Sega CD backup RAM
Michael Pavone <pavone@retrodev.com>
parents:
2327
diff
changeset
|
1658 segacd_format_bram(cd->bram, 8 * 1024); |
2083
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1659 } |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1660 free(bram_name); |
2281
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1661 bram_name = path_append(system->save_dir, "cart.bram"); |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1662 f = fopen(bram_name, "rb"); |
2335
c05b7c5e6f11
Automatically format Sega CD backup RAM
Michael Pavone <pavone@retrodev.com>
parents:
2327
diff
changeset
|
1663 long configured_size = 0x2000 << cd->bram_cart_id; |
2281
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1664 if (f) { |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1665 long existing_size = nearest_pow2(file_size(f)); |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1666 if (existing_size > 1 * 1024 * 1024) { |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1667 existing_size = 1 * 1024 * 1024; |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1668 } |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1669 if (existing_size != configured_size) { |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1670 if (existing_size > configured_size) { |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1671 free(cd->bram_cart); |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1672 cd->bram_cart = calloc(existing_size, 1); |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1673 } |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1674 cd->bram_cart_id = 0; |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1675 while (existing_size > (0x2000 <<cd->bram_cart_id)) { |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1676 cd->bram_cart_id++; |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1677 } |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1678 } |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1679 uint32_t read = fread(cd->bram_cart, 1, existing_size, f); |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1680 fclose(f); |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1681 if (read > 0) { |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1682 printf("Loaded BRAM cart from %s\n", bram_name); |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1683 } |
2335
c05b7c5e6f11
Automatically format Sega CD backup RAM
Michael Pavone <pavone@retrodev.com>
parents:
2327
diff
changeset
|
1684 } else { |
c05b7c5e6f11
Automatically format Sega CD backup RAM
Michael Pavone <pavone@retrodev.com>
parents:
2327
diff
changeset
|
1685 segacd_format_bram(cd->bram_cart, configured_size); |
2281
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1686 } |
b9fed07f19e4
Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents:
2280
diff
changeset
|
1687 free(bram_name); |
2083
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
1688 } |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1689 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1690 |
1208
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
1691 static void soft_reset(system_header *system) |
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
1692 { |
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
1693 genesis_context *gen = (genesis_context *)system; |
1556
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
1694 if (gen->reset_cycle == CYCLE_NEVER) { |
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
1695 double random = (double)rand()/(double)RAND_MAX; |
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
1696 gen->reset_cycle = gen->m68k->current_cycle + random * MCLKS_LINE * (gen->version_reg & HZ50 ? LINES_PAL : LINES_NTSC); |
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
1697 if (gen->reset_cycle < gen->m68k->target_cycle) { |
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
1698 gen->m68k->target_cycle = gen->reset_cycle; |
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
1699 } |
075df0844baa
Randomize soft reset timing and fix silly bug that was accidentally clearing IO state on soft reset
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
1700 } |
1208
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
1701 } |
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
1702 |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1703 static void free_genesis(system_header *system) |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1704 { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1705 genesis_context *gen = (genesis_context *)system; |
2164
4fbe1e7c4a73
Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents:
2150
diff
changeset
|
1706 if (gen->expansion) { |
4fbe1e7c4a73
Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents:
2150
diff
changeset
|
1707 free_segacd(gen->expansion); |
4fbe1e7c4a73
Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents:
2150
diff
changeset
|
1708 } |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1709 vdp_free(gen->vdp); |
1593
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1592
diff
changeset
|
1710 memmap_chunk *map = (memmap_chunk *)gen->m68k->options->gen.memmap; |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1711 m68k_options_free(gen->m68k->options); |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1712 free(gen->cart); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1713 free(gen->m68k); |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1714 free(gen->work_ram); |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
1715 z80_options_free(gen->z80->Z80_OPTS); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1716 free(gen->z80); |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1717 free(gen->zram); |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1718 ym_free(gen->ym); |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1719 psg_free(gen->psg); |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1720 free(gen->header.save_dir); |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
1721 free_rom_info(&gen->header.info); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1722 free(gen->lock_on); |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
1723 if (gen->save_type != SAVE_NONE && gen->mapper_type != MAPPER_SEGA_MED_V2) { |
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
1724 free(gen->save_storage); |
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
1725 } |
2248
f7e2e11f1214
Fix improper free of memory map array from rom_info
Michael Pavone <pavone@retrodev.com>
parents:
2243
diff
changeset
|
1726 free(map); |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1727 free(gen); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1728 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
1729 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1730 static void gamepad_down(system_header *system, uint8_t gamepad_num, uint8_t button) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1731 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1732 genesis_context *gen = (genesis_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1733 io_gamepad_down(&gen->io, gamepad_num, button); |
1610 | 1734 if (gen->mapper_type == MAPPER_JCART) { |
1735 jcart_gamepad_down(gen, gamepad_num, button); | |
1736 } | |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1737 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1738 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1739 static void gamepad_up(system_header *system, uint8_t gamepad_num, uint8_t button) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1740 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1741 genesis_context *gen = (genesis_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1742 io_gamepad_up(&gen->io, gamepad_num, button); |
1610 | 1743 if (gen->mapper_type == MAPPER_JCART) { |
1744 jcart_gamepad_up(gen, gamepad_num, button); | |
1745 } | |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1746 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1747 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1748 static void mouse_down(system_header *system, uint8_t mouse_num, uint8_t button) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1749 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1750 genesis_context *gen = (genesis_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1751 io_mouse_down(&gen->io, mouse_num, button); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1752 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1753 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1754 static void mouse_up(system_header *system, uint8_t mouse_num, uint8_t button) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1755 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1756 genesis_context *gen = (genesis_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1757 io_mouse_up(&gen->io, mouse_num, button); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1758 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1759 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1760 static void mouse_motion_absolute(system_header *system, uint8_t mouse_num, uint16_t x, uint16_t y) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1761 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1762 genesis_context *gen = (genesis_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1763 io_mouse_motion_absolute(&gen->io, mouse_num, x, y); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1764 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1765 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1766 static void mouse_motion_relative(system_header *system, uint8_t mouse_num, int32_t x, int32_t y) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1767 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1768 genesis_context *gen = (genesis_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1769 io_mouse_motion_relative(&gen->io, mouse_num, x, y); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1770 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1771 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1772 static void keyboard_down(system_header *system, uint8_t scancode) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1773 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1774 genesis_context *gen = (genesis_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1775 io_keyboard_down(&gen->io, scancode); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1776 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1777 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1778 static void keyboard_up(system_header *system, uint8_t scancode) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1779 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1780 genesis_context *gen = (genesis_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1781 io_keyboard_up(&gen->io, scancode); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1782 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1783 |
1798
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
1784 static void set_audio_config(genesis_context *gen) |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1766
diff
changeset
|
1785 { |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1766
diff
changeset
|
1786 char *config_gain; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1766
diff
changeset
|
1787 config_gain = tern_find_path(config, "audio\0psg_gain\0", TVAL_PTR).ptrval; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1766
diff
changeset
|
1788 render_audio_source_gaindb(gen->psg->audio, config_gain ? atof(config_gain) : 0.0f); |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1766
diff
changeset
|
1789 config_gain = tern_find_path(config, "audio\0fm_gain\0", TVAL_PTR).ptrval; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1766
diff
changeset
|
1790 render_audio_source_gaindb(gen->ym->audio, config_gain ? atof(config_gain) : 0.0f); |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
1791 |
1798
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
1792 char *config_dac = tern_find_path_default(config, "audio\0fm_dac\0", (tern_val){.ptrval="zero_offset"}, TVAL_PTR).ptrval; |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
1793 ym_enable_zero_offset(gen->ym, !strcmp(config_dac, "zero_offset")); |
2277
9e578fd493e1
Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2272
diff
changeset
|
1794 |
9e578fd493e1
Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2272
diff
changeset
|
1795 if (gen->expansion) { |
9e578fd493e1
Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2272
diff
changeset
|
1796 segacd_context *cd = gen->expansion; |
9e578fd493e1
Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2272
diff
changeset
|
1797 config_gain = tern_find_path(config, "audio\0rf5c164_gain\0", TVAL_PTR).ptrval; |
9e578fd493e1
Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2272
diff
changeset
|
1798 render_audio_source_gaindb(cd->pcm.audio, config_gain ? atof(config_gain) : -6.0f); |
9e578fd493e1
Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2272
diff
changeset
|
1799 config_gain = tern_find_path(config, "audio\0cdda_gain\0", TVAL_PTR).ptrval; |
9e578fd493e1
Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2272
diff
changeset
|
1800 render_audio_source_gaindb(cd->fader.audio, config_gain ? atof(config_gain) : -9.5f); |
9e578fd493e1
Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2272
diff
changeset
|
1801 } |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1766
diff
changeset
|
1802 } |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1766
diff
changeset
|
1803 |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
1804 static void config_updated(system_header *system) |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
1805 { |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
1806 genesis_context *gen = (genesis_context *)system; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
1807 setup_io_devices(config, &system->info, &gen->io); |
1798
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
1808 set_audio_config(gen); |
2384
03e6ac327ba0
Handle changes to sample rate while content is running
Michael Pavone <pavone@retrodev.com>
parents:
2354
diff
changeset
|
1809 //sample rate may have changed |
03e6ac327ba0
Handle changes to sample rate while content is running
Michael Pavone <pavone@retrodev.com>
parents:
2354
diff
changeset
|
1810 ym_adjust_master_clock(gen->ym, gen->master_clock); |
03e6ac327ba0
Handle changes to sample rate while content is running
Michael Pavone <pavone@retrodev.com>
parents:
2354
diff
changeset
|
1811 psg_adjust_master_clock(gen->psg, gen->master_clock); |
03e6ac327ba0
Handle changes to sample rate while content is running
Michael Pavone <pavone@retrodev.com>
parents:
2354
diff
changeset
|
1812 if (gen->expansion) { |
03e6ac327ba0
Handle changes to sample rate while content is running
Michael Pavone <pavone@retrodev.com>
parents:
2354
diff
changeset
|
1813 segacd_config_updated(gen->expansion); |
03e6ac327ba0
Handle changes to sample rate while content is running
Michael Pavone <pavone@retrodev.com>
parents:
2354
diff
changeset
|
1814 } |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
1815 } |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
1816 |
1909
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1817 static void start_vgm_log(system_header *system, char *filename) |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1818 { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1819 genesis_context *gen = (genesis_context *)system; |
2254
8b88d57d1218
Prevent VGM logging from getting messed up if slow/turbo is active at log start time
Michael Pavone <pavone@retrodev.com>
parents:
2248
diff
changeset
|
1820 vgm_writer *vgm = vgm_write_open(filename, gen->version_reg & HZ50 ? 50 : 60, gen->normal_clock, gen->m68k->current_cycle); |
1909
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1821 if (vgm) { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1822 printf("Started logging VGM to %s\n", filename); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1823 sync_sound(gen, vgm->last_cycle); |
2254
8b88d57d1218
Prevent VGM logging from getting messed up if slow/turbo is active at log start time
Michael Pavone <pavone@retrodev.com>
parents:
2248
diff
changeset
|
1824 ym_vgm_log(gen->ym, gen->normal_clock, vgm); |
8b88d57d1218
Prevent VGM logging from getting messed up if slow/turbo is active at log start time
Michael Pavone <pavone@retrodev.com>
parents:
2248
diff
changeset
|
1825 psg_vgm_log(gen->psg, gen->normal_clock, vgm); |
1909
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1826 gen->header.vgm_logging = 1; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1827 } else { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1828 printf("Failed to start logging to %s\n", filename); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1829 } |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1830 } |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1831 |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1832 static void stop_vgm_log(system_header *system) |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1833 { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1834 puts("Stopped VGM log"); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1835 genesis_context *gen = (genesis_context *)system; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1836 vgm_close(gen->ym->vgm); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1837 gen->ym->vgm = gen->psg->vgm = NULL; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1838 gen->header.vgm_logging = 0; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1839 } |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1840 |
2243
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1841 static void toggle_debug_view(system_header *system, uint8_t debug_view) |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1842 { |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2286
diff
changeset
|
1843 #ifndef IS_LIB |
2243
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1844 genesis_context *gen = (genesis_context *)system; |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1845 if (debug_view < DEBUG_OSCILLOSCOPE) { |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1846 vdp_toggle_debug_view(gen->vdp, debug_view); |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1847 } else if (debug_view == DEBUG_OSCILLOSCOPE) { |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1848 if (gen->ym->scope) { |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1849 oscilloscope *scope = gen->ym->scope; |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1850 gen->ym->scope = NULL; |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1851 gen->psg->scope = NULL; |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1852 if (gen->expansion) { |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1853 segacd_context *cd = gen->expansion; |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1854 cd->pcm.scope = NULL; |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1855 } |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1856 scope_close(scope); |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1857 } else { |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1858 oscilloscope *scope = create_oscilloscope(); |
2255
74112041b2c7
Proper calculation of sample rate for YM2612/PSG oscilloscope view
Michael Pavone <pavone@retrodev.com>
parents:
2254
diff
changeset
|
1859 ym_enable_scope(gen->ym, scope, gen->normal_clock); |
74112041b2c7
Proper calculation of sample rate for YM2612/PSG oscilloscope view
Michael Pavone <pavone@retrodev.com>
parents:
2254
diff
changeset
|
1860 psg_enable_scope(gen->psg, scope, gen->normal_clock); |
2243
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1861 if (gen->expansion) { |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1862 segacd_context *cd = gen->expansion; |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1863 rf5c164_enable_scope(&cd->pcm, scope); |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1864 } |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1865 } |
2271
3ef80963c2a7
Fix stamp address mask and add WIP CD graphics debug view
Michael Pavone <pavone@retrodev.com>
parents:
2267
diff
changeset
|
1866 } else if (debug_view == DEBUG_CD_GRAPHICS && gen->expansion) { |
3ef80963c2a7
Fix stamp address mask and add WIP CD graphics debug view
Michael Pavone <pavone@retrodev.com>
parents:
2267
diff
changeset
|
1867 scd_toggle_graphics_debug(gen->expansion); |
2243
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1868 } |
2302
0343f0d5add0
Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents:
2286
diff
changeset
|
1869 #endif |
2243
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1870 } |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
1871 |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1872 static void *tmss_rom_write_16(uint32_t address, void *context, uint16_t value) |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1873 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1874 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1875 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1876 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1877 return gen->tmss_write_16(address, context, value); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1878 } |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
1879 |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1880 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1881 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1882 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1883 static void *tmss_rom_write_8(uint32_t address, void *context, uint8_t value) |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1884 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1885 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1886 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1887 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1888 return gen->tmss_write_8(address, context, value); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1889 } |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
1890 |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1891 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1892 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1893 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1894 static uint16_t tmss_rom_read_16(uint32_t address, void *context) |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1895 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1896 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1897 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1898 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1899 return gen->tmss_read_16(address, context); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1900 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1901 return ((uint16_t *)gen->tmss_buffer)[address >> 1]; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1902 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1903 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1904 static uint8_t tmss_rom_read_8(uint32_t address, void *context) |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1905 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1906 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1907 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1908 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1909 return gen->tmss_read_8(address, context); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1910 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1911 #ifdef BLASTEM_BIG_ENDIAN |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1912 return gen->tmss_buffer[address]; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1913 #else |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1914 return gen->tmss_buffer[address ^ 1]; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1915 #endif |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1916 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1917 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1918 static void *tmss_word_write_16(uint32_t address, void *context, uint16_t value) |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1919 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1920 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1921 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1922 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1923 address += gen->tmss_write_offset; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1924 uint16_t *dest = get_native_pointer(address, (void **)m68k->mem_pointers, &m68k->options->gen); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1925 *dest = value; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1926 m68k_handle_code_write(address, m68k); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1927 } |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
1928 |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1929 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1930 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1931 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1932 static void *tmss_word_write_8(uint32_t address, void *context, uint8_t value) |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1933 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1934 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1935 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1936 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1937 address += gen->tmss_write_offset; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1938 uint8_t *dest = get_native_pointer(address & ~1, (void **)m68k->mem_pointers, &m68k->options->gen); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1939 #ifdef BLASTEM_BIG_ENDIAN |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1940 dest[address & 1] = value; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1941 #else |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1942 dest[address & 1 ^ 1] = value; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1943 #endif |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1944 m68k_handle_code_write(address & ~1, m68k); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1945 } |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
1946 |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1947 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1948 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1949 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1950 static void *tmss_odd_write_16(uint32_t address, void *context, uint16_t value) |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1951 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1952 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1953 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1954 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1955 memmap_chunk const *chunk = find_map_chunk(address + gen->tmss_write_offset, &m68k->options->gen, 0, NULL); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1956 address >>= 1; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1957 uint8_t *base = (uint8_t *)m68k->mem_pointers[chunk->ptr_index]; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1958 base[address] = value; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1959 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1960 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1961 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1962 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1963 static void *tmss_odd_write_8(uint32_t address, void *context, uint8_t value) |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1964 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1965 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1966 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1967 if (gen->tmss && (address & 1)) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1968 memmap_chunk const *chunk = find_map_chunk(address + gen->tmss_write_offset, &m68k->options->gen, 0, NULL); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1969 address >>= 1; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1970 uint8_t *base = (uint8_t *)m68k->mem_pointers[chunk->ptr_index]; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1971 base[address] = value; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1972 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1973 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1974 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1975 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1976 static void *tmss_even_write_16(uint32_t address, void *context, uint16_t value) |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1977 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1978 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1979 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1980 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1981 memmap_chunk const *chunk = find_map_chunk(address + gen->tmss_write_offset, &m68k->options->gen, 0, NULL); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1982 address >>= 1; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1983 uint8_t *base = (uint8_t *)m68k->mem_pointers[chunk->ptr_index]; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1984 base[address] = value >> 8; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1985 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1986 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1987 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1988 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1989 static void *tmss_even_write_8(uint32_t address, void *context, uint8_t value) |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1990 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1991 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1992 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1993 if (gen->tmss && !(address & 1)) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1994 memmap_chunk const *chunk = find_map_chunk(address + gen->tmss_write_offset, &m68k->options->gen, 0, NULL); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1995 address >>= 1; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1996 uint8_t *base = (uint8_t *)m68k->mem_pointers[chunk->ptr_index]; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1997 base[address] = value; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1998 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1999 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2000 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2001 |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2002 static genesis_context *shared_init(uint32_t system_opts, rom_info *rom, uint8_t force_region) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2003 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2004 static memmap_chunk z80_map[] = { |
2134
9caebcfeac72
Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents:
2090
diff
changeset
|
2005 { 0x0000, 0x4000, 0x1FFF, .flags = MMAP_READ | MMAP_WRITE | MMAP_CODE}, |
9caebcfeac72
Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents:
2090
diff
changeset
|
2006 { 0x8000, 0x10000, 0x7FFF, .read_8 = z80_read_bank, .write_8 = z80_write_bank}, |
9caebcfeac72
Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents:
2090
diff
changeset
|
2007 { 0x4000, 0x6000, 0x0003, .read_8 = z80_read_ym, .write_8 = z80_write_ym}, |
9caebcfeac72
Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents:
2090
diff
changeset
|
2008 { 0x6000, 0x6100, 0xFFFF, .write_8 = z80_write_bank_reg}, |
9caebcfeac72
Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents:
2090
diff
changeset
|
2009 { 0x7F00, 0x8000, 0x00FF, .read_8 = z80_vdp_port_read, .write_8 = z80_vdp_port_write} |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2010 }; |
2053 | 2011 |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2012 char *m68k_divider = tern_find_path(config, "clocks\0m68k_divider\0", TVAL_PTR).ptrval; |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2013 if (!m68k_divider) { |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2014 m68k_divider = "7"; |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2015 } |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2016 MCLKS_PER_68K = atoi(m68k_divider); |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2017 if (!MCLKS_PER_68K) { |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2018 MCLKS_PER_68K = 7; |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2019 } |
2053 | 2020 |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2021 genesis_context *gen = calloc(1, sizeof(genesis_context)); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
2022 gen->header.set_speed_percent = set_speed_percent; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
2023 gen->header.start_context = start_genesis; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
2024 gen->header.resume_context = resume_genesis; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
2025 gen->header.load_save = load_save; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
2026 gen->header.persist_save = persist_save; |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
2027 gen->header.load_state = load_state; |
1208
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
2028 gen->header.soft_reset = soft_reset; |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
2029 gen->header.free_context = free_genesis; |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
2030 gen->header.get_open_bus_value = get_open_bus_value; |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
2031 gen->header.request_exit = request_exit; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1108
diff
changeset
|
2032 gen->header.inc_debug_mode = inc_debug_mode; |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
2033 gen->header.gamepad_down = gamepad_down; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
2034 gen->header.gamepad_up = gamepad_up; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
2035 gen->header.mouse_down = mouse_down; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
2036 gen->header.mouse_up = mouse_up; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
2037 gen->header.mouse_motion_absolute = mouse_motion_absolute; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
2038 gen->header.mouse_motion_relative = mouse_motion_relative; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
2039 gen->header.keyboard_down = keyboard_down; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
2040 gen->header.keyboard_up = keyboard_up; |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
2041 gen->header.config_updated = config_updated; |
1690
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
2042 gen->header.serialize = serialize; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
2043 gen->header.deserialize = deserialize; |
1909
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
2044 gen->header.start_vgm_log = start_vgm_log; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
2045 gen->header.stop_vgm_log = stop_vgm_log; |
2243
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2228
diff
changeset
|
2046 gen->header.toggle_debug_view = toggle_debug_view; |
1377
e587f16e7d3d
Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents:
1374
diff
changeset
|
2047 gen->header.type = SYSTEM_GENESIS; |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
2048 gen->header.info = *rom; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2049 set_region(gen, rom, force_region); |
1901
5433252329fb
Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents:
1889
diff
changeset
|
2050 tern_node *model = get_model(config, SYSTEM_GENESIS); |
5433252329fb
Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents:
1889
diff
changeset
|
2051 uint8_t tmss = !strcmp(tern_find_ptr_default(model, "tmss", "off"), "on"); |
5433252329fb
Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents:
1889
diff
changeset
|
2052 if (tmss) { |
5433252329fb
Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents:
1889
diff
changeset
|
2053 gen->version_reg |= 1; |
2037
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
2054 } else { |
b0b0c31338c3
Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents:
2034
diff
changeset
|
2055 gen->vdp_unlocked = 1; |
1901
5433252329fb
Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents:
1889
diff
changeset
|
2056 } |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2057 |
1906
2d462aa78349
Make VDP VSRAM capacity respect model selection
Michael Pavone <pavone@retrodev.com>
parents:
1904
diff
changeset
|
2058 uint8_t max_vsram = !strcmp(tern_find_ptr_default(model, "vsram", "40"), "64"); |
2194
01ff005b08f6
Very rudimentary support for Game Gear VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
2184
diff
changeset
|
2059 gen->vdp = init_vdp_context(gen->version_reg & 0x40, max_vsram, VDP_GENESIS); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
2060 gen->vdp->system = &gen->header; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2061 gen->frame_end = vdp_cycles_to_frame_end(gen->vdp); |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1318
diff
changeset
|
2062 char * config_cycles = tern_find_path(config, "clocks\0max_cycles\0", TVAL_PTR).ptrval; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2063 gen->max_cycles = config_cycles ? atoi(config_cycles) : DEFAULT_SYNC_INTERVAL; |
1364
30123ca5856c
Added some code to try and prevent Z80 accesses and refresh cycles from screwing up interrupt latency more than on hardware
Michael Pavone <pavone@retrodev.com>
parents:
1348
diff
changeset
|
2064 gen->int_latency_prev1 = MCLKS_PER_68K * 32; |
30123ca5856c
Added some code to try and prevent Z80 accesses and refresh cycles from screwing up interrupt latency more than on hardware
Michael Pavone <pavone@retrodev.com>
parents:
1348
diff
changeset
|
2065 gen->int_latency_prev2 = MCLKS_PER_68K * 16; |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
2066 |
1565
61fafcbc2c38
Audio DRC now sounds good in both NTSC and PAL, just need to adjust constants to minimize latency without leading to dropouts
Michael Pavone <pavone@retrodev.com>
parents:
1557
diff
changeset
|
2067 render_set_video_standard((gen->version_reg & HZ50) ? VID_PAL : VID_NTSC); |
1946 | 2068 event_system_start(SYSTEM_GENESIS, (gen->version_reg & HZ50) ? VID_PAL : VID_NTSC, rom->name); |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
2069 |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2070 gen->ym = malloc(sizeof(ym2612_context)); |
1904
8312e574100a
Implement selectable YM2612/YM3834 invalid status port behavior
Michael Pavone <pavone@retrodev.com>
parents:
1902
diff
changeset
|
2071 char *fm = tern_find_ptr_default(model, "fm", "discrete 2612"); |
8312e574100a
Implement selectable YM2612/YM3834 invalid status port behavior
Michael Pavone <pavone@retrodev.com>
parents:
1902
diff
changeset
|
2072 if (!strcmp(fm + strlen(fm) -4, "3834")) { |
8312e574100a
Implement selectable YM2612/YM3834 invalid status port behavior
Michael Pavone <pavone@retrodev.com>
parents:
1902
diff
changeset
|
2073 system_opts |= YM_OPT_3834; |
8312e574100a
Implement selectable YM2612/YM3834 invalid status port behavior
Michael Pavone <pavone@retrodev.com>
parents:
1902
diff
changeset
|
2074 } |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
2075 ym_init(gen->ym, gen->master_clock, MCLKS_PER_YM, system_opts); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2076 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2077 gen->psg = malloc(sizeof(psg_context)); |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
2078 psg_init(gen->psg, gen->master_clock, MCLKS_PER_PSG); |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
2079 |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2080 z80_map[0].buffer = gen->zram = calloc(1, Z80_RAM_BYTES); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2081 #ifndef NO_Z80 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2082 z80_options *z_opts = malloc(sizeof(z80_options)); |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
2083 init_z80_opts(z_opts, z80_map, 5, NULL, 0, MCLKS_PER_Z80, 0xFFFF); |
1130
8f14767661fa
Remove memory map assumptions from Z80 core and move a little bit of logic to the generic backend.c so it can be shared between CPU cores
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
2084 gen->z80 = init_z80_context(z_opts); |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
2085 #ifndef NEW_CORE |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
2086 gen->z80->next_int_pulse = z80_next_int_pulse; |
1752
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
2087 #endif |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2088 z80_assert_reset(gen->z80, 0); |
1130
8f14767661fa
Remove memory map assumptions from Z80 core and move a little bit of logic to the generic backend.c so it can be shared between CPU cores
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
2089 #else |
8f14767661fa
Remove memory map assumptions from Z80 core and move a little bit of logic to the generic backend.c so it can be shared between CPU cores
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
2090 gen->z80 = calloc(1, sizeof(z80_context)); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2091 #endif |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2092 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2093 gen->z80->system = gen; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2094 gen->z80->mem_pointers[0] = gen->zram; |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2095 gen->z80->mem_pointers[1] = gen->z80->mem_pointers[2] = NULL; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2096 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2097 gen->work_ram = calloc(2, RAM_WORDS); |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1318
diff
changeset
|
2098 if (!strcmp("random", tern_find_path_default(config, "system\0ram_init\0", (tern_val){.ptrval = "zero"}, TVAL_PTR).ptrval)) |
1204
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2099 { |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2100 srand(time(NULL)); |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2101 for (int i = 0; i < RAM_WORDS; i++) |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2102 { |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2103 gen->work_ram[i] = rand(); |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2104 } |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2105 for (int i = 0; i < Z80_RAM_BYTES; i++) |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2106 { |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2107 gen->zram[i] = rand(); |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2108 } |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2109 for (int i = 0; i < VRAM_SIZE; i++) |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2110 { |
1333
69c25e1188e5
Small tweak to how SAT cache updates are done. Mostly fixes the rotating cube scene in Overdrive 2
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
2111 gen->vdp->vdpmem[i] = rand(); |
69c25e1188e5
Small tweak to how SAT cache updates are done. Mostly fixes the rotating cube scene in Overdrive 2
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
2112 } |
69c25e1188e5
Small tweak to how SAT cache updates are done. Mostly fixes the rotating cube scene in Overdrive 2
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
2113 for (int i = 0; i < SAT_CACHE_SIZE; i++) |
69c25e1188e5
Small tweak to how SAT cache updates are done. Mostly fixes the rotating cube scene in Overdrive 2
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
2114 { |
69c25e1188e5
Small tweak to how SAT cache updates are done. Mostly fixes the rotating cube scene in Overdrive 2
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
2115 gen->vdp->sat_cache[i] = rand(); |
1204
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2116 } |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2117 for (int i = 0; i < CRAM_SIZE; i++) |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2118 { |
1428
2540c05520f2
New savestates are working. New config file option for selecting format states will be saved in. Mostly complete, needs a little more work before release
Michael Pavone <pavone@retrodev.com>
parents:
1427
diff
changeset
|
2119 write_cram_internal(gen->vdp, i, rand()); |
1204
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2120 } |
1906
2d462aa78349
Make VDP VSRAM capacity respect model selection
Michael Pavone <pavone@retrodev.com>
parents:
1904
diff
changeset
|
2121 for (int i = 0; i < gen->vdp->vsram_size; i++) |
1204
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2122 { |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2123 gen->vdp->vsram[i] = rand(); |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2124 } |
d7be5b6e0a8d
Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents:
1188
diff
changeset
|
2125 } |
2053 | 2126 |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2127 return gen; |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2128 } |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2129 |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2130 static memmap_chunk base_map[] = { |
2134
9caebcfeac72
Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents:
2090
diff
changeset
|
2131 {0xE00000, 0x1000000, 0xFFFF, .flags = MMAP_READ | MMAP_WRITE | MMAP_CODE}, |
9caebcfeac72
Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents:
2090
diff
changeset
|
2132 {0xC00000, 0xE00000, 0x1FFFFF, .read_16 = (read_16_fun)vdp_port_read, .write_16 =(write_16_fun)vdp_port_write, |
9caebcfeac72
Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents:
2090
diff
changeset
|
2133 .read_8 = (read_8_fun)vdp_port_read_b, .write_8 = (write_8_fun)vdp_port_write_b}, |
9caebcfeac72
Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents:
2090
diff
changeset
|
2134 {0xA00000, 0xA12000, 0x1FFFF, .read_16 = (read_16_fun)io_read_w, .write_16 = (write_16_fun)io_write_w, |
9caebcfeac72
Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents:
2090
diff
changeset
|
2135 .read_8 = (read_8_fun)io_read, .write_8 = (write_8_fun)io_write}, |
9caebcfeac72
Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents:
2090
diff
changeset
|
2136 {0x000000, 0xFFFFFF, 0xFFFFFF, .read_16 = (read_16_fun)unused_read, .write_16 = unused_write, |
9caebcfeac72
Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents:
2090
diff
changeset
|
2137 .read_8 = (read_8_fun)unused_read_b, .write_8 = (write_8_fun)unused_write_b} |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2138 }; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2139 const size_t base_chunks = sizeof(base_map)/sizeof(*base_map); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2140 |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2141 genesis_context *alloc_config_genesis(void *rom, uint32_t rom_size, void *lock_on, uint32_t lock_on_size, uint32_t ym_opts, uint8_t force_region) |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2142 { |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2143 tern_node *rom_db = get_rom_db(); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2144 rom_info info = configure_rom(rom_db, rom, rom_size, lock_on, lock_on_size, base_map, base_chunks); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2145 rom = info.rom; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2146 rom_size = info.rom_size; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2147 #ifndef BLASTEM_BIG_ENDIAN |
2150
a418fa599b2e
Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents:
2134
diff
changeset
|
2148 byteswap_rom(nearest_pow2(rom_size), rom); |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2149 if (lock_on) { |
2150
a418fa599b2e
Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents:
2134
diff
changeset
|
2150 byteswap_rom(nearest_pow2(lock_on_size), lock_on); |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2151 } |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2152 #endif |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2153 char *m68k_divider = tern_find_path(config, "clocks\0m68k_divider\0", TVAL_PTR).ptrval; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2154 if (!m68k_divider) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2155 m68k_divider = "7"; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2156 } |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2157 MCLKS_PER_68K = atoi(m68k_divider); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2158 if (!MCLKS_PER_68K) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2159 MCLKS_PER_68K = 7; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2160 } |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2161 genesis_context *gen = shared_init(ym_opts, &info, force_region); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2162 gen->z80->mem_pointers[1] = gen->z80->mem_pointers[2] = rom; |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2163 |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2164 gen->cart = rom; |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2165 gen->lock_on = lock_on; |
2053 | 2166 |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2167 setup_io_devices(config, &info, &gen->io); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
2168 gen->header.has_keyboard = io_has_keyboard(&gen->io); |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2169 gen->mapper_type = info.mapper_type; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2170 gen->save_type = info.save_type; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2171 if (gen->save_type != SAVE_NONE) { |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2172 gen->save_ram_mask = info.save_mask; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2173 gen->save_size = info.save_size; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2174 gen->save_storage = info.save_buffer; |
2286
5d3411f52d00
Fix ui.reload for locked-on ROMs
Michael Pavone <pavone@retrodev.com>
parents:
2281
diff
changeset
|
2175 gen->header.info.save_buffer = info.save_buffer = NULL; |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2176 gen->eeprom_map = info.eeprom_map; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2177 gen->num_eeprom = info.num_eeprom; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2178 if (gen->save_type == SAVE_I2C) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2179 eeprom_init(&gen->eeprom, gen->save_storage, gen->save_size); |
1395
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1377
diff
changeset
|
2180 } else if (gen->save_type == SAVE_NOR) { |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2181 memcpy(&gen->nor, info.nor, sizeof(gen->nor)); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2182 //nor_flash_init(&gen->nor, gen->save_storage, gen->save_size, info.save_page_size, info.save_product_id, info.save_bus); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2183 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2184 } else { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2185 gen->save_storage = NULL; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2186 } |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
2187 |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2188 gen->mapper_start_index = info.mapper_start_index; |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
2189 |
2053 | 2190 tern_node *model = get_model(config, SYSTEM_GENESIS); |
2191 uint8_t tmss = !strcmp(tern_find_ptr_default(model, "tmss", "off"), "on"); | |
2192 | |
1165
9fc680b35dbb
Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
2193 //This must happen before we generate memory access functions in init_m68k_opts |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2194 uint8_t next_ptr_index = 0; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2195 uint32_t tmss_min_alloc = 16 * 1024; |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2196 for (int i = 0; i < info.map_chunks; i++) |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2197 { |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2198 if (info.map[i].start == 0xE00000) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2199 info.map[i].buffer = gen->work_ram; |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2200 if (!tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2201 break; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2202 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2203 } |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2204 if (info.map[i].flags & MMAP_PTR_IDX && info.map[i].ptr_index >= next_ptr_index) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2205 next_ptr_index = info.map[i].ptr_index + 1; |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2206 } |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2207 if (info.map[i].start < 0x400000 && info.map[i].read_16 != unused_read) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2208 uint32_t highest_offset = (info.map[i].end & info.map[i].mask) + 1; |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2209 if (highest_offset > tmss_min_alloc) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2210 tmss_min_alloc = highest_offset; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2211 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2212 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2213 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2214 if (tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2215 char *tmss_path = tern_find_path_default(config, "system\0tmss_path\0", (tern_val){.ptrval = "tmss.md"}, TVAL_PTR).ptrval; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2216 uint8_t *buffer = malloc(tmss_min_alloc); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2217 uint32_t tmss_size; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2218 if (is_absolute_path(tmss_path)) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2219 FILE *f = fopen(tmss_path, "rb"); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2220 if (!f) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2221 fatal_error("Configured to use a model with TMSS, but failed to load the TMSS ROM from %s\n", tmss_path); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2222 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2223 tmss_size = fread(buffer, 1, tmss_min_alloc, f); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2224 fclose(f); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2225 } else { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2226 char *tmp = read_bundled_file(tmss_path, &tmss_size); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2227 if (!tmp) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2228 fatal_error("Configured to use a model with TMSS, but failed to load the TMSS ROM from %s\n", tmss_path); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2229 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2230 memcpy(buffer, tmp, tmss_size); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2231 free(tmp); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2232 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2233 for (uint32_t padded = nearest_pow2(tmss_size); tmss_size < padded; tmss_size++) |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2234 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2235 buffer[tmss_size] = 0xFF; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2236 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2237 #ifndef BLASTEM_BIG_ENDIAN |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2238 byteswap_rom(tmss_size, (uint16_t *)buffer); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2239 #endif |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2240 //mirror TMSS ROM until we fill up to tmss_min_alloc |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2241 for (uint32_t dst = tmss_size; dst < tmss_min_alloc; dst += tmss_size) |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2242 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2243 memcpy(buffer + dst, buffer, dst + tmss_size > tmss_min_alloc ? tmss_min_alloc - dst : tmss_size); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2244 } |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2245 //modify mappings for ROM space to point to the TMSS ROM and fixup flags to allow switching back and forth |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2246 //WARNING: This code makes some pretty big assumptions about the kinds of map chunks it will encounter |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2247 for (int i = 0; i < info.map_chunks; i++) |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2248 { |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2249 if (info.map[i].start < 0x400000 && info.map[i].read_16 != unused_read) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2250 if (info.map[i].flags == MMAP_READ) { |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2251 //Normal ROM |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2252 info.map[i].flags |= MMAP_PTR_IDX | MMAP_CODE; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2253 info.map[i].ptr_index = next_ptr_index++; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2254 if (info.map[i].ptr_index >= NUM_MEM_AREAS) { |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2255 fatal_error("Too many memmap chunks with MMAP_PTR_IDX after TMSS remap\n"); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2256 } |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2257 gen->tmss_pointers[info.map[i].ptr_index] = info.map[i].buffer; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2258 info.map[i].buffer = buffer + (info.map[i].start & ~info.map[i].mask & (tmss_size - 1)); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2259 } else if (info.map[i].flags & MMAP_PTR_IDX) { |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2260 //Sega mapper page or multi-game mapper |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2261 gen->tmss_pointers[info.map[i].ptr_index] = info.map[i].buffer; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2262 info.map[i].buffer = buffer + (info.map[i].start & ~info.map[i].mask & (tmss_size - 1)); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2263 if (info.map[i].write_16) { |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2264 if (!gen->tmss_write_16) { |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2265 gen->tmss_write_16 = info.map[i].write_16; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2266 gen->tmss_write_8 = info.map[i].write_8; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2267 info.map[i].write_16 = tmss_rom_write_16; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2268 info.map[i].write_8 = tmss_rom_write_8; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2269 } else if (gen->tmss_write_16 == info.map[i].write_16) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2270 info.map[i].write_16 = tmss_rom_write_16; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2271 info.map[i].write_8 = tmss_rom_write_8; |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2272 } else { |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2273 warning("Chunk starting at %X has a write function, but we've already stored a different one for TMSS remap\n", info.map[i].start); |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2274 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2275 } |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2276 } else if ((info.map[i].flags & (MMAP_READ | MMAP_WRITE)) == (MMAP_READ | MMAP_WRITE)) { |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2277 //RAM or SRAM |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2278 info.map[i].flags |= MMAP_PTR_IDX; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2279 info.map[i].ptr_index = next_ptr_index++; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2280 gen->tmss_pointers[info.map[i].ptr_index] = info.map[i].buffer; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2281 info.map[i].buffer = buffer + (info.map[i].start & ~info.map[i].mask & (tmss_size - 1)); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2282 if (!gen->tmss_write_offset || gen->tmss_write_offset == info.map[i].start) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2283 gen->tmss_write_offset = info.map[i].start; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2284 info.map[i].flags &= ~MMAP_WRITE; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2285 if (info.map[i].flags & MMAP_ONLY_ODD) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2286 info.map[i].write_16 = tmss_odd_write_16; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2287 info.map[i].write_8 = tmss_odd_write_8; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2288 } else if (info.map[i].flags & MMAP_ONLY_EVEN) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2289 info.map[i].write_16 = tmss_even_write_16; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2290 info.map[i].write_8 = tmss_even_write_8; |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2291 } else { |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2292 info.map[i].write_16 = tmss_word_write_16; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2293 info.map[i].write_8 = tmss_word_write_8; |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2294 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2295 } else { |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2296 warning("Could not remap writes for chunk starting at %X for TMSS because write_offset is %X\n", info.map[i].start, gen->tmss_write_offset); |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2297 } |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2298 } else if (info.map[i].flags & MMAP_READ_CODE) { |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2299 //NOR flash |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2300 info.map[i].flags |= MMAP_PTR_IDX; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2301 info.map[i].ptr_index = next_ptr_index++; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2302 if (info.map[i].ptr_index >= NUM_MEM_AREAS) { |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2303 fatal_error("Too many memmap chunks with MMAP_PTR_IDX after TMSS remap\n"); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2304 } |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2305 gen->tmss_pointers[info.map[i].ptr_index] = info.map[i].buffer; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2306 info.map[i].buffer = buffer + (info.map[i].start & ~info.map[i].mask & (tmss_size - 1)); |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2307 if (!gen->tmss_write_16) { |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2308 gen->tmss_write_16 = info.map[i].write_16; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2309 gen->tmss_write_8 = info.map[i].write_8; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2310 gen->tmss_read_16 = info.map[i].read_16; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2311 gen->tmss_read_8 = info.map[i].read_8; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2312 info.map[i].write_16 = tmss_rom_write_16; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2313 info.map[i].write_8 = tmss_rom_write_8; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2314 info.map[i].read_16 = tmss_rom_read_16; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2315 info.map[i].read_8 = tmss_rom_read_8; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2316 } else if (gen->tmss_write_16 == info.map[i].write_16) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2317 info.map[i].write_16 = tmss_rom_write_16; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2318 info.map[i].write_8 = tmss_rom_write_8; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2319 info.map[i].read_16 = tmss_rom_read_16; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2320 info.map[i].read_8 = tmss_rom_read_8; |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2321 } else { |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2322 warning("Chunk starting at %X has a write function, but we've already stored a different one for TMSS remap\n", info.map[i].start); |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2323 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2324 } else { |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2325 warning("Didn't remap chunk starting at %X for TMSS because it has flags %X\n", info.map[i].start, info.map[i].flags); |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2326 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2327 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2328 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
2329 gen->tmss_buffer = buffer; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2330 } |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2331 memmap_chunk* map = info.map; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2332 uint32_t map_chunks = info.map_chunks; |
2088
c716af3f8980
Enable Sega CD emulation for carts if a CD image is "locked-on" even if the cart does not specify that it uses the CD peripheral in the header
Michael Pavone <pavone@retrodev.com>
parents:
2083
diff
changeset
|
2333 if (info.wants_cd || (current_media()->chain && current_media()->chain->type == MEDIA_CDROM)) { |
2277
9e578fd493e1
Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2272
diff
changeset
|
2334 gen->header.type = SYSTEM_SEGACD; |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2335 segacd_context *cd = alloc_configure_segacd((system_media *)current_media(), 0, force_region, &info); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2336 gen->expansion = cd; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2337 gen->version_reg &= ~NO_DISK; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2338 cd->genesis = gen; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2339 uint32_t cd_chunks; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2340 memmap_chunk *cd_map = segacd_main_cpu_map(gen->expansion, 1, &cd_chunks); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2341 map_chunks = cd_chunks + info.map_chunks; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2342 map = calloc(map_chunks, sizeof(memmap_chunk)); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2343 memcpy(map, info.map, sizeof(memmap_chunk) * (info.map_chunks - 1)); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2344 memcpy(map + info.map_chunks - 1, cd_map, sizeof(memmap_chunk) * cd_chunks); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2345 memcpy(map + map_chunks - 1, info.map + info.map_chunks - 1, sizeof(memmap_chunk)); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2346 free(info.map); |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2347 int max_ptr_index = -1; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2348 for (int i = 0; i < info.map_chunks - 1; i++) |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2349 { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2350 if (map[i].flags & MMAP_PTR_IDX && map[i].ptr_index > max_ptr_index) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2351 max_ptr_index = map[i].ptr_index; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2352 } |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2353 } |
2090
00b6592cad42
Fix typo that messed up Mode 1 for carts with mappers
Michael Pavone <pavone@retrodev.com>
parents:
2088
diff
changeset
|
2354 cd->memptr_start_index = max_ptr_index + 1; |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2355 for (int i = info.map_chunks - 1; i < map_chunks - 1; i++) |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2356 { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2357 if (map[i].flags & MMAP_PTR_IDX) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2358 map[i].ptr_index += cd->memptr_start_index; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2359 } |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2360 } |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2361 cd->base = 0x400000; |
2272
777900eb8e15
Add address logging support to sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
2271
diff
changeset
|
2362 cd->m68k->options->address_log = (ym_opts & OPT_ADDRESS_LOG) ? fopen("address_sub.log", "w") : NULL; |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2363 } |
2248
f7e2e11f1214
Fix improper free of memory map array from rom_info
Michael Pavone <pavone@retrodev.com>
parents:
2243
diff
changeset
|
2364 info.map = gen->header.info.map = NULL; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2365 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2366 m68k_options *opts = malloc(sizeof(m68k_options)); |
2350
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
2367 init_m68k_opts(opts, map, map_chunks, MCLKS_PER_68K, sync_components, int_ack); |
1901
5433252329fb
Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents:
1889
diff
changeset
|
2368 if (!strcmp(tern_find_ptr_default(model, "tas", "broken"), "broken")) { |
5433252329fb
Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents:
1889
diff
changeset
|
2369 opts->gen.flags |= M68K_OPT_BROKEN_READ_MODIFY; |
5433252329fb
Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents:
1889
diff
changeset
|
2370 } |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2371 gen->m68k = init_68k_context(opts, NULL); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2372 gen->m68k->system = gen; |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2373 opts->address_log = (ym_opts & OPT_ADDRESS_LOG) ? fopen("address.log", "w") : NULL; |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
2374 |
1165
9fc680b35dbb
Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
2375 //This must happen after the 68K context has been allocated |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2376 for (int i = 0; i < map_chunks; i++) |
1165
9fc680b35dbb
Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
2377 { |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2378 if (map[i].flags & MMAP_PTR_IDX) { |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2379 gen->m68k->mem_pointers[map[i].ptr_index] = map[i].buffer; |
1165
9fc680b35dbb
Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
2380 } |
9fc680b35dbb
Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
2381 } |
2052
3748a2a8a4b7
Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents:
2039
diff
changeset
|
2382 |
1452
f284ad74afe1
Make initial bank register state stored in bank_regs match what is put in to mem_pointers for the sega/SSF2 mapper. Invalidate RAM code ranges on RAM deserialization
Michael Pavone <pavone@retrodev.com>
parents:
1449
diff
changeset
|
2383 if (gen->mapper_type == MAPPER_SEGA) { |
f284ad74afe1
Make initial bank register state stored in bank_regs match what is put in to mem_pointers for the sega/SSF2 mapper. Invalidate RAM code ranges on RAM deserialization
Michael Pavone <pavone@retrodev.com>
parents:
1449
diff
changeset
|
2384 //initialize bank registers |
f284ad74afe1
Make initial bank register state stored in bank_regs match what is put in to mem_pointers for the sega/SSF2 mapper. Invalidate RAM code ranges on RAM deserialization
Michael Pavone <pavone@retrodev.com>
parents:
1449
diff
changeset
|
2385 for (int i = 1; i < sizeof(gen->bank_regs); i++) |
f284ad74afe1
Make initial bank register state stored in bank_regs match what is put in to mem_pointers for the sega/SSF2 mapper. Invalidate RAM code ranges on RAM deserialization
Michael Pavone <pavone@retrodev.com>
parents:
1449
diff
changeset
|
2386 { |
f284ad74afe1
Make initial bank register state stored in bank_regs match what is put in to mem_pointers for the sega/SSF2 mapper. Invalidate RAM code ranges on RAM deserialization
Michael Pavone <pavone@retrodev.com>
parents:
1449
diff
changeset
|
2387 gen->bank_regs[i] = i; |
f284ad74afe1
Make initial bank register state stored in bank_regs match what is put in to mem_pointers for the sega/SSF2 mapper. Invalidate RAM code ranges on RAM deserialization
Michael Pavone <pavone@retrodev.com>
parents:
1449
diff
changeset
|
2388 } |
f284ad74afe1
Make initial bank register state stored in bank_regs match what is put in to mem_pointers for the sega/SSF2 mapper. Invalidate RAM code ranges on RAM deserialization
Michael Pavone <pavone@retrodev.com>
parents:
1449
diff
changeset
|
2389 } |
1954
2fd0a8cb1c80
Properly initialize Genesis reset cycle on startup. Fixes crash in GDB remote debugger when stepping past the first two instructions
Michael Pavone <pavone@retrodev.com>
parents:
1946
diff
changeset
|
2390 gen->reset_cycle = CYCLE_NEVER; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2391 |
2277
9e578fd493e1
Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2272
diff
changeset
|
2392 set_audio_config(gen); |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2393 return gen; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2394 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2395 |
1692 | 2396 genesis_context *alloc_config_genesis_cdboot(system_media *media, uint32_t system_opts, uint8_t force_region) |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2397 { |
1692 | 2398 tern_node *rom_db = get_rom_db(); |
2399 rom_info info = configure_rom(rom_db, media->buffer, media->size, NULL, 0, base_map, base_chunks); | |
2267
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2400 if (media->size > 0x20B) { |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2401 //Use a byte in the security code region that's unique across all 3 regions |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2402 //since it's more reliable than the official header field for this |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2403 uint8_t *bytes = media->buffer; |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2404 switch (bytes[0x20B]) |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2405 { |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2406 case 0x7A: |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2407 info.regions = REGION_U; |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2408 break; |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2409 case 0xA1: |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2410 info.regions = REGION_J; |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2411 break; |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2412 case 0x64: |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2413 info.regions = REGION_E; |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2414 break; |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2415 } |
94cca8b8429e
Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents:
2255
diff
changeset
|
2416 } |
2053 | 2417 |
1692 | 2418 segacd_context *cd = alloc_configure_segacd(media, system_opts, force_region, &info); |
2419 genesis_context *gen = shared_init(system_opts, &info, force_region); | |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2420 gen->cart = gen->lock_on = NULL; |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2421 gen->save_storage = NULL; |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2422 gen->save_type = SAVE_NONE; |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2423 gen->version_reg &= ~NO_DISK; |
2053 | 2424 |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2425 gen->expansion = cd; |
2272
777900eb8e15
Add address logging support to sub CPU
Michael Pavone <pavone@retrodev.com>
parents:
2271
diff
changeset
|
2426 cd->m68k->options->address_log = (system_opts & OPT_ADDRESS_LOG) ? fopen("address_sub.log", "w") : NULL; |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2427 gen->version_reg &= ~NO_DISK; |
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2428 cd->genesis = gen; |
1692 | 2429 setup_io_devices(config, &info, &gen->io); |
2053 | 2430 |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2431 uint32_t cd_chunks; |
2054
8ee7ecbf3f21
Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents:
2053
diff
changeset
|
2432 memmap_chunk *cd_map = segacd_main_cpu_map(gen->expansion, 0, &cd_chunks); |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2433 memmap_chunk *map = malloc(sizeof(memmap_chunk) * (cd_chunks + base_chunks)); |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2434 memcpy(map, cd_map, sizeof(memmap_chunk) * cd_chunks); |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2435 memcpy(map + cd_chunks, base_map, sizeof(memmap_chunk) * base_chunks); |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2436 map[cd_chunks].buffer = gen->work_ram; |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2437 uint32_t num_chunks = cd_chunks + base_chunks; |
2053 | 2438 |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2439 m68k_options *opts = malloc(sizeof(m68k_options)); |
2350
f8b5142c06aa
Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents:
2336
diff
changeset
|
2440 init_m68k_opts(opts, map, num_chunks, MCLKS_PER_68K, sync_components, int_ack); |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2441 //TODO: make this configurable |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2442 opts->gen.flags |= M68K_OPT_BROKEN_READ_MODIFY; |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2443 gen->m68k = init_68k_context(opts, NULL); |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2444 gen->m68k->system = gen; |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2445 opts->address_log = (system_opts & OPT_ADDRESS_LOG) ? fopen("address.log", "w") : NULL; |
2053 | 2446 |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2447 //This must happen after the 68K context has been allocated |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2448 for (int i = 0; i < num_chunks; i++) |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2449 { |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2450 if (map[i].flags & MMAP_PTR_IDX) { |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2451 gen->m68k->mem_pointers[map[i].ptr_index] = map[i].buffer; |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2452 } |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2453 } |
2083
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
2080
diff
changeset
|
2454 gen->header.type = SYSTEM_SEGACD; |
2277
9e578fd493e1
Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2272
diff
changeset
|
2455 |
9e578fd493e1
Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents:
2272
diff
changeset
|
2456 set_audio_config(gen); |
1503
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2457 return gen; |
a763523dadf4
Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents:
1452
diff
changeset
|
2458 } |