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

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

Commit 1/2 (Library, Configurators and Serial Server):

  • Changed Emulate.inc so that making 286 and 386 versions now works. Additionally, only one processor type define is needed in the makefile.
  • Minor optimizations.
  • Fixed spelling and did some cleaning.
File size: 14.3 KB
RevLine 
[293]1; Project name : XTIDE Universal BIOS Configurator
[2]2; Description : Flash menu.
3
4
5; Flash error codes returned from progress bar task function
[293]6ERR_FLASH_SUCCESSFUL EQU 0
[2]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
[293]134 eMOVZX bx, [g_cfgVars+CFGVARS.bPageSize]
[2]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
[293]187 eMOVZX cx, [g_cfgVars+CFGVARS.bPageSize]
[2]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:
[293]257 mov ax, ERR_FLASH_SUCCESSFUL
[2]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
[293]280 eMOVZX dx, [g_cfgVars+CFGVARS.bPageSize]
[2]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
[293]313 eMOVZX ax, [g_cfgVars+CFGVARS.bSdpCommand]
314 eMOVZX cx, [g_cfgVars+CFGVARS.bPageSize]
[2]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
[181]373 mov ax, 100
[2]374 je SHORT .FlashComplete
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 stc
385 ret
386
387
388;--------------------------------------------------------------------
389; Processes results from flashing.
390; Computer will be rebooted if PC expansion card BIOS was flashed.
391;
392; FlashMenu_ProcessFlashResults
393; Parameters:
394; AX: Return code from progress bar task function
395; DS:SI Ptr to MENUPAGE
396; DS:DI Ptr to MENUPAGEITEM
397; SS:BP: Ptr to MENUVARS
398; Returns:
399; Nothing
400; Corrupts registers:
401; AX, BX, CX, DX, ES
402;--------------------------------------------------------------------
403ALIGN JUMP_ALIGN
404FlashMenu_ProcessFlashResults:
405 cmp ax, ERR_FLASH_POLL_TIMEOUT
406 je SHORT FlashMenu_PollingTimeoutErrorDuringFlashing
[293]407 call Flash_WasDataWriteSuccessful
[2]408 jne SHORT FlashMenu_DataVerifyErrorAfterFlashing
409 ; Fall to FlashMenu_EepromFlashedSuccessfully
410
411;--------------------------------------------------------------------
412; Computer will be rebooted if PC expansion card BIOS was flashed.
413;
414; FlashMenu_EepromFlashedSuccessfully
415; Parameters:
416; DS:SI Ptr to MENUPAGE
417; DS:DI Ptr to MENUPAGEITEM
418; SS:BP: Ptr to MENUVARS
419; Returns:
420; Nothing
421; Corrupts registers:
422; AX, BX, DX
423;--------------------------------------------------------------------
424FlashMenu_EepromFlashedSuccessfully:
425 cmp WORD [g_cfgVars+CFGVARS.rgbEepromBuffers+ROMVARS.wRomSign], 0AA55h
426 je SHORT .RebootSinceAllDone
427 mov WORD [di+MENUPAGEITEM.szDialog], g_szFlashDoneContinue
428 jmp MenuPageItem_DisplaySpecialFunctionDialog
429ALIGN JUMP_ALIGN
430.RebootSinceAllDone:
431 mov WORD [di+MENUPAGEITEM.szDialog], g_szFlashDoneReboot
432 call MenuPageItem_DisplaySpecialFunctionDialog
433 mov al, 0FEh ; System reset (AT+ keyboard controller)
434 out 64h, al ; Reset computer (AT+)
435 jmp WORD 0F000h:0FFF0h ; Safe reset on XTs only
436
437;--------------------------------------------------------------------
438; Displays flash error messages.
439;
440; FlashMenu_PollingTimeoutErrorDuringFlashing
441; FlashMenu_DataVerifyErrorAfterFlashing
442; Parameters:
443; DS:SI Ptr to MENUPAGE
444; DS:DI Ptr to MENUPAGEITEM
445; SS:BP: Ptr to MENUVARS
446; Returns:
447; Nothing
448; Corrupts registers:
449; AX, BX, DX
450;--------------------------------------------------------------------
451ALIGN JUMP_ALIGN
452FlashMenu_PollingTimeoutErrorDuringFlashing:
453 mov WORD [di+MENUPAGEITEM.szDialog], g_szFlashTimeout
454 jmp MenuPageItem_DisplaySpecialFunctionDialog
455
456ALIGN JUMP_ALIGN
457FlashMenu_DataVerifyErrorAfterFlashing:
458 mov WORD [di+MENUPAGEITEM.szDialog], g_szFlashVerifyErr
459 jmp MenuPageItem_DisplaySpecialFunctionDialog
Note: See TracBrowser for help on using the repository browser.