source: xtideuniversalbios/trunk/Assembly_Library/Src/Menu/MenuLoop.asm @ 526

Last change on this file since 526 was 526, checked in by krille_n_@…, 11 years ago

Changes:

  • Update of the copyright notices to include the year 2013.
File size: 5.8 KB
RevLine 
[41]1; Project name  :   Assembly Library
2; Description   :   Menu loop for waiting keystrokes.
3
[376]4;
[526]5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[376]7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
[526]12;
[376]13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
[526]16; GNU General Public License for more details.
[376]17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
[526]20
[41]21; Section containing code
22SECTION .text
23
24;--------------------------------------------------------------------
25; MenuLoop_Enter
26;   Parameters
27;       SS:BP:  Ptr to MENU
28;   Returns:
29;       Nothing
30;   Corrupts registers:
31;       AX, BX, CX, DX, SI, DI
32;--------------------------------------------------------------------
[369]33ALIGN MENU_JUMP_ALIGN
[41]34MenuLoop_Enter:
[58]35    call    KeystrokeProcessing
36    call    TimeoutProcessing
[189]37%ifdef MENUEVENT_IDLEPROCESSING_ENABLE
[105]38    call    MenuEvent_IdleProcessing    ; User idle processing
[189]39%endif
[41]40    test    BYTE [bp+MENU.bFlags], FLG_MENU_EXIT
41    jz      SHORT MenuLoop_Enter
[58]42    ret
[41]43
44
45;--------------------------------------------------------------------
[105]46; KeystrokeProcessing
[58]47; TimeoutProcessing
[41]48;   Parameters
49;       SS:BP:  Ptr to MENU
50;   Returns:
51;       Nothing
52;   Corrupts registers:
[58]53;       All, except SS:BP
[41]54;--------------------------------------------------------------------
[369]55ALIGN MENU_JUMP_ALIGN
[105]56KeystrokeProcessing:
57    call    Keyboard_GetKeystrokeToAX
58    jnz     SHORT ProcessKeystrokeFromAX
59NoKeystrokeToProcess:
60    ret
[41]61
[369]62ALIGN MENU_JUMP_ALIGN
[58]63TimeoutProcessing:
64    call    MenuTime_UpdateSelectionTimeout
[105]65    jnc     NoKeystrokeToProcess
[178]66    mov     al, CR  ; Fake ENTER to select item
[105]67    ; Fall to ProcessKeystrokeFromAX
[41]68
[58]69
[41]70;--------------------------------------------------------------------
71; ProcessKeystrokeFromAX
72;   Parameters
73;       AL:     ASCII character
74;       AH:     BIOS scan code
75;       SS:BP:  Ptr to MENU
76;   Returns:
[133]77;       Nothing
[41]78;   Corrupts registers:
79;       AX, BX, CX, DX, SI, DI
80;--------------------------------------------------------------------
[369]81ALIGN MENU_JUMP_ALIGN
[41]82ProcessKeystrokeFromAX:
[60]83    xchg    cx, ax
84    call    MenuTime_StopSelectionTimeout
85    xchg    ax, cx
86    call    .ProcessMenuSystemKeystrokeFromAX
[492]87%ifdef MENUEVENT_KeyStrokeInAX
[105]88    jc      SHORT NoKeystrokeToProcess
[41]89    jmp     MenuEvent_KeyStrokeInAX
[492]90%else
91    jmp     SHORT NoKeystrokeToProcess
92%endif
[526]93
[41]94;--------------------------------------------------------------------
[60]95; .ProcessMenuSystemKeystrokeFromAX
[41]96;   Parameters
97;       AL:     ASCII character
98;       AH:     BIOS scan code
99;       SS:BP:  Ptr to MENU
100;   Returns:
101;       CF:     Set if keystroke processed
102;               Cleared if keystroke not processed
103;       AL:     ASCII character (if CF cleared)
104;       AH:     BIOS scan code (if CF cleared)
105;   Corrupts registers:
106;       BX, CX, DX, SI, DI
107;--------------------------------------------------------------------
[369]108ALIGN MENU_JUMP_ALIGN
[60]109.ProcessMenuSystemKeystrokeFromAX:
[492]110%ifndef MENU_NO_ESC
[178]111    cmp     al, ESC
[41]112    je      SHORT .LeaveMenuWithoutSelectingItem
[492]113%endif
[178]114    cmp     al, CR
[41]115    je      SHORT .SelectItem
116
117    test    BYTE [bp+MENU.bFlags], FLG_MENU_USER_HANDLES_SCROLLING
118    jz      SHORT MenuLoop_ProcessScrollingKeysFromAX
[133]119    ret     ; Return with CF cleared since keystroke not processed
[41]120
[526]121%ifndef MENU_NO_ESC
[369]122ALIGN MENU_JUMP_ALIGN
[41]123.LeaveMenuWithoutSelectingItem:
[58]124    call    MenuEvent_ExitMenu
125    jnc     SHORT .CancelMenuExit
[41]126    call    MenuInit_CloseMenuWindow
[52]127    mov     WORD [bp+MENUINIT.wHighlightedItem], NO_ITEM_HIGHLIGHTED
[58]128.CancelMenuExit:
[41]129    stc
130    ret
[492]131%endif
[526]132
[369]133ALIGN MENU_JUMP_ALIGN
[41]134.SelectItem:
[52]135    mov     cx, [bp+MENUINIT.wHighlightedItem]
[41]136    call    MenuEvent_ItemSelectedFromCX
137    stc
138    ret
139
140
141;--------------------------------------------------------------------
142; MenuLoop_ProcessScrollingKeysFromAX
143;   Parameters
144;       AL:     ASCII character
145;       AH:     BIOS scan code
146;       SS:BP:  Ptr to MENU
147;   Returns:
148;       CF:     Set if keystroke processed
149;               Cleared if keystroke not processed
150;       AL:     ASCII character (if CF cleared)
151;       AH:     BIOS scan code (if CF cleared)
152;   Corrupts registers:
153;       BX, CX, DX, SI, DI
154;--------------------------------------------------------------------
[369]155ALIGN MENU_JUMP_ALIGN
[41]156MenuLoop_ProcessScrollingKeysFromAX:
[178]157    xchg    ah, al
158    cmp     al, MENU_KEY_PGUP
[41]159    je      SHORT .ChangeToPreviousPage
[178]160    cmp     al, MENU_KEY_PGDN
[41]161    je      SHORT .ChangeToNextPage
[178]162    cmp     al, MENU_KEY_HOME
[41]163    je      SHORT .SelectFirstItem
[178]164    cmp     al, MENU_KEY_END
[41]165    je      SHORT .SelectLastItem
166
[178]167    cmp     al, MENU_KEY_UP
[41]168    je      SHORT .DecrementSelectedItem
[178]169    cmp     al, MENU_KEY_DOWN
[41]170    je      SHORT .IncrementSelectedItem
171    clc     ; Clear CF since keystroke not processed
[178]172    xchg    ah, al
[41]173    ret
174
[369]175ALIGN MENU_JUMP_ALIGN
[41]176.ChangeToPreviousPage:
177    call    MenuScrollbars_GetMaxVisibleItemsOnPageToCX
178    xchg    ax, cx
179    neg     ax
[52]180    mov     cx, [bp+MENUINIT.wHighlightedItem]
[41]181    add     cx, ax
182    jge     SHORT .MoveHighlightedItemByAX  ; No rotation for PgUp
183    ; Fall to .SelectFirstItem
[369]184ALIGN MENU_JUMP_ALIGN
[41]185.SelectFirstItem:
[52]186    mov     ax, [bp+MENUINIT.wHighlightedItem]
[41]187    neg     ax
188    jmp     SHORT .MoveHighlightedItemByAX
189
[369]190ALIGN MENU_JUMP_ALIGN
[41]191.ChangeToNextPage:
192    call    MenuScrollbars_GetMaxVisibleItemsOnPageToCX
193    xchg    ax, cx
[52]194    mov     cx, [bp+MENUINIT.wHighlightedItem]
[41]195    add     cx, ax
196    cmp     cx, [bp+MENUINIT.wItems]
197    jb      SHORT .MoveHighlightedItemByAX  ; No rotation for PgDn
198    ; Fall to .SelectLastItem
[369]199ALIGN MENU_JUMP_ALIGN
[41]200.SelectLastItem:
[178]201    stc
[41]202    mov     ax, [bp+MENUINIT.wItems]
[178]203    sbb     ax, [bp+MENUINIT.wHighlightedItem]
[41]204    jmp     SHORT .MoveHighlightedItemByAX
205
[369]206ALIGN MENU_JUMP_ALIGN
[41]207.DecrementSelectedItem:
208    mov     ax, -1
[178]209    SKIP2B  cx  ; mov cx, <next instruction>
[41]210.IncrementSelectedItem:
[178]211    mov     al, 1   ; AH is already 0
[369]212ALIGN MENU_JUMP_ALIGN
[41]213.MoveHighlightedItemByAX:
214    call    MenuScrollbars_MoveHighlightedItemByAX
215    stc
216    ret
Note: See TracBrowser for help on using the repository browser.