IDEPatch 1.23 ============= J.G.Harston 70 Camm Street, Walkley, Sheffield S6 3TR mdfs.net/Info/Comp/BBC/IDE - jgh@mdfs.net By default ADFS accesses SCSI hard drives. It can be difficult to get the SCSI host adaptor for the Master, but IDE hard drives are cheap and easily available, as are IDE Compact Flash cards. An IDE interface can be built with two ICs to allow IDE drives to be used. This program patches ADFS 1.30 for the BBC and ADFS 1.50 for the Master to access IDE drives instead of SCSI drives. Additionally, ADFS is patched to preserve context on Ctrl-Break. Normally, when pressing Ctrl-Break ADFS forgets the current directory and library and the previous directory. This can be very inconvenient, as well as annoying, particularly in deeply nested directories on a hard drive. Also, if a hard drive is present, after *MOUNT or the first time ADFS is selected, a Library directory is looked for, regardless of the setting of *Configure Dir/NoDir. To use, you need a ROM image of ADFS 1.30 or ADFS 1.50. You can do this using the supplied *SrSave command, as the built-in command on the Master does not allow you to save a sideways ROM. On the Master ADFS is in bank 13, so save the ROM image as follows: */SrSave ADFS150 8000+4000 D On the BBC use *ROMS to find the ROM number ADFS is in and save with */SrSave ADFS130 8000+4000 Once you have a ROM image, run IDEPatch. You will be asked for the name of the ROM image to load. Once entered, it will display what machine is being targetted, patch the image, and ask for a filename to save the new image. If is pressed the default filename displayed is used. You can load the new image into sideways RAM or blow it into an EPROM and plug it into a spare ROM socket. If socket 8 on the Master motherboard is free, you can use that, otherwise you could plug it into an external cartridge. On the Master disable the onboard ADFS with *Unplug 13. If ADFS is your default filing system, change it to select the new ROM with *Configure FILE where is the bank your new ADFS ROM is in. If loading the new image to RAM, you will need to simulate a power-on reset to clear the workspace with: *FX151,78,127 ADFS will report itself as version 1.03 for the Electron version, 1.33 for the BBC B/B+ version and 1.53 for the Master version. The final '3' digit indicates ADFS has IDE drivers and preserves context on Break. Pressing Ctrl-Break or Ctrl-A-Break will remember the directory context. Pressing Ctrl-F-Break resets ADFS as normally. Additionally, *INFO and *EX will display full information on directories, giving a neater display. Also, the full file access byte is stored and retrieved. Hard Drive Initialisation ========================= The program HDInit will install a blank ADFS filesystem on a hard drive. You are given a menu that includes the following options: D: Select Drive I: Investigate Drive F: Format Drive X: Exit You can also press '*' and enter *commands. Option D lets you select a drive to use. You can also select a floppy drive with 4-7 to quickly blank a disk. Option I will investigate the current drive and find out various information about it. Option F will place a blank filesystem on the selected drive. If the drive hasn't been investigated to find its size, then the size is found first. You are then asked to confirm that you want to blank the drive by entering YES in capital letters. Once you have initialised the hard drive you should reset to clear the ADFS workspace or the disk map and root directory can be corrupted. Technical Information ===================== IDEPatch changes the code that detects the presence of the SCSI host interface and access SCSI devices. It looks for an IDE interface at &FC40-&FC47. Only 8-bit transfers are performed, the high byte of each word is ignored. Consequently, a 500M drive, for example, will only be able to be initialised as a 250M ADFS drive. To the outside world ADFS acts on SCSI commands. The SCSI system is accessible by the user through OSWORD &72. The only commands that are translated to IDE commands are &08 for Read (translated to IDE command &20) and &0A for Write (translated to IDE command &30). All other actions return a result of &27 indicating Unsupported SCSI Command. IDE result codes are translated to SCSI result codes as follows: IDE result code SCSI result code &20xx Device Write Fault &03 Write fault &x180 Bad data block &19 Bad track read &x140 Data error &11 Data CRC error &x120 Media changed &28 Media changed &x110 Sector not found &10 Sector not found &x108 Media change request &02 Drive door open &x104 Abort &2F Abort &x102 Track 0 not found &06 Track 0 not found &x101 Address mark not found &12 Address mark not found &00xx OK &00 OK &7F Unknown IDE result &27 Unsupported SCSI command Note that what is not made clear in much documentation is that bit 6 of the result returned from the disk access API (OSWORD &72 etc.) indicates the source. It is 0 for a hard drive error (giving &00-&3F) and 1 for a floppy error (giving &40-&7F). So, for example, error &10 is Sector not found on a hard drive, and &50 is Sector not found on a floppy. The exceptions are &00 for Ok and &7F for unknown error. The IDE device is accessed using CHS addressing - Cylinder, Head, Sector - with the geometry set to 64 sectors per track and 4 heads. This makes it easier to address the drive as divides and multiplies are avoided. IDE drive 0 is accessed by ADFS drive 0 and 1, IDE drive 1 is accessed by ADFS drive 2 and 3. Drive 0 and 2 access the first 512M of the drive, and drive 1 and 3 access the second 512M of each drive, allowing up to 4G of accessible hard drive space. For example, a 1600M hard drive will be seen as a 512M drive followed by a 288M drive. Future ADFS patches may access a RAM card with drive 6 or 7. The highest sector addressable by an IDE device is &FFFFFFF, giving access to 64G using 256-byte sectors. However, the highest sector addressed by ADFS's SCSI subsystem is &1FFFFF, giving 512M per logical drive using 256-byte sectors. Documentation is also unclear on the various Break effects. If *fadfs is used or F-Break is pressed then the current context is abandoned, all drives are unmounted and everything is set to an "unset" state. If *adfs, service call &12,8 or A-Break is used (or Break where ADFS is the default filing system) then the current context is preserved and the drive, directory and library are as before Break was pressed. On Power-On a default context of :0.$ is mounted. Of particular note is that Shift-Break does not change the current drive and directory, it boots from the currently-selected disk with the directory set to the current directly. If you do *MOUNT 1 then Shift-Break then :1.$.!Boot will be booted. If you want the $.!Boot file to start with the CSD set to $ you must explicitly include a *DIR $ command. IDE ADFS works with the 80x86 second processor. However, the GEM DOSBOOT and 6502.SYS code accesses the I/O hardware directly looking for a SCSI disk controller, so does not work correctly without being patched. IDE ADFS works correctly with the 32016 second processor from Pandora (eg within Bas32), but Panos does not boot correctly. ADFS Version Numbers ==================== ADFS 1.0x is ADFS for the Electron. ADFS 1.3x is ADFS for the BBC B or BBC B+. ADFS 1.5x is ADFS for the Master. The final digit is a bitmap indicating the hard drive hardware used: %abcd |||+---preserve context on Break and various bugfixes |00----SCSI drivers |01----IDE drivers |10----reserved |11----User port MMC drivers +------reserved, zero This gives: v1.03 for Electron IDE ADFS v1.33 for BBC IDE ADFS v1.53 for Master IDE ADFS The final byte of the ROM image is a BCD number that indicates IDEPatch program version that created it. Version History =============== 09-Sep-2002 v1.00 JGH: Ctrl-Break doesn't reset directory context. 03-Jul-2004 v1.10 JGH: Accesses IDE hard drives. 04-Nov-2004 v1.11 JGH: Fuller testing with IDE hardware. 25-Nov-2004 v1.12 JGH: Partially working using multiple sector access. 12-Dec-2004 v1.13 JGH: Accesses one sector at a time. 15-Dec-2004 v1.14 JGH: Each sector accessed twice to avoid DRQ bug. 17-Dec-2004 v1.15 JGH: SetGeometry sets correct drive. 27-Dec-2004 v1.16 JGH: Autofinds Library. 23-Feb-2005 v1.17 JGH: Access four drives on two devices. Doesn't wait for spin-up on power-on. 28-Apr-2005 v1.18 JGH: Removed test offset code. 15-May-2005 v1.19 JGH: Full access byte stored. 15-Aug-2005 v1.20 JGH: Unrecognised OSFILE returns A preserved. 23-Feb-2016 v1.21 JGH: Added optimisations from MMC code. 18-Apr-2016 v1.22 JGH: Combined BBC/Master patch programs. 18-May-2017 v1.23 JGH: Corrected unsupported OSFILE to work on BBC. Added delays to Tube transfers to work on 32016 CoPro.