/ C library -- sleep

/ sleep(quanta);

.globl	_sleep
alarm = 27.
pause = 29.
rti = 2

_sleep:
	mov	r5,-(sp)
	mov	sp,r5

	/catch alarm signal, save old value
	sys	signal; 14.; 1f
	mov	r0,0f

	/start alarm clock
	mov	4(r5),r0
	sys	alarm

	/wait for alarm
	sys	pause

	/clear alarm clock in case
	/return was for some other
	/reason
	clr	r0
	sys	alarm

	/if saved value of signal
	/is not "default (0)", reset
	tst	0f
	beq	2f
	sys	0; 9f

2:
	mov	(sp)+,r5
	rts	pc

	/alarm timeout routine
	/simply return
1:
	rti

.data
9:	sys	signal; 14.; 0:..
