' INPUT.INC:	Some input routines that make life easier.
'
' version:		6-25-84
' compiler:		Structured BASIC v1.12
' uses:			nothing
' module type:	include
'
' To use the routines in this file, you must have the statement
'
'		include INPUT.INC
'
' in your program.  Prior to using any of these procedures, use 
' the statement
'
'		do INITIALIZE.INPUT
'
' You can change the variable IN.CHAR$ anytime to need to check for
' different legal characters, such as digits-only.  You shouldn't
' need to change the cursor blink value except if you compile.

procedure INITIALIZE.INPUT		'Initialize cursor and proof string
	IN.CHAR$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 "
	IN.BLINK = 5 : IN.CURCNT = IN.BLINK
endproc

procedure GET.YES.OR.NO			'Get a yes or no answer from user
    'ANSWER contains either YES (1) or NO (0) on exit.
    IN.GOTIT = 0 : YES = 1 : NO = 0
    repeat
		do IN.GET.KEY
		if IN.KEY$ = "Y"
			IN.GOTIT = 1
			ANSWER = YES
		elseif IN.KEY$ = "N"
			IN.GOTIT = 1
			ANSWER = NO
		endif
	until IN.GOTIT = 1
endproc

procedure GET.STRING			'Get string from keyboard
	IN.INPUT$ = ""
	IN.START.COL = pos(0)
	repeat
		do IN.GET.KEY
		if IN.KEY$ = chr$(13) break
		if IN.KEY$ = chr$(8)
			do IN.DEL.CHAR
		elseif INSTR(IN.CHARS$,IN.KEY$) > 0
			do IN.INS.CHAR
		else
			beep
		endif
	until 1 = 0
endproc

procedure IN.GET.KEY	 		'Get uppercase key from keyboard
	repeat
		do IN.CURSOR
		IN.KEY$ = INKEY$
	until LEN(IN.KEY$) > 0
	if asc(IN.KEY$) > 96 and asc(IN.KEY$) < 123
		IN.KEY$ = chr$(asc(IN.KEY$) - 32)
	endif
endproc

procedure IN.INS.CHAR			'Add char to end of input string
	print IN.KEY$;
	IN.INPUT$ = IN.INPUT$ + IN.KEY$
endproc

procedure IN.DEL.CHAR			'Handle backspace key in input
	IN.CUR.COL = pos(0)
	if IN.CUR.COL > IN.START.COL
		IN.INPUT$ = LEFT$(IN.INPUT$,LEN(IN.INPUT$)-1)
		print " ";
		locate ,IN.CUR.COL-1
	else
		beep
	endif
endproc

procedure IN.CURSOR				'Simulate BASIC cursor
	if IN.CURCNT = IN.BLINK
		if IN.CURCHAR$ = chr$(&H5F)
			IN.CURCHAR$ = " "
		else
			IN.CURCHAR$ = chr$(&H5F)
		endif
		IN.CURCNT = 0
	endif
	print IN.CURCHAR$;
	IN.CURCNT = IN.CURCNT + 1
	locate ,pos(0)-1
endproc
