TriOS-alt/system/regnatix/perplex.spin

399 lines
27 KiB
Plaintext

{{
┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Autor: Ingo Kripahle │
│ Copyright (c) 2010 Ingo Kripahle │
│ See end of file for terms of use. │
│ Die Nutzungsbedingungen befinden sich am Ende der Datei │
└──────────────────────────────────────────────────────────────────────────────────────────────────────┘
Informationen : hive-project.de
Kontakt : drohne235@googlemail.com
System : TriOS
Name : plexus-tool
Chip : Regnatix
Typ : Programm
Version :
Subversion :
Logbuch :
24-10-2010-dr235
Kommandoliste:
Notizen:
}}
OBJ
num: "numbers"
ios: "ios"
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
OS_TIBLEN = 64 'gr??e des inputbuffers
VAR
'systemvariablen
byte tib[OS_TIBLEN] 'tastatur-input-buffer
byte cmdstr[OS_TIBLEN] 'kommandostring f?r interpreter
byte token1[OS_TIBLEN] 'parameterstring 1 für interpreter
byte token2[OS_TIBLEN] 'parameterstring 2 für interpreter
byte tibpos 'aktuelle position im tib
long ppos 'puffer für adresse
long pcnt 'puffer für zeilenzahl
byte plxnr 'nummer des geöffneten plexus
PUB main | wflag
ios.start 'ios initialisieren
'ios.startram
ios.printnl
plxnr := 0
repeat
os_cmdinput 'kommandoeingabe
os_cmdint 'kommandozeileninterpreter
PUB os_cmdinput | charc 'sys: stringeingabe eine zeile
''funktionsgruppe : sys
''funktion : stringeingabe eine zeile
''eingabe : -
''ausgabe : -
''variablen : tib - eingabepuffer zur string
'' : tibpos - aktuelle position im tib
ios.print(@prompt2)
tibpos := 0 'tibposition auf anfang setzen
repeat until (charc := ios.keywait) == $0D 'tasten einlesen bis return
if (tibpos + 1) < OS_TIBLEN 'zeile noch nicht zu lang?
case charc
ios#CHAR_BS: 'backspace
if tibpos > 0 'noch nicht anfang der zeile erreeicht?
tib[tibpos--] := 0 'ein zeichen aus puffer entfernen
ios.printctrl(ios#CHAR_TER_BS) 'steuerzeichen an terminal senden
other: 'zeicheneingabe
tib[tibpos++] := charc 'zeichen speichern
ios.printchar(charc) 'zeichen ausgeben
ios.printnl
tib[tibpos] := 0 'string abschließen
tibpos := charc := 0 'werte rücksetzen
PUB os_nxtoken1: stradr 'sys: token 1 von tib einlesen
''funktionsgruppe : sys
''funktion : nächsten token im eingabestring suchen und stringzeiger übergeben
''eingabe : -
''ausgabe : stradr - adresse auf einen string mit dem gefundenen token
''variablen : tib - eingabepuffer zur string
'' : tibpos - aktuelle position im tib
'' : token - tokenstring
stradr := os_tokenize(@token1)
PUB os_nxtoken2: stradr 'sys: token 2 von tib einlesen
''funktionsgruppe : sys
''funktion : nächsten token im eingabestring suchen und stringzeiger übergeben
''eingabe : -
''ausgabe : stradr - adresse auf einen string mit dem gefundenen token
''variablen : tib - eingabepuffer zur string
'' : tibpos - aktuelle position im tib
'' : token - tokenstring
stradr := os_tokenize(@token2)
PUB os_tokenize(token):stradr | i 'sys: liest nächsten token aus tib
i := 0
if tib[tibpos] <> 0 'abbruch bei leerem string
repeat until tib[tibpos] > ios#CHAR_SPACE 'führende leerzeichen ausbenden
tibpos++
repeat until (tib[tibpos] == ios#CHAR_SPACE) or (tib[tibpos] == 0) 'wiederholen bis leerzeichen oder stringende
byte[token][i] := tib[tibpos]
tibpos++
i++
else
token := 0
byte[token][i] := 0
stradr := token
PUB os_nextpos: tibpos2 'sys: setzt zeiger auf nächste position
''funktionsgruppe : sys
''funktion : tibpos auf nächstes token setzen
''eingabe : -
''ausgabe : tibpos2 - position des nächsten tokens in tib
''variablen : tib - eingabepuffer zur string
'' : tibpos - aktuelle position im tib
if tib[tibpos] <> 0
repeat until tib[tibpos] > ios#CHAR_SPACE 'führende leerzeichen ausbenden
tibpos++
return tibpos
PUB os_cmdint 'sys: kommandointerpreter
''funktionsgruppe : sys
''funktion : kommandointerpreter; zeichenkette ab tibpos wird als kommando interpretiert
'' : tibpos wird auf position hinter token gesetzt
''eingabe : -
''ausgabe : -
''variablen : tib - eingabepuffer zur string
'' : tibpos - aktuelle position im tib
repeat 'kommandostring kopieren
cmdstr[tibpos] := tib[tibpos]
tibpos++
until (tib[tibpos] == ios#CHAR_SPACE) or (tib[tibpos] == 0) 'wiederholen bis leerzeichen oder stringende
cmdstr[tibpos] := 0 'kommandostring abschließen
os_cmdexec(@cmdstr) 'interpreter aufrufen
tibpos := 0 'tastaturpuffer zurücksetzen
tib[0] := 0
PUB os_cmdexec(stradr) 'sys: kommando im ?bergebenen string wird als kommando interpretiert
{{os_smdexec - das kommando im ?bergebenen string wird als kommando interpretiert
stradr: adresse einer stringvariable die ein kommando enth?lt}}
if strcomp(stradr,string("help")) 'help
ios.print(@help1)
elseif strcomp(stradr,string("open"))
plx_open
elseif strcomp(stradr,string("close"))
plx_close
elseif strcomp(stradr,string("put"))
plx_put
elseif strcomp(stradr,string("get"))
plx_get
elseif strcomp(stradr,string("testout"))
plx_testout
elseif strcomp(stradr,string("testin"))
plx_testin
elseif strcomp(stradr,string("scan"))
plx_scan
elseif strcomp(stradr,string("reset"))
plx_reset
elseif strcomp(stradr,string("bye"))
ios.stop
elseif strcomp(stradr,string("debug"))
plx_debug
else 'kommando nicht gefunden
ios.print(stradr)
ios.print(@prompt3)
ios.printnl
PRI plx_reset
ios.plx_reset
plxnr := 0
PRI plx_scan|i,anz
ifnot plxnr
i := 1
anz := num.FromStr(os_nxtoken1,num#DEC)
ifnot anz
anz := 8
repeat anz
ios.print(string("Plexus :"))
ios.printtab
ios.printdec(i)
ios.printtab
ios.print(string("Status : "))
ios.printtab
if ios.plx_open(i)
ios.print(string("--"))
else
ios.print(string("ON"))
waitcnt(cnt + clkfreq/100)
ios.plx_close
ios.printnl
i++
waitcnt(cnt + clkfreq/100)
else
os_error(24)
PRI plx_testout|i
if plxnr
i := 0
repeat num.FromStr(os_nxtoken1,num#DEC)
ios.plx_put(1)
ios.plx_put(i++)
else
os_error(23)
PRI plx_testin|wert,i
if plxnr
i := 0
repeat
wert := plx_portin
ios.print(string("get["))
ios.printdec(i++)
ios.print(string("] : "))
ios.printtab
ios.printdec(wert)
ios.printtab
ios.print(string(": $"))
ios.printhex(wert,2)
ios.printtab
ios.print(string(": %"))
ios.printbin(wert,8)
ios.printnl
repeat while (wert == plx_portin) AND (ios.keystat == 0)
until ios.keystat
ios.key
else
os_error(23)
PRI plx_debug
repeat 16
ios.plx_put(2)
plx_get
waitcnt(cnt+clkfreq)
PRI plx_portin:wert
ios.plx_put(2)
wert := ios.plx_get
PRI plx_open
plxnr := num.FromStr(os_nxtoken1,num#DEC)
if os_error(ios.plx_open(plxnr))
plxnr := 0
PRI plx_close
os_error(ios.plx_close)
plxnr := 0
PRI plx_put
if plxnr
ios.plx_put(num.FromStr(os_nxtoken1,num#DEC))
else
os_error(23)
PRI plx_get|wert
if plxnr
wert := ios.plx_get
ios.print(string("get : "))
ios.printdec(wert)
ios.print(string(" : $"))
ios.printhex(wert,2)
ios.print(string(" : %"))
ios.printbin(wert,8)
ios.printnl
else
os_error(23)
PUB os_error(err):error 'sys: fehlerausgabe
if err
ios.printnl
ios.print(@err_s1)
ios.printdec(err)
ios.print(string(" : $"))
ios.printhex(err,2)
ios.printnl
ios.print(@err_s2)
case err
0: ios.print(@err0)
1: ios.print(@err1)
2: ios.print(@err2)
3: ios.print(@err3)
4: ios.print(@err4)
5: ios.print(@err5)
6: ios.print(@err6)
7: ios.print(@err7)
8: ios.print(@err8)
9: ios.print(@err9)
10: ios.print(@err10)
11: ios.print(@err11)
12: ios.print(@err12)
13: ios.print(@err13)
14: ios.print(@err14)
15: ios.print(@err15)
16: ios.print(@err16)
17: ios.print(@err17)
18: ios.print(@err18)
19: ios.print(@err19)
20: ios.print(@err20)
21: ios.print(@err21)
22: ios.print(@err22)
23: ios.print(@err23)
24: ios.print(@err24)
OTHER: ios.print(@errx)
ios.printnl
error := err
DAT
prompt1 byte "ok ", $0d, 0
prompt2 byte ": ", 0
prompt3 byte "? ",0
wait1 byte "<WEITER? */q:>",0
help1 file "perplex.txt"
byte $0d,0
err_s1 byte "Fehlernummer : ",0
err_s2 byte "Fehler : ",0
err0 byte "no error",0
err1 byte "fsys unmounted",0
err2 byte "fsys corrupted",0
err3 byte "fsys unsupported",0
err4 byte "not found",0
err5 byte "file not found",0
err6 byte "dir not found",0
err7 byte "file read only",0
err8 byte "end of file",0
err9 byte "end of directory",0
err10 byte "end of root",0
err11 byte "dir is full",0
err12 byte "dir is not empty",0
err13 byte "checksum error",0
err14 byte "reboot error",0
err15 byte "bpb corrupt",0
err16 byte "fsi corrupt",0
err17 byte "dir already exist",0
err18 byte "file already exist",0
err19 byte "out of disk free space",0
err20 byte "disk io error",0
err21 byte "command not found",0
err22 byte "timeout",0
err23 byte "device not open",0
err24 byte "device is open",0
errx byte "undefined",0
DAT
{{
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ 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. │
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
}}