Date : Sun, 28 Feb 2016 12:38:55 +0000
From : jgh@... (J.G.Harston)
Subject: Reading current colours
Several long journeys with my mind in neutral resulted in trimming the
code down to this:
LDA #0:STA col :\ Clear result
LDX #87:LDA #160:JSR osbyte :\ Get foreground text colour
STX mask :\ Save colour bitmap
LDX #96:LDA #160:JSR osbyte :\ Get maximum colour
STX max :\ Save maximum colour
INX:TXA:ORA #8 :\ Use bitmap from max as counter
.lp
ROL mask:ROL mask:ROL col :\ Rotate every second bit into result
ROR A:BCC lp :\ Loop until set bit rotated out
LDA col:AND max :\ Get result, AND with max colour
The epiphany was realising I could use the maximum number of colours
value as a counter by moving the bits out and waiting for the bit to
change. With a bit of a fudge to make '16 colours' rotate 3 times
instead of 4 times.
The simplest BASIC equivalent I could work out was this:
col%=FNosbyte(160,whatever,0)
FOR loop%=1 TO 3-INTSQR((FNosbyte(160,96,0)+1)/4)
col%=4*INTSQR((col%DIV16)+1)+SQR((col%AND15)+1)-5
NEXT loop%
I've written it up and added it to the Wiki.
--
J.G.Harston - jgh@... - mdfs.net/jgh