source: xtideuniversalbios/trunk/Assembly_Library/Src/Menu/MenuLoop.asm@ 278

Last change on this file since 278 was 189, checked in by gregli@…, 13 years ago

Additional space optimizations, including making IdleProcessing an option in MENUEVENT. Note the fall-through from one file to another, but that there are assembler checks to ensure the proper linkage is maintained. First version of StringsCompress.pl, a perl script to make StringsCompressed.asm from Strings.asm.

File size: 4.9 KB
RevLine 
[41]1; Project name : Assembly Library
2; Description : Menu loop for waiting keystrokes.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; MenuLoop_Enter
9; Parameters
10; SS:BP: Ptr to MENU
11; Returns:
12; Nothing
13; Corrupts registers:
14; AX, BX, CX, DX, SI, DI
15;--------------------------------------------------------------------
16ALIGN JUMP_ALIGN
17MenuLoop_Enter:
[58]18 call KeystrokeProcessing
19 call TimeoutProcessing
[189]20%ifdef MENUEVENT_IDLEPROCESSING_ENABLE
[105]21 call MenuEvent_IdleProcessing ; User idle processing
[189]22%endif
[41]23 test BYTE [bp+MENU.bFlags], FLG_MENU_EXIT
24 jz SHORT MenuLoop_Enter
[58]25 ret
[41]26
27
28;--------------------------------------------------------------------
[105]29; KeystrokeProcessing
[58]30; TimeoutProcessing
[41]31; Parameters
32; SS:BP: Ptr to MENU
33; Returns:
34; Nothing
35; Corrupts registers:
[58]36; All, except SS:BP
[41]37;--------------------------------------------------------------------
38ALIGN JUMP_ALIGN
[105]39KeystrokeProcessing:
40 call Keyboard_GetKeystrokeToAX
41 jnz SHORT ProcessKeystrokeFromAX
42NoKeystrokeToProcess:
43 ret
[41]44
[58]45ALIGN JUMP_ALIGN
46TimeoutProcessing:
47 call MenuTime_UpdateSelectionTimeout
[105]48 jnc NoKeystrokeToProcess
[178]49 mov al, CR ; Fake ENTER to select item
[105]50 ; Fall to ProcessKeystrokeFromAX
[41]51
[58]52
[41]53;--------------------------------------------------------------------
54; ProcessKeystrokeFromAX
55; Parameters
56; AL: ASCII character
57; AH: BIOS scan code
58; SS:BP: Ptr to MENU
59; Returns:
[133]60; Nothing
[41]61; Corrupts registers:
62; AX, BX, CX, DX, SI, DI
63;--------------------------------------------------------------------
64ALIGN JUMP_ALIGN
65ProcessKeystrokeFromAX:
[60]66 xchg cx, ax
67 call MenuTime_StopSelectionTimeout
68 xchg ax, cx
69 call .ProcessMenuSystemKeystrokeFromAX
[105]70 jc SHORT NoKeystrokeToProcess
[41]71 jmp MenuEvent_KeyStrokeInAX
72
73;--------------------------------------------------------------------
[60]74; .ProcessMenuSystemKeystrokeFromAX
[41]75; Parameters
76; AL: ASCII character
77; AH: BIOS scan code
78; SS:BP: Ptr to MENU
79; Returns:
80; CF: Set if keystroke processed
81; Cleared if keystroke not processed
82; AL: ASCII character (if CF cleared)
83; AH: BIOS scan code (if CF cleared)
84; Corrupts registers:
85; BX, CX, DX, SI, DI
86;--------------------------------------------------------------------
87ALIGN JUMP_ALIGN
[60]88.ProcessMenuSystemKeystrokeFromAX:
[178]89 cmp al, ESC
[41]90 je SHORT .LeaveMenuWithoutSelectingItem
[178]91 cmp al, CR
[41]92 je SHORT .SelectItem
93
94 test BYTE [bp+MENU.bFlags], FLG_MENU_USER_HANDLES_SCROLLING
95 jz SHORT MenuLoop_ProcessScrollingKeysFromAX
[133]96 ret ; Return with CF cleared since keystroke not processed
[41]97
98ALIGN JUMP_ALIGN
99.LeaveMenuWithoutSelectingItem:
[58]100 call MenuEvent_ExitMenu
101 jnc SHORT .CancelMenuExit
[41]102 call MenuInit_CloseMenuWindow
[52]103 mov WORD [bp+MENUINIT.wHighlightedItem], NO_ITEM_HIGHLIGHTED
[58]104.CancelMenuExit:
[41]105 stc
106 ret
107
108ALIGN JUMP_ALIGN
109.SelectItem:
[52]110 mov cx, [bp+MENUINIT.wHighlightedItem]
[41]111 call MenuEvent_ItemSelectedFromCX
112 stc
113 ret
114
115
116;--------------------------------------------------------------------
117; MenuLoop_ProcessScrollingKeysFromAX
118; Parameters
119; AL: ASCII character
120; AH: BIOS scan code
121; SS:BP: Ptr to MENU
122; Returns:
123; CF: Set if keystroke processed
124; Cleared if keystroke not processed
125; AL: ASCII character (if CF cleared)
126; AH: BIOS scan code (if CF cleared)
127; Corrupts registers:
128; BX, CX, DX, SI, DI
129;--------------------------------------------------------------------
130ALIGN JUMP_ALIGN
131MenuLoop_ProcessScrollingKeysFromAX:
[178]132 xchg ah, al
133 cmp al, MENU_KEY_PGUP
[41]134 je SHORT .ChangeToPreviousPage
[178]135 cmp al, MENU_KEY_PGDN
[41]136 je SHORT .ChangeToNextPage
[178]137 cmp al, MENU_KEY_HOME
[41]138 je SHORT .SelectFirstItem
[178]139 cmp al, MENU_KEY_END
[41]140 je SHORT .SelectLastItem
141
[178]142 cmp al, MENU_KEY_UP
[41]143 je SHORT .DecrementSelectedItem
[178]144 cmp al, MENU_KEY_DOWN
[41]145 je SHORT .IncrementSelectedItem
146 clc ; Clear CF since keystroke not processed
[178]147 xchg ah, al
[41]148 ret
149
150ALIGN JUMP_ALIGN
151.ChangeToPreviousPage:
152 call MenuScrollbars_GetMaxVisibleItemsOnPageToCX
153 xchg ax, cx
154 neg ax
[52]155 mov cx, [bp+MENUINIT.wHighlightedItem]
[41]156 add cx, ax
157 jge SHORT .MoveHighlightedItemByAX ; No rotation for PgUp
158 ; Fall to .SelectFirstItem
159ALIGN JUMP_ALIGN
160.SelectFirstItem:
[52]161 mov ax, [bp+MENUINIT.wHighlightedItem]
[41]162 neg ax
163 jmp SHORT .MoveHighlightedItemByAX
164
165ALIGN JUMP_ALIGN
166.ChangeToNextPage:
167 call MenuScrollbars_GetMaxVisibleItemsOnPageToCX
168 xchg ax, cx
[52]169 mov cx, [bp+MENUINIT.wHighlightedItem]
[41]170 add cx, ax
171 cmp cx, [bp+MENUINIT.wItems]
172 jb SHORT .MoveHighlightedItemByAX ; No rotation for PgDn
173 ; Fall to .SelectLastItem
174ALIGN JUMP_ALIGN
175.SelectLastItem:
[178]176 stc
[41]177 mov ax, [bp+MENUINIT.wItems]
[178]178 sbb ax, [bp+MENUINIT.wHighlightedItem]
[41]179 jmp SHORT .MoveHighlightedItemByAX
180
181ALIGN JUMP_ALIGN
182.DecrementSelectedItem:
183 mov ax, -1
[178]184 SKIP2B cx ; mov cx, <next instruction>
[41]185.IncrementSelectedItem:
[178]186 mov al, 1 ; AH is already 0
[41]187ALIGN JUMP_ALIGN
188.MoveHighlightedItemByAX:
189 call MenuScrollbars_MoveHighlightedItemByAX
190 stc
191 ret
Note: See TracBrowser for help on using the repository browser.