delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/11/18:00:34

From: the_doc AT primenet DOT com (David Boynton)
Newsgroups: comp.os.msdos.djgpp
Subject: I'm sure this is a FAQ, but I couldn't find the answer.
Date: Sat, 11 Apr 1998 19:52:55 GMT
Organization: http://extra.newsguy.com
Lines: 83
Message-ID: <352fc5a5.399357@enews.newsguy.com>
NNTP-Posting-Host: p-313.newsdawg.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Can anyone tell me why the following code doesn't work?  The breaking point
is when I try to assign the segment returned by __dpmi_allocate_dos_memory()
to the buffer in the disk read packet.  I'm obviously not converting it
correctly as this thing always either locks up my machine or throws a
windows protection error. :(
Thanks in advance, and sorry if this gets asked a lot.

---------------------------------------------------------

#include <dpmi.h>
#include <go32.h>
#include <assert.h>
#include <dos.h>
#include <stdlib.H>
#include <stdio.H>

typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef unsigned long DWORD;

int main (void)
{
        WORD nsects=1;		// These used to be parameters of a fxn,
        DWORD lsect=0;		// this little program is just to test
        BYTE drive=1;		// the code.
        BYTE pbuffer[512];

        memset(pbuffer, 0, 512);	// For debug purposes
        int iNoParas=0, iDosMemSelector=0;
	WORD wSegment=0, wNoBytes=0;

	struct {
		DWORD lsect;	// Starting sector
		WORD nsects;	// # of sectors to read
	        DWORD buffer;	// Where to put the stuff...
	} drp;

	wNoBytes=nsects*512;

	iNoParas=(wNoBytes+15) >> 4;
	wSegment=__dpmi_allocate_dos_memory(iNoParas, &iDosMemSelector);
        assert(iDosMemSelector > 0);
	drp.buffer=wSegment << 16;	// I've tried wSegment * 16 also
					// with similar results.

	drp.lsect=lsect;
	drp.nsects=nsects;

	dosmemput(&drp, sizeof(drp), __tb); // Copy our struct into DOS mem.

	__dpmi_regs in;
        memset (&in, 0, sizeof(__dpmi_regs));
	in.x.ax=0x7305;		// Extended Absolute Disk Read/Write

	in.h.dl=drive+1;	// Make it work like the old Borland fxn, so
				// the default drive isn't availible.

	in.x.si=0x0000;		// Read unknown data
	in.x.cx=0xffff;

	in.x.bx=(__tb & 0x0f);
	in.x.ds=((__tb >> 4) & 0xffff);
	__dpmi_int(0x21, &in);
	
	dosmemget(drp.buffer, wNoBytes, pbuffer);
        FILE *output=fopen ("pbuffer.bin", "wb");
        assert(output!=NULL);
        fwrite(pbuffer, 512, 1, output);
        fclose(output);

	// After this pbuffer contains nothing but garbage (actually, it's
	// part of DJGPP.ENV).  If I do the dosmemget on __tb, I can see the
	// disk read packet, so that's getting transferred to conventional
	// memory fine.

	__dpmi_free_dos_memory(iDosMemSelector);

	return 0;
}

-----------------------------------------------------------------------------
David Boynton <the_doc AT primenet DOT com> | "It wasn't always like this, I had a
Finger for PGP Key (3072/DA2C347A)   | life... once." - Ash, Army of Darkness

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019