source: xtideuniversalbios/trunk/Assembly_Library/Src/Display/DisplayPrint.asm@ 614

Last change on this file since 614 was 592, checked in by Krister Nordvall, 6 years ago

Changes:

  • The problem with NASM in the previous revision (r591) has been fixed.
  • The colors used by the boot menu and hotkey bar can now be customized by selecting one of a number of pre-defined color themes. Suggestions for additional themes are more than welcome!
  • Large builds are now 10 KB. Small builds are still 8 KB with the exception of the Tiny build which is now 4 KB. In other words, builds are now as small as possible to make it easier to combine them with other BIOSes.
  • Added code to the library to improve drive error handling. XTIDECFG can now handle "Drive Not Ready" errors.
  • Fixed a couple of potential bugs in AtaID.asm (AtaID_GetMaxPioModeToAXandMinCycleTimeToCX); 1) ATA1.bPioMode was treated as a WORD variable. 2) ATA2.bPIOSupp was assumed to be non-zero which would result in PIO mode 3 being returned if the assumption was wrong.
  • Made the same changes in the equivalent function used by BIOSDRVS (DisplayPioModeInformationUsingAtaInfoFromDSBX in AtaInfo.asm).
  • Fixed a bug from r587 in PDC20x30.asm in PDC20x30_GetMaxPioModeToALandMinPioCycleTimeToBX.
  • Fixed a bug from r523 in XTIDECFG where Auto Configure would only set the IRQ on one IDE interface on AT-builds.
  • XTIDECFG will now restore the default settings for the "Serial port virtual device" when reselecting it in the list of device types. This makes it behave consistently for all device types.
  • The eAAM macro is now used regardless if USE_UNDOC_INTEL is defined or not because it is apparently supported on all processors including the NEC V20/V30 CPUs.
  • Renamed the EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS define to EXCLUDE_FROM_XUB.
  • Added a define to exclude unused library code from BIOSDRVS (EXCLUDE_FROM_BIOSDRVS). This makes it a lot smaller than in previous revisions.
  • All unnecessary CLD-instructions are now under a new define 'CLD_NEEDED' which is only enabled for the BIOS. It is disabled for XTIDECFG and BIOSDRVS but can be enabled if needed by adding this define to the respective makefile. This change was made because these unnecessary instructions are wasteful and should never be needed. In fact, they only serve to hide bugs (in other peoples code) which I strongly believe should be avoided. I recommend people making their own BIOSes from source to not use this define as it's extremely unlikely to be needed.
  • Updated the copyright info in SerDrive and changed an URL to point to the new site.
  • Updated the copyright info and version number in BIOSDRVS.
  • Updated the copyright info in XTIDECFG.
  • Optimizations in general.
