source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/BiosFile.asm@ 463

Last change on this file since 463 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: 6.0 KB
Line 
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
21SECTION .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;--------------------------------------------------------------------
33ALIGN JUMP_ALIGN
34BiosFile_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
51ALIGN 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;--------------------------------------------------------------------
68ALIGN 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;--------------------------------------------------------------------
103ALIGN 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
124ALIGN 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;--------------------------------------------------------------------
139ALIGN JUMP_ALIGN
140BiosFile_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;--------------------------------------------------------------------
162ALIGN JUMP_ALIGN
163BiosFile_SaveRamBufferToFileInDSSI:
164 push es
165 push ds
166
167 call Buffers_GenerateChecksum
168 call Buffers_GetFileBufferToESDI
169 mov ax, [cs:g_cfgVars+CFGVARS.wImageSizeInWords]
170 call EEPROM_GetSmallestEepromSizeInWordsToCXforImageWithWordSizeInAX
171 xor dx, dx
172 shl cx, 1
173 rcl dx, 1 ; WORDs to BYTEs
174
175 mov al, FILE_ACCESS.WriteOnly
176 call FileIO_OpenWithPathInDSSIandFileAccessInAL
177 jc SHORT .DisplayErrorMessage
178
179 call Registers_CopyESDItoDSSI
180 call FileIO_WriteDXCXbytesFromDSSIusingHandleFromBX
181 jc SHORT .DisplayErrorMessage
182
183 call FileIO_CloseUsingHandleFromBX
184 call Buffers_ClearUnsavedChanges
185 call DisplayFileSavedSuccessfully
186 jmp SHORT .Return
187
188.DisplayErrorMessage:
189 call FileIO_CloseUsingHandleFromBX
190 call DisplayFailedToSaveFile
191ALIGN JUMP_ALIGN
192.Return:
193 pop ds
194 pop es
195 ret
196
197
198;--------------------------------------------------------------------
199; DisplayFileLoadedSuccessfully
200; DisplayFileSavedSuccessfully
201; DisplayFailedToLoadFile
202; DisplayFailedToSaveFile
203; DisplayFileTooBig
204; Parameters:
205; SS:BP: Menu handle
206; Returns:
207; Nothing
208; Corrupts registers:
209; AX, DX
210;--------------------------------------------------------------------
211ALIGN JUMP_ALIGN
212DisplayFileLoadedSuccessfully:
213 mov dx, g_szDlgMainLoadFile
214 jmp Dialogs_DisplayNotificationFromCSDX
215
216ALIGN JUMP_ALIGN
217DisplayFileSavedSuccessfully:
218 mov dx, g_szDlgMainSaveFile
219 jmp Dialogs_DisplayNotificationFromCSDX
220
221DisplayFailedToLoadFile:
222 mov dx, g_szDlgMainLoadErr
223 jmp Dialogs_DisplayErrorFromCSDX
224
225DisplayFailedToSaveFile:
226 mov dx, g_szDlgMainSaveErr
227 jmp Dialogs_DisplayErrorFromCSDX
228
229DisplayFileTooBig:
230 mov dx, g_szDlgMainFileTooBig
231 jmp Dialogs_DisplayErrorFromCSDX
Note: See TracBrowser for help on using the repository browser.