GETCD.CPP 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***************************************************************************
  19. ** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
  20. ***************************************************************************
  21. * *
  22. * Project Name : WWLIB *
  23. * *
  24. * File Name : GETCD.CPP *
  25. * *
  26. * Programmer : STEVE WETHERILL BASED ON JOE BOSTIC CODE *
  27. * *
  28. * Start Date : 5/13/94 *
  29. * *
  30. * Last Update : June 4, 1994 [SW] *
  31. * *
  32. *-------------------------------------------------------------------------*
  33. *-------------------------------------------------------------------------*
  34. * Functions: *
  35. * GetCDClass::GetCDClass -- default constructor *
  36. * GetCDClass::~GetCDClass -- destructor *
  37. * GetCDClass::GetCDDrive -- returns the logical CD drive *
  38. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  39. #include <stddef.h>
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <dos.h>
  44. #include "wwstd.h"
  45. #include "playcd.h"
  46. #include "wwmem.h"
  47. /***************************************************************************
  48. * GetCDClass -- default constructor *
  49. * *
  50. * *
  51. * *
  52. * INPUT: *
  53. * none *
  54. * OUTPUT: *
  55. * none *
  56. * WARNINGS: *
  57. * *
  58. * HISTORY: *
  59. * 05/26/1994 SW : Created. *
  60. *=========================================================================*/
  61. GetCDClass::GetCDClass(VOID)
  62. {
  63. memset ( this , 0 , sizeof ( GetCDClass ) ) ;
  64. if (DPMI_real_alloc(2, &cdDrive_addrp, &largestp))
  65. exit(1);
  66. CDCount = 0;
  67. CDIndex = 0;
  68. /*
  69. ** Set all CD drive placeholders to empty
  70. */
  71. memset (CDDrives, NO_CD_DRIVE, MAX_CD_DRIVES);
  72. /*
  73. ** Dos will only currently support one cd drive so just
  74. ** set the first entry to it.
  75. */
  76. GetCDDrives();
  77. }
  78. /***************************************************************************
  79. * GetCDClass -- destructor *
  80. * *
  81. * *
  82. * *
  83. * INPUT: *
  84. * none *
  85. * OUTPUT: *
  86. * none *
  87. * WARNINGS: *
  88. * *
  89. * HISTORY: *
  90. * 05/26/1994 SW: Created. *
  91. *=========================================================================*/
  92. GetCDClass::~GetCDClass(VOID)
  93. {
  94. if(cdDrive_addrp.seg)
  95. DPMI_real_free(cdDrive_addrp); // free up those conventional buffers
  96. }
  97. /***************************************************************************
  98. * GetCDDrive -- returns the logical CD drive *
  99. * *
  100. * *
  101. * *
  102. * INPUT: *
  103. * none *
  104. * OUTPUT: *
  105. * WORD logical_drive *
  106. * WARNINGS: *
  107. * *
  108. * HISTORY: *
  109. * 05/26/1994 SW : Created. *
  110. *=========================================================================*/
  111. void GetCDClass::GetCDDrives(VOID)
  112. {
  113. for (int lp = 0; lp < 26; lp++ ) {
  114. /*
  115. ** This call determines if the current specifed drive is a
  116. ** CD ROM drive.
  117. ** Input:
  118. ** AX = 150Bh
  119. ** CX = CD rom drive letter to check (A = 0, B = 1)
  120. ** Output:
  121. ** AX = non zero if drive is a CD ROM, zero if it is not.
  122. ** BX = Signature word (ADADh if CD rom extension are installed)
  123. */
  124. sregs . es = cdDrive_addrp . seg ;
  125. regs . x . ebx = 0;
  126. regs . x . eax = 0x150B;
  127. regs . x . ecx = lp;
  128. DPMI_real_intr ( 0x2F , & regs , & sregs ) ;
  129. if (regs.x.ebx == 0xADAD && regs.x.eax != 0) {
  130. CDDrives[CDCount++] = lp;
  131. }
  132. }
  133. }
  134. /* ==================================================================== */