Code: Alles auswählen
OBJ
ios: "ios"
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
OS_TIBLEN = 64
VAR
byte tibpos
byte tib[OS_TIBLEN]
byte inputstr
Pub main
ios.start
ios.startram
ios.print(string("Input test"))
ios.printnl
inputstr := os_cmdinput
ios.print(string("You typed: "))
ios.print(inputstr)
ios.stop
PUB os_cmdinput | charc 'eingaberoutine für eine kommandozeile
{{os_cmdinput - eingaberoutine für eine kommandozeile
tib - eingabepuffer
tibpos - index im tib}}
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 anterminal senden
other: ios.bus_putchar2(charc) 'sonstige zeichen
if (charc <> ios#CHAR_NL) & (charc <> ios#CHAR_BS) 'ausser sonderzeichen alles in tib
if (tibpos + 1) < OS_TIBLEN 'tastaturpuffer voll?
tib[tibpos++] := charc
tib[tibpos] := $0
until charc == $0D 'schleife bis RETURN
tibpos := 0
charc := 0