📄 ata_wc.asm
字号:
AtaWritePacket:
movlw 0x0a
movwf AtaDataLsb
movlw ATA_REG_DRIVEHEAD
call AtaWriteRegister
clrf AtaDataLsb
movlw ATA_REG_FEATURES
call AtaWriteRegister
clrf AtaDataLsb
movlw ATA_REG_CYLINDERLOW
call AtaWriteRegister
clrf AtaDataLsb
movlw ATA_REG_CYLINDERHIGH
call AtaWriteRegister
movlw ATA_COMMAND_PACKET
movwf AtaDataLsb
movlw ATA_REG_COMMAND
call AtaWriteRegister
call Delay10ms
AtaWc2:
movlw ATA_REG_STATUS
call AtaReadRegister
movf AtaDataLsb,w
andlw 0x08
btfsc status,z
goto AtaWc2
bcf status,rp1
bsf status,rp0
movlw PORTB_CONFIG2
movwf trisb
movlw PORTC_CONFIG2
movwf trisc
bcf status,rp1
bcf status,rp0
bcf porta,ATA_A0
bcf porta,ATA_A1
bcf porta,ATA_A2
movlw 0x06
movwf AtaCounter
movlw AtaPacket
movwf fsr
AtaWP1:
movf indf,w
movwf portb
incf fsr,f
movf indf,w
movwf portc
call Delay10ms
incf fsr,f
bcf porta,ATA_IOW
call Delay10ms
bsf porta,ATA_IOW
call Delay10ms
decfsz AtaCounter,f
goto AtaWP1
movlw D'12'
movwf AtaCounter
movlw AtaPacket
movwf fsr
Au1: clrf indf
incf fsr,f
decfsz AtaCounter,f
goto Au1
return
AtaWriteRegister:
movwf AtaRegister
bcf status,rp1
bsf status,rp0
movlw PORTB_CONFIG2
movwf trisb
movlw PORTC_CONFIG2
movwf trisc
bcf status,rp1
bcf status,rp0
rlf AtaRegister,w
iorlw 0x30
movwf porta
call Delay1ms
movf AtaDataLsb,w
movwf portb
clrf portc
call Delay1ms
bcf porta,ATA_IOW
call Delay1ms
bsf porta,ATA_IOW
call Delay1ms
return
AtaReadRegister:
movwf AtaRegister
bcf status,rp1
bsf status,rp0
movlw PORTB_CONFIG1
movwf trisb
movlw PORTC_CONFIG1
movwf trisc
bcf status,rp1
bcf status,rp0
rlf AtaRegister,w
iorlw 0x30
movwf porta
call Delay1ms
bcf porta,ATA_IOR
call Delay1ms
movf portb,w
movwf AtaDataLsb
movf portc,w
movwf AtaDataMsb
call Delay1ms
bsf porta,ATA_IOR
call Delay1ms
return
AtaReadPacketEmpty:
AtaRe1:
movlw ATA_REG_SECTORCOUNT
call AtaReadRegister
movf AtaDataLsb,w
andlw 0x03
xorlw 0x03
btfss status,z
goto AtaRe1
AtaReadNachamble:
call Delay200ms
AtaRe2:
movlw ATA_REG_STATUS
call AtaReadRegister
movf AtaDataLsb,w
andlw 0xc8
xorlw 0x40
btfss status,z
goto AtaRe2
movf AtaDataLsb,w
xorlw 0x50
return
#ifdef LCD
AtaReadIdentifyDrive:
return
#endif
#ifdef LCD
AtaReadPacketInquiry:
return
#endif
AtaReadPacketSubChannel:
call AtaReadPreamble
bcf porta,ATA_IOR
movf portc,w
movwf TrackStatus
call Delay10ms
bsf porta,ATA_IOR
call Delay10ms
bcf porta,ATA_IOR
call Delay10ms
bsf porta,ATA_IOR
call Delay10ms
bcf porta,ATA_IOR
call Delay10ms
bsf porta,ATA_IOR
call Delay10ms
bcf porta,ATA_IOR
call Delay10ms
movf portb,w
movwf TrackCurrentNr
bsf porta,ATA_IOR
call Delay10ms
bcf porta,ATA_IOR
call Delay10ms
movf portc,w
movwf TrackCurrentMSF_M
bsf porta,ATA_IOR
call Delay10ms
bcf porta,ATA_IOR
call Delay10ms
movf portb,w
movwf TrackCurrentMSF_S
movf portc,w
movwf TrackCurrentMSF_F
bsf porta,ATA_IOR
call Delay10ms
bcf porta,ATA_IOR
call Delay10ms
bsf porta,ATA_IOR
call Delay10ms
bcf porta,ATA_IOR
call Delay10ms
bsf porta,ATA_IOR
call Delay10ms
call AtaReadNachamble
return
AtaReadPacketToc:
call AtaReadPreamble
bcf porta,ATA_IOR
call Delay10ms
bsf porta,ATA_IOR
call Delay10ms
bcf porta,ATA_IOR
call Delay10ms
movf portb,w
movwf TrackFirstNr
movf portc,w
movwf TrackLastNr
bsf porta,ATA_IOR
AtaRt1:
call Delay10ms
bcf porta,ATA_IOR
call Delay10ms
bsf porta,ATA_IOR
call Delay10ms
bcf porta,ATA_IOR
call Delay10ms
movf portb,w
movwf TrackTempNr
bsf porta,ATA_IOR
call Delay10ms
movf TrackTempNr,w
xorwf TrackStartNr,w
btfsc status,z
goto AtaRSave1
movf TrackTempNr,w
xorlw 0xaa
btfsc status,z
goto AtaRSave2
bcf porta,ATA_IOR
call Delay10ms
bsf porta,ATA_IOR
call Delay10ms
bcf porta,ATA_IOR
call Delay10ms
bsf porta,ATA_IOR
goto AtaRt1
AtaRSave1:
bcf porta,ATA_IOR
call Delay10ms
movf portc,w
movwf TrackStartMSF_M
bsf porta,ATA_IOR
call Delay10ms
bcf porta,ATA_IOR
call Delay10ms
movf portb,w
movwf TrackStartMSF_S
movf portc,w
movwf TrackStartMSF_F
bsf porta,ATA_IOR
call Delay10ms
goto AtaRt1
AtaRSave2:
bcf porta,ATA_IOR
call Delay10ms
movf portc,w
movwf TrackLeadOutMSF_M
bsf porta,ATA_IOR
call Delay10ms
bcf porta,ATA_IOR
call Delay10ms
movf portb,w
movwf TrackLeadOutMSF_S
movf portc,w
movwf TrackLeadOutMSF_F
bsf porta,ATA_IOR
call Delay10ms
call AtaReadNachamble
return
AtaReadPreamble:
AtaRp1:
movlw ATA_REG_SECTORCOUNT
call AtaReadRegister
movf AtaDataLsb,w
andlw 0x03
xorlw 0x02
btfss status,z
goto AtaRp1
bcf status,rp1
bsf status,rp0
movlw PORTB_CONFIG1
movwf trisb
movlw PORTC_CONFIG1
movwf trisc
bcf status,rp1
bcf status,rp0
bcf porta,ATA_A0
bcf porta,ATA_A1
bcf porta,ATA_A2
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -