Thread: would this work?

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    140

    would this work?

    I want to load a really small .com file (like 200 bytes or something) into an array and then run it. Am I doing this right?

    int main()
    {
    unsigned char program[500]; // to store the program
    int i; //some crap for some crap
    FILE *fp; //to load the program

    for(i=0i;<500;i++) // clear the array
    program[i]='\0';

    fp=fopen("program.com", "rb");

    i=0;

    while( program[i]=fgetc(fp) !=EOF ); // load it up

    // sorry, donno how to do it without asm

    asm{
    mov bx, program[0]
    jmp bx
    }

    return 0;
    }

    Do you think this would work or would I have to do it differently.
    Acos is good

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Um... why?

    system("mycomfile.com");

    Quzah.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    140

    because I want to

    well... would that work?
    Acos is good

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    No it wouldn't, because

    1. You need to load the .com file aligned on a 16 byte boundary

    2. you need to save all your registers, and set some others.

    3. COM files can exit with a DOS interrupt, which will most likely take your program down with it.

    Here's some info
    http://www.acc.umu.se/~john/TAE/c001p16.htm

    You might be able to make it work for some files, but you're going to get pretty close to doing what system() does anyway.
    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.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    140

    Am I understanding this?

    The reason Im not using system() is because I want to try to make a simple little multitasking thing (a kernel I guess) that can load a couple of .com files (exe would probably be too hard) and switch betwen them 18.2 (int 1CH I think) times per second. Ok moving on, so I guess the psp is something that dos puts at [segment:0] and the actuall .com file is put at [segment:100H], is this right? If Im correct about that then couldnt I just load a file with no dos exit functions and at the end of the array that I load it into put a jmp instruction to wherever I want it to go once its finished?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    As far as I know, a .COM file begins with a PSP, which DOS overwrites with a few bits of information which are applicable at run time.

    It still wouldn't work, because DOS itself isn't re-entrant, so if you switched tasks whilst "a.com" was in the middle of a DOS function, and "b.com" tried to use DOS, then you're stuck - dunno what would happen.
    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.

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    140

    oh I see

    so your saying that like if program 1 called an int 21 function and then it switched to the next program in the middle of that call and that new program also called int 21 then it could get ugly. damn this could be tough, any alternatives you an think of?

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    Do you have the source for these .COM files?
    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.

  9. #9
    Registered User
    Join Date
    Sep 2001
    Posts
    140

    no

    nope. I would want my thing to be able to run any .com program so theres no way of knowing what it will run. It wouldnt work even if I saved all the registers before I had it switch to the other program?

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    > It wouldnt work even if I saved all the registers before I had it switch to the other program?
    No.

    If you're trying to write a kernel, then look around here
    http://www.google.com/search?hl=en&q=ctask+kernel

    I think you can get the source for ctask, and it will show you all the grubby bits you need to take care of, to persuade multi-tasking to run on DOS.

    Hopefully, it will allow you to see how to adapt your idea.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM