📄 windows.inc
字号:
;=============================================================================
; Insight, real-mode debugger for MS DOS / PC DOS / FreeDOS.
; Copyright (c) Victor M. Gamayunov, Sergey Pimenov, 1993, 96, 97, 2002.
; Modifications by Oleg O. Chukaev (2006, 2007).
;-----------------------------------------------------------------------------
; windows.inc
; Procedures for creating windows and menus.
;-----------------------------------------------------------------------------
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version 2
; of the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
; 02111-1307, USA.
;=============================================================================
;=============================================================================
; Changelog
;-----------------------------------------------------------------------------
; 2007-02-06 (Oleg O. Chukaev)
; Added comments to all (?) procedures.
;
; 2007-02-10 (Oleg O. Chukaev)
; All variables moved to act[u]data.inc
;
;=============================================================================
;=============================================================================
; exec_menu
;-----------------------------------------------------------------------------
; Creates horizontal menu.
; In: DS:SI -> menu structure.
; Format of menu structure:
; dw number-of-items
; dw ptr-to-list-of-strings
; dw ptr-to-list-of-submenus
;
; List of strings (menu items):
; db '~F~oo', 0
; db '~B~ar', 0
; db 'Baz', 0
; ...
; Hot keys enclosed in tildes (~).
;
; List of submenus:
; dw SUB_MENU, ptr-to-Foo-submenu-struc
; dw DISABLED, ptr-to-Bar-submenu-struc
; dw 0, ptr-to-Baz-procedure
; ...
;
; Format of submenu structure:
; db left, top, right, bottom ;coordinates
; dw number-of-items
; db number-of-selected-item
; db width-of-cursor
; dw ptr-to-list-of-procedures
; dw ptr-to-list-of-strings
;
; List of procedures:
; dw SUB_MENU, ptr-to-submenu-struc
; dw DISABLED, ptr-to-procedure
; dw 0, ptr-to-procedure
; ...
;
; Out: AX -- exit code
; Modf: AX, BX, CX, DX, SI, DI, BP
; Call: ---
; Use: ---
;
exec_menu:
xor bx,bx
mov dx,79
call save_window
cld
lodsw ;Number of menu items
mov cx,ax
mov bx,[h_pos]
@@next:
call update_hmenu
@@read:
call read_key
cmp ax,kbEsc
je @@esc
cmp ax,kbAltAlone
je @@esc
cmp ax,kbEnter
je @@enter
cmp ax,kbDown
je @@enter
cmp ax,kbRight
je @@right
cmp ax,kbLeft
je @@left
push si
mov si,[si] ;Ptr to string list
call find_menu_letter
pop si
jc @@read
mov bx,ax ;Menu item
call update_hmenu
jmp @@enter
@@right:
inc bx
cmp bx,cx
jb @@next
xor bx,bx
jmp @@next
@@left:
dec bx
jns @@next
mov bx,cx
dec bx
jmp @@next
@@enter:
push si
mov si,[si+2] ;Ptr to list of submenus
call exec_sub_menu
pop si
cmp ax,2
je @@left_exp
cmp ax,3
je @@right_exp
cmp ax,100h
jae @@quit
@@esc:
xor ax,ax
@@quit:
mov word [point_options],0
mov [h_pos],bx
xor bx,bx
mov dx,79
call restore_window
or ax,ax
jz @@ret
call ax
@@ret:
ret
@@left_exp:
dec bx
jns @@exp
mov bx,cx
dec bx
jmp @@exp
@@right_exp:
inc bx
cmp bx,cx
jb @@exp
xor bx,bx
@@exp:
call update_hmenu
jmp @@enter
;=============================================================================
; exec_sub_menu
;-----------------------------------------------------------------------------
; Creates submenu.
; In: DS:SI -> list of submenus
; BX -- number of current item
; Out: AX -- result:
; 1 -- menu item disabled
; >= 100h -- ptr to procedure
; Modf: AX
; Call: open_window_bord, vert_menu, exec_sub_menu, close_window
; Use: sub_struc, sub_coord, empty_title, point_options
;
exec_sub_menu:
push bx
push cx
push dx
push si
push word [sub_struc]
push word [sub_coord]
shl bx,1
shl bx,1
mov ax,[bx+si] ;DISABLED, SUB_MENU, etc.
test al,DISABLED
jz @@enabled
mov ax,1
jmp @@quit_2
@@enabled:
and ax,~DISABLED
or ax,ax
jnz @@sub_menu ;Submenu if bit 0 is set
mov ax,[bx+si+2] ;Otherwise -- procedure
; call word ptr [bx+si+2]
; xor ax,ax
jmp @@quit_2
@@sub_menu:
mov si,[bx+si+2] ;Ptr to submenu structure
lodsw
mov [sub_coord],ax ;Coordinates of top left corner
mov bx,ax
lodsw
mov dx,ax ;Coordinates of lower right corner
mov ax,atMenuBorder*256+1
push bx
push dx
push si
mov si,empty_title
mov cx,single_border
call open_window_bord
pop si
mov [sub_struc],si
@@next_menu:
lodsw
mov cx,ax ;Number of items
lodsw
mov dx,ax ;Selected/width
lodsw
mov bp,ax ;Ptr to list of procedures
mov [point_options],ax
lodsw
mov si,ax ;Ptr to list of strings
mov ax,[sub_coord]
add ax,0101h
mov bl,atMenuNorm
mov bh,atMenuSel
call vert_menu
mov si,[sub_struc]
mov [si+2],ah
cmp al,-3 ;???
jae @@quit_a ;???
push si
mov bl,al
mov bh,0
mov si,bp
call exec_sub_menu
pop si
cmp ax,1
je @@next_menu
@@quit:
pop dx
pop bx
call close_window
@@quit_2:
pop word [sub_coord]
pop word [sub_struc]
pop si
pop dx
pop cx
pop bx
ret
@@quit_a:
neg al
mov ah,0
jmp @@quit
;=============================================================================
; update_hmenu
;-----------------------------------------------------------------------------
; Updates horizontal menu.
; In: DS:SI -> pointer to string list (2nd word in menu structure)
; BX -- number of active item
; CX -- number of items
; Out: ---
; Modf: ---
; Call: pushr, popr
; Use: video_seg
;
update_hmenu:
call pushr
mov si,[si]
mov es,[video_seg]
xor di,di
xor bp,bp
mov ah,atHMenuNorm
mov al,' '
stosw
@@next_point:
mov ah,atHMenuNorm
mov dh,atHMenuNormHot
cmp bx,bp
jne @@1
mov ah,atHMenuSel
mov dh,atHMenuSelHot
@@1:
mov al,' '
stosw
@@next:
lodsb
cmp al,0
je @@end
cmp al,'~'
je @@sw
stosw
jmp @@next
@@sw:
xchg ah,dh
jmp @@next
@@end:
mov al,' '
stosw
inc bp
cmp bp,cx
jb @@next_point
mov cx,160
sub cx,di
shr cx,1
mov al,' '
mov ah,atHMenuNorm
rep stosw
call popr
ret
;=============================================================================
; local_menu
;-----------------------------------------------------------------------------
; Creates local menu.
; In: SI -> menu structure
; Out: CY -- ESC pressed
; NC -- Enter pressed:
; AX -> procedure
; Modf: AX
; Call: pushr, get_cursor, no_cursor, exec_sub_menu, set_cursor, popr
; Use: fake_table
;
local_menu:
call pushr
call get_cursor
push cx
call no_cursor
xor bx,bx ;Current item
mov [fake_table+2],si ;Ptr to submenu struc.
mov si,fake_table
call exec_sub_menu
mov [fake_table+2],ax ;Temp. variable
pop cx
call set_cursor
call popr
mov ax,[fake_table+2]
cmp ax,100h
ret
;=============================================================================
;~ifndef __ACT__
;~ReadString proc
;~ ; Expects: al=x, ah=y, di=@buffer, cl=width, ch=maxlen, si=@title
;~ push bx dx
;~ mov bx,ax
;~ mov dx,ax
;~ add dl,cl
;~ add dl,5
;~ add dh,2
;~ push bx dx
;~ push ax
;~ mov ah,atReadWindow
;~ call OpenWindow
;~ pop ax
;~ mov bl,atReadString
;~ mov bh,atsReadString
;~ call ReadLine
;~ pop dx bx
;~ call CloseWindow
;~ pop dx bx
;~ ret
;~endp
;~endif
;=============================================================================
; read_line
;-----------------------------------------------------------------------------
; Reads line.
; In: AL -- column
; AH -- row
; BL -- color (normal)
; BH -- color (selected)
; CL -- length of string
; CH -- max length of string
; DI -> buffer
; Out: AX -- ASCII/scan codes of key used to exit
; Modf: AX
; Call: pushr, get_addr, get_cursor, small_cursor, strlen, update_string,
; read_key, check_exit_read, set_cursor, gotoxy, popr, [test_char]
; Use: string_changed, read_string_attr, str_start, str_length,
; max_str_length, str_buffer, read_line_cur, read_line_cur_c,
; read_line_result
;
read_line:
call pushr
push cs
pop es
mov byte [string_changed],1
mov [read_string_attr],bx ;word!
add ax,0102h
mov [str_start],ax
push di
call get_addr
pop di
; mov bp,ax
mov [str_length],cl ;byte!
mov [max_str_length],ch ;byte!
mov [str_buffer],di
mov si,di
add si,[max_str_length]
mov byte [si],0
push cx
call get_cursor
mov [read_line_cur],cx
mov [read_line_cur_c],dx
call small_cursor
pop cx
; mov ch,0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -