; <MICRODOS XL> BY WALT LORD (C)
;
;--- OPERATING SYSTEM CONSTANTS ---
;---        AND ADDRESSES       ---
;
ICCOM	= $0342 	;I/O COMMAND
ICBADR	= $0344 	;BUFFER ADDR
ICBLEN	= $0348 	;BUFFER LENGTH
ICAUX1	= $034A 	;AUX 1
;
;VECTOR TABLE
;
DSKINV	= $E453 	;DISK HANDLER
CIOV	= $E456 	;CIO HANDLER
SIOV	= $E459 	;SIO HANDLER
SETVBV	= $E45C 	;SET VBI ADDRESS
XITVBV	= $E462 	;EXIT VBI
WARMSV	= $E474 	;WARM START
COLDSV	= $E477 	;COLD START
DOSVEC	= $0A 	;RUN DOS
INITADR	= $02E2 	;DOS LOAD/INIT
GOADR	= $02E0 	;DOS LOAD/GO
VDSLST	= $0200 	;DISPLAY LIST NMI
;
;SIO COMMAND BLOCK (DCB)
;
DDEVIC	= $0300
DUNIT	= $0301
DCOMND	= $0302
DSTATS	= $0303
DBUFLO	= $0304
DBUFHI	= $0305
DTIMLO	= $0306
DBYTLO	= $0308
DBYTHI	= $0309
DAUX1	= $030A
DAUX2	= $030B
;
RTCLKL	= $14 	;LOWER BYTE OF CLOCK
SOUNDR	= $41 	;QUIET I/O FLAG
SDMCTL	= $022F 	;SHADOW SCREEN CONTROL REG.
SDLSTL	= $0230 	;CONTAINS DISPLAY LIST ADDR.
STICK0	= $0278 	;STICK 0 SHADOW
STRIG0	= $0284 	;TRIG 0 SHADOW
COLORS	= $02C4 	;COLOR 0 SHADOW
CHBAS	= $02F4 	;CHAR SET ADDR HI BYTE
CHRORG	= $E000 	;OS CHAR SET ADDR
CONSOL	= $D01F 	;CONSOLE BUTTON REG
HSCROL	= $D404 	;HORZ SCROLL REG
VSCROL	= $D405 	;VERT SCROLL REG
WSYNC	= $D40A 	;CAUSES WAIT FOR VERT SYNC
VCOUNT	= $D40B 	;VERT LINE COUNTER
NMIEN	= $D40E 	;NMI ENABLE REG
;
;FLOATING POINT LOCATIONS
;
FASC	= $D8E6 	;FLOAT->ASCII
IFP	= $D9AA 	;INT->FLOAT
FR0	= $D4 	;FLOAT VARIBLE
INBUFF	= $F3 	;OUTPUT BUFFER PNTR
;
;--- PROGRAM VARIBLES, CONSTANTS, ---
;---        AND ADDRESSES         ---
;
;"BASE" IS THE DIFFERENCE BETWEEN
;THE ASSEMBLED ADDRESS AND THE RUN
;ADDRESS. USED BECAUSE MICRODOS XL
;WILL OCCUPY THE LOCATION OF DOS
;DURING OPERATION.
;
BASE	= $5000
;
LOADADR	= $0700 	;LOAD ADDR
DIRTAB	= $0A00 	;DIRECTORY TBL
DSPDAT	= $7000 	;DISPLAY DATA
MAGLN	= DSPDAT+330 	;MAGNIFIED LINE ADDR
STRTLN	= MAGLN+4 	;START OF DIPLAY FILE NAMES
BUFFER	= $0400 	;INPUT BUFFER ADDR
CHSET	= $3108 	;CHARSET LOAD ADDR
TOPDOS2	= $4000 	;LOMEM OF ATARI DOS 2
TOPOSS	= $2000 	;LOMEM OF OSS DOS
CHSTADR	= $3000 	;ADDR OF NEW CHARSET
SECBUF	= $6300 	;TEMP SECTOR BUFFER
DNSYFL	= $630E 	;DISK DENSITY FLAG
DOSLNK	= $630F 	;LINKS TO DOS FILE
;
;ZERO PAGE VARIBLES USED BY CREATOR
;
	*= $43
