Page 1 of 2

VGA palette

Posted: Mon Mar 07, 2005 7:36 am
by bubach
I recently wrote some code to change VGA modes without BIOS use, and I am having some trubble with the setting of the palette.
When I switch to mode 0x13 everything works ok (with the palette), but when I switch back to textmode it seems like only the first 8 colors can be changed.
The last 8 colors is still the same as it was in mode 0x13...
Any ideas of what might be wrong?

Code used:

Code: Select all

;--------------------------------------;
;  sets the palette for any mode.      ;
;  input:  si  =  pointer to palette.  ;
;          cx  =  number of colors.    ;
;  output: none.                       ;
;--------------------------------------;
set_palette:
     push     ax
     push     bx

     mov     ax, 0
     .l1:
     mov     ah, byte [esi]
     inc     si
     mov     bl, byte [esi]
     inc     si
     mov     bh, byte [esi]
     inc     si
     call     set_pal
     inc     al
     loop     .l1

     pop     bx
     pop     ax
     ret



;---------------------------------------------;
;  sets the palette color no. to rgb value.   ;
;                                             ;
; input:  al = color no.                      ;
;         ah = red                            ;
;         bl = green                          ;
;         bh = blue                           ;
;                                             ;
; output: none.                               ;
;---------------------------------------------;
set_pal:
     push     ax
     push     dx

     mov     dx, 0x03C8
     out     dx, al               ; the color no. is in al

     inc     dx                  ; port 0x03C9

     mov     al, ah               ; red i ah
     out     dx, al

     mov     al, bl               ; green in bl
     out     dx, al

     mov     al, bh               ; blue in bh
     out     dx, al

     pop     dx
     pop     ax
     ret
------------------------------------
     palette16     db   00, 00, 00, 00, 00, 42, 00, 42, 00, 00, 42, 42, 42
           db   00, 00, 42, 00, 42, 42, 21, 00, 42, 42, 42, 21, 21
           db   21, 21, 21, 63, 21, 63, 21, 21, 63, 63, 63, 21, 21
           db   63, 21, 63, 63, 63, 21, 63, 63, 63

Re:VGA palette

