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

Last change on this file since 392 was 376, checked in by gregli@…, 13 years ago

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 8.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-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.
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 no file or some other file is loaded
46; Corrupts registers:
47; CX, SI, DI, ES
48;--------------------------------------------------------------------
49ALIGN JUMP_ALIGN
50Buffers_IsXtideUniversalBiosLoaded:
51 test WORD [cs:g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED
52 jz SHORT .NoFileOrBiosLoaded
53
54 call Buffers_GetFileBufferToESDI
55 jmp SHORT Buffers_IsXtideUniversalBiosSignatureInESDI
56.NoFileOrBiosLoaded:
57 or cl, 1 ; Clear ZF
58 ret
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 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 cld
79 eSEG_STR repe, cs, cmpsw
80
81 pop di
82 ret
83
84
85;--------------------------------------------------------------------
86; Buffers_NewBiosWithSizeInDXCXandSourceInAXhasBeenLoadedForConfiguration
87; Parameters:
88; AX: EEPROM source (FLG_CFGVARS_FILELOADED or FLG_CFGVARS_ROMLOADED)
89; DX:CX: EEPROM size in bytes
90; Returns:
91; Nothing
92; Corrupts registers:
93; AX, CX, DX
94;--------------------------------------------------------------------
95ALIGN JUMP_ALIGN
96Buffers_NewBiosWithSizeInDXCXandSourceInAXhasBeenLoadedForConfiguration:
97 and WORD [cs:g_cfgVars+CFGVARS.wFlags], ~(FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED | FLG_CFGVARS_UNSAVED)
98 or WORD [cs:g_cfgVars+CFGVARS.wFlags], ax
99 shr dx, 1
100 rcr cx, 1
101 adc cx, BYTE 0 ; Round up to next WORD
102 mov [cs:g_cfgVars+CFGVARS.wImageSizeInWords], cx
103 ret
104
105
106;--------------------------------------------------------------------
107; Buffers_SetUnsavedChanges
108; Buffers_ClearUnsavedChanges
109; Parameters:
110; SS:BP: Menu handle
111; Returns:
112; Nothing
113; Corrupts registers:
114; Nothing
115;--------------------------------------------------------------------
116ALIGN JUMP_ALIGN
117Buffers_SetUnsavedChanges:
118 or WORD [cs:g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_UNSAVED
119 ret
120
121ALIGN JUMP_ALIGN
122Buffers_ClearUnsavedChanges:
123 and WORD [cs:g_cfgVars+CFGVARS.wFlags], ~FLG_CFGVARS_UNSAVED
124 ret
125
126
127;--------------------------------------------------------------------
128; Buffers_SaveChangesIfFileLoaded
129; Parameters:
130; Nothing
131; Returns:
132; Nothing
133; Corrupts registers:
134; AX, BX, CX, SI, DI
135;--------------------------------------------------------------------
136ALIGN JUMP_ALIGN
137Buffers_SaveChangesIfFileLoaded:
138 mov ax, [cs:g_cfgVars+CFGVARS.wFlags]
139 and ax, BYTE (FLG_CFGVARS_FILELOADED | FLG_CFGVARS_UNSAVED)
140 cmp ax, BYTE (FLG_CFGVARS_FILELOADED | FLG_CFGVARS_UNSAVED)
141 jne SHORT .NothingToSave
142 call Dialogs_DisplaySaveChangesDialog
143 jnz SHORT .NothingToSave
144 jmp BiosFile_SaveUnsavedChanges
145ALIGN JUMP_ALIGN
146.NothingToSave:
147 ret
148
149
150;--------------------------------------------------------------------
151; Buffers_AppendZeroesIfNeeded
152; Parameters:
153; Nothing
154; Returns:
155; Nothing
156; Corrupts registers:
157; AX, CX, DI
158;--------------------------------------------------------------------
159ALIGN JUMP_ALIGN
160Buffers_AppendZeroesIfNeeded:
161 push es
162
163 eMOVZX di, [cs:g_cfgVars+CFGVARS.bEepromType]
164 mov cx, [cs:di+g_rgwEepromTypeToSizeInWords]
165 sub cx, [cs:g_cfgVars+CFGVARS.wImageSizeInWords] ; CX = WORDs to append
166 jle SHORT .NoNeedToAppendZeroes
167
168 call Buffers_GetFileBufferToESDI
169 mov ax, [cs:g_cfgVars+CFGVARS.wImageSizeInWords]
170 shl ax, 1
171 add di, ax ; ES:DI now point first unused image byte
172 xor ax, ax
173 cld
174 rep stosw
175ALIGN JUMP_ALIGN
176.NoNeedToAppendZeroes:
177 pop es
178 ret
179
180
181;--------------------------------------------------------------------
182; Buffers_GenerateChecksum
183; Parameters:
184; Nothing
185; Returns:
186; Nothing
187; Corrupts registers:
188; AX, BX, CX, DI
189;--------------------------------------------------------------------
190ALIGN JUMP_ALIGN
191Buffers_GenerateChecksum:
192 push es
193
194 call Buffers_GetFileBufferToESDI
195 mov ax, [cs:g_cfgVars+CFGVARS.wImageSizeInWords]
196 call EEPROM_GetSmallestEepromSizeInWordsToCXforImageWithWordSizeInAX
197 shl cx, 1 ; Words to bytes
198 dec cx ; Leave space for checksum byte
199 xor ax, ax
200ALIGN JUMP_ALIGN
201.SumNextByte:
202 add al, [es:di]
203 inc di
204 loop .SumNextByte
205 neg al
206 mov [es:di], al
207
208 pop es
209 ret
210
211
212;--------------------------------------------------------------------
213; Buffers_GetRomvarsFlagsToAX
214; Parameters:
215; Nothing
216; Returns:
217; AX: ROMVARS.wFlags
218; Corrupts registers:
219; BX
220;--------------------------------------------------------------------
221ALIGN JUMP_ALIGN
222Buffers_GetRomvarsFlagsToAX:
223 mov bx, ROMVARS.wFlags
224 ; Fall to Buffers_GetRomvarsValueToAXfromOffsetInBX
225
226;--------------------------------------------------------------------
227; Buffers_GetRomvarsValueToAXfromOffsetInBX
228; Parameters:
229; BX: ROMVARS offset
230; Returns:
231; AX: Value
232; Corrupts registers:
233; Nothing
234;--------------------------------------------------------------------
235ALIGN JUMP_ALIGN
236Buffers_GetRomvarsValueToAXfromOffsetInBX:
237 push es
238 push di
239 call Buffers_GetFileBufferToESDI
240 mov ax, [es:bx+di]
241 pop di
242 pop es
243 ret
244
245
246;--------------------------------------------------------------------
247; Buffers_GetIdeControllerCountToCX
248; Parameters:
249; SS:BP: Menu handle
250; Returns:
251; CX: Number of IDE controllers to configure
252; ES:DI: Ptr to file buffer
253; Corrupts registers:
254; AX
255;--------------------------------------------------------------------
256ALIGN JUMP_ALIGN
257Buffers_GetIdeControllerCountToCX:
258 call Buffers_GetFileBufferToESDI
259 mov al, [es:di+ROMVARS.bIdeCnt]
260
261 ; Limit controller count for lite mode
262 test BYTE [es:di+ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
263 jnz SHORT .ReturnControllerCountInCX
264 MIN_U al, MAX_LITE_MODE_CONTROLLERS
265
266.ReturnControllerCountInCX:
267 cbw ; A maximum of 127 controllers should be sufficient
268 xchg cx, ax
269 ret
270
271
272;--------------------------------------------------------------------
273; Buffers_GetFileBufferToESDI
274; Buffers_GetFlashComparisonBufferToESDI
275; Buffers_GetFileDialogItemBufferToESDI
276; Parameters:
277; Nothing
278; Returns:
279; ES:DI: Ptr to file buffer
280; Corrupts registers:
281; Nothing
282;--------------------------------------------------------------------
283ALIGN JUMP_ALIGN
284Buffers_GetFlashComparisonBufferToESDI:
285Buffers_GetFileDialogItemBufferToESDI:
286 call Buffers_GetFileBufferToESDI
287 push di
288 mov di, es
289 add di, 1000h ; Third 64k page
290 mov es, di
291 pop di
292 ret
293ALIGN JUMP_ALIGN
294Buffers_GetFileBufferToESDI:
295 mov di, cs
296 add di, 1000h ; Change to next 64k page
297 mov es, di
298 xor di, di ; Ptr now in ES:DI
299 ret
Note: See TracBrowser for help on using the repository browser.