annotate sega_mapper.c @ 2155:6f58af5bd6fa

Add ROM DB entry for NHL 96 as it is missing SRAM info in the header
author Michael Pavone <pavone@retrodev.com>
date Thu, 07 Apr 2022 00:49:58 -0700
parents 3748a2a8a4b7
children b6fdedd3b070
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;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 switch(gen->save_type)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 case RAM_FLAG_BOTH:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 return gen->save_storage[address] << 8 | gen->save_storage[address+1];
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 case RAM_FLAG_EVEN:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 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
14 case RAM_FLAG_ODD:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 return gen->save_storage[address >> 1] | 0xFF00;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 return 0xFFFF;//We should never get here
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 }
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 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
21 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 genesis_context * gen = context->system;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 address &= gen->save_ram_mask;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
24 switch(gen->save_type)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 case RAM_FLAG_BOTH:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27 return gen->save_storage[address];
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28 case RAM_FLAG_EVEN:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 if (address & 1) {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30 return 0xFF;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
31 } else {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 return gen->save_storage[address >> 1];
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
34 case RAM_FLAG_ODD:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
35 if (address & 1) {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 return gen->save_storage[address >> 1];
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37 } else {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
38 return 0xFF;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
39 }
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 return 0xFF;//We should never get here
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42 }
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 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
45 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 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
47 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
48 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
49 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
50 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
51 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
52 }
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 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
54 }
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55 if ((gen->bank_regs[0] & 0x3) == 1) {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
56 address &= gen->save_ram_mask;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
57 switch(gen->save_type)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
58 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
59 case RAM_FLAG_BOTH:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 gen->save_storage[address] = value >> 8;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61 gen->save_storage[address+1] = value;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 break;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 case RAM_FLAG_EVEN:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64 gen->save_storage[address >> 1] = value >> 8;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 break;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 case RAM_FLAG_ODD:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 gen->save_storage[address >> 1] = value;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 break;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 }
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 return context;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72 }
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 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
75 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76 genesis_context * gen = context->system;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
77 if ((gen->bank_regs[0] & 0x3) == 1) {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 address &= gen->save_ram_mask;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 switch(gen->save_type)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
80 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 case RAM_FLAG_BOTH:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 gen->save_storage[address] = value;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 break;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 case RAM_FLAG_EVEN:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
85 if (!(address & 1)) {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 gen->save_storage[address >> 1] = value;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
88 break;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 case RAM_FLAG_ODD:
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
90 if (address & 1) {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
91 gen->save_storage[address >> 1] = value;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
92 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 break;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
94 }
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 return context;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
97 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
98
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
99 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
100 {
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 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
102 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
103 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
104 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
105 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
106 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
107 }
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 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
109 }
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 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
112 {
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 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
114 }
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 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
117 {
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 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
119 }
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 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
122 {
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 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
124 }
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 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
127 {
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 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
129 }
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 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
132 {
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 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
134 }
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 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
137 {
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 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
139 }
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 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
142 {
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 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
144 }
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 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
147 {
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 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
149 }
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 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
152 {
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 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
154 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
155 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
156 ((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
157 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
158 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
159 }
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 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
161 }
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 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
164 {
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 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
166 }
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 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
169 {
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 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
171 }
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 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
174 {
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 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
176 }
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 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
179 {
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 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
181 }
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 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
184 {
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 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
186 }
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 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
189 {
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 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
191 }
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 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
194 {
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 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
196 }
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 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
199 {
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 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
201 }
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
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
203 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
204 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
205 genesis_context * gen = context->system;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
206 address &= 0xE;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
207 address >>= 1;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
208 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
209 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
210 if (!value & 0x8000) {
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
211 //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
212 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
213 }
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 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
215 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
216 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
217 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
218 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
219 }
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 } else if (value & 1) {
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
221 //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
222 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
223 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
224 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
225 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
226 //For games that need more than 4MB
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
227 for (int i = 4; i < 8; i++)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
228 {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
229 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
230 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
231 } else {
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
232 //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
233 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
234 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
235 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
236 //For games that need more than 4MB
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
237 for (int i = 4; i < 8; i++)
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
238 {
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 + 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
240 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
241 }
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
242 } 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
243 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
244 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
245 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
246 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
247 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
248 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
249 }
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
250 gen->bank_regs[address] = value;
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
251 return context;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
252 }
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 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
255 {
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
256 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
257 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
258 address &= 0xF;
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
259 if (!address) {
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
260 //not sure if this is correct, possible byte sized writes are always rejected to $A130F0
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 write_bank_reg_w(address, context, value << 8 | 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
262 } 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
263 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
264 }
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 & 1) {
1415
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
266 write_bank_reg_w(address, context, value);
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
267 }
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
268 return context;
f7d653bb8899 Move Sega mapper implementation out of romdb.c
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
269 }
1444
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
270
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
271 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
272 {
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
273 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
274 }
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
275
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
276 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
277 {
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
278 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
279 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
280 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
281 {
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
282 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
283 }
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
284 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
285 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
286 } 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
287 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
288 {
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
289 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
290 }
1444
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
291 }
14a2834d010c Save/restore mapper state in native save states
Michael Pavone <pavone@retrodev.com>
parents: 1415
diff changeset
292 }