source: xtideuniversalbios/trunk/Assembly_Library/Src/Menu/Dialog/Dialog.asm @ 58

Last change on this file since 58 was 58, checked in by aitotat, 13 years ago

Changes to Assembly Library:

  • Exiting menu with ESC can now be canceled.
File size: 8.7 KB
Line 
1; File name     :   Dialog.asm
2; Project name  :   Assembly Library
3; Created date  :   6.8.2010
4; Last update   :   18.11.2010
5; Author        :   Tomi Tilli
6; Description   :   Common functions for many dialogs.
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; Dialog_DisplayWithDialogInputInDSSIandHandlerInBX
13;   Parameters:
14;       BX:     Offset to menu event handler
15;       DX:AX:  Optional user data
16;       DS:SI:  Ptr to DIALOG_INPUT
17;       SS:BP:  Ptr to parent MENU
18;   Returns:
19;       AX:     Selected item
20;   Corrupts registers:
21;       BX, CX, DX, SI, DI
22;--------------------------------------------------------------------
23ALIGN JUMP_ALIGN
24Dialog_DisplayWithDialogInputInDSSIandHandlerInBX:
25    push    es
26    push    ds
27    mov     di, bp                              ; Backup parent MENU
28    mov     cx, DIALOG_size
29    eENTER_STRUCT cx
30
31    call    Memory_ZeroSSBPwithSizeInCX
32    mov     [bp+DIALOG.fpDialogIO], si
33    mov     [bp+DIALOG.fpDialogIO+2], ds
34    mov     [bp+DIALOG.pParentMenu], di
35
36    call    MenuInit_EnterMenuWithHandlerInBXandUserDataInDXAX
37    call    Dialog_RemoveFromScreenByRedrawingParentMenu
38    call    Keyboard_RemoveAllKeystrokesFromBuffer
39
40    mov     ax, [bp+MENUINIT.wHighlightedItem]
41    eLEAVE_STRUCT DIALOG_size
42    pop     ds
43    pop     es
44    ret
45
46
47;--------------------------------------------------------------------
48; Dialog_EventNotHandled
49;   Parameters:
50;       BX:     Menu event (anything from MENUEVENT struct)
51;       SS:BP:  Ptr to DIALOG
52;   Returns:
53;       CF:     Cleared since event not processed
54;   Corrupts registers:
55;       Nothing
56;--------------------------------------------------------------------
57ALIGN JUMP_ALIGN
58Dialog_EventNotHandled:
59    clc
60    ret
61
62
63;--------------------------------------------------------------------
64; Dialog_EventAnyThatClosesDialog
65; Dialog_EventExitMenu
66;   Parameters:
67;       SS:BP:  Ptr to DIALOG
68;   Returns:
69;       CF:     Set since event processed
70;   Corrupts registers:
71;       Nothing
72;--------------------------------------------------------------------
73ALIGN JUMP_ALIGN
74Dialog_EventAnyThatClosesDialog:
75    call    MenuInit_CloseMenuWindow
76ALIGN JUMP_ALIGN
77Dialog_EventExitMenu:
78    stc
79    ret
80
81
82;--------------------------------------------------------------------
83; Dialog_EventInitializeMenuinitFromDSSIforSingleItemWithHighlightedItemInAX
84;   Parameters:
85;       AX:         Index of highlighted item
86;       DS:SI:      Ptr to MENUINIT struct to initialize
87;       SS:BP:      Ptr to DIALOG
88;   Returns:
89;       DS:SI:      Ptr to initialized MENUINIT struct
90;       CF:         Set since event processed
91;--------------------------------------------------------------------
92ALIGN JUMP_ALIGN
93Dialog_EventInitializeMenuinitFromDSSIforSingleItemWithHighlightedItemInAX:
94    les     di, [bp+DIALOG.fpDialogIO]
95    mov     WORD [es:di+DIALOG_INPUT.fszItems], g_szSingleItem
96    mov     [es:di+DIALOG_INPUT.fszItems+2], cs
97    ; Fall to Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX
98
99;--------------------------------------------------------------------
100; Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX
101;   Parameters:
102;       AX:         Index of highlighted item
103;       DS:SI:      Ptr to MENUINIT struct to initialize
104;       SS:BP:      Ptr to DIALOG
105;   Returns:
106;       DS:SI:      Ptr to initialized MENUINIT struct
107;       CF:         Set since event processed
108;--------------------------------------------------------------------
109ALIGN JUMP_ALIGN
110Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX:
111    mov     [bp+MENUINIT.wHighlightedItem], ax
112    les     di, [bp+DIALOG.fpDialogIO]
113    call    .GetWidthBasedOnParentMenuToAL
114    mov     [bp+MENUINIT.bWidth], al
115
116    lds     si, [es:di+DIALOG_INPUT.fszTitle]
117    call    ItemLineSplitter_GetLinesToAXforStringInDSSI
118    mov     [bp+MENUINIT.bTitleLines], al
119
120    lds     si, [es:di+DIALOG_INPUT.fszItems]
121    call    ItemLineSplitter_GetLinesToAXforStringInDSSI
122    mov     [bp+MENUINIT.wItems], ax
123
124    lds     si, [es:di+DIALOG_INPUT.fszInfo]
125    call    ItemLineSplitter_GetLinesToAXforStringInDSSI
126    mov     [bp+MENUINIT.bInfoLines], al
127
128    call    .GetHeightToAH              ; Line counts are required
129    mov     [bp+MENUINIT.bHeight], ah
130    stc
131    ret
132
133;--------------------------------------------------------------------
134; .GetWidthBasedOnParentMenuToAL
135;   Parameters:
136;       SS:BP:  Ptr to DIALOG
137;   Returns:
138;       AX:     Width for dialog
139;   Corrupts registers:
140;       BX
141;--------------------------------------------------------------------
142ALIGN JUMP_ALIGN
143.GetWidthBasedOnParentMenuToAL:
144    mov     bx, [bp+DIALOG.pParentMenu]
145    mov     al, [ss:bx+MENUINIT.bWidth]
146    sub     al, DIALOG_DELTA_WIDTH_FROM_PARENT
147    MIN_U   al, DIALOG_MAX_WIDTH
148    ret
149
150;--------------------------------------------------------------------
151; .GetHeightToAH
152;   Parameters:
153;       SS:BP:  Ptr to DIALOG
154;   Returns:
155;       AH:     Height for dialog
156;   Corrupts registers:
157;       AL, BX, DI
158;--------------------------------------------------------------------
159ALIGN JUMP_ALIGN
160.GetHeightToAH:
161    CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH
162    xchg    bx, ax
163    mov     ah, [bp+MENUINIT.bTitleLines]
164    add     ah, [bp+MENUINIT.wItems]
165    add     ah, [bp+MENUINIT.bInfoLines]
166    add     ah, BYTE MENU_VERTICAL_BORDER_LINES
167    MIN_U   ah, bh
168    MIN_U   ah, DIALOG_MAX_HEIGHT
169    ret
170
171
172;--------------------------------------------------------------------
173; Dialog_EventRefreshTitle
174; Dialog_EventRefreshInformation
175;   Parameters:
176;       SS:BP:      Ptr to DIALOG
177;   Returns:
178;       CF:         Set since event processed
179;--------------------------------------------------------------------
180ALIGN JUMP_ALIGN
181Dialog_EventRefreshTitle:
182    lds     si, [bp+DIALOG.fpDialogIO]
183    lds     si, [si+DIALOG_INPUT.fszTitle]
184    jmp     SHORT PrintTitleOrInfoLine
185
186ALIGN JUMP_ALIGN
187Dialog_EventRefreshInformation:
188    lds     si, [bp+DIALOG.fpDialogIO]
189    lds     si, [si+DIALOG_INPUT.fszInfo]
190    ; Fall to PrintTitleOrInfoLine
191
192ALIGN JUMP_ALIGN
193PrintTitleOrInfoLine:
194    mov     bx, ds
195    CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromBXSI
196    stc
197    ret
198
199
200;--------------------------------------------------------------------
201; Dialog_EventRefreshItemFromCX
202;   Parameters:
203;       CX:         Item to refresh
204;       SS:BP:      Ptr to DIALOG
205;   Returns:
206;       CF:         Set since event processed
207;--------------------------------------------------------------------
208ALIGN JUMP_ALIGN
209Dialog_EventRefreshItemFromCX:
210    lds     si, [bp+DIALOG.fpDialogIO]
211    lds     si, [si+DIALOG_INPUT.fszItems]
212    call    ItemLineSplitter_GetLineToDSSIandLengthToCXfromStringInDSSIwithIndexInCX
213    jnc     SHORT .LineNotFound
214
215    mov     bx, ds
216    CALL_DISPLAY_LIBRARY PrintCharBufferFromBXSIwithLengthInCX
217.LineNotFound:
218    stc
219    ret
220
221
222;--------------------------------------------------------------------
223; Dialog_RemoveFromScreenByRedrawingParentMenu
224;   Parameters:
225;       SS:BP:  Ptr to DIALOG
226;   Returns:
227;       Nothing
228;   Corrupts:
229;       AX, BX, CX, DX, SI, DI
230;--------------------------------------------------------------------
231ALIGN JUMP_ALIGN
232Dialog_RemoveFromScreenByRedrawingParentMenu:
233    mov     si, [bp+DIALOG.pParentMenu] ; SS:SI points to parent MENU
234    call    .ResetSelectionTimeoutFromParentMenuInSSSI
235    call    .GetParentTitleBorderCoordinatesToDX
236    call    MenuLocation_GetTitleBordersTopLeftCoordinatesToAX
237    cmp     ah, dh      ; Dialog taller than parent?
238    jb      SHORT .RedrawDialogAreaAndWholeParentWindow
239    jmp     SHORT .RedrawWholeParentWindow
240
241;--------------------------------------------------------------------
242; .ResetSelectionTimeoutFromParentMenuInSSSI
243;   Parameters:
244;       SS:SI:  Ptr to parent MENU
245;   Returns:
246;       Nothing
247;   Corrupts:
248;       AX, BX
249;--------------------------------------------------------------------
250ALIGN JUMP_ALIGN
251.ResetSelectionTimeoutFromParentMenuInSSSI:
252    xchg    bp, si
253    call    MenuTime_RestartSelectionTimeout    ; Restart timeout for parent MENU
254    xchg    si, bp
255    ret
256
257;--------------------------------------------------------------------
258; .GetParentTitleBorderCoordinatesToDX
259;   Parameters:
260;       SS:SI:  Ptr to parent MENU
261;       SS:BP:  Ptr to DIALOG
262;   Returns:
263;       DL:     Parent border column (X)
264;       DH:     Parent border row (Y)
265;   Corrupts:
266;       AX
267;--------------------------------------------------------------------
268ALIGN JUMP_ALIGN
269.GetParentTitleBorderCoordinatesToDX:
270    xchg    si, bp
271    call    MenuLocation_GetTitleBordersTopLeftCoordinatesToAX
272    xchg    bp, si
273    xchg    dx, ax
274    ret
275
276;--------------------------------------------------------------------
277; .RedrawDialogAreaAndWholeParentWindow
278; .RedrawWholeParentWindow
279;   Parameters:
280;       SS:SI:  Ptr to parent MENU
281;       SS:BP:  Ptr to DIALOG
282;   Returns:
283;       Nothing
284;   Corrupts:
285;       AX, BX, CX, DX, SI, DI
286;--------------------------------------------------------------------
287ALIGN JUMP_ALIGN
288.RedrawDialogAreaAndWholeParentWindow:
289    push    si
290    call    MenuBorders_AdjustDisplayContextForDrawingBorders
291    pop     si
292    mov     al, SCREEN_BACKGROUND_ATTRIBUTE
293    CALL_DISPLAY_LIBRARY SetCharacterAttributeFromAL
294    mov     ax, [bp+MENUINIT.wWidthAndHeight]
295    CALL_DISPLAY_LIBRARY ClearAreaWithHeightInAHandWidthInAL
296    ; Fall to .RedrawWholeParentWindow
297
298ALIGN JUMP_ALIGN
299.RedrawWholeParentWindow:
300    push    bp
301    mov     bp, si
302    call    MenuInit_RefreshMenuWindow
303    pop     bp
304    ret
Note: See TracBrowser for help on using the repository browser.