FAQ  •  Register  •  Login

UDG definition bug (*solved*)

<<

wilco2009

Posts: 28

Joined: Sat Nov 24, 2012 1:23 am

Post Wed Feb 20, 2013 10:55 pm

UDG definition bug (*solved*)

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

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Thu Feb 21, 2013 12:53 pm

Re: UDG definition bug

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

wilco2009

Posts: 28

Joined: Sat Nov 24, 2012 1:23 am

Post Thu Feb 21, 2013 9:42 pm

Re: UDG definition bug

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.
Last edited by wilco2009 on Mon Feb 25, 2013 11:12 pm, edited 1 time in total.
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Mon Feb 25, 2013 9:21 pm

Re: UDG definition bug

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

wilco2009

Posts: 28

Joined: Sat Nov 24, 2012 1:23 am

Post Tue Feb 26, 2013 7:27 pm

Re: UDG definition bug

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

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Feb 26, 2013 7:31 pm

Re: UDG definition bug

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 :P (UDG vars).
<<

wilco2009

Posts: 28

Joined: Sat Nov 24, 2012 1:23 am

Post Tue Feb 26, 2013 7:53 pm

Re: UDG definition bug

ok.
that's work right. :D
thank's very much.

Return to Bug Reports

Who is online

Users browsing this forum: No registered users and 4 guests

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

phpBB SEO