1 | ; Project name : XTIDE Univeral BIOS Configurator v2 |
---|
2 | ; Description : Functions for loading and saving BIOS image file. |
---|
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 |
---|
21 | SECTION .text |
---|
22 | |
---|
23 | ;-------------------------------------------------------------------- |
---|
24 | ; BiosFile_LoadFileFromDSSItoRamBuffer |
---|
25 | ; Parameters: |
---|
26 | ; DS:SI: Name of file to open |
---|
27 | ; SS:BP: Menu handle |
---|
28 | ; Returns: |
---|
29 | ; Nothing |
---|
30 | ; Corrupts registers: |
---|
31 | ; AX, BX, CX, DX, SI, DI |
---|
32 | ;-------------------------------------------------------------------- |
---|
33 | ALIGN JUMP_ALIGN |
---|
34 | BiosFile_LoadFileFromDSSItoRamBuffer: |
---|
35 | push ds |
---|
36 | |
---|
37 | call .OpenFileForLoadingFromDSSIandGetSizeToDXCX |
---|
38 | jc SHORT .DisplayErrorMessage |
---|
39 | call .LoadFileWithNameInDSSIhandleInBXandSizeInDXCXtoRamBuffer |
---|
40 | jc SHORT .DisplayErrorMessage |
---|
41 | |
---|
42 | mov ax, FLG_CFGVARS_FILELOADED |
---|
43 | call Buffers_NewBiosWithSizeInDXCXandSourceInAXhasBeenLoadedForConfiguration |
---|
44 | call FileIO_CloseUsingHandleFromBX |
---|
45 | call DisplayFileLoadedSuccessfully |
---|
46 | jmp SHORT .Return |
---|
47 | |
---|
48 | .DisplayErrorMessage: |
---|
49 | call FileIO_CloseUsingHandleFromBX |
---|
50 | call DisplayFailedToLoadFile |
---|
51 | ALIGN JUMP_ALIGN |
---|
52 | .Return: |
---|
53 | pop ds |
---|
54 | ret |
---|
55 | |
---|
56 | ;-------------------------------------------------------------------- |
---|
57 | ; .OpenFileForLoadingFromDSSIandGetSizeInBytesToDXCX |
---|
58 | ; Parameters: |
---|
59 | ; DS:SI: Name of file to open |
---|
60 | ; Returns: |
---|
61 | ; BX: File handle (if successful) |
---|
62 | ; DX:CX: File size (if successful) |
---|
63 | ; CF: Clear if successful |
---|
64 | ; Set if error |
---|
65 | ; Corrupts registers: |
---|
66 | ; AX |
---|
67 | ;-------------------------------------------------------------------- |
---|
68 | ALIGN JUMP_ALIGN |
---|
69 | .OpenFileForLoadingFromDSSIandGetSizeToDXCX: |
---|
70 | mov al, FILE_ACCESS.ReadOnly |
---|
71 | call FileIO_OpenWithPathInDSSIandFileAccessInAL |
---|
72 | jc SHORT .FileError |
---|
73 | call FileIO_GetFileSizeToDXAXusingHandleFromBXandResetFilePosition |
---|
74 | jc SHORT .FileError |
---|
75 | |
---|
76 | cmp dx, MAX_EEPROM_SIZE_IN_BYTES >> 16 |
---|
77 | ja SHORT .FileTooBig |
---|
78 | jb SHORT .FileNotTooBig |
---|
79 | cmp ax, MAX_EEPROM_SIZE_IN_BYTES & 0FFFFh |
---|
80 | ja SHORT .FileTooBig |
---|
81 | .FileNotTooBig: |
---|
82 | xchg cx, ax |
---|
83 | clc |
---|
84 | ret |
---|
85 | .FileTooBig: |
---|
86 | call DisplayFileTooBig |
---|
87 | stc |
---|
88 | .FileError: |
---|
89 | ret |
---|
90 | |
---|
91 | ;-------------------------------------------------------------------- |
---|
92 | ; .LoadFileWithNameInDSSIhandleInBXandSizeInDXCXtoRamBuffer |
---|
93 | ; Parameters: |
---|
94 | ; BX: File Handle |
---|
95 | ; DX:CX: File size |
---|
96 | ; DS:SI: File name |
---|
97 | ; Returns: |
---|
98 | ; CF: Clear if successful |
---|
99 | ; Set if error |
---|
100 | ; Corrupts registers: |
---|
101 | ; AX, SI, DI, DS |
---|
102 | ;-------------------------------------------------------------------- |
---|
103 | ALIGN JUMP_ALIGN |
---|
104 | .LoadFileWithNameInDSSIhandleInBXandSizeInDXCXtoRamBuffer: |
---|
105 | push es |
---|
106 | |
---|
107 | call Buffers_GetFileBufferToESDI |
---|
108 | call Registers_ExchangeDSSIwithESDI |
---|
109 | call FileIO_ReadDXCXbytesToDSSIusingHandleFromBX |
---|
110 | jc SHORT .ReturnError |
---|
111 | |
---|
112 | ; Store filename to Cfgvars from ESDI |
---|
113 | push cx |
---|
114 | |
---|
115 | call Registers_CopyESDItoDSSI ; File name in DS:SI |
---|
116 | push cs |
---|
117 | pop es |
---|
118 | mov di, g_cfgVars+CFGVARS.szOpenedFile |
---|
119 | cld |
---|
120 | call String_CopyDSSItoESDIandGetLengthToCX |
---|
121 | clc |
---|
122 | |
---|
123 | pop cx |
---|
124 | ALIGN JUMP_ALIGN |
---|
125 | .ReturnError: |
---|
126 | pop es |
---|
127 | ret |
---|
128 | |
---|
129 | |
---|
130 | ;-------------------------------------------------------------------- |
---|
131 | ; BiosFile_SaveUnsavedChanges |
---|
132 | ; Parameters: |
---|
133 | ; SS:BP: Menu handle |
---|
134 | ; Returns: |
---|
135 | ; Nothing |
---|
136 | ; Corrupts registers: |
---|
137 | ; AX, BX, CX, SI, DI |
---|
138 | ;-------------------------------------------------------------------- |
---|
139 | ALIGN JUMP_ALIGN |
---|
140 | BiosFile_SaveUnsavedChanges: |
---|
141 | push ds |
---|
142 | |
---|
143 | push cs |
---|
144 | pop ds |
---|
145 | mov si, g_cfgVars+CFGVARS.szOpenedFile |
---|
146 | call BiosFile_SaveRamBufferToFileInDSSI |
---|
147 | |
---|
148 | pop ds |
---|
149 | ret |
---|
150 | |
---|
151 | |
---|
152 | ;-------------------------------------------------------------------- |
---|
153 | ; BiosFile_SaveRamBufferToFileInDSSI |
---|
154 | ; Parameters: |
---|
155 | ; DS:SI: Name of file to save |
---|
156 | ; SS:BP: Menu handle |
---|
157 | ; Returns: |
---|
158 | ; Nothing |
---|
159 | ; Corrupts registers: |
---|
160 | ; AX, BX, CX, SI, DI |
---|
161 | ;-------------------------------------------------------------------- |
---|
162 | ALIGN JUMP_ALIGN |
---|
163 | BiosFile_SaveRamBufferToFileInDSSI: |
---|
164 | push es |
---|
165 | push ds |
---|
166 | |
---|
167 | call Buffers_GenerateChecksum |
---|
168 | call Buffers_GetFileBufferToESDI |
---|
169 | call EEPROM_GetXtideUniversalBiosSizeFromESDItoDXCX |
---|
170 | |
---|
171 | mov al, FILE_ACCESS.WriteOnly |
---|
172 | call FileIO_OpenWithPathInDSSIandFileAccessInAL |
---|
173 | jc SHORT .DisplayErrorMessage |
---|
174 | |
---|
175 | call Registers_CopyESDItoDSSI |
---|
176 | call FileIO_WriteDXCXbytesFromDSSIusingHandleFromBX |
---|
177 | jc SHORT .DisplayErrorMessage |
---|
178 | |
---|
179 | call FileIO_CloseUsingHandleFromBX |
---|
180 | call Buffers_ClearUnsavedChanges |
---|
181 | call DisplayFileSavedSuccessfully |
---|
182 | jmp SHORT .Return |
---|
183 | |
---|
184 | .DisplayErrorMessage: |
---|
185 | call FileIO_CloseUsingHandleFromBX |
---|
186 | call DisplayFailedToSaveFile |
---|
187 | ALIGN JUMP_ALIGN |
---|
188 | .Return: |
---|
189 | pop ds |
---|
190 | pop es |
---|
191 | ret |
---|
192 | |
---|
193 | |
---|
194 | ;-------------------------------------------------------------------- |
---|
195 | ; DisplayFileLoadedSuccessfully |
---|
196 | ; DisplayFileSavedSuccessfully |
---|
197 | ; DisplayFailedToLoadFile |
---|
198 | ; DisplayFailedToSaveFile |
---|
199 | ; DisplayFileTooBig |
---|
200 | ; Parameters: |
---|
201 | ; SS:BP: Menu handle |
---|
202 | ; Returns: |
---|
203 | ; Nothing |
---|
204 | ; Corrupts registers: |
---|
205 | ; AX, DX |
---|
206 | ;-------------------------------------------------------------------- |
---|
207 | ALIGN JUMP_ALIGN |
---|
208 | DisplayFileLoadedSuccessfully: |
---|
209 | mov dx, g_szDlgMainLoadFile |
---|
210 | jmp Dialogs_DisplayNotificationFromCSDX |
---|
211 | |
---|
212 | ALIGN JUMP_ALIGN |
---|
213 | DisplayFileSavedSuccessfully: |
---|
214 | mov dx, g_szDlgMainSaveFile |
---|
215 | jmp Dialogs_DisplayNotificationFromCSDX |
---|
216 | |
---|
217 | DisplayFailedToLoadFile: |
---|
218 | mov dx, g_szDlgMainLoadErr |
---|
219 | jmp Dialogs_DisplayErrorFromCSDX |
---|
220 | |
---|
221 | DisplayFailedToSaveFile: |
---|
222 | mov dx, g_szDlgMainSaveErr |
---|
223 | jmp Dialogs_DisplayErrorFromCSDX |
---|
224 | |
---|
225 | DisplayFileTooBig: |
---|
226 | mov dx, g_szDlgMainFileTooBig |
---|
227 | jmp Dialogs_DisplayErrorFromCSDX |
---|