annotate sega_mapper.c @ 2496:187bc857a76a default tip

Fix bug in MED mapper protection bit implementation
author Michael Pavone <pavone@retrodev.com>
date Sun, 28 Apr 2024 23:33:11 -0700
parents b9cd3c64652d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include "genesis.h"
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
2 #include "util.h"
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 uint16_t read_sram_w(uint32_t address, m68k_context * context)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 genesis_context * gen = context->system;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 address &= gen->save_ram_mask;
2234
b6fdedd3b070 Fix SRAM endianness for word-wide SRAM combined with Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 2052
diff changeset
8 uint16_t *word_storage = (uint16_t *)gen->save_storage;
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 switch(gen->save_type)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 case RAM_FLAG_BOTH:
2234
b6fdedd3b070 Fix SRAM endianness for word-wide SRAM combined with Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 2052
diff changeset
12 return word_storage[address >> 1];
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 case RAM_FLAG_EVEN:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 return gen->save_storage[address >> 1] << 8 | 0xFF;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 case RAM_FLAG_ODD:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 return gen->save_storage[address >> 1] | 0xFF00;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 return 0xFFFF;//We should never get here
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21 uint8_t read_sram_b(uint32_t address, m68k_context * context)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 genesis_context * gen = context->system;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
24 address &= gen->save_ram_mask;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25 switch(gen->save_type)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27 case RAM_FLAG_BOTH:
2234
b6fdedd3b070 Fix SRAM endianness for word-wide SRAM combined with Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 2052
diff changeset
28 return gen->save_storage[address ^ 1];
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 case RAM_FLAG_EVEN:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30 if (address & 1) {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
31 return 0xFF;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 } else {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 return gen->save_storage[address >> 1];
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
34 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
35 case RAM_FLAG_ODD:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 if (address & 1) {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37 return gen->save_storage[address >> 1];
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
38 } else {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
39 return 0xFF;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
40 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42 return 0xFF;//We should never get here
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 m68k_context * write_sram_area_w(uint32_t address, m68k_context * context, uint16_t value)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47 genesis_context * gen = context->system;
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
48 if (gen->mapper_type == MAPPER_SEGA_MED_V2) {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
49 if (gen->bank_regs[8] & 0x20) {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
50 uint32_t bank = address >> 19;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
51 address &= 0x7FFFF;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
52 context->mem_pointers[gen->mapper_start_index + bank][address >> 1] = value;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
53 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
54 return context;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
55 }
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
56 if ((gen->bank_regs[0] & 0x3) == 1) {
2234
b6fdedd3b070 Fix SRAM endianness for word-wide SRAM combined with Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 2052
diff changeset
57 uint16_t *word_storage = (uint16_t *)gen->save_storage;
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
58 address &= gen->save_ram_mask;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
59 switch(gen->save_type)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61 case RAM_FLAG_BOTH:
2234
b6fdedd3b070 Fix SRAM endianness for word-wide SRAM combined with Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 2052
diff changeset
62 word_storage[address >> 1] = value;
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 break;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64 case RAM_FLAG_EVEN:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 gen->save_storage[address >> 1] = value >> 8;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 break;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 case RAM_FLAG_ODD:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 gen->save_storage[address >> 1] = value;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 break;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72 return context;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
75 m68k_context * write_sram_area_b(uint32_t address, m68k_context * context, uint8_t value)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
77 genesis_context * gen = context->system;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 if ((gen->bank_regs[0] & 0x3) == 1) {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 address &= gen->save_ram_mask;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
80 switch(gen->save_type)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 case RAM_FLAG_BOTH:
2234
b6fdedd3b070 Fix SRAM endianness for word-wide SRAM combined with Sega mapper
Michael Pavone <pavone@retrodev.com>
parents: 2052
diff changeset
83 gen->save_storage[address ^ 1] = value;
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 break;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
85 case RAM_FLAG_EVEN:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 if (!(address & 1)) {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 gen->save_storage[address >> 1] = value;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
88 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 break;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
90 case RAM_FLAG_ODD:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
91 if (address & 1) {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
92 gen->save_storage[address >> 1] = value;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
94 break;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
95 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
96 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
97 return context;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
98 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
99
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
100 static void* write_med_ram_w(uint32_t address, void *vcontext, uint16_t value, uint16_t bank)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
101 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
102 m68k_context *context = vcontext;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
103 genesis_context * gen = context->system;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
104 if (gen->bank_regs[8] & 0x20) {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
105 context->mem_pointers[gen->mapper_start_index + bank][address >> 1] = value;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
106 address += bank * 0x80000;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
107 m68k_invalidate_code_range(gen->m68k, address, address + 2);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
108 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
109 return vcontext;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
110 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
111
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
112 void* write_med_ram0_w(uint32_t address, void *vcontext, uint16_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
113 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
114 return write_med_ram_w(address, vcontext, value, 0);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
115 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
116
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
117 void* write_med_ram1_w(uint32_t address, void *vcontext, uint16_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
118 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
119 return write_med_ram_w(address, vcontext, value, 1);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
120 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
121
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
122 void* write_med_ram2_w(uint32_t address, void *vcontext, uint16_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
123 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
124 return write_med_ram_w(address, vcontext, value, 2);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
125 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
126
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
127 void* write_med_ram3_w(uint32_t address, void *vcontext, uint16_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
128 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
129 return write_med_ram_w(address, vcontext, value, 3);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
130 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
131
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
132 void* write_med_ram4_w(uint32_t address, void *vcontext, uint16_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
133 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
134 return write_med_ram_w(address, vcontext, value, 4);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
135 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
136
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
137 void* write_med_ram5_w(uint32_t address, void *vcontext, uint16_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
138 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
139 return write_med_ram_w(address, vcontext, value, 5);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
140 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
141
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
142 void* write_med_ram6_w(uint32_t address, void *vcontext, uint16_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
143 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
144 return write_med_ram_w(address, vcontext, value, 6);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
145 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
146
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
147 void* write_med_ram7_w(uint32_t address, void *vcontext, uint16_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
148 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
149 return write_med_ram_w(address, vcontext, value, 7);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
150 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
151
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
152 static void* write_med_ram_b(uint32_t address, void *vcontext, uint8_t value, uint16_t bank)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
153 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
154 m68k_context *context = vcontext;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
155 genesis_context * gen = context->system;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
156 if (gen->bank_regs[8] & 0x20) {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
157 ((uint8_t*)context->mem_pointers[gen->mapper_start_index + bank])[address ^ 1] = value;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
158 address += bank * 0x80000;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
159 m68k_invalidate_code_range(gen->m68k, address, address + 1);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
160 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
161 return vcontext;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
162 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
163
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
164 void* write_med_ram0_b(uint32_t address, void *vcontext, uint8_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
165 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
166 return write_med_ram_b(address, vcontext, value, 0);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
167 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
168
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
169 void* write_med_ram1_b(uint32_t address, void *vcontext, uint8_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
170 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
171 return write_med_ram_b(address, vcontext, value, 1);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
172 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
173
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
174 void* write_med_ram2_b(uint32_t address, void *vcontext, uint8_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
175 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
176 return write_med_ram_b(address, vcontext, value, 2);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
177 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
178
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
179 void* write_med_ram3_b(uint32_t address, void *vcontext, uint8_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
180 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
181 return write_med_ram_b(address, vcontext, value, 3);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
182 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
183
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
184 void* write_med_ram4_b(uint32_t address, void *vcontext, uint8_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
185 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
186 return write_med_ram_b(address, vcontext, value, 4);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
187 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
188
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
189 void* write_med_ram5_b(uint32_t address, void *vcontext, uint8_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
190 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
191 return write_med_ram_b(address, vcontext, value, 5);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
192 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
193
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
194 void* write_med_ram6_b(uint32_t address, void *vcontext, uint8_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
195 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
196 return write_med_ram_b(address, vcontext, value, 6);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
197 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
198
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
199 void* write_med_ram7_b(uint32_t address, void *vcontext, uint8_t value)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
200 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
201 return write_med_ram_b(address, vcontext, value, 7);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
202 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
203
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
204 m68k_context * write_bank_reg_w(uint32_t address, m68k_context * context, uint16_t value)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
205 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
206 genesis_context * gen = context->system;
2340
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
207 if (gen->mapper_type == MAPPER_SEGA_MED_V2 && (address & 0xF0) < 0xF0) {
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
208 // ignore writes to other MED extended registers for now
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
209 return context;
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
210 }
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
211 address &= 0xE;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
212 address >>= 1;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
213 if (!address) {
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
214 if (gen->mapper_type == MAPPER_SEGA_MED_V2) {
2496
187bc857a76a Fix bug in MED mapper protection bit implementation
Michael Pavone <pavone@retrodev.com>
parents: 2340
diff changeset
215 if (!(value & 0x8000)) {
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
216 //writes without protection bit set are ignored
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
217 return context;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
218 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
219 gen->bank_regs[8] = value >> 8;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
220 void *new_ptr = gen->cart + 0x40000*(value & 0x1F);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
221 if (context->mem_pointers[gen->mapper_start_index] != new_ptr) {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
222 m68k_invalidate_code_range(gen->m68k, 0, 0x80000);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
223 context->mem_pointers[gen->mapper_start_index] = new_ptr;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
224 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
225 } else if (value & 1) {
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
226 //Used for games that only use the mapper for SRAM
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
227 if (context->mem_pointers[gen->mapper_start_index]) {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
228 gen->mapper_temp = context->mem_pointers[gen->mapper_start_index];
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
229 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
230 context->mem_pointers[gen->mapper_start_index] = NULL;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
231 //For games that need more than 4MB
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
232 for (int i = 4; i < 8; i++)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
233 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
234 context->mem_pointers[gen->mapper_start_index + i] = NULL;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
235 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
236 } else {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
237 //Used for games that only use the mapper for SRAM
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
238 if (!context->mem_pointers[gen->mapper_start_index]) {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
239 context->mem_pointers[gen->mapper_start_index] = gen->mapper_temp;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
240 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
241 //For games that need more than 4MB
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
242 for (int i = 4; i < 8; i++)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
243 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
244 context->mem_pointers[gen->mapper_start_index + i] = gen->cart + 0x40000*gen->bank_regs[i];
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
245 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
246 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
247 } else if (gen->mapper_type != MAPPER_SEGA_SRAM) {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
248 uint32_t mask = ((gen->mapper_type == MAPPER_SEGA_MED_V2 ? (16 *1024 * 1024) : nearest_pow2(gen->header.info.rom_size)) >> 1) - 1;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
249 void *new_ptr = gen->cart + ((0x40000*value) & mask);
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
250 if (context->mem_pointers[gen->mapper_start_index + address] != new_ptr) {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
251 m68k_invalidate_code_range(gen->m68k, address * 0x80000, (address + 1) * 0x80000);
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
252 context->mem_pointers[gen->mapper_start_index + address] = new_ptr;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
253 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
254 }
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
255 gen->bank_regs[address] = value;
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
256 return context;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
257 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
258
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
259 m68k_context * write_bank_reg_b(uint32_t address, m68k_context * context, uint8_t value)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
260 {
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
261 genesis_context * gen = context->system;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
262 if (gen->mapper_type == MAPPER_SEGA_MED_V2) {
2340
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
263 if ((address & 0xFF) == 0xF0) {
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
264 write_bank_reg_w(address, context, value << 8 | gen->bank_regs[0]);
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
265 } else if (address > 2 && (address & 1)) {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
266 write_bank_reg_w(address, context, value);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
267 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
268 } else if (address & 1) {
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
269 write_bank_reg_w(address, context, value);
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
270 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
271 return context;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
272 }
1444
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
273
2340
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
274 uint16_t med_reg_read_w(uint32_t address, void *vcontext)
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
275 {
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
276 m68k_context *context = vcontext;
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
277 switch (address & 0xFE)
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
278 {
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
279 case 0xE4:
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
280 //ensure USB serial read returns "not-ready" status
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
281 return 0x02;
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
282 default:
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
283 return read_word(context->last_prefetch_address, (void **)context->mem_pointers, &context->options->gen, context);
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
284 }
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
285 }
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
286
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
287 uint8_t med_reg_read_b(uint32_t address, void *vcontext)
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
288 {
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
289 uint16_t value = med_reg_read_w(address, vcontext);
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
290 if (address & 1) {
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
291 return value;
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
292 }
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
293 return value >> 8;
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
294 }
b9cd3c64652d Slightly more correct implementation of MED extended Sega mapper so s2built debug build doesn't hang
Michael Pavone <pavone@retrodev.com>
parents: 2234
diff changeset
295
1444
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
296 void sega_mapper_serialize(genesis_context *gen, serialize_buffer *buf)
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
297 {
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
298 save_buffer8(buf, gen->bank_regs, gen->mapper_type == MAPPER_SEGA_MED_V2 ? sizeof(gen->bank_regs) : sizeof(gen->bank_regs) - 1);
1444
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
299 }
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
300
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
301 void sega_mapper_deserialize(deserialize_buffer *buf, genesis_context *gen)
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
302 {
2052
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
303 if (gen->mapper_type == MAPPER_SEGA_MED_V2) {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
304 uint16_t reg0 = load_int8(buf);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
305 for (int i = 1; i < sizeof(gen->bank_regs) - 1; i++)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
306 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
307 write_bank_reg_w(i * 2, gen->m68k, load_int8(buf));
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
308 }
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
309 reg0 |= load_int8(buf) << 8;
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
310 write_bank_reg_w(0, gen->m68k, reg0);
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
311 } else {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
312 for (int i = 0; i < sizeof(gen->bank_regs) - 1; i++)
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
313 {
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
314 write_bank_reg_w(i * 2, gen->m68k, load_int8(buf));
3748a2a8a4b7 Support Sega mapper without 'SEGA SSF' in header or ROM DB entry and implement a subset of the extended Sega mapper implemented in the Mega Everdrive when 'SEGA SSF' is present
Michael Pavone <pavone@retrodev.com>
parents: 1863
diff changeset
315 }
1444
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
316 }
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
317 }