1 /* Mednafen - Multi-system Emulator
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18 #include "../shared.h"
19 #include "cart.h"
20 #include "map_rom.h"
21
22 class MD_Cart_Type_YaSe : public MD_Cart_Type
23 {
24 public:
25
26 MD_Cart_Type_YaSe(const md_game_info *ginfo, const uint8 *ROM, const uint32 ROM_size);
27 virtual ~MD_Cart_Type_YaSe() override;
28
29 virtual void Write8(uint32 A, uint8 V) override;
30 virtual void Write16(uint32 A, uint16 V) override;
31 virtual uint8 Read8(uint32 A) override;
32 virtual uint16 Read16(uint32 A) override;
33 virtual int StateAction(StateMem *sm, int load, int data_only, const char *section_name) override;
34
35 // In bytes
36 virtual uint32 GetNVMemorySize(void) override;
37 virtual void ReadNVMemory(uint8 *buffer) override;
38 virtual void WriteNVMemory(const uint8 *buffer) override;
39
40 private:
41
42 const uint8 *rom;
43 uint32 rom_size;
44 uint8 sram[4096];
45 };
46
47
MD_Cart_Type_YaSe(const md_game_info * ginfo,const uint8 * ROM,const uint32 ROM_size)48 MD_Cart_Type_YaSe::MD_Cart_Type_YaSe(const md_game_info *ginfo, const uint8 *ROM, const uint32 ROM_size)
49 {
50 this->rom = ROM;
51 this->rom_size = ROM_size;
52
53 memset(sram, 0xFF, 4096);
54 }
55
~MD_Cart_Type_YaSe()56 MD_Cart_Type_YaSe::~MD_Cart_Type_YaSe()
57 {
58
59 }
60
61
Write8(uint32 A,uint8 V)62 void MD_Cart_Type_YaSe::Write8(uint32 A, uint8 V)
63 {
64 if(A >= 0x200000 && A <= 0x201fff)
65 {
66 if(A & 1)
67 sram[(A >> 1) & 0x1FFF] = V;
68 }
69 }
70
Write16(uint32 A,uint16 V)71 void MD_Cart_Type_YaSe::Write16(uint32 A, uint16 V)
72 {
73 if(A >= 0x200000 && A <= 0x201fff)
74 {
75 sram[(A >> 1) & 0x1FFF] = V;
76 }
77 }
78
Read8(uint32 A)79 uint8 MD_Cart_Type_YaSe::Read8(uint32 A)
80 {
81 if(A >= 0x200000 && A <= 0x201fff)
82 {
83 if(A & 1)
84 return(sram[(A >> 1) & 0x1FFF]);
85 }
86
87 if(A < 0x400000)
88 {
89 if(A >= rom_size)
90 {
91 MD_DBG(MD_DBG_WARNING, "[MAP_YASE] Unknown read8 from 0x%08x\n", A);
92 return(0);
93 }
94 return(READ_BYTE_MSB(rom, A));
95 }
96
97 if(A == 0x400000)
98 return(0x63);
99 if(A == 0x400002)
100 return(0x98);
101 if(A == 0x400004)
102 return(0xC9);
103 if(A == 0x400006)
104 return(0x18);
105
106 MD_DBG(MD_DBG_WARNING, "[MAP_YASE] Unknown read8 from 0x%08x\n", A);
107 return(m68k_read_bus_8(A));
108 }
109
Read16(uint32 A)110 uint16 MD_Cart_Type_YaSe::Read16(uint32 A)
111 {
112 if(A >= 0x200000 && A <= 0x201fff)
113 return(sram[(A >> 1) & 0x1FFF]);
114
115 if(A < 0x400000)
116 {
117 if(A >= rom_size)
118 {
119 MD_DBG(MD_DBG_WARNING, "[MAP_YASE] Unknown read16 from 0x%08x\n", A);
120 return(0);
121 }
122 return(READ_WORD_MSB(rom, A));
123 }
124
125 if(A == 0x400000)
126 return(0x63);
127 if(A == 0x400002)
128 return(0x98);
129 if(A == 0x400004)
130 return(0xC9);
131 if(A == 0x400006)
132 return(0x18);
133
134 MD_DBG(MD_DBG_WARNING, "[MAP_YASE] Unknown read16 from 0x%08x\n", A);
135 return(m68k_read_bus_16(A));
136 }
137
StateAction(StateMem * sm,int load,int data_only,const char * section_name)138 int MD_Cart_Type_YaSe::StateAction(StateMem *sm, int load, int data_only, const char *section_name)
139 {
140 return(1);
141 }
142
GetNVMemorySize(void)143 uint32 MD_Cart_Type_YaSe::GetNVMemorySize(void)
144 {
145 return(4096);
146 }
147
ReadNVMemory(uint8 * buffer)148 void MD_Cart_Type_YaSe::ReadNVMemory(uint8 *buffer)
149 {
150 memcpy(buffer, sram, 4096);
151 }
152
WriteNVMemory(const uint8 * buffer)153 void MD_Cart_Type_YaSe::WriteNVMemory(const uint8 *buffer)
154 {
155 memcpy(sram, buffer, 4096);
156 }
157
MD_Make_Cart_Type_YaSe(const md_game_info * ginfo,const uint8 * ROM,const uint32 ROM_size,const uint32 iparam,const char * sparam)158 MD_Cart_Type *MD_Make_Cart_Type_YaSe(const md_game_info *ginfo, const uint8 *ROM, const uint32 ROM_size, const uint32 iparam, const char *sparam)
159 {
160 return(new MD_Cart_Type_YaSe(ginfo, ROM, ROM_size));
161 }
162