TriOS-alt/system/administra/aterm/aterm96.spin

473 lines
33 KiB
Plaintext

CON
_clkfreq = 80_000_000
_clkmode = xtal1 + pll16x
CON
_baudRate = 9600
OBJ
com: "COMEngine.spin"
fat: "admflash-fat.spin"
rtc: "admflash-rtc.spin"
str: "stringEngine.spin"
PUB shell
com.COMEngine(_baudRate)
fat.FATEngine
rtc.pauseForSeconds(5)
com.transmitCharacters(string("FAT Engine Terminal Now Running - Please Mount Disk First! Type... (mount 0)", 13, 13))
repeat
result := shellLine(string(13, ">_ "))
com.transmitCharacters(string("Running command: "))
com.transmitCharacters(result)
str.charactersToLowerCase(result)
com.transmitCharacter(13)
result := \shellCommands(result)
' if(result)
com.transmitCharacter(13)
com.transmitCharacters(string("Error : "))
com.transmitCharacters(str.numberToDecimal(result,4))
com.transmitCharacter(13)
PRI shellCommands(stringPointer)
stringPointer := str.tokenizeCharacters(stringPointer)
programClear(stringPointer)
programEcho(stringPointer)
programDate(stringPointer)
programTime(stringPointer)
programMount(stringPointer)
programUnmount(stringPointer)
programBoot(stringPointer)
programFormat(stringPointer)
programFreeSpace(stringPointer)
programUsedSpace(stringPointer)
programList(stringPointer)
programFind(stringPointer)
programChangeDirectory(stringPointer)
programChangeAttributes(stringPointer)
programRename(stringPointer)
programRemove(stringPointer)
programMakeFile(stringPointer)
programMakeDirectory(stringPointer)
programConcatenate(stringPointer)
programTestDisk(stringPointer)
programTest(stringPointer)
' abort string("Command Not Found")
abort 0
PRI shellLine(prompt)
com.transmitCharacters(prompt)
repeat until(com.receiveCheck(13))
if(com.receiveFull)
com.receiveFlush
com.transmitCharacters(string(13, "Buffer Overflow!", 13))
com.transmitCharacters(prompt)
repeat com.receiveNumber
str.putCharacter(com.receiveCharacter)
return str.trimCharacters(str.getCharacters)
PRI programClear(stringPointer)
if(strcomp(string("clear"), stringPointer))
rtc.pauseForMilliseconds(500)
com.transmitCharacter(0)
abort 0
PRI programEcho(stringPointer)
if(strcomp(string("echo"), stringPointer))
com.transmitCharacters(stringPointer += 5)
com.transmitCharacter(13)
abort 0
PRI programDate(stringPointer)
if(strcomp(string("date"), stringPointer))
com.transmitCharacters(lookup(rtc.getDay: string("Sunday, "), string("Monday, "), string("Tuesday, "), string("Wednesday, "), string("Thursday, "), string("Friday, "), string("Saturday, ")))
com.transmitCharacters(lookup(rtc.getMonth: string("January"), string("Feburary"), string("March"), string("April"), string("May"), string("June"), string("July"), string("August"), string("September"), string("October"), string("November"), string("December")))
com.transmitCharacters(str.numberToDecimal(rtc.getDate, 2))
com.transmitCharacter(",")
com.transmitCharacters(str.numberToDecimal(rtc.getYear, 4))
result := rtc.getHours
stringPointer := string(" AM", 13)
if(result > 12)
stringPointer := string(" PM", 13)
result -= 12
com.transmitCharacters(str.numberToDecimal(result, 2))
com.transmitCharacter(":")
com.transmitCharacters(str.numberToDecimal(rtc.getMinutes, 2) + 1)
com.transmitCharacter(":")
com.transmitCharacters(str.numberToDecimal(rtc.getSeconds, 2) + 1)
com.transmitCharacters(stringPointer)
abort 0
PRI programTime(stringPointer)
if(strcomp(string("time"), stringPointer))
com.transmitCharacters(string("Enter the time.", 13))
rtc.setYear(str.decimalToNumber(shellLine(string("Year (2000 - 2127): "))))
rtc.setMonth(str.decimalToNumber(shellLine(string("Month (1 - 12): "))))
rtc.setDay(str.decimalToNumber(shellLine(string("Day (1 - 7): "))))
rtc.setDate(str.decimalToNumber(shellLine(string("Date (1 - 31): "))))
rtc.setHours(str.decimalToNumber(shellLine(string("Hours (0 - 23): "))))
rtc.setMinutes(str.decimalToNumber(shellLine(string("Minutes (0 - 59): "))))
rtc.setSeconds(str.decimalToNumber(shellLine(string("Seconds (0 - 59): "))))
abort 0
PRI programMount(stringPointer)
if(strcomp(string("mount"), stringPointer))
com.transmitCharacters(str.trimCharacters(fat.mountPartition(str.decimalToNumber(str.tokenizeCharacters(0)), byte[str.tokenizeCharacters(0)])))
com.transmitCharacters(string(" Mounted", 13))
abort 0
PRI programUnmount(stringPointer)
if(strcomp(string("unmount"), stringPointer))
fat.unmountPartition
com.transmitCharacters(string("Done", 13))
abort 0
PRI programBoot(stringPointer) | storage[256]
if(strcomp(string("boot"), stringPointer))
stringPointer := str.tokenizeCharacters(0)
com.transmitCharacters(string("Are you sure you want to reboot from "))
com.transmitCharacters(stringPointer)
bytefill(@storage, 0, 256)
bytemove(@storage, stringPointer, strsize(stringPointer))
if(str.findCharacter(shellLine(string("? Y/N : ")), "Y"))
fat.bootPartition(@storage, "C")
abort 0
PRI programFormat(stringPointer)
if(strcomp(string("format"), stringPointer))
com.transmitCharacters(string("All data will be deleted from the current partition", 13))
if(str.findCharacter(shellLine(string("Are you sure? Y/N : ")), "Y"))
if(str.findCharacter(shellLine(string("Are you really sure? Y/N : ")), "Y"))
fat.formatPartition(str.decimalToNumber(str.tokenizeCharacters(shellLine(string("Enter <Partition Number> <Volume Label> Please: ")))),str.tokenizeCharacters(0), "C")
abort 0
PRI programFreeSpace(stringPointer)
if(strcomp(string("df"), stringPointer))
com.transmitCharacters(str.numberToDecimal(fat.checkFreeSectorCount(byte[str.tokenizeCharacters(0)]), 10))
com.transmitCharacters(string(" Free Sectors", 13))
abort 0
PRI programUsedSpace(stringPointer)
if(strcomp(string("du"), stringPointer))
com.transmitCharacters(str.numberToDecimal(fat.checkUsedSectorCount(byte[str.tokenizeCharacters(0)]), 10))
com.transmitCharacters(string(" Used Sectors", 13))
abort 0
PRI programList(stringPointer)
if(strcomp(string("ls"), stringPointer))
fat.listReset
repeat
result := fat.listName
ifnot(result)
abort 0
com.transmitCharacters(result)
if(fat.listIsReadOnly)
com.transmitCharacters(string(" R"))
else
com.transmitCharacters(string(" _"))
if(fat.listIsHidden)
com.transmitCharacter("H")
else
com.transmitCharacter("_")
if(fat.listIsSystem)
com.transmitCharacter("S")
else
com.transmitCharacter("_")
if(fat.listIsDirectory)
com.transmitCharacter("D")
else
com.transmitCharacter("_")
if(fat.listIsArchive)
com.transmitCharacter("A")
else
com.transmitCharacter("_")
com.transmitCharacters(str.numberToDecimal(fat.listSize, 10))
com.transmitCharacters(string(" Bytes"))
com.transmitCharacters(string(" [ Accessed"))
com.transmitCharacters(str.numberToDecimal(fat.listAccessMonth, 2))
com.transmitCharacter("/")
com.transmitCharacters(str.numberToDecimal(fat.listAccessDay, 2) + 1)
com.transmitCharacter("/")
com.transmitCharacters(str.numberToDecimal(fat.listAccessYear, 4) + 1)
com.transmitCharacters(string(" ] [ Created"))
com.transmitCharacters(str.numberToDecimal(fat.listCreationHours, 2))
com.transmitCharacter(":")
com.transmitCharacters(str.numberToDecimal(fat.listCreationMinutes, 2) + 1)
com.transmitCharacter(":")
com.transmitCharacters(str.numberToDecimal(fat.listCreationSeconds, 2) + 1)
com.transmitCharacters(str.numberToDecimal(fat.listCreationMonth, 2))
com.transmitCharacter("/")
com.transmitCharacters(str.numberToDecimal(fat.listCreationDay, 2) + 1)
com.transmitCharacter("/")
com.transmitCharacters(str.numberToDecimal(fat.listCreationYear, 4) + 1)
com.transmitCharacters(string(" ] [ Modified"))
com.transmitCharacters(str.numberToDecimal(fat.listModificationHours, 2))
com.transmitCharacter(":")
com.transmitCharacters(str.numberToDecimal(fat.listModificationMinutes, 2) + 1)
com.transmitCharacter(":")
com.transmitCharacters(str.numberToDecimal(fat.listModificationSeconds, 2) + 1)
com.transmitCharacters(str.numberToDecimal(fat.listModificationMonth, 2))
com.transmitCharacter("/")
com.transmitCharacters(str.numberToDecimal(fat.listModificationDay, 2) + 1)
com.transmitCharacter("/")
com.transmitCharacters(str.numberToDecimal(fat.listModificationYear, 4) + 1)
com.transmitCharacters(string(" ]", 13))
PRI programFind(stringPointer)
if(strcomp(string("find"), stringPointer))
com.transmitCharacters(str.trimCharacters(fat.listSearch(str.tokenizeCharacters(0))))
com.transmitCharacters(string(" Exist", 13))
abort 0
PRI programChangeDirectory(stringPointer)
if(strcomp(string("cd"), stringPointer))
com.transmitCharacters(str.trimCharacters(fat.changeDirectory(str.tokenizeCharacters(0))))
com.transmitCharacters(string(" Entered", 13))
abort 0
PRI programChangeAttributes(stringPointer)
if(strcomp(string("attrib"), stringPointer))
com.transmitCharacters(str.trimCharacters(fat.changeAttributes(str.tokenizeCharacters(0), str.tokenizeCharacters(0))))
com.transmitCharacters(string(" Changed", 13))
abort 0
PRI programRename(stringPointer)
if(strcomp(string("rename"), stringPointer))
com.transmitCharacters(str.trimCharacters(fat.renameEntry(str.tokenizeCharacters(0), str.tokenizeCharacters(0))))
com.transmitCharacters(string(" Renamed", 13))
abort 0
PRI programRemove(stringPointer)
if(strcomp(string("rm"), stringPointer))
com.transmitCharacters(str.trimCharacters(fat.deleteEntry(str.tokenizeCharacters(0))))
com.transmitCharacters(string(" Deleted", 13))
abort 0
PRI programMakeFile(stringPointer)
if(strcomp(string("mkfile"), stringPointer))
com.transmitCharacters(str.trimCharacters(fat.newFile(str.tokenizeCharacters(0))))
com.transmitCharacters(string(" Created", 13))
abort 0
PRI programMakeDirectory(stringPointer)
if(strcomp(string("mkdir"), stringPointer))
com.transmitCharacters(str.trimCharacters(fat.newDirectory(str.tokenizeCharacters(0))))
com.transmitCharacters(string(" Created", 13))
abort 0
PRI programConcatenate(stringPointer)
if(strcomp(string("cat"), stringPointer))
fat.openFile(str.tokenizeCharacters(0), string("R"))
case byte[str.tokenizeCharacters(0)]
"h", "H":
repeat fat.listSize
com.transmitCharacters(str.numberTohexadecimal(fat.readCharacter, 2))
com.transmitCharacter(" ")
if(++result == 10)
com.transmitCharacter(result~)
"d", "D":
repeat fat.listSize
com.transmitCharacters(str.numberToDecimal(fat.readCharacter, 3))
com.transmitCharacter(" ")
if(++result == 10)
com.transmitCharacter(result~)
"b", "B":
repeat fat.listSize
com.transmitCharacters(str.numberToBinary(fat.readCharacter, 8))
com.transmitCharacter(" ")
if(++result == 10)
com.transmitCharacter(result~)
other:
repeat fat.listSize
result := fat.readCharacter
if(result == 10)
rtc.pauseForMilliseconds(50)
next
com.transmitCharacter(result)
fat.closeFile
abort 0
PRI programTest(stringPointer)
if(strcomp(string("test"), stringPointer))
com.transmitCharacters(string(" Datei erzeugen...", 13))
fat.NewFile(string("ADMTEST.DAT"))
com.transmitCharacters(string(" Datei öffnen...", 13))
fat.openFile(string("ADMTEST.DAT"), "W")
com.transmitCharacters(string(" Daten schreiben...", 13))
repeat 1024
fat.writeCharacter(1)
com.transmitCharacters(string(" Datei schließen...", 13))
fat.closeFile
abort 0
PRI programTestDisk(stringPointer) | counter, buffer[128]
if(strcomp(string("testdisk"), stringPointer))
com.transmitCharacters(result := str.trimCharacters(fat.newFile(str.tokenizeCharacters(0))))
com.transmitCharacters(string(" Created, now testing character write and read speed...", 13, 13))
fat.openFile(result, string("W"))
stringPointer := cnt
counter := 0
repeat 32768
fat.writeCharacter(counter++)
stringPointer := cnt - stringPointer
com.transmitCharacters(string("Wrote 32,768 bytes at"))
com.transmitCharacters(str.numberToDecimal(((((32768 * (^^clkfreq)) / (^^stringPointer)) * (^^clkfreq)) / (^^stringPointer)), 10))
com.transmitCharacters(string(" bytes per second.", 13))
fat.closeFile
fat.openFile(result, string("R"))
stringPointer := cnt
counter := 0
repeat fat.listSize
if(fat.readCharacter <> (counter++ & $FF))
abort string("Data written invalid!")
stringPointer := cnt - stringPointer
com.transmitCharacters(string("Read 32,768 bytes at"))
com.transmitCharacters(str.numberToDecimal(((((32768 * (^^clkfreq)) / (^^stringPointer)) * (^^clkfreq)) / (^^stringPointer)), 10))
com.transmitCharacters(string(" bytes per second.", 13))
fat.closeFile
com.transmitCharacters(string(13, "Now testing block write write and read speed...", 13, 13))
fat.openFile(result, string("W"))
stringPointer := cnt
repeat 64
fat.writeData(@buffer, 512)
stringPointer := cnt - stringPointer
com.transmitCharacters(string("Wrote 32,768 bytes at"))
com.transmitCharacters(str.numberToDecimal(((((32768 * (^^clkfreq)) / (^^stringPointer)) * (^^clkfreq)) / (^^stringPointer)), 10))
com.transmitCharacters(string(" bytes per second.", 13))
fat.closeFile
fat.openFile(result, string("R"))
stringPointer := cnt
repeat 64
fat.readData(@buffer, 512)
stringPointer := cnt - stringPointer
com.transmitCharacters(string("Read 32,768 bytes at"))
com.transmitCharacters(str.numberToDecimal(((((32768 * (^^clkfreq)) / (^^stringPointer)) * (^^clkfreq)) / (^^stringPointer)), 10))
com.transmitCharacters(string(" bytes per second.", 13))
fat.closeFile
' fat.deleteEntry(result)
com.transmitCharacters(string(13, "Test finished!", 13))
abort 0
{{
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ TERMS OF USE: MIT License │
├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │
│files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │
│modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the │
│Software is furnished to do so, subject to the following conditions: │
│ │
│The above copyright notice and this permission notice shall be included in all copies or substantial portions of the │
│Software. │
│ │
│THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │
│WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │
│COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
│ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
}}