Mercurial > repos > blastem
annotate genesis.c @ 2034:8b2ef428d1aa
Implement TMSS ROM and cart mapping register
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 21 Feb 2021 14:35:16 -0800 |
parents | 894bf99a13f1 |
children | b0b0c31338c3 |
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" |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #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
|
8 #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
|
9 #include <stdlib.h> |
1188
448ce87b87fc
Fix missing include that prevented building Windows version
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
10 #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
|
11 #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
|
12 #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
|
13 #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
|
14 #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
|
15 #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
|
16 #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
|
17 #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
|
18 #include "saves.h" |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
19 #include "bindings.h" |
1610 | 20 #include "jcart.h" |
1901
5433252329fb
Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents:
1889
diff
changeset
|
21 #include "config.h" |
1946 | 22 #include "event_log.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
|
23 #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
|
24 #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
|
25 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
27 #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
|
28 #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
|
29 #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
|
30 #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
|
31 #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
|
32 #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
|
33 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 //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
|
35 #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
|
36 #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
|
37 |
1688
395f684c5379
Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
38 #ifdef IS_LIB |
1927
9fd4bedc1a31
Update libretro target to use render_audio shared audio code
Mike Pavone <pavone@retrodev.com>
parents:
1915
diff
changeset
|
39 #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
|
40 #else |
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
|
41 #define MAX_SOUND_CYCLES 100000 |
1688
395f684c5379
Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
42 #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
|
43 |
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
|
44 #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
|
45 #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
|
46 #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
|
47 #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
|
48 #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
|
49 #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
|
50 #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
|
51 #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
|
52 |
1946 | 53 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
|
54 { |
1946 | 55 if (all) { |
56 start_section(buf, SECTION_68000); | |
57 m68k_serialize(gen->m68k, m68k_pc, buf); | |
58 end_section(buf); | |
59 | |
60 start_section(buf, SECTION_Z80); | |
61 z80_serialize(gen->z80, buf); | |
62 end_section(buf); | |
63 } | |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
64 |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
65 start_section(buf, SECTION_VDP); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
66 vdp_serialize(gen->vdp, buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
67 end_section(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
68 |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
69 start_section(buf, SECTION_YM2612); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
70 ym_serialize(gen->ym, buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
71 end_section(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
72 |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
73 start_section(buf, SECTION_PSG); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
74 psg_serialize(gen->psg, buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
75 end_section(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
76 |
1946 | 77 if (all) { |
78 start_section(buf, SECTION_GEN_BUS_ARBITER); | |
79 save_int8(buf, gen->z80->reset); | |
80 save_int8(buf, gen->z80->busreq); | |
81 save_int16(buf, gen->z80_bank_reg); | |
82 end_section(buf); | |
83 | |
84 start_section(buf, SECTION_SEGA_IO_1); | |
85 io_serialize(gen->io.ports, buf); | |
86 end_section(buf); | |
87 | |
88 start_section(buf, SECTION_SEGA_IO_2); | |
89 io_serialize(gen->io.ports + 1, buf); | |
90 end_section(buf); | |
91 | |
92 start_section(buf, SECTION_SEGA_IO_EXT); | |
93 io_serialize(gen->io.ports + 2, buf); | |
94 end_section(buf); | |
95 | |
96 start_section(buf, SECTION_MAIN_RAM); | |
97 save_int8(buf, RAM_WORDS * 2 / 1024); | |
98 save_buffer16(buf, gen->work_ram, RAM_WORDS); | |
99 end_section(buf); | |
100 | |
101 start_section(buf, SECTION_SOUND_RAM); | |
102 save_int8(buf, Z80_RAM_BYTES / 1024); | |
103 save_buffer8(buf, gen->zram, Z80_RAM_BYTES); | |
104 end_section(buf); | |
105 | |
106 cart_serialize(&gen->header, buf); | |
107 } | |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
108 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
109 |
1690
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
110 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
|
111 { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
112 genesis_context *gen = (genesis_context *)sys; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
113 uint32_t address; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
114 if (gen->m68k->resume_pc) { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
115 gen->m68k->target_cycle = gen->m68k->current_cycle; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
116 gen->header.save_state = SERIALIZE_SLOT+1; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
117 resume_68k(gen->m68k); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
118 if (size_out) { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
119 *size_out = gen->serialize_size; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
120 } |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
121 return gen->serialize_tmp; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
122 } else { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
123 serialize_buffer state; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
124 init_serialize(&state); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
125 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
|
126 address |= read_word(6, (void **)gen->m68k->mem_pointers, &gen->m68k->options->gen, gen->m68k); |
1946 | 127 genesis_serialize(gen, &state, address, 1); |
1690
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
128 if (size_out) { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
129 *size_out = state.size; |
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 return state.data; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
132 } |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
133 } |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
134 |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
135 static void ram_deserialize(deserialize_buffer *buf, void *vgen) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
136 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
137 genesis_context *gen = vgen; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
138 uint32_t ram_size = load_int8(buf) * 1024 / 2; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
139 if (ram_size > RAM_WORDS) { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
140 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
|
141 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
142 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
|
143 m68k_invalidate_code_range(gen->m68k, 0xE00000, 0x1000000); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
144 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
145 |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
146 static void zram_deserialize(deserialize_buffer *buf, void *vgen) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
147 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
148 genesis_context *gen = vgen; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
149 uint32_t ram_size = load_int8(buf) * 1024; |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
150 if (ram_size > Z80_RAM_BYTES) { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
151 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
|
152 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
153 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
|
154 z80_invalidate_code_range(gen->z80, 0, 0x4000); |
1427
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 |
1445
349d50930c03
Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1444
diff
changeset
|
157 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
|
158 { |
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
|
159 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
|
160 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
|
161 } else { |
349d50930c03
Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1444
diff
changeset
|
162 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
|
163 } |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
164 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
|
165 } |
349d50930c03
Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1444
diff
changeset
|
166 |
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
|
167 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
|
168 { |
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
|
169 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
|
170 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
|
171 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
|
172 gen->z80_bank_reg = load_int16(buf) & 0x1FF; |
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
|
173 } |
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
|
174 |
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
|
175 static void adjust_int_cycle(m68k_context * context, vdp_context * v_context); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
176 void genesis_deserialize(deserialize_buffer *buf, genesis_context *gen) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
177 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 register_section_handler(buf, (section_handler){.fun = cart_deserialize, .data = gen}, SECTION_MAPPER); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
190 while (buf->cur_pos < buf->size) |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
191 { |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
192 load_section(buf); |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
193 } |
1445
349d50930c03
Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1444
diff
changeset
|
194 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
|
195 adjust_int_cycle(gen->m68k, gen->vdp); |
1690
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
196 free(buf->handlers); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
197 buf->handlers = NULL; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
198 } |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
199 |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
200 #include "m68k_internal.h" //needed for get_native_address_trans, should be eliminated once handling of PC is cleaned up |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
201 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
|
202 { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
203 genesis_context *gen = (genesis_context *)sys; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
204 deserialize_buffer buffer; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
205 init_deserialize(&buffer, data, size); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
206 genesis_deserialize(&buffer, gen); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
207 //HACK: Fix this once PC/IR is represented in a better way in 68K core |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
208 gen->m68k->resume_pc = get_native_address_trans(gen->m68k, gen->m68k->last_prefetch_address); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
209 } |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
210 |
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
|
211 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
|
212 { |
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
|
213 genesis_context *genesis = (genesis_context *)current_system; |
1420
975b5b7eaa77
Fix DMA from byte-wide SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1416
diff
changeset
|
214 //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
|
215 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
|
216 return 0; |
975b5b7eaa77
Fix DMA from byte-wide SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1416
diff
changeset
|
217 } |
975b5b7eaa77
Fix DMA from byte-wide SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1416
diff
changeset
|
218 |
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
|
219 //addresses here are word addresses (i.e. bit 0 corresponds to A1), so no need to do multiply by 2 |
1420
975b5b7eaa77
Fix DMA from byte-wide SRAM
Michael Pavone <pavone@retrodev.com>
parents:
1416
diff
changeset
|
220 return read_word(address * 2, (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
|
221 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 |
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
|
223 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
|
224 { |
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
|
225 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
|
226 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
|
227 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
229 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
|
230 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 //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
|
232 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
|
233 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
|
234 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
|
235 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 } |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 } |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
254 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
|
255 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
|
256 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
|
257 uint32_t next_eint_port2 = io_next_interrupt(gen->io.ports + 2, context->current_cycle); |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
258 uint32_t next_eint = next_eint_port0 < next_eint_port1 |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
259 ? (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
|
260 : (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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
267 } |
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
268 } |
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
|
269 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 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
|
272 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
|
273 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 /*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
|
275 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
|
276 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
|
277 }*/ |
1303
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1291
diff
changeset
|
278 |
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
|
279 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
|
280 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
|
281 return; |
208803173ebc
Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents:
1291
diff
changeset
|
282 } |
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
|
283 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 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
|
285 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
|
286 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
|
287 } 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
|
288 //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
|
289 //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
|
290 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
|
291 } |
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
|
292 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
|
293 //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
|
294 //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
|
295 //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
|
296 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
|
297 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
|
298 } 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
|
299 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
|
300 } 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
|
301 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
|
302 } |
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
|
303 |
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
|
304 } |
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
|
305 /*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
|
306 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
|
307 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
|
308 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
309 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
310 //#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
|
311 #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
|
312 #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
|
313 #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
|
314 #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
|
315 #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
|
316 #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
|
317 #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
|
318 |
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
|
319 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
|
320 { |
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
|
321 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
|
322 #ifdef NEW_CORE |
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
323 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
|
324 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
|
325 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
|
326 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
|
327 #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
|
328 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
|
329 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
|
330 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
|
331 #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
|
332 } |
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 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
334 static void sync_z80(z80_context * z_context, 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
|
335 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 #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
|
337 if (z80_enabled) { |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
338 #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
|
339 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
|
340 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
|
341 } |
1753
33ec5df77fac
Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
342 #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
|
343 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
|
344 } 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
|
345 #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
|
346 { |
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
|
347 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
|
348 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
349 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
350 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
351 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
|
352 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
353 //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
|
354 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
|
355 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
|
356 //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
|
357 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
|
358 //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
|
359 ym_run(gen->ym, 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
|
360 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
362 ym_run(gen->ym, 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
|
363 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 //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
|
365 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
366 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
367 //My refresh emulation isn't currently good enough and causes more problems than it solves |
1286
ca0383656a82
Basic refresh emulation that doesn't break direct color DMA demos. Fixes sound after entering pause menu in Pacman 2: The New Adventures
Michael Pavone <pavone@retrodev.com>
parents:
1285
diff
changeset
|
368 #define REFRESH_EMULATION |
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
|
369 #ifdef REFRESH_EMULATION |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
370 #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
|
371 #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
|
372 uint32_t last_sync_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
|
373 uint32_t refresh_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
|
374 #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
|
375 |
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
|
376 #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
|
377 #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
|
378 #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
|
379 |
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
|
380 m68k_context * sync_components(m68k_context * context, 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
|
381 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
382 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
|
383 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
|
384 z80_context * z_context = 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
|
385 #ifdef REFRESH_EMULATION |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
386 //lame estimation of refresh cycle delay |
1372
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
387 refresh_counter += context->current_cycle - last_sync_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
|
388 if (!gen->bus_busy) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
389 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL)); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
390 } |
1372
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
391 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); |
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
|
392 #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
|
393 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 uint32_t mclks = 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
|
395 sync_z80(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
|
396 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
|
397 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
|
398 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
|
399 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
|
400 io_run(gen->io.ports + 2, mclks); |
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
|
401 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
|
402 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
|
403 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
|
404 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
|
405 } |
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
|
406 if (v_context->frame != gen->last_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
|
407 //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); |
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
|
408 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
|
409 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
|
410 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
|
411 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
412 if(exit_after){ |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
413 --exit_after; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
414 if (!exit_after) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
415 exit(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
|
416 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
417 } |
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
|
418 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
|
419 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
|
420 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
|
421 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
|
422 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
|
423 io_adjust_cycles(gen->io.ports+2, context->current_cycle, deduction); |
1610 | 424 if (gen->mapper_type == MAPPER_JCART) { |
425 jcart_adjust_cycles(gen, deduction); | |
426 } | |
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
|
427 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
|
428 z80_adjust_cycles(z_context, deduction); |
1902
32a3aa7b4a45
Fix YM2612 busy flag timing
Michael Pavone <pavone@retrodev.com>
parents:
1901
diff
changeset
|
429 ym_adjust_cycles(gen->ym, deduction); |
1909
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
430 if (gen->ym->vgm) { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
431 vgm_adjust_cycles(gen->ym->vgm, deduction); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
432 } |
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
|
433 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
|
434 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
|
435 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
|
436 } |
1946 | 437 event_cycle_adjust(mclks, deduction); |
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
|
438 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
|
439 } |
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
|
440 } 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
|
441 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
|
442 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
|
443 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
445 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
|
446 //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
|
447 if (context->int_ack) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 //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); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
449 vdp_int_ack(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
|
450 context->int_ack = 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
|
451 } |
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
|
452 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
|
453 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
|
454 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
456 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
|
457 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
|
458 } |
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
|
459 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
|
460 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
|
461 gen->header.enter_debugger = 0; |
2033
894bf99a13f1
Make ui.enter_debuger respect which debuger is active
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
462 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
|
463 debugger(context, address); |
894bf99a13f1
Make ui.enter_debuger respect which debuger is active
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
464 } else { |
894bf99a13f1
Make ui.enter_debuger respect which debuger is active
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
465 gdb_debug_enter(context, address); |
894bf99a13f1
Make ui.enter_debuger respect which debuger is active
Michael Pavone <pavone@retrodev.com>
parents:
2025
diff
changeset
|
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 } |
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
|
468 #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
|
469 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
|
470 #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
|
471 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
|
472 #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
|
473 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
|
474 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
|
475 #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
|
476 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
|
477 //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
|
478 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
|
479 { |
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
|
480 sync_z80(z_context, z_context->current_cycle + MCLKS_PER_Z80); |
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
|
481 } |
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
|
482 } |
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
|
483 #endif |
1946 | 484 char *save_path = slot >= SERIALIZE_SLOT ? NULL : get_slot_name(&gen->header, slot, use_native_states ? "state" : "gst"); |
485 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
|
486 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
|
487 init_serialize(&state); |
1946 | 488 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
|
489 if (slot == SERIALIZE_SLOT) { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
490 gen->serialize_tmp = state.data; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
491 gen->serialize_size = state.size; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
492 context->sync_cycle = context->current_cycle; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
493 context->should_return = 1; |
1946 | 494 } else if (slot == EVENTLOG_SLOT) { |
495 event_state(context->current_cycle, &state); | |
1690
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
496 } else { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
497 save_to_file(&state, save_path); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
498 free(state.data); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
499 } |
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
|
500 } 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
|
501 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
|
502 } |
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
|
503 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
|
504 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
|
505 } |
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
|
506 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
|
507 } 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
|
508 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
|
509 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
510 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
511 #ifdef REFRESH_EMULATION |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
512 last_sync_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
|
513 #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
|
514 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
|
515 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
516 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
517 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
|
518 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
519 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
|
520 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
|
521 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
523 //printf("vdp_port write: %X, value: %X, cycle: %d\n", vdp_port, value, context->current_cycle); |
1372
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
524 #ifdef REFRESH_EMULATION |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
525 //do refresh check here so we can avoid adding a penalty for a refresh that happens during a VDP access |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
526 refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle; |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
527 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL)); |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
528 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
529 last_sync_cycle = context->current_cycle; |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
530 #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
|
531 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
|
532 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
|
533 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
|
534 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
|
535 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
|
536 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
|
537 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
|
538 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
|
539 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
|
540 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
|
541 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
|
542 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
|
543 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
|
544 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
|
545 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
|
546 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
547 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
|
548 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
|
549 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
|
550 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
|
551 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
552 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
553 //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
|
554 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
555 } 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
|
556 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
|
557 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
|
558 blocked = vdp_control_port_write(v_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
|
559 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
|
560 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
|
561 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
|
562 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
|
563 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
|
564 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
|
565 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
|
566 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
|
567 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
|
568 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
570 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
|
571 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
|
572 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
|
573 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
574 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
575 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
576 if (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
|
577 blocked = vdp_control_port_write(v_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
|
578 } 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
|
579 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
|
580 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
581 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
582 } 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
|
583 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
|
584 //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
|
585 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
|
586 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
587 } 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
|
588 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
|
589 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
590 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
|
591 //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
|
592 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
|
593 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
|
594 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
|
595 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
|
596 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
597 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
|
598 //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
|
599 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
|
600 sync_z80(gen->z80, 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
|
601 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
|
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 } 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
|
604 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
|
605 } 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
|
606 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
|
607 } |
1372
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
608 #ifdef REFRESH_EMULATION |
2012
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
609 last_sync_cycle -= 4 * MCLKS_PER_68K; |
1372
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
610 //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
|
611 //so advance refresh_counter but don't add any delays |
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
|
612 if (vdp_port >= 4 && vdp_port < 8 && v_context->cycles != before_cycle) { |
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
|
613 refresh_counter = 0; |
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
|
614 } else { |
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
|
615 refresh_counter += (context->current_cycle - last_sync_cycle); |
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
|
616 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); |
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
|
617 } |
1372
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
618 last_sync_cycle = context->current_cycle; |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
619 #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
|
620 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
|
621 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
622 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
623 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
|
624 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
625 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
|
626 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
627 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
628 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
|
629 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
630 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
|
631 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
|
632 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
|
633 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
|
634 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
|
635 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
636 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
|
637 //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
|
638 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
|
639 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
|
640 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
|
641 } 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
|
642 vdp_run_context_full(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
|
643 vdp_control_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
|
644 } 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
|
645 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
|
646 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
647 } 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
|
648 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
|
649 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
|
650 } 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
|
651 vdp_test_port_write(gen->vdp, 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
|
652 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
653 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
|
654 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
655 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
656 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
|
657 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
658 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
|
659 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
|
660 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
661 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
|
662 uint16_t value; |
1372
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
663 #ifdef REFRESH_EMULATION |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
664 //do refresh check here so we can avoid adding a penalty for a refresh that happens during a VDP access |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
665 refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle; |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
666 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL)); |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
667 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
668 last_sync_cycle = context->current_cycle; |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
669 #endif |
2021
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
670 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
|
671 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
|
672 vdp_context * v_context = gen->vdp; |
2021
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
673 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
|
674 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
|
675 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
|
676 value = vdp_data_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
|
677 } 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
|
678 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
|
679 } 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
|
680 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
|
681 //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
|
682 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
683 } 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
|
684 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
|
685 } else { |
1869
dc94354eab66
Fix accuracy bugs used by Novedicus to detect BlastEm/Exodus
Michael Pavone <pavone@retrodev.com>
parents:
1849
diff
changeset
|
686 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
|
687 } |
2021
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
688 if (v_context->cycles != before_cycle) { |
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
689 //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
|
690 context->current_cycle = v_context->cycles; |
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
691 //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
|
692 genesis_context *gen = context->system; |
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
693 gen->bus_busy = 1; |
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
694 sync_z80(gen->z80, v_context->cycles); |
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
695 gen->bus_busy = 0; |
270a4c875e0a
Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents:
2012
diff
changeset
|
696 } |
1372
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
697 #ifdef REFRESH_EMULATION |
2012
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
698 last_sync_cycle -= 4 * MCLKS_PER_68K; |
1372
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
699 //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
|
700 //so advance refresh_counter but don't add any delays |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
701 refresh_counter += (context->current_cycle - last_sync_cycle); |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
702 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
703 last_sync_cycle = context->current_cycle; |
d78ef6f4fba2
Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
704 #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
|
705 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
|
706 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
707 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
708 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
|
709 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
711 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
|
712 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
|
713 } 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
|
714 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
|
715 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
718 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
|
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 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
|
721 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
|
722 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
|
723 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
725 //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
|
726 //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
|
727 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
|
728 //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
|
729 //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
|
730 // 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
|
731 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
|
732 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
735 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
|
736 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
|
737 //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
|
738 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
|
739 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
|
740 ret = vdp_data_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
|
741 } 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
|
742 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
|
743 } 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
|
744 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
|
745 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } 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
|
747 //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
|
748 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
|
749 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
750 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
|
751 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
753 //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
|
754 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
|
755 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
756 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
|
757 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 genesis_context * gen = context->system; |
2012
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
759 #ifdef REFRESH_EMULATION |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
760 //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
761 refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle; |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
762 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL)); |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
763 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
764 last_sync_cycle = context->current_cycle - 4*MCLKS_PER_68K; |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
765 #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
|
766 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
|
767 //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
|
768 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
|
769 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
|
770 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
|
771 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
|
772 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
|
773 #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
|
774 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
|
775 #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
|
776 } 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
|
777 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
|
778 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
|
779 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
|
780 } 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
|
781 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
|
782 } 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
|
783 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
|
784 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } 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
|
786 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
|
787 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
|
788 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
|
789 } 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
|
790 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
|
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 } 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
|
793 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
|
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 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } 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
|
797 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
|
798 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
|
799 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
801 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
|
802 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
|
803 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
|
804 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
|
805 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
|
806 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
|
807 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
|
808 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
|
809 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
|
810 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
|
811 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
|
812 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
|
813 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
|
814 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
|
815 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
|
816 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
|
817 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
|
818 case 0x7: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
819 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
|
820 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
|
821 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
|
822 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
|
823 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
|
824 //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
|
825 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
|
826 case 0x9: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
827 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
|
828 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
|
829 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
|
830 case 0xA: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
831 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
|
832 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
|
833 case 0xC: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
834 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
|
835 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
|
836 case 0xD: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
837 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
|
838 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
|
839 case 0xF: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
840 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
|
841 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
|
842 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } 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
|
844 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
|
845 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
|
846 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
|
847 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
|
848 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
|
849 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
|
850 } 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
|
851 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
|
852 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
853 } 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
|
854 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
|
855 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
|
856 #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
|
857 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
|
858 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
|
859 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
|
860 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
|
861 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
|
862 #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
|
863 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
864 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
|
865 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
|
866 } 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
|
867 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
|
868 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } |
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
|
870 } 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
|
871 sync_z80(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
|
872 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
|
873 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
|
874 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
|
875 } 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
|
876 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
|
877 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
878 } 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
|
879 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
|
880 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
|
881 } 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
|
882 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
|
883 } |
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
|
884 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
|
885 } |
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
|
886 } 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
|
887 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
|
888 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } |
2012
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
891 #ifdef REFRESH_EMULATION |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
892 //no refresh delays during IO access |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
893 refresh_counter += context->current_cycle - last_sync_cycle; |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
894 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
895 #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
|
896 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
|
897 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
898 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
899 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
|
900 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
901 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
|
902 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
|
903 } 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
|
904 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
|
905 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
907 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
908 #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
|
909 #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
|
910 #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
|
911 #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
|
912 #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
|
913 #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
|
914 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
915 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
|
916 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
917 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
|
918 genesis_context *gen = context->system; |
2012
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
919 #ifdef REFRESH_EMULATION |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
920 //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
921 refresh_counter += context->current_cycle - 4*MCLKS_PER_68K - last_sync_cycle; |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
922 context->current_cycle += REFRESH_DELAY * MCLKS_PER_68K * (refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL)); |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
923 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
924 last_sync_cycle = context->current_cycle - 4*MCLKS_PER_68K; |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
925 #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
|
926 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
|
927 //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
|
928 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
|
929 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
|
930 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
|
931 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
|
932 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
|
933 } 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
|
934 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
|
935 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
|
936 } 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
|
937 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
|
938 } 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
|
939 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
|
940 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
|
941 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } 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
|
943 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
|
944 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
|
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 { |
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
|
947 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
|
948 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
|
949 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
951 //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
|
952 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
|
953 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
|
954 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
|
955 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
|
956 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
|
957 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
|
958 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
|
959 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
|
960 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
|
961 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
|
962 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
|
963 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
|
964 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
|
965 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
|
966 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
|
967 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
|
968 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
|
969 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
|
970 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
|
971 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
|
972 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
|
973 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
|
974 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
|
975 case 0x8: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
976 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
|
977 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
|
978 case 0x9: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
979 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
|
980 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
|
981 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
|
982 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
|
983 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
|
984 case 0xB: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
985 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
|
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 0xC: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
988 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
|
989 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
|
990 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
|
991 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
|
992 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
|
993 case 0xE: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
994 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
|
995 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
|
996 case 0xF: |
2025
e7a516f08cec
Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents:
2021
diff
changeset
|
997 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
|
998 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
|
999 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
|
1000 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
|
1001 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1002 } 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
|
1003 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
|
1004 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
|
1005 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
|
1006 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
|
1007 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
|
1008 } 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
|
1009 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
|
1010 } 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
|
1011 //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
|
1012 //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
|
1013 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
|
1014 } 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
|
1015 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
|
1016 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
|
1017 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
|
1018 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } |
2012
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
1021 #ifdef REFRESH_EMULATION |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
1022 //no refresh delays during IO access |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
1023 refresh_counter += context->current_cycle - last_sync_cycle; |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
1024 refresh_counter = refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL); |
b05295c2ad04
Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents:
1998
diff
changeset
|
1025 #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
|
1026 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
|
1027 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1029 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
|
1030 { |
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
|
1031 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
|
1032 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
|
1033 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
|
1034 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
|
1035 } 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
|
1036 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
|
1037 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
|
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 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
|
1040 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1042 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
|
1043 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
1045 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
|
1046 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
|
1047 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
|
1048 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
|
1049 } 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
|
1050 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
|
1051 } 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
|
1052 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
|
1053 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1054 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
|
1055 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1057 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
|
1058 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
1060 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
|
1061 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
|
1062 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
|
1063 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1065 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
|
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 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
|
1068 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
|
1069 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
|
1070 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
|
1071 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 //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
|
1073 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
|
1074 //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
|
1075 //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
|
1076 // 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
|
1077 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
|
1078 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1079 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
|
1080 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
|
1081 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
|
1082 } |
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
|
1083 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
|
1084 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
|
1085 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
|
1086 } 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
|
1087 //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
|
1088 //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
|
1089 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
|
1090 } 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
|
1091 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
|
1092 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1093 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
|
1094 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1095 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1096 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
|
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 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
|
1099 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
|
1100 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
|
1101 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
|
1102 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1103 //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
|
1104 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
|
1105 //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
|
1106 //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
|
1107 // 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
|
1108 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
|
1109 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
1111 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
|
1112 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
|
1113 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
|
1114 ((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
|
1115 } 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
|
1116 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
|
1117 } 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
|
1118 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
|
1119 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1120 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
|
1121 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1123 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
|
1124 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
1126 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
|
1127 |
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
|
1128 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
|
1129 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
|
1130 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1131 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
|
1132 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1133 |
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
|
1134 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
|
1135 { |
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
|
1136 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
|
1137 genesis_context *gen = context->system; |
1987
71732f2f6f42
Fix handling of unmapped reads/writes to the cart/expansion port region
Mike Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
1138 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
|
1139 //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
|
1140 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
|
1141 } 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
|
1142 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
|
1143 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
|
1144 } 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
|
1145 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
|
1146 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
|
1147 } |
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
|
1148 } 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
|
1149 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
|
1150 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
|
1151 } 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
|
1152 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
|
1153 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
|
1154 } |
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
|
1155 } 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
|
1156 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
|
1157 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
|
1158 } |
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 } |
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 |
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
|
1161 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
|
1162 { |
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
|
1163 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
|
1164 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
|
1165 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
|
1166 } 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
|
1167 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
|
1168 } |
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 } |
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
|
1170 |
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 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
|
1172 { |
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
|
1173 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
|
1174 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
|
1175 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
|
1176 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
|
1177 gen->tmss_lock[location >> 1 & 1] = 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
|
1178 } else if (has_tmss && location == 0xA14100) { |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1179 value &= 1; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1180 if (gen->tmss != value) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1181 gen->tmss = value; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1182 for (int i = 0; i < NUM_MEM_AREAS; i++) |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1183 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1184 uint16_t *tmp = context->mem_pointers[i]; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1185 context->mem_pointers[i] = gen->tmss_pointers[i]; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1186 gen->tmss_pointers[i] = tmp; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1187 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1188 m68k_invalidate_code_range(context, 0, 0x400000); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1189 } |
1987
71732f2f6f42
Fix handling of unmapped reads/writes to the cart/expansion port region
Mike Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
1190 } 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
|
1191 //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
|
1192 } 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
|
1193 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
|
1194 } |
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
|
1195 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
|
1196 } |
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
|
1197 |
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
|
1198 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
|
1199 { |
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
|
1200 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
|
1201 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
|
1202 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
|
1203 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
|
1204 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
|
1205 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
|
1206 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
|
1207 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
|
1208 } 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
|
1209 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
|
1210 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
|
1211 } |
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
|
1212 } 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
|
1213 if (location & 1) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1214 value &= 1; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1215 if (gen->tmss != value) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1216 gen->tmss = value; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1217 for (int i = 0; i < NUM_MEM_AREAS; i++) |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1218 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1219 uint16_t *tmp = context->mem_pointers[i]; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1220 context->mem_pointers[i] = gen->tmss_pointers[i]; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1221 gen->tmss_pointers[i] = tmp; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1222 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1223 m68k_invalidate_code_range(context, 0, 0x400000); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1224 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1225 } |
1987
71732f2f6f42
Fix handling of unmapped reads/writes to the cart/expansion port region
Mike Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
1226 } 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
|
1227 //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
|
1228 } 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
|
1229 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
|
1230 } |
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
|
1231 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
|
1232 } |
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
|
1233 |
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
|
1234 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
|
1235 { |
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
|
1236 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
|
1237 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
|
1238 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
|
1239 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
|
1240 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
|
1241 } |
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
|
1242 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
|
1243 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
|
1244 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1245 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
1247 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
1249 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
|
1250 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
|
1251 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
|
1252 } 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
|
1253 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
|
1254 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1255 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
1257 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
|
1258 } 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
|
1259 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
|
1260 } 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
|
1261 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
|
1262 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
1265 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
|
1266 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
|
1267 } 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
|
1268 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
|
1269 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
|
1270 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
|
1272 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1274 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
|
1275 { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1276 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
|
1277 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
|
1278 deserialize_buffer state; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1279 uint32_t pc = 0; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1280 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
|
1281 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
|
1282 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
|
1283 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
|
1284 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
|
1285 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
|
1286 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
|
1287 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
|
1288 } |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1289 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
|
1290 } |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1291 if (load_from_file(&state, statepath)) { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1292 genesis_deserialize(&state, gen); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1293 free(state.data); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1294 //HACK |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1295 pc = gen->m68k->last_prefetch_address; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1296 ret = 1; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1297 } else { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1298 strcpy(statepath + strlen(statepath)-strlen("state"), "gst"); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1299 pc = load_gst(gen, statepath); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1300 ret = pc != 0; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1301 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1302 if (ret) { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1303 gen->m68k->resume_pc = get_native_address_trans(gen->m68k, pc); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1304 } |
1479
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1305 done: |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1306 free(statepath); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1307 return ret; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1308 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1309 |
1479
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1310 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
|
1311 { |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1312 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
|
1313 { |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1314 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
|
1315 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
|
1316 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
|
1317 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
|
1318 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
|
1319 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
|
1320 //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
|
1321 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
|
1322 } |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1323 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
|
1324 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
|
1325 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
|
1326 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
|
1327 } |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1328 } |
1980
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1971
diff
changeset
|
1329 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
|
1330 bindings_release_capture(); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1927
diff
changeset
|
1331 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
|
1332 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
|
1333 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
|
1334 } |
1479
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1335 } |
a568dca999b2
Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
1336 |
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
|
1337 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
|
1338 { |
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
|
1339 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
|
1340 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
|
1341 //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
|
1342 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
|
1343 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
|
1344 if (load_from_file(&state, statefile)) { |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
1345 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
|
1346 free(state.data); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
1347 //HACK |
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
1348 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
|
1349 } 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
|
1350 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
|
1351 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
|
1352 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
|
1353 } |
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
|
1354 } |
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
|
1355 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
|
1356 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
|
1357 gen->header.enter_debugger = 0; |
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
|
1358 insert_breakpoint(gen->m68k, pc, gen->header.debugger_type == DEBUGGER_NATIVE ? debugger : gdb_debug_enter); |
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
|
1359 } |
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
|
1360 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
|
1361 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
|
1362 } 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
|
1363 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
|
1364 gen->header.enter_debugger = 0; |
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
|
1365 uint32_t address = gen->cart[2] << 16 | gen->cart[3]; |
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
|
1366 insert_breakpoint(gen->m68k, address, gen->header.debugger_type == DEBUGGER_NATIVE ? debugger : gdb_debug_enter); |
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
|
1367 } |
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
|
1368 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
|
1369 } |
1208
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
1370 handle_reset_requests(gen); |
1427
4e5797b3935a
WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents:
1420
diff
changeset
|
1371 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
|
1372 } |
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
|
1373 |
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
|
1374 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
|
1375 { |
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
|
1376 genesis_context *gen = (genesis_context *)system; |
1980
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1971
diff
changeset
|
1377 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
|
1378 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
|
1379 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
|
1380 bindings_reacquire_capture(); |
b387f1c5a1d0
WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents:
1927
diff
changeset
|
1381 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
|
1382 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
|
1383 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
|
1384 } |
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
|
1385 resume_68k(gen->m68k); |
1208
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
1386 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
|
1387 } |
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
|
1388 |
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
|
1389 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
|
1390 { |
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
|
1391 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
|
1392 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
|
1393 } |
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
|
1394 |
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
|
1395 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
|
1396 { |
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
|
1397 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
|
1398 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
|
1399 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
|
1400 } |
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
|
1401 |
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
|
1402 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
|
1403 { |
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
|
1404 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
|
1405 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
|
1406 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
|
1407 } |
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
|
1408 FILE * f = fopen(save_filename, "wb"); |
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
|
1409 if (!f) { |
1395
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1377
diff
changeset
|
1410 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
|
1411 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
|
1412 } |
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
|
1413 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
|
1414 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
|
1415 } |
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
|
1416 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
|
1417 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
|
1418 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
|
1419 } |
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
|
1420 fclose(f); |
1395
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1377
diff
changeset
|
1421 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
|
1422 } |
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
|
1423 |
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
|
1424 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
|
1425 { |
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
|
1426 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
|
1427 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
|
1428 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
|
1429 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
|
1430 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
|
1431 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
|
1432 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
|
1433 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
|
1434 } |
1395
efa7225e0f07
Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents:
1377
diff
changeset
|
1435 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
|
1436 } |
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
|
1437 } |
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
|
1438 } |
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
|
1439 |
1208
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
1440 static void soft_reset(system_header *system) |
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
1441 { |
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
1442 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
|
1443 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
|
1444 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
|
1445 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
|
1446 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
|
1447 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
|
1448 } |
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
|
1449 } |
1208
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
1450 } |
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
1451 |
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
|
1452 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
|
1453 { |
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
|
1454 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
|
1455 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
|
1456 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
|
1457 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
|
1458 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
|
1459 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
|
1460 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
|
1461 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
|
1462 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
|
1463 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
|
1464 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
|
1465 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
|
1466 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
|
1467 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
|
1468 free(gen->lock_on); |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1469 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
|
1470 } |
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
|
1471 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1472 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
|
1473 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1474 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
|
1475 io_gamepad_down(&gen->io, gamepad_num, button); |
1610 | 1476 if (gen->mapper_type == MAPPER_JCART) { |
1477 jcart_gamepad_down(gen, gamepad_num, button); | |
1478 } | |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1479 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1480 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1481 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
|
1482 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1483 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
|
1484 io_gamepad_up(&gen->io, gamepad_num, button); |
1610 | 1485 if (gen->mapper_type == MAPPER_JCART) { |
1486 jcart_gamepad_up(gen, gamepad_num, button); | |
1487 } | |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1488 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1489 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1490 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
|
1491 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1492 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
|
1493 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
|
1494 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1495 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1496 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
|
1497 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1498 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
|
1499 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
|
1500 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1501 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1502 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
|
1503 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1504 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
|
1505 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
|
1506 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1507 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1508 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
|
1509 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1510 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
|
1511 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
|
1512 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1513 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1514 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
|
1515 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1516 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
|
1517 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
|
1518 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1519 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1520 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
|
1521 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1522 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
|
1523 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
|
1524 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1525 |
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
|
1526 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
|
1527 { |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1766
diff
changeset
|
1528 char *config_gain; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1766
diff
changeset
|
1529 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
|
1530 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
|
1531 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
|
1532 render_audio_source_gaindb(gen->ym->audio, config_gain ? atof(config_gain) : 0.0f); |
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
|
1533 |
5278b6e44fc1
Optionally emulate the offset around zero in the imperfect DAC of a discrete YM2612
Michael Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
1534 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
|
1535 ym_enable_zero_offset(gen->ym, !strcmp(config_dac, "zero_offset")); |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1766
diff
changeset
|
1536 } |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1766
diff
changeset
|
1537 |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
1538 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
|
1539 { |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
1540 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
|
1541 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
|
1542 set_audio_config(gen); |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
1543 } |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
1544 |
1909
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1545 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
|
1546 { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1547 genesis_context *gen = (genesis_context *)system; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1548 vgm_writer *vgm = vgm_write_open(filename, gen->version_reg & HZ50 ? 50 : 60, gen->master_clock, gen->m68k->current_cycle); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1549 if (vgm) { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1550 printf("Started logging VGM to %s\n", filename); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1551 sync_sound(gen, vgm->last_cycle); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1552 ym_vgm_log(gen->ym, gen->master_clock, vgm); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1553 psg_vgm_log(gen->psg, gen->master_clock, vgm); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1554 gen->header.vgm_logging = 1; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1555 } else { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1556 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
|
1557 } |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1558 } |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1559 |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1560 static void stop_vgm_log(system_header *system) |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1561 { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1562 puts("Stopped VGM log"); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1563 genesis_context *gen = (genesis_context *)system; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1564 vgm_close(gen->ym->vgm); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1565 gen->ym->vgm = gen->psg->vgm = NULL; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1566 gen->header.vgm_logging = 0; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1567 } |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1568 |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1569 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
|
1570 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1571 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1572 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1573 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1574 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
|
1575 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1576 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1577 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1578 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1579 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1580 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
|
1581 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1582 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1583 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1584 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1585 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
|
1586 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1587 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1588 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1589 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1590 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1591 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
|
1592 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1593 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1594 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1595 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1596 return gen->tmss_read_16(address, context); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1597 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1598 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
|
1599 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1600 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1601 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
|
1602 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1603 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1604 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1605 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1606 return gen->tmss_read_8(address, context); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1607 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1608 #ifdef BLASTEM_BIG_ENDIAN |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1609 return gen->tmss_buffer[address]; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1610 #else |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1611 return gen->tmss_buffer[address ^ 1]; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1612 #endif |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1613 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1614 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1615 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
|
1616 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1617 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1618 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1619 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1620 address += gen->tmss_write_offset; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1621 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
|
1622 *dest = value; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1623 m68k_handle_code_write(address, m68k); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1624 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1625 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1626 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1627 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1628 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1629 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
|
1630 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1631 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1632 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1633 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1634 address += gen->tmss_write_offset; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1635 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
|
1636 #ifdef BLASTEM_BIG_ENDIAN |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1637 dest[address & 1] = value; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1638 #else |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1639 dest[address & 1 ^ 1] = value; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1640 #endif |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1641 m68k_handle_code_write(address & ~1, m68k); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1642 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1643 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1644 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1645 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1646 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1647 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
|
1648 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1649 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1650 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1651 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1652 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
|
1653 address >>= 1; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1654 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
|
1655 base[address] = value; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1656 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1657 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1658 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1659 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1660 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
|
1661 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1662 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1663 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1664 if (gen->tmss && (address & 1)) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1665 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
|
1666 address >>= 1; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1667 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
|
1668 base[address] = value; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1669 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1670 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1671 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1672 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1673 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
|
1674 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1675 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1676 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1677 if (gen->tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1678 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
|
1679 address >>= 1; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1680 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
|
1681 base[address] = value >> 8; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1682 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1683 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1684 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1685 |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1686 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
|
1687 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1688 m68k_context *m68k = context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1689 genesis_context *gen = m68k->system; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1690 if (gen->tmss && !(address & 1)) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1691 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
|
1692 address >>= 1; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1693 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
|
1694 base[address] = value; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1695 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1696 return context; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1697 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1698 |
1113
45db303fc705
Restore 68K address logging functionality
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
1699 genesis_context *alloc_init_genesis(rom_info *rom, void *main_rom, void *lock_on, uint32_t system_opts, 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
|
1700 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1701 static memmap_chunk z80_map[] = { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1702 { 0x0000, 0x4000, 0x1FFF, 0, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, NULL, NULL, NULL, NULL, 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
|
1703 { 0x8000, 0x10000, 0x7FFF, 0, 0, 0, NULL, NULL, NULL, z80_read_bank, z80_write_bank}, |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1704 { 0x4000, 0x6000, 0x0003, 0, 0, 0, NULL, NULL, NULL, z80_read_ym, z80_write_ym}, |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1705 { 0x6000, 0x6100, 0xFFFF, 0, 0, 0, NULL, NULL, NULL, NULL, z80_write_bank_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
|
1706 { 0x7F00, 0x8000, 0x00FF, 0, 0, 0, NULL, NULL, NULL, z80_vdp_port_read, z80_vdp_port_write} |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1707 }; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1708 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
|
1709 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
|
1710 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
|
1711 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
|
1712 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
|
1713 gen->header.persist_save = persist_save; |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1428
diff
changeset
|
1714 gen->header.load_state = load_state; |
1208
95f5253e75c7
Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents:
1204
diff
changeset
|
1715 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
|
1716 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
|
1717 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
|
1718 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
|
1719 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
|
1720 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
|
1721 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
|
1722 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
|
1723 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
|
1724 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
|
1725 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
|
1726 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
|
1727 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
|
1728 gen->header.config_updated = config_updated; |
1690
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
1729 gen->header.serialize = serialize; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
1730 gen->header.deserialize = deserialize; |
1909
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1731 gen->header.start_vgm_log = start_vgm_log; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1907
diff
changeset
|
1732 gen->header.stop_vgm_log = stop_vgm_log; |
1377
e587f16e7d3d
Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents:
1374
diff
changeset
|
1733 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
|
1734 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
|
1735 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
|
1736 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
|
1737 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
|
1738 if (tmss) { |
5433252329fb
Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents:
1889
diff
changeset
|
1739 gen->version_reg |= 1; |
5433252329fb
Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents:
1889
diff
changeset
|
1740 } |
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
|
1741 |
1906
2d462aa78349
Make VDP VSRAM capacity respect model selection
Michael Pavone <pavone@retrodev.com>
parents:
1904
diff
changeset
|
1742 uint8_t max_vsram = !strcmp(tern_find_ptr_default(model, "vsram", "40"), "64"); |
2d462aa78349
Make VDP VSRAM capacity respect model selection
Michael Pavone <pavone@retrodev.com>
parents:
1904
diff
changeset
|
1743 gen->vdp = init_vdp_context(gen->version_reg & 0x40, max_vsram); |
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
|
1744 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
|
1745 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
|
1746 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
|
1747 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
|
1748 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
|
1749 gen->int_latency_prev2 = MCLKS_PER_68K * 16; |
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
|
1750 |
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
|
1751 render_set_video_standard((gen->version_reg & HZ50) ? VID_PAL : VID_NTSC); |
1946 | 1752 event_system_start(SYSTEM_GENESIS, (gen->version_reg & HZ50) ? VID_PAL : VID_NTSC, rom->name); |
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
|
1753 |
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
|
1754 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
|
1755 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
|
1756 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
|
1757 system_opts |= YM_OPT_3834; |
8312e574100a
Implement selectable YM2612/YM3834 invalid status port behavior
Michael Pavone <pavone@retrodev.com>
parents:
1902
diff
changeset
|
1758 } |
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
|
1759 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
|
1760 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1761 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
|
1762 psg_init(gen->psg, gen->master_clock, MCLKS_PER_PSG); |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1766
diff
changeset
|
1763 |
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
|
1764 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
|
1765 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1766 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
|
1767 #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
|
1768 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
|
1769 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
|
1770 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
|
1771 #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
|
1772 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
|
1773 #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
|
1774 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
|
1775 #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
|
1776 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
|
1777 #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
|
1778 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1779 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
|
1780 gen->z80->mem_pointers[0] = gen->zram; |
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
|
1781 gen->z80->mem_pointers[1] = gen->z80->mem_pointers[2] = (uint8_t *)main_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
|
1782 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1783 gen->cart = main_rom; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1784 gen->lock_on = lock_on; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1785 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
|
1786 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
|
1787 { |
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
|
1788 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
|
1789 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
|
1790 { |
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
|
1791 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
|
1792 } |
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
|
1793 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
|
1794 { |
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
|
1795 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
|
1796 } |
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
|
1797 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
|
1798 { |
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
|
1799 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
|
1800 } |
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
|
1801 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
|
1802 { |
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
|
1803 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
|
1804 } |
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
|
1805 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
|
1806 { |
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
|
1807 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
|
1808 } |
1906
2d462aa78349
Make VDP VSRAM capacity respect model selection
Michael Pavone <pavone@retrodev.com>
parents:
1904
diff
changeset
|
1809 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
|
1810 { |
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
|
1811 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
|
1812 } |
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
|
1813 } |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1113
diff
changeset
|
1814 setup_io_devices(config, rom, &gen->io); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1576
diff
changeset
|
1815 gen->header.has_keyboard = io_has_keyboard(&gen->io); |
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
|
1816 |
1444
14a2834d010c
Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents:
1440
diff
changeset
|
1817 gen->mapper_type = rom->mapper_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
|
1818 gen->save_type = rom->save_type; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1819 if (gen->save_type != SAVE_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
|
1820 gen->save_ram_mask = rom->save_mask; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1821 gen->save_size = rom->save_size; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1822 gen->save_storage = rom->save_buffer; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1823 gen->eeprom_map = rom->eeprom_map; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1824 gen->num_eeprom = rom->num_eeprom; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1825 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
|
1826 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
|
1827 } else if (gen->save_type == SAVE_NOR) { |
1519
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1471
diff
changeset
|
1828 memcpy(&gen->nor, rom->nor, sizeof(gen->nor)); |
1f745318f10a
Made the NOR flash emulation a bit more flexible, but not yet flexible enough to properly support the flash chip in the MegaWiFi cart
Michael Pavone <pavone@retrodev.com>
parents:
1471
diff
changeset
|
1829 //nor_flash_init(&gen->nor, gen->save_storage, gen->save_size, rom->save_page_size, rom->save_product_id, rom->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
|
1830 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1831 } 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
|
1832 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
|
1833 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1834 |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1835 gen->mapper_start_index = rom->mapper_start_index; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1836 |
1165
9fc680b35dbb
Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
1837 //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
|
1838 uint8_t next_ptr_index = 0; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1839 uint32_t tmss_min_alloc = 16 * 1024; |
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
|
1840 for (int i = 0; i < rom->map_chunks; i++) |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1841 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1842 if (rom->map[i].start == 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
|
1843 rom->map[i].buffer = gen->work_ram; |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1844 if (!tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1845 break; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1846 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1847 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1848 if (rom->map[i].flags & MMAP_PTR_IDX && rom->map[i].ptr_index >= next_ptr_index) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1849 next_ptr_index = rom->map[i].ptr_index + 1; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1850 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1851 if (rom->map[i].start < 0x400000 && rom->map[i].read_16 != unused_read) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1852 uint32_t highest_offset = (rom->map[i].end & rom->map[i].mask) + 1; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1853 if (highest_offset > tmss_min_alloc) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1854 tmss_min_alloc = highest_offset; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1855 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1856 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1857 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1858 if (tmss) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1859 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
|
1860 uint8_t *buffer = malloc(tmss_min_alloc); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1861 uint32_t tmss_size; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1862 if (is_absolute_path(tmss_path)) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1863 FILE *f = fopen(tmss_path, "rb"); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1864 if (!f) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1865 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
|
1866 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1867 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
|
1868 fclose(f); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1869 } else { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1870 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
|
1871 if (!tmp) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1872 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
|
1873 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1874 memcpy(buffer, tmp, tmss_size); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1875 free(tmp); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1876 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1877 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
|
1878 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1879 buffer[tmss_size] = 0xFF; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1880 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1881 #ifndef BLASTEM_BIG_ENDIAN |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1882 byteswap_rom(tmss_size, (uint16_t *)buffer); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1883 #endif |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1884 //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
|
1885 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
|
1886 { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1887 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
|
1888 } |
2034
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1889 //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
|
1890 //WARNING: This code makes some pretty big assumptions about the kinds of map chunks it will encounter |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1891 for (int i = 0; i < rom->map_chunks; i++) |
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 if (rom->map[i].start < 0x400000 && rom->map[i].read_16 != unused_read) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1894 if (rom->map[i].flags == MMAP_READ) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1895 //Normal ROM |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1896 rom->map[i].flags |= MMAP_PTR_IDX | MMAP_CODE; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1897 rom->map[i].ptr_index = next_ptr_index++; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1898 if (rom->map[i].ptr_index >= NUM_MEM_AREAS) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1899 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
|
1900 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1901 gen->tmss_pointers[rom->map[i].ptr_index] = rom->map[i].buffer; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1902 rom->map[i].buffer = buffer + (rom->map[i].start & ~rom->map[i].mask & (tmss_size - 1)); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1903 } else if (rom->map[i].flags & MMAP_PTR_IDX) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1904 //Sega mapper page or multi-game mapper |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1905 gen->tmss_pointers[rom->map[i].ptr_index] = rom->map[i].buffer; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1906 rom->map[i].buffer = buffer + (rom->map[i].start & ~rom->map[i].mask & (tmss_size - 1)); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1907 if (rom->map[i].write_16) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1908 if (!gen->tmss_write_16) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1909 gen->tmss_write_16 = rom->map[i].write_16; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1910 gen->tmss_write_8 = rom->map[i].write_8; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1911 rom->map[i].write_16 = tmss_rom_write_16; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1912 rom->map[i].write_8 = tmss_rom_write_8; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1913 } else if (gen->tmss_write_16 == rom->map[i].write_16) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1914 rom->map[i].write_16 = tmss_rom_write_16; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1915 rom->map[i].write_8 = tmss_rom_write_8; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1916 } else { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1917 warning("Chunk starting at %X has a write function, but we've already stored a different one for TMSS remap\n", rom->map[i].start); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1918 } |
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 } else if ((rom->map[i].flags & (MMAP_READ | MMAP_WRITE)) == (MMAP_READ | MMAP_WRITE)) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1921 //RAM or SRAM |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1922 rom->map[i].flags |= MMAP_PTR_IDX; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1923 rom->map[i].ptr_index = next_ptr_index++; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1924 gen->tmss_pointers[rom->map[i].ptr_index] = rom->map[i].buffer; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1925 rom->map[i].buffer = buffer + (rom->map[i].start & ~rom->map[i].mask & (tmss_size - 1)); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1926 if (!gen->tmss_write_offset || gen->tmss_write_offset == rom->map[i].start) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1927 gen->tmss_write_offset = rom->map[i].start; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1928 rom->map[i].flags &= ~MMAP_WRITE; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1929 if (rom->map[i].flags & MMAP_ONLY_ODD) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1930 rom->map[i].write_16 = tmss_odd_write_16; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1931 rom->map[i].write_8 = tmss_odd_write_8; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1932 } else if (rom->map[i].flags & MMAP_ONLY_EVEN) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1933 rom->map[i].write_16 = tmss_even_write_16; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1934 rom->map[i].write_8 = tmss_even_write_8; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1935 } else { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1936 rom->map[i].write_16 = tmss_word_write_16; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1937 rom->map[i].write_8 = tmss_word_write_8; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1938 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1939 } else { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1940 warning("Could not remap writes for chunk starting at %X for TMSS because write_offset is %X\n", rom->map[i].start, gen->tmss_write_offset); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1941 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1942 } else if (rom->map[i].flags & MMAP_READ_CODE) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1943 //NOR flash |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1944 rom->map[i].flags |= MMAP_PTR_IDX; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1945 rom->map[i].ptr_index = next_ptr_index++; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1946 if (rom->map[i].ptr_index >= NUM_MEM_AREAS) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1947 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
|
1948 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1949 gen->tmss_pointers[rom->map[i].ptr_index] = rom->map[i].buffer; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1950 rom->map[i].buffer = buffer + (rom->map[i].start & ~rom->map[i].mask & (tmss_size - 1)); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1951 if (!gen->tmss_write_16) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1952 gen->tmss_write_16 = rom->map[i].write_16; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1953 gen->tmss_write_8 = rom->map[i].write_8; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1954 gen->tmss_read_16 = rom->map[i].read_16; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1955 gen->tmss_read_8 = rom->map[i].read_8; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1956 rom->map[i].write_16 = tmss_rom_write_16; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1957 rom->map[i].write_8 = tmss_rom_write_8; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1958 rom->map[i].read_16 = tmss_rom_read_16; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1959 rom->map[i].read_8 = tmss_rom_read_8; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1960 } else if (gen->tmss_write_16 == rom->map[i].write_16) { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1961 rom->map[i].write_16 = tmss_rom_write_16; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1962 rom->map[i].write_8 = tmss_rom_write_8; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1963 rom->map[i].read_16 = tmss_rom_read_16; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1964 rom->map[i].read_8 = tmss_rom_read_8; |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1965 } else { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1966 warning("Chunk starting at %X has a write function, but we've already stored a different one for TMSS remap\n", rom->map[i].start); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1967 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1968 } else { |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1969 warning("Didn't remap chunk starting at %X for TMSS because it has flags %X\n", rom->map[i].start, rom->map[i].flags); |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1970 } |
8b2ef428d1aa
Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents:
2033
diff
changeset
|
1971 } |
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 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
|
1974 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1975 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1976 m68k_options *opts = malloc(sizeof(m68k_options)); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1977 init_m68k_opts(opts, rom->map, rom->map_chunks, MCLKS_PER_68K); |
1901
5433252329fb
Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents:
1889
diff
changeset
|
1978 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
|
1979 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
|
1980 } |
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
|
1981 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
|
1982 gen->m68k->system = gen; |
1113
45db303fc705
Restore 68K address logging functionality
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
1983 opts->address_log = (system_opts & OPT_ADDRESS_LOG) ? fopen("address.log", "w") : NULL; |
1165
9fc680b35dbb
Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
1984 |
9fc680b35dbb
Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
1985 //This must happen after the 68K context has been allocated |
9fc680b35dbb
Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
1986 for (int i = 0; i < rom->map_chunks; i++) |
9fc680b35dbb
Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
1987 { |
9fc680b35dbb
Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
1988 if (rom->map[i].flags & MMAP_PTR_IDX) { |
9fc680b35dbb
Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
1989 gen->m68k->mem_pointers[rom->map[i].ptr_index] = rom->map[i].buffer; |
9fc680b35dbb
Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
1990 } |
9fc680b35dbb
Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
1991 } |
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
|
1992 |
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
|
1993 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
|
1994 //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
|
1995 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
|
1996 { |
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
|
1997 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
|
1998 } |
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
|
1999 } |
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
|
2000 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
|
2001 |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2002 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
|
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 |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
2005 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) |
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
|
2006 { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2007 static memmap_chunk base_map[] = { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2008 {0xE00000, 0x1000000, 0xFFFF, 0, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, 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
|
2009 NULL, NULL, NULL, 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
|
2010 {0xC00000, 0xE00000, 0x1FFFFF, 0, 0, 0, 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
|
2011 (read_16_fun)vdp_port_read, (write_16_fun)vdp_port_write, |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2012 (read_8_fun)vdp_port_read_b, (write_8_fun)vdp_port_write_b}, |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2013 {0xA00000, 0xA12000, 0x1FFFF, 0, 0, 0, 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
|
2014 (read_16_fun)io_read_w, (write_16_fun)io_write_w, |
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
|
2015 (read_8_fun)io_read, (write_8_fun)io_write}, |
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
|
2016 {0x000000, 0xFFFFFF, 0xFFFFFF, 0, 0, 0, NULL, |
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
|
2017 (read_16_fun)unused_read, (write_16_fun)unused_write, |
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
|
2018 (read_8_fun)unused_read_b, (write_8_fun)unused_write_b} |
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
|
2019 }; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2020 static tern_node *rom_db; |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. 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 if (!rom_db) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2022 rom_db = load_rom_db(); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2023 } |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
2024 rom_info info = configure_rom(rom_db, rom, rom_size, lock_on, lock_on_size, base_map, sizeof(base_map)/sizeof(base_map[0])); |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
2025 rom = info.rom; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
2026 rom_size = info.rom_size; |
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
|
2027 #ifndef BLASTEM_BIG_ENDIAN |
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
|
2028 byteswap_rom(rom_size, 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
|
2029 if (lock_on) { |
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
|
2030 byteswap_rom(lock_on_size, lock_on); |
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
|
2031 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2032 #endif |
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
|
2033 char *m68k_divider = tern_find_path(config, "clocks\0m68k_divider\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
|
2034 if (!m68k_divider) { |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2035 m68k_divider = "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
|
2036 } |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2037 MCLKS_PER_68K = atoi(m68k_divider); |
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2038 if (!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
|
2039 MCLKS_PER_68K = 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
|
2040 } |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
2041 return alloc_init_genesis(&info, rom, lock_on, ym_opts, 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
|
2042 } |