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