annotate genesis.c @ 2568:f0ace2494df6

Fix libretro build
author Michael Pavone <pavone@retrodev.com>
date Tue, 28 Jan 2025 23:38:06 -0800
parents 3f58fec775df
children 3d14db924e57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 /*
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 Copyright 2013-2016 Michael Pavone
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 This file is part of BlastEm.
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 */
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #include "genesis.h"
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
7 #include "segacd.h"
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 #include "blastem.h"
1414
d94855080529 Move I2C EEPROM and NOR Flash functions out of romdb.c into new files
Michael Pavone <pavone@retrodev.com>
parents: 1401
diff changeset
9 #include "nor.h"
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 #include <stdlib.h>
1188
448ce87b87fc Fix missing include that prevented building Windows version
Michael Pavone <pavone@retrodev.com>
parents: 1184
diff changeset
11 #include <ctype.h>
1204
d7be5b6e0a8d Added config file option to specify that RAM should be randomly initialized. Moved default_region inside a new "system" parent node in config
Michael Pavone <pavone@retrodev.com>
parents: 1188
diff changeset
12 #include <time.h>
1220
1e7977460d18 Add mising include in genesis.c so the Windows build works again
Michael Pavone <pavone@retrodev.com>
parents: 1215
diff changeset
13 #include <string.h>
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 #include "render.h"
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 #include "gst.h"
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 #include "util.h"
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1108
diff changeset
17 #include "debug.h"
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1108
diff changeset
18 #include "gdb_remote.h"
1478
da1dce39e846 Refactored save slot related logic to reduce duplication and allow reuse in new UI. Get state loading/saving mostly working in new UI
Michael Pavone <pavone@retrodev.com>
parents: 1471
diff changeset
19 #include "saves.h"
1583
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
20 #include "bindings.h"
1610
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1595
diff changeset
21 #include "jcart.h"
1901
5433252329fb Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents: 1889
diff changeset
22 #include "config.h"
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
23 #include "event_log.h"
2083
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
24 #include "paths.h"
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25 #define MCLKS_NTSC 53693175
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 #define MCLKS_PAL 53203395
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28 uint32_t MCLKS_PER_68K;
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 #define MCLKS_PER_YM 7
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30 #define MCLKS_PER_Z80 15
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
31 #define MCLKS_PER_PSG (MCLKS_PER_Z80*16)
1291
f17fe0d00626 Adjust Z80 interrupt pulse duration to match hardware measurements
Michael Pavone <pavone@retrodev.com>
parents: 1288
diff changeset
32 #define Z80_INT_PULSE_MCLKS 2573 //measured value is ~171.5 Z80 clocks
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 #define DEFAULT_SYNC_INTERVAL MCLKS_LINE
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
34 #define DEFAULT_LOWPASS_CUTOFF 3390
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
35
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 #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
37 #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
38
1688
395f684c5379 Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1643
diff changeset
39 #ifdef IS_LIB
2568
f0ace2494df6 Fix libretro build
Michael Pavone <pavone@retrodev.com>
parents: 2558
diff changeset
40 #define MAX_SOUND_CYCLES (MCLKS_PER_YM*OPN2_NUM_OPERATORS*6*4)
1688
395f684c5379 Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1643
diff changeset
41 #else
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
42 #define MAX_SOUND_CYCLES 100000
1688
395f684c5379 Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1643
diff changeset
43 #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
44
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
45 #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
46 #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
47 #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
48 #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
49 #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
50 #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
51 #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
52 #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
53
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
54 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
55 {
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
56 if (all) {
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
57 start_section(buf, SECTION_68000);
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
58 m68k_serialize(gen->m68k, m68k_pc, buf);
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
59 end_section(buf);
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
60
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
61 if (gen->header.type == SYSTEM_GENESIS) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
62 start_section(buf, SECTION_Z80);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
63 z80_serialize(gen->z80, buf);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
64 end_section(buf);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
65 }
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
66 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
67
1427
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
68 start_section(buf, SECTION_VDP);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
69 vdp_serialize(gen->vdp, buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
70 end_section(buf);
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
71
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
72 if (gen->header.type != SYSTEM_PICO && gen->header.type != SYSTEM_COPERA) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
73 start_section(buf, SECTION_YM2612);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
74 ym_serialize(gen->ym, buf);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
75 end_section(buf);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
76 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
77
1427
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
78 start_section(buf, SECTION_PSG);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
79 psg_serialize(gen->psg, buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
80 end_section(buf);
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
81
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
82 if (all) {
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
83 start_section(buf, SECTION_GEN_BUS_ARBITER);
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
84 save_int8(buf, gen->z80->reset);
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
85 save_int8(buf, gen->z80->busreq);
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
86 save_int16(buf, gen->z80_bank_reg);
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
87 //I think the refresh logic may technically be part of the VDP, but whatever
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
88 save_int32(buf, gen->last_sync_cycle);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
89 save_int32(buf, gen->refresh_counter);
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
90 end_section(buf);
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
91
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
92 if (gen->header.type == SYSTEM_GENESIS) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
93 start_section(buf, SECTION_SEGA_IO_1);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
94 io_serialize(gen->io.ports, buf);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
95 end_section(buf);
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
96
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
97 start_section(buf, SECTION_SEGA_IO_2);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
98 io_serialize(gen->io.ports + 1, buf);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
99 end_section(buf);
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
100
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
101 start_section(buf, SECTION_SEGA_IO_EXT);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
102 io_serialize(gen->io.ports + 2, buf);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
103 end_section(buf);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
104 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
105
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
106 start_section(buf, SECTION_MAIN_RAM);
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
107 save_int8(buf, RAM_WORDS * 2 / 1024);
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
108 save_buffer16(buf, gen->work_ram, RAM_WORDS);
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
109 end_section(buf);
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
110
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
111 if (gen->header.type == SYSTEM_GENESIS) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
112 start_section(buf, SECTION_SOUND_RAM);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
113 save_int8(buf, Z80_RAM_BYTES / 1024);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
114 save_buffer8(buf, gen->zram, Z80_RAM_BYTES);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
115 end_section(buf);
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
116
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
117 if (gen->version_reg & 0xF) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
118 //only save TMSS info if it's present
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
119 //that will allow a state saved on a model lacking TMSS
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
120 //to be loaded on a model that has it
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
121 start_section(buf, SECTION_TMSS);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
122 save_int8(buf, gen->tmss);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
123 save_buffer16(buf, gen->tmss_lock, 2);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
124 end_section(buf);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
125 }
2039
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
126 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
127
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
128 cart_serialize(&gen->header, buf);
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
129 }
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
130 if (gen->expansion) {
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
131 segacd_context *cd = gen->expansion;
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
132 segacd_serialize(cd, buf, all);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
133 }
1427
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
134 }
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
135
1690
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
136 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
137 {
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
138 genesis_context *gen = (genesis_context *)sys;
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
139 uint32_t address;
2500
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
140 #ifndef NEW_CORE
1690
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
141 if (gen->m68k->resume_pc) {
2476
aaf7bb58ffca Fix bug in Gen/MD serialize routine that could cause a use-after free in some cases
Michael Pavone <pavone@retrodev.com>
parents: 2466
diff changeset
142
1690
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
143 gen->header.save_state = SERIALIZE_SLOT+1;
2476
aaf7bb58ffca Fix bug in Gen/MD serialize routine that could cause a use-after free in some cases
Michael Pavone <pavone@retrodev.com>
parents: 2466
diff changeset
144 while (!gen->serialize_tmp)
aaf7bb58ffca Fix bug in Gen/MD serialize routine that could cause a use-after free in some cases
Michael Pavone <pavone@retrodev.com>
parents: 2466
diff changeset
145 {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
146 gen->m68k->target_cycle = gen->m68k->cycles + 1;
2476
aaf7bb58ffca Fix bug in Gen/MD serialize routine that could cause a use-after free in some cases
Michael Pavone <pavone@retrodev.com>
parents: 2466
diff changeset
147 resume_68k(gen->m68k);
aaf7bb58ffca Fix bug in Gen/MD serialize routine that could cause a use-after free in some cases
Michael Pavone <pavone@retrodev.com>
parents: 2466
diff changeset
148 }
1690
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
149 if (size_out) {
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
150 *size_out = gen->serialize_size;
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
151 }
2476
aaf7bb58ffca Fix bug in Gen/MD serialize routine that could cause a use-after free in some cases
Michael Pavone <pavone@retrodev.com>
parents: 2466
diff changeset
152 uint8_t *ret = gen->serialize_tmp;
aaf7bb58ffca Fix bug in Gen/MD serialize routine that could cause a use-after free in some cases
Michael Pavone <pavone@retrodev.com>
parents: 2466
diff changeset
153 gen->serialize_tmp = NULL;
aaf7bb58ffca Fix bug in Gen/MD serialize routine that could cause a use-after free in some cases
Michael Pavone <pavone@retrodev.com>
parents: 2466
diff changeset
154 return ret;
2500
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
155 } else
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
156 #endif
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
157 {
1690
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
158 serialize_buffer state;
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
159 init_serialize(&state);
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
160 uint32_t address = read_word(4, (void **)gen->m68k->mem_pointers, &gen->m68k->opts->gen, gen->m68k) << 16;
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
161 address |= read_word(6, (void **)gen->m68k->mem_pointers, &gen->m68k->opts->gen, gen->m68k);
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
162 genesis_serialize(gen, &state, address, 1);
1690
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
163 if (size_out) {
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
164 *size_out = state.size;
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
165 }
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
166 return state.data;
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
167 }
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
168 }
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
169
1427
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
170 static void ram_deserialize(deserialize_buffer *buf, void *vgen)
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
171 {
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
172 genesis_context *gen = vgen;
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
173 uint32_t ram_size = load_int8(buf) * 1024 / 2;
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
174 if (ram_size > RAM_WORDS) {
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
175 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
176 }
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
177 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
178 m68k_invalidate_code_range(gen->m68k, 0xE00000, 0x1000000);
1427
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
179 }
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
180
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
181 static void zram_deserialize(deserialize_buffer *buf, void *vgen)
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
182 {
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
183 genesis_context *gen = vgen;
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
184 uint32_t ram_size = load_int8(buf) * 1024;
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
185 if (ram_size > Z80_RAM_BYTES) {
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
186 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
187 }
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
188 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
189 z80_invalidate_code_range(gen->z80, 0, 0x4000);
1427
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
190 }
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
191
1445
349d50930c03 Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1444
diff changeset
192 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
193 {
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
194 if (gen->z80_bank_reg < 0x140) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
195 gen->z80->mem_pointers[1] = get_native_pointer(gen->z80_bank_reg << 15, (void **)gen->m68k->mem_pointers, &gen->m68k->opts->gen);
1445
349d50930c03 Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1444
diff changeset
196 } else {
349d50930c03 Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1444
diff changeset
197 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
198 }
1753
33ec5df77fac Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents: 1752
diff changeset
199 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
200 }
349d50930c03 Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1444
diff changeset
201
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
202 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
203 {
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
204 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
205 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
206 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
207 gen->z80_bank_reg = load_int16(buf) & 0x1FF;
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
208 if ((buf->size - buf->cur_pos) >= 2 * sizeof(uint32_t)) {
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
209 gen->last_sync_cycle = load_int32(buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
210 gen->refresh_counter = load_int32(buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
211 } else {
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
212 //save state is from an older version of BlastEm that lacks these fields
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
213 //set them to reasonable values
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
214 gen->last_sync_cycle = gen->m68k->cycles;
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
215 gen->refresh_counter = 0;
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
216 }
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
217 }
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
218
2039
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
219 static void tmss_deserialize(deserialize_buffer *buf, void *vgen)
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
220 {
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
221 genesis_context *gen = vgen;
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
222 gen->tmss = load_int8(buf);
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
223 load_buffer16(buf, gen->tmss_lock, 2);
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
224 }
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
225
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
226 static void adjust_int_cycle(m68k_context * context, vdp_context * v_context);
2039
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
227 static void check_tmss_lock(genesis_context *gen);
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
228 static void toggle_tmss_rom(genesis_context *gen);
2500
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
229 #ifndef NEW_CORE
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
230 #include "m68k_internal.h" //needed for get_native_address_trans, should be eliminated once handling of PC is cleaned up
2500
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
231 #endif
1427
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
232 void genesis_deserialize(deserialize_buffer *buf, genesis_context *gen)
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
233 {
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
234 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
235 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
236 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
237 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
238 register_section_handler(buf, (section_handler){.fun = ram_deserialize, .data = gen}, SECTION_MAIN_RAM);
1444
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1440
diff changeset
239 register_section_handler(buf, (section_handler){.fun = cart_deserialize, .data = gen}, SECTION_MAPPER);
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
240 if (gen->header.type == SYSTEM_GENESIS) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
241 register_section_handler(buf, (section_handler){.fun = z80_deserialize, .data = gen->z80}, SECTION_Z80);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
242 register_section_handler(buf, (section_handler){.fun = io_deserialize, .data = gen->io.ports}, SECTION_SEGA_IO_1);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
243 register_section_handler(buf, (section_handler){.fun = io_deserialize, .data = gen->io.ports + 1}, SECTION_SEGA_IO_2);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
244 register_section_handler(buf, (section_handler){.fun = io_deserialize, .data = gen->io.ports + 2}, SECTION_SEGA_IO_EXT);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
245 register_section_handler(buf, (section_handler){.fun = zram_deserialize, .data = gen}, SECTION_SOUND_RAM);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
246 register_section_handler(buf, (section_handler){.fun = tmss_deserialize, .data = gen}, SECTION_TMSS);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
247 }
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
248 if (gen->header.type != SYSTEM_PICO && gen->header.type != SYSTEM_COPERA) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
249 register_section_handler(buf, (section_handler){.fun = ym_deserialize, .data = gen->ym}, SECTION_YM2612);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
250 }
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
251 if (gen->expansion) {
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
252 segacd_context *cd = gen->expansion;
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
253 segacd_register_section_handlers(cd, buf);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
254 }
2039
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
255 uint8_t tmss_old = gen->tmss;
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
256 gen->tmss = 0xFF;
1427
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
257 while (buf->cur_pos < buf->size)
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
258 {
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
259 load_section(buf);
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
260 }
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
261 if (gen->header.type == SYSTEM_GENESIS && (gen->version_reg & 0xF)) {
2039
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
262 if (gen->tmss == 0xFF) {
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
263 //state lacked a TMSS section, assume that the game ROM is mapped in
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
264 //and that the VDP is unlocked
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
265 gen->tmss_lock[0] = 0x5345;
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
266 gen->tmss_lock[1] = 0x4741;
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
267 gen->tmss = 1;
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
268 }
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
269 if (gen->tmss != tmss_old) {
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
270 toggle_tmss_rom(gen);
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
271 }
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
272 check_tmss_lock(gen);
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
273 }
1445
349d50930c03 Save and restore Z80 bank register in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1444
diff changeset
274 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
275 adjust_int_cycle(gen->m68k, gen->vdp);
2500
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
276 #ifndef NEW_CORE
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
277 //HACK: Fix this once PC/IR is represented in a better way in 68K core
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
278 //Would be better for this hack to live in side the 68K core itself, but it's better to do it
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
279 //after RAM has been loaded to avoid any unnecessary retranslation
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
280 gen->m68k->resume_pc = get_native_address_trans(gen->m68k, gen->m68k->last_prefetch_address);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
281 if (gen->expansion) {
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
282 segacd_context *cd = gen->expansion;
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
283 cd->m68k->resume_pc = get_native_address_trans(cd->m68k, cd->m68k->last_prefetch_address);
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
284 }
2500
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
285 #endif
1690
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
286 free(buf->handlers);
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
287 buf->handlers = NULL;
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
288 }
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
289
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
290 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
291 {
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
292 genesis_context *gen = (genesis_context *)sys;
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
293 deserialize_buffer buffer;
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
294 init_deserialize(&buffer, data, size);
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
295 genesis_deserialize(&buffer, gen);
1427
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
296 }
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
297
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
298 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
299 {
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
300 genesis_context *genesis = (genesis_context *)current_system;
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
301 address *= 2;
1420
975b5b7eaa77 Fix DMA from byte-wide SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
302 //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
303 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
304 return 0;
975b5b7eaa77 Fix DMA from byte-wide SRAM
Michael Pavone <pavone@retrodev.com>
parents: 1416
diff changeset
305 }
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
306 if (genesis->expansion) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
307 segacd_context *cd = genesis->expansion;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
308 uint32_t word_ram = cd->base + 0x200000;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
309 uint32_t word_ram_end = cd->base + 0x240000;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
310 if (address >= word_ram && address < word_ram_end) {
2336
83f5529086c5 Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents: 2335
diff changeset
311 if (!cd->has_vdp_dma_value) {
2500
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
312 #ifdef NEW_CORE
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
313 cd->vdp_dma_value = genesis->m68k->prefetch;
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
314 #else
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
315 cd->vdp_dma_value = read_word(genesis->m68k->last_prefetch_address, (void **)genesis->m68k->mem_pointers, &genesis->m68k->opts->gen, genesis->m68k);
2500
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
316 #endif
2336
83f5529086c5 Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents: 2335
diff changeset
317 cd->has_vdp_dma_value = 1;
83f5529086c5 Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents: 2335
diff changeset
318 }
83f5529086c5 Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents: 2335
diff changeset
319 uint16_t ret = cd->vdp_dma_value;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
320 cd->vdp_dma_value = read_word(address, (void **)genesis->m68k->mem_pointers, &genesis->m68k->opts->gen, genesis->m68k);
2336
83f5529086c5 Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents: 2335
diff changeset
321 return ret;
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
322 }
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
323 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
324
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
325 return read_word(address, (void **)genesis->m68k->mem_pointers, &genesis->m68k->opts->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
326 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
327
2336
83f5529086c5 Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents: 2335
diff changeset
328 void vdp_dma_started(void)
83f5529086c5 Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents: 2335
diff changeset
329 {
83f5529086c5 Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents: 2335
diff changeset
330 genesis_context *genesis = (genesis_context *)current_system;
83f5529086c5 Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents: 2335
diff changeset
331 if (genesis->expansion) {
83f5529086c5 Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents: 2335
diff changeset
332 segacd_context *cd = genesis->expansion;
83f5529086c5 Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents: 2335
diff changeset
333 cd->has_vdp_dma_value = 0;
83f5529086c5 Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents: 2335
diff changeset
334 }
83f5529086c5 Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents: 2335
diff changeset
335 }
83f5529086c5 Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents: 2335
diff changeset
336
83f5529086c5 Make bogus word RAM read more appropriately bogus
Michael Pavone <pavone@retrodev.com>
parents: 2335
diff changeset
337
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
338 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
339 {
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
340 genesis_context *genesis = (genesis_context *)system;
2500
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
341 #ifdef NEW_CORE
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
342 return genesis->m68k->prefetch;
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
343 #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
344 return read_dma_value(genesis->m68k->last_prefetch_address/2);
2500
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
345 #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
346 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
347
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
348 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
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 //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
351 genesis_context *gen = context->system;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
352 if (context->sync_cycle - context->cycles > gen->max_cycles) {
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
353 context->sync_cycle = context->cycles + gen->max_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
354 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
356 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
357 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
358 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
359 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
360 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
361 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
362 }
2025
e7a516f08cec Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents: 2021
diff changeset
363 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
364 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
365 if (next_hint != CYCLE_NEVER) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
366 next_hint = next_hint < context->cycles ? context->cycles : next_hint;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
368 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
369 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
370
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
371 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
372 }
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
373 if (mask < 2 && (v_context->regs[REG_MODE_3] & BIT_EINT_EN) && gen->header.type == SYSTEM_GENESIS) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
374 uint32_t next_eint_port0 = io_next_interrupt(gen->io.ports, context->cycles);
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
375 uint32_t next_eint_port1 = io_next_interrupt(gen->io.ports + 1, context->cycles);
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
376 uint32_t next_eint_port2 = io_next_interrupt(gen->io.ports + 2, context->cycles);
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
377 uint32_t next_eint = next_eint_port0 < next_eint_port1
2025
e7a516f08cec Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents: 2021
diff changeset
378 ? (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
379 : (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
380 if (next_eint != CYCLE_NEVER) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
381 next_eint = next_eint < context->cycles ? context->cycles : next_eint;
2025
e7a516f08cec Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents: 2021
diff changeset
382 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
383 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
384 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
385 }
e7a516f08cec Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents: 2021
diff changeset
386 }
e7a516f08cec Implement serial IO, a generic serial device type and external interrupts
Michael Pavone <pavone@retrodev.com>
parents: 2021
diff changeset
387 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 }
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
390 if (context->int_cycle > context->cycles && context->int_pending == INT_PENDING_SR_CHANGE) {
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
391 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
392 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 /*if (context->int_cycle != old_int_cycle) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
394 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->cycles, v_context->frame, v_context->vcounter, v_context->hslot, context->status & 0x7, v_context->hint_counter);
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
396 }*/
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
397
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
398 if (context->status & M68K_STATUS_TRACE || context->trace_pending) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
399 context->target_cycle = context->cycles;
1303
208803173ebc Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents: 1291
diff changeset
400 return;
208803173ebc Implemented M68K trace mode. Some edge cases/SR update paths still need work
Michael Pavone <pavone@retrodev.com>
parents: 1291
diff changeset
401 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
402
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
403 context->target_cycle = context->int_cycle < context->sync_cycle ? context->int_cycle : context->sync_cycle;
2424
767ec72acca7 Avoid conflicts between watchpoints and normal debugger entry
Michael Pavone <pavone@retrodev.com>
parents: 2391
diff changeset
404 if (context->should_return || gen->header.enter_debugger || context->wp_hit) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
405 context->target_cycle = context->cycles;
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
406 } else if (context->target_cycle < 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
407 //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
408 //This can cause issues with the implementation of STOP though
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
409 context->target_cycle = 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
410 }
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
411 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
412 //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
413 //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
414 //to prevent this code forces some extra synchronization in the period immediately before an interrupt
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
415 if ((context->target_cycle - context->cycles) > gen->int_latency_prev1) {
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
416 context->target_cycle = context->sync_cycle = context->int_cycle - gen->int_latency_prev1;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
417 } else if ((context->target_cycle - context->cycles) > gen->int_latency_prev2) {
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
418 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
419 } else {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
420 context->target_cycle = context->sync_cycle = context->cycles;
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
421 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
422
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
423 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
424 /*printf("Cyc: %d, Trgt: %d, Int Cyc: %d, Int: %d, Mask: %X, V: %d, H: %d, HICount: %d, HReg: %d, Line: %d\n",
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
425 context->cycles, context->target_cycle, context->int_cycle, context->int_num, (context->status & 0x7),
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
426 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
427 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
428
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
429 //#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
430 #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
431 #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
432 #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
433 #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
434 #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
435 #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
436 #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
437
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
438 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
439 {
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
440 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
441 #ifdef NEW_CORE
33ec5df77fac Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents: 1752
diff changeset
442 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
443 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
444 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
445 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
446 #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
447 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
448 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
449 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
450 #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
451 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
452
2184
408fb8a7e990 Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2179
diff changeset
453 static void sync_z80(genesis_context *gen, uint32_t mclks)
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
454 {
2184
408fb8a7e990 Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2179
diff changeset
455 z80_context *z_context = gen->z80;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
456 #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
457 if (z80_enabled) {
1753
33ec5df77fac Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents: 1752
diff changeset
458 #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
459 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
460 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
461 }
1753
33ec5df77fac Integration of new Z80 core is sort of working now
Michael Pavone <pavone@retrodev.com>
parents: 1752
diff changeset
462 #endif
2184
408fb8a7e990 Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2179
diff changeset
463 if (gen->enter_z80_debugger && !z_context->reset && !z_context->busack) {
408fb8a7e990 Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2179
diff changeset
464 while (!z_context->pc) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
465 z80_run(z_context, z_context->Z80_CYCLE + 4);
2184
408fb8a7e990 Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2179
diff changeset
466 }
408fb8a7e990 Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2179
diff changeset
467 gen->enter_z80_debugger = 0;
2302
0343f0d5add0 Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents: 2286
diff changeset
468 #ifndef IS_LIB
2184
408fb8a7e990 Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2179
diff changeset
469 zdebugger(z_context, z_context->pc);
2302
0343f0d5add0 Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents: 2286
diff changeset
470 #endif
2184
408fb8a7e990 Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2179
diff changeset
471 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
472 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
473 } 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
474 #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
475 {
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
476 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
477 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
478 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
479
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
480 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
481 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 //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
483 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
484 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
485 //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
486 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
487 //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
488 ym_run(gen->ym, cur_target);
2080
bafb757e1cd2 Implement CD audio
Michael Pavone <pavone@retrodev.com>
parents: 2054
diff changeset
489 if (gen->expansion) {
bafb757e1cd2 Implement CD audio
Michael Pavone <pavone@retrodev.com>
parents: 2054
diff changeset
490 scd_run(gen->expansion, gen_cycle_to_scd(cur_target, gen));
bafb757e1cd2 Implement CD audio
Michael Pavone <pavone@retrodev.com>
parents: 2054
diff changeset
491 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
492 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
493 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
494 ym_run(gen->ym, target);
2080
bafb757e1cd2 Implement CD audio
Michael Pavone <pavone@retrodev.com>
parents: 2054
diff changeset
495 if (gen->expansion) {
bafb757e1cd2 Implement CD audio
Michael Pavone <pavone@retrodev.com>
parents: 2054
diff changeset
496 scd_run(gen->expansion, gen_cycle_to_scd(target, gen));
bafb757e1cd2 Implement CD audio
Michael Pavone <pavone@retrodev.com>
parents: 2054
diff changeset
497 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
498
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
499 //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
500 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
501
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
502 #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
503 #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
504
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
505 void gen_update_refresh(m68k_context *context)
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
506 {
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
507 uint32_t interval = MCLKS_PER_68K * REFRESH_INTERVAL;
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
508 genesis_context *gen = context->system;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
509 gen->refresh_counter += context->cycles - gen->last_sync_cycle;
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
510 gen->last_sync_cycle = context->cycles;
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
511 context->cycles += REFRESH_DELAY * MCLKS_PER_68K * (gen->refresh_counter / interval);
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
512 gen->refresh_counter = gen->refresh_counter % interval;
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
513 }
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
514
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
515 void gen_update_refresh_free_access(m68k_context *context)
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
516 {
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
517 genesis_context *gen = context->system;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
518 uint32_t before = context->cycles - 4*MCLKS_PER_68K;
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
519 if (before < gen->last_sync_cycle) {
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
520 return;
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
521 }
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
522 //Add refresh delays for any accesses that happened beofre the current one
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
523 gen->refresh_counter += before - gen->last_sync_cycle;
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
524 uint32_t interval = MCLKS_PER_68K * REFRESH_INTERVAL;
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
525 uint32_t delay = REFRESH_DELAY * MCLKS_PER_68K * (gen->refresh_counter / interval);
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
526 if (delay) {
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
527 //To avoid the extra cycles being absorbed in the refresh free update below, we need to update again
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
528 gen->refresh_counter = gen->refresh_counter % interval;
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
529 gen->refresh_counter += delay;
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
530 delay += REFRESH_DELAY * MCLKS_PER_68K * (gen->refresh_counter / interval);
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
531 context->cycles += delay;
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
532 }
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
533 gen->last_sync_cycle = context->cycles;
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
534 //advance refresh counter for the current access, but don't generate delays
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
535 gen->refresh_counter += 4*MCLKS_PER_68K;
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
536 gen->refresh_counter = gen->refresh_counter % interval;
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
537 }
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
538
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
539 void gen_update_refresh_no_wait(m68k_context *context)
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
540 {
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
541 uint32_t interval = MCLKS_PER_68K * REFRESH_INTERVAL;
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
542 genesis_context *gen = context->system;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
543 gen->refresh_counter += context->cycles - gen->last_sync_cycle;
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
544 gen->last_sync_cycle = context->cycles;
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
545 gen->refresh_counter = gen->refresh_counter % interval;
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
546 }
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
547
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
548 #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
549 #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
550 #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
551
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
552 static m68k_context *sync_components(m68k_context * context, uint32_t address)
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
553 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
555 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
556 z80_context * z_context = gen->z80;
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
557 if (gen->bus_busy) {
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
558 gen_update_refresh_no_wait(context);
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
559 } else {
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
560 gen_update_refresh(context);
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
561 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
563 uint32_t mclks = context->cycles;
2184
408fb8a7e990 Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2179
diff changeset
564 sync_z80(gen, mclks);
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
565 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
566 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
567 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
568 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
569 io_run(gen->io.ports + 2, mclks);
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
570 if (gen->expansion) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
571 scd_run(gen->expansion, gen_cycle_to_scd(mclks, gen));
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
572 }
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
573 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
574 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
575 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
576 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
577 }
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
578 if (v_context->frame != gen->last_frame) {
2302
0343f0d5add0 Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents: 2286
diff changeset
579 #ifndef IS_LIB
2243
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
580 if (gen->ym->scope) {
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
581 scope_render(gen->ym->scope);
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
582 }
2302
0343f0d5add0 Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents: 2286
diff changeset
583 #endif
1971
80920c21bb52 Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
Michael Pavone <pavone@retrodev.com>
parents: 1954
diff changeset
584 //printf("reached frame end %d | MCLK Cycles: %d, Target: %d, VDP cycles: %d, vcounter: %d, hslot: %d\n", gen->last_frame, mclks, gen->frame_end, v_context->cycles, v_context->vcounter, v_context->hslot);
2179
9a8dd4ba2753 Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
585 uint32_t elapsed = v_context->frame - gen->last_frame;
1971
80920c21bb52 Add an event log soft flush and call it twice per frame in between hard flushes to netplay latency when there are insufficient hardware updates to flush packets in the middle of a frame
Michael Pavone <pavone@retrodev.com>
parents: 1954
diff changeset
586 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
587 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
588 gen->last_flush_cycle = mclks;
2179
9a8dd4ba2753 Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
589 if (gen->header.enter_debugger_frames) {
9a8dd4ba2753 Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
590 if (elapsed >= gen->header.enter_debugger_frames) {
9a8dd4ba2753 Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
591 gen->header.enter_debugger_frames = 0;
9a8dd4ba2753 Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
592 gen->header.enter_debugger = 1;
9a8dd4ba2753 Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
593 } else {
9a8dd4ba2753 Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
594 gen->header.enter_debugger_frames -= elapsed;
9a8dd4ba2753 Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
595 }
9a8dd4ba2753 Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
596 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 if(exit_after){
2179
9a8dd4ba2753 Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
599 if (elapsed >= exit_after) {
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
600 exit(0);
2179
9a8dd4ba2753 Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
601 } else {
9a8dd4ba2753 Implement frame advance debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2164
diff changeset
602 exit_after -= elapsed;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
603 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 }
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
605 if (context->cycles > MAX_NO_ADJUST) {
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
606 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
607 vdp_adjust_cycles(v_context, deduction);
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
608 io_adjust_cycles(gen->io.ports, context->cycles, deduction);
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
609 io_adjust_cycles(gen->io.ports+1, context->cycles, deduction);
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
610 io_adjust_cycles(gen->io.ports+2, context->cycles, deduction);
1610
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1595
diff changeset
611 if (gen->mapper_type == MAPPER_JCART) {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1595
diff changeset
612 jcart_adjust_cycles(gen, deduction);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1595
diff changeset
613 }
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
614 context->cycles -= deduction;
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
615 z80_adjust_cycles(z_context, deduction);
1902
32a3aa7b4a45 Fix YM2612 busy flag timing
Michael Pavone <pavone@retrodev.com>
parents: 1901
diff changeset
616 ym_adjust_cycles(gen->ym, deduction);
1909
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
617 if (gen->ym->vgm) {
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
618 vgm_adjust_cycles(gen->ym->vgm, deduction);
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
619 }
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
620 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
621 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
622 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
623 }
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
624 event_cycle_adjust(mclks, deduction);
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
625 if (gen->expansion) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
626 scd_adjust_cycle(gen->expansion, deduction);
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
627 }
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
628 gen->last_flush_cycle -= deduction;
2548
3fc8a1f2eb84 Fix regression in Super Hang-On
Michael Pavone <pavone@retrodev.com>
parents: 2524
diff changeset
629 gen->last_sync_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
630 }
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
631 } 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
632 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
633 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
634 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
636 context->sync_cycle = gen->frame_end;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
637 //printf("Set sync cycle to: %d @ %d, vcounter: %d, hslot: %d\n", context->sync_cycle, context->cycles, v_context->vcounter, v_context->hslot);
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1108
diff changeset
638 if (!address && (gen->header.enter_debugger || gen->header.save_state)) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
639 context->sync_cycle = context->cycles + 1;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
642 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
643 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
644 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 if (address) {
2424
767ec72acca7 Avoid conflicts between watchpoints and normal debugger entry
Michael Pavone <pavone@retrodev.com>
parents: 2391
diff changeset
646 if (gen->header.enter_debugger || context->wp_hit) {
767ec72acca7 Avoid conflicts between watchpoints and normal debugger entry
Michael Pavone <pavone@retrodev.com>
parents: 2391
diff changeset
647 if (!context->wp_hit) {
767ec72acca7 Avoid conflicts between watchpoints and normal debugger entry
Michael Pavone <pavone@retrodev.com>
parents: 2391
diff changeset
648 gen->header.enter_debugger = 0;
767ec72acca7 Avoid conflicts between watchpoints and normal debugger entry
Michael Pavone <pavone@retrodev.com>
parents: 2391
diff changeset
649 }
2302
0343f0d5add0 Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents: 2286
diff changeset
650 #ifndef IS_LIB
2033
894bf99a13f1 Make ui.enter_debuger respect which debuger is active
Michael Pavone <pavone@retrodev.com>
parents: 2025
diff changeset
651 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
652 debugger(context, address);
894bf99a13f1 Make ui.enter_debuger respect which debuger is active
Michael Pavone <pavone@retrodev.com>
parents: 2025
diff changeset
653 } else {
894bf99a13f1 Make ui.enter_debuger respect which debuger is active
Michael Pavone <pavone@retrodev.com>
parents: 2025
diff changeset
654 gdb_debug_enter(context, address);
894bf99a13f1 Make ui.enter_debuger respect which debuger is active
Michael Pavone <pavone@retrodev.com>
parents: 2025
diff changeset
655 }
2302
0343f0d5add0 Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents: 2286
diff changeset
656 #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
657 }
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
658 #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
659 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
660 #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
661 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
662 #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
663 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
664 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
665 #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
666 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
667 //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
668 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
669 {
2184
408fb8a7e990 Implement argumentless variant of z80 debugger command
Michael Pavone <pavone@retrodev.com>
parents: 2179
diff changeset
670 sync_z80(gen, z_context->current_cycle + MCLKS_PER_Z80);
1440
7d4483944d4d Allow actually saving a save state in more Z80 states. Save busreq/reset state in bus arbiter section for "native" save states
Michael Pavone <pavone@retrodev.com>
parents: 1433
diff changeset
671 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 }
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
673 #endif
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
674 char *save_path = slot >= SERIALIZE_SLOT ? NULL : get_slot_name(&gen->header, slot, use_native_states ? "state" : "gst");
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
675 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
676 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
677 init_serialize(&state);
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
678 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
679 if (slot == SERIALIZE_SLOT) {
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
680 gen->serialize_tmp = state.data;
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
681 gen->serialize_size = state.size;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
682 context->sync_cycle = context->cycles;
1690
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
683 context->should_return = 1;
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
684 } else if (slot == EVENTLOG_SLOT) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
685 event_state(context->cycles, &state);
1690
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
686 } else {
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
687 save_to_file(&state, save_path);
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
688 free(state.data);
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
689 }
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
690 } 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
691 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
692 }
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
693 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
694 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
695 }
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
696 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
697 } else if(gen->header.save_state) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
698 context->sync_cycle = context->cycles + 1;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
699 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
700 }
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
701 return context;
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
702 }
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
703
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
704 static void sync_sound_pico(genesis_context * gen, uint32_t target)
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
705 {
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
706 while (target > gen->psg->cycles && target - gen->psg->cycles > MAX_SOUND_CYCLES)
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
707 {
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
708 uint32_t cur_target = gen->psg->cycles + MAX_SOUND_CYCLES;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
709 psg_run(gen->psg, cur_target);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
710 pico_pcm_run(gen->adpcm, cur_target);
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
711 if (gen->ymz) {
2558
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
712 //FIXME: These have a separate crystal
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
713 ymz263b_run(gen->ymz, cur_target);
2558
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
714 ymf262_run(gen->opl, cur_target);
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
715 }
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
716 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
717 psg_run(gen->psg, target);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
718 pico_pcm_run(gen->adpcm, target);
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
719 if (gen->ymz) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
720 ymz263b_run(gen->ymz, target);
2558
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
721 ymf262_run(gen->opl, target);
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
722 }
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
723 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
724
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
725 static void adjust_int_cycle_pico(m68k_context *context, vdp_context *v_context)
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
726 {
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
727 genesis_context *gen = context->system;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
728 if (context->sync_cycle - context->cycles > gen->max_cycles) {
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
729 context->sync_cycle = context->cycles + gen->max_cycles;
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
730 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
731 context->int_cycle = CYCLE_NEVER;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
732 uint8_t mask = context->status & 0x7;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
733 if (mask < 6) {
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
734 uint32_t next_vint = vdp_next_vint(v_context);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
735 if (next_vint != CYCLE_NEVER) {
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
736 context->int_cycle = next_vint;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
737 context->int_num = 6;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
738 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
739 if (mask < 5) {
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
740 uint32_t next_hint = vdp_next_hint(v_context);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
741 if (next_hint != CYCLE_NEVER) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
742 next_hint = next_hint < context->cycles ? context->cycles : next_hint;
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
743 if (next_hint < context->int_cycle) {
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
744 context->int_cycle = next_hint;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
745 context->int_num = 5;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
746
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
747 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
748 }
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
749 if (mask < 4) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
750 if (v_context->regs[REG_MODE_3] & BIT_EINT_EN) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
751 uint32_t next_eint_port0 = io_next_interrupt(gen->io.ports, context->cycles);
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
752 uint32_t next_eint_port1 = io_next_interrupt(gen->io.ports + 1, context->cycles);
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
753 uint32_t next_eint_port2 = io_next_interrupt(gen->io.ports + 2, context->cycles);
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
754 uint32_t next_eint = next_eint_port0 < next_eint_port1
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
755 ? (next_eint_port0 < next_eint_port2 ? next_eint_port0 : next_eint_port2)
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
756 : (next_eint_port1 < next_eint_port2 ? next_eint_port1 : next_eint_port2);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
757 if (next_eint != CYCLE_NEVER) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
758 next_eint = next_eint < context->cycles ? context->cycles : next_eint;
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
759 if (next_eint < context->int_cycle) {
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
760 context->int_cycle = next_eint;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
761 context->int_num = 2;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
762 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
763 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
764 }
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
765 if (mask < 3) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
766 uint32_t next_pcm_int = pico_pcm_next_int(gen->adpcm);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
767 if (next_pcm_int != CYCLE_NEVER && next_pcm_int < context->int_cycle) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
768 context->int_cycle = next_pcm_int;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
769 context->int_num = 3;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
770 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
771
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
772 if (mask < 2 && gen->ymz) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
773 uint32_t ymz_int = ymz263b_next_int(gen->ymz);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
774 if (ymz_int < context->int_cycle) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
775 context->int_cycle = ymz_int;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
776 context->int_num = 2;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
777 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
778 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
779 }
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
780 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
781 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
782 }
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
783 if (context->int_cycle > context->cycles && context->int_pending == INT_PENDING_SR_CHANGE) {
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
784 context->int_pending = INT_PENDING_NONE;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
785 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
786 /*if (context->int_cycle != old_int_cycle) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
787 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->cycles, v_context->frame, v_context->vcounter, v_context->hslot, context->status & 0x7, v_context->hint_counter);
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
788 old_int_cycle = context->int_cycle;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
789 }*/
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
790
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
791 if (context->status & M68K_STATUS_TRACE || context->trace_pending) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
792 context->target_cycle = context->cycles;
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
793 return;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
794 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
795
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
796 context->target_cycle = context->int_cycle < context->sync_cycle ? context->int_cycle : context->sync_cycle;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
797 if (context->should_return || gen->header.enter_debugger || context->wp_hit) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
798 context->target_cycle = context->cycles;
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
799 } else if (context->target_cycle < context->cycles) {
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
800 //Changes to SR can result in an interrupt cycle that's in the past
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
801 //This can cause issues with the implementation of STOP though
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
802 context->target_cycle = context->cycles;
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
803 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
804 if (context->target_cycle == context->int_cycle) {
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
805 //Currently delays from Z80 access and refresh are applied only when we sync
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
806 //this can cause extra latency when it comes to interrupts
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
807 //to prevent this code forces some extra synchronization in the period immediately before an interrupt
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
808 if ((context->target_cycle - context->cycles) > gen->int_latency_prev1) {
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
809 context->target_cycle = context->sync_cycle = context->int_cycle - gen->int_latency_prev1;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
810 } else if ((context->target_cycle - context->cycles) > gen->int_latency_prev2) {
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
811 context->target_cycle = context->sync_cycle = context->int_cycle - gen->int_latency_prev2;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
812 } else {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
813 context->target_cycle = context->sync_cycle = context->cycles;
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
814 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
815
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
816 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
817 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
818
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
819 static m68k_context* sync_components_pico(m68k_context * context, uint32_t address)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
820 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
821 genesis_context * gen = context->system;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
822 vdp_context * v_context = gen->vdp;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
823 if (gen->bus_busy) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
824 gen_update_refresh_no_wait(context);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
825 } else {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
826 gen_update_refresh(context);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
827 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
828
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
829 uint32_t mclks = context->cycles;
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
830 sync_sound_pico(gen, mclks);
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
831 vdp_run_context(v_context, mclks);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
832 if (mclks >= gen->reset_cycle) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
833 gen->reset_requested = 1;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
834 context->should_return = 1;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
835 gen->reset_cycle = CYCLE_NEVER;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
836 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
837 if (v_context->frame != gen->last_frame) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
838 #ifndef IS_LIB
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
839 if (gen->psg->scope) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
840 scope_render(gen->psg->scope);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
841 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
842 #endif
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
843 //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);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
844 uint32_t elapsed = v_context->frame - gen->last_frame;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
845 gen->last_frame = v_context->frame;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
846 event_flush(mclks);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
847 gen->last_flush_cycle = mclks;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
848 if (gen->header.enter_debugger_frames) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
849 if (elapsed >= gen->header.enter_debugger_frames) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
850 gen->header.enter_debugger_frames = 0;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
851 gen->header.enter_debugger = 1;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
852 } else {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
853 gen->header.enter_debugger_frames -= elapsed;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
854 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
855 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
856
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
857 if(exit_after){
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
858 if (elapsed >= exit_after) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
859 exit(0);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
860 } else {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
861 exit_after -= elapsed;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
862 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
863 }
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
864 if (context->cycles > MAX_NO_ADJUST) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
865 uint32_t deduction = mclks - ADJUST_BUFFER;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
866 vdp_adjust_cycles(v_context, deduction);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
867 if (gen->mapper_type == MAPPER_JCART) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
868 jcart_adjust_cycles(gen, deduction);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
869 }
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
870 context->cycles -= deduction;
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
871 if (gen->psg->vgm) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
872 vgm_adjust_cycles(gen->psg->vgm, deduction);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
873 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
874 gen->psg->cycles -= deduction;
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
875 gen->adpcm->cycle -= deduction;
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
876 if (gen->ymz) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
877 gen->ymz->cycle -= deduction;
2558
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
878 ymf262_adjust_cycles(gen->opl, deduction);
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
879 }
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
880 if (gen->reset_cycle != CYCLE_NEVER) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
881 gen->reset_cycle -= deduction;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
882 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
883 event_cycle_adjust(mclks, deduction);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
884 if (gen->expansion) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
885 scd_adjust_cycle(gen->expansion, deduction);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
886 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
887 gen->last_flush_cycle -= deduction;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
888 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
889 } else if (mclks - gen->last_flush_cycle > gen->soft_flush_cycles) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
890 event_soft_flush(mclks);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
891 gen->last_flush_cycle = mclks;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
892 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
893 gen->frame_end = vdp_cycles_to_frame_end(v_context);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
894 context->sync_cycle = gen->frame_end;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
895 //printf("Set sync cycle to: %d @ %d, vcounter: %d, hslot: %d\n", context->sync_cycle, context->cycles, v_context->vcounter, v_context->hslot);
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
896 if (!address && (gen->header.enter_debugger || gen->header.save_state)) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
897 context->sync_cycle = context->cycles + 1;
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
898 }
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
899 adjust_int_cycle_pico(context, v_context);
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
900 if (gen->reset_cycle < context->target_cycle) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
901 context->target_cycle = gen->reset_cycle;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
902 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
903 if (address) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
904 if (gen->header.enter_debugger || context->wp_hit) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
905 if (!context->wp_hit) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
906 gen->header.enter_debugger = 0;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
907 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
908 #ifndef IS_LIB
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
909 if (gen->header.debugger_type == DEBUGGER_NATIVE) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
910 debugger(context, address);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
911 } else {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
912 gdb_debug_enter(context, address);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
913 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
914 #endif
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
915 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
916 if (gen->header.save_state) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
917 uint8_t slot = gen->header.save_state - 1;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
918 gen->header.save_state = 0;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
919 char *save_path = slot >= SERIALIZE_SLOT ? NULL : get_slot_name(&gen->header, slot, use_native_states ? "state" : "gst");
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
920 if (use_native_states || slot >= SERIALIZE_SLOT) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
921 serialize_buffer state;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
922 init_serialize(&state);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
923 genesis_serialize(gen, &state, address, slot != EVENTLOG_SLOT);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
924 if (slot == SERIALIZE_SLOT) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
925 gen->serialize_tmp = state.data;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
926 gen->serialize_size = state.size;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
927 context->sync_cycle = context->cycles;
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
928 context->should_return = 1;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
929 } else if (slot == EVENTLOG_SLOT) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
930 event_state(context->cycles, &state);
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
931 } else {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
932 save_to_file(&state, save_path);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
933 free(state.data);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
934 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
935 } else {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
936 save_gst(gen, save_path, address);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
937 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
938 if (slot != SERIALIZE_SLOT) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
939 debug_message("Saved state to %s\n", save_path);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
940 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
941 free(save_path);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
942 } else if(gen->header.save_state) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
943 context->sync_cycle = context->cycles + 1;
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
944 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
945 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
946 return context;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
947 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
948
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
949 static m68k_context *int_ack(m68k_context *context)
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
950 {
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
951 genesis_context * gen = context->system;
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
952 if ((gen->header.type != SYSTEM_PICO && gen->header.type != SYSTEM_COPERA) || context->int_num > 3) {
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
953 vdp_context * v_context = gen->vdp;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
954 //printf("acknowledging %d @ %d:%d, vcounter: %d, hslot: %d\n", context->int_ack, context->cycles, v_context->cycles, v_context->vcounter, v_context->hslot);
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
955 vdp_run_context(v_context, context->cycles);
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
956 vdp_int_ack(v_context);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
957 }
2354
a773b8f09292 Remove old refresh hack that is causing VDPFifoTesting to have a failed test
Michael Pavone <pavone@retrodev.com>
parents: 2350
diff changeset
958
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
959 //the Genesis responds to these exclusively with !VPA which means its a slow
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
960 //6800 operation. documentation says these can take between 10 and 19 cycles.
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
961 //actual results measurements seem to suggest it's actually between 9 and 18
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
962 //Base 68K core has added 4 cycles for a normal int ack cycle already
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
963 //We add 5 + the current cycle count (in 68K cycles) mod 10 to simulate the
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
964 //additional variable delay from the use of the 6800 cycle
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
965 uint32_t cycle_count = context->cycles / context->opts->gen.clock_divider;
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
966 context->cycles += 5 + (cycle_count % 10);
2354
a773b8f09292 Remove old refresh hack that is causing VDPFifoTesting to have a failed test
Michael Pavone <pavone@retrodev.com>
parents: 2350
diff changeset
967
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
969 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
970
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
971 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
972 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
973 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
974 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
975 }
2037
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
976 genesis_context * gen = context->system;
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
977 if (!gen->vdp_unlocked) {
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
978 fatal_error("machine freeze due to VDP write to %X without TMSS unlock\n", 0xC00000 | vdp_port);
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
979 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
980 vdp_port &= 0x1F;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
981 //printf("vdp_port write: %X, value: %X, cycle: %d\n", vdp_port, value, context->cycles);
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
982
1372
d78ef6f4fba2 Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents: 1371
diff changeset
983 //do refresh check here so we can avoid adding a penalty for a refresh that happens during a VDP access
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
984 gen_update_refresh_free_access(context);
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
985
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
986 if (gen->header.type == SYSTEM_PICO || gen->header.type == SYSTEM_COPERA) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
987 sync_components_pico(context, 0);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
988 } else {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
989 sync_components(context, 0);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
990 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
991 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
992 uint32_t before_cycle = v_context->cycles;
2391
664c3e749428 Restore reset of refresh counter after DMA since its removal caused some regressions
Michael Pavone <pavone@retrodev.com>
parents: 2384
diff changeset
993 uint8_t did_dma = 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
994 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
995 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
996 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
997 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
998 while(v_context->flags & FLAG_DMA_RUN) {
2391
664c3e749428 Restore reset of refresh counter after DMA since its removal caused some regressions
Michael Pavone <pavone@retrodev.com>
parents: 2384
diff changeset
999 did_dma = 1;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1000 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
1001 if (v_context->cycles >= gen->frame_end) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1002 uint32_t cycle_diff = v_context->cycles - 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
1003 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
1004 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
1005 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
1006 }
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1007 context->cycles += m68k_cycle_diff;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1008 gen->bus_busy = 1;
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1009 if (gen->header.type == SYSTEM_PICO || gen->header.type == SYSTEM_COPERA) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1010 sync_components_pico(context, 0);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1011 } else {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1012 sync_components(context, 0);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1013 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
1015 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1016 }
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1017 //context->cycles = 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
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 } else if(vdp_port < 8) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1020 vdp_run_context_full(v_context, context->cycles);
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
1021 before_cycle = v_context->cycles;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1022 blocked = vdp_control_port_write(v_context, value, 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
1023 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
1024 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
1025 while(v_context->flags & FLAG_DMA_RUN) {
2391
664c3e749428 Restore reset of refresh counter after DMA since its removal caused some regressions
Michael Pavone <pavone@retrodev.com>
parents: 2384
diff changeset
1026 did_dma = 1;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
1028 if (v_context->cycles >= gen->frame_end) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1029 uint32_t cycle_diff = v_context->cycles - 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
1030 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
1031 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
1032 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
1033 }
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1034 context->cycles += m68k_cycle_diff;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 gen->bus_busy = 1;
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1036 if (gen->header.type == SYSTEM_PICO || gen->header.type == SYSTEM_COPERA) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1037 sync_components_pico(context, 0);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1038 } else {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1039 sync_components(context, 0);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1040 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
1042 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
1044
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 if (blocked < 0) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1046 blocked = vdp_control_port_write(v_context, value, 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
1047 } 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
1048 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
1049 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1050 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1051 } 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 context->sync_cycle = gen->frame_end = vdp_cycles_to_frame_end(v_context);
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1053 //printf("Set sync cycle to: %d @ %d, vcounter: %d, hslot: %d\n", context->sync_cycle, context->cycles, v_context->vcounter, v_context->hslot);
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1054 if (gen->header.type == SYSTEM_PICO || gen->header.type == SYSTEM_COPERA) {
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1055 adjust_int_cycle_pico(context, v_context);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1056 } else {
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1057 adjust_int_cycle(context, v_context);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1058 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1059 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1060 } 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
1061 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
1062 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 if (v_context->cycles != before_cycle) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1064 //printf("68K paused for %d (%d) cycles at cycle %d (%d) for write\n", v_context->cycles - context->cycles, v_context->cycles - before_cycle, context->cycles, before_cycle);
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1065 uint32_t cycle_diff = v_context->cycles - 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
1066 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
1067 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
1068 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
1069 }
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1070 context->cycles += m68k_cycle_diff;
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1071 if (gen->header.type == SYSTEM_GENESIS) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1072 //Lock the Z80 out of the bus until the VDP access is complete
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1073 gen->bus_busy = 1;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1074 sync_z80(gen, v_context->cycles);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1075 gen->bus_busy = 0;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1076 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } 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
1079 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
1080 } 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
1081 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
1082 }
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
1083
2391
664c3e749428 Restore reset of refresh counter after DMA since its removal caused some regressions
Michael Pavone <pavone@retrodev.com>
parents: 2384
diff changeset
1084 if (did_dma) {
664c3e749428 Restore reset of refresh counter after DMA since its removal caused some regressions
Michael Pavone <pavone@retrodev.com>
parents: 2384
diff changeset
1085 gen->refresh_counter = 0;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1086 gen->last_sync_cycle = context->cycles;
2391
664c3e749428 Restore reset of refresh counter after DMA since its removal caused some regressions
Michael Pavone <pavone@retrodev.com>
parents: 2384
diff changeset
1087 } else {
664c3e749428 Restore reset of refresh counter after DMA since its removal caused some regressions
Michael Pavone <pavone@retrodev.com>
parents: 2384
diff changeset
1088 //refresh may have happened while we were waiting on the VDP,
664c3e749428 Restore reset of refresh counter after DMA since its removal caused some regressions
Michael Pavone <pavone@retrodev.com>
parents: 2384
diff changeset
1089 //so advance refresh_counter but don't add any delays
664c3e749428 Restore reset of refresh counter after DMA since its removal caused some regressions
Michael Pavone <pavone@retrodev.com>
parents: 2384
diff changeset
1090 gen_update_refresh_no_wait(context);
664c3e749428 Restore reset of refresh counter after DMA since its removal caused some regressions
Michael Pavone <pavone@retrodev.com>
parents: 2384
diff changeset
1091 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
1093 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1095 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
1096 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
1098 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1100 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
1101 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1102 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
1103 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
1104 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
1105 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
1106 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
1107 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
1109 //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
1110 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
1111 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
1112 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
1113 } 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
1114 vdp_run_context_full(gen->vdp, context->Z80_CYCLE);
2227
eaaf28af3c94 Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents: 2194
diff changeset
1115 vdp_control_port_write(gen->vdp, value << 8 | value, context->Z80_CYCLE);
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1116 } 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
1117 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
1118 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } 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
1120 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
1121 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
1122 } else {
2327
9dd27530c570 Fix Z80 access to VDP debug register
Michael Pavone <pavone@retrodev.com>
parents: 2302
diff changeset
1123 vdp_test_port_write(gen->vdp, value << 8 | value);
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
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 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
1126 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1128 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
1129 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
1131 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
1132 }
2037
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
1133 genesis_context *gen = context->system;
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
1134 if (!gen->vdp_unlocked) {
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
1135 fatal_error("machine freeze due to VDP read from %X without TMSS unlock\n", 0xC00000 | vdp_port);
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
1136 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1137 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
1138 uint16_t value;
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
1139
1372
d78ef6f4fba2 Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents: 1371
diff changeset
1140 //do refresh check here so we can avoid adding a penalty for a refresh that happens during a VDP access
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
1141 gen_update_refresh_free_access(context);
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
1142
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1143 if (gen->header.type == SYSTEM_PICO || gen->header.type == SYSTEM_COPERA) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1144 sync_components_pico(context, 0);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1145 } else {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1146 sync_components(context, 0);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1147 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1148 vdp_context * v_context = gen->vdp;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1149 uint32_t before_cycle = 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
1150 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
1151 if (vdp_port < 4) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1152 value = vdp_data_port_read(v_context, &context->cycles, MCLKS_PER_68K);
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1153 } 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
1154 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
1155 } 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
1156 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
1157 //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
1158 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1159 } 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
1160 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
1161 } else {
1869
dc94354eab66 Fix accuracy bugs used by Novedicus to detect BlastEm/Exodus
Michael Pavone <pavone@retrodev.com>
parents: 1849
diff changeset
1162 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
1163 }
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1164 if (context->cycles != before_cycle) {
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1165 //printf("68K paused for %d (%d) cycles at cycle %d (%d) for read\n", v_context->cycles - context->cycles, v_context->cycles - before_cycle, context->cycles, before_cycle);
2021
270a4c875e0a Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents: 2012
diff changeset
1166 //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
1167 genesis_context *gen = context->system;
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1168 if (gen->header.type == SYSTEM_GENESIS) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1169 gen->bus_busy = 1;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1170 sync_z80(gen, context->cycles);
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1171 gen->bus_busy = 0;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1172 }
2021
270a4c875e0a Backed out changeset 96971b673f51
Michael Pavone <pavone@retrodev.com>
parents: 2012
diff changeset
1173 }
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
1174
1372
d78ef6f4fba2 Attempt at improving refresh emulation
Michael Pavone <pavone@retrodev.com>
parents: 1371
diff changeset
1175 //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
1176 //so advance refresh_counter but don't add any delays
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
1177 gen_update_refresh_no_wait(context);
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1178 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
1179 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1180
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1181 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
1182 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1183 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
1184 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
1185 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
1186 } 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
1187 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
1188 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1189 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1190
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1191 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
1192 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1193 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
1194 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
1195 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
1196 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1197 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
1198 //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
1199 //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
1200 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
1201 //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
1202 //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
1203 // Needs a new logic analyzer capture to get the actual delay on the 68K side
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1204 gen->m68k->cycles += 8 * MCLKS_PER_68K;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1205
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1206
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1207 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
1208 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
1209 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
1210 //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
1211 vdp_run_context(gen->vdp, context->Z80_CYCLE);
2227
eaaf28af3c94 Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents: 2194
diff changeset
1212 uint32_t before = context->Z80_CYCLE;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1213 if (vdp_port < 4) {
2227
eaaf28af3c94 Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents: 2194
diff changeset
1214 ret = vdp_data_port_read(gen->vdp, &context->Z80_CYCLE, MCLKS_PER_Z80);
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1215 } 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
1216 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
1217 } 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
1218 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
1219 }
2227
eaaf28af3c94 Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents: 2194
diff changeset
1220 if (context->Z80_CYCLE != before) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1221 gen->m68k->cycles += context->Z80_CYCLE - before;
2227
eaaf28af3c94 Implement VDP read latency and invalid write delays revealed by Ti_'s instruction timing ROM
Michael Pavone <pavone@retrodev.com>
parents: 2194
diff changeset
1222 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1223 } 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
1224 //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
1225 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
1226 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1227 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
1228 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1229
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1230 //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
1231 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
1232
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1233 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
1234 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 genesis_context * gen = context->system;
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
1236
2012
b05295c2ad04 Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents: 1998
diff changeset
1237 //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
1238 gen_update_refresh_free_access(context);
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
1239
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
1241 //Access to Z80 memory incurs a one 68K cycle wait state
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1242 context->cycles += MCLKS_PER_68K;
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1243 if (!z80_enabled || z80_get_busack(gen->z80, 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
1244 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
1245 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
1246 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
1247 #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
1248 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
1249 #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
1250 } else if (location < 0x6000) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1251 sync_sound(gen, 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
1252 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
1253 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
1254 } 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
1255 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
1256 } 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
1257 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
1258 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } 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
1260 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
1261 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
1262 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
1263 } 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
1264 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
1265 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1266 } 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
1267 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
1268 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1269 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 } 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
1271 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
1272 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
1273 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1274 case 0x1:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1275 io_data_write(gen->io.ports, value, 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
1276 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
1277 case 0x2:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1278 io_data_write(gen->io.ports+1, value, 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
1279 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
1280 case 0x3:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1281 io_data_write(gen->io.ports+2, value, 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
1282 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
1283 case 0x4:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1284 io_control_write(gen->io.ports, value, 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
1285 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
1286 case 0x5:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1287 io_control_write(gen->io.ports+1, value, 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
1288 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
1289 case 0x6:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1290 io_control_write(gen->io.ports+2, value, 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
1291 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
1292 case 0x7:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1293 io_tx_write(gen->io.ports, value, context->cycles);
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
1294 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
1295 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
1296 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
1297 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
1298 //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
1299 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
1300 case 0x9:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1301 io_sctrl_write(gen->io.ports, value, context->cycles);
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
1302 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
1303 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
1304 case 0xA:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1305 io_tx_write(gen->io.ports + 1, value, context->cycles);
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
1306 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
1307 case 0xC:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1308 io_sctrl_write(gen->io.ports + 1, value, context->cycles);
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
1309 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
1310 case 0xD:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1311 io_tx_write(gen->io.ports + 2, value, context->cycles);
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
1312 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
1313 case 0xF:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1314 io_sctrl_write(gen->io.ports + 2, value, context->cycles);
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
1315 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
1316 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1317 } 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
1318 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
1319 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
1320 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
1321 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
1322 if (z80_enabled) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1323 z80_assert_busreq(gen->z80, 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
1324 } 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
1325 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
1326 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1327 } 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
1328 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
1329 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
1330 #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
1331 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
1332 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
1333 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
1334 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
1335 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
1336 #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
1337 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1338 if (z80_enabled) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1339 z80_clear_busreq(gen->z80, 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
1340 } 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
1341 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
1342 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1343 }
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
1344 } else if (masked == 0x11200) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1345 sync_z80(gen, 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
1346 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
1347 if (z80_enabled) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1348 z80_clear_reset(gen->z80, 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
1349 } 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
1350 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
1351 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1352 } 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
1353 if (z80_enabled) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1354 z80_assert_reset(gen->z80, 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
1355 } 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
1356 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
1357 }
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
1358 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
1359 }
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
1360 } 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
1361 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
1362 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1363 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1364 }
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
1365
2012
b05295c2ad04 Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents: 1998
diff changeset
1366 //no refresh delays during IO access
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
1367 gen_update_refresh_no_wait(context);
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1368 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
1369 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1370
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1371 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
1372 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1373 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
1374 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
1375 } 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
1376 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
1377 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1378 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1379
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1380 static void* pico_io_write(uint32_t location, void *vcontext, uint8_t value)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1381 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1382 printf("Pico IO write.b %X - %X\n", location, value);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1383 return vcontext;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1384 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1385
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1386 static void* pico_io_write_w(uint32_t location, void *vcontext, uint16_t value)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1387 {
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1388 uint32_t port = location & 0xFE;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1389 m68k_context *context = vcontext;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1390 genesis_context *gen = context->system;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1391 if (port == 0x10) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1392 sync_sound_pico(gen, context->cycles);
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1393 pico_pcm_data_write(gen->adpcm, value);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1394 printf("PICO ADPCM Data: %04X\n", value);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1395 if (context->int_num == 3) {
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1396 adjust_int_cycle_pico(context, gen->vdp);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1397 }
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1398 } else if (port == 0x12) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1399 sync_sound_pico(gen, context->cycles);
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1400 printf("PICO ADPCM Control: %04X\n", value);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1401 pico_pcm_ctrl_write(gen->adpcm, value);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1402 adjust_int_cycle_pico(context, gen->vdp);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1403 } else {
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1404 return pico_io_write(location, vcontext, value);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1405 }
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1406 return vcontext;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1407 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1408
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1409 #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
1410 #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
1411 #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
1412 #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
1413 #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
1414 #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
1415
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1416 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
1417 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1418 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
1419 genesis_context *gen = context->system;
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
1420
2012
b05295c2ad04 Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents: 1998
diff changeset
1421 //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
1422 gen_update_refresh_free_access(context);
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
1423
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1424 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
1425 //Access to Z80 memory incurs a one 68K cycle wait state
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1426 context->cycles += MCLKS_PER_68K;
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1427 if (!z80_enabled || z80_get_busack(gen->z80, 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
1428 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
1429 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
1430 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
1431 } else if (location < 0x6000) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1432 sync_sound(gen, context->cycles);
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1433 value = ym_read_status(gen->ym, context->cycles, 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
1434 } 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
1435 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
1436 } 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
1437 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
1438 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
1439 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1440 } 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
1441 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
1442 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
1443 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1444 } 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
1445 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
1446 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
1447 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1448 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
1449 //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
1450 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
1451 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
1452 case 0x1:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1453 value = io_data_read(gen->io.ports, 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
1454 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
1455 case 0x2:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1456 value = io_data_read(gen->io.ports+1, 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
1457 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
1458 case 0x3:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1459 value = io_data_read(gen->io.ports+2, 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
1460 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
1461 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
1462 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
1463 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
1464 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
1465 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
1466 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
1467 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
1468 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
1469 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
1470 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
1471 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
1472 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
1473 case 0x8:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1474 value = io_rx_read(gen->io.ports, context->cycles);
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
1475 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
1476 case 0x9:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1477 value = io_sctrl_read(gen->io.ports, context->cycles);
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
1478 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
1479 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
1480 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
1481 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
1482 case 0xB:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1483 value = io_rx_read(gen->io.ports + 1, context->cycles);
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
1484 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
1485 case 0xC:
2524
25e40370e0e4 Fix some IO port serial mode bugs
Michael Pavone <pavone@retrodev.com>
parents: 2500
diff changeset
1486 value = io_sctrl_read(gen->io.ports + 1, context->cycles);
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
1487 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
1488 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
1489 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
1490 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
1491 case 0xE:
2524
25e40370e0e4 Fix some IO port serial mode bugs
Michael Pavone <pavone@retrodev.com>
parents: 2500
diff changeset
1492 value = io_rx_read(gen->io.ports + 2, context->cycles);
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
1493 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
1494 case 0xF:
2524
25e40370e0e4 Fix some IO port serial mode bugs
Michael Pavone <pavone@retrodev.com>
parents: 2500
diff changeset
1495 value = io_sctrl_read(gen->io.ports + 2, context->cycles);
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
1496 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
1497 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
1498 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
1499 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1500 } 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
1501 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
1502 if (masked == 0x11100) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1503 value = z80_enabled ? !z80_get_busack(gen->z80, context->cycles) : !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
1504 value |= (get_open_bus_value(&gen->header) >> 8) & 0xFE;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1505 dprintf("Byte read of BUSREQ returned %d @ %d (reset: %d)\n", value, context->cycles, 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
1506 } 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
1507 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
1508 } 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
1509 //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
1510 //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
1511 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
1512 } 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
1513 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
1514 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
1515 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
1516 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1517 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1518 }
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
1519
2012
b05295c2ad04 Small improvement to refresh cycle approximation
Mike Pavone <pavone@retrodev.com>
parents: 1998
diff changeset
1520 //no refresh delays during IO access
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
1521 gen_update_refresh_no_wait(context);
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1522 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
1523 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1524
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1525 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
1526 {
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
1527 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
1528 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
1529 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
1530 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
1531 } 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
1532 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
1533 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
1534 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1535 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
1536 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1537
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1538 static uint8_t pico_io_read(uint32_t location, void *vcontext)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1539 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1540 m68k_context *m68k = vcontext;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1541 genesis_context *gen = m68k->system;
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1542 uint16_t tmp;
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1543 switch(location >> 1 & 0x7F)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1544 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1545 case 0:
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1546 return gen->version_reg;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1547 case 1:
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1548 return gen->pico_button_state;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1549 case 2:
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1550 return gen->pico_pen_x >> 8;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1551 case 3:
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1552 return gen->pico_pen_x;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1553 case 4:
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1554 return gen->pico_pen_y >> 8;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1555 case 5:
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1556 return gen->pico_pen_y;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1557 case 6:
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1558 return gen->pico_page;
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1559 case 7:
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1560 //Copera titles seem to expect bit 0 to be 0 on a Copera and 1 on a Pico
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1561 if (gen->header.type == SYSTEM_PICO) {
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1562 return 1;
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1563 } else {
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1564 return 0;
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1565 }
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1566 case 8:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1567 //printf("uPD7759 data read @ %u\n", m68k->cycles);
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1568 sync_sound_pico(gen, m68k->cycles);
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1569 tmp = pico_pcm_data_read(gen->adpcm);
2433
2907c3312423 Fix byte reads of ADPCM ports. Fixes hangs in Sanchoume no Tama and Sailor Moon Sailor Stars - Tokimeki Party
Michael Pavone <pavone@retrodev.com>
parents: 2431
diff changeset
1570 return (location & 1) ? tmp : tmp >> 8;
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1571 case 9:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1572 //printf("uPD7759 contro/status read @ %u\n", m68k->cycles);
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1573 sync_sound_pico(gen, m68k->cycles);
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1574 tmp = pico_pcm_ctrl_read(gen->adpcm);
2433
2907c3312423 Fix byte reads of ADPCM ports. Fixes hangs in Sanchoume no Tama and Sailor Moon Sailor Stars - Tokimeki Party
Michael Pavone <pavone@retrodev.com>
parents: 2431
diff changeset
1575 return (location & 1) ? tmp : tmp >> 8;
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1576 return 0;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1577 default:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1578 printf("Unknown Pico IO read %X @ %u\n", location, m68k->cycles);
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1579 return 0xFF;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1580 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1581 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1582
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1583 static uint16_t pico_io_read_w(uint32_t location, void *vcontext)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1584 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1585 m68k_context *m68k = vcontext;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1586 genesis_context *gen = m68k->system;
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1587 uint32_t port = location & 0xFE;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1588 if (port == 0x10) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1589 sync_sound_pico(gen, m68k->cycles);
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1590 return pico_pcm_data_read(gen->adpcm);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1591 } else if (port == 0x12) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1592 sync_sound_pico(gen, m68k->cycles);
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1593 return pico_pcm_ctrl_read(gen->adpcm);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
1594 }
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1595 uint16_t value = pico_io_read(location, vcontext);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1596 return value | (value << 8);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1597 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1598
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1599 static uint16_t copera_io_read_w(uint32_t location, void *vcontext)
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1600 {
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1601 printf("Unhandled Copera 16-bit read %X\n", location);
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1602 return 0xFFFF;
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1603 }
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1604
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1605 static uint8_t copera_io_read(uint32_t location, void *vcontext)
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1606 {
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1607 uint8_t ret;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1608 m68k_context *m68k = vcontext;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1609 genesis_context *gen = m68k->system;
2558
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
1610 //FIXME: Copera sound hardware has a separate clock
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1611 switch (location & 0xFF)
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1612 {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1613 case 1:
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1614 case 5:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1615 ymz263b_run(gen->ymz, m68k->cycles);
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1616 ret = ymz263b_status_read(gen->ymz);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1617 printf("Copera YMZ263 Status read - %X: %X\n", location, ret);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1618 adjust_int_cycle_pico(gen->m68k, gen->vdp);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1619 return ret;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1620 case 3:
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1621 case 7:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1622 ymz263b_run(gen->ymz, m68k->cycles);
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1623 ret = ymz263b_data_read(gen->ymz, location & 4);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1624 printf("Copera YMZ263 Data read - %X: %X\n", location, ret);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1625 return ret;
2558
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
1626 case 0x28:
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
1627 ret = ymf262_read_status(gen->opl, m68k->cycles, 0);
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
1628 printf("Copera YMF262 Status read - %X: %X\n", location, ret);
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
1629 return ret;
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1630 default:
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1631 printf("Unhandled Copera 8-bit read %X\n", location);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1632 return 0xFF;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1633 }
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1634 }
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1635
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1636 static void* copera_io_write_w(uint32_t location, void *vcontext, uint16_t value)
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1637 {
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1638 printf("Unhandled Copera 16-bit write %X: %X\n", location, value);
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1639 return vcontext;
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1640 }
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1641
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1642 static void* copera_io_write(uint32_t location, void *vcontext, uint8_t value)
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1643 {
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1644 m68k_context *m68k = vcontext;
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1645 genesis_context *gen = m68k->system;
2558
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
1646 //FIXME: Copera sound hardware has a separate clock
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1647 switch (location & 0xFF)
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1648 {
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1649 case 1:
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1650 case 5:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1651 ymz263b_run(gen->ymz, m68k->cycles);
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1652 printf("Copera YMZ263 Address write - %X: %X\n", location, value);
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1653 ymz263b_address_write(gen->ymz, value);
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1654 break;
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1655 case 3:
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1656 case 7:
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1657 ymz263b_run(gen->ymz, m68k->cycles);
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1658 printf("Copera YMZ263 Channel #%d Data write - %X: %X\n", ((location & 4) >> 2) + 1, location, value);
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1659 ymz263b_data_write(gen->ymz, location & 4, value);
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1660 adjust_int_cycle_pico(gen->m68k, gen->vdp);
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1661 break;
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1662 case 0x24:
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1663 case 0x34:
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1664 printf("Copera YMF262 Address Part #%d write - %X: %X\n", ((location >> 4) & 1) + 1, location, value);
2558
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
1665 ymf262_run(gen->opl, m68k->cycles);
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
1666 if (location & 0x10) {
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
1667 ymf262_address_write_part2(gen->opl, value);
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
1668 } else {
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
1669 ymf262_address_write_part1(gen->opl, value);
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
1670 }
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1671 break;
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1672 case 0x28:
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
1673 printf("Copera YMF262 Data write - %X: %X\n", location, value);
2558
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
1674 ymf262_run(gen->opl, m68k->cycles);
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
1675 ymf262_data_write(gen->opl, value);
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1676 break;
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1677 case 0x40:
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1678 //Bit 4 = SCI
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1679 //Bit 5 = DIN
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1680 //Bit 6 = A0
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1681 //Possible Bit 0-3 are the same but for the other YM7128B
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1682 printf("Copera YM7128B Write - %X: %X\n", location, value);
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1683 break;
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1684 default:
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1685 printf("Unhandled Copera 8-bit write %X: %X\n", location, value);
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1686 }
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1687 return vcontext;
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1688 }
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1689
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1690 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
1691 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1692 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
1693 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
1694 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
1695 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
1696 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
1697 } 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
1698 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
1699 } 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
1700 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
1701 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
1703 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1705 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
1706 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
1708 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
1709 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
1710 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
1711 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1712
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1713 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
1714 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1715 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
1716 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
1717 if (gen->bus_busy) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1718 context->Z80_CYCLE = gen->m68k->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
1719 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1720 //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
1721 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
1722 //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
1723 //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
1724 // Needs a new logic analyzer capture to get the actual delay on the 68K side
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1725 gen->m68k->cycles += 8 * MCLKS_PER_68K;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1726
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1727 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
1728 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
1729 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
1730 }
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
1731 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
1732 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
1733 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
1734 } 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
1735 //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
1736 //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
1737 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
1738 } 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
1739 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
1740 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
1742 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1743
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1744 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
1745 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1746 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
1747 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
1748 if (gen->bus_busy) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1749 context->Z80_CYCLE = gen->m68k->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
1750 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1751 //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
1752 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
1753 //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
1754 //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
1755 // Needs a new logic analyzer capture to get the actual delay on the 68K side
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1756 gen->m68k->cycles += 8 * MCLKS_PER_68K;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1757
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1758 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
1759 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
1760 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
1761 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
1762 ((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
1763 } 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
1764 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
1765 } 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
1766 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
1767 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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 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
1769 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1770
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1771 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
1772 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1773 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
1774 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
1775
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
1776 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
1777 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
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 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
1780 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1781
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
1782 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
1783 {
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
1784 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
1785 genesis_context *gen = context->system;
2228
0db9dc6a9020 Some minor refresh emulation improvements
Michael Pavone <pavone@retrodev.com>
parents: 2227
diff changeset
1786 if (location >= 0x800000) {
0db9dc6a9020 Some minor refresh emulation improvements
Michael Pavone <pavone@retrodev.com>
parents: 2227
diff changeset
1787 //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1788 gen->refresh_counter += context->cycles - 4*MCLKS_PER_68K - gen->last_sync_cycle;
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1789 context->cycles += REFRESH_DELAY * MCLKS_PER_68K * (gen->refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL));
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
1790 gen->refresh_counter += 4*MCLKS_PER_68K;
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
1791 gen->refresh_counter = gen->refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL);
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1792 gen->last_sync_cycle = context->cycles;
2228
0db9dc6a9020 Some minor refresh emulation improvements
Michael Pavone <pavone@retrodev.com>
parents: 2227
diff changeset
1793 }
0db9dc6a9020 Some minor refresh emulation improvements
Michael Pavone <pavone@retrodev.com>
parents: 2227
diff changeset
1794
1987
71732f2f6f42 Fix handling of unmapped reads/writes to the cart/expansion port region
Mike Pavone <pavone@retrodev.com>
parents: 1980
diff changeset
1795 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
1796 //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
1797 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
1798 } 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
1799 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
1800 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
1801 } 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
1802 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
1803 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
1804 }
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
1805 } 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
1806 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
1807 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
1808 } 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
1809 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
1810 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
1811 }
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
1812 } 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
1813 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
1814 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
1815 }
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
1816 }
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
1817
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
1818 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
1819 {
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
1820 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
1821 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
1822 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
1823 } 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
1824 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
1825 }
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
1826 }
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
1827
2037
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
1828 static void check_tmss_lock(genesis_context *gen)
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
1829 {
2039
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
1830 gen->vdp_unlocked = gen->tmss_lock[0] == 0x5345 && gen->tmss_lock[1] == 0x4741;
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
1831 }
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
1832
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
1833 static void toggle_tmss_rom(genesis_context *gen)
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
1834 {
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
1835 m68k_context *context = gen->m68k;
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
1836 for (int i = 0; i < NUM_MEM_AREAS; i++)
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
1837 {
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
1838 uint16_t *tmp = context->mem_pointers[i];
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
1839 context->mem_pointers[i] = gen->tmss_pointers[i];
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
1840 gen->tmss_pointers[i] = tmp;
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
1841 }
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
1842 m68k_invalidate_code_range(context, 0, 0x400000);
2037
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
1843 }
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
1844
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
1845 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
1846 {
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
1847 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
1848 genesis_context *gen = context->system;
2228
0db9dc6a9020 Some minor refresh emulation improvements
Michael Pavone <pavone@retrodev.com>
parents: 2227
diff changeset
1849 if (location >= 0x800000) {
0db9dc6a9020 Some minor refresh emulation improvements
Michael Pavone <pavone@retrodev.com>
parents: 2227
diff changeset
1850 //do refresh check here so we can avoid adding a penalty for a refresh that happens during an IO area access
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1851 gen->refresh_counter += context->cycles - 4*MCLKS_PER_68K - gen->last_sync_cycle;
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1852 context->cycles += REFRESH_DELAY * MCLKS_PER_68K * (gen->refresh_counter / (MCLKS_PER_68K * REFRESH_INTERVAL));
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
1853 gen->refresh_counter += 4*MCLKS_PER_68K;
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
1854 gen->refresh_counter = gen->refresh_counter % (MCLKS_PER_68K * REFRESH_INTERVAL);
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
1855 gen->last_sync_cycle = context->cycles;
2228
0db9dc6a9020 Some minor refresh emulation improvements
Michael Pavone <pavone@retrodev.com>
parents: 2227
diff changeset
1856 }
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
1857
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
1858 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
1859 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
1860 gen->tmss_lock[location >> 1 & 1] = value;
2037
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
1861 check_tmss_lock(gen);
1907
b021ca0bc375 Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents: 1906
diff changeset
1862 } else if (has_tmss && location == 0xA14100) {
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
1863 value &= 1;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
1864 if (gen->tmss != value) {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
1865 gen->tmss = value;
2039
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
1866 toggle_tmss_rom(gen);
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
1867 }
1987
71732f2f6f42 Fix handling of unmapped reads/writes to the cart/expansion port region
Mike Pavone <pavone@retrodev.com>
parents: 1980
diff changeset
1868 } 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
1869 //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
1870 } 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
1871 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
1872 }
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
1873 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
1874 }
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
1875
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
1876 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
1877 {
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
1878 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
1879 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
1880 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
1881 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
1882 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
1883 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
1884 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
1885 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
1886 } 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
1887 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
1888 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
1889 }
2037
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
1890 check_tmss_lock(gen);
1907
b021ca0bc375 Some partial work on TMSS registers, more accurate open bus locations and implement machine freezes for unmapped areas in the IO region
Michael Pavone <pavone@retrodev.com>
parents: 1906
diff changeset
1891 } 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
1892 if (location & 1) {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
1893 value &= 1;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
1894 if (gen->tmss != value) {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
1895 gen->tmss = value;
2039
3b8e29ef1145 Add TMSS state to save states
Michael Pavone <pavone@retrodev.com>
parents: 2037
diff changeset
1896 toggle_tmss_rom(gen);
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
1897 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
1898 }
1987
71732f2f6f42 Fix handling of unmapped reads/writes to the cart/expansion port region
Mike Pavone <pavone@retrodev.com>
parents: 1980
diff changeset
1899 } 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
1900 //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
1901 } 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
1902 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
1903 }
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
1904 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
1905 }
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
1906
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
1907 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
1908 {
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
1909 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
1910 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
1911 context->master_clock = ((uint64_t)context->normal_clock * (uint64_t)percent) / 100;
2486
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1912 if (context->header.type != SYSTEM_PICO && context->header.type != SYSTEM_COPERA) {
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1913 while (context->ym->current_cycle != context->psg->cycles) {
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1914 sync_sound(context, context->psg->cycles + MCLKS_PER_PSG);
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1915 }
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1916 if (context->expansion) {
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1917 segacd_context *cd = context->expansion;
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1918 segacd_set_speed_percent(cd, percent);
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1919 }
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1920 ym_adjust_master_clock(context->ym, context->master_clock);
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1921 } else {
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1922 while (context->adpcm->cycle != context->psg->cycles) {
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1923 sync_sound_pico(context, context->psg->cycles + MCLKS_PER_PSG);
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1924 }
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1925 if (context->ymz) {
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1926 ymz263b_adjust_master_clock(context->ymz, context->master_clock);
2558
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
1927 ymf262_adjust_master_clock(context->opl, context->master_clock);
2486
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1928 }
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
1929 pico_pcm_adjust_master_clock(context->adpcm, context->master_clock);
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
1930 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1931 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
1932 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1933
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1934 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
1935 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1936 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
1937 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
1938 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
1939 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
1940 } 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
1941 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
1942 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1943 }
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1944 uint8_t is_50hz = 0;
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
1945 if (gen->header.type == SYSTEM_PICO || gen->header.type == SYSTEM_COPERA) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1946 if (region & REGION_E) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1947 is_50hz = 1;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1948 gen->version_reg = 0x20;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1949 } else if (region & REGION_J) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1950 gen->version_reg = 0;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1951 } else {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1952 gen->version_reg = 0x40;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1953 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1954 } else {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1955 if (region & REGION_E) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1956 gen->version_reg = NO_DISK | EUR;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1957 is_50hz = 1;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1958 } else if (region & REGION_J) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1959 gen->version_reg = NO_DISK | JAP;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1960 } else {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1961 gen->version_reg = NO_DISK | USA;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1962 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1963 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
1964
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1965 if (is_50hz) {
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1966 gen->normal_clock = MCLKS_PAL;
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1967 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
1968 } 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
1969 gen->normal_clock = MCLKS_NTSC;
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
1970 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
1971 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1972 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
1973 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. 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
1433
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
1975 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
1976 {
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
1977 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
1978 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
1979 deserialize_buffer state;
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
1980 uint32_t pc = 0;
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
1981 uint8_t ret;
2500
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
1982 #ifndef NEW_CORE
1479
a568dca999b2 Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
1983 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
1984 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
1985 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
1986 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
1987 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
1988 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
1989 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
1990 }
a568dca999b2 Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
1991 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
1992 }
2500
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
1993 #endif
1433
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
1994 if (load_from_file(&state, statepath)) {
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
1995 genesis_deserialize(&state, gen);
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
1996 free(state.data);
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
1997 ret = 1;
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
1998 } else {
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
1999 strcpy(statepath + strlen(statepath)-strlen("state"), "gst");
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
2000 pc = load_gst(gen, statepath);
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
2001 ret = pc != 0;
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
2002 }
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
2003 if (ret) {
2280
9ead0fe69d9b Implement savestate support for Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2278
diff changeset
2004 debug_message("Loaded state from %s\n", statepath);
1433
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
2005 }
1479
a568dca999b2 Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
2006 done:
1433
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
2007 free(statepath);
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
2008 return ret;
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
2009 }
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
2010
1479
a568dca999b2 Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
2011 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
2012 {
a568dca999b2 Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
2013 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
2014 {
a568dca999b2 Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
2015 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
2016 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
2017 gen->m68k->should_return = 0;
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2018 if (gen->header.type == SYSTEM_GENESIS) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
2019 z80_assert_reset(gen->z80, gen->m68k->cycles);
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
2020 z80_clear_busreq(gen->z80, gen->m68k->cycles);
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2021 }
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
2022 if (gen->header.type != SYSTEM_PICO && gen->header.type != SYSTEM_COPERA) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2023 ym_reset(gen->ym);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2024 }
1479
a568dca999b2 Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
2025 //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
2026 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
2027 }
a568dca999b2 Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
2028 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
2029 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
2030 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
2031 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
2032 }
a568dca999b2 Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
2033 }
1980
81df9aa2de9b Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents: 1971
diff changeset
2034 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
2035 bindings_release_capture();
b387f1c5a1d0 WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents: 1927
diff changeset
2036 vdp_release_framebuffer(gen->vdp);
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
2037 if (gen->header.type != SYSTEM_PICO && gen->header.type != SYSTEM_COPERA) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2038 render_pause_source(gen->ym->audio);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2039 }
1932
b387f1c5a1d0 WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents: 1927
diff changeset
2040 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
2041 }
1479
a568dca999b2 Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
2042 }
a568dca999b2 Fix genesis save state loading via Nuklear UI, sms probably still needs work
Michael Pavone <pavone@retrodev.com>
parents: 1478
diff changeset
2043
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
2044 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
2045 {
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
2046 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
2047 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
2048 //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
2049 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
2050 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
2051 if (load_from_file(&state, statefile)) {
1427
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
2052 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
2053 free(state.data);
2500
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
2054 #ifdef NEW_CORE
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
2055 pc = gen->m68k->pc;
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
2056 #else
1427
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
2057 //HACK
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
2058 pc = gen->m68k->last_prefetch_address;
2500
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
2059 #endif
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
2060 } 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
2061 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
2062 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
2063 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
2064 }
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
2065 }
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
2066 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
2067 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
2068 gen->header.enter_debugger = 0;
2302
0343f0d5add0 Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents: 2286
diff changeset
2069 #ifndef IS_LIB
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1108
diff changeset
2070 insert_breakpoint(gen->m68k, pc, gen->header.debugger_type == DEBUGGER_NATIVE ? debugger : gdb_debug_enter);
2302
0343f0d5add0 Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents: 2286
diff changeset
2071 #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
2072 }
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
2073 if (gen->header.type == SYSTEM_PICO || gen->header.type == SYSTEM_COPERA) {
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
2074 adjust_int_cycle_pico(gen->m68k, gen->vdp);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
2075 } else {
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
2076 adjust_int_cycle(gen->m68k, gen->vdp);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
2077 }
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
2078 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
2079 } 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
2080 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
2081 gen->header.enter_debugger = 0;
2302
0343f0d5add0 Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents: 2286
diff changeset
2082 #ifndef IS_LIB
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
2083 uint32_t address = read_word(4, (void **)gen->m68k->mem_pointers, &gen->m68k->opts->gen, gen->m68k) << 16
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
2084 | read_word(6, (void **)gen->m68k->mem_pointers, &gen->m68k->opts->gen, gen->m68k);
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1108
diff changeset
2085 insert_breakpoint(gen->m68k, address, gen->header.debugger_type == DEBUGGER_NATIVE ? debugger : gdb_debug_enter);
2302
0343f0d5add0 Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents: 2286
diff changeset
2086 #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
2087 }
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
2088 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
2089 }
2500
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
2090 #ifdef NEW_CORE
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
2091 while (!gen->m68k->should_return) {
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
2092 sync_components(gen->m68k, 0);
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
2093 m68k_execute(gen->m68k, gen->m68k->target_cycle);
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
2094 }
d44fe974fb85 Get blastem compiling with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2499
diff changeset
2095 #endif
1208
95f5253e75c7 Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents: 1204
diff changeset
2096 handle_reset_requests(gen);
1427
4e5797b3935a WIP - New savestate format
Michael Pavone <pavone@retrodev.com>
parents: 1420
diff changeset
2097 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
2098 }
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
2099
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
2100 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
2101 {
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
2102 genesis_context *gen = (genesis_context *)system;
1980
81df9aa2de9b Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents: 1971
diff changeset
2103 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
2104 gen->header.force_release = 0;
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
2105 if (gen->header.type == SYSTEM_PICO || gen->header.type == SYSTEM_COPERA) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2106 render_set_video_standard((gen->version_reg & 0x60) == 0x20 ? VID_PAL : VID_NTSC);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2107 } else {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2108 render_set_video_standard((gen->version_reg & HZ50) ? VID_PAL : VID_NTSC);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2109 }
1932
b387f1c5a1d0 WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents: 1927
diff changeset
2110 bindings_reacquire_capture();
b387f1c5a1d0 WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents: 1927
diff changeset
2111 vdp_reacquire_framebuffer(gen->vdp);
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
2112 if (gen->header.type != SYSTEM_PICO && gen->header.type != SYSTEM_COPERA) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2113 render_resume_source(gen->ym->audio);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2114 }
1932
b387f1c5a1d0 WIP new sync mode that runs emulation on audio thread
Michael Pavone <pavone@retrodev.com>
parents: 1927
diff changeset
2115 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
2116 }
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
2117 resume_68k(gen->m68k);
1208
95f5253e75c7 Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents: 1204
diff changeset
2118 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
2119 }
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
2120
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
2121 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
2122 {
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
2123 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
2124 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
2125 }
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
2126
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
2127 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
2128 {
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
2129 genesis_context *gen = (genesis_context *)system;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
2130 gen->m68k->target_cycle = gen->m68k->cycles;
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
2131 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
2132 }
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
2133
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
2134 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
2135 {
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
2136 genesis_context *gen = (genesis_context *)system;
2083
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2137 FILE *f;
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2138 if (gen->expansion) {
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2139 segacd_context *cd = gen->expansion;
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2140 char *bram_name = path_append(system->save_dir, "internal.bram");
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2141 f = fopen(bram_name, "wb");
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2142 if (f) {
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2143 fwrite(cd->bram, 1, 8 * 1024, f);
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2144 fclose(f);
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2145 printf("Saved internal BRAM to %s\n", bram_name);
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2146 }
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2147 free(bram_name);
2281
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2148 if (cd->bram_cart_id < 8) {
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2149 bram_name = path_append(system->save_dir, "cart.bram");
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2150 f = fopen(bram_name, "wb");
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2151 if (f) {
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2152 long configured_size = 0x2000 << cd->bram_cart_id;
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2153 fwrite(cd->bram_cart, 1, configured_size, f);
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2154 fclose(f);
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2155 printf("Saved BRAM cart to %s\n", bram_name);
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2156 }
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2157 free(bram_name);
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2158 }
2083
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2159 }
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
2160 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
2161 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
2162 }
2083
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2163 f = fopen(save_filename, "wb");
1111
2eb54e24914e Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents: 1108
diff changeset
2164 if (!f) {
1395
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1377
diff changeset
2165 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
2166 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
2167 }
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
2168 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
2169 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
2170 }
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
2171 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
2172 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
2173 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
2174 }
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
2175 fclose(f);
1395
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1377
diff changeset
2176 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
2177 }
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
2178
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
2179 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
2180 {
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
2181 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
2182 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
2183 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
2184 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
2185 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
2186 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
2187 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
2188 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
2189 }
1395
efa7225e0f07 Initial work to support parallel NOR flash and the Magistr 16
Michael Pavone <pavone@retrodev.com>
parents: 1377
diff changeset
2190 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
2191 }
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
2192 }
2083
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2193 if (gen->expansion) {
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2194 segacd_context *cd = gen->expansion;
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2195 char *bram_name = path_append(system->save_dir, "internal.bram");
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2196 f = fopen(bram_name, "rb");
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2197 if (f) {
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2198 uint32_t read = fread(cd->bram, 1, 8 * 1024, f);
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2199 fclose(f);
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2200 if (read > 0) {
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2201 printf("Loaded internal BRAM from %s\n", bram_name);
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2202 }
2335
c05b7c5e6f11 Automatically format Sega CD backup RAM
Michael Pavone <pavone@retrodev.com>
parents: 2327
diff changeset
2203 } else {
c05b7c5e6f11 Automatically format Sega CD backup RAM
Michael Pavone <pavone@retrodev.com>
parents: 2327
diff changeset
2204 segacd_format_bram(cd->bram, 8 * 1024);
2083
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2205 }
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2206 free(bram_name);
2281
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2207 bram_name = path_append(system->save_dir, "cart.bram");
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2208 f = fopen(bram_name, "rb");
2335
c05b7c5e6f11 Automatically format Sega CD backup RAM
Michael Pavone <pavone@retrodev.com>
parents: 2327
diff changeset
2209 long configured_size = 0x2000 << cd->bram_cart_id;
2281
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2210 if (f) {
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2211 long existing_size = nearest_pow2(file_size(f));
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2212 if (existing_size > 1 * 1024 * 1024) {
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2213 existing_size = 1 * 1024 * 1024;
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2214 }
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2215 if (existing_size != configured_size) {
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2216 if (existing_size > configured_size) {
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2217 free(cd->bram_cart);
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2218 cd->bram_cart = calloc(existing_size, 1);
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2219 }
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2220 cd->bram_cart_id = 0;
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2221 while (existing_size > (0x2000 <<cd->bram_cart_id)) {
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2222 cd->bram_cart_id++;
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2223 }
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2224 }
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2225 uint32_t read = fread(cd->bram_cart, 1, existing_size, f);
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2226 fclose(f);
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2227 if (read > 0) {
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2228 printf("Loaded BRAM cart from %s\n", bram_name);
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2229 }
2335
c05b7c5e6f11 Automatically format Sega CD backup RAM
Michael Pavone <pavone@retrodev.com>
parents: 2327
diff changeset
2230 } else {
c05b7c5e6f11 Automatically format Sega CD backup RAM
Michael Pavone <pavone@retrodev.com>
parents: 2327
diff changeset
2231 segacd_format_bram(cd->bram_cart, configured_size);
2281
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2232 }
b9fed07f19e4 Implement BRAM cart support
Michael Pavone <pavone@retrodev.com>
parents: 2280
diff changeset
2233 free(bram_name);
2083
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
2234 }
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
2235 }
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
2236
1208
95f5253e75c7 Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents: 1204
diff changeset
2237 static void soft_reset(system_header *system)
95f5253e75c7 Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents: 1204
diff changeset
2238 {
95f5253e75c7 Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents: 1204
diff changeset
2239 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
2240 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
2241 double random = (double)rand()/(double)RAND_MAX;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
2242 gen->reset_cycle = gen->m68k->cycles + random * MCLKS_LINE * (gen->version_reg & HZ50 ? LINES_PAL : LINES_NTSC);
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
2243 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
2244 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
2245 }
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
2246 }
1208
95f5253e75c7 Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents: 1204
diff changeset
2247 }
95f5253e75c7 Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents: 1204
diff changeset
2248
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
2249 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
2250 {
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
2251 genesis_context *gen = (genesis_context *)system;
2164
4fbe1e7c4a73 Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents: 2150
diff changeset
2252 if (gen->expansion) {
4fbe1e7c4a73 Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents: 2150
diff changeset
2253 free_segacd(gen->expansion);
4fbe1e7c4a73 Don't leak all Sega CD resources when freeing a Genesis instance
Michael Pavone <pavone@retrodev.com>
parents: 2150
diff changeset
2254 }
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
2255 vdp_free(gen->vdp);
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
2256 memmap_chunk *map = (memmap_chunk *)gen->m68k->opts->gen.memmap;
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
2257 m68k_options_free(gen->m68k->opts);
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
2258 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
2259 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
2260 free(gen->work_ram);
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2261 if (gen->header.type == SYSTEM_GENESIS) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2262 z80_options_free(gen->z80->Z80_OPTS);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2263 free(gen->z80);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2264 free(gen->zram);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2265 }
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
2266 if (gen->header.type == SYSTEM_PICO || gen->header.type == SYSTEM_COPERA) {
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
2267 pico_pcm_free(gen->adpcm);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
2268 free(gen->adpcm);
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
2269 if (gen->ymz) {
2486
e8eba0cd5444 Implement turbo/slow for Pico and Copera
Michael Pavone <pavone@retrodev.com>
parents: 2485
diff changeset
2270 ymz263b_free(gen->ymz);
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
2271 free(gen->ymz);
2558
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2272 ymf262_free(gen->opl);
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
2273 }
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
2274 } else {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2275 ym_free(gen->ym);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2276 }
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
2277 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
2278 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
2279 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
2280 free(gen->lock_on);
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
2281 if (gen->save_type != SAVE_NONE && gen->mapper_type != MAPPER_SEGA_MED_V2) {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
2282 free(gen->save_storage);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
2283 }
2248
f7e2e11f1214 Fix improper free of memory map array from rom_info
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
2284 free(map);
1116
fe8c79f82c22 More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents: 1113
diff changeset
2285 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
2286 }
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
2287
1583
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2288 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
2289 {
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2290 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
2291 io_gamepad_down(&gen->io, gamepad_num, button);
1610
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1595
diff changeset
2292 if (gen->mapper_type == MAPPER_JCART) {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1595
diff changeset
2293 jcart_gamepad_down(gen, gamepad_num, button);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1595
diff changeset
2294 }
1583
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2295 }
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2296
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2297 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
2298 {
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2299 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
2300 io_gamepad_up(&gen->io, gamepad_num, button);
1610
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1595
diff changeset
2301 if (gen->mapper_type == MAPPER_JCART) {
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1595
diff changeset
2302 jcart_gamepad_up(gen, gamepad_num, button);
c206a422d466 Added J-Cart support
Michael Pavone <pavone@retrodev.com>
parents: 1595
diff changeset
2303 }
1583
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2304 }
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2305
2429
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2306 static void pico_update_page(genesis_context *gen)
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2307 {
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2308 #ifndef IS_LIB
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2309 uint8_t page_num = 0;
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2310 uint8_t page = gen->pico_page;
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2311 while (page)
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2312 {
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2313 page_num++;
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2314 page >>= 1;
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2315 }
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2316 render_clear_window(gen->pico_story_window, 236, 205, 27);
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2317 int x, width;
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2318 if (page_num) {
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2319 x = 0;
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2320 width = 640;
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2321 } else {
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2322 render_fill_rect(gen->pico_story_window, 50, 29, 96, 0, 0, 320, 320);
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2323 x = 320;
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2324 width = 320;
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2325 }
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2326 if (gen->pico_story_pages[page_num] == 0xFF && page_num == 6 && gen->pico_story_pages[page_num - 1]) {
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2327 //repeat last page if storybook doesn't have a full 6 pages
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2328 //hack to deal with storybooks that skip page 5
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2329 page_num--;
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2330 }
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2331 if (gen->pico_story_pages[page_num] != 0xFF) {
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2332 render_draw_image(gen->pico_story_window, gen->pico_story_pages[page_num], x, 0, width, 320);
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2333 } else {
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2334 uint8_t grey = page * (255 / 5);
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2335 render_fill_rect(gen->pico_story_window, grey, grey, grey, x, 0, width, 320);
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2336 }
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2337 render_window_refresh(gen->pico_story_window);
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2338 #endif
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2339 }
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2340
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2341 static void gamepad_down_pico(system_header *system, uint8_t gamepad_num, uint8_t button)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2342 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2343 genesis_context *gen = (genesis_context *)system;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2344 if (gamepad_num != 1) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2345 return;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2346 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2347 //TODO: storyware display
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2348 if (button == BUTTON_C) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2349 gen->pico_page <<= 1;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2350 gen->pico_page |= 1;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2351 gen->pico_page &= 0x3F;
2429
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2352 pico_update_page(gen);
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2353 } else if (button == BUTTON_Z) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2354 gen->pico_page >>= 1;
2429
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2355 pico_update_page(gen);
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2356 } else if (button < BUTTON_B) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2357 gen->pico_button_state &= ~(1 << (button - 1));
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2358 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2359 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2360
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2361 static void gamepad_up_pico(system_header *system, uint8_t gamepad_num, uint8_t button)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2362 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2363 genesis_context *gen = (genesis_context *)system;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2364 if (gamepad_num != 1) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2365 return;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2366 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2367 if (button < BUTTON_B) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2368 gen->pico_button_state |= 1 << (button - 1);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2369 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2370 return;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2371 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2372
1583
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2373 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
2374 {
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2375 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
2376 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
2377 }
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2378
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2379 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
2380 {
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2381 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
2382 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
2383 }
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2384
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2385 static void mouse_down_pico(system_header *system, uint8_t mouse_num, uint8_t button)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2386 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2387 genesis_context *gen = (genesis_context *)system;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2388 if (button == MOUSE_LEFT) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2389 gen->pico_button_state &= ~0x80;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2390 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2391 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2392
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2393 static void mouse_up_pico(system_header *system, uint8_t mouse_num, uint8_t button)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2394 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2395 genesis_context *gen = (genesis_context *)system;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2396 if (button == MOUSE_LEFT) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2397 gen->pico_button_state |= 0x80;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2398 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2399 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2400
1583
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2401 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
2402 {
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2403 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
2404 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
2405 }
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2406
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2407 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
2408 {
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2409 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
2410 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
2411 }
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2412
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2413 static void mouse_motion_absolute_pico(system_header *system, uint8_t mouse_num, uint16_t x, uint16_t y)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2414 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2415 genesis_context *gen = (genesis_context *)system;
2429
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2416 //FIXME: coordinate translation feels a little off for storybook area
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2417 //TODO: limit to mouse motion on emulated storyware/drawing area
2429
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2418 if (y < 24) {
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2419 y = 24;
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2420 }
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2421 gen->pico_pen_x = x * (0x17D - 0x3C) / 640 + 0x3C;
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2422 if (y < 320) {
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2423 gen->pico_pen_y = (y-24) * (0x3F4-0x2F8) / (320-24) + 0x2F8;
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2424 } else {
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2425 gen->pico_pen_y = (y - 320) * (0x2f8-0x1FC) / 320 + 0x1FC;
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
2426 }
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2427 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2429 static void mouse_motion_relative_pico(system_header *system, uint8_t mouse_num, int32_t x, int32_t y)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2430 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2431 genesis_context *gen = (genesis_context *)system;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2432 //TODO: scale properly
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2433 //TODO: limit to mouse motion on emulated storyware/drawing area
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2434 gen->pico_pen_x += x;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2435 gen->pico_pen_y += y;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2436 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2437
1583
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2438 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
2439 {
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2440 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
2441 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
2442 }
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2443
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2444 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
2445 {
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2446 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
2447 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
2448 }
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2449
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2450 static void keyboard_down_pico(system_header *system, uint8_t scancode)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2451 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2452 genesis_context *gen = (genesis_context *)system;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2453 //TODO: Keyboard Pico emulation
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2454 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2455
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2456 static void keyboard_up_pico(system_header *system, uint8_t scancode)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2457 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2458 genesis_context *gen = (genesis_context *)system;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2459 //TODO: Keyboard Pico emulation
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2460 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2461
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
2462 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
2463 {
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1766
diff changeset
2464 char *config_gain;
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1766
diff changeset
2465 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
2466 render_audio_source_gaindb(gen->psg->audio, config_gain ? atof(config_gain) : 0.0f);
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
2467 if (gen->header.type != SYSTEM_PICO && gen->header.type != SYSTEM_COPERA) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2468 config_gain = tern_find_path(config, "audio\0fm_gain\0", TVAL_PTR).ptrval;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2469 render_audio_source_gaindb(gen->ym->audio, config_gain ? atof(config_gain) : 0.0f);
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
2470
2556
6f1eebc0a90b Add auto option for fm_dac config variable that bases zero offset on the select MD model
Michael Pavone <pavone@retrodev.com>
parents: 2548
diff changeset
2471 char *config_dac = tern_find_path_default(config, "audio\0fm_dac\0", (tern_val){.ptrval="auto"}, TVAL_PTR).ptrval;
6f1eebc0a90b Add auto option for fm_dac config variable that bases zero offset on the select MD model
Michael Pavone <pavone@retrodev.com>
parents: 2548
diff changeset
2472 uint8_t zero_offset = 0;
6f1eebc0a90b Add auto option for fm_dac config variable that bases zero offset on the select MD model
Michael Pavone <pavone@retrodev.com>
parents: 2548
diff changeset
2473 if (!strcmp(config_dac, "auto")) {
6f1eebc0a90b Add auto option for fm_dac config variable that bases zero offset on the select MD model
Michael Pavone <pavone@retrodev.com>
parents: 2548
diff changeset
2474 zero_offset = gen->ym->status_address_mask != 0;
6f1eebc0a90b Add auto option for fm_dac config variable that bases zero offset on the select MD model
Michael Pavone <pavone@retrodev.com>
parents: 2548
diff changeset
2475 } else if (!strcmp(config_dac, "zero_offset")) {
6f1eebc0a90b Add auto option for fm_dac config variable that bases zero offset on the select MD model
Michael Pavone <pavone@retrodev.com>
parents: 2548
diff changeset
2476 zero_offset = 1;
6f1eebc0a90b Add auto option for fm_dac config variable that bases zero offset on the select MD model
Michael Pavone <pavone@retrodev.com>
parents: 2548
diff changeset
2477 }
6f1eebc0a90b Add auto option for fm_dac config variable that bases zero offset on the select MD model
Michael Pavone <pavone@retrodev.com>
parents: 2548
diff changeset
2478 ym_enable_zero_offset(gen->ym, zero_offset);
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2479 }
2277
9e578fd493e1 Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2272
diff changeset
2480
9e578fd493e1 Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2272
diff changeset
2481 if (gen->expansion) {
9e578fd493e1 Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2272
diff changeset
2482 segacd_context *cd = gen->expansion;
9e578fd493e1 Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2272
diff changeset
2483 config_gain = tern_find_path(config, "audio\0rf5c164_gain\0", TVAL_PTR).ptrval;
9e578fd493e1 Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2272
diff changeset
2484 render_audio_source_gaindb(cd->pcm.audio, config_gain ? atof(config_gain) : -6.0f);
9e578fd493e1 Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2272
diff changeset
2485 config_gain = tern_find_path(config, "audio\0cdda_gain\0", TVAL_PTR).ptrval;
9e578fd493e1 Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2272
diff changeset
2486 render_audio_source_gaindb(cd->fader.audio, config_gain ? atof(config_gain) : -9.5f);
9e578fd493e1 Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2272
diff changeset
2487 }
1796
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1766
diff changeset
2488 }
51417bb557b6 Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents: 1766
diff changeset
2489
1595
360d5bab199f Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
2490 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
2491 {
360d5bab199f Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
2492 genesis_context *gen = (genesis_context *)system;
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2493 if (gen->header.type == SYSTEM_GENESIS) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2494 setup_io_devices(config, &system->info, &gen->io);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2495 }
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
2496 set_audio_config(gen);
2384
03e6ac327ba0 Handle changes to sample rate while content is running
Michael Pavone <pavone@retrodev.com>
parents: 2354
diff changeset
2497 //sample rate may have changed
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
2498 if (gen->header.type != SYSTEM_PICO && gen->header.type != SYSTEM_COPERA) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2499 ym_adjust_master_clock(gen->ym, gen->master_clock);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2500 }
2384
03e6ac327ba0 Handle changes to sample rate while content is running
Michael Pavone <pavone@retrodev.com>
parents: 2354
diff changeset
2501 psg_adjust_master_clock(gen->psg, gen->master_clock);
03e6ac327ba0 Handle changes to sample rate while content is running
Michael Pavone <pavone@retrodev.com>
parents: 2354
diff changeset
2502 if (gen->expansion) {
03e6ac327ba0 Handle changes to sample rate while content is running
Michael Pavone <pavone@retrodev.com>
parents: 2354
diff changeset
2503 segacd_config_updated(gen->expansion);
03e6ac327ba0 Handle changes to sample rate while content is running
Michael Pavone <pavone@retrodev.com>
parents: 2354
diff changeset
2504 }
1595
360d5bab199f Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
2505 }
360d5bab199f Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents: 1593
diff changeset
2506
1909
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2507 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
2508 {
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2509 genesis_context *gen = (genesis_context *)system;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
2510 vgm_writer *vgm = vgm_write_open(filename, gen->version_reg & HZ50 ? 50 : 60, gen->normal_clock, gen->m68k->cycles);
1909
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2511 if (vgm) {
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2512 printf("Started logging VGM to %s\n", filename);
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
2513 if (gen->header.type != SYSTEM_PICO && gen->header.type != SYSTEM_COPERA) {
2488
bfd09d3367ba Fix crash when enabling VGM recording while running Pico or Copera software
Michael Pavone <pavone@retrodev.com>
parents: 2486
diff changeset
2514 sync_sound(gen, vgm->last_cycle);
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2515 ym_vgm_log(gen->ym, gen->normal_clock, vgm);
2488
bfd09d3367ba Fix crash when enabling VGM recording while running Pico or Copera software
Michael Pavone <pavone@retrodev.com>
parents: 2486
diff changeset
2516 } else {
bfd09d3367ba Fix crash when enabling VGM recording while running Pico or Copera software
Michael Pavone <pavone@retrodev.com>
parents: 2486
diff changeset
2517 sync_sound_pico(gen, vgm->last_cycle);
2558
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2518 if (gen->opl) {
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2519 ymf262_vgm_log(gen->opl, gen->normal_clock, vgm);
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
2520 }
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2521 }
2254
8b88d57d1218 Prevent VGM logging from getting messed up if slow/turbo is active at log start time
Michael Pavone <pavone@retrodev.com>
parents: 2248
diff changeset
2522 psg_vgm_log(gen->psg, gen->normal_clock, vgm);
1909
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2523 gen->header.vgm_logging = 1;
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2524 } else {
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2525 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
2526 }
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2527 }
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2528
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2529 static void stop_vgm_log(system_header *system)
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2530 {
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2531 puts("Stopped VGM log");
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2532 genesis_context *gen = (genesis_context *)system;
2488
bfd09d3367ba Fix crash when enabling VGM recording while running Pico or Copera software
Michael Pavone <pavone@retrodev.com>
parents: 2486
diff changeset
2533 vgm_close(gen->psg->vgm);
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
2534 if (gen->header.type != SYSTEM_PICO && gen->header.type != SYSTEM_COPERA) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2535 gen->ym->vgm = NULL;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2536 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2537 gen->psg->vgm = NULL;
1909
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2538 gen->header.vgm_logging = 0;
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2539 }
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2540
2243
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2541 static void toggle_debug_view(system_header *system, uint8_t debug_view)
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2542 {
2302
0343f0d5add0 Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents: 2286
diff changeset
2543 #ifndef IS_LIB
2243
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2544 genesis_context *gen = (genesis_context *)system;
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2545 if (debug_view < DEBUG_OSCILLOSCOPE) {
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2546 vdp_toggle_debug_view(gen->vdp, debug_view);
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2547 } else if (debug_view == DEBUG_OSCILLOSCOPE) {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2548 if (gen->psg->scope) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2549 oscilloscope *scope = gen->psg->scope;
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
2550 if (gen->header.type == SYSTEM_PICO || gen->header.type == SYSTEM_COPERA) {
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
2551 gen->adpcm->scope = NULL;
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
2552 } else {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2553 gen->ym->scope = NULL;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2554 }
2243
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2555 gen->psg->scope = NULL;
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2556 if (gen->expansion) {
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2557 segacd_context *cd = gen->expansion;
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2558 cd->pcm.scope = NULL;
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2559 }
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2560 scope_close(scope);
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2561 } else {
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2562 oscilloscope *scope = create_oscilloscope();
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
2563 if (gen->header.type == SYSTEM_PICO || gen->header.type == SYSTEM_COPERA) {
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
2564 pico_pcm_enable_scope(gen->adpcm, scope, gen->normal_clock);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
2565 } else {
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2566 ym_enable_scope(gen->ym, scope, gen->normal_clock);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
2567 }
2255
74112041b2c7 Proper calculation of sample rate for YM2612/PSG oscilloscope view
Michael Pavone <pavone@retrodev.com>
parents: 2254
diff changeset
2568 psg_enable_scope(gen->psg, scope, gen->normal_clock);
2243
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2569 if (gen->expansion) {
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2570 segacd_context *cd = gen->expansion;
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2571 rf5c164_enable_scope(&cd->pcm, scope);
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2572 }
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2573 }
2271
3ef80963c2a7 Fix stamp address mask and add WIP CD graphics debug view
Michael Pavone <pavone@retrodev.com>
parents: 2267
diff changeset
2574 } else if (debug_view == DEBUG_CD_GRAPHICS && gen->expansion) {
3ef80963c2a7 Fix stamp address mask and add WIP CD graphics debug view
Michael Pavone <pavone@retrodev.com>
parents: 2267
diff changeset
2575 scd_toggle_graphics_debug(gen->expansion);
2243
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2576 }
2302
0343f0d5add0 Fix libretro build for real
Michael Pavone <pavone@retrodev.com>
parents: 2286
diff changeset
2577 #endif
2243
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2578 }
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2579
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2580 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
2581 {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2582 m68k_context *m68k = context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2583 genesis_context *gen = m68k->system;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2584 if (gen->tmss) {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2585 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
2586 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
2587
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2588 return context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2589 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2590
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2591 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
2592 {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2593 m68k_context *m68k = context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2594 genesis_context *gen = m68k->system;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2595 if (gen->tmss) {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2596 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
2597 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
2598
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2599 return context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2600 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2601
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2602 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
2603 {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2604 m68k_context *m68k = context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2605 genesis_context *gen = m68k->system;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2606 if (gen->tmss) {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2607 return gen->tmss_read_16(address, context);
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2608 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2609 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
2610 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2611
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2612 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
2613 {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2614 m68k_context *m68k = context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2615 genesis_context *gen = m68k->system;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2616 if (gen->tmss) {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2617 return gen->tmss_read_8(address, context);
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2618 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2619 #ifdef BLASTEM_BIG_ENDIAN
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2620 return gen->tmss_buffer[address];
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2621 #else
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2622 return gen->tmss_buffer[address ^ 1];
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2623 #endif
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2624 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2625
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2626 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
2627 {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2628 m68k_context *m68k = context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2629 genesis_context *gen = m68k->system;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2630 if (gen->tmss) {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2631 address += gen->tmss_write_offset;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
2632 uint16_t *dest = get_native_pointer(address, (void **)m68k->mem_pointers, &m68k->opts->gen);
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2633 *dest = value;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2634 m68k_handle_code_write(address, m68k);
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2635 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
2636
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2637 return context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2638 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2639
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2640 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
2641 {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2642 m68k_context *m68k = context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2643 genesis_context *gen = m68k->system;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2644 if (gen->tmss) {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2645 address += gen->tmss_write_offset;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
2646 uint8_t *dest = get_native_pointer(address & ~1, (void **)m68k->mem_pointers, &m68k->opts->gen);
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2647 #ifdef BLASTEM_BIG_ENDIAN
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2648 dest[address & 1] = value;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2649 #else
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2650 dest[address & 1 ^ 1] = value;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2651 #endif
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2652 m68k_handle_code_write(address & ~1, m68k);
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2653 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
2654
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2655 return context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2656 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2657
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2658 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
2659 {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2660 m68k_context *m68k = context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2661 genesis_context *gen = m68k->system;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2662 if (gen->tmss) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
2663 memmap_chunk const *chunk = find_map_chunk(address + gen->tmss_write_offset, &m68k->opts->gen, 0, NULL);
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2664 address >>= 1;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2665 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
2666 base[address] = value;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2667 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2668 return context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2669 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2670
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2671 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
2672 {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2673 m68k_context *m68k = context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2674 genesis_context *gen = m68k->system;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2675 if (gen->tmss && (address & 1)) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
2676 memmap_chunk const *chunk = find_map_chunk(address + gen->tmss_write_offset, &m68k->opts->gen, 0, NULL);
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2677 address >>= 1;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2678 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
2679 base[address] = value;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2680 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2681 return context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2682 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2683
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2684 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
2685 {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2686 m68k_context *m68k = context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2687 genesis_context *gen = m68k->system;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2688 if (gen->tmss) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
2689 memmap_chunk const *chunk = find_map_chunk(address + gen->tmss_write_offset, &m68k->opts->gen, 0, NULL);
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2690 address >>= 1;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2691 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
2692 base[address] = value >> 8;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2693 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2694 return context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2695 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2696
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2697 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
2698 {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2699 m68k_context *m68k = context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2700 genesis_context *gen = m68k->system;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2701 if (gen->tmss && !(address & 1)) {
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
2702 memmap_chunk const *chunk = find_map_chunk(address + gen->tmss_write_offset, &m68k->opts->gen, 0, NULL);
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2703 address >>= 1;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2704 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
2705 base[address] = value;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2706 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2707 return context;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2708 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2709
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2710 static genesis_context *shared_init(uint32_t system_opts, rom_info *rom, uint8_t force_region)
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2711 {
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2712 static memmap_chunk z80_map[] = {
2134
9caebcfeac72 Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents: 2090
diff changeset
2713 { 0x0000, 0x4000, 0x1FFF, .flags = MMAP_READ | MMAP_WRITE | MMAP_CODE},
9caebcfeac72 Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents: 2090
diff changeset
2714 { 0x8000, 0x10000, 0x7FFF, .read_8 = z80_read_bank, .write_8 = z80_write_bank},
9caebcfeac72 Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents: 2090
diff changeset
2715 { 0x4000, 0x6000, 0x0003, .read_8 = z80_read_ym, .write_8 = z80_write_ym},
9caebcfeac72 Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents: 2090
diff changeset
2716 { 0x6000, 0x6100, 0xFFFF, .write_8 = z80_write_bank_reg},
9caebcfeac72 Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents: 2090
diff changeset
2717 { 0x7F00, 0x8000, 0x00FF, .read_8 = z80_vdp_port_read, .write_8 = z80_vdp_port_write}
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2718 };
2053
3414a4423de1 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1692 2052
diff changeset
2719
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2720 char *m68k_divider = tern_find_path(config, "clocks\0m68k_divider\0", TVAL_PTR).ptrval;
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2721 if (!m68k_divider) {
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2722 m68k_divider = "7";
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2723 }
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2724 MCLKS_PER_68K = atoi(m68k_divider);
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2725 if (!MCLKS_PER_68K) {
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2726 MCLKS_PER_68K = 7;
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2727 }
2053
3414a4423de1 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1692 2052
diff changeset
2728
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2729 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
2730 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
2731 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
2732 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
2733 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
2734 gen->header.persist_save = persist_save;
1433
c886c54d8cf1 Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents: 1428
diff changeset
2735 gen->header.load_state = load_state;
1208
95f5253e75c7 Implement soft reset in Genesis mode
Michael Pavone <pavone@retrodev.com>
parents: 1204
diff changeset
2736 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
2737 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
2738 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
2739 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
2740 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
2741 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
2742 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
2743 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
2744 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
2745 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
2746 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
2747 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
2748 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
2749 gen->header.config_updated = config_updated;
1690
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
2750 gen->header.serialize = serialize;
319d90025d50 Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents: 1688
diff changeset
2751 gen->header.deserialize = deserialize;
1909
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2752 gen->header.start_vgm_log = start_vgm_log;
508522f08e4d Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents: 1907
diff changeset
2753 gen->header.stop_vgm_log = stop_vgm_log;
2243
0d1d5dccdd28 Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents: 2228
diff changeset
2754 gen->header.toggle_debug_view = toggle_debug_view;
1377
e587f16e7d3d Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents: 1374
diff changeset
2755 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
2756 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
2757 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
2758 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
2759 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
2760 if (tmss) {
5433252329fb Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents: 1889
diff changeset
2761 gen->version_reg |= 1;
2037
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
2762 } else {
b0b0c31338c3 Implement TMSS VDP lock
Michael Pavone <pavone@retrodev.com>
parents: 2034
diff changeset
2763 gen->vdp_unlocked = 1;
1901
5433252329fb Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents: 1889
diff changeset
2764 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2765
1906
2d462aa78349 Make VDP VSRAM capacity respect model selection
Michael Pavone <pavone@retrodev.com>
parents: 1904
diff changeset
2766 uint8_t max_vsram = !strcmp(tern_find_ptr_default(model, "vsram", "40"), "64");
2194
01ff005b08f6 Very rudimentary support for Game Gear VDP emulation
Michael Pavone <pavone@retrodev.com>
parents: 2184
diff changeset
2767 gen->vdp = init_vdp_context(gen->version_reg & 0x40, max_vsram, VDP_GENESIS);
1117
928a65750345 Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents: 1116
diff changeset
2768 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
2769 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
2770 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
2771 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
2772 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
2773 gen->int_latency_prev2 = MCLKS_PER_68K * 16;
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
2774
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
2775 render_set_video_standard((gen->version_reg & HZ50) ? VID_PAL : VID_NTSC);
1946
c3c62dbf1ceb WIP netplay support
Michael Pavone <pavone@retrodev.com>
parents: 1932
diff changeset
2776 event_system_start(SYSTEM_GENESIS, (gen->version_reg & HZ50) ? VID_PAL : VID_NTSC, rom->name);
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
2777
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2778 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
2779 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
2780 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
2781 system_opts |= YM_OPT_3834;
8312e574100a Implement selectable YM2612/YM3834 invalid status port behavior
Michael Pavone <pavone@retrodev.com>
parents: 1902
diff changeset
2782 }
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
2783 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
2784
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2785 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
2786 psg_init(gen->psg, gen->master_clock, MCLKS_PER_PSG);
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
2787
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2788 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
2789 #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
2790 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
2791 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
2792 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
2793 #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
2794 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
2795 #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
2796 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
2797 #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
2798 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
2799 #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
2800
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2801 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
2802 gen->z80->mem_pointers[0] = gen->zram;
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2803 gen->z80->mem_pointers[1] = gen->z80->mem_pointers[2] = NULL;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2804
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2805 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
2806 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
2807 {
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
2808 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
2809 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
2810 {
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
2811 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
2812 }
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
2813 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
2814 {
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
2815 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
2816 }
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
2817 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
2818 {
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
2819 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
2820 }
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
2821 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
2822 {
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
2823 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
2824 }
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
2825 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
2826 {
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
2827 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
2828 }
1906
2d462aa78349 Make VDP VSRAM capacity respect model selection
Michael Pavone <pavone@retrodev.com>
parents: 1904
diff changeset
2829 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
2830 {
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
2831 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
2832 }
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
2833 }
2053
3414a4423de1 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1692 2052
diff changeset
2834
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2835 return gen;
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2836 }
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2837
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2838 static memmap_chunk base_map[] = {
2134
9caebcfeac72 Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents: 2090
diff changeset
2839 {0xE00000, 0x1000000, 0xFFFF, .flags = MMAP_READ | MMAP_WRITE | MMAP_CODE},
9caebcfeac72 Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents: 2090
diff changeset
2840 {0xC00000, 0xE00000, 0x1FFFFF, .read_16 = (read_16_fun)vdp_port_read, .write_16 =(write_16_fun)vdp_port_write,
9caebcfeac72 Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents: 2090
diff changeset
2841 .read_8 = (read_8_fun)vdp_port_read_b, .write_8 = (write_8_fun)vdp_port_write_b},
9caebcfeac72 Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents: 2090
diff changeset
2842 {0xA00000, 0xA12000, 0x1FFFF, .read_16 = (read_16_fun)io_read_w, .write_16 = (write_16_fun)io_write_w,
9caebcfeac72 Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents: 2090
diff changeset
2843 .read_8 = (read_8_fun)io_read, .write_8 = (write_8_fun)io_write},
9caebcfeac72 Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents: 2090
diff changeset
2844 {0x000000, 0xFFFFFF, 0xFFFFFF, .read_16 = (read_16_fun)unused_read, .write_16 = unused_write,
9caebcfeac72 Implement word RAM interleaving in 1M mode, now passes mcd-verificator word RAM tests
Michael Pavone <pavone@retrodev.com>
parents: 2090
diff changeset
2845 .read_8 = (read_8_fun)unused_read_b, .write_8 = (write_8_fun)unused_write_b}
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2846 };
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2847 const size_t base_chunks = sizeof(base_map)/sizeof(*base_map);
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2848
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2849 genesis_context *alloc_config_genesis(void *rom, uint32_t rom_size, void *lock_on, uint32_t lock_on_size, uint32_t ym_opts, uint8_t force_region)
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2850 {
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2851 tern_node *rom_db = get_rom_db();
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2852 rom_info info = configure_rom(rom_db, rom, rom_size, lock_on, lock_on_size, base_map, base_chunks);
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2853 rom = info.rom;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2854 rom_size = info.rom_size;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2855 #ifndef BLASTEM_BIG_ENDIAN
2150
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2134
diff changeset
2856 byteswap_rom(nearest_pow2(rom_size), rom);
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2857 if (lock_on) {
2150
a418fa599b2e Add ROM DB entry to fix SRAM on Triple Play: Gold Edition and make some code changes so that 3MB dumps will work too
Michael Pavone <pavone@retrodev.com>
parents: 2134
diff changeset
2858 byteswap_rom(nearest_pow2(lock_on_size), lock_on);
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2859 }
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2860 #endif
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2861 char *m68k_divider = tern_find_path(config, "clocks\0m68k_divider\0", TVAL_PTR).ptrval;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2862 if (!m68k_divider) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2863 m68k_divider = "7";
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2864 }
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2865 MCLKS_PER_68K = atoi(m68k_divider);
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2866 if (!MCLKS_PER_68K) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2867 MCLKS_PER_68K = 7;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2868 }
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2869 genesis_context *gen = shared_init(ym_opts, &info, force_region);
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2870 gen->z80->mem_pointers[1] = gen->z80->mem_pointers[2] = rom;
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2871
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2872 gen->cart = rom;
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
2873 gen->lock_on = lock_on;
2053
3414a4423de1 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1692 2052
diff changeset
2874
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2875 setup_io_devices(config, &info, &gen->io);
1583
430dd12e4010 Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents: 1576
diff changeset
2876 gen->header.has_keyboard = io_has_keyboard(&gen->io);
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2877 gen->mapper_type = info.mapper_type;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2878 gen->save_type = info.save_type;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2879 if (gen->save_type != SAVE_NONE) {
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2880 gen->save_ram_mask = info.save_mask;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2881 gen->save_size = info.save_size;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2882 gen->save_storage = info.save_buffer;
2286
5d3411f52d00 Fix ui.reload for locked-on ROMs
Michael Pavone <pavone@retrodev.com>
parents: 2281
diff changeset
2883 gen->header.info.save_buffer = info.save_buffer = NULL;
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2884 gen->eeprom_map = info.eeprom_map;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2885 gen->num_eeprom = info.num_eeprom;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2886 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
2887 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
2888 } else if (gen->save_type == SAVE_NOR) {
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2889 memcpy(&gen->nor, info.nor, sizeof(gen->nor));
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2890 //nor_flash_init(&gen->nor, gen->save_storage, gen->save_size, info.save_page_size, info.save_product_id, info.save_bus);
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2891 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2892 } 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
2893 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
2894 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
2895
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2896 gen->mapper_start_index = info.mapper_start_index;
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
2897
2053
3414a4423de1 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1692 2052
diff changeset
2898 tern_node *model = get_model(config, SYSTEM_GENESIS);
3414a4423de1 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1692 2052
diff changeset
2899 uint8_t tmss = !strcmp(tern_find_ptr_default(model, "tmss", "off"), "on");
3414a4423de1 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1692 2052
diff changeset
2900
1165
9fc680b35dbb Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents: 1130
diff changeset
2901 //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
2902 uint8_t next_ptr_index = 0;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2903 uint32_t tmss_min_alloc = 16 * 1024;
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2904 for (int i = 0; i < info.map_chunks; i++)
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2905 {
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2906 if (info.map[i].start == 0xE00000) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2907 info.map[i].buffer = gen->work_ram;
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2908 if (!tmss) {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2909 break;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2910 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2911 }
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2912 if (info.map[i].flags & MMAP_PTR_IDX && info.map[i].ptr_index >= next_ptr_index) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2913 next_ptr_index = info.map[i].ptr_index + 1;
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2914 }
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2915 if (info.map[i].start < 0x400000 && info.map[i].read_16 != unused_read) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2916 uint32_t highest_offset = (info.map[i].end & info.map[i].mask) + 1;
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2917 if (highest_offset > tmss_min_alloc) {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2918 tmss_min_alloc = highest_offset;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2919 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2920 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2921 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2922 if (tmss) {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2923 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
2924 uint8_t *buffer = malloc(tmss_min_alloc);
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2925 uint32_t tmss_size;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2926 if (is_absolute_path(tmss_path)) {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2927 FILE *f = fopen(tmss_path, "rb");
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2928 if (!f) {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2929 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
2930 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2931 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
2932 fclose(f);
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2933 } else {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2934 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
2935 if (!tmp) {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2936 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
2937 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2938 memcpy(buffer, tmp, tmss_size);
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2939 free(tmp);
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2940 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2941 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
2942 {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2943 buffer[tmss_size] = 0xFF;
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2944 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2945 #ifndef BLASTEM_BIG_ENDIAN
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2946 byteswap_rom(tmss_size, (uint16_t *)buffer);
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2947 #endif
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2948 //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
2949 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
2950 {
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2951 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
2952 }
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2953 //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
2954 //WARNING: This code makes some pretty big assumptions about the kinds of map chunks it will encounter
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2955 for (int i = 0; i < info.map_chunks; i++)
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2956 {
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2957 if (info.map[i].start < 0x400000 && info.map[i].read_16 != unused_read) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2958 if (info.map[i].flags == MMAP_READ) {
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2959 //Normal ROM
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2960 info.map[i].flags |= MMAP_PTR_IDX | MMAP_CODE;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2961 info.map[i].ptr_index = next_ptr_index++;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2962 if (info.map[i].ptr_index >= NUM_MEM_AREAS) {
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2963 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
2964 }
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2965 gen->tmss_pointers[info.map[i].ptr_index] = info.map[i].buffer;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2966 info.map[i].buffer = buffer + (info.map[i].start & ~info.map[i].mask & (tmss_size - 1));
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2967 } else if (info.map[i].flags & MMAP_PTR_IDX) {
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2968 //Sega mapper page or multi-game mapper
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2969 gen->tmss_pointers[info.map[i].ptr_index] = info.map[i].buffer;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2970 info.map[i].buffer = buffer + (info.map[i].start & ~info.map[i].mask & (tmss_size - 1));
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2971 if (info.map[i].write_16) {
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2972 if (!gen->tmss_write_16) {
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2973 gen->tmss_write_16 = info.map[i].write_16;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2974 gen->tmss_write_8 = info.map[i].write_8;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2975 info.map[i].write_16 = tmss_rom_write_16;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2976 info.map[i].write_8 = tmss_rom_write_8;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2977 } else if (gen->tmss_write_16 == info.map[i].write_16) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2978 info.map[i].write_16 = tmss_rom_write_16;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2979 info.map[i].write_8 = tmss_rom_write_8;
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2980 } else {
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2981 warning("Chunk starting at %X has a write function, but we've already stored a different one for TMSS remap\n", info.map[i].start);
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2982 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2983 }
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2984 } else if ((info.map[i].flags & (MMAP_READ | MMAP_WRITE)) == (MMAP_READ | MMAP_WRITE)) {
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2985 //RAM or SRAM
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2986 info.map[i].flags |= MMAP_PTR_IDX;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2987 info.map[i].ptr_index = next_ptr_index++;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2988 gen->tmss_pointers[info.map[i].ptr_index] = info.map[i].buffer;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2989 info.map[i].buffer = buffer + (info.map[i].start & ~info.map[i].mask & (tmss_size - 1));
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2990 if (!gen->tmss_write_offset || gen->tmss_write_offset == info.map[i].start) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2991 gen->tmss_write_offset = info.map[i].start;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2992 info.map[i].flags &= ~MMAP_WRITE;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2993 if (info.map[i].flags & MMAP_ONLY_ODD) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2994 info.map[i].write_16 = tmss_odd_write_16;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2995 info.map[i].write_8 = tmss_odd_write_8;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2996 } else if (info.map[i].flags & MMAP_ONLY_EVEN) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2997 info.map[i].write_16 = tmss_even_write_16;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
2998 info.map[i].write_8 = tmss_even_write_8;
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
2999 } else {
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3000 info.map[i].write_16 = tmss_word_write_16;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3001 info.map[i].write_8 = tmss_word_write_8;
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
3002 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
3003 } else {
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3004 warning("Could not remap writes for chunk starting at %X for TMSS because write_offset is %X\n", info.map[i].start, gen->tmss_write_offset);
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
3005 }
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3006 } else if (info.map[i].flags & MMAP_READ_CODE) {
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
3007 //NOR flash
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3008 info.map[i].flags |= MMAP_PTR_IDX;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3009 info.map[i].ptr_index = next_ptr_index++;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3010 if (info.map[i].ptr_index >= NUM_MEM_AREAS) {
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
3011 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
3012 }
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3013 gen->tmss_pointers[info.map[i].ptr_index] = info.map[i].buffer;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3014 info.map[i].buffer = buffer + (info.map[i].start & ~info.map[i].mask & (tmss_size - 1));
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
3015 if (!gen->tmss_write_16) {
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3016 gen->tmss_write_16 = info.map[i].write_16;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3017 gen->tmss_write_8 = info.map[i].write_8;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3018 gen->tmss_read_16 = info.map[i].read_16;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3019 gen->tmss_read_8 = info.map[i].read_8;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3020 info.map[i].write_16 = tmss_rom_write_16;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3021 info.map[i].write_8 = tmss_rom_write_8;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3022 info.map[i].read_16 = tmss_rom_read_16;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3023 info.map[i].read_8 = tmss_rom_read_8;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3024 } else if (gen->tmss_write_16 == info.map[i].write_16) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3025 info.map[i].write_16 = tmss_rom_write_16;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3026 info.map[i].write_8 = tmss_rom_write_8;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3027 info.map[i].read_16 = tmss_rom_read_16;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3028 info.map[i].read_8 = tmss_rom_read_8;
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
3029 } else {
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3030 warning("Chunk starting at %X has a write function, but we've already stored a different one for TMSS remap\n", info.map[i].start);
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
3031 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
3032 } else {
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3033 warning("Didn't remap chunk starting at %X for TMSS because it has flags %X\n", info.map[i].start, info.map[i].flags);
2034
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
3034 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
3035 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
3036 }
8b2ef428d1aa Implement TMSS ROM and cart mapping register
Michael Pavone <pavone@retrodev.com>
parents: 2033
diff changeset
3037 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
3038 }
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3039 memmap_chunk* map = info.map;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3040 uint32_t map_chunks = info.map_chunks;
2088
c716af3f8980 Enable Sega CD emulation for carts if a CD image is "locked-on" even if the cart does not specify that it uses the CD peripheral in the header
Michael Pavone <pavone@retrodev.com>
parents: 2083
diff changeset
3041 if (info.wants_cd || (current_media()->chain && current_media()->chain->type == MEDIA_CDROM)) {
2277
9e578fd493e1 Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2272
diff changeset
3042 gen->header.type = SYSTEM_SEGACD;
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3043 segacd_context *cd = alloc_configure_segacd((system_media *)current_media(), 0, force_region, &info);
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3044 gen->expansion = cd;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3045 gen->version_reg &= ~NO_DISK;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3046 cd->genesis = gen;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3047 uint32_t cd_chunks;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3048 memmap_chunk *cd_map = segacd_main_cpu_map(gen->expansion, 1, &cd_chunks);
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3049 map_chunks = cd_chunks + info.map_chunks;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3050 map = calloc(map_chunks, sizeof(memmap_chunk));
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3051 memcpy(map, info.map, sizeof(memmap_chunk) * (info.map_chunks - 1));
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3052 memcpy(map + info.map_chunks - 1, cd_map, sizeof(memmap_chunk) * cd_chunks);
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3053 memcpy(map + map_chunks - 1, info.map + info.map_chunks - 1, sizeof(memmap_chunk));
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3054 free(info.map);
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3055 int max_ptr_index = -1;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3056 for (int i = 0; i < info.map_chunks - 1; i++)
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3057 {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3058 if (map[i].flags & MMAP_PTR_IDX && map[i].ptr_index > max_ptr_index) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3059 max_ptr_index = map[i].ptr_index;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3060 }
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3061 }
2090
00b6592cad42 Fix typo that messed up Mode 1 for carts with mappers
Michael Pavone <pavone@retrodev.com>
parents: 2088
diff changeset
3062 cd->memptr_start_index = max_ptr_index + 1;
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3063 for (int i = info.map_chunks - 1; i < map_chunks - 1; i++)
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3064 {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3065 if (map[i].flags & MMAP_PTR_IDX) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3066 map[i].ptr_index += cd->memptr_start_index;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3067 }
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3068 }
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3069 cd->base = 0x400000;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
3070 cd->m68k->opts->address_log = (ym_opts & OPT_ADDRESS_LOG) ? fopen("address_sub.log", "w") : NULL;
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3071 }
2248
f7e2e11f1214 Fix improper free of memory map array from rom_info
Michael Pavone <pavone@retrodev.com>
parents: 2243
diff changeset
3072 info.map = gen->header.info.map = NULL;
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3073
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3074 m68k_options *opts = malloc(sizeof(m68k_options));
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
3075 init_m68k_opts(opts, map, map_chunks, MCLKS_PER_68K, sync_components, int_ack);
1901
5433252329fb Set version reg and TAS behavior based on model config
Michael Pavone <pavone@retrodev.com>
parents: 1889
diff changeset
3076 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
3077 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
3078 }
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3079 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
3080 gen->m68k->system = gen;
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3081 opts->address_log = (ym_opts & OPT_ADDRESS_LOG) ? fopen("address.log", "w") : NULL;
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
3082
1165
9fc680b35dbb Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents: 1130
diff changeset
3083 //This must happen after the 68K context has been allocated
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3084 for (int i = 0; i < map_chunks; i++)
1165
9fc680b35dbb Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents: 1130
diff changeset
3085 {
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3086 if (map[i].flags & MMAP_PTR_IDX) {
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3087 gen->m68k->mem_pointers[map[i].ptr_index] = map[i].buffer;
1165
9fc680b35dbb Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents: 1130
diff changeset
3088 }
9fc680b35dbb Fix crash regression for games with some kind of mapper functionality
Michael Pavone <pavone@retrodev.com>
parents: 1130
diff changeset
3089 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 2039
diff changeset
3090
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
3091 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
3092 //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
3093 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
3094 {
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
3095 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
3096 }
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
3097 }
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
3098 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
3099
2277
9e578fd493e1 Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2272
diff changeset
3100 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
3101 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
3102 }
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3103
1692
5dacaef602a7 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1503 1643
diff changeset
3104 genesis_context *alloc_config_genesis_cdboot(system_media *media, uint32_t system_opts, uint8_t force_region)
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3105 {
1692
5dacaef602a7 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1503 1643
diff changeset
3106 tern_node *rom_db = get_rom_db();
5dacaef602a7 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1503 1643
diff changeset
3107 rom_info info = configure_rom(rom_db, media->buffer, media->size, NULL, 0, base_map, base_chunks);
2267
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3108 if (media->size > 0x20B) {
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3109 //Use a byte in the security code region that's unique across all 3 regions
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3110 //since it's more reliable than the official header field for this
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3111 uint8_t *bytes = media->buffer;
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3112 switch (bytes[0x20B])
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3113 {
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3114 case 0x7A:
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3115 info.regions = REGION_U;
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3116 break;
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3117 case 0xA1:
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3118 info.regions = REGION_J;
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3119 break;
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3120 case 0x64:
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3121 info.regions = REGION_E;
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3122 break;
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3123 }
94cca8b8429e Use byte in security code for region identification for Sega/Mega CD discs
Michael Pavone <pavone@retrodev.com>
parents: 2255
diff changeset
3124 }
2053
3414a4423de1 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1692 2052
diff changeset
3125
1692
5dacaef602a7 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1503 1643
diff changeset
3126 segacd_context *cd = alloc_configure_segacd(media, system_opts, force_region, &info);
5dacaef602a7 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1503 1643
diff changeset
3127 genesis_context *gen = shared_init(system_opts, &info, force_region);
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3128 gen->cart = gen->lock_on = NULL;
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3129 gen->save_storage = NULL;
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3130 gen->save_type = SAVE_NONE;
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3131 gen->version_reg &= ~NO_DISK;
2053
3414a4423de1 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1692 2052
diff changeset
3132
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3133 gen->expansion = cd;
2499
d74d3998482c Make some progress on compiling full emulator with new 68K core
Michael Pavone <pavone@retrodev.com>
parents: 2488
diff changeset
3134 cd->m68k->opts->address_log = (system_opts & OPT_ADDRESS_LOG) ? fopen("address_sub.log", "w") : NULL;
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3135 gen->version_reg &= ~NO_DISK;
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3136 cd->genesis = gen;
1692
5dacaef602a7 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1503 1643
diff changeset
3137 setup_io_devices(config, &info, &gen->io);
2053
3414a4423de1 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1692 2052
diff changeset
3138
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3139 uint32_t cd_chunks;
2054
8ee7ecbf3f21 Implement enough of Sega CD gate array and Sub CPU to pass Sik's Mode 1 test ROM
Michael Pavone <pavone@retrodev.com>
parents: 2053
diff changeset
3140 memmap_chunk *cd_map = segacd_main_cpu_map(gen->expansion, 0, &cd_chunks);
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3141 memmap_chunk *map = malloc(sizeof(memmap_chunk) * (cd_chunks + base_chunks));
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3142 memcpy(map, cd_map, sizeof(memmap_chunk) * cd_chunks);
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3143 memcpy(map + cd_chunks, base_map, sizeof(memmap_chunk) * base_chunks);
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3144 map[cd_chunks].buffer = gen->work_ram;
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3145 uint32_t num_chunks = cd_chunks + base_chunks;
2053
3414a4423de1 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1692 2052
diff changeset
3146
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3147 m68k_options *opts = malloc(sizeof(m68k_options));
2350
f8b5142c06aa Allow 68K to return mid-instruction. Adjust how 68K interrupt ack works so int2 busy flag timing is more correct. Fix some other SCD timing issues
Michael Pavone <pavone@retrodev.com>
parents: 2336
diff changeset
3148 init_m68k_opts(opts, map, num_chunks, MCLKS_PER_68K, sync_components, int_ack);
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3149 //TODO: make this configurable
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3150 opts->gen.flags |= M68K_OPT_BROKEN_READ_MODIFY;
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3151 gen->m68k = init_68k_context(opts, NULL);
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3152 gen->m68k->system = gen;
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3153 opts->address_log = (system_opts & OPT_ADDRESS_LOG) ? fopen("address.log", "w") : NULL;
2053
3414a4423de1 Merge from default
Michael Pavone <pavone@retrodev.com>
parents: 1692 2052
diff changeset
3154
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3155 //This must happen after the 68K context has been allocated
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3156 for (int i = 0; i < num_chunks; i++)
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3157 {
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3158 if (map[i].flags & MMAP_PTR_IDX) {
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3159 gen->m68k->mem_pointers[map[i].ptr_index] = map[i].buffer;
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3160 }
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3161 }
2083
372625dd9590 Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents: 2080
diff changeset
3162 gen->header.type = SYSTEM_SEGACD;
2277
9e578fd493e1 Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2272
diff changeset
3163
9e578fd493e1 Implement gain control for Ricoh PCM and CDDA with defaults based on Model 2 Sega CD
Michael Pavone <pavone@retrodev.com>
parents: 2272
diff changeset
3164 set_audio_config(gen);
1503
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3165 return gen;
a763523dadf4 Added code for initializing a combined Genesis + Sega CD system when a Sega CD ISO is loaded
Michael Pavone <pavone@retrodev.com>
parents: 1452
diff changeset
3166 }
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3167
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3168 static memmap_chunk pico_base_map[] = {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3169 {0xE00000, 0x1000000, 0xFFFF, .flags = MMAP_READ | MMAP_WRITE | MMAP_CODE},
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3170 {0xC00000, 0xE00000, 0x1FFFFF, .read_16 = (read_16_fun)vdp_port_read, .write_16 =(write_16_fun)vdp_port_write,
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3171 .read_8 = (read_8_fun)vdp_port_read_b, .write_8 = (write_8_fun)vdp_port_write_b},
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
3172 {0x800000, 0x900000, 0xFFFFFF, .read_16 = pico_io_read_w, .write_16 = pico_io_write_w,
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
3173 .read_8 = pico_io_read, .write_8 = pico_io_write},
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
3174 {0xB00000, 0xC00000, 0xFFFFFF, .read_16 = copera_io_read_w, .write_16 = copera_io_write_w,
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
3175 .read_8 = copera_io_read, .write_8 = copera_io_write}
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3176 };
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3177 const size_t pico_base_chunks = sizeof(pico_base_map)/sizeof(*pico_base_map);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3178
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
3179 genesis_context* alloc_config_pico(void *rom, uint32_t rom_size, void *lock_on, uint32_t lock_on_size, uint32_t ym_opts, uint8_t force_region, system_type stype)
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3180 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3181 tern_node *rom_db = get_rom_db();
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
3182 uint32_t chunks = pico_base_chunks;
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
3183 if (stype == SYSTEM_PICO) {
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
3184 chunks--;
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
3185 }
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
3186 rom_info info = configure_rom(rom_db, rom, rom_size, lock_on, lock_on_size, pico_base_map, chunks);
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3187 rom = info.rom;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3188 rom_size = info.rom_size;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3189 #ifndef BLASTEM_BIG_ENDIAN
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3190 byteswap_rom(nearest_pow2(rom_size), rom);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3191 if (lock_on) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3192 byteswap_rom(nearest_pow2(lock_on_size), lock_on);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3193 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3194 #endif
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3195 char *m68k_divider = tern_find_path(config, "clocks\0m68k_divider\0", TVAL_PTR).ptrval;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3196 if (!m68k_divider) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3197 m68k_divider = "7";
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3198 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3199 MCLKS_PER_68K = atoi(m68k_divider);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3200 if (!MCLKS_PER_68K) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3201 MCLKS_PER_68K = 7;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3202 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3203 genesis_context *gen = calloc(1, sizeof(genesis_context));
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3204 gen->header.set_speed_percent = set_speed_percent;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3205 gen->header.start_context = start_genesis;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3206 gen->header.resume_context = resume_genesis;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3207 gen->header.load_save = load_save;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3208 gen->header.persist_save = persist_save;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3209 gen->header.load_state = load_state;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3210 gen->header.soft_reset = soft_reset;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3211 gen->header.free_context = free_genesis;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3212 gen->header.get_open_bus_value = get_open_bus_value;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3213 gen->header.request_exit = request_exit;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3214 gen->header.inc_debug_mode = inc_debug_mode;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3215 gen->header.gamepad_down = gamepad_down_pico;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3216 gen->header.gamepad_up = gamepad_up_pico;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3217 gen->header.mouse_down = mouse_down_pico;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3218 gen->header.mouse_up = mouse_up_pico;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3219 gen->header.mouse_motion_absolute = mouse_motion_absolute_pico;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3220 gen->header.mouse_motion_relative = mouse_motion_relative_pico;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3221 gen->header.keyboard_down = keyboard_down_pico;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3222 gen->header.keyboard_up = keyboard_up_pico;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3223 gen->header.config_updated = config_updated;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3224 gen->header.serialize = serialize;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3225 gen->header.deserialize = deserialize;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3226 gen->header.start_vgm_log = start_vgm_log;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3227 gen->header.stop_vgm_log = stop_vgm_log;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3228 gen->header.toggle_debug_view = toggle_debug_view;
2459
cb62730d5c99 Initial work on Copera emulation
Michael Pavone <pavone@retrodev.com>
parents: 2438
diff changeset
3229 gen->header.type = stype;
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3230 gen->header.info = info;
2437
79a8cccb6ac1 Add region override for German version of The Lion King for Pico
Michael Pavone <pavone@retrodev.com>
parents: 2433
diff changeset
3231 set_region(gen, &info, force_region);
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3232 gen->vdp_unlocked = 1;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3233 gen->pico_button_state = 0xFF;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3234
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3235 gen->vdp = init_vdp_context((gen->version_reg & 0x60) == 0x20, 40, VDP_GENESIS);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3236 gen->vdp->system = &gen->header;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3237 gen->frame_end = vdp_cycles_to_frame_end(gen->vdp);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3238 char * config_cycles = tern_find_path(config, "clocks\0max_cycles\0", TVAL_PTR).ptrval;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3239 gen->max_cycles = config_cycles ? atoi(config_cycles) : DEFAULT_SYNC_INTERVAL;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3240 gen->int_latency_prev1 = MCLKS_PER_68K * 32;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3241 gen->int_latency_prev2 = MCLKS_PER_68K * 16;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3242
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3243 render_set_video_standard((gen->version_reg & 0x60) == 0x20 ? VID_PAL : VID_NTSC);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3244
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3245 gen->psg = calloc(1, sizeof(psg_context));
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3246 psg_init(gen->psg, gen->master_clock, MCLKS_PER_PSG);
2431
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
3247
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
3248 gen->adpcm = calloc(1, sizeof(pico_pcm));
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
3249 pico_pcm_init(gen->adpcm, gen->master_clock, 42);
61c0bfe10887 Somewhat busted support for Pico ADPCM
Michael Pavone <pavone@retrodev.com>
parents: 2429
diff changeset
3250
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
3251 if (stype == SYSTEM_COPERA) {
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
3252 gen->ymz = calloc(1, sizeof(*gen->ymz));
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
3253 //This divider is just a guess, PCB diagram in MAME shows no other crystal
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
3254 //Datasheet says the typical clock is 16.9344 MHz
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
3255 //Master clock / 3 is 17.897725 MHz which is reasonably close
2558
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
3256 //FIXME: Copera does actually have a separate crystal for these
2466
b5640ac9aea9 Initial stab at PCM/ADPCM support in YMZ263B emulation
Michael Pavone <pavone@retrodev.com>
parents: 2460
diff changeset
3257 ymz263b_init(gen->ymz, gen->master_clock, 3);
2558
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
3258 gen->opl = calloc(1, sizeof(*gen->opl));
3f58fec775df Initial work on YMF262 (aka OPL3) emulation
Michael Pavone <pavone@retrodev.com>
parents: 2556
diff changeset
3259 ymf262_init(gen->opl, gen->master_clock, 3, ym_opts);
2460
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
3260 }
a4f8fa24764b Initial work on emulating the YMZ263B in the Copera
Michael Pavone <pavone@retrodev.com>
parents: 2459
diff changeset
3261
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3262 gen->work_ram = calloc(2, RAM_WORDS);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3263 if (!strcmp("random", tern_find_path_default(config, "system\0ram_init\0", (tern_val){.ptrval = "zero"}, TVAL_PTR).ptrval))
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3264 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3265 srand(time(NULL));
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3266 for (int i = 0; i < RAM_WORDS; i++)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3267 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3268 gen->work_ram[i] = rand();
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3269 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3270 for (int i = 0; i < VRAM_SIZE; i++)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3271 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3272 gen->vdp->vdpmem[i] = rand();
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3273 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3274 for (int i = 0; i < SAT_CACHE_SIZE; i++)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3275 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3276 gen->vdp->sat_cache[i] = rand();
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3277 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3278 for (int i = 0; i < CRAM_SIZE; i++)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3279 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3280 write_cram_internal(gen->vdp, i, rand());
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3281 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3282 for (int i = 0; i < gen->vdp->vsram_size; i++)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3283 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3284 gen->vdp->vsram[i] = rand();
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3285 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3286 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3287 gen->cart = rom;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3288 gen->lock_on = lock_on;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3289 gen->header.has_keyboard = 0; //TODO: Keyboard Pico emulation
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3290 gen->mapper_type = info.mapper_type;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3291 gen->save_type = info.save_type;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3292 if (gen->save_type != SAVE_NONE) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3293 gen->save_ram_mask = info.save_mask;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3294 gen->save_size = info.save_size;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3295 gen->save_storage = info.save_buffer;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3296 gen->header.info.save_buffer = info.save_buffer = NULL;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3297 gen->eeprom_map = info.eeprom_map;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3298 gen->num_eeprom = info.num_eeprom;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3299 if (gen->save_type == SAVE_I2C) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3300 eeprom_init(&gen->eeprom, gen->save_storage, gen->save_size);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3301 } else if (gen->save_type == SAVE_NOR) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3302 memcpy(&gen->nor, info.nor, sizeof(gen->nor));
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3303 //nor_flash_init(&gen->nor, gen->save_storage, gen->save_size, info.save_page_size, info.save_product_id, info.save_bus);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3304 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3305 } else {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3306 gen->save_storage = NULL;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3307 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3308
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3309 gen->mapper_start_index = info.mapper_start_index;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3310 //This must happen before we generate memory access functions in init_m68k_opts
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3311 for (int i = 0; i < info.map_chunks; i++)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3312 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3313 if (info.map[i].start == 0xE00000) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3314 info.map[i].buffer = gen->work_ram;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3315 break;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3316 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3317 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3318
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3319 memmap_chunk* map = info.map;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3320 uint32_t map_chunks = info.map_chunks;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3321 info.map = gen->header.info.map = NULL;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3322
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3323 m68k_options *opts = malloc(sizeof(m68k_options));
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3324 init_m68k_opts(opts, map, map_chunks, MCLKS_PER_68K, sync_components_pico, int_ack);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3325 //TODO: Pico model selection
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3326 //if (!strcmp(tern_find_ptr_default(model, "tas", "broken"), "broken")) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3327 opts->gen.flags |= M68K_OPT_BROKEN_READ_MODIFY;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3328 //}
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3329 gen->m68k = init_68k_context(opts, NULL);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3330 gen->m68k->system = gen;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3331 opts->address_log = (ym_opts & OPT_ADDRESS_LOG) ? fopen("address.log", "w") : NULL;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3332
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3333 //This must happen after the 68K context has been allocated
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3334 for (int i = 0; i < map_chunks; i++)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3335 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3336 if (map[i].flags & MMAP_PTR_IDX) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3337 gen->m68k->mem_pointers[map[i].ptr_index] = map[i].buffer;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3338 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3339 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3340
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3341 if (gen->mapper_type == MAPPER_SEGA) {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3342 //initialize bank registers
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3343 for (int i = 1; i < sizeof(gen->bank_regs); i++)
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3344 {
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3345 gen->bank_regs[i] = i;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3346 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3347 }
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3348 gen->reset_cycle = CYCLE_NEVER;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3349
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3350 set_audio_config(gen);
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3351 bindings_set_mouse_mode(MOUSE_ABSOLUTE);
2429
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
3352 memset(gen->pico_story_pages, 0xFF, sizeof(gen->pico_story_pages));
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
3353 #ifndef IS_LIB
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
3354 gen->pico_story_window = render_create_window("Pico Storybook & Pad", 640, 640, NULL);
2438
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3355 char *manifest_name = alloc_concat(current_media()->name, ".manifest");
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3356 char *manifest_str = load_media_subfile(current_media(), manifest_name, NULL);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3357 tern_node *manifest = NULL;
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3358 if (manifest_str) {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3359 manifest = parse_config(manifest_str);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3360 if (!manifest) {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3361 printf("Failed to parse manifest %s\n", manifest_name);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3362 }
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3363 } else {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3364 printf("Manifest file %s not found\n", manifest_name);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3365 }
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3366
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3367 tern_node *pages = tern_find_node(manifest, "pages");
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3368 if (!pages && manifest) {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3369 printf("No pages key in %s\n", manifest_name);
2429
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
3370 }
2438
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3371 char numkey[18];
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3372 for (int i = 0; i < 7; i++) {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3373 uint8_t *img_data;
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3374 uint32_t img_size;
2429
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
3375 if (pages) {
2438
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3376 sprintf(numkey, "%d", i);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3377 char *page_path = tern_find_ptr(pages, numkey);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3378 if (page_path) {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3379 printf("page %d: %s\n", i, page_path);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3380 } else {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3381 continue;
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3382 }
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3383 img_data = load_media_subfile(current_media(), page_path, &img_size);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3384 if (!img_data) {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3385 printf("Failed to load image file for page %d from %s\n", i, page_path);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3386 continue;
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3387 }
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3388 } else {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3389 sprintf(numkey, "_%d.png", i);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3390 char *img_path = alloc_concat(current_media()->name, numkey);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3391 img_data = load_media_subfile(current_media(), img_path, &img_size);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3392 if (!img_data) {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3393 sprintf(numkey, "_%d.PNG", i);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3394 char *img_path_loud = alloc_concat(current_media()->name, numkey);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3395 img_data = load_media_subfile(current_media(), img_path_loud, &img_size);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3396 if (!img_data) {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3397 printf("Failed to load image file for page %d from %s or %s\n", i, img_path, img_path_loud);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3398 free(img_path);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3399 free(img_path_loud);
2429
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
3400 continue;
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
3401 }
2438
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3402 free(img_path_loud);
2429
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
3403 }
2438
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3404 free(img_path);
2429
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
3405 }
2438
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3406
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3407 gen->pico_story_pages[i] = render_static_image(gen->pico_story_window, img_data, img_size);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3408 if (gen->pico_story_pages[i] == 0xFF) {
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3409 printf("Failed to decode image for page %d\n", i);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3410 }
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3411 free(img_data);
2429
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
3412 }
2438
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3413
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3414 free(manifest_name);
bed4d3db8a3f More flexible loading of Pico storyware assets
Michael Pavone <pavone@retrodev.com>
parents: 2437
diff changeset
3415 tern_free(manifest);
2429
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
3416 pico_update_page(gen);
da3dc881d3f0 Initial implementation of storbook artwork display
Michael Pavone <pavone@retrodev.com>
parents: 2428
diff changeset
3417 #endif
2428
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3418 return gen;
65c2e4d990cc WIP Pico emulation
Michael Pavone <pavone@retrodev.com>
parents: 2424
diff changeset
3419 }