' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
'
'                           Q D E M O _ B . B A S
'
'  This file is a subcomponent of the QBSCR Screen Routines Demonstration
'  program QDEMO. It is not meant to run as a standalone program. Use only
'  in conjunction with the QDEMO.BAS program.  See QBSCR documentation or
'  QDEMO.BAS for more information.
'
' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

'$INCLUDE: 'qbscr.inc'
'$INCLUDE: 'mouse.bi'

COMMON SHARED kolor%
COMMON SHARED mouseExists%

DECLARE SUB InfoBox (messageNum%)
DECLARE SUB DrawBoxPointer (x%, y%)
DECLARE SUB SetChaosPalette (pal%())
DECLARE SUB ShowPaletteInfo (pal%())
DECLARE SUB SetPalette (pal%())

CONST CANTDOBRIGHTBACKS = -1
CONST CANTDOEGAVGACOLORS = -5
CONST NEEDCOLOR = -6
CONST QDEMO1CLRMISSING = -8
CONST QDEMO1MONMISSING = -9

SUB BrightBacks

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  This routine displays a screen's worth of data and two buttons in the
	'  window.  The first button is either Bright Backs or Normal Backs, de-
	'  pending on the current state of the system.  The other button is a
	'  Done button.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Display a window.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF kolor% THEN
		ft% = 6
		ft2% = 7
		bs% = STYLE3D
	ELSE
		InfoBox CANTDOBRIGHTBACKS
		EXIT SUB
	END IF

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  If we are using the mouse, make sure that it is off while we are
	'  writing to the screen.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF mouseExists% THEN
		MouseHide
	END IF

	MakeWindow 6, 6, 23, 75, 0, 7, 0, ft%, -1, 0, ""

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Add the screen buttons.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	DrawButton SINGLEBORDER, 8, 20, 23, 22, 0, 7, "Bright Backs", bs%
	DrawButton SINGLEBORDER, 25, 20, 40, 22, 0, 7, "Done", bs%

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Draw the text in colors that will not show when Bright Backs are off.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	MakeWindow 18, 42, 22, 73, 23, 7, 0, 0, -1, 0, ""
	LOCATE 20, 47, 0: PRINT "Bright Backgrounds ON!";

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Add explanatory text to the window.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	COLOR 0, 7
	Center "The QBSCR Screen Routines give you access to 16 background", 8
	Center "colors via the BlinkOff and BlinkOn routines.  They trade", 9
	Center "blinking attributes for bright backgrounds.  Below and to", 10
	Center "the right, a window has been drawn.  It is in colors that", 11
	Center "cannot be seen unless bright backgrounds are enabled.  To", 12
	Center "see the window, click on the Bright Backgrounds button or", 13
	Center "hit the B key.  To quit, click the Done button or hit the", 14
	Center "D or ESC keys.  See the QBSCR documentaiton for more info", 15
	Center "regarding the BlinkOff and BlinkOn routines.", 16
 

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Turn the mouse back on if it is around here.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF mouseExists% THEN
		MouseShow
	END IF

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Now we must wait on the user for a response of some kind.  To do this,
	'  we use the QBSCR routine GetEvent%.  It will return a keypress or a
	'  mouse event, whichever occurs first.  If the C, c, Esc, or right
	'  mouse buttons are pressed, or if the left button is pressed while the
	'  mouse cursor is on the Cancel button, we get out. If the P, p, or left
	'  mouse button is pressed while one the Print Form button, then we
	'  print a form and THEN get out.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	done% = FALSE
	brightState% = 0
	WHILE done% = FALSE

		' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
		'  Get an event of some kind.
		' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
		IF mouseExists% THEN
			MouseShow
		END IF
		result% = getEvent%(mouseExists%, kc%, mx%, my%)

		' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
		'  Decide what to do based on the event that occurred.
		' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
		SELECT CASE result%
			CASE EMpressedLeft      ' Mouse left button pressed.
			
				' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
				'  See if the mouse was on the PrintForm button.
				' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
				IF (mx% >= 8) AND (mx% <= 23) AND (my% >= 20) AND (my% <= 22) THEN
					IF brightState% = 0 THEN
						PressButton SINGLEBORDER, 8, 20, 23, 22, 0, 7, "Bright Backs", bs%
						DrawButton SINGLEBORDER, 8, 20, 23, 22, 0, 7, "Normal Backs", bs%
						BlinkOff
						brightState% = 1
					ELSE
						PressButton SINGLEBORDER, 8, 20, 23, 22, 0, 7, "Normal Backs", bs%
						DrawButton SINGLEBORDER, 8, 20, 23, 22, 0, 7, "Bright Backs", bs%
						BlinkOn
						brightState% = 0
					END IF
				END IF

				' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
				'  See if the mouse was on the Done button.
				' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
				IF (mx% >= 25) AND (mx% <= 40) AND (my% >= 20) AND (my% <= 22) THEN
					PressButton SINGLEBORDER, 25, 20, 40, 22, 0, 7, "Done", bs%
					done% = TRUE
				END IF

			CASE EMpressedRight     ' Right mouse button pressed.
				done% = TRUE

			CASE EKpressed          ' Keyboard pressed.
				IF (kc% = 27) OR (kc% = ASC("D")) OR (kc% = ASC("d")) THEN
					done% = TRUE
				END IF

				IF (kc% = ASC("B")) OR (kc% = ASC("b")) OR (kc% = ASC("N")) OR (kc% = ASC("n")) THEN
					IF brightState% = 0 THEN
						DrawButton SINGLEBORDER, 8, 20, 23, 22, 0, 7, "Normal Backs", bs%
						BlinkOff
						brightState% = 1
					ELSE
						DrawButton SINGLEBORDER, 8, 20, 23, 22, 0, 7, "Bright Backs", bs%
						BlinkOn
						brightState% = 0
					END IF
				END IF
			CASE ELSE
		END SELECT

	WEND

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Ensure that bright backgrounds are OFF when we leave this place, or
	'  the Get Fore/Back demo may be screwed up!
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	BlinkOn

