TriOS-alt/system/regnatix/regime.spin

622 lines
48 KiB
Plaintext
Raw Normal View History

2010-03-22 21:49:23 +01:00
<EFBFBD><EFBFBD>{{
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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 : Regime
Chip : Regnatix
Typ : Programm
Version : 00
Subversion : 02
Funktion : "Regime" ist ein einfacher Kommandozeileninterpreter.
Logbuch :
13-03-2009-dr235 - parameter<00>bergabe f<00>r externe kommandos implementiert
- korrektes screeninit nach bload
19-11-2008-dr235 - erste version aus dem ispin-projekt extrahiert
- ios als object extrahiert
21-11-2008-dr235 - dir um parameter b und m erweitert
- externe kommandos werden jetzt gestartet
20-01-2009-dr235 - bootmechanismus f<00>r bellatrix implementiert
18-08-2009-dr235 - dir erweitert um angabe des extenders (dir b .EXT)
22-03-2010-dr235 - anpassung trios
Kommandoliste:
- siehe regime.txt
}}
OBJ
num: "numbers"
ios: "ios"
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
OS_TIBLEN = 64 'gr<00><00>e des inputbuffers
ERAM = 1024 * 512 * 2 'gr<00><00>e eram
HRAM = 1024 * 32 'gr<00><00>e hram
RMON_ZEILEN = 16 'speichermonitor - angezeigte zeilen
RMON_BYTES = 8 'speichermonitor - zeichen pro byte
RINGBUFFER_LENGTH = 64 'length of each buffer
RINGBUFFERS = 10 'max. buffers
RINGBUFFER_SIZE = RINGBUFFER_LENGTH * RINGBUFFERS 'size if buffer
LIGHTBLUE = 0
YELLOW = 1
RED = 2
GREEN = 3
BLUE_REVERSE = 4
WHITE = 5
RED_INVERSE = 6
MAGENTA = 7
VERSION = $00000002
VAR
'systemvariablen
byte tib[OS_TIBLEN] 'tastatur-input-buffer
byte cmdstr[OS_TIBLEN] 'kommandostring f<00>r interpreter
byte parastr[OS_TIBLEN] 'parameterstring f<00>r interpreter
byte tibpos 'aktuelle position im tib
byte ringbuffer[RINGBUFFER_SIZE] 'ringbuffer
byte ringbufferpos 'position in buffer
byte s_ringbufferpos '"look at"- position
byte rbuffer_filled
byte cog[8] 'array for free-cog counter
byte act_color 'Speicher f<00>r gew<00>hlte zeichenfarbe
PUB main | flag,c, dummy
flag := ios.start 'ios initialisieren
'ios.startram 'init f<00>r ram-upload
act_color := 0 'farbe auf default (grau/blau)
rbuffer_filled := 0
if flag == 0 'kaltstart?
ios.bload(@gdriver) 'bellatrix mit grafiktreiber initialisieren
ios.screeninit(@system1,1) 'systemmeldung
ringbufferpos := 0 'set ringbufferposition to 0
ios.ram_write(1,ios#SIFLAG)
if 0 == ios.ram_read(ios#SIFLAG) 'screen neu initialisieren?
ios.screeninit(@system1,1) 'systemmeldung
ios.ram_write(1,ios#SIFLAG)
{{
rbuffer_filled := ios.ram_read(512) 'anzahl eintr<00>ge im ringpuffer einlesen
****************************************************
hier ringbuffer[] aus eRAM einlesen (Adresse $FC8)
********************************************************}}
ios.printnl
ios.print(@prompt1)
' ****************************************************************
repeat
os_cmdinput 'kommandoeingabe
os_cmdint 'kommandozeileninterpreter
PUB os_cmdinput | charc,i,l,c, dummy 'eingaberoutine f<00>r eine kommandozeile
{{os_cmdinput - eingaberoutine f<00>r eine kommandozeile
tib - eingabepuffer
tibpos - index im tib}}
i := 0
l := 0
ios.print(@prompt2)
tibpos := 0 'tibposition auf anfang setzen
repeat
if ios.keystat > 0 'taste gedr<00>ckt?
charc := ios.key 'tastencode holen
if (tibpos + 1) < OS_TIBLEN 'tastaturpuffer voll?
case charc
ios#CHAR_BS: 'backspace
if tibpos > 0
tibpos--
tib[tibpos] := $0 'letztes zeichen im puffer l<00>schen
ios.printctrl(ios#CHAR_TER_BS) 'steuerzeichen an terminal senden
"<00>!": 'cursor up
tibpos--
tib[tibpos] := $0
ios.curpos1
ios.curoff
ios.print(@leer)
ios.curpos1
tibpos := -1
ios.print(@prompt2)
ios.print(@ringbuffer[s_ringbufferpos * RINGBUFFER_LENGTH])
repeat
tibpos++
until ringbuffer[tibpos+(s_ringbufferpos * RINGBUFFER_LENGTH)] == $0
ios.cursetx(tibpos + 2)
ios.curon
l := 0
repeat
tib[l] := ringbuffer[l+(s_ringbufferpos * RINGBUFFER_LENGTH)]
l++
until ringbuffer[l+(s_ringbufferpos * RINGBUFFER_LENGTH)] == $0
tib[l] := $0
s_ringbufferpos ++
if s_ringbufferpos => rbuffer_filled
s_ringbufferpos := 0
"<00>!": 'cursor down
tibpos--
tib[tibpos] := $0
ios.curpos1
ios.curoff
ios.print(@leer)
ios.curpos1
tibpos := -1
ios.print(@prompt2)
ios.print(@ringbuffer[s_ringbufferpos * RINGBUFFER_LENGTH])
repeat
tibpos++
until ringbuffer[tibpos+(s_ringbufferpos * RINGBUFFER_LENGTH)] == $0
ios.cursetx(tibpos + 2)
ios.curon
l := 0
repeat
tib[l] := ringbuffer[l+(s_ringbufferpos * RINGBUFFER_LENGTH)]
l++
until ringbuffer[l+(s_ringbufferpos * RINGBUFFER_LENGTH)] == $0
tib[l] := $0
if s_ringbufferpos > 0
s_ringbufferpos --
else
if s_ringbufferpos == 0
s_ringbufferpos := rbuffer_filled
other: ios.bus_putchar2(charc) 'sonstige zeichen
if (charc <> ios#CHAR_NL) & (charc <> ios#CHAR_BS) & (charc <> $C2) & (charc <> $C3)'ausser sonderzeichen alles in tib
if (tibpos + 1) < OS_TIBLEN 'tastaturpuffer voll?
tib[tibpos++] := charc
tib[tibpos] := $0
until charc == $0D 'schleife bis RETURN
if (tib[0] <> ios#CHAR_NL) & (tib[0] <> $C2) & (tib[0] <> $C3) & (tib[0] <> $0)
repeat
ringbuffer[i+(ringbufferpos * RINGBUFFER_LENGTH)] := tib[i]
ios.ram_write(tib[i],i+(ringbufferpos * RINGBUFFER_LENGTH)+ $FC8) 'in eRAM schreiben
i++
until tib[i] == $0
ringbuffer[i+(ringbufferpos * RINGBUFFER_LENGTH)] := $0
s_ringbufferpos := ringbufferpos
ringbufferpos++
if ringbufferpos == RINGBUFFERS
ringbufferpos := 0
rbuffer_filled++
if rbuffer_filled > RINGBUFFERS
rbuffer_filled := RINGBUFFERS
ios.ram_write(rbuffer_filled, 512)
tibpos := 0
charc := 0
i := 0
PUB os_nextpara: stradr | i,adr 'liest n<00>chstes parameterfeld aus tib
{{os_nextpara - liest n<00>chstes parameterfeld aus tib und <00>bergibt einen stringzeiger auf einen 0-term-string
stradr: adresse eines string (0-term) mit dem parameter oder 0 (kein parameter)
tibpos: systemvariable wird auf neue position hinter parameter gesetzt}}
i := 0
adr := 0
if tib[tibpos] <> 0
repeat until tib[tibpos] > ios#CHAR_SPACE 'f<00>hrende leerzeichen ausbenden
tibpos++
repeat
parastr[i] := tib[tibpos]
tibpos++
i++
until (tib[tibpos] == ios#CHAR_SPACE) or (tib[tibpos] == 0) 'wiederholen bis leerzeichen oder stringende
parastr[i] := 0
adr := @parastr
result := adr
PUB os_nextpos: pos 'setzt zeiger auf n<00>chste position
if tib[tibpos] <> 0
repeat until tib[tibpos] > ios#CHAR_SPACE 'f<00>hrende leerzeichen ausbenden
tibpos++
result := tibpos
PUB os_cmdint | i 'kommandointerpretere
{{os_cmdint - kommandointerpreter, zeichenkette ab tibpos wird als kommando interpretiert
tibpos - wird auf position hinter kommando neu gesetzt}}
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
os_cmdexec(@cmdstr) 'interpreter aufrufen
tibpos := 0 'tastaturpuffer zur<00>cksetzen
tib[0] := 0
PUB os_cmdexec(stradr) 'kommando im <00>bergebenen string wird als kommando interpretiert
{{os_smdexec - das kommando im <00>bergebenen string wird als kommando interpretiert
stradr: adresse einer stringvariable die ein kommando enth<00>lt}}
if strcomp(stradr,@cmd1) 'help
ios.print(@help1)
elseif strcomp(stradr,@cmd2) 'mount - sd-card mounten
ios.sdmount
elseif strcomp(stradr,@cmd3) 'dir - verzeichnis anzeigen
sddir
elseif strcomp(stradr,@cmd4) 'type - textdatei auf bildschirm ausgeben
sdtype
elseif strcomp(stradr,@cmd5) 'load -
load
elseif strcomp(stradr,@cmd6) 'cls -
ios.printcls
elseif strcomp(stradr,@cmd7) 'bload - treiber --> bellatrix
load_bel
elseif strcomp(stradr,@cmd8) 'del
sddel
elseif strcomp(stradr,@cmd9) 'ver
fVer
elseif strcomp(stradr,@cmd10) 'buffer
show_buf
elseif strcomp(stradr,@cmd11) 'rem
'do nothing
elseif strcomp(stradr,@cmd12) 'echo
c_echo
elseif strcomp(stradr,@cmd13) 'color
c_color
elseif strcomp(stradr,@cmd14) 'cogs
get_free_cogs
elseif testbin(stradr) 'test auf externes kommando
ios.paraset(@tib + os_nextpos) 'parameterstring kopieren
ios.ldbin(stradr) 'anwendung starten
elseifnot FALSE 'kommando nicht gefunden
ios.print(@err1)
ios.print(stradr)
ios.printnl
ios.print(@prompt1)
PUB fVer
ios.print(@clistr)
ios.print(@prog)
ios.printnl
ios.print(@regstr)
ios.printhex(VERSION,6)
ios.printnl
ios.print(@admstr)
ios.printhex(ios.get_version(1),6)
ios.printnl
ios.print(@belstr)
ios.printhex(ios.get_version(2),6)
ios.printnl
PUB get_free_cogs | i,l
i := 0
ios.print(@cogs4)
ios.printnl
ios.setcolor(act_color)
'**********************************************
i := 0
i := ios.getcogs(0) 'regnatix
l := 8 - i
ios.print(@regstr)
repeat
ios.setcolor(RED)
ios.print(string("" "))
l--
until l == 0
repeat
ios.setcolor(GREEN)
ios.print(string("" "))
i--
until i == 0
ios.setcolor(act_color)
ios.printnl
i := 0
i := ios.getcogs(1) 'administra
l := 8 - i
ios.print(@admstr)
repeat
ios.setcolor(RED)
ios.print(string("" "))
l--
until l == 0
repeat
ios.setcolor(GREEN)
ios.print(string("" "))
i--
until i == 0
ios.setcolor(act_color)
ios.printnl
i := 0
i := ios.getcogs(2) 'bellatrix
l := 8 - i
ios.print(@belstr)
repeat
ios.setcolor(RED)
ios.print(string("" "))
l--
until l == 0
repeat
ios.setcolor(GREEN)
ios.print(string("" "))
i--
until i == 0
'************************************
ios.setcolor(act_color)
ios.printnl
ios.print(@cogs4)
ios.printnl
ios.print(string(" ("))
ios.setcolor(RED)
ios.print(string("" "))
ios.setcolor(act_color)
ios.print(@cogs5)
ios.printnl
PUB c_echo | i
ios.printnl
ios.print(@tib[5])
ios.printnl
PUB c_color | i
i := (tib[6] - 48)
'ios.printdec(i)
ios.setcolor(i)
act_color := i
PUB sddel | stradr,status 'datei auf sdcard l<00>schen
{{sddel - datei auf sdcard l<00>schen}}
stradr := os_nextpara 'dateinamen von komandozeile holen
status := ios.sdopen("r",stradr) 'test ob datei vorhanden
ios.sdclose
if status == 0 'datei ist vorhanden
ios.print(@msg2) 'datei l<00>schen?
if ios.keywait <> "j"
ios.print(string("nein"))
ios.printnl
return
else
ios.print(string("ja"))
ios.printnl
ios.sdopen("d",stradr) 'datei l<00>schen
ios.sdclose
else
ios.print(@msg1) 'datei nicht gefunden
ios.printnl
PUB show_buf | i,l
ios.printnl
i := 0
l := 0
ios.print(@ring)
ios.printnl
repeat
ios.printdec(i)
ios.print(string(" : "))
ios.print(@ringbuffer[l+(i * RINGBUFFER_LENGTH)])
ios.printnl
l := 0
i++
until i == RINGBUFFERS
PUB load_bel | stradr,status 'treiber f<00>r bellatrix laden
{{bload - treiber f<00>r bellatrix laden}}
stradr := os_nextpara
status := ios.sdopen("r",stradr)
if status == 0
ios.breset 'bellatrix neu starten
waitcnt(cnt + 200_000_000) 'warte bis bel fertig ist
ios.bload(stradr) 'treiberupload
waitcnt(cnt + 200_000_000) 'warte bis bel fertig ist
ios.screeninit(@system1,1) 'systemmeldung
else
ios.print(@err1)
ios.print(stradr)
ios.printnl
PUB testbin(stradr): flag | status,i,len 'testet ob das kommando als bin-datei vorliegt
{{testbin(stradr): flag - testet ob das kommando als bin-datei vorliegt
- string bei stradr wird um .bin erweitert
- flag = TRUE - kommando gefunden}}
flag := FALSE
len := strsize(stradr)
repeat i from 0 to 3 '.bin anh<00>ngen
byte[stradr][len + i] := byte[@ext1][i]
byte[stradr][len + i] := 0
status := ios.sdopen("r",stradr) 'datei vorhanden?
if 0 == status
flag := TRUE
ios.sdclose
PUB load | len,i,stradr1,stradr2 'startet bin-datei <00>ber loader
{{ldbin - startet bin-datei <00>ber loader}}
ios.paraset(@tib + os_nextpos) 'parameterstring kopieren
ios.ldbin(os_nextpara)
PUB sdtype | stradr,status,char,n,k 'textdatei ausgeben
{{sdtype <name> - textdatei ausgeben}}
stradr := os_nextpara 'dateinamen von kommandozeile holen
status := ios.sdopen("r",stradr) 'datei <00>ffnen
if status > 0
ios.print(string("Status : "))
ios.printdec(status)
ios.printnl
n := 1
if status == 0
repeat 'text ausgeben
char := ios.sdgetc
if char <> $FF
ios.printchar(char)
if char == ios#CHAR_NL 'zeilenzahl z<00>hlen und stop
if ++n == 20
n := 1
k := ios.keywait 'q bricht ab
if k == "q"
char := $FF
until char == $FF
status := ios.sdclose 'datei schlie<00>en
if status > 0
ios.print(string("Status : "))
ios.printdec(status)
ios.printnl
PUB sddir | stradr,n,c,i,len,wf,bf,mf,lf,ext 'cmd: dir - verzeichnis anzeigen
{{sddir - anzeige verzeichnis}}
stradr := os_nextpara
wf := bf:= lf := mf :=0
if stradr <> 0
len := strsize(stradr)
repeat i from 0 to len - 1
case byte[stradr][i]
"w": wf := 1 'merspaltig
"b": bf := 1 'extender
"m": mf := 1 'more
"l": lf := 1 'long
if bf == 1 'extender einlesen
ext := os_nextpara
ios.sddir 'kommando: verzeichnis <00>ffnen
n := 1
c := i := 0
repeat 'wiederhole bis verzeichnisende
stradr := ios.sdnext 'einen eintrag holen
if stradr <> 0 'ist eintrag g<00>ltig?
i++
len := strsize(stradr)
if bf == 1 'nur dateien mit entsprechendem extender
if strcomp(ext,(stradr+len-4)) '(@ext1,(stradr+len-4))
n++
ios.print(stradr)
if wf == 1
c++
ios.printtab
if wf == 0 OR c == 3
ios.printnl
c := 0
else 'alle dateien
n++
ios.print(stradr)
if wf == 1
c++
ios.printtab
if (wf == 0 OR c == 3) AND bf == 0
if lf == 1 'long-ausgabe
ios.printtab
ios.printhex(ios.sdfattrib,2) 'attribute
ios.printchar(":")
printftime(ios.sdftime)
ios.printtab
ios.printdec(ios.sdfsize) 'dateigr<00><00>e
ios.printnl
c := 0
if mf == 1 AND i == 10
ios.printnl
ios.print(@wait1)
if ios.keywait == "q"
return
ios.printnl
i := 0
while stradr <> 0 'wiederholen solange stradr <> 0
if wf == 1
ios.printnl
ios.printdec(--n)
ios.print(string(" Datei(en)"))
ios.printnl
PUB printftime(wert) | n 'zeitstempel ausgeben
n := (wert >> 26 & %1111111) + 1980
ios.printdec(n)
ios.printchar("-")
n := (wert >> 22 & %1111)
ios.printdec(n)
ios.printchar("-")
n := (wert >> 17 & %1111)
ios.printdec(n)
ios.printchar(" ")
n := (wert >> 12 & %1111)
ios.printdec(n)
ios.printchar(":")
n := (wert >> 6 & %111111)
ios.printdec(n)
ios.printchar(" ")
DAT
cstr byte "" " " " " " " " ",0
clistr byte "CLI : ",0
regstr byte "Regnatix : ",0
admstr byte "Administra: ",0
belstr byte "Bellatrix : ",0
cogs4 byte "%%%%%%%%%%%%%%%%%%%%",0
cogs5 byte " = running cog)",0
ring byte "Inhalt des Ringpuffers:",0
leer byte " ",0
system1 byte "<00>%Hive", 0
prog byte "Regime V. 0.2 - 2009 - kr/rd",0
prompt1 byte "ok ", $0d, 0
prompt2 byte "~ ", 0
prompt3 byte "" ", 0
msg1 byte "Datei nicht gefunden!",0
msg2 byte "Datei l<00>schen? <j/n> : ",0
err1 byte "? ",0
ext1 byte ".BIN",0
wait1 byte "<WEITER? */q:>",0
cmd1 byte "help",0
cmd2 byte "mount",0
cmd3 byte "dir",0
cmd4 byte "type",0
cmd5 byte "load",0
cmd6 byte "cls",0
cmd7 byte "bload",0
cmd8 byte "del",0
cmd9 byte "ver",0
cmd10 byte "rbuffer",0
cmd11 byte "rem",0
cmd12 byte "echo",0
cmd13 byte "color",0
cmd14 byte "cogs",0
gdriver byte "bel.sys", 0 'name des grafiktreibers
help1 file "regime.txt"
byte $0d,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. %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
}}