SCR_BASE
Posted: Wed Dec 11, 2024 11:41 pm
I spent a fair bit of time trying to explore what was going wrong in using SCR_BASE in SBASIC to find the base address of the screen on Q68 and QIMSI-Gold in the extended display modes (anything higher than the QL modes set by DISP_MODE 0 or 1).
I kept getting a negative value from SCR_BASE and it took me a while to realise that as SCR_BASE returns a signed 32 bit value, and the extended mode screens are at very high addresses on both machines ($FE80 0000) it's bound to return a negative value rather than the unsigned address value of 4,269,801,472 which corresponds to $FE80 0000. The same issue is true with other toolkit extensions which return screen base address.
Obviously having a 'negative' address may cause problems for programs which, for whatever reason, directly address the screen for doing graphics. (I was investigating why all sorts of things went wrong with an older program of mine which writes directly to the screen. Tut tut, naughty me
)
So in an effort to document the undocumented... (I'm sure some will say we shouldn't be writing direct to screens, but on very rare occasions it's necessary to directly manipulate the screen)
Unsigned 32 bit values go from 0 to 4,294,967,295 ($0 to $FFFF FFFF)
Signed 32 bit values go from -2,147,483,648 to +2,147,483,647
If we get a negative value from SCR_BASE we can do one of two things:
1) if the number is negative, add 4,294,967,296 (note: at these number sizes SBASIC will be using 'E' notation), something like: adr = SCR_BASE: IF adr < 0 THEN adr = adr + 4294967296
2) If the address returned by SCR_BASE is negative, check for MACHINE type and then do a hard address depending on the screen mode of the machine. MACHINE will be decimal 18 (hex 12) for Q68 or QIMSI-Gold, and if the screen address given by SCR_BASE is negative it will be at the fixed address $FE80 0000 (decimal 4269801472).
Method 2 only works on machines where the screen memory is at a fixed, known address. For standard QL mode 4 and 4 screens the base of screen is at QL addresses anyway, so a positive value which needs no change.
Any more ideas on this?
I kept getting a negative value from SCR_BASE and it took me a while to realise that as SCR_BASE returns a signed 32 bit value, and the extended mode screens are at very high addresses on both machines ($FE80 0000) it's bound to return a negative value rather than the unsigned address value of 4,269,801,472 which corresponds to $FE80 0000. The same issue is true with other toolkit extensions which return screen base address.
Obviously having a 'negative' address may cause problems for programs which, for whatever reason, directly address the screen for doing graphics. (I was investigating why all sorts of things went wrong with an older program of mine which writes directly to the screen. Tut tut, naughty me

So in an effort to document the undocumented... (I'm sure some will say we shouldn't be writing direct to screens, but on very rare occasions it's necessary to directly manipulate the screen)
Unsigned 32 bit values go from 0 to 4,294,967,295 ($0 to $FFFF FFFF)
Signed 32 bit values go from -2,147,483,648 to +2,147,483,647
If we get a negative value from SCR_BASE we can do one of two things:
1) if the number is negative, add 4,294,967,296 (note: at these number sizes SBASIC will be using 'E' notation), something like: adr = SCR_BASE: IF adr < 0 THEN adr = adr + 4294967296
2) If the address returned by SCR_BASE is negative, check for MACHINE type and then do a hard address depending on the screen mode of the machine. MACHINE will be decimal 18 (hex 12) for Q68 or QIMSI-Gold, and if the screen address given by SCR_BASE is negative it will be at the fixed address $FE80 0000 (decimal 4269801472).
Code: Select all
adr = SCR_BASE
IF adr < 0 THEN
IF MACHINE = 18 THEN adr = 4269801472
END IF
Any more ideas on this?