From: "Michael Stewart" Newsgroups: comp.os.msdos.djgpp Subject: Re: Selector code Date: Thu, 17 Jun 1999 10:20:13 +0100 Organization: (Posted via) Netcom Internet Ltd. Message-ID: <7kaeck$em5$1@taliesin.netcom.net.uk> References: NNTP-Posting-Host: hgty.capgemini.co.uk X-Trace: taliesin.netcom.net.uk 929610964 15045 194.42.240.2 (17 Jun 1999 09:16:04 GMT) X-Complaints-To: abuse AT corp DOT netcom DOT net DOT uk NNTP-Posting-Date: 17 Jun 1999 09:16:04 GMT X-Newsreader: Microsoft Outlook Express 4.72.3155.0 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0 Lines: 60 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Eli Zaretskii wrote in message ... > >On Wed, 16 Jun 1999, Michael Stewart wrote: > >> It creates a selector, given the location and size. So if you wanted a >> descriptor which spanned the VGA memory (0xa0000, 64000 bytes) you would >> call it like so. >> >> if (make_ds (video_ds, 0xa0000, 64000)) >> return -1; /* Error making descriptor */ > >I think it might be useful. > >> int make_ds (int &ds, int base, int limit) { >> static char ds_data[8]; > >Why did you make the ds_data[] array static? Thats what was in the original code, I never gave it much thought. >Also, I think it's better to declare it "unsigned char". Will do. >> limit--; >> ds_data[0] = limit & 0xff; >> ds_data[1] = limit >> 8 & 0xff; > >It might be better to make sure that if the size of the segment is >more than 1MB, the lower 12 bits in the limit you pass to >__dpmi_set_descriptor are set. This is because the DPMI spec requires >such large segments to be page-aligned, and some servers will fail the >call otherwise. Too many people posted here code that didn't work >because they failed to comply to that requirement, and it would be a >good idea to make this function take care of that for the user. Ok >> ds_data[6] = limit >> 16 & 0x0f + 0x40; > >The 0x40 part is only correct for limits less than 64KB (and even then >I think it needs to be 0x41). For larger segments, you need to make >it page-granular, so 0xc1 is the value in those cases. Ok >> ds_data[7] = 0x00; > >This is only right for addresses in the first 16MB range. Why the >limitation? As before it was in the original code. I'll look into changing it. Michael Stewart