Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Strange behaviour with memory pointer calculation (*solved*)
#1
Splitting this out from the other thread, sorry. Smile

In 1.6.2 there seems to be something weird going on when I perform calculations on memory pointers. My program switches between various banks of UDGs by POKEing 23675/23676 to point to different addresses. When I compiled with the 1.6.2 I noticed that none of my UDGs were working properly. After some experimentation I discovered that the maths I was using to calculate the high and low byte values was giving the wrong values for some reason.

Take a look at this program, which I adapted from my main program (hence it looking a bit weird, sorry):
Code:
dim n, b as ubyte
declare sub start()

start()

UDGS:
asm
defb 255,255,255,255,255,255,255,255
end asm

sub start()
    cls
    print "@UDGS = ";@UDGS
    print "@UDGS/256 = ";(@UDGS/256)
    print "int(@UDGS/256) = ";int(@UDGS/256)
    b=int(@UDGS/256)
    print "b = ";b
end sub

When I run this the address of the UDGS bank is 32793. The first two calculations that I print directly (without assigning to a variable) work as I would expect - the value is 128. But when I do the same calculation and assign it to ubyte 'b', the value suddenly becomes 254. This same program produces '128' in all PRINT statements using version 1.5.3 of ZX Basic.

I've no idea what's going on there, unfortunately. Sorry! Sad
Reply
#2
Thanks for reporting! this is a bug in the compiler. Will fix it ASAP :roll:
Reply
#3
Can you download version 1.6.4 and test it again, please? :roll:
Reply
#4
Thanks, boriel - it's much appreciated as always.

This one behaves better than 1.6.2, but I'm still having trouble with the other part of my calculation - I revised the test program to show this by adding a few extra lines:

Code:
dim n, b, c as ubyte
dim x as uinteger
declare sub start()

start()

UDGS:
asm
defb 255,255,255,255,255,255,255,255
end asm

sub start()

    cls
    print "@UDGS = ";@UDGS
    print "@UDGS/256 = ";(@UDGS/256)
    print "int(@UDGS/256) = ";int(@UDGS/256)
    print "@UDGS-((int(@UDGS/256))*256) = ";@UDGS-((int(@UDGS/256))*256)
    b=int(@UDGS/256)
    c=@UDGS-((int(@UDGS/256))*256)
    print "b = ";b
    print "c = ";c
    
    print
    
    x=@UDGS
    print "x = ";x
    print "x/256 = ";(x/256)
    print "int(x/256) = ";int(x/256)
    print "x-((int(x/256))*256) = ";x-((int(x/256))*256)
    b=int(x/256)
    c=x-((int(x/256))*256)
    print "b = ";b
    print "c = ";c
    
end sub

The (slightly dodgy, please forgive me - I was trying to do the whole thing in one line) code to calculate the high and low byte values for the UDG pointer is now getting one of the two values right but the other one is still wrong unless I assign the memory pointer to a variable first.

When I run the new test the value of @UDGS is 24601, so I would expect the values of b and c to be 96 and 25 respectively. Looking at the second set of results (where I assign @UDGS to the variable 'x' first) you can see this is what I get. But on the first set of results where I do the calculations with @UDGS directly the 'c' calculation results in '24576' rather than '25', so the byte value becomes '0'.

Sorry if this is a bit of a pain - I realise I could just adjust the code and avoid the issue entirely but I'm not sure how likely it is that the problem will appear elsewhere... Sad
Reply
#5
LTee Wrote:Sorry if this is a bit of a pain - I realise I could just adjust the code and avoid the issue entirely but I'm not sure how likely it is that the problem will appear elsewhere... Sad
On the contrary, it's me who must thank you! :roll:
This is what the compiler needs (more testing) and it's a way to contribute to it. I'll check it ASAP. Thx.
Reply
#6
OK, I think It's fixed now. Can you download version 1.6.6 and test it, please? :roll:
Reply
#7
Looking good, boriel - all my UDGs are back to normal and all of my other test programs are passing perfectly! I think you can mark this one as solved, thanks so much for the help!
Reply
#8
You're welcome Smile
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)