Posted: Mon Mar 07, 2005 7:37 am
by bubach
And the 256 palette (can't see why you would need it, but.. ):

Code: Select all

     palette256     db   00, 00, 00, 00, 10, 41, 12, 28, 18, 02, 43, 22, 35
           db   19, 09, 58, 00, 00, 57, 35, 12, 43, 43, 47, 24, 24
           db   28, 20, 24, 60, 10, 60, 15, 31, 47, 63, 62, 56, 20

... more and more rows of palette data ...     

           db   00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
           db   00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
           db   00
EDIT: evil pype.bot deleted my beautiful palette.. :'( ;)

Re:VGA palette

Posted: Mon Mar 07, 2005 9:08 am
by SANiK
I have had the same problem and never got it solved. (This is why I gave up on ASCII art =P)

I also find it funny how mine worked in Bochs but not on a real PC.

*keeps an eye on this post*

Re:VGA palette

Posted: Mon Mar 07, 2005 11:07 am
by bubach
Atleast my code shows the same on both Bochs and real computers.. :P
Any ideas from the rest of you?

[EDIT] I'll try to save the old palette and see if I atleast can restore that... Will be back with results...

Re:VGA palette

Posted: Tue Mar 08, 2005 3:16 am
by Pype.Clicker
just a random thought ... did you made sure you were in a *VGA* textmode ? if not, that could explain why it doesn't work better.

Re:VGA palette

Posted: Tue Mar 08, 2005 7:01 am
by bubach
Yeah... I set mode 0x03 via registers, reload the font (which by the way also looks a bit wierd) and try to set the new 16 color palette. On the last 8 colors I get some variations of red/brown...
I tried the code but without touching the palette, and then everything works..

Re:VGA palette

Posted: Tue Mar 08, 2005 9:21 am
by Pype.Clicker
i suggest a look at http://www.osdever.net/FreeVGA/vga/attrreg.htm#10 . The 'blink' bit (among other things) may explain troubles you're experiencing ...

btw, do you only have trouble with colors used as background or can't you change the color of WHITE text, for instance ?

Re:VGA palette

Posted: Tue Mar 08, 2005 10:52 am
by bubach
Thanks, I've seen that side. ;)
I haven't tried changing the backgrounds yet, it's the char colors I am having trubble with.

/ Christoffer

Re:VGA palette

Posted: Wed Mar 09, 2005 3:19 am
by Pype.Clicker
digging out from old palette code in outmup game

Code: Select all

PaletteRVB PROC FAR
;================================
;= Cette routine permet d'?crire=
;= des valeurs dans la palette  =
;= de couleurs                  =
;= Param?tres: AL=couleur       =
;=             BH=rouge         =
;=             BL=vert          =
;=             CH=bleu          =
;================================
      PUSH DX
      PUSH AX
      MOV DX,3C6h
      MOV AL,0FFh
      OUT DX,AL
      POP AX
      PUSH AX
      MOV DX,3C8h
      OUT DX,AL
      MOV DX,3C9h
      MOV AL,BH
      OUT DX,AL
      MOV AL,BL
      OUT DX,AL
      MOV AL,CH
      OUT DX,AL
      POP AX
      POP DX
      RETF
PaletteRVB ENDP
as i was reminding, i had another register used, the "PEL mask" register which i used to set to 255. They don't seem to talk about it in "FreeVGA", though ... http://www.inversereality.org/files/palettesetting.pdf confirms this, but i still don't find what it actually contains. it looks like noone actually knows and bochs will complain if you load it with something else than 255.

Considering

Code: Select all

+/* attribute controller registers */
+static const u_int8_t vga_atc[] = {
+   0x00,   /* 00: internal pallet  0 */
+   0x01,   /* 01: internal pallet  1 */
+   0x02,   /* 02: internal pallet  2 */
+   0x03,   /* 03: internal pallet  3 */
+   0x04,   /* 04: internal pallet  4 */
+   0x05,   /* 05: internal pallet  5 */
+   0x14,   /* 06: internal pallet  6 */
+   0x07,   /* 07: internal pallet  7 */
+   0x38,   /* 08: internal pallet  8 */
+   0x39,   /* 09: internal pallet  9 */
+   0x3a,   /* 0A: internal pallet 10 */
+   0x3b,   /* 0B: internal pallet 11 */
+   0x3c,   /* 0C: internal pallet 12 */
+   0x3d,   /* 0D: internal pallet 13 */
+   0x3e,   /* 0E: internal pallet 14 */
+   0x3f,   /* 0F: internal pallet 15 */
+   0x08,   /* 10: attribute mode control */
+   0x00,   /* 11: overscan color */
+   0x0f,   /* 12: color plane enable */
+   0x08,   /* 13: horizontal PEL panning */
+   0x00   /* 14: color select */
+};
(from http://mail-index.netbsd.org/port-arc/2 ... /0000.html), i would also try to alter colors 0x38 .. 0x3f just to check what it does. Actually, there are still weird things about VGA colors in text mode, including the fact that the overscan color (usually black) can be picked among 64 pre-defined colors ...

Re:VGA palette

Posted: Wed Mar 09, 2005 5:43 am
by Candy
I think the 0xFF comes from setting the DAC to 8-bit mode. I assume that 0x3F puts it in default 6-bit mode and that others are invalid. I never used 0x3c6 so I always used 3*6-bit colors.

Re:VGA palette

Posted: Wed Mar 09, 2005 5:55 am
by bubach
So basicly it should work ok if I add:

Code: Select all

          mov     al, 0xFF
          out     0x3C6, al
Strange, I have never seen that before.. Maybe becasue BIOS have done that for me at mode 0x13 exit..?
Thanks alot for your help. VGA sure is tricky.. The font I use for the modesetting is AFAIK the standard BIOS font for 80x25, but for me it looks a bit wierd on real computers (bochs displays it nicly).
Also on the first row I get "double" cursors, one line at the char space top and one on the bottom as normal (like =).. ;D

Re:VGA palette

Posted: Wed Mar 09, 2005 6:45 am
by Pype.Clicker
that might come from a value of "start cursor row" and "end cursor row" larger than the actual number of rows per character ...

Re:VGA palette

Posted: Wed Mar 09, 2005 7:04 am
by bubach
Hmm.. But my values for mode 0x03 is the same as every other version you might find on the net (tauron vga lib etc).

Re:VGA palette

Posted: Wed Mar 09, 2005 10:40 pm
by Chris Giese
In 16-color modes (including text mode), the color index into the 256-color palette goes through the attribute controller (AC). Your code has to take that into account.

Maybe your code works differently under Bochs and on a real PC because the two video BIOSes program the AC differently.

This little code snippet might help:
http://www.google.ca/groups?as_q=&[email protected]

Re:VGA palette

Posted: Thu Mar 10, 2005 2:02 pm
by bubach
Well,

Code: Select all

          mov    al, 0xFF
          out    0x3C6, al
didn't make any diffrens.
Chris: I'll check that out, thanks.