[41] | 1 | ; Project name : Assembly Library |
---|
| 2 | ; Description : Functions for display output. |
---|
| 3 | |
---|
| 4 | ; Section containing code |
---|
| 5 | SECTION .text |
---|
| 6 | |
---|
| 7 | ;-------------------------------------------------------------------- |
---|
| 8 | ; Supports following formatting types: |
---|
| 9 | ; %a Specifies attribute for next character |
---|
| 10 | ; %A Specifies attribute for remaining string (or until next %A) |
---|
| 11 | ; %d Prints signed 16-bit decimal integer |
---|
| 12 | ; %u Prints unsigned 16-bit decimal integer |
---|
| 13 | ; %x Prints 16-bit hexadecimal integer |
---|
| 14 | ; %s Prints string (from CS segment) |
---|
| 15 | ; %S Prints string (far pointer) |
---|
| 16 | ; %c Prints character |
---|
| 17 | ; %t Prints character number of times (character needs to be pushed first, then repeat times) |
---|
| 18 | ; %% Prints '%' character (no parameter pushed) |
---|
| 19 | ; |
---|
| 20 | ; Any placeholder can be set to minimum length by specifying |
---|
| 21 | ; minimum number of characters. For example %8d would append spaces |
---|
| 22 | ; after integer so that at least 8 characters would be printed. |
---|
[48] | 23 | ; |
---|
| 24 | ; When placing '-' after number, then spaces will be used for prepending. |
---|
| 25 | ; For example %8-d would prepend integer with spaces so that at least |
---|
| 26 | ; 8 characters would be printed. |
---|
[162] | 27 | ; |
---|
[41] | 28 | ; DisplayPrint_FormattedNullTerminatedStringFromCSSI |
---|
| 29 | ; Parameters: |
---|
| 30 | ; BP: SP before pushing parameters |
---|
| 31 | ; DS: BDA segment (zero) |
---|
| 32 | ; CS:SI: Pointer to string to format |
---|
| 33 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 34 | ; Stack: Parameters for formatting placeholders. |
---|
| 35 | ; Parameter for first placeholder must be pushed first. |
---|
| 36 | ; Low word must pushed first for placeholders requiring |
---|
| 37 | ; 32-bit parameters (two words). |
---|
| 38 | ; Returns: |
---|
| 39 | ; DI: Updated offset to video RAM |
---|
| 40 | ; Corrupts registers: |
---|
| 41 | ; AX, DX |
---|
| 42 | ;-------------------------------------------------------------------- |
---|
| 43 | ALIGN JUMP_ALIGN |
---|
| 44 | DisplayPrint_FormattedNullTerminatedStringFromCSSI: |
---|
| 45 | push bp |
---|
| 46 | push si |
---|
| 47 | push cx |
---|
| 48 | push bx |
---|
| 49 | push WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute] |
---|
| 50 | |
---|
| 51 | dec bp ; Point BP to... |
---|
| 52 | dec bp ; ...first stack parameter |
---|
| 53 | call DisplayFormat_ParseCharacters |
---|
| 54 | |
---|
| 55 | ; Pop original character attribute |
---|
| 56 | pop ax |
---|
| 57 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al |
---|
| 58 | |
---|
| 59 | pop bx |
---|
| 60 | pop cx |
---|
| 61 | pop si |
---|
| 62 | pop bp |
---|
| 63 | ret |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | ;-------------------------------------------------------------------- |
---|
[44] | 67 | ; DisplayPrint_SignedWordFromAXWithBaseInBX |
---|
[41] | 68 | ; Parameters: |
---|
| 69 | ; AX: Word to display |
---|
[44] | 70 | ; BX: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16) |
---|
[41] | 71 | ; DS: BDA segment (zero) |
---|
| 72 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 73 | ; Returns: |
---|
| 74 | ; DI: Updated offset to video RAM |
---|
| 75 | ; Corrupts registers: |
---|
| 76 | ; AX, DX |
---|
| 77 | ;-------------------------------------------------------------------- |
---|
[134] | 78 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
[41] | 79 | ALIGN JUMP_ALIGN |
---|
[44] | 80 | DisplayPrint_SignedWordFromAXWithBaseInBX: |
---|
| 81 | test ax, ax |
---|
| 82 | jns SHORT DisplayPrint_WordFromAXWithBaseInBX |
---|
[41] | 83 | |
---|
| 84 | push ax |
---|
| 85 | mov al, '-' |
---|
| 86 | call DisplayPrint_CharacterFromAL |
---|
| 87 | pop ax |
---|
| 88 | neg ax |
---|
[44] | 89 | ; Fall to DisplayPrint_WordFromAXWithBaseInBX |
---|
[134] | 90 | %endif |
---|
[41] | 91 | |
---|
| 92 | ;-------------------------------------------------------------------- |
---|
| 93 | ; DisplayPrint_WordFromAXWithBaseInBX |
---|
| 94 | ; Parameters: |
---|
| 95 | ; AX: Word to display |
---|
| 96 | ; BX: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16) |
---|
| 97 | ; DS: BDA segment (zero) |
---|
| 98 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 99 | ; Returns: |
---|
| 100 | ; DI: Updated offset to video RAM |
---|
| 101 | ; Corrupts registers: |
---|
| 102 | ; AX, DX |
---|
| 103 | ;-------------------------------------------------------------------- |
---|
| 104 | ALIGN JUMP_ALIGN |
---|
| 105 | DisplayPrint_WordFromAXWithBaseInBX: |
---|
| 106 | push cx |
---|
[44] | 107 | push bx |
---|
[41] | 108 | |
---|
| 109 | xor cx, cx |
---|
| 110 | ALIGN JUMP_ALIGN |
---|
| 111 | .DivideLoop: |
---|
| 112 | xor dx, dx ; DX:AX now holds the integer |
---|
| 113 | div bx ; Divide DX:AX by base |
---|
| 114 | push dx ; Push remainder |
---|
| 115 | inc cx ; Increment character count |
---|
| 116 | test ax, ax ; All divided? |
---|
| 117 | jnz SHORT .DivideLoop ; If not, loop |
---|
[44] | 118 | |
---|
| 119 | mov bx, .rgcDigitToCharacter |
---|
[41] | 120 | ALIGN JUMP_ALIGN |
---|
[44] | 121 | .PrintNextDigit: |
---|
| 122 | pop ax ; Pop digit |
---|
| 123 | eSEG cs |
---|
| 124 | xlatb |
---|
[41] | 125 | call DisplayPrint_CharacterFromAL |
---|
[44] | 126 | loop .PrintNextDigit |
---|
[41] | 127 | |
---|
[44] | 128 | pop bx |
---|
[41] | 129 | pop cx |
---|
| 130 | ret |
---|
| 131 | .rgcDigitToCharacter: db "0123456789ABCDEF" |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | ;-------------------------------------------------------------------- |
---|
| 135 | ; DisplayPrint_CharacterBufferFromBXSIwithLengthInCX |
---|
| 136 | ; Parameters: |
---|
| 137 | ; CX: Buffer length (characters) |
---|
| 138 | ; BX:SI: Ptr to NULL terminated string |
---|
| 139 | ; DS: BDA segment (zero) |
---|
| 140 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 141 | ; Returns: |
---|
| 142 | ; DI: Updated offset to video RAM |
---|
| 143 | ; Corrupts registers: |
---|
| 144 | ; AX, DX |
---|
| 145 | ;-------------------------------------------------------------------- |
---|
| 146 | ALIGN JUMP_ALIGN |
---|
| 147 | DisplayPrint_CharacterBufferFromBXSIwithLengthInCX: |
---|
[44] | 148 | jcxz .NothingToPrintSinceZeroLength |
---|
| 149 | push si |
---|
[41] | 150 | push cx |
---|
| 151 | |
---|
| 152 | ALIGN JUMP_ALIGN |
---|
[44] | 153 | .PrintNextCharacter: |
---|
| 154 | mov ds, bx |
---|
| 155 | lodsb |
---|
| 156 | LOAD_BDA_SEGMENT_TO ds, dx |
---|
| 157 | call DisplayPrint_CharacterFromAL |
---|
| 158 | loop .PrintNextCharacter |
---|
| 159 | |
---|
[181] | 160 | ;mov ds, cx ; Restore DS to BDA. Not needed unless DisplayPrint_CharacterFromAL changes DS. |
---|
[41] | 161 | pop cx |
---|
[44] | 162 | pop si |
---|
| 163 | .NothingToPrintSinceZeroLength: |
---|
[41] | 164 | ret |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | ;-------------------------------------------------------------------- |
---|
| 168 | ; DisplayPrint_NullTerminatedStringFromCSSI |
---|
| 169 | ; Parameters: |
---|
| 170 | ; CS:SI: Ptr to NULL terminated string |
---|
| 171 | ; DS: BDA segment (zero) |
---|
| 172 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 173 | ; Returns: |
---|
| 174 | ; DI: Updated offset to video RAM |
---|
| 175 | ; Corrupts registers: |
---|
| 176 | ; AX, DX |
---|
| 177 | ;-------------------------------------------------------------------- |
---|
| 178 | ALIGN JUMP_ALIGN |
---|
| 179 | DisplayPrint_NullTerminatedStringFromCSSI: |
---|
[44] | 180 | push bx |
---|
[41] | 181 | mov bx, cs |
---|
[44] | 182 | call DisplayPrint_NullTerminatedStringFromBXSI |
---|
| 183 | pop bx |
---|
| 184 | ret |
---|
[41] | 185 | |
---|
[44] | 186 | |
---|
[41] | 187 | ;-------------------------------------------------------------------- |
---|
| 188 | ; DisplayPrint_NullTerminatedStringFromBXSI |
---|
| 189 | ; Parameters: |
---|
| 190 | ; DS: BDA segment (zero) |
---|
| 191 | ; BX:SI: Ptr to NULL terminated string |
---|
| 192 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 193 | ; Returns: |
---|
| 194 | ; DI: Updated offset to video RAM |
---|
| 195 | ; Corrupts registers: |
---|
| 196 | ; AX, DX |
---|
| 197 | ;-------------------------------------------------------------------- |
---|
| 198 | ALIGN JUMP_ALIGN |
---|
| 199 | DisplayPrint_NullTerminatedStringFromBXSI: |
---|
[44] | 200 | push si |
---|
| 201 | push cx |
---|
[41] | 202 | |
---|
[44] | 203 | xor cx, cx |
---|
[41] | 204 | ALIGN JUMP_ALIGN |
---|
[44] | 205 | .PrintNextCharacter: |
---|
| 206 | mov ds, bx ; String segment to DS |
---|
| 207 | lodsb |
---|
| 208 | mov ds, cx ; BDA segment to DS |
---|
| 209 | test al, al ; NULL? |
---|
| 210 | jz SHORT .EndOfString |
---|
| 211 | call DisplayPrint_CharacterFromAL |
---|
| 212 | jmp SHORT .PrintNextCharacter |
---|
[41] | 213 | |
---|
| 214 | ALIGN JUMP_ALIGN |
---|
[44] | 215 | .EndOfString: |
---|
| 216 | pop cx |
---|
| 217 | pop si |
---|
[41] | 218 | ret |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | ;-------------------------------------------------------------------- |
---|
[67] | 222 | ; DisplayPrint_ClearScreenWithCharInALandAttributeInAH |
---|
[41] | 223 | ; Parameters: |
---|
[67] | 224 | ; AL: Character to clear with |
---|
| 225 | ; AH: Attribute to clear with |
---|
[41] | 226 | ; DS: BDA segment (zero) |
---|
| 227 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 228 | ; Returns: |
---|
| 229 | ; Nothing |
---|
| 230 | ; Corrupts registers: |
---|
| 231 | ; AX, DX |
---|
| 232 | ;-------------------------------------------------------------------- |
---|
| 233 | ALIGN JUMP_ALIGN |
---|
[67] | 234 | DisplayPrint_ClearScreenWithCharInALandAttributeInAH: |
---|
[41] | 235 | push di |
---|
[67] | 236 | push cx |
---|
| 237 | |
---|
| 238 | xchg cx, ax |
---|
[41] | 239 | xor ax, ax |
---|
[67] | 240 | call DisplayCursor_SetCoordinatesFromAX ; Updates DI |
---|
[41] | 241 | call DisplayPage_GetColumnsToALandRowsToAH |
---|
[67] | 242 | mul ah ; AX = AL*AH = Characters on screen |
---|
| 243 | xchg cx, ax ; AX = Char+Attr, CX = WORDs to store |
---|
| 244 | rep stosw |
---|
| 245 | |
---|
| 246 | pop cx |
---|
[41] | 247 | pop di |
---|
| 248 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di |
---|
| 249 | ret |
---|
| 250 | |
---|
| 251 | |
---|
| 252 | ;-------------------------------------------------------------------- |
---|
| 253 | ; DisplayPrint_ClearAreaWithHeightInAHandWidthInAL |
---|
| 254 | ; Parameters: |
---|
| 255 | ; AH: Area height |
---|
| 256 | ; AL: Area width |
---|
| 257 | ; DS: BDA segment (zero) |
---|
| 258 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 259 | ; Returns: |
---|
[42] | 260 | ; DI: Updated offset to video RAM |
---|
[41] | 261 | ; Corrupts registers: |
---|
| 262 | ; AX, DX |
---|
| 263 | ;-------------------------------------------------------------------- |
---|
[134] | 264 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
[41] | 265 | ALIGN JUMP_ALIGN |
---|
| 266 | DisplayPrint_ClearAreaWithHeightInAHandWidthInAL: |
---|
[42] | 267 | push si |
---|
[41] | 268 | push cx |
---|
| 269 | push bx |
---|
| 270 | |
---|
[42] | 271 | xchg bx, ax ; Area size to BX |
---|
[41] | 272 | call DisplayCursor_GetSoftwareCoordinatesToAX |
---|
[42] | 273 | xchg si, ax ; Software (Y,X) coordinates now in SI |
---|
| 274 | xor cx, cx |
---|
[41] | 275 | |
---|
| 276 | ALIGN JUMP_ALIGN |
---|
[42] | 277 | .ClearRowLoop: |
---|
| 278 | mov cl, bl ; Area width now in CX |
---|
[44] | 279 | mov al, SCREEN_BACKGROUND_CHARACTER |
---|
[42] | 280 | call DisplayPrint_RepeatCharacterFromALwithCountInCX |
---|
[41] | 281 | |
---|
[42] | 282 | xchg ax, si ; Coordinates to AX |
---|
| 283 | inc ah ; Increment row |
---|
| 284 | mov si, ax |
---|
[41] | 285 | call DisplayCursor_SetCoordinatesFromAX |
---|
[42] | 286 | dec bh ; Decrement rows left |
---|
| 287 | jnz SHORT .ClearRowLoop |
---|
[41] | 288 | |
---|
| 289 | pop bx |
---|
| 290 | pop cx |
---|
[42] | 291 | pop si |
---|
[41] | 292 | ret |
---|
[134] | 293 | %endif |
---|
[42] | 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: |
---|
[181] | 306 | ; DX |
---|
[42] | 307 | ;-------------------------------------------------------------------- |
---|
| 308 | ALIGN JUMP_ALIGN |
---|
| 309 | DisplayPrint_RepeatCharacterFromALwithCountInCX: |
---|
[44] | 310 | jcxz .NothingToRepeat |
---|
| 311 | push cx |
---|
| 312 | |
---|
| 313 | ALIGN JUMP_ALIGN |
---|
| 314 | .RepeatCharacter: |
---|
[42] | 315 | push ax |
---|
| 316 | call DisplayPrint_CharacterFromAL |
---|
| 317 | pop ax |
---|
[44] | 318 | loop .RepeatCharacter |
---|
| 319 | |
---|
| 320 | pop cx |
---|
| 321 | .NothingToRepeat: |
---|
[42] | 322 | ret |
---|
| 323 | |
---|
| 324 | |
---|
| 325 | ;-------------------------------------------------------------------- |
---|
[44] | 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 | ;-------------------------------------------------------------------- |
---|
| 335 | ALIGN JUMP_ALIGN |
---|
| 336 | DisplayPrint_Newline: |
---|
[52] | 337 | mov al, LF |
---|
| 338 | call DisplayPrint_CharacterFromAL |
---|
[44] | 339 | mov al, CR |
---|
| 340 | ; Fall to DisplayPrint_CharacterFromAL |
---|
| 341 | |
---|
| 342 | ;-------------------------------------------------------------------- |
---|
[42] | 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 | ;-------------------------------------------------------------------- |
---|
| 353 | ALIGN JUMP_ALIGN |
---|
| 354 | DisplayPrint_CharacterFromAL: |
---|
| 355 | mov ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute] |
---|
| 356 | jmp [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut] |
---|