[41] | 1 | ; File name : DisplayContext.asm |
---|
| 2 | ; Project name : Assembly Library |
---|
| 3 | ; Created date : 25.6.2010 |
---|
[45] | 4 | ; Last update : 28.9.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: |
---|
| 22 | call .DetectAndSetDisplaySegment |
---|
| 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 |
---|
| 26 | mov BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES |
---|
[41] | 27 | |
---|
| 28 | xor ax, ax |
---|
| 29 | call DisplayCursor_SetCoordinatesFromAX |
---|
| 30 | jmp SHORT DisplayContext_SynchronizeToHardware |
---|
| 31 | |
---|
| 32 | ;-------------------------------------------------------------------- |
---|
| 33 | ; .DetectAndSetDisplaySegment |
---|
| 34 | ; Parameters: |
---|
| 35 | ; DS: BDA segment (zero) |
---|
| 36 | ; Returns: |
---|
| 37 | ; Nothing |
---|
| 38 | ; Corrupts registers: |
---|
| 39 | ; Nothing |
---|
| 40 | ;-------------------------------------------------------------------- |
---|
| 41 | .DetectAndSetDisplaySegment: |
---|
| 42 | mov WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], COLOR_TEXT_SEGMENT |
---|
| 43 | cmp BYTE [VIDEO_BDA.bMode], MDA_TEXT_MODE |
---|
| 44 | jne SHORT .Return |
---|
| 45 | sub WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], COLOR_TEXT_SEGMENT - MONO_TEXT_SEGMENT |
---|
| 46 | .Return: |
---|
| 47 | ret |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | ;-------------------------------------------------------------------- |
---|
| 51 | ; DisplayContext_Push |
---|
| 52 | ; Parameters: |
---|
| 53 | ; Nothing |
---|
| 54 | ; Returns: |
---|
| 55 | ; Nothing |
---|
| 56 | ; Corrupts registers: |
---|
| 57 | ; AX, DI |
---|
| 58 | ;-------------------------------------------------------------------- |
---|
| 59 | ALIGN JUMP_ALIGN |
---|
| 60 | DisplayContext_Push: |
---|
| 61 | mov di, ds ; Backup DS |
---|
| 62 | LOAD_BDA_SEGMENT_TO ds, ax |
---|
| 63 | pop ax ; Pop return address |
---|
| 64 | |
---|
| 65 | %assign i 0 |
---|
| 66 | %rep DISPLAY_CONTEXT_size / 2 |
---|
| 67 | push WORD [VIDEO_BDA.displayContext + i] |
---|
| 68 | %assign i i+2 |
---|
| 69 | %endrep |
---|
| 70 | |
---|
| 71 | mov ds, di ; Restore DS |
---|
| 72 | jmp ax |
---|
| 73 | |
---|
| 74 | ;-------------------------------------------------------------------- |
---|
| 75 | ; DisplayContext_Pop |
---|
| 76 | ; Parameters: |
---|
| 77 | ; Nothing |
---|
| 78 | ; Returns: |
---|
| 79 | ; Nothing |
---|
| 80 | ; Corrupts registers: |
---|
| 81 | ; AX, DI |
---|
| 82 | ;-------------------------------------------------------------------- |
---|
| 83 | ALIGN JUMP_ALIGN |
---|
| 84 | DisplayContext_Pop: |
---|
| 85 | mov di, ds ; Backup DS |
---|
| 86 | LOAD_BDA_SEGMENT_TO ds, ax |
---|
| 87 | pop ax ; Pop return address |
---|
| 88 | |
---|
| 89 | %assign i DISPLAY_CONTEXT_size-2 |
---|
| 90 | %rep DISPLAY_CONTEXT_size / 2 |
---|
| 91 | pop WORD [VIDEO_BDA.displayContext + i] |
---|
| 92 | %assign i i-2 |
---|
| 93 | %endrep |
---|
| 94 | |
---|
| 95 | push ax ; Push return address |
---|
| 96 | push dx |
---|
| 97 | call DisplayContext_SynchronizeToHardware |
---|
| 98 | pop dx |
---|
| 99 | mov ds, di ; Restore DS |
---|
| 100 | ret |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | ;-------------------------------------------------------------------- |
---|
| 104 | ; DisplayContext_SynchronizeToHardware |
---|
| 105 | ; Parameters: |
---|
| 106 | ; DS: BDA segment (zero) |
---|
| 107 | ; Returns: |
---|
| 108 | ; Nothing |
---|
| 109 | ; Corrupts registers: |
---|
| 110 | ; AX, DX |
---|
| 111 | ;-------------------------------------------------------------------- |
---|
| 112 | ALIGN JUMP_ALIGN |
---|
| 113 | DisplayContext_SynchronizeToHardware: |
---|
| 114 | call DisplayPage_SynchronizeToHardware |
---|
| 115 | call DisplayCursor_SynchronizeShapeToHardware |
---|
| 116 | jmp DisplayCursor_SynchronizeCoordinatesToHardware |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | ;-------------------------------------------------------------------- |
---|
| 120 | ; DisplayContext_SetCharacterPointerFromBXAX |
---|
| 121 | ; Parameters: |
---|
| 122 | ; BX:AX: Ptr to destination for next character to output |
---|
| 123 | ; DS: BDA segment (zero) |
---|
| 124 | ; Returns: |
---|
| 125 | ; ES:DI: Pointer that was in DX:AX |
---|
| 126 | ; Corrupts registers: |
---|
| 127 | ; AX |
---|
| 128 | ;-------------------------------------------------------------------- |
---|
| 129 | ALIGN JUMP_ALIGN |
---|
| 130 | DisplayContext_SetCharacterPointerFromBXAX: |
---|
| 131 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax |
---|
| 132 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], bx |
---|
| 133 | xchg di, ax |
---|
| 134 | mov es, bx |
---|
| 135 | ret |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | ;-------------------------------------------------------------------- |
---|
| 139 | ; DisplayContext_GetCharacterPointerToBXAX |
---|
| 140 | ; Parameters: |
---|
| 141 | ; DS: BDA segment (zero) |
---|
| 142 | ; Returns: |
---|
| 143 | ; BX:AX: Ptr to destination for next character to output |
---|
| 144 | ; Corrupts registers: |
---|
| 145 | ; Nothing |
---|
| 146 | ;-------------------------------------------------------------------- |
---|
| 147 | ALIGN JUMP_ALIGN |
---|
| 148 | DisplayContext_GetCharacterPointerToBXAX: |
---|
| 149 | mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition] |
---|
| 150 | mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2] |
---|
| 151 | ret |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | ;-------------------------------------------------------------------- |
---|
[45] | 155 | ; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL |
---|
[41] | 156 | ; Parameters: |
---|
| 157 | ; AX: Offset to character output function |
---|
[45] | 158 | ; BL: Attribute Flag |
---|
[41] | 159 | ; DS: BDA segment (zero) |
---|
| 160 | ; Returns: |
---|
| 161 | ; Nothing |
---|
| 162 | ; Corrupts registers: |
---|
| 163 | ; Nothing |
---|
| 164 | ;-------------------------------------------------------------------- |
---|
| 165 | ALIGN JUMP_ALIGN |
---|
[45] | 166 | DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL: |
---|
[41] | 167 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax |
---|
[45] | 168 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl |
---|
[41] | 169 | ret |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | ;-------------------------------------------------------------------- |
---|
| 173 | ; DisplayContext_SetCharacterAttributeFromAL |
---|
| 174 | ; Parameters: |
---|
| 175 | ; AL: Character attribute |
---|
| 176 | ; DS: BDA segment (zero) |
---|
| 177 | ; Returns: |
---|
| 178 | ; Nothing |
---|
| 179 | ; Corrupts registers: |
---|
| 180 | ; Nothing |
---|
| 181 | ;-------------------------------------------------------------------- |
---|
| 182 | ALIGN JUMP_ALIGN |
---|
| 183 | DisplayContext_SetCharacterAttributeFromAL: |
---|
| 184 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al |
---|
| 185 | ret |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | ;-------------------------------------------------------------------- |
---|
| 189 | ; DisplayContext_SetCharacterOutputParameterFromAX |
---|
| 190 | ; Parameters: |
---|
| 191 | ; AX: Parameter for Character Output function |
---|
| 192 | ; DS: BDA segment (zero) |
---|
| 193 | ; Returns: |
---|
| 194 | ; Nothing |
---|
| 195 | ; Corrupts registers: |
---|
| 196 | ; Nothing |
---|
| 197 | ;-------------------------------------------------------------------- |
---|
| 198 | ALIGN JUMP_ALIGN |
---|
| 199 | DisplayContext_SetCharacterOutputParameterFromAX: |
---|
| 200 | mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax |
---|
| 201 | ret |
---|
| 202 | |
---|
| 203 | ;-------------------------------------------------------------------- |
---|
| 204 | ; DisplayContext_GetCharacterOutputParameterToDX |
---|
| 205 | ; Parameters: |
---|
| 206 | ; DS: BDA segment (zero) |
---|
| 207 | ; Returns: |
---|
| 208 | ; DX: User parameter for Character Output function |
---|
| 209 | ; Corrupts registers: |
---|
| 210 | ; Nothing |
---|
| 211 | ;-------------------------------------------------------------------- |
---|
| 212 | ALIGN JUMP_ALIGN |
---|
| 213 | DisplayContext_GetCharacterOutputParameterToDX: |
---|
| 214 | mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam] |
---|
| 215 | ret |
---|
[44] | 216 | |
---|
| 217 | |
---|
| 218 | ;-------------------------------------------------------------------- |
---|
| 219 | ; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX |
---|
| 220 | ; Parameters: |
---|
| 221 | ; AX: Offset in bytes from some character to another |
---|
| 222 | ; DS: BDA segment (zero) |
---|
| 223 | ; Returns: |
---|
| 224 | ; AX: Offset in characters from some character to another |
---|
| 225 | ; Corrupts registers: |
---|
| 226 | ; Nothing |
---|
| 227 | ;-------------------------------------------------------------------- |
---|
| 228 | ALIGN JUMP_ALIGN |
---|
| 229 | DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX: |
---|
| 230 | test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES |
---|
| 231 | jz SHORT ReturnOffsetInAX |
---|
| 232 | sar ax, 1 ; BYTE count to WORD count |
---|
| 233 | ret |
---|
| 234 | |
---|
| 235 | ;-------------------------------------------------------------------- |
---|
| 236 | ; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX |
---|
| 237 | ; Parameters: |
---|
| 238 | ; AX: Offset in characters from some character to another |
---|
| 239 | ; DS: BDA segment (zero) |
---|
| 240 | ; Returns: |
---|
| 241 | ; AX: Offset in bytes from some character to another |
---|
| 242 | ; Corrupts registers: |
---|
| 243 | ; Nothing |
---|
| 244 | ;-------------------------------------------------------------------- |
---|
| 245 | ALIGN JUMP_ALIGN |
---|
| 246 | DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX: |
---|
| 247 | test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES |
---|
| 248 | jz SHORT ReturnOffsetInAX |
---|
| 249 | sal ax, 1 ; WORD count to BYTE count |
---|
| 250 | ALIGN JUMP_ALIGN, ret |
---|
| 251 | ReturnOffsetInAX: |
---|
| 252 | ret |
---|