* Swellfish.sysとのインターフェース
* Oh!X 1995/11 p95-96
*
*	int	lazyupdate_open(unchar *mem,size_t memsiz);
*	int	lazyupdate_flush(void);
*	int	lazyupdate_close(void);
*	size_t	lazyupdate_calc(short nbuff);
*	int	lazyupdate_exist(void);
*
	.include	doscall.mac

	* for Assembler
	.xdef	lazyupdate_open
	.xdef	lazyupdate_flush
	.xdef	lazyupdate_close
	.xdef	lazyupdate_calc
	.xdef	lazyupdate_exist
	* for C
	.xdef	_lazyupdate_open
	.xdef	_lazyupdate_flush
	.xdef	_lazyupdate_close
	.xdef	_lazyupdate_calc
	.xdef	_lazyupdate_exist
*
CALC	equ	-4
OPEN	equ	0
FLUSH	equ	4
CLOSE	equ	8
*
CALL	macro	CALLNO
	.if	CALLNO.slt.0
	subq.l	#-CALLNO,(sp)
	.elseif	CALLNO.sgt.0
	add.l	#CALLNO,(sp)
	.endif
	DOS	_SUPER_JSR
	.endm
*
	.offset	4
MEM:	.ds.l	1
MEMSIZ:	.ds.l	1
*
	.offset	4
	.ds.w	1
NBUFF:	.ds.w	1
*
	.text
	.even
*
jumptable:	.dc.l	-1
*
lazyupdate_open:
_lazyupdate_open:
SAVREGS	reg	d1/a0
SAVSIZ	=	(1+1)*4
	movem.l	SAVREGS,-(sp)
	move.l	jumptable(pc),d0
	bpl	open
	bsr	getjumptable
	bmi	openretn
open:	move.l	d0,-(sp)
	DOS	_GETPDB
	movea.l	MEM+SAVSIZ+4(sp),a0
	move.l	MEMSIZ+SAVSIZ+4(sp),d1
	CALL	OPEN
	addq.l	#4,sp
openretn:
	movem.l	(sp)+,SAVREGS
	rts
*
lazyupdate_flush:
_lazyupdate_flush:
	move.l	jumptable(pc),d0
	bpl	flush
	bsr	getjumptable
	bmi	flushretn
flush:	move.l	d0,-(sp)
	CALL	FLUSH
	addq.l	#4,sp
flushretn:
	rts
*
lazyupdate_close:
_lazyupdate_close:
	move.l	jumptable(pc),-(sp)
	bmi	closeretn
	DOS	_GETPDB
	CALL	CLOSE
closeretn:
	addq.l	#4,sp
	rts
*
lazyupdate_calc:
_lazyupdate_calc:
	move.l	jumptable(pc),d0
	bpl	calc
	bsr	getjumptable
	bmi	calcerror
calc:	move.l	d0,-(sp)
	move.w	NBUFF+4(sp),d0
	CALL	CALC
	addq.l	#4,sp
	rts
*
calcerror:
	moveq.l	#0,d0
	rts
*
lazyupdate_exist:
_lazyupdate_exist:
getjumptable:
	move.l	d1,-(sp)
	moveq.l	#0,d1
	move.w	d1,-(sp)
	pea.l	devname(pc)
	DOS	_OPEN
	move.w	d0,d1
	bmi	getretn
	*
	move.l	d1,(sp)
	DOS	_IOCTRL
	andi.w	#$4084,d0
	cmpi.w	#$4084,d0
	bne	getclose
	*
	pea.l	4.w
	pea.l	jumptable(pc)
	move.l	d1,-(sp)
	addq.w	#2,(sp)
	DOS	_IOCTRL
	lea.l	12(sp),sp
getclose:
	move.w	d1,(sp)
	DOS	_CLOSE
getretn:
	addq.l	#6,sp
	movem.l	(sp)+,d1
	move.l	jumptable(pc),d0
	rts
*
devname:
	.dc.b	'@FUGU',0
	.end
