source: xtideuniversalbios/trunk/Configurator/Src/BiosFile.asm@ 386

Last change on this file since 386 was 181, checked in by krille_n_@…, 13 years ago

Changes to all parts of the project:

  • Size optimizations.
  • Added a define (EXCLUDE_FROM_XTIDECFG) to exclude unused library code from XTIDECFG.
  • Tried to minimize time spent with interrupts disabled.
  • Some minor attempts to improve speed (reordering instructions etc).
  • Tried to improve readability, did some cleanup and fixed some errors in comments.
File size: 6.2 KB
Line 
1; Project name : XTIDE Univeral BIOS Configurator
2; Description : Functions for loading and saving BIOS image file.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Saves changes to loaded BIOS image file if user wants to do so.
9;
10; BiosFile_SaveUnsavedChanges
11; Parameters:
12; SS:BP: Ptr to MENUVARS
13; Returns:
14; Nothing
15; Corrupts registers:
16; AX, BX, CX, DX, ES
17;--------------------------------------------------------------------
18ALIGN JUMP_ALIGN
19BiosFile_SaveUnsavedChanges:
20 push ds
21 push di
22 push si
23
24 ; Check if saving is needed
25 test WORD [cs:g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_UNSAVED
26 jz SHORT .Return
27 test WORD [cs:g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_FILELOADED
28 jz SHORT .Return
29
30 ; Ask if user wants to save
31 push cs
32 pop ds
33 push cs
34 pop es
35 call BiosFile_DoesUserWantToSaveChanges
36 jnc SHORT .Return
37
38 ; Write file
39 mov si, 80h ; DS:SI points to default DTA (DOS PSP:80h)
40 mov di, g_cfgVars+CFGVARS.rgbEepromBuffers ; ES:DI points to data to save
41 call EEPROM_GenerateChecksum
42 call BiosFile_SaveFile
43 jc SHORT .Return ; Return if error
44
45 ; Update unsaved status
46 and WORD [cs:g_cfgVars+CFGVARS.wFlags], ~FLG_CFGVARS_UNSAVED
47ALIGN JUMP_ALIGN
48.Return:
49 pop si
50 pop di
51 pop ds
52 ret
53
54;--------------------------------------------------------------------
55; Asks does user want to save changes to BIOS image file.
56;
57; BiosFile_DoesUserWantToSaveChanges
58; Parameters:
59; ES: String segment
60; SS:BP: Ptr to MENUVARS
61; Returns:
62; CF: Set if user wants to save changes
63; Cleared if used does not want to save changes
64; Corrupts registers:
65; AX, BX, CX, DX
66;--------------------------------------------------------------------
67ALIGN JUMP_ALIGN
68BiosFile_DoesUserWantToSaveChanges:
69 mov bl, WIDTH_DLG ; Dialog width
70 mov di, g_szDlgSaveChanges ; ES:DI points to string to display
71 jmp Menu_ShowYNDlg
72
73
74;--------------------------------------------------------------------
75; Saves loaded BIOS image to a file.
76;
77; BiosFile_SaveFile
78; Parameters:
79; DS:SI: Ptr to DTA for selected file
80; ES:DI: Ptr to data to save
81; SS:BP: Ptr to MENUVARS
82; Returns:
83; CF: Cleared if file saved successfully
84; Set if any error
85; Corrupts registers:
86; AX, BX, CX, DX
87;--------------------------------------------------------------------
88ALIGN JUMP_ALIGN
89BiosFile_SaveFile:
90 ; Open file
91 mov al, VAL_FACCS_WRITE ; Open for writing
92 lea dx, [si+DTA.szFile] ; DS:DX points to ASCIZ file name
93 call File_Open
94 jc SHORT BiosFile_DisplayFileErrorMessage
95
96 ; Save file
97 mov cx, [cs:g_cfgVars+CFGVARS.wEepromSize]
98 call File_Write
99 jc SHORT BiosFile_DisplayFileErrorMessage
100
101 ; Close file
102 jmp SHORT BiosFile_Close
103
104
105;--------------------------------------------------------------------
106; Loads file selected with BiosFile_SelectFile.
107;
108; BiosFile_LoadFile
109; Parameters:
110; DS:SI: Ptr to DTA for selected file
111; ES:DI: Ptr to buffer where to load file
112; SS:BP: Ptr to MENUVARS
113; Returns:
114; CX: EEPROM size in bytes
115; CF: Cleared if file loaded successfully
116; Set if any error
117; Corrupts registers:
118; AX, BX, DX
119;--------------------------------------------------------------------
120ALIGN JUMP_ALIGN
121BiosFile_LoadFile:
122 ; Open file
123 mov al, VAL_FACCS_READ ; Open for reading
124 lea dx, [si+DTA.szFile] ; DS:DX points to ASCIZ file name
125 call File_Open
126 jc SHORT BiosFile_DisplayFileErrorMessage
127
128 ; Load file to buffer
129 call BiosFile_GetFileSizeToCX
130 jc SHORT BiosFile_DisplayFileSizeErrorMessage
131 call File_Read
132 jc SHORT BiosFile_DisplayFileErrorMessage
133
134 ; Close file
135BiosFile_Close:
136 call File_Close
137 jc SHORT BiosFile_DisplayFileErrorMessage
138 ret
139
140
141;--------------------------------------------------------------------
142; Returns size for selected file and makes sure it is not too large.
143;
144; BiosFile_GetFileSizeToCX
145; Parameters:
146; DS:SI: Ptr to DTA for selected file
147; SS:BP: Ptr to MENUVARS
148; Returns:
149; CX: File size in bytes
150; CF: Set if file was too large
151; Cleared if supported size
152; Corrupts registers:
153; Nothing
154;--------------------------------------------------------------------
155ALIGN JUMP_ALIGN
156BiosFile_GetFileSizeToCX:
157 mov cx, [si+DTA.dwFileSize+2] ; High word of file size to CX
158 test cx, cx ; File larger than 65535 bytes? (clears CF)
159 mov cx, [si+DTA.dwFileSize] ; Low word of file size to CX
160 jnz SHORT .TooLargeFile
161 cmp cx, MAX_EEPROM_SIZE ; Too large?
162 ja SHORT .TooLargeFile
163 stc
164.TooLargeFile: ; CF is always cleared when jumping to here
165 cmc ; So we invert it
166 ret
167
168
169;--------------------------------------------------------------------
170; Displays error messages related to loading files.
171;
172; BiosFile_DisplayFileErrorMessage
173; BiosFile_DisplayFileSizeErrorMessage
174; Parameters:
175; AX: DOS File I/O error code (BiosFile_DisplayFileErrorMessage only)
176; DS:SI: Ptr to DTA for selected file
177; SS:BP: Ptr to MENUVARS
178; Returns:
179; CF: Set since error
180; Corrupts registers:
181; AX, BX, CX, DX
182;--------------------------------------------------------------------
183BiosFile_DisplayFileErrorMessage:
184 call File_GetErrStr ; Error string to ES:DI
185 jmp SHORT BiosFile_DisplayErrorMessage
186BiosFile_DisplayFileSizeErrorMessage:
187 push cs
188 pop es
189 mov di, g_szErrFileSize
190BiosFile_DisplayErrorMessage:
191 mov bl, WIDTH_DLG ; Dialog width
192 call Menu_ShowMsgDlg
193 stc
194 ret
195
196
197;--------------------------------------------------------------------
198; Selects BIOS file to be loaded.
199;
200; BiosFile_SelectFile
201; Parameters:
202; DS:DI Ptr to MENUPAGEITEM
203; SS:BP: Ptr to MENUVARS
204; Returns:
205; DS:SI: Ptr to DTA for selected file
206; CF: Set if file selected successfully
207; Cleared if user cancellation
208; Corrupts registers:
209; AX, BX, CX, DX, ES
210;--------------------------------------------------------------------
211ALIGN JUMP_ALIGN
212BiosFile_SelectFile:
213 push di
214 push cs ; Copy string segment...
215 pop es ; ...to ES
216 mov di, [di+MENUPAGEITEM.szDialog] ; ES:DI points to info string
217 mov si, g_szFileSearch ; DS:SI points to file search string
218 mov bl, WIDTH_DLG ; Dialog width
219 call Menu_ShowFileDlg ; Get DTA to DS:SI
220 pop di
221 ret
Note: See TracBrowser for help on using the repository browser.