BlueSCSI_disk.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * SCSI2SD V6 - Copyright (C) 2013 Michael McMaster <michael@codesrc.com>
  3. * Copyright (C) 2014 Doug Brown <doug@downtowndougbrown.com
  4. * ZuluSCSI™ - Copyright (c) 2022 Rabbit Hole Computing™
  5. * Copyright (C) 2024 Eric Helgeson <erichelgeson@gmail.com>
  6. *
  7. * It is derived from disk.h in SCSI2SD V6.
  8. *
  9. * This file is licensed under the GPL version 3 or any later version. 
  10. *
  11. * https://www.gnu.org/licenses/gpl-3.0.html
  12. * ----
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation, either version 3 of the License, or
  16. * (at your option) any later version. 
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. * GNU General Public License for more details. 
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  25. **/
  26. // SCSI disk access routines
  27. // Implements both SCSI2SD V6 disk.h functions and some extra.
  28. #pragma once
  29. #include <stdint.h>
  30. #include <scsi2sd.h>
  31. #include <scsiPhy.h>
  32. #include "ImageBackingStore.h"
  33. #include "BlueSCSI_config.h"
  34. extern "C" {
  35. #include <disk.h>
  36. #include <config.h>
  37. #include <scsi.h>
  38. }
  39. // Extended configuration stored alongside the normal SCSI2SD target information
  40. struct image_config_t: public S2S_TargetCfg
  41. {
  42. image_config_t() {};
  43. ImageBackingStore file;
  44. // For CD-ROM drive ejection
  45. bool ejected;
  46. uint8_t cdrom_events;
  47. bool reinsert_on_inquiry; // Reinsert on Inquiry command (to reinsert automatically after boot)
  48. bool reinsert_after_eject; // Reinsert next image after ejection
  49. // selects a physical button channel that will cause an eject action
  50. // default option of '0' disables this functionality
  51. uint8_t ejectButton;
  52. // For tape drive emulation, current position in blocks
  53. uint32_t tape_pos;
  54. // True if there is a subdirectory of images for this target
  55. bool image_directory;
  56. // the name of the currently mounted image in a dynamic image directory
  57. char current_image[MAX_FILE_PATH];
  58. // Index of image, for when image on-the-fly switching is used for CD drives
  59. // This is also used for dynamic directories to track how many images have been seen
  60. // Negative value forces restart from first image.
  61. int image_index;
  62. // Cue sheet file for CD-ROM images
  63. FsFile cuesheetfile;
  64. // Right-align vendor / product type strings (for Apple)
  65. // Standard SCSI uses left alignment
  66. // This field uses -1 for default when field is not set in .ini
  67. int rightAlignStrings;
  68. // Set Vendor / Product Id from image file name
  69. bool name_from_image;
  70. // Maximum amount of bytes to prefetch
  71. int prefetchbytes;
  72. // Warning about geometry settings
  73. bool geometrywarningprinted;
  74. // Clear any image state to zeros
  75. void clear();
  76. private:
  77. // There should be only one global instance of this struct per device, so make copy constructor private.
  78. image_config_t(const image_config_t&) = default;
  79. };
  80. // Should be polled intermittently to update the platform eject buttons.
  81. // Call with 'true' only if ejections should be performed immediately (typically when not busy)
  82. // Returns a mask of the buttons that registered an 'eject' action.
  83. uint8_t diskEjectButtonUpdate(bool immediate);
  84. // Reset all image configuration to empty reset state, close all images.
  85. void scsiDiskResetImages();
  86. // Close any files opened from SD card (prepare for remounting SD)
  87. void scsiDiskCloseSDCardImages();
  88. bool scsiDiskOpenHDDImage(const char *filename, int scsi_id, int scsi_lun, int block_size, S2S_CFG_TYPE type = S2S_CFG_FIXED);
  89. void scsiDiskLoadConfig(int target_idx);
  90. // Checks if a filename extension is appropriate for further processing as a disk image.
  91. // The current implementation does not check the the filename prefix for validity.
  92. bool scsiDiskFilenameValid(const char* name);
  93. // Clear the ROM drive header from flash
  94. bool scsiDiskClearRomDrive();
  95. // Program ROM drive and rename image file
  96. bool scsiDiskProgramRomDrive(const char *filename, int scsi_id, int blocksize, S2S_CFG_TYPE type);
  97. // Check if there is ROM drive configured in microcontroller flash
  98. bool scsiDiskCheckRomDrive();
  99. bool scsiDiskActivateRomDrive();
  100. // Returns true if there is at least one image active
  101. bool scsiDiskCheckAnyImagesConfigured();
  102. // Gets the next image filename for the target, if configured for multiple
  103. // images. As a side effect this advances image tracking to the next image.
  104. // Returns the length of the new image filename, or 0 if the target is not
  105. // configured for multiple images.
  106. int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buf_len);
  107. // Get pointer to extended image configuration based on target idx
  108. image_config_t &scsiDiskGetImageConfig(int target_idx);
  109. // Start data transfer from disk image to SCSI bus
  110. // Can be called by device type specific command implementations (such as READ CD)
  111. void scsiDiskStartRead(uint32_t lba, uint32_t blocks);
  112. // Start data transfer from SCSI bus to disk image
  113. void scsiDiskStartWrite(uint32_t lba, uint32_t blocks);
  114. // Returns true if there is at least one network device active
  115. bool scsiDiskCheckAnyNetworkDevicesConfigured();
  116. // Switch to next Drive image if multiple have been configured
  117. bool switchNextImage(image_config_t &img, const char* next_filename = nullptr);
  118. // For removable, non-CD based images
  119. void removableInsert(image_config_t &img);
  120. // For removable, non-CD based images
  121. void removableEject(image_config_t &img);