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

Last change on this file since 51 was 50, checked in by Tomi Tilli, 14 years ago

Changes to Assembly Library:
Removed Memory_ExchangeSSBPwithESDI since it obviously corrupted stack.
CGA detection is now only done once when initializing Display Context.
Moved File Library defines to File.inc.

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 : 9.10.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+MENU.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; Parameters:
66; SS:BP: Ptr to DIALOG
67; Returns:
68; CF: Set since event processed
69; Corrupts registers:
70; Nothing
71;--------------------------------------------------------------------
72ALIGN JUMP_ALIGN
73Dialog_EventAnyThatClosesDialog:
74 call MenuInit_CloseMenuWindow
75 stc
76 ret
77
78
79;--------------------------------------------------------------------
80; Dialog_EventInitializeMenuinitFromDSSIforSingleItem
81; Parameters:
82; DS:SI: Ptr to MENUINIT struct to initialize
83; SS:BP: Ptr to DIALOG
84; Returns:
85; DS:SI: Ptr to initialized MENUINIT struct
86; CF: Set since event processed
87;--------------------------------------------------------------------
88ALIGN JUMP_ALIGN
89Dialog_EventInitializeMenuinitFromDSSIforSingleItem:
90 les di, [bp+DIALOG.fpDialogIO]
91 mov WORD [es:di+DIALOG_INPUT.fszItems], g_szSingleItem
92 mov [es:di+DIALOG_INPUT.fszItems+2], cs
93 ; Fall to Dialog_EventInitializeMenuinitFromDSSI
94
95;--------------------------------------------------------------------
96; Dialog_EventInitializeMenuinitFromDSSI
97; Parameters:
98; DS:SI: Ptr to MENUINIT struct to initialize
99; SS:BP: Ptr to DIALOG
100; Returns:
101; DS:SI: Ptr to initialized MENUINIT struct
102; CF: Set since event processed
103;--------------------------------------------------------------------
104ALIGN JUMP_ALIGN
105Dialog_EventInitializeMenuinitFromDSSI:
106 les di, [bp+DIALOG.fpDialogIO]
107 call .GetWidthBasedOnParentMenuToAL
108 mov [bp+MENUINIT.bWidth], al
109
110 call MenuLocation_GetMaxTextLineLengthToAX
111 mov bx, ax
112 lds si, [es:di+DIALOG_INPUT.fszTitle]
113 call LineSplitter_SplitStringFromDSSIwithMaxLineLengthInAXandGetLineCountToAX
114 mov [bp+MENUINIT.bTitleLines], al
115
116 mov ax, bx
117 lds si, [es:di+DIALOG_INPUT.fszItems]
118 call LineSplitter_SplitStringFromDSSIwithMaxLineLengthInAXandGetLineCountToAX
119 mov [bp+MENUINIT.wItems], ax
120
121 xchg ax, bx
122 lds si, [es:di+DIALOG_INPUT.fszInfo]
123 call LineSplitter_SplitStringFromDSSIwithMaxLineLengthInAXandGetLineCountToAX
124 mov [bp+MENUINIT.bInfoLines], al
125
126 call .GetHeightToAH ; Line counts are required
127 mov [bp+MENUINIT.bHeight], ah
128 stc
129 ret
130
131;--------------------------------------------------------------------
132; .GetWidthBasedOnParentMenuToAL
133; Parameters:
134; SS:BP: Ptr to DIALOG
135; Returns:
136; AX: Width for dialog
137; Corrupts registers:
138; BX
139;--------------------------------------------------------------------
140ALIGN JUMP_ALIGN
141.GetWidthBasedOnParentMenuToAL:
142 mov bx, [bp+DIALOG.pParentMenu]
143 mov al, [ss:bx+MENUINIT.bWidth]
144 sub al, DIALOG_DELTA_WIDTH_FROM_PARENT
145 MIN_U al, DIALOG_MAX_WIDTH
146 ret
147
148;--------------------------------------------------------------------
149; .GetHeightToAH
150; Parameters:
151; SS:BP: Ptr to DIALOG
152; Returns:
153; AH: Height for dialog
154; Corrupts registers:
155; AL, BX, DI
156;--------------------------------------------------------------------
157ALIGN JUMP_ALIGN
158.GetHeightToAH:
159 CALL_DISPLAY_LIBRARY GetColumnsToALandRowsToAH
160 xchg bx, ax
161 mov ah, [bp+MENUINIT.bTitleLines]
162 add ah, [bp+MENUINIT.wItems]
163 add ah, [bp+MENUINIT.bInfoLines]
164 add ah, BYTE MENU_VERTICAL_BORDER_LINES
165 MIN_U ah, bh
166 MIN_U ah, DIALOG_MAX_HEIGHT
167 ret
168
169
170;--------------------------------------------------------------------
171; Dialog_EventRefreshTitle
172; Dialog_EventRefreshInformation
173; Parameters:
174; SS:BP: Ptr to DIALOG
175; Returns:
176; CF: Set since event processed
177;--------------------------------------------------------------------
178ALIGN JUMP_ALIGN
179Dialog_EventRefreshTitle:
180 mov dl, [bp+MENUINIT.bTitleLines]
181 lds si, [bp+DIALOG.fpDialogIO]
182 les di, [si+DIALOG_INPUT.fszTitle]
183 jmp SHORT PrintDLlinesFromESDI
184
185ALIGN JUMP_ALIGN
186Dialog_EventRefreshInformation:
187 mov dl, [bp+MENUINIT.bInfoLines]
188 lds si, [bp+DIALOG.fpDialogIO]
189 les di, [si+DIALOG_INPUT.fszInfo]
190 ; Fall to PrintDLlinesFromESDI
191
192ALIGN JUMP_ALIGN
193PrintDLlinesFromESDI:
194 xor cx, cx ; Start from line zero
195 mov dh, cl ; Line count now in DX
196ALIGN JUMP_ALIGN
197.PrintNextLine:
198 call LineSplitter_PrintLineInCXfromStringInESDI
199 push di
200 CALL_DISPLAY_LIBRARY PrintNewlineCharacters
201 pop di
202 inc cx
203 dec dx
204 jnz SHORT .PrintNextLine
205 stc
206 ret
207
208
209;--------------------------------------------------------------------
210; Dialog_EventRefreshItemFromCX
211; Parameters:
212; CX: Item to refresh
213; SS:BP: Ptr to DIALOG
214; Returns:
215; CF: Set since event processed
216;--------------------------------------------------------------------
217ALIGN JUMP_ALIGN
218Dialog_EventRefreshItemFromCX:
219 lds si, [bp+DIALOG.fpDialogIO]
220 les di, [si+DIALOG_INPUT.fszItems]
221 call LineSplitter_PrintLineInCXfromStringInESDI
222 stc
223 ret
224
225
226;--------------------------------------------------------------------
227; Dialog_RemoveFromScreenByRedrawingParentMenu
228; Parameters:
229; SS:BP: Ptr to DIALOG
230; Returns:
231; Nothing
232; Corrupts:
233; AX, BX, CX, DX, SI, DI
234;--------------------------------------------------------------------
235ALIGN JUMP_ALIGN
236Dialog_RemoveFromScreenByRedrawingParentMenu:
237 mov si, [bp+DIALOG.pParentMenu] ; SS:SI points to parent MENU
238 call .ResetSelectionTimeoutFromParentMenuInSSSI
239 call .GetParentTitleBorderCoordinatesToDX
240 call MenuLocation_GetTitleBordersTopLeftCoordinatesToAX
241 cmp ah, dh ; Dialog taller than parent?
242 jb SHORT .RedrawDialogAreaAndWholeParentWindow
243 jmp SHORT .RedrawWholeParentWindow
244
245;--------------------------------------------------------------------
246; .ResetSelectionTimeoutFromParentMenuInSSSI
247; Parameters:
248; SS:SI: Ptr to parent MENU
249; Returns:
250; Nothing
251; Corrupts:
252; AX, BX
253;--------------------------------------------------------------------
254ALIGN JUMP_ALIGN
255.ResetSelectionTimeoutFromParentMenuInSSSI:
256 xchg bp, si
257 call MenuTime_RestartSelectionTimeout ; Restart timeout for parent MENU
258 xchg si, bp
259 ret
260
261;--------------------------------------------------------------------
262; .GetParentTitleBorderCoordinatesToDX
263; Parameters:
264; SS:SI: Ptr to parent MENU
265; SS:BP: Ptr to DIALOG
266; Returns:
267; DL: Parent border column (X)
268; DH: Parent border row (Y)
269; Corrupts:
270; AX
271;--------------------------------------------------------------------
272ALIGN JUMP_ALIGN
273.GetParentTitleBorderCoordinatesToDX:
274 xchg si, bp
275 call MenuLocation_GetTitleBordersTopLeftCoordinatesToAX
276 xchg bp, si
277 xchg dx, ax
278 ret
279
280;--------------------------------------------------------------------
281; .RedrawDialogAreaAndWholeParentWindow
282; .RedrawWholeParentWindow
283; Parameters:
284; SS:SI: Ptr to parent MENU
285; SS:BP: Ptr to DIALOG
286; Returns:
287; Nothing
288; Corrupts:
289; AX, BX, CX, DX, SI, DI
290;--------------------------------------------------------------------
291ALIGN JUMP_ALIGN
292.RedrawDialogAreaAndWholeParentWindow:
293 push si
294 call MenuBorders_AdjustDisplayContextForDrawingBorders
295 pop si
296 mov al, SCREEN_BACKGROUND_ATTRIBUTE
297 CALL_DISPLAY_LIBRARY SetCharacterAttributeFromAL
298 mov ax, [bp+MENUINIT.wWidthAndHeight]
299 CALL_DISPLAY_LIBRARY ClearAreaWithHeightInAHandWidthInAL
300 ; Fall to .RedrawWholeParentWindow
301
302ALIGN JUMP_ALIGN
303.RedrawWholeParentWindow:
304 push bp
305 mov bp, si
306 call MenuInit_RefreshMenuWindow
307 pop bp
308 ret
Note: See TracBrowser for help on using the repository browser.