source: xtideuniversalbios/trunk/Assembly_Library/Src/Display/DisplayFormat.asm@ 50

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

Changes to Assembly Library:
Added functions to clear Menu Title and Information areas.
Implemented automatic line change when writing Menu Title and Information areas.
CGA snow related functions have been moved to CgaSnow.asm.
Keyboard input functions no longer produce beep for backspace.

File size: 10.5 KB
RevLine 
[41]1; File name : DisplayFormat.asm
2; Project name : Assembly Library
3; Created date : 29.6.2010
[48]4; Last update : 8.10.2010
[41]5; Author : Tomi Tilli
6; Description : Functions for displaying formatted strings.
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; DisplayFormat_ParseCharacters
13; Parameters:
14; DS: BDA segment (zero)
[44]15; SS:BP: Pointer to first format parameter (-=2 updates to next parameter)
[41]16; CS:SI: Pointer to string to format
17; ES:DI: Ptr to cursor location in video RAM
18; Returns:
[44]19; CS:SI: Ptr to end of format string (ptr to one past NULL)
[41]20; DI: Updated offset to video RAM
21; Corrupts registers:
[44]22; AX, BX, CX, DX, BP
[41]23;--------------------------------------------------------------------
24ALIGN JUMP_ALIGN
25DisplayFormat_ParseCharacters:
[44]26 call ReadCharacterAndTestForNull
27 jz SHORT .QuitCharacterParsing
28
29 ePUSH_T cx, DisplayFormat_ParseCharacters ; Return address
30 xor cx, cx ; Initial placeholder size
31 cmp al, '%' ; Format specifier?
32 je SHORT ParseFormatSpecifier
33 jmp DisplayPrint_CharacterFromAL
34
[41]35ALIGN JUMP_ALIGN
[44]36.QuitCharacterParsing:
[41]37 ret
38
[44]39
[41]40;--------------------------------------------------------------------
[44]41; ParseFormatSpecifier
[41]42; Parameters:
[44]43; CX: Placeholder size
44; DS: BDA segment (zero)
45; SS:BP: Pointer to first format parameter (-=2 for next parameter)
46; CS:SI: Pointer to string to format
47; ES:DI: Ptr to cursor location in video RAM
48; Returns:
49; SI: Updated to first unparsed character
50; DI: Updated offset to video RAM
51; BP: Updated to next format parameter
52; Corrupts registers:
53; AX, BX, CX, DX
54;--------------------------------------------------------------------
55ALIGN JUMP_ALIGN
56ParseFormatSpecifier:
57 call ReadCharacterAndTestForNull
58 call Char_IsDecimalDigitInAL
59 jc SHORT .ParsePlaceholderSizeDigitFromALtoCX
60 call GetFormatSpecifierParserToAX
61 call ax ; Parser function
62 dec bp
63 dec bp ; SS:BP now points to next parameter
64 test cx, cx
65 jnz SHORT PrependOrAppendSpaces
66 ret
67
68;--------------------------------------------------------------------
69; .ParsePlaceholderSizeDigitFromALtoCX
70; Parameters:
71; AL: Digit character from format string
72; CX: Current placeholder size
73; DS: BDA segment (zero)
74; Returns:
75; CX: Current placeholder size
76; Jumps back to ParseFormatSpecifier
77; Corrupts registers:
78; AX
79;--------------------------------------------------------------------
80ALIGN JUMP_ALIGN
81.ParsePlaceholderSizeDigitFromALtoCX:
82 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di
83 sub al, '0' ; Digit '0'...'9' to integer 0...9
84 mov ah, cl ; Previous number parameter to AH
85 aad ; AL += (AH * 10)
86 mov cl, al ; Updated number parameter now in CX
87 jmp SHORT ParseFormatSpecifier
88
89
90;--------------------------------------------------------------------
91; ReadCharacterAndTestForNull
92; Parameters:
[41]93; CS:SI: Pointer next character from string
94; Returns:
95; AL: Character from string
96; SI: Incremented to next character
97; ZF: Set if NULL, cleared if valid character
98; Corrupts registers:
99; Nothing
100;--------------------------------------------------------------------
101ALIGN JUMP_ALIGN
[44]102ReadCharacterAndTestForNull:
[41]103 eSEG cs
104 lodsb ; Load from CS:SI to AL
105 test al, al ; NULL to end string?
106 ret
107
108
109;--------------------------------------------------------------------
[44]110; GetFormatSpecifierParserToAX
[41]111; Parameters:
[44]112; AL: Format specifier character
[41]113; Returns:
[44]114; AX: Offset to parser function
[41]115; Corrupts registers:
[44]116; AX, BX
[41]117;--------------------------------------------------------------------
118ALIGN JUMP_ALIGN
[44]119GetFormatSpecifierParserToAX:
120 mov bx, .rgcFormatCharToLookupIndex
121ALIGN JUMP_ALIGN
122.CheckForNextSpecifierParser:
123 cmp al, [cs:bx]
124 je SHORT .ConvertIndexToFunctionOffset
125 inc bx
126 cmp bx, .rgcFormatCharToLookupIndexEnd
127 jb SHORT .CheckForNextSpecifierParser
128 mov ax, c_FormatCharacter
129 ret
130ALIGN JUMP_ALIGN
131.ConvertIndexToFunctionOffset:
132 sub bx, .rgcFormatCharToLookupIndex
133 shl bx, 1 ; Shift for WORD lookup
134 mov ax, [cs:bx+.rgfnFormatSpecifierParser]
135 ret
[41]136
[44]137.rgcFormatCharToLookupIndex:
138 db "aAduxsSct-+%"
139.rgcFormatCharToLookupIndexEnd:
140ALIGN WORD_ALIGN
141.rgfnFormatSpecifierParser:
142 dw a_FormatAttributeForNextCharacter
143 dw A_FormatAttributeForRemainingString
144 dw d_FormatSignedDecimalWord
145 dw u_FormatUnsignedDecimalWord
146 dw x_FormatHexadecimalWord
147 dw s_FormatStringFromSegmentCS
148 dw S_FormatStringFromFarPointer
149 dw c_FormatCharacter
150 dw t_FormatRepeatCharacter
151 dw PrepareToPrependParameterWithSpaces
152 dw PrepareToAppendSpacesAfterParameter
153 dw percent_FormatPercent
[41]154
[44]155
[41]156;--------------------------------------------------------------------
[44]157; PrependOrAppendSpaces
[41]158; Parameters:
[44]159; CX: Minimum length for format specifier in characters
[41]160; DS: BDA segment (zero)
161; ES:DI: Ptr to cursor location in video RAM
162; Returns:
[44]163; Nothing
[41]164; Corrupts registers:
165; AX, BX, CX, DX
166;--------------------------------------------------------------------
167ALIGN JUMP_ALIGN
[44]168PrependOrAppendSpaces:
169 mov ax, di
170 sub ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
171 test cx, cx
172 js SHORT .PrependWithSpaces
173 ; Fall to .AppendSpaces
[41]174
175;--------------------------------------------------------------------
[44]176; .AppendSpaces
[41]177; Parameters:
[44]178; AX: Number of format parameter BYTEs printed
179; CX: Minimum length for format specifier in characters
[41]180; DS: BDA segment (zero)
181; ES:DI: Ptr to cursor location in video RAM
182; Returns:
[44]183; Nothing
[41]184; Corrupts registers:
[44]185; AX, CX, DX
[41]186;--------------------------------------------------------------------
[44]187.AppendSpaces:
188 call DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
189 sub cx, ax
190 jle SHORT .NothingToAppendOrPrepend
[41]191 mov al, ' '
[44]192 jmp DisplayPrint_RepeatCharacterFromALwithCountInCX
[41]193
194;--------------------------------------------------------------------
[44]195; .PrependWithSpaces
[41]196; Parameters:
[44]197; AX: Number of format parameter BYTEs printed
198; CX: Negative minimum length for format specifier in characters
[41]199; DS: BDA segment (zero)
200; ES:DI: Ptr to cursor location in video RAM
201; Returns:
[44]202; Nothing
[41]203; Corrupts registers:
[44]204; AX, BX, CX, DX
[41]205;--------------------------------------------------------------------
206ALIGN JUMP_ALIGN
[44]207.PrependWithSpaces:
208 xchg ax, cx
209 neg ax
210 call DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
211 sub ax, cx ; AX = BYTEs to prepend, CX = BYTEs to move
212 jle SHORT .NothingToAppendOrPrepend
[41]213
[47]214 std
215 push si
[41]216
[47]217 lea si, [di-1] ; SI = Offset to last byte formatted
218 add di, ax ; DI = Cursor location after preceeding completed
219 push di
220 dec di ; DI = Offset where to move last byte formatted
221 xchg bx, ax ; BX = BYTEs to prepend
[48]222 call .ReverseCopyCXbytesFromESSItoESDI
[47]223 xchg ax, bx
224 call .ReversePrintAXspacesStartingFromESDI
225
226 pop di
227 pop si
228 cld ; Restore DF
229.NothingToAppendOrPrepend:
230 ret
231
232;--------------------------------------------------------------------
[48]233; .ReverseCopyCXbytesFromESSItoESDI
[47]234; Parameters:
[48]235; CX: Number of bytes to copy
[47]236; DS: BDA segment (zero)
[48]237; ES:SI: Ptr to old location
238; ES:DI: Ptr to new location
[47]239; Returns:
[48]240; DI: Updated to before last character copied
[47]241; Corrupts registers:
242; AX, CX, DX, SI
243;--------------------------------------------------------------------
244ALIGN JUMP_ALIGN
[48]245.ReverseCopyCXbytesFromESSItoESDI:
246 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
247 jz SHORT .CopyWithoutDisplayProcessing
[47]248
[48]249 WAIT_RETRACE_IF_NECESSARY_THEN rep movsb
250 dec di ; Point to preceeding character instead of attribute
251 ret
252ALIGN JUMP_ALIGN
253.CopyWithoutDisplayProcessing:
[44]254 eSEG_STR rep, es, movsb
[47]255 ret
256
257;--------------------------------------------------------------------
258; .ReversePrintAXspacesStartingFromESDI
259; Parameters:
260; AX: Number of spaces to print
261; DS: BDA segment (zero)
262; ES:DI: Ptr to destination in video RAM
263; Returns:
264; DI: Updated
265; Corrupts registers:
266; AX, CX, DX
267ALIGN JUMP_ALIGN
268.ReversePrintAXspacesStartingFromESDI:
[44]269 call DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
270 xchg cx, ax ; CX = Spaces to prepend
271 mov al, ' '
[47]272 jmp DisplayPrint_RepeatCharacterFromALwithCountInCX
[44]273
274
275
276;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
277; Formatting functions
[41]278; Parameters:
279; DS: BDA segment (zero)
[44]280; SS:BP: Pointer to next format parameter (-=2 updates to next parameter)
[41]281; ES:DI: Ptr to cursor location in video RAM
282; Returns:
[44]283; SS:BP: Points to last WORD parameter used
[41]284; Corrupts registers:
285; AX, BX, DX
[44]286;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[41]287ALIGN JUMP_ALIGN
[44]288a_FormatAttributeForNextCharacter:
[41]289 mov bl, [bp]
290 xchg bl, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
[44]291 push bx
292 push cx
293 push di
294 call DisplayFormat_ParseCharacters ; Recursive call
295 pop WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
296 pop cx
297 pop bx
[41]298 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], bl
[44]299 ret
[41]300
301ALIGN JUMP_ALIGN
[44]302A_FormatAttributeForRemainingString:
[41]303 mov al, [bp]
304 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
[44]305 ret
[41]306
307ALIGN JUMP_ALIGN
[44]308d_FormatSignedDecimalWord:
[41]309 mov ax, [bp]
[44]310 mov bx, 10
311 jmp DisplayPrint_SignedWordFromAXWithBaseInBX
[41]312
313ALIGN JUMP_ALIGN
[44]314u_FormatUnsignedDecimalWord:
[41]315 mov ax, [bp]
316 mov bx, 10
[44]317 jmp DisplayPrint_WordFromAXWithBaseInBX
[41]318
319ALIGN JUMP_ALIGN
[44]320x_FormatHexadecimalWord:
[41]321 mov ax, [bp]
322 mov bx, 16
323 call DisplayPrint_WordFromAXWithBaseInBX
324 mov al, 'h'
[44]325 jmp DisplayPrint_CharacterFromAL
[41]326
327ALIGN JUMP_ALIGN
[44]328s_FormatStringFromSegmentCS:
[41]329 xchg si, [bp]
330 call DisplayPrint_NullTerminatedStringFromCSSI
[44]331 mov si, [bp]
332 ret
[41]333
334ALIGN JUMP_ALIGN
[44]335S_FormatStringFromFarPointer:
336 mov bx, [bp-2]
[41]337 xchg si, [bp]
338 call DisplayPrint_NullTerminatedStringFromBXSI
[44]339 mov si, [bp]
340 dec bp
341 dec bp
342 ret
[41]343
344ALIGN JUMP_ALIGN
[44]345c_FormatCharacter:
[41]346 mov al, [bp]
[44]347 jmp DisplayPrint_CharacterFromAL
[41]348
349ALIGN JUMP_ALIGN
[44]350t_FormatRepeatCharacter:
351 push cx
[41]352 mov cx, [bp-2]
353 mov al, [bp]
354 call DisplayPrint_RepeatCharacterFromALwithCountInCX
[44]355 pop cx
356 dec bp
357 dec bp
358 ret
[41]359
360ALIGN JUMP_ALIGN
[44]361percent_FormatPercent:
[41]362 mov al, '%'
[44]363 jmp DisplayPrint_CharacterFromAL
[41]364
365ALIGN JUMP_ALIGN
[44]366PrepareToPrependParameterWithSpaces:
367 neg cx
368 ; Fall to PrepareToAppendSpacesAfterParameter
[41]369
370ALIGN JUMP_ALIGN
[44]371PrepareToAppendSpacesAfterParameter:
372 add sp, BYTE 2 ; Remove return offset
373 jmp ParseFormatSpecifier
Note: See TracBrowser for help on using the repository browser.