Re: [Flashforth-devel] FlashForth 2-Dimensional arrays?
Brought to you by:
oh2aun
|
From: <dab...@ya...> - 2019-06-03 15:25:55
|
Very Nice Thought!
(As the War College replied to Grace Murray Hopper about her answer on the problem of refueling a battle group at sea, "An interesting solution.")
I'm going to have to give that one a try once this project is wrapped up. Much cleaner than anything I came up with. Glad I'm not the only one who couldn't see a way back to the DOES>... (grin)
Thanks Again!
Keep up the good work. Stephen's warnings aside, it pays to know the underlying system.
On Monday, June 3, 2019, 9:35:57 AM EDT, Mikael Nordman <mik...@fl...> wrote:
Sorry Craig,
I cannot think of any good way to do that in FF.
Once you are executing in the DOES> part, which part of the 2ARRAY word,
I cannot think of any way to get back to defined array word to fetch a
size from flash.
That address is gone from the return stack.
Storing the size in flash can be done in the CREATE part with I, or
FLASH , RAM
But when the DOES> part is executing, there is no link to the array
word.
The only way I can think of is to initialize the size of each array in
ram after every warm start.
Except, there is a way :-) Not tested or complete, but you get the idea.
: 2array ( col, row -- addr )
\ create a word which points to a data area in flash
flash create
\ append the row size in flash
dup ,
\ append the start of the ram buffer in flash
ram here flash ,
\ allot the the ram buffer
cells * ram here allot
does>
\ Fetch the row size from flash
@+
\ Fetch the ram buffer address flash
@
\ etcetera
;
BR Mike
On 2019-06-02 16:55, craig bair via Flashforth-devel wrote:
> I've run into an interesting problem with FF-5 on Pic18F46K22 chips.
> 2-Dimensional arrays are really handy things. I'm setting up a
> rolling-average filter for the output of a multi-channel A/D chip to
> take a reading from a different channel each millisecond and average
> the reading I need from the correct ring-buffer whenever needed. The
> control routine works perfectly with a 2D-array in Forth to the limits
> that I can test it... until I shut the system down or do a reset.
> Suddenly the 2array word stops returning addresses other than for row
> Zero.
>
> Here's the word I use, derived from Stephen Pelc's (cleaned up so it
> doesn't crash when accessed):
> \ WORD ARRAY CREATION -- 2-Dimensional ( col, row -- addr )
> \ x0y0 x1y0 x2y0 ... xny0 x0y1 x1y1 ... xny1 x0y2 ... xnym
> : 2array \ x1 y2 -- ; [child] n1 n2 -- addr ; 2-D array
> \ make name word, save width, calculate size, allocate
> create over , cells * here over erase allot
> \ run time gives address of data
> does> dup @ rot * rot + 1+ cells +
> ;
>
> My best initial guess is that the COMMA is storing the row length into
> a ram location so a reset clears it to zero from that point on (in a
> Harvard Architecture processor).
>
> I can work around it by doing a specific address calculation routine
> with a 1D-array, but fixing "2array" for embedded controller would be
> better. Any suggestions or insights?
>
> craig
>
>
>
>
> _______________________________________________
> Flashforth-devel mailing list
> Fla...@li...
> https://lists.sourceforge.net/lists/listinfo/flashforth-devel
--
--
Mikael
_______________________________________________
Flashforth-devel mailing list
Fla...@li...
https://lists.sourceforge.net/lists/listinfo/flashforth-devel
|