source: xtideuniversalbios/trunk/Configurator/Src/Libraries/menu/menudlg.asm @ 2

Last change on this file since 2 was 2, checked in by aitotat, 14 years ago
File size: 7.1 KB
Line 
1; File name     :   menudlg.asm
2; Project name  :   Menu library
3; Created date  :   17.11.2009
4; Last update   :   4.12.2009
5; Author        :   Tomi Tilli
6; Description   :   ASM library to menu system.
7;                   Contains functions for displaying input dialogs.
8
9;--------------- Equates -----------------------------
10
11; Dialog init and return variables.
12; This is an expanded MSGVARS struct.
13struc DLGVARS
14    .msgVars    resb    MSGVARS_size
15
16    ; Dialog parameters for different dialogs
17    .wCXPrm:   
18    .wPrmBase:              ; Numeric base for DWORD dialog (10=dec, 16=hex...)
19    .wBuffLen   resb    2   ; Buffer length for string dialog (with STOP included)
20    .dwBuffPtr  resb    4   ; Far pointer to buffer to receive string
21
22    ; Return variables for different dialogs
23    .dwReturn:
24    .dwRetDW:               ; DWORD inputted by user
25    .wRetLen    resb    4   ; Length of string inputted by user (chars without STOP)
26    .fSuccess   resb    1   ; Was data inputted successfully by user
27                resb    1   ; Alignment
28endstruc
29
30
31;-------------- Private global variables -------------
32; Section containing initialized data
33;SECTION .data
34
35g_strYN:    db  "Y/N: ",STOP    ; For asking Y/N input
36
37
38;-------------- Public functions ---------------------
39; Section containing code
40SECTION .text
41
42;--------------------------------------------------------------------
43; Displays dialog.
44;
45; MenuDlg_Show
46;   Parameters:
47;       BL:     Dialog width with borders included
48;       CX:     Word parameter for dialog event handler
49;       DX:     Offset to dialog event handler
50;       SS:BP:  Ptr to MENUVARS
51;       DS:SI   Pointer parameter for dialog event handler
52;       ES:DI:  Ptr to STOP terminated string to display
53;   Returns:
54;       DX:AX:  User inputted data
55;       CF:     Set if user data inputted successfully
56;               Cleared is input cancelled
57;   Corrupts registers:
58;       BX, CX
59;--------------------------------------------------------------------
60ALIGN JUMP_ALIGN
61MenuDlg_Show:
62    ; Create stack frame
63    eENTER  DLGVARS_size, 0
64    sub     bp, DLGVARS_size                ; Point to DLGVARS
65
66    ; Initialize menu variables
67    mov     [bp+MENUVARS.bWidth], bl        ; Menu width
68    mov     WORD [bp+MENUVARS.wTopDwnH], 0100h  ; Title and Info size
69    mov     [bp+MENUVARS.fnEvent], dx       ; Store handler offset
70    mov     [bp+MSGVARS.wStrOff], di        ; Store far ptr...
71    mov     [bp+MSGVARS.wStrSeg], es        ; ...to string to display
72    mov     [bp+DLGVARS.wCXPrm], cx         ; Store word parameter
73    mov     [bp+DLGVARS.dwBuffPtr], si      ; Store far pointer...
74    mov     [bp+DLGVARS.dwBuffPtr+2], ds    ; ...parameter
75
76    ; Enter menu
77    call    MenuMsg_GetLineCnt              ; Get message line count to CX
78    mov     ax, CNT_SCRN_ROW-4              ; Load max line count without borders and info
79    MIN_U   ax, cx                          ; String lines to display to AX
80    add     al, 4                           ; Add borders for dlg height
81    mov     [bp+MENUVARS.bHeight], al       ; Store dialog height
82    call    MenuCrsr_GetCenter              ; Get X and Y coordinates to DX
83    xor     ax, ax                          ; Selection timeout (disable)
84    mov     bl, FLG_MNU_NOARRW              ; Menu flags
85    call    Menu_Init                       ; Returns only after dlg closed
86    call    MenuCrsr_Hide                   ; Hide cursor again
87
88    ; Return
89    mov     ax, [bp+DLGVARS.dwReturn]       ; Load return loword
90    mov     dx, [bp+DLGVARS.dwReturn+2]     ; Load return hiword
91    mov     bl, [bp+DLGVARS.fSuccess]       ; Load success flag
92    add     bp, DLGVARS_size                ; Point to old BP
93    eLEAVE                                  ; Destroy stack frame
94    rcr     bl, 1                           ; Move success flag to CF
95    ret
96
97
98;-------------- Private functions ---------------------
99
100;--------------------------------------------------------------------
101; DWORD input dialog event handler.
102;
103; MenuDlg_DWEvent
104;   Parameters:
105;       BX:     Callback event
106;       CX:     Selected menuitem index
107;       DX:     Event parameter (event specific)
108;       SS:BP:  Ptr to DLGVARS
109;   Returns:
110;       AH:     Event specific or unused
111;       AL:     1=Event processed
112;               0=Event not processed (default action if any)
113;   Corrupts registers:
114;       BX, CX, DX
115;--------------------------------------------------------------------
116ALIGN JUMP_ALIGN
117MenuDlg_DWEvent:
118    cmp     bx, EVNT_MNU_UPD            ; Update strings?
119    jne     MenuDlg_JmpToMsgEvnt        ;  If not, use message handler
120    test    dl, MFL_UPD_NFO             ; Update info strings?
121    jz      MenuDlg_JmpToMsgEvnt        ;  If not, use message handler
122
123    ; Get user input instead of drawing info strings
124    call    MenuCrsr_Show               ; Show cursor during input
125    mov     cx, [bp+DLGVARS.wPrmBase]   ; Load numeric base to CX
126    eMOVZX  dx, [bp+MENUVARS.bWidth]    ; Load dialog width
127    sub     dx, 4                       ; Subtract borders for max char count
128    call    Keys_PrintGetUint           ; Get DWORD
129    mov     [bp+DLGVARS.dwRetDW], ax    ; Store return loword
130    mov     [bp+DLGVARS.dwRetDW+2], dx  ; Store return hiword
131    rcl     BYTE [bp+DLGVARS.fSuccess], 1   ; Set or clear success flag
132
133    ; Exit menu
134ALIGN JUMP_ALIGN
135MenuDlg_ExitHandler:
136    or      BYTE [bp+MENUVARS.bFlags], FLG_MNU_EXIT
137    mov     ax, 1
138    ret
139
140ALIGN JUMP_ALIGN
141MenuDlg_JmpToMsgEvnt:
142    jmp     MenuMsg_MsgEvent
143
144
145;--------------------------------------------------------------------
146; Y/N dialog event handler.
147;
148; MenuDlg_YNEvent
149;   Parameters:
150;       BX:     Callback event
151;       CX:     Selected menuitem index
152;       DX:     Event parameter (event specific)
153;       SS:BP:  Ptr to DLGVARS
154;   Returns:
155;       AH:     Event specific or unused
156;       AL:     1=Event processed
157;               0=Event not processed (default action if any)
158;   Corrupts registers:
159;       BX, CX, DX
160;--------------------------------------------------------------------
161ALIGN JUMP_ALIGN
162MenuDlg_YNEvent:
163    cmp     bx, EVNT_MNU_UPD            ; Update strings?
164    jne     MenuDlg_JmpToMsgEvnt        ;  If not, use message handler
165    test    dl, MFL_UPD_NFO             ; Update info strings?
166    jz      MenuDlg_JmpToMsgEvnt        ;  If not, use message handler
167
168    ; Draw info string
169    push    ds
170    push    cs
171    pop     ds
172    mov     dx, g_strYN                 ; Y/N string in DS:DX
173    PRINT_STR
174    pop     ds
175
176    ; Wait for user input
177    call    MenuCrsr_Show               ; Show cursor during input
178    call    Keys_PrintGetYN
179    mov     [bp+DLGVARS.dwReturn], ax       ; Store return char
180    rcl     BYTE [bp+DLGVARS.fSuccess], 1   ; Set or clear Y/N flag
181    jmp     MenuDlg_ExitHandler
182
183
184;--------------------------------------------------------------------
185; String dialog event handler.
186;
187; MenuDlg_StrEvent
188;   Parameters:
189;       BX:     Callback event
190;       CX:     Selected menuitem index
191;       DX:     Event parameter (event specific)
192;       SS:BP:  Ptr to DLGVARS
193;   Returns:
194;       AH:     Event specific or unused
195;       AL:     1=Event processed
196;               0=Event not processed (default action if any)
197;   Corrupts registers:
198;       BX, CX, DX
199;--------------------------------------------------------------------
200ALIGN JUMP_ALIGN
201MenuDlg_StrEvent:
202    cmp     bx, EVNT_MNU_UPD            ; Update strings?
203    jne     MenuDlg_JmpToMsgEvnt        ;  If not, use message handler
204    test    dl, MFL_UPD_NFO             ; Update info strings?
205    jz      MenuDlg_JmpToMsgEvnt        ;  If not, use message handler
206
207    ; Get string from user
208    push    es
209    push    di
210    call    MenuCrsr_Show               ; Show cursor during input
211    mov     bx, .VerifyChar             ; Load offset to char verify function
212    mov     dx, [bp+DLGVARS.wBuffLen]   ; Load buffer length
213    mov     di, [bp+DLGVARS.dwBuffPtr]  ; Load buffer offset
214    mov     es, [bp+DLGVARS.dwBuffPtr+2]; Load buffer segment
215    call    Keys_GetStrToBuffer         ; Get string from user
216    mov     [bp+DLGVARS.wRetLen], ax    ; Store string length
217    rcl     BYTE [bp+DLGVARS.fSuccess], 1   ; Set or clear success flag
218    pop     di
219    pop     es
220    jmp     MenuDlg_ExitHandler
221ALIGN JUMP_ALIGN
222.VerifyChar:
223    stc                                 ; Set CF to allow all chars
224    ret
Note: See TracBrowser for help on using the repository browser.