FILNUM	*= *+1 	;# FILES DISPLAYED
MOVFL	*= *+1 	;SCROLLING FLAG
MOVCNT	*= *+2 	;DATA ADDR INC
INPFL	*= *+1 	;INPUT ACCEPTED FLAG
PROPTR	*= *+1 	;PROGRAM SELECTION PNTR
VSCRL	*= *+1 	;VSCROL PNTR
;
;ZERO PAGE VARIBLES USED BY MICRODOS XL
;
	*= $43
ENDBUF	*= *+1 	;END OF BUFFER PNTR
BFPNTR	*= *+2 	;POINTS TO BUFFER
MOVLOC	*= *+2 	;TEMP START MOVE ADDR
ENDPTR	*= *+2 	;TEMP END MOVE ADDR
;
;*** PROGRAM START ***
;
;TURN OFF SCREEN
;
	*= SDMCTL
	.BYTE 0
;
	*= $3FC0
;
;CLEAR MEMORY
;
CLRMEM	LDY #$40
CLR1	LDA #0
	TAX 
CLR2	STA TOPDOS2,X
	INX 
	BNE CLR2
	INC CLR2+2
	DEY 
	BNE CLR1
	RTS 
;
	*= INITADR
	.WORD CLRMEM
;
;SECTORS #1-3 (BOOT) AND #$2D0
;
	*= LOADADR+BASE
SECLG	= *-BASE 	;# BYTES/SECTOR
	.BYTE $80
	.BYTE 3 	;LOAD 3 SECTORS
	.WORD LOADADR 	;LOAD ADDR
	.WORD SETVEC 	;INIT ADDR
SETVEC	= *-BASE
	LDA # <GETFILE 	;SET DOSVEC
	STA DOSVEC 	;TO GETFILE
	LDA # >GETFILE
	STA DOSVEC+1
	LDA RSTFLG 	;DOS RUNNING?
	BEQ RESET 	;YES, BRANCH
	CLC 
	RTS 
;
RESET	JMP COLDSV 	;RESET PRESSED, RE-BOOT
;
RSTFLG	= *-BASE
	.BYTE 1 	;DOS RUN FLAG
SECLNK	= *-BASE
	.WORD 0 	;SECTOR LINK TO FILE
;
;*** GET FILE ROUTINE ***
;
GETFILE	= *-BASE
	LDA SECLG 	;SET TO CORRECT
	STA DBYTLO 	;DENSITY FOR READ
	BNE CONT0
	INC DBYTHI
CONT0	LDA #0
	STA RSTFLG 	;SET TO DOS RUNNING
	STA SOUNDR 	;QUIET LOAD
;
;SETUP DCB
;
	STA DBUFLO
	STA BFPNTR
	LDA # >BUFFER
	STA DBUFHI
	STA BFPNTR+1
	LDA SECLNK
	STA DAUX1
	LDA SECLNK+1
	STA DAUX2
	LDA #$31
	STA DDEVIC
	LDA #1
	STA DUNIT
	LDA #'R
	STA DCOMND
	JSR PREFILL 	;PRE-FILL BUFFER
	LDA BUFFER+2 	;STORE LOAD ADDR
	STA GOADR 	;FOR GO ADDR
	LDA BUFFER+3
	STA GOADR+1
	JSR RTRNST 	;SET INITADR TO "RTS"
;
;GET LOAD ADDRESS ROUTINE
;
GETADR	= *-BASE
	LDX #0
	LDA (BFPNTR),Y
	CMP #$FF
	BNE MOVADR
	JSR INCPTR
	LDA (BFPNTR),Y
	CMP #$FF
	BNE CONT1
	JSR INCPTR
	JMP MOVADR-BASE
;
CONT1	LDA #$FF
	STA MOVLOC
	INX 
;
;MOVE LOAD ADDRESS INTO PROGRAM
;
MOVADR	LDA (BFPNTR),Y
	STA MOVLOC,X
	JSR INCPTR
	INX 
	CPX #4
	BNE MOVADR
	LDA MOVLOC
	STA MOVPTR
	LDA MOVLOC+1
	STA MOVPTR+1
;
;MOVE DATA
;
MOVER	LDA BUFFER,Y
MOVPTR	= *+1-BASE
	STA $FFFF
	JSR INCPTR
	LDA MOVPTR+1
	CMP ENDPTR+1
	BCS TSTADR
