CDROM.C 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. /*
  14. * $Source: f:/miner/source/main/rcs/cdrom.c $
  15. * $Revision: 1.2 $
  16. * $Author: john $
  17. * $Date: 1995/03/20 15:01:19 $
  18. *
  19. * Routines to access a cdrom drive.
  20. *
  21. * $Log: cdrom.c $
  22. * Revision 1.2 1995/03/20 15:01:19 john
  23. * Initial revision.
  24. *
  25. * Revision 1.1 1995/03/14 16:56:59 john
  26. * Initial revision
  27. *
  28. *
  29. */
  30. #pragma off (unreferenced)
  31. static char rcsid[] = "$Id: cdrom.c 1.2 1995/03/20 15:01:19 john Exp $";
  32. #pragma on (unreferenced)
  33. #include <dos.h>
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include "dpmi.h"
  38. typedef struct {
  39. char unit;
  40. ushort dev_offset;
  41. ushort dev_segment;
  42. } dev_list;
  43. typedef struct _Dev_Hdr {
  44. unsigned int dev_next;
  45. unsigned short dev_att;
  46. ushort dev_stat;
  47. ushort dev_int;
  48. char dev_name[8];
  49. short dev_resv;
  50. char dev_letr;
  51. char dev_units;
  52. } dev_header;
  53. int find_descent_cd()
  54. {
  55. dpmi_real_regs rregs;
  56. // Get dos memory for call...
  57. dev_list * buf;
  58. dev_header *device;
  59. int num_drives, i;
  60. unsigned cdrive, cur_drive, cdrom_drive;
  61. memset(&rregs,0,sizeof(dpmi_real_regs));
  62. rregs.eax = 0x1500;
  63. rregs.ebx = 0;
  64. dpmi_real_int386x( 0x2f, &rregs );
  65. if ((rregs.ebx & 0xffff) == 0) {
  66. return -1; // No cdrom
  67. }
  68. num_drives = rregs.ebx;
  69. buf = (dev_list *)dpmi_get_temp_low_buffer( sizeof(dev_list)*26 );
  70. if (buf==NULL) {
  71. return -2; // Error getting memory!
  72. }
  73. memset(&rregs,0,sizeof(dpmi_real_regs));
  74. rregs.es = DPMI_real_segment(buf);
  75. rregs.ebx = DPMI_real_offset(buf);
  76. rregs.eax = 0x1501;
  77. dpmi_real_int386x( 0x2f, &rregs );
  78. cdrom_drive = 0;
  79. _dos_getdrive(&cdrive);
  80. for (i = 0; i < num_drives; i++) {
  81. device = (dev_header *)((buf[i].dev_segment<<4)+ buf[i].dev_offset);
  82. _dos_setdrive(device->dev_letr,&cur_drive);
  83. _dos_getdrive(&cur_drive);
  84. if (cur_drive == device->dev_letr) {
  85. if (!chdir("\\descent")) {
  86. FILE * fp;
  87. fp = fopen( "saturn.hog", "rb" );
  88. if ( fp ) {
  89. cdrom_drive = device->dev_letr;
  90. fclose(fp);
  91. break;
  92. }
  93. }
  94. }
  95. }
  96. _dos_setdrive(cdrive,&cur_drive);
  97. return cdrom_drive;
  98. }
  99.