NEW
PREFIX
AUTO 4,1
				.LIST OFF
				.OP	65C02
				.OR	$2000
				.TF SBIN/LOGIN
*--------------------------------------
				.INB INC/MACROS.I
				.INB INC/A2OSX.I
*--------------------------------------
				.DUMMY
				.OR ZPBIN
ZS.START
ZPPTR1			.BS 2
ZS.END
				.ED
*--------------------------------------
INPUT.BUF.SIZE	.EQ 16				
*--------------------------------------
*			File Header (16 Bytes)
*--------------------------------------
CS.START		cld
				jmp (.1,x)
				.DA #$61				6502,Level 1 (65c02)
				.DA #1					BIN Layout Version 1
				.DA #S.PS.F.EVENT		S.PS.F
				.DA #0
				.DA CS.END-CS.START		Code Size (without Constants)
				.DA DS.END-DS.START		Data SegmentSize
				.DA #16					Stack Size
				.DA #ZS.END-ZS.START	Zero Page Size
				.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1				.DA CS.INIT
				.DA CS.RUN
				.DA CS.DOEVENT
				.DA	CS.QUIT
L.MSG.NOPASSWD	.DA MSG.NOPASSWD				
L.MSG.LOGIN		.DA MSG.LOGIN
L.MSG.PASSWORD	.DA MSG.PASSWORD
L.MSG.ECHOCRLF	.DA MSG.ECHOCRLF
L.MSG.ECHODEL	.DA MSG.ECHODEL
L.ENV.SHELL		.DA ENV.SHELL
L.SHELL			.DA SHELL
L.ENV.HOME		.DA ENV.HOME
L.HOME			.DA HOME
				.DA 0
*--------------------------------------
CS.INIT			clc
				rts
*--------------------------------------
CS.RUN			>PUSHEA.G PW
				lda #0
				>SYSCALL GetPWUID
				bcc .10
				
				>PUSHBI 0
				>LDYA L.MSG.NOPASSWD
				>SYSCALL printf
				bcs .9
				bra .8
				
.10				>STZ.G INPUT.PrevCR

				>PUSHBI 0
				>LDYA L.MSG.LOGIN
				>SYSCALL printf
				bcs .9
				
				lda #0					Echo all caracters
				jsr INPUT.RESET

.1				>SYSCALL GetChar
				bcs .9
				
				jsr INPUT.CHARIN
				jsr INPUT.LINEIN
				bcc .1
				
				>PUSHBI 0
				>LDYA L.MSG.PASSWORD
				>SYSCALL printf
				bcs .9
				
				lda #'*'
				jsr INPUT.RESET
				
.2				>SYSCALL GetChar
				bcs .9
				
				jsr INPUT.CHARIN
				jsr INPUT.LINEIN
				bcc .2
				
				>PUSHBI 0
				>LDYA L.MSG.ECHOCRLF
				>SYSCALL printf
				bcs .9
				
.8				jsr CS.RUN.SETENV
				bcs .9
				
				>PUSHBI S.PS.F.HOLD+S.PS.F.DUPENV
				>LDYA L.SHELL
				>SYSCALL ExecL
.9				rts
*--------------------------------------
CS.RUN.SETENV	>PUSHW L.HOME
				>LDYA L.ENV.HOME
				>SYSCALL setenv
				bcs .9
				
				>PUSHW L.SHELL
				>LDYA L.ENV.SHELL
				>SYSCALL setenv
				bcs .9
				
				
				
.9				rts	
*--------------------------------------
CS.DOEVENT		
				sec
				rts		
*--------------------------------------
CS.QUIT			clc
				rts
*--------------------------------------
*				PRIVATE
*--------------------------------------
INPUT.RESET		>STA.G INPUT.PassChar

				>STZ.G INPUT.BUF
				>STA.G INPUT.Status
				rts
*--------------------------------------
INPUT.CHARIN	tax						save char...

				>LDA.G INPUT.Status
				bmi .9
				
				lda #INPUT.BUF
				clc
				adc pData
				sta ZPPTR1
				lda pData+1
				adc /INPUT.BUF
				sta ZPPTR1+1
				
				cpx #$20				Control Char?
				bcc .2
				
				cpx #C.DEL
				beq INPUT.CHARIN.DEL
				
				lda (ZPPTR1)
				
				cmp	#INPUT.BUF.SIZE		Buffer full?
				beq .9
				
				inc
				sta (ZPPTR1)
				tay
				
				txa
				sta (ZPPTR1),y
				
				>LDA.G INPUT.PassChar
				bne .1
				
				txa
				
.1				>SYSCALL PutChar
				bcs .9
				
				>STZ.G INPUT.PrevCR
				rts
				
.2				cpx #C.CR
				bne .3

				txa
				>STA.G INPUT.PrevCR
				
				lda #$80
				>STA.G INPUT.Status
				rts
				
.3				cpx #C.LF
				bne .4
				
				>LDA.G INPUT.PrevCR
				beq .1
				
.4				>STZ.G INPUT.PrevCR
				
.9				rts				
*--------------------------------------
INPUT.CHARIN.DEL
				lda (ZPPTR1)
				beq .8
				
				dec
				sta (ZPPTR1)
				
				>PUSHBI 0
				>LDYA L.MSG.ECHODEL
				>SYSCALL printf
				
.8				clc
				rts
*--------------------------------------
INPUT.LINEIN	ldy #INPUT.Status
				lda (pData),y
				asl						CS if a line is in the buffer
				rts
*--------------------------------------
CS.END
MSG.NOPASSWD	.AS "\r\n\r\nA2osX-Login:No ETC/PASSWD file present, Logged as ROOT.\r\n"
				.AZ "Consider adding ROOT password with USERADD command.\r\n\r\n"
MSG.LOGIN		.AZ "\r\nlogin:"
MSG.PASSWORD	.AZ "\r\npassword:"
MSG.ECHOCRLF	.AZ "\r\n"
MSG.ECHODEL		.DA #C.BS,#C.SPACE,#C.BS,#0
ENV.SHELL		.AZ "SHELL"
ENV.HOME		.AZ "HOME"
SHELL			.AZ "${ROOT}BIN/SH"
HOME			.AZ "${ROOT}ROOT/"
				.HS 00
*--------------------------------------
				.DUMMY
				.OR 0
DS.START
INPUT.BUF		.BS INPUT.BUF.SIZE+1
INPUT.Status	.BS 1
INPUT.PassChar	.BS 1
INPUT.PrevCR	.BS 1
PW				.BS S.PW
DS.END
				.ED
*--------------------------------------
MAN
SAVE USR/SRC/SBIN/LOGIN.S
ASM
