Mercurial > repos > blastem
annotate sms.c @ 1862:e07fc3d473b2
Basic UI navigation with controller
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 08 May 2019 23:44:40 -0700 |
parents | 51417bb557b6 |
children | 49f65d240299 2d462aa78349 |
rev | line source |
---|---|
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <string.h> |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <stdlib.h> |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include <stddef.h> |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include "sms.h" |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 #include "blastem.h" |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "render.h" |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include "util.h" |
1129
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
8 #include "debug.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:
1433
diff
changeset
|
9 #include "saves.h" |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
10 #include "bindings.h" |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 |
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
|
12 #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
|
13 #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
|
14 #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
|
15 #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
|
16 #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
|
17 #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
|
18 #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
|
19 #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
|
20 |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 static void *memory_io_write(uint32_t location, void *vcontext, uint8_t value) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 z80_context *z80 = vcontext; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 sms_context *sms = z80->system; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 if (location & 1) { |
1154
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
26 uint8_t fuzzy_ctrl_0 = sms->io.ports[0].control, fuzzy_ctrl_1 = sms->io.ports[1].control; |
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
|
27 io_control_write(sms->io.ports, (~value) << 5 & 0x60, z80->Z80_CYCLE); |
1154
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
28 fuzzy_ctrl_0 |= sms->io.ports[0].control; |
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
|
29 io_control_write(sms->io.ports+1, (~value) << 3 & 0x60, z80->Z80_CYCLE); |
1154
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
30 fuzzy_ctrl_1 |= sms->io.ports[1].control; |
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
31 if ( |
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
32 (fuzzy_ctrl_0 & 0x40 & (sms->io.ports[0].output ^ (value << 1)) & (value << 1)) |
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
33 || (fuzzy_ctrl_0 & 0x40 & (sms->io.ports[1].output ^ (value >> 1)) & (value >> 1)) |
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
34 ) { |
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
35 //TH is an output and it went from 0 -> 1 |
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
|
36 vdp_run_context(sms->vdp, z80->Z80_CYCLE); |
1154
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
37 vdp_latch_hv(sms->vdp); |
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
38 } |
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
|
39 io_data_write(sms->io.ports, value << 1, z80->Z80_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
|
40 io_data_write(sms->io.ports + 1, value >> 1, z80->Z80_CYCLE); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 } else { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 //TODO: memory control write |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 return vcontext; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 static uint8_t hv_read(uint32_t location, void *vcontext) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 z80_context *z80 = vcontext; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 sms_context *sms = z80->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
|
51 vdp_run_context(sms->vdp, z80->Z80_CYCLE); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 uint16_t hv = vdp_hv_counter_read(sms->vdp); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 if (location & 1) { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 return hv; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 } else { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 return hv >> 8; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 static void *sms_psg_write(uint32_t location, void *vcontext, uint8_t value) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 z80_context *z80 = vcontext; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 sms_context *sms = z80->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
|
64 psg_run(sms->psg, z80->Z80_CYCLE); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 psg_write(sms->psg, value); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 return vcontext; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 static void update_interrupts(sms_context *sms) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 uint32_t vint = vdp_next_vint(sms->vdp); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 uint32_t hint = vdp_next_hint(sms->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
|
73 #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
|
74 sms->z80->int_cycle = vint < hint ? vint : hint; |
1759
6e4faa10f9ee
Store sync_cycle in context rather than in a local in CPU DSL. Fix the timing of a number of instructions in new Z80 core
Michael Pavone <pavone@retrodev.com>
parents:
1752
diff
changeset
|
75 z80_sync_cycle(sms->z80, sms->z80->sync_cycle); |
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
|
76 #else |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 sms->z80->int_pulse_start = vint < hint ? vint : hint; |
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
|
78 #endif |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 static uint8_t vdp_read(uint32_t location, void *vcontext) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 z80_context *z80 = vcontext; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 sms_context *sms = z80->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
|
85 vdp_run_context(sms->vdp, z80->Z80_CYCLE); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 if (location & 1) { |
1126
63cd87d910cc
Clear interrupt status flags after getting the status register value rather than before
Michael Pavone <pavone@retrodev.com>
parents:
1120
diff
changeset
|
87 uint8_t ret = vdp_control_port_read(sms->vdp); |
1119
55ea7f9a4e92
Fix clearing of interrupt pending flags on control port read in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
88 sms->vdp->flags2 &= ~(FLAG2_VINT_PENDING|FLAG2_HINT_PENDING); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 update_interrupts(sms); |
1126
63cd87d910cc
Clear interrupt status flags after getting the status register value rather than before
Michael Pavone <pavone@retrodev.com>
parents:
1120
diff
changeset
|
90 return ret; |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 } else { |
1149
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
92 return vdp_data_port_read_pbc(sms->vdp); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 static void *vdp_write(uint32_t location, void *vcontext, uint8_t value) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 z80_context *z80 = vcontext; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 sms_context *sms = z80->system; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 if (location & 1) { |
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
|
101 vdp_run_context_full(sms->vdp, z80->Z80_CYCLE); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 vdp_control_port_write_pbc(sms->vdp, value); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 update_interrupts(sms); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 } 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
|
105 vdp_run_context(sms->vdp, z80->Z80_CYCLE); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 vdp_data_port_write_pbc(sms->vdp, value); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 return vcontext; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 static uint8_t io_read(uint32_t location, void *vcontext) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 z80_context *z80 = vcontext; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 sms_context *sms = z80->system; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 if (location == 0xC0 || location == 0xDC) { |
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
|
116 uint8_t port_a = io_data_read(sms->io.ports, z80->Z80_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
|
117 uint8_t port_b = io_data_read(sms->io.ports+1, z80->Z80_CYCLE); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 return (port_a & 0x3F) | (port_b << 6); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 if (location == 0xC1 || location == 0xDD) { |
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
|
121 uint8_t port_a = io_data_read(sms->io.ports, z80->Z80_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
|
122 uint8_t port_b = io_data_read(sms->io.ports+1, z80->Z80_CYCLE); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 return (port_a & 0x40) | (port_b >> 2 & 0xF) | (port_b << 1 & 0x80) | 0x10; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 return 0xFF; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
128 static void update_mem_map(uint32_t location, sms_context *sms, uint8_t value) |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
129 { |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
130 z80_context *z80 = sms->z80; |
1142
5c8b1c33ca10
Invalidate translated code on a cartridge bank change in SMS mode. Fix handling of bank 0
Michael Pavone <pavone@retrodev.com>
parents:
1141
diff
changeset
|
131 void *old_value; |
5c8b1c33ca10
Invalidate translated code on a cartridge bank change in SMS mode. Fix handling of bank 0
Michael Pavone <pavone@retrodev.com>
parents:
1141
diff
changeset
|
132 if (location) { |
5c8b1c33ca10
Invalidate translated code on a cartridge bank change in SMS mode. Fix handling of bank 0
Michael Pavone <pavone@retrodev.com>
parents:
1141
diff
changeset
|
133 uint32_t idx = location - 1; |
5c8b1c33ca10
Invalidate translated code on a cartridge bank change in SMS mode. Fix handling of bank 0
Michael Pavone <pavone@retrodev.com>
parents:
1141
diff
changeset
|
134 old_value = z80->mem_pointers[idx]; |
5c8b1c33ca10
Invalidate translated code on a cartridge bank change in SMS mode. Fix handling of bank 0
Michael Pavone <pavone@retrodev.com>
parents:
1141
diff
changeset
|
135 z80->mem_pointers[idx] = sms->rom + (value << 14 & (sms->rom_size-1)); |
5c8b1c33ca10
Invalidate translated code on a cartridge bank change in SMS mode. Fix handling of bank 0
Michael Pavone <pavone@retrodev.com>
parents:
1141
diff
changeset
|
136 if (old_value != z80->mem_pointers[idx]) { |
5c8b1c33ca10
Invalidate translated code on a cartridge bank change in SMS mode. Fix handling of bank 0
Michael Pavone <pavone@retrodev.com>
parents:
1141
diff
changeset
|
137 //invalidate any code we translated for the relevant bank |
5c8b1c33ca10
Invalidate translated code on a cartridge bank change in SMS mode. Fix handling of bank 0
Michael Pavone <pavone@retrodev.com>
parents:
1141
diff
changeset
|
138 z80_invalidate_code_range(z80, idx ? idx * 0x4000 : 0x400, idx * 0x4000 + 0x4000); |
5c8b1c33ca10
Invalidate translated code on a cartridge bank change in SMS mode. Fix handling of bank 0
Michael Pavone <pavone@retrodev.com>
parents:
1141
diff
changeset
|
139 } |
5c8b1c33ca10
Invalidate translated code on a cartridge bank change in SMS mode. Fix handling of bank 0
Michael Pavone <pavone@retrodev.com>
parents:
1141
diff
changeset
|
140 } else { |
1149
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
141 old_value = z80->mem_pointers[2]; |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
142 if (value & 8) { |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
143 //cartridge RAM is enabled |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
144 z80->mem_pointers[2] = sms->cart_ram + (value & 4 ? (SMS_CART_RAM_SIZE/2) : 0); |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
145 } else { |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
146 //cartridge RAM is disabled |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
147 z80->mem_pointers[2] = sms->rom + (sms->bank_regs[3] << 14 & (sms->rom_size-1)); |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
148 } |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
149 if (old_value != z80->mem_pointers[2]) { |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
150 //invalidate any code we translated for the relevant bank |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
151 z80_invalidate_code_range(z80, 0x8000, 0xC000); |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
152 } |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
153 } |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
154 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
155 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
156 static void *mapper_write(uint32_t location, void *vcontext, uint8_t value) |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
157 { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
158 z80_context *z80 = vcontext; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
159 sms_context *sms = z80->system; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
160 location &= 3; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
161 sms->ram[0x1FFC + location] = value; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
162 sms->bank_regs[location] = value; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
163 update_mem_map(location, sms, value); |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
164 return vcontext; |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
165 } |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
166 |
1149
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
167 static void *cart_ram_write(uint32_t location, void *vcontext, uint8_t value) |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
168 { |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
169 z80_context *z80 = vcontext; |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
170 sms_context *sms = z80->system; |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
171 if (sms->bank_regs[0] & 8) { |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
172 //cartridge RAM is enabled |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
173 location &= 0x3FFF; |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
174 z80->mem_pointers[2][location] = value; |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
175 z80_handle_code_write(0x8000 + location, z80); |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
176 } |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
177 return vcontext; |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
178 } |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
179 |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
180 uint8_t debug_commands(system_header *system, char *input_buf) |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
181 { |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
182 sms_context *sms = (sms_context *)system; |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
183 switch(input_buf[0]) |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
184 { |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
185 case 'v': |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
186 if (input_buf[1] == 'r') { |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
187 vdp_print_reg_explain(sms->vdp); |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
188 } else if (input_buf[1] == 's') { |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
189 vdp_print_sprite_table(sms->vdp); |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
190 } else { |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
191 return 0; |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
192 } |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
193 break; |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
194 } |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
195 return 1; |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
196 } |
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
197 |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 static memmap_chunk io_map[] = { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 {0x00, 0x40, 0xFF, 0, 0, 0, NULL, NULL, NULL, NULL, memory_io_write}, |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 {0x40, 0x80, 0xFF, 0, 0, 0, NULL, NULL, NULL, hv_read, sms_psg_write}, |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 {0x80, 0xC0, 0xFF, 0, 0, 0, NULL, NULL, NULL, vdp_read, vdp_write}, |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 {0xC0, 0x100,0xFF, 0, 0, 0, NULL, NULL, NULL, io_read, NULL} |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 }; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 static void set_speed_percent(system_header * system, uint32_t percent) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 sms_context *context = (sms_context *)system; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 uint32_t old_clock = context->master_clock; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 context->master_clock = ((uint64_t)context->normal_clock * (uint64_t)percent) / 100; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 psg_adjust_master_clock(context->psg, context->master_clock); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
214 void sms_serialize(sms_context *sms, serialize_buffer *buf) |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
215 { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
216 start_section(buf, SECTION_Z80); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
217 z80_serialize(sms->z80, buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
218 end_section(buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
219 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
220 start_section(buf, SECTION_VDP); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
221 vdp_serialize(sms->vdp, buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
222 end_section(buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
223 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
224 start_section(buf, SECTION_PSG); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
225 psg_serialize(sms->psg, buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
226 end_section(buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
227 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
228 start_section(buf, SECTION_SEGA_IO_1); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
229 io_serialize(sms->io.ports, buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
230 end_section(buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
231 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
232 start_section(buf, SECTION_SEGA_IO_2); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
233 io_serialize(sms->io.ports + 1, buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
234 end_section(buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
235 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
236 start_section(buf, SECTION_MAIN_RAM); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
237 save_int8(buf, sizeof(sms->ram) / 1024); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
238 save_buffer8(buf, sms->ram, sizeof(sms->ram)); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
239 end_section(buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
240 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
241 start_section(buf, SECTION_MAPPER); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
242 save_int8(buf, 1);//mapper type, 1 for Sega mapper |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
243 save_buffer8(buf, sms->bank_regs, sizeof(sms->bank_regs)); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
244 end_section(buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
245 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
246 start_section(buf, SECTION_CART_RAM); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
247 save_int8(buf, SMS_CART_RAM_SIZE / 1024); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
248 save_buffer8(buf, sms->cart_ram, SMS_CART_RAM_SIZE); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
249 end_section(buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
250 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
251 |
1690
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
252 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
|
253 { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
254 sms_context *sms = (sms_context *)sys; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
255 serialize_buffer state; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
256 init_serialize(&state); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
257 sms_serialize(sms, &state); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
258 if (size_out) { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
259 *size_out = state.size; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
260 } |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
261 return state.data; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
262 } |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
263 |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
264 static void ram_deserialize(deserialize_buffer *buf, void *vsms) |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
265 { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
266 sms_context *sms = vsms; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
267 uint32_t ram_size = load_int8(buf) * 1024; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
268 if (ram_size > sizeof(sms->ram)) { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
269 fatal_error("State has a RAM size of %d bytes", ram_size); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
270 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
271 load_buffer8(buf, sms->ram, ram_size); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
272 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
273 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
274 static void cart_ram_deserialize(deserialize_buffer *buf, void *vsms) |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
275 { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
276 sms_context *sms = vsms; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
277 uint32_t ram_size = load_int8(buf) * 1024; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
278 if (ram_size > SMS_CART_RAM_SIZE) { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
279 fatal_error("State has a cart RAM size of %d bytes", ram_size); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
280 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
281 load_buffer8(buf, sms->cart_ram, ram_size); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
282 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
283 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
284 static void mapper_deserialize(deserialize_buffer *buf, void *vsms) |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
285 { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
286 sms_context *sms = vsms; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
287 uint8_t mapper_type = load_int8(buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
288 if (mapper_type != 1) { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
289 warning("State contains an unrecognized mapper type %d, it may be from a newer version of BlastEm\n", mapper_type); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
290 return; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
291 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
292 for (int i = 0; i < sizeof(sms->bank_regs); i++) |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
293 { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
294 sms->bank_regs[i] = load_int8(buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
295 update_mem_map(i, sms, sms->bank_regs[i]); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
296 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
297 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
298 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
299 void sms_deserialize(deserialize_buffer *buf, sms_context *sms) |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
300 { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
301 register_section_handler(buf, (section_handler){.fun = z80_deserialize, .data = sms->z80}, SECTION_Z80); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
302 register_section_handler(buf, (section_handler){.fun = vdp_deserialize, .data = sms->vdp}, SECTION_VDP); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
303 register_section_handler(buf, (section_handler){.fun = psg_deserialize, .data = sms->psg}, SECTION_PSG); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
304 register_section_handler(buf, (section_handler){.fun = io_deserialize, .data = sms->io.ports}, SECTION_SEGA_IO_1); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
305 register_section_handler(buf, (section_handler){.fun = io_deserialize, .data = sms->io.ports + 1}, SECTION_SEGA_IO_2); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
306 register_section_handler(buf, (section_handler){.fun = ram_deserialize, .data = sms}, SECTION_MAIN_RAM); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
307 register_section_handler(buf, (section_handler){.fun = mapper_deserialize, .data = sms}, SECTION_MAPPER); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
308 register_section_handler(buf, (section_handler){.fun = cart_ram_deserialize, .data = sms}, SECTION_CART_RAM); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
309 //TODO: cart RAM |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
310 while (buf->cur_pos < buf->size) |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
311 { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
312 load_section(buf); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
313 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
314 z80_invalidate_code_range(sms->z80, 0xC000, 0x10000); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
315 if (sms->bank_regs[0] & 8) { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
316 //cart RAM is enabled, invalidate the region in case there is any code there |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
317 z80_invalidate_code_range(sms->z80, 0x8000, 0xC000); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
318 } |
1690
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
319 free(buf->handlers); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
320 buf->handlers = NULL; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
321 } |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
322 |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
323 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
|
324 { |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
325 sms_context *sms = (sms_context *)sys; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
326 deserialize_buffer buffer; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
327 init_deserialize(&buffer, data, size); |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
328 sms_deserialize(&buffer, sms); |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
329 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
330 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
331 static void save_state(sms_context *sms, uint8_t slot) |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
332 { |
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:
1433
diff
changeset
|
333 char *save_path = get_slot_name(&sms->header, slot, "state"); |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
334 serialize_buffer state; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
335 init_serialize(&state); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
336 sms_serialize(sms, &state); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
337 save_to_file(&state, save_path); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
338 printf("Saved state to %s\n", save_path); |
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:
1433
diff
changeset
|
339 free(save_path); |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
340 free(state.data); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
341 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
342 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
343 static uint8_t load_state_path(sms_context *sms, char *path) |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
344 { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
345 deserialize_buffer state; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
346 uint8_t ret; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
347 if ((ret = load_from_file(&state, path))) { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
348 sms_deserialize(&state, sms); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
349 free(state.data); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
350 printf("Loaded %s\n", path); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
351 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
352 return ret; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
353 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
354 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
355 static uint8_t load_state(system_header *system, uint8_t slot) |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
356 { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
357 sms_context *sms = (sms_context *)system; |
1480
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
358 char *statepath = get_slot_name(system, slot, "state"); |
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
359 uint8_t ret; |
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
|
360 #ifndef NEW_CORE |
1480
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
361 if (!sms->z80->native_pc) { |
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
362 ret = get_modification_time(statepath) != 0; |
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
363 if (ret) { |
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
364 system->delayed_load_slot = slot + 1; |
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
365 } |
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
366 goto done; |
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
367 |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
368 } |
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
|
369 #endif |
1480
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
370 ret = load_state_path(sms, statepath); |
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
371 done: |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
372 free(statepath); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
373 return ret; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
374 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
375 |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
376 static void run_sms(system_header *system) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
377 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
378 sms_context *sms = (sms_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
|
379 uint32_t target_cycle = sms->z80->Z80_CYCLE + 3420*16; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1162
diff
changeset
|
380 //TODO: PAL support |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1162
diff
changeset
|
381 render_set_video_standard(VID_NTSC); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
382 while (!sms->should_return) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
383 { |
1480
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
384 if (system->delayed_load_slot) { |
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
385 load_state(system, system->delayed_load_slot - 1); |
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
386 system->delayed_load_slot = 0; |
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
387 |
8464a3f09b94
Get SMS savestates working in Nuklear UI
Michael Pavone <pavone@retrodev.com>
parents:
1478
diff
changeset
|
388 } |
1129
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
389 if (system->enter_debugger && sms->z80->pc) { |
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
390 system->enter_debugger = 0; |
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
391 zdebugger(sms->z80, sms->z80->pc); |
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
392 } |
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
|
393 #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
|
394 if (sms->z80->nmi_cycle == CYCLE_NEVER) { |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
395 #else |
1377
e587f16e7d3d
Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
396 if (sms->z80->nmi_start == CYCLE_NEVER) { |
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
|
397 #endif |
1377
e587f16e7d3d
Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
398 uint32_t nmi = vdp_next_nmi(sms->vdp); |
e587f16e7d3d
Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
399 if (nmi != CYCLE_NEVER) { |
e587f16e7d3d
Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
400 z80_assert_nmi(sms->z80, nmi); |
e587f16e7d3d
Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
401 } |
e587f16e7d3d
Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
402 } |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 z80_run(sms->z80, target_cycle); |
1209
5ee6b6345ea9
Implement SMS hardware soft reset (note only available on real hardware on the Genesis in PBC mode)
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
404 if (sms->z80->reset) { |
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
|
405 z80_clear_reset(sms->z80, sms->z80->Z80_CYCLE + 128*15); |
1209
5ee6b6345ea9
Implement SMS hardware soft reset (note only available on real hardware on the Genesis in PBC mode)
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
406 } |
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
|
407 target_cycle = sms->z80->Z80_CYCLE; |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 vdp_run_context(sms->vdp, target_cycle); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
409 psg_run(sms->psg, target_cycle); |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
410 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
411 if (system->save_state) { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
412 while (!sms->z80->pc) { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
413 //advance Z80 to an instruction boundary |
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
|
414 z80_run(sms->z80, sms->z80->Z80_CYCLE + 1); |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
415 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
416 save_state(sms, system->save_state - 1); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
417 system->save_state = 0; |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
418 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
419 |
1377
e587f16e7d3d
Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
420 target_cycle += 3420*16; |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 if (target_cycle > 0x10000000) { |
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
|
422 uint32_t adjust = sms->z80->Z80_CYCLE - 3420*262*2; |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
423 io_adjust_cycles(sms->io.ports, sms->z80->Z80_CYCLE, adjust); |
d6d4c006a7b3
Initial attempt at interrupts in new Z80 core and integrating it into main executable
Michael Pavone <pavone@retrodev.com>
parents:
1690
diff
changeset
|
424 io_adjust_cycles(sms->io.ports+1, sms->z80->Z80_CYCLE, adjust); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 z80_adjust_cycles(sms->z80, adjust); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 vdp_adjust_cycles(sms->vdp, adjust); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
427 sms->psg->cycles -= adjust; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
428 target_cycle -= adjust; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
429 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
430 } |
1688
395f684c5379
Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
431 #ifndef IS_LIB |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
432 bindings_release_capture(); |
1401
b56c8c51ca5d
Properly release and reacquire framebuffer pointer when switching contexts. Hopefully fixes the LOCKRECT issue some people are seeing with the SDL 2 fallback renderer
Michael Pavone <pavone@retrodev.com>
parents:
1384
diff
changeset
|
433 vdp_release_framebuffer(sms->vdp); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1480
diff
changeset
|
434 render_pause_source(sms->psg->audio); |
1688
395f684c5379
Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
435 #endif |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 sms->should_return = 0; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
437 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
438 |
1401
b56c8c51ca5d
Properly release and reacquire framebuffer pointer when switching contexts. Hopefully fixes the LOCKRECT issue some people are seeing with the SDL 2 fallback renderer
Michael Pavone <pavone@retrodev.com>
parents:
1384
diff
changeset
|
439 static void resume_sms(system_header *system) |
b56c8c51ca5d
Properly release and reacquire framebuffer pointer when switching contexts. Hopefully fixes the LOCKRECT issue some people are seeing with the SDL 2 fallback renderer
Michael Pavone <pavone@retrodev.com>
parents:
1384
diff
changeset
|
440 { |
b56c8c51ca5d
Properly release and reacquire framebuffer pointer when switching contexts. Hopefully fixes the LOCKRECT issue some people are seeing with the SDL 2 fallback renderer
Michael Pavone <pavone@retrodev.com>
parents:
1384
diff
changeset
|
441 sms_context *sms = (sms_context *)system; |
1688
395f684c5379
Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
442 #ifndef IS_LIB |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
443 bindings_reacquire_capture(); |
1401
b56c8c51ca5d
Properly release and reacquire framebuffer pointer when switching contexts. Hopefully fixes the LOCKRECT issue some people are seeing with the SDL 2 fallback renderer
Michael Pavone <pavone@retrodev.com>
parents:
1384
diff
changeset
|
444 vdp_reacquire_framebuffer(sms->vdp); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1480
diff
changeset
|
445 render_resume_source(sms->psg->audio); |
1688
395f684c5379
Fixed the most glaring issues in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
446 #endif |
1401
b56c8c51ca5d
Properly release and reacquire framebuffer pointer when switching contexts. Hopefully fixes the LOCKRECT issue some people are seeing with the SDL 2 fallback renderer
Michael Pavone <pavone@retrodev.com>
parents:
1384
diff
changeset
|
447 run_sms(system); |
b56c8c51ca5d
Properly release and reacquire framebuffer pointer when switching contexts. Hopefully fixes the LOCKRECT issue some people are seeing with the SDL 2 fallback renderer
Michael Pavone <pavone@retrodev.com>
parents:
1384
diff
changeset
|
448 } |
b56c8c51ca5d
Properly release and reacquire framebuffer pointer when switching contexts. Hopefully fixes the LOCKRECT issue some people are seeing with the SDL 2 fallback renderer
Michael Pavone <pavone@retrodev.com>
parents:
1384
diff
changeset
|
449 |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
450 static void start_sms(system_header *system, char *statefile) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
451 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
452 sms_context *sms = (sms_context *)system; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
453 |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
454 z80_assert_reset(sms->z80, 0); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
455 z80_clear_reset(sms->z80, 128*15); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
456 |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
457 if (statefile) { |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
458 load_state_path(sms, statefile); |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
459 } |
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
460 |
1129
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
461 if (system->enter_debugger) { |
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
462 system->enter_debugger = 0; |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
463 zinsert_breakpoint(sms->z80, sms->z80->pc, (uint8_t *)zdebugger); |
1129
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
464 } |
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
465 |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
466 run_sms(system); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
467 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
468 |
1209
5ee6b6345ea9
Implement SMS hardware soft reset (note only available on real hardware on the Genesis in PBC mode)
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
469 static void soft_reset(system_header *system) |
5ee6b6345ea9
Implement SMS hardware soft reset (note only available on real hardware on the Genesis in PBC mode)
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
470 { |
5ee6b6345ea9
Implement SMS hardware soft reset (note only available on real hardware on the Genesis in PBC mode)
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
471 sms_context *sms = (sms_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
|
472 z80_assert_reset(sms->z80, sms->z80->Z80_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
|
473 #ifndef 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
|
474 sms->z80->target_cycle = sms->z80->sync_cycle = sms->z80->Z80_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
|
475 #endif |
1209
5ee6b6345ea9
Implement SMS hardware soft reset (note only available on real hardware on the Genesis in PBC mode)
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
476 } |
5ee6b6345ea9
Implement SMS hardware soft reset (note only available on real hardware on the Genesis in PBC mode)
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
477 |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
478 static void free_sms(system_header *system) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
479 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
480 sms_context *sms = (sms_context *)system; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
481 vdp_free(sms->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
|
482 z80_options_free(sms->z80->Z80_OPTS); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
483 free(sms->z80); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
484 psg_free(sms->psg); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 free(sms); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
486 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
487 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 static uint16_t get_open_bus_value(system_header *system) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
489 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
490 return 0xFFFF; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
491 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
492 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
493 static void request_exit(system_header *system) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
494 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
495 sms_context *sms = (sms_context *)system; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
496 sms->should_return = 1; |
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
|
497 #ifndef 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
|
498 sms->z80->target_cycle = sms->z80->sync_cycle = sms->z80->Z80_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
|
499 #endif |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
500 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
501 |
1120
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
502 static void inc_debug_mode(system_header *system) |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
503 { |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
504 sms_context *sms = (sms_context *)system; |
1643
6909c5d0bbb5
Removed old VDP debug functionality
Michael Pavone <pavone@retrodev.com>
parents:
1640
diff
changeset
|
505 vdp_inc_debug_mode(sms->vdp); |
1120
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
506 } |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
507 |
1384
1df16f5985f3
Added stub load_save and persist_save functions to SMS system so that we don't crash when switching games via the menu
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
508 static void load_save(system_header *system) |
1df16f5985f3
Added stub load_save and persist_save functions to SMS system so that we don't crash when switching games via the menu
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
509 { |
1df16f5985f3
Added stub load_save and persist_save functions to SMS system so that we don't crash when switching games via the menu
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
510 //TODO: Implement me |
1df16f5985f3
Added stub load_save and persist_save functions to SMS system so that we don't crash when switching games via the menu
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
511 } |
1df16f5985f3
Added stub load_save and persist_save functions to SMS system so that we don't crash when switching games via the menu
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
512 |
1df16f5985f3
Added stub load_save and persist_save functions to SMS system so that we don't crash when switching games via the menu
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
513 static void persist_save(system_header *system) |
1df16f5985f3
Added stub load_save and persist_save functions to SMS system so that we don't crash when switching games via the menu
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
514 { |
1df16f5985f3
Added stub load_save and persist_save functions to SMS system so that we don't crash when switching games via the menu
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
515 //TODO: Implement me |
1df16f5985f3
Added stub load_save and persist_save functions to SMS system so that we don't crash when switching games via the menu
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
516 } |
1df16f5985f3
Added stub load_save and persist_save functions to SMS system so that we don't crash when switching games via the menu
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
517 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
518 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:
1555
diff
changeset
|
519 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
520 sms_context *sms = (sms_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
521 if (gamepad_num == GAMEPAD_MAIN_UNIT) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
522 if (button == MAIN_UNIT_PAUSE) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
523 vdp_pbc_pause(sms->vdp); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
524 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
525 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
526 io_gamepad_down(&sms->io, gamepad_num, button); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
527 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
528 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
529 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
530 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:
1555
diff
changeset
|
531 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
532 sms_context *sms = (sms_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
533 io_gamepad_up(&sms->io, gamepad_num, button); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
534 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
535 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
536 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:
1555
diff
changeset
|
537 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
538 sms_context *sms = (sms_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
539 io_mouse_down(&sms->io, mouse_num, button); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
540 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
541 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
542 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:
1555
diff
changeset
|
543 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
544 sms_context *sms = (sms_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
545 io_mouse_up(&sms->io, mouse_num, button); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
546 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
547 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
548 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:
1555
diff
changeset
|
549 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
550 sms_context *sms = (sms_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
551 io_mouse_motion_absolute(&sms->io, mouse_num, x, y); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
552 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
553 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
554 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:
1555
diff
changeset
|
555 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
556 sms_context *sms = (sms_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
557 io_mouse_motion_relative(&sms->io, mouse_num, x, y); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
558 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
559 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
560 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:
1555
diff
changeset
|
561 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
562 sms_context *sms = (sms_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
563 io_keyboard_down(&sms->io, scancode); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
564 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
565 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
566 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:
1555
diff
changeset
|
567 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
568 sms_context *sms = (sms_context *)system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
569 io_keyboard_up(&sms->io, scancode); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
570 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
571 |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
572 static void set_gain_config(sms_context *sms) |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
573 { |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
574 char *config_gain; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
575 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:
1759
diff
changeset
|
576 render_audio_source_gaindb(sms->psg->audio, config_gain ? atof(config_gain) : 0.0f); |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
577 } |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
578 |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
579 static void config_updated(system_header *system) |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
580 { |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
581 sms_context *sms = (sms_context *)system; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
582 setup_io_devices(config, &system->info, &sms->io); |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
583 } |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
584 |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
585 |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
586 sms_context *alloc_configure_sms(system_media *media, uint32_t opts, uint8_t force_region) |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
587 { |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
588 sms_context *sms = calloc(1, sizeof(sms_context)); |
1201
aee2177a1630
Use filename for game title in SMS mode
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
589 uint32_t rom_size = nearest_pow2(media->size); |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
590 memmap_chunk memory_map[6]; |
1201
aee2177a1630
Use filename for game title in SMS mode
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
591 if (media->size > 0xC000) { |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
592 sms->header.info.map_chunks = 6; |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
593 uint8_t *ram_reg_overlap = sms->ram + sizeof(sms->ram) - 4; |
1201
aee2177a1630
Use filename for game title in SMS mode
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
594 memory_map[0] = (memmap_chunk){0x0000, 0x0400, 0xFFFF, 0, 0, MMAP_READ, media->buffer, NULL, NULL, NULL, NULL}; |
1142
5c8b1c33ca10
Invalidate translated code on a cartridge bank change in SMS mode. Fix handling of bank 0
Michael Pavone <pavone@retrodev.com>
parents:
1141
diff
changeset
|
595 memory_map[1] = (memmap_chunk){0x0400, 0x4000, 0xFFFF, 0, 0, MMAP_READ|MMAP_PTR_IDX|MMAP_CODE, NULL, NULL, NULL, NULL, NULL}; |
5c8b1c33ca10
Invalidate translated code on a cartridge bank change in SMS mode. Fix handling of bank 0
Michael Pavone <pavone@retrodev.com>
parents:
1141
diff
changeset
|
596 memory_map[2] = (memmap_chunk){0x4000, 0x8000, 0x3FFF, 0, 1, MMAP_READ|MMAP_PTR_IDX|MMAP_CODE, NULL, NULL, NULL, NULL, NULL}; |
1149
6b0da6021544
Don't lock up CPU if performing a read with writes configured when in PBC mode. Allow access to VDP debug commands from Z80 debugger in PBC mode. Handle Mode 4 in VDP debug print functions
Michael Pavone <pavone@retrodev.com>
parents:
1148
diff
changeset
|
597 memory_map[3] = (memmap_chunk){0x8000, 0xC000, 0x3FFF, 0, 2, MMAP_READ|MMAP_PTR_IDX|MMAP_CODE, NULL, NULL, NULL, NULL, cart_ram_write}; |
1142
5c8b1c33ca10
Invalidate translated code on a cartridge bank change in SMS mode. Fix handling of bank 0
Michael Pavone <pavone@retrodev.com>
parents:
1141
diff
changeset
|
598 memory_map[4] = (memmap_chunk){0xC000, 0xFFFC, sizeof(sms->ram)-1, 0, 0, MMAP_READ|MMAP_WRITE|MMAP_CODE, sms->ram, NULL, NULL, NULL, NULL}; |
1162
c4ea535cf57e
Forgot that the expansion to 32-bit values for 16-bit addresses is not done when calling a C function to handle a memory operation. Mask on location in mapper_write was needed afterall
Michael Pavone <pavone@retrodev.com>
parents:
1154
diff
changeset
|
599 memory_map[5] = (memmap_chunk){0xFFFC, 0x10000, 0x0003, 0, 0, MMAP_READ, ram_reg_overlap, NULL, NULL, NULL, mapper_write}; |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
600 } else { |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
601 sms->header.info.map_chunks = 2; |
1201
aee2177a1630
Use filename for game title in SMS mode
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
602 memory_map[0] = (memmap_chunk){0x0000, 0xC000, rom_size-1, 0, 0, MMAP_READ, media->buffer, NULL, NULL, NULL, NULL}; |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
603 memory_map[1] = (memmap_chunk){0xC000, 0x10000, sizeof(sms->ram)-1, 0, 0, MMAP_READ|MMAP_WRITE|MMAP_CODE, sms->ram, NULL, NULL, NULL, NULL}; |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
604 }; |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
605 sms->header.info.map = malloc(sizeof(memmap_chunk) * sms->header.info.map_chunks); |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
606 memcpy(sms->header.info.map, memory_map, sizeof(memmap_chunk) * sms->header.info.map_chunks); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
607 z80_options *zopts = malloc(sizeof(z80_options)); |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
608 init_z80_opts(zopts, sms->header.info.map, sms->header.info.map_chunks, io_map, 4, 15, 0xFF); |
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:
1129
diff
changeset
|
609 sms->z80 = init_z80_context(zopts); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
610 sms->z80->system = sms; |
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
|
611 sms->z80->Z80_OPTS->gen.debug_cmd_handler = debug_commands; |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
612 |
1201
aee2177a1630
Use filename for game title in SMS mode
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
613 sms->rom = media->buffer; |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
614 sms->rom_size = rom_size; |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
615 if (sms->header.info.map_chunks > 2) { |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
616 sms->z80->mem_pointers[0] = sms->rom; |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
617 sms->z80->mem_pointers[1] = sms->rom + 0x4000; |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
618 sms->z80->mem_pointers[2] = sms->rom + 0x8000; |
1162
c4ea535cf57e
Forgot that the expansion to 32-bit values for 16-bit addresses is not done when calling a C function to handle a memory operation. Mask on location in mapper_write was needed afterall
Michael Pavone <pavone@retrodev.com>
parents:
1154
diff
changeset
|
619 sms->bank_regs[1] = 0; |
c4ea535cf57e
Forgot that the expansion to 32-bit values for 16-bit addresses is not done when calling a C function to handle a memory operation. Mask on location in mapper_write was needed afterall
Michael Pavone <pavone@retrodev.com>
parents:
1154
diff
changeset
|
620 sms->bank_regs[2] = 0x4000 >> 14; |
c4ea535cf57e
Forgot that the expansion to 32-bit values for 16-bit addresses is not done when calling a C function to handle a memory operation. Mask on location in mapper_write was needed afterall
Michael Pavone <pavone@retrodev.com>
parents:
1154
diff
changeset
|
621 sms->bank_regs[3] = 0x8000 >> 14; |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
622 } |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
623 |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
624 //TODO: Detect region and pick master clock based off of that |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
625 sms->normal_clock = sms->master_clock = 53693175; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
626 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
627 sms->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
|
628 psg_init(sms->psg, sms->master_clock, 15*16); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
629 |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
630 set_gain_config(sms); |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1759
diff
changeset
|
631 |
1640
3602f3b20072
Small cleanup of vdp_context struct layout and removal of separately allocated buffers
Michael Pavone <pavone@retrodev.com>
parents:
1595
diff
changeset
|
632 sms->vdp = init_vdp_context(0); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
633 sms->vdp->system = &sms->header; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
634 |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
635 sms->header.info.save_type = SAVE_NONE; |
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
636 sms->header.info.name = strdup(media->name); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
637 |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
638 setup_io_devices(config, &sms->header.info, &sms->io); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
639 sms->header.has_keyboard = io_has_keyboard(&sms->io); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
640 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
641 sms->header.set_speed_percent = set_speed_percent; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
642 sms->header.start_context = start_sms; |
1401
b56c8c51ca5d
Properly release and reacquire framebuffer pointer when switching contexts. Hopefully fixes the LOCKRECT issue some people are seeing with the SDL 2 fallback renderer
Michael Pavone <pavone@retrodev.com>
parents:
1384
diff
changeset
|
643 sms->header.resume_context = resume_sms; |
1384
1df16f5985f3
Added stub load_save and persist_save functions to SMS system so that we don't crash when switching games via the menu
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
644 sms->header.load_save = load_save; |
1df16f5985f3
Added stub load_save and persist_save functions to SMS system so that we don't crash when switching games via the menu
Michael Pavone <pavone@retrodev.com>
parents:
1379
diff
changeset
|
645 sms->header.persist_save = persist_save; |
1433
c886c54d8cf1
Added save states to SMS emulation
Michael Pavone <pavone@retrodev.com>
parents:
1401
diff
changeset
|
646 sms->header.load_state = load_state; |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
647 sms->header.free_context = free_sms; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
648 sms->header.get_open_bus_value = get_open_bus_value; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
649 sms->header.request_exit = request_exit; |
1209
5ee6b6345ea9
Implement SMS hardware soft reset (note only available on real hardware on the Genesis in PBC mode)
Michael Pavone <pavone@retrodev.com>
parents:
1201
diff
changeset
|
650 sms->header.soft_reset = soft_reset; |
1120
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
651 sms->header.inc_debug_mode = inc_debug_mode; |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
652 sms->header.gamepad_down = gamepad_down; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
653 sms->header.gamepad_up = gamepad_up; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
654 sms->header.mouse_down = mouse_down; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
655 sms->header.mouse_up = mouse_up; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
656 sms->header.mouse_motion_absolute = mouse_motion_absolute; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
657 sms->header.mouse_motion_relative = mouse_motion_relative; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
658 sms->header.keyboard_down = keyboard_down; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
659 sms->header.keyboard_up = keyboard_up; |
1595
360d5bab199f
Update controller config when changed in UI without restart
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
660 sms->header.config_updated = config_updated; |
1690
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
661 sms->header.serialize = serialize; |
319d90025d50
Implement serialization/deserialization in libretro build
Mike Pavone <pavone@retrodev.com>
parents:
1688
diff
changeset
|
662 sms->header.deserialize = deserialize; |
1377
e587f16e7d3d
Implemented SMS pause button
Michael Pavone <pavone@retrodev.com>
parents:
1371
diff
changeset
|
663 sms->header.type = SYSTEM_SMS; |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
664 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
665 return sms; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
666 } |