ZuluSCSI_disk.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. *
  6. * It is derived from disk.h in SCSI2SD V6.
  7. *
  8. * This file is licensed under the GPL version 3 or any later version. 
  9. *
  10. * https://www.gnu.org/licenses/gpl-3.0.html
  11. * ----
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version. 
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. * GNU General Public License for more details. 
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  24. **/
  25. // SCSI disk access routines
  26. // Implements both SCSI2SD V6 disk.h functions and some extra.
  27. #pragma once
  28. #include <stdint.h>
  29. #include <scsi2sd.h>
  30. #include <scsiPhy.h>
  31. #include "ImageBackingStore.h"
  32. #include "ZuluSCSI_config.h"
  33. extern "C" {
  34. #include <disk.h>
  35. #include <config.h>
  36. #include <scsi.h>
  37. }
  38. // Extended configuration stored alongside the normal SCSI2SD target information
  39. struct image_config_t: public S2S_TargetCfg
  40. {
  41. // There should be only one global instance of this struct per device, so disallow copy constructor.
  42. image_config_t() = default;
  43. image_config_t(const image_config_t&) = delete;
  44. ImageBackingStore file;
  45. // For CD-ROM drive ejection
  46. bool ejected;
  47. uint8_t cdrom_events;
  48. bool reinsert_on_inquiry; // Reinsert on Inquiry command (to reinsert automatically after boot)
  49. bool reinsert_after_eject; // Reinsert next image after ejection
  50. // selects a physical button channel that will cause an eject action
  51. // default option of '0' disables this functionality
  52. uint8_t ejectButton;
  53. // For tape drive emulation, current position in blocks
  54. uint32_t tape_pos;
  55. // True if there is a subdirectory of images for this target
  56. bool image_directory;
  57. // the name of the currently mounted image in a dynamic image directory
  58. char current_image[MAX_FILE_PATH];
  59. // Index of image, for when image on-the-fly switching is used for CD drives
  60. // This is also used for dynamic directories to track how many images have been seen
  61. uint8_t 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. // Maximum amount of bytes to prefetch
  69. int prefetchbytes;
  70. // Warning about geometry settings
  71. bool geometrywarningprinted;
  72. };
  73. // Should be polled intermittently to update the platform eject buttons.
  74. // Call with 'true' only if ejections should be performed immediately (typically when not busy)
  75. // Returns a mask of the buttons that registered an 'eject' action.
  76. uint8_t diskEjectButtonUpdate(bool immediate);
  77. // Reset all image configuration to empty reset state, close all images.
  78. void scsiDiskResetImages();
  79. // Close any files opened from SD card (prepare for remounting SD)
  80. void scsiDiskCloseSDCardImages();
  81. bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int scsi_lun, int blocksize, S2S_CFG_TYPE type = S2S_CFG_FIXED);
  82. void scsiDiskLoadConfig(int target_idx);
  83. // Checks if a filename extension is appropriate for further processing as a disk image.
  84. // The current implementation does not check the the filename prefix for validity.
  85. bool scsiDiskFilenameValid(const char* name);
  86. // Clear the ROM drive header from flash
  87. bool scsiDiskClearRomDrive();
  88. // Program ROM drive and rename image file
  89. bool scsiDiskProgramRomDrive(const char *filename, int scsi_id, int blocksize, S2S_CFG_TYPE type);
  90. // Check if there is ROM drive configured in microcontroller flash
  91. bool scsiDiskCheckRomDrive();
  92. bool scsiDiskActivateRomDrive();
  93. // Returns true if there is at least one image active
  94. bool scsiDiskCheckAnyImagesConfigured();
  95. // Gets the next image filename for the target, if configured for multiple
  96. // images. As a side effect this advances image tracking to the next image.
  97. // Returns the length of the new image filename, or 0 if the target is not
  98. // configured for multiple images.
  99. int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buflen);
  100. // Get pointer to extended image configuration based on target idx
  101. image_config_t &scsiDiskGetImageConfig(int target_idx);
  102. // Start data transfer from disk image to SCSI bus
  103. // Can be called by device type specific command implementations (such as READ CD)
  104. void scsiDiskStartRead(uint32_t lba, uint32_t blocks);
  105. // Start data transfer from SCSI bus to disk image
  106. void scsiDiskStartWrite(uint32_t lba, uint32_t blocks);