END SUB

SUB DrawBoxPointer (x%, y%)

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  This routine is used by the GetForeBack routine, and simply draws a
	'  box-shaped pointer on the screen at the passed-in coordinates.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

	COLOR 15, 0
	LOCATE y%, x%, 0
	PRINT "ÚÄ¿";
	LOCATE y% + 1, x%, 0
	PRINT "³";
	LOCATE y% + 1, x% + 2, 0
	PRINT "³";
	LOCATE y% + 2, x%, 0
	PRINT "ÀÄÙ";

END SUB

SUB EgaVgaColors

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  This demo-nstrates the rgbRGB function and the use of 64 possible
	'  colors in text mode with an EGA/VGA card.  Uses the QBSCR EgaPresent
	'  function to determine if an EGA/VGA is present.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  If an EGA/VGA is not present, then display an error and get outta here.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF (EgaPresent% = FALSE) THEN
		InfoBox CANTDOEGAVGACOLORS
		EXIT SUB
	END IF

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Need to make sure color is available, since it is possible to have a
	'  monochrome VGA system.  If not, error and exit.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF kolor% = FALSE THEN
		InfoBox NEEDCOLOR
		EXIT SUB
	END IF

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  If mouse is around, hide it.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF mouseExists% THEN
		MouseHide
	END IF

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Define and initialize palette arrays.  The values in the arrays were
	'  predetermined to be the correct colors.  You can experiment with the
	'  rgbRGB function on your own to see all 64 possible colors.  These
	'  color calues will be used by the rgbRGB% function later.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	DIM redPal%(9, 3)
	DIM greenPal%(9, 3)
	DIM bluePal%(9, 3)
	DIM chaosPal%(9, 3)

	' Reds
	redPal%(1, 1) = 1: redPal%(1, 2) = 0: redPal%(1, 3) = 0
	redPal%(2, 1) = 2: redPal%(2, 2) = 0: redPal%(2, 3) = 0
	redPal%(3, 1) = 2: redPal%(3, 2) = 1: redPal%(3, 3) = 0
	redPal%(4, 1) = 3: redPal%(4, 2) = 1: redPal%(4, 3) = 0
	redPal%(5, 1) = 3: redPal%(5, 2) = 0: redPal%(5, 3) = 0
	redPal%(6, 1) = 3: redPal%(6, 2) = 0: redPal%(6, 3) = 1
	redPal%(7, 1) = 3: redPal%(7, 2) = 1: redPal%(7, 3) = 1
	redPal%(8, 1) = 3: redPal%(8, 2) = 1: redPal%(8, 3) = 2
	redPal%(9, 1) = 3: redPal%(9, 2) = 2: redPal%(9, 3) = 2

	' Greens
	greenPal%(1, 1) = 0: greenPal%(1, 2) = 1: greenPal%(1, 3) = 0
	greenPal%(2, 1) = 0: greenPal%(2, 2) = 2: greenPal%(2, 3) = 1
	greenPal%(3, 1) = 0: greenPal%(3, 2) = 2: greenPal%(3, 3) = 0
	greenPal%(4, 1) = 0: greenPal%(4, 2) = 3: greenPal%(4, 3) = 0
	greenPal%(5, 1) = 1: greenPal%(5, 2) = 3: greenPal%(5, 3) = 1
	greenPal%(6, 1) = 0: greenPal%(6, 2) = 3: greenPal%(6, 3) = 1
	greenPal%(7, 1) = 2: greenPal%(7, 2) = 3: greenPal%(7, 3) = 0
	greenPal%(8, 1) = 2: greenPal%(8, 2) = 3: greenPal%(8, 3) = 1
	greenPal%(9, 1) = 2: greenPal%(9, 2) = 3: greenPal%(9, 3) = 2

	' Blues
	bluePal%(1, 1) = 0: bluePal%(1, 2) = 0: bluePal%(1, 3) = 1
	bluePal%(2, 1) = 0: bluePal%(2, 2) = 0: bluePal%(2, 3) = 2
	bluePal%(3, 1) = 0: bluePal%(3, 2) = 1: bluePal%(3, 3) = 2
	bluePal%(4, 1) = 0: bluePal%(4, 2) = 0: bluePal%(4, 3) = 3
	bluePal%(5, 1) = 0: bluePal%(5, 2) = 1: bluePal%(5, 3) = 3
	bluePal%(6, 1) = 1: bluePal%(6, 2) = 0: bluePal%(6, 3) = 3
	bluePal%(7, 1) = 1: bluePal%(7, 2) = 1: bluePal%(7, 3) = 3
	bluePal%(8, 1) = 0: bluePal%(8, 2) = 2: bluePal%(8, 3) = 3
	bluePal%(9, 1) = 1: bluePal%(9, 2) = 2: bluePal%(9, 3) = 3

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Draw a simple window on the screen with Proceed and Cancel buttons
	'  that explains what's about to happen.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF kolor% THEN
		ft1% = 6
		ft2% = 7
		bs% = STYLE3D
	ELSE
		ft1% = 6
		ft2% = 7
		bs% = STYLE3D
	END IF
	MakeWindow 5, 8, 23, 73, 0, 7, 0, ft1%, -1, 0, ""
	MakeWindow 6, 10, 22, 71, 0, 7, 0, ft2%, -1, 0, ""
	MakeWindow 7, 21, 9, 60, 0, 7, 0, ft1%, -1, 0, ""
	Center "EGA/VGA Extended Text Colors", 8
	DrawButton SINGLEBORDER, 12, 19, 25, 21, 0, 7, "See Colors", bs%
	DrawButton SINGLEBORDER, 27, 19, 40, 21, 0, 7, "Cancel", bs%
	LOCATE 11, 13, 0: PRINT "A new capability in version 1.7 of the QBSCR Screen";
	LOCATE 12, 13, 0: PRINT "Routines is the use of up to 16 of 64 total colors when";
	LOCATE 13, 13, 0: PRINT "using an EGA or VGA video card.  Since you have one, you";
	LOCATE 14, 13, 0: PRINT "will be able to see what we're talking about by clicking";
	LOCATE 15, 13, 0: PRINT "the See Colors button below (or hitting the S key).  If";
	LOCATE 16, 13, 0: PRINT "you really don't care or don't want to see, then click";
	LOCATE 17, 13, 0: PRINT "the Cancel button (or hit C or ESC).";

	done% = FALSE
	seeColors% = FALSE
	IF mouseExists% THEN
		MouseShow
	END IF
	WHILE done% = FALSE

		result% = getEvent%(mouseExists%, kc%, mx%, my%)

		SELECT CASE result%
			CASE EMpressedLeft
				IF (mx% >= 12) AND (mx% <= 25) AND (my% >= 19) AND (my% <= 21) THEN
					PressButton SINGLEBORDER, 12, 19, 25, 21, 0, 7, "See Colors", bs%
					done% = TRUE
					seeColors% = TRUE
				END IF
				IF (mx% >= 27) AND (mx% <= 40) AND (my% >= 19) AND (my% <= 21) THEN
					PressButton SINGLEBORDER, 27, 19, 40, 21, 0, 7, "Cancel", bs%
					done% = TRUE
				END IF
			CASE EMpressedRight
				done% = TRUE
			CASE EKpressed
				IF (kc% = ASC("S")) OR (kc% = ASC("s")) OR (kc% = 13) THEN
					done% = TRUE
					seeColors% = TRUE
				END IF
				IF (kc% = ASC("C")) OR (kc% = ASC("c")) OR (kc% = 27) THEN
					done% = TRUE
				END IF
			CASE ELSE
		END SELECT

	WEND

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  If user aborted the operation, then get out.  Otherwise, continue on.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF seeColors% = FALSE THEN
		EXIT SUB
	END IF

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Make the interface for the color viewing stuff (dang this is fun!)
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF mouseExists% THEN
		MouseHide
	END IF
	MakeWindow 3, 7, 23, 73, 0, 7, 0, ft1%, -1, 0, ""
	MakeWindow 17, 9, 22, 58, 0, 7, 0, ft2%, -1, 0, ""
	MakeWindow 4, 9, 16, 58, 0, 0, 0, 0, -1, 0, ""
	DrawButton SINGLEBORDER, 61, 4, 70, 6, 0, 7, "Reds", bs%
	DrawButton SINGLEBORDER, 61, 7, 70, 9, 0, 7, "Greens", bs%
	DrawButton SINGLEBORDER, 61, 10, 70, 12, 0, 7, "Blues", bs%
	DrawButton SINGLEBORDER, 61, 13, 70, 15, 0, 7, "Chaos", bs%
	DrawButton DOUBLEBORDER, 61, 19, 70, 21, 0, 7, "Done", bs%
	LOCATE 18, 11, 0: PRINT "Note that this demo shows only some of the 64";
	LOCATE 19, 11, 0: PRINT "possible colors.  Chaos shows random colors.";
	LOCATE 20, 11, 0: PRINT "Click buttons or hit the first letter to see";
	LOCATE 21, 11, 0: PRINT "the color sets named. Done exits to the menu.";

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Since we will be using colors above value 7, we need to set the Bright
	'  Background capability ON, by calling the QBSCR routine BlinkOff.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	BlinkOff

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	' Set the palette initially to the red set.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	SetPalette redPal%()

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Add in the text that will be viewed in the new nifty colors.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	LOCATE 5, 11, 0: COLOR 15, 0: PRINT "Color Display                   Color Values";
	LOCATE 6, 11, 0: PRINT STRING$(45, 196);
	LOCATE 7, 11, 0: COLOR 0, 1: PRINT " As Background ";
	COLOR 1, 0: PRINT " As Foreground";
	LOCATE 8, 11, 0: COLOR 0, 2: PRINT " As Background ";
	COLOR 2, 0: PRINT " As Foreground";
	LOCATE 9, 11, 0: COLOR 0, 3: PRINT " As Background ";
	COLOR 3, 0: PRINT " As Foreground";
	LOCATE 10, 11, 0: COLOR 0, 4: PRINT " As Background ";
	COLOR 4, 0: PRINT " As Foreground";
	LOCATE 11, 11, 0: COLOR 0, 5: PRINT " As Background ";
	COLOR 5, 0: PRINT " As Foreground";
	LOCATE 12, 11, 0: COLOR 0, 6: PRINT " As Background ";
	COLOR 6, 0: PRINT " As Foreground";
	LOCATE 13, 11, 0: COLOR 16, 0: PRINT " As Background ";
	COLOR 8, 0: PRINT " As Foreground";
	LOCATE 14, 11, 0: COLOR 16, 1: PRINT " As Background ";
	COLOR 9, 0: PRINT " As Foreground";
	LOCATE 15, 11, 0: COLOR 16, 2: PRINT " As Background ";
	COLOR 10, 0: PRINT " As Foreground";

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Now add in the informational stuff.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	ShowPaletteInfo redPal%()

	IF mouseExists% THEN
		MouseShow
	END IF
	done% = FALSE
	WHILE done% = FALSE

		result% = getEvent%(mouseExists%, kc%, mx%, my%)

		SELECT CASE result%
			CASE EMpressedLeft
			 
				' Reds
				IF (mx% >= 61) AND (mx% <= 70) AND (my% >= 4) AND (my% <= 6) THEN
					PressButton SINGLEBORDER, 61, 4, 70, 6, 0, 7, "Reds", bs%
					MouseHide
					SetPalette redPal%()
					ShowPaletteInfo redPal%()
					MouseShow
				END IF
				' Greens button
				IF (mx% >= 61) AND (mx% <= 70) AND (my% >= 7) AND (my% <= 9) THEN
					PressButton SINGLEBORDER, 61, 7, 70, 9, 0, 7, "Greens", bs%
					MouseHide
					SetPalette greenPal%()
					ShowPaletteInfo greenPal%()
					MouseShow
				END IF
				' Blues button
				IF (mx% >= 61) AND (mx% <= 70) AND (my% >= 10) AND (my% <= 12) THEN
					PressButton SINGLEBORDER, 61, 10, 70, 12, 0, 7, "Blues", bs%
					MouseHide
					SetPalette bluePal%()
					ShowPaletteInfo bluePal%()
					MouseShow
				END IF
				' Chaos button
				IF (mx% >= 61) AND (mx% <= 70) AND (my% >= 13) AND (my% <= 15) THEN
					PressButton SINGLEBORDER, 61, 13, 70, 15, 0, 7, "Chaos", bs%
					MouseHide
					SetChaosPalette chaosPal%()
					ShowPaletteInfo chaosPal%()
					MouseShow
				END IF
				' Done button
				IF (mx% >= 61) AND (mx% <= 70) AND (my% >= 19) AND (my% <= 21) THEN
					PressButton DOUBLEBORDER, 61, 19, 70, 21, 0, 7, "Done", bs%
					done% = TRUE
				END IF
			CASE EMpressedRight
				done% = TRUE
			CASE EKpressed
				IF (kc% = ASC("R")) OR (kc% = ASC("r")) THEN     ' Reds
					IF mouseExists% THEN MouseHide
					SetPalette redPal%()
					ShowPaletteInfo redPal%()
					IF mouseExists% THEN MouseShow
				END IF
				IF (kc% = ASC("G")) OR (kc% = ASC("g")) THEN     ' Greens
					IF mouseExists% THEN MouseHide
					SetPalette greenPal%()
					ShowPaletteInfo greenPal%()
					IF mouseExists% THEN MouseShow
				END IF
				IF (kc% = ASC("B")) OR (kc% = ASC("b")) THEN     ' Blues
					IF mouseExists% THEN MouseHide
					SetPalette bluePal%()
					ShowPaletteInfo bluePal%()
					IF mouseExists% THEN MouseShow
				END IF
				IF (kc% = ASC("C")) OR (kc% = ASC("c")) THEN     ' Blues
					IF mouseExists% THEN MouseHide
					SetChaosPalette chaosPal%()
					ShowPaletteInfo chaosPal%()
					IF mouseExists% THEN MouseShow
				END IF
				IF (kc% = ASC("D")) OR (kc% = ASC("d")) OR (kc% = 27) THEN  ' Done
					done% = TRUE
				END IF
			CASE ELSE
		END SELECT

	WEND

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Last but not least, we clean up.  Hide the mouse first of all.  The
	'  Clear out the window with the colors in it.  If we don't do this, then
	'  the text tere will revert to normal colors when we reset the palette.
	'  This isn't bad, but doesn't look "clean."  Then reset the palette to
	'  normal defaults by calling the PALETTE statement with no parameters.
	'  Last, call BlinkOn to restore blinking attributes.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF mouseExists% THEN
		MouseHide
	END IF
	Wipe 4, 16, 9, 58, 0
	PALETTE
	BlinkOn
 
