PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
				.LIST OFF
				.OP	65C02
				.OR	$2000
				.TF /A2OSX.BOOT/BIN/RM
*--------------------------------------
				.INB INC/MACROS.I
				.INB INC/A2OSX.I
*--------------------------------------
ZPPtr1			.EQ ZPBIN
ZPPtr2			.EQ ZPBIN+2
*--------------------------------------
*			File Header (16 Bytes)
*--------------------------------------
CS.START		cld
				jmp (.1,x)
				.DA #$61				6502,Level 1 (65c02)
				.DA #1					BIN Layout Version 1
				.DA 0
				.DA CS.END-CS.START		Code Length To Relocate
				.DA DS.END-DS.START		Data Segment to Allocate
				.DA 0
				.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1				.DA CS.INIT
				.DA CS.RUN
				.DA CS.DOEVENT		
				.DA	CS.QUIT
L.MSG.USAGE		.DA MSG.USAGE
L.MSG.OK		.DA MSG.OK
L.MSG.ERR		.DA MSG.ERR
L.FullPath		.DA FullPath				
				.DA 0
*--------------------------------------
CS.INIT			>SYSCALL SYS.GetArgC
				cmp #1
				bne .99

				lda #1
				>SYSCALL SYS.GetArgA
				>SYSCALL SYS.GetFullPathYA
				stx hFullPath
				
				>SYSCALL SYS.ListDirInitYA
				bcs .98
				ldy #hS.LISTDIR
				sta (pData),y
				
				jsr .98
				
				lda (pPs)
				ora #S.PS.F.EVENT		Now accept events
				sta (pPs)
				clc
				rts
				
.98				pha
				lda hFullPath
				>SYSCALL SYS.FreeMemA
				pla
				sec
				rts
				
.99				>LDYA L.MSG.USAGE
				>SYSCALL SYS.PStrOutYA
				lda #SYSMGR.ERRSYN
				sec
				rts
*--------------------------------------
CS.RUN			ldy #bCANCEL
				lda (pData),y
				beq .10

				sec
				rts
				
.10				ldy #bSTOP
				lda (pData),y
				beq .1
				clc
.99				rts
				
.1				ldy #hS.LISTDIR
				lda (pData),y
				>SYSCALL SYS.ListDirNextA
				bcs .99
				
				pha
				>SYSCALL SYS.GetMemPtrA
				>STYA ZPPtr1
				lda (ZPPtr1)
				pha
				
				and #$0F
				sta (ZPPtr1)			Adjust Filename len
				
				pla
				and #$F0
				cmp #$F0				Volume ($F) HEADER ?
				beq .8
				cmp #$E0				Dir ($E) HEADER ?
				beq .8
				
				ldy #hS.LISTDIR
				lda (pData),y
				>SYSCALL SYS.GetMemPtrA
				>STYA ZPPtr2
				
				ldy #S.LISTDIR.hPATH
				lda (ZPPtr2),y
				>SYSCALL SYS.GetMemPtrA
				>STYA ZPPtr2
				
				lda (ZPPtr2)
				tax
				tay
				
.2				lda (ZPPtr2),y
				sta FullPath,y
				dey
				bne .2
				
				ldy #0
.3				inx
				iny
				lda (ZPPtr1),y
				sta FullPath,x
				tya
				cmp (ZPPtr1)
				bne .3
				
				stx FullPath
				
				>LDYA L.FullPath	
				>SYSCALL SYS.PStrOutYA
				
				>LDYA L.FullPath	
				>SYSCALL SYS.MLIDestroyYA
				bcs .5
				>LDYA L.MSG.OK
				>SYSCALL SYS.PStrOutYA
				bra .8
				
.5				>PUSHA
				>LDYA L.MSG.ERR
				>SYSCALL SYS.PStrOutYA
				
.8				pla
				>SYSCALL SYS.FreeMemA
				clc
				rts
*--------------------------------------
CS.DOEVENT		ldy #S.EVT.hDEV		is Event from active IN device?
				lda (pEvent),y
				ldy #S.PS.hINDEV
				cmp (pPs),y
				bne .9

				lda (pEvent)
				and #S.EVT.F.KEY		is it a KEY event?
				beq .9

				ldy #S.EVT.DATAHI		is it an O or SAPPLE key ?
				lda (pEvent),y
				bne	.9

				ldy #S.EVT.DATALO	
				lda (pEvent),y
				cmp #$03				Ctrl-C
				bne .1

				lda #$FF
				ldy #bCANCEL
				sta (pData),y
				bra .8
				
.1				cmp #$13				Ctrl-S
				bne .8
				
				ldy #bSTOP
				lda (pData),y
				eor #$FF
				sta (pData),y

.8				clc
				rts
				
.9				sec
				rts
*--------------------------------------
CS.QUIT			ldy #hS.LISTDIR
				lda (pData),y
				beq .1
				
				>SYSCALL SYS.ListDirCloseA
				
.1				ldy #hDirPath
				lda (pData),y
				beq .2
				>SYSCALL SYS.FreeMemA
				
.2				clc
				rts
*--------------------------------------
CS.END
MSG.USAGE		>PSTRING "Usage : RM [file/Dir, *,? wildcards allowed]\n"
MSG.OK			>PSTRING " [Ok]\n"
MSG.ERR			>PSTRING " [%h]\n"
hFullPath		.BS 1
FullPath		.BS 64
*--------------------------------------
				.DUMMY
				.OR 0
DS.START
hDirPath		.BS 1
hS.LISTDIR		.BS 1
bSTOP			.BS 1
bCANCEL			.BS 1
DS.END
				.ED
*--------------------------------------
MAN
SAVE BIN/RM.S
ASM
