source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm@ 592

Last change on this file since 592 was 592, checked in by Krister Nordvall, 7 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: 9.3 KB
Line 
1; Project name : XTIDE Universal BIOS Configurator v2
2; Description : Functions for accessing file and flash buffers.
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; Buffers_Clear
25; Parameters:
26; Nothing
27; Returns:
28; Nothing
29; Corrupts registers:
30; AX, CX, DI, ES
31;--------------------------------------------------------------------
32ALIGN JUMP_ALIGN
33Buffers_Clear:
34 call Buffers_GetFileBufferToESDI
35 mov cx, ROMVARS_size
36 jmp Memory_ZeroESDIwithSizeInCX
37
38
39;--------------------------------------------------------------------
40; Buffers_IsXtideUniversalBiosLoaded
41; Parameters:
42; Nothing
43; Returns:
44; ZF: Set if supported version of XTIDE Universal BIOS is loaded
45; Cleared if no file or some other file is loaded
46; Corrupts registers:
47; CX, SI, DI, ES
48;--------------------------------------------------------------------
49ALIGN JUMP_ALIGN
50Buffers_IsXtideUniversalBiosLoaded:
51 test BYTE [cs:g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED
52 jnz SHORT .FileOrBiosLoaded
53 test sp, sp ; Clear ZF
54 ret
55
56.FileOrBiosLoaded:
57 call Buffers_GetFileBufferToESDI
58 ; Fall to Buffers_IsXtideUniversalBiosSignatureInESDI
59
60
61;--------------------------------------------------------------------
62; Buffers_IsXtideUniversalBiosSignatureInESDI
63; Parameters:
64; ES:DI: Ptr to possible XTIDE Universal BIOS location
65; Returns:
66; ZF: Set if supported version of XTIDE Universal BIOS is loaded
67; Cleared if no file or some other file is loaded
68; Corrupts registers:
69; CX, SI
70;--------------------------------------------------------------------
71ALIGN JUMP_ALIGN
72Buffers_IsXtideUniversalBiosSignatureInESDI:
73 push di
74
75 mov si, g_szXtideUniversalBiosSignature
76 add di, BYTE ROMVARS.rgbSign
77 mov cx, XTIDE_SIGNATURE_LENGTH / 2
78%ifdef CLD_NEEDED
79 cld
80%endif
81 eSEG_STR repe, cs, cmpsw
82
83 pop di
84 ret
85
86
87;--------------------------------------------------------------------
88; Buffers_IsXTbuildLoaded
89; Parameters:
90; Nothing
91; Returns:
92; ZF: Set if XT or XT+ build is loaded
93; Cleared if some other (AT, 386) build is loaded
94; Corrupts registers:
95; Nothing
96;--------------------------------------------------------------------
97ALIGN JUMP_ALIGN
98Buffers_IsXTbuildLoaded:
99%strlen BUILD_TYPE_OFFSET TITLE_STRING_START
100 push es
101 push di
102 call Buffers_GetFileBufferToESDI
103 cmp WORD [es:di+ROMVARS.szTitle+BUILD_TYPE_OFFSET+1], 'XT' ; +1 is for '('
104 pop di
105 pop es
106 ret
107%undef BUILD_TYPE_OFFSET
108
109
110;--------------------------------------------------------------------
111; Buffers_NewBiosWithSizeInDXCXandSourceInAXhasBeenLoadedForConfiguration
112; Parameters:
113; AL: EEPROM source (FLG_CFGVARS_FILELOADED or FLG_CFGVARS_ROMLOADED)
114; DX:CX: EEPROM size in bytes
115; Returns:
116; Nothing
117; Corrupts registers:
118; CX, DX
119;--------------------------------------------------------------------
120ALIGN JUMP_ALIGN
121Buffers_NewBiosWithSizeInDXCXandSourceInAXhasBeenLoadedForConfiguration:
122 and BYTE [cs:g_cfgVars+CFGVARS.wFlags], ~(FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED | FLG_CFGVARS_UNSAVED)
123 or [cs:g_cfgVars+CFGVARS.wFlags], al
124 shr dx, 1
125 rcr cx, 1
126 adc cx, BYTE 0 ; Round up to next WORD
127 mov [cs:g_cfgVars+CFGVARS.wImageSizeInWords], cx
128 ret
129
130
131;--------------------------------------------------------------------
132; Buffers_SetUnsavedChanges
133; Buffers_ClearUnsavedChanges
134; Parameters:
135; SS:BP: Menu handle
136; Returns:
137; Nothing
138; Corrupts registers:
139; Nothing
140;--------------------------------------------------------------------
141ALIGN JUMP_ALIGN
142Buffers_SetUnsavedChanges:
143 or BYTE [cs:g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_UNSAVED
144 ret
145
146ALIGN JUMP_ALIGN
147Buffers_ClearUnsavedChanges:
148 and BYTE [cs:g_cfgVars+CFGVARS.wFlags], ~FLG_CFGVARS_UNSAVED
149 ret
150
151
152;--------------------------------------------------------------------
153; Buffers_SaveChangesIfFileLoaded
154; Parameters:
155; Nothing
156; Returns:
157; Nothing
158; Corrupts registers:
159; AX, BX, CX, SI, DI
160;--------------------------------------------------------------------
161ALIGN JUMP_ALIGN
162Buffers_SaveChangesIfFileLoaded:
163 mov al, [cs:g_cfgVars+CFGVARS.wFlags]
164 and al, FLG_CFGVARS_FILELOADED | FLG_CFGVARS_UNSAVED
165 jz SHORT .NothingToSave
166 jpo SHORT .NothingToSave
167 mov bx, g_szDlgSaveChanges
168 call Dialogs_DisplayYesNoResponseDialogWithTitleStringInBX
169 jnz SHORT .NothingToSave
170 jmp BiosFile_SaveUnsavedChanges
171ALIGN JUMP_ALIGN
172.NothingToSave:
173 ret
174
175
176;--------------------------------------------------------------------
177; Buffers_AppendZeroesIfNeeded
178; Parameters:
179; Nothing
180; Returns:
181; Nothing
182; Corrupts registers:
183; AX, CX, DI
184;--------------------------------------------------------------------
185ALIGN JUMP_ALIGN
186Buffers_AppendZeroesIfNeeded:
187 push es
188
189 eMOVZX di, [cs:g_cfgVars+CFGVARS.bEepromType]
190;%if g_rgwEepromTypeToSizeInWords = 0 ; *FIXME* It really is but NASM won't accept this.
191 mov cx, [cs:di]
192;%else
193; mov cx, [cs:di+g_rgwEepromTypeToSizeInWords]
194;%endif
195 sub cx, [cs:g_cfgVars+CFGVARS.wImageSizeInWords] ; CX = WORDs to append
196 jbe SHORT .NoNeedToAppendZeroes
197
198 call Buffers_GetFileBufferToESDI
199 mov ax, [cs:g_cfgVars+CFGVARS.wImageSizeInWords]
200 eSHL_IM ax, 1
201 add di, ax ; ES:DI now point first unused image byte
202 xor ax, ax
203%ifdef CLD_NEEDED
204 cld
205%endif
206 rep stosw
207ALIGN JUMP_ALIGN
208.NoNeedToAppendZeroes:
209 pop es
210 ret
211
212
213;--------------------------------------------------------------------
214; Buffers_GenerateChecksum
215; Parameters:
216; Nothing
217; Returns:
218; Nothing
219; Corrupts registers:
220; AX, BX, CX, DI
221;--------------------------------------------------------------------
222ALIGN JUMP_ALIGN
223Buffers_GenerateChecksum:
224 push es
225 push dx
226
227 call Buffers_GetFileBufferToESDI
228 call EEPROM_GetXtideUniversalBiosSizeFromESDItoDXCX
229%ifdef CLD_NEEDED
230 cld
231%endif
232
233; Compatibility fix for 3Com 3C503 cards where the ASIC returns 8080h as the last two bytes of the ROM.
234
235 ; Assume the BIOS size is not 8K, ie generate a normal checksum.
236 dec cx
237 mov ax, 100h
238 cmp cx, 8192 - 1
239 jne SHORT .BiosSizeIsNot8K
240 ; The BIOS size is 8K and therefore a potential candidate for a 3Com 3C503 card.
241 mov cl, (8192 - 3) & 0FFh
242 mov ah, 3
243ALIGN JUMP_ALIGN
244.BiosSizeIsNot8K:
245.SumNextByte:
246 add al, [es:di]
247 inc di
248 loop .SumNextByte
249.NextChecksumByte:
250 neg al
251 stosb
252 dec ah
253 jnz SHORT .NextChecksumByte
254
255 pop dx
256 pop es
257 ret
258
259
260;--------------------------------------------------------------------
261; Buffers_GetRomvarsFlagsToAX
262; Parameters:
263; Nothing
264; Returns:
265; AX: ROMVARS.wFlags
266; Corrupts registers:
267; BX
268;--------------------------------------------------------------------
269ALIGN JUMP_ALIGN
270Buffers_GetRomvarsFlagsToAX:
271 mov bx, ROMVARS.wFlags
272 ; Fall to Buffers_GetRomvarsValueToAXfromOffsetInBX
273
274;--------------------------------------------------------------------
275; Buffers_GetRomvarsValueToAXfromOffsetInBX
276; Parameters:
277; BX: ROMVARS offset
278; Returns:
279; AX: Value
280; Corrupts registers:
281; Nothing
282;--------------------------------------------------------------------
283ALIGN JUMP_ALIGN
284Buffers_GetRomvarsValueToAXfromOffsetInBX:
285 push es
286 push di
287 call Buffers_GetFileBufferToESDI
288 mov ax, [es:bx+di]
289 pop di
290 pop es
291 ret
292
293
294;--------------------------------------------------------------------
295; Buffers_GetIdeControllerCountToCX
296; Parameters:
297; SS:BP: Menu handle
298; Returns:
299; CX: Number of IDE controllers to configure
300; ES:DI: Ptr to file buffer
301; Corrupts registers:
302; Nothing
303;--------------------------------------------------------------------
304ALIGN JUMP_ALIGN
305Buffers_GetIdeControllerCountToCX:
306 xor cx, cx
307 call Buffers_GetFileBufferToESDI
308 or cl, [es:di+ROMVARS.bIdeCnt]
309 jnz SHORT .LimitControllerCountForLiteMode
310 inc cx ; Make sure there is at least one controller
311
312.LimitControllerCountForLiteMode:
313 test BYTE [es:di+ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
314 jnz SHORT .ReturnControllerCountInCX
315 MIN_U cl, MAX_LITE_MODE_CONTROLLERS
316
317.ReturnControllerCountInCX:
318 ret
319
320
321;--------------------------------------------------------------------
322; Buffers_GetFlashComparisonBufferToESDI
323; Buffers_GetFileDialogItemBufferToESDI
324; Buffers_GetFileBufferToESDI
325; Parameters:
326; Nothing
327; Returns:
328; ES:DI: Ptr to file buffer
329; Corrupts registers:
330; Nothing
331;--------------------------------------------------------------------
332ALIGN JUMP_ALIGN
333Buffers_GetFlashComparisonBufferToESDI:
334Buffers_GetFileDialogItemBufferToESDI:
335 call Buffers_GetFileBufferToESDI
336 mov di, es
337 SKIP2B f
338Buffers_GetFileBufferToESDI:
339 mov di, cs
340 add di, 1000h ; Change to next 64k page
341 mov es, di
342 xor di, di ; Ptr now in ES:DI
343 ret
Note: See TracBrowser for help on using the repository browser.