END SUB

SUB GetForeBack

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  This routine will demonstrate the GetForeground and GetBackground
	'  routines from the QBSCR Screen Routines.  It uses PutScreen as well
	'  to display a premade picture.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Load and display the correct image, but only if the file exists.  If
	'  the image file is missing, then display an error message and get out.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF mouseExists% THEN
		MouseHide
	END IF
	IF kolor% THEN
		ft% = 6: ft2% = 7
		bs% = STYLE3D
		IF FirstFile%("QDEMO_1.CLR", NormalAttr, dta$) THEN
			PutScreen "QDEMO_1.CLR"
		ELSE
			InfoBox QDEMO1CLRMISSING
			EXIT SUB
		END IF
	ELSE
		ft% = 0: ft2% = 0
		bs% = STYLE2D
		IF FirstFile%("QDEMO_1.MON", NormalAttr, dta$) THEN
			PutScreen "QDEMO_1.MON"
		ELSE
			InfoBox QDEMO1MONMISSING
			EXIT SUB
		END IF
	END IF

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Add a window to the bottom part of the screen and add all interface
	'  bits to it.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	COLOR 0, 7
	FOR i% = 16 TO 25
		LOCATE i%, 1, 0: PRINT SPACE$(80);
	NEXT i%
	MakeWindow 16, 2, 25, 79, 0, 7, 0, ft2%, -1, 0, ""
	MakeWindow 17, 16, 19, 65, 0, 7, 0, ft%, -1, 0, ""
	DrawButton SINGLEBORDER, 4, 22, 13, 24, 0, 7, "Done", bs%

	LOCATE 21, 17, 0: PRINT "Use the arrow keys or the mouse to move the small box above";
	LOCATE 22, 17, 0: PRINT "around the screen.  The foreground and background colors of";
	LOCATE 23, 17, 0: PRINT "of the character in the box will be displayed.";

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Now initialize a few variables we will be using to keep track of
	'  things for us.  Get the current mouse position and set out starting
	'  point there.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	DIM sc%(18)
	IF mouseExists% THEN
		MousePosition curX%, curY%
		curX% = (curX% \ 8) + 1
		curY% = (curY% \ 8) + 1
	ELSE
		curX% = 39: curY% = 9
	END IF
	oldX% = curX%: oldY% = curY%
 
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Find out the forground and background colors in the initial box
	'  position, and display them in the interface box below the picture.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	curFG% = GetForeground%(curY% + 1, curX% + 1)
	curBG% = GetBackground%(curY% + 1, curX% + 1)
	txt$ = "Foreground:" + STR$(curFG%) + "  Background:" + STR$(curBG%)
	COLOR 0, 7
	Center txt$, 18

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Since the mouse represents the upper-left corner of the pointer box,
	'  we must ensure that it is not moved passed column 78, or part of the
	'  box will disappear off the right edge of the screen.  Rather than check
	'  the mouse position every time the mouse is moved, we'll let the QBSCR
	'  mouse routine called MouseSetMinMaxX do it for us.  It prevents the
	'  mouse from being moved farther than we want it to.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF mouseExists% THEN
		MouseSetMinMaxX 1, 77 * 8
	END IF

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Save the screen underneath the small box that will be drawn at the
	'  curX%, curY% location.  Then draw the box.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	okToRestore% = FALSE
	IF (curY% < 14) THEN
		BlockSave curX%, curX% + 2, curY%, curY% + 2, sc%(), GetVideoSegment!
		DrawBoxPointer curX%, curY%
		okToRestore% = TRUE
	ELSE
		MouseShow
	END IF

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Now that everything is set up, we sit in a loop waiting on events.
	'  If the mouse is moved or the arrow keys are pressed, we must move the
	'  box around.  There is an added complication, though.  If the mouse is
	'  moved below the picture into the interface box, the mouse cursor must
	'  be redisplayed and we are in regular mouse mode.  If moved back into
	'  the picture, we are then moving the box around again.  You'll see...
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	done% = FALSE
	WHILE done% = FALSE

		result% = getEvent%(mouseExists%, kc%, mx%, my%)
			
		SELECT CASE result%
			CASE EMmoved
			 
				' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
				'  If mouse WAS in picture, and NOW is in interface box, turn mouse
				'  back on.
				' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
				IF (my% > 14) THEN
					IF okToRestore% THEN
						BlockRestore oldX%, oldX% + 2, oldY%, oldY% + 2, sc%(), GetVideoSegment!
					END IF
					MouseShow
				END IF

				' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
				'  If mouse is in picture, and was last time, simply update the box
				'  and its associated information.
				' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
				IF (my% <= 14) THEN
					curX% = mx%
					curY% = my%
					'okToRestore% = TRUE
					update% = TRUE
				END IF

			CASE EMpressedLeft

				' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
				'  If the left mouse button was pressed, then see if it was on the
				'  Done button.  If so, then press the button and exit.
				' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
				IF (mx% >= 4) AND (mx% <= 13) AND (my% >= 22) AND (my% <= 24) THEN
					PressButton SINGLEBORDER, 4, 22, 13, 24, 0, 7, "Done", bs%
					done% = TRUE
				END IF

			CASE EMpressedRight
				done% = TRUE

			CASE EKpressed

				IF curY% > 14 THEN
					curY% = 14
				END IF

				SELECT CASE kc%
					CASE LEFTARROW
						IF curX% > 1 THEN
							curX% = curX% - 1
						ELSE
							curX% = 78
						END IF
						update% = TRUE
					CASE RIGHTARROW
						IF curX% < 78 THEN
							curX% = curX% + 1
						ELSE
							curX% = 1
						END IF
						update% = TRUE
					CASE UPARROW
						IF curY% > 1 AND curY% < 15 THEN
							curY% = curY% - 1
						ELSE
							curY% = 14
						END IF
						update% = TRUE
					CASE DOWNARROW
						IF curY% < 14 THEN
							curY% = curY% + 1
						ELSE
							curY% = 1
						END IF
						update% = TRUE
					CASE 27, ASC("D"), ASC("d")
						done% = TRUE
					CASE ELSE
				END SELECT
			CASE ELSE

		END SELECT

		IF update% THEN
			MouseHide
			update% = FALSE
			IF okToRestore% THEN
				BlockRestore oldX%, oldX% + 2, oldY%, oldY% + 2, sc%(), GetVideoSegment!
			END IF
			okToRestore% = TRUE
			BlockSave curX%, curX% + 2, curY%, curY% + 2, sc%(), GetVideoSegment!
			DrawBoxPointer curX%, curY%
			oldX% = curX%
			oldY% = curY%
			curFG% = GetForeground%(curY% + 1, curX% + 1)
			curBG% = GetBackground%(curY% + 1, curX% + 1)
			txt$ = "Foreground:" + STR$(curFG%) + "  Background:" + STR$(curBG%)
			COLOR 0, 7
			Center SPACE$(40), 18
			Center txt$, 18
		END IF

	WEND

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Lastly, since we restricted the mouse's movement earlier, we must un-
	'  restrict it before we leave.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	IF mouseExists% THEN
		MouseSetMinMaxX 1, 79 * 8
	END IF

