Capturing dos text screen in C

This is a discussion on Capturing dos text screen in C within the C Programming forums, part of the General Programming Boards category; Hai. I am actually a VB programmer. I have a new project and have to write 2 dos based program ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    8

    Unhappy Capturing dos text screen in C

    Hai. I am actually a VB programmer. I have a new project and have to write 2 dos based program in Turbo C. With no knowledge I manage to complete 1. Now I have problem with the capturing the dos text screen. I know it is located at b800:0 memory location. How do I get this detail out and send it to a text file. As a new user to C programming, I am totally lost here.

    Can anyone help me on how to read the value from the address location b800:0?

    Thank you very much. Your co-operation is very much appreciated.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851
    Well the first question is why are you using such an ancient compiler?

    Most people write stuff to a text file when they've got hold of the text. Rummaging around in video memory 'after the event' is a lot more complicated.

    How about stating what it is you want to do?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    Well If you just want to see all the output of program in text file use redirection.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    8
    Hai..I am writing a program that can capture a dos text screen and write it to a text file. Now this system will be placed in a virtual harddisk on a motherboard. It is actually to test RAM produce and to capture the test result. In order to test the RAM there are only the motherboards without the harddisk. Therefore we need to use the ancient compiler as this will not need any library or any dependencies after compiling to an .exe. The test program is done by the client's side. But to capture the result from the monitor and write it to a text file is my problem. When writing to c:\test.txt, it will be some how mirrored to the server. (Client has already done the configuration).

    Now I just need to get that sample test on the monitor and send it to a text file. (Capturing dos text screen). I have search on the net but only could find until b800:0 but I am not sure how to get the data out of it. Pls Help.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    8

    Dos text capturing program in Turbo C

    Hai..I am writing a program that can capture a dos text screen and write it to a text file. Now this system will be placed in a virtual harddisk on a motherboard. It is actually to test RAM produce and to capture the test result. In order to test the RAM there are only the motherboards without the harddisk. Therefore we need to use the ancient compiler as this will not need any library or any dependencies after compiling to an .exe. The test program is done by the client's side. But to capture the result from the monitor and write it to a text file is my problem. When writing to c:\test.txt, it will be some how mirrored to the server. (Client has already done the configuration).

    Now I just need to get that sample test on the monitor and send it to a text file. (Capturing dos text screen). I have search on the net but only could find until b800:0 but I am not sure how to get the data out of it. Pls Help.

  6. #6
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    The info you have is a segment and an offset for very old memory mapped stuff, if you try to access that offset in windows you will get an access violation.

    GetStdHandle ( STD_OUTPUT_HANDLE ) ;
    ReadConsoleOutput

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    8
    Quote Originally Posted by valis
    The info you have is a segment and an offset for very old memory mapped stuff, if you try to access that offset in windows you will get an access violation.

    GetStdHandle ( STD_OUTPUT_HANDLE ) ;
    ReadConsoleOutput

    But only the development of the system will be on a windows paltform. But the actual one will be in only a dos platform. This is because the motherboard does not have a harddisk and only have dos install on their virtual memory. That is why I opt to use b800:0.

    If there are any other suggestions please advice.

    Thank you.

  8. #8
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Quote Originally Posted by hednast
    This is because the motherboard does not have a harddisk and only have dos install on their virtual memory.
    That presents an interesting dillema because virtual memory is the term for temporary storage on the harddrive.

    But more to the point, you could take two routes. The first I'm not 100% sure on if it will work or not and that would be to get a pointer to B800 and read data. The second would be to embed some assembly in the program for reading it.

  9. #9
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    you could either do it in assembly and use segement prefix, or use the MK_FP macro:
    char __far *fpConsoleMem = MK_FP ( 0xb800, 0x0000 ) ;

  10. #10
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    Code:
    unsigned char far* text_mem = (unsigned char far*)0xB8000000
    Works fine in TC and doesnt rely on features that may or may not exist (__far and MK_FP() for example).

    Remember that only the bytes at even addresses have character info.

    You might want a binary-mode file, in the event that someone is writing control characters to get fancy glyphs.

    Incidentally, B800:0000 is the first text screen for color adapters. If the adapter is monochrome, the screen is at B000:0000 instead.
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

  11. #11
    Registered User
    Join Date
    Aug 2005
    Posts
    8
    Quote Originally Posted by zx-1
    Code:
    unsigned char far* text_mem = (unsigned char far*)0xB8000000
    Works fine in TC and doesnt rely on features that may or may not exist (__far and MK_FP() for example).
    Hai.......Thanks to all who have replied my post. Nevertheless, I have tried the codes

    Below is the code segment

    #include <stdio.h>
    #include <dos.h>


    int main()
    {
    long i;
    unsigned char far* text_mem = (unsigned char far*) 0xb8000000;

    for(i=0;i<100;i++)
    printf("%s",text_mem[i]);
    return 0;
    }


    I still does not work. I am not sure if that is the way to output the result. Please help me verify as I am just a beginner in C.

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851
    To be honest, this is not a job I would have given to a VB programmer who's never done C before. We're going to end up pretty much writing the whole thing for you, then you're going to go away and use it - maybe even claim credit for it, who knows.

    People who come here to learn are fine, people who come here hoping for others to do their own jobs are not. If you want to pay someone else to do your work for you, then goto www.rentacoder.com.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  13. #13
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    Oh now I get you(i think ).May this help you.if not,my apology
    Code:
    #include <stdio.h>
    #include <dos.h>
    
    
    int main()
    {
    int i;
    unsigned char far* text_mem = (unsigned char far*) 0xb0008000;
    FILE *fp = fopen("TEXT.TXT", "w");
    if(fp==NULL)
    exit(1);
    
    for(i=0;i<2900;i+=2)
    fputc(*(text_mem+i),fp);
    
    fclose(fp);
    return 0;
    }


    edit:-do print on screen something(wat you want to write on file) before for loop.
    Last edited by cbastard; 08-11-2005 at 04:02 PM.

  14. #14
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Windows XP will NOT generate an access violation if you program this using a DOS-based compiler. Heck you could do it in assembly lanugage as well. Each cell in 80x25x16 colors occupies 2 bytes in memory. The first byte represents the ASCII value of the character in the cell and the second byte represents the foreground and background color of the cell. The formula is this:

    bytevalue=(foreground*15)+background

    The only limitation is that some text modes do not allow for any background colors above 8 or above dark grey.

    Here is the default color setup for text mode 80x25x16

    0 - black
    1 - dark blue
    2 - dark green
    3 - dark cyan
    4 - red
    5 - magenta
    6 - brown
    7 - dark white
    8 - grey
    9 - light blue
    10 - light green
    11 - cyan (light cyan)
    12 - orange (light red)
    13 - purple (light magenta)
    14 - yellow (light brown)
    15 - bright white (light white)

    All you need to do is create a pointer to the start of the video memory for that mode. Since it is B800:0000 and since each cell is 2 bytes you only need to know how many rows and columns are on the screen to capture it.

    80*25*2=4000 bytes or 0x0FA0 bytes.

    Allocate a 4000 byte buffer, read 4000 bytes via your pointer to video memory starting at B800:0000. Write the buffer to disk.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. changing dos screen
    By nepdude in forum C Programming
    Replies: 12
    Last Post: 07-07-2007, 03:13 AM
  2. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  3. question about printing on screen and not overwriting text...
    By revelation437 in forum C Programming
    Replies: 2
    Last Post: 12-14-2002, 02:48 PM
  4. How do you add colour to the text in DOS?
    By techie in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-19-2001, 12:55 PM
  5. Replies: 6
    Last Post: 09-12-2001, 11:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21