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 |
---|
21 | SECTION .text |
---|
22 | |
---|
23 | ;-------------------------------------------------------------------- |
---|
24 | ; Buffers_Clear |
---|
25 | ; Parameters: |
---|
26 | ; Nothing |
---|
27 | ; Returns: |
---|
28 | ; Nothing |
---|
29 | ; Corrupts registers: |
---|
30 | ; AX, CX, DI, ES |
---|
31 | ;-------------------------------------------------------------------- |
---|
32 | ALIGN JUMP_ALIGN |
---|
33 | Buffers_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 | ;-------------------------------------------------------------------- |
---|
49 | ALIGN JUMP_ALIGN |
---|
50 | Buffers_IsXtideUniversalBiosLoaded: |
---|
51 | test BYTE [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 | ;-------------------------------------------------------------------- |
---|
71 | ALIGN JUMP_ALIGN |
---|
72 | Buffers_IsXtideUniversalBiosSignatureInESDI: |
---|
73 | push di |
---|
74 | |
---|
75 | mov si, g_sXtideUniversalBiosSignature |
---|
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 | ;-------------------------------------------------------------------- |
---|
97 | ALIGN JUMP_ALIGN |
---|
98 | Buffers_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_NewBiosWithSizeInDXCXandSourceInALhasBeenLoadedForConfiguration |
---|
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 | ;-------------------------------------------------------------------- |
---|
120 | ALIGN JUMP_ALIGN |
---|
121 | Buffers_NewBiosWithSizeInDXCXandSourceInALhasBeenLoadedForConfiguration: |
---|
122 | and BYTE [g_cfgVars+CFGVARS.wFlags], ~(FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED | FLG_CFGVARS_UNSAVED) |
---|
123 | or [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 [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 | ;-------------------------------------------------------------------- |
---|
141 | ALIGN JUMP_ALIGN |
---|
142 | Buffers_SetUnsavedChanges: |
---|
143 | or BYTE [g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_UNSAVED |
---|
144 | ret |
---|
145 | |
---|
146 | ALIGN JUMP_ALIGN |
---|
147 | Buffers_ClearUnsavedChanges: |
---|
148 | and BYTE [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 | ;-------------------------------------------------------------------- |
---|
161 | ALIGN JUMP_ALIGN |
---|
162 | Buffers_SaveChangesIfFileLoaded: |
---|
163 | test BYTE [g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_FILELOADED | FLG_CFGVARS_UNSAVED |
---|
164 | jz SHORT .NothingToSave |
---|
165 | jpo SHORT .NothingToSave |
---|
166 | mov bx, g_szDlgSaveChanges |
---|
167 | call Dialogs_DisplayYesNoResponseDialogWithTitleStringInBX |
---|
168 | jnz SHORT .NothingToSave |
---|
169 | jmp BiosFile_SaveUnsavedChanges |
---|
170 | ALIGN JUMP_ALIGN |
---|
171 | .NothingToSave: |
---|
172 | ret |
---|
173 | |
---|
174 | ;-------------------------------------------------------------------- |
---|
175 | ; Buffers_GetSelectedEepromSizeInWordsToAX |
---|
176 | ; Parameters: |
---|
177 | ; Nothing |
---|
178 | ; Returns: |
---|
179 | ; AX: Selected EEPROM size in WORDs |
---|
180 | ; Corrupts registers: |
---|
181 | ; BX |
---|
182 | ;-------------------------------------------------------------------- |
---|
183 | ALIGN JUMP_ALIGN |
---|
184 | Buffers_GetSelectedEepromSizeInWordsToAX: |
---|
185 | eMOVZX bx, [g_cfgVars+CFGVARS.bEepromType] |
---|
186 | mov ax, [bx+g_rgwEepromTypeToSizeInWords] |
---|
187 | |
---|
188 | cmp bl, EEPROM_TYPE.SST_39SF |
---|
189 | jne SHORT .HaveEepromSize |
---|
190 | cmp ax, [g_cfgVars+CFGVARS.wImageSizeInWords] |
---|
191 | jae SHORT .HaveEepromSize |
---|
192 | eSHL_IM ax, 1 ; Auto-double SST size when too small. |
---|
193 | .HaveEepromSize: |
---|
194 | ret |
---|
195 | |
---|
196 | ;-------------------------------------------------------------------- |
---|
197 | ; Buffers_AppendZeroesIfNeeded |
---|
198 | ; Parameters: |
---|
199 | ; Nothing |
---|
200 | ; Returns: |
---|
201 | ; Nothing |
---|
202 | ; Corrupts registers: |
---|
203 | ; AX, BX, CX, DI |
---|
204 | ;-------------------------------------------------------------------- |
---|
205 | ALIGN JUMP_ALIGN |
---|
206 | Buffers_AppendZeroesIfNeeded: |
---|
207 | call Buffers_GetSelectedEepromSizeInWordsToAX |
---|
208 | mov cx, [g_cfgVars+CFGVARS.wImageSizeInWords] |
---|
209 | sub ax, cx ; AX = WORDs to append |
---|
210 | jbe SHORT .NoNeedToAppendZeroes |
---|
211 | |
---|
212 | eSHL_IM cx, 1 |
---|
213 | push es |
---|
214 | call Buffers_GetFileBufferToESDI |
---|
215 | add di, cx ; ES:DI now point first unused image byte |
---|
216 | xor cx, cx |
---|
217 | xchg cx, ax |
---|
218 | %ifdef CLD_NEEDED |
---|
219 | cld |
---|
220 | %endif |
---|
221 | rep stosw |
---|
222 | pop es |
---|
223 | .NoNeedToAppendZeroes: |
---|
224 | ret |
---|
225 | |
---|
226 | |
---|
227 | ;-------------------------------------------------------------------- |
---|
228 | ; Buffers_GenerateChecksum |
---|
229 | ; Parameters: |
---|
230 | ; Nothing |
---|
231 | ; Returns: |
---|
232 | ; Nothing |
---|
233 | ; Corrupts registers: |
---|
234 | ; AX, BX, CX, DI |
---|
235 | ;-------------------------------------------------------------------- |
---|
236 | ALIGN JUMP_ALIGN |
---|
237 | Buffers_GenerateChecksum: |
---|
238 | push es |
---|
239 | push dx |
---|
240 | |
---|
241 | call Buffers_GetFileBufferToESDI |
---|
242 | call EEPROM_GetXtideUniversalBiosSizeFromESDItoDXCX |
---|
243 | %ifdef CLD_NEEDED |
---|
244 | cld |
---|
245 | %endif |
---|
246 | |
---|
247 | ; Compatibility fix for 3Com 3C503 cards where the ASIC returns 8080h as the last two bytes of the ROM. |
---|
248 | |
---|
249 | ; Assume the BIOS size is not 8K, ie generate a normal checksum. |
---|
250 | dec cx |
---|
251 | mov ax, 100h |
---|
252 | cmp cx, 8192 - 1 |
---|
253 | jne SHORT .BiosSizeIsNot8K |
---|
254 | ; The BIOS size is 8K and therefore a potential candidate for a 3Com 3C503 card. |
---|
255 | mov cl, (8192 - 3) & 0FFh |
---|
256 | mov ah, 3 |
---|
257 | ALIGN JUMP_ALIGN |
---|
258 | .BiosSizeIsNot8K: |
---|
259 | .SumNextByte: |
---|
260 | add al, [es:di] |
---|
261 | inc di |
---|
262 | loop .SumNextByte |
---|
263 | .NextChecksumByte: |
---|
264 | neg al |
---|
265 | stosb |
---|
266 | dec ah |
---|
267 | jnz SHORT .NextChecksumByte |
---|
268 | |
---|
269 | pop dx |
---|
270 | pop es |
---|
271 | ret |
---|
272 | |
---|
273 | |
---|
274 | ;-------------------------------------------------------------------- |
---|
275 | ; Buffers_GetRomvarsFlagsToAX |
---|
276 | ; Parameters: |
---|
277 | ; Nothing |
---|
278 | ; Returns: |
---|
279 | ; AX: ROMVARS.wFlags |
---|
280 | ; Corrupts registers: |
---|
281 | ; BX |
---|
282 | ;-------------------------------------------------------------------- |
---|
283 | ALIGN JUMP_ALIGN |
---|
284 | Buffers_GetRomvarsFlagsToAX: |
---|
285 | mov bx, ROMVARS.wFlags |
---|
286 | ; Fall to Buffers_GetRomvarsValueToAXfromOffsetInBX |
---|
287 | |
---|
288 | ;-------------------------------------------------------------------- |
---|
289 | ; Buffers_GetRomvarsValueToAXfromOffsetInBX |
---|
290 | ; Parameters: |
---|
291 | ; BX: ROMVARS offset |
---|
292 | ; Returns: |
---|
293 | ; AX: Value |
---|
294 | ; Corrupts registers: |
---|
295 | ; Nothing |
---|
296 | ;-------------------------------------------------------------------- |
---|
297 | ALIGN JUMP_ALIGN |
---|
298 | Buffers_GetRomvarsValueToAXfromOffsetInBX: |
---|
299 | push es |
---|
300 | push di |
---|
301 | call Buffers_GetFileBufferToESDI |
---|
302 | mov ax, [es:bx+di] |
---|
303 | pop di |
---|
304 | pop es |
---|
305 | ret |
---|
306 | |
---|
307 | |
---|
308 | ;-------------------------------------------------------------------- |
---|
309 | ; Buffers_GetIdeControllerCountToCX |
---|
310 | ; Parameters: |
---|
311 | ; SS:BP: Menu handle |
---|
312 | ; Returns: |
---|
313 | ; CX: Number of IDE controllers to configure |
---|
314 | ; ES:DI: Ptr to file buffer |
---|
315 | ; Corrupts registers: |
---|
316 | ; Nothing |
---|
317 | ;-------------------------------------------------------------------- |
---|
318 | ALIGN JUMP_ALIGN |
---|
319 | Buffers_GetIdeControllerCountToCX: |
---|
320 | xor cx, cx |
---|
321 | call Buffers_GetFileBufferToESDI |
---|
322 | or cl, [es:di+ROMVARS.bIdeCnt] |
---|
323 | jnz SHORT .LimitControllerCountForLiteMode |
---|
324 | inc cx ; Make sure there is at least one controller |
---|
325 | |
---|
326 | .LimitControllerCountForLiteMode: |
---|
327 | test BYTE [es:di+ROMVARS.wFlags], FLG_ROMVARS_FULLMODE |
---|
328 | jnz SHORT .ReturnControllerCountInCX |
---|
329 | MIN_U cl, MAX_LITE_MODE_CONTROLLERS |
---|
330 | |
---|
331 | .ReturnControllerCountInCX: |
---|
332 | ret |
---|
333 | |
---|
334 | |
---|
335 | ;-------------------------------------------------------------------- |
---|
336 | ; Buffers_GetFlashComparisonBufferToESDI |
---|
337 | ; Buffers_GetFileDialogItemBufferToESDI |
---|
338 | ; Buffers_GetFileBufferToESDI |
---|
339 | ; Parameters: |
---|
340 | ; Nothing |
---|
341 | ; Returns: |
---|
342 | ; ES:DI: Ptr to file buffer |
---|
343 | ; Corrupts registers: |
---|
344 | ; Nothing |
---|
345 | ;-------------------------------------------------------------------- |
---|
346 | ALIGN JUMP_ALIGN |
---|
347 | Buffers_GetFlashComparisonBufferToESDI: |
---|
348 | Buffers_GetFileDialogItemBufferToESDI: |
---|
349 | call Buffers_GetFileBufferToESDI |
---|
350 | mov di, es |
---|
351 | SKIP2B f |
---|
352 | Buffers_GetFileBufferToESDI: |
---|
353 | mov di, cs |
---|
354 | add di, 1000h ; Change to next 64k page |
---|
355 | mov es, di |
---|
356 | xor di, di ; Ptr now in ES:DI |
---|
357 | ret |
---|