title DoubleDOS Idle Function
name ddidle
include model.ash
include lattice.ash
;
;  Passes control to the other DoubleDOS task 
;for two timer ticks. 
;
;	dbldos();
;
cseg

ddflag db 80h		;-127 = unchecked, 
			;1 = installed,
			;0 = not installed
;
;Pass idle time to the other task.
;
func dbldos
dd0:	cmp	cs:ddflag,0	;test it
	jz	ddz		;0=not present
	jg	dd1		;1=present
	call	ddcheck		;else 1st time
	jmp	dd0		;check presence

dd1:	push	ds
	push	es
	mov	al,2		;# timer ticks,
	int	0feh		;DDOS func
	pop	es
	pop	ds
ddz:
endf dbldos 

;
;Check for the presense of DoubleDOS, set the
;flag accordingly. 
;
ddcheck:
	push	ds
	push	es
	mov	ah,0e4h		;wierd DOS call
	mov	al,0		;seed it,
	xor	bx,bx
	xor	cx,cx
	xor	dx,dx
	int	21h
	pop	es
	pop	ds

	mov	ah,1		;AL=ret code
	dec	al		;AH=presence
	jz	di1		;1,2=present
	dec	al
	jz	di1
	xor	ah,ah
di1:	mov	cs:ddflag,ah
di2:	ret

endc

	end
