Game Programming with DGJPP
Graphics by Lord Azathoth

Programming the CDROM
The CDROM is very useful for the audio and the data storage. Isn't very simply to programming a small AudioCD player, and I will teach you the secrets of this drive. I use the Microsoft CDROM Extension (MSCDEX) and a bit of AT&T assembly language. If you don't know the AT&T syntax please go to this site and read the ASM tutorial.

Checking the installation of MSCDEX
For checking the presence of the MSCDEX driver call the function 0x1100 of the multilex interrupt (int 0x2F) with the value 0xDADA pushed on the stack; the driver is installed only if the function return the value 0xFF in the register al:

   BOOL installed;

   __asm__ __volatile__ ("
      movw $56026, %%ax
      pushw %%ax
      movw $4352, %%ax
      int $47
      popw %%bx
      cmpb $255, %%al
      jne not_installed
      movb $1, %0
   not_installed:"
      : "=g"(installed)
   );
The installation check isn't difficult. Another important informations is the version of the MSCDEX driver....

Read the MSCDEX driver version
Under W95 (MSCDEX v2.95) the IOCTL call (used for the CDROM functions) are incompatible with the IOCTL call of older MSCDEX versions (truly is the DOS to be incompatible), so is very important to read the MSCDEX driver version. Using the function 0x150C of the INT 0x2F we can read a word that contain the version:

   WORD version;

   __asm__ __volatile__ ("
      movw $5388, %%ax
      int $47
      movw %%bx, %0"
      : "=g"(version)
   );
The high byte of the version contain the version number, and the low byte the revision number (E.g. if version=0x025F the MSCDEX version is 2.95).

Read the number of CDROM drives installed
Another important information is the number of CDROM drives installed on the system. Via the function 0x1500 of INT 0x2F we can read the number of drives and the number of the drive where the first CDROM is installed:

   WORD number;
   BYTE firstdrive;

   __asm__ __volatile__ ("
      movw $5376, %%ax
      movw $0, %%bx
      int  $47
      movw %%bx, %0
      movb %%cl, %1"
      : "=g"(number), "=g"(firstdrive)
   );
Using this function we know where the first CDROM drive is installed, but if there are other drives?

Read the list of the CDROM drives
The function 0x150D of INT 0x2F fills an array of byte (longer than the number of CDROM drives installed on the system) with the number of drives that use. E.g. if the first CDROM drive is installed on the drive E:, drivelist[0] will contain 4, and the second on drive G: drivelist[1] will contain 6. The function use a buffer in real memory, so we can use the __tb (transfer buffer) internal of DJGPP:

   __dpmi_regs regs;
   char drivelist[MAX_CDROMS];


   regs.x.ax=0x150D;
   regs.x.bx=__tb & 0x0F;
   regs.x.es=(__tb >> 4) & 0xFFFF;
   __dpmi_int(0x2F, ®s);
   dosmemget(__tb, number, drivelist);
And now we can access to all the CDROM drives.

Detect if the drive is a CDROM drive
There are another way to detect where the CDROM drives are installed: test each drive. This is done by using the function 0x150B of INT 0x2F. This function return 1 if the specified drive is a CDROM drive:

   WORD drive=4;		// 4 = drive E: (0 = A:, 1 = B:, ...)
   BOOL isCDROM=FALSE;

   __asm__ __volatile__ ("
      movw $5387, %%ax
      mov  %1, %%cx
      int  $47
      orw  %%ax, %%ax
      jz   not_cd_rom
      cmpw $44461, %%bx
      jne  not_cd_rom
      movb $1, %0
   not_cd_rom: "
      : "=g"(isCDROM)
      : "g"(drive)
   );
So we can check a short number of drives for detect where the CDROM drives are installed. Wanna see the demo program?



[main] [prec] [next] [email]

Site Made and Maintained by The Dark Angel <DarkAngel@tin.it>
My ICQ Number is 2063026
You Visited This Page times


This page hosted by Geocities Icon Get your own Free Home Page