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