Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UDG definition bug (*solved*)
#1
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.
Reply
#2
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.
Reply
#3
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.
Reply
#4
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...
Reply
#5
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]
Reply
#6
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).
Reply
#7
ok.
that's work right. Big Grin
thank's very much.
Reply
#8
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.
Reply
#9
(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.
Reply
#10
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
Reply
#11
(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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)