pst printing variable
Hi, I was using the "lookup" command and having a problem with the pst commands to print out the lookup index. I can't find a similar example. I have tried "pst.chars", and "pst.dec". what is the proper way to print the sting or value of "list" associated with lookup? Thanks
CON
_clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz
_xinfreq = 5_000_000
obj
pst:"parallax serial terminal"
pub view|index,list
pst.start(115_200)
waitcnt(clkfreq/2+cnt)
repeat index from 1 to 7
list:=lookup(index: "hi",1234,"bye",5678,"bon jour",2222,"adios")
pst.Dec(list)
waitcnt(clkfreq+cnt)

Comments
Okay, here's a core that works -- not that you numbers are changed to strings as you cannot mix those types. If you need them to be numbers, put them in a separate list.
con { pst formatting } #1, HOME, GOTOXY, #8, BKSP, TAB, LF, CLREOL, CLRDN, CR #14, GOTOX, GOTOY, CLS obj term : "jm_fullduplexserial" var dat MyList0 byte "hi", 0 MyList1 byte "1234", 0 MyList2 byte "bye", 0 MyList3 byte "5678", 0 MyList4 byte "bon jour", 0 MyList5 byte "2222", 0 MyList6 byte "adios", 0 pub main | idx, p_list setup repeat repeat idx from 0 to 6 p_list := lookupz(idx : @MyList0, @MyList1, @Mylist2, @MyList3, @MyList4, @MyList5, @MyList6) term.str(p_list) term.tx(CR) pause(1000) pub setup '' Setup IO and objects for application term.start(RX1, TX1, %0000, 115_200) ' start serial for terminalBTW... PST is just FullDuplexSerial with training wheels -- take of the training wheels!
BTW, here's how I would print the list. I always strive to create code that can be used across a variety of applications.
con { pst formatting } #1, HOME, GOTOXY, #8, BKSP, TAB, LF, CLREOL, CLRDN, CR #14, GOTOX, GOTOY, CLS obj term : "jm_fullduplexserial" dat MyList byte "hi", 0 byte "1234", 0 byte "bye", 0 byte "5678", 0 byte "bon jour", 0 byte "2222", 0 byte "adios", 0 pub main | idx, p_list setup repeat repeat idx from 0 to 6 term.str(str_pntr(@MyList, idx)) term.tx(CR) pause(1000) pub str_pntr(p_list, item) | c '' Returns pointer for string within a list of strings repeat while (item > 0) ' loop until item found c := byte[p_list++] ' get a character if (c == 0) ' if 0 (end of current string) --item ' decrement item count return p_listThis uses a method called str_pntr() to find the starting address of a specific string within a list of strings.
PUB FindString(firstStr, stringIndex) '' Finds start address of one string in a list '' of strings. "firstStr" is the address of '' string #0 in the list. "stringIndex" '' indicates which of the strings in the list '' the method is to find. result := firstStr repeat while stringIndex repeat while byte[result++] stringIndex--I admit to being pretty pleased with myself after writing it. I complimented myself with the thought "It looks like something JonnyMac would write".
While our methods aren't exactly the same, I like to think my compliment was justified.
High praise, indeed.
</sarc>
The lookup list works fine for strings, provided they're formatted correctly:
repeat index from 1 to 7 pst.str(lookup(index: string("hi"),string("1234"),string("bye"),string("5678"),string("bon jour"),string("2222"),string("adios"))) pst.char($0D)