-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFTLIB.abp
179 lines (141 loc) · 4.24 KB
/
FTLIB.abp
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
#include "FTLIB.idx"
#console
#include <RGBALib.sbp>
Print "PSX PAD MEMORY CARD READER WITH FT232H v2017.4.5 - RGBA_CRT 2017"
Dim ft AS *FT232H
'Block3FF で書き込み実験
ft=new FT232H()
ft->listupDeviceToConsole()
Dim ftID As Long
input "Select device >",ftID
if ft->openDevice(ftID)=FALSE Then Print "OpenError" : End
Print ex"OK.\n"
Locate 0,4
ConsoleClearCurrentLine()
Print "Select:"
Print " 0.View MemCard State"
Print " 1.View GamePad State"
Print " 2.Dump MemCard"
Print " 3.Write Memcard"
Dim mode AS Long,inStr AS String
Do
Locate 0,9
ConsoleClearCurrentLine()
Input ">",mode
Select Case mode
Case 1
padView()
Case 2
Input ex"Input FileName > ",inStr
dumpMemory(inStr)
Case 3
Input ex"Input ImageFileName > ",inStr
writeMemFull(inStr)
Case Else
memStatus()
End Select
Loop
Const CS1_PIN=3 '下位から 0, 1, 2, 3番目のピン
Const CS2_PIN=4
Sub writeMemTest()
Dim buf[129] AS Byte,i AS Long,pdata As *PSX_PAD_DATA
Dim pad AS *FT232H_PS1_PORT,out AS File
pad=new FT232H_PS1_PORT(ft,CS1_PIN,CS2_PIN)
memStatus(pad)
Dim Adr AS Word
Adr=1023
if pad->readMemBlock(0,Adr,buf)=PRMC_NO_CARD Then Print "Card not inserted."
Dump(buf,128+4)
buf[0]++
Dim ret As Long
ret=pad->writeMemBlock(0,Adr,buf)
if ret<>PRMC_OK Then
Print "Write Error!!!!!!!!!!!!!!! : ";ret
Endif
if pad->readMemBlock(0,Adr,buf)=PRMC_NO_CARD Then Print "Card not inserted."
Dump(buf,128+4)
printf(ex"\nsum = %02X\n",pad->calcXOR(Adr,buf))
End Sub
Sub writeMemFull(path AS BytePtr)
Dim in AS File,buf[128] AS Byte
Dim pad AS *FT232H_PS1_PORT,out AS File
pad=new FT232H_PS1_PORT(ft,CS1_PIN,CS2_PIN)
if in.openFile(path,GENERIC_READ)=FALSE Then
Print "OpenFile Error"
ExitSub
End If
Dim i AS Long,e AS Long
For i = 0 To pad->PSX_MEM_NUM_BLOCKS*pad->PSX_MEM_NUM_FRAMES-1
printf("[WRITE]Address : %04X progress : %d%% ErrorCount : %d",i,(i/(pad->PSX_MEM_NUM_BLOCKS*pad->PSX_MEM_NUM_FRAMES)*100) AS DWord,e)
ConsoleReturnLine()
in.read(buf,128)
if pad->writeMemBlock(0,i,buf) <> PRMC_OK Then e++ : i-- : Continue
Next i
Print "WRITE OK."
End Sub
Sub dumpMemory(path AS BytePtr)
Dim buf[129] AS Byte,i AS Long,pdata As *PSX_PAD_DATA
Dim pad AS *FT232H_PS1_PORT,out AS File
pad=new FT232H_PS1_PORT(ft,CS1_PIN,CS2_PIN)
pdata=calloc(sizeof(PSX_PAD_DATA)+19)
out.openFile(path,GENERIC_WRITE)
'Print pad->readMemBlock(0,&H0382,buf)
Dim adr AS DWord,e AS Long
For adr = 0 To pad->PSX_MEM_NUM_BLOCKS*pad->PSX_MEM_NUM_FRAMES-1
printf("[READ]Address : %04X progress : %d%% ErrorCount : %d",adr,(adr/(pad->PSX_MEM_NUM_BLOCKS*pad->PSX_MEM_NUM_FRAMES)*100) AS DWord,e)
ConsoleReturnLine()
if pad->readMemBlock(0,adr,buf) <> PRMC_OK Then e++ : adr-- : Continue
out.write(buf,pad->PSX_MEM_FRAME_SIZE)
Next i
out.close()
Print "ok"
Dump(buf,128)
End Sub
Sub dumpMemFrame(adr AS Word)
Dim buf[129] AS Byte,i AS Long,pdata As *PSX_PAD_DATA
Dim pad AS *FT232H_PS1_PORT,out AS File
pad=new FT232H_PS1_PORT(ft,CS1_PIN,CS2_PIN)
pdata=calloc(sizeof(PSX_PAD_DATA)+19)
out.openFile(sprintfStr("dump_%04X.bin",adr),GENERIC_WRITE)
if pad->readMemBlock(0,adr,buf) <> PRMC_OK Then Print "err"
out.write(buf,pad->PSX_MEM_FRAME_SIZE)
out.close()
Print "ok"
Dump(buf,128)
End Sub
Sub memStatus()
Dim p1s AS BytePtr, p2s AS BytePtr
Dim pad AS *FT232H_PS1_PORT,out AS File
pad=new FT232H_PS1_PORT(ft,CS1_PIN,CS2_PIN)
if pad->isMemoryInserted(0) = TRUE Then
p1s = " INSERTED "
Else
p1s = " NOT INSERTED "
End If
if pad->isMemoryInserted(1) = TRUE Then
p2s = " INSERTED "
Else
p2s = " NOT INSERTED "
End If
printf(ex"Memory card : \n\t\t\t\tPORT1 [%s]\t\tPORT2 [%s]\n\n",p1s,p2s)
End Sub
Sub padView()
Dim buf[129] AS Byte,i AS Long,pdata As *PSX_PAD_DATA
Dim pad AS *FT232H_PS1_PORT,out AS File
pad=new FT232H_PS1_PORT(ft,CS1_PIN,CS2_PIN)
pdata=calloc(sizeof(PSX_PAD_DATA)+19)
Do
Locate 0,10
memStatus()
Locate 0,13
pad->getPadData(0,pdata)
Dump(pdata,sizeof(PSX_PAD_DATA))
pad->printPadData(pdata)
Print
Locate 0,20
pad->getPadData(1,pdata)
Dump(pdata,sizeof(PSX_PAD_DATA))
pad->printPadData(pdata)
Sleep(10)
Loop
End Sub