[Flashforth-devel] FlashForth 2-Dimensional arrays?
Brought to you by:
oh2aun
|
From: <dab...@ya...> - 2019-06-02 13:55:19
|
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
|