Solved

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

Posted on 2004-10-15
4
607 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
  • 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Moving applications to the cloud or switching services to cloud-based ones, is a stressful job.  Here's how you can make it easier.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now