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