Bptr Symbol and S_W variable questions

matchbox

Senior Member
I'm wondering if there is a way to give a Bit Pointer locations a Symbol? The example below doesn't check out. But I was wondering if there is a way to do it, that I have missed.

Code:
Symbol TEST = bptr = 50

Main:
If @TEST = 1 then : Goto stuff
Endif
And also wondering if a Special Word variable can be separated into its bytes?

Thanks guys
 

lbenson

Senior Member
Apparently "@" must be followed by bptr or ptr (but I'd be happy to be shown otherwise).
bptrTest1.jpg
But you can use DEFINE:
bptrTest2.jpg
There are no available constituent bytes for the "s_w#" variables--you'd need to move them to a word variable and use its constituent bytes.\
 

matchbox

Senior Member
Thanks Ibenson.
I was hoping there may have been some tricks that others had came across in there use of these two functions.
Its useful to have extra variables.
But I find myself getting lost with the use of too many BPTR.
It would make reading the code far easier if they could be assigned to symbols.
 

lbenson

Senior Member
What are you accessing with bptr? If it's single bytes of upper ram, you might do better with symbols and peek/poke.

Symbol upperrambyte=58
Peek upperrambyte, b7
Inc b7
Poke upperrambyte, b7
 

cpedw

Senior Member
And also wondering if a Special Word variable can be separated into its bytes?
You could use something like this:
Code:
#PICAXE 08M2

SYMBOL lowbyte = b2
SYMBOL highbyte = b3

' Assign values to be saved in s_w0
lowbyte = 15
highbyte = 75
' Assign low byte of s_w0 without altering high byte
s_w0 = s_w0 / 256 * 256 + lowbyte
' Assign high byte of s_w0 without altering low byte
s_w0 = s_w0//256
s_w0 = highbyte * 256 + s_w0
' Change lowbyte & highbyte to check values get through
lowbyte = 22
highbyte = 24
'Extract low byte & high byte without altering either
lowbyte = s_w0 // 256
highbyte = s_w0 / 256

sertxd ("lowbyte ",#lowbyte, " highbyte ", #highbyte)
Macros could be used to assign and extract the values more readily.

Derek
 

Aries

New Member
You can't use a SYMBOL for an expression with an "=", so the syntax check fails at that point. In any case if you substituted what your symbol ought to mean into the code, it would look like
Code:
if @bptr = 50 = 1 then: goto stuff
endif
and although YOU might know what it is supposed to mean, the compiler doesn't. What I think you are trying to say is
Code:
bptr = 50: if @bptr = 1 then: goto stuff
endif
You can do this, using a trick from hippy ...
Code:
#define ramloc(loc) b0 >=0 then :endif:bptr = loc:if @bptr

if ramloc(50) = 1 then : goto stuff
endif
This expands to
Code:
if b0 >=0 then :endif:bptr = 50:if @bptr = 1 then : goto stuff
endif
which I think is what you want.

Of course, you will need other #define's for expressions other than IF
 

lbenson

Senior Member
Oh, I like it, Aries, especially the trick, "b0>=0", because it is always true that b0 is greater than or equal to zero, so the throwaway "if" statement works unconditionally.

Here is the PEEK version, using a spare byte, "SYMBOL scratch=b27" instead of bptr.
Code:
symbol scratch=b27 ' some free byte
#define ramloc(loc) b0>=0 then: endif: peek loc,scratch: if scratch

poke 50,1
if ramloc(50)=1 then: sertxd("Ram byte 50 = 1",cr,lf): else: sertxd("Ram byte 50 NOT = 1",cr,lf): endif
poke 50,0
if ramloc(50)=1 then: sertxd("Ram byte 50 = 1",cr,lf): else: sertxd("Ram byte 50 NOT = 1",cr,lf): endif
But ... if the test is only for 0 or 1, then there are a whole lot of bit variables one could use instead.
 
Last edited:

lbenson

Senior Member
The PEEK version also works with variables:
Code:
symbol scratch=b27 ' some free byte
#define ramloc(loc) b0>=0 then: endif: peek loc,scratch: if scratch

poke 50,1
if ramloc(50)=1 then: sertxd("Ram byte 50 = 1",cr,lf): else: sertxd("Ram byte 50 NOT = 1",cr,lf): endif
poke 50,0
if ramloc(50)=1 then: sertxd("Ram byte 50 = 1",cr,lf): else: sertxd("Ram byte 50 NOT = 1",cr,lf): endif

b1=49
poke b1,1
if ramloc(b1)=1 then: sertxd("Ram byte ",#b1," = 1",cr,lf): else: sertxd("Ram byte ",#b1," NOT = 1",cr,lf): endif
poke b1,0
if ramloc(b1)=1 then: sertxd("Ram byte ",#b1," = 1",cr,lf): else: sertxd("Ram byte ",#b1," NOT = 1",cr,lf): endif
Output:
Code:
Ram byte 50 = 1
Ram byte 50 NOT = 1
Ram byte 49 = 1
Ram byte 49 NOT = 1
 

matchbox

Senior Member
Thanks for input and thought into the matter guys.
I'll give your layout a go Aries, and see how I find the application of it.

The reason for asking the original question was to find a simple and tidy method of doing this. Without too much memory use. As you can imagine, if I have already used up the standard variables, then the program is getting large and complicated. So a clean layout is something that I was looking for as well.
 
Top