cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/06/16/13:40:25

From: "Michael Stewart" <mike AT reggin DOT freeserve DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Selector code
Date: Wed, 16 Jun 1999 10:26:07 +0100
Organization: (Posted via) Netcom Internet Ltd.
Lines: 45
Message-ID: <7k7qc5$pc2$1@taliesin.netcom.net.uk>
NNTP-Posting-Host: hgty.capgemini.co.uk
X-Trace: taliesin.netcom.net.uk 929524933 25986 194.42.240.2 (16 Jun 1999 09:22:13 GMT)
X-Complaints-To: abuse AT corp DOT netcom DOT net DOT uk
NNTP-Posting-Date: 16 Jun 1999 09:22:13 GMT
X-Newsreader: Microsoft Outlook Express 4.72.3155.0
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I would like to get people opinions on this bit of code, whether it is
useful/pointless, could be improved or any errors in it. I have only been
able to test it with the video memory and it works, I'll be testing it a bit
more thoroughly as soon as I get chance.

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 */

And to use it
/* Plot a pixel (col 15) in the top left corner of the screen (in mode 0x13
etc) */
_farpokeb (video_ds, 0, 15);

/* Plot a pixel (col 15) in the bottom right corner of the screen (in mode
0x13 etc) */
_farpokeb (video_ds, 63999, 15);

int make_ds (int &ds, int base, int limit) {
   static char ds_data[8];

   limit--;
   ds_data[0] = limit & 0xff;
   ds_data[1] = limit >> 8 & 0xff;
   ds_data[2] = base & 0xff;
   ds_data[3] = base >> 8 & 0xff;
   ds_data[4] = base >> 16 & 0xff;
   ds_data[5] = 0xf3;
   ds_data[6] = limit >> 16 & 0x0f + 0x40;
   ds_data[7] = 0x00;

   ds = __dpmi_allocate_ldt_descriptors (1);

   return __dpmi_set_descriptor (ds, ds_data);
}

Based on code in the FAQ and code posted here by Bonifati
<abonifati AT telsa DOT it>
Even more credit must go to Eli Zaretskii for letting me know how much
better this method is over using _dos_ds (in short: more memory protection)


- Raw text -


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