include	clib.inc
include	io.inc
include errno.inc
include string.inc

PPROC	perror, string:DPTR
	MMOV	dx,word ptr string+2
	mov	bx,word ptr string
	mov	ax,bx
	or	ax,dx
	jz	perror_00
	mov	es,dx
	mov	al,es:[bx]
	or	al,al
	jz	perror_00
	push	2
	MPUSH	dx
	push	bx
	MPUSH	dx
	push	bx
	call	strlen
	push	ax
	call	write
	push	2
	MPUSH	ds
	push	offset seperator
	push	2
	call	write
    perror_00:
	push	2
	MPUSH	ds
	mov	bx,errno
	add	bx,bx
  ifdef LDATA
	add	bx,bx
  endif
	add	bx,offset sys_errlist
	mov	ax,[bx]
	push	ax
	MPUSH	ds
	push	ax
	call	strlen
	push	ax
	call	write
	push	2
	MPUSH	ds
	push	offset newline
	push	1
	call	write
	ret
PEND	perror

_DATA	SEGMENT
seperator db ": ",0
newline	  db 13,0
_DATA	ENDS

	END
