/* gcc -m32 -nostdlib -nostdinc -Wl,--oformat=binary,-Ttext,0x100 20181028-hsync.s */
	.code16
	n=300
	onesec=75
	nn=15
	.globl _start
_start:	xor	%ax,%ax
	mov	%ax,%ds
	mov	$32768,%bx	# 75Hz timer for 5MHz
	testb	$0x80,0x501
	je	1f
	mov	$26624,%bx	# 75Hz timer for 8MHz
1:	cli
	mov	$0x24,%al
	out	%al,$0x77
	mov	%bh,%al
	out	%al,$0x71
1:	in	$0x71,%al
	cmp	$0,%al
	jne	1b
1:	in	$0x71,%al
	cmp	$0,%al
	je	1b
	mov	$n,%cx
lp:	xor	%bx,%bx
1:	in	$0x71,%al
	cmp	$0,%al
	je	1f
	in	$0x60,%al
	xor	%ah,%al
	test	$0x40,%al
	je	1b
	xor	$0x40,%ah
	jne	1b
	inc	%bx
	jmp	1b
1:	in	$0x71,%al
	cmp	$0,%al
	jne	1f
	in	$0x60,%al
	xor	%ah,%al
	test	$0x40,%al
	je	1b
	xor	$0x40,%ah
	jne	1b
	inc	%bx
	jmp	1b
1:	push	%bx
	loop	lp
	sti
	mov	$n/nn,%cx
1:	mov	$nn,%di
	xor	%ax,%ax
2:	pop	%bx
	add	%bx,%ax
	dec	%di
	jne	2b
	mov	$onesec/nn,%bx
	mul	%bx
	push	%dx
	push	%ax
	mov	$16,%bx
	push	%bx
	call	p
	pop	%bx
	pop	%ax
	pop	%dx
	loop	1b
	int	$0x20
p:	push	%bp
	mov	%sp,%bp
	mov	8(%bp),%ax
	xor	%dx,%dx
	mov	$10,%bx
	div	%bx
	push	%ax
	mov	6(%bp),%ax
	div	%bx
	pop	%bx
	push	%dx
	push	%bx
	push	%ax
	mov	4(%bp),%ax
	dec	%ax
	je	1f
	push	%ax
	call	p
	pop	%ax
1:	pop	%ax
	pop	%ax
	mov	8(%bp),%ax
	or	6(%bp),%ax
	pop	%ax
	jne	1f
	mov	$' '-'0',%al
1:	add	$'0',%al
	int	$0x29
	pop	%bp
	ret
