include	clib.inc
include	stdio.inc
include	string.inc
include	conio.inc

PPROC	tmsgbox, dname:dword, flag:word
local	dobj:S_DOBJ
local	tobj:S_TOBJ
local	cols:word
local	lcnt:word
local	backgr:byte
	push	si
	push	di
	xor	si,si
	mov	di,offset _bufin
	mov	al,at_background[B_Title]
	mov	backgr,al
	cmp	byte ptr [di],0
	jz	tmsgbox_01
    tmsgbox_00:
	push	ds
	push	di
	push	10
	call	strchr
	jz	tmsgbox_01
	cmp	si,17
	ja	tmsgbox_01
	inc	si
	inc	ax
	mov	di,ax
	jmp	tmsgbox_00
    tmsgbox_01:
	mov	ax,flag
	mov	dobj.dl_flag,ax
	mov	dobj.dl_rect.rc_x,10
	mov	dobj.dl_rect.rc_y,7
	mov     ax,si
	add	al,6
	mov	dobj.dl_rect.rc_row,al
	mov	dobj.dl_rect.rc_col,58
	mov	dobj.dl_count,1
	mov	dobj.dl_index,0
	lea	ax,tobj
	mov	word ptr dobj.dl_object,ax
	mov	word ptr dobj.dl_object+2,ss
	mov	tobj.to_flag,_O_PBUTT
	mov	tobj.to_rect.rc_x,25
	mov     ax,si
	add	al,4
	mov	tobj.to_rect.rc_y,al
	mov	tobj.to_rect.rc_row,1
	mov	tobj.to_rect.rc_col,6
	mov	tobj.to_ascii,'O'
	mov	al,at_background[B_Dialog]
	or	al,at_foreground[F_Dialog]
	test	dobj.dl_flag,_D_STERR
	jz	tmsgbox_02
	mov	at_background[B_Title],70h
	mov	al,at_background[B_Red]
	or	al,at_foreground[F_Gray]
	or	tobj.to_flag,_O_DEXIT
    tmsgbox_02:
	MPUSH	ss
	lea	dx,dobj
	push	dx
	push	ax
	pushm	dname
	call	dlopen
	jnz	tmsgbox_03
	jmp	tmsgbox_error
    tmsgbox_03:
	mov	di,offset _bufin
	mov	si,di
	mov	al,dobj.dl_rect.rc_col
	mov	ah,0
	mov	cols,ax
	mov	lcnt,2
	jmp	tmsgbox_05
    tmsgbox_04:
	mov	byte ptr [si],0
	inc	si
	mov	cx,cols
	mov	al,byte ptr cols
	mov	ah,byte ptr lcnt
	les	bx,dobj.dl_wp
	call	center_text
	mov	di,si
	inc	lcnt
	cmp	lcnt,20
	ja      tmsgbox_modal
    tmsgbox_05:
	cmp	byte ptr [si],0
	je	tmsgbox_modal
	push	ds
	push	di
	push	10
	call	strchr
	mov	si,ax
	jnz	tmsgbox_04
    tmsgbox_modal:
	pushm	dobj.dl_wp
	pushm	tobj.to_rect
	push	cols
	call	rcbprc
	push	dx
	push	ax
	push	cols
	mov	ah,0
	mov	al,tobj.to_rect.rc_col
	push	ax
	MPUSH	ds
	push    offset cp_pushb_ok
	call	wcpbutt
	mov	al,backgr
	mov	at_background[B_Title],al
	mov	cx,cols
	mov	al,byte ptr cols
	mov	ah,byte ptr lcnt
	les	bx,dobj.dl_wp
	call	center_text
	MPUSH	ss
	lea	ax,dobj
	push	ax
	call	dlmodal
    tmsgbox_end:
	pop	di
	pop	si
	ret
    tmsgbox_error:
	xor	ax,ax
	jmp	tmsgbox_end
PEND	tmsgbox

_TEXT	SEGMENT

center_text:
	cmp	byte ptr [di],0
	jz	center_text_00
	mul	ah
	add	ax,3
	add	ax,ax
	add	bx,ax
	sub	cx,8
	mov	dx,ds
	mov	ax,di
	call	@wcenter
    center_text_00:
	ret

_TEXT	ENDS

_DATA	SEGMENT
cp_pushb_ok db	'&Ok',0
_DATA	ENDS

	END
