Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!iuvax!uceng!mfinegan From: mfinegan@uceng.UC.EDU (michael k finegan) Newsgroups: comp.graphics Subject: Re: VGA Colors Message-ID: <2806@uceng.UC.EDU> Date: 10 Nov 89 20:40:11 GMT References: <824@uwm.edu> Organization: Univ. of Cincinnati, College of Engg. Lines: 252 For those who wanted a grey scale palette on the VGA - here is a combination of C and assembler that loads a LUT into the VGA (256 color) palette. I used MASM and MSC v. 5.1, but should work, with minor changes, for turboc, etc. The same ideas work for 'superVGA' - just change the set_size_color() routine to select your favorite mode and resolution. You could try loading a modified palette, as someone suggested, with colors that were close to grey - the dark greys are very similar. Hope this is what you wanted ... Mike Finegan mfinegan@uceng.UC.EDU ------------------------ cut here for start of C file -------------------------- /* vgapals.c * * (c) 1989 Michael K. Finegan, Jr. * * Simplistic, and inefficient, way to display * unsigned char image on 320x200 vga display, * but illustrates use of LoadPals() with display * of centered 200 x 256 image - a grey scale ramp. * * assuming masm 'loadpals.asm;' was previously executed: * compiled using `cl /AL /c vgapals.c followed by * `link vgademo+loadpals;' * * for small model - change all "far" to "near" in loadpals.asm ... */ #include #include #include #include #define FALSE 0 #define TRUE 1 #define SAVE_LOAD 1 #define RESTORE 0 /* used by LoadPals */ extern unsigned char far NewLut[], far OldLut[]; main() { int i, x, y; void LoadPals(); /* LoadPals is large model (far return) assembler */ int GetChar(); /* also far return assembler ... */ void setvmode(), set_size_colors(), writepix(); /* Load palette with reduced (64 level) gray scale (R = G = B). * * Only the 6 least signifigant bits of R,G,B bytes are * used for the output Look Up Table. * * NOTE: you could load your LUT (256*3 bytes), maybe * previously saved to file, into NewLut, instead ... */ for(i=0;i<256;i++) { NewLut[3*i + 0] = (unsigned char)(i/4); /* R */ NewLut[3*i + 1] = (unsigned char)(i/4); /* G */ NewLut[3*i + 2] = (unsigned char)(i/4); /* B */ } setvmode(0x13); /* 0x13 <==> 256 color 320 by 200 VGA */ set_size_colors(320,200,256); LoadPals(SAVE_LOAD); /* * draw a grey scale 'ramp' * * "x + 32" shifts 256 column image to center of screen. */ for(y=0;y<200;y++) { for(x=0;x<256;x++) writepix(x + 32,y,(unsigned char)x); } GetChar(); /* i.e. wait for keystroke before quitting ... */ LoadPals(RESTORE); setvmode(0x3); /* 0x3 <==> text; should restore previous mode ... */ } void set_size_colors(max_x,max_y,colors) int max_x, max_y, colors; { union REGS inregs, outregs; inregs.x.ax = 0x7e; inregs.x.bx = (unsigned)max_x; inregs.x.cx = (unsigned)max_y; inregs.x.dx = (unsigned)colors; int86(0x10,&inregs,&outregs); } void setvmode(mode) int mode; { union REGS inregs, outregs; inregs.h.ah = 0; inregs.h.al = mode; int86(0x10,&inregs,&outregs); } void writepix(x,y,value) int x, y; unsigned char value; { union REGS inregs, outregs; /* simple video bios call, could write directly to memory ... * * image processing coordinate system - 0,0 @ upper left corner */ inregs.h.al = value; inregs.h.ah = 0x0C; /* write dot */ inregs.h.bh = 0; /* assume page 0 */ inregs.x.cx = (unsigned)x; inregs.x.dx = (unsigned)y; int86(0x10,&inregs,&outregs); } ------------------------ cut here for end of C file ---------------------------- ------------------------ cut here for start of asm file ------------------------ TITLE 'BIOS load of palette' NAME LoadPals PAGE 55,132 _DATA SEGMENT _NewLut db 800 dup (?) _OldLut db 800 dup (?) _DATA ENDS _BSS SEGMENT _BSS ENDS CONST SEGMENT CONST ENDS DGROUP GROUP CONST,_BSS,_DATA _TEXT SEGMENT byte public 'CODE' ASSUME cs:_TEXT,ds:DGROUP,es:DGROUP,ss:DGROUP PUBLIC _NewLut, _OldLut ; (c) 1989 Michael K. Finegan, Jr. ; ; LoadPals Load VGA 256 color palette ; ; Call with AX = [3,2,1,0] (for MSC, LoadPals(AX) ) ; Where: ; 3 ==> Just Load pals ; 1 ==> Save current pals, then Load new pals ; 2 ==> Just Restore pals ; 0 ==> Save current pals, then Restore old pals ; Assume: ; NewLut filled with new LUT; OldLut holds saved LUT, ; depending on calling sequence. ; ; LoadPals(1) followed by LoadPals(2) leaves palette unchanged ... ; PUBLIC _LoadPals _LoadPals PROC far test ax,1 jz restore cmp ax,3 je load mov ah,10h ; set palette reg.s/intensity/blink function mov al,17h ; read a block of DAC color registers mov bx,0 ; start with register 0 mov cx,100h ; and read all 256 push es mov dx, seg _OldLut mov es,dx mov dx, offset _OldLut push bp ; int 10h can modify int 10h ; assume same data segment pop bp pop es load: mov ah,10h ; set palette reg.s/intensity/blink function mov al,12h ; update a block of DAC color registers mov bx,0 ; start with register 0 mov cx,100h ; and change all 256 push es mov dx, seg _NewLut mov es,dx mov dx, offset _NewLut push bp ; int 10h can modify int 10h ; assume same data segment pop bp pop es jmp finished restore: ; *** check values written to registers to debug *** cmp ax,2 je just_restore mov ah,10h ; set palette reg.s/intensity/blink function mov al,17h ; read a block of DAC color registers mov bx,0 ; start with register 0 mov cx,100h ; and read all 256 push es mov dx, seg _NewLut mov es,dx mov dx, offset _NewLut push bp ; int 10h can modify int 10h ; assume same data segment pop bp pop es just_restore: ; restore the pal values read into _Outputlist by a previous ; call to _LoadPals(RESTORE) mov ah,10h ; set palette reg.s/intensity/blink function mov al,12h ; update a block of DAC color registers mov bx,0 ; start with register 0 mov cx,100h ; and change all 256 push es mov dx, seg _OldLut mov es,dx mov dx, offset _OldLut push bp ; int 10h can modify int 10h ; assume same data segment pop bp pop es finished: ret _LoadPals ENDP ; GetChar reads char from keyboard, with no Cntrl-Brk ; check, no echo, and the returned in . PUBLIC _GetChar _GetChar PROC far mov ah,0 INT 16h ret _GetChar ENDP _TEXT ENDS END ------------------------ cut here for end of asm file --------------------------