# gcc -nostdlib -nostdinc -Wl,--oformat,binary,-Ttext,0x100 cal2.s -o cal2.com
	.code16
	.global	_start
_start:	mov	$0x80,%si
	xor	%bx,%bx
	xor	%cx,%cx
	xor	%dx,%dx
	cld
	lodsb
	mov	%al,%ah
1:	dec	%ah
	js	err
	lodsb
	cmp	$' ',%al
	je	1b
1:	cmp	$',',%al
	je	1f
	cmp	$'9',%al
	ja	err
	sub	$'0',%al
	jb	err
	mov	%bl,%bh
	mov	%ch,%bl
	mov	%cl,%ch
	mov	%al,%cl
	dec	%ah
	js	err
	lodsb
	jmp	1b
err:	mov	$errarg,%dx
	mov	$9,%ah
	int	$0x21
	ret
1:	dec	%ah
	js	1f
	lodsb
	cmp	$'9',%al
	ja	err
	sub	$'0',%al
	jb	err
	cmp	$1,%dx
	ja	err
	mov	%dl,%dh
	mov	%al,%dl
	jmp	1b
1:	test	%dh,%dh
	je	1f
	add	$10,%dl
1:	dec	%dl
	js	err
	cmp	$11,%dl
	ja	err
	shl	%bh
	and	$2,%bh
	add	%bh,%bl
	and	$3,%bl
	shl	%bl
	add	%bl,%ch
	shl	%bl
	shl	%bl
	add	%bl,%ch
	shr	%ch
	jnc	1f
	add	$10,%cl
1:	mov	$tbl,%bx
	mov	%ch,%al
	xlat
	mov	%al,%dh
	mov	%cl,%ah
	and	$7,%al
	add	%ah,%al
	shr	%ah
	shr	%ah
	add	%al,%ah
	test	%cl,%cl
	jne	1f
	shl	%dh
	sbb	%cl,%cl
1:	test	$3,%cl
	jne	1f
	cmp	$1,%dl
	ja	1f
	add	$13,%dl
1:	mov	%dl,%al
	xlat
	mov	$4,%cl
	shr	%cl,%al
	and	$7,%al
	add	%ah,%al
1:	cmp	$7,%al
	jb	1f
	sub	$7,%al
	jmp	1b
1:	xchg	%dl,%al
	inc	%ax
	xlat
	shr	%cl,%al
	and	$7,%al
	add	%ah,%al
1:	cmp	$7,%al
	jb	1f
	sub	$7,%al
	jmp	1b
1:	mov	%al,%bh
	mov	%dl,%bl
	mov	$hdr,%dx
	mov	$9,%ah
	int	$0x21
	mov	$0xfa00,%cx
1:	cmp	%cl,%bl
	je	1f
	mov	$buf,%dx
	mov	$9,%ah
	int	$0x21
	inc	%cx
	jmp	1b
3:	cmp	%cl,%bh
	je	4f
	inc	%bx
	jmp	5f
4:	movw	$0x2020,-1(%di)
	jmp	2f
1:	mov	$buf+2,%di
	movb	$0x30,(%di)
	mov	$28,%bl
2:	dec	%bl
	js	1f
	je	3b
5:	incb	(%di)
	cmpb	$0x3a,(%di)
	jne	1f
	orb	$0x30,-1(%di)
	addw	$0xf601,-1(%di)
1:	mov	$buf,%dx
	mov	$9,%ah
	int	$0x21
	inc	%cl
	cmp	$7,%cl
	jb	2b
	mov	$crlf,%dx
	mov	$9,%ah
	int	$0x21
	add	$0xf9,%cx
	jne	2b
	ret
errarg:	.ascii	"Bad parameter\r\n$"
hdr:	.ascii	"Sun Mon Tue Wed Thu Fri Sat"
crlf:	.ascii	"\r\n$"
buf:	.ascii	"    $"
tbl:	.byte	0x00
	.byte	0x34
	.byte	0x31
	.byte	0x65
	.byte	0x12
	.byte	0xc5
	.byte	0x62
	.byte	0x26
	.byte	0x53
	.byte	0x00
	.byte	0xb3
	.byte	0x50
	.byte	0x14
	.byte	0x61
	.byte	0x25
	.byte	0xb1
	.byte	0x65
	.byte	0x12
	.byte	0x46
	.byte	0x63
