;
;  IO.MAC - Input/Output Functions
;
;  PAUSE  KEY?  KEY  SPACE  EMIT  TYPE  SPACES  CR  CONSOLE
;  PRINTER
;

;	PAUSE  ( -- )

	hdr	1,'PAUSE'	; multitasking support
pause:	call	aexec
pause1:	dw	0		; patched by COLD

;	KEY?  ( -- flag )	(vkeyq) @execute pause

	hdr	1,'KEY?'
keyq:	call	docol
	dw	lit,vkeyq
	dw	aexec
	dw	pause
	dw	exit

;	KEY  ( -- char )	(vkey) @execute pause

	hdr	1,'KEY'
key:	call	docol
	dw	lit,vkey
	dw	aexec
	dw	pause
	dw	exit

;	SPACE  ( -- )		bl emit

	hdr	1,'SPACE'
space:	ld	l,32
	push	hl
;	jp	emit

;	EMIT  ( char -- )	(vemit) @execute 1 out +! pause

	hdr	1,'EMIT'
emit:	call	docol
	dw	lit,vemit
	dw	aexec
	dw	one,outt,pstor
	dw	pause
	dw	exit

;	TYPE  ( c-addr u -- )	0 ?do count emit loop drop

	hdr	1,'TYPE'
typee:	call	docol
	dw	zero
	dw	xqdo,typee2
typee1:	dw	count,emit
	dw	xloop,typee1
typee2:	dw	drop
	dw	exit

;	SPACES  ( +n -- )	0 max 0 ?do space loop

	hdr	1,'SPACES'
spacs:	call	docol
	dw	zero,max,zero
	dw	xqdo,spacs2
spacs1:	dw	space
	dw	xloop,spacs1
spacs2:	dw	exit

;	CR  ( -- )		(cr) emit (lf) emit out off

	hdr	1,'CR'
crr:	call	docol
	dw	clit
	db	cr
	dw	emit
	dw	clit
	db	lf
	dw	emit
	dw	outt,off
	dw	exit

;	CONSOLE  ( -- ) 	(vcon) @ (vemit) !

	hdr	1,'CONSOLE'	; set EMIT to terminal
consol:	ld	hl,(vcon)
	ld	(vemit),hl
	nextt

;	PRINTER  ( -- ) 	(vlst) @ (vemit) !

	hdr	1,'PRINTER'	; set EMIT to printer
prnt:	ld	hl,(vlst)
	ld	(vemit),hl
	nextt

;	end

