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

Last change on this file since 576 was 531, checked in by krille_n_@…, 12 years ago

Changes:

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