Home > Software engineering >  Initializing color palette assembly
Initializing color palette assembly

Time:03-14

Is there a way I can restore the standard color palette(256) after changing it's values using port 3C8h? Here is how I changed it.

proc copyPal
    mov si, offset palette
    mov cx, 256
    mov dx, 3C8h
    mov al, 0
    out dx, al
    inc dx
    palLoop:
    mov al, [si 2]
    shr al, 2
    out dx, al
    mov al, [si 1]
    shr al, 2
    out dx, al
    mov al, [si]
    out dx, al
    add si, 4
    loop palLoop
    ret
endp copyPal

CodePudding user response:

You can read the 256 color registers in a similar way. Just use the PEL Address Read Mode Register at 03C7h.
Next codes require that the segment registers DS and ES are equal and that the direction flag is clear (cld).

PreservePal:
    mov di, offset Buffer768
    mov cx, 256
    mov dx, 03C7h   ; Address
    mov al, 0
    out dx, al
    mov dx, 03C9h   ; Data
  palLoop:
    in  al, dx      ; Red
    stosb
    in  al, dx      ; Green
    stosb
    in  al, dx      ; Blue
    stosb
    loop palLoop
    ret

For restoration, use next code:

RestorePal:
    mov si, offset Buffer768
    mov cx, 256
    mov dx, 03C8h   ; Address
    mov al, 0
    out dx, al
    mov dx, 03C9h   ; Data
  palLoop:
    lodsb
    out dx, al      ; Red
    lodsb
    out dx, al      ; Green
    lodsb
    out dx, al      ; Blue
    loop palLoop
    ret

Please note that your palette buffer has 1024 bytes (8 bits per byte hence your conversion factor of 4), whereas my Buffer768 has 768 bytes (6 bits per byte hence no conversion needed).

  • Related