BlueSCSI_platform_config_hook.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * Copyright (C) 2023 Eric Helgeson
  3. *
  4. * This file is part of BlueSCSI
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version. 
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. * GNU General Public License for more details. 
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  18. **/
  19. #include <minIni.h>
  20. #include "BlueSCSI_disk.h"
  21. #include "BlueSCSI_log.h"
  22. #include "BlueSCSI_platform_config_hook.h"
  23. static bool isValidMacintoshImage(image_config_t *img)
  24. {
  25. bool result = true;
  26. const char apple_magic[2] = {0x45, 0x52};
  27. const char block_size[2] = {0x02, 0x00}; // 512 BE == 2
  28. const char lido_sig[4] = {'C', 'M', 'S', '_' };
  29. byte tmp[4] = {0};
  30. // Check for Apple Magic
  31. img->file.seek(0);
  32. img->file.read(tmp, 2);
  33. if(memcmp(apple_magic, tmp, 2) != 0)
  34. {
  35. debuglog("Apple magic not found.");
  36. result = false;
  37. }
  38. // Check HFS Block size is 512
  39. img->file.seek(2);
  40. img->file.read(tmp, 2);
  41. if(memcmp(block_size, tmp, 2) != 0)
  42. {
  43. debuglog("Block size not 512", block_size);
  44. result = false;
  45. }
  46. // Find SCSI Driver offset
  47. img->file.seek(MACINTOSH_SCSI_DRIVER_OFFSET);
  48. img->file.read(tmp, 4);
  49. uint64_t driver_offset_blocks = int((unsigned char)(tmp[0]) << 24 | (unsigned char)(tmp[1]) << 16 |
  50. (unsigned char)(tmp[2]) << 8 | (unsigned char)(tmp[3]));
  51. // Find size of SCSI Driver partition
  52. img->file.seek(MACINTOSH_SCSI_DRIVER_SIZE_OFFSET);
  53. img->file.read(tmp, 2);
  54. int driver_size_blocks = int((unsigned char)(tmp[0]) << 8 | (unsigned char)(tmp[1]));
  55. // SCSI Driver sanity checks
  56. if((driver_size_blocks * MACINTOSH_BLOCK_SIZE) > MACINTOSH_SCSI_DRIVER_MAX_SIZE ||
  57. (driver_offset_blocks * MACINTOSH_BLOCK_SIZE) > img->file.size())
  58. {
  59. debuglog("Invalid Macintosh SCSI Driver partition detected.");
  60. result = false;
  61. }
  62. // Contains Lido Driver - driver causes issues on a Mac Plus and is generally slower than the Apple 4.3 or FWB.
  63. // Also causes compatibility issues with other drivers.
  64. img->file.seek(driver_offset_blocks * MACINTOSH_BLOCK_SIZE + LIDO_SIG_OFFSET);
  65. img->file.read(tmp, 4);
  66. if(memcmp(lido_sig, tmp, 4) == 0)
  67. {
  68. log("---- WARNING: This drive contains the LIDO driver and may cause issues.");
  69. }
  70. return result;
  71. }
  72. // Called from BlueSCSI_disk after image is initalized.
  73. void platformConfigHook(image_config_t *img)
  74. {
  75. if(ini_getbool("SCSI", "DisableConfigHook", false, CONFIGFILE))
  76. {
  77. debuglog("Skipping platformConfigHook due to DisableConfigHook");
  78. return;
  79. }
  80. if (img->quirks == S2S_CFG_QUIRKS_APPLE)
  81. {
  82. if(img->deviceType == S2S_CFG_FIXED)
  83. {
  84. if(!isValidMacintoshImage(img))
  85. {
  86. log("---- WARNING: This image does not appear to be a valid Macintosh Device image. See: https://github.com/BlueSCSI/BlueSCSI-v2/wiki/Disk-Images");
  87. }
  88. else
  89. {
  90. debuglog("---- Valid Macintosh Device Image detected.");
  91. }
  92. }
  93. // Macintosh hosts reserve ID 7, so warn the user this configuration wont work
  94. if((img->scsiId & S2S_CFG_TARGET_ID_BITS) == 7)
  95. {
  96. log("---- WARNING: Quirks set to Apple so can not use SCSI ID 7!");
  97. }
  98. }
  99. }