Date : Sun, 25 Oct 2015 13:33:22 +0000 (WET)
From : bbcmicro@... (Peter Coghlan)
Subject: Reading current colours
>
> I'd got as far as:
> colour% =FNosword(160,whatever)
> maxColour%=FNosword(160,96)
> IF maxColour%=3:colour%=colour% DIV 8
> colour%=colour% AND maxColour%
>
> or:
> LDX #whatever:JSR osword160:PHA :\ read colour mask
> LDX #96:JSR osword160:TAX:PLA :\ read max. colour
> CPX #3:BNE skip:LSR A:LSR A:LSR A:.skip :\ divide by 8 if max=3
> STX temp:AND temp :\ AND with max. colour
>
> which works for 2-colour and 4-colour modes, but it looks like 16-colour
> modes is going to end up being a chunk of special-case code. I was
> hoping I could build something that was just arithmetic manipulation,
> not a load of IF cases. But it looks like it will end up being a special
> case for each colour depth.
>
I think this should work for all modes except the text only modes. If you
AND the result with the maximum colour number, it should work for everything
(except mode 7 of course).
LDA #160
LDX #87 \ Get foreground text colour byte
JSR osbyte
TXA
PHA
LDA #160
LDX #97 \ Get pixels per byte minus 1
JSR osbyte
INX \ Get pixels per byte
STX counter
PLA
LDY #8 \ Go around once for each bit in byte
.loop1
LDX counter \ Get pixels per byte each time around
.loop2
LSR A \ Discard one bit for each pixel per byte
DEX
BNE loop2
ROR result \ Rotate in one discarded bit only
DEY
BNE loop1 \ Go around entire byte
LDA result
RTS
Regards,
Peter Coghlan.