[41] | 1 | ; Project name : Assembly Library |
---|
| 2 | ; Description : Functions for managing display context. |
---|
| 3 | |
---|
| 4 | ; Section containing code |
---|
| 5 | SECTION .text |
---|
| 6 | |
---|
| 7 | ;-------------------------------------------------------------------- |
---|
| 8 | ; DisplayContext_Initialize |
---|
| 9 | ; Parameters: |
---|
| 10 | ; DS: BDA segment (zero) |
---|
| 11 | ; Returns: |
---|
| 12 | ; Nothing |
---|
| 13 | ; Corrupts registers: |
---|
| 14 | ; AX, DX, DI |
---|
| 15 | ;-------------------------------------------------------------------- |
---|
| 16 | ALIGN JUMP_ALIGN |
---|
| 17 | DisplayContext_Initialize: |
---|
| 18 | mov WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], DEFAULT_CHARACTER_OUTPUT |
---|
| 19 | mov WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCursorShape], CURSOR_NORMAL |
---|
[44] | 20 | mov BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], SCREEN_BACKGROUND_ATTRIBUTE |
---|
[101] | 21 | ; Fall to .DetectAndSetDisplaySegment |
---|
[41] | 22 | |
---|
| 23 | ;-------------------------------------------------------------------- |
---|
| 24 | ; .DetectAndSetDisplaySegment |
---|
| 25 | ; Parameters: |
---|
| 26 | ; DS: BDA segment (zero) |
---|
| 27 | ; Returns: |
---|
| 28 | ; Nothing |
---|
| 29 | ; Corrupts registers: |
---|
[50] | 30 | ; AX, DX |
---|
[41] | 31 | ;-------------------------------------------------------------------- |
---|
| 32 | .DetectAndSetDisplaySegment: |
---|
[50] | 33 | mov ax, COLOR_TEXT_SEGMENT |
---|
[41] | 34 | cmp BYTE [VIDEO_BDA.bMode], MDA_TEXT_MODE |
---|
[101] | 35 | eCMOVE ah, MONO_TEXT_SEGMENT >> 8 |
---|
[50] | 36 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], ax |
---|
[101] | 37 | ; Fall to .InitializeFlags |
---|
[50] | 38 | |
---|
| 39 | ;-------------------------------------------------------------------- |
---|
| 40 | ; .InitializeFlags |
---|
| 41 | ; Parameters: |
---|
| 42 | ; DS: BDA segment (zero) |
---|
| 43 | ; Returns: |
---|
| 44 | ; Nothing |
---|
| 45 | ; Corrupts registers: |
---|
| 46 | ; AX, DX |
---|
| 47 | ;-------------------------------------------------------------------- |
---|
| 48 | .InitializeFlags: |
---|
| 49 | mov dl, FLG_CONTEXT_ATTRIBUTES |
---|
| 50 | call CgaSnow_IsCgaPresent |
---|
| 51 | jnc SHORT .DoNotSetCgaFlag |
---|
| 52 | or dl, FLG_CONTEXT_CGA |
---|
| 53 | .DoNotSetCgaFlag: |
---|
| 54 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], dl |
---|
[101] | 55 | ; Fall to .InitializeCursor |
---|
[41] | 56 | |
---|
[101] | 57 | ;-------------------------------------------------------------------- |
---|
| 58 | ; .InitializeCursor |
---|
| 59 | ; Parameters: |
---|
| 60 | ; DS: BDA segment (zero) |
---|
| 61 | ; Returns: |
---|
| 62 | ; Nothing |
---|
| 63 | ; Corrupts registers: |
---|
| 64 | ; AX, DX |
---|
| 65 | ;-------------------------------------------------------------------- |
---|
| 66 | .InitializeCursor: |
---|
[115] | 67 | call DisplayCursor_GetHardwareCoordinatesToAX ; Coordinates before init |
---|
| 68 | call DisplayCursor_SetCoordinatesFromAX ; Cursor to Display Context |
---|
[101] | 69 | ; Fall to DisplayContext_SynchronizeToHardware |
---|
[41] | 70 | |
---|
| 71 | ;-------------------------------------------------------------------- |
---|
[101] | 72 | ; DisplayContext_SynchronizeToHardware |
---|
| 73 | ; Parameters: |
---|
| 74 | ; DS: BDA segment (zero) |
---|
| 75 | ; Returns: |
---|
| 76 | ; Nothing |
---|
| 77 | ; Corrupts registers: |
---|
| 78 | ; AX, DX |
---|
| 79 | ;-------------------------------------------------------------------- |
---|
| 80 | ALIGN JUMP_ALIGN |
---|
| 81 | DisplayContext_SynchronizeToHardware: |
---|
| 82 | call DisplayPage_SynchronizeToHardware |
---|
| 83 | call DisplayCursor_SynchronizeShapeToHardware |
---|
| 84 | jmp DisplayCursor_SynchronizeCoordinatesToHardware |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | ;-------------------------------------------------------------------- |
---|
[41] | 88 | ; DisplayContext_Push |
---|
| 89 | ; Parameters: |
---|
| 90 | ; Nothing |
---|
| 91 | ; Returns: |
---|
| 92 | ; Nothing |
---|
| 93 | ; Corrupts registers: |
---|
| 94 | ; AX, DI |
---|
| 95 | ;-------------------------------------------------------------------- |
---|
| 96 | ALIGN JUMP_ALIGN |
---|
| 97 | DisplayContext_Push: |
---|
| 98 | mov di, ds ; Backup DS |
---|
| 99 | LOAD_BDA_SEGMENT_TO ds, ax |
---|
| 100 | pop ax ; Pop return address |
---|
| 101 | |
---|
[194] | 102 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS |
---|
[41] | 103 | %assign i 0 |
---|
| 104 | %rep DISPLAY_CONTEXT_size / 2 |
---|
| 105 | push WORD [VIDEO_BDA.displayContext + i] |
---|
| 106 | %assign i i+2 |
---|
| 107 | %endrep |
---|
[194] | 108 | %endif |
---|
| 109 | |
---|
[41] | 110 | mov ds, di ; Restore DS |
---|
| 111 | jmp ax |
---|
| 112 | |
---|
| 113 | ;-------------------------------------------------------------------- |
---|
| 114 | ; DisplayContext_Pop |
---|
| 115 | ; Parameters: |
---|
| 116 | ; Nothing |
---|
| 117 | ; Returns: |
---|
| 118 | ; Nothing |
---|
| 119 | ; Corrupts registers: |
---|
| 120 | ; AX, DI |
---|
| 121 | ;-------------------------------------------------------------------- |
---|
| 122 | ALIGN JUMP_ALIGN |
---|
| 123 | DisplayContext_Pop: |
---|
| 124 | mov di, ds ; Backup DS |
---|
| 125 | LOAD_BDA_SEGMENT_TO ds, ax |
---|
| 126 | pop ax ; Pop return address |
---|
| 127 | |
---|
[194] | 128 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS |
---|
[41] | 129 | %assign i DISPLAY_CONTEXT_size-2 |
---|
| 130 | %rep DISPLAY_CONTEXT_size / 2 |
---|
| 131 | pop WORD [VIDEO_BDA.displayContext + i] |
---|
| 132 | %assign i i-2 |
---|
| 133 | %endrep |
---|
[194] | 134 | %endif |
---|
| 135 | |
---|
[41] | 136 | push ax ; Push return address |
---|
| 137 | push dx |
---|
| 138 | call DisplayContext_SynchronizeToHardware |
---|
| 139 | pop dx |
---|
| 140 | mov ds, di ; Restore DS |
---|
| 141 | ret |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | ;-------------------------------------------------------------------- |
---|
[52] | 145 | ; DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX |
---|
[48] | 146 | ; Parameters: |
---|
[52] | 147 | ; CX: Off screen buffer length in characters |
---|
| 148 | ; ES:BX: Ptr to off screen buffer |
---|
[48] | 149 | ; Returns: |
---|
| 150 | ; Nothing |
---|
| 151 | ; Corrupts registers: |
---|
[52] | 152 | ; AX, DI |
---|
[48] | 153 | ;-------------------------------------------------------------------- |
---|
[133] | 154 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
[48] | 155 | ALIGN JUMP_ALIGN |
---|
[52] | 156 | DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX: |
---|
[48] | 157 | push ds |
---|
| 158 | |
---|
| 159 | LOAD_BDA_SEGMENT_TO ds, di |
---|
| 160 | xchg ax, bx |
---|
| 161 | mov bx, es |
---|
| 162 | call DisplayContext_SetCharacterPointerFromBXAX ; ES:DI now has the pointer |
---|
| 163 | |
---|
| 164 | mov bl, ATTRIBUTES_NOT_USED |
---|
| 165 | mov ax, BUFFER_OUTPUT_WITH_CHAR_ONLY |
---|
| 166 | call DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL |
---|
[52] | 167 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], cx |
---|
[48] | 168 | |
---|
| 169 | mov bx, di |
---|
| 170 | pop ds |
---|
| 171 | ret |
---|
[133] | 172 | %endif |
---|
[48] | 173 | |
---|
| 174 | |
---|
| 175 | ;-------------------------------------------------------------------- |
---|
[41] | 176 | ; DisplayContext_SetCharacterPointerFromBXAX |
---|
| 177 | ; Parameters: |
---|
| 178 | ; BX:AX: Ptr to destination for next character to output |
---|
| 179 | ; DS: BDA segment (zero) |
---|
| 180 | ; Returns: |
---|
[48] | 181 | ; ES:DI: Pointer that was in BX:AX |
---|
[41] | 182 | ; Corrupts registers: |
---|
| 183 | ; AX |
---|
| 184 | ;-------------------------------------------------------------------- |
---|
[133] | 185 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
[41] | 186 | ALIGN JUMP_ALIGN |
---|
| 187 | DisplayContext_SetCharacterPointerFromBXAX: |
---|
| 188 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax |
---|
| 189 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], bx |
---|
| 190 | xchg di, ax |
---|
| 191 | mov es, bx |
---|
| 192 | ret |
---|
[133] | 193 | %endif |
---|
[41] | 194 | |
---|
| 195 | |
---|
| 196 | ;-------------------------------------------------------------------- |
---|
| 197 | ; DisplayContext_GetCharacterPointerToBXAX |
---|
| 198 | ; Parameters: |
---|
| 199 | ; DS: BDA segment (zero) |
---|
| 200 | ; Returns: |
---|
| 201 | ; BX:AX: Ptr to destination for next character to output |
---|
| 202 | ; Corrupts registers: |
---|
| 203 | ; Nothing |
---|
| 204 | ;-------------------------------------------------------------------- |
---|
[133] | 205 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
[41] | 206 | ALIGN JUMP_ALIGN |
---|
| 207 | DisplayContext_GetCharacterPointerToBXAX: |
---|
| 208 | mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition] |
---|
| 209 | mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2] |
---|
| 210 | ret |
---|
[133] | 211 | %endif |
---|
[41] | 212 | |
---|
| 213 | |
---|
| 214 | ;-------------------------------------------------------------------- |
---|
[45] | 215 | ; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL |
---|
[41] | 216 | ; Parameters: |
---|
| 217 | ; AX: Offset to character output function |
---|
[45] | 218 | ; BL: Attribute Flag |
---|
[41] | 219 | ; DS: BDA segment (zero) |
---|
| 220 | ; Returns: |
---|
| 221 | ; Nothing |
---|
| 222 | ; Corrupts registers: |
---|
[50] | 223 | ; BL |
---|
[41] | 224 | ;-------------------------------------------------------------------- |
---|
| 225 | ALIGN JUMP_ALIGN |
---|
[45] | 226 | DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL: |
---|
[50] | 227 | and bl, FLG_CONTEXT_ATTRIBUTES |
---|
| 228 | and BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES |
---|
| 229 | or [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl |
---|
[41] | 230 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax |
---|
| 231 | ret |
---|
[194] | 232 | |
---|
[41] | 233 | |
---|
| 234 | ;-------------------------------------------------------------------- |
---|
| 235 | ; DisplayContext_SetCharacterAttributeFromAL |
---|
| 236 | ; Parameters: |
---|
| 237 | ; AL: Character attribute |
---|
| 238 | ; DS: BDA segment (zero) |
---|
| 239 | ; Returns: |
---|
| 240 | ; Nothing |
---|
| 241 | ; Corrupts registers: |
---|
| 242 | ; Nothing |
---|
| 243 | ;-------------------------------------------------------------------- |
---|
| 244 | ALIGN JUMP_ALIGN |
---|
| 245 | DisplayContext_SetCharacterAttributeFromAL: |
---|
| 246 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al |
---|
| 247 | ret |
---|
| 248 | |
---|
| 249 | |
---|
| 250 | ;-------------------------------------------------------------------- |
---|
| 251 | ; DisplayContext_SetCharacterOutputParameterFromAX |
---|
| 252 | ; Parameters: |
---|
| 253 | ; AX: Parameter for Character Output function |
---|
| 254 | ; DS: BDA segment (zero) |
---|
| 255 | ; Returns: |
---|
| 256 | ; Nothing |
---|
| 257 | ; Corrupts registers: |
---|
| 258 | ; Nothing |
---|
| 259 | ;-------------------------------------------------------------------- |
---|
| 260 | ALIGN JUMP_ALIGN |
---|
| 261 | DisplayContext_SetCharacterOutputParameterFromAX: |
---|
| 262 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax |
---|
| 263 | ret |
---|
| 264 | |
---|
[194] | 265 | |
---|
[41] | 266 | ;-------------------------------------------------------------------- |
---|
| 267 | ; DisplayContext_GetCharacterOutputParameterToDX |
---|
| 268 | ; Parameters: |
---|
| 269 | ; DS: BDA segment (zero) |
---|
| 270 | ; Returns: |
---|
| 271 | ; DX: User parameter for Character Output function |
---|
| 272 | ; Corrupts registers: |
---|
| 273 | ; Nothing |
---|
[133] | 274 | ;-------------------------------------------------------------------- |
---|
[181] | 275 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS OR EXCLUDE_FROM_XTIDECFG ; This is currently unused (dead code) |
---|
| 276 | ALIGN JUMP_ALIGN |
---|
| 277 | DisplayContext_GetCharacterOutputParameterToDX: |
---|
| 278 | mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam] |
---|
| 279 | ret |
---|
| 280 | %endif |
---|
[44] | 281 | |
---|
| 282 | |
---|
| 283 | ;-------------------------------------------------------------------- |
---|
| 284 | ; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX |
---|
| 285 | ; Parameters: |
---|
| 286 | ; AX: Offset in bytes from some character to another |
---|
| 287 | ; DS: BDA segment (zero) |
---|
| 288 | ; Returns: |
---|
| 289 | ; AX: Offset in characters from some character to another |
---|
| 290 | ; Corrupts registers: |
---|
| 291 | ; Nothing |
---|
[133] | 292 | ;-------------------------------------------------------------------- |
---|
[194] | 293 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
[44] | 294 | ALIGN JUMP_ALIGN |
---|
| 295 | DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX: |
---|
| 296 | test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES |
---|
| 297 | jz SHORT ReturnOffsetInAX |
---|
| 298 | sar ax, 1 ; BYTE count to WORD count |
---|
| 299 | ret |
---|
[194] | 300 | %endif |
---|
[44] | 301 | |
---|
[194] | 302 | |
---|
[44] | 303 | ;-------------------------------------------------------------------- |
---|
| 304 | ; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX |
---|
| 305 | ; Parameters: |
---|
| 306 | ; AX: Offset in characters from some character to another |
---|
| 307 | ; DS: BDA segment (zero) |
---|
| 308 | ; Returns: |
---|
| 309 | ; AX: Offset in bytes from some character to another |
---|
| 310 | ; Corrupts registers: |
---|
| 311 | ; Nothing |
---|
[133] | 312 | ;-------------------------------------------------------------------- |
---|
[194] | 313 | %ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS |
---|
[44] | 314 | ALIGN JUMP_ALIGN |
---|
| 315 | DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX: |
---|
| 316 | test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES |
---|
| 317 | jz SHORT ReturnOffsetInAX |
---|
| 318 | sal ax, 1 ; WORD count to BYTE count |
---|
| 319 | ALIGN JUMP_ALIGN, ret |
---|
| 320 | ReturnOffsetInAX: |
---|
| 321 | ret |
---|
[194] | 322 | %endif |
---|