Welcome! Log In Create A New Profile

Advanced

Dumb flsave question

Posted by pete_l 
Dumb flsave question
November 03, 2012 09:33PM
OK, I've got a few BV500s (yay!)
I've nailed how to talk to them (double yay!!)
I've got some code to work (whoop-de-doo)
I can't figure out how to save stuff in flash (boo!)

Here's the code I'm running
#option echo off
#option only on   // only load functions that don't already exists

dim i
dim a(256)

function aa()

for i=0 to 255
  a(i)=i
  print format$(" % 4d", i)
  if (i%8) = 7
    print "\n"
  endif
next
endf
and as you would expect, when it runs, it produces the following output:
<<<--- this should show a screenshot
link: screenshot

And as you can see, the global array, called a() is accessible from the command line.
What I'm trying to do is to write this array to flash - but I can't work out how.

I've tried
flsave(a)
but that just throws a couple of errors:
ERROR (27) - "expecting ("
ERROR (3) - "stack underflow"
which makes me suspect I'm not using the right number of args to flsave() or that they're the wrong type.
I've also tried flsave("a" ) which does something, but only seems to write 336 bytes, here:
ok flsave("a") fFunctions 3
Bytes to save=336
Next free_flash=9d018000
This does appear to save something related to the array a(), as after a reset, I can do a
print a(99)
and get a value of zero returned - I was hoping to get 99 back. Whereas when I perform an flclear(1) and the chip reboots, the
same print a(99) spits an ERROR (0) <a> message at me, so something's happening.

However I can't find any examples of how to use these functions, so any help would be greatly appreciated.

Pete



Edited 1 time(s). Last edit at 11/03/2012 09:40PM by pete_l.
Re: Dumb flsave question
November 04, 2012 09:54AM
try flsave("") *** this is open bracket double quote double quote close bracket - not winky smiley - must find out how to switch them off.

see Keywords - flsave
Re: Dumb flsave question
November 04, 2012 12:32PM
Heh, heh. wink smile nod blind horse. (I had hoped that putting stuff inside CODE would stop that. Oh well.

Here's what I got
System cold start
--------- Hardware Detect ----------
 ======================================
| machineBASIC Version 2.06            
| Saves 0                              |
| MBCHIPMX1 Serial#  201222065          
|                                      |
| Documentation www.doc.byvac.com      |
| Library    www.mbasic.byvac.com      |
|                                      |
| Copyright Jim Spence 2012            |
 ======================================
ok [06][06]
lines loaded 16
ok a
    0    1    2    3    4    5    6    7
    8    9   10   11   12   13   14   15
   16   17   18   19   20   21   22   23
   24   25   26   27   28   29   30   31
   32   33   34   35   36   37   38   39
   40   41   42   43   44   45   46   47
   48   49   50   51   52   53   54   55
   56   57   58   59   60   61   62   63
   64   65   66   67   68   69   70   71
   72   73   74   75   76   77   78   79
   80   81   82   83   84   85   86   87
   88   89   90   91   92   93   94   95
   96   97   98   99  100  101  102  103
  104  105  106  107  108  109  110  111
  112  113  114  115  116  117  118  119
  120  121  122  123  124  125  126  127

ok flsave("") Functions 3
Bytes to save=376
Next free_flash=9d018000

ok fltell Page size 1024
Flash start 0x9d017c00
Current start 0x9d018000
Current free space, bytes 32764
Save number 1
ok reset
[c8]
Text input Buffer 83 allocated Baud 115200

System cold start
Curent save 1
--------- Hardware Detect ----------
 ======================================
| machineBASIC Version 2.06            
| Saves 1                              |
| MBCHIPMX1 Serial#  201222065          
|                                      |
| Documentation www.doc.byvac.com      |
| Library    www.mbasic.byvac.com      |
|                                      |
| Copyright Jim Spence 2012            |
 ======================================
ok print a(99)
0
I changed the size of the array from 256 to 128, so that (with the overheads) it would fit into a single 1KB page.
The bytes saved changes depending on the details of what I save and how. However, while the metadata of the array is preserved in flash, the contents seem not to be. I've found that with the 128 element array, trying to access elements > 128 throw an error - as you'd expect. So the flash does know how big it is.
Puzzling. Might try strings next.
Re: Dumb flsave question
November 04, 2012 02:09PM
You can't add a filled array to flash as it is stored in RAM and on reset the RAM could contain anything, an array is read/write. The array would still exist but it would need filling at runtime on start up. What you may be looking for is a constant. An array, byte constant is a sting, escape "\nn" can be used for non-printable characters. There is a limit of 80 characters per line when inputting and so several constants may be needed for 256 bytes.

Coming soon for the MX1 version 2.06 201226067+ will allow a new method of specifying a constant very similar to C using curly brackets thus:
constant a${1,2,3,4,5 /
            6,7,8}
This will be useful for fonts and the like. It is available for the MX3 now but needs more testing on the MX1.
Re: Dumb flsave question
November 10, 2012 12:57PM
Ahh, yeah. Thinking about it that makes perfect sense. Thanks for sorting me out with that.
Sorry, only registered users may post in this forum.

Click here to login