Scratchpad labels

RadioBob

New Member
Is there any provision for labels to refer to locations within the scratchpad (20X2 particularly)? It would be nice to have a label to easily calculate the offset required to address particular parts of the scratchpad.

Thanks for any suggestions!
 

nick12ab

Senior Member
Not directly, but you could just set the location you want as a constant and use 'ptr = constant'. Alternatively, but inefficiently, a gosub can be used:
Code:
gosub setscratchpadtowhatever
b0 = @ptr
end

setscratchpadtowhatever:
ptr = 213
return
 

RadioBob

New Member
Lables for scratchpad memory

Thanks for your suggestion. It really is a bit of a cludge though as you would have to count to find various offsets, which is error prone, and also needs to be recounted if anything changes in scratchpad memory. We should be able to use the "assembler" to calculate offsets. It would seem to be fairly easy to introduce a label directive to have the value of the current position within the scratchpad. Perhaps it will come some time. I'm anxiously awaiting #include as well!

i.e.

ptr = next_byte
..... :next_char = @ptrinc: .......

eeprom (...........)
next_byte:
eeprom ("Some Text",0,...........)
 

westaust55

Moderator
I am not sure that I fully understand your requirement but the Lookup command may help.

Is the error in counting that you mention you or the program?

Keep in mind the PICAXE chips use interpreted BASIC and not a compiler creating assembler code.

Maybe an example showing more precisely what you wish to achieve/do may help folks give you some ideas.
 

BeanieBots

Moderator
Not sure I fully understand the requirement either!

It IS possible to rename the pointer
Symbol MyDataLocation = @ptr

Therefore, it IS possible to name a specific location pointer.
and it is also possible to get yourself into a great big mess by re-naming @ptr as I have proved to myself:eek:

If you want specific locations with names, then it might be easier to use SFR and peek/poke.
eg Peek MyData,MyDataLocation where MyData is a suitable variable and MyDataLocation is defined constant.
 
Last edited:

Simmicht

Senior Member
my method

I do this sort of thing in a 28X2 environment.

'-------------------------------------------------
'EEPROM TABLE
SYMBOL Temp_CalADR=80 'byte for adjustign TEMP
SYMBOL Pres_CalADR=81 'byte for adjustign Barometric
SYMBOL Humd_CalADR=82 'byte for adjustign Humidity
SYMBOL Scrl_CalADR=83 'byte for adjustign Scroll Speed
SYMBOL Brig_CalADR=84 'byte for adjusting LED Brightness

'========================
'Scratch Pad
SYMBOL Pres_24hPtr = 207 'Where the last 24 hours data stored
SYMBOL Temp_24hPtr = 183 'Where the last 24 hours data stored
SYMBOL Humd_24hPtr = 159 'Where the last 24 hours data stored



'later
Read BRIG_CalADR,Cal_Value

'or

WRITE BRIG_CalADR,Cal_Value



'scratchpad acceess
'fill the buffer with 0
BPTR = Pres_24hPtr
FOR B0=0 to 23
@BPTRINC = 0 'Fill the buffer
NEXT
 

MartinM57

Moderator
We should be able to use the "assembler" to calculate offsets.
It's a nice idea, but there is no "assembler" and the low-level concept as understood by assembler programmers that a label is just a program/data address doesn't really apply in PICAXE Basic due to the way the "compiler" produces byte packed run time interpreted code.

I think you will have to choose from the various ideas above...
 

inglewoodpete

Senior Member
There's another way to use the scratchpad too - as a table. In this example, the records in the table have a fixed length of 7 bytes

I hope I have the code snippets correct:
Code:
   #picaxe 28x1
   'Scratchpad/Table
   Symbol spStartOfData       = 42     'Start of data series
   Symbol spBytesPerRecord    = 7      'Allows for stepping through table
   'Offsets within local record of pole data
   Symbol spPoleIDOffset      = 0      '1 byte:  Pole board ID
   Symbol spModeOffset   = 1           '1 byte:  Mode of the controller
   Symbol spPoleStatusOffset  = 2      '1 byte:  Status of the pole
   Symbol spReqdPosnOffset    = 3      '&4 2 bytes: Required Position
   Symbol spActualPosnOffset  = 5      '&6 2 bytes: Actual Position
   'Constants
   Symbol False               = 0
   Symbol True                = 1
   'Variables
   Symbol tNotFound           = bit7   'in b0
   Symbol bRecordNum          = b9
   Symbol bSearchVal          = b10
   Symbol wActualPosn         = w8
   Symbol wActualPosn.Lo      = b16
   Symbol wActualPosn.Hi      = b17
   Symbol bStatus             = b7
   '
   '** Get the Pole Status of the 3rd record
   bRecordNum = 2                        'First record is 0
   ptr = bRecordNum * spBytesPerRecord + spStartOfData + spPoleStatusOffset
   bStatus = @ptr
   '
   '** Find next free location
   bRecordNum = 0                        'Initialise
   tNotFound = True
   ptr = spStartOfData + spPoleIDOffset'(Offset is optional here)
   Do Until @ptr = 0                     'Test for end-of-table (ID=0)
      ptr = ptr + spBytesPerRecord
      Inc bRecordNum
   Loop
   '
   '** Get the actual position of pole ID #5
   bSearchVal = 5                        'Search for this record number
   bRecordNum = 0                        'Initialise
   tNotFound = True
   ptr = spStartOfData + spPoleIDOffset'(Offset is optional here)
   Do Until @ptr = 0                     'Test for end-of-table (ID=0)
      If @ptr = bSearchVal Then
         tNotFound = False               'Have the record
         ptr = ptr + spActualPosnOffset 'Get the position offset
         wActualPosn.Lo = @ptrInc       'Get the position
         wActualPosn.Hi = @ptr          ' (word value)
         Exit
      EndIf
      ptr = ptr + spBytesPerRecord
      Inc bRecordNum
   Loop
 
Top