; XCDROM.ASM    Written 8-Feb-2006 by Jack R. Ellis.
;
; XCDROM is free software.  You can redistribute and/or modify it under
; the terms of the GNU General Public License (hereafter called GPL) as
; published by the Free Software Foundation, either version 2 of GPL or
; any later versions at your option.  XCDROM is distributed in the hope
; that it will be useful, but WITHOUT ANY WARRANTY and without even the
; implied warranties of MERCHANTABILITY nor of FITNESS FOR A PARTICULAR
; PURPOSE!   See the GPL for details.   You should have received a copy
; of the GPL with your XCDROM files.  If not write to the Free Software
; Foundation Inc., 59 Temple Place Ste. 330, Boston, MA 02111-1307 USA.
; http://www.gnu.org/licenses/
;
; This is a DOS driver for 1 to 3 CD-ROM drives on PC mainboards having
; a VIA VT8235 or similar chipset.   On loading, XCDROM checks both IDE
; channels for CD-ROM drives and runs all the drives it finds.   It has
; switch options (see below) to indicate a desired "driver name" and to
; override its "IDE order" search and check for specific CD-ROM drives.
; XCDROM accepts requests from a "CD-ROM redirector" (SHCDX33A, MSCDEX,
; etc.) for the CD-ROM drive.   If the XDMA disk driver (V3.1 or later)
; is also present and is using output overlap, XCDROM shall synchronize
; all I-O activity on its drive with XDMA I-O.    This lets XDMA output
; overlap be used even where an UltraDMA hard-disk and the CD-ROM drive
; are sharing the same IDE channel!    Also, if V3.1+ XDMA with overlap
; or any V3.0+ XDMA/XDMAJR driver is present, a CD-ROM drive capable of
; UltraDMA will be enabled for it.   XCDROM can be run with older XDMA/
; UDMA2/UDMA drivers or "stand-alone", in which case it will scan for a
; mainboard UltraDMA controller by itself.    If one is found, a CD-ROM
; drive capable of UltraDMA will also be enabled for it.   Other XCDROM
; features are the same as for any DOS CD-ROM driver.   XCDROM does not
; use interrupts and is only for "legacy" IDE channels at I-O addresses
; 01F0h (primary) and 0170h (secondary).
;
; XCDROM switch options are as follows:
;
;    /AX   Excludes ALL audio functions.   This makes the driver report
;	     on a Device-Status request that it reads DATA tracks only!
;	     /AX reduces the resident driver by 448 bytes.    UltraDMA,
;	     multi-drives, and other driver features are NOT affected!
;
;    /D:   Specifies the desired "device name" which SHCDX33A or MSCDEX
;	     will use during their initialization to address the CD-ROM
;	     drives.   Examples are:  /D:CDROM1  /D:MYCDROM  etc.   The
;	     device name must be from 1 to 8 bytes valid for use in DOS
;	     filenames.   If /D: is omitted, or the "device name" after
;	     a /D: is missing or invalid, "XCDROM" will be the default.
;
;    /L    Limits UltraDMA to "low memory" below 640K.   /L is REQUIRED
;	     to use UMBPCI or a similar driver whose upper-memory areas
;	     cannot do UltraDMA.   If /L is given, the driver must load
;	     in LOW memory so its DMA command-lists can fetch preperly,
;	     or driver loading will ABORT!   /L causes any I-O requests
;	     above 640K to use "PIO mode" input.   Note that /L will be
;	     IGNORED if /UX is also given.
;
;    /Mn   Specifies the MAXIMUM UltraDMA "mode" to be set for a CD-ROM
;	     drive, where  n  is a number between 0 and 6, as follows:
;		 0 = ATA-16, 16 MB/sec.    4 = ATA-66,   66 MB/sec.
;		 1 = ATA-25, 25 MB/sec.    5 = ATA-100, 100 MB/sec.
;		 2 = ATA-33, 33 MB/sec.    6 = ATA-133, 133 MB/sec.
;		 3 = ATA-44, 44 MB/sec.
;	     A CD-ROM drive designed to use "modes" LESS than the given
;	     value will be limited to its own highest "mode".   /M will
;	     be IGNORED for CD-ROM drives which cannot do UltraDMA, and
;	     it will be ignored for ALL drives if /UX is also given.
;
;    /PM   Requests the driver to check the IDE primary-master unit for
;	     a CD-ROM drive during driver init.    If a CD-ROM drive is
;	     NOT found as primary-master, driver loading will ABORT!
;
;    /PS   Same as /PM but tests the primary-slave unit only.
;
;    /SM   Same as /PM but tests the secondary-master unit only.
;
;    /SS   Same as /PM but tests the secondary-slave unit only.
;
;	     --- NOTE ---
;	     Using multiple drives, multiple  /PM /PS /SM /SS  switches
;	     can be given.    The first-specified drive is addressed as
;	     "unit 0", the second as "unit 1", etc.   If fewer switches
;	     than drives are given, the unreferenced drives will NOT be
;	     used.    If NO such switches are given, the driver "scans"
;	     for CD-ROM drives, from primary-master to secondary-slave.
;	     The first drive found will be "unit 0", the second will be
;	     "unit 1", etc.
;
;    /UF   Enables "Fast UltraDMA".   Data input requests that cross an
;	     UltraDMA "64K boundary" are executed using a 2-element DMA
;	     command list, one for data up to the boundary, and one for
;	     data beyond it.   CD-ROM speed is increased significantly.
;	     "PIO mode" input is still needed for user buffers that are
;	     misaligned (not at an even 4-byte address).    /UF will be
;	     IGNORED for CD-ROM drives which cannot do UltraDMA.
;
;	     --- NOTE ---
;	     Despite any UltraDMA specs, NOT ALL chipsets or mainboards
;	     can run multi-element DMA commands properly!   Although it
;	     is valuable, /UF must be TESTED on every system, and "Fast
;	     UltraDMA" should be enabled with CARE!!
;
;    /UX   Disables ALL UltraDMA, even for CD-ROM drives capable of it.
;	     The driver then uses "PIO mode" for all data input.    /UX
;	     should be needed only for tests and diagnostic work.
;
; For each switch, a dash may replace the slash, and lower-case letters
; may be used.
;
;
; Revision History:
; ----------------
;  V2.4   6-Feb-07       Modified "Legacy" IDE Primary and Secondary address, and ;                        DMA Interrupt value.
;  V2.2   8-Feb-06  JRE  Corrected DVD handling and "regular" UltraDMA.
;  V2.1  31-Jan-06  JRE  Deleted init "Set Mode" commands (BIOS will do
;			   them anyway) to avoid conflicts.
;  V2.0  27-Jan-06  JRE  Startup and seek timeouts increased.  Added up
;			   to ATA-133 support.  Minor size reductions.
;  V1.9  20-Jan-06  JRE  Fixed errors in Multi-Session and I-O logic.
;  V1.8  17-Jan-06  JRE  Fixed Multi-Session "TOC input" to support ALL
;			   drives, added a drive "reset" on I-O errors.
;  V1.7  14-Jan-06  JRE  Updated XCDROM to read a "Multi Session" disk.
;  V1.6  10-Jan-06  JRE  XCDROM now has stand-alone UltraDMA capability
;			   and no longer requires XDMA/XDMAJR!   "Audio
;			   Busy" status is now updated on ALL requests.
;  V1.5   5-Jan-06  JRE  Fixed "Audio Status" & /AX device-status flags
;			   and added support for up to 3 CD-ROM drives.
;  V1.4   2-Jan-06  JRE  Initial release, added /AX and dual drives.
;  V1.3  30-Dec-05  JRE  4th "Beta" issue, uses V3.1+ XDMA "OCheck".
;  V1.2  23-Dec-05  JRE  3rd "Beta" issue, new /UF and /UX switches.
;  V1.1  15-Dec-05  JRE  2nd "Beta" issue, improved XDMA linkage.
;  V1.0  14-Dec-05  JRE  Original "Beta" XCDROM issue.
;
