Solved

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

Posted on 2004-10-15
4
638 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
In this blog we highlight approaches to managed security as a service.  We also look into ConnectWise’s value in aiding MSPs’ security management and indicate why critical alerting is a necessary integration.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

719 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