Changeset 44 in xtideuniversalbios for trunk/Assembly_Library/Src/Display/DisplayFormat.asm
- Timestamp:
- Sep 27, 2010, 7:23:36 PM (15 years ago)
- google:author:
- aitotat
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Assembly_Library/Src/Display/DisplayFormat.asm
r41 r44 2 2 ; Project name : Assembly Library 3 3 ; Created date : 29.6.2010 4 ; Last update : 10.8.20104 ; Last update : 26.9.2010 5 5 ; Author : Tomi Tilli 6 6 ; Description : Functions for displaying formatted strings. … … 13 13 ; Parameters: 14 14 ; DS: BDA segment (zero) 15 ; SS:BP: Pointer to first format parameter (-=2 updates to next parameter) 16 ; CS:SI: Pointer to string to format 17 ; ES:DI: Ptr to cursor location in video RAM 18 ; Returns: 19 ; CS:SI: Ptr to end of format string (ptr to one past NULL) 20 ; DI: Updated offset to video RAM 21 ; Corrupts registers: 22 ; AX, BX, CX, DX, BP 23 ;-------------------------------------------------------------------- 24 ALIGN JUMP_ALIGN 25 DisplayFormat_ParseCharacters: 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 35 ALIGN JUMP_ALIGN 36 .QuitCharacterParsing: 37 ret 38 39 40 ;-------------------------------------------------------------------- 41 ; ParseFormatSpecifier 42 ; Parameters: 43 ; CX: Placeholder size 44 ; DS: BDA segment (zero) 15 45 ; SS:BP: Pointer to first format parameter (-=2 for next parameter) 16 46 ; CS:SI: Pointer to string to format 17 47 ; ES:DI: Ptr to cursor location in video RAM 18 48 ; Returns: 49 ; SI: Updated to first unparsed character 19 50 ; DI: Updated offset to video RAM 20 ; Corrupts registers: 21 ; AX, BX, CX, DX, SI, BP 22 ;-------------------------------------------------------------------- 23 ALIGN JUMP_ALIGN 24 DisplayFormat_ParseCharacters: 25 call .ReadCharacterAndTestForNull 26 jz SHORT .Return 27 xor cx, cx ; Zero CX for parsing number parameter 28 cmp al, '%' 29 je SHORT .FormatParameterEncountered 30 call DisplayPrint_CharacterFromAL ; Control or printable character 31 jmp SHORT DisplayFormat_ParseCharacters 32 ALIGN JUMP_ALIGN 33 .Return: 34 ret 35 36 ;-------------------------------------------------------------------- 37 ; .ReadCharacterAndTestForNull 38 ; Parameters: 39 ; CS:SI: Pointer next character from string 40 ; Returns: 41 ; AL: Character from string 42 ; SI: Incremented to next character 43 ; ZF: Set if NULL, cleared if valid character 44 ; Corrupts registers: 45 ; Nothing 46 ;-------------------------------------------------------------------- 47 ALIGN JUMP_ALIGN 48 .ReadCharacterAndTestForNull: 49 eSEG cs 50 lodsb ; Load from CS:SI to AL 51 test al, al ; NULL to end string? 52 ret 53 54 55 ;-------------------------------------------------------------------- 56 ; .FormatParameterEncountered 57 ; Parameters: 58 ; CX: Zero or previous number parameter 59 ; DS: BDA segment (zero) 60 ; SS:BP: Pointer to next format parameter 61 ; CS:SI: Pointer to next format string character 62 ; ES:DI: Ptr to cursor location in video RAM 63 ; Returns: 64 ; SI: Incremented to next character 65 ; BP: Offset to next format parameter 66 ; Eventually jumps to DisplayFormat_ParseCharacters 51 ; BP: Updated to next format parameter 67 52 ; Corrupts registers: 68 53 ; AX, BX, CX, DX 69 54 ;-------------------------------------------------------------------- 70 55 ALIGN JUMP_ALIGN 71 .FormatParameterEncountered: 72 call .ReadCharacterAndTestForNull 73 jz SHORT .Return 56 ParseFormatSpecifier: 57 call ReadCharacterAndTestForNull 74 58 call Char_IsDecimalDigitInAL 75 jnc SHORT .FormatWithCorrectFormatFunction 76 ; Fall to .ParseNumberParameterToCX 77 78 ;-------------------------------------------------------------------- 79 ; .ParseNumberParameterToCX 80 ; Parameters: 81 ; AL: Number digit from format string 82 ; CX: Zero or previous number parameter 83 ; Returns: 84 ; CX: Updated number parameter 85 ; Jumps to .FormatParameterEncountered 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 86 77 ; Corrupts registers: 87 78 ; AX 88 79 ;-------------------------------------------------------------------- 89 .ParseNumberParameterToCX: 80 ALIGN JUMP_ALIGN 81 .ParsePlaceholderSizeDigitFromALtoCX: 82 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di 90 83 sub al, '0' ; Digit '0'...'9' to integer 0...9 91 84 mov ah, cl ; Previous number parameter to AH 92 85 aad ; AL += (AH * 10) 93 86 mov cl, al ; Updated number parameter now in CX 94 jmp SHORT .FormatParameterEncountered 95 96 ;-------------------------------------------------------------------- 97 ; .FormatWithCorrectFormatFunction 98 ; Parameters: 99 ; AL: Format placeholder character (non digit character after '%') 100 ; CX: Number parameter (zero if no number parameter present) 101 ; DS: BDA segment (zero) 102 ; SS:BP: Pointer to format parameter 103 ; CS:SI: Pointer to next format string character 104 ; ES:DI: Ptr to cursor location in video RAM 105 ; Returns: 106 ; Eventually jumps to DisplayFormat_ParseCharacters 87 jmp SHORT ParseFormatSpecifier 88 89 90 ;-------------------------------------------------------------------- 91 ; ReadCharacterAndTestForNull 92 ; Parameters: 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 ;-------------------------------------------------------------------- 101 ALIGN JUMP_ALIGN 102 ReadCharacterAndTestForNull: 103 eSEG cs 104 lodsb ; Load from CS:SI to AL 105 test al, al ; NULL to end string? 106 ret 107 108 109 ;-------------------------------------------------------------------- 110 ; GetFormatSpecifierParserToAX 111 ; Parameters: 112 ; AL: Format specifier character 113 ; Returns: 114 ; AX: Offset to parser function 115 ; Corrupts registers: 116 ; AX, BX 117 ;-------------------------------------------------------------------- 118 ALIGN JUMP_ALIGN 119 GetFormatSpecifierParserToAX: 120 mov bx, .rgcFormatCharToLookupIndex 121 ALIGN 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 130 ALIGN JUMP_ALIGN 131 .ConvertIndexToFunctionOffset: 132 sub bx, .rgcFormatCharToLookupIndex 133 shl bx, 1 ; Shift for WORD lookup 134 mov ax, [cs:bx+.rgfnFormatSpecifierParser] 135 ret 136 137 .rgcFormatCharToLookupIndex: 138 db "aAduxsSct-+%" 139 .rgcFormatCharToLookupIndexEnd: 140 ALIGN 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 154 155 156 ;-------------------------------------------------------------------- 157 ; PrependOrAppendSpaces 158 ; Parameters: 159 ; CX: Minimum length for format specifier in characters 160 ; DS: BDA segment (zero) 161 ; ES:DI: Ptr to cursor location in video RAM 162 ; Returns: 163 ; Nothing 107 164 ; Corrupts registers: 108 165 ; AX, BX, CX, DX 109 166 ;-------------------------------------------------------------------- 110 167 ALIGN JUMP_ALIGN 111 .FormatWithCorrectFormatFunction: 112 xor bx, bx ; Zero lookup index 113 ALIGN JUMP_ALIGN 114 .PlaceholderComparisonLoop: 115 cmp al, [cs:bx+.rgcFormatCharToLookupIndex] 116 je SHORT .JumpToFormatPlaceholder 117 inc bx 118 cmp bl, .EndOFrgcFormatCharToLookupIndex - .rgcFormatCharToLookupIndex 119 jb SHORT .PlaceholderComparisonLoop ; Loop 120 call DisplayPrint_CharacterFromAL ; Display unsupported format character 121 ; Fall to .UpdateSpacesToAppendAfterPrintingSingleCharacter 122 123 ;-------------------------------------------------------------------- 124 ; .UpdateSpacesToAppendAfterPrintingSingleCharacter 125 ; .UpdateSpacesToAppend 126 ; Parameters: 127 ; BX: Number of characters printed (.UpdateSpacesToAppend only) 128 ; CX: Number parameter (zero if no number parameter present) 129 ; DS: BDA segment (zero) 130 ; SS:BP: Pointer to format parameter 131 ; CS:SI: Pointer to next format string character 132 ; ES:DI: Ptr to cursor location in video RAM 133 ; Returns: 134 ; CX: Number of spaces to append 135 ; Jumps to .PrepareToFormatNextParameter 168 PrependOrAppendSpaces: 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 174 175 ;-------------------------------------------------------------------- 176 ; .AppendSpaces 177 ; Parameters: 178 ; AX: Number of format parameter BYTEs printed 179 ; CX: Minimum length for format specifier in characters 180 ; DS: BDA segment (zero) 181 ; ES:DI: Ptr to cursor location in video RAM 182 ; Returns: 183 ; Nothing 184 ; Corrupts registers: 185 ; AX, CX, DX 186 ;-------------------------------------------------------------------- 187 .AppendSpaces: 188 call DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX 189 sub cx, ax 190 jle SHORT .NothingToAppendOrPrepend 191 mov al, ' ' 192 jmp DisplayPrint_RepeatCharacterFromALwithCountInCX 193 194 ;-------------------------------------------------------------------- 195 ; .PrependWithSpaces 196 ; Parameters: 197 ; AX: Number of format parameter BYTEs printed 198 ; CX: Negative minimum length for format specifier in characters 199 ; DS: BDA segment (zero) 200 ; ES:DI: Ptr to cursor location in video RAM 201 ; Returns: 202 ; Nothing 136 203 ; Corrupts registers: 137 204 ; AX, BX, CX, DX 138 205 ;-------------------------------------------------------------------- 139 206 ALIGN JUMP_ALIGN 140 .UpdateSpacesToAppendAfterPrintingSingleCharacter: 141 mov bx, 1 142 ALIGN JUMP_ALIGN 143 .UpdateSpacesToAppend: 144 jcxz .PrepareToFormatNextParameter 145 sub cx, bx ; Number of spaces to append 146 jle SHORT .PrepareToFormatNextParameter 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 213 214 mov bx, di 215 add bx, ax ; BX = DI after prepending 216 217 push si 218 dec di ; DI = Offset to last byte formatted 219 mov si, di 220 add di, ax ; DI = Offset to new location for last byte 221 std 222 eSEG_STR rep, es, movsb 223 224 mov dl, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags] 225 and dx, BYTE FLG_CONTEXT_ATTRIBUTES 226 not dx 227 and di, dx ; WORD alignment when using attributes 228 229 call DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX 230 xchg cx, ax ; CX = Spaces to prepend 147 231 mov al, ' ' 148 232 call DisplayPrint_RepeatCharacterFromALwithCountInCX 149 ; Fall to .PrepareToFormatNextParameter 150 151 ;-------------------------------------------------------------------- 152 ; .PrepareToFormatNextParameter 153 ; Parameters: 154 ; DS: BDA segment (zero) 155 ; SS:BP: Pointer to format parameter 156 ; CS:SI: Pointer to next format string character 157 ; ES:DI: Ptr to cursor location in video RAM 158 ; Returns: 159 ; BP: Adjusted to point next stack parameter 160 ; Jumps to DisplayFormat_ParseCharacters 161 ; Corrupts registers: 162 ; Nothing 163 ;-------------------------------------------------------------------- 164 ALIGN JUMP_ALIGN 165 .PrepareToFormatNextParameter: 166 dec bp 167 dec bp 168 jmp SHORT DisplayFormat_ParseCharacters 169 170 171 ;-------------------------------------------------------------------- 172 ; .JumpToFormatPlaceholder 173 ; Parameters: 174 ; BX: Lookup index for format function 175 ; CX: Number parameter (zero if no number parameter present) 176 ; DS: BDA segment (zero) 177 ; SS:BP: Pointer to next format parameter 178 ; CS:SI: Pointer to next format string character 179 ; ES:DI: Ptr to cursor location in video RAM 180 ; Returns: 181 ; Eventually jumps to DisplayFormat_ParseCharacters 233 cld ; Restore DF 234 235 mov di, bx 236 pop si 237 .NothingToAppendOrPrepend: 238 ret 239 240 241 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 242 ; Formatting functions 243 ; Parameters: 244 ; DS: BDA segment (zero) 245 ; SS:BP: Pointer to next format parameter (-=2 updates to next parameter) 246 ; ES:DI: Ptr to cursor location in video RAM 247 ; Returns: 248 ; SS:BP: Points to last WORD parameter used 182 249 ; Corrupts registers: 183 250 ; AX, BX, DX 184 ;-------------------------------------------------------------------- 185 ALIGN JUMP_ALIGN 186 .JumpToFormatPlaceholder: 187 shl bx, 1 ; Shift for WORD lookup 188 jmp [cs:bx+.rgfnFormatParameter] 189 190 ALIGN JUMP_ALIGN 191 .a_FormatAttributeForNextCharacter: 251 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 252 ALIGN JUMP_ALIGN 253 a_FormatAttributeForNextCharacter: 192 254 mov bl, [bp] 193 255 xchg bl, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute] 194 call .ReadCharacterAndTestForNull 195 jz SHORT .Return 196 call DisplayPrint_CharacterFromAL 256 push bx 257 push cx 258 push di 259 call DisplayFormat_ParseCharacters ; Recursive call 260 pop WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition] 261 pop cx 262 pop bx 197 263 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], bl 198 jmp SHORT .UpdateSpacesToAppendAfterPrintingSingleCharacter199 200 ALIGN JUMP_ALIGN 201 .A_FormatAttributeForRemainingString:264 ret 265 266 ALIGN JUMP_ALIGN 267 A_FormatAttributeForRemainingString: 202 268 mov al, [bp] 203 269 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al 204 jmp SHORT .PrepareToFormatNextParameter 205 206 ALIGN JUMP_ALIGN 207 .d_FormatSignedDecimalWord: 208 mov ax, [bp] 209 call DisplayPrint_SignedDecimalIntegerFromAX 210 jmp SHORT .UpdateSpacesToAppend 211 212 ALIGN JUMP_ALIGN 213 .u_FormatUnsignedDecimalWord: 270 ret 271 272 ALIGN JUMP_ALIGN 273 d_FormatSignedDecimalWord: 214 274 mov ax, [bp] 215 275 mov bx, 10 216 call DisplayPrint_WordFromAXWithBaseInBX 217 jmp SHORT .UpdateSpacesToAppend 218 219 ALIGN JUMP_ALIGN 220 .x_FormatHexadecimalWord: 276 jmp DisplayPrint_SignedWordFromAXWithBaseInBX 277 278 ALIGN JUMP_ALIGN 279 u_FormatUnsignedDecimalWord: 280 mov ax, [bp] 281 mov bx, 10 282 jmp DisplayPrint_WordFromAXWithBaseInBX 283 284 ALIGN JUMP_ALIGN 285 x_FormatHexadecimalWord: 221 286 mov ax, [bp] 222 287 mov bx, 16 223 288 call DisplayPrint_WordFromAXWithBaseInBX 224 inc bx ; Increment character count for 'h'225 289 mov al, 'h' 226 call DisplayPrint_CharacterFromAL 227 jmp SHORT .UpdateSpacesToAppend 228 229 ALIGN JUMP_ALIGN 230 .s_FormatStringFromSegmentCS: 290 jmp DisplayPrint_CharacterFromAL 291 292 ALIGN JUMP_ALIGN 293 s_FormatStringFromSegmentCS: 231 294 xchg si, [bp] 232 295 call DisplayPrint_NullTerminatedStringFromCSSI 233 mov si, [bp] ; Restore SI 234 jmp SHORT .UpdateSpacesToAppend 235 236 ALIGN JUMP_ALIGN 237 .S_FormatStringFromFarPointer: 296 mov si, [bp] 297 ret 298 299 ALIGN JUMP_ALIGN 300 S_FormatStringFromFarPointer: 301 mov bx, [bp-2] 238 302 xchg si, [bp] 239 mov bx, [bp-2]240 303 call DisplayPrint_NullTerminatedStringFromBXSI 241 mov si, [bp] ; Restore SI 242 jmp SHORT .UpdateSpacesToAppendWithDWordParameter 243 244 ALIGN JUMP_ALIGN 245 .c_FormatCharacter: 304 mov si, [bp] 305 dec bp 306 dec bp 307 ret 308 309 ALIGN JUMP_ALIGN 310 c_FormatCharacter: 246 311 mov al, [bp] 247 jmp SHORT .FormatSingleCharacterFromAL 248 249 ALIGN JUMP_ALIGN 250 .t_FormatRepeatCharacter: 312 jmp DisplayPrint_CharacterFromAL 313 314 ALIGN JUMP_ALIGN 315 t_FormatRepeatCharacter: 316 push cx 251 317 mov cx, [bp-2] 252 mov bx, cx253 318 mov al, [bp] 254 319 call DisplayPrint_RepeatCharacterFromALwithCountInCX 255 jmp SHORT .UpdateSpacesToAppendWithDWordParameter 256 257 ALIGN JUMP_ALIGN 258 .percent_FormatPercent: 320 pop cx 321 dec bp 322 dec bp 323 ret 324 325 ALIGN JUMP_ALIGN 326 percent_FormatPercent: 259 327 mov al, '%' 260 inc bp ; Adjust here since... 261 inc bp ; ...no parameter on stack 262 ; Fall to .FormatSingleCharacterFromAL 263 264 ALIGN JUMP_ALIGN 265 .FormatSingleCharacterFromAL: 266 call DisplayPrint_CharacterFromAL 267 jmp .UpdateSpacesToAppendAfterPrintingSingleCharacter 268 269 ALIGN JUMP_ALIGN 270 .UpdateSpacesToAppendWithDWordParameter: 271 dec bp 272 dec bp 273 jmp .UpdateSpacesToAppend 274 275 276 ; Table for converting format character to jump table index 277 .rgcFormatCharToLookupIndex: 278 db "aAduxsSct%" 279 .EndOFrgcFormatCharToLookupIndex: 280 281 ; Jump table 282 ALIGN WORD_ALIGN 283 .rgfnFormatParameter: 284 dw .a_FormatAttributeForNextCharacter 285 dw .A_FormatAttributeForRemainingString 286 dw .d_FormatSignedDecimalWord 287 dw .u_FormatUnsignedDecimalWord 288 dw .x_FormatHexadecimalWord 289 dw .s_FormatStringFromSegmentCS 290 dw .S_FormatStringFromFarPointer 291 dw .c_FormatCharacter 292 dw .t_FormatRepeatCharacter 293 dw .percent_FormatPercent 328 jmp DisplayPrint_CharacterFromAL 329 330 ALIGN JUMP_ALIGN 331 PrepareToPrependParameterWithSpaces: 332 neg cx 333 ; Fall to PrepareToAppendSpacesAfterParameter 334 335 ALIGN JUMP_ALIGN 336 PrepareToAppendSpacesAfterParameter: 337 add sp, BYTE 2 ; Remove return offset 338 jmp ParseFormatSpecifier
Note:
See TracChangeset
for help on using the changeset viewer.