[41] | 1 | ; File name : MenuLoop.asm
|
---|
| 2 | ; Project name : Assembly Library
|
---|
| 3 | ; Created date : 22.7.2010
|
---|
[52] | 4 | ; Last update : 12.10.2010
|
---|
[41] | 5 | ; Author : Tomi Tilli
|
---|
| 6 | ; Description : Menu loop for waiting keystrokes.
|
---|
| 7 |
|
---|
| 8 | ; Section containing code
|
---|
| 9 | SECTION .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 | ;--------------------------------------------------------------------
|
---|
| 20 | ALIGN JUMP_ALIGN
|
---|
| 21 | MenuLoop_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 |
|
---|
| 36 | ALIGN 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 | ;--------------------------------------------------------------------
|
---|
| 50 | ALIGN JUMP_ALIGN
|
---|
| 51 | IdleTimeProcessing:
|
---|
| 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 | ;--------------------------------------------------------------------
|
---|
| 66 | ALIGN JUMP_ALIGN
|
---|
| 67 | ProcessKeystrokeFromAX:
|
---|
| 68 | call .ProcessMenuSystemKeystroke
|
---|
| 69 | jc SHORT .Return
|
---|
| 70 | jmp MenuEvent_KeyStrokeInAX
|
---|
| 71 | ALIGN 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 | ;--------------------------------------------------------------------
|
---|
| 89 | ALIGN 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 |
|
---|
| 101 | ALIGN JUMP_ALIGN
|
---|
| 102 | .LeaveMenuWithoutSelectingItem:
|
---|
| 103 | call MenuInit_CloseMenuWindow
|
---|
[52] | 104 | mov WORD [bp+MENUINIT.wHighlightedItem], NO_ITEM_HIGHLIGHTED
|
---|
[41] | 105 | stc
|
---|
| 106 | ret
|
---|
| 107 |
|
---|
| 108 | ALIGN JUMP_ALIGN
|
---|
| 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 | ;--------------------------------------------------------------------
|
---|
| 130 | ALIGN JUMP_ALIGN
|
---|
| 131 | MenuLoop_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 |
|
---|
| 148 | ALIGN JUMP_ALIGN
|
---|
| 149 | .ChangeToPreviousPage:
|
---|
| 150 | call MenuScrollbars_GetMaxVisibleItemsOnPageToCX
|
---|
| 151 | xchg ax, cx
|
---|
| 152 | neg ax
|
---|
[52] | 153 | mov cx, [bp+MENUINIT.wHighlightedItem]
|
---|
[41] | 154 | add cx, ax
|
---|
| 155 | jge SHORT .MoveHighlightedItemByAX ; No rotation for PgUp
|
---|
| 156 | ; Fall to .SelectFirstItem
|
---|
| 157 | ALIGN JUMP_ALIGN
|
---|
| 158 | .SelectFirstItem:
|
---|
[52] | 159 | mov ax, [bp+MENUINIT.wHighlightedItem]
|
---|
[41] | 160 | neg ax
|
---|
| 161 | jmp SHORT .MoveHighlightedItemByAX
|
---|
| 162 |
|
---|
| 163 | ALIGN JUMP_ALIGN
|
---|
| 164 | .ChangeToNextPage:
|
---|
| 165 | call MenuScrollbars_GetMaxVisibleItemsOnPageToCX
|
---|
| 166 | xchg ax, cx
|
---|
[52] | 167 | mov cx, [bp+MENUINIT.wHighlightedItem]
|
---|
[41] | 168 | add cx, ax
|
---|
| 169 | cmp cx, [bp+MENUINIT.wItems]
|
---|
| 170 | jb SHORT .MoveHighlightedItemByAX ; No rotation for PgDn
|
---|
| 171 | ; Fall to .SelectLastItem
|
---|
| 172 | ALIGN JUMP_ALIGN
|
---|
| 173 | .SelectLastItem:
|
---|
| 174 | mov ax, [bp+MENUINIT.wItems]
|
---|
[52] | 175 | sub ax, [bp+MENUINIT.wHighlightedItem]
|
---|
[41] | 176 | dec ax
|
---|
| 177 | jmp SHORT .MoveHighlightedItemByAX
|
---|
| 178 |
|
---|
| 179 | ALIGN JUMP_ALIGN
|
---|
| 180 | .DecrementSelectedItem:
|
---|
| 181 | mov ax, -1
|
---|
| 182 | jmp SHORT .MoveHighlightedItemByAX
|
---|
| 183 | ALIGN JUMP_ALIGN
|
---|
| 184 | .IncrementSelectedItem:
|
---|
| 185 | mov ax, 1
|
---|
| 186 | ALIGN JUMP_ALIGN
|
---|
| 187 | .MoveHighlightedItemByAX:
|
---|
| 188 | call MenuScrollbars_MoveHighlightedItemByAX
|
---|
| 189 | call MenuTime_RestartSelectionTimeout
|
---|
| 190 | stc
|
---|
| 191 | ret
|
---|