Forum
UDG definition bug (*solved*) - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15)
+---- Thread: UDG definition bug (*solved*) (/showthread.php?tid=530)



UDG definition bug (*solved*) - wilco2009 - 02-20-2013

The ZXSpectrum hangs with the following code:
Code:
FOR n=0 TO 7: POKE USR "A"+n,255: NEXT n
FOR n=0 TO 7: POKE USR "B"+n,255: NEXT n
FOR n=0 TO 7: POKE USR "C"+n,255: NEXT n
FOR n=0 TO 7: POKE USR "D"+n,255: NEXT n
FOR n=0 TO 7: POKE USR "E"+n,255: NEXT n
FOR n=0 TO 7: POKE USR "F"+n,255: NEXT n

PRINT "\a \b \c \d \e \f"
Definition of UDG A & B works properly but program does not work from UDG C.


Re: UDG definition bug - boriel - 02-21-2013

Try compiling with --spectrum and see if it works. If it does, then it's not a bug, but a memory corruption.

The UDG zone is not reserved anymore, and POKE USR "a" will poke into the address pointed by PEEK Uinteger 23676. You will have to set this address to a safe (unallocated) memory zone. The --spectrum flag does this already for you (among other things).

The new (optima way) is to define an array of bytes, and POKEing 23676 to its address:
Code:
DIM myudg(8 * 10) As Ubyte : REM 10 UDG chars
POKE Uinteger 23676, @myudg(0) : REM Points 23676 to Address of myudg array 1st element
Now you can safely use USR "a".
However, a better way is to directly initialize the array:
Code:
DIM myudg(9, 7) As Ubyte => { {255, 255, 255, 255,  255, 255, 255, 255}, _
        {255, 255, 255, 255,  255, 255, 255, 255}, _
       ... ' 10 times
       } : REM 10 UDG chars
POKE Uinteger 23676, @myudg(0) : REM Points 23676 to Address of myudg array 1st element already with graphics
Since the myudg array already contains the UDG data, you needn't to use POKE, and will save memory.

Note: The --spectrum flag tries to be the most compatible with original Sinclair Basic (at the expenses performance and memory).
If you are converting old original Sinclair BASIC programs, this flag could be useful.


Re: UDG definition bug - wilco2009 - 02-21-2013

I'm afraid this is not the problem. I typed the following code:
Code:
#pragma explicit = false
DIM myudg(8 * 10) As Ubyte : REM 10 UDG chars
POKE Uinteger 23676, @myudg(0) : REM Points 23676 to Address of myudg array 1st element

FOR n=0 TO 7: POKE USR "A"+n,255: NEXT n
FOR n=0 TO 7: POKE USR "B"+n,255: NEXT n
FOR n=0 TO 7: POKE USR "C"+n,255: NEXT n
FOR n=0 TO 7: POKE USR "D"+n,255: NEXT n
FOR n=0 TO 7: POKE USR "E"+n,255: NEXT n
FOR n=0 TO 7: POKE USR "F"+n,255: NEXT n

PRINT "\a \b \c \d \e \f"
And the behaviour still being the same. Spectrum hangs when execute POKE USR "C" sentence.
Also does not work with --sinclair option.
The following code works perfectly:

Code:
9705 FOR N=0 TO 8*6-1: POKE USR "A"+N,255: NEXT N

Of course your solution is much more efficient than previous code. I'll use that you propose.


Re: UDG definition bug - boriel - 02-25-2013

Sorry for the delay (yes, busy) :oops:

You're right. There is a BUG in the USR asm routine. Even more, this routine might be corrupting your memory silently even if your program does not crash in the 1st instance...

Please, download version 1.3.0s975 and tell me if works ok now...


Re: UDG definition bug - wilco2009 - 02-26-2013

working, but....... the solution you proposed previously doesn't work
The result of the following code is a set of aleatory UDGs. Attached you can see a screenshot of the result.
Code:
DIM myudg(8 * 10-1) As Ubyte = {_
        255,255,255,255,255,255,255,255,_
        255,255,255,255,255,255,255,255,_
        255,255,255,255,255,255,255,255,_
        255,255,255,255,255,255,255,255,_
        255,255,255,255,255,255,255,255,_
        255,255,255,255,255,255,255,255,_
        255,255,255,255,255,255,255,255,_
        255,255,255,255,255,255,255,255,_
        255,255,255,255,255,255,255,255,_
        255,255,255,255,255,255,255,255_
    }
POKE Uinteger 23676, @myudg(0) : REM Points 23676 to Address of myudg array 1st element
PRINT "\a \b \c \d \e \f"

[Image: testuep.png]


Re: UDG definition bug - boriel - 02-26-2013

wilco2009 Wrote:working, but....... the solution you proposed previously doesn't work
The result of the following code is a set of aleatory UDGs. Attached you can see a screenshot of the result.
Code:
[...]
POKE Uinteger 23676, @myudg(0) : REM Points 23676 to Address of myudg array 1st element
PRINT "\a \b \c \d \e \f"
My bad! It was POKE Uinteger 23675 Tongue (UDG vars).


Re: UDG definition bug - wilco2009 - 02-26-2013

ok.
that's work right. Big Grin
thank's very much.


RE: UDG definition bug (*solved*) - worcestersource - 04-05-2021

I've been scratching my head around this. I've found that if you declare the array that holds the UDGs in an (a, b) format, when you call it, the array needs to take two parts.

Code:
POKE uInteger 23675, @graphicsdata(0,0)

This may help someone in the future.


RE: UDG definition bug (*solved*) - boriel - 04-06-2021

(04-05-2021, 08:57 PM)worcestersource Wrote: I've been scratching my head around this. I've found that if you declare the array that holds the UDGs in an (a, b) format, when you call it, the array needs to take two parts.

Code:
POKE uInteger 23675, @graphicsdata(0,0)

This may help someone in the future.

It's already been discussed in the forum (somewhere). In general for an array a(i1, i2, i3, .., iN), the first element is a(0,0,0,0,0...0), and you can use @ to get its address.


RE: UDG definition bug (*solved*) - worcestersource - 04-06-2021

Yes, thanks. I thought adding my comment might help someone like me that's coming back to coding after a long time but both a bit rusty and learning how to do new things.

zxbasic is marvellous, by the way!  Smile


RE: UDG definition bug (*solved*) - boriel - 04-07-2021

(04-06-2021, 07:19 PM)worcestersource Wrote: Yes, thanks. I thought adding my comment might help someone like me that's coming back to coding after a long time but both a bit rusty and learning how to do new things.

zxbasic is marvellous, by the way!  Smile

No worries. I understand. Indeed I'm working in a good tutorial. Will announce it once it have some good content. Cool