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

Last change on this file since 594 was 592, checked in by Krister Nordvall, 6 years ago

Changes:

  • The problem with NASM in the previous revision (r591) has been fixed.
  • The colors used by the boot menu and hotkey bar can now be customized by selecting one of a number of pre-defined color themes. Suggestions for additional themes are more than welcome!
  • Large builds are now 10 KB. Small builds are still 8 KB with the exception of the Tiny build which is now 4 KB. In other words, builds are now as small as possible to make it easier to combine them with other BIOSes.
  • Added code to the library to improve drive error handling. XTIDECFG can now handle "Drive Not Ready" errors.
  • Fixed a couple of potential bugs in AtaID.asm (AtaID_GetMaxPioModeToAXandMinCycleTimeToCX); 1) ATA1.bPioMode was treated as a WORD variable. 2) ATA2.bPIOSupp was assumed to be non-zero which would result in PIO mode 3 being returned if the assumption was wrong.
  • Made the same changes in the equivalent function used by BIOSDRVS (DisplayPioModeInformationUsingAtaInfoFromDSBX in AtaInfo.asm).
  • Fixed a bug from r587 in PDC20x30.asm in PDC20x30_GetMaxPioModeToALandMinPioCycleTimeToBX.
  • Fixed a bug from r523 in XTIDECFG where Auto Configure would only set the IRQ on one IDE interface on AT-builds.
  • XTIDECFG will now restore the default settings for the "Serial port virtual device" when reselecting it in the list of device types. This makes it behave consistently for all device types.
  • The eAAM macro is now used regardless if USE_UNDOC_INTEL is defined or not because it is apparently supported on all processors including the NEC V20/V30 CPUs.
  • Renamed the EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS define to EXCLUDE_FROM_XUB.
  • Added a define to exclude unused library code from BIOSDRVS (EXCLUDE_FROM_BIOSDRVS). This makes it a lot smaller than in previous revisions.
  • All unnecessary CLD-instructions are now under a new define 'CLD_NEEDED' which is only enabled for the BIOS. It is disabled for XTIDECFG and BIOSDRVS but can be enabled if needed by adding this define to the respective makefile. This change was made because these unnecessary instructions are wasteful and should never be needed. In fact, they only serve to hide bugs (in other peoples code) which I strongly believe should be avoided. I recommend people making their own BIOSes from source to not use this define as it's extremely unlikely to be needed.
  • Updated the copyright info in SerDrive and changed an URL to point to the new site.
  • Updated the copyright info and version number in BIOSDRVS.
  • Updated the copyright info in XTIDECFG.
  • Optimizations in general.
