Reading the RGB values of the console color palette

前端 未结 1 1509
不思量自难忘°
不思量自难忘° 2020-12-07 03:34

Meat

In C or C++ is there any way to read the color palette RGB values directly? Especially interesting is the extended color space used by xterm (and others) to d

相关标签:
1条回答
  • 2020-12-07 03:44

    [Edit 1] sorry this not leads to solution but for others i added DAC palette IO access

    look the old legacy EGA/VGA references ...

    • you can access palette via I/O
    • i think it was ports 0x03C8, 0x03C9 hex.
    • of course in modern OS you have no access to it
    • so try it in DOS-BOX or what ever and save the original palette values, they should be the same.

    for direct access try this:

    BYTE r,g,b,c=5; // R,G,B values are 6 bit only !!!
    out 0x3C8,c;    // set color index to work with <0,255>
    in  r,0x3C9;    // read color pallete for color c
    in  g,0x3C9;    // not sure if it should be r,g,b 
    in  b,0x3C9;    // or b,g,r ... i did not use it for too many years
    out 0x3C8,c;    // set color index to work with <0,255>
    out 0x3C9,r;    // write color pallete for color c
    out 0x3C9,g;
    out 0x3C9,b;
    

    C/C++ do not have in,out operations so use this:

    BYTE i,o;       // this must be local !!!
    WORD port;      // this must be local !!!
    asm {
        mov dx,port // in i,port
        in al,dx
        mov o,al
    
        mov dx,port // out port,o
        mov al,o
        out dx,al
        }
    
    0 讨论(0)
提交回复
热议问题