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

Last change on this file since 64 was 57, checked in by Tomi Tilli, 14 years ago

Initial commit (Work in progress).

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