CONT4	INC MOVPTR
	BNE MOVER
	INC MOVPTR+1
	BNE MOVER
TSTADR	LDA MOVPTR
	CMP ENDPTR
	BCC CONT4
	JSR JPINIT 	;END OF SUBFILE, INITIALIZE
	JMP GETADR 	;GET NEXT SUBFILE
;
;ROUTINE TO INCREMENT THE Y REG.
;IF END OF BUFFER, FILL BUFFER
;
INCPTR	= *-BASE
	INY 
	CPY ENDBUF
	BCS FLLBUF
	RTS 
;
BUFFLEN	= *+1 	;#BYTES/SECTOR - 3
FLLBUF	LDY #$7D 	;GET SECTOR LINKS
	LDA (BFPNTR),Y
	AND #3
	STA DAUX2
	INY 
	LDA (BFPNTR),Y
	STA DAUX1
	ORA DAUX2
	BEQ RUNIT 	;EOF? JUMP THRU GOADR
PREFILL	= *-BASE
	TXA 
	PHA 
CONT5	JSR GETSEC 	;GET SECTOR
	BMI CONT5 	;ERROR, TRY AGAIN
	LDY SECLG 	;GET # BYTES IN SECTOR
	DEY 
	LDA (BFPNTR),Y
	STA ENDBUF 	;STORE IN END OF BUFFER PNTR
	PLA 
	TAX 
	LDY #0
	RTS 
;
;GET SECTOR ROUTINE
;
GETSEC	= *-BASE
	LDA #$40
	STA DSTATS
	LDA #7
	STA DTIMLO
	JMP SIOV
;
;JUMP THRU INIT ADDRESS
;
JPINIT	= *-BASE
	TYA 
	PHA 
	JSR JINI
	PLA 
	TAY 
;
;RESET INIT ADDRESS TO "RTS"
;
RTRNST	= *-BASE
	LDA # <RTRN
	STA INITADR
	LDA # >[RTRN-BASE]
	STA INITADR+1
RTRN	RTS 
;
JINI	= *-BASE
	JMP (INITADR)
;
;INITIALIZE THEN RUN
;
RUNIT	JSR JINI
	JMP (GOADR)
;
;*** MAINLINE ***
;
MAINLN	= *-BASE
	LDA #$FF 	;INIT # OF FILES
	STA FILNUM
	LDA #$69 	;SET UP DCB
	STA DAUX1
	LDA #1
	STA DAUX2
	LDA # >BUFFER
	STA DBUFHI
	LDA #0
	STA DBUFLO
	STA ENDPTR 	;SET DIRECTORY
	LDA # >DIRTAB 	;TABLE PNTR
	STA ENDPTR+1
	LDA # <STRTLN 	;SET SCREEN PNTR
	STA MOVLOC
	LDA # >STRTLN
	STA MOVLOC+1
CONT10	JSR GETSEC 	;GET SECTOR
	BMI ENDDIR 	;ERROR, GOTO END
	INC DAUX1 	;INCREMENT SECTOR #
	LDX #0 	;RESET BUFFER PNTR
	STX BFPNTR
CONT11	LDY #0
	LDA (BFPNTR),Y
	BEQ ENDDIR 	;ZERO? END.
	BMI NEXDIR 	;IF - THEN LOCKED
	AND #$20 	;IF NOT LOCKED NEXT
	BEQ NEXDIR 	;DIRECTORY
	INC FILNUM 	;FOUND, INC COUNT
	LDY #3
CONT101	LDA (BFPNTR),Y 	;STORE SECTOR PNTRS
	STA (ENDPTR,X)
	INC ENDPTR
	INY 
	CPY #5
	BNE CONT101
CONT12	LDA (BFPNTR),Y 	;DISPLAY NAME
	SEC 
	SBC #$20 	;CONVERT TO SCREEN DATA
	STA (MOVLOC,X)
	INC MOVLOC
	BNE CONT13
	INC MOVLOC+1
CONT13	INY 
	CPY #$10
	BNE CONT12
	LDA MOVLOC 	;INC TO NEXT LINE
	CLC 
	ADC #29
	STA MOVLOC
	BCC NEXDIR
	INC MOVLOC+1
NEXDIR	LDA BFPNTR 	;SET UP FOR NEXT DIRECTORY
	CLC 
	ADC #$10
	STA BFPNTR
	CMP SECLG
	BEQ CONT10 	;END OF SECTOR
	BNE CONT11 	;NOT END, CONTINUE
;
ENDDIR	LDA NEWCOL,Y 	;STORE NEW COLORS
	STA COLORS,Y
	DEY 
	BNE ENDDIR
	LDA # <DSPLST 	;STORE NEW DL
	STA SDLSTL
	LDA # >DSPLST
	STA SDLSTL+1
	LDA # <DSPLI 	;POINT TO DLI
	STA VDSLST
	LDA # >DSPLI
	STA VDSLST+1
	LDA #$30 	;SET TO NEW
	STA CHBAS 	;CHARACTER SET
	LDA #$F0 	;TURN ON DLI
	STA NMIEN
	LDA #0 	;CLEAR FLAGS
	STA MOVFL
	STA INPFL
	STA PROPTR
	LDA #9 	;SET VSCROL
	STA VSCROL
	LDA FILNUM 	;ANY LOCKED FILES?
	BEQ CONT14 	;NO, BRANCH
	LDY # <VBI 	;INSTALL DEFERRED VBI
	LDX # >VBI
	LDA #7
	JSR SETVBV
CONT14	LDA #$21 	;SET SCREEN TO NARROW
	STA SDMCTL
GETINPT	LDA INPFL 	;WAIT FOR INPUT
	BEQ GETINPT 	;THRU DEF. VBI
	LDA PROPTR 	;GET FILE PNTR
	ASL A 	;MULTIPLY * 2
	TAX 
	LDA DIRTAB,X 	;POINT INTO DIRECTORY
	STA SECLNK 	;TABLE AND STORE
	LDA DIRTAB+1,X 	;SECTOR LINKS
	STA SECLNK+1
	LDA #0
	TAX 
	LDY #$A0
LOOP5	STA TOPOSS,X
	INX 
	BNE LOOP5
	INC LOOP5+2
	DEY 
	BNE LOOP5
	INC RSTFLG 	;SET TO DOS DONE
	JMP WARMSV 	;WARM START
;
;"DOS.SYS" FILE
;
	*= $6000
	.BYTE $FF,$FF 	;BINARY LOAD HEADER
	.WORD SDMCTL,SDMCTL
	.BYTE 0 	;TURN OFF SCREEN
	.WORD MOVCHS,ENDDOS
;
;*** MOVE O.S. CHARACTER SET ***
;
MOVCHS	LDX #0
MV0	LDA CHRORG,X
	STA CHSTADR,X
	INX 
	BNE MV0
	INC MV0+5
	INC MV0+2
	LDA MV0+2
	CMP #$E2 	;TOP OF UPPER CASE?
	BNE MV0 	;NO, CONTINUE
	RTS  	;RETURN
;
;*** DEFERED VBI ***
;
VBI	LDA MOVFL 	;SCROLLING?
	BNE CONTMV 	;YES, CONTINUE
	LDA CONSOL 	;READ CONSOL
	ROR A
	ROR A
	BCC DOWN 	;SELECT PRESSED?
	ROR A
	BCC UP 	;OPTION PRESSED
	LDA STICK0 	;READ STICK0
	ROR A
	BCC UP 	;UP?
	ROR A
	BCC DOWN 	;DOWN?
	LDY STRIG0 	;STICK TRIGGER
	BEQ FOUND 	;PRESSED?
	LDA CONSOL 	;START PRESSED?
	ROR A
	BCS EXIT 	;NOTHING EXIT
;
;SELECTION IS MADE
;
FOUND	INC INPFL 	;SET FLAG
	BNE EXIT 	;EXIT
;
;SCROLL UP
;
UP	LDA PROPTR 	;END OF PROGRAMS?
	CMP FILNUM
	BCS EXIT
	INC PROPTR 	;NO, INC POINTER
	LDX #40 	;INC DSPDAT BY 40
	LDY #0
	TYA  	;SCROLL UP VALUES
	BEQ SETMOV
;
;SCROLL DOWN
;
DOWN	LDA PROPTR 	;TOP OF PROGRAMS
	BEQ EXIT 	;YES, EXIT
	DEC PROPTR 	;DEC POINTER
	LDX #-40 	;INC DSPDAT BY -40
	LDY #$FF
	LDA #$0A 	;SCROLL DOWN VALUES
