[41] | 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 | ;--------------------------------------------------------------------
|
---|
[369] | 16 | ALIGN MENU_JUMP_ALIGN
|
---|
[41] | 17 | MenuLoop_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 | ;--------------------------------------------------------------------
|
---|
[369] | 38 | ALIGN MENU_JUMP_ALIGN
|
---|
[105] | 39 | KeystrokeProcessing:
|
---|
| 40 | call Keyboard_GetKeystrokeToAX
|
---|
| 41 | jnz SHORT ProcessKeystrokeFromAX
|
---|
| 42 | NoKeystrokeToProcess:
|
---|
| 43 | ret
|
---|
[41] | 44 |
|
---|
[369] | 45 | ALIGN MENU_JUMP_ALIGN
|
---|
[58] | 46 | TimeoutProcessing:
|
---|
| 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 | ;--------------------------------------------------------------------
|
---|
[369] | 64 | ALIGN MENU_JUMP_ALIGN
|
---|
[41] | 65 | ProcessKeystrokeFromAX:
|
---|
[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 | ;--------------------------------------------------------------------
|
---|
[369] | 87 | ALIGN MENU_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 |
|
---|
[369] | 98 | ALIGN MENU_JUMP_ALIGN
|
---|
[41] | 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 |
|
---|
[369] | 108 | ALIGN MENU_JUMP_ALIGN
|
---|
[41] | 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 | ;--------------------------------------------------------------------
|
---|
[369] | 130 | ALIGN MENU_JUMP_ALIGN
|
---|
[41] | 131 | MenuLoop_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 |
|
---|
[369] | 150 | ALIGN MENU_JUMP_ALIGN
|
---|
[41] | 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
|
---|
[369] | 159 | ALIGN MENU_JUMP_ALIGN
|
---|
[41] | 160 | .SelectFirstItem:
|
---|
[52] | 161 | mov ax, [bp+MENUINIT.wHighlightedItem]
|
---|
[41] | 162 | neg ax
|
---|
| 163 | jmp SHORT .MoveHighlightedItemByAX
|
---|
| 164 |
|
---|
[369] | 165 | ALIGN MENU_JUMP_ALIGN
|
---|
[41] | 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
|
---|
[369] | 174 | ALIGN MENU_JUMP_ALIGN
|
---|
[41] | 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 |
|
---|
[369] | 181 | ALIGN MENU_JUMP_ALIGN
|
---|
[41] | 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
|
---|
[369] | 187 | ALIGN MENU_JUMP_ALIGN
|
---|
[41] | 188 | .MoveHighlightedItemByAX:
|
---|
| 189 | call MenuScrollbars_MoveHighlightedItemByAX
|
---|
| 190 | stc
|
---|
| 191 | ret
|
---|