www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/17/20:33:40

From: "Marp" <Marp AT 0 DOT 0 DOT 0 DOT 0>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Few lines, huge problems...
Date: Wed, 17 Nov 1999 19:36:06 -0500
Organization: MindSpring Enterprises
Lines: 96
Message-ID: <80vhlt$8fu$1@nntp3.atl.mindspring.net>
References: <3832D080 DOT 1B79710F AT planet DOT it>
NNTP-Posting-Host: c7.b7.cf.28
X-Server-Date: 18 Nov 1999 00:36:13 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2314.1300
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

icemaze <icemaze AT planet DOT it> wrote in message
news:3832D080 DOT 1B79710F AT planet DOT it...
> I'm trying to make a cdrom library with DJGPP. I need to use assembly
> to communicate with MSCDEX, and I managed to get, for example, its
> version number and the number of CDs installed. I need some help with
> this piece of asm code I found in a CD-Programming FAQ: it's
> written in C.
>
> ---- BEGIN ----
> char* allocDriveArray (int driveCount)
> {
>   char* array = (char*)malloc(driveCount * sizeof(char));
>   union REGS r;
>   struct SREGS s;
>   s.es = FP_SEG(array);
>   r.x.bx = FP_OFF(array);
>   r.x.ax = 0x150D;
>   int86x(0x2F, &r, &r, &s);
>   return array;
> }
> ---- END ----

This function should be changed to take a pointer to a buffer as one of its
arguements and the return value indicates success or failure. But anyway...

> I tried to port it to DJGPP C++ (since I'm making an Object Oriented
> Library), but there is nothing like FP_SEG and FP_OFF in DJGPP, so I
> don't know what to give to ES and BX. Can someone help me out? I read
> the DJGPP FAQ, but I didn't understand how to use the transfer buffer:
> all I managed to get is a SIGNAL_ABORT!! This is the latest version of
> my code:
>
> ---- BEGIN ----
> void cdromclass::GetCDDrives (void)
> {
>   char *_drive = new char [_number_of_drives];
>
> // Trying to use DJGPP transfer buffer... but it doesn't work!! :(
>   unsigned long t = __tb >> 4;
>   t &= 0xFFFF;
>
>   asm // Function which should put in "_drive" the drive number of each
>       // CDROM unit present.
>   (
>     "movl  %0, %%es;"
>     "movw  %1, %%bx;"
>     "movw  $0x150D, %%ax;"
>     "int   $2F;"

You can't call MSCDEX, a real mode service, directly from protected mode.
You need to make a call to DPMI and that will call the service for you.
There are funtions in DJGPP that will call DPMI for you(__dpmi_int() for
example). These routines really don't need to be in assembly at all (the
ones provided by DJGPP already are). You probably will see little speed
improvement with assembly doing this it's just not worth it.

As for using the transfer buffer. MSCDEX requires space in conventional
memory to put data since it can't access memory outside of it. So what you
need to do is allocate some space in conventional memory and use dosmemput()
and dosmemget() to transfer data between the buffer and your program's
memory space. The transfer buffer is space that DJGPP allocates for itself
specifically for this purpose and you may use it if you wish. If you have
problems using it you can allocate the required memory yourself using
__dpmi_allocate_dos_memory(). I suggest you look up in the libc documention
the following functions:

__dpmi_allocate_dos_memory()
__dpmi_free_dos_memory()
__dpmi_int()
dosmemput()
dosmemget()

These functions should be exactly what you need for doing this kind of work.
I also suggest you CAREFULLY read chap 18 of the DJGPP FAQ and then ask
about anything specific in there that needs clarification as I though it was
pretty clear about what needs to be done.

>     :
>     : "g" (t), "g" (__tb & 0x000F)  // drive_number or drives_number???
>     : "memory","cc"
>   );
>
>   printf ("\n\nLinear buffer address: %04X:%01X.", (__tb >> 4) & 0xFFFF,
> __tb & 0x000F);
>   for (k = 0; k < _number_of_drives; k++)
>     printf ("\nDrive %d is #%d!", k, _drive[k]);
>   delete [] _drive;
> }
> ---- END ----
>
> Help! ^_^
>
> --
> icemaze AT planet DOT it


- Raw text -


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