This is a recurrent question:
You're facing truncation because y * 32 is computed on first place (* has precedence over +), and y * 32 = 576 ( > 255). Some compilers do type promotion (coercion) automatically. ZX Basic does not because for Z80 (8 bits, no multiplication instruction) this will degrade performance. In the future this feature will be added as an option.
You can cast explicitly:
The above will fix it, signaling that y value must used as an Uinteger in that multiplication. See CAST for an explanation.
Anyway, there's already a very fast function for calculating the ATTR address:
ATTR function is implemented in a library (#include <attr.bas>). And so is POINT.
You're facing truncation because y * 32 is computed on first place (* has precedence over +), and y * 32 = 576 ( > 255). Some compilers do type promotion (coercion) automatically. ZX Basic does not because for Z80 (8 bits, no multiplication instruction) this will degrade performance. In the future this feature will be added as an option.
You can cast explicitly:
Code:
attrMem=22528+CAST(Uinteger, y)*32+x
Anyway, there's already a very fast function for calculating the ATTR address:
Code:
#include <attr.bas>
DIM x,y AS UBYTE
CLS
y=18
x=4
POKE AttrAddr(y, x),16 'red paper, black ink
ATTR function is implemented in a library (#include <attr.bas>). And so is POINT.