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
RevLine 
[41]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
[50]24 mov cx, DIALOG_size
25 eENTER_STRUCT cx
[41]26
[46]27 call Memory_ZeroSSBPwithSizeInCX
[41]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
[52]36 mov ax, [bp+MENUINIT.wHighlightedItem]
[41]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
[58]61; Dialog_EventExitMenu
[41]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
[58]72ALIGN JUMP_ALIGN
73Dialog_EventExitMenu:
[41]74 stc
75 ret
76
77
78;--------------------------------------------------------------------
[52]79; Dialog_EventInitializeMenuinitFromDSSIforSingleItemWithHighlightedItemInAX
[41]80; Parameters:
[52]81; AX: Index of highlighted item
[41]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
[52]89Dialog_EventInitializeMenuinitFromDSSIforSingleItemWithHighlightedItemInAX:
[41]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
[52]93 ; Fall to Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX
[41]94
95;--------------------------------------------------------------------
[52]96; Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX
[41]97; Parameters:
[52]98; AX: Index of highlighted item
[41]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
[52]106Dialog_EventInitializeMenuinitFromDSSIwithHighlightedItemInAX:
107 mov [bp+MENUINIT.wHighlightedItem], ax
[41]108 les di, [bp+DIALOG.fpDialogIO]
109 call .GetWidthBasedOnParentMenuToAL
110 mov [bp+MENUINIT.bWidth], al
111
112 lds si, [es:di+DIALOG_INPUT.fszTitle]
[52]113 call ItemLineSplitter_GetLinesToAXforStringInDSSI
[41]114 mov [bp+MENUINIT.bTitleLines], al
115
116 lds si, [es:di+DIALOG_INPUT.fszItems]
[52]117 call ItemLineSplitter_GetLinesToAXforStringInDSSI
[41]118 mov [bp+MENUINIT.wItems], ax
119
120 lds si, [es:di+DIALOG_INPUT.fszInfo]
[52]121 call ItemLineSplitter_GetLinesToAXforStringInDSSI
[41]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
[181]129
[41]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
[181]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:
[41]149 ret
150
[181]151
[41]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
[181]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:
[41]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]
[52]193 lds si, [si+DIALOG_INPUT.fszTitle]
194 jmp SHORT PrintTitleOrInfoLine
[41]195
196ALIGN JUMP_ALIGN
197Dialog_EventRefreshInformation:
198 lds si, [bp+DIALOG.fpDialogIO]
[52]199 lds si, [si+DIALOG_INPUT.fszInfo]
200 ; Fall to PrintTitleOrInfoLine
[41]201
202ALIGN JUMP_ALIGN
[52]203PrintTitleOrInfoLine:
204 mov bx, ds
205 CALL_DISPLAY_LIBRARY PrintNullTerminatedStringFromBXSI
[41]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]
[52]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:
[41]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?
[162]247 jnb SHORT .RedrawWholeParentWindow
248 ; Fall to .RedrawDialogAreaAndWholeParentWindow
[41]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:
[48]262 push si
263 call MenuBorders_AdjustDisplayContextForDrawingBorders
264 pop si
[44]265 mov al, SCREEN_BACKGROUND_ATTRIBUTE
[41]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
[162]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.