Solved

VGA 640x480 Pixel Write....400 points!!!

Posted on 2004-10-15
4
633 Views
Last Modified: 2008-02-01
Hello Everyone...
OK, so I can write to the VGA memory and get something on the screen, I get the write color and beginning position, but when I try to write only one pixel, I get what seems to be 4 pixels in a row. I have an idea of what it is, but I can seem to come up with a solution for it. Anyone care to help? I need to be able to write to one pixel, with a specified color.

Thanks,
Ernie
0
Comment
Question by:fastawdtsi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 9

Expert Comment

by:BeyondWu
ID: 12326805
In which Mode? 16 colors or 256 colors? pls post some of your code.

regards,
Wu
0
 

Author Comment

by:fastawdtsi
ID: 12327130
648x480 16 colors...

Thanks
0
 
LVL 2

Accepted Solution

by:
MrT-RSI earned 400 total points
ID: 12351451
you have to select the right plane first:

This is something from a Pascal Mode-X library, but it should get you on the way:

  procedure putpixel(x,y : word;color : byte); assembler;

  asm
    { set plane }
    mov dx,$03c4 {VGA sequencer}
    mov al,$02 {index $02 -> set write plane register}
    mov cx,x
    and cl,00000011b {x mod 4}
    mov ah,1
    shl ah,cl {which plane}
    out dx,ax
    { calculate offset }
    mov di,x
    shr di,2 {x div 4}
    mov ax,y
    mov cl,mxsizeshift1
    shl ax,cl
    add di,ax
    mov ax,y
    mov cl,mxsizeshift2
    shl ax,cl
    add di,ax {offset}
    mov ax,$a000 {VGA segment}
    mov es,ax
    { put pixel }
    mov al,color
    mov es:[di],al
  end;

By putting 00001111b in ah you can write 4 pixels at once on all planes (as you already dicovered).

Size shifters 1 and 2 are used to multiply the y coord with the width of the screen.
0
 
LVL 9

Expert Comment

by:BeyondWu
ID: 12378387
fastawdtsi,

Sorry for my late response, I'm on the vacation..
Here is the code, although it's not a pure asm code, but it really can work, it works well in my windows WDM driver(both CRT and LCD)...
I think it's easy for you to convert it into assemble languange, if not, please tell me, I hope I can convert it for you.

void  outportb(short port, BYTE val)
{
      __asm
      {      
            mov dx, port
            mov al, val
            out dx, al
      }      
}

gramMem is your VGA memory pointer. A000:0000
// x,y--> coordinates
// val--> color
// odd--> see WriteLine function, FIXME, this parameter could be optimized
void drawpixel16(int x, int y, BYTE val, BYTE odd)
{
      BYTE i = 3 - x % 4;
      BYTE temp;

      /*0 - means copy, 0x8 - AND, 0x10 - OR, 0x18 - XOR*/
      outportb(0x3ce, 0x03);
      outportb(0x3cf, 0x0);
      
      outportb(0x3ce, 0x05);
      outportb(0x3cf, 0x02);

      outportb(0x3C4, 2);
      outportb(0x3C5, 0xFF);

      /*ditermine which bit we want to change*/
      /*Bit Mask Register, enable/disable the bit modify with 0/1*/
      outportb(0x3ce, 0x08);
      if(x%8 < 4)
            outportb(0x3Cf, 1<<(i+4));
      else
            outportb(0x3Cf, 1<<(i+0));

      temp = gramMem[y*80 + x/8];    // need to read it again! otherwise in you can't show anything, it's crazy!

      if(x%2 == 0)      
            gramMem[y*80 + x/8] = val>>(odd?0:4);
      else
            gramMem[y*80 + x/8] = val>>(odd?4:0);
}

// how to draw a line
void WriteLine(int x, int y, BYTE* buffer, int nlen, int bitcount)
{
      switch(bitcount)
      {
      case 4:
            {
                  int i=0;
                  BYTE odd = x % 2;

                  while(i < nlen)
                  {
                        drawpixel16(x, y, *buffer, odd);
                        if(i%2)
                              buffer++;
                        i++;
                        x++;
                  }
            }
            break;
      }
}

regards,
Wu
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
binary bomb phase 6 4 2,388
Buffer bomb nitro 1 4,408
What are the %fs and %gs registers? 3 1,298
crash on a QT GUI Project 1 393
Determining the an SCCM package name from the Package ID
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question