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

Last change on this file since 95 was 67, checked in by Tomi Tilli, 14 years ago

Changes to Assembly Library:

  • Forgot to update SI on new File Read and Write functions.
  • Screen clearing function now accepts any character and attribute.
  • Menu library now accepts CR,LF combination as line feed. Previously only LF,CR worked properly.
File size: 9.6 KB
RevLine 
[41]1; File name : Display.asm
2; Project name : Assembly Library
3; Created date : 26.6.2010
[67]4; Last update : 7.12.2010
[41]5; Author : Tomi Tilli
6; Description : Functions for display output.
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; Supports following formatting types:
13; %a Specifies attribute for next character
14; %A Specifies attribute for remaining string (or until next %A)
15; %d Prints signed 16-bit decimal integer
16; %u Prints unsigned 16-bit decimal integer
17; %x Prints 16-bit hexadecimal integer
18; %s Prints string (from CS segment)
19; %S Prints string (far pointer)
20; %c Prints character
21; %t Prints character number of times (character needs to be pushed first, then repeat times)
22; %% Prints '%' character (no parameter pushed)
23;
24; Any placeholder can be set to minimum length by specifying
25; minimum number of characters. For example %8d would append spaces
26; after integer so that at least 8 characters would be printed.
[48]27;
28; When placing '-' after number, then spaces will be used for prepending.
29; For example %8-d would prepend integer with spaces so that at least
30; 8 characters would be printed.
[41]31;
32; DisplayPrint_FormattedNullTerminatedStringFromCSSI
33; Parameters:
34; BP: SP before pushing parameters
35; DS: BDA segment (zero)
36; CS:SI: Pointer to string to format
37; ES:DI: Ptr to cursor location in video RAM
38; Stack: Parameters for formatting placeholders.
39; Parameter for first placeholder must be pushed first.
40; Low word must pushed first for placeholders requiring
41; 32-bit parameters (two words).
42; Returns:
43; DI: Updated offset to video RAM
44; Corrupts registers:
45; AX, DX
46;--------------------------------------------------------------------
47ALIGN JUMP_ALIGN
48DisplayPrint_FormattedNullTerminatedStringFromCSSI:
49 push bp
50 push si
51 push cx
52 push bx
53 push WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
54
55 dec bp ; Point BP to...
56 dec bp ; ...first stack parameter
57 call DisplayFormat_ParseCharacters
58
59 ; Pop original character attribute
60 pop ax
61 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
62
63 pop bx
64 pop cx
65 pop si
66 pop bp
67 ret
68
69
70;--------------------------------------------------------------------
[44]71; DisplayPrint_SignedWordFromAXWithBaseInBX
[41]72; Parameters:
73; AX: Word to display
[44]74; BX: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
[41]75; DS: BDA segment (zero)
76; ES:DI: Ptr to cursor location in video RAM
77; Returns:
78; DI: Updated offset to video RAM
79; Corrupts registers:
80; AX, DX
81;--------------------------------------------------------------------
82ALIGN JUMP_ALIGN
[44]83DisplayPrint_SignedWordFromAXWithBaseInBX:
84 test ax, ax
85 jns SHORT DisplayPrint_WordFromAXWithBaseInBX
[41]86
87 push ax
88 mov al, '-'
89 call DisplayPrint_CharacterFromAL
90 pop ax
91 neg ax
[44]92 ; Fall to DisplayPrint_WordFromAXWithBaseInBX
[41]93
94;--------------------------------------------------------------------
95; DisplayPrint_WordFromAXWithBaseInBX
96; Parameters:
97; AX: Word to display
98; BX: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
99; DS: BDA segment (zero)
100; ES:DI: Ptr to cursor location in video RAM
101; Returns:
102; DI: Updated offset to video RAM
103; Corrupts registers:
104; AX, DX
105;--------------------------------------------------------------------
106ALIGN JUMP_ALIGN
107DisplayPrint_WordFromAXWithBaseInBX:
108 push cx
[44]109 push bx
[41]110
111 xor cx, cx
112ALIGN JUMP_ALIGN
113.DivideLoop:
114 xor dx, dx ; DX:AX now holds the integer
115 div bx ; Divide DX:AX by base
116 push dx ; Push remainder
117 inc cx ; Increment character count
118 test ax, ax ; All divided?
119 jnz SHORT .DivideLoop ; If not, loop
[44]120
121 mov bx, .rgcDigitToCharacter
[41]122ALIGN JUMP_ALIGN
[44]123.PrintNextDigit:
124 pop ax ; Pop digit
125 eSEG cs
126 xlatb
[41]127 call DisplayPrint_CharacterFromAL
[44]128 loop .PrintNextDigit
[41]129
[44]130 pop bx
[41]131 pop cx
132 ret
133.rgcDigitToCharacter: db "0123456789ABCDEF"
134
135
136;--------------------------------------------------------------------
137; DisplayPrint_CharacterBufferFromBXSIwithLengthInCX
138; Parameters:
139; CX: Buffer length (characters)
140; BX:SI: Ptr to NULL terminated string
141; DS: BDA segment (zero)
142; ES:DI: Ptr to cursor location in video RAM
143; Returns:
144; DI: Updated offset to video RAM
145; Corrupts registers:
146; AX, DX
147;--------------------------------------------------------------------
148ALIGN JUMP_ALIGN
149DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
[44]150 jcxz .NothingToPrintSinceZeroLength
151 push si
[41]152 push cx
153
154ALIGN JUMP_ALIGN
[44]155.PrintNextCharacter:
156 mov ds, bx
157 lodsb
158 LOAD_BDA_SEGMENT_TO ds, dx
159 call DisplayPrint_CharacterFromAL
160 loop .PrintNextCharacter
161
162 LOAD_BDA_SEGMENT_TO ds, dx
[41]163 pop cx
[44]164 pop si
165.NothingToPrintSinceZeroLength:
[41]166 ret
167
168
169;--------------------------------------------------------------------
170; DisplayPrint_NullTerminatedStringFromCSSI
171; Parameters:
172; CS:SI: Ptr to NULL terminated string
173; DS: BDA segment (zero)
174; ES:DI: Ptr to cursor location in video RAM
175; Returns:
176; DI: Updated offset to video RAM
177; Corrupts registers:
178; AX, DX
179;--------------------------------------------------------------------
180ALIGN JUMP_ALIGN
181DisplayPrint_NullTerminatedStringFromCSSI:
[44]182 push bx
[41]183 mov bx, cs
[44]184 call DisplayPrint_NullTerminatedStringFromBXSI
185 pop bx
186 ret
[41]187
[44]188
[41]189;--------------------------------------------------------------------
190; DisplayPrint_NullTerminatedStringFromBXSI
191; Parameters:
192; DS: BDA segment (zero)
193; BX:SI: Ptr to NULL terminated string
194; ES:DI: Ptr to cursor location in video RAM
195; Returns:
196; DI: Updated offset to video RAM
197; Corrupts registers:
198; AX, DX
199;--------------------------------------------------------------------
200ALIGN JUMP_ALIGN
201DisplayPrint_NullTerminatedStringFromBXSI:
[44]202 push si
203 push cx
[41]204
[44]205 xor cx, cx
[41]206ALIGN JUMP_ALIGN
[44]207.PrintNextCharacter:
208 mov ds, bx ; String segment to DS
209 lodsb
210 mov ds, cx ; BDA segment to DS
211 test al, al ; NULL?
212 jz SHORT .EndOfString
213 call DisplayPrint_CharacterFromAL
214 jmp SHORT .PrintNextCharacter
[41]215
216ALIGN JUMP_ALIGN
[44]217.EndOfString:
218 pop cx
219 pop si
[41]220 ret
221
222
223;--------------------------------------------------------------------
[67]224; DisplayPrint_ClearScreenWithCharInALandAttributeInAH
[41]225; Parameters:
[67]226; AL: Character to clear with
227; AH: Attribute to clear with
[41]228; DS: BDA segment (zero)
229; ES:DI: Ptr to cursor location in video RAM
230; Returns:
231; Nothing
232; Corrupts registers:
233; AX, DX
234;--------------------------------------------------------------------
235ALIGN JUMP_ALIGN
[67]236DisplayPrint_ClearScreenWithCharInALandAttributeInAH:
[41]237 push di
[67]238 push cx
239
240 xchg cx, ax
[41]241 xor ax, ax
[67]242 call DisplayCursor_SetCoordinatesFromAX ; Updates DI
[41]243 call DisplayPage_GetColumnsToALandRowsToAH
[67]244 mul ah ; AX = AL*AH = Characters on screen
245 xchg cx, ax ; AX = Char+Attr, CX = WORDs to store
246 rep stosw
247
248 pop cx
[41]249 pop di
250 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di
251 ret
252
253
254;--------------------------------------------------------------------
255; DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
256; Parameters:
257; AH: Area height
258; AL: Area width
259; DS: BDA segment (zero)
260; ES:DI: Ptr to cursor location in video RAM
261; Returns:
[42]262; DI: Updated offset to video RAM
[41]263; Corrupts registers:
264; AX, DX
265;--------------------------------------------------------------------
266ALIGN JUMP_ALIGN
267DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
[42]268 push si
[41]269 push cx
270 push bx
271
[42]272 xchg bx, ax ; Area size to BX
[41]273 call DisplayCursor_GetSoftwareCoordinatesToAX
[42]274 xchg si, ax ; Software (Y,X) coordinates now in SI
275 xor cx, cx
[41]276
277ALIGN JUMP_ALIGN
[42]278.ClearRowLoop:
279 mov cl, bl ; Area width now in CX
[44]280 mov al, SCREEN_BACKGROUND_CHARACTER
[42]281 call DisplayPrint_RepeatCharacterFromALwithCountInCX
[41]282
[42]283 xchg ax, si ; Coordinates to AX
284 inc ah ; Increment row
285 mov si, ax
[41]286 call DisplayCursor_SetCoordinatesFromAX
[42]287 dec bh ; Decrement rows left
288 jnz SHORT .ClearRowLoop
[41]289
290 pop bx
291 pop cx
[42]292 pop si
[41]293 ret
[42]294
295
296;--------------------------------------------------------------------
297; DisplayPrint_RepeatCharacterFromALwithCountInCX
298; Parameters:
299; AL: Character to display
300; CX: Repeat count
301; DS: BDA segment (zero)
302; ES:DI: Ptr to cursor location in video RAM
303; Returns:
304; DI: Updated offset to video RAM
305; Corrupts registers:
306; AX, DX
307;--------------------------------------------------------------------
308ALIGN JUMP_ALIGN
309DisplayPrint_RepeatCharacterFromALwithCountInCX:
[44]310 jcxz .NothingToRepeat
311 push cx
312
313ALIGN JUMP_ALIGN
314.RepeatCharacter:
[42]315 push ax
316 call DisplayPrint_CharacterFromAL
317 pop ax
[44]318 loop .RepeatCharacter
319
320 pop cx
321.NothingToRepeat:
[42]322 ret
323
324
325;--------------------------------------------------------------------
[44]326; DisplayPrint_Newline
327; Parameters:
328; DS: BDA segment (zero)
329; ES:DI: Ptr to cursor location in video RAM
330; Returns:
331; DI: Updated offset to video RAM
332; Corrupts registers:
333; AX, DX
334;--------------------------------------------------------------------
335ALIGN JUMP_ALIGN
336DisplayPrint_Newline:
[52]337 mov al, LF
338 call DisplayPrint_CharacterFromAL
[44]339 mov al, CR
340 ; Fall to DisplayPrint_CharacterFromAL
341
342;--------------------------------------------------------------------
[42]343; DisplayPrint_CharacterFromAL
344; Parameters:
345; AL: Character to display
346; DS: BDA segment (zero)
347; ES:DI: Ptr to cursor location in video RAM
348; Returns:
349; DI: Updated offset to video RAM
350; Corrupts registers:
351; AX, DX
352;--------------------------------------------------------------------
353ALIGN JUMP_ALIGN
354DisplayPrint_CharacterFromAL:
355 mov ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
356 jmp [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
Note: See TracBrowser for help on using the repository browser.