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
RevLine 
[41]1; Project name  :   Assembly Library
2; Description   :   Functions for display output.
3
4; Section containing code
5SECTION .text
6
[223]7
[41]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.
[48]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.
[162]28;
[41]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
[186]64
[41]65    ret
66
67
68;--------------------------------------------------------------------
[44]69; DisplayPrint_SignedWordFromAXWithBaseInBX
[41]70;   Parameters:
71;       AX:     Word to display
[44]72;       BX:     Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
[41]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;--------------------------------------------------------------------
[134]80%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]81ALIGN JUMP_ALIGN
[44]82DisplayPrint_SignedWordFromAXWithBaseInBX:
83    test    ax, ax
84    jns     SHORT DisplayPrint_WordFromAXWithBaseInBX
[41]85
86    push    ax
87    mov     al, '-'
88    call    DisplayPrint_CharacterFromAL
89    pop     ax
90    neg     ax
[44]91    ; Fall to DisplayPrint_WordFromAXWithBaseInBX
[134]92%endif
[41]93
[323]94
95%ifndef MODULE_STRINGS_COMPRESSED
[41]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
[323]107;--------------------------------------------------------------------
[41]108ALIGN JUMP_ALIGN
109DisplayPrint_WordFromAXWithBaseInBX:
110    push    cx
[44]111    push    bx
[41]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
[44]122
[323]123PrintAllPushedDigits:
124    mov     bx, g_rgcDigitToCharacter
[41]125ALIGN JUMP_ALIGN
[44]126.PrintNextDigit:
127    pop     ax                  ; Pop digit
[223]128    cs xlatb
[41]129    call    DisplayPrint_CharacterFromAL
[44]130    loop    .PrintNextDigit
[41]131
[44]132    pop     bx
[41]133    pop     cx
134    ret
[341]135
[323]136g_rgcDigitToCharacter:  db  "0123456789ABCDEF"
[341]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
[186]168
169%endif  ; MODULE_STRINGS_COMPRESSED
[41]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;--------------------------------------------------------------------
[223]184%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]185ALIGN JUMP_ALIGN
186DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
[44]187    jcxz    .NothingToPrintSinceZeroLength
188    push    si
[41]189    push    cx
190
191ALIGN JUMP_ALIGN
[44]192.PrintNextCharacter:
193    mov     ds, bx
194    lodsb
195    LOAD_BDA_SEGMENT_TO ds, dx
196    call    DisplayPrint_CharacterFromAL
197    loop    .PrintNextCharacter
198
[41]199    pop     cx
[44]200    pop     si
201.NothingToPrintSinceZeroLength:
[41]202    ret
[194]203%endif
[41]204
[186]205
[41]206;--------------------------------------------------------------------
[67]207; DisplayPrint_ClearScreenWithCharInALandAttributeInAH
[41]208;   Parameters:
[67]209;       AL:     Character to clear with
210;       AH:     Attribute to clear with
[41]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
[67]219DisplayPrint_ClearScreenWithCharInALandAttributeInAH:
[41]220    push    di
[67]221    push    cx
222
223    xchg    cx, ax
[41]224    xor     ax, ax
[67]225    call    DisplayCursor_SetCoordinatesFromAX      ; Updates DI
[41]226    call    DisplayPage_GetColumnsToALandRowsToAH
[67]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
[41]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:
[42]245;       DI:     Updated offset to video RAM
[41]246;   Corrupts registers:
247;       AX, DX
248;--------------------------------------------------------------------
[134]249%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]250ALIGN JUMP_ALIGN
251DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
[42]252    push    si
[41]253    push    cx
254    push    bx
255
[42]256    xchg    bx, ax                          ; Area size to BX
[41]257    call    DisplayCursor_GetSoftwareCoordinatesToAX
[42]258    xchg    si, ax                          ; Software (Y,X) coordinates now in SI
259    xor     cx, cx
[41]260
261ALIGN JUMP_ALIGN
[42]262.ClearRowLoop:
263    mov     cl, bl                          ; Area width now in CX
[44]264    mov     al, SCREEN_BACKGROUND_CHARACTER
[42]265    call    DisplayPrint_RepeatCharacterFromALwithCountInCX
[41]266
[42]267    xchg    ax, si                          ; Coordinates to AX
268    inc     ah                              ; Increment row
269    mov     si, ax
[41]270    call    DisplayCursor_SetCoordinatesFromAX
[42]271    dec     bh                              ; Decrement rows left
272    jnz     SHORT .ClearRowLoop
[41]273
274    pop     bx
275    pop     cx
[42]276    pop     si
[41]277    ret
[134]278%endif
[42]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:
[181]291;       DX
[42]292;--------------------------------------------------------------------
293ALIGN JUMP_ALIGN
294DisplayPrint_RepeatCharacterFromALwithCountInCX:
[44]295    jcxz    .NothingToRepeat
296    push    cx
297
298ALIGN JUMP_ALIGN
299.RepeatCharacter:
[42]300    push    ax
301    call    DisplayPrint_CharacterFromAL
302    pop     ax
[44]303    loop    .RepeatCharacter
304
305    pop     cx
306.NothingToRepeat:
[42]307    ret
[223]308
[186]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.
[223]325;;;
[186]326ALIGN JUMP_ALIGN
327DisplayPrint_NullTerminatedStringFromCSSI:
328    push    bx
329    mov     bx, cs
330    call    DisplayPrint_NullTerminatedStringFromBXSI
331    pop     bx
332    ret
333%endif
[42]334
335
[186]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)
[223]339;;;
[186]340
[42]341;--------------------------------------------------------------------
[44]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;--------------------------------------------------------------------
[186]351%ifdef MODULE_STRINGS_COMPRESSED
[44]352ALIGN JUMP_ALIGN
[186]353DisplayPrint_Newline_FormatAdjustBP:
[223]354    inc     bp                  ; we didn't need a parameter after all, readjust BP
[186]355    inc     bp
[194]356    ; fall through to DisplayPrint_Newline
[186]357%endif
358
[223]359ALIGN JUMP_ALIGN
[44]360DisplayPrint_Newline:
[52]361    mov     al, LF
362    call    DisplayPrint_CharacterFromAL
[44]363    mov     al, CR
364    ; Fall to DisplayPrint_CharacterFromAL
365
366;--------------------------------------------------------------------
[42]367; DisplayPrint_CharacterFromAL
368;   Parameters:
369;       AL:     Character to display
[186]370;               Zero value is ignored (no characer is printed)
[42]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:
[186]380    test    al,al
381    jz      DisplayPrint_Ret
[241]382
[42]383    mov     ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
384    jmp     [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
[186]385
[223]386
[186]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
[223]418
419DisplayPrint_Ret:               ; random ret to jump to
[186]420    ret
421
Note: See TracBrowser for help on using the repository browser.