{{ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ 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 : HSS-Player Chip : Regnatix Typ : Programm Version : 00 Subversion : 02 Funktion : HSS-Player für die Kommandozeile Logbuch : 08-04-2010-dr235 - fork aus regime - anpassung an trios }} OBJ 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 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 byte rows 'aktuelle anzahl der nutzbaren zeilen byte cols 'aktuelle Anzahl der nutzbaren spalten byte cog[8] 'array for free-cog counter byte act_color 'Speicher für gewählte zeichenfarbe long datcnt 'zeiger für dateiliste byte fn[12] 'puffer für dateinamen PUB main | flag flag := ios.start 'ios initialisieren ' ios.startram 'init für ram-upload rows := 23 'zeilenzahl temp. setzen cols := 64 ios.printnl ios.print(@prompt1) repeat cmd_dir ios.printnl os_cmdinput 'kommandoeingabe \os_cmdint 'kommandozeileninterpreter CON ''------------------------------------------------- INTERPRETER 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_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++ 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 ausführen {{os_smdexec - das kommando im übergebenen string wird als kommando interpretiert stradr: adresse einer stringvariable die ein kommando enthält}} if strcomp(stradr,string("stop")) 'stop hss_stop elseif strcomp(stradr,string("pause")) 'pause hss_pause elseif strcomp(stradr,string("play")) 'play hss_play elseif strcomp(stradr,string("rep")) 'repeat hss_repeat elseif strcomp(stradr,string("reg")) 'reg hss_reg elseif strcomp(stradr,string("intreg")) 'intreg hss_intreg elseif strcomp(stradr,string("list")) 'list hss_list elseif strcomp(stradr,string("bye")) 'bye cmd_bye elseif strcomp(stradr,string("help")) 'help cmd_help elseif strcomp(stradr,string("mount")) 'mount - sd-card mounten cmd_mount elseif strcomp(stradr,string("dir")) 'dir - verzeichnis anzeigen cmd_dir elseif strcomp(stradr,string("cls")) 'cls - bildschirm löschen ios.printcls elseif strcomp(stradr,string("unmount")) 'unmount - medium abmelden cmd_unmount elseif strcomp(stradr,string("cd")) 'cd - verzeichnis wechseln cmd_cd elseif os_testhss(stradr) '.hss ios.hss_playfile(stradr) 'datei abspielen else 'kommando nicht gefunden ios.print(@msg1) ios.print(stradr) ios.printnl ios.print(@prompt1) 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) OTHER: ios.print(@errx) ios.printnl error := err PUB os_testhss(stradr): flag | status,i,len 'sys: 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}} 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 status == 0 'datei gefunden flag := TRUE else 'datei nicht gefunden flag := FALSE byte[stradr][len] := 0 'extender wieder abschneiden ios.sdclose PUB str_find(string1, string2) : buffer | counter 'sys: string suchen '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Searches a string of characters for the first occurence of the specified string of characters. │ '' │ │ '' │ Returns the address of that string of characters if found and zero if not found. │ '' │ │ '' │ string1 - A pointer to the string of characters to search. │ '' │ string2 - A pointer to the string of characters to find in the string of characters to search. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ repeat strsize(string1--) if(byte[++string1] == byte[string2]) repeat counter from 0 to (strsize(string2) - 1) if(byte[string1][counter] <> byte[string2][counter]) buffer~~ ifnot(buffer~) return string1 PUB str_lower(characters) '' 4 Stack Longs 'sys: in kleine zeichen wandeln '' ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ '' │ Demotes all upper case characters in the set of ("A","Z") to their lower case equivalents. │ '' │ │ '' │ Characters - A pointer to a string of characters to convert to lowercase. │ '' └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ repeat strsize(characters--) result := byte[++characters] if((result => "A") and (result =< "Z")) byte[characters] := (result + 32) CON ''------------------------------------------------- HSS-KOMMANDOS PUB hss_stop 'hss: player stoppen ios.hss_stop PUB hss_pause 'hss: player pause ios.hss_pause PUB hss_play 'hss: player starten ios.hss_play PUB hss_repeat | stradr,len,fcnt,i 'hss: alle songs auf der sd-card abspielen ios.sddir 'kommando: verzeichnis öffnen hss_startlist 'zum listenanfang fcnt := 0 'zähler für dateianzahl repeat while (stradr := ios.sdnext) 'dateiliste einlesen ios.print(stradr) if str_find(stradr,@ext1) ios.printchar("◀") fcnt++ hss_wrfn(stradr) ios.printnl ios.print(string("Anzahl Dateien : ")) ios.printdec(fcnt) ios.printnl hss_startlist 'zum listenanfang repeat i from 0 to fcnt-1 'dateiliste abspielen hss_rdfn(@fn) hss_playsong(@fn) hss_fadeout ios.printnl PUB hss_fadeout | i 'hss: song langsam ausblenden repeat i from 0 to 15 ios.hss_vol(15 - i) waitcnt(cnt + 60_000_000) waitcnt(cnt + 30_000_000) PUB hss_wrfn(stradr) | len,i 'hss: kopiert dateinamen in eram len := strsize(stradr) repeat i from 0 to len-1 ios.ram_write(byte[stradr][i],datcnt++) ios.ram_write(0,datcnt++) PUB hss_rdfn(stradr) | i,n 'hss: liest dateinamen aus eram i := 0 repeat n := ios.ram_read(datcnt++) byte[stradr][i++] := n while n <> 0 PUB hss_startlist 'hss: zeiger auf listenanfang (dateinamen) datcnt := 0 PUB hss_playsong(stradr) | n,q,key 'hss: spielt die musikdatei bis zum ende ios.curoff ios.print(string("PlaySong : ")) ios.print(stradr) ios.printnl ios.hss_stop ios.hss_playfile(stradr) repeat n := ios.hss_intreg(ios#iRepeat) 'anzahl der schleifendurchläufe abfragen q := ios.hss_intreg(ios#iEndFlag) ios.curpos1 ios.print(string("iRepeat : ")) ios.printdec(n) ios.print(string(" iEndFlag : ")) ios.printdec(q) if ios.key abort until n == 3 or q == 1 ios.printnl ios.curon PUB hss_list | i,n 'hss: trackerliste ausgeben ios.printcls repeat repeat until ios.hss_intreg(ios#iRowFlag) == 0 repeat until ios.hss_intreg(ios#iRowFlag) == 1 'synchronisation bis zeile fertig bearbeitet ios.printhex(ios.hss_intreg(ios#iBeatC),4) ios.printchar("-") ios.printhex(ios.hss_intreg(ios#iEngineC),4) ios.printchar(":") ios.printchar(" ") repeat i from 1 to 4 hss_printnote(ios.hss_intreg(i*5+ios#iNote)) 'note n := ios.hss_intreg(i*5+ios#iOktave) if n ios.printhex(n,1) 'oktave else ios.printchar("-") ios.printchar(" ") n := ios.hss_intreg(i*5+ios#iVolume) if n ios.printhex(n,1) 'volume else ios.printchar("-") ios.printchar(" ") n := ios.hss_intreg(i*5+ios#iEffekt) if n ios.printhex(n,1) 'effekt else ios.printchar("-") ios.printchar(" ") n := ios.hss_intreg(i*5+ios#iInstrument) if n ios.printhex(n,1) 'instrument else ios.printchar("-") ios.printchar(" ") ios.printnl until ios.keystat > 0 'taste gedrückt? ios.key ios.curon ios.printnl PUB hss_printnote(n) 'hss: notenwert ausgeben 'C1,C#1,D1,D#1,E1,F1,F#1,G1,G#1,A1,A#1,H1 case n 0: ios.print(string(" ")) 1: ios.print(string("C ")) 2: ios.print(string("C#")) 3: ios.print(string("D ")) 4: ios.print(string("D#")) 5: ios.print(string("E ")) 6: ios.print(string("F ")) 7: ios.print(string("F#")) 8: ios.print(string("G ")) 9: ios.print(string("G#")) 10: ios.print(string("A ")) 11: ios.print(string("A#")) 12: ios.print(string("H ")) PUB hss_intreg | i,j,n,wert 'hss: anzeige interfaceregister ios.printcls repeat ios.curhome ios.curoff ios.printnl repeat i from 0 to 4 ios.printhex(i*8,2) ios.printchar(":") repeat j from 0 to 4 n := (i*5)+j wert := ios.hss_intreg(n) ios.printhex(wert,4) ios.printchar(" ") ios.printnl until ios.keystat > 0 'taste gedrückt? ios.key ios.curon ios.printnl PUB hss_reg | wert,i,j,n 'hss: kontinuierliche anzeige der regsiterwerte {{ 8 x 6 register long 0 kanal a 3>>16 f 4 v 8 kanal b 16 kanal c 24 kanal d }} ios.printcls repeat ios.curhome ios.curoff repeat j from 0 to 3 ios.printnl ios.printnl ios.printhex(j*8,2) ios.printchar(":") repeat i from 0 to 3 n := (j*8)+i wert := ios.hss_peek(n) ios.printhex(wert,8) ios.printchar(" ") ios.printnl ios.printhex(j*8+4,2) ios.printchar(":") repeat i from 4 to 7 n := (j*8)+i wert := ios.hss_peek(n) ios.printhex(wert,8) ios.printchar(" ") ios.printnl ios.printnl ios.print(string("Channel A F: ")) wert := ios.hss_peek(0+3) ios.printhex(wert>>16,4) ios.print(string(" V: ")) wert := ios.hss_peek(0+4) ios.printhex(wert,2) ios.printnl ios.print(string("Channel B F: ")) wert := ios.hss_peek(8+3) ios.printhex(wert>>16,4) ios.print(string(" V: ")) wert := ios.hss_peek(8+4) ios.printhex(wert,2) ios.printnl ios.print(string("Channel C F: ")) wert := ios.hss_peek(16+3) ios.printhex(wert>>16,4) ios.print(string(" V: ")) wert := ios.hss_peek(16+4) ios.printhex(wert,2) ios.printnl ios.print(string("Channel D F: ")) wert := ios.hss_peek(24+3) ios.printhex(wert>>16,4) ios.print(string(" V: ")) wert := ios.hss_peek(24+4) ios.printhex(wert,2) until ios.keystat > 0 'taste gedrückt? ios.key ios.curon ios.printnl CON ''------------------------------------------------- CLI-KOMMANDOS PUB cmd_bye 'cmd: bye ios.stop PUB cmd_mount | err 'cmd: mount err := ios.sdmount os_error(err) ifnot err ios.print(@msg4) ios.print(ios.sdvolname) ios.printnl PUB cmd_unmount 'cmd: unmount os_error(ios.sdunmount) PUB cmd_cd 'cmd: verzeichnis wechseln os_error(ios.sdchdir(os_nxtoken1)) PUB cmd_help | i,char,n 'cmd: textdatei ausgeben n := i := 1 repeat until (char := byte[@help1][i++]) == 0 'text ausgeben ios.printchar(char) if char == ios#CHAR_NL 'zeilenzahl zählen und stop if ++n == (rows - 2) n := 1 if ios.keywait == "q" return PUB cmd_dir|fcnt,stradr,hflag 'cmd: verzeichnis anzeigen {{sddir - anzeige verzeichnis}} if ios.sdcheckmounted 'test ob medium gemounted ist hflag := 1 stradr := os_nxtoken1 'parameter einlesen ios.print(@msg5) ios.print(@msg3) ios.print(ios.sdvolname) ifnot os_error(ios.sddir) 'verzeichnis öffnen fcnt := cmd_dir_w(hflag) ios.printnl ios.print(@msg5) ios.print(@msg4) ios.printdec(fcnt) else os_error(1) PUB cmd_dir_w(hflag):fcnt|stradr,lcnt,wcnt 'cmd: kurze dir-anzeige fcnt := 0 lcnt := (rows - 2) * 4 wcnt := 3 ios.printnl repeat while (stradr := ios.sdnext) ifnot ios.sdfattrib(ios#F_HIDDEN) & hflag 'versteckte dateien anzeigen? if ios.sdfattrib(ios#F_DIR) 'verzeichnisname ios.setcolor(1) ios.print(string("▶ ")) ios.print(stradr) ios.setcolor(0) elseif ios.sdfattrib(ios#F_HIDDEN) ios.setcolor(2) ios.print(string(" ")) str_lower(stradr) ios.print(stradr) ios.setcolor(0) else 'dateiname ios.print(string(" ")) str_lower(stradr) ios.print(stradr) ifnot wcnt-- wcnt := 3 ios.printnl else ios.printtab fcnt++ ifnot --lcnt lcnt := (rows - 2) * 4 if ios.keywait == "q" return DAT 'strings prompt1 byte " ok ", $0d, 0 prompt2 byte "~ ", 0 msg1 byte " ? ",0 msg2 byte "Volume : ",0 msg3 byte "Datenträger : ",0 msg4 byte "Anzahl der Dateien : ",0 msg5 byte "• ",0 ext1 byte ".HSS",0 help1 file "hplay.txt" byte 13,0 DAT 'systemfehler 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 errx byte "undefined",0 DAT 'lizenz {{ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ 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. │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ }}