	NAM	DOS
******** VERSION 1.00 ***********
* WRITTEN BY R. H. UITERWYK

COMREG	EQU	$8018
DATREG	EQU	$801B
RESTRT	EQU	$2403
READ	EQU	$242B
READ0	EQU	$242E
PRELIM	EQU	$2523
WRITE	EQU	$255F
WRITE0	EQU	$2561
DRIVE	EQU	$25AC
TRACK	EQU	$0000
SECTOR	EQU	$0001
BMEMH	EQU	$0004
EMEMH	EQU	$0006
SAVEX	EQU	$0009
PROGX	EQU	$000B
NDRIVE	EQU	$000D

	ORG	$3000
BUFNXT	RMB	2
ENDBUF	RMB	2
BUFFER	RMB	80
CREFLG	RMB	1
DECPNT	RMB	1
LIBSEC	RMB	1
NEEDNO	RMB	1
TYPE	RMB	1
STARTX	RMB	2
ENDX	RMB	2
GOX	RMB	2
HILINE	RMB	2
TEMPX1	RMB	2
TEMPX2	RMB	2
TEMPX3	RMB	2
NAME	RMB	8
PASSWD	RMB	8
DBUFFR	RMB	256
OVERFL	RMB	32

	ORG	$2600

DOS	LDX	#COPMSG
	LDAA	#$FF
	STAA	DECPNT
	JSR	OUTPUT
DOS1	LDS	#$A049
	JSR	DOSTRT
	BRA	DOS1
OUTCHA	JMP	OUTEEE
OUTEEE	EQU	$E1D1
INCH	JMP	INEEE
INEEE	EQU	$E1AC
PRNCHA	JMP	OUTPIA
OUTPIA	STX	SAVEX
	LDX	#$801C
	STAA	0,X
	LDAA	#$36
	STAA	1,X
	LDAA	#$3E
	STAA	1,X
OUTPI3	TST	1,X
	BPL	OUTPI3
	LDAA	0,X
	LDX	SAVEX
	RTS
OUTCH	TST	DECPNT
	BNE	OUTCHA
	BRA	PRNCHA
PRINT	CLR	DECPNT
	JMP	READY
****************
RLIB	LDAA	#3
	BRA	LIB1
WLIB	LDAA	#2
	CLR	NEEDNO
	CLR	CREFLG
LIB1	PSHA
	LDAA	#2
	STAA	TRACK
	CLRA
	STAA	SECTOR
	JSR	PRELIM
LIB2	LDAA	SECTOR
	STAA	LIBSEC
	LDX	#DBUFFR+255
	ST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ING
	BNE	LIB9
	TST	CREFLG
	BEQ	LIB82
	LDX	#NOTCRE
	JMP	LIB65
LIB82	LDAB	ENDX
	SUBB	STARTX
	INCB
	CMPB	3,X
	BLS	LIB88
	LDX	#FLFULL
	JMP	LIB65
LIB88	LDAB	#8
	SEI
	STS	SAVEX
	LDS	#STARTX-1
LIB89	PULA
	STAA	5,X
	INX
	DECB
	BNE	LIB89
	LDS	SAVEX
	NOP
	CLI
	LDX	TEMPX2
	LDAB	TYPE
	LDAA	20,X
	BEQ	*+5
	CBA
	BNE	LIB91
	STAB	20,X
	LDAA	LIBSEC
	STAA	SECTOR
LIB895	LDX	#DBUFFR
	JSR	WRITE0
LIB9	LDX	TEMPX2
	LDAA	TYPE
	CMPA	#$FF
	BEQ	LIB95
	TST	20,X
	BEQ	LIB95
	CMPA	20,X
	BEQ	LIB95
LIB91	LDX	#TYPERR
	JMP	LIB65
LIB95	LDX	27,X
	STX	HILINE
	LDX	TEMPX2
	LDX	25,X
	STX	GOX
	LDX	TEMPX2
	LDX	23,X
	STX	EMEMH
	STX	ENDX
	LDX	TEMPX2
	LDAA	16,X
	STAA	TRACK
	LDAA	17,X
	STAA	SECTOR
	LDAA	20,X
	STAA	TYPE
	LDX	21,X
	STX	STARTX
	STX	BMEMH
	LDX	TEMPX2
RETURN	RTS

DSKFUL	FCC	'DISK FULL - PACK'
	FCB	$0D,$0A,$15,4
NOTFND	FCC	'FILE NOT FOUND'
	FCB	$0D,$0A,$15,4
FLFULL	FCC	'FILE FULL - RENAME'
	FCB	$0D,$0A,$15,4
TYPERR	FCC	'FILE TYPE MISMATCH'
	FCB	$0D,$0A,$15,4
PASERR	FCC	'PASSWORD INVALID'
	FCB	$0D,$0A,$15,4
NOTCRE	FCC	'FILE ALREADY EXISTS'
	FCB	$0D,$0A,$15,4

DEL	LDX	#DELMSG
	JSR	OUTPUT
	BRA	KEYBD0
KEYBD	LDAA	#'?
	JSR	OUTCH
	LDAA	#$20
	JSR	OUTCH
KEYBD0	LD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	BUFNXT
	BRA	MAKN
MAKNU1	JSR	GETNAM
	JSR	CLRPAS
	CMPA	#',
	BNE	*+5
	JSR	GETPAS
	RTS

INIT	JSR	SELECT
	LDX	#SURMSG
	JSR	OUTNCR
	JSR	KEYBD
	LDX	#BUFFER
	JSR	SKIPSP
	CMPA	#'Y
	BEQ	*+5
	JMP	DOSTRT
	JSR	PRELIM
	CLRA
	STAA	TRACK
	STAA	SECTOR
INIT1	LDAB	TRACK
	STAB	DATREG
	LDAB	#$1B		* SEEK, LOAD, NOVERIFY
	STAB	COMREG
	JSR	RETURN
	JSR	RETURN
INIT11	LDAB	COMREG
	BITB	#1
	BNE	INIT11
	LDAB	#$F4		* WRITE TRACK
	STAB	COMREG
	LDAB	#46
	CLRA
INIT2	JSR	UNPACK
	DECB
	BNE	INIT2
	LDAA	#$FC
	JSR	UNPACK
	LDAB	#11
	CLRA
INIT22	JSR	UNPACK
	DECB
	BNE	INIT22
INIT3	LDAB	#6
	CLRA
INIT31	JSR	UNPACK
	DECB
	BNE	INIT31
	LDAA	#$FE
	JSR	UNPACK
	LDAA	TRACK
	JSR	UNPACK
	CLRA
	JSR	UNPACK
	LDAA	SECTOR
	JSR	UNPACK
	LDAA	#$01
	JSR	UNPACK
	LDAA	#$F7
	JSR	UNPACK
	LDAB	#17
	CLRA
INIT33	JSR	UNPACK
	DECB
	BNE	INIT33
	LDAA	#$FB
	JSR	UNPACK
	CLRB
	LDAA	#$E5
INIT35	JSR	UNPACK
	DECB
	BNE	INIT35
	LDAA	#$F7
	JSR	UNPACK
	LDAB	#11
	CLRA
INIT37	JSR	UNPACK
	DECB
	BNE	INIT37
	LDAB	SECTOR
	INCB
	STAB	SECTOR
	CMPB	#10
	BNE	INIT3
INIT4	LDAB	COMREG
	BITB	#1
	BEQ	INIT45
	BRA	INIT4
INIT45	CLRA
	STAA	SECTOR
	LDAA	TRACK
	INCA
	STAA	TRACK
	CMPA	#35
	BEQ	INIT5
	JMP	INIT1
INIT5	CLRA
	STAA	TRACK
	STAA	SECTOR
	LDX	#$2FFF
	STX	EMEMH
	LDX	#$2400
	JSR	WRITE
	CLRA
	STAA	SECTOR
	LDAA	#2
	STAA	TRACK
	LDX	#DBUFFR+255
	STX	EMEMH
	LDX	#DBUFFR
	LDAA	#'$
	STAA	0,X
	INX
	LDAA	#'D
	STAA	0,X
	INX
	LDAA	#'O
	STAA	0,X
	INX
	LDAA	#'S
	STAA	0,X
	LDAB	#12
	LDAA	#$20
	INX
INIT51	STAA	0,X
	INX
	DECB
	BNE	INIT51
	CLR	1,X
	CLR	2,X
	CLR	4,X
	LDAA	#20
	STAA	3,X
	LDAA	#$FF
	STAA	16,X
	LDAA	#$03
	STAA	32,X
	CLRA
	STAA	33,X
	STAA	36,X
	CLR	0,X
	STS	SAVEX
	LDS	#$2400
	STS	5,X
	LDS	#$2FFF
	STS	7,X
	LDS	#$2600
	STS	9,X
	LDS	#$014A		* NUMBER OF SECOTRS
	STS	34,X
	LDS	SAVEX
	LDX	#DBUFFR
	JSR	WRITE0
	JMP	DOSTRT
UNPACK	PSHB
UNPAC1	LDAB	COMREG
	BITB	#2
	BEQ	UNPAC1
	STAA	DATREG
	PULB
	RTS
CREATE	CLRA
	STAA	TYPE
	JSR	MAKNAM
CREAT2	LDX	#SECNUM
	JSR	OUTNCR
	JSR	KEYBD
	LDX	#BUFFER
	JSR	BYTE
	BCS	CREAT2
	STAA	NEEDNO
	LDX	#$0000
	STX	STARTX
	STX	ENDX
	LDX	#DOS
	STX	GOX
	STX	HILINE
	LDAA	#2
	STAA	CREFLG
	JSR	LIB1
	JMP	DOSTRT
HOME	JSR	SELECT
	JSR	PRELIM
	JMP	DOSTRT
RENAME	LDAA	#$FF
	STAA	TYPE
	JSR	MAKNAM
	JSR	RLIB
	LDAA	#$02
	STAA	TRACK
	LDAA	LIBSEC
	STAA	SECTOR
	STX	TEMPX2
	LDX	#NEWMSG
	JSR	OUTNCR
	JSR	MAKNA0
	LDAB	#16
	LDX	TEMPX2
	STS	SA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