source: xtideuniversalbios/trunk/Assembly_Library/Src/Display/DisplayContext.asm@ 368

Last change on this file since 368 was 287, checked in by aitotat@…, 13 years ago

Changes to Assembly Library:

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