Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using blue colour palette in VGA, with QBasic
#1
Hello everyone

I've always been able to use the green and red colour palettes, but whenever I try that for the blue colour, an error message appears. It's been years since I last tried it, but I think the message was "Invalid Function Parameter", but in portugueseSmile. I think it has to do with the number being too big for the function, but I used the procedure described in tutorials, something like: "Green + Red * 64 + Blue * 128" (again, this is from memory so it may not be entirely correct). Is it because I'm using the Interpreter, and it only works with the Compiler (technically making it a bug), or am I doing something wrong? Could you give a very brief code snippet that works? Sorry if this is discussed in tutorials or faqs that I haven't looked into. Thanks.

(I've read the palette tutorial on the site, but it doesn't work for me, since I usually avoid direct port calls and assembly statements).
Reply
#2
Here you go dude:

Code:
'' QB palette shifting example
'' cha0s Jun '06
'' save as QBRGB.BAS
'' ----------------------------


DECLARE FUNCTION QBRGB& (r AS INTEGER, b AS INTEGER, g AS INTEGER)
DEFINT A-Z

CONST colorCurrent = 4 '' random palette location to modify.

SCREEN 13


'' Display 50, 50, 50
PALETTE colorCurrent, QBRGB&(50, 50, 50)
PAINT (0, 0), colorCurrent
LOCATE 1: PRINT "light-gray"
WHILE LEN(INKEY$) = 0: WEND


'' Display 10, 35, 50
PALETTE colorCurrent, QBRGB&(10, 45, 50)
PAINT (0, 0), colorCurrent
LOCATE 1: PRINT "blue and greenish"
WHILE LEN(INKEY$) = 0: WEND


'' Display 50, 35, 8
PALETTE colorCurrent, QBRGB&(50, 35, 8)
PAINT (0, 0), colorCurrent
LOCATE 1: PRINT "orange"
WHILE LEN(INKEY$) = 0: WEND

FUNCTION QBRGB& (r AS INTEGER, g AS INTEGER, b AS INTEGER)

  QBRGB& = 65536 * b + 256 * g + r

END FUNCTION

RGB is implemented in FB as a macro, which means it's lots faster than using a function to shift the values, like in the QB version. You can calculate the rgb value inline of course, but that gets messy. ;p
Reply
#3
I'll try that Chaos, thanks.
Reply
#4
This is generally faster (in most computers):

Code:
SUB SetDAC (Index%, r%, g%, b%)
   OUT &H3c8, Index%
   OUT &H3c9, r%
   OUT &H3c9, g%
   OUT &H3c9, b%
END SUB
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#5
In QBasic 1.1 , the PALETTE command doesn't appear to accept extended integers. Could someone try it, using the blue colour, and corroborate this?

I still haven't tried the code snippet (QBasic is installed in my 486, not my net machine), but I can predict that it won't work, because the PALETTE command won't work itself, unless you use only the green and red colours. Thanks Nathan, but I won't do port output, my 486 is way too valuable for me to do that, no safety-net there if I do a typing mistake.
Reply
#6
OK, let me correct myself, the code snippet does work with QBasic 1.1. I've never been able to do it because, for some reason, QBasic doesn't think 256*256 is the same thing as 65536. Go figure.
Reply
#7
Keep in mind that the pallete command performs error checking on the supplied RGB values to ensure that they are in the range of 0 to 63, not 0 to 255. Consequently not every 24 bit value (3 eight bit fields) is a legal parameter.

This is done because the VGA DAC only provided six bits for the RGB values.
Reply
#8
Man, you won't break your computer OUTing to the VGA BIOS I/O ports. Every program you use on it does it for everything.

Try this:

Code:
a& = 256*256
PRINT a&

Always use the correct data type.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)