; LAST UPDATE: 13.11.2024 savelij
VIEW_CHS EQU 1
HDD_DETECTOR LD IX,.HDDDETECT
RST8 _WINW
LD HL,ADR_CAT
RST8 _COM_DEV,_COMHDDN,_DEV_INIT
LD A,H
AND A
JR Z,.MASTER_FOUND
DEC A
CALL Z,.CDDVDFOUNDM
JR Z,.SLAVE
PUSH HL
LD HL,.MASTERNONE
RST8 _PRINT_MESSAGE
POP HL
JR .SLAVE
.MASTER_FOUND LD C,1
CALL .HDD_INFO
.SLAVE LD A,L
AND A
JR Z,.SLAVE_FOUND
DEC A
CALL Z,.CDDVDFOUNDS
JP Z,.ENDTEST
LD HL,.SLAVENONE
RST8 _PRINT_MESSAGE
JR .ENDTEST;.SD_TEST
.SLAVE_FOUND LD C,2
CALL .HDD_INFO
;.SD_TEST CALL .GET_SD_INFO
.ENDTEST LD HL,.TXTANYKEY
RST8 _PRINT_MESSAGE
.WAITENTER EI
HALT
BIT 5,(IY+1)
JR Z,.WAITENTER
LD A,(LAST_K)
CP 0X0D
JR NZ,.WAITENTER
JP RESTART
.HDD_INFO PUSH HL
DEC C
LD HL,.MASTERFOUND
JR Z,.HDDI1
LD HL,.SLAVEFOUND
.HDDI1
RST8 _PRINT_MESSAGE
LD A,C
EX AF,AF'
LD HL,ADR_CAT
RST8 _COM_DEV,_COMHDDN,_DEV_READID
LD HL,ADR_CAT+46
PUSH HL
LD B,0X18
.MF01 LD A,(HL)
INC HL
LD E,(HL)
DEC HL
LD (HL),E
INC HL
LD (HL),A
INC HL
DJNZ .MF01
LD HL,ADR_CAT+46+42
IF VIEW_CHS
LD (HL),"\r"
INC HL
ENDIF
LD (HL),0
POP HL
RST8 _PRINT_MESSAGE ;имя винта
IF VIEW_CHS
LD HL,.CHS
RST8 _PRINT_MESSAGE
LD HL,ADR_CAT+0X200
LD DE,(ADR_CAT + 1 * WORD) ;количество цилиндров
RST8 _MATH,_HEX2DECTXT
RST8 _PRINT_MESSAGE
LD A,"/"
RST8 _PRINT_A
LD DE,(ADR_CAT + 3 * WORD) ;количество головок
RST8 _MATH,_HEX1DECTXT
RST8 _PRINT_MESSAGE
LD A,"/"
RST8 _PRINT_A
LD DE,(ADR_CAT + 6 * WORD) ;количество секторов
RST8 _MATH,_HEX1DECTXT
RST8 _PRINT_MESSAGE
ENDIF
LD HL,.TXTSIZE
RST8 _PRINT_MESSAGE
LD IXL,0 ; текст "MB"
; LD HL,.NEWLINE
; RST8 _PRINT_MESSAGE
; проверка бита поддержки LBA48
LD HL,(ADR_CAT + 83 * WORD)
LD A,H
AND %00000100 ; бит 10 в слове 83
JR Z,.LBA28
; для LBA48
.LBA48 LD HL,(ADR_CAT + 100 * WORD + 1); размер в секторах /256
LD DE,(ADR_CAT + 101 * WORD + 1)
LD BC,(ADR_CAT + 102 * WORD + 1)
LD B,3
CALL .DIV_LBA
LD A,C
AND A
JR Z,.L3
LD IXL,1 ; текст "GB"
LD B,2
LD L,H
LD H,E
LD E,D
LD D,C
LD C,0
CALL .DIV_LBA
JR .L3
; для LBA28
.LBA28
LD HL,(ADR_CAT + 60 * WORD + 1)
LD DE,(ADR_CAT + 61 * WORD + 1) ; размер в LBA секторах
LD BC,3 << 8 + 0
CALL .DIV_LBA
.L3 LD B,D
LD C,E
EX DE,HL
LD HL,ADR_CAT+0X200
RST8 _MATH,_HEX4DECTXT
RST8 _PRINT_MESSAGE
LD A,IXL
AND A
LD HL,.TXTMB
JR Z,.L4
LD HL,.TXTGB
.L4
RST8 _PRINT_MESSAGE
POP HL
RET
.DIV_LBA
.L1 SRL C
RR D
RR E
RR H
RR L
DJNZ .L1
RET
.CDDVDFOUNDS PUSH HL
LD HL,.SLAVECDDVD
JR .CDDVDFOUND
.CDDVDFOUNDM PUSH HL
LD HL,.MASTERCDDVD
.CDDVDFOUND PUSH AF
RST8 _PRINT_MESSAGE
POP AF
POP HL
RET
.GET_SD_INFO
RST8 _COM_DEV,_CONTROL_SD
AND A
JR Z,.GSI01
; SD карта не найдена
LD HL,.SD_NOT_FOUND
RST8 _PRINT_MESSAGE
RET
.GSI01
RET
.HDDDETECT DB 0,0,24,32,0X07,0X1F,%01010000,0
DW 0,0,.TXTHDDDET,0,0,0
.TXTHDDDET DZ "\1\x17\XFF\3Device detector\r"
.TXTSIZE DZ "\rSize:"
.TXTMB DZ " MB\r"
.TXTGB DZ " GB\r"
.MASTERFOUND DZ "\rHDD master found\r"
.SLAVEFOUND DZ "\rHDD slave found\r"
.MASTERNONE DZ "\rHDD master not found\r"
.SLAVENONE DZ "\rHDD slave not found\r"
.MASTERCDDVD DZ "\rCD/DVD-ROM master found\r"
.SLAVECDDVD DZ "\rCD/DVD-ROM slave found\r"
.CHS DZ "C/H/S: "
.SD_NOT_FOUND DZ "SD Card not found\r"
.NEWLINE DZ "\r"
.TXTANYKEY DZ "\x16\x17\0\3Press ENTER to main menu"
IF 0
;[получение размера карты в секторах]
GET_SD_SIZE PUSH IX
PEC_OFF M_SHADOW_BF
IFDEF UNREAL
LD BC,0X3C;0
LD DE,0X1800;29120
ELSE
PUSH HL
PUSH HL
LD A,CMD_09
CALL OUT_COM
CALL IN_OOUT
CP 0XFE
JR NZ,$-5
LD BC,P_DATA
POP HL
POP IX
LD B,0X14
INIR
BIT 6,(IX+0)
JR Z,SDVERS_10
;спецификация версия 2.0
;C_SIZE (22 bit) 69:48 0x45:30
;00 01 02 03 04 05 06 07 08 09
;xx xx xx xx xx xxxx1111 xxxxxxxx xx111111 11111111 11111111
LD BC,1
LD L,(IX+9)
LD H,(IX+8)
LD A,(IX+7)
AND %00111111
LD E,A
LD D,B ;DEHL=C_SIZE (22 БИТА)
ADD HL,BC
EX DE,HL
LD C,B
ADC HL,BC
EX DE,HL
REPT 2
ADD HL,HL
EX DE,HL
ADC HL,HL
EX DE,HL
ENDM
LD B,H
LD C,L ;BCDE=количество секторов
CALL EXIT_SDREAD
POP IX
RET
;спецификация версия 1.0
;C_SIZE (12 bit) 73:62 0x49:3E
;C_SIZE_MULT (3 bit) 49:47 0x31:2F
;00 01 02 03 04 05 06 07 08 09 0A
;xx xx xx xx xx xxxx1111 xxxxxx11 11111111 11xxxxxx xxxxxx11 1xxxxxxx
SDVERS_10 LD L,(IX+7)
LD A,(IX+6)
AND %00000011
LD H,A
ADD HL,HL
ADD HL,HL
LD A,(IX+8)
RLCA
RLCA
AND %00000011
OR L
LD L,A
EX DE,HL ;DE=C_SIZE
LD L,(IX+10)
LD H,(IX+9)
ADD HL,HL
LD A,H
AND %00000111
ADD A,2
LD B,A ;B=C_SIZE_MULT+2
LD HL,1
ADD HL,HL
DJNZ $-1
INC DE
LD B,H
LD C,L
CALL MULTIPLY
LD B,H
LD C,L ;количество секторов
ENDIF
CALL EXIT_SDREAD
POP IX
RET
ENDIF