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

Last change on this file since 82 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
Line 
1; File name : Display.asm
2; Project name : Assembly Library
3; Created date : 26.6.2010
4; Last update : 7.12.2010
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.
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.
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;--------------------------------------------------------------------
71; DisplayPrint_SignedWordFromAXWithBaseInBX
72; Parameters:
73; AX: Word to display
74; BX: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
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
83DisplayPrint_SignedWordFromAXWithBaseInBX:
84 test ax, ax
85 jns SHORT DisplayPrint_WordFromAXWithBaseInBX
86
87 push ax
88 mov al, '-'
89 call DisplayPrint_CharacterFromAL
90 pop ax
91 neg ax
92 ; Fall to DisplayPrint_WordFromAXWithBaseInBX
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
109 push bx
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
120
121 mov bx, .rgcDigitToCharacter
122ALIGN JUMP_ALIGN
123.PrintNextDigit:
124 pop ax ; Pop digit
125 eSEG cs
126 xlatb
127 call DisplayPrint_CharacterFromAL
128 loop .PrintNextDigit
129
130 pop bx
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:
150 jcxz .NothingToPrintSinceZeroLength
151 push si
152 push cx
153
154ALIGN JUMP_ALIGN
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
163 pop cx
164 pop si
165.NothingToPrintSinceZeroLength:
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:
182 push bx
183 mov bx, cs
184 call DisplayPrint_NullTerminatedStringFromBXSI
185 pop bx
186 ret
187
188
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:
202 push si
203 push cx
204
205 xor cx, cx
206ALIGN JUMP_ALIGN
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
215
216ALIGN JUMP_ALIGN
217.EndOfString:
218 pop cx
219 pop si
220 ret
221
222
223;--------------------------------------------------------------------
224; DisplayPrint_ClearScreenWithCharInALandAttributeInAH
225; Parameters:
226; AL: Character to clear with
227; AH: Attribute to clear with
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
236DisplayPrint_ClearScreenWithCharInALandAttributeInAH:
237 push di
238 push cx
239
240 xchg cx, ax
241 xor ax, ax
242 call DisplayCursor_SetCoordinatesFromAX ; Updates DI
243 call DisplayPage_GetColumnsToALandRowsToAH
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
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:
262; DI: Updated offset to video RAM
263; Corrupts registers:
264; AX, DX
265;--------------------------------------------------------------------
266ALIGN JUMP_ALIGN
267DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
268 push si
269 push cx
270 push bx
271
272 xchg bx, ax ; Area size to BX
273 call DisplayCursor_GetSoftwareCoordinatesToAX
274 xchg si, ax ; Software (Y,X) coordinates now in SI
275 xor cx, cx
276
277ALIGN JUMP_ALIGN
278.ClearRowLoop:
279 mov cl, bl ; Area width now in CX
280 mov al, SCREEN_BACKGROUND_CHARACTER
281 call DisplayPrint_RepeatCharacterFromALwithCountInCX
282
283 xchg ax, si ; Coordinates to AX
284 inc ah ; Increment row
285 mov si, ax
286 call DisplayCursor_SetCoordinatesFromAX
287 dec bh ; Decrement rows left
288 jnz SHORT .ClearRowLoop
289
290 pop bx
291 pop cx
292 pop si
293 ret
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:
310 jcxz .NothingToRepeat
311 push cx
312
313ALIGN JUMP_ALIGN
314.RepeatCharacter:
315 push ax
316 call DisplayPrint_CharacterFromAL
317 pop ax
318 loop .RepeatCharacter
319
320 pop cx
321.NothingToRepeat:
322 ret
323
324
325;--------------------------------------------------------------------
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:
337 mov al, LF
338 call DisplayPrint_CharacterFromAL
339 mov al, CR
340 ; Fall to DisplayPrint_CharacterFromAL
341
342;--------------------------------------------------------------------
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.