FAQ  •  Register  •  Login

Strange behaviour with memory pointer calculation (*solved*)

<<

LTee

Posts: 153

Joined: Tue Jul 07, 2009 2:54 pm

Post Sun Jun 25, 2017 3:33 pm

Strange behaviour with memory pointer calculation (*solved*)

Splitting this out from the other thread, sorry. :)

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! :(
<<

boriel

Site Admin

Posts: 1462

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Jun 27, 2017 1:30 pm

Re: Strange behaviour with memory pointer calculation

Thanks for reporting! this is a bug in the compiler. Will fix it ASAP :roll:
<<

boriel

Site Admin

Posts: 1462

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Wed Jun 28, 2017 10:39 pm

Re: Strange behaviour with memory pointer calculation

Can you download version 1.6.4 and test it again, please? :roll:
<<

LTee

Posts: 153

Joined: Tue Jul 07, 2009 2:54 pm

Post Thu Jun 29, 2017 9:38 pm

Re: Strange behaviour with memory pointer calculation

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... :(
<<

boriel

Site Admin

Posts: 1462

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Thu Jun 29, 2017 11:01 pm

Re: Strange behaviour with memory pointer calculation

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... :(

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.
<<

boriel

Site Admin

Posts: 1462

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Jul 01, 2017 1:24 am

Re: Strange behaviour with memory pointer calculation

OK, I think It's fixed now. Can you download version 1.6.6 and test it, please? :roll:
<<

LTee

Posts: 153

Joined: Tue Jul 07, 2009 2:54 pm

Post Sat Jul 01, 2017 8:25 pm

Re: Strange behaviour with memory pointer calculation

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!
<<

boriel

Site Admin

Posts: 1462

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sun Jul 02, 2017 7:46 pm

Re: Strange behaviour with memory pointer calculation

You're welcome :)

Return to Bug Reports

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO