-
Notifications
You must be signed in to change notification settings - Fork 0
/
ROM_Class.sbp
247 lines (194 loc) · 5.5 KB
/
ROM_Class.sbp
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
Const FT_EPROM_VPP_PIN = 4
Const FT_EPROM_RST_PIN = 5
Const FT_EPROM_ENABLE_PIN = 6
Const FT_EPROM_READ_ENABLE_PIN = 7
Const FT_EPROM_WRITE = &HFF
Const FT_EPROM_READ = &H00
Enum FT_EPROM_IO
FTE_INPUT
FTE_OUTPUT
End Enum
Class FT232H_PPROM_BASE
Protected
dummy AS DWord
Address AS DWord
Data AS DWord
dir AS FT_EPROM_IO
ft AS *FT232H
mcp As *FT232H_MCP23017
bRomEnalbe AS BOOL
bReadEnable AS BOOL
bWriteEnable AS BOOL
Public
Sub init(ftc AS *FT232H)
ft=ftc
ft->gpio->setACBusDir(&HFF)
ft->gpio->setADBusDir(&HF0)
mcp=new FT232H_MCP23017(ft,3,60)
mcp->SetPort(&H0000,&H0000)
SetLatch(0)
bRomEnalbe=FALSE
bReadEnable=FALSE
bWriteEnable=TRUE
ROMEnable(TRUE)
ReadEnable(TRUE)
WriteEnable(FALSE)
'RST
ft->gpio->setADBusBit(FT_EPROM_RST_PIN,1)
mcp->SetPortValWord(0)
Address=0
dir=FTE_OUTPUT
SetDatabusDirection(FTE_INPUT)
ft->flush()
End Sub
Sub ROMEnable(ef AS BOOL)
if bRomEnalbe <> ef Then
ft->gpio->setADBusBit(FT_EPROM_ENABLE_PIN,not(ef) AND &H01)
bRomEnalbe=ef
End If
End Sub
Sub ReadEnable(ef AS BOOL)
if bReadEnable <> ef Then
if ef=TRUE Then
SetDatabusDirection(FTE_INPUT)
ft->gpio->setADBusBit(FT_EPROM_READ_ENABLE_PIN,not(ef) AND &H01)
Else
ft->gpio->setADBusBit(FT_EPROM_READ_ENABLE_PIN,not(ef) AND &H01)
SetDatabusDirection(FTE_OUTPUT)
End If
bReadEnable=ef
End If
End Sub
Sub SetAddress(adr AS DWord)(forceLatch As BOOL)
'変更の必要がある時だけLATCH
/* if (adr xor Address) >> 16 or forceLatch Then
SetLatch(adr>>16)
End If
*/
if (((adr xor Address) >> 8) And &HFF) or forceLatch Then
mcp->SetPortValWord(adr AS Word)
Else
mcp->SetPortValA(adr AS Word)
End If
Address=adr
End Sub
Sub SetData(data AS Byte)
SetDatabusDirection(FTE_OUTPUT)
ft->gpio->setACBus(data AS Byte)
End Sub
Sub ReadDataRequest()
SetDatabusDirection(FTE_INPUT)
ReadEnable(TRUE)
ft->gpio->ACBusReadRequest()
ReadEnable(FALSE)
End Sub
Sub AreaReadRequest(adr AS DWord,length As DWord)(bRD_pulse AS BOOL, deepRead AS BOOL)
Dim i aS DWord
SetDatabusDirection(FTE_INPUT)
' ft->clockWithNoData(4)
Do
SetAddress(adr+i)
' アドレス伝搬待ち
' 20240104 DMG-BZOJでOEの下げ後のWAITが必要なことが判明
' 20240105 DMG-BZOJではACBusのドライブ電流を16mAから4mAに落としたらこのウェイトは不要なことがわかった
' ft->clockWithNoData(4)
ReadEnable(TRUE)
' データ出力待ち
if bRD_pulse Then ft->clockWithNoData(7) '通常ROM
' ft->clockWithNoData(4) '通常ROM
' ft->clockWithNoData(15) 'NP安定
' 0=8clock = 133.3ns
ft->gpio->ACBusReadRequest()
if deepRead Then
ft->clockWithNoData(15)
ft->gpio->ACBusReadRequest()
ft->clockWithNoData(15)
ft->gpio->ACBusReadRequest()
ft->clockWithNoData(15)
ft->gpio->ACBusReadRequest()
ft->clockWithNoData(15)
ft->gpio->ACBusReadRequest()
Endif
' Readパルス
' 202205 遊戯王でRE Pulseが常に必要なことを確認。RdPluseはウェイトの挿入に使用数量に変更
ReadEnable(FALSE)
i++
if length<=i Then ExitDo
Loop
End Sub
Sub WriteEnable(ef AS BOOL)
if bWriteEnable <> ef Then
if ef=FALSE Then
SetDatabusDirection(FTE_INPUT)
ft->gpio->setADBusBit(FT_EPROM_VPP_PIN,not(ef) AND &H01)
Else
ft->gpio->setADBusBit(FT_EPROM_VPP_PIN,not(ef) AND &H01)
SetDatabusDirection(FTE_OUTPUT)
End If
bWriteEnable=ef
End If
End Sub
Function FT_SendCommands() AS BOOL
FT_SendCommands = ft->sendCommands()
End Function
Function FT_ReceiveData(data AS BytePtr,length AS DWord) AS BOOL
FT_ReceiveData = ft->reciveData(data,length)
End Function
Virtual Sub WriteByte(data AS Byte)
protected
Sub SetLatch(val AS Byte)
ft->gpio->setADBusBit(FT_EPROM_RST_PIN,1) 'LATCH START
mcp->SetPortValA(val) 'LATCH SET
ft->addCommand(ex"¥x9c¥x39¥x00",3) 'Wait 13us
mcp->SetPortValA(val) 'LATCH SET
ft->gpio->setADBusBit(FT_EPROM_RST_PIN,0) 'LATCH HOLD
End Sub
Sub SetDatabusDirection(idr AS FT_EPROM_IO)
if dir=idr Then ExitSub
dir=idr
if idr=FTE_INPUT Then
ft->gpio->setACBusDir(FT_EPROM_READ)
Else
ft->gpio->setACBusDir(FT_EPROM_WRITE)
End If
End Sub
End Class
Class FT232H_DMGROM : Inherits FT232H_PPROM_BASE
Public
Sub FT232H_DMGROM(ftc AS *FT232H)
init(ftc)
End Sub
Function AreaWirte(adr AS DWord,buffer AS BytePtr,length AS DWord) AS BOOL
Dim i AS DWord,checkBuf AS BytePtr,tmp AS DWord
ft->flush()
For i=0 To length-1
SetAddress(adr+i,TRUE)
WriteByte(buffer[i])
if i Mod &H10=0 Then ft->sendCommands()
Next i
ft->addCommand(ex"¥x9c¥xa0¥x00",3) 'wait 55us 0x0080
AreaWirte=TRUE '戻り値:OK
'書き込みチェック
checkBuf = calloc(length+5)
AreaReadRequest(adr,length)
ft->sendCommands()
ft->reciveData(checkBuf,length)
For i=0 To length-1
if buffer[i] <> checkBuf[i] Then
AreaWirte=FALSE '戻り値:NG
ExitFor
End If
Next i
free(checkBuf)
End Function
'このルーチンには一切のムダがないのでいじらないこと(20190905現ざう)
Sub WriteByte(data AS Byte)
ReadEnable(FALSE)
SetData(data) 'SET WRITE DATA
WriteEnable(TRUE)
ft->clockWithNoData(0)
WriteEnable(FALSE)
ft->clockWithNoData(0)
End Sub
Private
End Class