File size: 12.6 KB
Line 
1; Project name : Assembly Library
2; Description : Functions for display output.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
12;
13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
20; Section containing code
21SECTION .text
22
23
24;--------------------------------------------------------------------
25; Supports following formatting types:
26; %a Specifies attribute for next character
27; %A Specifies attribute for remaining string (or until next %A)
28; %d Prints signed 16-bit decimal integer
29; %u Prints unsigned 16-bit decimal integer
30; %x Prints 16-bit hexadecimal integer
31; %s Prints string (from CS segment)
32; %S Prints string (far pointer)
33; %c Prints character
34; %t Prints character number of times (character needs to be pushed first, then repeat times)
35; %% Prints '%' character (no parameter pushed)
36;
37; Any placeholder can be set to minimum length by specifying
38; minimum number of characters. For example %8d would append spaces
39; after integer so that at least 8 characters would be printed.
40;
41; When placing '-' after number, then spaces will be used for prepending.
42; For example %8-d would prepend integer with spaces so that at least
43; 8 characters would be printed.
44;
45; DisplayPrint_FormattedNullTerminatedStringFromCSSI
46; Parameters:
47; BP: SP before pushing parameters
48; DS: BDA segment (zero)
49; CS:SI: Pointer to string to format
50; ES:DI: Ptr to cursor location in video RAM
51; Stack: Parameters for formatting placeholders.
52; Parameter for first placeholder must be pushed first.
53; Low word must pushed first for placeholders requiring
54; 32-bit parameters (two words).
55; Returns:
56; DI: Updated offset to video RAM
57; Corrupts registers:
58; AX, DX
59;--------------------------------------------------------------------
60ALIGN DISPLAY_JUMP_ALIGN
61DisplayPrint_FormattedNullTerminatedStringFromCSSI:
62 push bp
63 push si
64 push cx
65 push bx
66 push WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
67
68 dec bp ; Point BP to...
69 dec bp ; ...first stack parameter
70 call DisplayFormat_ParseCharacters
71
72 ; Pop original character attribute
73 pop ax
74 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
75
76 pop bx
77 pop cx
78 pop si
79 pop bp
80
81 ret
82
83
84;--------------------------------------------------------------------
85; DisplayPrint_SignedWordFromAXWithBaseInBL
86; Parameters:
87; AX: Word to display
88; BL: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
89; DS: BDA segment (zero)
90; ES:DI: Ptr to cursor location in video RAM
91; Returns:
92; DI: Updated offset to video RAM
93; Corrupts registers:
94; AX, BH, DX
95;--------------------------------------------------------------------
96%ifndef EXCLUDE_FROM_XUB
97ALIGN DISPLAY_JUMP_ALIGN
98DisplayPrint_SignedWordFromAXWithBaseInBL:
99 sahf
100 jns SHORT DisplayPrint_WordFromAXWithBaseInBL
101
102 push ax
103 mov al, '-'
104 call DisplayPrint_CharacterFromAL
105 pop ax
106 neg ax
107 ; Fall to DisplayPrint_WordFromAXWithBaseInBL
108%endif
109
110
111;--------------------------------------------------------------------
112; DisplayPrint_WordFromAXWithBaseInBL
113; Parameters:
114; AX: Word to display
115; BL: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
116; DS: BDA segment (zero)
117; ES:DI: Ptr to cursor location in video RAM
118; Returns:
119; DI: Updated offset to video RAM
120; Corrupts registers:
121; AX, BH, DX
122;--------------------------------------------------------------------
123%ifndef MODULE_STRINGS_COMPRESSED
124ALIGN DISPLAY_JUMP_ALIGN
125DisplayPrint_WordFromAXWithBaseInBL:
126 push cx
127
128 xor cx, cx
129 xor bh, bh ; Base now in BX
130ALIGN DISPLAY_JUMP_ALIGN
131.DivideLoop:
132 inc cx ; Increment character count
133 xor dx, dx ; DX:AX now holds the integer
134 div bx ; Divide DX:AX by base
135 push dx ; Push remainder
136 test ax, ax ; All divided?
137 jnz SHORT .DivideLoop ; If not, loop
138
139ALIGN DISPLAY_JUMP_ALIGN
140PrintAllPushedDigits: ; Unused entrypoint OK
141.PrintNextDigit:
142 pop ax ; Pop digit
143 cmp al, 10 ; Convert binary digit in AL to ASCII hex digit ('0'-'9' or 'A'-'F')
144 sbb al, 69h
145 das
146 call DisplayPrint_CharacterFromAL
147 loop .PrintNextDigit
148
149 pop cx
150 ret
151%endif ; ~MODULE_STRINGS_COMPRESSED
152
153;--------------------------------------------------------------------
154; DisplayPrint_QWordFromSSBPwithBaseInBX
155; Parameters:
156; SS:BP: QWord to display
157; BX: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
158; DS: BDA segment (zero)
159; ES:DI: Ptr to cursor location in video RAM
160; Returns:
161; DI: Updated offset to video RAM
162; Corrupts registers:
163; AX, DX, [SS:BP]
164;--------------------------------------------------------------------
165%ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_XTIDECFG
166ALIGN DISPLAY_JUMP_ALIGN
167DisplayPrint_QWordFromSSBPwithBaseInBX:
168 push cx
169
170 mov cx, bx ; CX = Integer base
171 xor bx, bx ; BX = Character count
172ALIGN DISPLAY_JUMP_ALIGN
173.DivideLoop:
174 call Math_DivQWatSSBPbyCX; Divide by base
175 push dx ; Push remainder
176 inc bx ; Increment character count
177 cmp WORD [bp], BYTE 0 ; All divided?
178 jne SHORT .DivideLoop ; If not, loop
179 xchg cx, bx ; Character count to CX, Integer base to BX
180 jmp SHORT PrintAllPushedDigits
181%endif
182
183
184;--------------------------------------------------------------------
185; DisplayPrint_CharacterBufferFromBXSIwithLengthInCX
186; Parameters:
187; CX: Buffer length (characters)
188; BX:SI: Ptr to NULL terminated string
189; DS: BDA segment (zero)
190; ES:DI: Ptr to cursor location in video RAM
191; Returns:
192; DI: Updated offset to video RAM
193; Corrupts registers:
194; AX, DX
195;--------------------------------------------------------------------
196%ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
197ALIGN DISPLAY_JUMP_ALIGN
198DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
199 jcxz .NothingToPrintSinceZeroLength
200 push si
201 push cx
202
203ALIGN DISPLAY_JUMP_ALIGN
204.PrintNextCharacter:
205 mov ds, bx
206 lodsb
207 LOAD_BDA_SEGMENT_TO ds, dx
208 call DisplayPrint_CharacterFromAL
209 loop .PrintNextCharacter
210
211 pop cx
212 pop si
213.NothingToPrintSinceZeroLength:
214 ret
215%endif
216
217
218;--------------------------------------------------------------------
219; DisplayPrint_ClearScreenWithCharInALandAttributeInAH
220; Parameters:
221; AL: Character to clear with
222; AH: Attribute to clear with
223; DS: BDA segment (zero)
224; ES:DI: Ptr to cursor location in video RAM
225; Returns:
226; Nothing
227; Corrupts registers:
228; AX, DX
229;--------------------------------------------------------------------
230%ifdef INCLUDE_MENU_LIBRARY
231ALIGN DISPLAY_JUMP_ALIGN
232DisplayPrint_ClearScreenWithCharInALandAttributeInAH:
233 push di
234 push cx
235
236 xchg cx, ax
237 xor ax, ax
238 call DisplayCursor_SetCoordinatesFromAX ; Updates DI
239 call DisplayPage_GetColumnsToALandRowsToAH
240 mul ah ; AX = AL*AH = Characters on screen
241 xchg cx, ax ; AX = Char+Attr, CX = WORDs to store
242 rep stosw
243
244 pop cx
245 pop di
246 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di
247 ret
248%endif
249
250
251;--------------------------------------------------------------------
252; DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
253; Parameters:
254; AH: Area height
255; AL: Area width
256; DS: BDA segment (zero)
257; ES:DI: Ptr to cursor location in video RAM
258; Returns:
259; DI: Updated offset to video RAM
260; Corrupts registers:
261; AX, DX
262;--------------------------------------------------------------------
263%ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
264ALIGN DISPLAY_JUMP_ALIGN
265DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
266 push si
267 push cx
268 push bx
269
270 xchg bx, ax ; Area size to BX
271 call DisplayCursor_GetSoftwareCoordinatesToAX
272 xchg si, ax ; Software (Y,X) coordinates now in SI
273 xor cx, cx
274
275ALIGN DISPLAY_JUMP_ALIGN
276.ClearRowLoop:
277 mov cl, bl ; Area width now in CX
278 mov al, SCREEN_BACKGROUND_CHARACTER
279 call DisplayPrint_RepeatCharacterFromALwithCountInCX
280
281 xchg ax, si ; Coordinates to AX
282 inc ah ; Increment row
283 mov si, ax
284 call DisplayCursor_SetCoordinatesFromAX
285 dec bh ; Decrement rows left
286 jnz SHORT .ClearRowLoop
287
288 pop bx
289 pop cx
290 pop si
291 ret
292%endif
293
294%ifdef EXCLUDE_FROM_XUB
295 %define EXCLUDE
296 %ifndef MODULE_STRINGS_COMPRESSED
297 %undef EXCLUDE
298 %endif
299 %ifdef MODULE_HOTKEYS OR MODULE_BOOT_MENU
300 %undef EXCLUDE
301 %endif
302%endif
303
304%ifndef EXCLUDE
305;--------------------------------------------------------------------
306; DisplayPrint_RepeatCharacterFromALwithCountInCX
307; Parameters:
308; AL: Character to display
309; CX: Repeat count
310; DS: BDA segment (zero)
311; ES:DI: Ptr to cursor location in video RAM
312; Returns:
313; DI: Updated offset to video RAM
314; Corrupts registers:
315; DX
316;--------------------------------------------------------------------
317ALIGN DISPLAY_JUMP_ALIGN
318DisplayPrint_RepeatCharacterFromALwithCountInCX:
319 jcxz .NothingToRepeat
320 push cx
321
322ALIGN DISPLAY_JUMP_ALIGN
323.RepeatCharacter:
324 push ax
325 call DisplayPrint_CharacterFromAL
326 pop ax
327 loop .RepeatCharacter
328
329 pop cx
330.NothingToRepeat:
331 ret
332%endif
333%undef EXCLUDE
334
335;--------------------------------------------------------------------
336; DisplayPrint_NullTerminatedStringFromCSSI
337; Parameters:
338; CS:SI: Ptr to NULL terminated string
339; DS: BDA segment (zero)
340; ES:DI: Ptr to cursor location in video RAM
341; Returns:
342; DI: Updated offset to video RAM
343; Corrupts registers:
344; AX, DX
345;--------------------------------------------------------------------
346%ifndef MODULE_STRINGS_COMPRESSED
347;;;
348;;; Take care when using this routine with compressed strings (which is why it is disabled).
349;;; All strings in CSSI should go through the DisplayFormatCompressed code to be decoded.
350;;;
351ALIGN DISPLAY_JUMP_ALIGN
352DisplayPrint_NullTerminatedStringFromCSSI:
353 push bx
354 mov bx, cs
355 call DisplayPrint_NullTerminatedStringFromBXSI
356 pop bx
357 ret
358%endif
359
360
361;;;
362;;; Note that the following routines need to be at the bottom of this file
363;;; to accomodate short jumps from the next file (DisplayFormat/DisplayFormatCompressed)
364;;;
365
366;--------------------------------------------------------------------
367; DisplayPrint_Newline
368; Parameters:
369; DS: BDA segment (zero)
370; ES:DI: Ptr to cursor location in video RAM
371; Returns:
372; DI: Updated offset to video RAM
373; Corrupts registers:
374; AX, DX
375;--------------------------------------------------------------------
376%ifdef MODULE_STRINGS_COMPRESSED
377ALIGN DISPLAY_JUMP_ALIGN
378DisplayPrint_Newline_FormatAdjustBP:
379 inc bp ; we didn't need a parameter after all, readjust BP
380 inc bp
381 ; fall through to DisplayPrint_Newline
382%endif
383
384ALIGN DISPLAY_JUMP_ALIGN
385DisplayPrint_Newline:
386 mov al, LF
387 call DisplayPrint_CharacterFromAL
388 mov al, CR
389 ; Fall to DisplayPrint_CharacterFromAL
390
391;--------------------------------------------------------------------
392; DisplayPrint_CharacterFromAL
393; Parameters:
394; AL: Character to display
395; Zero value is ignored (no character is printed)
396; DS: BDA segment (zero)
397; ES:DI: Ptr to cursor location in video RAM
398; Returns:
399; DI: Updated offset to video RAM
400; Corrupts registers:
401; AX, DX
402;--------------------------------------------------------------------
403ALIGN DISPLAY_JUMP_ALIGN
404DisplayPrint_CharacterFromAL:
405 test al, al
406 jz DisplayPrint_Ret
407
408 mov ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
409 jmp [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
410
411
412;--------------------------------------------------------------------
413; DisplayPrint_NullTerminatedStringFromBXSI
414; Parameters:
415; DS: BDA segment (zero)
416; BX:SI: Ptr to NULL terminated string
417; ES:DI: Ptr to cursor location in video RAM
418; Returns:
419; DI: Updated offset to video RAM
420; Corrupts registers:
421; AX, DX
422;--------------------------------------------------------------------
423ALIGN DISPLAY_JUMP_ALIGN
424DisplayPrint_NullTerminatedStringFromBXSI:
425 push si
426 push cx
427
428 xor cx, cx
429ALIGN DISPLAY_JUMP_ALIGN
430.PrintNextCharacter:
431 mov ds, bx ; String segment to DS
432 lodsb
433 mov ds, cx ; BDA segment to DS
434 test al, al ; NULL?
435 jz SHORT .EndOfString
436 call DisplayPrint_CharacterFromAL
437 jmp SHORT .PrintNextCharacter
438
439ALIGN DISPLAY_JUMP_ALIGN
440.EndOfString:
441 pop cx
442 pop si
443
444DisplayPrint_Ret: ; random ret to jump to
445 ret
446
Note: See TracBrowser for help on using the repository browser.