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

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

Changes to Assembly Library:

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