include	clib.inc
include	dos.inc
include	syserrls.inc
include	conio.inc
include	errno.inc

_DATA	SEGMENT

	EXTRN	IDD_SystemError:DWORD

RECT_X	EQU	14
RECT_Y	EQU	5
RECT_C	EQU	53
RECT_R	EQU	15

DOBJ	DW	001Dh
	DB	4,3
DOBJX	DB	RECT_X
DOBJY	DB	RECT_Y
	DB	RECT_C
	DB	RECT_R
DLWP	DD	?
	DD	_DATA:ID_IGNORE

ID_IGNORE	DW _O_PBUTT
		DB 0,'C',4,6,13,1
		DD ?,?
ID_RETRY	DW _O_PBUTT
		DB 0,'R',4,8,13,1
		DD ?,?
ID_TERMINATE	DW _O_PBUTT
		DB 0,'T',4,10,13,1
		DD ?,?
ID_FAIL		DW _O_PBUTT
		DB 0,'A',4,12,13,1
		DD ?,?

CP_ERONDEVICE	DB 'Error on device:',0
CP_ERMEMORY	DB 'Memory error:',0
CP_ERBLOCKDEV	DB 'Block Device Error:',0
CP_ERDRIVE	DB 'Error on drive A:',0
CP_ERDISKAREA	DB 'Disk area of error:',0
CP_DISKAREA	DB 'DOS FAT ROOTDATA'

_DATA	ENDS

_TEXT	SEGMENT

systemerror proc dist pascal public uses dx cx bx es si di
local	WP[1680]:BYTE
	xor	di,di
	push	ss
	lea	ax,WP
	push	ax
	mov	WORD PTR DLWP,ax
	mov	WORD PTR DLWP+2,ss
	push	ds
	mov	ax,word ptr IDD_SystemError
	add	ax,5*8+2
	push	ax
	push	RECT_C*RECT_R
	call	wcunzip
	mov	DOBJ,_D_DOPEN or _D_MYBUF or _D_SHADE or _D_DMOVE
	mov	DOBJX,RECT_X
	mov	DOBJY,RECT_Y
	mov	DOBJ.dl_index,3
	push	ds
	push	OFFSET DOBJ
	call	dlshow
	mov	al,sys_erflag
	test	al,20h
	jz	systemerror_00
	mov     ID_IGNORE,_O_PBUTT
    systemerror_00:
	test	al,10h
	jz	systemerror_01
	mov     ID_RETRY,_O_PBUTT
    systemerror_01:
       test	al,08h
	jz	systemerror_02
	mov     ID_FAIL,_O_PBUTT
    systemerror_02:
	mov	dx,ds
	test	al,80h
	jz	systemerror_04
	les	bx,sys_erdevice
	test	BYTE PTR es:[bx+5],80h
	jz	systemerror_03
	mov	di,OFFSET CP_ERONDEVICE
	mov	dx,WORD PTR sys_erdevice+2
	mov	ax,WORD PTR sys_erdevice
	add	ax,10
	mov	bh,RECT_Y+2
	mov	bl,RECT_X+21
	mov	cl,7
	jmp	systemerror_05
    systemerror_03:
	mov	di,OFFSET CP_ERMEMORY
	test	BYTE PTR sys_erflag,02h
	jnz	systemerror_06
	mov	di,OFFSET CP_ERBLOCKDEV
	jmp	systemerror_06
    systemerror_04:
	mov	di,OFFSET CP_ERDRIVE
	mov	al,sys_erdrive
	add	al,'A'
	mov	[di+15],al
	mov	bh,RECT_Y+3
	mov	bl,RECT_X+4
	xor	cx,cx
	mov	ax,OFFSET CP_ERDISKAREA
	call	@scputs
	mov	al,sys_erflag
	and	ax,6
	add	ax,ax
	add	ax,OFFSET CP_DISKAREA
	mov	bl,RECT_X+24
	mov	cl,4
    systemerror_05:
	call	@scputs
    systemerror_06:
	mov	ax,OFFSET CP_UNKNOWN
	mov	dx,sys_ercode
	cmp	dx,20
	ja	systemerror_07
	shl	dx,DPTRZ/2
	mov	bx,dx
	mov	ax,WORD PTR [bx+dos_errlist]
    systemerror_07:
	mov	dx,ds
	mov	bh,RECT_Y+4
	mov	bl,RECT_X+4
	mov	cx,RECT_C-8
	cmp	di,OFFSET CP_ERDRIVE
	jne	systemerror_08
	mov	bh,RECT_Y+2
	mov	bl,RECT_X+24
	mov	cl,RECT_C-27
    systemerror_08:
	call	@scputs
	mov	bh,RECT_Y+2
	mov	bl,RECT_X+4
	mov	ax,di
	call	@scputs
	xor	ax,ax
	mov	sys_ercode,ax
	mov	sys_erflag,al
	mov	sys_erdrive,al
	push	10
	push	9
	call	beep
	push	ds
	push	OFFSET DOBJ
	call	dlmodal
	test	ax,ax
	mov	dx,3
	jz	systemerror_09
	dec	ax
	mov	dx,ax
    systemerror_09:
	mov	ax,dx
	ret
systemerror endp

_TEXT	ENDS

	END
