?? interpreter.bas
字號:
' Getting USER-Input and executes Commands
Declare Sub DoCommand()
Declare Sub ExtractToken()
Declare Function GetNextTokenStr(ByVal pbLen_Max as Byte ) as String
Declare Function GetNextTokenLong(byVAl plMin as Long , byVal plMax as Long ) as Long
Declare Sub PrintParameterErrorl(plParamLow as Long , plParamHigh as Long)
Declare Sub PrintParameterCountError(byVal psParm_Anzahl as String)
Declare Sub GetInput(byVal pbByte as Byte)
Declare Sub PrintPrompt()
Declare Function GetLongFromBuffer(pbSRAMArray as Byte , byVal pbPos as Word) as Long
Declare Function GetWordFromBuffer(pbSRAMArray as Byte , byVal pbPos as Word) as Word
Declare Sub SRAMDump(pwSRAMPointer as Word , byVal pwLength as Word)
Const cpToken_max = 10 ' Count of Tokens in USER-Input
Const cpStrsep = " " ' Blank: Separator between tokens
Const cpNo = 0 '
Const cpYes = 1
Const cPCInput_Len = 40 ' max. length of user-Input
Dim gsPCInput as String * 40 ' holds user-input
Dim gbPosStrParts(cpToken_max) As Byte ' for analysing user-input
Dim gbLenStrParts(cpToken_max) As Byte '
Dim gbCntToken As Byte ' found tokens in user-input
Dim gbToken_Actual as Byte ' actual handled token of user-input
Dim gbPCInPutError as Byte ' holds error-code during analysing user-input
Dim gbPCInputPointer as Byte ' string-pointer during user-input
gbPCInputPointer = 1
Dim CF_TransferBuffer(1024) as Byte ' Transferbuffer von und zur CF for 2 Sectors
Dim TransferBuffer_Write as Word
End
Sub GetInput(pbByte as Byte)
' stores bytes from user and wait for CR (&H13)
Print #1 , chr(pbByte); ' echo back to user
select case pbByte
Case &H0D ' Line-end?
print chr(&H0A)
DoCommand ' analyse command and execute
gbPCInputPointer = 1 ' reset for new user-input
gsPCInput = ""
PrintPrompt
case &H08 ' backspace ?
decr gbPCInputPointer
case Else ' store user-input
mid(gsPCINput , gbPCInputPointer , 1) = pbByte
incr gbPCInputPointer
mid(gsPCInput , gbPCInputPointer , 1) = &H00 ' string-terminator
if gbPCInputPointer > cPCInput_Len then 'don't exceed input-string
gbPCInputPointer = cPCInput_Len
end if
end Select
End Sub
Sub DoCommand
' interpretes the user-input and execute
' Local variables
Local lByte1 as Byte , lByte2 as Byte
Local lInt1 as Integer , lInt2 as Integer
Local lWord1 as Word , lWord2 as Word , lWord3 as Word
Local lLong1 as Long , lLong2 as Long , lLong3 as Long , lLong4 as Long
Local lbPos as Byte
Local lsToken as String * 20 ' Hold Tokens
Local lbLen as Byte
Local lwSRAMPointer as Word
ExtractToken ' token analysing
gbToken_actual = 0 ' reset to beginn of line (first token)
gbPCInputError = cpNo
If gbcntToken > 0 Then ' is there any input
lsToken = GetNextTokenStr(20) ' get first string-token = command
lstoken = ucase(lsToken) ' all uppercase
lwSRAMPointer = varptr(Cf_Transferbuffer(1))
' Pointer to SRAM Buffer
Select Case lsToken
Case "CFI" ' Show CF-Card Information Block
Print #1 , "Read Card Info"
GetDriveIdentity lwSRAMPointer ' read Info to SRAM
TransferBuffer_Write = 0
SRAMDump lwSRAMPointer , 512 ' Dump SRAM
' Get Count of Sectors in Compactflash-Card
lLong1 = GetLongFromBuffer(CF_Transferbuffer(1) , 120) : lLong2 = lLong1 * 512
print lLong1 ; " Sectors = " ; lLong2 ; " Bytes"
' Get Buffersize of Compactflash-Card
lWord1 = GetWordFromBuffer(CF_TransferBuffer(1) , 42)
lLong2 = lWord1 * 512
print "CF-Buffersize = " ; lWord1 ; " Sectors = " ; lLong2 ; " Bytes"
Case "CFR" ' Reset Compactflash Card
DriveReset
Case "MBR" ' Show Masterboot record = Sector 0
lLong1 = 0
print #1 , "Read Master Boot Record ... " ;
ReadSector LWSRAMPointer , lLong1 , 1 ' read Sector to CF_Transferbuffer
TransferBuffer_Write = 0
print #1 , "done"
SRAMDump lwSRAMPointer , 512 ' show CF_Transferbuffer
print #1 , " " : Print #1 , "Partition-Table" : print #1 , " "
lWord1 = 446 ' first partition entry starts at 446
for lByte1 = 1 to 4
lWord2 = lWord1 + 1
if CF_TransferBuffer(lWord2) > 0 then
print #1 , "Partition " ; lByte1 ; " " ;
lWord2 = lWord1 + 8
lLong1 = GetLongFromBuffer(CF_Transferbuffer(1) , lWord2)
lWord2 = lWord1 + 12
lLong2 = GetLongFromBuffer(CF_Transferbuffer(1) , lWord2)
lLong3 = lLong1 + lLong2
print #1 , "Sector: " ; lLong1 ; " to " ; lLong3 ; " = " ; lLong2 ; " Sectors; ";
lWord2 = lWord1 + 5
lByte1 = Cf_TransferBuffer(lWord2)
print #1 , "File-System Type: " ; hex(lByte1)
end if
lWord1 = lWord1 + 16
next
Case "SD" ' Sector Dump
If gbCntToken = 2 then
lLong1 = GetNextTokenLong(0 , 2000000)
lLong2 = lLong1
elseif gbCntToken = 3 then
lLong1 = GetNextTokenLong(0 , 2000000)
lLong2 = GetNextTokenLong(lLong1 , 2000000)
else
PrintparameterCountError "1, 2 "
exit sub
end if
If gbPCInputError = cpNo then
for lLong3 = lLong1 to lLong2
print #1 , "Read Sector: " ; lLong3 ; " ... " ;
ReadSector lwSRAMPointer , lLong3 , 1
TransferBuffer_Write = 0
Print #1 , " done"
SRAMDump lwSRAMPointer , 512
next
End if
Case "MD" ' Memory Dump
lWord2 = 512
if gbCntToken = 1 then
elseif gbCntToken = 2 then
lLong1 = GetNextTokenLong(0 , &HFFFF)
lwSRAMPointer = lLong1 ' assign to word
elseif gbCntToken = 3 then
lLong1 = GetNextTokenLong(0 , &HFFFF)
lwSRAMPointer = lLong1 ' assign to word
lLong2 = GetNextTokenLong(lLong1 , &HFFFF)
lWord2 = lLong2
else
PrintParameterCountError "0, 1, 2 "
end if
if gbPCInputError = cpNo then
SRAMDump lwSRAMPointer , lWord2 ' Show 512 Bytes
End if
Case "SW" ' Sector Write
If gbCntToken = 3 then
lLong1 = GetNextTokenLong(0 , 2000000)
lLong2 = GetNextTokenLong(1 , &H7F)
lByte1 = lLong2
lLong3 = lLong1 + lLong2
elseif gbCntToken = 4 then
lLong1 = GetNextTokenLong(0 , 2000000)
lLong2 = GetNextTokenLong(1 , &H7F)
lByte1 = lLong2
lLong3 = lLong1 + lLong2
lLong4 = GetNextTokenLong(0 , &HFFFF)
lwSRAMPointer = lLong4
else
PrintparameterCountError "2, 3 "
exit sub
end if
If gbPCInputError = cpNo then
print #1 , "Write " ; lByte1 ; " Sector(s) = " ; lLong1 ; " to " ; lLong2 ; " CF-Card from" ;
if gbCntToken = 4 then
print #1 , "SRAM Address " ; hex(lwSRAMPointer) ; " ... " ;
else
print #1 , "Transfer-Buffer ... " ;
end if
WriteSector lwSRAMPointer , lLong1 , lByte1
print #1 , " done"
End If
Case "MT" ' Fill Memory with Text
if gbCntToken > 1 then
lByte1 = gbPosStrParts(2)
do
incr TRANSFERBUFFER_WRITE
lsToken = mid(gsPCInput , lByte1 , 1)
lByte2 = ASC(lsToken)
if lByte2 = 0 then ' String Terminator
exit do
end if
CF_Transferbuffer(Transferbuffer_Write) = lByte2
incr lByte1
loop until Transferbuffer_Write > 1023
End IF
Case "MP" ' Memory Pointer for MB and MT
if gbCntToken = 2 then
lLong1 = GetNextTokenLong(0 , 1023)
if gbPCInputError = cpNo then
TransferBuffer_Write = lLong1
end if
else
PrintParameterCountError "1 "
End if
Case "MB" 'Fill Memory with Same Byte
if gbCntToken > 1 then
for lByte1 = 2 to gbCntToken
lLong1 = GetNextTokenLong(0 , 255)
if gbPCInputError = cpNo then
incr TransferBuffer_Write
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -