[2] | 1 | ; File name : menu.asm
|
---|
| 2 | ; Project name : Menu library
|
---|
| 3 | ; Created date : 9.11.2009
|
---|
[83] | 4 | ; Last update : 6.1.2011
|
---|
| 5 | ; Author : Tomi Tilli,
|
---|
| 6 | ; : Krister Nordvall (optimizations)
|
---|
[2] | 7 | ; Description : ASM library to menu system.
|
---|
| 8 | ;
|
---|
| 9 | ; Menu.asm contains function to be called from
|
---|
| 10 | ; user code. Functions in other menu source files
|
---|
| 11 | ; are only to be called by menu library itself!
|
---|
| 12 |
|
---|
| 13 | ; Optional features.
|
---|
| 14 | %define USE_MENU_DIALOGS ; All dialogs
|
---|
| 15 | ;%define USE_MENU_SETSEL ; Menu_SetSel
|
---|
[78] | 16 | %define USE_MENU_TOGGLEINFO ; Menu_ToggleInfo
|
---|
[2] | 17 | %define USE_MENU_INVITEMCNT ; Menu_InvItemCnt
|
---|
| 18 |
|
---|
| 19 | ; Include other menu source files.
|
---|
| 20 | %include "menudraw.asm"
|
---|
| 21 | %include "menucrsr.asm"
|
---|
| 22 | %include "menuloop.asm"
|
---|
| 23 | %ifdef USE_MENU_DIALOGS
|
---|
| 24 | %include "menumsg.asm"
|
---|
| 25 | %include "menudlg.asm"
|
---|
| 26 | %include "menuprog.asm"
|
---|
| 27 | %include "menufile.asm"
|
---|
| 28 | %endif
|
---|
| 29 |
|
---|
| 30 | ;--------------- Equates -----------------------------
|
---|
| 31 |
|
---|
| 32 | ; Menu Initialization Variables.
|
---|
| 33 | ; Menu must always be initialized to stack.
|
---|
| 34 | struc MENUVARS
|
---|
| 35 | ; Menu size set by user
|
---|
| 36 | .wSize:
|
---|
| 37 | .bWidth resb 1 ; Menu full width in chars (borders included)
|
---|
| 38 | .bHeight resb 1 ; Menu full height in chars (borders included)
|
---|
| 39 | .wTopDwnH:
|
---|
| 40 | .bTitleH resb 1 ; Title height in chars (borders not included, 0=disabled)
|
---|
| 41 | .bInfoH resb 1 ; Info height in chars (borders not included, 0=disabled)
|
---|
| 42 |
|
---|
| 43 | ; Menu callback system set by user
|
---|
| 44 | .fnEvent resb 2 ; Offset to event callback function
|
---|
| 45 |
|
---|
| 46 | ; Menu library internal variables.
|
---|
| 47 | ; Do not modify from outside menu library!
|
---|
| 48 | .wTimeInit resb 2 ; System time ticks for autoselect (0=disabled)
|
---|
| 49 | .wTimeout resb 2 ; System time ticks left for autoselect
|
---|
| 50 | .wTimeLast resb 2 ; System time ticks when last read
|
---|
| 51 | .wInitCrsr: ; Initial cursor coordinates
|
---|
| 52 | .bInitX resb 1
|
---|
| 53 | .bInitY resb 1
|
---|
| 54 |
|
---|
| 55 | ; Item related variables
|
---|
| 56 | .wItemCnt resb 2 ; Total number of items in menu
|
---|
| 57 | .wItemSel resb 2 ; Index of currently selected (pointed) menuitem
|
---|
| 58 | .wItemTop resb 2 ; Index of first visible menuitem
|
---|
| 59 | .bVisCnt resb 1 ; Maximum number of visible menuitems
|
---|
| 60 | .bFlags resb 1 ; Menu flags
|
---|
| 61 |
|
---|
| 62 | ; User specific variables start here.
|
---|
| 63 | ; 4-byte user pointer is stored here if menu created with Menu_Enter.
|
---|
| 64 | ; Data is user specific if menu was created directly with Menu_Init.
|
---|
| 65 | .user resb 0
|
---|
| 66 | endstruc
|
---|
| 67 |
|
---|
| 68 | ; Screen row count (can be used to limit max menu height)
|
---|
| 69 | CNT_SCRN_ROW EQU 25 ; Number of rows on screen
|
---|
| 70 |
|
---|
| 71 | ; Menu flags
|
---|
| 72 | FLG_MNU_EXIT EQU (1<<0) ; Set when menu operation is to be stopped
|
---|
| 73 | FLG_MNU_NOARRW EQU (1<<1) ; Do not draw item selection arrow
|
---|
| 74 | FLG_MNU_HIDENFO EQU (1<<2) ; Hide menu information
|
---|
| 75 |
|
---|
| 76 | ; Menu update and invalidate flags
|
---|
| 77 | MFL_UPD_TITLE EQU (1<<0) ; Update title string(s)
|
---|
| 78 | MFL_UPD_NFO EQU (1<<1) ; Update info string(s)
|
---|
| 79 | MFL_UPD_ITEM EQU (1<<2) ; Update item string(s)
|
---|
| 80 | MFL_UPD_NOCLEAR EQU (1<<4) ; Do not clear old chars (prevents flickering)
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | ;--------------------------------------------------------------------
|
---|
| 84 | ; Event callback function prototype.
|
---|
| 85 | ;
|
---|
| 86 | ; MENUVARS.fnEvent
|
---|
| 87 | ; Parameters:
|
---|
| 88 | ; BX: Callback event
|
---|
| 89 | ; CX: Menuitem index (usually index of selected Menuitem)
|
---|
| 90 | ; DX: Event parameter (event specific)
|
---|
| 91 | ; SS:BP: Ptr to MENUVARS
|
---|
| 92 | ; Other regs: Undefined
|
---|
| 93 | ; Returns:
|
---|
| 94 | ; AH: Event specific or unused. Set to 0 if unused.
|
---|
| 95 | ; AL: 1=Event processed
|
---|
| 96 | ; 0=Event not processed (default action if any)
|
---|
| 97 | ; Other regs: Event specific or unused.
|
---|
| 98 | ; Corrupts registers:
|
---|
| 99 | ; BX, CX, DX
|
---|
| 100 | ;--------------------------------------------------------------------
|
---|
| 101 | EVNT_MNU_EXIT EQU 0 ; Menu will quit
|
---|
| 102 | ; Ret AH: 1 to cancel exit
|
---|
| 103 | ; 0 to allow menu exit
|
---|
| 104 | EVNT_MMU_SELCHG EQU 1 ; Menuitem selection changed (with arrows)
|
---|
| 105 | EVNT_MNU_SELSET EQU 2 ; Menuitem selected (with Enter)
|
---|
| 106 | EVNT_MNU_KEY EQU 3 ; Keyboard key pressed
|
---|
| 107 | ; DH: BIOS Scan Code
|
---|
| 108 | ; DL: ASCII Char (if any)
|
---|
| 109 | EVNT_MNU_UPD EQU 4 ; Menu needs to be updated (use currect cursor position)
|
---|
| 110 | ; DL: MFL_UPD_TITLE set to update title string
|
---|
| 111 | ; MFL_UPD_NFO set to update info string
|
---|
| 112 | ; MFL_UPD_ITEM Set to update menuitem string
|
---|
| 113 | ; CX: Index of Menuitem to update
|
---|
| 114 | EVNT_MNU_GETDEF EQU 5 ; Request menuitem to be selected by default
|
---|
| 115 | ; Ret CX: Index of menuitem to select
|
---|
| 116 | EVNT_MNU_INITDONE EQU 6 ; Menu has been initialized (created) but not yet drawn
|
---|
| 117 |
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 | ;-------------- Private global variables -------------
|
---|
| 121 | ; Section containing initialized data
|
---|
| 122 | ;SECTION .data
|
---|
| 123 |
|
---|
| 124 |
|
---|
| 125 | ;-------------- Public functions ---------------------
|
---|
| 126 | ; Section containing code
|
---|
| 127 | SECTION .text
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | ;--------------------------------------------------------------------
|
---|
| 131 | ; Enters menu or submenu. Menu_Init does not have to be called
|
---|
| 132 | ; if this function is used to enter menu or submenu.
|
---|
| 133 | ; Menu_Init need to be called only when creating stack frame manually.
|
---|
| 134 | ; Manual creation allows custom menu position and user defined variables.
|
---|
| 135 | ;
|
---|
| 136 | ; Menu_Enter
|
---|
| 137 | ; Parameters:
|
---|
| 138 | ; AL: Menu width with borders included
|
---|
| 139 | ; AH: Menu height with borders included
|
---|
| 140 | ; BL: Title line count (0=disable title)
|
---|
| 141 | ; BH: Info line count (0=disable info)
|
---|
| 142 | ; CL: Number of menuitems in top menu
|
---|
| 143 | ; CH: Menu flags
|
---|
| 144 | ; DX: Selection timeout in milliseconds (0=timeout disabled)
|
---|
| 145 | ; DS:SI: User specific far pointer (will be stored to MENUVARS.user)
|
---|
| 146 | ; CS:DI: Pointer to menu event handler function
|
---|
| 147 | ; Returns:
|
---|
| 148 | ; CX: Index of last pointed Menuitem (not necessary selected with ENTER)
|
---|
| 149 | ; FFFFh if cancelled with ESC
|
---|
| 150 | ; Corrupts registers:
|
---|
| 151 | ; AX, BX, DX
|
---|
| 152 | ;--------------------------------------------------------------------
|
---|
| 153 | ALIGN JUMP_ALIGN
|
---|
| 154 | Menu_Enter:
|
---|
| 155 | ; Create stack frame
|
---|
| 156 | eENTER MENUVARS_size+4, 0
|
---|
| 157 | sub bp, MENUVARS_size+4 ; Point to MENUVARS
|
---|
| 158 |
|
---|
| 159 | ; Initialize menu variables
|
---|
| 160 | mov [bp+MENUVARS.wSize], ax
|
---|
| 161 | mov [bp+MENUVARS.wTopDwnH], bx
|
---|
| 162 | mov [bp+MENUVARS.fnEvent], di
|
---|
| 163 | mov [bp+MENUVARS.user], si
|
---|
| 164 | mov [bp+MENUVARS.user+2], ds
|
---|
| 165 |
|
---|
| 166 | ; Prepare to call Menu_Init
|
---|
| 167 | push dx ; Store timeout
|
---|
| 168 | call MenuCrsr_GetCenter ; Get centered coordinates to DX
|
---|
| 169 | pop ax ; Restore timeout to AX
|
---|
| 170 | xor bx, bx ; Zero BX
|
---|
| 171 | xchg bl, ch ; Menu flags to BL, Item count to CX
|
---|
| 172 | call Menu_Init
|
---|
| 173 |
|
---|
| 174 | ; Destroy stack frame
|
---|
| 175 | add bp, MENUVARS_size+4 ; Point to old BP
|
---|
| 176 | eLEAVE ; Destroy stack frame
|
---|
| 177 | ret
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 | ;--------------------------------------------------------------------
|
---|
| 181 | ; Initialize Menu.
|
---|
| 182 | ; This function returns only after Menu_Exit has been called from
|
---|
| 183 | ; event callback function (MENUVARS.fnEvent).
|
---|
| 184 | ; Caller must clean MENUVARS from stack once this function returns!
|
---|
| 185 | ;
|
---|
| 186 | ; Multiple menus can be created to implement submenus.
|
---|
| 187 | ;
|
---|
| 188 | ; Menu_Init
|
---|
| 189 | ; Parameters:
|
---|
| 190 | ; AX: Selection timeout (ms, 0=timeout disabled)
|
---|
| 191 | ; BL: Menu flags
|
---|
| 192 | ; CX: Number of menuitems in top menu
|
---|
| 193 | ; DX: Top left coordinate for menu
|
---|
| 194 | ; SS:BP: Ptr to MENUVARS
|
---|
| 195 | ; Returns:
|
---|
| 196 | ; CX: Index of last pointed Menuitem (not necessary selected with ENTER)
|
---|
| 197 | ; FFFFh if cancelled with ESC
|
---|
| 198 | ; Corrupts registers:
|
---|
| 199 | ; AX, BX, DX
|
---|
| 200 | ;--------------------------------------------------------------------
|
---|
| 201 | ALIGN JUMP_ALIGN
|
---|
| 202 | Menu_Init:
|
---|
| 203 | ; Initialize internal variables
|
---|
| 204 | call Menu_StartTimeout
|
---|
| 205 | xor ax, ax ; Zero AX
|
---|
| 206 | mov [bp+MENUVARS.wInitCrsr], dx
|
---|
| 207 | mov [bp+MENUVARS.wItemCnt], cx
|
---|
| 208 | mov [bp+MENUVARS.wItemSel], ax
|
---|
| 209 | mov [bp+MENUVARS.wItemTop], ax
|
---|
| 210 | mov [bp+MENUVARS.bFlags], bl
|
---|
| 211 |
|
---|
| 212 | ; Calculate number of visible menuitems
|
---|
| 213 | eMOVZX ax, [bp+MENUVARS.bHeight] ; Load menu total height
|
---|
| 214 | times 2 dec ax ; Decrement top and borders
|
---|
| 215 | or ah, [bp+MENUVARS.bTitleH] ; Load title height
|
---|
| 216 | jz .CheckInfo ; If no title, check if info
|
---|
| 217 | sub al, ah ; Subtract title lines
|
---|
| 218 | dec ax ; Decrement item border
|
---|
| 219 | ALIGN JUMP_ALIGN
|
---|
| 220 | .CheckInfo:
|
---|
| 221 | xor ah, ah ; Zero AH
|
---|
| 222 | or ah, [bp+MENUVARS.bInfoH] ; Load info height
|
---|
| 223 | jz .StoreVisible ; If no info, jump to store
|
---|
| 224 | sub al, ah ; Subtract info lines
|
---|
| 225 | dec ax ; Decrement item border
|
---|
| 226 | ALIGN JUMP_ALIGN
|
---|
| 227 | .StoreVisible:
|
---|
| 228 | mov [bp+MENUVARS.bVisCnt], al ; Store max visible menuitems
|
---|
| 229 |
|
---|
| 230 | ; Get default menuitem
|
---|
| 231 | mov bx, EVNT_MNU_GETDEF
|
---|
| 232 | call MenuLoop_SendEvent
|
---|
| 233 | test al, al ; Default menuitem returned?
|
---|
| 234 | jz .InitDone ; If not, continue
|
---|
| 235 | mov [bp+MENUVARS.wItemSel], cx ; Store default
|
---|
| 236 | eMOVZX ax, [bp+MENUVARS.bVisCnt] ; Load one past last to be displayed
|
---|
| 237 | cmp cx, ax ; Visible selection?
|
---|
| 238 | jb .InitDone ; If so, continue
|
---|
| 239 | mov [bp+MENUVARS.wItemTop], cx ; Set selected to topmost
|
---|
| 240 |
|
---|
| 241 | ; Send EVNT_MNU_INITDONE event
|
---|
| 242 | ALIGN JUMP_ALIGN
|
---|
| 243 | .InitDone:
|
---|
| 244 | mov bx, EVNT_MNU_INITDONE
|
---|
| 245 | call MenuLoop_SendEvent
|
---|
| 246 |
|
---|
| 247 | ; Draw menu
|
---|
| 248 | call MenuCrsr_Hide ; Hide cursor
|
---|
| 249 | mov cx, -1 ; Invalidate all menuitems
|
---|
| 250 | mov dl, MFL_UPD_TITLE | MFL_UPD_ITEM | MFL_UPD_NFO
|
---|
| 251 | call Menu_Invalidate
|
---|
| 252 |
|
---|
| 253 | ; Enter menu loop until Menu_Exit is called
|
---|
| 254 | call MenuLoop_Enter
|
---|
| 255 | call MenuCrsr_Show ; Show cursor again
|
---|
| 256 | mov cx, [bp+MENUVARS.wItemSel] ; Load return value
|
---|
| 257 | ret
|
---|
| 258 |
|
---|
| 259 |
|
---|
| 260 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 261 | ; Below functions are called only from event callback function ;
|
---|
| 262 | ; (MENUVARS.fnEvent) ;
|
---|
| 263 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 264 |
|
---|
| 265 | ;--------------------------------------------------------------------
|
---|
| 266 | ; Sets wanted menuitem selected and draws changes.
|
---|
| 267 | ;
|
---|
| 268 | ; Menu_SetSel
|
---|
| 269 | ; Parameters:
|
---|
| 270 | ; CX: Index of menuitem to set selected
|
---|
| 271 | ; SS:BP: Ptr to MENUVARS for menu to refresh
|
---|
| 272 | ; Returns:
|
---|
| 273 | ; Nothing
|
---|
| 274 | ; Corrupts registers:
|
---|
| 275 | ; AX, BX, CX, DX
|
---|
| 276 | ;--------------------------------------------------------------------
|
---|
| 277 | %ifdef USE_MENU_SETSEL
|
---|
| 278 | ALIGN JUMP_ALIGN
|
---|
| 279 | Menu_SetSel:
|
---|
| 280 | cmp cx, [bp+MENUVARS.wItemCnt] ; Valid menuitem index?
|
---|
| 281 | jae .Return ; If not, return
|
---|
| 282 | mov [bp+MENUVARS.wItemSel], cx ; Store new selected index
|
---|
| 283 |
|
---|
| 284 | ; Scroll if necessary
|
---|
| 285 | mov ax, [bp+MENUVARS.wItemTop] ; Load index of topmost visible
|
---|
| 286 | MIN_U ax, cx ; AX = new topmost visible
|
---|
| 287 | mov [bp+MENUVARS.wItemTop], ax ; Store new topmost
|
---|
| 288 | add al, [bp+MENUVARS.bVisCnt] ; AX to one past...
|
---|
| 289 | adc ah, 0 ; ...last visible
|
---|
| 290 | cmp cx, ax ; After last visible?
|
---|
| 291 | jb .SendSelChg ; If not, continue
|
---|
| 292 | mov [bp+MENUVARS.wItemTop], cx ; New selection to topmost
|
---|
| 293 |
|
---|
| 294 | ; Send EVNT_MMU_SELCHG message
|
---|
| 295 | ALIGN JUMP_ALIGN
|
---|
| 296 | .SendSelChg:
|
---|
| 297 | mov bx, EVNT_MMU_SELCHG
|
---|
| 298 | call MenuLoop_SendEvent
|
---|
| 299 |
|
---|
| 300 | ; Redraw changes
|
---|
| 301 | mov cx, -1 ; Invalidate all menuitems
|
---|
| 302 | mov dl, MFL_UPD_ITEM
|
---|
| 303 | call Menu_Invalidate
|
---|
| 304 | .Return:
|
---|
| 305 | ret
|
---|
| 306 | %endif
|
---|
| 307 |
|
---|
| 308 |
|
---|
| 309 | ;--------------------------------------------------------------------
|
---|
| 310 | ; Shows or hides menu information at the bottom of menu.
|
---|
| 311 | ;
|
---|
| 312 | ; Menu_ShowInfo Enables menu information
|
---|
| 313 | ; Menu_HideInfo Disables menu information
|
---|
| 314 | ; Menu_ToggleInfo Enables or disables menu information
|
---|
| 315 | ; Parameters:
|
---|
| 316 | ; SS:BP: Ptr to MENUVARS for menu
|
---|
| 317 | ; Returns:
|
---|
| 318 | ; Nothing
|
---|
| 319 | ; Corrupts registers:
|
---|
| 320 | ; AX, BX, DX
|
---|
| 321 | ;--------------------------------------------------------------------
|
---|
| 322 | %ifdef USE_MENU_TOGGLEINFO
|
---|
| 323 | ALIGN JUMP_ALIGN
|
---|
| 324 | Menu_ShowInfo:
|
---|
| 325 | test BYTE [bp+MENUVARS.bFlags], FLG_MNU_HIDENFO
|
---|
| 326 | jnz Menu_ToggleInfo
|
---|
| 327 | ret
|
---|
| 328 | ALIGN JUMP_ALIGN
|
---|
| 329 | Menu_HideInfo:
|
---|
| 330 | test BYTE [bp+MENUVARS.bFlags], FLG_MNU_HIDENFO
|
---|
| 331 | jz Menu_ToggleInfo
|
---|
| 332 | ret
|
---|
| 333 | ALIGN JUMP_ALIGN
|
---|
| 334 | Menu_ToggleInfo:
|
---|
| 335 | xor BYTE [bp+MENUVARS.bFlags], FLG_MNU_HIDENFO
|
---|
| 336 | ; Fall to Menu_RefreshMenu
|
---|
| 337 | %endif
|
---|
| 338 |
|
---|
| 339 |
|
---|
| 340 | ;--------------------------------------------------------------------
|
---|
| 341 | ; Refreshes menu. This function must be called when
|
---|
| 342 | ; call to submenu Menu_Enter (or Menu_Init) returns.
|
---|
| 343 | ;
|
---|
| 344 | ; Menu_RefreshMenu
|
---|
| 345 | ; Parameters:
|
---|
| 346 | ; SS:BP: Ptr to MENUVARS for menu to refresh
|
---|
| 347 | ; Returns:
|
---|
| 348 | ; Nothing
|
---|
| 349 | ; Corrupts registers:
|
---|
| 350 | ; AX, BX, DX
|
---|
| 351 | ;--------------------------------------------------------------------
|
---|
| 352 | ALIGN JUMP_ALIGN
|
---|
| 353 | Menu_RefreshMenu:
|
---|
| 354 | push cx
|
---|
| 355 | call MenuCrsr_Hide ; Hide cursor
|
---|
| 356 | call Menu_RestartTimeout ; Restart selection timeout
|
---|
| 357 | call Menu_GetTime ; Get system time ticks to CX:DX
|
---|
| 358 | mov [bp+MENUVARS.wTimeLast], dx ; Store last time updated
|
---|
| 359 | call Keys_ClrBuffer ; Clear keyboard buffer
|
---|
| 360 | call MenuDraw_ClrScr ; Clear screen
|
---|
| 361 | mov cx, -1 ; Invalidate all menuitems
|
---|
| 362 | mov dl, MFL_UPD_TITLE | MFL_UPD_NFO | MFL_UPD_ITEM
|
---|
| 363 | call Menu_Invalidate ; Redraw everything
|
---|
| 364 | pop cx
|
---|
| 365 | ret
|
---|
| 366 |
|
---|
| 367 |
|
---|
| 368 | ;--------------------------------------------------------------------
|
---|
| 369 | ; Destroy menu by causing Menu_Init to return.
|
---|
| 370 | ;
|
---|
| 371 | ; Menu_Exit
|
---|
| 372 | ; Parameters:
|
---|
| 373 | ; SS:BP: Ptr to MENUVARS
|
---|
| 374 | ; Returns:
|
---|
| 375 | ; CF: Set if user cancelled exit
|
---|
| 376 | ; Cleared if user allowed exit
|
---|
| 377 | ; Corrupts registers:
|
---|
| 378 | ; AX, BX, CX, DX
|
---|
| 379 | ;--------------------------------------------------------------------
|
---|
| 380 | ALIGN JUMP_ALIGN
|
---|
| 381 | Menu_Exit:
|
---|
| 382 | mov bx, EVNT_MNU_EXIT
|
---|
| 383 | call MenuLoop_SendEvent
|
---|
| 384 | rcr ah, 1 ; AH bit 0 to CF
|
---|
| 385 | jc .Return ; Do not exit if AH non-zero
|
---|
| 386 | or BYTE [bp+MENUVARS.bFlags], FLG_MNU_EXIT ; (Clear CF)
|
---|
| 387 | ALIGN JUMP_ALIGN
|
---|
| 388 | .Return:
|
---|
| 389 | ret
|
---|
| 390 |
|
---|
| 391 |
|
---|
| 392 | ;--------------------------------------------------------------------
|
---|
| 393 | ; Invalidate any menu string.
|
---|
| 394 | ; Menu then sends EVNT_MNU_UPD events when necessary.
|
---|
| 395 | ;
|
---|
| 396 | ; Menu_InvItemCnt Changes total item count and invalidates
|
---|
| 397 | ; Parameters: (in addition to Menu_Invalidate)
|
---|
| 398 | ; CX: New Total item count
|
---|
| 399 | ; Menu_Invalidate
|
---|
| 400 | ; Parameters:
|
---|
| 401 | ; DL: Invalidate flags (any combination is valid):
|
---|
| 402 | ; MFL_UPD_NOCLEAR Set to prevent clearing old chars
|
---|
| 403 | ; MFL_UPD_TITLE Invalidate menu title string
|
---|
| 404 | ; MFL_UPD_NFO Invalidate menu info string
|
---|
| 405 | ; MFL_UPD_ITEM Invalidate menuitem strings
|
---|
| 406 | ; CX: Index of Menuitem to update
|
---|
| 407 | ; -1 to update all menuitems
|
---|
| 408 | ; SS:BP: Ptr to MENUVARS
|
---|
| 409 | ; Returns:
|
---|
| 410 | ; Nothing
|
---|
| 411 | ; Corrupts registers:
|
---|
| 412 | ; AX, BX, CX, DX
|
---|
| 413 | ;--------------------------------------------------------------------
|
---|
| 414 | %ifdef USE_MENU_INVITEMCNT
|
---|
| 415 | ALIGN JUMP_ALIGN
|
---|
| 416 | Menu_InvItemCnt:
|
---|
| 417 | xor ax, ax
|
---|
| 418 | mov [bp+MENUVARS.wItemCnt], cx
|
---|
| 419 | mov [bp+MENUVARS.wItemSel], ax
|
---|
| 420 | mov [bp+MENUVARS.wItemTop], ax
|
---|
[83] | 421 | xchg cx, ax ; CX = 0
|
---|
| 422 | dec cx ; CX = -1 (Invalidate all items)
|
---|
[78] | 423 | or dl, MFL_UPD_ITEM
|
---|
[2] | 424 | %endif
|
---|
| 425 | ALIGN JUMP_ALIGN
|
---|
| 426 | Menu_Invalidate:
|
---|
| 427 | push di
|
---|
| 428 | mov di, dx
|
---|
| 429 | test di, MFL_UPD_ITEM ; Invalidate Menuitems?
|
---|
| 430 | jz .InvTitle ; If not, jump to invalidate Title
|
---|
| 431 | cmp cx, -1 ; Redraw all menuitems?
|
---|
| 432 | je .InvAllItems ; If so, jump to draw
|
---|
| 433 | call MenuCrsr_PointNthItem ; Set cursor position
|
---|
| 434 | call MenuDraw_Item ; Draw single menuitem
|
---|
| 435 | jmp .InvTitle ; Jump to invalidate Title
|
---|
| 436 | ALIGN JUMP_ALIGN
|
---|
| 437 | .InvAllItems:
|
---|
| 438 | test di, MFL_UPD_NOCLEAR ; Keep background?
|
---|
| 439 | jnz .DrawAllItems ; If not, jump to draw
|
---|
| 440 | call MenuDraw_ItemBorders ; Draw item borders
|
---|
| 441 | ALIGN JUMP_ALIGN
|
---|
| 442 | .DrawAllItems:
|
---|
| 443 | call MenuDraw_AllItemsNoBord ; Draw items without borders
|
---|
| 444 |
|
---|
| 445 | ALIGN JUMP_ALIGN
|
---|
| 446 | .InvTitle:
|
---|
| 447 | test di, MFL_UPD_TITLE ; Invalidate Title?
|
---|
| 448 | jz .InvInfo ; If not, jump to invalidate Info
|
---|
| 449 | test di, MFL_UPD_NOCLEAR ; Keep background?
|
---|
| 450 | jnz .DrawTitle ; If not, jump to draw
|
---|
| 451 | call MenuDraw_TitleBorders ; Draw borders
|
---|
| 452 | ALIGN JUMP_ALIGN
|
---|
| 453 | .DrawTitle:
|
---|
| 454 | call MenuDraw_TitleNoBord ; Draw title without borders
|
---|
| 455 |
|
---|
| 456 | ALIGN JUMP_ALIGN
|
---|
| 457 | .InvInfo:
|
---|
| 458 | test di, MFL_UPD_NFO ; Invalidate Info?
|
---|
| 459 | jz .Return ; If not, return
|
---|
| 460 | test di, MFL_UPD_NOCLEAR ; Keep background?
|
---|
| 461 | jnz .DrawInfo ; If not, jump to draw
|
---|
| 462 | call MenuDraw_InfoBorders ; Draw borders
|
---|
| 463 | ALIGN JUMP_ALIGN
|
---|
| 464 | .DrawInfo:
|
---|
| 465 | call MenuDraw_InfoNoBord ; Draw info without borders
|
---|
| 466 | ALIGN JUMP_ALIGN
|
---|
| 467 | .Return:
|
---|
| 468 | pop di
|
---|
| 469 | ret
|
---|
| 470 |
|
---|
| 471 |
|
---|
| 472 | ;--------------------------------------------------------------------
|
---|
| 473 | ; Starts or stops menu selection timeout.
|
---|
| 474 | ;
|
---|
| 475 | ; Menu_StopTimeout ; Stops timeout
|
---|
| 476 | ; Menu_StartTimeout ; Starts timeout with new value
|
---|
| 477 | ; Menu_RestartTimeout ; Restarts timeout with previous value
|
---|
| 478 | ; Parameters:
|
---|
| 479 | ; AX: New timeout value in ms (for Menu_StartTimeout only)
|
---|
| 480 | ; SS:BP: Ptr to MENUVARS
|
---|
| 481 | ; Returns:
|
---|
| 482 | ; Nothing
|
---|
| 483 | ; Corrupts registers:
|
---|
| 484 | ; AX
|
---|
| 485 | ;--------------------------------------------------------------------
|
---|
| 486 | ALIGN JUMP_ALIGN
|
---|
| 487 | Menu_StopTimeout:
|
---|
| 488 | xor ax, ax
|
---|
| 489 | ALIGN JUMP_ALIGN
|
---|
| 490 | Menu_StartTimeout:
|
---|
| 491 | push dx
|
---|
| 492 | push bx
|
---|
| 493 | xor dx, dx
|
---|
| 494 | mov bx, 55 ; 1 timer tick = 54.945ms
|
---|
| 495 | div bx ; DX:AX / 55
|
---|
| 496 | mov [bp+MENUVARS.wTimeInit], ax ; Store timer tick count
|
---|
| 497 | mov [bp+MENUVARS.wTimeout], ax
|
---|
| 498 | pop bx
|
---|
| 499 | pop dx
|
---|
| 500 | ret
|
---|
| 501 | ALIGN JUMP_ALIGN
|
---|
| 502 | Menu_RestartTimeout:
|
---|
| 503 | mov ax, [bp+MENUVARS.wTimeInit]
|
---|
| 504 | mov [bp+MENUVARS.wTimeout], ax
|
---|
| 505 | ret
|
---|
| 506 |
|
---|
| 507 |
|
---|
| 508 | ;--------------------------------------------------------------------
|
---|
| 509 | ; Returns system time in clock ticks. One tick is 54.95ms.
|
---|
| 510 | ;
|
---|
| 511 | ; Menu_GetTime
|
---|
| 512 | ; Parameters:
|
---|
| 513 | ; Nothing
|
---|
| 514 | ; Returns:
|
---|
| 515 | ; AL: Midnight flag, set if midnight passed since last read
|
---|
| 516 | ; CX:DX: Number of clock ticks since midnight
|
---|
| 517 | ; Corrupts registers:
|
---|
| 518 | ; AH
|
---|
| 519 | ;--------------------------------------------------------------------
|
---|
| 520 | ALIGN JUMP_ALIGN
|
---|
| 521 | Menu_GetTime:
|
---|
| 522 | xor ah, ah ; Get System Time
|
---|
| 523 | int 1Ah
|
---|
| 524 | ret
|
---|
| 525 |
|
---|
| 526 |
|
---|
| 527 | ;--------------------------------------------------------------------
|
---|
| 528 | ; Checks if Menuitem is currently visible.
|
---|
| 529 | ;
|
---|
| 530 | ; Menu_IsItemVisible
|
---|
| 531 | ; Parameters:
|
---|
| 532 | ; AX: Menuitem index
|
---|
| 533 | ; SS:BP: Ptr to MENUVARS
|
---|
| 534 | ; Returns:
|
---|
| 535 | ; CF: Set if Menuitem is visible
|
---|
| 536 | ; Cleared if Menuitem is not visible
|
---|
| 537 | ; Corrupts registers:
|
---|
| 538 | ; Nothing
|
---|
| 539 | ;--------------------------------------------------------------------
|
---|
| 540 | ALIGN JUMP_ALIGN
|
---|
| 541 | Menu_IsItemVisible:
|
---|
| 542 | push dx
|
---|
| 543 | mov dx, [bp+MENUVARS.wItemTop] ; Load index of first visible
|
---|
| 544 | cmp ax, dx ; First visible menuitem?
|
---|
| 545 | jb .RetFalse ; If below, return false
|
---|
| 546 | add dl, [bp+MENUVARS.bVisCnt] ; Inc to one past...
|
---|
| 547 | adc dh, 0 ; ...last visible menuitem
|
---|
[83] | 548 | cmp ax, dx ; Over last visible or not?
|
---|
| 549 | cmc ; Either way, fall through
|
---|
| 550 | ALIGN JUMP_ALIGN ; CF will reflect TRUE/FALSE
|
---|
[2] | 551 | .RetFalse:
|
---|
[83] | 552 | cmc
|
---|
[2] | 553 | pop dx
|
---|
| 554 | ret
|
---|
| 555 |
|
---|
| 556 |
|
---|
| 557 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 558 | ; Optional Dialog functions start here ;
|
---|
| 559 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 560 | %ifdef USE_MENU_DIALOGS
|
---|
| 561 |
|
---|
| 562 | ;--------------------------------------------------------------------
|
---|
| 563 | ; Shows message dialog to display string.
|
---|
| 564 | ; String can be multiple lines but line feeds will be determined
|
---|
| 565 | ; by menu system.
|
---|
| 566 | ;
|
---|
| 567 | ; Menu_ShowMsgDlg
|
---|
| 568 | ; Parameters:
|
---|
| 569 | ; BL: Dialog width with borders included
|
---|
| 570 | ; SS:BP: Ptr to MENUVARS
|
---|
| 571 | ; ES:DI: Ptr to STOP terminated string to display
|
---|
| 572 | ; Returns:
|
---|
| 573 | ; Nothing
|
---|
| 574 | ; Corrupts registers:
|
---|
| 575 | ; AX, BX, CX, DX
|
---|
| 576 | ;--------------------------------------------------------------------
|
---|
| 577 | ALIGN JUMP_ALIGN
|
---|
| 578 | Menu_ShowMsgDlg:
|
---|
| 579 | call MenuMsg_ShowMessage
|
---|
| 580 | jmp Menu_RefreshMenu
|
---|
| 581 |
|
---|
| 582 |
|
---|
| 583 | ;--------------------------------------------------------------------
|
---|
| 584 | ; Shows dialog that asks unsigned DWORD from user.
|
---|
| 585 | ;
|
---|
| 586 | ; Menu_ShowDWDlg
|
---|
| 587 | ; Parameters:
|
---|
| 588 | ; BL: Dialog width with borders included
|
---|
| 589 | ; CX: Numeric base (10=dec, 16=hex...)
|
---|
| 590 | ; SS:BP: Ptr to MENUVARS
|
---|
| 591 | ; ES:DI: Ptr to STOP terminated string to display
|
---|
| 592 | ; Returns:
|
---|
| 593 | ; DX:AX: User inputted data
|
---|
| 594 | ; CF: Set if user data inputted successfully
|
---|
| 595 | ; Cleared is input cancelled
|
---|
| 596 | ; Corrupts registers:
|
---|
| 597 | ; BX, CX
|
---|
| 598 | ;--------------------------------------------------------------------
|
---|
| 599 | ALIGN JUMP_ALIGN
|
---|
| 600 | Menu_ShowDWDlg:
|
---|
| 601 | mov dx, MenuDlg_DWEvent ; Offset to event handler
|
---|
| 602 | call MenuDlg_Show
|
---|
| 603 | push ax
|
---|
| 604 | push dx
|
---|
| 605 | pushf
|
---|
| 606 | call Menu_RefreshMenu
|
---|
| 607 | popf
|
---|
| 608 | pop dx
|
---|
| 609 | pop ax
|
---|
| 610 | ret
|
---|
| 611 |
|
---|
| 612 |
|
---|
| 613 | ;--------------------------------------------------------------------
|
---|
| 614 | ; Shows dialog that asks Y/N input from user.
|
---|
| 615 | ;
|
---|
| 616 | ; Menu_ShowYNDlg
|
---|
| 617 | ; Parameters:
|
---|
| 618 | ; BL: Dialog width with borders included
|
---|
| 619 | ; SS:BP: Ptr to MENUVARS
|
---|
| 620 | ; ES:DI: Ptr to STOP terminated string to display
|
---|
| 621 | ; Returns:
|
---|
| 622 | ; AX: 'Y' if Y pressed
|
---|
| 623 | ; 'N' if N pressed
|
---|
| 624 | ; Zero if ESC pressed
|
---|
| 625 | ; CF: Set if Y pressed
|
---|
| 626 | ; Cleared if N or ESC pressed
|
---|
| 627 | ; Corrupts registers:
|
---|
| 628 | ; BX, CX, DX
|
---|
| 629 | ;--------------------------------------------------------------------
|
---|
| 630 | ALIGN JUMP_ALIGN
|
---|
| 631 | Menu_ShowYNDlg:
|
---|
| 632 | mov dx, MenuDlg_YNEvent ; Offset to event handler
|
---|
[83] | 633 | jmp ContinueMenuShowDlg
|
---|
[2] | 634 |
|
---|
| 635 |
|
---|
| 636 | ;--------------------------------------------------------------------
|
---|
| 637 | ; Shows dialog that asks any string from user.
|
---|
| 638 | ;
|
---|
| 639 | ; Menu_ShowStrDlg
|
---|
| 640 | ; Parameters:
|
---|
| 641 | ; BL: Dialog width with borders included
|
---|
| 642 | ; CX: Buffer length with STOP included
|
---|
| 643 | ; SS:BP: Ptr to MENUVARS
|
---|
| 644 | ; ES:DI: Ptr to STOP terminated string to display
|
---|
| 645 | ; DS:SI: Prt to buffer to receive string
|
---|
| 646 | ; Returns:
|
---|
| 647 | ; AX: String length in characters without STOP
|
---|
| 648 | ; CF: Set if string inputted successfully
|
---|
| 649 | ; Cleared if user cancellation
|
---|
| 650 | ; Corrupts registers:
|
---|
| 651 | ; BX, CX, DX
|
---|
| 652 | ;--------------------------------------------------------------------
|
---|
| 653 | ALIGN JUMP_ALIGN
|
---|
| 654 | Menu_ShowStrDlg:
|
---|
| 655 | mov dx, MenuDlg_StrEvent ; Offset to event handler
|
---|
[83] | 656 | ContinueMenuShowDlg:
|
---|
[2] | 657 | call MenuDlg_Show
|
---|
| 658 | push ax
|
---|
| 659 | pushf
|
---|
| 660 | call Menu_RefreshMenu
|
---|
| 661 | popf
|
---|
| 662 | pop ax
|
---|
| 663 | ret
|
---|
| 664 |
|
---|
| 665 |
|
---|
| 666 | ;--------------------------------------------------------------------
|
---|
| 667 | ; Shows progress bar dialog.
|
---|
| 668 | ;
|
---|
| 669 | ; Menu_ShowProgDlg
|
---|
| 670 | ; Parameters:
|
---|
| 671 | ; BL: Dialog width with borders included
|
---|
| 672 | ; BH: Dialog height with borders included
|
---|
| 673 | ; SS:BP: Ptr to MENUVARS
|
---|
| 674 | ; ES:DI: Far ptr to user specified task function
|
---|
| 675 | ; DS:SI: User specified far pointer
|
---|
| 676 | ; Returns:
|
---|
| 677 | ; AX: User specified return code
|
---|
| 678 | ; Corrupts registers:
|
---|
| 679 | ; BX, CX, DX
|
---|
| 680 | ;--------------------------------------------------------------------
|
---|
| 681 | ALIGN JUMP_ALIGN
|
---|
| 682 | Menu_ShowProgDlg:
|
---|
| 683 | call MenuProg_Show
|
---|
| 684 | push ax
|
---|
| 685 | call Menu_RefreshMenu
|
---|
| 686 | pop ax
|
---|
| 687 | ret
|
---|
| 688 |
|
---|
| 689 |
|
---|
| 690 | ;--------------------------------------------------------------------
|
---|
| 691 | ; Shows dialog that user can use to select file.
|
---|
| 692 | ;
|
---|
| 693 | ; Menu_ShowFileDlg
|
---|
| 694 | ; Parameters:
|
---|
| 695 | ; BL: Dialog width with borders included
|
---|
| 696 | ; SS:BP: Ptr to MENUVARS
|
---|
| 697 | ; ES:DI: Ptr to STOP terminated info string
|
---|
| 698 | ; DS:SI: Ptr to file search string (* and ? wildcards supported)
|
---|
| 699 | ; Returns:
|
---|
| 700 | ; DS:SI: Ptr to DTA for selected file
|
---|
| 701 | ; CF: Set if file selected successfully
|
---|
| 702 | ; Cleared if user cancellation
|
---|
| 703 | ; Corrupts registers:
|
---|
| 704 | ; AX, BX, CX, DX
|
---|
| 705 | ;--------------------------------------------------------------------
|
---|
| 706 | ALIGN JUMP_ALIGN
|
---|
| 707 | Menu_ShowFileDlg:
|
---|
| 708 | call MenuFile_ShowDlg
|
---|
| 709 | pushf
|
---|
| 710 | call Menu_RefreshMenu
|
---|
| 711 | popf
|
---|
| 712 | ret
|
---|
| 713 |
|
---|
| 714 |
|
---|
| 715 | %endif ; USE_MENU_DIALOGS
|
---|