BlueSCSI_platform_config_hook.cpp 3.8 KB

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