Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Different result than expected when poking to screen
#1
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: tK1VcJ5.png]

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: UdGaSL2.png]

Anyone know what I am doing wrong here?

Thanks!
Reply
#2
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.
Reply
#3
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: T5Qs3w0.gif]
Reply
#4
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.
Reply
#5
Yes much quicker! Thanks!

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


See <!-- l --><a class="postlink-local" href="https://forum.boriel.com/zx-basic-compiler/topic385.html">zx-basic-compiler/topic385.html</a><!-- l --> 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 ( <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Library">http://www.boriel.com/wiki/en/index.php ... IC:Library</a><!-- m --> ) either!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)