source: xtideuniversalbios/trunk/Configurator/Src/Menupages/FlashMenu.asm@ 162

Last change on this file since 162 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: 14.4 KB
RevLine 
[2]1; Project name : XTIDE Univeral BIOS Configurator
2; Description : Flash menu.
3
4
5; Flash error codes returned from progress bar task function
6ERR_FLASH_SUCCESSFULL EQU 0
7ERR_FLASH_POLL_TIMEOUT EQU 1
8
9
10; Section containing initialized data
11SECTION .data
12
13; -Back to previous menu
14; *Start flashing
15; +SDP command (Enable)
16; EEPROM address (D000h)
17; Page size (1)
18; Generate checksum byte (Y)
19
20ALIGN WORD_ALIGN
21g_MenuPageFlash:
22istruc MENUPAGE
23 at MENUPAGE.bItemCnt, db 6
24iend
25istruc MENUPAGEITEM ; Back to previous menu
26 at MENUPAGEITEM.fnActivate, dw MainPageItem_ActivateLeaveSubmenu
27 at MENUPAGEITEM.fnNameFormat, dw MenuPageItemFormat_NameForAnyType
28 at MENUPAGEITEM.szName, dw g_szPreviousMenu
29 at MENUPAGEITEM.szInfo, dw g_szNfoCfgBack
30 at MENUPAGEITEM.szHelp, dw g_szNfoCfgBack
31 at MENUPAGEITEM.bFlags, db FLG_MENUPAGEITEM_VISIBLE
32 at MENUPAGEITEM.bType, db TYPE_MENUPAGEITEM_BACK
33iend
34istruc MENUPAGEITEM ; Start flashing
35 at MENUPAGEITEM.fnActivate, dw FlashMenu_ActivateStartFlashing
36 at MENUPAGEITEM.fnNameFormat, dw MenuPageItemFormat_NameForAnyType
37 at MENUPAGEITEM.szName, dw g_szItemFlashStart
38 at MENUPAGEITEM.szInfo, dw g_szNfoFlashStart
39 at MENUPAGEITEM.szHelp, dw g_szNfoFlashStart
40 at MENUPAGEITEM.bFlags, db FLG_MENUPAGEITEM_VISIBLE
41 at MENUPAGEITEM.bType, db TYPE_MENUPAGEITEM_SPECIAL
42iend
43istruc MENUPAGEITEM ; SDP command
44 at MENUPAGEITEM.fnActivate, dw FlashMenu_ActivateSdpCommand
45 at MENUPAGEITEM.fnNameFormat, dw MenuPageItemFormat_LookupString
46 at MENUPAGEITEM.pValue, dw g_cfgVars+CFGVARS.bSdpCommand
47 at MENUPAGEITEM.pSubMenuPage, dw g_MenuPageSdpCommand
48 at MENUPAGEITEM.rgszLookup, dw g_rgszSdpValueToString
49 at MENUPAGEITEM.szName, dw g_szItemFlashSDP
50 at MENUPAGEITEM.szInfo, dw g_szNfoFlashSDP
51 at MENUPAGEITEM.szHelp, dw g_szHelpFlashSDP
52 at MENUPAGEITEM.bFlags, db FLG_MENUPAGEITEM_VISIBLE
53 at MENUPAGEITEM.bType, db TYPE_MENUPAGEITEM_NEXT
54iend
55istruc MENUPAGEITEM ; EEPROM address
56 at MENUPAGEITEM.fnActivate, dw MenuPageItem_GetHexWordFromUserWithoutMarkingUnsaved
57 at MENUPAGEITEM.fnNameFormat, dw MenuPageItemFormat_NameForAnyType
58 at MENUPAGEITEM.pValue, dw g_cfgVars+CFGVARS.wEepromSegment
59 at MENUPAGEITEM.szName, dw g_szItemFlashAddr
60 at MENUPAGEITEM.szInfo, dw g_szNfoFlashAddr
61 at MENUPAGEITEM.szHelp, dw g_szNfoFlashAddr
62 at MENUPAGEITEM.szDialog, dw g_szDlgFlashAddr
63 at MENUPAGEITEM.bFlags, db FLG_MENUPAGEITEM_VISIBLE
64 at MENUPAGEITEM.bType, db TYPE_MENUPAGEITEM_HEX_WORD
65iend
66istruc MENUPAGEITEM ; Page size
67 at MENUPAGEITEM.fnActivate, dw FlashMenu_ActivatePageSize
68 at MENUPAGEITEM.fnNameFormat, dw MenuPageItemFormat_NameForAnyType
69 at MENUPAGEITEM.pValue, dw g_cfgVars+CFGVARS.bPageSize
70 at MENUPAGEITEM.wValueMin, dw 1
71 at MENUPAGEITEM.wValueMax, dw 64
72 at MENUPAGEITEM.szName, dw g_szItemFlashPageSize
73 at MENUPAGEITEM.szInfo, dw g_szNfoFlashPageSize
74 at MENUPAGEITEM.szHelp, dw g_szHelpFlashPageSize
75 at MENUPAGEITEM.szDialog, dw g_szDlgFlashPageSize
76 at MENUPAGEITEM.bFlags, db FLG_MENUPAGEITEM_VISIBLE
77 at MENUPAGEITEM.bType, db TYPE_MENUPAGEITEM_UNSIGNED_BYTE
78iend
79istruc MENUPAGEITEM ; Generate checksum byte
80 at MENUPAGEITEM.fnActivate, dw MenuPageItem_GetBoolFromUserWithoutMarkingUnsaved
81 at MENUPAGEITEM.fnNameFormat, dw MenuPageItemFormat_NameForAnyType
82 at MENUPAGEITEM.pValue, dw g_cfgVars+CFGVARS.wFlags
83 at MENUPAGEITEM.wValueMask, dw FLG_CFGVARS_CHECKSUM
84 at MENUPAGEITEM.szName, dw g_szItemFlashChecksum
85 at MENUPAGEITEM.szInfo, dw g_szNfoFlashChecksum
86 at MENUPAGEITEM.szHelp, dw g_szHelpFlashChecksum
87 at MENUPAGEITEM.szDialog, dw g_szDlgFlashChecksum
88 at MENUPAGEITEM.bFlags, db FLG_MENUPAGEITEM_VISIBLE
89 at MENUPAGEITEM.bType, db TYPE_MENUPAGEITEM_FLAG
90iend
91
92
93; Section containing code
94SECTION .text
95
96;--------------------------------------------------------------------
97; FlashMenu_ActivateSdpCommand
98; Parameters:
99; DS:SI Ptr to MENUPAGE
100; DS:DI Ptr to MENUPAGEITEM
101; SS:BP: Ptr to MENUVARS
102; Returns:
103; CF: Set if menuitem changed
104; Cleared if no changes
105; Corrupts registers:
106; AX, BX, CX, DX
107;--------------------------------------------------------------------
108ALIGN JUMP_ALIGN
109FlashMenu_ActivateSdpCommand:
110 call MainPageItem_ActivateSubmenuForGettingLookupValueWithoutMarkingUnsaved
111 jnc SHORT .Return
112 call FormatTitle_RedrawMenuTitle
113 stc
114.Return:
115 ret
116
117
118;--------------------------------------------------------------------
119; FlashMenu_ActivatePageSize
120; Parameters:
121; DS:SI Ptr to MENUPAGE
122; DS:DI Ptr to MENUPAGEITEM
123; SS:BP: Ptr to MENUVARS
124; Returns:
125; CF: Set if menuitem changed
126; Cleared if no changes
127; Corrupts registers:
128; AX, BX, CX, DX
129;--------------------------------------------------------------------
130ALIGN JUMP_ALIGN
131FlashMenu_ActivatePageSize:
132 call MenuPageItem_GetByteFromUserWithoutMarkingUnsaved
133 jnc SHORT .Cancel
134 eMOVZX bx, BYTE [g_cfgVars+CFGVARS.bPageSize]
135 eBSR ax, bx ; AX = Index of highest order bit
136 mov cx, 1
137 xchg ax, cx
138 shl ax, cl ; AX = 1, 2, 4, 8, 16, 32 or 64
139 mov [g_cfgVars+CFGVARS.bPageSize], al
140 stc
141.Cancel:
142 ret
143
144
145;--------------------------------------------------------------------
146; FlashMenu_ActivateStartFlashing
147; Parameters:
148; DS:SI Ptr to MENUPAGE
149; DS:DI Ptr to MENUPAGEITEM
150; SS:BP: Ptr to MENUVARS
151; Returns:
152; CF: Set if menuitem changed
153; Cleared if no changes
154; Corrupts registers:
155; AX, BX, CX, DX, ES
156;--------------------------------------------------------------------
157ALIGN JUMP_ALIGN
158FlashMenu_ActivateStartFlashing:
159 test WORD [g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_CHECKSUM
160 jz SHORT .CopyContentsForComparison
161 call EEPROM_GenerateChecksum
162ALIGN JUMP_ALIGN
163.CopyContentsForComparison:
164 call Flash_CopyCurrentContentsForComparison
165 call FlashMenu_InitializeFlashVars
166 call FlashMenu_CreateProgressDialogAndStartFlashing
167 call FlashMenu_ProcessFlashResults
168 clc
169 ret
170
171;--------------------------------------------------------------------
172; Initializes FLASHVARS.
173;
174; FlashMenu_InitializeFlashVars
175; Parameters:
176; DS: CS
177; Returns:
178; Nothing
179; Corrupts registers:
180; AX, CX, DX
181;--------------------------------------------------------------------
182ALIGN JUMP_ALIGN
183FlashMenu_InitializeFlashVars:
184 ; Total number of pages to write
185 xor dx, dx
186 mov ax, [g_cfgVars+CFGVARS.wEepromSize] ; DX:AX = Bytes to write
187 eMOVZX cx, BYTE [g_cfgVars+CFGVARS.bPageSize]
188 div cx ; AX = Total number of pages
189 mov [g_cfgVars+CFGVARS.flashVars+FLASHVARS.wTotalPages], ax
190 mov [g_cfgVars+CFGVARS.flashVars+FLASHVARS.wPagesLeft], ax
191
192 ; Number of pages to write before updating progress bar
193 mov cx, WIDTH_DLG-4
194 div cx ; AX = Number of pages before update
195 mov [g_cfgVars+CFGVARS.flashVars+FLASHVARS.wPagesBeforeDraw], ax
196
197 ; Zero offset since nothing written yet
198 mov WORD [g_cfgVars+CFGVARS.flashVars+FLASHVARS.wByteOffset], 0
199 ret
200
201;--------------------------------------------------------------------
202; Shows progress bar dialog.
203;
204; FlashMenu_CreateProgressDialogAndStartFlashing
205; Parameters:
206; SS:BP: Ptr to MENUVARS
207; Returns:
208; AX: Return code from progress bar task function
209; Corrupts registers:
210; BX, CX, DX, ES
211;--------------------------------------------------------------------
212ALIGN JUMP_ALIGN
213FlashMenu_CreateProgressDialogAndStartFlashing:
214 push ds
215 push di
216 push si
217
218 mov bx, WIDTH_DLG | (5<<8) ; Height = 5 rows
219 mov si, g_cfgVars+CFGVARS.flashVars ; DS:SI points to FLASHVARS
220 push cs
221 pop es
222 mov di, FlashMenu_FlashProgressBarTask ; ES:DI points to progress bar task function
223 call Menu_ShowProgDlg
224
225 pop si
226 pop di
227 pop ds
228 ret
229
230;--------------------------------------------------------------------
231; Progress bar task function for flashing.
232; Cursor will be set to Title string location so progress dialog
233; title string can be modified if so wanted.
234; Remember to return with RETF instead of RET!
235;
236; FlashMenu_FlashProgressBarTask
237; Parameters:
238; DS:SI: Pointer to FLASHVARS
239; Returns:
240; AX: Error code if task completed (CF set)
241; Task completion percentage (0...100) if CF cleared
242; CF: Set if task was completed or cancelled
243; Cleared if task must be continued
244; Corrupts registers:
245; BX, CX, DX
246;--------------------------------------------------------------------
247ALIGN JUMP_ALIGN
248FlashMenu_FlashProgressBarTask:
249 call FlashMenu_UpdateProgressBarTitle
250 call FlashMenu_FlashAllPagesBeforeUpdate
251 jc SHORT .Timeout
252 call FlashMenu_CalculateCompletionPercentage
253 jc SHORT .FlashComplete
254 retf
255ALIGN JUMP_ALIGN
256.FlashComplete:
257 mov ax, ERR_FLASH_SUCCESSFULL
258 retf
259.Timeout:
260 mov ax, ERR_FLASH_POLL_TIMEOUT
261 retf
262
263
264;--------------------------------------------------------------------
265; Updates progress bar dialog title string.
266;
267; FlashMenu_UpdateProgressBarTitle
268; Parameters:
269; DS:SI: Pointer to FLASHVARS
270; Returns:
271; Nothing
272; Corrupts registers:
273; AX, DX
274;--------------------------------------------------------------------
275ALIGN JUMP_ALIGN
276FlashMenu_UpdateProgressBarTitle:
277 push si
278 mov ax, [si+FLASHVARS.wTotalPages]
279 sub ax, [si+FLASHVARS.wPagesLeft] ; AX=Pages written
280 eMOVZX dx, BYTE [g_cfgVars+CFGVARS.bPageSize]
281 mul dx ; AX=Bytes written
282
283 push WORD [g_cfgVars+CFGVARS.wEepromSize] ; EEPROM size
284 push ax ; Bytes written
285 mov si, g_szFlashProgress
286 call Print_Format
287 add sp, BYTE 4 ; Clean stack
288 pop si
289 ret
290
291;--------------------------------------------------------------------
292; Flashes pages until it is time to update progress bar.
293;
294; FlashMenu_FlashAllPagesBeforeUpdate
295; Parameters:
296; DS:SI: Pointer to FLASHVARS
297; Returns:
298; CF: Cleared if pages written successfully
299; Set if polling timeout
300; Corrupts registers:
301; AX, BX, CX, DX
[145]302;--------------------------------------------------------------------
[2]303ALIGN JUMP_ALIGN
304FlashMenu_FlashAllPagesBeforeUpdate:
305 push es
306 push bp
307 push di
308 push si
309
310 mov bp, si
311 mov dx, [si+FLASHVARS.wPagesBeforeDraw]
312 call FlashMenu_GetPointersToPageToFlash
313 eMOVZX ax, BYTE [g_cfgVars+CFGVARS.bSdpCommand]
314 eMOVZX cx, BYTE [g_cfgVars+CFGVARS.bPageSize]
315ALIGN JUMP_ALIGN
316.PageLoop:
317 call Flash_WritePage
318 jc SHORT .Return
319 add [ds:bp+FLASHVARS.wByteOffset], cx
320 clc
321 dec WORD [ds:bp+FLASHVARS.wPagesLeft]
322 jz SHORT .Return ; Test since .wPagesBeforeDraw might write too much
323 dec dx
324 jnz SHORT .PageLoop
325.Return:
326 pop si
327 pop di
328 pop bp
329 pop es
330 ret
331
332;--------------------------------------------------------------------
333; Returns all pointers required for flashing.
334;
335; FlashMenu_GetPointersToPageToFlash
336; Parameters:
337; DS:SI: Pointer to FLASHVARS
338; Returns:
339; DS:BX: Pointer to comparison buffer
340; DS:SI: Pointer to source data buffer
341; ES:DI: Pointer to EEPROM
342; Corrupts registers:
343; AX
344;--------------------------------------------------------------------
345ALIGN JUMP_ALIGN
346FlashMenu_GetPointersToPageToFlash:
347 mov ax, [si+FLASHVARS.wByteOffset]
348 call EEPROM_GetComparisonBufferPointerToDSBX
349 call EEPROM_GetSourceBufferPointerToDSSI
350 call EEPROM_GetEepromPointerToESDI
351 add bx, ax
352 add si, ax
353 add di, ax
354 ret
355
356
357;--------------------------------------------------------------------
358; Returns all pointers required for flashing.
359;
360; FlashMenu_GetFlashPointersToNextPage
361; Parameters:
362; DS:SI: Pointer to FLASHVARS
363; Returns:
364; AX: Completion percentage (0...100)
365; CF: Set if all done
366; Cleared if not yet complete
367; Corrupts registers:
368; Nothing
369;--------------------------------------------------------------------
370ALIGN JUMP_ALIGN
371FlashMenu_CalculateCompletionPercentage:
372 cmp WORD [si+FLASHVARS.wPagesLeft], 0
373 je SHORT .FlashComplete
374 mov ax, 100
375 mul WORD [si+FLASHVARS.wPagesLeft]
376 div WORD [si+FLASHVARS.wTotalPages] ; AX = Percentage left to write
377 mov ah, 100
378 sub ah, al
379 mov al, ah
380 xor ah, ah ; AX = Percentage written (clears CF)
381 ret
382ALIGN JUMP_ALIGN
383.FlashComplete:
384 mov ax, 100
385 stc
386 ret
387
388
389;--------------------------------------------------------------------
390; Processes results from flashing.
391; Computer will be rebooted if PC expansion card BIOS was flashed.
392;
393; FlashMenu_ProcessFlashResults
394; Parameters:
395; AX: Return code from progress bar task function
396; DS:SI Ptr to MENUPAGE
397; DS:DI Ptr to MENUPAGEITEM
398; SS:BP: Ptr to MENUVARS
399; Returns:
400; Nothing
401; Corrupts registers:
402; AX, BX, CX, DX, ES
403;--------------------------------------------------------------------
404ALIGN JUMP_ALIGN
405FlashMenu_ProcessFlashResults:
406 cmp ax, ERR_FLASH_POLL_TIMEOUT
407 je SHORT FlashMenu_PollingTimeoutErrorDuringFlashing
408 call Flash_WasDataWriteSuccessfull
409 jne SHORT FlashMenu_DataVerifyErrorAfterFlashing
410 ; Fall to FlashMenu_EepromFlashedSuccessfully
411
412;--------------------------------------------------------------------
413; Computer will be rebooted if PC expansion card BIOS was flashed.
414;
415; FlashMenu_EepromFlashedSuccessfully
416; Parameters:
417; DS:SI Ptr to MENUPAGE
418; DS:DI Ptr to MENUPAGEITEM
419; SS:BP: Ptr to MENUVARS
420; Returns:
421; Nothing
422; Corrupts registers:
423; AX, BX, DX
424;--------------------------------------------------------------------
425FlashMenu_EepromFlashedSuccessfully:
426 cmp WORD [g_cfgVars+CFGVARS.rgbEepromBuffers+ROMVARS.wRomSign], 0AA55h
427 je SHORT .RebootSinceAllDone
428 mov WORD [di+MENUPAGEITEM.szDialog], g_szFlashDoneContinue
429 jmp MenuPageItem_DisplaySpecialFunctionDialog
430ALIGN JUMP_ALIGN
431.RebootSinceAllDone:
432 mov WORD [di+MENUPAGEITEM.szDialog], g_szFlashDoneReboot
433 call MenuPageItem_DisplaySpecialFunctionDialog
434 mov al, 0FEh ; System reset (AT+ keyboard controller)
435 out 64h, al ; Reset computer (AT+)
436 jmp WORD 0F000h:0FFF0h ; Safe reset on XTs only
437
438;--------------------------------------------------------------------
439; Displays flash error messages.
440;
441; FlashMenu_PollingTimeoutErrorDuringFlashing
442; FlashMenu_DataVerifyErrorAfterFlashing
443; Parameters:
444; DS:SI Ptr to MENUPAGE
445; DS:DI Ptr to MENUPAGEITEM
446; SS:BP: Ptr to MENUVARS
447; Returns:
448; Nothing
449; Corrupts registers:
450; AX, BX, DX
451;--------------------------------------------------------------------
452ALIGN JUMP_ALIGN
453FlashMenu_PollingTimeoutErrorDuringFlashing:
454 mov WORD [di+MENUPAGEITEM.szDialog], g_szFlashTimeout
455 jmp MenuPageItem_DisplaySpecialFunctionDialog
456
457ALIGN JUMP_ALIGN
458FlashMenu_DataVerifyErrorAfterFlashing:
459 mov WORD [di+MENUPAGEITEM.szDialog], g_szFlashVerifyErr
460 jmp MenuPageItem_DisplaySpecialFunctionDialog
Note: See TracBrowser for help on using the repository browser.