OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 3:28 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Problem with VGA 16 palette
PostPosted: Mon Mar 18, 2002 6:03 am 
I have a strange problem with the VGA palette
When i want to change the color , not all the new values are accepted. This is a sample code to reproduce the problem. The color pointed by the arrow should be white. You can use nasm to assemble the progam. The problem comes with vmware, bochs and real boot. This code is a part of my loader.
Note : i use direct setting of vga register , but when i use INT the problem comes to.

Code:
; ***********************************************************************
; ***********************************************************************

; definition
%define            _b       byte
%define            _w       word
%define            _d      dword


; ***********************

; *************************************************************************


           mov      ax, cs            ;
           mov      ds, ax            ;
           mov      es, ax            ;
           mov     ax, 0x0000      ;
               mov     ss, ax
               mov     sp, 0xFFFF
               
           ; VGA mode 640*480 16 colors
           mov      al, 0x12      ;
           mov      ah, 00            ;
           int       10h

           
           call      synch
           

           ;******************************
           ; Palette  colors
           ;mask
           mov      dx, 3c6h
           mov      al, 0ffh
           out       dx, al

           
           ; index 0
           mov      dx, 3c8h
           mov      al, 00
           out       dx, al
           mov      dx, 3c9h
           
           ;0
           mov      al, 00
           out       dx, al
           mov      al, 00
           out      dx, al
           mov      al, 00
           out      dx, al
           
           ;1
           mov      al, 35
           out       dx, al
           mov      al, 05
           out      dx, al
           mov      al, 07
           out      dx, al
           
           ;2
           mov      al, 21
           out       dx, al
           mov      al, 03
           out      dx, al
           mov      al, 04
           out      dx, al
           
           ;3
           mov      al, 37
           out       dx, al
           mov      al, 21
           out      dx, al
           mov      al, 23
           out      dx, al
           
           ;4
           mov      al, 01
           out       dx, al
           mov      al, 04
           out      dx, al
           mov      al, 05
           out      dx, al
           
           ;5
           mov      al, 63
           out       dx, al
           mov      al, 63
           out      dx, al
           mov      al, 63
           out      dx, al
           
           
           ;6
           mov      al, 63
           out       dx, al
           mov      al, 63
           out      dx, al
           mov      al, 63
           out      dx, al
           
           ;7
           mov      al, 00
           out       dx, al
           mov      al, 00
           out      dx, al
           mov      al, 63
           out      dx, al
           
           ;8
           mov      al, 63
           out       dx, al
           mov      al, 63
           out      dx, al
           mov      al, 63
           out      dx, al
           
           ;9
           mov      al, 63
           out       dx, al
           mov      al, 63
           out      dx, al
           mov      al, 63
           out      dx, al
           
; draw the bar            
           
           xor      bx, bx
           mov      cx, 15
           mov      _b [colindex], 00
draw:            inc      bx
           add      _b [colindex], 1
           call      drawbar
           loop      draw

; drow arrow
           mov      cl, 10
           mov      ax, 308      
           mov      bx, 326
           call      setpix            
           inc      bx
           call      setpix            
           inc      bx
           call      setpix            
           inc      bx
           call      setpix            
           inc      bx
           call      setpix            
           inc      bx
           call      setpix
           mov      bx, 327
           mov      ax, 307
           call      setpix
           add      ax, 2
           call      setpix            
           mov      bx, 328
           mov      ax, 306
           call      setpix
           add      ax, 4
           call      setpix            
           
           


                                   
end:            
;                  
; end of program      
           xor     ah, ah
           int     16h             ; wait user hit keyboard
           mov      al, 0x02      ; restore video mode
           mov      ah, 00            ;
           int       10h
           
           mov      ax, 4c00h      ;end of program
           int       21h      
; *************************************************************************

; ***********************
; * FONCTIONS            *
; *************************************************************************
;*************************************
;* drawBar
;* Dessine 8 de pixel dans la barre
;* de progression
;* BX : position
;* cl : color
;*************************************
drawbar:
           pusha
           mov      ax, 10
           mul      bx
           
           mov      cx, 10
           add      ax, 241
trace:             mov      bx, 321
           push      cx
           mov      cl, [colindex]
           call      setpix
           inc      bx
           call      setpix
           inc      bx
           call       setpix
           inc      bx
           call       setpix
           inc      bx
           call       setpix
           pop      cx
           inc      ax
           loop      trace
                 
           

           popa
           ret




;*************************************
;* synch
;* vertical synch
;*************************************
synch:      
           pusha
           mov      dx, 0x03da      
S1:
           in      al, dx
           test      al, 08
           jz      S1
S2:
           in      al, dx
           test      al, 08
           jnz      S2
           popa
           ret
;*************************************




;*************************************
;* setpix
;* ax : x
;* bx : y
;* cl : color
;*************************************
setpix :
     pusha
     ;push      ds
     ;calcul de la position
     push      cx
     push       bx
     push      ax
     mov      ax, 0A000h
     mov      es, ax
     ;xor       eax, eax      ;
     pop      ax            ;
     
     mov      bx, ax
     shr       ax, 3
     and      bx, 00000111b
     pop      cx            ;
     push      ax            ;
     push      bx            ;
     ;pop      bx            ;                   
     mov      ax, 80
     mul      cx
     pop      cx            ;
     pop      bx            ;
     add      bx, ax            ;
     mov      ax, 1000000010000000b
     shr      ax, cl
     ;mov      cl, 01
     mov      cl, al
     mov      al, [es:bx]      ;
     mov       dx, 3ceh
     mov      ax, 0205h
     out      dx, ax
     mov      ax, 0003h
     out      dx, ax
     
     mov      ah, cl
     ;mov      ah, 01
     mov      al, 08
     out      dx, ax
     pop      cx
     mov      [es:bx], cl
     
     
     
     ;pop      ds      
     popa
     ret
;*************************************



; ***********************
; * DATA            *
; *************************************************************************

colindex:
     db      00



Ps : sorry for my bad english , i'm french


Top
  
 
 Post subject: Re: Problem with VGA 16 palette
PostPosted: Mon Mar 18, 2002 8:29 pm 
set the 16-color palette, too

(I did not test this code)

     mov dx,3C0h
     mov cx,16
     mov al,0
foo:
     out dx,al
     inc dx
     out dx,al
     dec dx
     inc al
     loop foo

     mov al,20h ; lock palette; turn on display
     out dx,al


Top
  
 
 Post subject: Re: Problem with VGA 16 palette
PostPosted: Tue Mar 19, 2002 2:40 am 
Thanks !
Your answer drived me on the right way.
It was the 16-color palette index, but your code is wrong (nearly right in fact). Here the corect code
Code:
           mov       dx,3C0h      ; init
           mov       cx,16
           mov       al,0
foo:
           out       dx,al
           out       dx,al
           inc       al
           loop       foo

             mov       al,20h        ; lock palette; turn on display  
             out       dx,al


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: SemrushBot [Bot] and 153 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group