END SUB

SUB SetChaosPalette (pal%())

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  This routine sets a random palette of 9 colors.  Used only by the
	'  EgaVgaColors demo routine.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Set nine random colors.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	RANDOMIZE TIMER

	pal%(1, 1) = (INT(RND(1) * 4)): pal%(1, 2) = (INT(RND(1) * 4)): pal%(1, 3) = (INT(RND(1) * 4))
	pal%(2, 1) = (INT(RND(1) * 4)): pal%(2, 2) = (INT(RND(1) * 4)): pal%(2, 3) = (INT(RND(1) * 4))
	pal%(3, 1) = (INT(RND(1) * 4)): pal%(3, 2) = (INT(RND(1) * 4)): pal%(3, 3) = (INT(RND(1) * 4))
	pal%(4, 1) = (INT(RND(1) * 4)): pal%(4, 2) = (INT(RND(1) * 4)): pal%(4, 3) = (INT(RND(1) * 4))
	pal%(5, 1) = (INT(RND(1) * 4)): pal%(5, 2) = (INT(RND(1) * 4)): pal%(5, 3) = (INT(RND(1) * 4))
	pal%(6, 1) = (INT(RND(1) * 4)): pal%(6, 2) = (INT(RND(1) * 4)): pal%(6, 3) = (INT(RND(1) * 4))
	pal%(7, 1) = (INT(RND(1) * 4)): pal%(7, 2) = (INT(RND(1) * 4)): pal%(7, 3) = (INT(RND(1) * 4))
	pal%(8, 1) = (INT(RND(1) * 4)): pal%(8, 2) = (INT(RND(1) * 4)): pal%(8, 3) = (INT(RND(1) * 4))
	pal%(9, 1) = (INT(RND(1) * 4)): pal%(9, 2) = (INT(RND(1) * 4)): pal%(9, 3) = (INT(RND(1) * 4))

	PALETTE 1, rgbRGB%(pal%(1, 1), pal%(1, 2), pal%(1, 3))
	PALETTE 2, rgbRGB%(pal%(2, 1), pal%(2, 2), pal%(2, 3))
	PALETTE 3, rgbRGB%(pal%(3, 1), pal%(3, 2), pal%(3, 3))
	PALETTE 4, rgbRGB%(pal%(4, 1), pal%(4, 2), pal%(4, 3))
	PALETTE 5, rgbRGB%(pal%(5, 1), pal%(5, 2), pal%(5, 3))
	PALETTE 6, rgbRGB%(pal%(6, 1), pal%(6, 2), pal%(6, 3))
	PALETTE 8, rgbRGB%(pal%(7, 1), pal%(7, 2), pal%(7, 3))
	PALETTE 9, rgbRGB%(pal%(8, 1), pal%(8, 2), pal%(8, 3))
	PALETTE 10, rgbRGB%(pal%(9, 1), pal%(9, 2), pal%(9, 3))
 
