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

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

Changes:

  • Added a new define (USE_UNDOC_INTEL) that enables optimizations possible by using undocumented instructions available on all Intel processors and truly compatible clones. AFAIK the only exceptions are the NEC V-series and the Sony CXQ70108 processors so this option should be safe for use on the AT builds.
  • Building BIOSDRVS or the BIOS without MODULE_STRINGS_COMPRESSED would fail due to the recent code exclusions so I changed them a bit. Also fixed the mistaken change to Main.asm
  • Changed the Tandy specific info in Configuration_FullMode.txt so it matches the info in the Wiki.
  • Optimizations and fixes in general.
File size: 10.6 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
[376]6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
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
129 %rep DISPLAY_CONTEXT_size / 2
130 push WORD [VIDEO_BDA.displayContext + i]
131 %assign i i+2
132 %endrep
[194]133%endif
[491]134
[41]135 mov ds, di ; Restore DS
136 jmp ax
137
[491]138
[369]139ALIGN DISPLAY_JUMP_ALIGN
[41]140DisplayContext_Pop:
141 mov di, ds ; Backup DS
142 LOAD_BDA_SEGMENT_TO ds, ax
143 pop ax ; Pop return address
144
[491]145%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
[41]146 %assign i DISPLAY_CONTEXT_size-2
147 %rep DISPLAY_CONTEXT_size / 2
148 pop WORD [VIDEO_BDA.displayContext + i]
149 %assign i i-2
150 %endrep
[194]151%endif
[491]152
[41]153 push ax ; Push return address
154 push dx
155 call DisplayContext_SynchronizeToHardware
156 pop dx
157 mov ds, di ; Restore DS
158 ret
[491]159%endif ; EXCLUDE
160%undef EXCLUDE
[41]161
[491]162
[41]163;--------------------------------------------------------------------
[52]164; DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX
[48]165; Parameters:
[52]166; CX: Off screen buffer length in characters
167; ES:BX: Ptr to off screen buffer
[48]168; Returns:
169; Nothing
170; Corrupts registers:
[52]171; AX, DI
[48]172;--------------------------------------------------------------------
[133]173%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[369]174ALIGN DISPLAY_JUMP_ALIGN
[52]175DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX:
[48]176 push ds
177
178 LOAD_BDA_SEGMENT_TO ds, di
179 xchg ax, bx
180 mov bx, es
181 call DisplayContext_SetCharacterPointerFromBXAX ; ES:DI now has the pointer
182
183 mov bl, ATTRIBUTES_NOT_USED
184 mov ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
185 call DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
[52]186 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], cx
[48]187
188 mov bx, di
189 pop ds
190 ret
[491]191%endif ; EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[48]192
193
194;--------------------------------------------------------------------
[41]195; DisplayContext_SetCharacterPointerFromBXAX
196; Parameters:
197; BX:AX: Ptr to destination for next character to output
198; DS: BDA segment (zero)
199; Returns:
[48]200; ES:DI: Pointer that was in BX:AX
[41]201; Corrupts registers:
202; AX
203;--------------------------------------------------------------------
[133]204%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[369]205ALIGN DISPLAY_JUMP_ALIGN
[41]206DisplayContext_SetCharacterPointerFromBXAX:
207 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax
208 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], bx
209 xchg di, ax
210 mov es, bx
211 ret
[133]212%endif
[41]213
214
215;--------------------------------------------------------------------
216; DisplayContext_GetCharacterPointerToBXAX
217; Parameters:
218; DS: BDA segment (zero)
219; Returns:
220; BX:AX: Ptr to destination for next character to output
221; Corrupts registers:
222; Nothing
223;--------------------------------------------------------------------
[133]224%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[369]225ALIGN DISPLAY_JUMP_ALIGN
[41]226DisplayContext_GetCharacterPointerToBXAX:
227 mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
228 mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
229 ret
[133]230%endif
[41]231
232
[491]233%ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
234 %ifndef MODULE_BOOT_MENU
235 %define EXCLUDE
236 %endif
237%endif
[41]238;--------------------------------------------------------------------
[45]239; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
[41]240; Parameters:
241; AX: Offset to character output function
[45]242; BL: Attribute Flag
[41]243; DS: BDA segment (zero)
244; Returns:
245; Nothing
246; Corrupts registers:
[50]247; BL
[41]248;--------------------------------------------------------------------
[491]249%ifndef EXCLUDE ; 1 of 3
[369]250ALIGN DISPLAY_JUMP_ALIGN
[45]251DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
[50]252 and bl, FLG_CONTEXT_ATTRIBUTES
253 and BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES
254 or [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl
[41]255 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
256 ret
[491]257%endif
[41]258
[489]259
[41]260;--------------------------------------------------------------------
261; DisplayContext_SetCharacterAttributeFromAL
262; Parameters:
263; AL: Character attribute
264; DS: BDA segment (zero)
265; Returns:
266; Nothing
267; Corrupts registers:
268; Nothing
269;--------------------------------------------------------------------
[491]270%ifndef EXCLUDE ; 2 of 3
[369]271ALIGN DISPLAY_JUMP_ALIGN
[41]272DisplayContext_SetCharacterAttributeFromAL:
273 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
274 ret
[491]275%endif
[41]276
277
278;--------------------------------------------------------------------
279; DisplayContext_SetCharacterOutputParameterFromAX
280; Parameters:
281; AX: Parameter for Character Output function
282; DS: BDA segment (zero)
283; Returns:
284; Nothing
285; Corrupts registers:
286; Nothing
287;--------------------------------------------------------------------
[491]288%ifndef EXCLUDE ; 3 of 3
[369]289ALIGN DISPLAY_JUMP_ALIGN
[41]290DisplayContext_SetCharacterOutputParameterFromAX:
291 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax
292 ret
[491]293%endif
294
295%undef EXCLUDE
296
297
[41]298;--------------------------------------------------------------------
299; DisplayContext_GetCharacterOutputParameterToDX
300; Parameters:
301; DS: BDA segment (zero)
302; Returns:
303; DX: User parameter for Character Output function
304; Corrupts registers:
305; Nothing
[133]306;--------------------------------------------------------------------
[491]307%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS OR EXCLUDE_FROM_XTIDECFG
[369]308ALIGN DISPLAY_JUMP_ALIGN
[181]309DisplayContext_GetCharacterOutputParameterToDX:
310 mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
311 ret
312%endif
[44]313
314
315;--------------------------------------------------------------------
316; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
317; Parameters:
318; AX: Offset in bytes from some character to another
319; DS: BDA segment (zero)
320; Returns:
321; AX: Offset in characters from some character to another
322; Corrupts registers:
323; Nothing
[133]324;--------------------------------------------------------------------
[201]325%ifndef MODULE_STRINGS_COMPRESSED
[369]326ALIGN DISPLAY_JUMP_ALIGN
[44]327DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX:
328 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
329 jz SHORT ReturnOffsetInAX
330 sar ax, 1 ; BYTE count to WORD count
331 ret
[194]332%endif
[44]333
[491]334
[44]335;--------------------------------------------------------------------
336; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
337; Parameters:
338; AX: Offset in characters from some character to another
339; DS: BDA segment (zero)
340; Returns:
341; AX: Offset in bytes from some character to another
342; Corrupts registers:
343; Nothing
[133]344;--------------------------------------------------------------------
[201]345%ifndef MODULE_STRINGS_COMPRESSED
[369]346ALIGN DISPLAY_JUMP_ALIGN
[44]347DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX:
348 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
349 jz SHORT ReturnOffsetInAX
350 sal ax, 1 ; WORD count to BYTE count
[369]351ALIGN DISPLAY_JUMP_ALIGN, ret
[44]352ReturnOffsetInAX:
353 ret
[194]354%endif
Note: See TracBrowser for help on using the repository browser.