NEW
  AUTO 3,1
*--------------------------------------
HIS.Init		>LDYAI HISBUF.MAX		Get a buffer for History

				>SYSCALL StrVNew
				bcs .9

				>STA.G HIS.hBuf

*				>STZ.G HIS.Count
*				>STZ.G HIS.Head
*				clc

.9				rts
*--------------------------------------
HIS.Add			>LDA.G HIS.hBuf
				beq .9

				>LDA.G HIS.Count
				cmp #HISCNT.MAX
				bcs .1

				inc
				sta (pData),y

				>STA.G HIS.Head
				bra .2

.1				ldy #HIS.Head
				jsr HIS.NextY			replace oldest
				sta (pData),y

.2				tax

				>PUSHB.G HIS.hBuf
				>PUSHBI 0
				txa
				>PUSHA
				>PUSHW ZPCLBuf
				>SYSCALL StrVSet

.9				rts
*--------------------------------------
HIS.Select		>LDA.G HIS.Count
				bne .10

				clc
.99				rts

.10				jsr CL.Reset

				ldx #0

.1				inx
				phx
				jsr HIS.GetX
				plx
				bcs .99

				>PUSHW L.MSG.HIS
				txa
				dec
				>PUSHA
				>PUSHW ZPCLBuf
				>PUSHBI 3
				phx
				>SYSCALL PrintF
				plx
				bcs .9

				txa
				>CMP.G HIS.Count
				bne .1

				>LDYA L.MSG.HISPROMPT
				jsr IO.OutYA
				bcs .9

				lda #0
				sta (ZPCLBuf)

				ldy #HIS.Ptr
				sta (ZPCLBuf),y

				>SYSCALL GetChar
				bcs .9

				cmp #'0'
				bcc .7

				cmp #'9'+1
				bcs .7

				and #$f
				inc
				>STA.G HIS.Ptr

.7				>LDYA L.MSG.HISROMPTCLR
				jsr IO.OutYA
				bcs .9

				jsr CL.PrintPrompt
				bcc HIS.GetToCL1
.9
HIS.Select.RTS	rts
*--------------------------------------
HIS.GetPrev		>LDA.G HIS.Count
				beq HIS.Select.RTS		empty history,nothing to do

				>LDA.G HIS.Ptr
				bne .1

				>LDA.G HIS.Head			Get newest
				bra HIS.GetToCL

.1				dec
				bne .2

				>LDA.G HIS.Count

.2				bra HIS.GetToCL
*--------------------------------------
HIS.GetNext		>LDA.G HIS.Count
				beq HIS.Select.RTS		empty history,nothing to do

				>LDA.G HIS.Ptr
				bne .1

				ldy #HIS.Head

.1				jsr HIS.NextY
*--------------------------------------
HIS.GetToCL		>STA.G HIS.Ptr

				jsr CL.CLR.1

HIS.GetToCL1	>LDA.G HIS.Ptr
				beq .9

				tax
				jsr HIS.GetX
				bcs .9

				ldy #$ff

.1				iny
				lda (ZPCLBuf),y
				bne .1

				tya

				>STA.G CL.Ptr
				>STA.G CL.Len

				>LDYA ZPCLBuf
				jmp IO.OutYA

.9				rts
*--------------------------------------
HIS.GetX		>PUSHB.G HIS.hBuf
				>PUSHBI 0
				txa
				>PUSHA
				>PUSHW ZPCLBuf
				>SYSCALL StrVGet
				rts
*--------------------------------------
HIS.NextY		lda (pData),y

				phy
				>CMP.G HIS.Count
				ply

				bcc .1

				lda #0

.1				inc

				rts
*--------------------------------------
MAN
SAVE usr/src/bin/sh.s.his
LOAD usr/src/bin/sh.s
ASM
