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

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

Initial commit for Assembly Library.

File size: 4.9 KB
Line 
1; File name : MenuLoop.asm
2; Project name : Assembly Library
3; Created date : 22.7.2010
4; Last update : 16.9.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 test BYTE [bp+MENU.bFlags], FLG_MENU_EXIT
23 jnz SHORT .ExitMenu
24 call IdleTimeProcessing
25
26 call MenuTime_UpdateSelectionTimeout
27 mov ah, MENU_KEY_ENTER ; Fake ENTER to select item
28 jc SHORT .ProcessFakedKeystrokeCausedByTimeout
29
30 call Keyboard_GetKeystrokeToAX
31 jz SHORT MenuLoop_Enter
32.ProcessFakedKeystrokeCausedByTimeout:
33 call ProcessKeystrokeFromAX
34 jmp SHORT MenuLoop_Enter
35
36ALIGN JUMP_ALIGN
37.ExitMenu:
38 jmp MenuEvent_ExitMenu
39
40
41;--------------------------------------------------------------------
42; IdleTimeProcessing
43; Parameters
44; SS:BP: Ptr to MENU
45; Returns:
46; Nothing
47; Corrupts registers:
48; AX, BX, DX
49;--------------------------------------------------------------------
50ALIGN JUMP_ALIGN
51IdleTimeProcessing:
52 jmp MenuEvent_IdleProcessing ; User idle processing
53
54
55;--------------------------------------------------------------------
56; ProcessKeystrokeFromAX
57; Parameters
58; AL: ASCII character
59; AH: BIOS scan code
60; SS:BP: Ptr to MENU
61; Returns:
62; Nothing
63; Corrupts registers:
64; AX, BX, CX, DX, SI, DI
65;--------------------------------------------------------------------
66ALIGN JUMP_ALIGN
67ProcessKeystrokeFromAX:
68 call .ProcessMenuSystemKeystroke
69 jc SHORT .Return
70 jmp MenuEvent_KeyStrokeInAX
71ALIGN JUMP_ALIGN, ret
72.Return:
73 ret
74
75;--------------------------------------------------------------------
76; .ProcessMenuSystemKeystroke
77; Parameters
78; AL: ASCII character
79; AH: BIOS scan code
80; SS:BP: Ptr to MENU
81; Returns:
82; CF: Set if keystroke processed
83; Cleared if keystroke not processed
84; AL: ASCII character (if CF cleared)
85; AH: BIOS scan code (if CF cleared)
86; Corrupts registers:
87; BX, CX, DX, SI, DI
88;--------------------------------------------------------------------
89ALIGN JUMP_ALIGN
90.ProcessMenuSystemKeystroke:
91 cmp ah, MENU_KEY_ESC
92 je SHORT .LeaveMenuWithoutSelectingItem
93 cmp ah, MENU_KEY_ENTER
94 je SHORT .SelectItem
95
96 test BYTE [bp+MENU.bFlags], FLG_MENU_USER_HANDLES_SCROLLING
97 jz SHORT MenuLoop_ProcessScrollingKeysFromAX
98 clc ; Clear CF since keystroke not processed
99 ret
100
101ALIGN JUMP_ALIGN
102.LeaveMenuWithoutSelectingItem:
103 call MenuInit_CloseMenuWindow
104 mov WORD [bp+MENU.wHighlightedItem], NO_ITEM_HIGHLIGHTED
105 stc
106 ret
107
108ALIGN JUMP_ALIGN
109.SelectItem:
110 mov cx, [bp+MENU.wHighlightedItem]
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:
132 cmp ah, MENU_KEY_PGUP
133 je SHORT .ChangeToPreviousPage
134 cmp ah, MENU_KEY_PGDN
135 je SHORT .ChangeToNextPage
136 cmp ah, MENU_KEY_HOME
137 je SHORT .SelectFirstItem
138 cmp ah, MENU_KEY_END
139 je SHORT .SelectLastItem
140
141 cmp ah, MENU_KEY_UP
142 je SHORT .DecrementSelectedItem
143 cmp ah, MENU_KEY_DOWN
144 je SHORT .IncrementSelectedItem
145 clc ; Clear CF since keystroke not processed
146 ret
147
148ALIGN JUMP_ALIGN
149.ChangeToPreviousPage:
150 call MenuScrollbars_GetMaxVisibleItemsOnPageToCX
151 xchg ax, cx
152 neg ax
153 mov cx, [bp+MENU.wHighlightedItem]
154 add cx, ax
155 jge SHORT .MoveHighlightedItemByAX ; No rotation for PgUp
156 ; Fall to .SelectFirstItem
157ALIGN JUMP_ALIGN
158.SelectFirstItem:
159 mov ax, [bp+MENU.wHighlightedItem]
160 neg ax
161 jmp SHORT .MoveHighlightedItemByAX
162
163ALIGN JUMP_ALIGN
164.ChangeToNextPage:
165 call MenuScrollbars_GetMaxVisibleItemsOnPageToCX
166 xchg ax, cx
167 mov cx, [bp+MENU.wHighlightedItem]
168 add cx, ax
169 cmp cx, [bp+MENUINIT.wItems]
170 jb SHORT .MoveHighlightedItemByAX ; No rotation for PgDn
171 ; Fall to .SelectLastItem
172ALIGN JUMP_ALIGN
173.SelectLastItem:
174 mov ax, [bp+MENUINIT.wItems]
175 sub ax, [bp+MENU.wHighlightedItem]
176 dec ax
177 jmp SHORT .MoveHighlightedItemByAX
178
179ALIGN JUMP_ALIGN
180.DecrementSelectedItem:
181 mov ax, -1
182 jmp SHORT .MoveHighlightedItemByAX
183ALIGN JUMP_ALIGN
184.IncrementSelectedItem:
185 mov ax, 1
186ALIGN JUMP_ALIGN
187.MoveHighlightedItemByAX:
188 call MenuScrollbars_MoveHighlightedItemByAX
189 call MenuTime_RestartSelectionTimeout
190 stc
191 ret
Note: See TracBrowser for help on using the repository browser.