Re: Color parsingã By: Kirkman to echicken on Sun Dec 03 2017 02:36 pmãã > Re: Color parsingã > By: echicken to Kirkman on Sun Dec 03 2017 03:28 pmã >ã > ec> The foreground colour is in the lower three bits of the byte.ã > ec> var fg = attr&7; // 7 is essentially (1<<0)|(1<<1)|(1<<2)ã >ã > Wow, that was fast! Thanks, echicken.ã >ã > I was looking around online and experimenting with a bitwise calculator, andã > I ended up doing something like this:ã >ã > // Use bitwise AND with a mask to get the four rightmost bits.ã > // dec 15 | bin 00001111 | hex 0xfã > var fg = theAttr & 15;ã >ã > // Use bitwise AND with a mask to get the four leftmost bits.ã > // dec 240 | bin 11110000 | hex 0xf0ã > var bg = theAttr & 240;ã >ã > I think it's working, but I have other issues in my code to sort out beforeã > I can say 100%.ã >ã > Then I'm doing fg = fg & 7 to change high colors into low equivalents.ããIt's a little odd to be using decimal numbers in bit-wise operations (e.g. 0xf0ãmakes more sense than 240, given the context).ããBut I would usually use macros or constants for these magic numbers anyway.ãLike so (in JS):ãã const BG_COLOR = 0x70;ã const FG_COLOR = 0x07;ããThe BLINK and HIGH bit values are already defined in sbbsdefs.js (along withãall the color bit values).ããAnyway, so parsing the foreground color with the high/bright flag:ãã var fg_color = attr & (FG_COLOR | HIGH);ãã var bg_color = attr & BG_COLOR; // exclude the blink flagããTo convert the background color to a foreground color, just shift-right 4-bits.ãã var color = bg_color >> 4; // move the upper nibble to the lowerããThen you could compare 'color' against the color values defined in sbbsdefs.jsã(e.g. RED, BLUE, etc.).ããTo convert a foreground color to a background color, shift-left:ãã var bg_color = (color & FG_COLOR) << 4;ããIf you know that "color" won't include the HIGH flag or any other values thanã0-7, then you don't need the "& FG_COLOR" part.ããAnd the reason for all this madness?ã
https://en.wikipedia.org/wiki/Color_Graphics_Adapterã:-)ãã digital manããSynchronet "Real Fact" #64:ãSynchronet PCMS (introduced w/v2.0) is Programmable Command and Menu Structure.ãNorco, CA WX: 67.9øF, 56.0% humidity, 0 mph ESE wind, 0.00 inches rain/24hrsã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã