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

Last change on this file since 318 was 181, checked in by krille_n_@…, 13 years ago

Changes to all parts of the project:

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