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