Shop OBEX P1 Docs P2 Docs Learn Events
Addressing Scratchpad Ram or EEPROM memory directly from IF-statements — Parallax Forums

Addressing Scratchpad Ram or EEPROM memory directly from IF-statements

andre.nieuwoudtandre.nieuwoudt Posts: 65
edited 2010-10-09 15:40 in General Discussion
Let me start off by saying that I think Stamps are great, except for one thing: the surprisingly limited RAM available for Variable definition.

To get around this problem, I would like to use Scratchpad RAM or EEPROM space in the remaining 7 slots of the BS2px. However, to GET and READ, you need variables, and there is not enough RAM for all the variables I need.

What I would like to do, is to be able to refer directly to, for instance, a value stored at an address in the Scratchpad RAM or EEPROM from. e.g. within an IF-statement, without having to GET the value into a variable first.

For example:

IF (GET BYTE, 10) > (GET BYTE, 17) THEN..... ' Direct reference to BYTE values in Scratchpad RAM at Addresses 10 and 17

or:

IF (GET WORD, 10) > (GET WORD, 17) THEN...... ' Direct reference to WORD values in Scratchpad RAM at Addresses 10 and 17

or:

IF (READ BYTE, 10) > (READ BYTE, 17) THEN....... ' Direct reference to BYTE values in EEPROM at Addresses 10 and 17 in Slot 0

or:

SEROUT 1, 396, [GET WORD, 10] ' Serial Out the BYTE value stored at Address 10 in Scratchpad RAM

I can not find any syntax to do something like this, which is a pity, because we have access to a lot of bytes above and beyond the Variable RAM to store data, but not for declaring variables.

Has anybody perhaps discovered a way to do this, apart from resorting to Multi-slot programs or Master-Slave setups?

If not, I would really like to submit this as a development request to Parallax.

PS. Using "Common" or "General" variables is OK to PUT or WRITE the values in the first place, but not an option for subsequent GET or READ processing.

Comments

  • MoskogMoskog Posts: 554
    edited 2010-10-09 14:47
    Well, I think the limitations of the BS-family is one of the most interesting things, to avoid these limitations are always a challenge and most often there are solutions to whatever problems that occur.
    In your case, are you sure there are no way you can re-use variables or use "smaller" vars, like bytes instead of words and things like that?

    If you post your code in the BASIC Stamp-forum I guess someone here will be helpful with advices.
  • ZootZoot Posts: 2,227
    edited 2010-10-09 15:40
    I use SPRAM a lot in my Stamp-based projects. Sorry, but there is no way around having to move values from SPRAM to "work" RAM. I generally allocate almost no "real" variables to working ram (e.g. B0-B25) and instead use "working" RAM as just that -- work space. Most of my "real" data and variables are in SPRAM. Then I use constants to address that RAM, which makes it easy to allocate SPRAM and keep of track it....
    HighAddr CON 123 ' or 63 or whatever you want the max SPRAM block to be
    SomeVar6 CON HighAddr
    SomeVar5 CON SomeVar6-1
    SomeVar4 CON SomeVar5-1
    SomeVar3 CON SomeVar4-1
    SomeVar2 CON SomeVar3-1
    SomeVar1 CON SomeVar2-1
    ' note that I am working down from highest addr; this saves low
    ' spram addresses for SPSTR and the like
    ' using relative constants makes it easy to insert more addresses
    ' without rewriting all your constants
    
    workW1 VAR Word ' note that these are also used for implied arrays
    work1 VAR workW1.LOWBYTE
    work2 VAR workW1.HIGHBYTE
    workW2 VAR Word
    work3 VAR workW2.LOWBYTE
    work4 VAR workW2.HIGHBYTE
    workW3 VAR Word
    work5 VAR workW3.LOWBYTE
    work6 VAR workW3.HIGHBYTE
    idx VAR Byte
    
    ' then in practice...
    FOR idx = 0 TO 5 ' get 6 bytes into work space
       GET somework1+idx, work1(idx)
    NEXT
    work1 = work1+1
    work2 = work2+1
    ' etc
    FOR idx = 0 TO 5 ' get 6 bytes into work space
       PUT somework1+idx, work1(idx)
    NEXT
    
    GET someVar5, Word workW1
    workW1 = workW1 + $1000
    PUT someVar5, Word workW1
    
    GET someVar1, work1
    work1 = work1 + 123 & $FF
    PUT someVar1, work1
    ' etc
    
Sign In or Register to comment.