include libmacro.inc

beglib	'crt'


item	'clrscr','*'
	push	ax
	mov	ax, 03h
	int	10h
	pop	ax

item	'readkey','*'
	push	ax
	mov	ah, 0
	int	16h
	xor	ah, ah

item	'scancode','*'
	push	ax
	mov	ah, 0
	int	16h
	mov	al, ah
	xor	ah, ah

item	'clrkbdbuf','*'
	cli
	sub	bx, bx
	mov	es, bx
	mov	bl, es:[041Ah]
	mov	es:[041Ch], bl
	sti

item	'keypressed','*'
;	cli
;	push	ax
;	sub	ax, ax
;	mov	es, ax
;	mov	al, es:[041Ah]
;	mov	ah, es:[041Ch]
;	cmp	ah, al
;	setne	al
;	sti

	push	ax
	mov	ah, 01
	int	16h
	setnz	al

item	'cursoroff','*'
	push	ax
	mov     ah, 03h         ; BIOS INT 10 func 3 (Get Cursor pos)}
	int     10h             ; Call INT 10}
	or      ch, 0100000b    ; Turn on cursor bit}
	mov     ah, 01h         ; BIOS INT 10 func 1 (Set cursor type)}
	int     10h             ; Call INT 10}
	pop	ax

item	'cursoron','*'
	push	ax
	mov     ah, 03h         ; BIOS INT 10 func 3 (Get Cursor pos)}
	int     10h             ; Call INT 10}
	and     ch, 1011111b    ; Turn off cursor bit}
	mov     ah, 01h         ; BIOS INT 10 func 1 (Set cursor type)}
	int     10h             ; Call INT 10}
	pop	ax

item	'delay','*'
	mov	bx, ax
	mov	ah, 0
	int	1Ah
	add	bx, dx
d_:	int	1Ah
	cmp	dx, bx
	jl	d_
	pop	ax

item	'sound',0,0,0

		xchg		ax, bx
                cmp             bx,21
                jnc             sound_ok
                mov             bx,21
                sound_ok:
                mov             al,0b6h
                out             43h,al
                mov             dx,14h
                mov             ax,4f38h
                div             bx
                out             42h,al
                mov             al,ah
                out             42h,al
                in              al,61h
                or              al,3
                out             61h,al
		pop		ax

	item	'nosound',0,0,0
		push		ax
		in              al,61h
                and             al,0fch
                out             61h,al	
		pop		ax
endlib