source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenuPrint.asm @ 241

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

Space optimizations in the Boot Menu and BootInfo routines, taking advantage of nested %s. Optimization in the init of RamVars to avoid writing the signature twice. Preparing for addition of serial floppy support, starting to break the assumption that our drives are always 80h or higher.

File size: 13.0 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Description   :   Functions for printing boot menu strings.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; BootMenuPrint_RefreshItem
9; 
10;   Parameters:
11;       DL:     Untranslated Floppy Drive number
12;   Returns:
13;       Nothing
14;   Corrupts registers:
15;       AX, BX, DX, SI, DI
16;--------------------------------------------------------------------
17ALIGN JUMP_ALIGN
18BootMenuPrint_RefreshItem:
19    call    BootMenu_GetDriveToDXforMenuitemInCX_And_RamVars_GetSegmentToDS
20    jnc     BootMenuEvent_EventCompleted            ; if no menu item selected, out we go
21       
22    push    bp
23    mov     bp, sp
24
25    call    RamVars_IsDriveHandledByThisBIOS               
26    jnc     .notOurs
27
28    call    FindDPT_ForDriveNumber                  ; if it is one of ours, print the string in bootnfo
29    call    BootInfo_ConvertDPTtoBX
30    mov     si, g_szDriveNumBOOTNFO                 ; special g_szDriveNum that prints from BDA
31    jmp     .go
32       
33.notOurs:
34    mov     si,g_szDriveNum                                 
35    mov     bx,g_szForeignHD                        ; assume a hard disk for the moment
36       
37    test    dl,80h                                         
38    js      .go
39    mov     bl,((g_szFloppyDrv)-$$ & 0xff)          ; and revisit the earlier assumption...
40       
41.go:
42    mov     ax, dx                                  ; preserve DL for the floppy drive letter addition
43    call    DriveXlate_ToOrBack
44    push    dx                                      ; translated drive number
45    push    bx                                      ; sub string
46    add     al, 'A'                                 ; floppy drive letter (we always push this although
47    push    ax                                      ; the hard disks don't ever use it, but it does no harm)
48       
49    jmp     short BootMenuPrint_FormatCSSIfromParamsInSSBP
50
51;--------------------------------------------------------------------
52; Prints Boot Menu title strings.
53;
54; BootMenuPrint_TitleStrings
55;   Parameters:
56;       Nothing
57;   Returns:
58;       CF:     Set since menu event handled
59;   Corrupts registers:
60;       AX, SI, DI
61;--------------------------------------------------------------------
62ALIGN JUMP_ALIGN
63BootMenuPrint_TitleStrings:
64    mov     si, ROMVARS.szTitle
65    call    BootMenuPrint_NullTerminatedStringFromCSSIandSetCF
66    CALL_DISPLAY_LIBRARY PrintNewlineCharacters
67    mov     si, ROMVARS.szVersion
68    ; Fall to BootMenuPrint_NullTerminatedStringFromCSSIandSetCF
69
70;--------------------------------------------------------------------
71; BootMenuPrint_NullTerminatedStringFromCSSIandSetCF
72;   Parameters:
73;       CS:SI:  Ptr to NULL terminated string to print
74;   Returns:
75;       CF:     Set since menu event was handled successfully
76;   Corrupts registers:
77;       AX, DI
78;--------------------------------------------------------------------
79ALIGN JUMP_ALIGN
80BootMenuPrint_NullTerminatedStringFromCSSIandSetCF:
81;
82; We send all CSSI strings through the Format routine for the case of
83; compressed strings, but this doesn't hurt in the non-compressed case either
84; (perhaps a little slower, but shouldn't be noticeable to the user)
85; and results in smaller code size.
86;
87    push    bp
88    mov     bp,sp
89    jmp     short BootMenuPrint_FormatCSSIfromParamsInSSBP
90
91       
92;--------------------------------------------------------------------
93; BootMenuPrint_FloppyMenuitemInformation
94;   Parameters:
95;       DL:     Untranslated Floppy Drive number
96;       DS:     RAMVARS segment
97;   Returns:
98;       CF:     Set since menu event was handled successfully
99;   Corrupts registers:
100;       AX, BX, CX, DX, SI, DI, ES
101;--------------------------------------------------------------------
102
103ALIGN JUMP_ALIGN
104BootMenuPrint_RefreshInformation:
105    CALL_MENU_LIBRARY ClearInformationArea     
106       
107    call    BootMenu_GetDriveToDXforMenuitemInCX_And_RamVars_GetSegmentToDS
108    jnc     BootMenuEvent_EventCompleted                ; if no menu selection, abort
109
110    push    bp
111    mov     bp, sp
112
113    test    dl, dl                                      ; are we a hard disk?
114    js      BootMenuPrint_HardDiskRefreshInformation       
115       
116    call    FloppyDrive_GetType                         ; Get Floppy Drive type to BX
117
118    mov     cx, g_szFddSizeOr                           ; .PrintXTFloppyType
119    test    bx, bx                                      ; Two possibilities? (FLOPPY_TYPE_525_OR_35_DD)     
120    jz      SHORT BootMenuPrint_HardDiskRefreshInformation.output
121
122    mov     cl, (g_szFddUnknown - $$) & 0xff            ; .PrintUnknownFloppyType
123    cmp     bl, FLOPPY_TYPE_35_ED
124    ja      SHORT BootMenuPrint_HardDiskRefreshInformation.output
125       
126    ; Fall to .PrintKnownFloppyType
127
128;--------------------------------------------------------------------
129; .PrintKnownFloppyType
130;   Parameters:
131;       BX:     Floppy drive type
132;   Returns:
133;       CF:     Set since menu event was handled successfully
134;   Corrupts registers:
135;       AX, BX, SI, DI
136; 
137; Floppy Drive Types:
138;
139;   0  Handled above 
140;   1  FLOPPY_TYPE_525_DD          5 1/4   360K
141;   2  FLOPPY_TYPE_525_HD          5 1/4   1.2M
142;   3  FLOPPY_TYPE_35_DD           3 1/2   720K
143;   4  FLOPPY_TYPE_35_HD           3 1/2   1.44M
144;   5  3.5" ED on some BIOSes      3 1/2   2.88M
145;   6  FLOPPY_TYPE_35_ED           3 1/2   2.88M
146;   >6 Unknwon, handled above
147; 
148;--------------------------------------------------------------------
149.PrintKnownFloppyType:
150    mov     cl, (g_szFddSize - $$) & 0xff
151    push    cx
152       
153    mov     cl, (g_szFddThreeHalf - $$) & 0xff
154    cmp     bl, FLOPPY_TYPE_525_HD
155    ja      .ThreeHalf
156    mov     cl, (g_szFddFiveQuarter - $$) & 0xff
157.ThreeHalf:     
158    push    cx                                          ; "5 1/4" or "3 1/2"
159
160    mov     al,FloppyTypes.rgbCapacityMultiplier
161    mul     byte [cs:bx+FloppyTypes.rgbCapacity - 1]    ; -1 since 0 is handled above and not in the table
162    push    ax
163
164    jmp     short BootMenuPrint_HardDiskRefreshInformation.output
165
166
167;--------------------------------------------------------------------
168; Prints Hard Disk Menuitem information strings.
169;
170; BootMenuPrint_HardDiskMenuitemInformation
171;   Parameters:
172;       DL:     Untranslated Hard Disk number
173;       DS:     RAMVARS segment
174;   Returns:
175;       CF:     Set since menu event was handled successfully
176;   Corrupts registers:
177;       BX, CX, DX, SI, DI, ES
178;--------------------------------------------------------------------
179ALIGN JUMP_ALIGN
180BootMenuPrint_HardDiskRefreshInformation:       
181    call    RamVars_IsDriveHandledByThisBIOS
182    jnc     SHORT .HardDiskMenuitemInfoForForeignDrive
183    call    FindDPT_ForDriveNumber                      ; DS:DI to point DPT
184    ; Fall to .HardDiskMenuitemInfoForOurDrive
185
186;--------------------------------------------------------------------
187; .HardDiskMenuitemInfoForOurDrive
188;   Parameters:
189;       DL:     Untranslated Hard Disk number
190;       DS:DI:  Ptr to DPT
191;   Returns:
192;       Nothing
193;   Corrupts registers:
194;       AX, BX, CX, DX, SI, DI, ES
195;--------------------------------------------------------------------
196.HardDiskMenuitemInfoForOurDrive:
197    ePUSH_T ax, g_szSizeDual
198       
199    ; Get and push L-CHS size
200    call    AH15h_GetSectorCountToDXAX
201    call    ConvertSectorCountInBXDXAXtoSizeAndPushForFormat
202
203    ; Get and push total LBA size
204    call    BootInfo_GetTotalSectorCount
205    call    ConvertSectorCountInBXDXAXtoSizeAndPushForFormat       
206    jmp     BootMenuPrintCfg_ForOurDrive
207               
208;--------------------------------------------------------------------
209; .HardDiskMenuitemInfoForForeignDrive
210;   Parameters:
211;       DL:     Untranslated Hard Disk number
212;       DS:     RAMVARS segment
213;   Returns:
214;       CF:     Set since menu event was handled successfully
215;   Corrupts registers:
216;       AX, BX, CX, DX, SI, DI
217;--------------------------------------------------------------------
218ALIGN JUMP_ALIGN
219.HardDiskMenuitemInfoForForeignDrive:
220    call    DriveXlate_ToOrBack
221    call    AH15h_GetSectorCountFromForeignDriveToDXAX
222    call    ConvertSectorCountInBXDXAXtoSizeAndPushForFormat
223
224ALIGN JUMP_ALIGN       
225.output:
226    mov     si, g_szCapacity
227;;; fall-through
228
229;--------------------------------------------------------------------
230; BootMenuPrint_FormatCSSIfromParamsInSSBP
231;   Parameters:
232;       CS:SI:  Ptr to string to format
233;       BP:     SP before pushing parameters
234;   Returns:
235;       BP:     Popped from stack
236;       CF:     Set since menu event was handled successfully       
237;   Corrupts registers:
238;       AX, DI
239;--------------------------------------------------------------------
240ALIGN JUMP_ALIGN
241BootMenuPrint_FormatCSSIfromParamsInSSBP:
242    CALL_DISPLAY_LIBRARY FormatNullTerminatedStringFromCSSI
243    stc             ; Successfull return from menu event
244    pop     bp
245    ret
246       
247       
248;--------------------------------------------------------------------
249; BootMenuPrint_ClearScreen
250;   Parameters:
251;       Nothing
252;   Returns:
253;       Nothing
254;   Corrupts registers:
255;       AX, DI
256;--------------------------------------------------------------------
257ALIGN JUMP_ALIGN
258BootMenuPrint_ClearScreen:
259    call    BootMenuPrint_InitializeDisplayContext
260    xor     ax, ax
261    CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
262    mov     ax, ' ' | (MONO_NORMAL<<8)
263    CALL_DISPLAY_LIBRARY ClearScreenWithCharInALandAttrInAH
264    ret
265
266
267;--------------------------------------------------------------------
268; BootMenuPrint_TheBottomOfScreen
269;   Parameters:
270;       DS:     RAMVARS segment
271;   Returns:
272;       Nothing
273;   Corrupts registers:
274;       AX, BX, CX, DX, SI, DI
275;--------------------------------------------------------------------
276ALIGN JUMP_ALIGN
277BootMenuPrint_TheBottomOfScreen:
278    call    FloppyDrive_GetCountToCX
279    mov     bl, cl                  ; Floppy Drive count to BL
280    call    RamVars_GetHardDiskCountFromBDAtoCX
281    mov     bh, cl                  ; Hard Disk count to BH
282    ; Fall to .MoveCursorToHotkeyStrings
283
284;--------------------------------------------------------------------
285; .MoveCursorToHotkeyStrings
286;   Parameters:
287;       Nothing
288;   Returns:
289;       Nothing
290;   Corrupts registers:
291;       AX, DI
292;--------------------------------------------------------------------
293.MoveCursorToHotkeyStrings:
294    CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH
295    xor     al, al
296    dec     ah
297    CALL_DISPLAY_LIBRARY SetCursorCoordinatesFromAX
298    ; Fall to .PrintHotkeyString
299
300;--------------------------------------------------------------------
301; .PrintHotkeyString
302;   Parameters:
303;       BL:     Floppy Drives
304;       BH:     Hard Drives
305;   Returns:
306;       Nothing
307;   Corrupts registers:
308;       AX, CX, DX, SI, DI
309;--------------------------------------------------------------------
310.PrintHotkeyString:
311    ; Display Library should not be called like this
312    mov     si, ATTRIBUTE_CHARS.cHighlightedItem
313    call    MenuAttribute_GetToAXfromTypeInSI
314    xchg    dx, ax
315    mov     cx, MONO_BRIGHT
316
317    test    bl, bl      ; Any Floppy Drives?
318    jz      SHORT .SkipFloppyDriveHotkeys
319    mov     ax, 'A' | (ANGLE_QUOTE_RIGHT<<8)
320    mov     si, g_szFDD
321    call    PushHotkeyParamsAndFormat
322
323.SkipFloppyDriveHotkeys:
324    test    bh, bh      ; Any Hard Drives?
325    jz      SHORT .SkipHardDriveHotkeys
326    xchg    ax, cx      ; Store Key Attribute
327    call    BootMenu_GetLetterForFirstHardDiskToCL
328    mov     ch, ANGLE_QUOTE_RIGHT
329    xchg    ax, cx
330    mov     si, g_szHDD
331    call    PushHotkeyParamsAndFormat
332
333.SkipHardDriveHotkeys:
334    ; Fall to .PrintRomBootHotkey
335
336;--------------------------------------------------------------------
337; .PrintRomBootHotkey
338;   Parameters:
339;       CX:     Key Attribute
340;       DX:     Description Attribute
341;   Returns:
342;       Nothing
343;   Corrupts registers:
344;       AX, SI, DI
345;--------------------------------------------------------------------
346.PrintRomBootHotkey:
347    mov     ax, 'F' | ('8'<<8)      ; F8
348    mov     si, g_szRomBoot
349    ; Fall to PushHotkeyParamsAndFormat
350
351;--------------------------------------------------------------------
352; PushHotkeyParamsAndFormat
353;   Parameters:
354;       AL:     First character
355;       AH:     Second character
356;       CX:     Key Attribute
357;       DX:     Description Attribute
358;       CS:SI:  Description string
359;   Returns:
360;       Nothing
361;   Corrupts registers:
362;       AX, SI, DI
363;--------------------------------------------------------------------
364ALIGN JUMP_ALIGN
365PushHotkeyParamsAndFormat:
366    push    bp
367    mov     bp, sp
368
369    push    cx          ; Key attribute
370    push    ax          ; First character
371    xchg    al, ah
372    push    ax          ; Second character
373    push    dx          ; Description attribute
374    push    si          ; Description string
375    push    cx          ; Key attribute for last space
376    mov     si, g_szHotkey
377       
378BootMenuPrint_FormatCSSIfromParamsInSSBP_Relay: 
379    jmp     SHORT BootMenuPrint_FormatCSSIfromParamsInSSBP
380
381
382;--------------------------------------------------------------------
383; BootMenuPrint_InitializeDisplayContext
384;   Parameters:
385;       Nothing
386;   Returns:
387;       Nothing
388;   Corrupts registers:
389;       AX, DI
390;--------------------------------------------------------------------
391ALIGN JUMP_ALIGN
392BootMenuPrint_InitializeDisplayContext:
393    CALL_DISPLAY_LIBRARY InitializeDisplayContext
394    ret
395
396
397;--------------------------------------------------------------------
398; ConvertSectorCountInBXDXAXtoSizeAndPushForFormat
399;   Parameters:
400;       BX:DX:AX:   Sector count
401;   Returns:
402;       Size in stack
403;   Corrupts registers:
404;       AX, BX, CX, DX, SI
405;--------------------------------------------------------------------
406ALIGN JUMP_ALIGN
407ConvertSectorCountInBXDXAXtoSizeAndPushForFormat:
408    pop     si                      ; Pop return address
409    ePUSH_T cx, g_szCapacityNum     ; Push format substring
410    call    Size_ConvertSectorCountInBXDXAXtoKiB
411    mov     cx, BYTE_MULTIPLES.kiB
412    call    Size_GetSizeToAXAndCharToDLfromBXDXAXwithMagnitudeInCX
413    push    ax                      ; Size in magnitude
414    push    cx                      ; Tenths
415    push    dx                      ; Magnitude character
416    jmp     si
417
418
419FloppyTypes:
420.rgbCapacityMultiplier equ 20           ; Multiplier to reduce word sized values to byte size
421.rgbCapacity:
422    db      360   / FloppyTypes.rgbCapacityMultiplier    ;  type 1
423    db      1200  / FloppyTypes.rgbCapacityMultiplier    ;  type 2
424    db      720   / FloppyTypes.rgbCapacityMultiplier    ;  type 3
425    db      1440  / FloppyTypes.rgbCapacityMultiplier    ;  type 4
426    db      2880  / FloppyTypes.rgbCapacityMultiplier    ;  type 5
427    db      2880  / FloppyTypes.rgbCapacityMultiplier    ;  type 6
428
429
430
431
432       
433
434
435       
Note: See TracBrowser for help on using the repository browser.