File size: 11.1 KB
Line 
1; Project name : Assembly Library
2; Description : Functions for managing display context.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 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.
12;
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
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
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;--------------------------------------------------------------------
32ALIGN DISPLAY_JUMP_ALIGN
33DisplayContext_Initialize:
34 mov WORD [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], DEFAULT_CHARACTER_OUTPUT
35 mov BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], SCREEN_BACKGROUND_ATTRIBUTE
36 call DisplayCursor_GetDefaultCursorShapeToAX
37 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCursorShape], ax
38 ; Fall to .DetectAndSetDisplaySegment
39
40;--------------------------------------------------------------------
41; .DetectAndSetDisplaySegment
42; Parameters:
43; DS: BDA segment (zero)
44; Returns:
45; Nothing
46; Corrupts registers:
47; AX, DX
48;--------------------------------------------------------------------
49.DetectAndSetDisplaySegment:
50 mov ax, COLOR_TEXT_SEGMENT
51 cmp BYTE [VIDEO_BDA.bMode], MDA_TEXT_MODE
52 eCMOVE ah, MONO_TEXT_SEGMENT >> 8
53 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], ax
54 ; Fall to .InitializeFlags
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 eCMOVC dl, FLG_CONTEXT_ATTRIBUTES | FLG_CONTEXT_CGA
69 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], dl
70 ; Fall to .InitializeCursor
71
72;--------------------------------------------------------------------
73; .InitializeCursor
74; Parameters:
75; DS: BDA segment (zero)
76; Returns:
77; Nothing
78; Corrupts registers:
79; AX, DX
80;--------------------------------------------------------------------
81.InitializeCursor:
82 call DisplayCursor_GetHardwareCoordinatesToAX ; Coordinates before init
83 call DisplayCursor_SetCoordinatesFromAX ; Cursor to Display Context
84 ; Fall to DisplayContext_SynchronizeToHardware
85
86;--------------------------------------------------------------------
87; DisplayContext_SynchronizeToHardware
88; Parameters:
89; DS: BDA segment (zero)
90; Returns:
91; Nothing
92; Corrupts registers:
93; AX, DX
94;--------------------------------------------------------------------
95ALIGN DISPLAY_JUMP_ALIGN
96DisplayContext_SynchronizeToHardware:
97 call DisplayPage_SynchronizeToHardware
98 call DisplayCursor_SynchronizeShapeToHardware
99 jmp DisplayCursor_SynchronizeCoordinatesToHardware
100
101
102;--------------------------------------------------------------------
103; DisplayContext_Push
104; DisplayContext_Pop
105; Parameters:
106; Nothing
107; Returns:
108; Nothing
109; Corrupts registers:
110; AX, DI
111;--------------------------------------------------------------------
112%ifdef EXCLUDE_FROM_XUB
113 %ifndef MODULE_BOOT_MENU
114 %define EXCLUDE
115 %endif
116%endif
117
118%ifndef EXCLUDE OR EXCLUDE_FROM_BIOSDRVS
119ALIGN DISPLAY_JUMP_ALIGN
120DisplayContext_Push:
121 mov di, ds ; Backup DS
122 LOAD_BDA_SEGMENT_TO ds, ax
123 pop ax ; Pop return address
124
125%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
126 %assign i 0
127 %ifdef USE_386
128 %rep DISPLAY_CONTEXT_size / 4
129 push DWORD [VIDEO_BDA.displayContext + i]
130 %assign i i+4
131 %endrep
132 %else
133 %rep DISPLAY_CONTEXT_size / 2
134 push WORD [VIDEO_BDA.displayContext + i]
135 %assign i i+2
136 %endrep
137 %endif
138%endif
139
140 mov ds, di ; Restore DS
141 jmp ax
142
143
144ALIGN DISPLAY_JUMP_ALIGN
145DisplayContext_Pop:
146 mov di, ds ; Backup DS
147 LOAD_BDA_SEGMENT_TO ds, ax
148 pop ax ; Pop return address
149
150%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
151 %ifdef USE_386
152 %assign i DISPLAY_CONTEXT_size-4
153 %rep DISPLAY_CONTEXT_size / 4
154 pop DWORD [VIDEO_BDA.displayContext + i]
155 %assign i i-4
156 %endrep
157 %else
158 %assign i DISPLAY_CONTEXT_size-2
159 %rep DISPLAY_CONTEXT_size / 2
160 pop WORD [VIDEO_BDA.displayContext + i]
161 %assign i i-2
162 %endrep
163 %endif
164%endif
165
166 push ax ; Push return address
167 push dx
168 call DisplayContext_SynchronizeToHardware
169 pop dx
170 mov ds, di ; Restore DS
171 ret
172%endif ; EXCLUDE OR EXCLUDE_FROM_BIOSDRVS
173%undef EXCLUDE
174
175
176;--------------------------------------------------------------------
177; DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX
178; Parameters:
179; CX: Off screen buffer length in characters
180; ES:BX: Ptr to off screen buffer
181; Returns:
182; Nothing
183; Corrupts registers:
184; AX, DI
185;--------------------------------------------------------------------
186%ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
187ALIGN DISPLAY_JUMP_ALIGN
188DisplayContext_PrepareOffScreenBufferInESBXwithLengthInCX:
189 push ds
190
191 LOAD_BDA_SEGMENT_TO ds, di
192 xchg ax, bx
193 mov bx, es
194 call DisplayContext_SetCharacterPointerFromBXAX ; ES:DI now has the pointer
195
196 mov bl, ATTRIBUTES_NOT_USED
197 mov ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
198 call DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
199 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], cx
200
201 mov bx, di
202 pop ds
203 ret
204%endif ; EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
205
206
207;--------------------------------------------------------------------
208; DisplayContext_SetCharacterPointerFromBXAX
209; Parameters:
210; BX:AX: Ptr to destination for next character to output
211; DS: BDA segment (zero)
212; Returns:
213; ES:DI: Pointer that was in BX:AX
214; Corrupts registers:
215; AX
216;--------------------------------------------------------------------
217%ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
218ALIGN DISPLAY_JUMP_ALIGN
219DisplayContext_SetCharacterPointerFromBXAX:
220 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition], ax
221 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2], bx
222 xchg di, ax
223 mov es, bx
224 ret
225%endif
226
227
228;--------------------------------------------------------------------
229; DisplayContext_GetCharacterPointerToBXAX
230; Parameters:
231; DS: BDA segment (zero)
232; Returns:
233; BX:AX: Ptr to destination for next character to output
234; Corrupts registers:
235; Nothing
236;--------------------------------------------------------------------
237%ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_BIOSDRVS
238ALIGN DISPLAY_JUMP_ALIGN
239DisplayContext_GetCharacterPointerToBXAX:
240 mov ax, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition]
241 mov bx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fpCursorPosition+2]
242 ret
243%endif
244
245
246%ifdef EXCLUDE_FROM_XUB
247 %ifndef MODULE_BOOT_MENU
248 %define EXCLUDE
249 %endif
250%endif
251;--------------------------------------------------------------------
252; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
253; Parameters:
254; AX: Offset to character output function
255; BL: Attribute Flag
256; DS: BDA segment (zero)
257; Returns:
258; Nothing
259; Corrupts registers:
260; BL
261;--------------------------------------------------------------------
262%ifndef EXCLUDE ; 1 of 3
263ALIGN DISPLAY_JUMP_ALIGN
264DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
265 and bl, FLG_CONTEXT_ATTRIBUTES
266 and BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES
267 or [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl
268 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
269 ret
270%endif
271
272
273;--------------------------------------------------------------------
274; DisplayContext_SetCharacterAttributeFromAL
275; Parameters:
276; AL: Character attribute
277; DS: BDA segment (zero)
278; Returns:
279; Nothing
280; Corrupts registers:
281; Nothing
282;--------------------------------------------------------------------
283%ifndef EXCLUDE ; 2 of 3
284%ifndef EXCLUDE_FROM_BIOSDRVS
285ALIGN DISPLAY_JUMP_ALIGN
286DisplayContext_SetCharacterAttributeFromAL:
287 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bAttribute], al
288 ret
289%endif
290%endif
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;--------------------------------------------------------------------
303%ifndef EXCLUDE ; 3 of 3
304%ifndef EXCLUDE_FROM_BIOSDRVS
305ALIGN DISPLAY_JUMP_ALIGN
306DisplayContext_SetCharacterOutputParameterFromAX:
307 mov [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam], ax
308 ret
309%endif
310%endif
311
312%undef EXCLUDE
313
314
315;--------------------------------------------------------------------
316; DisplayContext_GetCharacterOutputParameterToDX
317; Parameters:
318; DS: BDA segment (zero)
319; Returns:
320; DX: User parameter for Character Output function
321; Corrupts registers:
322; Nothing
323;--------------------------------------------------------------------
324%ifndef EXCLUDE_FROM_XUB OR EXCLUDE_FROM_XTIDECFG OR EXCLUDE_FROM_BIOSDRVS
325ALIGN DISPLAY_JUMP_ALIGN
326DisplayContext_GetCharacterOutputParameterToDX:
327 mov dx, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
328 ret
329%endif
330
331
332;--------------------------------------------------------------------
333; DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX
334; Parameters:
335; AX: Offset in bytes from some character to another
336; DS: BDA segment (zero)
337; Returns:
338; AX: Offset in characters from some character to another
339; Corrupts registers:
340; Nothing
341;--------------------------------------------------------------------
342%ifndef MODULE_STRINGS_COMPRESSED
343ALIGN DISPLAY_JUMP_ALIGN
344DisplayContext_GetCharacterOffsetToAXfromByteOffsetInAX:
345 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
346 jz SHORT ReturnOffsetInAX
347 sar ax, 1 ; BYTE count to WORD count
348 ret
349%endif
350
351
352;--------------------------------------------------------------------
353; DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX
354; Parameters:
355; AX: Offset in characters from some character to another
356; DS: BDA segment (zero)
357; Returns:
358; AX: Offset in bytes from some character to another
359; Corrupts registers:
360; Nothing
361;--------------------------------------------------------------------
362%ifndef MODULE_STRINGS_COMPRESSED
363ALIGN DISPLAY_JUMP_ALIGN
364DisplayContext_GetByteOffsetToAXfromCharacterOffsetInAX:
365 test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_ATTRIBUTES
366 jz SHORT ReturnOffsetInAX
367 sal ax, 1 ; WORD count to BYTE count
368ALIGN DISPLAY_JUMP_ALIGN, ret
369ReturnOffsetInAX:
370 ret
371%endif
Note: See TracBrowser for help on using the repository browser.