[41] | 1 | ; File name : Display.asm
|
---|
| 2 | ; Project name : Assembly Library
|
---|
| 3 | ; Created date : 26.6.2010
|
---|
[52] | 4 | ; Last update : 11.10.2010
|
---|
[41] | 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.
|
---|
[48] | 27 | ;
|
---|
| 28 | ; When placing '-' after number, then spaces will be used for prepending.
|
---|
| 29 | ; For example %8-d would prepend integer with spaces so that at least
|
---|
| 30 | ; 8 characters would be printed.
|
---|
[41] | 31 | ;
|
---|
| 32 | ; DisplayPrint_FormattedNullTerminatedStringFromCSSI
|
---|
| 33 | ; Parameters:
|
---|
| 34 | ; BP: SP before pushing parameters
|
---|
| 35 | ; DS: BDA segment (zero)
|
---|
| 36 | ; CS:SI: Pointer to string to format
|
---|
| 37 | ; ES:DI: Ptr to cursor location in video RAM
|
---|
| 38 | ; Stack: Parameters for formatting placeholders.
|
---|
| 39 | ; Parameter for first placeholder must be pushed first.
|
---|
| 40 | ; Low word must pushed first for placeholders requiring
|
---|
| 41 | ; 32-bit parameters (two words).
|
---|
| 42 | ; Returns:
|
---|
| 43 | ; DI: Updated offset to video RAM
|
---|
| 44 | ; Corrupts registers:
|
---|
| 45 | ; AX, DX
|
---|
| 46 | ;--------------------------------------------------------------------
|
---|
| 47 | ALIGN JUMP_ALIGN
|
---|
| 48 | DisplayPrint_FormattedNullTerminatedStringFromCSSI:
|
---|
| 49 | push bp
|
---|
| 50 | push si
|
---|
| 51 | push cx
|
---|
| 52 | push bx
|
---|
| 53 | push WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
|
---|
| 54 |
|
---|
| 55 | dec bp ; Point BP to...
|
---|
| 56 | dec bp ; ...first stack parameter
|
---|
| 57 | call DisplayFormat_ParseCharacters
|
---|
| 58 |
|
---|
| 59 | ; Pop original character attribute
|
---|
| 60 | pop ax
|
---|
| 61 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
|
---|
| 62 |
|
---|
| 63 | pop bx
|
---|
| 64 | pop cx
|
---|
| 65 | pop si
|
---|
| 66 | pop bp
|
---|
| 67 | ret
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | ;--------------------------------------------------------------------
|
---|
[44] | 71 | ; DisplayPrint_SignedWordFromAXWithBaseInBX
|
---|
[41] | 72 | ; Parameters:
|
---|
| 73 | ; AX: Word to display
|
---|
[44] | 74 | ; BX: Integer base (binary=2, octal=8, decimal=10, hexadecimal=16)
|
---|
[41] | 75 | ; DS: BDA segment (zero)
|
---|
| 76 | ; ES:DI: Ptr to cursor location in video RAM
|
---|
| 77 | ; Returns:
|
---|
| 78 | ; DI: Updated offset to video RAM
|
---|
| 79 | ; Corrupts registers:
|
---|
| 80 | ; AX, DX
|
---|
| 81 | ;--------------------------------------------------------------------
|
---|
| 82 | ALIGN JUMP_ALIGN
|
---|
[44] | 83 | DisplayPrint_SignedWordFromAXWithBaseInBX:
|
---|
| 84 | test ax, ax
|
---|
| 85 | jns SHORT DisplayPrint_WordFromAXWithBaseInBX
|
---|
[41] | 86 |
|
---|
| 87 | push ax
|
---|
| 88 | mov al, '-'
|
---|
| 89 | call DisplayPrint_CharacterFromAL
|
---|
| 90 | pop ax
|
---|
| 91 | neg ax
|
---|
[44] | 92 | ; Fall to DisplayPrint_WordFromAXWithBaseInBX
|
---|
[41] | 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 | ; DI: Updated offset to video RAM
|
---|
| 103 | ; Corrupts registers:
|
---|
| 104 | ; AX, DX
|
---|
| 105 | ;--------------------------------------------------------------------
|
---|
| 106 | ALIGN JUMP_ALIGN
|
---|
| 107 | DisplayPrint_WordFromAXWithBaseInBX:
|
---|
| 108 | push cx
|
---|
[44] | 109 | push bx
|
---|
[41] | 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
|
---|
[44] | 120 |
|
---|
| 121 | mov bx, .rgcDigitToCharacter
|
---|
[41] | 122 | ALIGN JUMP_ALIGN
|
---|
[44] | 123 | .PrintNextDigit:
|
---|
| 124 | pop ax ; Pop digit
|
---|
| 125 | eSEG cs
|
---|
| 126 | xlatb
|
---|
[41] | 127 | call DisplayPrint_CharacterFromAL
|
---|
[44] | 128 | loop .PrintNextDigit
|
---|
[41] | 129 |
|
---|
[44] | 130 | pop bx
|
---|
[41] | 131 | pop cx
|
---|
| 132 | ret
|
---|
| 133 | .rgcDigitToCharacter: db "0123456789ABCDEF"
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 | ;--------------------------------------------------------------------
|
---|
| 137 | ; DisplayPrint_CharacterBufferFromBXSIwithLengthInCX
|
---|
| 138 | ; Parameters:
|
---|
| 139 | ; CX: Buffer length (characters)
|
---|
| 140 | ; BX:SI: Ptr to NULL terminated string
|
---|
| 141 | ; DS: BDA segment (zero)
|
---|
| 142 | ; ES:DI: Ptr to cursor location in video RAM
|
---|
| 143 | ; Returns:
|
---|
| 144 | ; DI: Updated offset to video RAM
|
---|
| 145 | ; Corrupts registers:
|
---|
| 146 | ; AX, DX
|
---|
| 147 | ;--------------------------------------------------------------------
|
---|
| 148 | ALIGN JUMP_ALIGN
|
---|
| 149 | DisplayPrint_CharacterBufferFromBXSIwithLengthInCX:
|
---|
[44] | 150 | jcxz .NothingToPrintSinceZeroLength
|
---|
| 151 | push si
|
---|
[41] | 152 | push cx
|
---|
| 153 |
|
---|
| 154 | ALIGN JUMP_ALIGN
|
---|
[44] | 155 | .PrintNextCharacter:
|
---|
| 156 | mov ds, bx
|
---|
| 157 | lodsb
|
---|
| 158 | LOAD_BDA_SEGMENT_TO ds, dx
|
---|
| 159 | call DisplayPrint_CharacterFromAL
|
---|
| 160 | loop .PrintNextCharacter
|
---|
| 161 |
|
---|
| 162 | LOAD_BDA_SEGMENT_TO ds, dx
|
---|
[41] | 163 | pop cx
|
---|
[44] | 164 | pop si
|
---|
| 165 | .NothingToPrintSinceZeroLength:
|
---|
[41] | 166 | ret
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 | ;--------------------------------------------------------------------
|
---|
| 170 | ; DisplayPrint_NullTerminatedStringFromCSSI
|
---|
| 171 | ; Parameters:
|
---|
| 172 | ; CS:SI: Ptr to NULL terminated string
|
---|
| 173 | ; DS: BDA segment (zero)
|
---|
| 174 | ; ES:DI: Ptr to cursor location in video RAM
|
---|
| 175 | ; Returns:
|
---|
| 176 | ; DI: Updated offset to video RAM
|
---|
| 177 | ; Corrupts registers:
|
---|
| 178 | ; AX, DX
|
---|
| 179 | ;--------------------------------------------------------------------
|
---|
| 180 | ALIGN JUMP_ALIGN
|
---|
| 181 | DisplayPrint_NullTerminatedStringFromCSSI:
|
---|
[44] | 182 | push bx
|
---|
[41] | 183 | mov bx, cs
|
---|
[44] | 184 | call DisplayPrint_NullTerminatedStringFromBXSI
|
---|
| 185 | pop bx
|
---|
| 186 | ret
|
---|
[41] | 187 |
|
---|
[44] | 188 |
|
---|
[41] | 189 | ;--------------------------------------------------------------------
|
---|
| 190 | ; DisplayPrint_NullTerminatedStringFromBXSI
|
---|
| 191 | ; Parameters:
|
---|
| 192 | ; DS: BDA segment (zero)
|
---|
| 193 | ; BX:SI: Ptr to NULL terminated string
|
---|
| 194 | ; ES:DI: Ptr to cursor location in video RAM
|
---|
| 195 | ; Returns:
|
---|
| 196 | ; DI: Updated offset to video RAM
|
---|
| 197 | ; Corrupts registers:
|
---|
| 198 | ; AX, DX
|
---|
| 199 | ;--------------------------------------------------------------------
|
---|
| 200 | ALIGN JUMP_ALIGN
|
---|
| 201 | DisplayPrint_NullTerminatedStringFromBXSI:
|
---|
[44] | 202 | push si
|
---|
| 203 | push cx
|
---|
[41] | 204 |
|
---|
[44] | 205 | xor cx, cx
|
---|
[41] | 206 | ALIGN JUMP_ALIGN
|
---|
[44] | 207 | .PrintNextCharacter:
|
---|
| 208 | mov ds, bx ; String segment to DS
|
---|
| 209 | lodsb
|
---|
| 210 | mov ds, cx ; BDA segment to DS
|
---|
| 211 | test al, al ; NULL?
|
---|
| 212 | jz SHORT .EndOfString
|
---|
| 213 | call DisplayPrint_CharacterFromAL
|
---|
| 214 | jmp SHORT .PrintNextCharacter
|
---|
[41] | 215 |
|
---|
| 216 | ALIGN JUMP_ALIGN
|
---|
[44] | 217 | .EndOfString:
|
---|
| 218 | pop cx
|
---|
| 219 | pop si
|
---|
[41] | 220 | ret
|
---|
| 221 |
|
---|
| 222 |
|
---|
| 223 | ;--------------------------------------------------------------------
|
---|
| 224 | ; DisplayPrint_ClearScreen
|
---|
| 225 | ; Parameters:
|
---|
| 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
|
---|
| 234 | DisplayPrint_ClearScreen:
|
---|
| 235 | push di
|
---|
| 236 | xor ax, ax
|
---|
| 237 | call DisplayCursor_SetCoordinatesFromAX
|
---|
| 238 | call DisplayPage_GetColumnsToALandRowsToAH
|
---|
| 239 | call DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
|
---|
| 240 | pop di
|
---|
| 241 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], di
|
---|
| 242 | ret
|
---|
| 243 |
|
---|
| 244 |
|
---|
| 245 | ;--------------------------------------------------------------------
|
---|
| 246 | ; DisplayPrint_ClearAreaWithHeightInAHandWidthInAL
|
---|
| 247 | ; Parameters:
|
---|
| 248 | ; AH: Area height
|
---|
| 249 | ; AL: Area width
|
---|
| 250 | ; DS: BDA segment (zero)
|
---|
| 251 | ; ES:DI: Ptr to cursor location in video RAM
|
---|
| 252 | ; Returns:
|
---|
[42] | 253 | ; DI: Updated offset to video RAM
|
---|
[41] | 254 | ; Corrupts registers:
|
---|
| 255 | ; AX, DX
|
---|
| 256 | ;--------------------------------------------------------------------
|
---|
| 257 | ALIGN JUMP_ALIGN
|
---|
| 258 | DisplayPrint_ClearAreaWithHeightInAHandWidthInAL:
|
---|
[42] | 259 | push si
|
---|
[41] | 260 | push cx
|
---|
| 261 | push bx
|
---|
| 262 |
|
---|
[42] | 263 | xchg bx, ax ; Area size to BX
|
---|
[41] | 264 | call DisplayCursor_GetSoftwareCoordinatesToAX
|
---|
[42] | 265 | xchg si, ax ; Software (Y,X) coordinates now in SI
|
---|
| 266 | xor cx, cx
|
---|
[41] | 267 |
|
---|
| 268 | ALIGN JUMP_ALIGN
|
---|
[42] | 269 | .ClearRowLoop:
|
---|
| 270 | mov cl, bl ; Area width now in CX
|
---|
[44] | 271 | mov al, SCREEN_BACKGROUND_CHARACTER
|
---|
[42] | 272 | call DisplayPrint_RepeatCharacterFromALwithCountInCX
|
---|
[41] | 273 |
|
---|
[42] | 274 | xchg ax, si ; Coordinates to AX
|
---|
| 275 | inc ah ; Increment row
|
---|
| 276 | mov si, ax
|
---|
[41] | 277 | call DisplayCursor_SetCoordinatesFromAX
|
---|
[42] | 278 | dec bh ; Decrement rows left
|
---|
| 279 | jnz SHORT .ClearRowLoop
|
---|
[41] | 280 |
|
---|
| 281 | pop bx
|
---|
| 282 | pop cx
|
---|
[42] | 283 | pop si
|
---|
[41] | 284 | ret
|
---|
[42] | 285 |
|
---|
| 286 |
|
---|
| 287 | ;--------------------------------------------------------------------
|
---|
| 288 | ; DisplayPrint_RepeatCharacterFromALwithCountInCX
|
---|
| 289 | ; Parameters:
|
---|
| 290 | ; AL: Character to display
|
---|
| 291 | ; CX: Repeat count
|
---|
| 292 | ; DS: BDA segment (zero)
|
---|
| 293 | ; ES:DI: Ptr to cursor location in video RAM
|
---|
| 294 | ; Returns:
|
---|
| 295 | ; DI: Updated offset to video RAM
|
---|
| 296 | ; Corrupts registers:
|
---|
| 297 | ; AX, DX
|
---|
| 298 | ;--------------------------------------------------------------------
|
---|
| 299 | ALIGN JUMP_ALIGN
|
---|
| 300 | DisplayPrint_RepeatCharacterFromALwithCountInCX:
|
---|
[44] | 301 | jcxz .NothingToRepeat
|
---|
| 302 | push cx
|
---|
| 303 |
|
---|
| 304 | ALIGN JUMP_ALIGN
|
---|
| 305 | .RepeatCharacter:
|
---|
[42] | 306 | push ax
|
---|
| 307 | call DisplayPrint_CharacterFromAL
|
---|
| 308 | pop ax
|
---|
[44] | 309 | loop .RepeatCharacter
|
---|
| 310 |
|
---|
| 311 | pop cx
|
---|
| 312 | .NothingToRepeat:
|
---|
[42] | 313 | ret
|
---|
| 314 |
|
---|
| 315 |
|
---|
| 316 | ;--------------------------------------------------------------------
|
---|
[44] | 317 | ; DisplayPrint_Newline
|
---|
| 318 | ; Parameters:
|
---|
| 319 | ; DS: BDA segment (zero)
|
---|
| 320 | ; ES:DI: Ptr to cursor location in video RAM
|
---|
| 321 | ; Returns:
|
---|
| 322 | ; DI: Updated offset to video RAM
|
---|
| 323 | ; Corrupts registers:
|
---|
| 324 | ; AX, DX
|
---|
| 325 | ;--------------------------------------------------------------------
|
---|
| 326 | ALIGN JUMP_ALIGN
|
---|
| 327 | DisplayPrint_Newline:
|
---|
[52] | 328 | mov al, LF
|
---|
| 329 | call DisplayPrint_CharacterFromAL
|
---|
[44] | 330 | mov al, CR
|
---|
| 331 | ; Fall to DisplayPrint_CharacterFromAL
|
---|
| 332 |
|
---|
| 333 | ;--------------------------------------------------------------------
|
---|
[42] | 334 | ; DisplayPrint_CharacterFromAL
|
---|
| 335 | ; Parameters:
|
---|
| 336 | ; AL: Character to display
|
---|
| 337 | ; DS: BDA segment (zero)
|
---|
| 338 | ; ES:DI: Ptr to cursor location in video RAM
|
---|
| 339 | ; Returns:
|
---|
| 340 | ; DI: Updated offset to video RAM
|
---|
| 341 | ; Corrupts registers:
|
---|
| 342 | ; AX, DX
|
---|
| 343 | ;--------------------------------------------------------------------
|
---|
| 344 | ALIGN JUMP_ALIGN
|
---|
| 345 | DisplayPrint_CharacterFromAL:
|
---|
| 346 | mov ah, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute]
|
---|
| 347 | jmp [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut]
|
---|