BlueSCSI_mode.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * Copyright (C) 2013 Michael McMaster <michael@codesrc.com>
  3. * Copyright (C) 2014 Doug Brown <doug@downtowndougbrown.com>
  4. * Copyright (C) 2019 Landon Rodgers <g.landon.rodgers@gmail.com>
  5. * ZuluSCSI™ - Copyright (c) 2023 Rabbit Hole Computing™
  6. *
  7. * ZuluSCSI™ firmware is licensed under the GPL version 3 or any later version. 
  8. *
  9. * https://www.gnu.org/licenses/gpl-3.0.html
  10. * ----
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version. 
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. * GNU General Public License for more details. 
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  23. **/
  24. #include <stdint.h>
  25. #include <string.h>
  26. #include "BlueSCSI_cdrom.h"
  27. extern "C" {
  28. #include "BlueSCSI_mode.h"
  29. }
  30. static const uint8_t CDROMCDParametersPage[] =
  31. {
  32. 0x0D, // page code
  33. 0x06, // page length
  34. 0x00, // reserved
  35. 0x0D, // reserved, inactivity time 8 min
  36. 0x00, 0x3C, // 60 seconds per MSF M unit
  37. 0x00, 0x4B // 75 frames per MSF S unit
  38. };
  39. #ifdef ENABLE_AUDIO_OUTPUT
  40. static const uint8_t CDROMAudioControlParametersPage[] =
  41. {
  42. 0x0E, // page code
  43. 0x0E, // page length
  44. 0x04, // 'Immed' bit set, 'SOTC' bit not set
  45. 0x00, // reserved
  46. 0x00, // reserved
  47. 0x80, // 1 LBAs/sec multip
  48. 0x00, 0x4B, // 75 LBAs/sec
  49. 0x03, 0xFF, // output port 0 active, max volume
  50. 0x03, 0xFF, // output port 1 active, max volume
  51. 0x00, 0x00, // output port 2 inactive
  52. 0x00, 0x00 // output port 3 inactive
  53. };
  54. #endif
  55. static void pageIn(int pc, int dataIdx, const uint8_t* pageData, int pageLen)
  56. {
  57. memcpy(&scsiDev.data[dataIdx], pageData, pageLen);
  58. if (pc == 0x01) // Mask out (un)changable values
  59. {
  60. memset(&scsiDev.data[dataIdx+2], 0, pageLen - 2);
  61. }
  62. }
  63. extern "C"
  64. int modeSenseCDDevicePage(int pc, int idx, int pageCode, int* pageFound)
  65. {
  66. if ((scsiDev.target->cfg->deviceType == S2S_CFG_OPTICAL)
  67. && (pageCode == 0x0D || pageCode == 0x3F))
  68. {
  69. *pageFound = 1;
  70. pageIn(
  71. pc,
  72. idx,
  73. CDROMCDParametersPage,
  74. sizeof(CDROMCDParametersPage));
  75. return sizeof(CDROMCDParametersPage);
  76. }
  77. else
  78. {
  79. return 0;
  80. }
  81. }
  82. extern "C"
  83. int modeSenseCDAudioControlPage(int pc, int idx, int pageCode, int* pageFound)
  84. {
  85. #ifdef ENABLE_AUDIO_OUTPUT
  86. if ((scsiDev.target->cfg->deviceType == S2S_CFG_OPTICAL)
  87. && (pageCode == 0x0E || pageCode == 0x3F))
  88. {
  89. *pageFound = 1;
  90. pageIn(
  91. pc,
  92. idx,
  93. CDROMAudioControlParametersPage,
  94. sizeof(CDROMAudioControlParametersPage));
  95. return sizeof(CDROMAudioControlParametersPage);
  96. }
  97. else
  98. {
  99. return 0;
  100. }
  101. #else
  102. return 0;
  103. #endif
  104. }