AUTOIDE.ASM - R02. It is possible that ATAPI auto-detection began to work correctly.

This commit is contained in:
Anatoliy Belyanskiy 2023-08-17 02:51:28 +10:00
parent 07a21f3978
commit dec9cb50d1

View File

@ -1,9 +1,14 @@
;
;R01 01.08.2001 FIX BUG INT "SELECT_IDE"
;R00 24.07.2001 ADD SECONDARY IDE
;INITIAL NEW VERSION (2.48) 24.07.2001
;========================================================
;[BEGIN]
;//MODULE: AUTOIDE
;//CREATE: 27-07-2001 AUTHOR: Denis Parinov
;-----------------------------------------------------------------------
;Rev Date Name Description
;-----------------------------------------------------------------------
;R02 17.08.2023 BAO Fixed bug with AUTODETECT ATAPI Drives
;R01 01.08.2001 DNS FIX BUG INT "SELECT_IDE"
;R00 24.07.2001 DNS ADD SECONDARY IDE
; 24.07.2001 DNS INITIAL NEW VERSION 2.48
;=======================================================================
; MODULE AUTOIDE
/*
@ -100,35 +105,37 @@ CDAUTO:
SELECT_IDE:
AND A ;%0000'0011
LD D,#A0
JR Z,IAUTO0
LD D,IDE.ATA.Master
JR Z,.AUTO_0
DEC A
LD D,#B0
JR Z,IAUTO0
JR Z,.AUTO_0
DEC A
LD D,#A0 ;R00
JR Z,IAUTO1 ;R00
DEC A ;R00
LD D,#B0 ;R00
IAUTO1: LD A,IDE.Chanel.Secondary ;R00 ;SELECT SECONDARY
OUT (IDE.Chanel.Set),A ;R00
;LD A,1
JP IAUTO ;R00
IAUTO0:
LD A,IDE.Chanel.Primary ;R00 ;SELECT PRIMARY
OUT (IDE.Chanel.Set),A ;R00
;LD A,0
;R00
LD D,IDE.ATA.Master
JR Z,.AUTO_1
DEC A
LD D,IDE.ATA.Slave
.AUTO_1: LD A,IDE.Chanel.Secondary ;SELECT SECONDARY
OUT (IDE.Chanel.Set),A
;LD A,1
JP .AUTO
.AUTO_0: LD A,IDE.Chanel.Primary ;SELECT PRIMARY
OUT (IDE.Chanel.Set),A
;
;LD A,0
XOR A
IAUTO: LD (ICHANEL),A
LD BC,IDE.Write.DriveCtrl ;R01
OUT (C),D ;R01
.AUTO: LD (ICHANEL),A
;R01
LD BC,IDE.Write.DriveCtrl
OUT (C),D
;
RET
IDEAUTO:
CALL SELECT_IDE
;MASTER
LD A,#FF
LD A,IDE.Device.NONE
LD (IDEDEV),A
CDMASTR:
LD (SKIP),A
@ -177,15 +184,72 @@ NO_BUSY:
; 1 select device (port+6)
; 2 read status byte(port+7) if =-1 then there is no disk
; if busy to many time then no disk
; 3 send id command 0ec0h if error then send packet device id command
; 0a1h if error then no disk.
; 3 send id command #ec if error then send packet device id command
; #a1 if error then no disk.
; commands must be send byte by byte dword operations are used only for data transfers.
;CP IDE.Device.NONE
;JR NZ,1F
;R02
CP IDE.Device.NONE
JR NZ,.check_next
;JP NZ,DETECT_ATA_ATAPI
;
1: CP IDE.Device.CDROM
JP Z,NOHDD ;¯à¨  ¢â®¤¥â¥ªâ¥, ¥á«¨ âãâ CD, â® ­¨ª®£¤  ­¥ ¡ã¤¥â ¯¥à¥å®¤  ­  NOHDD
DETECT_ATA_ATAPI: ;R02
; 1. Set the Sectorcount, LBAlo, LBAmid, and LBAhi IO ports to 0 (port 0x1F2 to 0x1F5).
LD BC,IDE.Write.Counter
OUT (C),0 ;out0-ok
INC C ;IDE.Write.Sector
OUT (C),0 ;out0-ok
INC C ;IDE.Write.CylinderLow
OUT (C),0 ;out0-ok
INC C ;IDE.Write.CylinderHigh
OUT (C),0 ;out0-ok
;
; 2. Send the IDENTIFY command (0xEC) to the Command IO port (0x1F7).
LD BC,IDE.Write.Command
LD E,ATA_IDENTIFY_DEVICE
OUT (C),E
;
; 3. Read the Status port (0x1F7) again.
LD B,0
.pause: DJNZ .pause
; 3.1 If the value read is 0, the drive does not exist.
LD BC,IDE.Read.Status
IN A,(C)
JP Z,ABSENT
; 3.2 For any other value: poll the Status port (0x1F7) until bit 7 (BSY, value = 0x80) clears.
LD HL,WAIT_SML
LD DE,#8000
CALL WAIT_PRT
JP C,ABSENT
; 3.3 At this point you need to check the LBAmid and LBAhi ports (0x1F4 and 0x1F5) to see
; if they are non-zero. If so, the drive is not ATA, and you should stop polling.
LD BC,IDE.Read.CylinderLow
IN A,(C)
INC C ;IDE.Read.CylinderHigh
IN B,(C)
OR B
JP NZ,NOHDD ; IT IS ATAPI
; 3.5 Otherwise, continue polling one of the Status ports until bit 3 (DRQ, value = 8) sets, or until bit 0 (ERR, value = 1) sets.
LD HL,WAIT_SML
LD DE,#0101 ;!FIXIT
CALL WAIT_PRT
JP NC,ABSENT
;
; 4. At that point, if ERR is clear, the data is ready to read from the Data port (0x1F0). Read 256 16-bit values, and store them.
LD A,IDE.Device.HDD
LD (IDEDEV),A
JP GETPARM
;
;;;;;;;;;;;;;;;;;;;;;;; R02
NO_BUSY.check_next:
CP IDE.Device.CDROM
JP Z,NOHDD
;!TODO ¯à¨¡à âìáï âãâ. <20>®á«¥ R02 âãâ ¬®¦­® ã¡à âì ¬­®£® «¨è­¥£®
;-=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-==-=-=;
LD E,ATA_NOP
LD BC,IDE.Write.Command
OUT (C),E
@ -220,7 +284,7 @@ WXREADY:
LD DE,#0101
CALL WAIT_PRT
JP NC,NOHDD
;-=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-==-=-=-=-=-=-=-==-=-=;
GETPARM:
LD HL,WAIT_IDE
LD DE,#0808
@ -394,6 +458,7 @@ SKIPKEY:
LD (SKIP),A
SCF
RET
SKIP: DB #FF
IDEDEV: DB #FF
ICHANEL: DB #00