📄 fileaccess.bas
字号:
Case 32 ' user ID memory
'Build one or more formatted lines
OutAddr = (LineAddrHigh * 65536) + (LineAddr And 65520)
DataCount = 0
Do While DataCount < LineDataCount
'Built a formatted line of data
OutLine = Dec2Hex(OutAddr, 6) & " "
For i = DataCount To DataCount + 15
OutLine = OutLine & Dec2Hex(InData(i), 2) & " "
OutAddr = OutAddr + 1
Next i
DataCount = DataCount + 16
UIDOut.WriteLine (OutLine)
Loop
Case 48 ' config memory
'Build one or more formatted lines
OutAddr = (LineAddrHigh * 65536) + (LineAddr And 65520)
DataCount = 0
Do While DataCount < LineDataCount
'Built a formatted line of data
OutLine = Dec2Hex(OutAddr, 6) & " "
For i = DataCount To DataCount + 15
OutLine = OutLine & Dec2Hex(InData(i), 2) & " "
OutAddr = OutAddr + 1
Next i
DataCount = DataCount + 16
CFGOut.WriteLine (OutLine)
Loop
Case 240 ' EEDATA memory
'Build one or more formatted lines
OutAddr = (LineAddr And 65520)
DataCount = 0
Do While DataCount < LineDataCount
'Built a formatted line of data
OutLine = Dec2Hex(OutAddr, 6) & " "
For i = DataCount To DataCount + 15
OutLine = OutLine & Dec2Hex(InData(i), 2) & " "
OutAddr = OutAddr + 1
Next i
DataCount = DataCount + 16
EEOut.WriteLine (OutLine)
Loop
End Select
Case 1
Exit Do
Case 4
LineAddrHigh = (Val("&H1" & Mid(FileLine, 10, 4)) And 65535)
End Select
End If
Loop
InFile.Close
PMOut.Close
EEOut.Close
UIDOut.Close
CFGOut.Close
End Function
Public Function ImportP16HEXFile(InHEXFile As String) As Integer
Dim FileLine
Dim InData(256) As Byte
Dim LineData As String
Dim LineDataCount As Byte
Dim LineAddr As Long
Dim LineCode As Byte
Dim DataCount As Byte
Dim OutAddr As Long
Dim LongAddr As Long
Dim Checksum As Long
Dim OutOffset As Long
Dim OutLine As String
Dim LineAddrHigh As Long
'Examine the HEX file for incompatability
ImportP16HEXFile = ValidateHEXFile(InHEXFile)
If ImportP16HEXFile < 0 Then
Exit Function
End If
Set fs = CreateObject("Scripting.FileSystemObject")
Set InFile = fs.OpenTextFile(InHEXFile, 1, False, 0)
Set PMOut = fs.CreateTextFile(VB.App.Path & "\" & PicBootS.ProgMemFile, True)
Set EEOut = fs.CreateTextFile(VB.App.Path & "\" & PicBootS.EEDataFile, True)
Do While InFile.AtEndOfStream <> True
FileLine = InFile.ReadLine
'Init the array with 0xFF
For i = 0 To 255
InData(i) = 255
Next i
LineCode = 0
If Mid(FileLine, 1, 1) = ":" Then
'Parse the line
LineDataCount = Val("&H" & Mid(FileLine, 2, 2))
LineAddr = Val("&H1" & Mid(FileLine, 4, 4)) And 65535
LineCode = Val("&H" & Mid(FileLine, 8, 2))
LineData = Mid(FileLine, 10, (LineDataCount * 2))
Select Case LineCode
Case 0
'Get and order the data
OutOffset = LineAddr Mod 16
For i = 0 To LineDataCount - 1
InData(i + OutOffset) = Val("&H" & Mid(LineData, (i * 2) + 1, 2))
Next i
If LineAddrHigh = 0 Then
Select Case Address
Case 0 To 8191 ' regular program memory
'Build one or more formatted lines
OutAddr = (LineAddrHigh * 65536) + (LineAddr And 65520)
DataCount = 0
Do While DataCount < LineDataCount
'Built a formatted line of data
OutLine = Dec2Hex(OutAddr, 6) & " "
For i = DataCount To DataCount + 15
OutLine = OutLine & Dec2Hex(InData(i), 2) & " "
OutAddr = OutAddr + 1
Next i
DataCount = DataCount + 16
PMOut.WriteLine (OutLine)
Loop
Case 8448 To 8959 ' EEDATA memory
OutAddr = (LineAddr And 65520)
DataCount = 0
Do While DataCount < LineDataCount
'Built a formatted line of data
OutLine = Dec2Hex(OutAddr, 6) & " "
For i = DataCount To DataCount + 15
OutLine = OutLine & Dec2Hex(InData(i), 2) & " "
OutAddr = OutAddr + 1
Next i
DataCount = DataCount + 16
EEOut.WriteLine (OutLine)
Loop
End Select
End If
Case 1
Exit Do
Case 4
LineAddrHigh = (Val("&H1" & Mid(FileLine, 10, 4)) And 65535)
End Select
End If
Loop
InFile.Close
PMOut.Close
EEOut.Close
End Function
Function ValidateHEXFile(InHEXFile As String) As Integer
Dim Checksum As Integer
Dim InFileLine As String
Dim DataCount As Integer
Dim AddrCode As Integer
Dim Address As Long
Dim DataByte As Integer
On Error GoTo ErrorHandler
Set fs = CreateObject("Scripting.FileSystemObject")
ChDir VB.App.Path
Set InFile = fs.OpenTextFile(InHEXFile, 1, False, 0)
'Check for an empty file
If InFile.AtEndOfStream = True Then
ValidateHEXFile = -1
InFile.Close
Exit Function
End If
'Validate the file before using it
Do While InFile.AtEndOfStream <> True
InFileLine = InFile.ReadLine
AddrCode = 0
If Mid(InFileLine, 1, 1) = "" Then
DataByte = Asc(" ")
Else
DataByte = Asc(Mid(InFileLine, 1, 1))
End If
'check the line
Select Case DataByte
Case Asc(":")
AddrCode = Val("&H" & Mid(InFileLine, 8, 2))
DataCount = Val("&H" & Mid(InFileLine, 2, 2))
Address = Val("&H1" & Mid(InFileLine, 4, 4)) And 65535
'check count and alignment of regular data
' If AddrCode = 0 Then
' If DataCount Mod 16 <> 0 Then
' ValidateHEXFile = -2
' End If
' If Address Mod 16 <> 0 Then
' ValidateHEXFile = -2
' End If
' End If
Checksum = 0
For i = 0 To DataCount + 4
Checksum = Checksum + Val("&H" & Mid(InFileLine, (2 * i) + 2, 2))
Next i
If (Checksum And 255) <> 0 Then
ValidateHEXFile = -3
InFile.Close
Exit Function
End If
Case Asc(" "), Asc(vbTab), Asc(vbCr), Asc(vbLf)
Case Else
ValidateHEXFile = -4
InFile.Close
Exit Function
End Select
If AddrCode = 1 Then
Exit Do
End If
If InFile.AtEndOfStream = True Then
ValidateHEXFile = -5
InFile.Close
Exit Function
End If
Loop
If ValidateHEXFile <> -2 Then
ValidateHEXFile = 1
End If
InFile.Close
Exit Function
ErrorHandler:
Err.Clear
ValidateHEXFile = -6
InFile.Close
End Function
Function ConvertHEX(InHEXFile As String, OutHEXFile As String) As Integer
Dim BufferData(256) As Byte
Dim BufferCount As Integer
Dim Checksum As Integer
Dim InFileLine As String
Dim OutFileLine As String
Dim DataString As String
Dim DataCount As Integer
Dim DataCode As Integer
Dim Address As Integer
Dim HighAddress As Long
Dim DataStr As String
Dim NewAddr As Long
'Open file objects
Set fs = CreateObject("Scripting.FileSystemObject")
ChDir VB.App.Path
Set InFile = fs.OpenTextFile(InHEXFile, 1, False, 0)
Set OutFile = fs.CreateTextFile(OutHEXFile, True)
Do While InFile.AtEndOfStream <> True
InFileLine = InFile.ReadLine
If Mid(InFileLine, 1, 1) = ":" Then
DataCount = Val("&H" & Mid(InFileLine, 2, 2))
DataCode = Val("&H" & Mid(InFileLine, 8, 2))
Address = Val("&H1" & Mid(InFileLine, 4, 4)) And 65535
DataStr = Mid(InFileLine, 10, DataCount * 2)
Select Case DataCode
Case 0
For i = 0 To DataCount - 1
BufferData(i) = Val("&H" & Mid(DataStr, (i * 2) + 1, 2))
Next i
Case 1
Exit Do
Case 4
HighAddress = Val("&H" & DataStr)
End Select
End If
Loop
InFile.Close
OutFile.Close
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -