	section text,code

	include "LVO3.0/exec_lib.i"
	include "LVO3.0/graphics_lib.i"
	include "LVO3.0/intuition_lib.i"
	include "exec/execbase.i"
	include "graphics/gfxbase.i"

	xref	_SysBase

	xdef	_FlushAll
	xdef	_EmptyMsgPort

_EmptyMsgPort:
	move.l	_SysBase,a6
	move.l	d2,-(sp)
.loop
	jsr	_LVOGetMsg(a6)
	tst.l	d0
	beq	.end
	move.l	d0,a1
	jsr	_LVOReplyMsg(a6)
	move.l	d2,a0
	bra.s	.loop
.end
	move.l	(sp)+,d2
	rts

_FlushAll:
	move.l	d2,-(sp)
	move.l	_SysBase,a6
	jsr	_LVOForbid(a6)
	move.l	LibList(a6),a1
	move.w	#_LVORemLibrary,d2
	bsr.s	.remall

	move.l	DeviceList(a6),a1
	move.w	#_LVORemDevice,d2
	bsr.s	.remall

	lea	gfxname,a1
	moveq	#0,d0
	jsr	_LVOOpenLibrary(a6)
	move.l	d0,a6
	move.l	gb_TextFonts(a6),a1
	move.w	#_LVORemFont,d2
	bsr.s	.remall
	move.l	a6,a1
	move.l	_SysBase,a6
	jsr	_LVOCloseLibrary(a6)
	jsr	_LVOPermit(a6)
	move.l	(sp)+,d2
	rts

.remloop
	jsr	0(a6,d2.w)
	move.l	(a1),a1
.remall
	tst.l	(a1)
	beq.b	.remloop
	rts

	cnop	0,2
gfxname
	dc.b	"graphics.library",0

	end
