saving the screen using video emory addresses

Discussion in 'C' started by mj1709, Dec 16, 2011.

  1. mj1709

    mj1709 New Member

    Joined:
    Dec 16, 2011
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<math.h>
    #include<stdlib.h>
    void savevdo(int sr,int er,int sc,int ec,int *imager);
    void showvdo(int sr,int er,int sc,int ec,int imager[]);
    int *buffer;
    main()
    {
    printf("hello");
    getch();
    savevdo(1,1,15,15,buffer);
    clrscr();
    showvdo(1,1,15,15,buffer);
    getch();
    }
    
    void savevdo(int sr,int er,int sc,int ec,int *imager)
    {
    int i,j;
    char far *vid;
    int count=0;
    for(i=sr;i<=er;i++)
    {for(j=sc;j<=ec;j++)
    {
    vid=(char far*)0xB8000000+i*160+j*2;
    *(imager+count)=*vid;
    *(imager+count+1)=*(vid+1);
    count+=2;
    }}
    }
    
    
    void showvdo(int sr,int er,int sc,int ec,int imager[])
    
    {
    int i,j;
    char far *vid;
    int count=0;
    for(i=sr;i<=er;i++)
    {for(j=sc;j<=ec;j++)
    {
    vid=(char far*)0xB8000000+i*160+j*2;
    *vid=*(imager+count);
    *(vid+1)=*(imager+count+1);
    count++;
    }}
    }
    
    //there is no error regarding the base address 0xB800

    this is not working i mean.......the screen is not at all copied and later displaye......plz help wid dis....... :nonod:
     
    Last edited by a moderator: Dec 16, 2011
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Your code doesn't allocate any space for buffer.
     
  3. mj1709

    mj1709 New Member

    Joined:
    Dec 16, 2011
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    it would be kind of yours if u tell how to allocate space for buffer.....?if that means doing...........buffer=(int *)malloc(800).....then doing his too does not make any difference....................... :(
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Have you checked that:
    (a) reading from memory starting at 0xB8000000 gives values that correspond to what's on screen, and
    (b) writing to memory starting at 0xB8000000 puts characters onto the screen that correspond to the numbers you stored?

    What operating system are you using (including the full version number)? Also, what compiler (again, including the full version number)?

    malloc is the way to create space and regardless - you must do this, and free() the memory after you've finished with it. If this doesn't make any difference, then the problem must be down to something else.
     
  5. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Also, why is buffer of type int and not char? I would have thought that it should be char. This could also be the problem, but try it first.
     
  6. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
  7. mj1709

    mj1709 New Member

    Joined:
    Dec 16, 2011
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    well im using windows xp professional basic version......dunno the number and Borland C++ 3.0 as my compiler...........................and the only thing that my code is able to do is that it can write anything to the sreen using the video memory...............but when we try to access data from the vdo memory by saving into an int *buffer NO ACCESS FROM IT TAKES PLACE and the screen is blank..............

    like the following code shows the character 'g' with the appropriate attributes used usng video memory.........
    Code:
    
    #include<conio.h>
    #include<stdio.h>
    #include<stdlib.h>
    void savevdo(int sr,int er,int sc,int ec,int *imager);
    void showvdo(int sr,int er,int sc,int ec,int *imager);
    void write2screen(int row,int column,char c,int attb);
    int *buffer;
    main()
    {
    printf("Hello");
    write2screen(5,5,'g',146);
    getch();
    savevdo(1,1,48,48,buffer);
    clrscr();
    getch();
    showvdo(1,1,48,48,buffer);
    getch();
    }
    
    void savevdo(int sr,int er,int sc,int ec,int *imager)
    {
    int i,j;
    int far *vid;
    int count=0;
    for(i=sr;i<=er;i++)
    {for(j=sc;j<=ec;j++)
    {
    vid=(int far*)0xB8000000+i*160+j*2;
    *(imager+count)=*vid;
    *(imager+count+1)=*(vid+1);
    count+=2;
    }}
    }
    void write2screen(int row,int column,char c,int attb)
    {
    char far *vid;
    vid=(char far*)0xB8000000+row*160+column*2;
    *vid=c;
    vid++;
    *vid=attb;
    }
    void showvdo(int sr,int er,int sc,int ec,int *imager)
    
    {
    int i,j;
    int far *vid;
    int count=0;
    for(i=sr;i<=er;i++)
    {for(j=sc;j<=ec;j++)
    {
    vid=(int far*)0xB8000000+i*160+j*2;
    *vid=*(imager+count);
    *(vid+1)=*(imager+count+1);
    count++;
    }}
    }
    
    
    
     
  8. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Maybe it's write-only memory. Hence the other part of my question: have you checked
    (a) reading from memory starting at 0xB8000000 gives values that correspond to what's on screen

    Cos if you can't do that, then your program has no chance of working. The code appears to be fine, BUT it assumes you can both read and write 0xB8000000+.

    With XP the DOS box isn't really running MS-DOS - it's running an emulator. So writing to memory isn't necessarily going to work as you would expect on a simpler system that is just running MS-DOS. Try it on a PC that's only running DOS - you might find that works OK.
     
  9. mj1709

    mj1709 New Member

    Joined:
    Dec 16, 2011
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    thanks for ur initiative........:)
     
  10. mj1709

    mj1709 New Member

    Joined:
    Dec 16, 2011
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    the error ws quite silly of me:D:eek::goofy::smug:......i u look i have given the initial row and the final row as the same in the first part of the code which made all the difference...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice