Fixed jtable (was: Re: Re: New lib module - 'libjtable.fs')
David McNab <[email protected]> Fri, 29 Oct 2004 00:59:36 +1300
| Newsgroups | gmane.comp.lang.forth.picforth |
|---|---|
| Message-ID | <[email protected]> |
Hi, My original jtable wasn't working because PCLATH wasn't being set prior to setting PCL Here's an amended version (attached) which writes instructions to the table word to set PCLATH to the upper byte of the table's location. I'm still only part-understanding the entrails of PicForth, so I'm not 100% certain that this setting of PCLATH won't have undesired side-effects. However, this fix seems to be working fine on my project. As a side note - it would appear that the standard 'ftable' (from which I ripped code for jtable) also suffers from this limitation. Might be worth looking at having 'ftable' also adjust PCLATH. Cheers David David McNab wrote: > Samuel Tardieu wrote: > >> Thanks David, it will be included in PicForth 0.32. I have added >> appropriate documentation as well. > > > Great. > > But there's presently a caveat - it's only working when the entire table > is located in the first 256 words of program memory. > > I'll look for a fix (or maybe you'll beat me to it). > _______________________________________________ PicForth mailing list [email protected] http://lists.rfc1149.net/mailman/listinfo/picforth
libjtable.fs
(text/plain, 531 B)
\ Provides jump table primitives
host
: element-jtable ( xt -- ) goto ;
meta
: jtable ( "name" -- start endxt elemxt )
reachable tcshere ['] end-ftable ['] element-jtable
\ need to save index on stack, hence the ':' instead of '::'
meta> :
\ frig to insert instruction to set pclath, so tables located
\ outside first 256 bytes of prog mem will work
tcshere $100 / movlw
pclath movwf
\ now can pull index off stack
meta> >w
return-in-w pcl ,f addwf
-tcompile
;
target