Shop OBEX P1 Docs P2 Docs Learn Events
Femtobasic Save & Load to Hydra SD Card? — Parallax Forums

Femtobasic Save & Load to Hydra SD Card?

HumanoidoHumanoido Posts: 5,770
edited 2009-05-03 18:11 in Propeller 1
Using Femtobasic without any changes, will save and load programs work with the plug in Hydra SD Card?

Post Edited (humanoido) : 4/29/2009 4:15:07 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-29 16:22
    FemtoBasic can save and load programs to 32K pages of EEPROM

    save [noparse][[/noparse] $08000 ] : rem saves to 2nd 32K area of EEPROM
    save [noparse][[/noparse] $10000 ] : rem saves to 3rd 32K area of EEPROM
    save [noparse][[/noparse] $18000 ] : rem saves to 4th 32K area of EEPROM

    The 1st 32K area starts at $00000 and contains the boot area with FemtoBasic itself

    You don't have to save Basic programs to a 32K boundary, but there's no checking whether one program overlaps onto another already stored. FemtoBasic only stores what's needed and Basic programs normally are less than 8K in size, so you could keep 3 * 4 = 12 programs in the Hydra's extra 96K of EEPROM (past the 1st 32K).

    The load statement works the same way

    You can also save and load a single program using just the LOAD and SAVE statements without any parameters. These use the area in the 1st 32K of EEPROM past the end of FemtoBasic. This area gets overwritten if you download a fresh copy of FemtoBasic or any other program. The 32K areas past the 1st one are untouched when you download a new program.

    If you have an expansion card plugged in, the expansion card takes the place of the on-board EEPROM and the on-board EEPROM gets relocated to $20000. That means that you have another 96K available (since you probably want to keep the on-board EEPROM's 1st 32K with a copy of FemtoBasic in it in case you need to remove the expansion card.

    FemtoBasic will check the EEPROM area used by "SAVE" and "LOAD" for an automatic start program. Look at the documentation for details.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-29 16:30
    Yes, FemtoBasic should work unchanged with the Hydra SD card expansion card. I haven't actually tested it with the expansion card, but FemtoBasic was tested with a homemade expansion card SD card adapter and the "official" Hydra SD card adapter was built to duplicate the homemade adapter and work with FemtoBasic.
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-04-29 18:41
    Mike, thanks very much for the lucid explanation. It appears to work very logically and has the capacity to do exactly what I want for the project.

    In the future I hope to see a variety of programming examples and maybe a source material newsletter or something can be put together about Femtobasic program apps at that time. [noparse]:)[/noparse]

    Just a final note - what does femtobasic stand for? I got the basic part, and maybe t is for the original t in tiny basic? I googled it but didn't see the mysterious answer.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-29 19:56
    You know, I don't remember why it's called FemtoBasic other than that we've had microBasic (10^-6), nanoBasic (10^-9), picoBasic (10^-12) and femtoBasic (10^-15). I think Tomas Rokicki called his homage to RadioShack Basic by the name of nanoBasic and the next derivation became femtoBasic, possibly at his recommendation.
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-05-01 06:44
    Thanks Mike. I should have known about the femto part, and it's good to have a bit of history of how all this originated.

    I'm interested in using FemtoBasic to develop serious applications with Hydra, but need a way to save and then load programs after the Hydra is reset or power cycled.

    If I save a program into the main Hydra board like this:

    SAVE [noparse][[/noparse]A]

    It will save perfect. Then if clear out the program in RAM with NEW, and do a LIST, it is verified that the program is erased from RAM. I can then do this:

    LOAD [noparse][[/noparse]A]

    and the program will load perfect back into RAM, and I can LIST it, again, perfect.

    Now the problem begins. If I turn off the Hydra board, or reset it, the FemtoBasic will show the first greeting line on the screen and remain locked up.

    It happens with the main board, or with the game card, (both were loaded with FemtoBasic).

    Can you give me a working example code line of how to save or load programs using the the Hydra board, and same for load/save using the 128K game card? (so it will work when reset or power cycled)
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-05-01 18:24
    Ok, got it to work. Apparently load/save without the memory specification parameter overwrites the stored memory position of FemtoBasic in EEPROM. That's why the lockup occurred upon reboot and not during initial RAM operation. With the parameter specified by Mike, it works fine in 32 K blocks since the programs are unlikely to exceed that memory size at this time. So mainly specify the memory locations so nothing overwrites the language. I'm glad to see this aspect working now, the resets are gone, and everything is going well. With a routine to calculate the size of the program, and the position of the memory blocks, many programs could be stored in EEPROM. What is the best way to do this?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-01 19:00
    When calculating locations to save and load programs, remember that the address you give is changed to the next 64 byte boundary minus two so that the length of the program is stored in the last 2 bytes of the first 64 byte aligned block and the program itself is stored in 64 byte pieces beyond that.

    For example, if you specify a starting SAVE address of $8000 through $803E, the length of the program is stored in $803E/$803F and the actual program is stored in 64 byte pieces starting at $8040. You can store other information in the first 62 bytes of the EEPROM area used. You could store a program name or number there and have a "master" program that searches for a particular name and loads and executes that saved program.

    When you use a LOAD with an address of $8000 through $803E, the same algorithm is used so the length is expected to be in $803E/$803F.
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-05-03 08:40
    Thanks Mike! It seems you can smoothly move through these hex memory location values and ranges with the greatest of ease. What method works best for converting decimal ranges to hex - a converter program, some big reference tables, a formula, or... ?

    Post Edited (humanoido) : 5/3/2009 6:10:26 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-03 14:10
    Why convert anything? They're all 32 bit integers. I just wrote them as hex numbers for convenience and because they're more meaningful that way. You could just as easily write SAVE[noparse][[/noparse] 32768 ] as SAVE[noparse][[/noparse] $8000 ].

    In terms of knowing what to write ... I memorized the powers of two up through 16 bits.

    Post Edited (Mike Green) : 5/3/2009 2:17:08 PM GMT
  • HumanoidoHumanoido Posts: 5,770
    edited 2009-05-03 18:11
    Thanks very much!
Sign In or Register to comment.