;
;STORE VALUES START SCROLL
;
SETMOV	STA VSCRL
	STX MOVCNT
	STY MOVCNT+1
	LDA #0 	;CLICK SPEAKER
	STA CONSOL
	INC MOVFL 	;SET MOVE FLAG
CONTMV	LDX VSCRL 	;GET NEXT VSCROL
	LDA SCRVAL,X 	;VALUE
	BMI INCDSP 	;NEG? INC DSPDAT
STORE	INC VSCRL 	;POINT TO NEXT VALUE
	STA VSCROL 	;STORE INTO VSCROL
	CMP #9 	;EQUALS 9?
	BCC EXIT 	;NO, EXIT
	LDA #0 	;SET DONE SCROLL
	STA MOVFL
;
;ROTATE COLOR AND EXIT DEF. VBI
;
EXIT	LDA RTCLKL
	AND #3
	BNE GONE
	LDA COLORS
	CLC 
	ADC #1
	ORA #8
	STA COLORS
GONE	JMP XITVBV
;
;INCREMENT DISPLAY DATA POINTERS
;
INCDSP	AND #$0F 	;MASK OFF VSCROL VALUE
	PHA  	;STORE IT
	LDA DSPTR1 	;TOP OF WINDOW PNTR
	CLC 
	ADC MOVCNT
	STA DSPTR1
	LDA DSPTR1+1
	ADC MOVCNT+1
	STA DSPTR1+1
	LDA DSPTR2 	;MAGNIFIED LINE PNTR
	CLC 
	ADC MOVCNT
	STA DSPTR2
	LDA DSPTR2+1
	ADC MOVCNT+1
	STA DSPTR2+1
	LDA DSPTR3 	;BELOW MAGNIFIED LINE PNTR
	CLC 
	ADC MOVCNT
	STA DSPTR3
	LDA DSPTR3+1
	ADC MOVCNT+1
	STA DSPTR3+1
	PLA  	;RESTORE VSCROL VALUE
	JMP STORE 	;GO STORE IT
;
;VSCROL VALUE TABLE
;
SCRVAL	.BYTE $F0,1,2,3,4,5,6,7,8,9
	.BYTE 8,7,6,5,4,3,2,1,0,$F9
;
;*** DISPLAY LIST ***
;
DSPLST	.BYTE $70,$70,$70,$47
	.WORD HEADLN
	.BYTE $50,$73
DSPTR1	.WORD DSPDAT
	.BYTE $33,$33,$33,$33,$33,$33,$92
	.BYTE 0,$D6
DSPTR2	.WORD MAGLN
	.BYTE $73
DSPTR3	.WORD DSPDAT+320
	.BYTE $33,$33,$33,$33,$33,$33,$12
	.BYTE $70,$46
	.WORD FOOTLN
	.BYTE $41
	.WORD DSPLST
;
;HEADING LINE
;
HEADLN	.SBYTE "  "
	.SBYTE +$80,"microdos"
	.SBYTE "  "
	.SBYTE +$80,"xl"
;
;FOOTER LINE
;
FOOTLN	.SBYTE "  "
	.SBYTE +$80,"up"
	.SBYTE " "
	.SBYTE +$80,"down"
	.SBYTE " "
	.SBYTE +$80,"fire"
	.SBYTE "  "
;
;DISPLAY LIST INTERRUPT
;
DSPLI	PHA 
	LDA VCOUNT
	CMP #64 	;VCOUNT>=64
	BCS D1 	;YES.
	LDA #4 	;SET HSCROL TO 4
	BNE D2
;
D1	LDA NEWCOL 	;STORE FOOTER COLOR
	STA $D019 	;IN REGISTER
	LDA #2 	;SET HSCROL TO 2
D2	STA WSYNC 	;- WSYNC -
	STA HSCROL
	PLA 
	RTI 
;
;NEW COLORS
;
NEWCOL	.BYTE $68,$0D,$85,$28
ENDDOS	.BYTE $80
;
	.WORD INITADR,INITADR+1
	.WORD MOVCHS
;
;
;CUSTOM CHARACTER SET
;
	.WORD CHSET,CHSET+$CE
