*=======================================================*
*	System routines modified from BAD MOOD		*
*=======================================================*

	xdef		_appl_init,_appl_exit,_vq_extnd,_vq_color


* int ap_id = appl_init(void);
* 1 word to int_out
*
_appl_init:
	move.l		#int_out,aes_int_out_addr
	lea		control,a0
	move.w		#10,(a0)+
	move.w		#0,(a0)+
	move.w		#1,(a0)+
	move.w		#0,(a0)+
	move.w		#0,(a0)+
	bsr		AES
	move.w		int_out,d0
	rts

* int status = appl_exit(void);
* 1 word to int_out
*
_appl_exit:
	move.l		#int_out,aes_int_out_addr
	lea		control,a0
	move.w		#19,(a0)+
	move.w		#0,(a0)+
	move.w		#1,(a0)+
	move.w		#0,(a0)+
	move.w		#0,(a0)+
	clr.w		int_out
	bsr		AES
.wait:	move.w		int_out,d0
	beq.s		.wait
	rts

	ifne 0
* handle = graf_handle();
*
graf_handle:
	lea		control,a0
	move.w		#77,(a0)+
	move.w		#0,(a0)+
	move.w		#5,(a0)+
	move.w		#0,(a0)+
	move.w		#0,(a0)+
	bsr		AES
	move.w		int_out,d0
	rts

* handle = v_opnvwk();
*
v_opnvwk:
	lea		control,a0
	move.w		#100,(a0)+
	move.w		#0,(a0)+
	move.w		#6,(a0)+
	move.w		#11,(a0)+
	move.w		#45,(a0)+
	move.w		#0,(a0)+
	move.w		handle,(a0)+
	lea		int_in,a0
	moveq		#1,d0
	move.w		d0,(a0)+
	move.w		d0,(a0)+
	move.w		d0,(a0)+
	move.w		d0,(a0)+
	move.w		d0,(a0)+
	move.w		d0,(a0)+
	move.w		d0,(a0)+
	move.w		d0,(a0)+
	move.w		d0,(a0)+
	move.w		d0,(a0)+
	move.w		#2,(a0)+
	bsr		VDI
	move.w		control+12,vhandle
	lea		int_out,a0
	move.w		(a0)+,d1
	move.w		(a0)+,d2
	addq.w		#1,d1
	addq.w		#1,d2
	move.w		d1,vwork_w
	move.w		d2,vwork_h
	rts
	endc

* void vq_extnd(int handle, int info_flag, int *int_out, int *pts_out);
*
_vq_extnd:
	move.l		#int_in,vdi_int_in_addr
	move.l		#pts_in,vdi_pts_in_addr
	lea		control,a0
	move.w		#102,(a0)+
	move.w		#0,(a0)+
	move.w		#6,(a0)+
	move.w		#1,(a0)+
	move.w		#45,(a0)+
	move.w		#0,(a0)+
	move.l		4(a7),d0
	move.w		d0,(a0)+
	move.l		8(a7),d0
	move.w		d0,int_in
	move.l		12(a7),vdi_int_out_addr
	move.l		16(a7),vdi_pts_out_addr
	bsr		VDI
	rts

* void vq_color(int handle, int colour, int flag, int *int_out);
*
_vq_color:
	move.l		#int_in,vdi_int_in_addr
	move.l		#pts_in,vdi_pts_in_addr
	move.l		#pts_out,vdi_pts_out_addr
	lea		control,a0
	move.w		#26,(a0)+
	move.w		#0,(a0)+
	move.w		#0,(a0)+
	move.w		#2,(a0)+
	move.w		#4,(a0)+
	move.w		#0,(a0)+
	move.l		4(a7),d0
	move.w		d0,(a0)+
	move.l		8(a7),d0
	move.w		d0,int_in
	move.l		12(a7),d0
	move.w		d0,int_in+2
	move.l		16(a7),vdi_int_out_addr
	bsr		VDI
	rts

	ifne	0
v_clsvwk:
	lea		control,a0
	move.w		#101,(a0)+
	move.w		#0,(a0)+
	move.w		#0,(a0)+
	move.w		#0,(a0)+
	move.w		#0,(a0)+
	move.w		#0,(a0)+
	move.w		vhandle,(a0)+
	bsr		VDI
	rts
	endc

AES:	movem.l		d2/a2,-(a7)	; Necessary?
	move.l		#aespb,d1
	move.w		#200,d0
	trap		#2	
	movem.l		(a7)+,d2/a2
	rts

VDI:	movem.l		d2/a2,-(a7)	; Necessary?
	move.l		#vdipb,d1
	moveq		#115,d0
	trap		#2	
	movem.l		(a7)+,d2/a2
	rts


	data

vdipb:
vdi_control_addr:	dc.l	control
vdi_int_in_addr:	dc.l	int_in
vdi_pts_in_addr:	dc.l	pts_in
vdi_int_out_addr:	dc.l	int_out
vdi_pts_out_addr:	dc.l	pts_out

aespb:
aes_control_addr:	dc.l	control
aes_global_addr:	dc.l	global
aes_int_in_addr:	dc.l	int_in
aes_int_out_addr:	dc.l	int_out
aes_addr_in_addr:	dc.l	addr_in
aes_addr_out_addr:	dc.l	addr_out


	bss

control:
opcode:			ds.w	1
sintin:			ds.w	1
sintout:		ds.w	1
saddrin:		ds.w	1
saddrout:		ds.w	1
			ds.w	6

global:
apversion:		ds.w	1
apcount:		ds.w	1
apid:			ds.w	1
apprivate:		ds.l	1
apptree:		ds.l	1
ap1resv:		ds.l	1	
ap2resv:		ds.l	1
ap3resv:		ds.l	1
ap4resv:		ds.l	1

int_in:			ds.w	16
pts_in:			ds.w	8
int_out:		ds.w	4
pts_out:		ds.w	4
addr_in:		ds.l	4
addr_out		ds.l	4

	end