Shop OBEX P1 Docs P2 Docs Learn Events
Concept.... Reprogram within your program bsp stamps — Parallax Forums

Concept.... Reprogram within your program bsp stamps

kelvin jameskelvin james Posts: 531
edited 2009-03-01 01:42 in BASIC Stamp
To keep it short as possible, i figured that the hex code shown in the eeprom map actually was duplicated on the stamp memory itself. I guess a no-brainer for most people. So, i thought certain values in the map could be matched to the pbasic code, like commands and values. After some close investigation of the map with some simple code, it was easy to pick out the change of values with the 2 commands i was checking out ( high and low ).

Now, the main idea was to be able to change the pbasic eeprom code within the running program itself on the fly. It couldn't be done with a bs2, because the program would basically have to be reset for the change in code to take effect. But the bsp is another story. Moving to another program slot,some code is used to overwrite the eeprom code area in the main program, when the main program is returned to, it restarts with the new changes.

The purpose of this is to be able to change the way the main program ( or other slots ) start and run. Meaning you could reprogram some code on the bsp from the running program itself, depending on certain conditional states.

Many issues with this, like writing to a sensitive eeprom area for program code, don't want to do it very often. But if done wisely, no different than writing from the editor itself. Also, once it is over-written, a restart does not get you back the original program.

This was just proof of concept, i might go further with it, but i wanted to see if it could work. You can see in the emap picture the difference in the hex values for the high and low code ( 3E low, 2E high ). I programmed the bsp with the low code ($3E) to slot 0, switched to slot 1, wrote to slot 0 with store at location 2044 with $2E, returned to slot 0, and it worked. If you run the program with a led, you will see the led comes on at the return to the main program.
I also used some scratch ram to set some flags, so the main program will know that operation has been done, and won't keep writing the same location again.

It is only a concept thing, whether it actually comes to any viable use is questionable. Anyway, blew the whole day on this, when i should of been doing some work around here.


' {$STAMP BS2p,overwrite1.bsp,overwrite3.bsp}
' {$PBASIC 2.5}
' {$PORT COM1}

v VAR Bit
x VAR Bit

LOW 0
PAUSE 5000
GET 0, v
IF v = 1  THEN r2
RUN 1

r2:
GET 1, x
IF x = 1 THEN LOW 0 : END
RUN 2



' {$STAMP BS2p}
' {$PBASIC 2.5}
' {$PORT COM1}

v VAR Bit
x VAR Bit
v =1

STORE 0
PUT 0, v
WRITE 2044, $2E
RUN 0



' {$STAMP BS2p}
' {$PBASIC 2.5}
' {$PORT COM1}
y VAR Bit
x VAR Bit
x = 1

LOW 0
PAUSE 1000
HIGH 0
PAUSE 1000
LOW 0
PAUSE 1000
PUT 1, x
RUN 0
Sign In or Register to comment.