source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm@ 271

Last change on this file since 271 was 258, checked in by gregli@…, 12 years ago

Added floppy drive emulation over the serial connection (MODULE_SERIAL_FLOPPY). Along the way, various optimizations were made to stay within the 8K ROM size target. Also, serial code now returns the number of sectors transferred.

File size: 4.1 KB
RevLine 
[148]1; Project name : XTIDE Universal BIOS
[3]2; Description : Int 13h function AH=9h, Initialize Drive Parameters.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Int 13h function AH=9h, Initialize Drive Parameters.
9;
10; AH9h_HandlerForInitializeDriveParameters
11; Parameters:
[148]12; DL: Translated Drive number
13; DS:DI: Ptr to DPT (in RAMVARS segment)
[150]14; SS:BP: Ptr to IDEPACK
15; Returns with INTPACK:
[3]16; AH: Int 13h return status
17; CF: 0 if succesfull, 1 if error
18;--------------------------------------------------------------------
19AH9h_HandlerForInitializeDriveParameters:
[84]20%ifndef USE_186
[3]21 call AH9h_InitializeDriveForUse
[148]22 jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[84]23%else
[148]24 push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[162]25 ; Fall to AH9h_InitializeDriveForUse
[84]26%endif
[3]27
28
29;--------------------------------------------------------------------
30; Initialized drive to be ready for use.
31;
32; AH9h_InitializeDriveForUse
33; Parameters:
[148]34; DS:DI: Ptr to DPT (in RAMVARS segment)
[150]35; SS:BP: Ptr to IDEPACK
[3]36; Returns:
37; AH: Int 13h return status
38; CF: 0 if succesfull, 1 if error
39; Corrupts registers:
[148]40; AL, BX, DX
[3]41;--------------------------------------------------------------------
42AH9h_InitializeDriveForUse:
43 push cx
44
[258]45%ifdef MODULE_SERIAL
46 ;
47 ; no need to do this for serial deveices, and we use the DPT_RESET flag bits
48 ; to store the drive type for serial floppy drives (MODULE_SERIAL_FLOPPY)
49 ;
50 xor ah, ah
51 test byte [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE ; Clears CF
52 jnz .ReturnNotSuccessfull
53%endif
54
[3]55 ; Try to select drive and wait until ready
[158]56 or BYTE [di+DPT.bFlagsHigh], MASKH_DPT_RESET ; Everything uninitialized
[150]57 call AccessDPT_GetDriveSelectByteToAL
58 mov [bp+IDEPACK.bDrvAndHead], al
59 call Device_SelectDrive
[3]60 jc SHORT .ReturnNotSuccessfull
[158]61 and BYTE [di+DPT.bFlagsHigh], ~FLGH_DPT_RESET_nDRDY ; Clear since success
[3]62
63 ; Initialize CHS parameters if LBA is not used
[150]64 call InitializeDeviceParameters
[3]65 jc SHORT .RecalibrateDrive
[158]66 and BYTE [di+DPT.bFlagsHigh], ~FLGH_DPT_RESET_nINITPRMS
[3]67
68 ; Recalibrate drive by seeking to cylinder 0
69.RecalibrateDrive:
70 call AH11h_RecalibrateDrive
71 jc SHORT .InitializeBlockMode
[158]72 and BYTE [di+DPT.bFlagsHigh], ~FLGH_DPT_RESET_nRECALIBRATE
[3]73
74 ; Initialize block mode transfers
75.InitializeBlockMode:
[150]76 call InitializeBlockMode
[3]77 jc SHORT .ReturnNotSuccessfull
[158]78 and BYTE [di+DPT.bFlagsHigh], ~FLGH_DPT_RESET_nSETBLOCK ; Keeps CF clear
[3]79
80.ReturnNotSuccessfull:
81 pop cx
82 ret
83
84
85;--------------------------------------------------------------------
[150]86; InitializeDeviceParameters
[3]87; Parameters:
[150]88; DS:DI: Ptr to DPT (in RAMVARS segment)
89; SS:BP: Ptr to IDEPACK
[3]90; Returns:
91; AH: BIOS Error code
92; CF: Cleared if succesfull
93; Set if any error
94; Corrupts registers:
[150]95; AL, BX, CX, DX
[3]96;--------------------------------------------------------------------
[150]97InitializeDeviceParameters:
[3]98 ; No need to initialize CHS parameters if LBA mode enabled
[158]99 test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA ; Clear CF
[150]100 jnz SHORT ReturnSuccessSinceInitializationNotNeeded
[3]101
[157]102 ; Initialize Logical Sectors per Track and Max Head number
[227]103 mov ah, [di+DPT.bPchsHeads]
[150]104 dec ah ; Max Head number
[227]105 mov dl, [di+DPT.bPchsSectors] ; Sectors per Track
[150]106 mov al, COMMAND_INITIALIZE_DEVICE_PARAMETERS
107 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
108 jmp Idepack_StoreNonExtParametersAndIssueCommandFromAL
[3]109
110
111;--------------------------------------------------------------------
[150]112; InitializeBlockMode
[3]113; Parameters:
[150]114; DS:DI: Ptr to DPT (in RAMVARS segment)
[3]115; Returns:
116; AH: BIOS Error code
117; CF: Cleared if succesfull
118; Set if any error
119; Corrupts registers:
120; AL, BX, CX, DX
121;--------------------------------------------------------------------
[150]122InitializeBlockMode:
[158]123 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED ; Clear CF
[150]124 jz SHORT ReturnSuccessSinceInitializationNotNeeded
125
126 mov al, [di+DPT_ATA.bMaxBlock] ; Load max block size, zero AH
[3]127 jmp AH24h_SetBlockSize
[150]128ReturnSuccessSinceInitializationNotNeeded:
[3]129 ret
Note: See TracBrowser for help on using the repository browser.