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! :)
ASM: What does port 3c8h & 3c9h do?
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
© 2022 - 2024 — McMap. All rights reserved.
0x03c9
will make it automatically to advance, so you don't need to output the index of colour to0x03c8
ahead of each one. Unfortunately you never know what is the current state, that's why it starts by outputting at least the0
index. ("unfortunately" if you are working on 256B intro for DOS, where saving that oneout
of index would help a lot, but it will start from0
colour only on some PCs+DOS combinations). – Deformity