From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: how to convert real mode pointer into protected mode ? Date: Tue, 19 Aug 1997 08:54:55 -0400 Organization: Cornell University http://www.cornell.edu Lines: 97 Sender: asu1 AT cornell DOT edu (Verified) Message-ID: <33F9979F.57A0@cornell.edu> References: <33F82B88 DOT 642 AT chem DOT uw DOT edu DOT pl> <5tasf6$cvc AT dfw-ixnews12 DOT ix DOT netcom DOT com> <33F97B9B DOT 74D7 AT chem DOT uw DOT edu DOT pl> Reply-To: asu1 AT cornell DOT edu NNTP-Posting-Host: cu-dialup-0011.cit.cornell.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Wojciech Galazka wrote: > > firewind wrote: > > > > I know very little about DOS stuff, having started with DJGPP. But, I do > > know some. :) Are you sure the _far* functions aren't what you want? For > > example, here is the code to read the DOS InDOS flag: > > Well, as I said probably cannot help. And why? > Here's the problem description. > > Upon return from a real mode ISR I get a pointer in ES:DI > pointing to a structure in memory under 640 kB. > The size of the structure is not known in advance so I > cannot just call dosmemget to copy the struct into > my own one. > The definition of the structure is something like > > struct foo { > short size > struct { > short min > short max > } * minmax; //holds a 'size' number of minmax structures > } > don't think of this as a C structure. think of it as the layout of bytes in memory. then you have: WORD size <--- pointed to by ES:DI WORD off offset WORD seg segment where WORD stands for '16 bit integer'. the code below (which will take some time to put into cmpilable form, should do what you were doing with the for loop below. unsigned addr1, addr2; unsigned short size; int i; addr1 = ES << 4 +DI; addr2 = _farpeekw(_dos_ds, addr1+2) + 16 * _farpeekw(_dos_ds, addr1+4); size = _farpeekw(_dos_ds, addr1); /* no of substructures */ while(size) { printf("Min: %d, Max: %d\n", _farpeekw(_dos_ds, addr2) \ _farpeekw(dos_ds, addr2 + 2); addr2 += 4; size--; } now, you might want to transfer this stuff to virtual memory. in that case, you _can_ use movedata or dosmemget/put function because at the time you get the real mode address in ES:DI, you can compute the total size of the structure as size = _farpeekw(_dos_ds, es << 4 + di); as before the address of the minmax structures is: addr2 = _farpeekw(_dos_ds, addr1+2) + 16 * _farpeekw(_dos_ds, addr1+4); where addr1 = es << 4 + di. now, suppose you have the following in your program: typedef struct minmax { short min; short max; } minmax __attribute__((packed)); then, you can allocate minmax* buffer = (minmax *) malloc(size*sizeof(minmax)); and use: movedata(_dos_ds, addr2, _my_ds(), (unsigned) buffer); hope this helps. i am writing this in a hurry before i leave for the office, so there will be mistakes. -- Sinan ******************************************************************* A. Sinan Unur WWWWWW |--O+O mailto:sinan DOT unur AT cornell DOT edu C ^ http://www.people.cornell.edu/pages/asu1/ \ ~/ Unsolicited e-mail is _not_ welcome, and will be billed for. *******************************************************************