VGA palette

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:VGA palette

Post by bubach »

Thanks Chris!
Worked fine... :)
From the C code you had in that link I was able to put this together:

Code: Select all

;---------------------------------------------;
;  sets the palette (256 colors)              ;
;                                             ;
; input:  esi = palette.                      ;
; output: none.                               ;
;---------------------------------------------;
set_palette256:
     push     ax
     push     cx
     push     dx

     xor     cx, cx
     .l1:
     mov     dx, 0x03C8
     mov     al, cl               ; color no. = loop no.
     out     dx, al
     inc     dx                  ; port 0x3C9
     mov     al, byte [esi]            ; red
     out     dx, al
     inc     esi
     mov     al, byte [esi]            ; green
     out     dx, al
     inc     esi
     mov     al, byte [esi]            ; blue
     out     dx, al
     inc     esi

     inc     cx
     cmp     cx, 256
     jl     .l1

     pop     dx
     pop     cx
     pop     ax
     ret


;---------------------------------------------;
;  sets the palette (16 colors)               ;
;                                             ;
; input:  esi = pointer to palette.           ;
; output: none.                               ;
;---------------------------------------------;
set_palette16:
     push     ax
     push     cx
     push     dx

     xor     cx, cx
     .l1:
     mov     dx, 0x3DA
     in     al, dx
     mov     al, cl               ; color no.
     mov     dx, 0x3C0
     out     dx, al
     inc     dx                  ; port 0x3C1
     in     al, dx
     mov     dx, 0x3C8
     out     dx, al

     inc     dx                  ; port 0x3C9
     mov     al, byte [esi]            ; red
     out     dx, al
     inc     esi
     mov     al, byte [esi]            ; green
     out     dx, al
     inc     esi
     mov     al, byte [esi]            ; blue
     out     dx, al
     inc     esi

     inc     cx
     cmp     cx, 16
     jl     .l1

     mov     dx, 0x3DA
     in     al, dx
     mov     al, 0x20
     mov     dx, 0x3C0
     out     dx, al

     pop     dx
     pop     cx
     pop     ax
     ret
May help someone (SANiK)?
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
Post Reply