FAQ  •  Register  •  Login

Different result than expected when poking to screen

<<

emook

Posts: 27

Joined: Tue Dec 06, 2016 1:23 am

Post Sat Dec 10, 2016 9:31 pm

Different result than expected when poking to screen

Hello,

In normal basic we can do this following code :

  Code:
10 BORDER 0: PAPER 0: INK 6: CLS
20 FOR i=1 TO 7
30 FOR y=0 TO 21
40 FOR x=0 TO 31
50 LET l=22528+x+y*32
60 POKE l,8*i
70 NEXT x
80 NEXT y
90 NEXT i



Image

To fill the screen with the desired colour (I know this example seems pointless, but the same method to poke a screen char is used quite a bit for me)

however, in ZXB it only seems to pokes to the top third of the screen :

  Code:
border 0
paper 0
ink 6
cls

dim i as ubyte
dim x as ubyte
dim y as ubyte
dim l as uinteger

FOR i=1 TO 6
FOR y=0 TO 23
FOR x=0 TO 31
l=22528+x+y*32
POKE l,8*i
NEXT
NEXT
NEXT


Image

Anyone know what I am doing wrong here?

Thanks!
<<

emook

Posts: 27

Joined: Tue Dec 06, 2016 1:23 am

Post Sat Dec 10, 2016 9:33 pm

Re: Different result than expected when poking to screen

OK - even though X and Y never exceed 255 they also have to be defined as Integers.

dim x as uinteger
dim y as uinteger

Fixes the issue! I suspect this is due to the internal calculations done in ZXB.
<<

emook

Posts: 27

Joined: Tue Dec 06, 2016 1:23 am

Post Sat Dec 10, 2016 9:59 pm

Re: Different result than expected when poking to screen

Additionally - This seems to be massively slower than Hisoft basic compiler.

In the following GIF I compile with HISOFT, then ZXB - you will see the difference in speeds.

Image
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sun Dec 25, 2016 7:52 pm

Re: Different result than expected when poking to screen

Yes, the 1st problem is for Uinteger overflow.
But you can do this:

  Code:
dim i as ubyte
dim x as ubyte
dim y as ubyte
dim l as uinteger

FOR i=1 TO 6
FOR y=0 TO 23
FOR x=0 TO 31
l=22528+x+(CAST(UInteger, y)<<5): REM Cast from ubyte to Uinteger to avoid overflow
POKE l,i<<3
NEXT
NEXT
NEXT

Also, when you multiply by a power of 2 (e.g. 8, 32 like in this case) you can use << n, where n is the power.
For example, 8 = 2^3, so to multiply per 8 you do (x << 3). The same applies to integer division with >>.
Normally ZX Basic does this automatically, but for some reason it's not working in this case, so I put it explicitly.
Compile this code with -O3 (optimize for speed) and tell me if it goes fast.

Use -O3 (might have bugs!) when you have tested your program, to get a faster optimized code.
<<

emook

Posts: 27

Joined: Tue Dec 06, 2016 1:23 am

Post Tue Dec 27, 2016 2:26 am

Re: Different result than expected when poking to screen

Yes much quicker! Thanks!

:)
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Wed Dec 28, 2016 1:33 pm

Re: Different result than expected when poking to screen

[quote="emook"]Additionally - This seems to be massively slower than Hisoft basic compiler.


See zx-basic-compiler/topic385.html for all the testing I did on this.


Hisoft doesn't let you drop to hand coded assembly for where you really want the best speed, or allow you to add in stuff from the a library ( http://www.boriel.com/wiki/en/index.php ... IC:Library ) either!

Return to ZX Basic Compiler

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