OSWORD &72

From BeebWiki
Jump to: navigation, search

OSWORD &72 (114) - Perform SCSI/MFM disk operation

Specification

   On entry:
       XY?0  = 0, returned result
       XY!1  = data address
       XY?5  = command
       XY?6  = drive number in b5-b7, sector b16-b20 in b0-b4
       XY?7  = sector number b8-b15
       XY?8  = sector number b0-b7
       XY?9  = number of sectors or 0
       XY?10 = 0
       XY!11 = data length if X%?9=0

This is a standard SCSI command block. The drive number in XY?6 is ORed with the current drive. If ADFS is not selected when the call is made, ADFS is selected. Consequently, any code that calls OSWORD &72 must remember the current filing system and restore it afterwards. In practice ADFS must be done before calling OSWORD &72 as the internal selection code can often leave the hardware and driving code in an insufficiently consistant enough state to function correctly, and will also try to mount the current disk which will fail if is not a actually formatted to ADFS.

Selecting ADFS must be done with *FADFS and not *ADFS or *FX143,18,8 to avoid trying to mount the disk.

Bear in mind that drives 0-3 are only floppy drives if there are no hard drives present. Drives 4-7 are always floppy drives, if code must access floppy drives it must always use drives 4-7.

OSWORD &72 can read data from disks with sector sizes other than 256 bytes, but the passed sector number must be 16*track+sector, and it is best to read only one sector at a time when doing so. For example disks formatted to five sectors of 1024 bytes can be read (such as SJ MDFS, ADFS F), sector 0 on track 1 on side 0 is read as sector 16, sector 0 on track 0 on side 1 is read as sector 1280 (ie 80*16+0).

Commands

   &00 Test drive ready *
   &01 Restore to track zero *
   &02 reserved
   &03 Request sense status (SCSI result) *
   &04 Format drive
   &05 Check track format
   &06 Format track
   &07 Format bad track
   &08 Read data *
   &09 Read Verify
   &0A Write data *
   &0B Seek track *
   &0C Initialise drive characteristics
   &0D Read ECC burst error length
   &0E Format Alternative Track
   &0F Write Sector Buffer
   &10 Read Sector Buffer
   &12 Read device identity string
   &15 Write drive characteristics
   &1A Read drive characteristics
   &1B Park heads/Start/stop unit; stop if XY?9=0, start if XY?9=1 *
   &2F Verify drive
   
   &70 RAM diagnostic
   &71 reserved
   &72 reserved
   &73 Drive diagnostic
   &74 Controller internal diagnostics
   &75 Read long
   &76 Write long
   
   &E0 RAM Diagnostic
   &E1 Reserved
   &E2 Reserved
   &E3 Drive Diagnostic
   &E4 Controller Internal Diagnostics
   &E5 Read Long
   &E6 Write Long
   &E7 Retry Statistics

Commands marked with * are listed in Acorn documentation.

Results

   &00 Ok
   &01 No index - is drive formatted?
   &02 Drive door open/Seek error/Seek not completed
   &03 Write fault/Media error (disc dirty)
   &04 Drive not ready
   &05 Malformed SCSI command
   &06 Track 0 not found
                                                  &40 Write protected (FDC status &40)
                                                  &48 CRC error (FDC status &08)
   &10 ID CRC error - sector not found            &50 Sector not found (FDC status &10)
   &11 Data CRC error
   &12 ID address mark not found
   &13 Data address mark not found - sector found but no data
   &14 Record not found - Sector not found
   &15 Seek error - Track not found
   &16 unused
   &17 unused
   &18 Correctable data error
   &19 Verify error/Bad Track flag set in track accessed
   &1A Interleave error/Format error
   &1B unused
   &1C Unformatted or bad format (eg no ADFS partitions)
   &1D Self test failed
   &1E Defective track
   &1F unused
   
   &20 Invalid command to controller              &60 Bad SCSI command
   &21 Illegal disc address - beyond end of disk  &61 Bad disc address
   &22 unused
   &23 Volume error                               &63 Volume error
   &24 Invalid parameter to controller            &64 Bad arguments
   &25 Illegal drive number                       &65 Bad drive
   &26 Invalid field in parameter list/Timeout    &66 Drive timed out
   &27 Unsupported controller command             &67 Unsupported SCSI command
   &28 Media changed
   &29
   &2A
   &2B
   &2C Error count overflow
   &2D
   &2E
   &2F Abort                                      &6F Abort
   
   &30 Controller RAM error
   &31 Controller program memory CRC error
   &33 Controller polynominal error
   
   &7F Unknown SCSI result

The result byte can be preloaded with a value to return if no OSWORD &72 routine exists. For instance, preloading the result with &00 makes all such failed calls appear to succeed, preloading with &50 makes all calls appear to return 'Sector not found'.

Acorn documentation is inconsistant about the range of the returned result. What is not made clear is that bit 6 is used to indicate if the error is from the hard drive controller or the floppy controller. Floppy errors are the same as hard drive errors, ORed with &40. Floppy errors are also the 1770 status byte ORed with &40.

The floppy drivers only respond to &08 (Read), &0A (Write) and &0B (Seek). Any other command will return &67 (Floppy: Unsupported SCSI command). Drivers for non-SCSI devices (such as IDE or MMC drivers) must return their results as the appropriate result from this table.

Coding

The following routine can be used to perform an OSWORD &72 call. It requires X%=>15-byte control block, Y%=X%DIV256.

   DEFFNscsi(addr%,cmd%,drv%,sect%,num%):LOCALfs%
   fs%=FNfs:IFfs%<>8:*FADFS
   X%?0=0:X%!1=addr%:X%?5=cmd%:X%?6=drv%*32+((sect%AND&1F0000)DIV65536)
   X%?7=((sect%AND&FF00)DIV256):X%?8=sect%:X%!9=num%:X%!11=0
   A%=&72:CALL&FFF1:A%=?X%:IFfs%<>8:OSCLI"FX143,18,"+STR$fs%
   =A%
   DEFFNfs:LOCALA%,E%,Y%:=(USR&FFDA)AND&FF

Cumana Electron DFS disk access

The Cumana Double Densisty Electron DFS implments the following OSWORD &72 call:

   On entry:
       XY?0  = Control byte,
               b0: side select 0,1
               b1: drive 1 select
               b2: drive 2 select
               b3: 0=double density, 1=single density
       XY?1  = command
       XY?2  = track
       XY?3  = sector
       XY?4  = data
       XY!5  = address
       XY?9  = 0, holds result on exit

Commands

   &04=Seek track zero
   &14=Seek track
   &50=Step in one track
   &70=Step out one track
   &80=Read sector
   &A0=Write sector
       b0-b1=step rate 6ms/12ms/20ms/30ms

Results

   XY?2=new track
   XY?3=new sector
   XY?9=result
        &00=Ok
        &08=CRC error
        &10=Sector not found
        &40=Write protected

See Also

WikiSysop (talk) 13:44, 8 March 2015 (UTC)