source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm@ 198

Last change on this file since 198 was 193, checked in by gregli@…, 13 years ago

Space optimizations in AccessDPT.asm, transfer one routine to a macro (retaining some encapsulation), and transfer the unique part of another routine to the one place it was being called (which also makes what it was doing more transparent).

File size: 3.7 KB
RevLine 
[99]1; Project name : XTIDE Universal BIOS
[3]2; Description : Functions for accessing DPT data.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
[150]8; AccessDPT_GetDriveSelectByteToAL
9; Parameters:
10; DS:DI: Ptr to Disk Parameter Table
11; Returns:
12; AL: Drive Select Byte
13; Corrupts registers:
14; Nothing
15;--------------------------------------------------------------------
16ALIGN JUMP_ALIGN
17AccessDPT_GetDriveSelectByteToAL:
18 mov al, [di+DPT.wFlags]
19 and al, FLG_DRVNHEAD_LBA | FLG_DRVNHEAD_DRV
20 or al, MASK_DRVNHEAD_SET ; Bits set to 1 for old drives
21 ret
22
23
24;--------------------------------------------------------------------
25; AccessDPT_GetDeviceControlByteToAL
26; Parameters:
27; DS:DI: Ptr to Disk Parameter Table
28; Returns:
29; AL: Device Control Byte
30; Corrupts registers:
31; Nothing
32;--------------------------------------------------------------------
33ALIGN JUMP_ALIGN
34AccessDPT_GetDeviceControlByteToAL:
35 xor al, al
[158]36 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_ENABLE_IRQ
[150]37 jnz SHORT .EnableDeviceIrq
38 or al, FLG_DEVCONTROL_nIEN ; Disable IRQ
39.EnableDeviceIrq:
40 ret
41
[193]42
[150]43;--------------------------------------------------------------------
[173]44; AccessDPT_GetLCHS
[3]45; Parameters:
46; DS:DI: Ptr to Disk Parameter Table
47; Returns:
48; AX: Number of L-CHS sectors per track
49; BX: Number of L-CHS cylinders
50; DX: Number of L-CHS heads
51; Corrupts registers:
[173]52; CX
[3]53;--------------------------------------------------------------------
[173]54AccessDPT_GetLCHS:
55 ; Load CHS from DPT
56 eMOVZX ax, BYTE [di+DPT.bSectors]
57 mov bx, [di+DPT.dwCylinders]
[161]58 cwd
[173]59 mov dl, [di+DPT.bHeads]
60
61 ; Only need to limit sectors for LBA assist
62 test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
[181]63 jz SHORT AccessDPT_ShiftPCHinBXDXtoLCH
[173]64
[181]65 cmp WORD [di+DPT.dwCylinders+2], BYTE 0
66 jnz SHORT .Return_MAX_LCHS_CYLINDERS
[173]67
[181]68 ; Limit cylinders to 1024
69 cmp bx, MAX_LCHS_CYLINDERS
70 jb SHORT .Return
71ALIGN JUMP_ALIGN
72.Return_MAX_LCHS_CYLINDERS:
[173]73 mov bx, MAX_LCHS_CYLINDERS
[181]74ALIGN JUMP_ALIGN, ret
75.Return:
[3]76 ret
77
78
79;--------------------------------------------------------------------
[173]80; AccessDPT_ShiftPCHinBXDXtoLCH
81; Parameters:
82; BX: P-CHS cylinders (1...16383)
83; DX: P-CHS heads (1...16)
84; Returns:
85; BX: Number of L-CHS cylinders (1...1024)
86; DX: Number of L-CHS heads (1...255)
87; CX: Number of bits shifted
88; Corrupts registers:
89; Nothing
90;--------------------------------------------------------------------
91AccessDPT_ShiftPCHinBXDXtoLCH:
92 xor cx, cx
93.ShiftLoop:
94 cmp bx, MAX_LCHS_CYLINDERS ; Need to shift?
95 jbe SHORT .LimitHeadsTo255 ; If not, return
96 inc cx ; Increment shift count
97 shr bx, 1 ; Halve cylinders
98 shl dx, 1 ; Double heads
99 jmp SHORT .ShiftLoop
100.LimitHeadsTo255: ; DOS does not support drives with 256 heads
[181]101 sub dl, dh ; DH set only when 256 logical heads
[173]102 xor dh, dh
103 ret
104
[193]105
[173]106;--------------------------------------------------------------------
[3]107; Returns pointer to DRVPARAMS for master or slave drive.
108;
109; AccessDPT_GetPointerToDRVPARAMStoCSBX
110; Parameters:
111; DS:DI: Ptr to Disk Parameter Table
112; Returns:
113; CS:BX: Ptr to DRVPARAMS
114; Corrupts registers:
115; Nothing
116;--------------------------------------------------------------------
117ALIGN JUMP_ALIGN
118AccessDPT_GetPointerToDRVPARAMStoCSBX:
[150]119 eMOVZX bx, [di+DPT.bIdevarsOffset] ; CS:BX points to IDEVARS
120 add bx, BYTE IDEVARS.drvParamsMaster ; CS:BX points to Master Drive DRVPARAMS
[158]121 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
[150]122 jz SHORT .ReturnPointerToDRVPARAMS
123 add bx, BYTE DRVPARAMS_size ; CS:BX points to Slave Drive DRVPARAMS
124.ReturnPointerToDRVPARAMS:
[3]125 ret
Note: See TracBrowser for help on using the repository browser.