source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm @ 270

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

Fixed a bug with the number of floppy drives reported, if there were no floppy drives emulated.

File size: 5.0 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Description   :   Functions for accessings RAMVARS.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Initializes RAMVARS.
9; Drive detection can be started after this function returns.
10;
11; RamVars_Initialize
12;   Parameters:
13;       Nothing
14;   Returns:
15;       DS:     RAMVARS segment
16;   Corrupts registers:
17;       AX, CX, DI
18;--------------------------------------------------------------------
19RamVars_Initialize:
20    push    es
21    ; Fall to .StealMemoryForRAMVARS
22
23;--------------------------------------------------------------------
24; .StealMemoryForRAMVARS
25;   Parameters:
26;       Nothing
27;   Returns:
28;       DS:     RAMVARS segment
29;   Corrupts registers:
30;       AX
31;--------------------------------------------------------------------
32.StealMemoryForRAMVARS:
33    mov     ax, LITE_MODE_RAMVARS_SEGMENT
34    test    BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
35    jz      SHORT .InitializeRamvars    ; No need to steal RAM
36
37    LOAD_BDA_SEGMENT_TO ds, ax, !       ; Zero AX
38    mov     al, [cs:ROMVARS.bStealSize]
39    sub     [BDA.wBaseMem], ax
40    mov     ax, [BDA.wBaseMem]
41    eSHL_IM ax, 6                       ; Segment to first stolen kB (*=40h)
42    ; Fall to .InitializeRamvars
43
44;--------------------------------------------------------------------
45; .InitializeRamvars
46;   Parameters:
47;       AX:     RAMVARS segment
48;   Returns:
49;       DS:     RAMVARS segment
50;   Corrupts registers:
51;       AX, CX, DI, ES
52;--------------------------------------------------------------------
53.InitializeRamvars:
54    mov     ds, ax
55    mov     es, ax
56    mov     cx, RAMVARS_size
57    xor     di, di
58    call    Memory_ZeroESDIwithSizeInCX
59    mov     WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
60    ; Fall to .InitializeDriveTranslationAndReturn
61
62;--------------------------------------------------------------------
63; .InitializeDriveTranslationAndReturn
64;   Parameters:
65;       DS:     RAMVARS segment
66;   Returns:
67;       Nothing
68;   Corrupts registers:
69;       AX
70;--------------------------------------------------------------------
71.InitializeDriveTranslationAndReturn:
72    pop     es
73    jmp     DriveXlate_Reset
74
75
76;--------------------------------------------------------------------
77; Returns segment to RAMVARS.
78; RAMVARS might be located at the top of interrupt vectors (0030:0000h)
79; or at the top of system base RAM.
80;
81; RamVars_GetSegmentToDS
82;   Parameters:
83;       Nothing
84;   Returns:
85;       DS:     RAMVARS segment
86;   Corrupts registers:
87;       DI
88;--------------------------------------------------------------------
89ALIGN JUMP_ALIGN
90RamVars_GetSegmentToDS:
91    test    BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
92    jnz     SHORT .GetStolenSegmentToDS
93%ifndef USE_186
94    mov     di, LITE_MODE_RAMVARS_SEGMENT
95    mov     ds, di
96%else
97    push    LITE_MODE_RAMVARS_SEGMENT
98    pop     ds
99%endif
100    ret
101
102ALIGN JUMP_ALIGN
103.GetStolenSegmentToDS:
104    LOAD_BDA_SEGMENT_TO ds, di
105    mov     di, [BDA.wBaseMem]      ; Load available base memory size in kB
106    eSHL_IM di, 6                   ; Segment to first stolen kB (*=40h)
107ALIGN JUMP_ALIGN
108.LoopStolenKBs:
109    mov     ds, di                  ; EBDA segment to DS
110    add     di, BYTE 64             ; DI to next stolen kB
111    cmp     WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
112    jne     SHORT .LoopStolenKBs    ; Loop until sign found (always found eventually)
113    ret
114
115
116;--------------------------------------------------------------------
117; RamVars_GetHardDiskCountFromBDAtoAX
118;   Parameters:
119;       DS:     RAMVARS segment
120;   Returns:
121;       AX:     Total hard disk count
122;   Corrupts registers:
123;       CX
124;--------------------------------------------------------------------
125ALIGN JUMP_ALIGN
126RamVars_GetHardDiskCountFromBDAtoAX:
127    push    es
128
129    LOAD_BDA_SEGMENT_TO es, ax
130    call    RamVars_GetCountOfKnownDrivesToAX
131    mov     cl, [es:BDA.bHDCount]
132    MAX_U   al, cl
133       
134    pop     es
135    ret
136
137;--------------------------------------------------------------------
138; RamVars_GetCountOfKnownDrivesToAX
139;   Parameters:
140;       DS:     RAMVARS segment
141;   Returns:
142;       AX:     Total hard disk count
143;   Corrupts registers:
144;       None
145;--------------------------------------------------------------------
146ALIGN JUMP_ALIGN
147RamVars_GetCountOfKnownDrivesToAX:
148    mov     ax, [RAMVARS.wDrvCntAndFirst]
149    add     al, ah
150    and     al, 7fh
151    cbw
152    ret
153   
154;--------------------------------------------------------------------
155; RamVars_GetIdeControllerCountToCX
156;   Parameters:
157;       Nothing
158;   Returns:
159;       CX:     Number of IDE controllers to handle
160;   Corrupts registers:
161;       Nothing
162;--------------------------------------------------------------------
163ALIGN JUMP_ALIGN
164RamVars_GetIdeControllerCountToCX:
165    eMOVZX  cx, BYTE [cs:ROMVARS.bIdeCnt]
166    ret
167
168%ifdef MODULE_SERIAL_FLOPPY
169;--------------------------------------------------------------------
170; RamVars_UnpackFlopCntAndFirstToAL
171;   Parameters:
172;       Nothing
173;   Returns:
174;       AL:     First floppy drive number supported
175;       CF:     Number of floppy drives supported (clear = 1, set = 2)
176;       SF:     Emulating drives (clear = yes, set = no)
177;   Corrupts registers:
178;       Nothing
179;--------------------------------------------------------------------       
180ALIGN JUMP_ALIGN
181RamVars_UnpackFlopCntAndFirstToAL:
182    mov     al, [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst]
183    sar     al, 1       
184    ret
185%endif
Note: See TracBrowser for help on using the repository browser.