[41] | 1 | ; Project name : Assembly Library
|
---|
| 2 | ; Description : Functions for managing display context.
|
---|
| 3 |
|
---|
[376] | 4 | ;
|
---|
| 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
| 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
|
---|
| 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.
|
---|
| 12 | ;
|
---|
| 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
|
---|
| 16 | ; GNU General Public License for more details.
|
---|
| 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
| 18 | ;
|
---|
| 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
|
---|
| 68 | jnc SHORT .DoNotSetCgaFlag
|
---|
| 69 | or dl, FLG_CONTEXT_CGA
|
---|
| 70 | .DoNotSetCgaFlag:
|
---|
| 71 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], dl
|
---|
[101] | 72 | ; Fall to .InitializeCursor
|
---|
[41] | 73 |
|
---|
[101] | 74 | ;--------------------------------------------------------------------
|
---|
| 75 | ; .InitializeCursor
|
---|
| 76 | ; Parameters:
|
---|
| 77 | ; DS: BDA segment (zero)
|
---|
| 78 | ; Returns:
|
---|
| 79 | ; Nothing
|
---|
| 80 | ; Corrupts registers:
|
---|
| 81 | ; AX, DX
|
---|
| 82 | ;--------------------------------------------------------------------
|
---|
| 83 | .InitializeCursor:
|
---|
[115] | 84 | call DisplayCursor_GetHardwareCoordinatesToAX ; Coordinates before init
|
---|
| 85 | call DisplayCursor_SetCoordinatesFromAX ; Cursor to Display Context
|
---|
[101] | 86 | ; Fall to DisplayContext_SynchronizeToHardware
|
---|
[41] | 87 |
|
---|
| 88 | ;--------------------------------------------------------------------
|
---|
[101] | 89 | ; DisplayContext_SynchronizeToHardware
|
---|
| 90 | ; Parameters:
|
---|
| 91 | ; DS: BDA segment (zero)
|
---|
| 92 | ; Returns:
|
---|
| 93 | ; Nothing
|
---|
| 94 | ; Corrupts registers:
|
---|
| 95 | ; AX, DX
|
---|
| 96 | ;--------------------------------------------------------------------
|
---|
[369] | 97 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[101] | 98 | DisplayContext_SynchronizeToHardware:
|
---|
| 99 | call DisplayPage_SynchronizeToHardware
|
---|
| 100 | call DisplayCursor_SynchronizeShapeToHardware
|
---|
| 101 | jmp DisplayCursor_SynchronizeCoordinatesToHardware
|
---|
| 102 |
|
---|
| 103 |
|
---|
[489] | 104 | %ifdef INCLUDE_MENU_LIBRARY
|
---|
| 105 |
|
---|
[101] | 106 | ;--------------------------------------------------------------------
|
---|
[41] | 107 | ; DisplayContext_Push
|
---|
| 108 | ; Parameters:
|
---|
| 109 | ; Nothing
|
---|
| 110 | ; Returns:
|
---|
| 111 | ; Nothing
|
---|
| 112 | ; Corrupts registers:
|
---|
| 113 | ; AX, DI
|
---|
| 114 | ;--------------------------------------------------------------------
|
---|
[369] | 115 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[41] | 116 | DisplayContext_Push:
|
---|
| 117 | mov di, ds ; Backup DS
|
---|
| 118 | LOAD_BDA_SEGMENT_TO ds, ax
|
---|
| 119 | pop ax ; Pop return address
|
---|
| 120 |
|
---|
[194] | 121 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
|
---|
[41] | 122 | %assign i 0
|
---|
| 123 | %rep DISPLAY_CONTEXT_size / 2
|
---|
| 124 | push WORD [VIDEO_BDA.displayContext + i]
|
---|
| 125 | %assign i i+2
|
---|
| 126 | %endrep
|
---|
[194] | 127 | %endif
|
---|
| 128 |
|
---|
[41] | 129 | mov ds, di ; Restore DS
|
---|
| 130 | jmp ax
|
---|
| 131 |
|
---|
| 132 | ;--------------------------------------------------------------------
|
---|
| 133 | ; DisplayContext_Pop
|
---|
| 134 | ; Parameters:
|
---|
| 135 | ; Nothing
|
---|
| 136 | ; Returns:
|
---|
| 137 | ; Nothing
|
---|
| 138 | ; Corrupts registers:
|
---|
| 139 | ; AX, DI
|
---|
| 140 | ;--------------------------------------------------------------------
|
---|
[369] | 141 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[41] | 142 | DisplayContext_Pop:
|
---|
| 143 | mov di, ds ; Backup DS
|
---|
| 144 | LOAD_BDA_SEGMENT_TO ds, ax
|
---|
| 145 | pop ax ; Pop return address
|
---|
| 146 |
|
---|
[194] | 147 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
|
---|
[41] | 148 | %assign i DISPLAY_CONTEXT_size-2
|
---|
| 149 | %rep DISPLAY_CONTEXT_size / 2
|
---|
| 150 | pop WORD [VIDEO_BDA.displayContext + i]
|
---|
| 151 | %assign i i-2
|
---|
| 152 | %endrep
|
---|
[194] | 153 | %endif
|
---|
| 154 |
|
---|
[41] | 155 | push ax ; Push return address
|
---|
| 156 | push dx
|
---|
| 157 | call DisplayContext_SynchronizeToHardware
|
---|
| 158 | pop dx
|
---|
| 159 | mov ds, di ; Restore DS
|
---|
| 160 | ret
|
---|
[489] | 161 | %endif
|
---|
[41] | 162 |
|
---|
| 163 | ;--------------------------------------------------------------------
|
---|
[52] | 164 | ; DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX
|
---|
[48] | 165 | ; Parameters:
|
---|
[52] | 166 | ; CX: Off screen buffer length in characters
|
---|
| 167 | ; ES:BX: Ptr to off screen buffer
|
---|
[48] | 168 | ; Returns:
|
---|
| 169 | ; Nothing
|
---|
| 170 | ; Corrupts registers:
|
---|
[52] | 171 | ; AX, DI
|
---|
[48] | 172 | ;--------------------------------------------------------------------
|
---|
[133] | 173 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[369] | 174 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[52] | 175 | DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX:
|
---|
[48] | 176 | push ds
|
---|
| 177 |
|
---|
| 178 | LOAD_BDA_SEGMENT_TO ds, di
|
---|
| 179 | xchg ax, bx
|
---|
| 180 | mov bx, es
|
---|
| 181 | call DisplayContext_SetCharacterPointerFromBXAX ; ES:DI now has the pointer
|
---|
| 182 |
|
---|
| 183 | mov bl, ATTRIBUTES_NOT_USED
|
---|
| 184 | mov ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
|
---|
| 185 | call DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
|
---|
[52] | 186 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], cx
|
---|
[48] | 187 |
|
---|
| 188 | mov bx, di
|
---|
| 189 | pop ds
|
---|
| 190 | ret
|
---|
| 191 |
|
---|
[489] | 192 | %endif ; INCLUDE_MENU_LIBRARY
|
---|
[48] | 193 |
|
---|
[489] | 194 |
|
---|
[48] | 195 | ;--------------------------------------------------------------------
|
---|
[41] | 196 | ; DisplayContext_SetCharacterPointerFromBXAX
|
---|
| 197 | ; Parameters:
|
---|
| 198 | ; BX:AX: Ptr to destination for next character to output
|
---|
| 199 | ; DS: BDA segment (zero)
|
---|
| 200 | ; Returns:
|
---|
[48] | 201 | ; ES:DI: Pointer that was in BX:AX
|
---|
[41] | 202 | ; Corrupts registers:
|
---|
| 203 | ; AX
|
---|
| 204 | ;--------------------------------------------------------------------
|
---|
[133] | 205 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[369] | 206 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[41] | 207 | DisplayContext_SetCharacterPointerFromBXAX:
|
---|
| 208 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax
|
---|
| 209 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], bx
|
---|
| 210 | xchg di, ax
|
---|
| 211 | mov es, bx
|
---|
| 212 | ret
|
---|
[133] | 213 | %endif
|
---|
[41] | 214 |
|
---|
| 215 |
|
---|
| 216 | ;--------------------------------------------------------------------
|
---|
| 217 | ; DisplayContext_GetCharacterPointerToBXAX
|
---|
| 218 | ; Parameters:
|
---|
| 219 | ; DS: BDA segment (zero)
|
---|
| 220 | ; Returns:
|
---|
| 221 | ; BX:AX: Ptr to destination for next character to output
|
---|
| 222 | ; Corrupts registers:
|
---|
| 223 | ; Nothing
|
---|
| 224 | ;--------------------------------------------------------------------
|
---|
[133] | 225 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
|
---|
[369] | 226 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[41] | 227 | DisplayContext_GetCharacterPointerToBXAX:
|
---|
| 228 | mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
|
---|
| 229 | mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
|
---|
| 230 | ret
|
---|
[133] | 231 | %endif
|
---|
[41] | 232 |
|
---|
[489] | 233 | %ifdef INCLUDE_MENU_LIBRARY
|
---|
[41] | 234 |
|
---|
| 235 | ;--------------------------------------------------------------------
|
---|
[45] | 236 | ; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
|
---|
[41] | 237 | ; Parameters:
|
---|
| 238 | ; AX: Offset to character output function
|
---|
[45] | 239 | ; BL: Attribute Flag
|
---|
[41] | 240 | ; DS: BDA segment (zero)
|
---|
| 241 | ; Returns:
|
---|
| 242 | ; Nothing
|
---|
| 243 | ; Corrupts registers:
|
---|
[50] | 244 | ; BL
|
---|
[41] | 245 | ;--------------------------------------------------------------------
|
---|
[369] | 246 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[45] | 247 | DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
|
---|
[50] | 248 | and bl, FLG_CONTEXT_ATTRIBUTES
|
---|
| 249 | and BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES
|
---|
| 250 | or [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl
|
---|
[41] | 251 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
|
---|
| 252 | ret
|
---|
| 253 |
|
---|
[489] | 254 |
|
---|
[41] | 255 | ;--------------------------------------------------------------------
|
---|
| 256 | ; DisplayContext_SetCharacterAttributeFromAL
|
---|
| 257 | ; Parameters:
|
---|
| 258 | ; AL: Character attribute
|
---|
| 259 | ; DS: BDA segment (zero)
|
---|
| 260 | ; Returns:
|
---|
| 261 | ; Nothing
|
---|
| 262 | ; Corrupts registers:
|
---|
| 263 | ; Nothing
|
---|
| 264 | ;--------------------------------------------------------------------
|
---|
[369] | 265 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[41] | 266 | DisplayContext_SetCharacterAttributeFromAL:
|
---|
| 267 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
|
---|
| 268 | ret
|
---|
| 269 |
|
---|
| 270 |
|
---|
| 271 | ;--------------------------------------------------------------------
|
---|
| 272 | ; DisplayContext_SetCharacterOutputParameterFromAX
|
---|
| 273 | ; Parameters:
|
---|
| 274 | ; AX: Parameter for Character Output function
|
---|
| 275 | ; DS: BDA segment (zero)
|
---|
| 276 | ; Returns:
|
---|
| 277 | ; Nothing
|
---|
| 278 | ; Corrupts registers:
|
---|
| 279 | ; Nothing
|
---|
| 280 | ;--------------------------------------------------------------------
|
---|
[369] | 281 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[41] | 282 | DisplayContext_SetCharacterOutputParameterFromAX:
|
---|
| 283 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax
|
---|
| 284 | ret
|
---|
[194] | 285 |
|
---|
[489] | 286 | %endif ; INCLUDE_MENU_LIBRARY
|
---|
| 287 |
|
---|
[41] | 288 | ;--------------------------------------------------------------------
|
---|
| 289 | ; DisplayContext_GetCharacterOutputParameterToDX
|
---|
| 290 | ; Parameters:
|
---|
| 291 | ; DS: BDA segment (zero)
|
---|
| 292 | ; Returns:
|
---|
| 293 | ; DX: User parameter for Character Output function
|
---|
| 294 | ; Corrupts registers:
|
---|
| 295 | ; Nothing
|
---|
[133] | 296 | ;--------------------------------------------------------------------
|
---|
[181] | 297 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS OR EXCLUDE_FROM_XTIDECFG ; This is currently unused (dead code)
|
---|
[369] | 298 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[181] | 299 | DisplayContext_GetCharacterOutputParameterToDX:
|
---|
| 300 | mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
|
---|
| 301 | ret
|
---|
| 302 | %endif
|
---|
[44] | 303 |
|
---|
| 304 |
|
---|
| 305 | ;--------------------------------------------------------------------
|
---|
| 306 | ; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
|
---|
| 307 | ; Parameters:
|
---|
| 308 | ; AX: Offset in bytes from some character to another
|
---|
| 309 | ; DS: BDA segment (zero)
|
---|
| 310 | ; Returns:
|
---|
| 311 | ; AX: Offset in characters from some character to another
|
---|
| 312 | ; Corrupts registers:
|
---|
| 313 | ; Nothing
|
---|
[133] | 314 | ;--------------------------------------------------------------------
|
---|
[201] | 315 | %ifndef MODULE_STRINGS_COMPRESSED
|
---|
[369] | 316 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[44] | 317 | DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX:
|
---|
| 318 | test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
|
---|
| 319 | jz SHORT ReturnOffsetInAX
|
---|
| 320 | sar ax, 1 ; BYTE count to WORD count
|
---|
| 321 | ret
|
---|
[194] | 322 | %endif
|
---|
[44] | 323 |
|
---|
[194] | 324 |
|
---|
[44] | 325 | ;--------------------------------------------------------------------
|
---|
| 326 | ; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
|
---|
| 327 | ; Parameters:
|
---|
| 328 | ; AX: Offset in characters from some character to another
|
---|
| 329 | ; DS: BDA segment (zero)
|
---|
| 330 | ; Returns:
|
---|
| 331 | ; AX: Offset in bytes from some character to another
|
---|
| 332 | ; Corrupts registers:
|
---|
| 333 | ; Nothing
|
---|
[133] | 334 | ;--------------------------------------------------------------------
|
---|
[201] | 335 | %ifndef MODULE_STRINGS_COMPRESSED
|
---|
[369] | 336 | ALIGN DISPLAY_JUMP_ALIGN
|
---|
[44] | 337 | DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX:
|
---|
| 338 | test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
|
---|
| 339 | jz SHORT ReturnOffsetInAX
|
---|
| 340 | sal ax, 1 ; WORD count to BYTE count
|
---|
[369] | 341 | ALIGN DISPLAY_JUMP_ALIGN, ret
|
---|
[44] | 342 | ReturnOffsetInAX:
|
---|
| 343 | ret
|
---|
[194] | 344 | %endif
|
---|