ZuluSCSI_disk.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. extern "C" {
  33. #include <disk.h>
  34. #include <config.h>
  35. #include <scsi.h>
  36. }
  37. // Extended configuration stored alongside the normal SCSI2SD target information
  38. struct image_config_t: public S2S_TargetCfg
  39. {
  40. // There should be only one global instance of this struct per device, so disallow copy constructor.
  41. image_config_t() = default;
  42. image_config_t(const image_config_t&) = delete;
  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. // Index of image, for when image on-the-fly switching is used for CD drives
  55. int image_index;
  56. // Cue sheet file for CD-ROM images
  57. FsFile cuesheetfile;
  58. // Right-align vendor / product type strings (for Apple)
  59. // Standard SCSI uses left alignment
  60. // This field uses -1 for default when field is not set in .ini
  61. int rightAlignStrings;
  62. // Maximum amount of bytes to prefetch
  63. int prefetchbytes;
  64. // Warning about geometry settings
  65. bool geometrywarningprinted;
  66. };
  67. // Should be polled intermittently to update the platform eject buttons.
  68. // Call with 'true' only if ejections should be performed immediately (typically when not busy)
  69. // Returns a mask of the buttons that registered an 'eject' action.
  70. uint8_t diskEjectButtonUpdate(bool immediate);
  71. // Reset all image configuration to empty reset state, close all images.
  72. void scsiDiskResetImages();
  73. // Close any files opened from SD card (prepare for remounting SD)
  74. void scsiDiskCloseSDCardImages();
  75. bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int scsi_lun, int blocksize, S2S_CFG_TYPE type = S2S_CFG_FIXED);
  76. void scsiDiskLoadConfig(int target_idx);
  77. // Clear the ROM drive header from flash
  78. bool scsiDiskClearRomDrive();
  79. // Program ROM drive and rename image file
  80. bool scsiDiskProgramRomDrive(const char *filename, int scsi_id, int blocksize, S2S_CFG_TYPE type);
  81. // Check if there is ROM drive configured in microcontroller flash
  82. bool scsiDiskCheckRomDrive();
  83. bool scsiDiskActivateRomDrive();
  84. // Returns true if there is at least one image active
  85. bool scsiDiskCheckAnyImagesConfigured();
  86. // Check if image file name is overridden in config,
  87. // including image index for multi-image CD-ROM emulation
  88. bool scsiDiskGetImageNameFromConfig(image_config_t &img, char *buf, size_t buflen);
  89. // Get pointer to extended image configuration based on target idx
  90. image_config_t &scsiDiskGetImageConfig(int target_idx);
  91. // Start data transfer from disk image to SCSI bus
  92. // Can be called by device type specific command implementations (such as READ CD)
  93. void scsiDiskStartRead(uint32_t lba, uint32_t blocks);
  94. // Start data transfer from SCSI bus to disk image
  95. void scsiDiskStartWrite(uint32_t lba, uint32_t blocks);