;
CHRSET	.BYTE 63,51,51,127,115,115,115,0
	.BYTE 126,102,102,127,103,103,127,0
	.BYTE 127,103,103,96,99,99,127,0
	.BYTE 126,102,102,119,119,119,127,0
	.BYTE 127,96,96,127,112,112,127,0
	.BYTE 127,96,96,127,112,112,112,0
	.BYTE 127,99,96,111,103,103,127,0
	.BYTE 115,115,115,127,115,115,115,0
	.BYTE 127,28,28,28,28,28,127,0
	.BYTE 12,12,12,14,14,110,126,0,102
	.BYTE 102,108,127,103,103,103,0
	.BYTE 48,48,48,112,112,112,126,0
	.BYTE 103,127,127,119,103,103,103,0
	.BYTE 103,119,127,111,103,103,103,0
	.BYTE 127,99,99,103,103,103,127,0
	.BYTE 127,99,99,127,112,112,112,0
	.BYTE 127,99,99,103,103,103,127,7
	.BYTE 126,102,102,127,119,119,119,0
	.BYTE 127,96,127,3,115,115,127,0
	.BYTE 127,28,28,28,28,28,28,0,103
	.BYTE 103,103,103,103,103,127,0
	.BYTE 103,103,103,103,111,62,28,0
	.BYTE 103,103,103,111,127,127,103,0
	.BYTE 115,115,115,62,103,103,103,0
	.BYTE 103,103,103,127,28,28,28,0
	.BYTE 127,102,108,24,55,103,127
;
	.WORD 170+$7000,187+$7000
	.SBYTE "(C) WALT LORD 1984"
;
;LOAD SIO DCB FOR SECTOR #$2D0
;
	.WORD DBUFLO,DBUFHI
	.WORD $0880
	.WORD DAUX1,DAUX2
	.WORD $02D0
;
	.WORD INITADR,INITADR+1
	.WORD GETSEC
;
	.WORD GOADR,GOADR+1
	.WORD MAINLN
;
DOSLEN	= *-$6000
;
;CREATOR PROGRAM THAT WRITES
;MICRODOS XL ONTO A DISK
;
	*= $6400
CREATE	LDY #5
CR0	LDA NEWCOL,Y 	;STORE NEW COLORS
	STA COLORS,Y
	DEY 
	BNE CR0
	LDA # <MNUDSPL 	;STORE NEW DL
	STA SDLSTL
	LDA # >MNUDSPL
	STA SDLSTL+1
	LDY #2
CR05	LDX #0
CR1	LDA CHRORG,X 	;MOVE OS CHARSET
	STA TOPDOS2,X
	INX 
	BNE CR1
	INC CR1+2
	INC CR1+5
	DEY 
	BNE CR05
	LDX #$D0
CR2	LDA CHRSET-1,X 	;MOVE CHARSET
	STA $4107,X
	DEX 
	BNE CR2
	LDA #$40 	;SET TO NEW CHARSET
	STA CHBAS
	LDA #$21 	;NARROW SCREEN
	STA SDMCTL
CRLOOP	LDA CONSOL 	;GET CONSOL
	ROR A 	;START PRESSED?
	BCC WRITE 	;YES,WRITE LOADER
	ROR A 	;SELECT PRESSED?
	BCS CRLOOP
	LDA SYSNAME+1 	;GET CURRENT DISK#
	CMP #'4 	;#=4?
	BNE CR42 	;NO, SKIP
	LDA #'1 	;RESET TO 1
	BNE CR43
;
CR42	CLC  	;INCREMENT #
	ADC #1
CR43	STA SYSNAME+1 	;# IN REQ. NAMES
	STA TMPNAME+1
	STA RENAME+1
	AND #$17 	;MAKE SCREEN BYTE
	ORA #$80 	;INVERSE VIDEO
	STA DRVMSG 	;DISPLAY IT
	LDA #0 	;WAIT FOR BUTTON RELEASE
	STA RTCLKL
	LDA #50
CR45	CMP RTCLKL
	BNE CR45
	BEQ CRLOOP
;
WRITE	LDX #23 	;CLEAR ERRMSG
	LDA #0
CR5	STA ERRLN,X
	DEX 
	BNE CR5
	JSR WRITLDR
	JMP CRLOOP
