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