assemblyx86bmpvga

ASM: What does port 3c8h & 3c9h do?


I'm trying to create ASM code which will load and print an 256 color BMP file.
I saw several codes that do this job, and they first load 0 to port 3c8h, and then load the palette to port 3c9h.
What does the load to those ports do?
Thanks in addition! :)


Solution

  • I remember using those ports to set up VGA color palette. You out the color number on 3c8 and R, G, B values on 3c9 consecutively, IIRC:

    mov al, 1    ; set color index 0's rgb value
    mov dx, 3c8h
    out dx, al
    inc dx       ; now 3c9h
    mov al, 11h
    out dx, al   ; set R = 11h
    mov al, 22h
    out dx, al   ; set G = 22h
    mov al, 33h
    out dx, al   ; set B = 33h
    

    so whenever VGA hardware encounters the value "1" in video memory it would emit a pixel with an RGB value of #112233.

    Because the color index register is automatically incremented by VGA chip, you could also make use of OUTS instructions. to change the whole palette of the VGA card according to a memory block, you could simply do a:

    xor al, al      ; zero al register
    mov dx, 3c8h
    out dx, al      ; start with color zero
    inc dx          ; dx = 3c9h
    lds si, palette ; ds:si points to color palette data
    mov cx, 300h    ; 3 bytes rgb x 256 colors
    rep outsb