last free eeprom byte before program
Archiver
Posts: 46,084
A PBASIC hack...
'{$PBASIC 2.5}
' findfree.bpe
' (c)2003 Tracy Allen http://www.emesys.com
' finds the last free eeprom byte
' before overwriting program memory
' hack NOTICE:
' last instruction in the program must be a dummy gosub
' never to be executed.
' Hack reads return address tokens from the branch table.
' Can be used with any Stamp II, any bank
' and BS2p, BS2pe can use STORE to probe other banks
x VAR Word
n VAR Nib
y VAR Byte
z VAR Word
i VAR Nib
lastfree data word 0 ' program will modify this at runtime
top:
GOSUB findfree ' finds last available eeprom byte
WRITE lastfree, Word z ' store the value
main:
DO
' your program goes here
' can WRITE data up to <lastfree>
LOOP
' subroutines
findfree: ' reads from PBASIC branch table
READ $7fe , Word x
n=x.NIB3>>1
x=$7ff-(x&$1fff>>2)
READ x,y
READ x+1, Word z
x=z<<n|(y>>(8-n))& $3fff
n=x>>11
x = x & $7ff
z=x*8+n-29
x=z/8
n=z//8
z=$7ff-x-(n MAX 1)
RETURN
' the last instruction in all the program has to be a GOSUB,
' as follows. The target label does not matter.
' never execute this gosub
' it is counted among the bytes that may be overwritten.
END
GOSUB top
'{$PBASIC 2.5}
' findfree.bpe
' (c)2003 Tracy Allen http://www.emesys.com
' finds the last free eeprom byte
' before overwriting program memory
' hack NOTICE:
' last instruction in the program must be a dummy gosub
' never to be executed.
' Hack reads return address tokens from the branch table.
' Can be used with any Stamp II, any bank
' and BS2p, BS2pe can use STORE to probe other banks
x VAR Word
n VAR Nib
y VAR Byte
z VAR Word
i VAR Nib
lastfree data word 0 ' program will modify this at runtime
top:
GOSUB findfree ' finds last available eeprom byte
WRITE lastfree, Word z ' store the value
main:
DO
' your program goes here
' can WRITE data up to <lastfree>
LOOP
' subroutines
findfree: ' reads from PBASIC branch table
READ $7fe , Word x
n=x.NIB3>>1
x=$7ff-(x&$1fff>>2)
READ x,y
READ x+1, Word z
x=z<<n|(y>>(8-n))& $3fff
n=x>>11
x = x & $7ff
z=x*8+n-29
x=z/8
n=z//8
z=$7ff-x-(n MAX 1)
RETURN
' the last instruction in all the program has to be a GOSUB,
' as follows. The target label does not matter.
' never execute this gosub
' it is counted among the bytes that may be overwritten.
END
GOSUB top