Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : CMM2: Demystifying Mode 1 Colours
Author | Message | ||||
Womble Senior Member Joined: 09/07/2020 Location: United KingdomPosts: 267 |
I have read the manual, but am so used to the old GWBASIC/QBASIC color numbers that I was getting rather confused. Wombles are easily confused In order to demystify this for a numpty like me I wrote this little program. Mode1COLOURS.zip '--------------------------------------------------------------------------- ' Mode1COLOURS.BAS ' Demystifying the Integer Values and Red Green Blue values for RGB() mode1 ' Womble 24SEPT2020 '--------------------------------------------------------------------------- MODE 1,8 CLS OPEN "Mode1COLOURS.TXT" FOR OUTPUT AS #1 'Open a text file, Output a heading PRINT #1,"---------------------------------------------------------------------------" PRINT #1," Mode1COLOURS.BAS" PRINT #1," Demystifying the Integer Values and Red Green Blue values for RGB() mode1" PRINT #1," Womble 24SEPT2020" PRINT #1,"---------------------------------------------------------------------------" COLOUR RGB(WHITE) : PRINT #1,"White?", ColourValueOutput (RGB(white)) COLOUR RGB(WHITE) : PRINT #1,"Black?", ColourValueOutput (RGB(black)) COLOUR RGB(WHITE) : PRINT #1,"Blue?", ColourValueOutput (RGB(blue)) COLOUR RGB(WHITE) : PRINT #1,"Green?", ColourValueOutput (RGB(green)) COLOUR RGB(WHITE) : PRINT #1,"Cyan?", ColourValueOutput (RGB(cyan)) COLOUR RGB(WHITE) : PRINT #1,"Red?", ColourValueOutput (RGB(red)) COLOUR RGB(WHITE) : PRINT #1,"Magenta?", ColourValueOutput (RGB(magenta)) COLOUR RGB(WHITE) : PRINT #1,"Yellow?", ColourValueOutput (RGB(yellow)) COLOUR RGB(WHITE) : PRINT #1,"Brown?", ColourValueOutput (RGB(brown)) COLOUR RGB(WHITE) : PRINT #1,"Grey?", ColourValueOutput (RGB(gray)) CLOSE #1 'Close the file 'Display the colours onscreen COLOUR RGB(WHITE) : PRINT "White?", ColourValuePrint (RGB(white)) COLOUR RGB(WHITE) : PRINT "Black?", ColourValuePrint (RGB(black)) COLOUR RGB(WHITE) : PRINT "Blue?", ColourValuePrint (RGB(blue)) COLOUR RGB(WHITE) : PRINT "Green?", ColourValuePrint (RGB(green)) COLOUR RGB(WHITE) : PRINT "Cyan?", ColourValuePrint (RGB(cyan)) COLOUR RGB(WHITE) : PRINT "Red?", ColourValuePrint (RGB(red)) COLOUR RGB(WHITE) : PRINT "Magenta?", ColourValuePrint (RGB(magenta)) COLOUR RGB(WHITE) : PRINT "Yellow?", ColourValuePrint (RGB(yellow)) COLOUR RGB(WHITE) : PRINT "Brown?", ColourValuePrint (RGB(brown)) COLOUR RGB(WHITE) : PRINT "Grey?", ColourValuePrint (RGB(gray)) 'Pause until ESC is pressed DO : LOOP UNTIL INKEY$=CHR$(27) END '--------------------------------------------------------------------------- 'Output the colour information to a file SUB ColourValueOutput pcol% 'Parameter pcol% is the integer representation of the RGB() value LOCAL N$ = HEX$(pcol%) 'Convert to Hexadecimal String 'only 24 bits are colour info LOCAL TN$ = "&H"+MID$(N$,2,2) 'Extract Red Component (top 8bits) LOCAL MN$ = "&H"+MID$(N$,4,2) 'Extract Green Component (middle 8bits) LOCAL BN$ = "&H"+RIGHT$(N$,2) 'Extract Blue Component (bottom 8bits) PRINT #1,"decimal";pcol% 'Output the value in decimal to a file PRINT #1,"Red",VAL(TN$),"Green",VAL(MN$),"Blue",VAL(BN$) 'Output each 8bit value in decimal PRINT #1,"Red",TN$,"Green",MN$,"Blue",BN$ 'Output each 8bit value in hexadecimal PRINT #1,"-----------------------------------" 'print a separating line END SUB '--------------------------------------------------------------------------- 'Output the colour information to the screen SUB ColourValuePrint pcol% 'Parameter pcol% is the integer representation of the RGB() value COLOUR RGB(White) 'Text Heading Colour LOCAL N$ = HEX$(pcol%) 'Convert to Hexadecimal String 'only 24 bits are colour info LOCAL TN$ = "&H"+MID$(N$,2,2) 'Extract Red Component (top 8bits) LOCAL MN$ = "&H"+MID$(N$,4,2) 'Extract Green Component (middle 8bits) LOCAL BN$ = "&H"+RIGHT$(N$,2) 'Extract Blue Component (bottom 8bits) PRINT "decimal";pcol% 'print the value in decimal PRINT "Red",VAL(TN$),"Green",VAL(MN$),"Blue",VAL(BN$) 'print each 8bit value in decimal COLOUR pcol% 'Set Output to this colour PRINT "Red",TN$,"Green",MN$,"Blue",BN$ 'print each 8bit value in hexadecimal PRINT "--------------------------------" 'print a separating line END SUB '--------------------------------------------------------------------------- It writes a file "Mode1COLOURS.TXT" on to the SD card, and displays the results onscreen (press ESC to exit) and shows the RGB(r,g,b) values for the predefined colour shortcuts. It also shows how to set the foregraound colours for PRINT statements. I did not bother with background colours, the syntax is the same (from the manual): COLOUR fore [, back] or COLOR fore [, back] Sets the default colour for commands (PRINT, etc) that display on the on the VGA monitor. 'fore' is the foreground colour, 'back' is the background colour. The background is optional and if not specified will default to black. eg. COLOUR RGB(Yellow),RGB(Red) sets foreground to Yellow, background to Red using the shortcut form (not case sensitive). This is equivalent to COLOR RGB(255,255,0),RGB(255,0,0) --------------------------------------------------------------------------- Mode1COLOURS.BAS Demystifying the Integer Values and Red Green Blue values for RGB() mode1 Womble 24SEPT2020 --------------------------------------------------------------------------- White? decimal 268435455 Red 255 Green 255 Blue 255 Red &HFF Green &HFF Blue &HFF ----------------------------------- Black? decimal 0 Red 0 Green 0 Blue 0 Red &H Green &H Blue &H0 ----------------------------------- Blue? decimal 251658495 Red 0 Green 0 Blue 255 Red &H00 Green &H00 Blue &HFF ----------------------------------- Green? decimal 251723520 Red 0 Green 255 Blue 0 Red &H00 Green &HFF Blue &H00 ----------------------------------- Cyan? decimal 251723775 Red 0 Green 255 Blue 255 Red &H00 Green &HFF Blue &HFF ----------------------------------- Red? decimal 268369920 Red 255 Green 0 Blue 0 Red &HFF Green &H00 Blue &H00 ----------------------------------- Magenta? decimal 268370112 Red 255 Green 0 Blue 192 Red &HFF Green &H00 Blue &HC0 ----------------------------------- Yellow? decimal 268435200 Red 255 Green 255 Blue 0 Red &HFF Green &HFF Blue &H00 ----------------------------------- Brown? decimal 268402688 Red 255 Green 128 Blue 0 Red &HFF Green &H80 Blue &H00 ----------------------------------- Grey? decimal 255868992 Red 64 Green 64 Blue 64 Red &H40 Green &H40 Blue &H40 ----------------------------------- I am posting this here in case it helps any new CMM2 users. |
||||
Womble Senior Member Joined: 09/07/2020 Location: United KingdomPosts: 267 |
Ok ... more hacking about to replicate old dialects of Basic (Gw, Q, etc.) GwBasicCOLOURS.zip '----------------------------------------------------------------------------------------- ' GwBasicCOLOURS.BAS ' Recreating the GwBasic/QBasic COLOR and LOCATE commands for the CMM2 ' cycles through the CMM2 modes in 8bit colour and shows how to determine test screen size ' ' syntax: ' Gcolour foreground%, background% ' Glocate screenrow%, column% ' ' Womble 24SEPT2020 '----------------------------------------------------------------------------------------- 'Set array option base to index from 0 OPTION BASE 0 'clear the screen to avoid unwanted scrolling from the CMM2 user interace CLS 'Constants used to hold RGB values 'Tweak these RGB values to adjust the shades displayed CONST Gblack% = RGB(0,0,0) CONST Gblue% = RGB(0,0,128) CONST Ggreen% = RGB(0,179,0) CONST Gcyan% = RGB(0,148,148) CONST Gred% = RGB(128,0,0) CONST Gmagenta% = RGB(128,0,128) CONST Gbrown% = RGB(128,128,0) CONST Ggray% = RGB(187,187,187) CONST Gcharcoal% = RGB(85,85,85) CONST Gbblue% = RGB(85,85,255) CONST Gbgreen% = RGB(85,255,85) CONST Gbcyan% = RGB(85,255,255) CONST Gorange% = RGB(255,85,64) CONST Gpink% = RGB(255,64,255) CONST Gyellow% = RGB(255,255,0) CONST Gwhite% = RGB(255,255,255) DIM Gcolour%(15) 'Array of RGB values, index is GwBasic color number 'Load the RGB values from the constants into the array Gcolour%(0) = Gblack% Gcolour%(1) = Gblue% Gcolour%(2) = Ggreen% Gcolour%(3) = Gcyan% Gcolour%(4) = Gred% Gcolour%(5) = Gmagenta% Gcolour%(6) = Gbrown% Gcolour%(7) = Ggray% Gcolour%(8) = Gcharcoal% Gcolour%(9) = Gbblue% Gcolour%(10) = Gbgreen% Gcolour%(11) = Gbcyan% Gcolour%(12) = Gorange% Gcolour%(13) = Gpink% Gcolour%(14) = Gyellow% Gcolour%(15) = Gwhite% '--------------------------------------------------------------------------------- 'Test the locate finction and print characters at each corner of screen Glocate 49,0 print "X"; Glocate 49,99 print "X" Glocate 0,99 print "X" Glocate 0,0 print "Mode 1,8 "+STR$(MM.INFO(FONTWIDTH))+"x"+STR$(MM.INFO(FONTHEIGHT))+" font : Hit Esc to Start" do : loop until inkey$=chr$(27) 'try different modes for m% = 1 to 12 mode m%,8 cls Gcolor 15,0 'Default Colours Glocate ((MM.VRES \ MM.INFO(FONTHEIGHT))-2),1 'Penultimate row PRINT "Font "+STR$(MM.INFO(FONTWIDTH))+"x"+STR$(MM.INFO(FONTHEIGHT)), PRINT "= Rows "+STR$(MM.VRES \ MM.INFO(FONTHEIGHT))+" Cols "+STR$(MM.hRES \ MM.INFO(FONTWIDTH)) Glocate ((MM.VRES \ MM.INFO(FONTHEIGHT))-1),1 'Bottom, Left of screen PRINT "Mode "+STR$(m%)+".8 "+"Hit ESC to continue"; for f = 0 to 15 for b = 0 to 15 Gcolor f,b Glocate f,b print "#" next b next f do : loop until inkey$=chr$(27) next m% 'reset screen mode and exit mode 1,8 end '--------------------------------------------------------------------------------- SUB Gcolor Gfore%, Gback% LOCAL Gf% = Gfore% LOCAL Gb% = Gback% IF Gf% > 15 OR Gf% < 0 THEN Gf% = 15 'default to High Intensity White foreground ENDIF IF Gb% > 15 OR Gb% < 0 THEN Gb% = 0 'default to Black background ENDIF COLOUR Gcolour%( Gf% ),Gcolour%( Gb% ) 'set the colours END SUB '--------------------------------------------------------------------------------- SUB Glocate row%, col% LOCAL x% = col% LOCAL y% = row% IF x% < 0 OR x% > ( MM.HRES \ MM.INFO(FONTWIDTH) ) THEN 'max character in row x% = MM.HRES \ MM.INFO(FONTWIDTH) 'set to max characters ENDIF IF y% < 0 OR y% > ( MM.VRES \ MM.INFO(FONTHEIGHT) ) THEN 'max rows onscreen y% = MM.VRES \ MM.INFO(FONTHEIGHT) 'set to max rows ENDIF PRINT @((MM.INFO(FONTWIDTH)*x%),(MM.INFO(FONTHEIGHT)*y%))""; 'position cursor 'where x is the character column, and y is the character row 'https://www.thebackshed.com/forum/ViewTopic.php?TID=12778&PID=155313#155313#155313 END SUB '--------------------------------------------------------------------------------- Its a crude hack but I hope this is helpful to someone Tested on Firmware V5.05.06b14 both headless (TerraTerm & Windows Camera), and with a 4:3 VGA screen and keyboard. Edited 2020-09-25 07:14 by Womble |
||||
Print this page |