[PicForth] Problems/solutions with ftables
Dan Andersson
dan at andersson.co.uk
Mon Oct 11 18:25:02 CEST 2004
Now now!
Don't reinvent the 7bit storage wheel again. Use RADIX50. It's clean and
well documented!
For those of you unfamiliar with RADIX50 - YOURE TO YOUNG! Long live
PDP11!
Dan
On Tue, 2004-10-12 at 02:53 +1300, David McNab wrote:
> Hi,
>
> Just a few quick observations:
>
> 1. I've noticed that program-memory tables, created with
> ftable...end-table, only work if all the data in the table resides in
> the first 256 bytes of program memory. The ADDWF PCL,F trick used for
> indexing the table seems to set PCH to $00, regardless of the current IP.
>
> 2. If file1.fs includes file2.fs, and file2.fs contains an
> ftable..end-table construct, subsequent includes from file1.fs fail.
>
> 3. libstrings.fs doesn't work. Specifically, str-char is always
> returning $01. I've used exactly the code from the doco for
> 'c".."'/'str-char'. No good.
>
> Anyway, here's what I've done to work around these issues:
>
> I'm working on a program that does lots of user interaction via buttons
> and LCD, and requires several strings to be stored. So I've chosen to
> put them in program memory.
>
> What I've had to do is write a utility that automatically converts a
> file containing something like:
>
> fred = "hello, world"
> mary = "smaller"
> jim = "blah"
>
> into:
>
> ftable mystrings
> $68 t, $65 t, $6c t, $6c t, $6f t, $2c t, $20 t, $77 t,
> $6f t, $72 t, $6c t, $64 t, 0 t, $62 t, $6c t, $61 t,
> $68 t, 0 t, $73 t, $6d t, $61 t, $6c t, $6c t, $65 t,
> $72 t, 0 t,
> end-table
> $0 constant fred
> $d constant jim
> $12 constant mary
>
> Here, 'fred', 'jim' and 'mary' are offsets into this table, pointing to
> the start of null-terminated strings.
>
> This allows any chosen offset to be passed to a loop, hardcoded to use
> 'mystrings', which indexes this table and invokes a callback for each
> char in the string.
>
> Finally, I've arrived at a way to enter strings in human-readable
> format, have them automatically translated to table decs, such that I
> can do stuff like:
>
> lcd-line1 fred lcd-put-string
> lcd-line2 mary lcd-put-string
>
> And as long as I ensure that the whole table is residing in first 256
> bytes, all is ok. What's really great about ftable is that it takes
> advantage of the RETLW instruction, so that there is zero overhead for
> each string (apart from its null-terminator).
>
> (Makes me wonder if i should hack up an encoder to store 2 7-bit ASCII
> chars in each machine word).
>
> All this said, I find that overall, PicForth is a god-send for my PIC
> project. Between it and gpsim, I'm in PIC Hacking Heaven, especially
> after weaning myself off the insulting PICAXE BASIC environment. So
> thank you, Samuel, for a master-work! :))
> I really hope you find the inspiration to keep going on it.
>
____________________________________________________________________________
This email and all attachments have been scanned by Kingston Communications'
email Anti-Virus service and no known viruses were detected.
____________________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rfc1149.net/pipermail/picforth/attachments/20041011/b0f0509b/attachment.html
More information about the PicForth
mailing list