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

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

Changes:

  • Fixed a bug from r323 in DisplayPrint.asm.
  • Removed some unused code from XTIDECFG (undoing the change to Math.asm in r336 as part of it).
File size: 11.5 KB
Line 
1; Project name  :   Assembly Library
2; Description   :   Functions for display output.
3
4; Section containing code
5SECTION .text
6
7
8;--------------------------------------------------------------------
9; Supports following formatting types:
10;   %a      Specifies attribute for next character
11;   %A      Specifies attribute for remaining string (or until next %A)
12;   %d      Prints signed 16-bit decimal integer
13;   %u      Prints unsigned 16-bit decimal integer
14;   %x      Prints 16-bit hexadecimal integer
15;   %s      Prints string (from CS segment)
16;   %S      Prints string (far pointer)
17;   %c      Prints character
18;   %t      Prints character number of times (character needs to be pushed first, then repeat times)
19;   %%      Prints '%' character (no parameter pushed)
20;
21;   Any placeholder can be set to minimum length by specifying
22;   minimum number of characters. For example %8d would append spaces
23;   after integer so that at least 8 characters would be printed.
24;
25;   When placing '-' after number, then spaces will be used for prepending.
26;   For example %8-d would prepend integer with spaces so that at least
27;   8 characters would be printed.
28;
29; DisplayPrint_FormattedNullTerminatedStringFromCSSI
30;   Parameters:
31;       BP:     SP before pushing parameters
32;       DS:     BDA segment (zero)
33;       CS:SI:  Pointer to string to format
34;       ES:DI:  Ptr to cursor location in video RAM
35;       Stack:  Parameters for formatting placeholders.
36;               Parameter for first placeholder must be pushed first.
37;               Low word must pushed first for placeholders requiring
38;               32-bit parameters (two words).
39;   Returns:
40;       DI:     Updated offset to video RAM
41;   Corrupts registers:
42;       AX, DX
43;--------------------------------------------------------------------
44ALIGN JUMP_ALIGN
45DisplayPrint_FormattedNullTerminatedStringFromCSSI:
46    push    bp
47    push    si
48    push    cx
49    push    bx
50    push    WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
51
52    dec     bp                  ; Point BP to...
53    dec     bp                  ; ...first stack parameter
54    call    DisplayFormat_ParseCharacters
55
56    ; Pop original character attribute
57    pop     ax
58    mov     [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
59
60    pop     bx
61    pop     cx
62    pop     si
63    pop     bp
64
65    ret
66
67
68;--------------------------------------------------------------------
69; DisplayPrint_SignedWordFromAXWithBaseInBX
70;   Parameters:
71;       AX:     Word to display
72;       BX:     Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
73;       DS:     BDA segment (zero)
74;       ES:DI:  Ptr to cursor location in video RAM
75;   Returns:
76;       DI:     Updated offset to video RAM
77;   Corrupts registers:
78;       AX, DX
79;--------------------------------------------------------------------
80%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
81ALIGN JUMP_ALIGN
82DisplayPrint_SignedWordFromAXWithBaseInBX:
83    test    ax, ax
84    jns     SHORT DisplayPrint_WordFromAXWithBaseInBX
85
86    push    ax
87    mov     al, '-'
88    call    DisplayPrint_CharacterFromAL
89    pop     ax
90    neg     ax
91    ; Fall to DisplayPrint_WordFromAXWithBaseInBX
92%endif
93
94
95%ifndef MODULE_STRINGS_COMPRESSED
96;--------------------------------------------------------------------
97; DisplayPrint_WordFromAXWithBaseInBX
98;   Parameters:
99;       AX:     Word to display
100;       BX:     Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
101;       DS:     BDA segment (zero)
102;       ES:DI:  Ptr to cursor location in video RAM
103;   Returns:
104;       DI:     Updated offset to video RAM
105;   Corrupts registers:
106;       AX, DX
107;--------------------------------------------------------------------
108ALIGN JUMP_ALIGN
109DisplayPrint_WordFromAXWithBaseInBX:
110    push    cx
111    push    bx
112
113    xor     cx, cx
114ALIGN JUMP_ALIGN
115.DivideLoop:
116    xor     dx, dx              ; DX:AX now holds the integer
117    div     bx                  ; Divide DX:AX by base
118    push    dx                  ; Push remainder
119    inc     cx                  ; Increment character count
120    test    ax, ax              ; All divided?
121    jnz     SHORT .DivideLoop   ;  If not, loop
122
123PrintAllPushedDigits:
124    mov     bx, g_rgcDigitToCharacter
125ALIGN JUMP_ALIGN
126.PrintNextDigit:
127    pop     ax                  ; Pop digit
128    cs xlatb
129    call    DisplayPrint_CharacterFromAL
130    loop    .PrintNextDigit
131
132    pop     bx
133    pop     cx
134    ret
135
136g_rgcDigitToCharacter:  db  "0123456789ABCDEF"
137
138;--------------------------------------------------------------------
139; DisplayPrint_QWordFromSSBPwithBaseInBX
140;   Parameters:
141;       SS:BP:  QWord to display
142;       BX:     Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
143;       DS:     BDA segment (zero)
144;       ES:DI:  Ptr to cursor location in video RAM
145;   Returns:
146;       DI:     Updated offset to video RAM
147;   Corrupts registers:
148;       AX, DX, [SS:BP]
149;--------------------------------------------------------------------
150%ifndef EXCLUDE_FROM_XTIDECFG   ; Not used in XTIDECFG
151ALIGN JUMP_ALIGN
152DisplayPrint_QWordFromSSBPwithBaseInBX:
153    push    cx
154    push    bx
155
156    mov     cx, bx              ; CX = Integer base
157    xor     bx, bx              ; BX = Character count
158ALIGN JUMP_ALIGN
159.DivideLoop:
160    call    Math_DivQWatSSBPbyCX; Divide by base
161    push    dx                  ; Push remainder
162    inc     bx                  ; Increment character count
163    cmp     WORD [bp], BYTE 0   ; All divided?
164    jne     SHORT .DivideLoop   ;  If not, loop
165    mov     cx, bx              ; Character count to CX
166    jmp     SHORT PrintAllPushedDigits
167%endif  ; EXCLUDE_FROM_XTIDECFG
168
169%endif  ; MODULE_STRINGS_COMPRESSED
170
171
172;--------------------------------------------------------------------
173; DisplayPrint_CharacterBufferFromBXSIwithLengthInCX
174;   Parameters:
175;       CX:     Buffer length (characters)
176;       BX:SI:  Ptr to NULL terminated string
177;       DS:     BDA segment (zero)
178;       ES:DI:  Ptr to cursor location in video RAM
179;   Returns:
180;       DI:     Updated offset to video RAM
181;   Corrupts registers:
182;       AX, DX
183;--------------------------------------------------------------------
184%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
185ALIGN JUMP_ALIGN
186DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
187    jcxz    .NothingToPrintSinceZeroLength
188    push    si
189    push    cx
190
191ALIGN JUMP_ALIGN
192.PrintNextCharacter:
193    mov     ds, bx
194    lodsb
195    LOAD_BDA_SEGMENT_TO ds, dx
196    call    DisplayPrint_CharacterFromAL
197    loop    .PrintNextCharacter
198
199    pop     cx
200    pop     si
201.NothingToPrintSinceZeroLength:
202    ret
203%endif
204
205
206;--------------------------------------------------------------------
207; DisplayPrint_ClearScreenWithCharInALandAttributeInAH
208;   Parameters:
209;       AL:     Character to clear with
210;       AH:     Attribute to clear with
211;       DS:     BDA segment (zero)
212;       ES:DI:  Ptr to cursor location in video RAM
213;   Returns:
214;       Nothing
215;   Corrupts registers:
216;       AX, DX
217;--------------------------------------------------------------------
218ALIGN JUMP_ALIGN
219DisplayPrint_ClearScreenWithCharInALandAttributeInAH:
220    push    di
221    push    cx
222
223    xchg    cx, ax
224    xor     ax, ax
225    call    DisplayCursor_SetCoordinatesFromAX      ; Updates DI
226    call    DisplayPage_GetColumnsToALandRowsToAH
227    mul     ah      ; AX = AL*AH = Characters on screen
228    xchg    cx, ax  ; AX = Char+Attr, CX = WORDs to store
229    rep stosw
230
231    pop     cx
232    pop     di
233    mov     [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di
234    ret
235
236
237;--------------------------------------------------------------------
238; DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
239;   Parameters:
240;       AH:     Area height
241;       AL:     Area width
242;       DS:     BDA segment (zero)
243;       ES:DI:  Ptr to cursor location in video RAM
244;   Returns:
245;       DI:     Updated offset to video RAM
246;   Corrupts registers:
247;       AX, DX
248;--------------------------------------------------------------------
249%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
250ALIGN JUMP_ALIGN
251DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
252    push    si
253    push    cx
254    push    bx
255
256    xchg    bx, ax                          ; Area size to BX
257    call    DisplayCursor_GetSoftwareCoordinatesToAX
258    xchg    si, ax                          ; Software (Y,X) coordinates now in SI
259    xor     cx, cx
260
261ALIGN JUMP_ALIGN
262.ClearRowLoop:
263    mov     cl, bl                          ; Area width now in CX
264    mov     al, SCREEN_BACKGROUND_CHARACTER
265    call    DisplayPrint_RepeatCharacterFromALwithCountInCX
266
267    xchg    ax, si                          ; Coordinates to AX
268    inc     ah                              ; Increment row
269    mov     si, ax
270    call    DisplayCursor_SetCoordinatesFromAX
271    dec     bh                              ; Decrement rows left
272    jnz     SHORT .ClearRowLoop
273
274    pop     bx
275    pop     cx
276    pop     si
277    ret
278%endif
279
280
281;--------------------------------------------------------------------
282; DisplayPrint_RepeatCharacterFromALwithCountInCX
283;   Parameters:
284;       AL:     Character to display
285;       CX:     Repeat count
286;       DS:     BDA segment (zero)
287;       ES:DI:  Ptr to cursor location in video RAM
288;   Returns:
289;       DI:     Updated offset to video RAM
290;   Corrupts registers:
291;       DX
292;--------------------------------------------------------------------
293ALIGN JUMP_ALIGN
294DisplayPrint_RepeatCharacterFromALwithCountInCX:
295    jcxz    .NothingToRepeat
296    push    cx
297
298ALIGN JUMP_ALIGN
299.RepeatCharacter:
300    push    ax
301    call    DisplayPrint_CharacterFromAL
302    pop     ax
303    loop    .RepeatCharacter
304
305    pop     cx
306.NothingToRepeat:
307    ret
308
309
310;--------------------------------------------------------------------
311; DisplayPrint_NullTerminatedStringFromCSSI
312;   Parameters:
313;       CS:SI:  Ptr to NULL terminated string
314;       DS:     BDA segment (zero)
315;       ES:DI:  Ptr to cursor location in video RAM
316;   Returns:
317;       DI:     Updated offset to video RAM
318;   Corrupts registers:
319;       AX, DX
320;--------------------------------------------------------------------
321%ifndef MODULE_STRINGS_COMPRESSED
322;;;
323;;; Take care when using this routine with compressed strings (which is why it is disabled).
324;;; All strings in CSSI should go through the DisplayFormatCompressed code to be decoded.
325;;;
326ALIGN JUMP_ALIGN
327DisplayPrint_NullTerminatedStringFromCSSI:
328    push    bx
329    mov     bx, cs
330    call    DisplayPrint_NullTerminatedStringFromBXSI
331    pop     bx
332    ret
333%endif
334
335
336;;;
337;;; Note that the following routines need to be at the bottom of this file
338;;; to accomodate short jumps from the next file (DisplayFormat/DisplayFormatCompressed)
339;;;
340
341;--------------------------------------------------------------------
342; DisplayPrint_Newline
343;   Parameters:
344;       DS:     BDA segment (zero)
345;       ES:DI:  Ptr to cursor location in video RAM
346;   Returns:
347;       DI:     Updated offset to video RAM
348;   Corrupts registers:
349;       AX, DX
350;--------------------------------------------------------------------
351%ifdef MODULE_STRINGS_COMPRESSED
352ALIGN JUMP_ALIGN
353DisplayPrint_Newline_FormatAdjustBP:
354    inc     bp                  ; we didn't need a parameter after all, readjust BP
355    inc     bp
356    ; fall through to DisplayPrint_Newline
357%endif
358
359ALIGN JUMP_ALIGN
360DisplayPrint_Newline:
361    mov     al, LF
362    call    DisplayPrint_CharacterFromAL
363    mov     al, CR
364    ; Fall to DisplayPrint_CharacterFromAL
365
366;--------------------------------------------------------------------
367; DisplayPrint_CharacterFromAL
368;   Parameters:
369;       AL:     Character to display
370;               Zero value is ignored (no characer is printed)
371;       DS:     BDA segment (zero)
372;       ES:DI:  Ptr to cursor location in video RAM
373;   Returns:
374;       DI:     Updated offset to video RAM
375;   Corrupts registers:
376;       AX, DX
377;--------------------------------------------------------------------
378ALIGN JUMP_ALIGN
379DisplayPrint_CharacterFromAL:
380    test    al,al
381    jz      DisplayPrint_Ret
382
383    mov     ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
384    jmp     [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
385
386
387;--------------------------------------------------------------------
388; DisplayPrint_NullTerminatedStringFromBXSI
389;   Parameters:
390;       DS:     BDA segment (zero)
391;       BX:SI:  Ptr to NULL terminated string
392;       ES:DI:  Ptr to cursor location in video RAM
393;   Returns:
394;       DI:     Updated offset to video RAM
395;   Corrupts registers:
396;       AX, DX
397;--------------------------------------------------------------------
398ALIGN JUMP_ALIGN
399DisplayPrint_NullTerminatedStringFromBXSI:
400    push    si
401    push    cx
402
403    xor     cx, cx
404ALIGN JUMP_ALIGN
405.PrintNextCharacter:
406    mov     ds, bx              ; String segment to DS
407    lodsb
408    mov     ds, cx              ; BDA segment to DS
409    test    al, al              ; NULL?
410    jz      SHORT .EndOfString
411    call    DisplayPrint_CharacterFromAL
412    jmp     SHORT .PrintNextCharacter
413
414ALIGN JUMP_ALIGN
415.EndOfString:
416    pop     cx
417    pop     si
418
419DisplayPrint_Ret:               ; random ret to jump to
420    ret
421
Note: See TracBrowser for help on using the repository browser.