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

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