Reading current colours
OSBYTE 160 reads the VDU variables, and OSBYTE 160,87 to OSBYTE 160,90 read the current text and graphics colours:
OSBYTE 160,87: | read foreground text colour |
OSBYTE 160,88: | read background text colour |
OSBYTE 160,89: | read foreground graphics colour |
OSBYTE 160,90: | read background graphics colour |
Unfortunately, they don't return the actual logical colour supplied as the parameter to COLOUR or GCOL. They return the bitmap that that colour stores in the screen memory:
2 colours: | &00, &FF |
4 colours: | &00, &0F, &F0, &FF |
16 colours: | &00, &03, &0C, &0F, &30, &33, &3C, &3F, &C0, &C3, &CC, &CF, &F0, &F3, &FC, &FF |
The values returned in 2-colour and 4-colour MODEs can be converted to logical colour numbers quite easily:
colour% =FNosword(160,whatever) maxColour%=FNosword(160,96) colour%=(colour% DIV 8) AND maxColour%
or:
LDX #whatever:JSR osword160:PHA :\ read colour mask LDX #96:JSR osword160:STA temp :\ read max. colour PLA:LSR A:LSR A:LSR A :\ divide colour mask by 8 AND temp :\ AND with max. colour
Converting 16-colour colour masks is more complicated. Also, on the Master the graphics colour is stored elsewhere.