Try running this code there is a surprise in it
metron9
Posts: 1,100
I have not quite figured out how to come back from program 2 yet. My goal was to make a memory swap function to run subroutines written compiled and stored on external memory for the BS2. I am just using data statements in this to see if it could be done.
If I knew how the tokenizer handled pointers for goto and returns it would be easier.
As it stands now though, one could use a setup program almost 2000 bytes long then pull in the main program but once it was done rebooting the stamp would only run the first program. Unles I can find a way to jump to the bootloader code fafter the first swap it could only be done once.
Fun to play with though, reminds me of my C64 days.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
If I knew how the tokenizer handled pointers for goto and returns it would be easier.
As it stands now though, one could use a setup program almost 2000 bytes long then pull in the main program but once it was done rebooting the stamp would only run the first program. Unles I can find a way to jump to the bootloader code fafter the first swap it could only be done once.
Fun to play with though, reminds me of my C64 days.
' {$STAMP BS2} ' {$PBASIC 2.5} ' {$PORT COM2} BUFFER VAR Byte FN VAR Byte WL VAR Word DATA 0,0,0,0 DATA $00,$00,$A6 DATA $D9,$D3,$EC,$69,$36,$34,$53,$36,$35,$4B,$9A,$29,$9B,$9A,$25 DATA $CD,$90,$66,$54,$13,$84,$4C,$35,$07,$C0 MAIN: DEBUG "This is program 1" BOOT: WL=$07E0 FOR FN=0 TO 31 READ FN,BUFFER WRITE WL,BUFFER WL=WL+1 NEXT DEBUG CR,"STARTING PROGRAM 2",CR GOTO MAIN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
Comments
Due to the last GOTO MAIN, the same eeprom locations are overwritten every loop.
This will wear out your stamp in a short time.
regards peter
If I knew how the interpreter handled the GOTO pointer, then you could overlay the goto pointer to a specific point allowing the boot loader to be in eeproms lower memory 0...xxx.
You are correct, running subroutines if many swaps are required would not be good. But it does have potential for a boot loader to run external programs stored on external eeprom like the other stamps with program slots if one could decipher the goto interpretation of tokenized code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
I remember I did something like this back in 2000/2001.
A search through the basic stamp archive might·give the thread.
The way I tried it was·first defining word variables and aliases using those words
for variables used to load in·other code (from external eeprom), without overwriting
the bootloader.·As program code starts at·$7FF·and grows
downwards I don't think you should overwrite addresses $7E0-$7FF.
Basically, every program should start with the identical bootloader code.
You only read in the code that follows the bootloader code.
regards peter
If you are interested in the inner workings of the Stamp regarding the tokenizer coding of things like GOTO and RETURN, you should get a copy of Brian Forbes' Book.
There is an example of a self-replacing program in the BASIC Stamp 1 app notes, which I think is still available on the Parallax downloads page. There are some very clever programs there, many of them having been written by Scott Edwards, I think.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I see the app note on the BS1. Interesting it overwrites its own code that is executing. I did not think to do this as typically the boot loader section doesn't overwrite itself.
I will give it a go tonight on the BS2. Should be easy to implement a multi program boat loader on the BS2 using this method. I will post it as a project when it is stable.
Thanks Tracy.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!