source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH15h_HSize.asm @ 283

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

Fixed bug where total sector count was not being properly calculated from ah08 values, as head value is zero based instead of one based. The calcaultion is more complicated than one would like because the head number is in a single byte and could be 255 and we need to avoid an overflow.

File size: 3.0 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Description   :   Int 13h function AH=15h, Read Disk Drive Size.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Int 13h function AH=15h, Read Disk Drive Size.
9;
10; AH15h_HandlerForReadDiskDriveSize
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;       If succesfull:
17;           AH:     Hard Disk: 3 (Hard disk accessible)
18;                   Floppy:    1 (Floppy disk, without change detection)
19;           CX:DX:  Total number of sectors
20;           CF:     0
21;       If failed:
22;           AH:     0 (Drive not present)
23;           CX:DX:  0
24;           CF:     1
25;--------------------------------------------------------------------
26ALIGN JUMP_ALIGN
27AH15h_HandlerForReadDiskDriveSize:
28%ifdef MODULE_SERIAL_FLOPPY
29    mov     cl, 1                                       ; 1 = floppy disk, no change detection
30               
31    test    dl,dl                                       ; DO NOT store the sector count if this is a 
32    jns     .FloppyDrive                                ; floppy disk, some OS's depend on this not 
33                                                        ; happening for floppies in order to boot.
34%endif
35       
36    call    AH15h_GetSectorCountToBXDXAX
37    mov     [bp+IDEPACK.intpack+INTPACK.cx], dx         ; HIWORD to CX
38    xchg    [bp+IDEPACK.intpack+INTPACK.dx], ax         ; LOWORD to DX, AL gets drive number
39
40    xor     ah, ah     
41%ifdef MODULE_SERIAL_FLOPPY             
42    mov     cl, 3                                       ; 3 = Hard Disk Accessible
43.FloppyDrive:
44       
45    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber   ; Store success to BDA and CF       
46    mov     BYTE [bp+IDEPACK.intpack+INTPACK.ah], cl
47%else
48    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH    ; Store success to BDA and CF       
49    mov     BYTE [bp+IDEPACK.intpack+INTPACK.ah], 3
50%endif     
51       
52    jmp     Int13h_ReturnFromHandlerWithoutStoringErrorCode
53
54
55;--------------------------------------------------------------------
56; AH15h_GetSectorCountFromForeignDriveToDXAX:
57; AH15h_GetSectorCountToBXDXAX:
58;   Parameters:
59;       DL:     Drive number (AH15h_GetSectorCountFromForeignDriveToDXAX only)
60;       DS:     RAMVARS segment
61;       DS:DI:  Ptr to DPT (AH15h_GetSectorCountToDXAX only)
62;   Returns:
63;       DX:AX:  Total sector count
64;       BX:     Zero
65;   Corrupts registers:
66;       CX
67;--------------------------------------------------------------------
68AH15h_GetSectorCountFromForeignDriveToDXAX:
69    mov     ah, GET_DRIVE_PARAMETERS
70    call    Int13h_CallPreviousInt13hHandler
71    jmp     SHORT ConvertAH08hReturnValuesToSectorCount
72
73AH15h_GetSectorCountToBXDXAX:
74    call    AH8h_GetDriveParameters
75    ; Fall to ConvertAH08hReturnValuesToSectorCount
76
77ConvertAH08hReturnValuesToSectorCount:
78    call    Address_ExtractLCHSparametersFromOldInt13hAddress
79
80    mov     al, bl      ; Get sector value
81    mul     bh          ; Multiply by heads-1 (since bh is zero based, and could be 255 and overflow)
82    xor     bh, bh      ; Clear upper byte for following addition...
83    add     ax, bx      ; Add in one more sector value, since heads was off by one
84    inc     cx          ; Max cylinder number to cylinder count (again, zero based)
85    mul     cx          ; Multiply in cylinders
86    xor     bx, bx      ; Zero upper 16-bits, sector count will not be that large
87       
88    ret
Note: See TracBrowser for help on using the repository browser.