TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: David Nugent
from: Brenton Vettoretti
date: 1994-04-22 12:42:06
subject: msdos program

Once upon a time Paul Edwards wrote,

PE> I want a program to run under MSDOS, compiled with BC++ 3.1,
PE> which will dump all the accessible memory (ie from location 0
PE> to location 1048576) to a file. I know how to do it if I was
PE> dealing with a flat memory model on a decent operating
PE> system, but not under MSDOS.

David Nugent replied with the following work of art.

DN> # include 
DN> # include 
DN> # include 
DN> # include 
DN> # include 
DN> int
DN> main (int argc, char * argv[])
DN> {
DN>    unsigned short seg = 0;
DN>    char const * nam = (argc > 1) ? argv[1] : "dump.mem";
DN>    int fd = open (nam, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IREAD|S_IWRITE);
DN>    if (fd == -1)
DN>    {
DN>        fprintf(stderr, "Unable to create %s\n", nam);
DN>        return 1;
DN>    }
DN>    do
DN>    {
DN>        asm {
DN>            mov     bx,[fd]
DN>            xor     dx,dx
DN>            mov     cx,0x1000   /* write in 4K blocks */
DN>            mov     ah,0x40
DN>            push    ds
DN>            mov     ds,[seg]
DN>            int     0x21
DN>            pop     ds
DN>        }
DN>        seg += 0x0100;
DN>    }
DN>    while (seg != 0);
DN>    close (fd);
DN>    return 0;
DN> }

DN> Apologies for the inline assembler, but I don't do much truely
DN> 'unportable' stuff in C.  If I've got to "DOS" it, I'll usually
DN> use asm anyway rather than fiddle with MK_FP's and so forth.
DN> I guess it depends on what you're used to, but I've got more flight
DN> hours in asm than in DOSish C. :-)
DN> This is also memory model independant.

Hey David, That's "no fair" :)

If I had known you could use a trick like that I would have proposed
the following "trick" which doesn't even need a C compiler so it's
not only model independent but vendor and version independent :)

Snip this and save it in a text file called DUMPIT

...[start snip]...
n dump.mem
r bx
0010
r cx
0000
r cs
0000
w cs:0000
q
...[end of snip]..

At the DOS prompt type " DEBUG < DUMPIT "

It's also faster than any other method posted and is smaller too :)

Cheers, Brenton

--- PQWK200
* Origin: TestPoint (3:711/934.7)
SEEN-BY: 711/809 934
@PATH: 711/934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.