PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
mbm29f033c.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
11#include "acflash_internal.h"
12
13static int flash_erase_0(flash_addr_t addr);
14static int flash_program_0(flash_addr_t addr, const flash_data_t *buf, int size);
15static int flash_reset_0(flash_addr_t addr);
16static int flash_status_0(flash_addr_t addr);
17
18static struct flash_ops ops_22 = {
19 "Fujitsu 29F033C", 131072u, 64u, 0, &flash_erase_0, &flash_program_0, &flash_reset_0, &flash_status_0};
20
21static void flash_delay(int x)
22{
23 int v1;
24
25 v1 = x - 1;
26 while ( v1-- >= 0 )
27 ;
28}
29
30static int flash_erase_0(flash_addr_t addr)
31{
32 int count;
33 int pass;
34 int i;
35 unsigned int v8;
36 int v9;
37
38 count = 0;
39 pass = 0;
40 i = 1;
41 *(volatile acUint16 *)addr = 0xAAAA;
42 *(volatile acUint16 *)addr = 0x5555;
43 *(volatile acUint16 *)addr = 0x8080;
44 *(volatile acUint16 *)addr = 0xAAAA;
45 *(volatile acUint16 *)addr = 0x5555;
46 *(volatile acUint16 *)addr = 0x3030;
47 while ( i >= 0 )
48 {
49 int threshold;
50 int shift;
51 acUint16 tmp_var;
52
53 threshold = 200;
54 shift = 8 * i;
55 tmp_var = *(volatile acUint16 *)addr >> (8 * i);
56 do
57 {
58 v8 = tmp_var ^ (*(volatile acUint16 *)addr >> (shift & 0xFF));
59 tmp_var = *(volatile acUint16 *)addr >> (shift & 0xFF);
60 if ( ((v8 >> 6) & 1) == 0 )
61 break;
62 if ( threshold <= 0 )
63 DelayThread(200);
64 else
65 --threshold;
66 ++count;
67 } while ( ((uiptr)tmp_var & 0x20) == 0 );
68 if ( ((tmp_var ^ ((*(volatile acUint16 *)addr >> (shift & 0xFF)) & 0xFF)) & 0x40) == 0 )
69 ++pass;
70 --i;
71 }
72 v9 = -116;
73 if ( pass == 2 )
74 v9 = count;
75 if ( v9 < 0 )
76 return -116;
77 return 0x20000;
78}
79
80static int flash_program_0(flash_addr_t addr, const flash_data_t *buf, int size)
81{
82 int v4;
83 int rest;
84 acUint8 d;
85 int threshold;
86 int v15;
87 acUint8 x;
88
89 v4 = size;
90 rest = size;
91 while ( 1 )
92 {
93 int count;
94 int pass;
95 int i;
96 flash_data_t data;
97 int v11;
98 int shift;
99 int tmp_v12;
100
101 if ( rest <= 0 )
102 return v4 - rest;
103 count = 0;
104 pass = 0;
105 i = 1;
106 data = *buf;
107 *(volatile acUint16 *)addr = 0xAAAA;
108 *(volatile acUint16 *)addr = 0x5555;
109 *(volatile acUint16 *)addr = 0xA0A0;
110 v11 = data;
111 *(volatile acUint16 *)addr = data;
112 shift = 8;
113 while ( i >= 0 )
114 {
115 d = (v11 >> (shift & 0xFF)) & 0xFF;
116 threshold = 200;
117 v15 = (v11 >> (shift & 0xFF)) & 0xFF;
118 do
119 {
120 x = ((int)*(volatile acUint16 *)addr >> (shift & 0xFF)) & 0xFF;
121 if ( v15 == x )
122 break;
123 if ( threshold <= 0 )
124 {
125 DelayThread(200);
126 }
127 else
128 {
129 --threshold;
130 }
131 ++count;
132 } while ( (x & 0x20) == 0 );
133 if ( d == (((int)*(volatile acUint16 *)addr >> (shift & 0xFF)) & 0xFF) )
134 ++pass;
135 shift = 8 * --i;
136 }
137 tmp_v12 = -116;
138 if ( pass == 2 )
139 tmp_v12 = count;
140 if ( tmp_v12 < 0 )
141 return rest - v4;
142 ++buf;
143 rest -= 2;
144 }
145}
146
147static int flash_reset_0(flash_addr_t addr)
148{
149 *(acUint16 *)addr = 0xF0F0;
150 flash_delay(100);
151 return 0x800000;
152}
153
154static int flash_status_0(flash_addr_t addr)
155{
156 int pass;
157 int i;
158
159 (void)addr;
160 pass = 0;
161 for ( i = 1; i >= 0; --i )
162 ++pass;
163 if ( pass == 2 )
164 return 1;
165 return 2;
166}
167
168flash_ops_t flash_probe_mbm29f033c(flash_addr_t addr)
169{
170 int vendor;
171 int device;
172
173 flash_reset_0(addr);
174 *(volatile acUint16 *)addr = 0xAAAA;
175 *(volatile acUint16 *)addr = 0x5555;
176 *(volatile acUint16 *)addr = 0x9090;
177 DelayThread(500);
178 vendor = *(volatile acUint16 *)addr;
179 device = *(volatile acUint16 *)(addr + 2);
180 flash_reset_0(addr);
181 // cppcheck-suppress knownConditionTrueFalse
182 if ( vendor != 0x404 || device != 0xD4D4 )
183 {
184 return 0;
185 }
186 return &ops_22;
187}
u32 count
start sector of fragmented bd/file