[41] | 1 | ; File name : Display.asm |
---|
| 2 | ; Project name : Assembly Library |
---|
| 3 | ; Created date : 26.6.2010 |
---|
| 4 | ; Last update : 10.8.2010 |
---|
| 5 | ; Author : Tomi Tilli |
---|
| 6 | ; Description : Functions for display output. |
---|
| 7 | |
---|
| 8 | ; Section containing code |
---|
| 9 | SECTION .text |
---|
| 10 | |
---|
| 11 | ;-------------------------------------------------------------------- |
---|
| 12 | ; Supports following formatting types: |
---|
| 13 | ; %a Specifies attribute for next character |
---|
| 14 | ; %A Specifies attribute for remaining string (or until next %A) |
---|
| 15 | ; %d Prints signed 16-bit decimal integer |
---|
| 16 | ; %u Prints unsigned 16-bit decimal integer |
---|
| 17 | ; %x Prints 16-bit hexadecimal integer |
---|
| 18 | ; %s Prints string (from CS segment) |
---|
| 19 | ; %S Prints string (far pointer) |
---|
| 20 | ; %c Prints character |
---|
| 21 | ; %t Prints character number of times (character needs to be pushed first, then repeat times) |
---|
| 22 | ; %% Prints '%' character (no parameter pushed) |
---|
| 23 | ; |
---|
| 24 | ; Any placeholder can be set to minimum length by specifying |
---|
| 25 | ; minimum number of characters. For example %8d would append spaces |
---|
| 26 | ; after integer so that at least 8 characters would be printed. |
---|
| 27 | ; |
---|
| 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 | ;-------------------------------------------------------------------- |
---|
| 67 | ; DisplayPrint_SignedDecimalIntegerFromAX |
---|
| 68 | ; Parameters: |
---|
| 69 | ; AX: Word to display |
---|
| 70 | ; DS: BDA segment (zero) |
---|
| 71 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 72 | ; Returns: |
---|
| 73 | ; BX: Number of characters printed |
---|
| 74 | ; DI: Updated offset to video RAM |
---|
| 75 | ; Corrupts registers: |
---|
| 76 | ; AX, DX |
---|
| 77 | ;-------------------------------------------------------------------- |
---|
| 78 | ALIGN JUMP_ALIGN |
---|
| 79 | DisplayPrint_SignedDecimalIntegerFromAX: |
---|
| 80 | mov bx, 10 |
---|
| 81 | test ah, 1<<7 ; Sign bit set? |
---|
| 82 | jz SHORT DisplayPrint_WordFromAXWithBaseInBX |
---|
| 83 | |
---|
| 84 | push ax |
---|
| 85 | mov al, '-' |
---|
| 86 | call DisplayPrint_CharacterFromAL |
---|
| 87 | pop ax |
---|
| 88 | neg ax |
---|
| 89 | call DisplayPrint_WordFromAXWithBaseInBX |
---|
| 90 | inc bx ; Increment character count for '-' |
---|
| 91 | ret |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | ;-------------------------------------------------------------------- |
---|
| 95 | ; DisplayPrint_WordFromAXWithBaseInBX |
---|
| 96 | ; Parameters: |
---|
| 97 | ; AX: Word to display |
---|
| 98 | ; BX: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16) |
---|
| 99 | ; DS: BDA segment (zero) |
---|
| 100 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 101 | ; Returns: |
---|
| 102 | ; BX: Number of characters printed |
---|
| 103 | ; DI: Updated offset to video RAM |
---|
| 104 | ; Corrupts registers: |
---|
| 105 | ; AX, DX |
---|
| 106 | ;-------------------------------------------------------------------- |
---|
| 107 | ALIGN JUMP_ALIGN |
---|
| 108 | DisplayPrint_WordFromAXWithBaseInBX: |
---|
| 109 | push cx |
---|
| 110 | |
---|
| 111 | xor cx, cx |
---|
| 112 | ALIGN JUMP_ALIGN |
---|
| 113 | .DivideLoop: |
---|
| 114 | xor dx, dx ; DX:AX now holds the integer |
---|
| 115 | div bx ; Divide DX:AX by base |
---|
| 116 | push dx ; Push remainder |
---|
| 117 | inc cx ; Increment character count |
---|
| 118 | test ax, ax ; All divided? |
---|
| 119 | jnz SHORT .DivideLoop ; If not, loop |
---|
| 120 | mov dx, cx ; Character count to DX |
---|
| 121 | ALIGN JUMP_ALIGN |
---|
| 122 | .PrintLoop: |
---|
| 123 | pop bx ; Pop digit |
---|
| 124 | mov al, [cs:bx+.rgcDigitToCharacter] |
---|
| 125 | call DisplayPrint_CharacterFromAL |
---|
| 126 | loop .PrintLoop |
---|
| 127 | mov bx, dx ; Return characters printed |
---|
| 128 | |
---|
| 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 | ; BX: Number of characters printed |
---|
| 143 | ; DI: Updated offset to video RAM |
---|
| 144 | ; Corrupts registers: |
---|
| 145 | ; AX, DX |
---|
| 146 | ;-------------------------------------------------------------------- |
---|
| 147 | ALIGN JUMP_ALIGN |
---|
| 148 | DisplayPrint_CharacterBufferFromBXSIwithLengthInCX: |
---|
| 149 | push cx |
---|
| 150 | |
---|
| 151 | mov es, bx ; Buffer now in ES:SI |
---|
| 152 | xor bx, bx ; Zero character counter |
---|
| 153 | jcxz .BufferPrinted |
---|
| 154 | ALIGN JUMP_ALIGN |
---|
| 155 | .CharacterOutputLoop: |
---|
| 156 | mov al, [es:bx+si] |
---|
| 157 | inc bx |
---|
| 158 | call LoadDisplaySegmentAndPrintCharacterFromAL |
---|
| 159 | loop .CharacterOutputLoop |
---|
| 160 | .BufferPrinted: |
---|
| 161 | mov es, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2] |
---|
| 162 | pop cx |
---|
| 163 | ret |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | ;-------------------------------------------------------------------- |
---|
| 167 | ; DisplayPrint_NullTerminatedStringFromCSSI |
---|
| 168 | ; Parameters: |
---|
| 169 | ; CS:SI: Ptr to NULL terminated string |
---|
| 170 | ; DS: BDA segment (zero) |
---|
| 171 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 172 | ; Returns: |
---|
| 173 | ; BX: Number of characters printed |
---|
| 174 | ; DI: Updated offset to video RAM |
---|
| 175 | ; Corrupts registers: |
---|
| 176 | ; AX, DX |
---|
| 177 | ;-------------------------------------------------------------------- |
---|
| 178 | ALIGN JUMP_ALIGN |
---|
| 179 | DisplayPrint_NullTerminatedStringFromCSSI: |
---|
| 180 | mov bx, cs |
---|
| 181 | ; Fall to DisplayPrint_NullTerminatedStringFromBXSI |
---|
| 182 | |
---|
| 183 | ;-------------------------------------------------------------------- |
---|
| 184 | ; DisplayPrint_NullTerminatedStringFromBXSI |
---|
| 185 | ; Parameters: |
---|
| 186 | ; DS: BDA segment (zero) |
---|
| 187 | ; BX:SI: Ptr to NULL terminated string |
---|
| 188 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 189 | ; Returns: |
---|
| 190 | ; BX: Number of characters printed |
---|
| 191 | ; DI: Updated offset to video RAM |
---|
| 192 | ; Corrupts registers: |
---|
| 193 | ; AX, DX |
---|
| 194 | ;-------------------------------------------------------------------- |
---|
| 195 | ALIGN JUMP_ALIGN |
---|
| 196 | DisplayPrint_NullTerminatedStringFromBXSI: |
---|
| 197 | mov es, bx ; String now in ES:SI |
---|
| 198 | xor bx, bx ; Zero character counter |
---|
| 199 | ALIGN JUMP_ALIGN |
---|
| 200 | .CharacterOutputLoop: |
---|
| 201 | mov al, [es:bx+si] |
---|
| 202 | test al, al |
---|
| 203 | jz SHORT .AllCharacterPrinted |
---|
| 204 | inc bx |
---|
| 205 | |
---|
| 206 | call LoadDisplaySegmentAndPrintCharacterFromAL |
---|
| 207 | jmp SHORT .CharacterOutputLoop |
---|
| 208 | ALIGN JUMP_ALIGN |
---|
| 209 | .AllCharacterPrinted: |
---|
| 210 | mov es, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2] |
---|
| 211 | ret |
---|
| 212 | |
---|
| 213 | ;-------------------------------------------------------------------- |
---|
| 214 | ; LoadDisplaySegmentAndPrintCharacterFromAL |
---|
| 215 | ; Parameters: |
---|
| 216 | ; AL: Character to print |
---|
| 217 | ; DI: Offset to cursor location in video RAM |
---|
| 218 | ; DS: BDA segment (zero) |
---|
| 219 | ; Returns: |
---|
| 220 | ; DI: Updated offset to video RAM |
---|
| 221 | ; Corrupts registers: |
---|
| 222 | ; AX, DX |
---|
| 223 | ;-------------------------------------------------------------------- |
---|
| 224 | ALIGN JUMP_ALIGN |
---|
| 225 | LoadDisplaySegmentAndPrintCharacterFromAL: |
---|
| 226 | push es |
---|
| 227 | mov es, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2] |
---|
| 228 | call DisplayPrint_CharacterFromAL |
---|
| 229 | pop es |
---|
| 230 | ret |
---|
| 231 | |
---|
| 232 | |
---|
| 233 | ;-------------------------------------------------------------------- |
---|
| 234 | ; DisplayPrint_Newline |
---|
| 235 | ; Parameters: |
---|
| 236 | ; DS: BDA segment (zero) |
---|
| 237 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 238 | ; Returns: |
---|
| 239 | ; DI: Updated offset to video RAM |
---|
| 240 | ; Corrupts registers: |
---|
| 241 | ; AX, DX |
---|
| 242 | ;-------------------------------------------------------------------- |
---|
| 243 | ALIGN JUMP_ALIGN |
---|
| 244 | DisplayPrint_Newline: |
---|
| 245 | mov al, CR |
---|
| 246 | call DisplayPrint_CharacterFromAL |
---|
| 247 | mov al, LF |
---|
| 248 | jmp SHORT DisplayPrint_CharacterFromAL |
---|
| 249 | |
---|
| 250 | |
---|
| 251 | ;-------------------------------------------------------------------- |
---|
| 252 | ; DisplayPrint_RepeatCharacterFromALwithCountInCX |
---|
| 253 | ; Parameters: |
---|
| 254 | ; AL: Character to display |
---|
| 255 | ; CX: Repeat count |
---|
| 256 | ; DS: BDA segment (zero) |
---|
| 257 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 258 | ; Returns: |
---|
| 259 | ; DI: Updated offset to video RAM |
---|
| 260 | ; Corrupts registers: |
---|
| 261 | ; AX, DX |
---|
| 262 | ;-------------------------------------------------------------------- |
---|
| 263 | ALIGN JUMP_ALIGN |
---|
| 264 | DisplayPrint_RepeatCharacterFromALwithCountInCX: |
---|
| 265 | push ax |
---|
| 266 | call DisplayPrint_CharacterFromAL |
---|
| 267 | pop ax |
---|
| 268 | loop DisplayPrint_RepeatCharacterFromALwithCountInCX |
---|
| 269 | ret |
---|
| 270 | |
---|
| 271 | |
---|
| 272 | ;-------------------------------------------------------------------- |
---|
| 273 | ; DisplayPrint_CharacterFromAL |
---|
| 274 | ; Parameters: |
---|
| 275 | ; AL: Character to display |
---|
| 276 | ; DS: BDA segment (zero) |
---|
| 277 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 278 | ; Returns: |
---|
| 279 | ; DI: Updated offset to video RAM |
---|
| 280 | ; Corrupts registers: |
---|
| 281 | ; AX, DX |
---|
| 282 | ;-------------------------------------------------------------------- |
---|
| 283 | ALIGN JUMP_ALIGN |
---|
| 284 | DisplayPrint_CharacterFromAL: |
---|
| 285 | mov ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute] |
---|
| 286 | jmp [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut] |
---|
| 287 | |
---|
| 288 | |
---|
| 289 | ;-------------------------------------------------------------------- |
---|
| 290 | ; DisplayPrint_ClearScreen |
---|
| 291 | ; Parameters: |
---|
| 292 | ; DS: BDA segment (zero) |
---|
| 293 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 294 | ; Returns: |
---|
| 295 | ; Nothing |
---|
| 296 | ; Corrupts registers: |
---|
| 297 | ; AX, DX |
---|
| 298 | ;-------------------------------------------------------------------- |
---|
| 299 | ALIGN JUMP_ALIGN |
---|
| 300 | DisplayPrint_ClearScreen: |
---|
| 301 | push di |
---|
| 302 | xor ax, ax |
---|
| 303 | call DisplayCursor_SetCoordinatesFromAX |
---|
| 304 | call DisplayPage_GetColumnsToALandRowsToAH |
---|
| 305 | call DisplayPrint_ClearAreaWithHeightInAHandWidthInAL |
---|
| 306 | pop di |
---|
| 307 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di |
---|
| 308 | ret |
---|
| 309 | |
---|
| 310 | |
---|
| 311 | ;-------------------------------------------------------------------- |
---|
| 312 | ; DisplayPrint_ClearAreaWithHeightInAHandWidthInAL |
---|
| 313 | ; Parameters: |
---|
| 314 | ; AH: Area height |
---|
| 315 | ; AL: Area width |
---|
| 316 | ; DS: BDA segment (zero) |
---|
| 317 | ; ES:DI: Ptr to cursor location in video RAM |
---|
| 318 | ; Returns: |
---|
| 319 | ; Nothing |
---|
| 320 | ; Corrupts registers: |
---|
| 321 | ; AX, DX |
---|
| 322 | ;-------------------------------------------------------------------- |
---|
| 323 | ALIGN JUMP_ALIGN |
---|
| 324 | DisplayPrint_ClearAreaWithHeightInAHandWidthInAL: |
---|
| 325 | push cx |
---|
| 326 | push bx |
---|
| 327 | push di |
---|
| 328 | |
---|
| 329 | xchg bx, ax ; Move parameters to BX |
---|
| 330 | call DisplayCursor_GetSoftwareCoordinatesToAX |
---|
| 331 | xchg dx, ax ; Coordinates now in DX |
---|
| 332 | xor cx, cx ; Zero CX |
---|
| 333 | |
---|
| 334 | ALIGN JUMP_ALIGN |
---|
| 335 | .ClearRowFromArea: |
---|
| 336 | mov al, ' ' ; Clear with space |
---|
| 337 | mov ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute] |
---|
| 338 | mov cl, bl ; Area width = WORDs to clear |
---|
| 339 | rep stosw |
---|
| 340 | dec bh |
---|
| 341 | jz SHORT .AreaCleared |
---|
| 342 | |
---|
| 343 | inc dh ; Increment row |
---|
| 344 | push dx |
---|
| 345 | xchg ax, dx |
---|
| 346 | call DisplayCursor_SetCoordinatesFromAX |
---|
| 347 | pop dx |
---|
| 348 | jmp SHORT .ClearRowFromArea |
---|
| 349 | |
---|
| 350 | ALIGN JUMP_ALIGN |
---|
| 351 | .AreaCleared: |
---|
| 352 | pop di |
---|
| 353 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di |
---|
| 354 | pop bx |
---|
| 355 | pop cx |
---|
| 356 | ret |
---|