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

Last change on this file since 104 was 103, checked in by krille_n_@…, 14 years ago

Optimizations to Assembly Library.

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