Cliff Hacks Things.

Tuesday, January 01, 2008

PropellerForth v8.01 alpha; HYDRA tidbit

After my winter sprint, PropellerForth v8.01 alpha has been posted on the project page. (I'm using Ubuntu-style version numbers, so 8.01 is the January 2008 release.)

As it says in the release notes, the version currently available there is an alpha release. It's been tested, it works, and it's probably close to the final release, but I reserve the right to make changes in the near future before pronouncing it official. In particular, the docs are not nearly complete -- I'm working on it.

Source hasn't been posted yet; still trying to figure out how best to do that.

A HYDRA PropellerForth Tip

The HYDRA board is one of PropellerForth's officially supported targets. One of its slick (but undocumented) features is how it handles the on-board EEPROM when a cartridge is inserted: it gets remapped to a higher address space, but remains accessible.

PropellerForth's EEPROM words (included in the v8.01 'full' release) support addressing multiple EEPROMs on the I2C bus, using Atmel-style device and page addressing. The visible address space is:

  • No cartridge: onboard EEPROM at 0x00000 - 0x1FFFF

  • Cartridge: onboard EEPROM at 0x20000 - 0x3FFFF, cartridge at 0x00000 - 0x1FFFF

This opens some interesting possibilities:

  • Programs could use both EEPROMs together, for 256KiB of bulk data storage.

  • A reasonably simple Forth word could copy one EEPROM to the other, to clone a cartridge or back up the on-board software.

I'll leave those as exercises to the reader; for now, here's a word, ?cart, that checks whether a cartridge is currently inserted in the HYDRA.

hex \ the base of champions
: ?cart ( -- flag )
\ Try to read base of remapped on-board EEPROM.
20000 ['] eeread catch \ Guard with catch to intercept failure
nip \ Discard the address (if failed) or the result (if succeeded), leaving exception
0= ; \ If the exception is 0 (none caught), return 'true', otherwise 'false'.

To help you test it, here is the cartridge monster. (Hey, I can only type in so many dry source examples before I try to make one funny.)

: O_O \ See, it's a face. ... well, I thought it was funny. :-P
?cart if exit then \ Don't bug the user if a cartridge is present
begin \ Loop and complain...
1 seconds wait
?cart until \ ... until a cartridge appears

(Hot-swapping cartridges on the HYDRA should work fine as long as the EEPROM is not being accessed when it happens -- just be careful to insert the cartridge straight.)

Labels: ,