Debian Codegraph @

mednafen/wswan/eeprom.c

raw symbols SCIP
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 #include <ctype.h>
21 #include <string.h>
22
23 #include "wswan.h"cxx . . $ `<file>/mednafen/wswan/wswan.h`/
24 #include "eeprom.h"cxx . . $ `<file>/mednafen/wswan/eeprom.h`/
25 #include "wswan-memory.h"cxx . . $ `<file>/mednafen/wswan/wswan-memory.h`/
26 #include "../state_inline.h"cxx . . $ `<file>/mednafen/state_inline.h`/
27
28 uint8_tcxx . . $ uint8_t# wsEEPROMcxx . . $ wsEEPROM.[2048];
29 static uint8_tcxx . . $ uint8_t# iEEPROMcxx . . $ iEEPROM.[0x400];
30 static const uint8_tcxx . . $ uint8_t# iEEPROM_Initcxx . . $ iEEPROM_Init.[0x400] =
31 {
32 255,255,255,255,255,255,192,255,0,0,0,0,
33 0,0,0,0,0,0,0,0,0,0,0,0,
34 0,0,127,0,255,255,255,255,255,255,255,255,
35 255,255,255,255,255,255,0,0,0,0,0,0,
36 0,0,0,0,0,0,0,0,0,0,0,0,
37 0,0,0,0,0,0,0,0,0,0,0,0,
38 0,0,0,0,0,0,255,255,255,255,255,255,
39 255,255,255,255,255,255,255,255,255,255,255,255,
40 0,252,255,1,255,253,255,253,255,253,255,253,
41 255,253,255,253,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 255,255,255,255,255,255,255,255,255,255,255,255,
62 255,255,255,255,255,255,255,255,255,255,255,255,
63 255,255,255,255,255,255,255,255,255,255,255,255,
64 0,0,3,3,0,0,0,64,128,0,0,0,
65 0,0,0,0,0,0,0,0,0,0,0,0,
66 0,0,0,0,0,0,0,0,0,0,0,0,
67 0,0,0,0,0,0,0,0,0,0,0,0,
68 135,5,140,9,5,12,139,12,144,0,0,2,
69 0,76,165,0,128,0,0,0,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,127,255,127,
72 255,127,255,127,255,127,255,127,255,127,255,127,
73 255,127,255,127,255,127,255,127,255,127,255,127,
74 255,127,255,127,255,127,255,127,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 255,255,255,255,255,255,255,255,255,255,255,255,
94 255,255,255,255,255,255,255,255,255,255,255,255,
95 255,255,255,255,255,255,255,255,255,255,255,255,
96 0,0,6,6,6,6,6,0,0,0,0,0,
97 1,128,15,0,1,1,1,15,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 0,0,0,0,0,0,0,0,0,0,0,0,
102 0,0,0,0,0,0,0,0,0,0,0,0,
103 0,0,0,0,0,0,0,0,0,0,0,0,
104 'C'-54,'Y'-54,'G'-54,'N'-54,'E'-54,0,0,0,0,0,0,0,0,0,0,
105 0,32,1,1,33,1,4,0,1,
106 0,152,60,127,74,1,53,1,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,255,255,255,255,255,255,255,255,
115 255,255,255,255,255,255,255,255,255,255,255,255,
116 255,255,255,255,255,255,255,255,255,255,255,255,
117 255,255,255,255
118 };
119
120 static uint8_tcxx . . $ uint8_t# iEEPROM_Commandcxx . . $ iEEPROM_Command., EEPROM_Commandcxx . . $ EEPROM_Command.;
121 static uint16_tcxx . . $ uint16_t# iEEPROM_Addresscxx . . $ iEEPROM_Address., EEPROM_Addresscxx . . $ EEPROM_Address.;
122
123 uint8_tcxx . . $ uint8_t# WSwan_EEPROMReadcxx . . $ WSwan_EEPROMRead(32407b39b2dfce37).(uint32_tcxx . . $ uint32_t# A)
124 {
125 switch(A)
126 {
127 default:
128 break;
129 case 0xBA:
130 return(iEEPROMcxx . . $ iEEPROM.[(iEEPROM_Addresscxx . . $ iEEPROM_Address. << 1) & 0x3FF]);
131 case 0xBB:
132 return(iEEPROMcxx . . $ iEEPROM.[((iEEPROM_Addresscxx . . $ iEEPROM_Address. << 1) | 1) & 0x3FF]);
133 case 0xBC:
134 return(iEEPROM_Addresscxx . . $ iEEPROM_Address. >> 0);
135 case 0xBD:
136 return(iEEPROM_Addresscxx . . $ iEEPROM_Address. >> 8);
137 case 0xBE:
138 if(iEEPROM_Commandcxx . . $ iEEPROM_Command. & 0x20)
139 return iEEPROM_Commandcxx . . $ iEEPROM_Command.|2;
140 if(iEEPROM_Commandcxx . . $ iEEPROM_Command. & 0x10)
141 return iEEPROM_Commandcxx . . $ iEEPROM_Command.|1;
142 return iEEPROM_Commandcxx . . $ iEEPROM_Command. | 3;
143 case 0xC4:
144 return(wsEEPROMcxx . . $ wsEEPROM.[(EEPROM_Addresscxx . . $ EEPROM_Address. << 1) & (eeprom_sizecxx . . $ eeprom_size. - 1)]);
145 case 0xC5:
146 return(wsEEPROMcxx . . $ wsEEPROM.[((EEPROM_Addresscxx . . $ EEPROM_Address. << 1) | 1) & (eeprom_sizecxx . . $ eeprom_size. - 1)]);
147 case 0xC6:
148 return(EEPROM_Addresscxx . . $ EEPROM_Address. >> 0);
149 case 0xC7:
150 return(EEPROM_Addresscxx . . $ EEPROM_Address. >> 8);
151 case 0xC8:
152 if(EEPROM_Commandcxx . . $ EEPROM_Command. & 0x20)
153 return EEPROM_Commandcxx . . $ EEPROM_Command.|2;
154 if(EEPROM_Commandcxx . . $ EEPROM_Command. & 0x10)
155 return EEPROM_Commandcxx . . $ EEPROM_Command.|1;
156 return EEPROM_Commandcxx . . $ EEPROM_Command. | 3;
157 }
158
159 return 0;
160 }
161
162
163 void WSwan_EEPROMWritecxx . . $ WSwan_EEPROMWrite(cc289a6b3dfc48da).(uint32_tcxx . . $ uint32_t# A, uint8_tcxx . . $ uint8_t# V)
164 {
165 switch(A)
166 {
167 case 0xBA:
168 iEEPROMcxx . . $ iEEPROM.[(iEEPROM_Addresscxx . . $ iEEPROM_Address. << 1) & 0x3FF] = V;
169 break;
170 case 0xBB:
171 iEEPROMcxx . . $ iEEPROM.[((iEEPROM_Addresscxx . . $ iEEPROM_Address. << 1) | 1) & 0x3FF] = V;
172 break;
173 case 0xBC:
174 iEEPROM_Addresscxx . . $ iEEPROM_Address. &= 0xFF00; iEEPROM_Addresscxx . . $ iEEPROM_Address. |= (V << 0);
175 break;
176 case 0xBD:
177 iEEPROM_Addresscxx . . $ iEEPROM_Address. &= 0x00FF; iEEPROM_Addresscxx . . $ iEEPROM_Address. |= (V << 8);
178 break;
179 case 0xBE:
180 iEEPROM_Commandcxx . . $ iEEPROM_Command. = V;
181 break;
182 case 0xC4:
183 wsEEPROMcxx . . $ wsEEPROM.[(EEPROM_Addresscxx . . $ EEPROM_Address. << 1) & (eeprom_sizecxx . . $ eeprom_size. - 1)] = V;
184 break;
185 case 0xC5:
186 wsEEPROMcxx . . $ wsEEPROM.[((EEPROM_Addresscxx . . $ EEPROM_Address. << 1) | 1) & (eeprom_sizecxx . . $ eeprom_size. - 1)] = V;
187 break;
188 case 0xC6:
189 EEPROM_Addresscxx . . $ EEPROM_Address. &= 0xFF00; EEPROM_Addresscxx . . $ EEPROM_Address. |= (V << 0);
190 break;
191 case 0xC7:
192 EEPROM_Addresscxx . . $ EEPROM_Address. &= 0x00FF; EEPROM_Addresscxx . . $ EEPROM_Address. |= (V << 8);
193 break;
194 case 0xC8:
195 EEPROM_Commandcxx . . $ EEPROM_Command. = V;
196 break;
197 }
198 }
199
200 void WSwan_EEPROMResetcxx . . $ WSwan_EEPROMReset(49f6e7a06ebc5aa8).(void)
201 {
202 iEEPROM_Commandcxx . . $ iEEPROM_Command. = EEPROM_Commandcxx . . $ EEPROM_Command. = 0;
203 iEEPROM_Addresscxx . . $ iEEPROM_Address. = EEPROM_Addresscxx . . $ EEPROM_Address. = 0;
204 }
205
206 #define mBCD16cxx . . $ `mednafen/wswan/eeprom.c:206:10`!(value) ( (((((value)%100) / 10) <<4)|((value)%10)) | ((((((value / 100)%100) / 10) <<4)|((value / 100)%10))<<8) )
207 #define INT16_TO_BCDcxx . . $ `mednafen/wswan/eeprom.c:207:9`!(A) ((((((A) % 100) / 10) * 16 + ((A) % 10))) | (((((((A) / 100) % 100) / 10) * 16 + (((A) / 100) % 10))) << 8))
208
209 void WSwan_EEPROMInitcxx . . $ WSwan_EEPROMInit(3e1aae3d42b5adca).(const char *Name, const uint16_tcxx . . $ uint16_t# BYear, const uint8_tcxx . . $ uint8_t# BMonth, const uint8_tcxx . . $ uint8_t# BDay, const uint8_tcxx . . $ uint8_t# Sex, const uint8_tcxx . . $ uint8_t# Blood)
210 {
211 unsigned x;
212 uint16_tcxx . . $ uint16_t# bcd_BYear;
213
214 memsetcxx . . $ memset(d1de1e4fb215f1c6).(wsEEPROMcxx . . $ wsEEPROM., 0, 2048);
215 memcpycxx . . $ memcpy(cc817cb175f282d).(iEEPROMcxx . . $ iEEPROM., iEEPROM_Initcxx . . $ iEEPROM_Init., 0x400);
216
217 for(x = 0; x < 16; x++)
218 {
219 uint8_tcxx . . $ uint8_t# zechar = 0;
220
221 if(x < strlencxx . . $ strlen(751346f8406fd082).(Name))
222 {
223 char tc = touppercxx . . $ `<external>/17904084882347303253/ctype.h:221:11`!(Name[x]);
224 if(tc == ' ') zechar = 0;
225 else if(tc >= '0' && tc <= '9') zechar = tc - '0' + 0x1;
226 else if(tc >= 'A' && tc <= 'Z') zechar = tc - 'A' + 0xB;
227 else if(tc >= 'a' && tc <= 'z') zechar = tc - 'a' + 0xB + 26;
228 }
229 iEEPROMcxx . . $ iEEPROM.[0x360 + x] = zechar;
230 }
231
232 bcd_BYear = INT16_TO_BCDcxx . . $ `mednafen/wswan/eeprom.c:207:9`!(BYear);
233
234 iEEPROMcxx . . $ iEEPROM.[0x370] = (bcd_BYear >> 8) & 0xFF;
235 iEEPROMcxx . . $ iEEPROM.[0x371] = (bcd_BYear >> 0) & 0xFF;
236 iEEPROMcxx . . $ iEEPROM.[0x372] = mBCDcxx . . $ `mednafen/wswan/wswan.h:20:10`!(BMonth);
237 iEEPROMcxx . . $ iEEPROM.[0x373] = mBCDcxx . . $ `mednafen/wswan/wswan.h:20:10`!(BDay);
238 iEEPROMcxx . . $ iEEPROM.[0x374] = Sex;
239 iEEPROMcxx . . $ iEEPROM.[0x375] = Blood;
240 }
241
242 int WSwan_EEPROMStateActioncxx . . $ WSwan_EEPROMStateAction(a45b884b8cf568d5).(StateMemcxx . . $ StateMem# *sm, int load, int data_only)
243 {
244 SFORMATcxx . . $ SFORMAT# StateRegs[] =
245 {
246 SFVARNcxx . . $ `mednafen/state_inline.h:5:9`!(iEEPROM_Command, "iEEPROM_Command"),
247 SFVARNcxx . . $ `mednafen/state_inline.h:5:9`!(iEEPROM_Address, "iEEPROM_Address"),
248 SFVARNcxx . . $ `mednafen/state_inline.h:5:9`!(EEPROM_Command, "EEPROM_Command"),
249 SFVARNcxx . . $ `mednafen/state_inline.h:5:9`!(EEPROM_Address, "EEPROM_Address"),
250 SFARRAYNcxx . . $ `mednafen/state_inline.h:8:9`!((iEEPROM), (sizeof(iEEPROM)), "iEEPROM"),
251 SFARRAYNcxx . . $ `mednafen/state_inline.h:8:9`!(eeprom_size ? wsEEPROM : NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!, eeprom_size, "EEPROM"),
252 { 0, 0, 0, 0 }
253 };
254
255 if(!MDFNSS_StateActioncxx . . $ MDFNSS_StateAction(3f628545d3b0df83).(sm, load, data_only, StateRegs, "EEPR", falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!))
256 return 0;
257
258 return 1;
259 }