12-25-2016, 07:52 PM
Yes, the 1st problem is for Uinteger overflow.
But you can do this:
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.
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
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.