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

Last change on this file since 59 was 58, checked in by Tomi Tilli, 14 years ago

Changes to Assembly Library:

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