DSTREAM.CPP 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. *
  20. * C O N F I D E N T I A L -- W E S T W O O D S T U D I O S
  21. *
  22. *----------------------------------------------------------------------------
  23. *
  24. * PROJECT
  25. * VQAPlay32 library.
  26. *
  27. * FILE
  28. * dstream.c
  29. *
  30. * DESCRIPTION
  31. * DOS IO handler.
  32. *
  33. * PROGRAMMER
  34. * Denzil E. Long, Jr.
  35. *
  36. * DATE
  37. * April 10, 1995
  38. *
  39. *----------------------------------------------------------------------------
  40. *
  41. * PUBLIC
  42. * VQA_InitAsDOS - Initialize IO with the standard DOS handler.
  43. *
  44. * PRIVATE
  45. * VQADOSHandler - Standard DOS IO handler.
  46. *
  47. ****************************************************************************/
  48. #include <fcntl.h>
  49. #include <io.h>
  50. #include "vqaplayp.h"
  51. /*---------------------------------------------------------------------------
  52. * PRIVATE DECLARATIONS
  53. *-------------------------------------------------------------------------*/
  54. static long VQADOSHandler(VQAHandle *vqa, long action, void *buffer,
  55. long nbytes);
  56. /****************************************************************************
  57. *
  58. * NAME
  59. * VQA_InitAsDOS - Initialize IO with the standard DOS handler.
  60. *
  61. * SYNOPSIS
  62. * VQA_InitAsDOS(VQA)
  63. *
  64. * VQA_InitAsDOS(VQAHandle *);
  65. *
  66. * FUNCTION
  67. * Initialize the IO of the specified handle as a standard DOS access.
  68. *
  69. * INPUTS
  70. * VQA - Pointer to VQAHandle to initialize as DOS.
  71. *
  72. * RESULT
  73. * NONE
  74. *
  75. ****************************************************************************/
  76. void VQA_InitAsDOS(VQAHandle *vqa)
  77. {
  78. ((VQAHandleP *)vqa)->IOHandler = VQADOSHandler;
  79. }
  80. /****************************************************************************
  81. *
  82. * NAME
  83. * VQADOSHandler - Standard DOS IO handler.
  84. *
  85. * SYNOPSIS
  86. * Error = VQADOSHandler(VQA, Action, Buffer, NBytes)
  87. *
  88. * unsigned long VQADOSHandler(VQAHandle *, long, long, long);
  89. *
  90. * FUNCTION
  91. * Perform the requested action on the standard DOS file system.
  92. *
  93. * INPUTS
  94. * VQA - VQAHandle to operate on.
  95. * Action - Action to perform.
  96. * Buffer - Buffer to Read/Write to/from.
  97. * NBytes - Number of bytes to operate on.
  98. *
  99. * RESULT
  100. * Error - 0 if successful, otherwise error.
  101. *
  102. ****************************************************************************/
  103. static long VQADOSHandler(VQAHandle *vqa, long action, void *buffer,
  104. long nbytes)
  105. {
  106. long fh;
  107. long error;
  108. fh = vqa->VQAio;
  109. /* Perform the action specified by the IO command */
  110. switch (action) {
  111. /* VQACMD_READ means read NBytes and place it in the memory
  112. * pointed to by Buffer.
  113. *
  114. * Any error code returned will be remapped by VQA library into
  115. * VQAERR_READ.
  116. */
  117. case VQACMD_READ:
  118. error = (read(fh, buffer, nbytes) != nbytes);
  119. break;
  120. /* VQACMD_WRITE is analogous to VQACMD_READ.
  121. *
  122. * Writing is not allowed to the VQA file, VQA library will remap the
  123. * error into VQAERR_WRITE.
  124. */
  125. case VQACMD_WRITE:
  126. error = 1;
  127. break;
  128. /* VQACMD_SEEK asks that you perform a seek relative to the current
  129. * position. NBytes is a signed number, indicating seek direction
  130. * (positive for forward, negative for backward). Buffer has no meaning
  131. * here.
  132. *
  133. * Any error code returned will be remapped by VQA library into
  134. * VQAERR_SEEK.
  135. */
  136. case VQACMD_SEEK:
  137. error = (lseek(fh, nbytes, (long)buffer) == -1);
  138. break;
  139. /* VQACMD_OPEN asks that you open the file for access. */
  140. case VQACMD_OPEN:
  141. error = open((char *)buffer, (O_RDONLY|O_BINARY));
  142. if (error != -1) {
  143. vqa->VQAio = error;
  144. error = 0;
  145. }
  146. break;
  147. case VQACMD_CLOSE:
  148. close(fh);
  149. error = 0;
  150. break;
  151. /* VQACMD_INIT means to prepare your IO for reading. This is used for
  152. * certain IOs that can't be read immediately upon opening, and need
  153. * further preparation. This operation is allowed to fail; the error code
  154. * will be returned directly to the client.
  155. */
  156. case VQACMD_INIT:
  157. /* IFFCMD_CLEANUP means to terminate the transaction with the associated
  158. * IO. This is used for IOs that can't simply be closed. This operation
  159. * is not allowed to fail; any error returned will be ignored.
  160. */
  161. case VQACMD_CLEANUP:
  162. error = 0;
  163. break;
  164. }
  165. return (error);
  166. }