;
;WRITE LOADER ON DISK
;
WRITLDR	LDX #$30 	;SET TO CHANNEL #3
	LDY # <SYSNAME 	;POINT TO
	LDA # >SYSNAME 	;"D:D*.SYS"
	JSR STORADR 	;STORE POINTER
	LDA #$24 	;LOAD UNLOCK COMMAND
	JSR EXCCIO 	;EXECUTE CIO COMMAND
	LDA #$21 	;LOAD DELETE COMMAND
	JSR EXCCIO 	;EXECUTE CIO COMMAND
	LDY # <TMPNAME 	;POINT TO
	LDA # >TMPNAME 	;"D:TEMP.TMP"
	JSR STORADR 	;STORE PNTRS
	LDA #$03 	;LOAD OPEN COMMAND
	LDY #$08 	;SET TO OUTPUT
	JSR EXCCIO 	;EXECUTE COMMAND
	BMI ERRJMP 	;BRANCH IF CIO ERROR
	LDA #0 	;SET BUFFER ADDR
	STA ICBADR,X
	LDA #$60
	STA ICBADR+1,X
	LDA # <DOSLEN 	;BUFFER LENGTH
	STA ICBLEN,X
	LDA # >DOSLEN
	STA ICBLEN+1,X
	LDA #$0B 	;LOAD PUT CHAR COMMAND
	JSR EXCCIO 	;EXECUTE COMMAND
	BMI ERRJMP 	;BRANCH IF CIO ERROR
	LDA #$0C 	;LOAD CLOSE COMMAND
	JSR EXCCIO 	;EXECUTE COMMAND
	BMI ERRJMP 	;BRANCH IF CIO ERROR
	LDY # <RENAME 	;POINT TO
	LDA # >RENAME 	;"D:TEMP.TMP,DOS.SYS"
	JSR STORADR 	;STORE PNTRS
	LDA #$20 	;LOAD RENAME COMMAND
	JSR EXCCIO 	;EXECUTE COMMAND
	BPL GOODCIO 	;BRANCH IF CIO OK
ERRJMP	JMP ERRPRS 	;JUMP TO ERROR ROUTINE
;
GOODCIO	LDA #1 	;READ 1ST SECTOR
	STA DAUX1
	LDA #0
	STA DAUX2
	STA DBUFLO
	LDA # >SECBUF
	STA DBUFHI
	LDA #'R
	STA DCOMND
	JSR DSKINV
	BPL C0
	JMP ERRPRS
;
C0	LDA DOSLNK 	;DOS SECTOR LINKS
	STA SECLNK+BASE
	LDA DOSLNK+1
	STA SECLNK+BASE+1
	LDA DNSYFL 	;GET DENSITY FLAG
	CMP #2 	;DOUBLE DENSITY?
	BEQ DBLDENS 	;YES, BRANCH
	LDX #5
CR4	LDA SNGMSG,X 	;SET "SINGLE" MSG
	STA DENSMSG,X
	DEX 
	BPL CR4
	LDA #$80 	;SET SINGLE VALUES
	LDX #$7D
	BNE STRDNS
;
DBLDENS	LDX #5 	;SET "DOUBLE" MSG
CR3	LDA DBLMSG,X
	STA DENSMSG,X
	DEX 
	BPL CR3
	LDA #0 	;SET DOUBLE VALUES
	LDX #$FD
STRDNS	STA SECLG+BASE 	;STORE SECTOR LENGTH
	STX BUFFLEN 	;BYTES/SECTOR OFFSET
	LDA #'W 	;WRITE 1ST SECTOR
	STA DCOMND
	LDA #$57
	STA DBUFHI
WRSEC	JSR DSKINV
	BMI ERRPRS
	LDA DBUFLO 	;ADVANCE TO NEXT SECTOR
	CLC 
	ADC #$80
	STA DBUFLO
	BCC INSCT
	INC DBUFHI
INSCT	INC DAUX1
	LDA DAUX1
	CMP #4
	BNE WRSEC
	LDA #$D0 	;WRITE SECTOR $2D0
	STA DAUX1
	LDA #2
	STA DAUX2
	LDA SECLG+BASE 	;IN DESIRED DENSITY
	STA DBYTLO
	BNE C1
	INC DBYTHI
