Thread: question about XMS programming

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    127

    question about XMS programming

    HI,
    i'm programming on XMS with TurboC under DOS, the program will be right when i compile it with Small Model. but when i compile it with Large Model, the program gets bad, the error is that calling XMS driver entry function, the program will get a Divided-By-Zero error.
    i don't know why it is caused, and how to solve it.
    Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Obviously, a divide-by-zero error is a program trying to go x/0. I don't know what would cause it if the program worked under the small model. Post the program in question (the code, that is).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    127
    Code:
    static void far(* __xms_driver)(void) = 0; //it stores the xms driver entry function address
    
    bool xmsInit(void) //get the xms driver entry function
    {
       union  REGS  r;
       struct SREGS s;
       unsigned long driver_entry = 0;
       
       
       if(__xms_driver != 0) return true;   
    
       r.x.ax = 0x4300;  
       int86(0x2f, &r, &r);
       if(r.h.al != 0x80)
            return false;
            
       segread(&s);
       r.x.ax = 0x4310;
       int86x(0x2f, &r, &r, &s); 
       
       driver_entry = s.es;
       driver_entry <<= 16;
       driver_entry += r.x.bx;
       __xms_driver = (void (far*)())driver_entry;
       return true; 
    }
    
    bool __xms_mem_move(struct __WXMS_TAG far* xms_ptr)
    {
        int segs, offs, status;
    
        int ds_, si_;
        segs = FP_SEG(xms_ptr);
        offs = FP_OFF(xms_ptr);
        
        ds_ = _DS;
        si_ = _SI;
    
          _AH = 0xb;
          _DS = segs;
          _SI = offs;   
    
        __xms_driver(); //crashed here!!!!!!!!!!!!!!!!!!! divided by zero
        status = _AX;
    
        _SI = si_;
        _DS = ds_;
    
        return (status == 1)?(true): (false);
    }
    compiler is TC2, memory model is large, i really dont know what causes the program crashed
    Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Or join the real world where 640K is just a distant memory of a bygone age.
    Get a 32 bit compiler for heavens sake!
    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
    Aug 2003
    Posts
    127
    Sorry, the OS-platform is MS-DOS 7.1, so i cann't use 32-bit compiler...
    Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Unless you recompile the code for __xms_driver() as a large model, it's probably not going to work.

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    127
    thanks
    swoopy, you meant i have to recompile the code for __xms_driver as small model?? how to do?
    Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >swoopy, you meant i have to recompile the code for __xms_driver as small model?? how to do?
    jinhao, I guess there are three questions:
    1) Do you have the source code for __xms_driver?
    2) Did you compile it as a large model or small model?
    3) If it works as a small model, why are you changing to a large model?

    There's a member who frequents this forum named Bubba who might be able to help you. But he tends to disappear for long periods before reappearing.

  9. #9
    Registered User
    Join Date
    Aug 2003
    Posts
    127
    i found the real place where the divide error caused

    in the __xms_mem_move
    [CODE]
    _AH = 0xb;
    _DS = segs; //it,s here divide error, WHY?
    _SI = offs;
    [CODE]
    Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.

  10. #10
    Registered User
    Join Date
    Aug 2003
    Posts
    127
    the problem is that when i change the value of DS in large memory model, the program reports divide error.

    i don't know whether i can chage the value of DS in the large memory model
    Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM