mode 0x12 please help

Hi,



Im new at VGA programming. Im simply trying to write say a green pixel directly into memory, as follows.



However, it doesnt work. I end up with monochrome.



Also, I have to stay in mode 640X480. Could some please let me know what Im doing wrong. :)



Thanks,

Rachel.

//some parts of the module



byte *ptr=(byte *)0xA0000000L;



union REGS regs;



regs.h.ah = 0x00;

regs.h.al = 0x12;

int86(0x10, &regs, &regs);



x=100;

y=100;

ptr[y*640+x]=2; //green pixel




Comments

  • : Hi,

    :

    : I’m new at VGA programming. I’m simply trying to write say a green pixel directly into memory, as follows.

    :

    : However, it doesn’t work. I end up with monochrome.

    :

    : Also, I have to stay in mode 640X480. Could some please let me know what I‘m doing wrong. :)

    :

    : Thanks,

    : Rachel.

    : //some parts of the module

    :

    : byte *ptr=(byte *)0xA0000000L;

    :

    : union REGS regs;

    :

    : regs.h.ah = 0x00;

    : regs.h.al = 0x12;

    : int86(0x10, s, s);

    :

    : x=100;

    : y=100;

    : ptr[y*640+x]=2; //green pixel

    :

    :

    Hi

    in mode 12h you cant write a pixel straigt to video memory

    explainnation

    640 * 480 = 307200 > 64k //memory block



    if you were useing black - wite you use bits

    640*480 = 307200 <64k*8 <br>
    this fits in a 64 k mem block.



    every pixel consist out of 4 bits 2^4=16

    mode 12h uses 4 black and white memory blocks called the planes.

    all planes start at A000h to slect the plane you're writing too you use the plane slector register of your video card. I don't know the port number you have to use.



    you can set the pixel by this



    select plane 0

    make the right bit 0

    select plane 1

    make the right bit 1

    select plane 2

    make the right bit 0

    select plane 3

    make the right bit 0



    now you have a green pixel at that place



    I hope this helped you



    greetings Jeroen

    (sorry for my english it's)








  • Thanks Jeroen,



    So I'll have to select the planes each time I place a pixel on screen, if I were to draw an image on the display? Or is there an easier way of doing this?



    My intention is to copy a bitmap file and then put it on the display in mode 12h. If you could you give me some sort of direction of how I could do this? Thanks,



    Rachel.


  • Dear Rachel



    : My intention is to copy a bitmap file and then put it on the display in mode 12h. If you could you give me some sort of direction of how I could do this?

    :

    : Rachel.

    :



    It depends a bit on what you call a bitmap file.

    If you really mean a *.BMP file, then you have to do some steps of reorganization of the BMP-data. In a BMP-file the videolines are in reversed order (bottom line comes first) and in 16-colors modes each byte containes 2 pixels.

    But if you simply nead savepic/loadpic routines and there is no necessity for using a standard file format, then it would be the easiest to store and restore one bit plane after each other.



    I have placed some useful routines at the end of this message.



    Hope this helps a bit,



    Thomas.





    /* some EGA/VGA graphics routines */



    #define BLOCKSIZE 38400L /* 640x480 mode */



    /* #define BLOCKSIZE 28000L 640x350 mode */



    void savepic(char *filename)

    {

    FILE *handle;

    char far *screen = (char far *)0xA0000000;

    long int i;

    unsigned char p;

    outp(0x3ce,0x05); /* Graphics Mode */

    outp(0x3cf,0x00); /* Read Mode 0 */

    handle = fopen(filename,"wb");

    for(p=0;p<4;p++)<br>
    {

    outp(0x3ce,0x04); /* Read Map Select */

    outp(0x3cf,p); /* Latch Register p */

    for(i=0L;i
    fputc(screen[i],handle);

    }

    fclose(handle);

    }



    void loadpic(char *filename)

    {

    FILE *handle;

    char far *screen = (char far *)0xA0000000;

    long int i;

    unsigned char p;

    handle = fopen(filename,"rb");

    for(p=0;p<4;p++)<br>
    {

    outp(0x3c4,0x02); /* Map Mask */

    outp(0x3c5,1<<p); /* Bit Plane p */<br>
    for(i=0L;i
    screen[i] = fgetc(handle);

    }

    fclose(handle);

    }



    void setpixel(int x, int y, int col)

    {

    char far *screen = (char far *)0xA0000000;

    long int i;

    unsigned char b;

    outp(0x3ce,0x05); /* Graphics Mode */

    outp(0x3cf,0x02); /* Write Mode 2 */

    i = y*80 + x/8; /* Memory Location */

    b = (0x80)>>(x%8); /* compute Bit Mask */

    outp(0x3ce,0x08); /* Bit Mask Register */

    outp(0x3cf,b); /* Bit Mask */

    outp(0x3ce,0x03); /* Function Select Register */

    outp(0x3cf,0x00); /* Replace Pixel */

    b = screen[i]; /* Dummy Read to refresh latch registers */

    screen[i] = col; /* Set Pixel */

    }




  • Dear Rachel,



    if you run into trouble by using the given setpixel routine (e.g. if you got only some strange vertical lines) then probably you have to disable the compiler optimization.

    Some compilers (e.g. VC++ with standard options) remove the dummy read of the latch registers. The dummy read is necessary to load the latch registers by the bytes from the corresponding bitplanes.

    Without this there would be some random data in the latch registers which will be stored back to the bitplanes in the succeeding write command.



    void setpixel(int x, int y, int col)

    {

    char far *screen = (char far *)0xA0000000;

    long int i;

    unsigned char b;

    outp(0x3ce,0x05); /* Graphics Mode */

    outp(0x3cf,0x02); /* Write Mode 2 */

    i = y*80 + x/8; /* Memory Location */

    b = (0x80)>>(x%8); /* compute Bit Mask */

    outp(0x3ce,0x08); /* Bit Mask Register */

    outp(0x3cf,b); /* Bit Mask */

    outp(0x3ce,0x03); /* Function Select Register */

    outp(0x3cf,0x00); /* Replace Pixel */

    b = screen[i]; /* Dummy Read to refresh latch registers */

    screen[i] = col; /* Set Pixel */

    }



    Thomas.


  • Rachel, did you solve your problem. I am trying to solve the same problem you were talking about in your email (VGA mode 12h)
  • : Rachel, did you solve your problem. I am trying to solve the same problem you were talking about in your email (VGA mode 12h)
    :
    Get a graphics library and have it handle that stuff for you. You didn't say what langauge you're using so I can't make a recomendation.
    There are many out there, get one and get some sleep.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories