[41] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Functions for managing display context.
|
---|
| 3 |
|
---|
[376] | 4 | ;
|
---|
[491] | 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
[526] | 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
[376] | 7 | ;
|
---|
| 8 | ; This program is free software; you can redistribute it and/or modify
|
---|
| 9 | ; it under the terms of the GNU General Public License as published by
|
---|
| 10 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
| 11 | ; (at your option) any later version.
|
---|
[491] | 12 | ;
|
---|
[376] | 13 | ; This program is distributed in the hope that it will be useful,
|
---|
| 14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
[491] | 16 | ; GNU General Public License for more details.
|
---|
[376] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
[491] | 18 | ;
|
---|
[376] | 19 |
|
---|
[41] | 20 | ; Section containing code
|
---|
| 21 | SECTION .text
|
---|
| 22 |
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
| 24 | ; DisplayContext_Initialize
|
---|
| 25 | ; Parameters:
|
---|
| 26 | ; DS: BDA segment (zero)
|
---|
| 27 | ; Returns:
|
---|
| 28 | ; Nothing
|
---|
| 29 | ; Corrupts registers:
|
---|
| 30 | ; AX, DX, DI
|
---|
| 31 | ;--------------------------------------------------------------------
|
---|
[369] | 32 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[41] | 33 | DisplayContext_Initialize:
|
---|
| 34 | mov WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], DEFAULT_CHARACTER_OUTPUT
|
---|
[44] | 35 | mov BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], SCREEN_BACKGROUND_ATTRIBUTE
|
---|
[407] | 36 | call DisplayCursor_GetDefaultCursorShapeToAX
|
---|
[287] | 37 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCursorShape], ax
|
---|
[101] | 38 | ; Fall to .DetectAndSetDisplaySegment
|
---|
[41] | 39 |
|
---|
| 40 | ;--------------------------------------------------------------------
|
---|
| 41 | ; .DetectAndSetDisplaySegment
|
---|
| 42 | ; Parameters:
|
---|
| 43 | ; DS: BDA segment (zero)
|
---|
| 44 | ; Returns:
|
---|
| 45 | ; Nothing
|
---|
| 46 | ; Corrupts registers:
|
---|
[50] | 47 | ; AX, DX
|
---|
[41] | 48 | ;--------------------------------------------------------------------
|
---|
| 49 | .DetectAndSetDisplaySegment:
|
---|
[50] | 50 | mov ax, COLOR_TEXT_SEGMENT
|
---|
[41] | 51 | cmp BYTE [VIDEO_BDA.bMode], MDA_TEXT_MODE
|
---|
[101] | 52 | eCMOVE ah, MONO_TEXT_SEGMENT >> 8
|
---|
[50] | 53 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], ax
|
---|
[101] | 54 | ; Fall to .InitializeFlags
|
---|
[50] | 55 |
|
---|
| 56 | ;--------------------------------------------------------------------
|
---|
| 57 | ; .InitializeFlags
|
---|
| 58 | ; Parameters:
|
---|
| 59 | ; DS: BDA segment (zero)
|
---|
| 60 | ; Returns:
|
---|
| 61 | ; Nothing
|
---|
| 62 | ; Corrupts registers:
|
---|
| 63 | ; AX, DX
|
---|
| 64 | ;--------------------------------------------------------------------
|
---|
| 65 | .InitializeFlags:
|
---|
| 66 | mov dl, FLG_CONTEXT_ATTRIBUTES
|
---|
| 67 | call CgaSnow_IsCgaPresent
|
---|
[588] | 68 | eCMOVC dl, FLG_CONTEXT_ATTRIBUTES | FLG_CONTEXT_CGA
|
---|
[50] | 69 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], dl
|
---|
[101] | 70 | ; Fall to .InitializeCursor
|
---|
[41] | 71 |
|
---|
[101] | 72 | ;--------------------------------------------------------------------
|
---|
| 73 | ; .InitializeCursor
|
---|
| 74 | ; Parameters:
|
---|
| 75 | ; DS: BDA segment (zero)
|
---|
| 76 | ; Returns:
|
---|
| 77 | ; Nothing
|
---|
| 78 | ; Corrupts registers:
|
---|
| 79 | ; AX, DX
|
---|
| 80 | ;--------------------------------------------------------------------
|
---|
| 81 | .InitializeCursor:
|
---|
[115] | 82 | call DisplayCursor_GetHardwareCoordinatesToAX ; Coordinates before init
|
---|
| 83 | call DisplayCursor_SetCoordinatesFromAX ; Cursor to Display Context
|
---|
[101] | 84 | ; Fall to DisplayContext_SynchronizeToHardware
|
---|
[41] | 85 |
|
---|
| 86 | ;--------------------------------------------------------------------
|
---|
[101] | 87 | ; DisplayContext_SynchronizeToHardware
|
---|
| 88 | ; Parameters:
|
---|
| 89 | ; DS: BDA segment (zero)
|
---|
| 90 | ; Returns:
|
---|
| 91 | ; Nothing
|
---|
| 92 | ; Corrupts registers:
|
---|
| 93 | ; AX, DX
|
---|
| 94 | ;--------------------------------------------------------------------
|
---|
[369] | 95 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[101] | 96 | DisplayContext_SynchronizeToHardware:
|
---|
| 97 | call DisplayPage_SynchronizeToHardware
|
---|
| 98 | call DisplayCursor_SynchronizeShapeToHardware
|
---|
| 99 | jmp DisplayCursor_SynchronizeCoordinatesToHardware
|
---|
| 100 |
|
---|
| 101 |
|
---|
| 102 | ;--------------------------------------------------------------------
|
---|
[41] | 103 | ; DisplayContext_Push
|
---|
[491] | 104 | ; DisplayContext_Pop
|
---|
[41] | 105 | ; Parameters:
|
---|
| 106 | ; Nothing
|
---|
| 107 | ; Returns:
|
---|
| 108 | ; Nothing
|
---|
| 109 | ; Corrupts registers:
|
---|
| 110 | ; AX, DI
|
---|
| 111 | ;--------------------------------------------------------------------
|
---|
[592] | 112 | %ifdef EXCLUDE_FROM_XUB
|
---|
[491] | 113 | %ifndef MODULE_BOOT_MENU
|
---|
| 114 | %define EXCLUDE
|
---|
| 115 | %endif
|
---|
| 116 | %endif
|
---|
| 117 |
|
---|
[592] | 118 | %ifndef EXCLUDE OR EXCLUDE_FROM_BIOSDRVS
|
---|
[369] | 119 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[41] | 120 | DisplayContext_Push:
|
---|
| 121 | mov di, ds ; Backup DS
|
---|
| 122 | LOAD_BDA_SEGMENT_TO ds, ax
|
---|
| 123 | pop ax ; Pop return address
|
---|
| 124 |
|
---|
[194] | 125 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
|
---|
[41] | 126 | %assign i 0
|
---|
[531] | 127 | %ifdef USE_386
|
---|
| 128 | %rep DISPLAY_CONTEXT_size / 4
|
---|
| 129 | push DWORD [VIDEO_BDA.displayContext + i]
|
---|
| 130 | %assign i i+4
|
---|
| 131 | %endrep
|
---|
| 132 | %else
|
---|
| 133 | %rep DISPLAY_CONTEXT_size / 2
|
---|
| 134 | push WORD [VIDEO_BDA.displayContext + i]
|
---|
| 135 | %assign i i+2
|
---|
| 136 | %endrep
|
---|
| 137 | %endif
|
---|
[194] | 138 | %endif
|
---|
[491] | 139 |
|
---|
[41] | 140 | mov ds, di ; Restore DS
|
---|
| 141 | jmp ax
|
---|
| 142 |
|
---|
[491] | 143 |
|
---|
[369] | 144 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[41] | 145 | DisplayContext_Pop:
|
---|
| 146 | mov di, ds ; Backup DS
|
---|
| 147 | LOAD_BDA_SEGMENT_TO ds, ax
|
---|
| 148 | pop ax ; Pop return address
|
---|
| 149 |
|
---|
[491] | 150 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
|
---|
[531] | 151 | %ifdef USE_386
|
---|
| 152 | %assign i DISPLAY_CONTEXT_size-4
|
---|
| 153 | %rep DISPLAY_CONTEXT_size / 4
|
---|
| 154 | pop DWORD [VIDEO_BDA.displayContext + i]
|
---|
| 155 | %assign i i-4
|
---|
| 156 | %endrep
|
---|
| 157 | %else
|
---|
| 158 | %assign i DISPLAY_CONTEXT_size-2
|
---|
| 159 | %rep DISPLAY_CONTEXT_size / 2
|
---|
| 160 | pop WORD [VIDEO_BDA.displayContext + i]
|
---|
| 161 | %assign i i-2
|
---|
| 162 | %endrep
|
---|
| 163 | %endif
|
---|
[194] | 164 | %endif
|
---|
[491] | 165 |
|
---|
[41] | 166 | push ax ; Push return address
|
---|
| 167 | push dx
|
---|
| 168 | call DisplayContext_SynchronizeToHardware
|
---|
| 169 | pop dx
|
---|
| 170 | mov ds, di ; Restore DS
|
---|
| 171 | ret
|
---|
[592] | 172 | %endif ; EXCLUDE OR EXCLUDE_FROM_BIOSDRVS
|
---|
[491] | 173 | %undef EXCLUDE
|
---|
[41] | 174 |
|
---|
[491] | 175 |
|
---|
[41] | 176 | ;--------------------------------------------------------------------
|
---|
[52] | 177 | ; DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX
|
---|
[48] | 178 | ; Parameters:
|
---|
[52] | 179 | ; CX: Off screen buffer length in characters
|
---|
| 180 | ; ES:BX: Ptr to off screen buffer
|
---|
[48] | 181 | ; Returns:
|
---|
| 182 | ; Nothing
|
---|
| 183 | ; Corrupts registers:
|
---|
[52] | 184 | ; AX, DI
|
---|
[48] | 185 | ;--------------------------------------------------------------------
|
---|
[592] | 186 | %ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
|
---|
[369] | 187 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[52] | 188 | DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX:
|
---|
[48] | 189 | push ds
|
---|
| 190 |
|
---|
| 191 | LOAD_BDA_SEGMENT_TO ds, di
|
---|
| 192 | xchg ax, bx
|
---|
| 193 | mov bx, es
|
---|
| 194 | call DisplayContext_SetCharacterPointerFromBXAX ; ES:DI now has the pointer
|
---|
| 195 |
|
---|
| 196 | mov bl, ATTRIBUTES_NOT_USED
|
---|
| 197 | mov ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
|
---|
| 198 | call DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
|
---|
[52] | 199 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], cx
|
---|
[48] | 200 |
|
---|
| 201 | mov bx, di
|
---|
| 202 | pop ds
|
---|
| 203 | ret
|
---|
[592] | 204 | %endif ; EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
|
---|
[48] | 205 |
|
---|
| 206 |
|
---|
| 207 | ;--------------------------------------------------------------------
|
---|
[41] | 208 | ; DisplayContext_SetCharacterPointerFromBXAX
|
---|
| 209 | ; Parameters:
|
---|
| 210 | ; BX:AX: Ptr to destination for next character to output
|
---|
| 211 | ; DS: BDA segment (zero)
|
---|
| 212 | ; Returns:
|
---|
[48] | 213 | ; ES:DI: Pointer that was in BX:AX
|
---|
[41] | 214 | ; Corrupts registers:
|
---|
| 215 | ; AX
|
---|
| 216 | ;--------------------------------------------------------------------
|
---|
[592] | 217 | %ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
|
---|
[369] | 218 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[41] | 219 | DisplayContext_SetCharacterPointerFromBXAX:
|
---|
| 220 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax
|
---|
| 221 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], bx
|
---|
| 222 | xchg di, ax
|
---|
| 223 | mov es, bx
|
---|
| 224 | ret
|
---|
[133] | 225 | %endif
|
---|
[41] | 226 |
|
---|
| 227 |
|
---|
| 228 | ;--------------------------------------------------------------------
|
---|
| 229 | ; DisplayContext_GetCharacterPointerToBXAX
|
---|
| 230 | ; Parameters:
|
---|
| 231 | ; DS: BDA segment (zero)
|
---|
| 232 | ; Returns:
|
---|
| 233 | ; BX:AX: Ptr to destination for next character to output
|
---|
| 234 | ; Corrupts registers:
|
---|
| 235 | ; Nothing
|
---|
| 236 | ;--------------------------------------------------------------------
|
---|
[592] | 237 | %ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
|
---|
[369] | 238 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[41] | 239 | DisplayContext_GetCharacterPointerToBXAX:
|
---|
| 240 | mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
|
---|
| 241 | mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
|
---|
| 242 | ret
|
---|
[133] | 243 | %endif
|
---|
[41] | 244 |
|
---|
| 245 |
|
---|
[592] | 246 | %ifdef EXCLUDE_FROM_XUB
|
---|
[491] | 247 | %ifndef MODULE_BOOT_MENU
|
---|
| 248 | %define EXCLUDE
|
---|
| 249 | %endif
|
---|
| 250 | %endif
|
---|
[41] | 251 | ;--------------------------------------------------------------------
|
---|
[45] | 252 | ; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
|
---|
[41] | 253 | ; Parameters:
|
---|
| 254 | ; AX: Offset to character output function
|
---|
[45] | 255 | ; BL: Attribute Flag
|
---|
[41] | 256 | ; DS: BDA segment (zero)
|
---|
| 257 | ; Returns:
|
---|
| 258 | ; Nothing
|
---|
| 259 | ; Corrupts registers:
|
---|
[50] | 260 | ; BL
|
---|
[41] | 261 | ;--------------------------------------------------------------------
|
---|
[491] | 262 | %ifndef EXCLUDE ; 1 of 3
|
---|
[369] | 263 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[45] | 264 | DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
|
---|
[50] | 265 | and bl, FLG_CONTEXT_ATTRIBUTES
|
---|
| 266 | and BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES
|
---|
| 267 | or [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl
|
---|
[41] | 268 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
|
---|
| 269 | ret
|
---|
[491] | 270 | %endif
|
---|
[41] | 271 |
|
---|
[489] | 272 |
|
---|
[41] | 273 | ;--------------------------------------------------------------------
|
---|
| 274 | ; DisplayContext_SetCharacterAttributeFromAL
|
---|
| 275 | ; Parameters:
|
---|
| 276 | ; AL: Character attribute
|
---|
| 277 | ; DS: BDA segment (zero)
|
---|
| 278 | ; Returns:
|
---|
| 279 | ; Nothing
|
---|
| 280 | ; Corrupts registers:
|
---|
| 281 | ; Nothing
|
---|
| 282 | ;--------------------------------------------------------------------
|
---|
[491] | 283 | %ifndef EXCLUDE ; 2 of 3
|
---|
[592] | 284 | %ifndef EXCLUDE_FROM_BIOSDRVS
|
---|
[369] | 285 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[41] | 286 | DisplayContext_SetCharacterAttributeFromAL:
|
---|
| 287 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
|
---|
| 288 | ret
|
---|
[491] | 289 | %endif
|
---|
[592] | 290 | %endif
|
---|
[41] | 291 |
|
---|
| 292 |
|
---|
| 293 | ;--------------------------------------------------------------------
|
---|
| 294 | ; DisplayContext_SetCharacterOutputParameterFromAX
|
---|
| 295 | ; Parameters:
|
---|
| 296 | ; AX: Parameter for Character Output function
|
---|
| 297 | ; DS: BDA segment (zero)
|
---|
| 298 | ; Returns:
|
---|
| 299 | ; Nothing
|
---|
| 300 | ; Corrupts registers:
|
---|
| 301 | ; Nothing
|
---|
| 302 | ;--------------------------------------------------------------------
|
---|
[491] | 303 | %ifndef EXCLUDE ; 3 of 3
|
---|
[592] | 304 | %ifndef EXCLUDE_FROM_BIOSDRVS
|
---|
[369] | 305 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[41] | 306 | DisplayContext_SetCharacterOutputParameterFromAX:
|
---|
| 307 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax
|
---|
| 308 | ret
|
---|
[491] | 309 | %endif
|
---|
[592] | 310 | %endif
|
---|
[491] | 311 |
|
---|
| 312 | %undef EXCLUDE
|
---|
| 313 |
|
---|
| 314 |
|
---|
[41] | 315 | ;--------------------------------------------------------------------
|
---|
| 316 | ; DisplayContext_GetCharacterOutputParameterToDX
|
---|
| 317 | ; Parameters:
|
---|
| 318 | ; DS: BDA segment (zero)
|
---|
| 319 | ; Returns:
|
---|
| 320 | ; DX: User parameter for Character Output function
|
---|
| 321 | ; Corrupts registers:
|
---|
| 322 | ; Nothing
|
---|
[133] | 323 | ;--------------------------------------------------------------------
|
---|
[592] | 324 | %ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_XTIDECFG OR EXCLUDE_FROM_BIOSDRVS
|
---|
[369] | 325 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[181] | 326 | DisplayContext_GetCharacterOutputParameterToDX:
|
---|
| 327 | mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
|
---|
| 328 | ret
|
---|
| 329 | %endif
|
---|
[44] | 330 |
|
---|
| 331 |
|
---|
| 332 | ;--------------------------------------------------------------------
|
---|
| 333 | ; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
|
---|
| 334 | ; Parameters:
|
---|
| 335 | ; AX: Offset in bytes from some character to another
|
---|
| 336 | ; DS: BDA segment (zero)
|
---|
| 337 | ; Returns:
|
---|
| 338 | ; AX: Offset in characters from some character to another
|
---|
| 339 | ; Corrupts registers:
|
---|
| 340 | ; Nothing
|
---|
[133] | 341 | ;--------------------------------------------------------------------
|
---|
[201] | 342 | %ifndef MODULE_STRINGS_COMPRESSED
|
---|
[369] | 343 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[44] | 344 | DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX:
|
---|
| 345 | test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
|
---|
| 346 | jz SHORT ReturnOffsetInAX
|
---|
| 347 | sar ax, 1 ; BYTE count to WORD count
|
---|
| 348 | ret
|
---|
[194] | 349 | %endif
|
---|
[44] | 350 |
|
---|
[491] | 351 |
|
---|
[44] | 352 | ;--------------------------------------------------------------------
|
---|
| 353 | ; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
|
---|
| 354 | ; Parameters:
|
---|
| 355 | ; AX: Offset in characters from some character to another
|
---|
| 356 | ; DS: BDA segment (zero)
|
---|
| 357 | ; Returns:
|
---|
| 358 | ; AX: Offset in bytes from some character to another
|
---|
| 359 | ; Corrupts registers:
|
---|
| 360 | ; Nothing
|
---|
[133] | 361 | ;--------------------------------------------------------------------
|
---|
[201] | 362 | %ifndef MODULE_STRINGS_COMPRESSED
|
---|
[369] | 363 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[44] | 364 | DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX:
|
---|
| 365 | test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
|
---|
| 366 | jz SHORT ReturnOffsetInAX
|
---|
| 367 | sal ax, 1 ; WORD count to BYTE count
|
---|
[369] | 368 | ALIGN DISPLAY_JUMP_ALIGN, ret
|
---|
[44] | 369 | ReturnOffsetInAX:
|
---|
| 370 | ret
|
---|
[194] | 371 | %endif
|
---|