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