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

Last change on this file since 270 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
Line 
1; Project name : XTIDE Universal BIOS
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:
12; DL: Translated Drive number
13; DS:DI: Ptr to DPT (in RAMVARS segment)
14; SS:BP: Ptr to IDEPACK
15; Returns with INTPACK:
16; AH: Int 13h return status
17; CF: 0 if succesfull, 1 if error
18;--------------------------------------------------------------------
19AH9h_HandlerForInitializeDriveParameters:
20%ifndef USE_186
21 call AH9h_InitializeDriveForUse
22 jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
23%else
24 push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
25 ; Fall to AH9h_InitializeDriveForUse
26%endif
27
28
29;--------------------------------------------------------------------
30; Initialized drive to be ready for use.
31;
32; AH9h_InitializeDriveForUse
33; Parameters:
34; DS:DI: Ptr to DPT (in RAMVARS segment)
35; SS:BP: Ptr to IDEPACK
36; Returns:
37; AH: Int 13h return status
38; CF: 0 if succesfull, 1 if error
39; Corrupts registers:
40; AL, BX, DX
41;--------------------------------------------------------------------
42AH9h_InitializeDriveForUse:
43 push cx
44
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
55 ; Try to select drive and wait until ready
56 or BYTE [di+DPT.bFlagsHigh], MASKH_DPT_RESET ; Everything uninitialized
57 call AccessDPT_GetDriveSelectByteToAL
58 mov [bp+IDEPACK.bDrvAndHead], al
59 call Device_SelectDrive
60 jc SHORT .ReturnNotSuccessfull
61 and BYTE [di+DPT.bFlagsHigh], ~FLGH_DPT_RESET_nDRDY ; Clear since success
62
63 ; Initialize CHS parameters if LBA is not used
64 call InitializeDeviceParameters
65 jc SHORT .RecalibrateDrive
66 and BYTE [di+DPT.bFlagsHigh], ~FLGH_DPT_RESET_nINITPRMS
67
68 ; Recalibrate drive by seeking to cylinder 0
69.RecalibrateDrive:
70 call AH11h_RecalibrateDrive
71 jc SHORT .InitializeBlockMode
72 and BYTE [di+DPT.bFlagsHigh], ~FLGH_DPT_RESET_nRECALIBRATE
73
74 ; Initialize block mode transfers
75.InitializeBlockMode:
76 call InitializeBlockMode
77 jc SHORT .ReturnNotSuccessfull
78 and BYTE [di+DPT.bFlagsHigh], ~FLGH_DPT_RESET_nSETBLOCK ; Keeps CF clear
79
80.ReturnNotSuccessfull:
81 pop cx
82 ret
83
84
85;--------------------------------------------------------------------
86; InitializeDeviceParameters
87; Parameters:
88; DS:DI: Ptr to DPT (in RAMVARS segment)
89; SS:BP: Ptr to IDEPACK
90; Returns:
91; AH: BIOS Error code
92; CF: Cleared if succesfull
93; Set if any error
94; Corrupts registers:
95; AL, BX, CX, DX
96;--------------------------------------------------------------------
97InitializeDeviceParameters:
98 ; No need to initialize CHS parameters if LBA mode enabled
99 test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA ; Clear CF
100 jnz SHORT ReturnSuccessSinceInitializationNotNeeded
101
102 ; Initialize Logical Sectors per Track and Max Head number
103 mov ah, [di+DPT.bPchsHeads]
104 dec ah ; Max Head number
105 mov dl, [di+DPT.bPchsSectors] ; Sectors per Track
106 mov al, COMMAND_INITIALIZE_DEVICE_PARAMETERS
107 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
108 jmp Idepack_StoreNonExtParametersAndIssueCommandFromAL
109
110
111;--------------------------------------------------------------------
112; InitializeBlockMode
113; Parameters:
114; DS:DI: Ptr to DPT (in RAMVARS segment)
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;--------------------------------------------------------------------
122InitializeBlockMode:
123 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED ; Clear CF
124 jz SHORT ReturnSuccessSinceInitializationNotNeeded
125
126 mov al, [di+DPT_ATA.bMaxBlock] ; Load max block size, zero AH
127 jmp AH24h_SetBlockSize
128ReturnSuccessSinceInitializationNotNeeded:
129 ret
Note: See TracBrowser for help on using the repository browser.