TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Paul Edwards
from: david nugent
date: 1994-04-20 05:44:18
subject: msdos program

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


# include 
# include 
# include 
# include 
# include 

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

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


  cheers,
  david

---

* Origin: Unique Computing Pty Ltd (3:632/348)
SEEN-BY: 50/99 54/54 620/243 623/625 632/103 301 348 365 386 998 633/371
SEEN-BY: 634/384 635/210 502 503 541 544 636/100 670/206 711/409 430 807 808
SEEN-BY: 711/809 932 934 712/623 713/888 714/906 800/1
@PATH: 632/348 635/503 50/99 54/54 711/808 809 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™.