forked from TASEmulators/BizHawk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eeprom.cpp
214 lines (195 loc) · 7.7 KB
/
eeprom.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/* Cygne
*
* Copyright notice for this file:
* Copyright (C) 2002 Dox [email protected]
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "system.h"
#include <ctype.h>
#include <cstring>
namespace MDFN_IEN_WSWAN
{
static const uint8 iEEPROM_Init[0x400] =
{
255,255,255,255,255,255,192,255,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,127,0,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
0,252,255,1,255,253,255,253,255,253,255,253,
255,253,255,253,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
0,0,3,3,0,0,0,64,128,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
135,5,140,9,5,12,139,12,144,0,0,2,
0,76,165,0,128,0,0,0,255,127,255,127,
255,127,255,127,255,127,255,127,255,127,255,127,
255,127,255,127,255,127,255,127,255,127,255,127,
255,127,255,127,255,127,255,127,255,127,255,127,
255,127,255,127,255,127,255,127,255,127,255,127,
255,127,255,127,255,127,255,127,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
0,0,6,6,6,6,6,0,0,0,0,0,
1,128,15,0,1,1,1,15,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,
'C'-54,'Y'-54,'G'-54,'N'-54,'E'-54,0,0,0,0,0,0,0,0,0,0,
0,32,1,1,33,1,4,0,1,
0,152,60,127,74,1,53,1,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,255,255,255,255,255,
255,255,255,255
};
uint8 EEPROM::Read(uint32 A)
{
switch(A)
{
default: Debug::printf("Read: %04x\n", A); break;
case 0xBA: return(iEEPROM[(iEEPROM_Address << 1) & 0x3FF]);
case 0xBB: return(iEEPROM[((iEEPROM_Address << 1) | 1) & 0x3FF]);
case 0xBC: return(iEEPROM_Address >> 0);
case 0xBD: return(iEEPROM_Address >> 8);
case 0xBE:
if(iEEPROM_Command & 0x20) return iEEPROM_Command|2;
if(iEEPROM_Command & 0x10) return iEEPROM_Command|1;
return iEEPROM_Command | 3;
case 0xC4: return(wsEEPROM[(EEPROM_Address << 1) & (eeprom_size - 1)]);
case 0xC5: return(wsEEPROM[((EEPROM_Address << 1) | 1) & (eeprom_size - 1)]);
case 0xC6: return(EEPROM_Address >> 0);
case 0xC7: return(EEPROM_Address >> 8);
case 0xC8: if(EEPROM_Command & 0x20) return EEPROM_Command|2;
if(EEPROM_Command & 0x10) return EEPROM_Command|1;
return EEPROM_Command | 3;
}
return(0);
}
void EEPROM::Write(uint32 A, uint8 V)
{
switch(A)
{
case 0xBA: iEEPROM[(iEEPROM_Address << 1) & 0x3FF] = V; break;
case 0xBB: iEEPROM[((iEEPROM_Address << 1) | 1) & 0x3FF] = V; break;
case 0xBC: iEEPROM_Address &= 0xFF00; iEEPROM_Address |= (V << 0); break;
case 0xBD: iEEPROM_Address &= 0x00FF; iEEPROM_Address |= (V << 8); break;
case 0xBE: iEEPROM_Command = V; break;
case 0xC4: wsEEPROM[(EEPROM_Address << 1) & (eeprom_size - 1)] = V; break;
case 0xC5: wsEEPROM[((EEPROM_Address << 1) | 1) & (eeprom_size - 1)] = V; break;
case 0xC6: EEPROM_Address &= 0xFF00; EEPROM_Address |= (V << 0); break;
case 0xC7: EEPROM_Address &= 0x00FF; EEPROM_Address |= (V << 8); break;
case 0xC8: EEPROM_Command = V; break;
}
}
void EEPROM::Reset()
{
iEEPROM_Command = EEPROM_Command = 0;
iEEPROM_Address = EEPROM_Address = 0;
}
void EEPROM::Init(const char *Name, const uint16 BYear, const uint8 BMonth, const uint8 BDay, const uint8 Sex, const uint8 Blood)
{
std::memset(wsEEPROM, 0, 2048);
std::memcpy(iEEPROM, iEEPROM_Init, 0x400);
for(unsigned int x = 0; x < 16; x++)
{
uint8 zechar = 0;
if(x < std::strlen(Name))
{
char tc = toupper(Name[x]);
if(tc == ' ') zechar = 0;
else if(tc >= '0' && tc <= '9') zechar = tc - '0' + 0x1;
else if(tc >= 'A' && tc <= 'Z') zechar = tc - 'A' + 0xB;
else if(tc >= 'a' && tc <= 'z') zechar = tc - 'a' + 0xB + 26;
}
iEEPROM[0x360 + x] = zechar;
}
#define mBCD16(value) ( (((((value)%100) / 10) <<4)|((value)%10)) | ((((((value / 100)%100) / 10) <<4)|((value / 100)%10))<<8) )
#define INT16_TO_BCD(A) ((((((A) % 100) / 10) * 16 + ((A) % 10))) | (((((((A) / 100) % 100) / 10) * 16 + (((A) / 100) % 10))) << 8)) // convert INT16 --> BCD
uint16 bcd_BYear = INT16_TO_BCD(BYear);
iEEPROM[0x370] = (bcd_BYear >> 8) & 0xFF;
iEEPROM[0x371] = (bcd_BYear >> 0) & 0xFF;
iEEPROM[0x372] = mBCD(BMonth);
iEEPROM[0x373] = mBCD(BDay);
iEEPROM[0x374] = Sex;
iEEPROM[0x375] = Blood;
}
SYNCFUNC(EEPROM)
{
NSS(iEEPROM_Command);
NSS(EEPROM_Command);
NSS(iEEPROM_Address);
NSS(EEPROM_Address);
NSS(eeprom_size);
NSS(iEEPROM);
NSS(wsEEPROM);
}
}