END SUB

SUB SetPalette (pal%())

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  This routine is used by the EgaVgaColors demo routine.  It sets some
	'  of the palette to the attributes passed in the pal%() array.  Note
	'  that the array is assumed to be a 2D 9x3 array, like DIM pal%(9, 3).
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Set palette attributes.  Note that attribute 7 is skipped, since we
	'  use that color (light grey) extensively in the interface.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	PALETTE 1, rgbRGB%(pal%(1, 1), pal%(1, 2), pal%(1, 3))
	PALETTE 2, rgbRGB%(pal%(2, 1), pal%(2, 2), pal%(2, 3))
	PALETTE 3, rgbRGB%(pal%(3, 1), pal%(3, 2), pal%(3, 3))
	PALETTE 4, rgbRGB%(pal%(4, 1), pal%(4, 2), pal%(4, 3))
	PALETTE 5, rgbRGB%(pal%(5, 1), pal%(5, 2), pal%(5, 3))
	PALETTE 6, rgbRGB%(pal%(6, 1), pal%(6, 2), pal%(6, 3))
	PALETTE 8, rgbRGB%(pal%(7, 1), pal%(7, 2), pal%(7, 3))
	PALETTE 9, rgbRGB%(pal%(8, 1), pal%(8, 2), pal%(8, 3))
	PALETTE 10, rgbRGB%(pal%(9, 1), pal%(9, 2), pal%(9, 3))

END SUB

SUB ShowPaletteInfo (pal%())

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  This routine displays data in the array passed-in, assumed to by a 2D
	'  9x3 array, as in DIM pal%(9, 3).  Used only by the EgaVgaColors demo.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ

	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	'  Show palette data in color 7 at a fixed display location.
	' ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
	COLOR 7, 0
	FOR i% = 1 TO 9
		LOCATE i% + 6, 43, 0: PRINT "R="; LTRIM$(STR$(pal%(i%, 1)));
		PRINT "  G="; LTRIM$(STR$(pal%(i%, 2)));
		PRINT "  B="; LTRIM$(STR$(pal%(i%, 3)));
	NEXT i%

END SUB