C1	LDA #$80
	STA DSTATS
	LDA #$07
	STA DTIMLO
	JSR SIOV
	BMI ERRPRS
	LDX #7
C05	LDA DONEMSG,X 	;PRINT "- DONE -"
	STA ERRMSG+2,X
	DEX 
	BPL C05
	RTS 
;
;PROCESS ERROR ROUTINE
;
ERRPRS	TYA  	;STORE ERROR NUMBER
	PHA 
	LDA #$0C 	;LOAD CLOSE COMMAND
	LDX #$30 	;SET TO CHANNEL #3
	JSR EXCCIO 	;EXECUTE COMMAND
	PLA  	;RESTORE ERROR NUMBER
	STA FR0 	;PROCESS ERROR
	LDA #0
	STA FR0+1
	JSR IFP 	;CONVERT TO
	JSR FASC 	;FLOAT.PNT->ASCII
	LDY #$FF
C15	INY 
	LDA (INBUFF),Y 	;CONVERT ASCII
	SEC  	;TO SCREEN VALUES
	SBC #$20
	STA ERRNUM,Y
	LDA (INBUFF),Y
	BPL C15
	AND #$7F
	SEC 
	SBC #$20
	STA ERRNUM,Y
	LDX #6
C2	LDA ERRLTR,X 	;PRINT "ERROR -"
	STA ERRMSG,X
	DEX 
	BPL C2
	RTS 
;
EXCCIO	STA ICCOM,X 	;STORE COMMAND
	TYA 
	STA ICAUX1,X 	;STORE AUX BYTE
	JSR CIOV 	;DO CIO
	RTS 
;
STORADR	STA ICBADR+1,X 	;STORE ADDRESS
	TYA 
	STA ICBADR,X
	RTS 
	.BYTE 0
;
;FILE NAMES
;
SYSNAME	.BYTE "D1:D*.SYS",$9B
TMPNAME	.BYTE "D1:TEMP.TMP",$9B
RENAME	.BYTE "D1:TEMP.TMP,DOS.SYS",$9B
;
;MENU DISPLAY LIST
;
MNUDSPL	.BYTE $70,$70,$70,$46
	.WORD ANLHDG
	.BYTE $50,$47
	.WORD MCRHDG
	.BYTE $50,$47
	.WORD CRTLN
	.BYTE $50,$42
	.WORD DSPDAT
	.BYTE 2,2,2,2,2,2,2,2,2,2,2,2
	.BYTE $70,$46
	.WORD ERRLN
	.BYTE $41
	.WORD MNUDSPL
;
;HEADING LINES
;
ANLHDG	.SBYTE "     "
	.SBYTE +$80,"ANALOG"
	.SBYTE "   "
MCRHDG	.SBYTE "  "
	.SBYTE +$80,"microdos"
	.SBYTE "  "
	.SBYTE +$80,"xl"
CRTLN	.SBYTE "    "
	.SBYTE +$80,"creator"
	.SBYTE "     "
;
;DISPLAY DATA
;
	*= DSPDAT
	.SBYTE +$80,"        INSERT F"
	.SBYTE +$80,"ORMATTED         "
	.SBYTE +$80,"          DISK  "
	.SBYTE +$80,"INTO            "
	.SBYTE +$80,"           DRIVE #"
DRVMSG	.SBYTE +$80,"1            "
;
	*= *+44
	.SBYTE +$80," SELECT "
;
	*= *+49
	.SBYTE "TO CHANGE DISK DRIVE #"
;
	*= *+49
	.SBYTE +$80," START "
;
	*= *+48
	.SBYTE "TO WRITE LOADER ONTO DISK"
;
	*= *+36
	.SBYTE +$80,"         "
DENSMSG	.SBYTE +$80,"SINGLE "
	.SBYTE +$80,"DENSITY         "
;
ERRLN	*= *+2
ERRMSG	*= *+8
ERRNUM	*= *+24
;
;MESSAGES
;
SNGMSG	.SBYTE +$80,"SINGLE"
DBLMSG	.SBYTE +$80,"DOUBLE"
ERRLTR	.SBYTE +$80,"error -"
DONEMSG	.SBYTE +$80,"-"
	.SBYTE " "
	.SBYTE +$80,"done"
	.SBYTE " "
	.SBYTE +$80,"-"
;
	*= GOADR
	.WORD CREATE
	.END 
