Announcement

Collapse
No announcement yet.

Disk Access Routines - Re-POST

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Disk Access Routines - Re-POST

    All,

    Someone had recently sent me an email asking me to repost this information. I thought that I had already done this but didn't see it when I did a search. So here it is.
    Code:
    'X13 Disk Interrupt Vectors
    %CMD_RESET_DISK				= 0
    %CMD_INSTALLED				= 1
    %CMD_STATUS				= 1
    %CMD_READ_SECTOR			= 2
    %CMD_WRITE_SECTOR			= 3
    %CMD_VERIFY_SECTOR			= 4
    %CMD_LOCK_UNLOCK			= 5
    %CMD_EJECT_MEDIA			= 6
    %CMD_EXTENDED_SEEK			= 7
    %CMD_GET_PARAMETERS			= 8
    %CMD_EXT_MEDIA_CHANGE			= 9
    %CMD_SET_HARDWARE_CONFIG		= &HE
    
    
    'X13 Command Vectors
    'Set Hardware Configuration
    %ENABLE_PREFETCH			= &H00
    %DISABLE_PREFETCH			= &H01
    %SET_MAX_PIO_MODE			= &H02
    %SET_PIO_MODE_0				= &H03
    %SET_DEFAULT_PIO_MODE			= &H04
    %ENABLE_INT13_MAX_DMA_MODE		= &H05
    %DISABLE_INT13_DMA_MODE			= &H06
    
    'DOS Interrupt Call
    %INT13		= &H13
    
    
    TYPE X13Buffer
      PacketSize       AS BYTE     ' size of returned data structure
      Reserved         AS BYTE     'duh
      BlocksToTransfer AS WORD     'Number of sectors to transfer
      TransferBuffer   AS BYTE PTR 'Pointer to Transfer Buffer
      StartingBlock    AS QUAD     'Sector to transfer from
    END TYPE	
    
    FUNCTION XInt13(X13Command AS BYTE, BYVAL Buffer AS DWORD, Drive AS STRING, StartingSector AS QUAD, NumberOfSectors AS WORD) AS INTEGER
    DIM DriveNum AS INTEGER
    DIM Segment AS WORD
    DIM Offset AS WORD
    
      DriveNum% = ASCII(UCASE$(Drive$)) - 64
    
      IF DriveNum% < 3 THEN
        DriveNum% = 3
      ELSE
        DriveNum% = DriveNum% + 125
      END IF
    
    AXRegister% = X13Command? + &H40
    SHIFT LEFT AXRegister%, 8
    
    SELECT CASE X13Command?
      CASE %CMD_INSTALLED
        REG %BX,&H55AA
    
      CASE %CMD_READ_SECTOR, %CMD_WRITE_SECTOR
        IF (NumberOfSectors?? = 0) OR (NumberOfSectors?? = 1) THEN
          DIM SectorBuffer AS X13Buffer
        ELSE
          DIM SectorBuffer(NumberOfSectors - 1) AS X13Buffer
        END IF
    
        SectorBuffer.PacketSize?        = &H10
        SectorBuffer.Reserved?          = 0
        SectorBuffer.BlocksToTransfer?? = NumberOfSectors??
        SectorBuffer.TransferBuffer     = Buffer
        SectorBuffer.StartingBlock&&    = StartingSector&&
    
        REG %DS,VARSEG(SectorBuffer)
        REG %SI,VARPTR(SectorBuffer)
    
      CASE %CMD_GET_PARAMETERS
        Offset?? = BITS??(Buffer???)
        ROTATE RIGHT Buffer???, 16
        Segment?? = BITS??(Buffer???)
    
        REG %DS,Segment??
        REG %SI,Offset??
    
      CASE %CMD_SET_HARDWARE_CONFIG
        AXRegister% = X13Command + &H5E
        SHIFT LEFT AXRegister%, 16
    
      CASE ELSE
    END SELECT
    
    REG %DX,DriveNum%
    REG %AX,AXRegister%
    
    CALL INTERRUPT %INT13
    
    CarryFlag% = REG(%FLAGS)
    AXRegister% = REG(%AX)
    BXRegister% = REG(%BX)
    CarryFlag% = BIT(CarryFlag%, 0)
    IF CarryFlag% THEN
      IF (X13Command = %CMD_INSTALLED) AND (BXRegister% <> &HAA55) THEN
        FUNCTION = %False
      ELSE
        IF INSTR(UCASE$(COMMAND$), "DEBUG") THEN
          SHIFT RIGHT AXRegister%, 8
          CALL DiskStatus(ByCopy Register%)
        END IF
      END IF
      FUNCTION = %False
    END IF
    
    FUNCTION = %True
    END FUNCTION
    
    SUB DiskStatus(StatusCode AS WORD)
    PRINT
    PRINT "Disk Operation StatusCode(";StatusCode;") ";
    SELECT CASE StatusCode
      CASE &H00
        PRINT "returned successfully completed"
      CASE &H01
        PRINT "caused an invalid function in AH or an invlaid parameter"
      CASE &H02
        PRINT "returned address mark not found"
      CASE &H03
        PRINT "disk write-protected"
      CASE &H04
        PRINT "sector not found/read error"
      CASE &H05
        PRINT "reset failed (hard disk)"
      CASE &H06
        PRINT "disk changed (floppy or removable)"
      CASE &H07
        PRINT "drive paramter activity failed (hard disk)"
      CASE &H08
        PRINT "DMA overrun"
      CASE &H09
        PRINT "data boundary error (attempted DMA across 64K boundary or > 80h sectors"
      CASE &H0A
        PRINT "bad sector detected (hard disk)"
      CASE &H0B
        PRINT "bad track detected (hard disk)"
      CASE &H0C
        PRINT "unsupported track or invalid media"
      CASE &H0D
        PRINT "invalid number of sectors on format"
      CASE &H0E
        PRINT "control data address mark detected (hard disk)"
      CASE &H0F
        PRINT "DMA arbitration level out of range (hard disk)"
      CASE &H10
        PRINT "uncorrectable CRC or ECC error on read"
      CASE &H11
        PRINT "data ECC corrected (hard disk)"
      CASE &H20
        PRINT "controller failure"
      CASE &H31
        PRINT "no media in drive (IBM/MS Int13 extensions)"
      CASE &H40
        PRINT "seek failed"
      CASE &H80
        PRINT "timeout (not ready)"
      CASE &HAA
        PRINT "drive not ready (hard disk)"
      CASE &HB0
        PRINT "volume not locked in drive (XInt13)"
      CASE &HB1
        PRINT "volume locked in drive (XInt13)"
      CASE &HB2
        PRINT "volume not removable (XInt13)"
      CASE &HB3
        PRINT "volume in use (XInt13)"
      CASE &HB4
        PRINT "lock count exceeded (XInt13)"
      CASE &HB5
        PRINT "valid eject request failed (Xint13)"
      CASE &HBB
        PRINT "undefined error (hard disk)"
      CASE &HCC
        PRINT "write fault (hard disk)"
      CASE &HE0
        PRINT "status register error (hard disk)"
      CASE &HFF
        PRINT "sense operation failed (hard disk)"
    
    END SELECT
    END SUB

    [This message has been edited by Mark Collins (edited January 24, 2003).]

    * UBB [code] tags added by Administrator
Working...
X