{{ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ 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übergabe fü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ü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öße des inputbuffers ERAM = 1024 * 512 * 2 'größe eram HRAM = 1024 * 32 'größ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ür interpreter byte parastr[OS_TIBLEN] 'parameterstring fü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ür gewählte zeichenfarbe PUB main | flag,c, dummy flag := ios.start 'ios initialisieren 'ios.startram 'init fü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ä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ür eine kommandozeile {{os_cmdinput - eingaberoutine fü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ü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öschen ios.printctrl(ios#CHAR_TER_BS) 'steuerzeichen an terminal senden "↑": '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 "↓": '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ächstes parameterfeld aus tib {{os_nextpara - liest nächstes parameterfeld aus tib und ü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ü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ächste position if tib[tibpos] <> 0 repeat until tib[tibpos] > ios#CHAR_SPACE 'fü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ücksetzen tib[0] := 0 PUB os_cmdexec(stradr) '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,@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öschen {{sddel - datei auf sdcard lö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ö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ö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ür bellatrix laden {{bload - treiber fü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ä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 über loader {{ldbin - startet bin-datei über loader}} ios.paraset(@tib + os_nextpos) 'parameterstring kopieren ios.ldbin(os_nextpara) PUB sdtype | stradr,status,char,n,k 'textdatei ausgeben {{sdtype - textdatei ausgeben}} stradr := os_nextpara 'dateinamen von kommandozeile holen status := ios.sdopen("r",stradr) 'datei ö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ä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ß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 öffnen n := 1 c := i := 0 repeat 'wiederhole bis verzeichnisende stradr := ios.sdnext 'einen eintrag holen if stradr <> 0 'ist eintrag gü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öß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 "▶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öschen? : ",0 err1 byte "? ",0 ext1 byte ".BIN",0 wait1 byte "",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. │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ }}