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

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

Minor size optimizations to all parts of the project (even the old Configurator).
Also added a new 'release' option to the makefiles of both versions of the Configurator. It invokes UPX and makes the Configurator programs ridiculously tiny.

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