Mercurial > repos > blastem
annotate sms.c @ 1299:da1ffc4026c4
Fix latching of V32 mode bit
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 25 Mar 2017 11:31:43 -0700 |
parents | 5ee6b6345ea9 |
children | 071e761bcdcf |
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" |
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
|
9 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 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
|
11 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 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
|
13 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
|
14 if (location & 1) { |
1154
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
15 uint8_t fuzzy_ctrl_0 = sms->io.ports[0].control, fuzzy_ctrl_1 = sms->io.ports[1].control; |
1143
d4d770cfbc62
Fix handling of IO control writes in SMS mode
Michael Pavone <pavone@retrodev.com>
parents:
1142
diff
changeset
|
16 sms->io.ports[0].control = (~value) << 5 & 0x60; |
1154
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
17 fuzzy_ctrl_0 |= sms->io.ports[0].control; |
1143
d4d770cfbc62
Fix handling of IO control writes in SMS mode
Michael Pavone <pavone@retrodev.com>
parents:
1142
diff
changeset
|
18 sms->io.ports[1].control = (~value) << 3 & 0x60; |
1154
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
19 fuzzy_ctrl_1 |= sms->io.ports[1].control; |
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
20 if ( |
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
21 (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
|
22 || (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
|
23 ) { |
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
24 //TH is an output and it went from 0 -> 1 |
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
25 vdp_run_context(sms->vdp, z80->current_cycle); |
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
26 vdp_latch_hv(sms->vdp); |
c83ec07ddbac
Implemented Mode 4 H conter latching
Michael Pavone <pavone@retrodev.com>
parents:
1149
diff
changeset
|
27 } |
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
|
28 io_data_write(sms->io.ports, value << 1, z80->current_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
|
29 io_data_write(sms->io.ports + 1, value >> 1, z80->current_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
|
30 } 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
|
31 //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
|
32 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 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
|
34 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 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
|
37 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 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
|
39 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
|
40 vdp_run_context(sms->vdp, z80->current_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
|
41 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
|
42 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
|
43 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
|
44 } 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
|
45 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
|
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 } |
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 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
|
50 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 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
|
52 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
|
53 psg_run(sms->psg, z80->current_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
|
54 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
|
55 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
|
56 } |
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 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
|
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 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
|
61 uint32_t hint = vdp_next_hint(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
|
62 sms->z80->int_pulse_start = vint < hint ? vint : hint; |
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 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 |
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 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
|
66 { |
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 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
|
68 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
|
69 vdp_run_context(sms->vdp, z80->current_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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 } 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
|
76 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
|
77 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 } |
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 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
|
81 { |
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 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
|
83 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
|
84 vdp_run_context(sms->vdp, z80->current_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
|
85 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
|
86 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
|
87 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
|
88 } 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
|
89 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
|
90 } |
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 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
|
92 } |
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 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
|
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 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
|
97 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
|
98 if (location == 0xC0 || location == 0xDC) { |
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 uint8_t port_a = io_data_read(sms->io.ports, z80->current_cycle); |
1148
80ef49539550
Fix reading from second controller port in SMS mode
Michael Pavone <pavone@retrodev.com>
parents:
1143
diff
changeset
|
100 uint8_t port_b = io_data_read(sms->io.ports+1, z80->current_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
|
101 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
|
102 } |
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 if (location == 0xC1 || location == 0xDD) { |
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 uint8_t port_a = io_data_read(sms->io.ports, z80->current_cycle); |
1148
80ef49539550
Fix reading from second controller port in SMS mode
Michael Pavone <pavone@retrodev.com>
parents:
1143
diff
changeset
|
105 uint8_t port_b = io_data_read(sms->io.ports+1, z80->current_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 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
|
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 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
|
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 |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
111 static void *mapper_write(uint32_t location, void *vcontext, uint8_t value) |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
112 { |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
113 z80_context *z80 = vcontext; |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
114 sms_context *sms = z80->system; |
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
|
115 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
|
116 location &= 3; |
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
|
117 sms->ram[0x1FFC + location] = value; |
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
|
118 sms->bank_regs[location] = value; |
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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 //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
|
125 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
|
126 } |
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
|
127 } 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
|
128 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
|
129 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
|
130 //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
|
131 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
|
132 } 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
|
133 //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
|
134 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
|
135 } |
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
|
136 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
|
137 //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
|
138 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
|
139 } |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
140 } |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
141 return vcontext; |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
142 } |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
143 |
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
|
144 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
|
145 { |
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 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
|
147 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
|
148 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
|
149 //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
|
150 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
|
151 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
|
152 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
|
153 } |
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
|
154 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
|
155 } |
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
|
156 |
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
|
157 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
|
158 { |
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
|
159 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
|
160 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
|
161 { |
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
|
162 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
|
163 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
|
164 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
|
165 } 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
|
166 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
|
167 } 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
|
168 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
|
169 } |
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 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
|
171 } |
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 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
|
173 } |
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 |
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
|
175 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
|
176 {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
|
177 {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
|
178 {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
|
179 {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
|
180 }; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 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
|
183 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 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
|
185 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
|
186 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
|
187 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 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
|
189 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 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
|
192 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 render_disable_ym(); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 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
|
195 uint32_t target_cycle = sms->z80->current_cycle + 3420*262; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1162
diff
changeset
|
196 //TODO: PAL support |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1162
diff
changeset
|
197 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
|
198 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
|
199 { |
1129
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
200 if (system->enter_debugger && sms->z80->pc) { |
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
201 system->enter_debugger = 0; |
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
202 zdebugger(sms->z80, sms->z80->pc); |
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
203 } |
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
|
204 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
|
205 if (sms->z80->reset) { |
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
|
206 z80_clear_reset(sms->z80, sms->z80->current_cycle + 128*15); |
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
|
207 } |
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
|
208 target_cycle = sms->z80->current_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
|
209 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
|
210 psg_run(sms->psg, 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
|
211 target_cycle += 3420*262; |
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 if (target_cycle > 0x10000000) { |
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 uint32_t adjust = sms->z80->current_cycle - 3420*262*2; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 io_adjust_cycles(sms->io.ports, sms->z80->current_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
|
215 io_adjust_cycles(sms->io.ports+1, sms->z80->current_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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 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
|
223 render_enable_ym(); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 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
|
227 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 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
|
229 set_keybindings(&sms->io); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 |
1129
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
231 if (system->enter_debugger) { |
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
232 system->enter_debugger = 0; |
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
233 zinsert_breakpoint(sms->z80, 0, (uint8_t *)zdebugger); |
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
234 } |
6b5c92b6205c
Enabled Z80 debugger in PBC mode
Michael Pavone <pavone@retrodev.com>
parents:
1126
diff
changeset
|
235 |
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
|
236 z80_assert_reset(sms->z80, 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
|
237 z80_clear_reset(sms->z80, 128*15); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 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
|
240 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 |
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
|
242 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
|
243 { |
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
|
244 sms_context *sms = (sms_context *)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
|
245 z80_assert_reset(sms->z80, sms->z80->current_cycle); |
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
|
246 sms->z80->target_cycle = sms->z80->sync_cycle = sms->z80->current_cycle; |
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
|
247 } |
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
|
248 |
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
|
249 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
|
250 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 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
|
252 vdp_free(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
|
253 z80_options_free(sms->z80->options); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 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
|
255 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
|
256 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
|
257 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 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
|
260 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 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
|
262 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 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
|
265 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 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
|
267 sms->should_return = 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
|
268 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 |
1120
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
270 static void inc_debug_mode(system_header *system) |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
271 { |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
272 sms_context *sms = (sms_context *)system; |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
273 sms->vdp->debug++; |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
274 if (sms->vdp->debug == 7) { |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
275 sms->vdp->debug = 0; |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
276 } |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
277 } |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
278 |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
279 static void inc_debug_pal(system_header *system) |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
280 { |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
281 sms_context *sms = (sms_context *)system; |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
282 sms->vdp->debug_pal++; |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
283 if (sms->vdp->debug_pal == 4) { |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
284 sms->vdp->debug_pal = 0; |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
285 } |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
286 } |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
287 |
1201
aee2177a1630
Use filename for game title in SMS mode
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
288 sms_context *alloc_configure_sms(system_media *media, uint32_t opts, uint8_t force_region, rom_info *info_out) |
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
|
289 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
290 memset(info_out, 0, sizeof(*info_out)); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
291 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
|
292 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
|
293 memmap_chunk memory_map[6]; |
1201
aee2177a1630
Use filename for game title in SMS mode
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
294 if (media->size > 0xC000) { |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
295 info_out->map_chunks = 6; |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 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
|
303 } else { |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
304 info_out->map_chunks = 2; |
1201
aee2177a1630
Use filename for game title in SMS mode
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
305 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
|
306 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
|
307 }; |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
308 info_out->map = malloc(sizeof(memmap_chunk) * info_out->map_chunks); |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
309 memcpy(info_out->map, memory_map, sizeof(memmap_chunk) * info_out->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
|
310 z80_options *zopts = malloc(sizeof(z80_options)); |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
311 init_z80_opts(zopts, info_out->map, info_out->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
|
312 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
|
313 sms->z80->system = sms; |
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
|
314 sms->z80->options->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
|
315 |
1201
aee2177a1630
Use filename for game title in SMS mode
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
316 sms->rom = media->buffer; |
1141
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
317 sms->rom_size = rom_size; |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
318 if (info_out->map_chunks > 2) { |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
319 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 } |
7e199bebde2f
Initial support for Sega's family of SMS mappers
Michael Pavone <pavone@retrodev.com>
parents:
1130
diff
changeset
|
326 |
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
|
327 char * lowpass_cutoff_str = tern_find_path(config, "audio\0lowpass_cutoff\0").ptrval; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
328 uint32_t lowpass_cutoff = lowpass_cutoff_str ? atoi(lowpass_cutoff_str) : 3390; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
329 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
330 //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
|
331 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
|
332 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
333 sms->psg = malloc(sizeof(psg_context)); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 psg_init(sms->psg, render_sample_rate(), sms->master_clock, 15*16, render_audio_buffer(), lowpass_cutoff); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
335 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
336 sms->vdp = malloc(sizeof(vdp_context)); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
337 init_vdp_context(sms->vdp, 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
|
338 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
|
339 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
340 info_out->save_type = SAVE_NONE; |
1201
aee2177a1630
Use filename for game title in SMS mode
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
341 info_out->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
|
342 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
343 setup_io_devices(config, info_out, &sms->io); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
344 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
345 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
|
346 sms->header.start_context = start_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
|
347 sms->header.resume_context = run_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
|
348 //TODO: Fill in NULL values |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
349 sms->header.load_save = 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
|
350 sms->header.persist_save = 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
|
351 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
|
352 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
|
353 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
|
354 sms->header.soft_reset = soft_reset; |
1120
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
355 sms->header.inc_debug_mode = inc_debug_mode; |
e9369d6f0101
Somewhat broken implementation of Mode 4
Michael Pavone <pavone@retrodev.com>
parents:
1119
diff
changeset
|
356 sms->header.inc_debug_pal = inc_debug_pal; |
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
|
357 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
358 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
|
359 } |