0001   0000             ;
0002   0000             ; Apple DOS 3.1 Disassembly - (Patched Release - RAWDOS)
0003   0000             ;
0004   0000             ; This disassembly is based on the original pre-release Apple DOS source
0005   0000             ; code written in 1978 by Paul Laughton, then an employee of Shepardson
0006   0000             ; Microsystems. The source document is identified on the title page with
0007   0000             ; the following text:
0008   0000             ;
0009   0000             ;	.TITLE	SHEP,'APPLE DOS'
0010   0000             ;	6.3	10-6-78
0011   0000             ;	8 BIT ASSEMBLER
0012   0000             ;	.M6502
0013   0000             ;
0014   0000             ; The binary produced by assembling this source has been compared to
0015   0000             ; the RAWDOS binary included on the Apple DOS 3.1 Master Disk and was
0016   0000             ; was found to be identical with one exception:
0017   0000             ;
0018   0000             ; Assembling this source code into a binary will generally initialize
0019   0000             ; reserved memory byte (RMB) address spaces as well as any unused address
0020   0000             ; space (addresses located between the end of a given section of code and
0021   0000             ; a new ORG directive) to 0x00 or 0xff, depending on the assembler used.
0022   0000             ;
0023   0000             ; Accordingly, all comparisons to the original DOS 3.1 binary insured
0024   0000             ; that the only differences were with byte values that were located in
0025   0000             ; unused address locations or in RMB address locations.
0026   0000             ;
0027   0000             ;
0028   0000             ; Scott LaBombard
0029   0000             ; labomb@rochester.rr.com
0030   0000             ; 12/04/2013
0031   0000             ;
0032   0000             
0033   0000             #INCLUDE "MOTO.H"
0040+  0000             .LIST
0034   0000             
0035   0000             	.TITLE	"APPLE DOS 3.1"
0036   0000             *
0037   0000             **************************************************************************************
0038   0000             *	(C)  COPYRIGHT 1978  APPLE COMPUTER, INC
0039   0000             **************************************************************************************
0040   0000             ORG1	EQU	$1B00
0041   0000             ORG2	EQU	$3600
0042   0000             DISKIO	EQU	$3D00
0043   0000             ASC1	EQU	$3800
0044   0000             AEC1	EQU	$3A8F
0045   0000             ASC2	EQU	$3D00
0046   0000             AEC2	EQU	$3FFF
0047   0000             EDOS	EQU	$4000

Page      1    APPLE DOS 3.1

0048   0000             	PAGE
0049   1B00             	ORG	ORG1
0050   1B00 4C 7E 1D    BEGIN	JMP	DBINIT
0051   1B03             ;
0052   1B03             DOSREL
0053   1B03             ;
0054   1B03             ;	GET RELOCATION PARMS
0055   1B03             ;
0056   1B03             DR0
0057   1B03             LOC1	EQU	$26
0058   1B03 A9 BF       	LDA	#$BF		; START AT BF00
0059   1B05 8D 41 00    	STA	!ZPGWRK+1	; TO LOOK FOR
0060   1B08 A2 00       	LDX	#0		; HIGH RAM
0061   1B0A 8E 40 00    	STX	!ZPGWRK
0062   1B0D             DR1B
0063   1B0D A0 00       	LDY	#0		;APPLE TEST
0064   1B0F A1 40       	LDA	(ZPGWRK,X)
0065   1B11 85 26       	STA	LOC1
0066   1B13 98          DR1	TYA
0067   1B14 45 26       	EOR	LOC1
0068   1B16 85 26       	STA	LOC1
0069   1B18 98          	TYA
0070   1B19 41 40       	EOR	(ZPGWRK,X)
0071   1B1B 81 40       	STA	(ZPGWRK,X)
0072   1B1D C5 26       	CMP	LOC1
0073   1B1F D0 05       	BNE	DR1A
0074   1B21 C8          	INY
0075   1B22 D0 EF       	BNE	DR1
0076   1B24 F0 05       	BEQ	DR2		; BR IF TOOK
0077   1B26             DR1A
0078   1B26 CE 41 00    	DEC	!ZPGWRK+1	; NOT RAM
0079   1B29 D0 E2       	BNE	DR1B		; TRY NEXT PAGE
0080   1B2B             ;
0081   1B2B             DR2
0082   1B2B             ;
0083   1B2B 20 40 35    	JSR	DR2PAT		; *** PATCH ***
0084   1B2E C8          	INY			; NEW END OF DOS                     
0085   1B2F 8C 6A 1C    	STY	NEPAGE           
0086   1B32 38          	SEC
0087   1B33 98          	TYA
0088   1B34 ED 6B 1C    	SBC	DOSLNG		; MINUS DOS LENGTH
0089   1B37 8D 69 1C    	STA	NSPAGE		; IS NEW START OF DOS
0090   1B3A 38          	SEC
0091   1B3B ED 67 1C    	SBC	RSPAGE		; MINUS OLD DOS START
0092   1B3E F0 C0       	BEQ	BEGIN		; (BREIF NO DELTA)
0093   1B40 8D 6C 1C    	STA	DELTA		; IS DELTA

Page      2    APPLE DOS 3.1

0094   1B43             	PAGE
0095   1B43 AD 67 1C    	LDA	RSPAGE		; RESET START PAGE TO NORMAL
0096   1B46 8D 0D 1D    	STA	ASTART+1
0097   1B49             ;
0098   1B49 A9 1D       	LDA	#DBINIT/256	;RESET PI RTN TO NORMAL
0099   1B4B 8D 49 37    	STA	DI3+2
0100   1B4E A9 7E       	LDA	#DBINIT&255
0101   1B50 8D 48 37    	STA	DI3+1
0102   1B53             ;
0103   1B53             ;

Page      3    APPLE DOS 3.1

0104   1B53             	PAGE
0105   1B53             ;
0106   1B53             ;
0107   1B53             ;	RELOCATE ADR TABLES
0108   1B53             ;
0109   1B53 A2 00       	LDX	#0
0110   1B55 8E 40 00    	STX	!ZPGWRK
0111   1B58             DR3
0112   1B58 BD 1A 1C    	LDA	ADRTAB+1,X
0113   1B5B A8          	TAY
0114   1B5C BD 1B 1C    	LDA	ADRTAB+2,X
0115   1B5F 8D 41 00    	STA	!ZPGWRK+1
0116   1B62 4C 73 1B    	JMP	DR5
0117   1B65             ;
0118   1B65             DR4
0119   1B65 18          	CLC
0120   1B66 B1 40       	LDA	(ZPGWRK),Y
0121   1B68 6D 6C 1C    	ADC	DELTA
0122   1B6B 91 40       	STA	(ZPGWRK),Y
0123   1B6D C8          	INY
0124   1B6E D0 03       	BNE	DR5
0125   1B70 EE 41 00    	INC	!ZPGWRK+1
0126   1B73 C8          DR5	INY
0127   1B74 D0 03       	BNE	DR6
0128   1B76 EE 41 00    	INC	!ZPGWRK+1
0129   1B79             ;
0130   1B79             DR6
0131   1B79 AD 41 00    	LDA	!ZPGWRK+1
0132   1B7C DD 1D 1C    	CMP	ADRTAB+4,X
0133   1B7F 90 E4       	BCC	DR4
0134   1B81 98          	TYA
0135   1B82 DD 1C 1C    	CMP	ADRTAB+3,X
0136   1B85 90 DE       	BCC	DR4
0137   1B87             ;
0138   1B87 8A          	TXA
0139   1B88 18          	CLC
0140   1B89 69 04       	ADC	#4
0141   1B8B AA          	TAX
0142   1B8C EC 19 1C    	CPX	ADRTAB
0143   1B8F 90 C7       	BCC	DR3

Page      4    APPLE DOS 3.1

0144   1B91             	PAGE
0145   1B91             ;
0146   1B91             ;	RELOCATE CODE
0147   1B91             ;
0148   1B91 A2 00       	LDX	#0
0149   1B93 8E D4 32    DR7	STX	TEMP1
0150   1B96             ;
0151   1B96 BD 4B 1C    	LDA	CDETAB+1,X	; GET A START OF CODE ADR
0152   1B99 8D 40 00    	STA	!ZPGWRK		; PUT IN ZPG
0153   1B9C BD 4C 1C    	LDA	CDETAB+2,X
0154   1B9F 8D 41 00    	STA	!ZPGWRK+1
0155   1BA2             ;
0156   1BA2 A2 00       DR8	LDX	#0
0157   1BA4 A1 40       	LDA	(ZPGWRK,X)	; GET OP CODE
0158   1BA6 20 8E F8    	JSR	INSDS2		; GO FIND OUT HOW LONG
0159   1BA9             ;
0160   1BA9 AC 2F 00    	LDY	!LENGTH		; GET HOW LONG
0161   1BAC C0 02       	CPY	#2		; IF IT AINT
0162   1BAE D0 11       	BNE	DR9		; 3 THEN DONT RELOC
0163   1BB0 B1 40       	LDA	(ZPGWRK),Y	; GET PAGE FROM INST
0164   1BB2 CD 67 1C    	CMP	RSPAGE		; IF PAGE < REL START
0165   1BB5 90 0A       	BCC	DR9		; THEN IGNORE
0166   1BB7 CD 68 1C    	CMP	REPAGE		; IF PAGE >= REL END
0167   1BBA B0 05       	BCS	DR9		; THEN IGNORE
0168   1BBC 6D 6C 1C    	ADC	DELTA		; ELSE ADD DELTA
0169   1BBF 91 40       	STA	(ZPGWRK),Y	; TO RELOCATE
0170   1BC1             ;
0171   1BC1 38          DR9	SEC
0172   1BC2 AD 2F 00    	LDA	!LENGTH		; ADD LENGTH
0173   1BC5 6D 40 00    	ADC	!ZPGWRK		; TO PC
0174   1BC8 8D 40 00    	STA	!ZPGWRK
0175   1BCB A9 00       	LDA	#0
0176   1BCD 6D 41 00    	ADC	!ZPGWRK+1
0177   1BD0 8D 41 00    	STA	!ZPGWRK+1
0178   1BD3             ;
0179   1BD3 AE D4 32    	LDX	TEMP1		; CHECK FOR END
0180   1BD6 DD 4E 1C    	CMP	CDETAB+4,X	; OF CODE SEGMENT
0181   1BD9 90 C7       	BCC	DR8		; BR NOT END
0182   1BDB AD 40 00    	LDA	!ZPGWRK
0183   1BDE DD 4D 1C    	CMP	CDETAB+3,X
0184   1BE1 90 BF       	BCC	DR8		; BR NOT END
0185   1BE3             ;
0186   1BE3 8A          	TXA
0187   1BE4 18          	CLC
0188   1BE5 69 04       	ADC	#4		; INCREMENT TABLE INDEX
0189   1BE7 AA          	TAX
0190   1BE8 EC 4A 1C    	CPX	CDETAB		; DONE
0191   1BEB 90 A6       	BCC	DR7		; BR IF NOT
0192   1BED             ;

Page      5    APPLE DOS 3.1

0193   1BED             	PAGE
0194   1BED             ;
0195   1BED             ;	MOVE TO RELOCATED CODE
0196   1BED             ;
0197   1BED A9 3F       	LDA	#DEPAGE-1
0198   1BEF 8D 41 00    	STA	!ZPGWRK+1	; ZPGWRK=FROM
0199   1BF2 AC 6A 1C    	LDY	NEPAGE
0200   1BF5 88          	DEY
0201   1BF6 8C 43 00    	STY	!ZPGFCB+1	; ZPGFCB = TOO
0202   1BF9 A9 00       	LDA	#0
0203   1BFB 8D 40 00    	STA	!ZPGWRK
0204   1BFE 8D 42 00    	STA	!ZPGFCB
0205   1C01 A8          	TAY
0206   1C02             ;
0207   1C02 B1 40       DR10	LDA	(ZPGWRK),Y	; BYTE FROM
0208   1C04 91 42       	STA	(ZPGFCB),Y	; BYTE TO
0209   1C06 C8          	INY			; INCREMENT
0210   1C07 D0 F9       	BNE	DR10		; BR NOT FULL PAGE
0211   1C09 CE 6D 1C    	DEC	DPGCNT		; DECREMENT PAGE CNT
0212   1C0C F0 08       	BEQ	DR11		; BR IF DONE
0213   1C0E CE 41 00    	DEC	!ZPGWRK+1	; INC FROM PAGE
0214   1C11 CE 43 00    	DEC	!ZPGFCB+1	; INC TOO PAGE
0215   1C14 D0 EC       	BNE	DR10		; MOVE PAGE
0216   1C16             ;
0217   1C16 4C 36 1E    DR11	JMP	DBVECT+3	; DONE

Page      6    APPLE DOS 3.1

0218   1C19             	PAGE
0219   1C19             DEPAGE	EQU	EDOS/256
0220   1C19             DSPAGE	EQU	STARTT/256
0221   1C19             INSDS2	EQU	$F88E
0222   1C19             LENGTH	EQU	$2F
0223   1C19 24          ADRTAB	DB	9*4
0224   1C1A 00 1D 56 1D 	DW	@@SAT1,@@EAT1
0225   1C1E 58 1D 5A 1D 	DW	@@RUN,@@RUN+2
0226   1C22 62 1D 64 1D 	DW	@@IBVT+2,@@IBVT+4
0227   1C26 6A 1D 6E 1D 	DW	@@AS1VT,@@AS1VT+4
0228   1C2A 74 1D 78 1D 	DW	@@AS2VT,@@AS2VT+4
0229   1C2E 7A 1D 7C 1D 	DW	@@AS2VT+6,@@AS2VT+8
0230   1C32 03 2A 3F 2A 	DW	@@SAT2,@@EAT2
0231   1C36 E4 37 E8 37 	DW	@@BAIOB,@@ADOSLD+2
0232   1C3A EE 37 F0 37 	DW	@@IBDCTP,@@IBDCTP+2
0233   1C3E 00 00 00 00 	DW	@0,@0
0234   1C42 00 00 00 00 	DW	@0,@0
0235   1C46 00 00 00 00 	DW	@0,@0
0236   1C4A             CDETAB
0237   1C4A 18          	DB	6*4
0238   1C4B 7E 1D E0 27 	DW	@@SC1,@@EC1
0239   1C4F 3F 2A CF 32 	DW	@@SC2,@@EC2
0240   1C53 00 37 E0 37 	DW	@@SC3,@@EC3
0241   1C57 32 35 FE 35 	DW	@@SDP1,@@EDP1
0242   1C5B 00 38 8F 3A 	DW	@@ASC1,@@AEC1
0243   1C5F 00 3D FF 3F 	DW	@@ASC2,@@AEC2
0244   1C63 00 00 00 00 	DW	@0,@0
0245   1C67             ;
0246   1C67 1D          RSPAGE	DB	DSPAGE
0247   1C68 40          REPAGE	DB	DEPAGE
0248   1C69             ;
0249   1C69 00          NSPAGE	DB	0
0250   1C6A 00          NEPAGE	DB	0
0251   1C6B             ;
0252   1C6B 23          DOSLNG	DB	DEPAGE-DSPAGE
0253   1C6C             ;
0254   1C6C 00          DELTA	DB	0
0255   1C6D 23          DPGCNT	DB	DEPAGE-DSPAGE

Page      7    APPLE DOS 3.1

0256   1C6E             	PAGE
0257   1D00             	BOUND	256
0258   1D00             ;
0259   1D00             ;	RELOCATION TABLES
0260   1D00             ;
0261   1D00             START
0262   1D00             SAT1
0263   1D00 D3 1C       FTAB	DW	@@*-45		;START OF FTABS
0264   1D02 4D 1E       CINA	DW	@@CHRIN		;CHAR IN ADR
0265   1D04 7E 1E       COUTA	DW	@@CHROUT	;CHAR OUT ADR
0266   1D06 B8 29       FN1ADR	DW	@@FNAME1
0267   1D08 D6 29       FN2ADR	DW	@@FNAME2
0268   1D0A A3 29       SVBLA	DW	@@SVBL
0269   1D0C 00 1B       ASTART	DW	@@BEGIN		; CHANGED TO START BY RELOCATE
0270   1D0E EF 34       CCBADR	DW	@@CCB
0271   1D10             ;
0272   1D10             OUTSVT				;CHAR OUTPUT STATE VECTOR TABLE
0273   1D10 AB 1E       	DW	@@COS0-1
0274   1D12 CA 1E       	DW	@@COS1-1
0275   1D14 DB 1E       	DW	@@COS2-1
0276   1D16 E7 1E       	DW	@@COS3-1
0277   1D18 FD 1E       	DW	@@COS4-1
0278   1D1A 0C 1F       	DW	@@COS5-1
0279   1D1C 1C 1F       	DW	@@COS6-1
0280   1D1E             ;				COMMAND EXECUTION TABLE
0281   1D1E             CMDETB
0282   1D1E E3 24       	DW	@@EINIT-1
0283   1D20 A4 23       	DW	@@ELOAD-1
0284   1D22 2F 23       	DW	@@ESAVE-1
0285   1D24 75 24       	DW	@@ERUN-1
0286   1D26 8C 24       	DW	@@ECHAIN-1
0287   1D28 ED 21       	DW	@@EDEL-1
0288   1D2A FB 21       	DW	@@ELOCK-1
0289   1D2C FF 21       	DW	@@EUNLK-1
0290   1D2E 77 22       	DW	@@ECLOSE-1
0291   1D30 AF 24       	DW	@@EREAD-1
0292   1D32 4E 25       	DW	@@EEXEC-1
0293   1D34 A4 24       	DW	@@EWRITE-1
0294   1D36 65 25       	DW	@@EPOS-1
0295   1D38 35 22       	DW	@@EOPEN-1
0296   1D3A 22 22       	DW	@@EAPND-1
0297   1D3C 0B 22       	DW	@@EREN-1
0298   1D3E 00 25       	DW	@@ECAT-1
0299   1D40 BD 21       	DW	@@EMON-1
0300   1D42 C7 21       	DW	@@ENOMON-1
0301   1D44 B3 21       	DW	@@EPR-1
0302   1D46 B8 21       	DW	@@EIN-1
0303   1D48 DB 21       	DW	@@EMAXF-1
0304   1D4A 0C 25       	DW	@@EAS-1
0305   1D4C 30 25       	DW	@@EINT-1
0306   1D4E BF 22       	DW	@@EBSV-1
0307   1D50 EB 22       	DW	@@EBLD-1
0308   1D52 26 23       	DW	@@EBRUN-1
0309   1D54 07 22       	DW	@@EVAR-1
0310   1D56             EAT1

Page      8    APPLE DOS 3.1

0311   1D56             	PAGE
0312   1D56             ;
0313   1D56             ;	NON-RELOCATING ADRS
0314   1D56             ;
0315   1D56             IBASVT
0316   1D56 36 E8       CHAIN	DW	@@IBCHN
0317   1D58 82 24       RUN	DW	@@IBRUN
0318   1D5A E3 E3       BREAK	DW	@@IBBRK
0319   1D5C 00 E0       GO	DW	@@IBGO
0320   1D5E 03 E0       CONT	DW	@@IBCONT	;BASIC CONT ENTRY POINT
0321   1D60 36 E8 82 24 IBVT	DW	@@IBCHN,@@IBRUN,@@IBBRK
0321   1D64 E3 E3 
0322   1D66 00 E0 03 E0 	DW	@@IBGO,@@IBCONT
0323   1D6A             IBVTL	EQU	*-IBVT
0324   1D6A             ;
0325   1D6A 99 24 99 24 AS1VT	DW	@@ASRUN1,@@ASRUN1,@@ASBRK1
0325   1D6E 65 D8 
0326   1D70 00 E0 00 00 	DW	@@IBGO,@@0
0327   1D74             AS1VTL	EQU	*-AS1VT
0328   1D74             ;
0329   1D74 9F 24 9F 24 AS2VT	DW	@@ASRUN2,@@ASRUN2,@@ASBRK2
0329   1D78 67 10 
0330   1D7A 7E 1D 00 00 	DW	@@DBINIT,@@0
0331   1D7E             AS2VTL	EQU	*-AS2VT

Page      9    APPLE DOS 3.1

0332   1D7E             	PAGE
0333   1D7E             ;
0334   1D7E             ;	EQUATES REQD TO FIND THINGS IN APPLE II
0335   1D7E             ;
0336   1D7E             SETVID	EQU	$FE93
0337   1D7E             SETKBD	EQU	$FE89
0338   1D7E             PROMPT	EQU	$33		; PROMPT CHAR
0339   1D7E             OUTSW	EQU	$36		;OUTPUT VECTOR SWITCH
0340   1D7E             INSW	EQU	$38		;INPUT VECTOR SWITCH
0341   1D7E             ZPGWRK	EQU	$40		;ZERO PAGE WORK CELL
0342   1D7E             CNUM	EQU	$44		;CONVERTED NUMERIC
0343   1D7E             LBUFF	EQU	$200		;LINE BUFFER
0344   1D7E             MULT	EQU	$FB63		;MULT ROUTINE
0345   1D7E             INPRT	EQU	$FE8B		;SET IN PORT
0346   1D7E             OUTPRT	EQU	$FE95		; SET OUT PORT
0347   1D7E             IBCHN	EQU	$E836		;BASIC RUN
0348   1D7E             IBLMEM	EQU	$4A		;BASIC LOW MEMORY
0349   1D7E             IBHMEM	EQU	$4C		;INTEGER BASIC HIMEM
0350   1D7E             IBSOP	EQU	$CA		;INTEGER BASIC START OF CGM
0351   1D7E             IBBRK	EQU	$E3E3		; BASIC BREAK
0352   1D7E             IBGO	EQU	$E000		; BASIC ENTRY POINT
0353   1D7E             IBCONT	EQU	$E003		; BASIC CONTINUE ENTRY POINT
0354   1D7E             IBSOV	EQU	$CC		; BASIC START OF VARIABLES
0355   1D7E             ASSOP	EQU	$67		; AS START OF PROGRAM
0356   1D7E             ASEOP	EQU	$AF		; AS END OF PROGRAM
0357   1D7E             ASEOP2	EQU	$69		;AS END-OF PGM 2
0358   1D7E             ASHM1	EQU	$73		; AS HIGH MEM 1
0359   1D7E             ASHM2	EQU	$6F		; AS HIGH MEM 2
0360   1D7E             ASLMEM	EQU	ASSOP		; AS LOW MEM
0361   1D7E             ASBRK1	EQU	$D865		; AS ROM BREAK
0362   1D7E             ASBRK2	EQU	$1067		; AS RAM BREAK
0363   1D7E             AITSTL	EQU	$E000		; AS 1 IB TEST LOC
0364   1D7E             ATSTV	EQU	$4C		; AS TEST VALUE
0365   1D7E             ITSTV	EQU	$20		; IB TEST VALUE
0366   1D7E             BOOTSL	EQU	$2E		;BOOT FROM SLOT
0367   1D7E             ZPGFCB	EQU	$42		;ZERO PAGE WORK CELL
0368   1D7E             HOME	EQU	$FC58
0369   1D7E             PRINT	EQU	$FDED
0370   1D7E             GETKEY	EQU	$FD0C

Page     10    APPLE DOS 3.1

0371   1D7E             	PAGE
0372   1D7E             ;
0373   1D7E             ;	DOS BASIC INTERPRETER  INITIAL ENTRY
0374   1D7E             ;
0375   1D7E             SC1
0376   1D7E             DBINIT
0377   1D7E AD E9 37    	LDA	IBSLOT		;GET BOOT SLOT
0378   1D81 4A          	LSRA
0379   1D82 4A          	LSRA
0380   1D83 4A          	LSRA
0381   1D84 4A          	LSRA
0382   1D85 8D AD 29    	STA	CS		;SET AS CURRENT SLOT
0383   1D88 AD EA 37    	LDA	IBDRVN		;GET BOOT DRIVE NUMBER
0384   1D8B 8D AB 29    	STA	CD		;SET AS CURRENT DRIVE
0385   1D8E AD 00 E0    	LDA	AITSTL		; GET APPLESOFT/IB TEST
0386   1D91 49 20       	EOR	#ITSTV		; IF AS THEN
0387   1D93 D0 11       	BNE	IAS1		; GO TO AS INIT
0388   1D95             ;				; ELSE INIT FOR IB
0389   1D95 8D F9 29    	STA	ASIBSW		; SET SW FOR IB
0390   1D98 A2 0A       	LDX	#IBVTL		; GET IB VT LENGTH
0391   1D9A BD 5F 1D    IIB1	LDA	IBVT-1,X	; MOVE IB ADDR
0392   1D9D 9D 55 1D    	STA	IBASVT-1,X
0393   1DA0 CA          	DEX
0394   1DA1 D0 F7       	BNE	IIB1
0395   1DA3 4C B6 1D    	JMP	INITAA
0396   1DA6             ;
0397   1DA6             IAS1
0398   1DA6 A9 40       	LDA	#$40		; INDICATE ROM APPLESOFT
0399   1DA8 8D F9 29    	STA	ASIBSW
0400   1DAB A2 0A       	LDX	#AS1VTL
0401   1DAD BD 69 1D    IAS1A	LDA	AS1VT-1,X	; MOVE ROM AS ADRS
0402   1DB0 9D 55 1D    	STA	IBASVT-1,X
0403   1DB3 CA          	DEX
0404   1DB4 D0 F7       	BNE	IAS1A
0405   1DB6             ;
0406   1DB6             INITAA
0407   1DB6 38          	SEC			; INDICATE INIT
0408   1DB7 B0 01       	BCS	INITA
0409   1DB9             DBRST
0410   1DB9 18          	CLC			; INDICATE RESET
0411   1DBA             ;
0412   1DBA             INITA
0413   1DBA 08          	PHP			; SAVE INIT/RESET
0414   1DBB 20 AD 27    	JSR	MVCSW		; GO MOVE CHAR SWITCH
0415   1DBE A9 70       	LDA	#MC+MI+MO	; SET MONITOR MODES
0416   1DC0 8D A1 29    	STA	MONMOD
0417   1DC3 A9 00       	LDA	#0
0418   1DC5 8D 95 29    	STA	OSTATE		; CLEAR OUTSTATE AND EXECUTE STATE
0419   1DC8 28          	PLP			; GET INIT/RESET
0420   1DC9 6A          	RORA			;SHIFT CARRY TO MSB
0421   1DCA 8D 94 29    	STA	ISTATE		; SAVE INSTATE
0422   1DCD 30 03       	BMI	INITB		; BR IF INIT
0423   1DCF 6C 5E 1D    	JMP	(CONT)		;GO TO CONTINUE ENTRY
0424   1DD2 6C 5C 1D    INITB	JMP	(GO)		; GO TO ENTRY

Page     11    APPLE DOS 3.1

0425   1DD5             	PAGE
0426   1DD5             INITC
0427   1DD5 0A          	ASLA			; OF ISTATE NOT ON
0428   1DD6 10 19       	BPL	INITD		; THEN NOT RAM AS
0429   1DD8 8D F9 29    	STA	ASIBSW		; SET RAM AS
0430   1DDB A2 0A       	LDX	#AS2VTL
0431   1DDD BD 73 1D    IAS2A	LDA	AS2VT-1,X	; MOVE RAM AS ADRS
0432   1DE0 9D 55 1D    	STA	IBASVT-1,X
0433   1DE3 CA          	DEX
0434   1DE4 D0 F7       	BNE	IAS2A
0435   1DE6 A2 1D       	LDX	#29
0436   1DE8 BD D6 29    IAS2B	LDA	FNAME2,X
0437   1DEB 9D B8 29    	STA	FNAME1,X         
0438   1DEE CA          	DEX
0439   1DEF 10 F7       	BPL	IAS2B
0440   1DF1             ;
0441   1DF1             INITD
0442   1DF1 AD F4 29    	LDA	DFNFTS		; GO BUILD FILE TABS
0443   1DF4 8D 9A 29    	STA	CNFTBS		; AND SET MEM BOUNDS
0444   1DF7 20 30 27    	JSR	BLDFTB
0445   1DFA AD F6 29    	LDA	ESTATE		;GET EXEC STATE
0446   1DFD F0 09       	BEQ	INITZ		; BR IF NOT EXECTUTE
0447   1DFF 48          	PHA			;SVE CHAR
0448   1E00 20 01 26    	JSR	MVEFTA		;GO MOVE EX FILE TAB ADR TO ZP
0449   1E03 68          	PLA			;GET SAVED CHAR
0450   1E04 A0 00       	LDY	#0
0451   1E06 91 40       	STA	(ZPGWRK),Y	;
0452   1E08             INITZ
0453   1E08 20 B7 26    	JSR	CLRSTS		; SET IN AND OUT STATES TO ZERO
0454   1E0B A2 27       	LDX	#IFBL
0455   1E0D BD 33 1E    INITE	LDA	DBVECT,X	;MOVE RESTART VECTORS	
0456   1E10 9D D0 03    	STA	$3D0,X
0457   1E13 CA          	DEX
0458   1E14 10 F7       	BPL	INITE
0459   1E16 AD A2 29    	LDA	CMDNO		; IF NOT BOOT
0460   1E19 D0 0A       	BNE	INITF		; THEN DONE
0461   1E1B AD B8 29    	LDA	FNAME1		; IF FN1
0462   1E1E 49 A0       	EOR	#$A0		; NOT DONE
0463   1E20 F0 03       	BEQ	INITF		; THEN DONE
0464   1E22 4C 76 24    	JMP	ERUN		; ELSE
0465   1E25             ;
0466   1E25             IFB
0467   1E25             INITF
0468   1E25 AD A5 29    	LDA	SVCMD
0469   1E28 F0 06       	BEQ	INITG
0470   1E2A 8D A2 29    	STA	CMDNO
0471   1E2D 4C FF 20    	JMP	CMDGO
0472   1E30             INITG
0473   1E30 4C 50 1F    	JMP	ORTN
0474   1E33             ;
0475   1E33 4C B9 1D    DBVECT	JMP	DBRST
0476   1E36 4C 7E 1D    	JMP	DBINIT
0477   1E39 4C 3F 2A    	JMP	DOSENT
0478   1E3C 4C 00 3D    	JMP	DISKIO
0479   1E3F             CCBLDR
0480   1E3F AD 0F 1D    	LDA	CCBADR+1
0481   1E42 AC 0E 1D    	LDY	CCBADR
0482   1E45 60          	RTS
0483   1E46             IOBLDR
0484   1E46 AD 04 2A    	LDA	AIOB+1
0485   1E49 AC 03 2A    	LDY	AIOB
0486   1E4C 60          	RTS
0487   1E4D             IFBL	EQU	*-IFB-1

Page     12    APPLE DOS 3.1

0488   1E4D             	PAGE
0489   1E4D             ;
0490   1E4D             ;	CHRIN  CHAR RCVD VIA IN SWITCH
0491   1E4D             ;
0492   1E4D             CHRIN
0493   1E4D 20 92 1E    	JSR	SVREGS
0494   1E50 AD 94 29    	LDA	ISTATE		;IF NOT DISKIN
0495   1E53 F0 0D       	BEQ	CHIN1		;THEN BRANCH, ELSE
0496   1E55 10 03       	BPL	CHIN0
0497   1E57 4C D5 1D    	JMP	INITC
0498   1E5A             CHIN0
0499   1E5A AD 9F 29    	LDA	SVA
0500   1E5D 91 28       	STA	($28),Y
0501   1E5F 4C AD 25    	JMP	INCFD		;AND GET CHAR FROM DISK
0502   1E62             CHIN1
0503   1E62 AD F6 29    	LDA	ESTATE
0504   1E65 F0 03       	BEQ	CHIN2
0505   1E67 4C E6 25    	JMP	NXTEXC
0506   1E6A             CHIN2
0507   1E6A A9 03       	LDA	#3		;SET OUT CHAR
0508   1E6C 8D 95 29    	STA	OSTATE		;STATE TO INPUT ECHO
0509   1E6F 20 57 1F    	JSR	LDREGS
0510   1E72 20 7B 1E    	JSR	GETIN
0511   1E75 8D 9F 29    	STA	SVA
0512   1E78 4C 50 1F    	JMP	ORTN
0513   1E7B             ;
0514   1E7B 6C 38 00    GETIN	JMP	(INSW)
0515   1E7E             ;
0516   1E7E             ;	CHROUT  CHAR RCVD VIA OUTPUT SWITCH
0517   1E7E             ;
0518   1E7E             CHROUT
0519   1E7E 20 92 1E    	JSR	SVREGS		;SAVE REGS
0520   1E81             ;
0521   1E81 AD 95 29    	LDA	OSTATE		;GET OUT SPARE
0522   1E84 0A          	ASLA
0523   1E85 AA          	TAX
0524   1E86 BD 11 1D    	LDA	OUTSVT+1,x	;GET ROUTINE ADR
0525   1E89 48          	PHA
0526   1E8A BD 10 1D    	LDA	OUTSVT,x
0527   1E8D 48          	PHA
0528   1E8E AD 9F 29    	LDA	SVA
0529   1E91 60          	RTS			;GO TO ROUTINE
0530   1E92             ;
0531   1E92             ;	SVREGS  SAVE REGS WHILE PROCESSING CHARS
0532   1E92             ;
0533   1E92             SVREGS
0534   1E92 8D 9F 29    	STA	SVA		;SAVE ACU
0535   1E95 8E 9D 29    	STX	SVX
0536   1E98 8C 9E 29    	STY	SVY
0537   1E9B BA          	TSX
0538   1E9C E8          	INX
0539   1E9D E8          	INX
0540   1E9E 8E 9C 29    	STX	SVSTK
0541   1EA1 A2 03       	LDX	#3		;SET FOR FOUR BYTE MOVE
0542   1EA3 BD 96 29    SVRB	LDA	SVOUTS,X	;MOVE SAVED OUT AND IN SW
0543   1EA6 95 36       	STA	OUTSW,X		;TO APPLE OUT/IN SW
0544   1EA8 CA          	DEX
0545   1EA9 10 F8       	BPL	SVRB
0546   1EAB 60          	RTS			;DONE

Page     13    APPLE DOS 3.1

0547   1EAC             	PAGE
0548   1EAC             ;
0549   1EAC             ;	COS0  1ST CHAR OF PRINTED OUTPUT LINE
0550   1EAC             ;		CHECK FOR CNTL-D
0551   1EAC             ;
0552   1EAC             COS0
0553   1EAC AE 94 29    	LDX	ISTATE		; IS IN STATE NOT ZERO
0554   1EAF F0 08       	BEQ	COS01
0555   1EB1 C9 BF       	CMP	#'?'+$80	;THEN IS THIS ?
0556   1EB3 F0 68       	BEQ	COS6		;THEN PRINT ONLY IF MONITOR
0557   1EB5 C5 33       	CMP	PROMPT
0558   1EB7 F0 64       	BEQ	COS6
0559   1EB9             COS01
0560   1EB9 A2 02       	LDX	#2
0561   1EBB 8E 95 29    	STX	OSTATE
0562   1EBE CD F5 29    	CMP	CCHAR		;IF NOT CNTL-D
0563   1EC1 D0 19       	BNE	COS2		; THEN GO TO STATE 2
0564   1EC3 CA          	DEX
0565   1EC4 8E 95 29    	STX	OSTATE		;ELSE STATE = 1
0566   1EC7 CA          	DEX
0567   1EC8 8E A0 29    	STX	LBUFD		;AND LBUFD=0
0568   1ECB             ;
0569   1ECB             ;	COS1  ACCUMULATE CMD FROM PRINTED OUTPUT
0570   1ECB             ;
0571   1ECB             COS1
0572   1ECB AE A0 29    	LDX	LBUFD		;GET LINE BUFF DISPL
0573   1ECE 9D 00 02    COS1A	STA	LBUFF,X		;PUT CHAR IN BUFF
0574   1ED1 E8          	INX			;INCR PTR
0575   1ED2 8E A0 29    	STX	LBUFD		;SAVE PTR
0576   1ED5 C9 8D       	CMP	#$8D		;WAS THIS A CR
0577   1ED7 D0 62       	BNE	CMDRTN		;IF NOT THEN PR CHAR
0578   1ED9             ;
0579   1ED9 4C 6F 1F    	JMP	SCNCMD		;GO SCAN COMMAND
0580   1EDC             ;
0581   1EDC             ;	COS2  PRINTED OUTPUT, NOT FIRST CHAR
0582   1EDC             ;
0583   1EDC             COS2
0584   1EDC C9 8D       	CMP	#$8D		;IS IT A CR
0585   1EDE D0 6A       	BNE	PRRTN		;BR IF NOT
0586   1EE0 A2 00       	LDX	#0		;SET FOR POSSIBLE C-D NEXT
0587   1EE2 8E 95 29    	STX	OSTATE		;NEXT STATE
0588   1EE5 4C 4A 1F    	JMP	PRRTN		;GO PRINT CHAR

Page     14    APPLE DOS 3.1

0589   1EE8             	PAGE
0590   1EE8             ;
0591   1EE8             ;	COS3  KEY IN ECHO PRINT
0592   1EE8             ;
0593   1EE8             COS3
0594   1EE8 A2 00       	LDX	#0
0595   1EEA 8E 95 29    	STX	OSTATE		;RESET OUT STATE
0596   1EED C9 8D       	CMP	#$8D		;IS IT CR
0597   1EEF F0 07       	BEQ	COS3A		; IF CR THEN CMD CHECK
0598   1EF1 AD F6 29    	LDA	ESTATE		;ELSE: IF NOT EXECUTE
0599   1EF4 F0 54       	BEQ	PRRTN		; THEN PRINT CHAR
0600   1EF6 D0 4B       	BNE	DRTNI		; ELSE: PRINT IF MON INPUT
0601   1EF8             COS3A
0602   1EF8 AE 9D 29    	LDX	SVX		;GET LINE INDEX
0603   1EFB 4C CE 1E    	JMP	COS1A
0604   1EFE             ;
0605   1EFE             ;	COS4  DISK OUTPUT MODE
0606   1EFE             ;
0607   1EFE             COS4
0608   1EFE C9 8D       	CMP	#$8D		;IS IT CR
0609   1F00 D0 05       	BNE	COS4A		;BR IF NOT CR
0610   1F02 A9 05       	LDA	#5		;SET STATE FOR CNTL-D
0611   1F04 8D 95 29    	STA	OSTATE		;EXAMINE
0612   1F07 20 97 25    COS4A	JSR	OCTD		;GO OUTPUT CHAR TO DISK
0613   1F0A 4C 3F 1F    	JMP	DRTNO		;GO TO DATA RETURN (OUT)
0614   1F0D             ;
0615   1F0D             ;	COS5  DISK OUTPUT MODE  1ST CHAR OF A LINE
0616   1F0D             ;
0617   1F0D             COS5
0618   1F0D CD F5 29    	CMP	CCHAR		;IS IT CNTL D
0619   1F10 F0 9A       	BEQ	COS0		;BR IF CNTL D
0620   1F12 C9 8A       	CMP	#$8A		;LINE FEED?
0621   1F14 F0 F1       	BEQ	COS4A
0622   1F16 A2 04       	LDX	#4
0623   1F18 8E 95 29    	STX	OSTATE		;SET NEW OUT STATE
0624   1F1B D0 E1       	BNE	COS4		;BR IF NOT CNTL D
0625   1F1D             ;                               
0626   1F1D             ;	COS6  DISK INPUT ECHO  
0627   1F1D             ;                               
0628   1F1D A9 00       COS6	LDA	#0
0629   1F1F 8D 95 29    	STA	OSTATE		;RESET OUT STATE = 0
0630   1F22 F0 1F       	BEQ	DRTNI		;GO TO DATA IN RETURN

Page     15    APPLE DOS 3.1

0631   1F24             	PAGE
0632   1F24             ;
0633   1F24             ;	PRRTN  PRINT CHAR RETURN
0634   1F24             ;
0635   1F24             ;
0636   1F24             ;	CMDRTN  PRINT CHAR IF MONITOR CMBS MODE
0637   1F24             ;	DRTNO  PRINT CHAR IF MONITOR DATA OUT
0638   1F24             ;	DRTNI  PRINT CHAR IF MONITOR DATA IN
0639   1F24             ;
0640   1F24             CERTN
0641   1F24 AD 00 02    	LDA	LBUFF		; CHECK FOR PRINTED COMMAND
0642   1F27 CD F5 29    	CMP	CCHAR
0643   1F2A F0 0F       	BEQ	CMDRTN		; IF PC THEN NO RESET X REG
0644   1F2C A9 A0       	LDA	#$A0		;BLANK
0645   1F2E 8D 00 02    	STA	LBUFF
0646   1F31 A9 8D       	LDA	#$8D		;PLUS CR
0647   1F33 8D 01 02    	STA	LBUFF+1		; TO OUT BUFFER
0648   1F36 A2 00       	LDX	#0		;RESET TO SOL
0649   1F38 8E 9D 29    	STX	SVX
0650   1F3B A9 40       CMDRTN	LDA	#MC
0651   1F3D D0 06       	BNE	MODECK
0652   1F3F A9 10       DRTNO	LDA	#MO
0653   1F41 D0 02       	BNE	MODECK
0654   1F43 A9 20       DRTNI	LDA	#MI
0655   1F45             ;
0656   1F45             MODECK
0657   1F45 2D A1 29    	AND	MONMOD		;AND WITH MODE
0658   1F48 F0 06       	BEQ	ORTN		;BR IF NOT PRINT
0659   1F4A 20 57 1F    PRRTN	JSR	LDREGS
0660   1F4D 20 61 1F    	JSR	ORTN1
0661   1F50             ORTN
0662   1F50 20 AD 27    	JSR	MVCSW
0663   1F53 AE 9C 29    	LDX	SVSTK
0664   1F56 9A          	TXS
0665   1F57             LDREGS
0666   1F57 AD 9F 29    	LDA	SVA		;ACU
0667   1F5A AC 9E 29    	LDY	SVY		;Y
0668   1F5D AE 9D 29    	LDX	SVX		;X
0669   1F60 60          	RTS			;BY PASS PRINT
0670   1F61             ;
0671   1F61 6C 36 00    ORTN1	JMP	(OUTSW)
0672   1F64             ;
0673   1F64             ;	PRCRIF  PRINT CR IF MON CMDS
0674   1F64             ;
0675   1F64             PRCRIF
0676   1F64 2C A1 29    	BIT	MONMOD		; IF NOT MON CMDS
0677   1F67 50 05       	BVC	PRCIFR		; THEN RETURN
0678   1F69 A9 8D       	LDA	#$8D		; ELSE PRINT CR
0679   1F6B 20 61 1F    	JSR	ORTN1
0680   1F6E 60          PRCIFR	RTS

Page     16    APPLE DOS 3.1

0681   1F6F             	PAGE
0682   1F6F             ;
0683   1F6F             ;	SCNCMD  SCAN COMMAND
0684   1F6F             ;
0685   1F6F             SCNCMD
0686   1F6F A0 FF       	LDY	#$FF
0687   1F71 8C A2 29    	STY	CMDNO		;RESET COMMAND NUMBER
0688   1F74 C8          	INY
0689   1F75 8C A5 29    	STY	SVCMD
0690   1F78             SC0
0691   1F78 EE A2 29    	INC	CMDNO		;INCR CMD NO
0692   1F7B A2 00       	LDX	#0		;RESET LINE INDEX TO 0
0693   1F7D 08          	PHP			; SAVE EQ STATUS
0694   1F7E BD 00 02    	LDA	LBUFF,X		;GET 1ST  LINE CHAR
0695   1F81 CD F5 29    	CMP	CCHAR		; IS IT CONTROL D
0696   1F84 D0 01       	BNE	SC0A		; BR /IF NOT
0697   1F86 E8          	INX			;INCR OVER CNTLD
0698   1F87 8E A0 29    SC0A	STX	LBUFD
0699   1F8A             ;
0700   1F8A             SC1X
0701   1F8A 20 29 21    	JSR	GNBC		; GET NON BLANK INPUT CHAR
0702   1F8D 29 7F       	AND	#$7F		; MSB OF CHAR OFF
0703   1F8F 59 E0 27    	EOR	CMDNTB,Y		; EOR WITH INPUT
0704   1F92 C8          	INY			; INCREMENT TABLE INDEX
0705   1F93 0A          	ASLA			; IF MSB OF EOR RESULT ON
0706   1F94 F0 02       	BEQ	SC1A		; IF RESULT NOT NOW ZERO
0707   1F96 68          	PLA			; THEN INPUT DOES NOT
0708   1F97 08          	PHP			; EQUAL ENTRY
0709   1F98 90 F0       SC1A	BCC	SC1X		; LOOP FOR END ENTRY
0710   1F9A             ;
0711   1F9A 28          	PLP			; IF INPUT EQUALS END
0712   1F9B F0 20       	BEQ	SYNTAX		; THEN GO SYNTAX
0713   1F9D             ;
0714   1F9D B9 E0 27    	LDA	CMDNTB,Y	; IF NEXT TABLE CHAR NOT ZERO
0715   1FA0 D0 D6       	BNE	SC0		; THEN SCAN THE NEXT TABLE ENTRY
0716   1FA2             CNF				;COMMAND NOT FOUND
0717   1FA2 AD 00 02    	LDA	LBUFF		;LINE IS A CONTROL-D
0718   1FA5 CD F5 29    	CMP	CCHAR		; THEN THIS IS A
0719   1FA8 F0 03       	BEQ	CNF1		;POSSIBLE SYNTAX ERROR, ELSE
0720   1FAA 4C 4A 1F    	JMP	PRRTN		;ITS A BASIC INPUT LINE
0721   1FAD             CNF1
0722   1FAD AD 01 02    	LDA	LBUFF+1		;GET  NEXT CHAR
0723   1FB0 C9 8D       	CMP	#$8D		;IS IT A CR
0724   1FB2 D0 06       	BNE	CSERR		;BR IF CR
0725   1FB4 20 B7 26    	JSR	CLRSTS		; CLEAR THE STATES
0726   1FB7 4C 3B 1F    	JMP	CMDRTN		;CNTL-D ONLY
0727   1FBA             ;
0728   1FBA 4C 22 26    CSERR	JMP	ESYNTX

Page     17    APPLE DOS 3.1

0729   1FBD             	PAGE
0730   1FBD             ;
0731   1FBD             ;	SYNTAX  FIGURE OUT WHAT WE GOT HERE
0732   1FBD             ;
0733   1FBD             SYNTAX
0734   1FBD AD A2 29    	LDA	CMDNO		;CMDNO=CMDNO*2
0735   1FC0 0A          	ASLA
0736   1FC1 8D A2 29    	STA	CMDNO
0737   1FC4             ;
0738   1FC4 A8          	TAY
0739   1FC5 A9 20       	LDA	#FN1
0740   1FC7 39 65 28    	AND	CMDSTB,Y	;IS FN1 REGD
0741   1FCA F0 63       	BEQ	SN10		;BR IF NOT 
0742   1FCC 20 22 20    	JSR	CLRFNS
0743   1FCF 08          	PHP			; SAVE EG STATUS
0744   1FD0             SN2
0745   1FD0 20 29 21    	JSR	GNBC		;GET NON BLANK CHAR
0746   1FD3 F0 1E       	BEQ	SN6		;BR IF CR OR COMMA
0747   1FD5 0A          	ASLA			; TEST FOR ALPHA
0748   1FD6 90 05       	BCC	SN2A		; BR IF ALPHA
0749   1FD8 30 03       	BMI	SN2A		; BR IS ALPHA
0750   1FDA 4C A2 1F    	JMP	CNF		; LURCH IF NOT ALPHA
0751   1FDD 6A          SN2A	RORA			;RESTORE BITS
0752   1FDE 4C E6 1F    	JMP	SN4		;AWAY WE GO
0753   1FE1 20 18 21    SN3	JSR	GNXTC		;GO GET NEXT CHAR
0754   1FE4 F0 0D       	BEQ	SN6		;BR IF COMMA OR CHAR
0755   1FE6 99 B8 29    SN4	STA	FNAME1,Y	;PUT INTO FILENAME
0756   1FE9 C8          	INY			;INC FN INDEX
0757   1FEA C0 3C       	CPY	#60		; ATFN FN INDEX
0758   1FEC 90 F3       	BCC	SN3		;BR IF NOT
0759   1FEE 20 18 21    SN5	JSR	GNXTC		;LOOP UNTIL CR OR COMMA
0760   1FF1 F0 FB       	BEQ	SN5		
0761   1FF3             ;
0762   1FF3 28          SN6	PLP			;WAS THIS FN2 L OO
0763   1FF4 D0 0F       	BNE	SN7		;BR IF IT WAS
0764   1FF6             ;
0765   1FF6 AC A2 29    	LDY	CMDNO
0766   1FF9 A9 10       	LDA	#FN2
0767   1FFB 39 65 28    	AND	CMDSTB,Y	;IF FN2 NOT REGD THEN
0768   1FFE F0 0C       	BEQ	SN8		;BRANCH
0769   2000             ;
0770   2000 A0 1E       	LDY	#30		; SET FN2 INDEX
0771   2002 08          	PHP			; INDICATE FN2 SEEK
0772   2003 D0 CB       	BNE	SN2		;GO LOOK FOR FN2
0773   2005             ;
0774   2005 AD D6 29    SN7	LDA	FNAME2		;IF 1ST CHAR OF
0775   2008 C9 A0       	CMP	#$A0		;FN2 IS BLANK THEN
0776   200A F0 13       	BEQ	SERR1		;SYNTAX ERROR
0777   200C             ;
0778   200C AD B8 29    SN8	LDA	FNAME1		;IF 1ST CHAR OF
0779   200F C9 A0       	CMP	#$A0		;FN1 IS NOT BLANK
0780   2011 D0 45       	BNE	SOPTS		;THEN GO LOOK FOR OPTIONS
0781   2013             ;
0782   2013 AC A2 29    	LDY	CMDNO
0783   2016 A9 C0       	LDA	#NPB+NPE	;IF CMD MUST HAVE FILENAME
0784   2018 39 65 28    	AND	CMDSTB,Y	;THEN
0785   201B F0 02       	BEQ	SERR1		;THIS IS ERROR ELSE
0786   201D             ;
0787   201D 10 39       	BPL	SOPTS		; ITS EXECUTABLE WITHOUT
0788   201F             ;
0789   201F 4C A2 1F    SERR1	JMP	CNF
0790   2022             ;
0791   2022             CLRFNS
0792   2022 A9 00       	LDA	#0
0793   2024 A0 3C       	LDY	#60
0794   2026             CLRFNA
0795   2026 A9 A0       	LDA	#$A0
0796   2028 99 B7 29    SN1	STA	FNAME1-1,Y	;CLEAR FN1, FN2
0797   202B 88          	DEY
0798   202C D0 FA       	BNE	SN1
0799   202E 60          	RTS

Page     18    APPLE DOS 3.1

0800   202F             	PAGE
0801   202F             SN10				;FILE NAMES NOT REGD
0802   202F 8D B8 29    	STA	FNAME1
0803   2032 A9 0C       	LDA	#NUM1+NUM2	;IF NEITHER NUM1
0804   2034 39 65 28    	AND	CMDSTB,Y	;OR NUM2 IS REGD
0805   2037 F0 1F       	BEQ	SOPTS		;THEN GO LOOK AT OPTIONS
0806   2039             ;
0807   2039 20 3E 21    	JSR	GETNUM		;GO GET NUMERICS
0808   203C B0 E1       	BCS	SERR1
0809   203E             ;
0810   203E A8          	TAY			; IF HIGH DIGIT NOT
0811   203F D0 DE       	BNE	SERR1		;ZERO THEN BAD
0812   2041             ;
0813   2041 E0 11       	CPX	#17		;IF LOW DIGIT GT 16
0814   2043 B0 DA       	BCS	SERR1		;THEN BAD
0815   2045             ;
0816   2045 AC A2 29    	LDY	CMDNO
0817   2048 A9 08       	LDA	#NUM1
0818   204A 39 65 28    	AND	CMDSTB,Y	;IF WE WANT NUM2
0819   204D F0 06       	BEQ	SN11
0820   204F             ;
0821   204F E0 08       	CPX	#8		;IF NUM2>1
0822   2051 B0 CC       	BCS	SERR1		;THEN ERROR, ELSE
0823   2053 90 03       	BCC	SOPTS		;GO SCAN OPTIONS
0824   2055             ;
0825   2055             SN11
0826   2055 8A          	TXA			;IF NUM1=0
0827   2056 F0 C7       	BEQ	SERR1		;THEN ERROR, ELSE
0828   2058             ;

Page     19    APPLE DOS 3.1

0829   2058             	PAGE
0830   2058             ;
0831   2058             ;	SOPTS  LOOK FOR SYNTAX OPTIONS
0832   2058             ;
0833   2058             SOPTS
0834   2058 A9 00       	LDA	#0
0835   205A 8D A8 29    	STA	INOPTS		;CLEAR INPUT OPTIONS
0836   205D 8D B7 29    	STA	IMBITS
0837   2060 8D AF 29    	STA	CL
0838   2063 8D B0 29    	STA	CL+1
0839   2066 8D A6 29    	STA	TEMP1A
0840   2069 AD A0 29    	LDA	LBUFD		;SET PASS 1
0841   206C             ;
0842   206C 20 29 21    SP1	JSR	GNBC		;GO GET NON-BLANK CHAR
0843   206F D0 1F       	BNE	SP2		;BR IF NOT COMMA OR CR
0844   2071 C9 8D       	CMP	#$8D		;IF CHAR IS COMMA
0845   2073 D0 F7       	BNE	SP1		;THEN GO GET CHAR
0846   2075             ;
0847   2075 AE A2 29    	LDX	CMDNO		;OPTIONS INPUT = I
0848   2078 AD A8 29    	LDA	INOPTS		;ALLOW OPTS = A
0849   207B 1D 66 28    	ORA	CMDSTB+1,X	;IF (A OR I)
0850   207E 5D 66 28    	EOR	CMDSTB+1,X	;OR A NOT = 0 THEN
0851   2081 D0 9C       	BNE	SERR1		;WE HAVE UNALLOWED OPTIONS
0852   2083             ;
0853   2083 AE A6 29    	LDX	TEMP1A		;IF THIS IS PASS 2
0854   2086 F0 77       	BEQ	CMDGO		;THEN DONE,
0855   2088 8D A6 29    	STA	TEMP1A		;ELSE SET PASS
0856   208B 8E A0 29    	STX	LBUFD		;RESTORE LBUFD AND
0857   208E D0 DC       	BNE	SP1		;GO DO PASS 2
0858   2090             ;
0859   2090 A2 0A       SP2	LDX	#OPT1L		;COMPARE CHAR HAVE WITH
0860   2092 DD 9C 28    SP3	CMP	OPTAB1-1,X	;CHARS IN OPT TABLE
0861   2095 F0 05       	BEQ	SP4		;IF NOT FOUND CONTINUE
0862   2097 CA          	DEX
0863   2098 D0 F8       	BNE	SP3		;IF NOT FOUND
0864   209A F0 60       	BEQ	SERR2		;THEN SYNTAX ERROR
0865   209C             ;
0866   209C BD A6 28    SP4	LDA	OPTAB2-1,X	;IF CORRESPONDING OP TAB 2 IS
0867   209F 30 47       	BMI	SP8		;MINUS THEN IT MONITOR BITS
0868   20A1 0D A8 29    	ORA	INOPTS
0869   20A4 8D A8 29    	STA	INOPTS
0870   20A7 CA          	DEX
0871   20A8             ;
0872   20A8 8E A7 29    	STX	TEMP2A		;ELSE A NUMERIC MUST FOLLOW
0873   20AB 20 3E 21    	JSR	GETNUM		;FOLLOW
0874   20AE B0 4C       	BCS	SERR2
0875   20B0             ;
0876   20B0 AD A7 29    	LDA	TEMP2A		; GET IOTION NUMBER
0877   20B3 0A          	ASLA			;MULT BY 4
0878   20B4 0A          	ASLA
0879   20B5 A8          	TAY
0880   20B6             ;
0881   20B6 A5 45       	LDA	CNUM+1		;IF RESULT NUM HI IS
0882   20B8 D0 09       	BNE	SP5		;GT 0, THEN GT LOW RANGE
0883   20BA A5 44       	LDA	CNUM		;TEST RESULT LOW
0884   20BC D9 B1 28    	CMP	OPTAB3,Y	;WITH LOW RANGE (LOW)
0885   20BF 90 3B       	BCC	SERR2		;BR IF RESULT < LR
0886   20C1 A5 45       	LDA	CNUM+1
0887   20C3 D9 B4 28    SP5	CMP	OPTAB3+3,Y
0888   20C6 90 0B       	BCC	SP6		;BR IF LESS
0889   20C8 D0 32       	BNE	SERR2		;BR IF GRREATER
0890   20CA A5 44       	LDA	CNUM
0891   20CC D9 B3 28    	CMP	OPTAB3+2,Y
0892   20CF 90 02       	BCC	SP6		;BR IF LESS
0893   20D1 D0 29       	BNE	SERR2		;BR IF GREATER
0894   20D3             ;
0895   20D3 AD A6 29    SP6	LDA	TEMP1A		;IF PASS 1,THEN
0896   20D6 D0 94       	BNE	SP1		;DONT STORE RESULT
0897   20D8 98          	TYA
0898   20D9 4A          	LSRA
0899   20DA A8          	TAY
0900   20DB             ;
0901   20DB A5 45       	LDA	CNUM+1		;STORE THE RESULT
0902   20DD 99 AA 29    	STA	CUROPT+1,Y
0903   20E0 A5 44       	LDA	CNUM
0904   20E2 99 A9 29    	STA	CUROPT,Y
0905   20E5 4C 6C 20    SP7	JMP	SP1		;GO FOR NEXT OPT
0906   20E8             ;
0907   20E8             SP8				;MONITOR REG
0908   20E8 48          	PHA			;SAVE TYPE REG
0909   20E9 A9 80       	LDA	#CIO		;SET OPTION OF CIO
0910   20EB 0D A8 29    	ORA	INOPTS
0911   20EE 8D A8 29    	STA	INOPTS
0912   20F1 68          	PLA			;RESTORE REG
0913   20F2 29 7F       	AND	#$7F		;CLEAR CIO
0914   20F4 0D B7 29    	ORA	IMBITS		;OR WITH PREV IMBITS
0915   20F7 8D B7 29    	STA	IMBITS
0916   20FA D0 E9       	BNE	SP7		;GO FOR NEXT
0917   20FC             ;
0918   20FC 4C A2 1F    SERR2	JMP	CNF

Page     20    APPLE DOS 3.1

0919   20FF             	PAGE
0920   20FF             ;
0921   20FF             ;	CMDGO  EXECUTE COMMAND
0922   20FF             ;
0923   20FF             CMDGO
0924   20FF 20 B7 26    	JSR	CLRSTS
0925   2102 20 33 21    	JSR	CLRCCB		;GO CLEAR CCB
0926   2105 20 0B 21    	JSR	ECMD		;GO EXECUTE
0927   2108 4C 24 1F    	JMP	CERTN
0928   210B             ECMD
0929   210B AD A2 29    	LDA	CMDNO		;COMMAND NO
0930   210E AA          	TAX			;IS CMD EXEC TAB INDEX
0931   210F BD 1F 1D    	LDA	CMDETB+1,X	;GET CMD ADR
0932   2112 48          	PHA			;ONTO STACK
0933   2113 BD 1E 1D    	LDA	CMDETB,X
0934   2116 48          	PHA
0935   2117 60          	RTS			;AND GOTO COMMAND
0936   2118             ;
0937   2118             ;	GNXTC  GET NEXT CHAR
0938   2118             ;
0939   2118             GNXTC
0940   2118 AE A0 29    	LDX	LBUFD
0941   211B BD 00 02    	LDA	LBUFF,X		;GET NEXT CHAR AND IF
0942   211E C9 8D       	CMP	#$8D		;IT IS A CR
0943   2120 F0 06       	BEQ	GNXTCR		;THEN RETURN WITHOUT
0944   2122 E8          	INX			;INCR TO NEXT CHAR
0945   2123 8E A0 29    	STX	LBUFD
0946   2126 C9 AC       	CMP	#','+$80	;TEST FOR COMMA
0947   2128 60          GNXTCR	RTS
0948   2129             ;
0949   2129             ;	GNBC  GET NON BLANK CHAR
0950   2129             ;
0951   2129             GNBC:
0952   2129 20 18 21    	JSR	GNXTC		;GO GET NEXT CHAR
0953   212C F0 FA       	BEQ	GNXTCR		;BR IF COMMA OR CR
0954   212E C9 A0       	CMP	#$A0		;IS IT BLANK
0955   2130 F0 F7       	BEQ	GNBC		;BR IF BLANK
0956   2132 60          	RTS			;DONE
0957   2133             ;
0958   2133             ;	CLRCCB  CLEAR CCB
0959   2133             ;
0960   2133             CLRCCB
0961   2133 A9 00       	LDA	#0
0962   2135 A0 16       	LDY	#CCBLEN		;CCB LENGTH
0963   2137 99 EE 34    CLC1	STA	CCB-1,Y		;CLEAR BYTE
0964   213A 88          	DEY
0965   213B D0 FA       	BNE	CLC1
0966   213D 60          	RTS

Page     21    APPLE DOS 3.1

0967   213E             	PAGE
0968   213E             ;
0969   213E             ;	GETNUM  COVERT ASCII INPUT TO NUMERIC
0970   213E             ;
0971   213E             GETNUM
0972   213E A9 00       	LDA	#0		;CLEAR WORK AREA
0973   2140 85 44       	STA	CNUM
0974   2142 85 45       	STA	CNUM+1
0975   2144 20 29 21    	JSR	GNBC
0976   2147 08          	PHP
0977   2148 C9 A4       	CMP	#$A4
0978   214A F0 3E       	BEQ	HEXNUM
0979   214C 28          	PLP
0980   214D 4C 53 21    	JMP	GN2A
0981   2150             ;
0982   2150 20 29 21    GN2	JSR	GNBC		;GET NEXT NON BLANK
0983   2153             GN2A
0984   2153 D0 06       	BNE	GN3		;BR NOT COMMA OR CR
0985   2155 A6 44       	LDX	CNUM		;X=RESULT LOW
0986   2157 A5 45       	LDA	CNUM+1		;Y=RESULT HI
0987   2159 18          	CLC
0988   215A 60          	RTS			;DONE
0989   215B             ;
0990   215B 38          GN3	SEC
0991   215C E9 B0       	SBC	#$B0		;SUBTRACT ASCII 0
0992   215E 30 21       	BMI	GN4		;BR IF NOT NUM
0993   2160 C9 0A       	CMP	#10
0994   2162 B0 1D       	BCS	GN4		;BR IF NOT NUM
0995   2164 20 83 21    	JSR	GN5		;OLD*2
0996   2167 65 44       	ADC	CNUM		;PLUS NEW
0997   2169 AA          	TAX
0998   216A A9 00       	LDA	#0
0999   216C 65 45       	ADC	CNUM+1
1000   216E A8          	TAY
1001   216F 20 83 21    	JSR	GN5		;OLD*4
1002   2172 20 83 21    	JSR	GN5		;OLD*8
1003   2175 8A          	TXA			;OLD*8 + OLD*2 + NEW
1004   2176 65 44       	ADC	CNUM
1005   2178 85 44       	STA	CNUM		;=OLD*10 + NEW
1006   217A 98          	TYA
1007   217B 65 45       	ADC	CNUM+1
1008   217D 85 45       	STA	CNUM+1
1009   217F 90 CF       	BCC	GN2
1010   2181             ;
1011   2181             GN4
1012   2181 38          	SEC                     
1013   2182 60          	RTS			;DONE
1014   2183             GN5
1015   2183 06 44       	ASL	CNUM		;CNUM * 2
1016   2185 26 45       	ROL	CNUM+1
1017   2187 B0 F8       	BCS	GN4
1018   2189 60          	RTS

Page     22    APPLE DOS 3.1

1019   218A             	PAGE
1020   218A             ;
1021   218A             HEXNUM
1022   218A 28          	PLP
1023   218B             HN0
1024   218B 20 29 21    	JSR	GNBC		;GO GET CHAR
1025   218E F0 C3       	BEQ	GN2A		;BR IF CR OR COMMA
1026   2190             ;
1027   2190 38          	SEC
1028   2191 E9 B0       	SBC	#$B0		;CHAR  ASCII0
1029   2193 30 EC       	BMI	GN4		;BR IF LT0
1030   2195 C9 0A       	CMP	#10		;IS IT LT10
1031   2197 90 08       	BCC	HN1		;BR IF LT
1032   2199 E9 07       	SBC	#$7		;SUB 7 FOR ASCII A
1033   219B 30 E4       	BMI	GN4		;BR IF LT A
1034   219D C9 10       	CMP	#16		;TEST GT 15
1035   219F B0 E0       	BCS	GN4		;BR GT 15
1036   21A1 20 83 21    HN1	JSR	GN5		;OLD*2
1037   21A4 20 83 21    	JSR	GN5		;OLD*4
1038   21A7 20 83 21    	JSR	GN5		;OLD*8
1039   21AA 20 83 21    	JSR	GN5		;OLD*16
1040   21AD 05 44       	ORA	CNUM		;OR IN NEW
1041   21AF 85 44       	STA	CNUM		;SAVE NEW
1042   21B1 4C 8B 21    	JMP	HN0		;GO FOR NEXT CHAR

Page     23    APPLE DOS 3.1

1043   21B4             	PAGE
1044   21B4             ;
1045   21B4             ;	EPR  EXECUTE PR#
1046   21B4             ;
1047   21B4             EPR
1048   21B4 A5 44       	LDA	CNUM		;GET PORT
1049   21B6 4C 95 FE    	JMP	OUTPRT		;GO DO IT
1050   21B9             ;
1051   21B9             ;	EIN  EXECUTE IN#       
1052   21B9             ;
1053   21B9             EIN
1054   21B9 A5 44       	LDA	CNUM		;GET PORT
1055   21BB 4C 8B FE    	JMP	INPRT		; GO DO IT
1056   21BE             ;
1057   21BE             ;	EMON  EXECUTE MONITOR CMD
1058   21BE             ;
1059   21BE             EMON
1060   21BE AD A1 29    	LDA	MONMOD		;GET CURRETN BITS
1061   21C1 0D B7 29    	ORA	IMBITS		;OR IN NEW BITS
1062   21C4 8D A1 29    	STA	MONMOD		;SET NEW MODE
1063   21C7 60          	RTS
1064   21C8             ;
1065   21C8             ;	ENOMON  EXECUTE NO MONITOR CMD
1066   21C8             ;
1067   21C8             ENOMON
1068   21C8 2C B7 29    	BIT	IMBITS
1069   21CB 50 03       	BVC	ENM1
1070   21CD 20 64 1F    	JSR	PRCRIF
1071   21D0             ENM1
1072   21D0 A9 70       	LDA	#$70
1073   21D2 4D B7 29    	EOR	IMBITS		;INVERT INPUT BITS
1074   21D5 2D A1 29    	AND	MONMOD		;AND WITH CURRENT
1075   21D8 8D A1 29    	STA	MONMOD		;SET NEW MODE
1076   21DB 60          	RTS

Page     24    APPLE DOS 3.1

1077   21DC             	PAGE
1078   21DC             ;
1079   21DC             ; 	EMAXF  EXECUTE MAX FILES
1080   21DC             ;
1081   21DC             EMAXF
1082   21DC A9 00       	LDA	#0		; RESET EXECUTE
1083   21DE 8D F6 29    	STA	ESTATE
1084   21E1 A5 44       	LDA	CNUM		;SAVE NEW NO FILES
1085   21E3 48          	PHA
1086   21E4 20 A5 22    	JSR	CLALL		;GO CLOSE ALL TBLS
1087   21E7 68          	PLA
1088   21E8 8D 9A 29    	STA	CNFTBS		;SET NEW NO FILE TBLS
1089   21EB 4C 30 27    	JMP	BLDFTB		; GO BUILD NEW ONES
1090   21EE             ;
1091   21EE             ;	EDEL  DELETE A FILE
1092   21EE             ;
1093   21EE             EDEL
1094   21EE A9 05       	LDA	#CRQDEL		;DELETE REQUEST
1095   21F0 20 38 22    	JSR	OPEN		;GO OPEN
1096   21F3 20 C0 26    	JSR	FILSRC		;FIND FILE
1097   21F6 A0 00       	LDY	#0
1098   21F8 98          	TYA
1099   21F9 91 40       	STA	(ZPGWRK),Y	;RESET FN
1100   21FB 60          	RTS
1101   21FC             ;
1102   21FC             ;	ELOCK  LOCK A FILE
1103   21FC             ;
1104   21FC             ELOCK
1105   21FC A9 07       	LDA	#CRQLCK		;SET LOCK
1106   21FE D0 02       	BNE	ELGO
1107   2200             ;
1108   2200             ;	EUNLK  UNLOCK A FILE
1109   2200             ;
1110   2200             EUNLK
1111   2200 A9 08       	LDA	#CRQUNL		;SET UNLOCK
1112   2202             ELGO
1113   2202 20 38 22    	JSR	OPEN		;OPEN FILE & UNLOCK
1114   2205 4C 78 22    	JMP	ECLOSE		; CLOSE IT
1115   2208             ;
1116   2208             ;	EVAR  VERIFY A FILE
1117   2208             ;
1118   2208             EVAR
1119   2208 4C B5 37    	JMP	DP1		;*** PATCH ***
1120   220B 00          	BRK

Page     25    APPLE DOS 3.1

1121   220C             	PAGE
1122   220C             ;
1123   220C             ;	EREN  RENAME A FILE
1124   220C             ;
1125   220C             EREN
1126   220C AD 08 1D    	LDA	FN2ADR		;MOVE FILE NAME2
1127   220F 8D F1 34    	STA	CCBFN2
1128   2212 AD 09 1D    	LDA	FN2ADR+1
1129   2215 8D F2 34    	STA	CCBFN2+1
1130   2218 A9 09       	LDA	#CRQRNM
1131   221A 8D A6 29    	STA	TEMP1A		;SET RENAME
1132   221D 20 56 22    	JSR	EO3		;GO OPEN AND RENAME
1133   2220 4C 78 22    	JMP	ECLOSE		; GO CLOSE
1134   2223             ;
1135   2223             ;	EAPND  OPEN FILE FOR APPEND
1136   2223             ;
1137   2223             EAPND
1138   2223 20 36 22    	JSR	EOPEN		; GO OPEN
1139   2226 A9 06       	LDA	#CREFNF
1140   2228 CD F9 34    	CMP	CCBSTA		; IF FILE CREATED
1141   222B D0 01       	BNE	AP1
1142   222D 60          	RTS
1143   222E             AP1
1144   222E 20 F0 25    	JSR	RBYTE		; READ A BYTE
1145   2231 D0 FB       	BNE	AP1		; BR IF NOT ZERO
1146   2233             ;
1147   2233 4C DB 24    	JMP	RWP3		;GO RE-POSITION

Page     26    APPLE DOS 3.1

1148   2236             	PAGE
1149   2236             ;
1150   2236             ;	EOPEN  OPEN A FILE
1151   2236             ;
1152   2236             EOPEN
1153   2236 A9 01       	LDA	#CRQOPN
1154   2238             OPEN
1155   2238 8D A6 29    	STA	TEMP1A
1156   223B AD AF 29    	LDA	CL		;IF NO LENGTH ENTERED
1157   223E D0 0A       	BNE	EO1             ;THEN SET DEFAULT OF 1
1158   2240 AD B0 29    	LDA	CL+1
1159   2243 D0 05       	BNE	EO1
1160   2245 A9 01       	LDA	#1
1161   2247 8D AF 29    	STA	CL
1162   224A             EO1
1163   224A AD AF 29    	LDA	CL		;MOVE REC LENGTH
1164   224D 8D F1 34    	STA	CCBRLN
1165   2250 AD B0 29    	LDA	CL+1
1166   2253 8D F2 34    	STA	CCBRLN+1
1167   2256             EO3
1168   2256 20 78 22    	JSR	ECLOSE		;GO CLOSE IF OPEN
1169   2259 A5 45       	LDA	CNUM+1		;GET AVALL ENTRY
1170   225B D0 03       	BNE	EO5		;BR IF ONE AVAIL
1171   225D 4C 26 26    	JMP	ENFA		;DONE - NO FILES AVAIL
1172   2260             EO5
1173   2260 85 41       	STA	ZPGWRK+1	;MOVE AVAIL SLOT TO ZPG
1174   2262 A5 44       	LDA	CNUM
1175   2264 85 40       	STA	ZPGWRK
1176   2266 20 9F 26    	JSR	MVFN1		;GO MOVE FILE NAME
1177   2269 20 AA 26    	JSR	MVBUFP		;GO MOVE BUF PTRS
1178   226C 20 76 26    	JSR	OPNSUP		;GO SET UP OPEN
1179   226F AD A6 29    	LDA	TEMP1A		;SET OPEN REG
1180   2272 8D EF 34    	STA	CCBREQ
1181   2275 4C 0C 26    	JMP	DOSGO		; GO OPEN

Page     27    APPLE DOS 3.1

1182   2278             	PAGE
1183   2278             ;
1184   2278             ;	ECLOSE  EXECUTE CLOSE FILE COMMAND
1185   2278             ;
1186   2278             ECLOSE
1187   2278 AD B8 29    	LDA	FNAME1
1188   227B C9 A0       	CMP	#$A0
1189   227D F0 26       	BEQ	CLALL
1190   227F 20 C0 26    	JSR	FILSRC		;GO FIND FILE
1191   2282 B0 06       	BCS	ECL1		; BR IF NOT FOUND
1192   2284 20 8B 22    	JSR	CLOSE		;GO CLOSE
1193   2287 4C 78 22    	JMP	ECLOSE		;GO SEE IF ANY MORE OPEN
1194   228A 60          ECL1	RTS
1195   228B             ;
1196   228B             ;	CLOSE  CLOSE A FILE    
1197   228B             ;
1198   228B             CLOSE
1199   228B 20 0B 27    	JSR	TSTEXC
1200   228E D0 05       	BNE	CLX
1201   2290 A9 00       	LDA	#0
1202   2292 8D F6 29    	STA	ESTATE
1203   2295             CLX
1204   2295 A0 00       	LDY	#0		;CLEAR 1ST FN
1205   2297 98          	TYA			;CHAR TO ZERO
1206   2298 91 40       	STA	(ZPGWRK),Y
1207   229A 20 AA 26    	JSR	MVBUFP		;MOVE BUFFER PTRS
1208   229D A9 02       	LDA	#CRQCLS		;SET CLOSE
1209   229F 8D EF 34    	STA	CCBREQ
1210   22A2 4C 0C 26    	JMP	DOSGO		;GO CLOSE
1211   22A5             ;
1212   22A5             ;	CLALL  CLOSE ALL FILES 
1213   22A5             ;
1214   22A5             CLALL
1215   22A5 20 EE 26    	JSR	TSINIT		;GO INIT FILE SEARCH
1216   22A8 D0 05       	BNE	CL1
1217   22AA             CL0
1218   22AA 20 F6 26    	JSR	TSNXT		;NEXT ENTRY
1219   22AD F0 10       	BEQ	CL2		;BR IF NO MORE
1220   22AF             CL1
1221   22AF 20 0B 27    	JSR	TSTEXC
1222   22B2 F0 F6       	BEQ	CL0
1223   22B4 20 06 27    	JSR	TSTOPN		;GO TEST OPEN
1224   22B7 F0 F1       	BEQ	CL0		;BR NOT OPEN
1225   22B9 20 8B 22    	JSR	CLOSE		;GO CLOSE
1226   22BC 4C A5 22    	JMP	CLALL		;START OVER
1227   22BF 60          CL2	RTS			;DONE

Page     28    APPLE DOS 3.1

1228   22C0             	PAGE
1229   22C0             ;
1230   22C0             ;	EBSV  EXECUTE BINARY SAVE
1231   22C0             ;
1232   22C0             EBSV
1233   22C0 A9 09       	LDA	#A+L		; IF A+L
1234   22C2 2D A8 29    	AND	INOPTS
1235   22C5 C9 09       	CMP	#A+L
1236   22C7 F0 03       	BEQ	EBSV1
1237   22C9 4C A2 1F    	JMP	CNF		;THEN ERROR
1238   22CC             EBSV1
1239   22CC A9 04       	LDA	#4		; SET BINARY FILE
1240   22CE 20 67 23    	JSR	SV1		; GO OPEN & TEST
1241   22D1 AD B6 29    	LDA	CA+1		; OUTPUTADR OF BLOCK
1242   22D4 AC B5 29    	LDY	CA
1243   22D7 20 72 23    	JSR	SV2
1244   22DA AD B0 29    	LDA	CL+1		; GO OPEN AND TEST
1245   22DD AC AF 29    	LDY	CL
1246   22E0 20 72 23    	JSR	SV2		; OUTPUT LENGTH
1247   22E3 AD B6 29    	LDA	CA+1		; GET ADR GIVEN
1248   22E6 AC B5 29    	LDY	CA
1249   22E9 4C 91 23    	JMP	SV3		; OUTPUT BLOCK
1250   22EC             ;
1251   22EC             ;	EBLD  EXECUTE BINARY LOAD
1252   22EC             ;
1253   22EC             EBLD
1254   22EC 20 36 22    	JSR	EOPEN
1255   22EF A9 06       	LDA	#CREFNF
1256   22F1 CD F9 34    	CMP	CCBSTA
1257   22F4 D0 03       	BNE	EBLD2
1258   22F6 4C B2 23    	JMP	KLUTZ
1259   22F9             EBLD2
1260   22F9 A9 7F       	LDA	#$7F
1261   22FB 2D F6 34    	AND	CCBFUC
1262   22FE C9 04       	CMP	#4
1263   2300 F0 03       	BEQ	EBLD3
1264   2302 4C 32 26    	JMP	ENBF
1265   2305             EBLD3
1266   2305 A9 04       	LDA	#4		; SET BINARY FILE
1267   2307 20 67 23    	JSR	SV1		; GO OPEN $ TEST
1268   230A 20 13 24    	JSR	LD2		; GO GET ADR
1269   230D AA          	TAX
1270   230E AD A8 29    	LDA	INOPTS
1271   2311 29 01       	AND	#A		; IF ADR NOT GIVEN
1272   2313 D0 06       	BNE	EBLD1
1273   2315 8E B5 29    	STX	CA		; THEN USE ADR FROM FILE
1274   2318 8C B6 29    	STY	CA+1
1275   231B             EBLD1
1276   231B 20 13 24    	JSR	LD2		; GET LENGTH
1277   231E AE B5 29    	LDX	CA		; GET GIVEN ADR
1278   2321 AC B6 29    	LDY	CA+1
1279   2324 4C 44 24    	JMP	LD3		; GO GET BLOCK
1280   2327             ;
1281   2327             ;	EBRUN  EXECUTE BINARY RUN
1282   2327             ;
1283   2327             EBRUN
1284   2327 20 EC 22    	JSR	EBLD		; GO LOAD FILE
1285   232A 20 AD 27    	JSR	MVCSW		;GO RESTORE CHAR I/O SW
1286   232D 6C B5 29    	JMP	(CA)		; GO EXEC THE STUFF

Page     29    APPLE DOS 3.1

1287   2330             	PAGE
1288   2330             ;
1289   2330             ;	ESAVE  EXECUTE SAVE REQUEST
1290   2330             ;
1291   2330             ESAVE
1292   2330 AD F9 29    	LDA	ASIBSW		; IF IB THEN
1293   2333 F0 19       	BEQ	EIBSV		; GO TO IB SAVE
1294   2335 A9 02       	LDA	#2		; GET APPLESOFT PGM
1295   2337 20 67 23    	JSR	SV1		; GO OPEN AND TEST
1296   233A             ;
1297   233A 38          	SEC			; BLOCK LENGTH
1298   233B A5 AF       	LDA	ASEOP		; =EOP-SOP
1299   233D E5 67       	SBC	ASSOP
1300   233F A8          	TAY
1301   2340 A5 B0       	LDA	ASEOP+1
1302   2342 E5 68       	SBC	ASSOP+1
1303   2344 20 72 23    	JSR	SV2		; GO OUTPUT LRNGTH
1304   2347             ;
1305   2347 A5 68       	LDA	ASSOP+1		; BLOCK ADR
1306   2349 A4 67       	LDY	ASSOP		; =SOP
1307   234B 4C 91 23    	JMP	SV3		; GO OUTPUT BLOCK
1308   234E             ;
1309   234E             EIBSV
1310   234E A9 01       	LDA	#1		; SET IB PGM
1311   2350 20 67 23    	JSR	SV1		; GO OPEN AND TEST
1312   2353             ;
1313   2353 38          	SEC			; BLOCK LENGTH
1314   2354 A5 4C       	LDA	IBHMEM		; =HIMEM-SOP
1315   2356 E5 CA       	SBC	IBSOP
1316   2358 A8          	TAY
1317   2359 A5 4D       	LDA	IBHMEM+1
1318   235B E5 CB       	SBC	IBSOP+1
1319   235D 20 72 23    	JSR	SV2		; GO OUTPUT LENGTH
1320   2360             ;
1321   2360 A5 CB       	LDA	IBSOP+1		; BLOCK ADR
1322   2362 A4 CA       	LDY	IBSOP		; =SOP
1323   2364 4C 91 23    	JMP	SV3		; GO OUTPUT BLOCK
1324   2367             ;
1325   2367             SV1
1326   2367             SV1A
1327   2367 8D F6 34    	STA	CCBFUC		; SET PGM TYPE
1328   236A 48          	PHA			; SAVE PGM TYPE
1329   236B 20 36 22    	JSR	EOPEN		; GO OPEN FILE
1330   236E 68          	PLA			; GET SAVE TYPE
1331   236F 4C 20 27    	JMP	TSTFUC		; GO CHECK
1332   2372             ;
1333   2372             SV2
1334   2372 8C F5 34    	STY	CCBBLN		; SET BLOCK LENGTH
1335   2375 8C F7 34    	STY	CCBDAT		; AND DATA BYTE
1336   2378 8D F6 34    	STA	CCBBLN+1
1337   237B A9 04       	LDA	#CRQWR		; INDICATE WRITE
1338   237D 8D EF 34    	STA	CCBREQ
1339   2380 A9 01       	LDA	#CRMNBT		; NEXT BYTE
1340   2382 8D F0 34    	STA	CCBRQM
1341   2385 20 0C 26    	JSR	DOSGO		; GO WRITE
1342   2388 AD F6 34    	LDA	CCBBLN+1	; OTHER BYTE TOO
1343   238B 8D F7 34    	STA	CCBDAT
1344   238E 4C 0C 26    	JMP	DOSGO
1345   2391             ;
1346   2391 8C F7 34    SV3	STY	CCBBBA		; SET BLOCK ADR
1347   2394 8D F8 34    	STA	CCBBBA+1
1348   2397 A9 02       	LDA	#CRMNBL		; INDICATE BLOCK I/O
1349   2399 8D F0 34    	STA	CCBRQM
1350   239C 20 0C 26    	JSR	DOSGO		; GO DO IT
1351   239F 4C 78 22    	JMP	ECLOSE		; CLOSE FILE

Page     30    APPLE DOS 3.1

1352   23A2             	PAGE
1353   23A2 4C 2E 26    NBPER	JMP	ERNUl
1354   23A5             ;
1355   23A5             ;	ELOAD  EXECUTE LOAD REQUEST
1356   23A5             ;
1357   23A5             ELOAD
1358   23A5 20 A5 22    	JSR	CLALL		;GO CLOSE ALL
1359   23A8 20 36 22    	JSR	EOPEN		; OPEN FILE
1360   23AB A9 06       	LDA	#CREFNF
1361   23AD CD F9 34    	CMP	CCBSTA		; WAS FILE FOUND
1362   23B0 D0 08       	BNE	ELD1		; BR IF FOUND
1363   23B2             ;
1364   23B2 20 EE 21    KLUTZ	JSR	EDEL		; DELETE NEW FILE
1365   23B5 A9 06       	LDA	#CREFNF		; FILE NOT FOUND MSG
1366   23B7 4C 34 26    	JMP	ERROR		; GO
1367   23BA             ;
1368   23BA             ELD1
1369   23BA A9 7F       	LDA	#$7F		; MASK PROTECT BIT
1370   23BC 2D F6 34    	AND	CCBFUC		; OUT OF FUC
1371   23BF F0 E1       	BEQ	NBPER		; BR IF ERROR
1372   23C1 29 03       	AND	#$03		; ISOLOLATE IB & AS
1373   23C3 F0 DD       	BEQ	NBPER		; BR IF ERROR
1374   23C5 8D F6 34    	STA	CCBFUC		; SAVE IB/AS ONLY
1375   23C8 AD F9 29    	LDA	ASIBSW		; IF IB THEN
1376   23CB F0 22       	BEQ	EIBL		; GO TO IB LOAD
1377   23CD A9 02       	LDA	#2
1378   23CF 20 56 24    	JSR	LD1		; GO OPEN AND TEST
1379   23D2             ;
1380   23D2 20 13 24    	JSR	LD2		; GO GET BLOCK LENGTH
1381   23D5             ;
1382   23D5 18          	CLC
1383   23D6 65 67       	ADC	ASSOP		; ADD BLOCK LENGTH TO SOP
1384   23D8 AA          	TAX
1385   23D9 98          	TYA
1386   23DA 65 68       	ADC	ASSOP+1
1387   23DC             ;
1388   23DC C5 74       	CMP	ASHM1+1		; IF BL+SOP >=HMEM
1389   23DE B0 70       	BCS	MFULL		; THEN WONT FIT
1390   23E0             ;
1391   23E0 85 B0       	STA	ASEOP+1		; SET NEW EOP ADR
1392   23E2 85 6A       	STA	ASEOP2+1
1393   23E4 86 AF       	STX	ASEOP
1394   23E6 86 69       	STX	ASEOP2
1395   23E8 A6 67       	LDX	ASSOP		; GET ADR WHERE TO LOAD
1396   23EA A4 68       	LDY	ASSOP+1
1397   23EC 4C 44 24    	JMP	LD3		; GO LOAD
1398   23EF             ;
1399   23EF             EIBL
1400   23EF A9 01       	LDA	#1		; SET IB PGM
1401   23F1 20 56 24    	JSR	LD1		; GO OPEN AND TEST
1402   23F4             ;
1403   23F4 20 13 24    	JSR	LD2		; GO GET BLOCK LENGTH
1404   23F7             ;
1405   23F7 38          	SEC			; HMEM - BLOK LENGTH
1406   23F8 A5 4C       	LDA	IBHMEM		; IS NEW SOP
1407   23FA ED A3 29    	SBC	SVBL
1408   23FD AA          	TAX
1409   23FE A5 4D       	LDA	IBHMEM+1
1410   2400 ED A4 29    	SBC	SVBL+1
1411   2403 90 4B       	BCC	MFULL
1412   2405 A8          	TAY
1413   2406             ;
1414   2406 C4 4B       	CPY	IBLMEM+1	; IF NEW SOP <= LMEM
1415   2408 90 46       	BCC	MFULL
1416   240A F0 44       	BEQ	MFULL
1417   240C 84 CB       	STY	IBSOP+1		; SET NEW SOP
1418   240E 86 CA       	STX	IBSOP
1419   2410 4C 44 24    	JMP	LD3
1420   2413             ;
1421   2413             LD2
1422   2413 AD 0A 1D    	LDA	SVBLA		; MOVE ADR OF WHERE
1423   2416 8D F7 34    	STA	CCBBBA		; TO PUT DATA TO
1424   2419 AD 0B 1D    	LDA	SVBLA+1		; CCBN
1425   241C 8D F8 34    	STA	CCBBBA+1
1426   241F A9 00       	LDA	#0
1427   2421 8D F6 34    	STA	CCBBLN+1	; READ INTO
1428   2424 A9 02       	LDA	#2
1429   2426 8D F5 34    	STA	CCBBLN
1430   2429 A9 03       	LDA	#CRQRD		; READ
1431   242B 8D EF 34    	STA	CCBREQ
1432   242E A9 02       	LDA	#CRMNBL		; BLOCK
1433   2430 8D F0 34    	STA	CCBRQM
1434   2433 20 0C 26    	JSR	DOSGO
1435   2436 AD A4 29    	LDA	SVBL+1
1436   2439 8D F6 34    	STA	CCBBLN+1
1437   243C A8          	TAY
1438   243D AD A3 29    	LDA	SVBL
1439   2440 8D F5 34    	STA	CCBBLN
1440   2443 60          	RTS
1441   2444             ;
1442   2444             LD3
1443   2444 8E F7 34    	STX	CCBBBA		; SET BLOCK ADR
1444   2447 8C F8 34    	STY	CCBBBA+1
1445   244A 20 0C 26    	JSR	DOSGO		; GET BLOCK
1446   244D 4C 78 22    	JMP	ECLOSE		; GO CLOSE FILE
1447   2450             ;
1448   2450             MFULL
1449   2450 20 78 22    	JSR	ECLOSE		; GO CLOSE FILE
1450   2453 4C 2A 26    	JMP	MFERR		; AND GIVE ERR MSG
1451   2456             LD1
1452   2456 CD F6 34    	CMP	CCBFUC		; TEST TYP
1453   2459 F0 1A       	BEQ	LD1C		; BR IF MATCH
1454   245B AE A2 29    	LDX	CMDNO
1455   245E 8E A5 29    	STX	SVCMD
1456   2461 4A          	LSRA
1457   2462 F0 03       	BEQ	LD1A		; BR IF PGM IS AS
1458   2464 4C 31 25    	JMP	EINT		; GO FOR INTG BASIC
1459   2467             ;
1460   2467             LD1A
1461   2467 A2 1D       	LDX	#29		; SAVE FILE NAME
1462   2469 BD B8 29    LD1B	LDA	FNAME1,X	; INCASE IS RAM APPLESOFT
1463   246C 9D D6 29    	STA	FNAME2,X
1464   246F CA          	DEX
1465   2470 10 F7       	BPL	LD1B
1466   2472 4C 0D 25    	JMP	EAS		; GO FOR AS
1467   2475             ;
1468   2475 60          LD1C	RTS

Page     31    APPLE DOS 3.1

1469   2476             	PAGE
1470   2476             ;
1471   2476             ;	ERUN  EXECUTE RUN REQUEST
1472   2476             ;
1473   2476             ERUN
1474   2476 20 A5 23    	JSR	ELOAD		;LOAD PGM
1475   2479 20 64 1F    	JSR	PRCRIF
1476   247C 20 AD 27    	JSR	MVCSW		;GO RESTORE CHAR I/O SW
1477   247F 6C 58 1D    	JMP	(RUN)
1478   2482             ;
1479   2482             ;	IBRUN  INT BASIC RUN   
1480   2482             ;
1481   2482             IBRUN
1482   2482 A5 4A       	LDA	IBLMEM		;RESET START OF VARS
1483   2484 85 CC       	STA	IBSOV
1484   2486 A5 4B       	LDA	IBLMEM+1
1485   2488 85 CD       	STA	IBSOV+1
1486   248A 6C 56 1D    	JMP	(CHAIN)
1487   248D             ;
1488   248D             ;	EHCAIN  EXECUTE CHAIN REQUEST
1489   248D             ;
1490   248D             ECHAIN
1491   248D 20 A5 23    	JSR	ELOAD		;LOAD PGM
1492   2490 20 64 1F    	JSR	PRCRIF
1493   2493 20 AD 27    	JSR	MVCSW		;GO RESTORE CHAR I/O SW
1494   2496 6C 56 1D    	JMP	(CHAIN)
1495   2499 20 65 D6    ASRUN1	JSR	$D665		;ROM
1496   249C 4C D2 D7    	JMP	$D7D2
1497   249F 20 65 0E    ASRUN2	JSR	$E65		; RAM
1498   24A2 4C D4 0F    	JMP	$FD4

Page     32    APPLE DOS 3.1

1499   24A5             	PAGE
1500   24A5             ;
1501   24A5             ;	EWRITE  WRITE CMD EXECUTE
1502   24A5             ;
1503   24A5             EWRITE
1504   24A5 20 BB 24    	JSR	RWPOSN		;GO POSITION FILE IF REQD
1505   24A8 A9 05       	LDA	#5
1506   24AA 8D 95 29    	STA	OSTATE		;SET OSTATE=5
1507   24AD 4C 24 1F    	JMP	CERTN		;DONE
1508   24B0             ;
1509   24B0             ;	EREAD  READ COMD EXECUTE
1510   24B0             ;
1511   24B0             EREAD
1512   24B0 20 BB 24    	JSR	RWPOSN		;GO POSITION FILE IF REGD
1513   24B3 A9 01       	LDA	#1
1514   24B5 8D 94 29    	STA	ISTATE		;SET ISTATE = DISK INPUT 
1515   24B8 4C 24 1F    	JMP	CERTN		;DONE
1516   24BB             ;
1517   24BB             ;	RWPOSN  POSITION FOR READ/WRITE
1518   24BB             ;
1519   24BB             RWPOSN
1520   24BB 20 C0 26    	JSR	FILSRC		;FIND THE FILE
1521   24BE 90 06       	BCC	RWP1		;BR IF FILE FOUND
1522   24C0 20 36 22    	JSR	EOPEN		;GO OPEN FOR KLUTZ
1523   24C3 4C C9 24    	JMP	RWP2		;THEN SKIP NEXT LINE
1524   24C6             RWP1
1525   24C6 20 AA 26    	JSR	MVBUFP		;MOVE BUFF POINTERS
1526   24C9             RWP2
1527   24C9 AD A8 29    	LDA	INOPTS		;GET IN OPTIONS
1528   24CC 29 06       	AND	#R+B		;WAS IT B OR R
1529   24CE F0 13       	BEQ	RWPR		;BR IF NOT
1530   24D0 A2 03       	LDX	#3
1531   24D2 BD B1 29    RWP2A	LDA	CR,X		;MOVE REL REC
1532   24D5 9D F1 34    	STA	CCBRRN,X	;AND REL BYTE
1533   24D8 CA          	DEX
1534   24D9 10 F7       	BPL	RWP2A
1535   24DB             RWP3
1536   24DB A9 0A       	LDA	#CRQPOS		;INDICATE POSITION REQUIRED
1537   24DD 8D EF 34    	STA	CCBREQ
1538   24E0 20 0C 26    	JSR	DOSGO
1539   24E3 60          RWPR	RTS			;DONE

Page     33    APPLE DOS 3.1

1540   24E4             	PAGE
1541   24E4             ;
1542   24E4             ;
1543   24E4             ;	EINIT  EXECUTE INIT COMMAND
1544   24E4             ;
1545   24E4             EINIT
1546   24E4 A9 40       	LDA	#V		; MUST HAVE
1547   24E6 2D A8 29    	AND	INOPTS		; VOL OPTION
1548   24E9 F0 13       	BEQ	INER
1549   24EB AD A9 29    	LDA	CV		; AND VOL MUST
1550   24EE F0 0E       	BEQ	INER		; BR GT 0
1551   24F0 AD 0D 1D    	LDA	ASTART+1
1552   24F3 8D F0 34    	STA	CCBBSA
1553   24F6 A9 0B       	LDA	#CRQFMT
1554   24F8 20 38 22    	JSR	OPEN
1555   24FB 4C 30 23    	JMP	ESAVE
1556   24FE             ;
1557   24FE 4C A2 1F    INER	JMP	CNF
1558   2501             ;
1559   2501             ;	ECAT  PRINT CATALOG
1560   2501             ;
1561   2501             ECAT
1562   2501 A9 06       	LDA	#CRQDIR
1563   2503 20 38 22    	JSR	OPEN		;GO PRETEND OPEN
1564   2506 AD F3 34    	LDA	CCBVOL
1565   2509 8D A9 29    	STA	CV
1566   250C 60          	RTS

Page     34    APPLE DOS 3.1

1567   250D             	PAGE
1568   250D             ;
1569   250D             ;	EAS  EXECUTE APPLESOFT REQUEST
1570   250D             ;
1571   250D             EAS
1572   250D A9 4C       	LDA	#ATSTV		; GET APPLESOFT TEST VALUE
1573   250F 20 3B 25    	JSR	SWTST		; GO SWITCH AND TEST
1574   2512 F0 24       	BEQ	GOINIT		; GO SWITCH AND TEST
1575   2514 A9 00       	LDA	#0
1576   2516 8D F9 29    	STA	ASIBSW
1577   2519             ;
1578   2519 A0 1E       	LDY	#30
1579   251B 20 26 20    	JSR	CLRFNA
1580   251E A2 09       	LDX	#FASBL
1581   2520 BD F9 29    EAS1	LDA	FASB-1,X	; MOVE SYSTEM FILE NAME
1582   2523 9D B7 29    	STA	FNAME1-1,X
1583   2526 CA          	DEX
1584   2527 D0 F7       	BNE	EAS1
1585   2529             ;
1586   2529 A9 C0       	LDA	#$C0
1587   252B 8D 94 29    	STA	ISTATE		; FOR RAM APPLESOFT
1588   252E 4C 76 24    	JMP	ERUN		; GO LOAD AND RUN
1589   2531             ;
1590   2531             ;	EINT  EXECUTE INTEGER REQUEST
1591   2531             ;
1592   2531             EINT
1593   2531 A9 20       	LDA	#ITSTV		; GET IB TEST VALUE
1594   2533 20 3B 25    	JSR	SWTST		; GO SWITCH AND RUN
1595   2536 D0 D5       	BNE	EAS		; BR IF NOT IB
1596   2538             GOINIT
1597   2538 4C 7E 1D    	JMP	DBINIT		; GO INIT DOS
1598   253B             SWTST
1599   253B CD 00 E0    	CMP	AITSTL		; TEST CURRENT VALUE
1600   253E F0 0E       	BEQ	SWTR
1601   2540 8D 80 C0    	STA	$C080		; TRY SWITCH 1
1602   2543 CD 00 E0    	CMP	AITSTL		; TEST AGAIN
1603   2546 F0 06       	BEQ	SWTR		; BR IF NOW SAME
1604   2548 8D 81 C0    	STA	$C081		; TRY SWITCH 2
1605   254B CD 00 E0    	CMP	AITSTL		; TEST AND
1606   254E 60          SWTR	RTS			; RETURN
1607   254F             ;

Page     35    APPLE DOS 3.1

1608   254F             	PAGE
1609   254F             ;
1610   254F             ;	EEXEC  EXEC CMD
1611   254F             ;
1612   254F             EEXEC
1613   254F 20 36 22    	JSR	EOPEN		; OPEN FILE
1614   2552 AD 92 29    	LDA	CFTABA
1615   2555 8D F7 29    	STA	EFTABA		; MOVE TABLE POINTERS
1616   2558 AD 93 29    	LDA	CFTABA+1
1617   255B 8D F8 29    	STA	EFTABA+1
1618   255E AD B8 29    	LDA	FNAME1		;USE FILENAME
1619   2561 8D F6 29    	STA	ESTATE		; SET EX STATE NON ZERO
1620   2564 D0 0E       	BNE	EXP2
1621   2566             ;
1622   2566             ;
1623   2566             ;	EPOS  EXECUTE POSITION
1624   2566             ;
1625   2566             EPOS	
1626   2566 20 C0 26    	JSR	FILSRC
1627   2569 90 06       	BCC	EXP1
1628   256B 20 36 22    	JSR	EOPEN
1629   256E 4C 74 25    	JMP	EXP2
1630   2571 20 AA 26    EXP1	JSR	MVBUFP
1631   2574             EXP2
1632   2574 AD A8 29    	LDA	INOPTS		; GET OPTIONS
1633   2577 29 04       	AND	#R		; TEST R
1634   2579 F0 1B       	BEQ	EX2		; BR IF NOT R
1635   257B             ;
1636   257B AD B1 29    EX0	LDA	CR		; IF CR NOT ZERO
1637   257E D0 08       	BNE	EX1A		; THEN DECREMENT
1638   2580 AE B2 29    	LDX	CR+1
1639   2583 F0 11       	BEQ	EX2
1640   2585 CE B2 29    	DEC	CR+1
1641   2588 CE B1 29    EX1A	DEC	CR
1642   258B 20 F0 25    EX1	JSR	RBYTE		; AND READ A RECORD
1643   258E F0 34       	BEQ	ICFD4
1644   2590 C9 8D       	CMP	#$8D		; UNTIL CR
1645   2592 D0 F7       	BNE	EX1
1646   2594 F0 E5       	BEQ	EX0		; THEN TEST CR AGAIN
1647   2596             ;
1648   2596 60          EX2	RTS			; DONE

Page     36    APPLE DOS 3.1

1649   2597             	PAGE
1650   2597             ;
1651   2597             ;	OCTD  OUTPUT A CHAR TO DISK
1652   2597             ;
1653   2597             OCTD
1654   2597 20 CF 25    	JSR	TSTRUN		;GO TEST RUN
1655   259A AD 9F 29    	LDA	SVA		;CHAR IN SAVED ACU
1656   259D 8D F7 34    	STA	CCBDAT		;PUT IN CCDBDATA AREA
1657   25A0 A9 04       	LDA	#CRQWR		;SET WRITE
1658   25A2 8D EF 34    	STA	CCBREQ
1659   25A5 A9 01       	LDA	#CRMNBT		;SET NEXT BYTE
1660   25A7 8D F0 34    	STA	CCBRQM
1661   25AA 4C 0C 26    	JMP	DOSGO		; GO WRITE BYTE
1662   25AD             ;
1663   25AD             ;	INCFD  INPUT A CHAR FROM DISK
1664   25AD             ;
1665   25AD             INCFD
1666   25AD 20 CF 25    	JSR	TSTRUN		;GO TEST RUN
1667   25B0 A9 06       	LDA	#6		;SET OUT STE = 6
1668   25B2             ICFD3
1669   25B2 8D 95 29    	STA	OSTATE		;TO CATCH ECHO
1670   25B5 20 F0 25    	JSR	RBYTE
1671   25B8 D0 0F       	BNE	ICFD1		;BR IF NOT ZERO CHAR
1672   25BA             ;
1673   25BA 20 8B 22    	JSR	CLOSE
1674   25BD A9 03       	LDA	#3
1675   25BF CD 95 29    	CMP	OSTATE
1676   25C2 F0 08       	BEQ	ICFD0
1677   25C4             ICFD4
1678   25C4 A9 05       	LDA	#CREEOF
1679   25C6 4C 34 26    	JMP	ERROR		;GO TO ERROR
1680   25C9             ICFD1
1681   25C9 8D 9F 29    	STA	SVA		;PUT INTO SAVED ACU
1682   25CC             ICFD0
1683   25CC 4C 50 1F    	JMP	ORTN		;GO RESTORE REGS AND RTS
1684   25CF             ;
1685   25CF             TSTRUN
1686   25CF AD F9 29    	LDA	ASIBSW		;GET AS/INT BASIC SWITCH
1687   25D2 F0 05       	BEQ	TR1		; BR IF INT
1688   25D4 A6 76       	LDX	$76		;TEST AS RUN
1689   25D6 4C D5 3F    	JMP	ASRWPAT		;AS READ/WRITE > LINE # 255 PATCH
1690   25D9             TR1
1691   25D9 A5 D9       	LDA	$D9		;GET INT RUN FLAG
1692   25DB 30 2E       	BMI	MVEFRT		; BR IF RUN
1693   25DD             ICFDB				; NOT RUN MODE
1694   25DD 20 8B 22    	JSR	CLOSE		;GO CLOSE FILE
1695   25E0 20 B7 26    	JSR	CLRSTS		;GO CLEAR STATES
1696   25E3 4C 50 1F    	JMP	ORTN

Page     37    APPLE DOS 3.1

1697   25E6             	PAGE
1698   25E6             ;
1699   25E6             ;	NXTEXC  NEXT EXECUTE CHAR
1700   25E6             ;
1701   25E6             NXTEXC
1702   25E6 20 01 26    	JSR	MVEFTA
1703   25E9 20 AA 26    	JSR	MVBUFP		; GO MOVE PTRS
1704   25EC A9 03       	LDA	#3
1705   25EE D0 C2       	BNE	ICFD3
1706   25F0             ;
1707   25F0             ;	RBYTE  READ NEXT BYTE
1708   25F0             ;
1709   25F0             RBYTE
1710   25F0 A9 03       	LDA	#CRQRD		;SET READ
1711   25F2 8D EF 34    	STA	CCBREQ
1712   25F5 A9 01       	LDA	#CRMNBT		;SET NEXT BYTE
1713   25F7 8D F0 34    	STA	CCBRQM
1714   25FA 20 0C 26    	JSR	DOSGO		;GO TO DOS
1715   25FD AD F7 34    	LDA	CCBDAT		;GET THE DATA BYTE
1716   2600 60          	RTS
1717   2601             MVEFTA
1718   2601 AD F8 29    	LDA	EFTABA+1	; MOVE TABLE ADR
1719   2604 85 41       	STA	ZPGWRK+1	; NO ZPG
1720   2606 AD F7 29    	LDA	EFTABA
1721   2609 85 40       	STA	ZPGWRK
1722   260B 60          MVEFRT	RTS

Page     38    APPLE DOS 3.1

1723   260C             	PAGE
1724   260C             ;
1725   260C             ;	DOSGO  GOTO DOS
1726   260C             ;
1727   260C             DOSGO
1728   260C 20 3F 2A    	JSR	DOSENT		;GO TO DOS
1729   260F B0 01       	BCS	DG1		;BR IF ERROR
1730   2611 60          	RTS			;DONE
1731   2612             ;
1732   2612             DG1
1733   2612 AD F9 34    	LDA	CCBSTA		;GET STATUS OF I/O
1734   2615 C9 05       	CMP	#CREEOF		;EOF ?
1735   2617 D0 06       	BNE	DG2		;BR IF NOT
1736   2619 A2 00       	LDX	#0		;SET OTHER EIF
1737   261B 8E F7 34    	STX	CCBDAT		; DONE
1738   261E 60          	RTS
1739   261F             DG2
1740   261F 4C 34 26    	JMP	ERROR		;GO DO ERROR
1741   2622             ;

Page     39    APPLE DOS 3.1

1742   2622             	PAGE
1743   2622             ;
1744   2622             ;	ERROR ROUTINE
1745   2622             ;
1746   2622 A9 0B       ESYNTX	LDA	#CREFLK+1
1747   2624 D0 0E       	BNE	ERROR
1748   2626 A9 0C       ENFA	LDA	#CREFLK+2
1749   2628 D0 0A       	BNE	ERROR
1750   262A A9 0E       MFERR	LDA	#CREFLK+4
1751   262C D0 06       	BNE	ERROR
1752   262E A9 0D       ERNUl	LDA	#CREFLK+3
1753   2630 D0 02       	BNE	ERROR
1754   2632 A9 0F       ENBF	LDA	#CREFLK+5
1755   2634             ;
1756   2634             ERROR
1757   2634 8D 9F 29    	STA	SVA		;SAVE MSG NUMBER
1758   2637 20 B7 26    	JSR	CLRSTS
1759   263A AD F9 29    	LDA	ASIBSW		;GET AS/IN BASIC SWITCH
1760   263D F0 04       	BEQ	ERNAS		;BR IF NOT APPLESOFT
1761   263F A5 D8       	LDA	$D8		;GET ON ERR FLAG
1762   2641 30 10       	BMI	ERRTN		;BRT IF ON ERR IS GO
1763   2643             ERNAS
1764   2643 A2 00       	LDX	#0
1765   2645 20 5E 26    	JSR	EMPR		;GO OUTPUT
1766   2648 AE 9F 29    	LDX	SVA		;GET SAVE MSG
1767   264B 20 5E 26    	JSR	EMPR		;GO OUTPUT MSG 
1768   264E A2 10       	LDX	#CREFLK+6
1769   2650 20 5E 26    	JSR	EMPR
1770   2653 20 AD 27    ERRTN	JSR	MVCSW		;GO MOVE CHAR I/O SW
1771   2656 AE 9F 29    	LDX	SVA
1772   2659 A9 03       	LDA	#03
1773   265B 6C 5A 1D    	JMP	(BREAK)
1774   265E             ;
1775   265E             EMPR
1776   265E BD 81 29    	LDA	EMDTB,X		;GET ITS DISPL
1777   2661 AA          	TAX			;INTO X
1778   2662             EMPR1
1779   2662 8E A6 29    	STX	TEMP1A		;SAVE DISPL
1780   2665 BD CD 28    	LDA	EMSG,X		;GET MSG CHAR
1781   2668 48          	PHA			;SAVE CHAR
1782   2669 09 80       	ORA	#$80		;SET MSB ON
1783   266B 20 61 1F    	JSR	ORTN1		;OUTPUT CHAR
1784   266E AE A6 29    	LDX	TEMP1A		;GET INDEX
1785   2671 E8          	INX			;INCREMENT IT
1786   2672 68          	PLA			;RE-LOAD CHAR
1787   2673 10 ED       	BPL	EMPR1		;BR IF MORE CHARS
1788   2675 60          	RTS			;DONE

Page     40    APPLE DOS 3.1

1789   2676             	PAGE
1790   2676             ;
1791   2676             ;	OPNSUP  OPEN SET UP
1792   2676             ;
1793   2676             OPNSUP
1794   2676 AD A9 29    	LDA	CV		;VOLUME
1795   2679 8D F3 34    	STA	CCBVOL
1796   267C AD AB 29    	LDA	CD		;DRIVE
1797   267F 8D F4 34    	STA	CCBDRV
1798   2682 AD AD 29    	LDA	CS		;SLOT
1799   2685 8D F5 34    	STA	CCBSLT
1800   2688 AD 06 1D    	LDA	FN1ADR		;FILENAME 1 ADR
1801   268B 8D F7 34    	STA	CCBFN1
1802   268E AD 07 1D    	LDA	FN1ADR+1
1803   2691 8D F8 34    	STA	CCBFN1+1
1804   2694 A5 40       	LDA	ZPGWRK
1805   2696 8D 92 29    	STA	CFTABA
1806   2699 A5 41       	LDA	ZPGWRK+1
1807   269B 8D 93 29    	STA	CFTABA+1
1808   269E 60          	RTS
1809   269F             ;
1810   269F             ;	MVFN1  MOVE FILE NAME 1 TO FILE PTR
1811   269F             ;
1812   269F             MVFN1
1813   269F A0 1D       	LDY	#29
1814   26A1 B9 B8 29    MVFN1A	LDA	FNAME1,Y
1815   26A4 91 40       	STA	(ZPGWRK),Y
1816   26A6 88          	DEY
1817   26A7 10 F8       	BPL	MVFN1A
1818   26A9 60          	RTS
1819   26AA             ;
1820   26AA             ;	MVBUFP  MOVE BUFFER PTRS TO CCB
1821   26AA             ;
1822   26AA             MVBUFP
1823   26AA A0 1E       	LDY	#30
1824   26AC B1 40       MVBP1	LDA	(ZPGWRK),Y
1825   26AE 99 DD 34    	STA	CCBFCB-30,Y
1826   26B1 C8          	INY
1827   26B2 C0 26       	CPY	#38
1828   26B4 D0 F6       	BNE	MVBP1
1829   26B6 60          	RTS
1830   26B7             ;
1831   26B7             ;	CLRSTS  CLEAR STATES
1832   26B7             ;
1833   26B7             CLRSTS
1834   26B7 A0 00       	LDY	#0
1835   26B9 8C 94 29    	STY	ISTATE
1836   26BC 8C 95 29    	STY	OSTATE
1837   26BF 60          	RTS

Page     41    APPLE DOS 3.1

1838   26C0             	PAGE
1839   26C0             ;
1840   26C0             ;	FILSRC  SEARCH FOR FILE NAME1
1841   26C0             ;
1842   26C0             FILSRC
1843   26C0 A9 00       	LDA	#0		;CLEAR SV AVAIL
1844   26C2 85 45       	STA	CNUM+1
1845   26C4             ;
1846   26C4 20 EE 26    	JSR	TSINIT		;GO INIT SEARCH
1847   26C7 4C CF 26    	JMP	FLS1A
1848   26CA 20 F6 26    FLS1	JSR	TSNXT		;LOOK AT NEXT
1849   26CD F0 1D       	BEQ	FLS4		;BR IF NO NEXT
1850   26CF             ;
1851   26CF 20 06 27    FLS1A	JSR	TSTOPN		;GO TEST OPEN
1852   26D2 D0 0A       	BNE	FLS2		;BR IF OPEN
1853   26D4             ;
1854   26D4 A5 40       	LDA	ZPGWRK		;SAVE AVAIL ENTRY ADR
1855   26D6 85 44       	STA	CNUM
1856   26D8 A5 41       	LDA	ZPGWRK+1
1857   26DA 85 45       	STA	CNUM+1
1858   26DC D0 EC       	BNE	FLS1		;GO LOOK SOME MORE
1859   26DE             ;
1860   26DE A0 1D       FLS2	LDY	#29		; FILE HAD 30 CHARS
1861   26E0 B1 40       FLS3	LDA	(ZPGWRK),Y	;GET CHAR
1862   26E2 D9 B8 29    	CMP	FNAME1,Y	;TEST CHAR
1863   26E5 D0 E3       	BNE	FLS1		;BR NOT
1864   26E7 88          	DEY
1865   26E8 10 F6       	BPL	FLS3		; LOOK AT 30 CHARS
1866   26EA 18          	CLC			;FOUND
1867   26EB 60          	RTS			;DONE
1868   26EC             ;
1869   26EC 38          FLS4	SEC			;NOT FOUND
1870   26ED 60          	RTS			;DONE

Page     42    APPLE DOS 3.1

1871   26EE             	PAGE
1872   26EE             ;
1873   26EE             ;	TSINIT  INITIALIZE FOR FTAB SEARCH
1874   26EE             ;	TSNXT  GET NEXT FTAB ENTRY
1875   26EE             ;
1876   26EE             TSINIT
1877   26EE AD 00 1D    	LDA	FTAB		;GET 1ST PTR ADR
1878   26F1 AE 01 1D    	LDX	FTAB+1
1879   26F4 D0 0A       	BNE	TSST
1880   26F6             TSNXT
1881   26F6 A0 25       	LDY	#37		; GET LINK
1882   26F8 B1 40       	LDA	(ZPGWRK),Y
1883   26FA F0 09       	BEQ	TSR		;BR IF NO LINK
1884   26FC             ;
1885   26FC AA          	TAX
1886   26FD 88          	DEY
1887   26FE B1 40       	LDA	(ZPGWRK),Y
1888   2700             TSST
1889   2700 86 41       	STX	ZPGWRK+1
1890   2702 85 40       	STA	ZPGWRK
1891   2704 8A          	TXA			;SET NE CC
1892   2705 60          TSR	RTS
1893   2706             ;
1894   2706             ;	TSTOPN  TST FOR OPEN FILE
1895   2706             ;
1896   2706             TSTOPN
1897   2706 A0 00       	LDY	#0		;GET 1ST CHAR OF FN
1898   2708 B1 40       	LDA	(ZPGWRK),Y
1899   270A 60          	RTS
1900   270B             ;
1901   270B             ;	TSTEXC  TEST CURRENT FILE FOR EXECUTE
1902   270B             ;
1903   270B             TSTEXC
1904   270B AD F6 29    	LDA	ESTATE		; IF ESTATE = 0
1905   270E F0 0E       	BEQ	TXC1		; THEN NO EXECUTE FILE
1906   2710 AD F7 29    	LDA	EFTABA		; TEST CURRENT
1907   2713 C5 40       	CMP	ZPGWRK
1908   2715 D0 08       	BNE	TXC2		; IS NOT
1909   2717 AD F8 29    	LDA	EFTABA+1
1910   271A C5 41       	CMP	ZPGWRK+1
1911   271C F0 01       	BEQ	TXC2		; IS
1912   271E CA          TXC1	DEX			; IS NOT
1913   271F 60          TXC2	RTS			; DONE

Page     43    APPLE DOS 3.1

1914   2720             	PAGE
1915   2720             ;
1916   2720             ;	TSTFUC  TEST FILE USE CODE FOR PGM
1917   2720             ;
1918   2720             TSTFUC
1919   2720 4D F6 34    	EOR	CCBFUC
1920   2723 F0 0A       	BEQ	TFUCR
1921   2725 29 7F       	AND	#$7F
1922   2727 F0 06       	BEQ	TFUCR
1923   2729 20 78 22    	JSR	ECLOSE		; GO CLOSE THE SOB
1924   272C 4C 2E 26    	JMP	ERNUl
1925   272F 60          TFUCR	RTS

Page     44    APPLE DOS 3.1

1926   2730             	PAGE
1927   2730             ;
1928   2730             ;	BLDFTB  BUILD FILE TABLES
1929   2730             ;	TABLE MAP:
1930   2730             ;		HIMEM,SOP
1931   2730             ;		SBUFF  N	(256)
1932   2730             ;		DBUFF  N	(256)
1933   2730             ;		FTB     N	(FCBLEN)
1934   2730             ;		HEADER N	(38)
1935   2730             ;
1936   2730             ;
1937   2730             ;		SBUFF  1
1938   2730             ;		DBUFF  1
1939   2730             ;		FTB    1
1940   2730             ;		HEADER 1
1941   2730             ;		THIS PROGRAM
1942   2730             ;
1943   2730             ;	HEADER MAP:
1944   2730             ;		FILENAME (30)
1945   2730             ;		FTB PTR	 (2)
1946   2730             ;		DBUF PTR (2)
1947   2730             ;		SBUF PTR (2)
1948   2730             ;		LINK	 (2)
1949   2730             ;
1950   2730             BLDFTB
1951   2730 38          	SEC
1952   2731 AD 00 1D    	LDA	FTAB		;START OF FTAB AREA
1953   2734 85 40       	STA	ZPGWRK		;IS 1ST FTB PTR
1954   2736 AD 01 1D    	LDA	FTAB+1		;HEADER
1955   2739 85 41       	STA	ZPGWRK+1
1956   273B AD 9A 29    	LDA	CNFTBS		;MOVE NO FTABS
1957   273E 8D A6 29    	STA	TEMP1A		;TO TEMP
1958   2741             ;
1959   2741 A0 00       BFT1	LDY	#0
1960   2743 98          	TYA
1961   2744 91 40       	STA	(ZPGWRK),Y	;1ST CHAR FN=0
1962   2746 A0 1E       	LDY	#30		; INC Y TO FCB PTR
1963   2748 38          	SEC
1964   2749 A5 40       	LDA	ZPGWRK		;END OF PTR HEADER
1965   274B E9 2D       	SBC	#FCBLEN		;MINUS FTAB LENGTH
1966   274D 91 40       	STA	(ZPGWRK),Y	;IS START OF FTB
1967   274F 48          	PHA			;SAVE LOW ADR BYTE
1968   2750 A5 41       	LDA	ZPGWRK+1
1969   2752 E9 00       	SBC	#0
1970   2754 C8          	INY
1971   2755 91 40       	STA	(ZPGWRK),Y
1972   2757 AA          	TAX
1973   2758 CA          	DEX			;FTB ADR  256
1974   2759 68          	PLA			;IS ADR DIR BUFF
1975   275A 48          	PHA
1976   275B C8          	INY
1977   275C 91 40       	STA	(ZPGWRK),Y	;SET DIR BUF PTR
1978   275E 8A          	TXA
1979   275F C8          	INY
1980   2760 91 40       	STA	(ZPGWRK),Y
1981   2762 AA          	TAX
1982   2763 CA          	DEX			;DIR BUFF - 256
1983   2764 68          	PLA			;IS SBUFF ADR
1984   2765 48          	PHA
1985   2766 C8          	INY
1986   2767 91 40       	STA	(ZPGWRK),Y
1987   2769 C8          	INY
1988   276A 8A          	TXA
1989   276B 91 40       	STA	(ZPGWRK),Y
1990   276D             ;
1991   276D CE A6 29    	DEC	TEMP1A		;DECREMENT TABLE INDEX
1992   2770 F0 17       	BEQ	BFT2		;COUNT AND BR IF DONE
1993   2772 AA          	TAX
1994   2773 68          	PLA
1995   2774 38          	SEC
1996   2775 E9 26       	SBC	#38		; SBUFF ADR - 38
1997   2777 C8          	INY
1998   2778 91 40       	STA	(ZPGWRK),Y	;IF ADR OF NEXT TAB
1999   277A 48          	PHA			;WHICH GOES INTO
2000   277B 8A          	TXA			;LINK
2001   277C E9 00       	SBC	#0
2002   277E C8          	INY
2003   277F 91 40       	STA	(ZPGWRK),Y
2004   2781 85 41       	STA	ZPGWRK+1	;AND INTO ZPGWRK
2005   2783 68          	PLA			;FOR NEXT ENTRY
2006   2784 85 40       	STA	ZPGWRK		;BUILD
2007   2786 4C 41 27    	JMP	BFT1		;GO BUILD NEXT
2008   2789             ;
2009   2789             BFT2
2010   2789 48          	PHA
2011   278A A9 00       	LDA	#0		;SET LAST LINK
2012   278C C8          	INY			;TO ZERO
2013   278D 91 40       	STA	(ZPGWRK),Y
2014   278F C8          	INY
2015   2790 91 40       	STA	(ZPGWRK),Y
2016   2792             ;
2017   2792 AD F9 29    	LDA	ASIBSW		;IF IB THEN GO
2018   2795 F0 0B       	BEQ	BFT1B
2019   2797             ;
2020   2797 68          	PLA			; SET APPLESOFT
2021   2798 85 74       	STA	ASHM1+1		; UPPER MEM LIMITS
2022   279A 85 70       	STA	ASHM2+1
2023   279C 68          	PLA
2024   279D 85 73       	STA	ASHM1
2025   279F 85 6F       	STA	ASHM2
2026   27A1 60          	RTS
2027   27A2             ;
2028   27A2             BFT1B
2029   27A2 68          	PLA			; SET IB
2030   27A3 85 4D       	STA	IBHMEM+1	; UPPER MEM LIMITS
2031   27A5 85 CB       	STA	IBSOP+1
2032   27A7 68          	PLA
2033   27A8 85 4C       	STA	IBHMEM
2034   27AA 85 CA       	STA	IBSOP
2035   27AC 60          	RTS

Page     45    APPLE DOS 3.1

2036   27AD             	PAGE
2037   27AD             ;
2038   27AD             ;	MVISW  MOVE INPUT SWITCH
2039   27AD             ;
2040   27AD             MVCSW
2041   27AD A5 39       	LDA	INSW+1
2042   27AF CD 03 1D    	CMP	CINA+1
2043   27B2 F0 12       	BEQ	MVOSW
2044   27B4 8D 99 29    	STA	SVINS+1
2045   27B7 A5 38       	LDA	INSW		;SAVE CHAR IN SWITCH
2046   27B9 8D 98 29    	STA	SVINS
2047   27BC             ;
2048   27BC AD 02 1D    	LDA	CINA		;SET DB CHAR IN ADR
2049   27BF 85 38       	STA	INSW
2050   27C1 AD 03 1D    	LDA	CINA+1
2051   27C4 85 39       	STA	INSW+1
2052   27C6             ;
2053   27C6             ;
2054   27C6             ;	MVOSW  MOVE OUTPUT SWITCH
2055   27C6             ;
2056   27C6             MVOSW
2057   27C6 A5 37       	LDA	OUTSW+1
2058   27C8 CD 05 1D    	CMP	COUTA+1
2059   27CB F0 12       	BEQ	MVSRTN
2060   27CD 8D 97 29    	STA	SVOUTS+1
2061   27D0 A5 36       	LDA	OUTSW		;SAVE CHAR OUT SWITCH
2062   27D2 8D 96 29    	STA	SVOUTS
2063   27D5             ;
2064   27D5 AD 04 1D    	LDA	COUTA		;SET DB CHAR OUT ADR
2065   27D8 85 36       	STA	OUTSW
2066   27DA AD 05 1D    	LDA	COUTA+1
2067   27DD 85 37       	STA	OUTSW+1
2068   27DF             MVSRTN
2069   27DF 60          	RTS

Page     46    APPLE DOS 3.1

2070   27E0             	PAGE
2071   27E0             ;
2072   27E0             ;	COMMAND NAME TABLE
2073   27E0             ;
2074   27E0             EC1
2075   27E0             CMDNTB
2076   27E0 49 4E 49 D4 	DB01	"INIT"
2077   27E4 4C 4F 41 C4 	DB01	"LOAD"
2078   27E8 53 41 56 C5 	DB01	"SAVE"
2079   27EC 52 55 CE    	DB01	"RUN"
2080   27EF 43 48 41 49 	DB01	"CHAIN"
2080   27F3 CE 
2081   27F4 44 45 4C 45 	DB01	"DELETE"
2081   27F8 54 C5 
2082   27FA 4C 4F 43 CB 	DB01	"LOCK"
2083   27FE 55 4E 4C 4F 	DB01	"UNLOCK"
2083   2802 43 CB 
2084   2804 43 4C 4F 53 	DB01	"CLOSE"
2084   2808 C5 
2085   2809 52 45 41 C4 	DB01	"READ"
2086   280D 45 58 45 C3 	DB01	"EXEC"
2087   2811 57 52 49 54 	DB01	"WRITE"
2087   2815 C5 
2088   2816 50 4F 53 49 	DB01	"POSITION"
2088   281A 54 49 4F CE 
2089   281E 4F 50 45 CE 	DB01	"OPEN"
2090   2822 41 50 50 45 	DB01	"APPEND"
2090   2826 4E C4 
2091   2828 52 45 4E 41 	DB01	"RENAME"
2091   282C 4D C5 
2092   282E 43 41 54 41 	DB01	"CATALOG"
2092   2832 4C 4F C7 
2093   2835 4D 4F CE    	DB01	"MON"
2094   2838 4E 4F 4D 4F 	DB01	"NOMON"
2094   283C CE 
2095   283D 50 52 A3    	DB01	"PR#"
2096   2840 49 4E A3    	DB01	"IN#"
2097   2843 4D 41 58 46 	DB01	"MAXFILES"
2097   2847 49 4C 45 D3 
2098   284B 46 D0       	DB01	"FP"
2099   284D 49 4E D4    	DB01	"INT"
2100   2850 42 53 41 56 	DB01	"BSAVE"
2100   2854 C5 
2101   2855 42 4C 4F 41 	DB01	"BLOAD"
2101   2859 C4 
2102   285A 42 52 55 CE 	DB01	"BRUN"
2103   285E 56 45 52 49 	DB01	"VERIFY"
2103   2862 46 D9 
2104   2864 00          	DB	0

Page     47    APPLE DOS 3.1

2105   2865             	PAGE
2106   2865             ;
2107   2865             ;	COMMAND SYNTAX OP EQUATES FOR SYNTAX BYTE ONE
2108   2865             ;
2109   2865             NPB	EQU	$80		;NO PARMS OK, COMMAND GOES TO BASIC
2110   2865             NPE	EQU	$40		;NO PARMS OK, COMMAND TO EXECUTION RTN
2111   2865             FN1	EQU	$20		;FILE NAME1 REGD
2112   2865             FN2	EQU	$10		;FILE NAME2 REGD
2113   2865             NUM1	EQU	$08		;NUMERIC 0-7 REGD
2114   2865             NUM2	EQU	$04		;NUMERIC 1-10 REGD
2115   2865             ;
2116   2865             ;	COMMAND SYNTAX OP EQUATES FOR SYNTAX BYTE TWO
2117   2865             ;
2118   2865             V	EQU	$40		;VOLUME ALLOWED
2119   2865             D	EQU	$20		;DRIVE ALLOWED
2120   2865             S	EQU	$10		;SLOT ALLOWED
2121   2865             L	EQU	$08		;LENGTH ALLOWED
2122   2865             R	EQU	$04		;RECORD NUMBER ALLOWED
2123   2865             B	EQU	$02		;BYTE NUMBER ALLOWED
2124   2865             A	EQU	$01		; ADDRESS
2125   2865             CIO	EQU	$80		;C,I, OR O ALLOWED
2126   2865             ;
2127   2865             ; 	COMMAND SYNTAX TABLE
2128   2865             ;		EACH COMMAND HAS TWO BYTE ENTRY
2129   2865             ;
2130   2865             CMDSTB
2131   2865 20 70       	DB	FN1,V+D+S	; INIT
2132   2867 A0 70       	DB	NPB+FN1,V+D+S	;LOAD
2133   2869 A0 70       	DB	NPB+FN1,V+D+S	;SAVE
2134   286B A0 70       	DB	NPB+FN1,V+D+S	;RUN
2135   286D 20 70       	DB	FN1,V+D+S	;CHAIN
2136   286F 20 70       	DB	FN1,V+D+S	;DELETE
2137   2871 20 70       	DB	FN1,V+D+S	;LOCK
2138   2873 20 70       	DB	FN1,V+D+S	;UNLOCK
2139   2875 60 00       	DB	NPE+FN1,0	;CLOSE
2140   2877 20 06       	DB	FN1,B+R		;READ
2141   2879 20 74       	DB	FN1,R+V+D+S	; EXEC
2142   287B 20 06       	DB	FN1,B+R		;WRITE
2143   287D 20 04       	DB	FN1,R		;POSITION
2144   287F 20 78       	DB	FN1,L+V+D+S	;OPEN
2145   2881 20 78       	DB	FN1,L+V+D+S	; APPEND
2146   2883 30 70       	DB	FN1+FN2,V+D+S	;RENAME
2147   2885 40 70       	DB	NPE,V+D+S	;CATALOG
2148   2887 40 80       	DB	NPE,CIO		;MONITOR
2149   2889 40 80       	DB	NPE,CIO		;NO MONITOR
2150   288B 08 00       	DB	NUM1,0		;PR#
2151   288D 08 00       	DB	NUM1,0		;IN#
2152   288F 04 00       	DB	NUM2,0		;MAXFILES
2153   2891 40 70       	DB	NPE,V+D+S	;APPLESOFT
2154   2893 40 00       	DB	NPE,0		; INT
2155   2895 20 79       	DB	FN1,V+D+S+A+L	; BSAVE
2156   2897 20 71       	DB	FN1,V+D+S+A	; BLOAD
2157   2899 20 71       	DB	FN1,V+D+S+A	; BRUN
2158   289B 20 70       	DB	FN1,V+D+S	; VERIFY

Page     48    APPLE DOS 3.1

2159   289D             	PAGE
2160   289D             ;
2161   289D             ; 	OPTAB  OPTIONAL PARMS SYNTAX TABLES
2162   289D             ;
2163   289D             OPTAB1
2164   289D D6 C4 D3 CC 	DB11	"VDSLRBACIO"
2164   28A1 D2 C2 C1 C3 
2164   28A5 C9 CF 
2165   28A7             OPT1L	EQU	*-OPTAB1
2166   28A7             OPTAB2
2167   28A7 40 20 10 08 	DB	V,D,S,L,R,B,A,CIO+MC,CIO+MI,CIO+MO
2167   28AB 04 02 01 C0 
2167   28AF A0 90 
2168   28B1             OPTAB3
2169   28B1 00 00 FE 00 	DW	@@0,254		;VOL RANGE
2170   28B5 01 00 02 00 	DW	@@1,@@2		;DRIVE RANGE
2171   28B9 01 00 07 00 	DW	@@1,@@7		;SLOT RANGE
2172   28BD 01 00 FF 7F 	DW	@@1,32767	;LENGTH RANGE
2173   28C1 00 00 FF 7F 	DW	@@0,32767	;REC NO RANGE
2174   28C5 00 00 FF 7F 	DW	@@0,32767	;REC BYTE NO RANGE
2175   28C9 00 00 00 C0 	DW	@@0,@@$C000	;ADDRESS RANGE

Page     49    APPLE DOS 3.1

2176   28CD             	PAGE
2177   28CD             ;
2178   28CD             ; 	ERROR MESSAGE TABLES
2179   28CD             ;
2180   28CD             EMSG
2181   28CD 0D 07       	DB	$0D,$07
2182   28CF 2A 2A 2A 44 	DB01	"***DISK: "
2182   28D3 49 53 4B 3A 
2182   28D7 A0 
2183   28D8             EM1	EQU	*-EMSG
2184   28D8             EM2	EQU	*-EMSG
2185   28D8             EM3	EQU	*-EMSG
2186   28D8 53 59 D3    	DB01	"SYS"
2187   28DB             EM4	EQU	*-EMSG
2188   28DB 57 52 49 54 	DB01	"WRITE PROTECT"
2188   28DF 45 20 50 52 
2188   28E3 4F 54 45 43 
2188   28E7 D4 
2189   28E8             EM5	EQU	*-EMSG
2190   28E8 45 4E 44 20 	DB01	"END OF DATA"
2190   28EC 4F 46 20 44 
2190   28F0 41 54 C1 
2191   28F3             EM6	EQU	*-EMSG
2192   28F3 46 49 4C 45 	DB01	"FILE NOT FOUND"
2192   28F7 20 4E 4F 54 
2192   28FB 20 46 4F 55 
2192   28FF 4E C4 
2193   2901             EM7	EQU	*-EMSG
2194   2901 56 4F 4C 55 	DB01	"VOLUME MISMATCH"
2194   2905 4D 45 20 4D 
2194   2909 49 53 4D 41 
2194   290D 54 43 C8 
2195   2910             EM8	EQU	*-EMSG
2196   2910 44 49 53 4B 	DB01	"DISK I/O"
2196   2914 20 49 2F CF 
2197   2918             EM9	EQU	*-EMSG
2198   2918 44 49 53 4B 	DB01	"DISK FULL"
2198   291C 20 46 55 4C 
2198   2920 CC 
2199   2921             EM10	EQU	*-EMSG
2200   2921 46 49 4C 45 	DB01	"FILE LOCKED"
2200   2925 20 4C 4F 43 
2200   2929 4B 45 C4 
2201   292C             EM11	EQU	*-EMSG
2202   292C 43 4D 44 20 	DB01	"CMD SYNTAX"
2202   2930 53 59 4E 54 
2202   2934 41 D8 
2203   2936             EM12	EQU	*-EMSG
2204   2936 4E 4F 20 46 	DB01	"NO FILE BUFFS AVAIL"
2204   293A 49 4C 45 20 
2204   293E 42 55 46 46 
2204   2942 53 20 41 56 
2204   2946 41 49 CC 
2205   2949             EM13	EQU	*-EMSG
2206   2949 4E 4F 54 20 	DB01	"NOT BASIC PROGRAM"
2206   294D 42 41 53 49 
2206   2951 43 20 50 52 
2206   2955 4F 47 52 41 
2206   2959 CD 
2207   295A             EM14	EQU	*-EMSG
2208   295A 50 52 4F 47 	DB01	"PROGRAM TOO LARGE"
2208   295E 52 41 4D 20 
2208   2962 54 4F 4F 20 
2208   2966 4C 41 52 47 
2208   296A C5 
2209   296B             EM15	EQU	*-EMSG
2210   296B 4E 4F 54 20 	DB01	"NOT BINARY FILE"
2210   296F 42 49 4E 41 
2210   2973 52 59 20 46 
2210   2977 49 4C C5 
2211   297A             ;
2212   297A             EML	EQU	*-EMSG
2213   297A 20 45 52 52 	DB	" ERROR"
2213   297E 4F 52 
2214   2980 8D          	DB	$8D
2215   2981             EMDTB
2216   2981 00 0B 0B 0B 	DB	0,EM1,EM2,EM3,EM4
2216   2985 0E 
2217   2986 1B 26 34 43 	DB	EM5,EM6,EM7,EM8,EM9
2217   298A 4B 
2218   298B 54 5F 69 7C 	DB	EM10,EM11,EM12,EM13,EM14
2218   298F 8D 
2219   2990 9E AD       	DB	EM15,EML

Page     50    APPLE DOS 3.1

2220   2992             	PAGE
2221   2992             ;
2222   2992             ; 	MISC BUT REQD CELLS
2223   2992             ;
2224   2992 2D 18       CFTABA	DW	@@$182D		;CURRENT FILE TABLE POINTER
2225   2994 00          ISTATE	DB	$00		;INPUT STATE
2226   2995 03          OSTATE	DB	$03		;OUTPUT STATE
2227   2996 F0 FD       SVOUTS	DW	@@$FDF0		;SAVED OUT SWITCH
2228   2998 1B FD       SVINS	DW	@@$FD1B		;SAVED IN SWITCH
2229   299A 03          CNFTBS	DB	$03		;CURRENT NO FILE TABLES
2230   299B 03          DFNFTB	DB	$03		;DEFAULT NO FILE TABLES
2231   299C F7          SVSTK	DB	$F7		;SAVED STACK PTR
2232   299D 00          SVX	DB	$00		;DSAVED X REG
2233   299E 01          SVY	DB	$01		;SAVED Y REG
2234   299F A0          SVA	DB	$A0		;SAVED ACU
2235   29A0 0E          LBUFD	DB	$0E		;LINE BUFF DSPL
2236   29A1 70          MONMOD	DB	$70		;MONITOR MODE BITS
2237   29A2             MC	EQU	$40		;MONITOR CMDS
2238   29A2             MI	EQU	$20		;MONITOR INPUT
2239   29A2             MO	EQU	$10		;MONITOR OUTPUT
2240   29A2 20          CMDNO	DB	$20		;COMMAND NO
2241   29A3 00 00       SVBL	DB	0,0
2242   29A5 00          SVCMD	DB	0		
2243   29A6 06          TEMP1A	DB	$06
2244   29A7 01          TEMP2A	DB	1
2245   29A8 30          INOPTS	DB	$30		;INPUT OPTIONS
2246   29A9             CUROPT				;CURRENT OPTIONS
2247   29A9 10 00       CV	DW	@@$10		;VOLUME
2248   29AB 01 00       CD	DW	@@1		;DRIVE		
2249   29AD 07 00       CS	DW	@@7		;SLOT
2250   29AF 01 00       CL	DW	@@1		;RECORD LENGTH
2251   29B1 00 00       CR	DW	@@0		;RECORD NUMBER
2252   29B3 00 00       CB	DW	@@0		;RECORD BYTE
2253   29B5 00 00       CA	DW	@@0		;ADDRESS
2254   29B7 00          IMBITS	DB	0
2255   29B8             FNAME1	RMB	30		;FILENAME 1
2256   29D6             FNAME2	RMB	30		;FILENAME 2
2257   29F4 03          DFNFTS	DB	3		;DEFAULT FILE TABLES = 3
2258   29F5 84          CCHAR	DB	$84		;CONTROL CHAR
2259   29F6 00          ESTATE	DB	0		;EXECUTE STATE
2260   29F7 00 00       EFTABA	DB 	0,0		;EXECUTE FILE TABLE POINTER
2261   29F9 00          ASIBSW	DB	0		;APPLESOFT, IB SWITCH
2262   29FA C1 D0 D0 CC FASB	DB11	"APPLESOFT"
2262   29FE C5 D3 CF C6 
2262   2A02 D4 
2263   2A03             FASBL	EQU	*-FASB

Page     51    APPLE DOS 3.1

2264   2A03             	PAGE
2265   2A03             ;
2266   2A03             ; 	DOS ADR TABLES (RELOCATED)
2267   2A03             ;
2268   2A03             SAT2
2269   2A03 E8 37       AIOB	DW	@@IOB		;5-ADR IOB
2270   2A05 EF 32       AVTOC	DW	@@VTOC		;6-ADR VTOC
2271   2A07 EF 33       AVOLDR	DW	@@VOLDIR	;7-ADR VOLDIR
2272   2A09 00 40       AEND	DW	@@EDOS		;END OF DOS
2273   2A0B             ;
2274   2A0B BA 32       CMDVT	DW	@@GOODIO-1	;0-NULL
2275   2A0D 5A 2A       	DW	@@FOPEN-1	;1-OPEN FILE
2276   2A0F 22 2B       	DW	@@FCLOSE-1	;2-CLOSE FILE
2277   2A11 74 2B       	DW	@@FREAD-1	;3-READ FILE
2278   2A13 8C 2B       	DW	@@FWRITE-1	;4-WRITE DATA
2279   2A15 4A 2C       	DW	@@FDEL-1	;5-DELETE FILE
2280   2A17 B7 2C       	DW	@@RDIR-1	;6-READ DIRECTORY
2281   2A19 0B 2C       	DW	@@FLOCK-1	;7-LOCK A FILE
2282   2A1B 12 2C       	DW	@@FUNLCK-1	;8-UNLOCK A FILE
2283   2A1D 56 2B       	DW	@@FRNME-1	;9-RENAME
2284   2A1F 2E 2C       	DW	@@FPOSTN-1	;10-POSITION A FILE
2285   2A21 AC 2D       	DW	@@FFMT-1	;FORMAT
2286   2A23 34 2C       	DW	@@FVAR-1	; VARIFY
2287   2A25 BA 32       	DW	@@GOODIO-1	;11-SPARE
2288   2A27             ;
2289   2A27             RVT
2290   2A27 BA 32       	DW	@@GOODIO-1
2291   2A29 A6 2B       	DW	@@RNXBYT-1	;1-RD NEXT BYTE
2292   2A2B B2 2B       	DW	@@RNXBLK-1	;1-RD NEXT BLOCK
2293   2A2D A3 2B       	DW	@@RSPBYT-1	;2-RD SPECIFIC BYTE
2294   2A2F AF 2B       	DW	@@RSPBLK-1	;3-RD SPECIFIC BLOCK
2295   2A31 BA 32       	DW	@@GOODIO-1	;4-SPARE
2296   2A33             ;
2297   2A33             WVT
2298   2A33 BA 32       	DW	@@GOODIO-1
2299   2A35 DA 2B       	DW	@@WNXBYT-1	;1-WR NEXT BYTE
2300   2A37 E6 2B       	DW	@@WNXBLK-1	;WR NEXT BLOCK
2301   2A39 D7 2B       	DW	@@WSPBYT-1	;2-WR SPECIFIC BYTE
2302   2A3B E3 2B       	DW	@@WSPBLK-1	;3-WR SPECIFIC BLOCK
2303   2A3D BA 32       	DW	@@GOODIO-1	;4- SPARE
2304   2A3F             EAT2

Page     52    APPLE DOS 3.1

2305   2A3F             	PAGE
2306   2A3F             ;
2307   2A3F             ;	DOSENT  DOS EXTERNAL ENTRY POINT
2308   2A3F             ;		EXIT PARM
2309   2A3F             ;				CARRY CLEAR = OPERATION OK
2310   2A3F             ;				CARRY SET = ERROR
2311   2A3F             ;
2312   2A3F             SC2
2313   2A3F             DOSENT
2314   2A3F BA          	TSX
2315   2A40 8E D3 32    	STX	ENTSTK
2316   2A43 20 89 2D    	JSR	CLCFCB		;GO CALCULATE FCB
2317   2A46 AD EF 34    	LDA	CCBREQ		;GET REQUEST
2318   2A49 C9 0D       	CMP	#CRQMAX		;TTEST REQ RANGE
2319   2A4B B0 0B       	BCS	ERR2		;BR OUT OF RANGE
2320   2A4D 0A          	ASLA			;REQ CODE *2
2321   2A4E AA          	TAX
2322   2A4F BD 0C 2A    	LDA	CMDVT+1,X	;PUSH ADR ONTO STACK
2323   2A52 48          	PHA
2324   2A53 BD 0B 2A    	LDA	CMDVT,X
2325   2A56 48          	PHA
2326   2A57 60          	RTS
2327   2A58 4C 9F 32    ERR2	JMP	ERROR2

Page     53    APPLE DOS 3.1

2328   2A5B             	PAGE
2329   2A5B             ;
2330   2A5B             ;	FOPEN  OPEN A FILE
2331   2A5B             ;
2332   2A5B             FOPEN
2333   2A5B 20 61 2A    	JSR	DOPEN
2334   2A5E 4C BB 32    	JMP	GOODIO
2335   2A61             ;
2336   2A61             DOPEN
2337   2A61             ;
2338   2A61 20 F9 2A    	JSR	DCBSUP
2339   2A64             ;
2340   2A64             ;
2341   2A64 A9 01       	LDA	#1
2342   2A66 8D 17 35    	STA	DCBSDL+1
2343   2A69 AE F2 34    	LDX	CCBRLN+1	;MOVE RECORD LENGTH
2344   2A6C AD F1 34    	LDA	CCBRLN
2345   2A6F D0 05       	BNE	FO2
2346   2A71 E0 00       	CPX	#0
2347   2A73 D0 01       	BNE	FO2
2348   2A75 E8          	INX			;SET RL=256
2349   2A76 8D 1C 35    FO2	STA	DCBRCL
2350   2A79 8E 1D 35    	STX	DCBRCL+1
2351   2A7C             ;
2352   2A7C 20 05 31    	JSR	FNDFIL		;GO FIND FILE
2353   2A7F 90 45       	BCC	FO3		;BR IF FOUND
2354   2A81             ;				;CREATE FILE
2355   2A81 A9 00       	LDA	#0
2356   2A83 9D 1C 34    	STA	VDFILE+34,X
2357   2A86 A9 01       	LDA	#1
2358   2A88 9D 1B 34    	STA	VDFILE+33,X
2359   2A8B 8E D4 32    	STX	TEMP1		;SAVE VDIR INDEX
2360   2A8E 8E 0D 35    	STX	DCBVDI
2361   2A91 20 80 31    	JSR	GETSEC		;GO ALLOCATE SECTOR
2362   2A94 AE D4 32    	LDX	TEMP1
2363   2A97 9D FB 33    	STA	VDFILE+1,X	;PUT SECTOR INTO VDIR
2364   2A9A 8D 06 35    	STA	DCBFDS		;PUT SECTOR AS FIRST FILE DIR
2365   2A9D 8D 08 35    	STA	DCBCDS		;PUT SECTOR AS CURRENT FILE DIR
2366   2AA0             ;
2367   2AA0 AD 25 35    	LDA	DCBATK		;GET ALLOCATED TRACK
2368   2AA3 9D FA 33    	STA	VDFILE,X	;PUT INTO VDIR
2369   2AA6 8D 05 35    	STA	DCBFDT		;AND AS 1ST FILE DIR
2370   2AA9 8D 07 35    	STA	DCBCDT		;AND AS CURRENT FILE DIR
2371   2AAC             ;
2372   2AAC AD F6 34    	LDA	CCBFUC		;SET USE CODE
2373   2AAF 9D FC 33    	STA	VDFILE+2,X	;INTO DIRECTORY
2374   2AB2             ;
2375   2AB2 20 73 2F    	JSR	WRVDIR		;GO WRITE VOL DIRECTORY
2376   2AB5             ;
2377   2AB5 20 3F 2E    	JSR	MVFCBD		;MOVE FILE DIR ADR TO ZP
2378   2AB8 20 50 2E    	JSR	CLRSEC		;GO CLEAR IT
2379   2ABB 20 76 2E    	JSR	WRFDGO		;GO WRITE FILE DIRECTORY DONE CREATION
2380   2ABE             ;				DONE CREATION
2381   2ABE AE D4 32    	LDX	TEMP1		;RE-GET INDEX
2382   2AC1 A9 06       	LDA	#CREFNF
2383   2AC3 8D F9 34    	STA	CCBSTA
2384   2AC6             ;
2385   2AC6             FO3
2386   2AC6 BD FA 33    	LDA	VDFILE,X	;MOVE FILE DIR TRACK
2387   2AC9 8D 05 35    	STA	DCBFDT
2388   2ACC BD FB 33    	LDA	VDFILE+1,X	;MOVE FILE DIR SECTOR
2389   2ACF 8D 06 35    	STA	DCBFDS
2390   2AD2 BD FC 33    	LDA	VDFILE+2,X	;MOVE FILE USE CODE
2391   2AD5 8D F6 34    	STA	CCBFUC
2392   2AD8 8D 2A 35    	STA	DCBFUC
2393   2ADB BD 1B 34    	LDA	VDFILE+33,X
2394   2ADE 8D 22 35    	STA	DCBNSA
2395   2AE1 BD 1C 34    	LDA	VDFILE+34,X
2396   2AE4 8D 23 35    	STA	DCBNSA+1
2397   2AE7             ;
2398   2AE7 A9 FF       	LDA	#255		;INDICATE NO SECTOR
2399   2AE9 8D 14 35    	STA	DCBCMS		;IN MEMORY
2400   2AEC 8D 15 35    	STA	DCBCMS+1
2401   2AEF AD 16 33    	LDA	VTDMS		;MOVE MAX FD SECS
2402   2AF2 8D 0E 35    	STA	DCBDMS		;TO DCB
2403   2AF5 18          	CLC
2404   2AF6 4C 9A 2E    	JMP	RDFDIR		; READ 1ST DIRECTORY RECORD
2405   2AF9             ;
2406   2AF9             ;
2407   2AF9             ;
2408   2AF9             ;
2409   2AF9             DCBSUP
2410   2AF9 A9 00       	LDA	#0
2411   2AFB AA          	TAX
2412   2AFC 9D 05 35    FO1	STA	FCBDCB,X	;CLEAR DCB
2413   2AFF E8          	INX
2414   2B00 E0 2D       	CPX	#DCBLEN
2415   2B02 D0 F8       	BNE	FO1
2416   2B04             ;
2417   2B04 AD F3 34    	LDA	CCBVOL		;MOVE VOL
2418   2B07 49 FF       	EOR	#$FF		;INVERT VOL BITS
2419   2B09 8D 2D 35    	STA	DCBVOL
2420   2B0C AD F4 34    	LDA	CCBDRV		;MOVE DRIVE
2421   2B0F 8D 2C 35    	STA	DCBDRV
2422   2B12 AD F5 34    	LDA	CCBSLT		;GET USER SPEC SLOT
2423   2B15 0A          	ASLA			;SLOT*16
2424   2B16 0A          	ASLA
2425   2B17 0A          	ASLA
2426   2B18 0A          	ASLA
2427   2B19 AA          	TAX
2428   2B1A 8E 2B 35    	STX	DCBSLT
2429   2B1D A9 11       	LDA	#17
2430   2B1F 8D 2E 35    	STA	DCBVTN
2431   2B22 60          	RTS

Page     54    APPLE DOS 3.1

2432   2B23             	PAGE
2433   2B23             ;
2434   2B23             ;	FCLOSE  CLOSE A FILE
2435   2B23             ;
2436   2B23             FCLOSE
2437   2B23 20 59 2E    	JSR	WRSECT		;WRITE OPEN SECTOR
2438   2B26 20 70 2E    	JSR	WRFDIR		;GO WRITE FILE DIRECTORY
2439   2B29 20 FF 31    	JSR	FRETRK		;FREE UNUSED SECTORS
2440   2B2C A9 02       	LDA	#IBCWTS
2441   2B2E 2D 09 35    	AND	DCBWRF
2442   2B31 F0 21       	BEQ	FC2
2443   2B33             ;
2444   2B33 20 33 2F    	JSR	RDVTOC		; READ VTOC
2445   2B36 A9 00       	LDA	#0
2446   2B38 18          	CLC
2447   2B39             FC1
2448   2B39 20 4D 2F    	JSR	RDVDIR		; READ VDIR
2449   2B3C 38          	SEC
2450   2B3D CE 0C 35    	DEC	DCBVDR
2451   2B40 D0 F7       	BNE	FC1		; BR IF NOT
2452   2B42 AE 0D 35    	LDX	DCBVDI		; GET FILES INDEX
2453   2B45 AD 22 35    	LDA	DCBNSA		; MOVE NO SECTIONS ALLOCATED
2454   2B48 9D 1B 34    	STA	VDFILE+33,X
2455   2B4B AD 23 35    	LDA	DCBNSA+1
2456   2B4E 9D 1C 34    	STA	VDFILE+34,X
2457   2B51 20 73 2F    	JSR	WRVDIR		; WRITE VOL DIR REC
2458   2B54             ;
2459   2B54             ;
2460   2B54             FC2
2461   2B54 4C BB 32    	JMP	GOODIO		;DONE

Page     55    APPLE DOS 3.1

2462   2B57             	PAGE
2463   2B57             ;
2464   2B57             ;	FRNME  RENAME A FILE
2465   2B57             ;
2466   2B57             FRNME
2467   2B57 20 61 2A    	JSR	DOPEN		;GO OPEN FILE
2468   2B5A AD 2A 35    	LDA	DCBFUC		;GET USE CODE
2469   2B5D 30 2B       	BMI	ER10		;BR IF LOCKED
2470   2B5F AD F1 34    	LDA	CCBFN2		;MOVE NEW FN
2471   2B62 85 42       	STA	ZPGFCB		;PTR TO ZPG
2472   2B64 AD F2 34    	LDA	CCBFN2+1
2473   2B67 85 43       	STA	ZPGFCB+1
2474   2B69 AE D4 32    	LDX	TEMP1		;GET VDIR INDEX
2475   2B6C 20 58 31    	JSR	MVFN		;GO MOVE FILE NAME
2476   2B6F 20 73 2F    	JSR	WRVDIR		;GO WRITE FILE VDIR
2477   2B72 4C BB 32    	JMP	GOODIO		;DONE RENAME

Page     56    APPLE DOS 3.1

2478   2B75             	PAGE
2479   2B75             ;
2480   2B75             ;	FREAD  READ A FILE
2481   2B75             ;
2482   2B75             FREAD
2483   2B75             ;
2484   2B75 AD F0 34    	LDA	CCBRQM		;GET REQ MOD
2485   2B78 C9 05       	CMP	#CRMMAX		;TEST LIMIT
2486   2B7A B0 0B       	BCS	ERR3A
2487   2B7C             ;
2488   2B7C 0A          	ASLA			;CODE*2
2489   2B7D AA          	TAX
2490   2B7E BD 28 2A    	LDA	RVT+1,X		;GET READ ROUTINE
2491   2B81 48          	PHA			;VECTOR ADR
2492   2B82 BD 27 2A    	LDA	RVT,X
2493   2B85 48          	PHA			;AND
2494   2B86 60          	RTS			;GO TO IT
2495   2B87             ;
2496   2B87 4C A3 32    ERR3A	JMP	ERROR3
2497   2B8A 4C B7 32    ER10	JMP	ERRR10
2498   2B8D             ;
2499   2B8D             ;	FWRITE  WRITE A FILE
2500   2B8D             ;
2501   2B8D             FWRITE
2502   2B8D AD 2A 35    	LDA	DCBFUC		;IS FILE LOCKED
2503   2B90 30 F8       	BMI	ER10		;BR IF LOCKED
2504   2B92 AD F0 34    	LDA	CCBRQM		;GET REQ MOD
2505   2B95 C9 05       	CMP	#CRMMAX		;IN RANGE
2506   2B97 B0 EE       	BCS	ERR3A		;BR IF NOT IN RANGE
2507   2B99             ;
2508   2B99 0A          	ASLA
2509   2B9A AA          	TAX
2510   2B9B BD 34 2A    	LDA	WVT+1,X		;GET ROUTINE ADR
2511   2B9E 48          	PHA
2512   2B9F BD 33 2A    	LDA	WVT,X
2513   2BA2 48          	PHA
2514   2BA3 60          	RTS			;AND GO TO IT

Page     57    APPLE DOS 3.1

2515   2BA4             	PAGE
2516   2BA4             ;
2517   2BA4             ;	RSPBYT  READ A SPECIFIC BYTE
2518   2BA4             ;
2519   2BA4             RSPBYT
2520   2BA4 20 3C 32    	JSR	LOCSEC		;GO GET REQD REL SECTOR
2521   2BA7             ;
2522   2BA7             ;	RNXBYT  READ NEXT BYTE
2523   2BA7             ;
2524   2BA7 20 C5 2B    RNXBYT	JSR	GETBYT		;GO GET BYTE
2525   2BAA 8D F7 34    	STA	CCBDAT		;PUT IN CCB
2526   2BAD 4C BB 32    	JMP	GOODIO		;DONE
2527   2BB0             ;
2528   2BB0             ;	RSPBLK  READ A SPECIFIC BLOCK
2529   2BB0             ;
2530   2BB0 20 3C 32    RSPBLK	JSR	LOCSEC		;GO LOCATE REL SECTOR
2531   2BB3             ;
2532   2BB3             ;	RNXBLK  READ NEXT BLOCK
2533   2BB3             ;
2534   2BB3             RNXBLK
2535   2BB3 20 F1 30    	JSR	DTBLN		;GO DECR LEN (NOT RTN IF=0)
2536   2BB6 20 C5 2B    	JSR	GETBYT		;GO GET BYTE
2537   2BB9 48          	PHA
2538   2BBA 20 DE 30    	JSR	MIBDA		;GO MOVE BLOCK ADR AND INCR
2539   2BBD A0 00       	LDY	#0
2540   2BBF 68          	PLA
2541   2BC0 91 42       	STA	(ZPGFCB),Y	;SET DATA BYTE
2542   2BC2 4C B3 2B    	JMP	RNXBLK		;GO FOR NEXT BYTE
2543   2BC5             ;
2544   2BC5             ;	GETBYT  GET A DATA BYTE
2545   2BC5             ;
2546   2BC5             GETBYT
2547   2BC5 20 F2 2F    	JSR	LOCNXB		;LOCATE NEXT BYTE
2548   2BC8 B0 0B       	BCS	EOFIN		;BR IF EOF
2549   2BCA B1 42       	LDA	(ZPGFCB),Y	;BR IF EOF
2550   2BCC 48          	PHA			;SAVE IT
2551   2BCD 20 97 30    	JSR	INCRRB		;INCR REC BYTE
2552   2BD0 20 D0 30    	JSR	INCSCB		;INCR SAVED BYTE
2553   2BD3 68          	PLA			;GET SAVED BYTE
2554   2BD4 60          	RTS			;RETURN
2555   2BD5             ;
2556   2BD5 4C AB 32    EOFIN	JMP	ERROR5		;GO TO EOF RTN

Page     58    APPLE DOS 3.1

2557   2BD8             	PAGE
2558   2BD8             ;
2559   2BD8             ;	WSPBYT  WRITE SPECIFIC BYTE
2560   2BD8             ;
2561   2BD8             WSPBYT
2562   2BD8 20 3C 32    	JSR	LOCSEC		;GO LOCATE SECTOR
2563   2BDB             ;
2564   2BDB             ;	WNXBYT  WRITE NEXT BYTE
2565   2BDB             ;
2566   2BDB             WNXBYT
2567   2BDB AD F7 34    	LDA	CCBDAT		;GET THE BYTE
2568   2BDE 20 F7 2B    	JSR	PUTBYT		;GO WRITE BYTE
2569   2BE1 4C BB 32    	JMP	GOODIO		;DONE
2570   2BE4             ;
2571   2BE4             ;	WSPBLK  WRITE NEXT BLOCK
2572   2BE4             ;
2573   2BE4             WSPBLK
2574   2BE4 20 3C 32    	JSR	LOCSEC		;GO LOCATE SECTOR
2575   2BE7             ;
2576   2BE7             ;	WNXBLK  WRITE BLOCK
2577   2BE7             ;
2578   2BE7             WNXBLK
2579   2BE7 20 DE 30    	JSR	MIBDA		;GO MOVE ADR TO ZPG AND DEC
2580   2BEA A0 00       	LDY	#0
2581   2BEC B1 42       	LDA	(ZPGFCB),Y	;GET DATA BYTE
2582   2BEE 20 F7 2B    	JSR	PUTBYT		;GO PUT IT
2583   2BF1 20 F1 30    	JSR	DTBLN		;GO DEC BLK LEN (NOT RTN IF = 0)
2584   2BF4 4C E7 2B    	JMP	WNXBLK
2585   2BF7             ;
2586   2BF7             ;	PUTBYT  PUT OUT ONE BYTE
2587   2BF7             ;
2588   2BF7             PUTBYT
2589   2BF7 48          	PHA			;SAVE DATA BYTE
2590   2BF8 20 F2 2F    	JSR	LOCNXB		;GO LOCATE NEXT BYTE
2591   2BFB             ;
2592   2BFB 68          	PLA			;GO SAVED BYTE
2593   2BFC 91 42       	STA	(ZPGFCB),Y	;PUT THE BYTE
2594   2BFE A9 40       	LDA	#$40		;SET WRITE SECTOR REQD
2595   2C00 0D 09 35    	ORA	DCBWRF
2596   2C03 8D 09 35    	STA	DCBWRF
2597   2C06             ;
2598   2C06 20 97 30    	JSR	INCRRB		;INCR REL REC BYTE
2599   2C09 4C D0 30    	JMP	INCSCB		; INCR SECTOR BYTE

Page     59    APPLE DOS 3.1

2600   2C0C             	PAGE
2601   2C0C             ;
2602   2C0C             ;	FLOCK  LOCK A FILE
2603   2C0C             ;
2604   2C0C A9 80       FLOCK	LDA	#$80		;REMEMBER LOCK
2605   2C0E 8D D6 32    	STA	TEMP3
2606   2C11 D0 05       	BNE	LCKGO
2607   2C13             ;
2608   2C13             ;	FUNLCK  UNLOCK A FILE
2609   2C13             ;
2610   2C13 A9 00       FUNLCK	LDA	#00		;REMEMBER UNLOCK
2611   2C15 8D D6 32    	STA	TEMP3
2612   2C18             ;
2613   2C18             LCKGO
2614   2C18             ;
2615   2C18 20 61 2A    	JSR	DOPEN		;GO OPEN FILE
2616   2C1B AE D4 32    	LDX	TEMP1
2617   2C1E BD FC 33    	LDA	VDFILE+2,X	;GET FILE USE CODE
2618   2C21 29 7F       	AND	#$7F		;TURN OFF LOCK
2619   2C23 0D D6 32    	ORA	TEMP3
2620   2C26 9D FC 33    	STA	VDFILE+2,X
2621   2C29 20 73 2F    	JSR	WRVDIR
2622   2C2C 4C BB 32    	JMP	GOODIO
2623   2C2F             ;
2624   2C2F             ;	FPOSTN  POSITION A FILE
2625   2C2F 20 3C 32    FPOSTN	JSR	LOCSEC		;GO POSITION
2626   2C32 4C BB 32    	JMP	GOODIO		;DONE
2627   2C35             ;
2628   2C35             ;
2629   2C35             ;	FVAR  VARIFY A FILE
2630   2C35             ;
2631   2C35             FVAR
2632   2C35 20 61 2A    	JSR	DOPEN		; OPEN FILE
2633   2C38 20 F2 2F    VAR1	JSR	LOCNXB		; READ A SECTOR
2634   2C3B B0 0B       	BCS	VAR2		; BR IF EOF
2635   2C3D EE 18 35    	INC	DCBCRS		; INCREMENT SECTOR
2636   2C40 D0 F6       	BNE	VAR1
2637   2C42 EE 19 35    	INC	DCBCRS+1
2638   2C45 4C 38 2C    	JMP	VAR1		; READ THIS ONE
2639   2C48 4C BB 32    VAR2	JMP	GOODIO		; DONE	

Page     60    APPLE DOS 3.1

2640   2C4B             	PAGE
2641   2C4B             ;
2642   2C4B             ;	FDEL  DELETE A FILE
2643   2C4B             ;
2644   2C4B             FDEL
2645   2C4B 20 61 2A    	JSR	DOPEN		;GO OPEN FILE
2646   2C4E             ;
2647   2C4E AE D4 32    	LDX	TEMP1		;SAVED INDEX
2648   2C51 BD FC 33    	LDA	VDFILE+2,X	;IS FILE LOCKED
2649   2C54 10 03       	BPL	FD3		;BR NOT LOCKED
2650   2C56 4C B7 32    	JMP	ERRR10
2651   2C59             ;
2652   2C59             FD3
2653   2C59 AE D4 32    	LDX	TEMP1		;GET SAVED INDEX
2654   2C5C BD FA 33    	LDA	VDFILE,X	;GET DIR TRACK
2655   2C5F 8D 05 35    	STA	DCBFDT		;SET AS 1ST FD TRACK
2656   2C62 9D 1A 34    	STA	VDFILE+32,X	;SAVE IN LC OF FN
2657   2C65 A9 FF       	LDA	#$FF		;DELETED FILE MARKER
2658   2C67 9D FA 33    	STA	VDFILE,X	;CLEAR ENTRY
2659   2C6A BC FB 33    	LDY	VDFILE+1,X	;GET DIR SECTOR
2660   2C6D 8C 06 35    	STY	DCBFDS		;SET AS 1ST FD SEC
2661   2C70 20 73 2F    	JSR	WRVDIR		;GO WRITE VOLUME DIR
2662   2C73 18          	CLC
2663   2C74 20 9A 2E    FD4	JSR	RDFDIR		;GET 1ST FILE DIR SECTOR
2664   2C77 B0 2A       	BCS	FD7		;BR IF NO MORE
2665   2C79 20 3F 2E    	JSR	MVFCBD		;MOVE DIR TO ZPG
2666   2C7C A0 0C       	LDY	#FDENT		;POINT Y TO 1ST SEC ENT
2667   2C7E 8C D4 32    FD5	STY	TEMP1		;SAVE Y
2668   2C81 B1 42       	LDA	(ZPGFCB),Y	;GET REACK
2669   2C83 30 0B       	BMI	FD6		;BR IF DONE
2670   2C85 F0 09       	BEQ	FD6		;BR IF END OF FILE
2671   2C87 48          	PHA			;SAVE TRK
2672   2C88 C8          	INY
2673   2C89 B1 42       	LDA	(ZPGFCB),Y	;GET SECTOR
2674   2C8B A8          	TAY			;TO Y
2675   2C8C 68          	PLA			;GET TRK
2676   2C8D 20 A9 2C    	JSR	FDSUB		;GO FREE SECTOR
2677   2C90 AC D4 32    FD6	LDY	TEMP1		;GET DIR INDEX
2678   2C93 C8          	INY			;INCR TO NEXT ENTRY
2679   2C94 C8          	INY
2680   2C95 D0 E7       	BNE	FD5		;BR NOT DONE THIS DIR
2681   2C97 AD 07 35    	LDA	DCBCDT		;GET THIS DIR TRK
2682   2C9A AC 08 35    	LDY	DCBCDS		;AND SECTOR
2683   2C9D 20 A9 2C    	JSR	FDSUB		;AND GO FREE IT
2684   2CA0 38          	SEC			;GO
2685   2CA1 B0 D1       	BCS	FD4		;READ NEXT DIR
2686   2CA3             FD7
2687   2CA3 20 37 2F    	JSR	WRVTOC
2688   2CA6 4C BB 32    	JMP	GOODIO
2689   2CA9             ;
2690   2CA9             FDSUB
2691   2CA9 38          	SEC			;SET FOR RE USE OF SEC
2692   2CAA 20 19 32    	JSR	FRESEC		;GO FREE SECTOR
2693   2CAD A9 00       	LDA	#0		;CLEAR DCB BIT MAP
2694   2CAF A2 03       	LDX	#3
2695   2CB1 9D 24 35    FDS1	STA	DCBALS,X
2696   2CB4 CA          	DEX
2697   2CB5 10 FA       	BPL	FDS1
2698   2CB7 60          	RTS

Page     61    APPLE DOS 3.1

2699   2CB8             	PAGE
2700   2CB8             ;
2701   2CB8             ;	RDIR  PRINT DIRECTORY
2702   2CB8             ;
2703   2CB8             RDIR
2704   2CB8 20 F9 2A    	JSR	DCBSUP
2705   2CBB A9 FF       	LDA	#$FF
2706   2CBD 8D 2D 35    	STA	DCBVOL
2707   2CC0 20 33 2F    	JSR	RDVTOC
2708   2CC3 A9 16       	LDA	#22		; SET 21 LINES
2709   2CC5 8D D5 32    	STA	TEMP2
2710   2CC8 20 4E 2D    	JSR	PRCR		;GO PRINT
2711   2CCB 20 4E 2D    	JSR	PRCR		; PRINT ANOTHER CHAR
2712   2CCE A2 0B       	LDX	#VML		; VOLUME MSG LENGTH
2713   2CD0 BD E3 32    RD0	LDA	VOLMES,X	; GET MSG CHAR
2714   2CD3 20 ED FD    	JSR	PRINT		; PRINT IT
2715   2CD6 CA          	DEX			; DECREMENT COUNT
2716   2CD7 10 F7       	BPL	RD0		; BR IF MORE
2717   2CD9             ;
2718   2CD9 86 45       	STX	CNUM+1
2719   2CDB AD F6 37    	LDA	IBSMOD		; MOVE VOL NO FOR
2720   2CDE 85 44       	STA	CNUM		; CONVERSION
2721   2CE0 20 61 2D    	JSR	PRNUM		; GO PRINT VOL NO
2722   2CE3             ;
2723   2CE3 20 4E 2D    	JSR	PRCR		; PRINT CR
2724   2CE6 20 4E 2D    	JSR	PRCR		; AND AGAIN
2725   2CE9             ;
2726   2CE9 18          	CLC			;FIRST RECORD
2727   2CEA             ;
2728   2CEA 20 4D 2F    RD1	JSR	RDVDIR		;GO READ REC
2729   2CED B0 5C       	BCS	RD5
2730   2CEF A2 00       	LDX	#0		;SET INDEX=0
2731   2CF1 8E D4 32    RD2	STX	TEMP1		;SAVE INDEX
2732   2CF4 BD FA 33    	LDA	VDFILE,X	;GET TRACK
2733   2CF7 F0 52       	BEQ	RD5		;BR IF END OF DIR
2734   2CF9 30 49       	BMI	RD4		;BR IF DELETED
2735   2CFB             ;
2736   2CFB A0 A0       	LDY	#$A0		; BLANK
2737   2CFD BD FC 33    	LDA	VDFILE+2,X	; GET TYPE
2738   2D00 10 02       	BPL	RD2A		; BR IF NOT LOCKED
2739   2D02 A0 AA       	LDY	#'*'+$80	; AST
2740   2D04 98          RD2A	TYA			; ACU = AST OR BLANK
2741   2D05 20 ED FD    	JSR	PRINT		; PRINT ACU
2742   2D08             ;
2743   2D08 BD FC 33    	LDA	VDFILE+2,X	; GET TYPE
2744   2D0B 29 07       	AND	#$07		; MASK OUT MISC
2745   2D0D A0 03       	LDY	#3		; SET INDEX = 3
2746   2D0F 4A          RD2B	LSRA			; SHIFT OUT LSB
2747   2D10 B0 03       	BCS	RD2C		;BR IF TYPE BIT OUT
2748   2D12 88          	DEY			; DEC INDEX
2749   2D13 D0 FA       	BNE	RD2B		; BR IF NOT ACC BITS
2750   2D15             RD2C
2751   2D15 B9 DF 32    	LDA	FTTAB,Y		; GET TYPE CODE
2752   2D18 20 ED FD    	JSR	PRINT		; PRINT IT
2753   2D1B A9 A0       	LDA	#$A0		; BLANK
2754   2D1D 20 ED FD    	JSR	PRINT		; PRINT
2755   2D20             ;
2756   2D20 BD 1B 34    	LDA	VDFILE+33,X	; MOVE FILE LENGTH
2757   2D23 85 44       	STA	CNUM		; TO CNUM
2758   2D25 BD 1C 34    	LDA	VDFILE+34,X
2759   2D28 85 45       	STA	CNUM+1
2760   2D2A 20 61 2D    	JSR	PRNUM		; GO PRINT NUMBER
2761   2D2D A9 A0       	LDA	#$A0		; BLANK
2762   2D2F 20 ED FD    	JSR	PRINT		; PRINT
2763   2D32             ;
2764   2D32 E8          	INX
2765   2D33 E8          	INX
2766   2D34 E8          	INX
2767   2D35 A0 1D       	LDY	#29
2768   2D37 BD FA 33    RD3	LDA	VDFILE,X	;GET CHAR
2769   2D3A 20 ED FD    	JSR	PRINT		;PRINT CHAR
2770   2D3D E8          	INX
2771   2D3E 88          	DEY
2772   2D3F 10 F6       	BPL	RD3
2773   2D41 20 4E 2D    	JSR	PRCR		;GO PRINT CR
2774   2D44 20 6C 31    RD4	JSR	VDINC		;INCR INDEX
2775   2D47 90 A8       	BCC	RD2		;BR IF MORE IN DIR
2776   2D49 B0 9F       	BCS	RD1		;GO READ NEXT DIR SECT
2777   2D4B             ;
2778   2D4B 4C BB 32    RD5	JMP	GOODIO		;DONE
2779   2D4E             ;
2780   2D4E             PRCR
2781   2D4E A9 8D       	LDA	#$8D		;CR
2782   2D50 20 ED FD    	JSR	PRINT		;PRINTED
2783   2D53 CE D5 32    	DEC	TEMP2		;DEC LINE COUNTER
2784   2D56 D0 08       	BNE	PRCR1		;BR IF NOT ZERO
2785   2D58 20 0C FD    	JSR	GETKEY		;WAIT FOR INPUT
2786   2D5B A9 15       	LDA	#21		; RESET LINE COUNTER
2787   2D5D 8D D5 32    	STA	TEMP2
2788   2D60 60          PRCR1	RTS			;DONE

Page     62    APPLE DOS 3.1

2789   2D61             	PAGE
2790   2D61             PRNUM
2791   2D61 A0 02       	LDY	#2		; 3 DIGITS
2792   2D63 A9 00       PRN1	LDA	#0		; INIT DIGIT TO ZERO
2793   2D65 48          	PHA			; SAVE IT
2794   2D66             ;
2795   2D66 A5 44       PRN2	LDA	CNUM		; GET NUMBER
2796   2D68 D9 DC 32    	CMP	CVTAB,Y		; IF NUM < CVTAB ENTRY
2797   2D6B 90 12       	BCC	PRN3		; THEN DONE THIS DIGIT
2798   2D6D             ;
2799   2D6D F9 DC 32    	SBC	CVTAB,Y		; SUBTRACT TABLE ENTRY
2800   2D70 85 44       	STA	CNUM		; FROM NUM
2801   2D72 A5 45       	LDA	CNUM+1
2802   2D74 E9 00       	SBC	#0
2803   2D76 85 45       	STA	CNUM+1
2804   2D78 68          	PLA			; INCREMENT DIGIT
2805   2D79 69 00       	ADC	#0
2806   2D7B 48          	PHA
2807   2D7C 4C 66 2D    	JMP	PRN2		; TRY AGAIN
2808   2D7F             ;
2809   2D7F             PRN3
2810   2D7F 68          	PLA			; GET DIGIT
2811   2D80 09 B0       	ORA	#$B0		; ADD ASCII
2812   2D82 20 ED FD    	JSR	PRINT		; PRINT IT
2813   2D85 88          	DEY			; DECREMENT DIGIT COUNT
2814   2D86 10 DB       	BPL	PRN1		; BR IF MORE DIGIT
2815   2D88             ;
2816   2D88 60          	RTS			; DONE

Page     63    APPLE DOS 3.1

2817   2D89             	PAGE
2818   2D89             ;
2819   2D89             ;	CLCFCB  GET FCB VIA INDEX AND MOVE IT
2820   2D89             ;
2821   2D89             CLCFCB
2822   2D89             ;
2823   2D89 20 3B 2E    	JSR	MVFCBP		;MOVE FCB PTR TO ZPG
2824   2D8C A0 00       	LDY	#0
2825   2D8E 8C F9 34    	STY	CCBSTA
2826   2D91 B1 42       CF3	LDA	(ZPGFCB),Y	;MOVE FCB TO
2827   2D93 99 05 35    	STA	FCBB,Y		;FCB WORK AREA
2828   2D96 C8          	INY
2829   2D97 C0 2D       	CPY	#FCBLEN
2830   2D99 D0 F6       	BNE	CF3
2831   2D9B             ;
2832   2D9B 18          	CLC			;DONE
2833   2D9C 60          	RTS
2834   2D9D             ;
2835   2D9D             ;	RTNFCB  MOVE FCB FROM WORK AREA TO FCB
2836   2D9D             ;
2837   2D9D             RTNFCB
2838   2D9D 20 3B 2E    	JSR	MVFCBP		;MOVE FCB ADR TO ZPG
2839   2DA0             ;
2840   2DA0 A0 00       	LDY	#0
2841   2DA2 B9 05 35    RF1	LDA	FCBB,Y
2842   2DA5 91 42       	STA	(ZPGFCB),Y
2843   2DA7 C8          	INY
2844   2DA8 C0 2D       	CPY	#FCBLEN
2845   2DAA D0 F6       	BNE	RF1
2846   2DAC 60          	RTS

Page     64    APPLE DOS 3.1

2847   2DAD             	PAGE
2848   2DAD             ;
2849   2DAD             ;	FFMT  EXECUTE FORMAT REQUEST
2850   2DAD             ;
2851   2DAD             FFMT
2852   2DAD 20 F9 2A    	JSR	DCBSUP		; SET UP DCB
2853   2DB0 A9 04       	LDA	#IBFMT
2854   2DB2 20 94 2F    	JSR	DCBIO2
2855   2DB5 AD 2D 35    	LDA	DCBVOL		; SET VOL NO
2856   2DB8 49 FF       	EOR	#$FF
2857   2DBA 8D F5 32    	STA	VVOLNO
2858   2DBD A9 11       	LDA	#17
2859   2DBF 8D 1F 33    	STA	VALCA1		; ALOCATE BYTE 1
2860   2DC2 A9 01       	LDA	#1
2861   2DC4 8D 20 33    	STA	VALCA2		; ADD BYTE 2
2862   2DC7             ;
2863   2DC7 A2 38       	LDX	#VSECAL-VTOC
2864   2DC9 A9 00       	LDA	#0
2865   2DCB 9D EF 32    NT1	STA	VTOC,X		; CLEAR SECTOR AREA
2866   2DCE E8          	INX
2867   2DCF D0 FA       	BNE	NT1
2868   2DD1             ;
2869   2DD1 A2 0C       	LDX	#3*4		;START AT TRACK 3
2870   2DD3 E0 8C       NT2	CPX	#35*4		; END AT TRACK 35
2871   2DD5 F0 14       	BEQ	NT4
2872   2DD7 A0 03       	LDY	#3		; 4 BYTES OF INFO
2873   2DD9 B9 D8 32    NT3	LDA	ALC10S,Y	; 10 SECTORS ALLOCATE
2874   2DDC 9D 27 33    	STA	VSECAL,X
2875   2DDF E8          	INX
2876   2DE0 88          	DEY
2877   2DE1 10 F6       	BPL	NT3
2878   2DE3 E0 44       	CPX	#17*4		; AT TRACK 17
2879   2DE5 D0 EC       	BNE	NT2		; BR IF NOT
2880   2DE7 A2 48       	LDX	#18*4		; SKIP TO 18
2881   2DE9 D0 E8       	BNE	NT2
2882   2DEB             ;
2883   2DEB 20 37 2F    NT4	JSR	WRVTOC		; WRITE NEW VTOC
2884   2DEE             ;
2885   2DEE A2 00       	LDX	#0
2886   2DF0 8A          	TXA
2887   2DF1 9D EF 33    NT5	STA	VOLDIR,X	; CLEAR VOLDIR
2888   2DF4 E8          	INX
2889   2DF5 D0 FA       	BNE	NT5
2890   2DF7             ;
2891   2DF7 20 81 2F    	JSR	MVVDBA		; MOVE BUF PTRS
2892   2DFA             ;
2893   2DFA A9 11       	LDA	#17		; TRACK 17
2894   2DFC AC 24 33    	LDY	VNOSEC
2895   2DFF 88          	DEY
2896   2E00 88          	DEY
2897   2E01 8D EC 37    	STA	IBTRK		; INTO IOB
2898   2E04 8D F0 33    NT6	STA	VDLTRK		; INTO LINK
2899   2E07 8C F1 33    NT7	STY	VDLSEC
2900   2E0A C8          	INY
2901   2E0B 8C ED 37    	STY	IBSECT
2902   2E0E A9 02       	LDA	#IBCWTS
2903   2E10 20 94 2F    	JSR	DCBIO2
2904   2E13 AC F1 33    	LDY	VDLSEC
2905   2E16 88          	DEY			; DECREMENT SECTOR
2906   2E17 30 05       	BMI	NT8		; BR LAST WRITTEN
2907   2E19 D0 EC       	BNE	NT7		; BR NOT LAST
2908   2E1B 98          	TYA			; LAST, SET LINK TRK=0
2909   2E1C F0 E6       	BEQ	NT6
2910   2E1E             ;
2911   2E1E             NT8
2912   2E1E 20 27 2E    	JSR	DLDSUP		; GO SET UP FOR DOSLDR
2913   2E21 20 4A 37    	JSR	WBOOT		;GO WRITE THE BOOT
2914   2E24 4C BB 32    	JMP	GOODIO		; DONE

Page     65    APPLE DOS 3.1

2915   2E27             	PAGE
2916   2E27             ;
2917   2E27             ;	DLDSUP  SET UP FOR DOSLDR
2918   2E27             ;
2919   2E27             DLDSUP
2920   2E27 AD F0 34    	LDA	CCBBSA
2921   2E2A 8D F1 37    	STA	IBBUFP+1	; START ADR
2922   2E2D A9 00       	LDA	#0
2923   2E2F 8D F0 37    	STA	IBBUFP
2924   2E32 AD 2D 35    	LDA	DCBVOL		; VOL
2925   2E35 49 FF       	EOR	#$FF
2926   2E37 8D EB 37    	STA	IBVOL
2927   2E3A 60          	RTS

Page     66    APPLE DOS 3.1

2928   2E3B             	PAGE
2929   2E3B             ;
2930   2E3B             ;	MVFCBX  MOVE FCB ADRS TO ZPGFCB
2931   2E3B             ;
2932   2E3B A2 00       MVFCBP	LDX	#0		;MOVE FCB ADR
2933   2E3D F0 06       	BEQ	MVF1
2934   2E3F A2 02       MVFCBD	LDX	#2		;MOVE FCB DIR BUFF
2935   2E41 D0 02       	BNE	MVF1
2936   2E43 A2 04       MVFCBS	LDX	#4		;MOVE FCB SECTOR BUFF
2937   2E45             ;
2938   2E45             MVF1
2939   2E45 BD FB 34    	LDA	CFCBAD,X	;DO THE MOVE
2940   2E48 85 42       	STA	ZPGFCB
2941   2E4A BD FC 34    	LDA	CFCBAD+1,X
2942   2E4D 85 43       	STA	ZPGFCB+1
2943   2E4F 60          	RTS
2944   2E50             ;
2945   2E50             ;	CLRSEC  CLEAR SECTOR
2946   2E50             ;
2947   2E50             CLRSEC
2948   2E50 A9 00       	LDA	#0
2949   2E52 A8          	TAY
2950   2E53 91 42       CS1	STA	(ZPGFCB),Y
2951   2E55 C8          	INY
2952   2E56 D0 FB       	BNE	CS1
2953   2E58 60          	RTS

Page     67    APPLE DOS 3.1

2954   2E59             	PAGE
2955   2E59             ;
2956   2E59             ;	WRSECT  WRITE CURRENT SECTOR IF REQD
2957   2E59             ;
2958   2E59             WRSECT
2959   2E59 2C 09 35    	BIT	DCBWRF		;GET WRITE REQD FLAG
2960   2E5C 70 01       	BVS	WRSGO		;BR IF WRITE SECTOR REQD
2961   2E5E 60          	RTS			;RTS
2962   2E5F             ;
2963   2E5F             WRSGO
2964   2E5F 20 20 2F    	JSR	MVSBA		;GO MOVE SECT BUFF ADR
2965   2E62             ;
2966   2E62 A9 02       	LDA	#IBCWTS		;GET COMMAND
2967   2E64 20 8E 2F    	JSR	DCBIO		;GO FILL IN IOB AND DO IO
2968   2E67             ;
2969   2E67 A9 BF       	LDA	#$BF		;SET WRITE SECTOR REQD BIT OFF
2970   2E69 2D 09 35    	AND	DCBWRF
2971   2E6C 8D 09 35    	STA	DCBWRF
2972   2E6F 60          	RTS			;DONE

Page     68    APPLE DOS 3.1

2973   2E70             	PAGE
2974   2E70             ;
2975   2E70             ;	WRFDIR  WRITE FILE DIRECTORY IF REQD
2976   2E70             ;
2977   2E70             WRFDIR
2978   2E70 AD 09 35    	LDA	DCBWRF		;GET WRITE REQD FLAG
2979   2E73 30 01       	BMI	WRFDGO		;BR IF WRITE DIR REQD
2980   2E75 60          	RTS			;DONE IF NOT
2981   2E76             ;
2982   2E76             WRFDGO
2983   2E76 20 87 2E    	JSR	MVFDBA
2984   2E79             ;
2985   2E79 A9 02       	LDA	#IBCWTS		;GET WRITE CMD
2986   2E7B 20 8E 2F    	JSR	DCBIO		;GO FILL IN IOB AND DO I/O
2987   2E7E             ;
2988   2E7E A9 7F       	LDA	#$7F		;TURN WRITE DIR REQD BIT OFF
2989   2E80 2D 09 35    	AND	DCBWRF
2990   2E83 8D 09 35    	STA	DCBWRF
2991   2E86 60          	RTS			;DONE
2992   2E87             ;
2993   2E87             ;	MVFDBA  MOVE FILE DIRECTORY BUFF ASDR TO IOD
2994   2E87             ;
2995   2E87             MVFDBA
2996   2E87 AD FD 34    	LDA	CFCBDR		;MOVE ADR
2997   2E8A 8D F0 37    	STA	IBBUFP
2998   2E8D AD FE 34    	LDA	CFCBDR+1
2999   2E90 8D F1 37    	STA	IBBUFP+1
3000   2E93 AE 07 35    	LDX	DCBCDT		;GET TRACK
3001   2E96 AC 08 35    	LDY	DCBCDS		;GET SECTOR
3002   2E99 60          	RTS

Page     69    APPLE DOS 3.1

3003   2E9A             	PAGE
3004   2E9A             ;
3005   2E9A             ;	RDFDIR  READ FILE DIRECTORY
3006   2E9A             ;
3007   2E9A             RDFDIR
3008   2E9A 08          	PHP			;SAVE STATUS
3009   2E9B 20 70 2E    	JSR	WRFDIR		;GO WRITE CURRENT DIR IF REQD
3010   2E9E 20 87 2E    	JSR	MVFDBA		;GO MOVE DBUFF ADR TO ZPG
3011   2EA1 20 3F 2E    	JSR	MVFCBD		;MOVE DBUFF ADR TO ZPG
3012   2EA4 28          	PLP			;GET SAVED STATUS
3013   2EA5 B0 09       	BCS	RFDNXT		;BR IF RD NEXT
3014   2EA7             ;
3015   2EA7 AE 05 35    	LDX	DCBFDT		;TRACK
3016   2EAA AC 06 35    	LDY	DCBFDS		;SECTOR
3017   2EAD 4C F1 2E    	JMP	RFDIO1		;GO READ
3018   2EB0             ;
3019   2EB0             RFDNXT
3020   2EB0 A0 01       	LDY	#FDLTRK		;GET LINK TRACK
3021   2EB2 B1 42       	LDA	(ZPGFCB),Y
3022   2EB4 F0 08       	BEQ	RFDNL		;NR NO LINK
3023   2EB6 AA          	TAX			;PUT TRACK INTO X
3024   2EB7 C8          	INY
3025   2EB8 B1 42       	LDA	(ZPGFCB),Y	;SET LINK SECTOR
3026   2EBA A8          	TAY			;PUT SECTOR INTO Y
3027   2EBB 4C F1 2E    	JMP	RFDIO1		;GO DO I/O
3028   2EBE             ;
3029   2EBE             RFDNL
3030   2EBE AD EF 34    	LDA	CCBREQ		;THIS A WRITE
3031   2EC1 C9 04       	CMP	#CRQWR
3032   2EC3 F0 02       	BEQ	RFDNL1		;BR IF WRITE
3033   2EC5 38          	SEC			;SET EOF
3034   2EC6 60          	RTS			;RETURN
3035   2EC7             ;
3036   2EC7             RFDNL1
3037   2EC7 20 80 31    	JSR	GETSEC		;GET A SECTOR
3038   2ECA A0 02       	LDY	#FDLSEC
3039   2ECC 91 42       	STA	(ZPGFCB),Y	;PUT IN LINK
3040   2ECE 48          	PHA			;SAVE SECTOR
3041   2ECF 88          	DEY
3042   2ED0 AD 25 35    	LDA	DCBATK		;GET TRACK
3043   2ED3 91 42       	STA	(ZPGFCB),Y	;PUT IN LINK
3044   2ED5 48          	PHA			;SAVE TRACK
3045   2ED6 20 76 2E    	JSR	WRFDGO		;GO WRITE OLD DIR DEC
3046   2ED9             ;
3047   2ED9 20 50 2E    	JSR	CLRSEC		;CLEAN OUT DIR
3048   2EDC A0 05       	LDY	#FDFRS		;SET NEW DIR SEC 1ST REL
3049   2EDE AD 12 35    	LDA	DCBDNF		;FILE SECTOR
3050   2EE1 91 42       	STA	(ZPGFCB),Y
3051   2EE3 C8          	INY
3052   2EE4 AD 13 35    	LDA	DCBDNF+1
3053   2EE7 91 42       	STA	(ZPGFCB),Y
3054   2EE9             ;
3055   2EE9 68          	PLA			;GET SAVED TRACK
3056   2EEA AA          	TAX			;INTO X
3057   2EEB 68          	PLA			;GET SAVED SECTOR
3058   2EEC A8          	TAY			;INTO Y
3059   2EED A9 02       	LDA	#IBCWTS		;SET WRITE CMD
3060   2EEF D0 02       	BNE	RFDIO2		;GO DO I/O
3061   2EF1             ;
3062   2EF1 A9 01       RFDIO1	LDA	#IBCRTS		;SET READ CMD
3063   2EF3 8E 07 35    RFDIO2	STX	DCBCDT		;SET CURR TRACK
3064   2EF6 8C 08 35    	STY	DCBCDS		;SET CURR SECTOR
3065   2EF9 20 8E 2F    	JSR	DCBIO		;GO I/O
3066   2EFC             ;
3067   2EFC A0 05       	LDY	#FDFRS		;GET POINTER TO FIRST RE SECTOR
3068   2EFE B1 42       	LDA	(ZPGFCB),Y	;GET FRS
3069   2F00 8D 10 35    	STA	DCBDFS		;SET INTO DCB
3070   2F03 18          	CLC
3071   2F04 6D 0E 35    	ADC	DCBDMS		;ADD MAX SECTORS
3072   2F07 8D 12 35    	STA	DCBDNF		;PUT INTO DCB
3073   2F0A             ;
3074   2F0A C8          	INY			;DO SAME FOR HI BYTE
3075   2F0B B1 42       	LDA	(ZPGFCB),Y
3076   2F0D 8D 11 35    	STA	DCBDFS+1
3077   2F10 6D 0F 35    	ADC	DCBDMS+1
3078   2F13 8D 13 35    	STA	DCBDNF+1
3079   2F16             ;
3080   2F16 18          	CLC
3081   2F17 60          	RTS			;DONE

Page     70    APPLE DOS 3.1

3082   2F18             	PAGE
3083   2F18             ;
3084   2F18             ;	RDSECT  READ A SECTOR
3085   2F18             ;
3086   2F18             RDSECT
3087   2F18 20 20 2F    	JSR	MVSBA		;GO MOVE SECTOR BUFFER ADR
3088   2F1B             ;
3089   2F1B A9 01       	LDA	#IBCRTS
3090   2F1D 4C 8E 2F    	JMP	DCBIO		;GO DO I/O
3091   2F20             ;
3092   2F20             ;	MVSBA  MOVE SECTOR BUFFER ADR FOR I/O
3093   2F20             ;
3094   2F20             MVSBA
3095   2F20 AC FF 34    	LDY	CFCBSB		;GET SECTOR BUFF ADR
3096   2F23 AD 00 35    	LDA	CFCBSB+1
3097   2F26 8C F0 37    	STY	IBBUFP		;SET IOB SECTOR
3098   2F29 8D F1 37    	STA	IBBUFP+1	;BUFF PTR
3099   2F2C AE 0A 35    	LDX	DCBTRK		;GET TRACK
3100   2F2F AC 0B 35    	LDY	DCBSEC		;GET SECTOR
3101   2F32 60          	RTS			;RTN

Page     71    APPLE DOS 3.1

3102   2F33             	PAGE
3103   2F33             ;
3104   2F33             ;	RDVTOC  READ VTOC
3105   2F33             ;	WRVTOC  WRITE VTOC
3106   2F33             ;
3107   2F33             RDVTOC
3108   2F33 A9 01       	LDA	#IBCRTS		;READ
3109   2F35 D0 02       	BNE	VTIO
3110   2F37             WRVTOC
3111   2F37 A9 02       	LDA	#IBCWTS		;WRITE
3112   2F39             ;
3113   2F39 AC 05 2A    VTIO	LDY	AVTOC		;MOVE BUFF ADR
3114   2F3C 8C F0 37    	STY	IBBUFP
3115   2F3F AC 06 2A    	LDY	AVTOC+1
3116   2F42 8C F1 37    	STY	IBBUFP+1
3117   2F45             ;
3118   2F45 AE 2E 35    	LDX	DCBVTN		;GET TRACK
3119   2F48 A0 00       	LDY	#0
3120   2F4A 4C 8E 2F    	JMP	DCBIO		;GO DO I/O

Page     72    APPLE DOS 3.1

3121   2F4D             	PAGE
3122   2F4D             ;
3123   2F4D             ;	RDVDIR  READ VOLUME DIRECTOR
3124   2F4D             ;
3125   2F4D             RDVDIR
3126   2F4D 08          	PHP			;SAVES STATUS
3127   2F4E 20 81 2F    	JSR	MVVDBA
3128   2F51             ;
3129   2F51 28          	PLP			;GET STATUS
3130   2F52 B0 08       	BCS	RVDA		;BR IF R0 NEXT
3131   2F54             ;
3132   2F54 AC F1 32    	LDY	VDIRSC		;GET LINK SECTOR
3133   2F57 AE F0 32    	LDX	VDIRTK		;GET FIRST TRK
3134   2F5A D0 0A       	BNE	RDVGO		;GO READ
3135   2F5C             ;
3136   2F5C             RVDA
3137   2F5C AE F0 33    	LDX	VDLTRK		;GET SECTOR
3138   2F5F D0 02       	BNE	RDVC		;BR IF A LINK
3139   2F61 38          	SEC			; SET END OF DIR
3140   2F62 60          	RTS
3141   2F63             ;
3142   2F63 AC F1 33    RDVC	LDY	VDLSEC		;GET SECTOR
3143   2F66             RDVGO
3144   2F66 8E CF 32    	STX	CVDTRK		;SET CUR TRACK
3145   2F69 8C D0 32    	STY	CVDSEC		;SET CUR SECTOR
3146   2F6C A9 01       	LDA	#IBCRTS		;GET CMD
3147   2F6E 20 8E 2F    	JSR	DCBIO		; GO DO I/O
3148   2F71 18          	CLC
3149   2F72 60          	RTS

Page     73    APPLE DOS 3.1

3150   2F73             	PAGE
3151   2F73             ;
3152   2F73             ;	WRVDIR  WRITE VOLUME DIRECTORY SECTOR
3153   2F73             ;
3154   2F73             WRVDIR
3155   2F73 20 81 2F    	JSR	MVVDBA
3156   2F76             ;
3157   2F76 AE CF 32    	LDX	CVDTRK		;CURRENT TRACK
3158   2F79 AC D0 32    	LDY	CVDSEC		;CURRENT SECTOR
3159   2F7C A9 02       	LDA	#IBCWTS		;WRITE COMMAND
3160   2F7E 4C 8E 2F    	JMP	DCBIO		;GO DO I/O
3161   2F81             ;
3162   2F81             ;	MVVDBA  MOVE VOL DIR BUF ADR TO IOB
3163   2F81             ;
3164   2F81             MVVDBA
3165   2F81 AD 07 2A    	LDA	AVOLDR		;MOVE ADR
3166   2F84 8D F0 37    	STA	IBBUFP
3167   2F87 AD 08 2A    	LDA	AVOLDR+1
3168   2F8A 8D F1 37    	STA	IBBUFP+1
3169   2F8D 60          	RTS

Page     74    APPLE DOS 3.1

3170   2F8E             	PAGE
3171   2F8E             ;
3172   2F8E             ;	DCBIO  DO I/O FOR A DCB
3173   2F8E             ;
3174   2F8E             DCBIO
3175   2F8E 8E EC 37    	STX	IBTRK		;TRACK
3176   2F91 8C ED 37    	STY	IBSECT		;SECTOR
3177   2F94             DCBIO2
3178   2F94 8D F4 37    	STA	IBCMD		;COMMAND
3179   2F97 C9 02       	CMP	#IBCWTS
3180   2F99 D0 06       	BNE	DCBIO1
3181   2F9B 0D 09 35    	ORA	DCBWRF
3182   2F9E 8D 09 35    	STA	DCBWRF
3183   2FA1             DCBIO1
3184   2FA1 AD 2D 35    	LDA	DCBVOL		;VOL
3185   2FA4 49 FF       	EOR	#$FF		;UNINVERT VOL BITS
3186   2FA6 8D EB 37    	STA	IBVOL
3187   2FA9 AD 2B 35    	LDA	DCBSLT		;SLOT
3188   2FAC 8D E9 37    	STA	IBSLOT
3189   2FAF AD 2C 35    	LDA	DCBDRV		;DRIVE
3190   2FB2 8D EA 37    	STA	IBDRVN
3191   2FB5 AD 16 35    	LDA	DCBSDL		;LENGTH
3192   2FB8 8D F2 37    	STA	IBDLEN
3193   2FBB AD 17 35    	LDA	DCBSDL+1
3194   2FBE 8D F3 37    	STA	IBDLEN+1
3195   2FC1 A9 01       	LDA	#1		;IOB TYPE
3196   2FC3 8D E8 37    	STA	IBTYPE
3197   2FC6             ;
3198   2FC6 AC 03 2A    	LDY	AIOB		;IOB ADR
3199   2FC9 AD 04 2A    	LDA	AIOB+1
3200   2FCC 20 00 3D    	JSR	DISKIO		;GO DO I/O
3201   2FCF             ;
3202   2FCF AD F6 37    	LDA	IBSMOD
3203   2FD2 8D F3 34    	STA	CCBVOL
3204   2FD5 A9 FF       	LDA	#$FF		;RESET VOL
3205   2FD7 8D EB 37    	STA	IBVOL
3206   2FDA B0 01       	BCS	BADIO		;BR IF BAD
3207   2FDC 60          	RTS			;RTN IF GOOD
3208   2FDD             ;
3209   2FDD AD F5 37    BADIO	LDA	IBSTAT		; GET STATUS
3210   2FE0 A0 07       	LDY	#CREVMM
3211   2FE2 C9 20       	CMP	#IBVMME		; WAS IT VOLUME MISMATCH
3212   2FE4 F0 08       	BEQ	BD2		; BR IF YES
3213   2FE6 A0 04       	LDY	#CREPRO
3214   2FE8 C9 10       	CMP	#IBWPER
3215   2FEA F0 02       	BEQ	BD2
3216   2FEC A0 08       	LDY	#CREIOE
3217   2FEE 98          BD2	TYA
3218   2FEF 4C C1 32    	JMP	ERRORB		;GO RTN

Page     75    APPLE DOS 3.1

3219   2FF2             	PAGE
3220   2FF2             ;
3221   2FF2             ;	LOCNXB  LOCATE NEXT BYTE
3222   2FF2             ;
3223   2FF2             LOCNXB
3224   2FF2 AD 18 35    	LDA	DCBCRS		;IS THE CURRENT RELATIVE SECTOR
3225   2FF5 CD 14 35    	CMP	DCBCMS		;EQUAL TO THE CURRENT MEM SECTOR
3226   2FF8 D0 08       	BNE	LNB1		;BR IF NOT EQ
3227   2FFA AD 19 35    	LDA	DCBCRS+1
3228   2FFD CD 15 35    	CMP	DCBCMS+1
3229   3000 F0 66       	BEQ	LNB8		;BR IF REQD SECTOR IN MEM
3230   3002             ;
3231   3002             LNB1				;NEED A DIFFERENT SECTOR IN MEM
3232   3002 20 59 2E    	JSR	WRSECT		;GO WRITE SECTOR(IF REQD)
3233   3005             ;
3234   3005 AD 19 35    LNB2	LDA	DCBCRS+1	;IS CURRENT REL SECTORY
3235   3008 CD 11 35    	CMP	DCBDFS+1	;IS CURRENT DIRECTORY (LOW LIMIT)
3236   300B 90 1C       	BCC	LNB4		;BR IF IN A PREVIOUS DIR
3237   300D D0 08       	BNE	LNB3		;BR IF MAYBE IN THIS ONE
3238   300F AD 18 35    	LDA	DCBCRS		;TEST LOW BYTES
3239   3012 CD 10 35    	CMP	DCBDFS
3240   3015 90 12       	BCC	LNB4		;BR IF IN PREVIOUS DIR
3241   3017             ;
3242   3017 AD 19 35    LNB3	LDA	DCBCRS+1	;IS CURRENT REL SECTOR
3243   301A CD 13 35    	CMP	DCBDNF+1	;IN CURRENT DIRECTOR (HI LIMIT)
3244   301D 90 10       	BCC	LNB6		;BR IF IN THIS ONE
3245   301F D0 08       	BNE	LNB4		;BR IF IN A NEXT DIR
3246   3021 AD 18 35    	LDA	DCBCRS
3247   3024 CD 12 35    	CMP	DCBDNF
3248   3027 90 06       	BCC	LNB6		;BR IF IN THIS ONE
3249   3029             ;				;REQD SECTOR IN A NEXT DIRECTORY
3250   3029 20 9A 2E    LNB4	JSR	RDFDIR		;GO READ NEXT FILE DIR
3251   302C 90 D7       	BCC	LNB2		;BR NXT AVAIL
3252   302E 60          	RTS			;RETURN IF EOF DIR
3253   302F             ;
3254   302F             ;
3255   302F             LNB6
3256   302F 38          	SEC			;CALCULATE DISPL INTO DIR
3257   3030 AD 18 35    	LDA	DCBCRS		;REQD REL SECTOR MINUS
3258   3033 ED 10 35    	SBC	DCBDFS
3259   3036 0A          	ASLA			;TIMES 2
3260   3037 69 0C       	ADC	#FDENT		;PLUS DISPL TO 1ST
3261   3039 A8          	TAY
3262   303A 20 3F 2E    	JSR	MVFCBD		;MOVE ADR TO ZPG
3263   303D B1 42       	LDA	(ZPGFCB),Y	;GET TRACK
3264   303F D0 0F       	BNE	LNB7		;BR IF NOT ZERO
3265   3041 AD EF 34    	LDA	CCBREQ
3266   3044 C9 04       	CMP	#CRQWR		;WRITE!
3267   3046 F0 02       	BEQ	LNB7A
3268   3048 38          	SEC
3269   3049 60          	RTS
3270   304A 20 70 30    LNB7A	JSR	GNWSEC		;GO GET A NEW SECTOR
3271   304D 4C 5C 30    	JMP	LNBCON
3272   3050 8D 0A 35    LNB7	STA	DCBTRK		;SET TRK INTO DCB
3273   3053 C8          	INY
3274   3054 B1 42       	LDA	(ZPGFCB),Y	;GET SECTOR
3275   3056 8D 0B 35    	STA	DCBSEC		;PUT INTO DCB
3276   3059 20 18 2F    	JSR	RDSECT		;GO READ SECTOR
3277   305C AD 18 35    LNBCON	LDA	DCBCRS		;MOVE CUR REL SECTOR
3278   305F 8D 14 35    	STA	DCBCMS
3279   3062 AD 19 35    	LDA	DCBCRS+1	;TO CUR MEM SECTOR
3280   3065 8D 15 35    	STA	DCBCMS+1
3281   3068             ;
3282   3068             LNB8
3283   3068 20 43 2E    	JSR	MVFCBS		;MOVE SECTOR BUFF ADR TO ZP
3284   306B AC 1A 35    	LDY	DCBCSB		;GET SECT BYTE
3285   306E 18          	CLC			;CARRY CLEAR = ALL OK
3286   306F 60          	RTS			;DONE

Page     76    APPLE DOS 3.1

3287   3070             	PAGE
3288   3070             ;
3289   3070             ;
3290   3070             GNWSEC				;NEED NEW SECTOR
3291   3070 8C D5 32    	STY	TEMP2		;SAVE DIR INDEX
3292   3073 20 80 31    	JSR	GETSEC		;GET A SECTOR
3293   3076 AC D5 32    	LDY	TEMP2
3294   3079 C8          	INY
3295   307A 91 42       	STA	(ZPGFCB),Y	;SET NEW TRACK
3296   307C 8D 0B 35    	STA	DCBSEC
3297   307F 88          	DEY
3298   3080 AD 25 35    	LDA	DCBATK
3299   3083 91 42       	STA	(ZPGFCB),Y	;SET NEW TRACK
3300   3085 8D 0A 35    	STA	DCBTRK
3301   3088             ;
3302   3088 20 43 2E    	JSR	MVFCBS
3303   308B 20 50 2E    	JSR	CLRSEC		;GO CLEAR SECTOR
3304   308E             ;
3305   308E             ;
3306   308E A9 C0       	LDA	#$C0		;INDICATE BOTH
3307   3090 0D 09 35    	ORA	DCBWRF		;DIR AND SECTOR
3308   3093 8D 09 35    	STA	DCBWRF		;MUST BE WRITTEN
3309   3096 60          	RTS			;DONE

Page     77    APPLE DOS 3.1

3310   3097             	PAGE			
3311   3097             ;
3312   3097             ;	INCRRB  INCREMENT RELATIVE RECORD BYTE
3313   3097             ;
3314   3097             INCRRB
3315   3097 AE 1E 35    	LDX	DCBCRR		;MOVE BYTE JUST READ OR WRITTEN
3316   309A 8E F1 34    	STX	CCBRRN
3317   309D AE 1F 35    	LDX	DCBCRR+1
3318   30A0 8E F2 34    	STX	CCBRRN+1
3319   30A3 AE 20 35    	LDX	DCBCRB		;X=REL BYTE (LOW)
3320   30A6 AC 21 35    	LDY	DCBCRB+1	;Y=REL BYTE HI
3321   30A9 8E F3 34    	STX	CCBBYT
3322   30AC 8C F4 34    	STY	CCBBYT+1
3323   30AF E8          	INX			;INC REL BYTE (LOW)
3324   30B0 D0 01       	BNE	INCR1		;BR IF NO CARRY
3325   30B2 C8          	INY			;INC REL BYTE (HI)
3326   30B3             ;
3327   30B3 CC 1D 35    INCR1	CPY	DCBRCL+1	;REL BYTE=REC LENGTH
3328   30B6 D0 11       	BNE	INCR2		;BR IF NOT
3329   30B8 EC 1C 35    	CPX	DCBRCL		;TEST LOW BYTES
3330   30BB D0 0C       	BNE	INCR2
3331   30BD A2 00       	LDX	#0
3332   30BF A0 00       	LDY	#0		;RESET REL BYTE TO ZERO
3333   30C1 EE 1E 35    	INC	DCBCRR		;AND INCR
3334   30C4 D0 03       	BNE	INCR2		;RELATIVE RECORD
3335   30C6 EE 1F 35    	INC	DCBCRR+1
3336   30C9             ;
3337   30C9 8E 20 35    INCR2	STX	DCBCRB		;SAVE NEW RELATIVE BYTE
3338   30CC 8C 21 35    	STY	DCBCRB+1
3339   30CF             ;
3340   30CF 60          	RTS

Page     78    APPLE DOS 3.1

3341   30D0             	PAGE
3342   30D0             ;
3343   30D0             ;	INCSCB  INCREMENT SECTOR BYTE
3344   30D0             ;
3345   30D0             INCSCB
3346   30D0 EE 1A 35    	INC	DCBCSB		;INC SECTOR BYTE
3347   30D3 D0 08       	BNE	INCS2		;BR IF NOT FULL
3348   30D5 EE 18 35    	INC	DCBCRS		;AND INCR
3349   30D8 D0 03       	BNE	INCS2		;RELATIVE SECTOR
3350   30DA EE 19 35    	INC	DCBCRS+1
3351   30DD             ;
3352   30DD             ;
3353   30DD             INCS2
3354   30DD 60          	RTS			;DONE

Page     79    APPLE DOS 3.1

3355   30DE             	PAGE
3356   30DE             ;
3357   30DE             ;	MIBDA  MOVE AND INCREMENT CCBDAT
3358   30DE             ;
3359   30DE             MIBDA
3360   30DE AC F7 34    	LDY	CCBBBA		;Y=ADR LOW
3361   30E1 AE F8 34    	LDX	CCBBBA+1	;X=ADR HI
3362   30E4 84 42       	STY	ZPGFCB		;PUT ADR INTO ZPG
3363   30E6 86 43       	STX	ZPGFCB+1
3364   30E8             ;
3365   30E8 EE F7 34    	INC	CCBBBA		;INC ADR LOW
3366   30EB D0 03       	BNE	MIB1		;BR IF NOT ZERO
3367   30ED EE F8 34    	INC	CCBBBA+1	;INC ADR HI
3368   30F0 60          MIB1	RTS			;DONE
3369   30F1             ;
3370   30F1             ;	DTBLN  DECREMENT BLOCK LENGTH AND TEST ZERO
3371   30F1             ;
3372   30F1             DTBLN
3373   30F1 AC F5 34    	LDY	CCBBLN		;GET LEN LOW
3374   30F4 D0 08       	BNE	DTB1		;BR IF NOT ZERO
3375   30F6 AE F6 34    	LDX	CCBBLN+1	;GET LEN HI
3376   30F9 F0 07       	BEQ	DTB2		;BR IF LEN=0
3377   30FB CE F6 34    	DEC	CCBBLN+1	;DEC LEN (HIGH)
3378   30FE CE F5 34    DTB1	DEC	CCBBLN		;DEC LEN (LOW)
3379   3101 60          	RTS			;DONE
3380   3102             ;
3381   3102 4C BB 32    DTB2	JMP	GOODIO		;FINISHED BLOCK

Page     80    APPLE DOS 3.1

3382   3105             	PAGE
3383   3105             ;
3384   3105             ;	FNDFIL  FIND FILE NAME IN VOLUME DIR
3385   3105             ;
3386   3105             FNDFIL
3387   3105 20 33 2F    	JSR	RDVTOC		;GO GET VTOC
3388   3108 AD F7 34    	LDA	CCBFN1		;MOVE FN PTR
3389   310B 85 42       	STA	ZPGFCB		;TO ZERO PAGE
3390   310D AD F8 34    	LDA	CCBFN1+1
3391   3110 85 43       	STA	ZPGFCB+1
3392   3112 A9 01       	LDA	#1
3393   3114 8D D5 32    FF1	STA	TEMP2
3394   3117 A9 00       	LDA	#0
3395   3119 8D 0C 35    	STA	DCBVDR
3396   311C 18          	CLC
3397   311D             FF2
3398   311D EE 0C 35    	INC	DCBVDR
3399   3120 20 4D 2F    	JSR	RDVDIR		;GO GET VDIR SECTOR
3400   3123 B0 51       	BCS	FF4A
3401   3125 A2 00       	LDX	#0		;SET FOR 1ST FILE
3402   3127             ;
3403   3127 8E D4 32    FF3	STX	TEMP1		;SAVE INDEX
3404   312A BD FA 33    	LDA	VDFILE,X	;GET FILE TRK
3405   312D F0 1F       	BEQ	FF6		;BR IF LAST ENTRY
3406   312F 30 22       	BMI	FF7		;BR DELETED ENTRY
3407   3131 A0 00       	LDY	#0		;X=X+3
3408   3133 E8          	INX
3409   3134 E8          	INX
3410   3135 E8          FF4	INX
3411   3136 B1 42       	LDA	(ZPGFCB),Y	;GET FN CHAR
3412   3138 DD FA 33    	CMP	VDFILE,X	;COMPARE TO ENTRY CHAR
3413   313B D0 0A       	BNE	FF5		;BR IF NOT SAME
3414   313D C8          	INY
3415   313E C0 1E       	CPY	#30		; ALL 30 CHARS
3416   3140 D0 F3       	BNE	FF4		;BR IF NOT
3417   3142 AE D4 32    	LDX	TEMP1		;GET INDEX
3418   3145 18          	CLC			;FILE FOUND
3419   3146 60          	RTS			;RETURN
3420   3147             ;
3421   3147             FF5
3422   3147 20 6C 31    	JSR	VDINC
3423   314A 90 DB       	BCC	FF3
3424   314C B0 CF       	BCS	FF2
3425   314E             ;
3426   314E AC D5 32    FF6	LDY	TEMP2		;LOOKING FOR DELETED
3427   3151 D0 C1       	BNE	FF1		;BR IF NOT (DO)
3428   3153             ;
3429   3153 AC D5 32    FF7	LDY	TEMP2		;LOOKING FOR EMPTY
3430   3156 D0 EF       	BNE	FF5		;BR IF NOT
3431   3158             ;
3432   3158             MVFN
3433   3158 A0 00       	LDY	#0		;HAVE NEW ENTTRY
3434   315A E8          	INX
3435   315B E8          	INX
3436   315C E8          FF8	INX
3437   315D B1 42       	LDA	(ZPGFCB),Y	;MOVE FILE NAME
3438   315F 9D FA 33    	STA	VDFILE,X
3439   3162 C8          	INY
3440   3163 C0 1E       	CPY	#30
3441   3165 D0 F5       	BNE	FF8
3442   3167             ;
3443   3167 AE D4 32    	LDX	TEMP1		;GET INDEX
3444   316A 38          	SEC			;SET NOT OLD
3445   316B 60          	RTS			;DONE
3446   316C             VDINC
3447   316C 18          	CLC
3448   316D AD D4 32    	LDA	TEMP1
3449   3170 69 23       	ADC	#35
3450   3172 AA          	TAX
3451   3173 E0 F5       	CPX	#VDFLEN
3452   3175 60          	RTS
3453   3176             FF4A
3454   3176 A9 00       	LDA	#0
3455   3178 AC D5 32    	LDY	TEMP2
3456   317B D0 97       	BNE	FF1
3457   317D 4C B3 32    	JMP	ERROR9

Page     81    APPLE DOS 3.1

3458   3180             	PAGE
3459   3180             ;
3460   3180             ;	GETSEC  GET A SECTOR
3461   3180             ;
3462   3180             GETSEC
3463   3180 AD 25 35    	LDA	DCBATK		;GET ALLOCATED TRK
3464   3183 F0 21       	BEQ	GSS1		;BR IF NONE
3465   3185             ;
3466   3185             GS0
3467   3185 CE 24 35    	DEC	DCBALS		;DECREMENT SECTOR NO
3468   3188 30 17       	BMI	CS2		;BR IF NO SECTORS REM
3469   318A             ;
3470   318A 18          	CLC
3471   318B A2 04       	LDX	#4		;4 BYTE SHIFT
3472   318D 3E 25 35    GS1	ROL	DCBABM-1,X	;SHIFT BYTE LEFT
3473   3190 CA          	DEX
3474   3191 D0 FA       	BNE	GS1
3475   3193 90 F0       	BCC	GS0		;BR IF NO SECTOR
3476   3195             ;
3477   3195 EE 22 35    	INC	DCBNSA
3478   3198 D0 03       	BNE	GS1A
3479   319A EE 23 35    	INC	DCBNSA+1
3480   319D             GS1A
3481   319D AD 24 35    	LDA	DCBALS		;GET ALLOCATED SECTOR
3482   31A0 60          	RTS			;RETURN
3483   31A1             ;
3484   31A1 A9 00       CS2	LDA	#0		;CLEAR ALLOCATED
3485   31A3 8D 25 35    	STA	DCBATK		;TRK
3486   31A6             ;
3487   31A6 A9 00       GSS1	LDA	#0		;SET SEARCH STATE=0
3488   31A8 8D D6 32    	STA	TEMP3
3489   31AB 20 33 2F    	JSR	RDVTOC		;GET VTOC
3490   31AE             ;
3491   31AE             GS2
3492   31AE 18          	CLC
3493   31AF AD 1F 33    	LDA	VALCA1		;GET LAST ALLOCATED TRK
3494   31B2 6D 20 33    	ADC	VALCA2		;AD (+1) OR (-1)
3495   31B5 F0 09       	BEQ	GS3		;BR IF DECK TO ZERO
3496   31B7 CD 23 33    	CMP	VNOTRK
3497   31BA 90 14       	BCC	GS5		;BR IF NOT AT OUTER LIMIT
3498   31BC A9 FF       	LDA	#$FF		;SET (-1)
3499   31BE D0 0A       	BNE	GS4
3500   31C0 AD D6 32    GS3	LDA	TEMP3		;GET SEARCH STATE
3501   31C3 D0 37       	BNE	ERR9		;BR IF NOT ZERO
3502   31C5 A9 01       	LDA	#1		;SET (+1)
3503   31C7 8D D6 32    	STA	TEMP3		;SET SEARCH STATE = 1
3504   31CA 8D 20 33    GS4	STA	VALCA2		;SET NEW (+1) OR (-1)
3505   31CD 18          	CLC
3506   31CE 69 11       	ADC	#17		; ADD VTOC TRK NO
3507   31D0 8D 1F 33    GS5	STA	VALCA1		;SET NEW LAST ALLOCATED
3508   31D3 8D 25 35    	STA	DCBATK		;PUT IN DCB
3509   31D6             ;
3510   31D6 A8          	TAY			;ALLOCATED TRACK
3511   31D7 0A          	ASLA			;TIME 4
3512   31D8 0A          	ASLA
3513   31D9 A8          	TAY
3514   31DA A2 04       	LDX	#4
3515   31DC 18          	CLC
3516   31DD B9 2A 33    GS6	LDA	VSECAL+3,Y	;MOVE BIT MAP BYTE
3517   31E0 9D 25 35    	STA	DCBABM-1,X
3518   31E3 F0 06       	BEQ	GS7		;BR IF NO BITS ON
3519   31E5 38          	SEC			;SET HAVE A SECTOR
3520   31E6 A9 00       	LDA	#0		;CLEAR VTOC BYTE
3521   31E8 99 2A 33    	STA	VSECAL+3,Y
3522   31EB 88          GS7	DEY
3523   31EC CA          	DEX
3524   31ED D0 EE       	BNE	GS6		;BR IF MORE TO MOVE
3525   31EF 90 BD       	BCC	GS2
3526   31F1 20 37 2F    	JSR	WRVTOC		;GO WRITE VTOC
3527   31F4 AD 24 33    	LDA	VNOSEC		;GET NO SECTORS
3528   31F7 8D 24 35    	STA	DCBALS		;SET IN DCB SECTOR BYTE
3529   31FA D0 89       	BNE	GS0		;GO ALLOCATED SECTOR
3530   31FC 4C B3 32    ERR9	JMP	ERROR9

Page     82    APPLE DOS 3.1

3531   31FF             	PAGE
3532   31FF             ;
3533   31FF             ;	FRETRK  FREE TRACK OF SECTORS
3534   31FF             ;
3535   31FF             FRETRK
3536   31FF AD 25 35    	LDA	DCBATK		;GET ALLOCATED TRACK
3537   3202 D0 01       	BNE	FT1		;BR IF NONE
3538   3204 60          	RTS			;DONE
3539   3205 48          FT1	PHA
3540   3206 20 33 2F    	JSR	RDVTOC		;GET VTOC
3541   3209 AC 24 35    	LDY	DCBALS		;GET SECTORS
3542   320C 68          	PLA			;GET TRACK
3543   320D 18          	CLC			;SET FREE
3544   320E 20 19 32    	JSR	FRESEC		;GO FREE
3545   3211 A9 00       	LDA	#0		;CLEAR ALLOCATED TRK
3546   3213 8D 25 35    	STA	DCBATK
3547   3216 4C 37 2F    	JMP	WRVTOC		;WRITE VTOC
3548   3219             ;
3549   3219             ;	FRESEC  FREE A SECTOR
3550   3219             ;		A=TRK, Y=SECTOR, C=ON/OFF
3551   3219             ;
3552   3219             FRESEC
3553   3219 A2 FC       FS1	LDX	#252		;4 BYTE SHIFT
3554   321B 7E 2A 34    FS2	ROR	DCBABM-252,X	;SHIFT IN CARRY
3555   321E E8          	INX			;NEXT BYTE
3556   321F D0 FA       	BNE	FS2		;BR IF NOT DONE
3557   3221 C8          	INY			;INC SECTOR NO
3558   3222 CC 24 33    	CPY	VNOSEC		;NORMAL
3559   3225 D0 F2       	BNE	FS1		;BR IF NOT
3560   3227             ;
3561   3227 0A          	ASLA			;TRACK*4
3562   3228 0A          	ASLA
3563   3229 A8          	TAY
3564   322A F0 0F       	BEQ	FS4
3565   322C A2 04       	LDX	#4
3566   322E BD 25 35    FS3	LDA	DCBABM-1,X	;GET BIT MAP BYTE
3567   3231 19 2A 33    	ORA	VSECAL+3,Y	;GET BIT MAP BYTE
3568   3234 99 2A 33    	STA	VSECAL+3,Y	;OR WITH VTOC BM
3569   3237 88          	DEY
3570   3238 CA          	DEX
3571   3239 D0 F3       	BNE	FS3
3572   323B 60          FS4	RTS			;DONE

Page     83    APPLE DOS 3.1

3573   323C             	PAGE
3574   323C             ;
3575   323C             ;	LOCSEC  LOCATE SECTOR FOR RECORD I/O
3576   323C             ;
3577   323C             ;	RELSEC = (REL REC * RECLEN + RELBYTE)/256
3578   323C             ;	SECBYT = REMAINDER
3579   323C             ;
3580   323C             LOCSEC
3581   323C AD F1 34    	LDA	CCBRRN		;RELATIVE RECORD NUMBER
3582   323F 8D 1A 35    	STA	DCBCSB		;TO CSB FOR MULT
3583   3242 8D 1E 35    	STA	DCBCRR		;AND CRR FOR SAVE
3584   3245 AD F2 34    	LDA	CCBRRN+1
3585   3248 8D 18 35    	STA	DCBCRS
3586   324B 8D 1F 35    	STA	DCBCRR+1
3587   324E A9 00       	LDA	#0
3588   3250 8D 19 35    	STA	DCBCRS+1	;HIGH CRS=0
3589   3253 A0 10       	LDY	#16		;16 BIT MULT
3590   3255             ;
3591   3255 AA          LS1	TAX			;SAVE MS BYTE
3592   3256 AD 1A 35    	LDA	DCBCSB
3593   3259 4A          	LSRA			;IF NO CARRY THEN NO PART PROD
3594   325A B0 03       	BCS	LS1A
3595   325C 8A          	TXA
3596   325D 90 0E       	BCC	LS2
3597   325F 18          LS1A	CLC
3598   3260 AD 19 35    	LDA	DCBCRS+1	;FPORM PARTIAL PROD
3599   3263 6D 1C 35    	ADC	DCBRCL
3600   3266 8D 19 35    	STA	DCBCRS+1
3601   3269 8A          	TXA
3602   326A 6D 1D 35    	ADC	DCBRCL+1
3603   326D             ;
3604   326D 6A          LS2	RORA			;MULT BY 2
3605   326E 6E 19 35    	ROR	DCBCRS+1
3606   3271 6E 18 35    	ROR	DCBCRS
3607   3274 6E 1A 35    	ROR	DCBCSB
3608   3277 88          	DEY			;DEC BIT COUNT
3609   3278 D0 DB       	BNE	LS1		;BR IF MORE BITS
3610   327A             ;
3611   327A AD F3 34    	LDA	CCBBYT		;ADD REL BYTE RESULT
3612   327D 8D 20 35    	STA	DCBCRB		;(SAVE REL BYTE)
3613   3280 6D 1A 35    	ADC	DCBCSB
3614   3283 8D 1A 35    	STA	DCBCSB
3615   3286 AD F4 34    	LDA	CCBBYT+1
3616   3289 8D 21 35    	STA	DCBCRB+1	;(SAVE REL BYTE)
3617   328C 6D 18 35    	ADC	DCBCRS
3618   328F 8D 18 35    	STA	DCBCRS
3619   3292 A9 00       	LDA	#0
3620   3294 6D 19 35    	ADC	DCBCRS+1
3621   3297 8D 19 35    	STA	DCBCRS+1
3622   329A 60          	RTS

Page     84    APPLE DOS 3.1

3623   329B             	PAGE
3624   329B A9 01       ERROR1	LDA	#CREFUN
3625   329D D0 22       	BNE	ERRORA
3626   329F A9 02       ERROR2	LDA	#CRERR
3627   32A1 D0 1E       	BNE	ERRORA
3628   32A3 A9 03       ERROR3	LDA	#CREMRE
3629   32A5 D0 1A       	BNE	ERRORA
3630   32A7 A9 04       ERROR4	LDA	#CREPRO
3631   32A9 D0 16       	BNE	ERRORA
3632   32AB A9 05       ERROR5	LDA	#CREEOF
3633   32AD D0 12       	BNE	ERRORA
3634   32AF A9 06       ERROR6	LDA	#CREFNF
3635   32B1 D0 0E       	BNE	ERRORA
3636   32B3 A9 09       ERROR9	LDA	#CRENSA
3637   32B5 D0 0A       	BNE	ERRORA
3638   32B7 A9 0A       ERRR10	LDA	#CREFLK
3639   32B9 D0 06       	BNE	ERRORA
3640   32BB AD F9 34    GOODIO	LDA	CCBSTA
3641   32BE 18          	CLC			;CARRY=CLR
3642   32BF 90 01       	BCC	RETURN		;GO RETURN
3643   32C1             ERRORA
3644   32C1 38          ERRORB	SEC			;CARRY=SET
3645   32C2             RETURN
3646   32C2 08          	PHP
3647   32C3 8D F9 34    	STA	CCBSTA		;SET STA
3648   32C6 20 9D 2D    	JSR	RTNFCB		;GO RTN FCB
3649   32C9 28          	PLP			;GET STATUS
3650   32CA AE D3 32    	LDX	ENTSTK		;GET ENT STACK
3651   32CD 9A          	TXS			;RESTORE STACK
3652   32CE 60          	RTS			;DONE
3653   32CF             EC2

Page     85    APPLE DOS 3.1

3654   32CF             	PAGE
3655   32CF             ;
3656   32CF             ; 	MISC DOS WORK CELLS
3657   32CF             ;
3658   32CF 11          CVDTRK	DB	$11		;CUR VOL DIR TRK
3659   32D0 0B          CVDSEC	DB	$0B		;CUR VOL DIR SECTOR
3660   32D1 00 00       CURCCB	DB	0,0		;CURRENT CCB ADR
3661   32D3 F5          ENTSTK	DB	$F5		;ENTRY STACK POINTER
3662   32D4 00          TEMP1	DB	0		;TEMP BYTE 1
3663   32D5 0C          TEMP2	DB	$0C		;TEMP BYTE 2
3664   32D6 00          TEMP3	DB	0		;TEMP BYTE 3
3665   32D7 00          ENTSLT	DB	0		;BOOT SLOT SAVED
3666   32D8 00 00 F8 FF ALC10S	DB	0,0,$F8,$FF	;ALLOCATATION TRACK BIT MAP
3667   32DC 01 0A 64    CVTAB	DB	1,10,100	; CONVERSION TABLE
3668   32DF D4 C2 C1 C9 FTTAB	DB11	"TBAI"		; FILE TYPE CONVERSION TABLE
3669   32E3 A0 C5 CD D5 VOLMES	DB11	" EMULOV KSID"
3669   32E7 CC CF D6 A0 
3669   32EB CB D3 C9 C4 
3670   32EF             VML	EQU	*-VOLMES-1

Page     86    APPLE DOS 3.1

3671   32EF             	PAGE
3672   32EF             ;
3673   32EF             ; 	VTOC RECORD AREA
3674   32EF             ;
3675   32EF             VTOC
3676   32EF 01          VDOST	DB	1		; DOS TYPE
3677   32F0 11          VDIRTK	DB	17		;COLUME DIRECTORY SECTOR
3678   32F1 0C          VDIRSC	DB	12		;VOLUME DIRECTORY SECTOR
3679   32F2 01          VDOSRN	DB	1		; DOS RELEASE NUMBER
3680   32F3 01          	DB	1		; SPARE
3681   32F4 01          	DB	1		; SPARE
3682   32F5 10          VVOLNO	DB	16		;VOLUME NUMBER
3683   32F6             	RMB	32		; SPARE
3684   3316 7A          VTDMS	DB	122		;MAX SECTORS IN A FILE DIR
3685   3317             VSPARE	RMB	8		;SPARES
3686   331F             ;
3687   331F 1E          VALCA1	DB	30		;ALOCATION ALGORITHM BYTE 1
3688   3320 01          VALCA2	DB	1		;AA BYTE 2
3689   3321 00          VALCA3	DB	0		;AA BYTE 3
3690   3322 00          VALCA4	DB	0		;AA BYTE 4
3691   3323 23          VNOTRK	DB	35		;NO TRACKS ON VOL
3692   3324 0D          VNOSEC	DB	13		; NO SECTORS PER TRACK
3693   3325 00 01       VSECLN	DW	256		;NO BYTES PER SECTOR
3694   3327             ;
3695   3327             VSECAL	EQU	*		;SECTOR ALLOCATION AREA
3696   3327             ;				SECTORS ALLOCATED BY BIT MAP
3697   3327             ;				4 BYTES OF BITS PER TRACK
3698   3327             ;				LEFT MOST BIT REPRESENTS SECTOR N
3699   3327             ;				WHERE N=NO SECTORS PER TRACK
3700   3327             ;
3701   3327             ;

Page     87    APPLE DOS 3.1

3702   3327             	PAGE
3703   33EF             	ORG	VTOC+256
3704   33EF             ;
3705   33EF             ; 	VOLUME DIRECTORY AREA
3706   33EF             ;
3707   33EF             VOLDIR
3708   33EF 00          VDTCDE	DB	0		; VOLUME DIRECTORY TYPECODE
3709   33F0             VDLTRK	RMB	1		;VD LINK TRACK
3710   33F1             VDLSEC	RMB	1		;VD LINK SECTOR
3711   33F2             VDNF	RMB	1		;VD NUMBER FILES THIS SECTOR
3712   33F3             VDSPAR	RMB	7		;SPARES
3713   33FA             ;
3714   33FA             VDFILE	EQU	*		;FILE ALLOCATION AREA (7 FILES)
3715   33FA             ;				EACH FILE
3716   33FA             ;					FILE DIR TRK
3717   33FA             ;					FILE DIR SECTOR
3718   33FA             ;					FILE USE CODE
3719   33FA             ;				 FILE NAME (30)
3720   33FA             ;				FILE SECTOR COUNT (2)
3721   34EF             	ORG	VOLDIR+256
3722   34EF             VDEND	EQU	*
3723   34EF             VDLEN	EQU	*-VOLDIR
3724   34EF             VDFLEN	EQU	*-VDFILE
3725   34EF             ;

Page     88    APPLE DOS 3.1

3726   34EF             	PAGE
3727   34EF             ;
3728   34EF             ;	COMMAND CONTROL BLOCK (CCB)
3729   34EF             ;
3730   34EF             CCB
3731   34EF             CCBREQ	RMB	1		;USER REQUEST BYTE
3732   34F0             CRQNUL	EQU	0		;0-NO REQUEST
3733   34F0             CRQOPN	EQU	1		;1-OPEN FILE
3734   34F0             CRQCLS	EQU	2		;2-CLOSE FILE
3735   34F0             CRQRD	EQU	3		;3-READ DATA
3736   34F0             CRQWR	EQU	4		;WRITE DATA
3737   34F0             CRQDEL	EQU	5		;5-DELETE FILE
3738   34F0             CRQDIR	EQU	6		;6-READ DIRECTORY
3739   34F0             CRQLCK	EQU	7		;7-LOCK FILE
3740   34F0             CRQUNL	EQU	8		;8-UNLOCK FILE
3741   34F0             CRQRNM	EQU	9		;9-RENAME
3742   34F0             CRQPOS	EQU	10		;10-POSITION FILE
3743   34F0             CRQFMT	EQU	11		;11-FORMAT
3744   34F0             CRQVAR	EQU	12		; 12-VERIFY
3745   34F0             CRQMAX	EQU	13
3746   34F0             ;
3747   34F0             CCBBSA				; FORMAT  BOOT START ADR PAGE
3748   34F0             CCBRQM	RMB	1		;REQUEST MODIFIER BYTE
3749   34F1             CRMNUL	EQU	0		;NO MODIFIER
3750   34F1             CRMNBT	EQU	1		;R/W  1  NEXT BYTE
3751   34F1             CRMNBL	EQU	2		;R/W  2  NEXT BLOCK
3752   34F1             CRMSBT	EQU	3		;R/W  3  SPECIFC BYTE
3753   34F1             CRMSBL	EQU	4		;R/W  4  SPECIFIC BLOCK
3754   34F1             CRMMAX	EQU	5
3755   34F1             ;
3756   34F1             CCBRRN				;I/O  RELATIVE RECORD NUMBER
3757   34F1             CCBFN2				;RENAME  FILE NAME 2 PTR
3758   34F1             CCBRLN	RMB	2		;OPEN  RECORD LENGTH
3759   34F3             ;
3760   34F3             CCBBYT				;I/O  RELATIVE RECORD NO(2 BYTES)
3761   34F3             CCBVOL	RMB	1		;OPEN  VOL NO.
3762   34F4             CCBDRV	RMB	1		;OPEN  DRIVE
3763   34F5             ;
3764   34F5             CCBBLN				;I/O  BLOCK LENGTH (2 BYTES)
3765   34F5             CCBSLT	RMB	1		;OPEN  SLOT NO.
3766   34F6             CCBFUC	RMB	1		;OPEN - FILE USE CODE
3767   34F7             ;
3768   34F7             CCBFN1				;OPEN, DELETE, LOCK, UNLOCK, RENAME  FILENAME P
3769   34F7             CCBBBA				;BLCOKK I/O  BLOCK BUFFER PTR
3770   34F7             CCBDAT	RMB	2		;BYTE I/O  DTA BYTE
3771   34F9             ;
3772   34F9             CCBSTA	RMB	1		;RESULT STATUS
3773   34FA             CREFUN	EQU	1		;FCB UNALLOCATED
3774   34FA             CRERR	EQU	2		;CCB REQ RANGE ERR
3775   34FA             CREMRE	EQU	3		;REQ MOD RANGE ERR
3776   34FA             CREPRO	EQU	4		; WRITE PROTECT
3777   34FA             CREEOF	EQU	5		;END OF FILE ON READ
3778   34FA             CREFNF	EQU	6		;FILE NOT FOUND
3779   34FA             CREVMM	EQU	7		;VOL MIS MATCH
3780   34FA             CREIOE	EQU	8		;I/O ERR
3781   34FA             CRENSA	EQU	9		;NO SECTORS AVAILABLE
3782   34FA             CREFLK	EQU	10		;FILE LOCKED
3783   34FA             ;
3784   34FA             CCBSM	RMB	1		;STATUS MODIFIER
3785   34FB             CCBFCB	RMB	2		;FCB PTR
3786   34FD             CCBDBP	RMB	2		;DIR BUF PTR
3787   34FF             CCBSBP	RMB	2		;SECTOR BUF PTR
3788   3501             CCBSPR	RMB	4		;SPARE
3789   3505             CCBLEN	EQU	*-CCB		;CCB LENGTH
3790   3505             CFCBAD	EQU	CCBFCB
3791   3505             CFCBDR	EQU	CCBDBP
3792   3505             CFCBSB	EQU	CCBSBP

Page     89    APPLE DOS 3.1

3793   3505             	PAGE
3794   3505             ;
3795   3505             ;	FILE CONTROL BLOCK (FCB) DEFINITION
3796   3505             ;		DCB  FILE DATA CONTROL BLOCK
3797   3505             ;
3798   3505             FCBB
3799   3505             ;
3800   3505             ;	DATA CONTROL BLOCK
3801   3505             ;
3802   3505             FCBDCB
3803   3505             DCBFDT	RMB	1		;1ST FILE DIRECTORY TRACK
3804   3506             DCBFDS	RMB	1		;1ST FILE DIRECTORY SECTOR
3805   3507             DCBCDT	RMB	1		;CURRENT FILE DIRECTORY
3806   3508             DCBCDS	RMB	1		;CURRENT FILE DIRECTORY
3807   3509             DCBWRF	RMB	1		;WRITE REQD FLAG
3808   350A             ;				;$80=WRITE FILE DIR
3809   350A             ;				;$40=WRITE SECTOR DIR
3810   350A             DCBTRK	RMB	1		;SECTOR TRACK ADR
3811   350B             DCBSEC	RMB	1		;SECTOR ADR
3812   350C             DCBVDR	RMB	1		; VOL DIR REC
3813   350D             DCBVDI	RMB	1		; VOL DIR INDEX
3814   350E             DCBDMS	RMB	2		;MAX NO DIRECTORY SECTORS
3815   3510             DCBDFS	RMB	2		;CURRENT DIR 1ST REL SECTRO
3816   3512             DCBDNF	RMB	2		;REL SECTOR OF NXT DIR
3817   3514             DCBCMS	RMB	2		;SECTOR CURRENTLY IN MEMORY
3818   3516             DCBSDL	RMB	2		;SECTOR DATA LENGTH
3819   3518             DCBCRS	RMB	2		;CURRENT RELATIVE SECTOR
3820   351A             DCBCSB	RMB	2		;REL SECTOR OF NXT DIR
3821   351C             DCBRCL	RMB	2		;SECTOR CURRENTLY IN MEMORY
3822   351E             DCBCRR	RMB	2		;SECTOR DATA LENGTH
3823   3520             DCBCRB	RMB	2		;CURRENT RELATIVE SECTOR
3824   3522             DCBNSA	RMB	2		; NO SECTORS ALLOCATED
3825   3524             ;
3826   3524             DCBALS	RMB	1		;ALLOCATION SECTOR BYTE
3827   3525             DCBATK	RMB	1		;ALLOCATION TRACK
3828   3526             DCBABM	RMB	4		;ALLOCATION TRACK SECTOR BIT MAP
3829   352A             ;
3830   352A             DCBFUC	RMB	1		;FILE USE CODE
3831   352B             DCBSLT	RMB	1		;SLOT NUMBER
3832   352C             DCBDRV	RMB	1		;DRIVE NUMBER
3833   352D             DCBVOL	RMB	1		;VOLUME DRIVER
3834   352E             DCBVTN	RMB	1		;VTOC TRACK NUMBER
3835   352F             ;
3836   352F             DCBSPR	RMB	3		;SPARES
3837   3532             ;
3838   3532             DCBLEN	EQU	*-FCBDCB	;DCB LENGTH
3839   3532             FCBLEN	EQU	*-FCBB		;FCB LENGTH

Page     90    APPLE DOS 3.1

3840   3532             	PAGE
3841   3532             ;
3842   3532             ;	DOS	PATCH AREA 1
3843   3532             SDP1
3844   3532             EDP1	EQU	ORG2-2
3845   3532 00 00 00 00 	DB	0,0,0,0,0,0,0
3845   3536 00 00 00 
3846   3539 00 00 00 00 	DB	0,0,0,0,0,0,0	
3846   353D 00 00 00 
3847   3540             DR2PAT				;*** PATCH *** (DOSREL - FIND END OF DOS)
3848   3540 A5 41       	LDA	ZPGWRK+1	;GET TOP OF RAM PAGE FOUND
3849   3542 29 DF       	AND	#$DF		;SAVE 8K LESS THAN TOP OF RAM IF 16K, 32K, OR 48K SYS
3850   3544 85 43       	STA	ZPGFCB+1	;LEAVE AS IS IF 20K, 24K, OR 36K SYSTEM
3851   3546 86 42       	STX	ZPGFCB		;ZERO LO
3852   3548 A1 42       	LDA	(ZPGFCB,X)	;GET BYTE FROM (POSSIBLY NEW) TOP OF RAM
3853   354A 48          	PHA			;SAVE IT TO STACK
3854   354B 85 26       	STA	LOC1		;TEST FOR RAM AGAIN
3855   354D             DR2P1
3856   354D 98          	TYA			;FIRST PASS=0
3857   354E 45 26       	EOR	LOC1
3858   3550 85 26       	STA	LOC1
3859   3552 98          	TYA
3860   3553 41 40       	EOR	(ZPGWRK,X)
3861   3555 81 42       	STA	(ZPGFCB,X)
3862   3557 C5 26       	CMP	LOC1
3863   3559 D0 07       	BNE	DR2P3		;BR IF NOT RAM
3864   355B C8          	INY			;NEXT VERIFY PASS
3865   355C D0 EF       	BNE	DR2P1
3866   355E A4 43       	LDY	ZPGFCB+1	;GET TOP OF RAM PAGE IF TOOK
3867   3560 68          	PLA			;RESTORE LAST BYTE READ FROM RAM
3868   3561 60          	RTS			;RTN WITH (POSSIBLY NEW) TOP OF RAM PAGE
3869   3562             ;
3870   3562             DR2P3
3871   3562 68          	PLA			;RESTORE LAST BYTE READ FROM RAM
3872   3563 81 42       	STA	(ZPGFCB,X)	;PUT IT BACK IN RAM
3873   3565 A4 41       	LDY	ZPGWRK+1	;GET ORIG TOP OF RAM PAGE
3874   3567 60          	RTS			;AND RETURN
3875   3568             ;
3876   3568             ;	DOSLDR  DOS LOADER AND WRITTER
3877   3568             ;
3878   3600             	ORG	ORG2
3879   3600             DOSLDR
3880   3600             ;	GARBAGED BOOT REC 0 HERE
3881   3600             	RMB	254
3882   36FE 36          GRSPG	DB	$36
3883   36FF 48          GRPGC	DB	$48

Page     91    APPLE DOS 3.1

3884   3700             	PAGE
3885   3700             SC3
3886   3700             ;
3887   3700             ;	READ DOS AFTER BOOT
3888   3700             ;;
3889   3700 8E E9 37    	STX	IBSLOT		;SET BOOT SLOT
3890   3703 8E F7 37    	STX	IBPSLT		; SET PREVIOUS SLOT
3891   3706 A9 01       	LDA	#1		;SET PREV DRIVE
3892   3708 8D F8 37    	STA	IBPDRV
3893   370B 8D EA 37    	STA	IBDRVN
3894   370E             ;
3895   370E AD E0 37    	LDA	NDPGS		;COPY NO PAGES TO GET
3896   3711 8D E1 37    	STA	BRWCNT
3897   3714 A9 00       	LDA	#0
3898   3716 8D EC 37    	STA	IBTRK		; SET TRACK 0
3899   3719             ;
3900   3719 AD E2 37    	LDA	BSDSEC		;COPY START DOS SECTOR
3901   371C 8D ED 37    	STA	IBSECT
3902   371F             ;
3903   371F AD E3 37    	LDA	BGNDOS		;COPY STARTR DOS ADR
3904   3722 8D F1 37    	STA	IBBUFP+1
3905   3725             ;
3906   3725 A9 01       	LDA	#IBCRTS		;SET READ
3907   3727 8D F4 37    	STA	IBCMD
3908   372A             ;
3909   372A 8A          	TXA			;SET PREV TRACK = 0
3910   372B 4A          	LSRA
3911   372C 4A          	LSRA
3912   372D 4A          	LSRA
3913   372E 4A          	LSRA
3914   372F AA          	TAX
3915   3730 A9 00       	LDA	#0
3916   3732 9D F8 04    	STA	$4F8,X
3917   3735 9D 78 04    	STA	$478,X
3918   3738 20 93 37    	JSR	BOOTIO		; GO READ DOS
3919   373B             ;
3920   373B             ;	DOSINT  INITIALIZE DOS
3921   373B             ;
3922   373B             DOSINT
3923   373B A2 FF       	LDX	#$FF
3924   373D 9A          	TXS
3925   373E 8E EB 37    	STX	IBVOL
3926   3741 20 93 FE    	JSR	SETVID
3927   3744 20 89 FE    	JSR	SETKBD
3928   3747             ;
3929   3747 4C 03 1B    DI3	JMP	DOSREL		; GO TO POST INIT ROUTINE

Page     92    APPLE DOS 3.1

3930   374A             	PAGE
3931   374A             WBOOT
3932   374A AD F1 37    	LDA	IBBUFP+1	;GET START OF DOS
3933   374D 8D E3 37    	STA	BGNDOS		;SAVE IR
3934   3750 38          	SEC
3935   3751 AD E7 37    	LDA	ADOSLD+1	;CALCULATE
3936   3754 ED E3 37    	SBC	BGNDOS
3937   3757 8D E0 37    	STA	NDPGS		;NO DOS PAGES
3938   375A             ;
3939   375A A9 00       	LDA	#0
3940   375C 8D EC 37    	STA	IBTRK		;TRACK=0
3941   375F 8D ED 37    	STA	IBSECT		;SECTOR=0
3942   3762 8D F0 37    	STA	IBBUFP
3943   3765             ;
3944   3765 AD E7 37    	LDA	ADOSLD+1	;GET BOOT START ADR
3945   3768 8D F1 37    	STA	IBBUFP+1	;TO BUFP
3946   376B 8D FE 36    	STA	GRSPG		;TO GARBAGE RECORD
3947   376E             ;
3948   376E A9 0A       	LDA	#10		;NO OF BOOT PAGES
3949   3770 8D E1 37    	STA	BRWCNT		;TO BOOT I/O COUNTER
3950   3773 8D E2 37    	STA	BSDSEC
3951   3776 A9 48       	LDA	#$48
3952   3778 8D FF 36    	STA	GRPGC
3953   377B             ;
3954   377B A9 02       	LDA	#IBCWTS		;SET WRITE
3955   377D 8D F4 37    	STA	IBCMD
3956   3780             ;
3957   3780 20 93 37    	JSR	BOOTIO		; GO WRITE BOOT SECTORS
3958   3783             ;
3959   3783 AD E3 37    	LDA	BGNDOS		;SET START OF DOS
3960   3786 8D F1 37    	STA	IBBUFP+1
3961   3789             ;
3962   3789 AD E0 37    	LDA	NDPGS
3963   378C 8D E1 37    	STA	BRWCNT
3964   378F 20 93 37    	JSR	BOOTIO		;GO WRITE DOS
3965   3792             ;
3966   3792 60          	RTS			;DONE

Page     93    APPLE DOS 3.1

3967   3793             	PAGE
3968   3793             BOOTIO
3969   3793 AD E5 37    	LDA	BAIOB+1
3970   3796 AC E4 37    	LDY	BAIOB
3971   3799 20 00 3D    	JSR	DISKIO
3972   379C             
3973   379C AC ED 37    	LDY	IBSECT		;GET SECTOR
3974   379F C8          	INY			;INCREMENT TO NEXT
3975   37A0 C0 0D       	CPY	#13		;AT END OF TRACK
3976   37A2 D0 05       	BNE	BIO1		;BR IF NOT SECTOR ZERO
3977   37A4 A0 00       	LDY	#0		;SET TO SECTOR ZERO
3978   37A6 EE EC 37    	INC	IBTRK
3979   37A9 8C ED 37    BIO1	STY	IBSECT		;SET NEXT SECTOR
3980   37AC             ;
3981   37AC EE F1 37    	INC	IBBUFP+1	; INCREMENT BUFFER POINTER
3982   37AF CE E1 37    	DEC	BRWCNT		;DECREMENT PAGE COUNTER
3983   37B2 D0 DF       	BNE	BOOTIO		;BR IF NOT DONE
3984   37B4 60          	RTS
3985   37B5             ;

Page     94    APPLE DOS 3.1

3986   37B5             	PAGE
3987   37B5             ;
3988   37B5             ;	DOS PATCH AREA 1
3989   37B5             ;
3990   37B5             DP1	EQU	*		;*** PATCH *** (EVAR)
3991   37B5 A9 0C       	LDA	#CRQVAR		;VERIFY COMMAND
3992   37B7 20 38 22    	JSR	OPEN		;TRY VERIFY
3993   37BA A9 06       	LDA	#CREFNF		;FILE NOT FOUND ERROR CODE
3994   37BC CD F9 34    	CMP	CCBSTA		;TEST FILE NOT FOUND
3995   37BF D0 03       	BNE	DP11		;BR IF FOUND
3996   37C1 4C B2 23    	JMP	KLUTZ		;ELSE GO FIX THINGS
3997   37C4             DP11
3998   37C4 4C 78 22    	JMP	ECLOSE		; FILE FOUND, CLOSE AND RTN
3999   37C7             ;
4000   3800             	BOUND 256
4001   37E0             	ORG	*-$20
4002   37E0             EC3
4003   37E0 00          NDPGS	DB	0
4004   37E1 00          BRWCNT	DB	0
4005   37E2 00          BSDSEC	DB	0
4006   37E3 00          BGNDOS	DB	0
4007   37E4 E8 37       BAIOB	DW	@@IOB
4008   37E6 00 36       ADOSLD	DW	@@DOSLDR

Page     95    APPLE DOS 3.1

4009   37E8             	PAGE
4010   37E8             ;
4011   37E8             ;	IOB  INPUT / OUTPUT CONTROL BLOCK
4012   37E8             ;	      THE IOB IS USED FOR THE INTERFACE
4013   37E8             ;	      BETWEEN DOS AND THE DISK I/O ROUTINES
4014   37E8             ;
4015   37E8             IOB
4016   37E8 01          IBTYPE	DB	1		;IOB TYPE CODE
4017   37E9 60          IBSLOT	DB	$60		;CONTROLLER SLOT NO.
4018   37EA 01          IBDRVN	DB	1		;DRIVE NUMBER
4019   37EB FF          IBVOL	DB	$FF		;VOLUME NUMBER
4020   37EC 11          IBTRK	DB	$11		;TRACK NUMBER
4021   37ED 0B          IBSECT	DB	$0B		;SECTOR NUMBER
4022   37EE FB 37       IBDCTP	DW	@@DCT
4023   37F0 EF 33       IBBUFP	DW	@@$33EF		;POINTER TO BUFFER
4024   37F2 00 00       IBDLEN	DW	@@0		;DATA LENGTH
4025   37F4 01          IBCMD	DB	1		;COMMAND 
4026   37F5             IBCNUL	EQU	0		;0-NULL COMMAND
4027   37F5             IBCRTS	EQU	1		;1-READ TRACK, SECTOR
4028   37F5             IBCWTS	EQU	2		;2-WRITE TRACK, SECTOR
4029   37F5             IBFMT	EQU	4		;4-FORMAT DISK
4030   37F5             IBBOOT	EQU	8		;8-WRITE BOOT
4031   37F5 00          IBSTAT	DB	0		;STATUS 
4032   37F6             IBRERR	EQU	$80		;READ ERR
4033   37F6             IBDERR	EQU	$40		;DRIVE ERR
4034   37F6             IBVMME	EQU	$20		;VOLUME MISMATCH
4035   37F6             IBWPER	EQU	$10		;WRITE PROTECT ERROR
4036   37F6 10          IBSMOD	DB	$10		;STATUS MODIFIER BYTE
4037   37F7 60          IBPSLT	DB	$60		;PREVIOUS SLOT
4038   37F8 01          IBPDRV	DB	1		;PREVIOUS DRIVE
4039   37F9             IBSPAR	RMB	2		;IOB SPARES
4040   37FB 00 01 EF D8 DCT	DB	0,1,$EF,$D8
4041   37FF 00          	DB	0

Page     96    APPLE DOS 3.1

4042   3800             	PAGE
4043   3800             ;
4044   3800             ;	FILE DIRECTORY DEFINITION
4045   3800             ;
4046   3800             ;	ORG	0
4047   3800             ;FILDIR
4048   3800             ;FDUCDE	RMB	1		;FILE USE CODE
4049   3800             ;FDLTRK	RMB	1		;LINK TO NXT DIR TRACK
4050   3800             ;FDLSEC	RMB	1		;LINK TO NEXT DIR SECTOR
4051   3800             ;FDNSA	RMB	1		;NO SECTOR ALLOCATED
4052   3800             ;FDLSDL	RMB	1		;LAST SECTOR DATA LENGTH
4053   3800             ;FDFRS	RMB	2		;1ST RELATIVE SECTOR IN THIS DIR
4054   3800             ;FDSPAR	RMB	5		;SPARES
4055   3800             ;;
4056   3800             ;FDENT	RMB	1		;START OF FILE ENTRIES (122)
4057   3800             ;FDTRK	EQU	0		;TRACK 
4058   3800             ;FDSEC	EQU	1		;SECTOR
4059   3800             ;;
4060   3800             ;FDLAST	EQU	FILDIR+256
4061   3800             ;
4062   3800             ZPORG	EQU	0
4063   3800             FILDIR	EQU	ZPORG
4064   3800             FDUCDE	EQU	ZPORG		;FILE USE CODE
4065   3800             FDLTRK	EQU	ZPORG+1		;LINK TO NXT DIR TRACK
4066   3800             FDLSEC	EQU	ZPORG+2		;LINK TO NEXT DIR SECTOR
4067   3800             FDNSA	EQU	ZPORG+3		;NO SECTOR ALLOCATED
4068   3800             FDLSDL	EQU	ZPORG+4		;LAST SECTOR DATA LENGTH
4069   3800             FDFRS	EQU	ZPORG+5		;1ST RELATIVE SECTOR IN THIS DIR
4070   3800             FDSPAR	EQU	ZPORG+7		;SPARES
4071   3800             ;
4072   3800             FDENT	EQU	ZPORG+12	;START OF FILE ENTRIES (122)
4073   3800             FDTRK	EQU	0		;TRACK 
4074   3800             FDSEC	EQU	1		;SECTOR
4075   3800             ;
4076   3800             FDLAST	EQU	FILDIR+256

Page     97    APPLE DOS 3.1

4077   3800             	PAGE
4078   3800             ;
4079   3800             ***************************
4080   3800             *         DISC-II         *
4081   3800             *     13-SECTOR FORMAT    *
4082   3800             *      READ AND WRITE     *
4083   3800             *       SUBROUTINES       *
4084   3800             *                         *
4085   3800             ***************************
4086   3800             *                         *
4087   3800             *                         *
4088   3800             *     COPYRIGHT 1978      *
4089   3800             *   APPLE COMPUTER INC.   *
4090   3800             *                         *
4091   3800             *   ALL RIGHTS RESERVED   *
4092   3800             *                         *
4093   3800             ***************************
4094   3800             *                         *
4095   3800             *      MAY 25, 1978       *
4096   3800             *          WOZ            *
4097   3800             *      R. WIGGINTON       *
4098   3800             *                         *
4099   3800             ***************************

Page     98    APPLE DOS 3.1

4100   3800             	EJECT
4101   3800             ***************************
4102   3800             *                         *
4103   3800             *     CRITICAL TIMING     *
4104   3800             *   REQUIRES PAGE BOUND   *
4105   3800             *   CONSIDERATIONS FOR    *
4106   3800             *      CODE AND DATA      *
4107   3800             *                         *
4108   3800             *     -----CODE-----      *
4109   3800             *                         *
4110   3800             *   VIRTUALLY THE ENTIRE  *
4111   3800             *     'WRITE' ROUTINE     *
4112   3800             *      MUST NOT CROSS     *
4113   3800             *     PAGE BOUNDARIES.    *
4114   3800             *                         *
4115   3800             *  CRITICAL BRANCHES IN   *
4116   3800             *  THE 'WRITE', 'READ',   *
4117   3800             *  AND 'READ ADR' SUBRS   *
4118   3800             *  WHICH MUST NOT CROSS   *
4119   3800             *  PAGE BOUNDARIES ARE    *
4120   3800             *  NOTED IN COMMENTS.     *
4121   3800             *                         *
4122   3800             *     -----DATA-----      *
4123   3800             *                         *
4124   3800             *  NBUF1, NBUF2, NBUF3,   *
4125   3800             *  NBUF4, AND NBUF5 ARE   *
4126   3800             *  51-BYTE RAM BUFFERS    *
4127   3800             *  WHICH SHOULD ALL BE    *
4128   3800             *  LOCATED ON A SINGLE    *
4129   3800             *  PAGE BEGINNING WITH    *
4130   3800             *  NBUF1. (NBUF5 IS 52).  *
4131   3800             *                         *
4132   3800             *  NBUF6, NBUF7, AND      *
4133   3800             *  NBUF8 MUST NOT CROSS   *
4134   3800             *  PAGE BOUNDARIES AND    *
4135   3800             *  SHOULD BE LOCATED      *
4136   3800             *  ON A PAGE BEGINNING    *
4137   3800             *  WITH NBUF6.  NBUF6     *
4138   3800             *  AND NBUF7 ARE 51 BYTES *
4139   3800             *  WHILE NBUF8 IS 52.     *
4140   3800             *                         *
4141   3800             *  NIBLIZING TABLE 'NIBL' *
4142   3800             *  (32 BYTES) MUST NOT    *
4143   3800             *  CROSS PAGE BOUNDARY.   *
4144   3800             *  CONVERTS 5-BIT NIBLS   *
4145   3800             *  TO 7-BIT NIBLS.        *
4146   3800             *                         *
4147   3800             *  DENIBLIZING TABLE      *
4148   3800             *  'DNIBL' MUST BE ON A   *
4149   3800             *  PAGE BOUNDARY, BUT     *
4150   3800             *  ONLY DNIBL,$AB TO      *
4151   3800             *  DNIBL,$FF NEED BE      *
4152   3800             *  USED.  CONVERTS 7-BIT  *
4153   3800             *  NIBLS TO 5-BIT NIBLS.  *
4154   3800             *                         *
4155   3800             ***************************

Page     99    APPLE DOS 3.1

4156   3800             	EJECT
4157   3800             ***************************
4158   3800             *                         *
4159   3800             *         EQUATES         *
4160   3800             *                         *
4161   3800             ***************************
4162   3800             *                         *
4163   3800             *    -----PRENIBL----     *
4164   3800             *      AND POSTNIBL       *
4165   3800             *                         *
4166   3800             ***************************
4167   3800             BUF	EQU	$3E		;TWO BYTE POINTER.
4168   3800             *
4169   3800             *        POINTS TO 256-BYTE
4170   3800             *        USER BUFFER ANYWHERE
4171   3800             *        IN MEMORY.  PRENIBL
4172   3800             *        CONVERTS USER DATA
4173   3800             *        (IN BUF) INTO 5-BIT
4174   3800             *        NIBLS 000ABCDE IN
4175   3800             *        NBUF1 THROUGH NBUF8
4176   3800             *        PRIOR TO 'WRITE'.
4177   3800             *        POSTNIBL CONVERTS
4178   3800             *        5-BIT NIBLS ABCDE000
4179   3800             *        BACK TO USER DATA
4180   3800             *        (IN BUF) AFTER 'READ'.
4181   3800             *
4182   3800             NBUF1	EQU	$3B00
4183   3800             NBUF2	EQU	$3B33		;OBSERVE THESE
4184   3800             NBUF3	EQU	$3B66		;PLACEMENTS
4185   3800             NBUF4	EQU	$3B99		;RELATIVE TO
4186   3800             NBUF5	EQU	$3BCC		;PAGE STARTS!
4187   3800             NBUF6	EQU	$3C00	
4188   3800             NBUF7	EQU	$3C33	
4189   3800             NBUF8	EQU	$3C66		;(TO $BC99)
4190   3800             *
4191   3800             T0	EQU	$26		;TEMPS USED BY PRENIBL
4192   3800             T1	EQU	$27		;   AND POSTNIBL.
4193   3800             T2	EQU	$2A		;TEMP USED BY PRENIBL.
4194   3800             *
4195   3800             ************************
4196   3800             *                      *
4197   3800             *    ----READADR----   *
4198   3800             *                      *
4199   3800             ************************
4200   3800             COUNT	EQU	$26		;'MUST FIND' COUNT.
4201   3800             LAST	EQU	$26		;'ODD BIT' NIBLS.
4202   3800             CSUM	EQU	$27		;CHECKSUM BYTE.
4203   3800             CSSTV	EQU	$2C		;FOUR BYTES,
4204   3800             *       CHECKSUM, SECTOR, TRACK, AND VOLUME.
4205   3800             *
4206   3800             ************************
4207   3800             *                      *
4208   3800             *    ----WRITE----     *
4209   3800             *                      *
4210   3800             *    USES ALL NBUFS    *
4211   3800             *      AND 32-BYTE     *
4212   3800             *   DATA TABLE 'NIBL'  *
4213   3800             *                      *
4214   3800             ************************
4215   3800             WTEMP	EQU	$26		;TEMP FOR DATA AT NBUF6,0.
4216   3800             SLOTZ	EQU	$27		;SLOTNUM IN Z-PAG LOC.
4217   3800             SLOTABS	EQU	$678		;SLOTNUM IN NON-ZPAG LOC.
4218   3800             *
4219   3800             ************************
4220   3800             *                      *
4221   3800             *     -----READ----    *
4222   3800             *                      *
4223   3800             *    USES ALL NBUFS    *
4224   3800             *  USES LAST 54 BYTES  *
4225   3800             *  OF A CODE PAGE FOR  *
4226   3800             *  USED BYTES OF DNIBL *
4227   3800             *  TABLE.              *
4228   3800             *                      *
4229   3800             ************************
4230   3800             IDX	EQU	$26 		;INDEX INTO (BUF).
4231   3800             DNIBL	EQU	$3A00		;7-BIT TO 5-BIT NIBLS.
4232   3800             *
4233   3800             ************************
4234   3800             *                      *
4235   3800             *    ---- SEEK ----    *
4236   3800             *                      *
4237   3800             ************************
4238   3800             TRKCNT	EQU	$26		;HALFTRKS MOVED COUNT.
4239   3800             PRIOR	EQU	$27		;PRIOR HALFTRACK.
4240   3800             TRKN	EQU	$2A		;DESIRED TRACK.
4241   3800             SLOTTEMP EQU	$2B		;SLOT NUM TIMES $10.
4242   3800             CURTRK	EQU	$478		;CURRENT TRACK ON ENTYR.
4243   3800             *
4244   3800             ************************
4245   3800             *                      *
4246   3800             *   ---- MSWAIT ----   *
4247   3800             *                      *
4248   3800             ************************
4249   3800             MONTIMEL EQU	$46
4250   3800             MONTIMEH EQU	$47
4251   3800             *
4252   3800             ************************
4253   3800             *                      *
4254   3800             *    DEVICE ADDRESS    *
4255   3800             *     ASSIGNMENTS      *
4256   3800             *                      *
4257   3800             ************************
4258   3800             PHASEOFF EQU	$C080		;STEPPER PHASE OFF.
4259   3800             PHASEON	EQU	$C081		;STEPPER PHASE ON.
4260   3800             Q6L	EQU	$C08C		;Q7L,Q6L=READ
4261   3800             Q6H	EQU	$C08D		;Q7L,Q6H=SENSE WPROT
4262   3800             Q7L	EQU	$C08E		;Q7H,Q6L=WRITE
4263   3800             Q7H	EQU	$C08F		;Q7H,Q6H=WRITE STORE

Page    100    APPLE DOS 3.1

4264   3800             	EJECT
4265   3800             ****************************
4266   3800             *                          *
4267   3800             *    PRENIBLIZE SUBR       *
4268   3800             *                          *
4269   3800             ****************************
4270   3800             *                          *
4271   3800             *  CONVERTS 256 BYTES OF   *
4272   3800             *  USER DATA IN (BUF),0    *
4273   3800             *  TO (BUF),255 INTO 410   *
4274   3800             *  5-BIT NIBLS (000ABCDE)  *
4275   3800             *  IN NBUF1 THROUGH NBUF8. *
4276   3800             *                          *
4277   3800             *    ---- ON ENTRY ----    *
4278   3800             *                          *
4279   3800             *  BUF IS 2-BYTE POINTER   *
4280   3800             *    TO 256 BYTES OF USER  *
4281   3800             *    DATA.                 *
4282   3800             *                          *
4283   3800             *    ---- ON EXIT -----    *
4284   3800             *                          *
4285   3800             *  A-REG: UNCERTAIN.       *
4286   3800             *  X-REG: UNCERTAIN.       *
4287   3800             *  Y-REG: HOLDS $FF.       *
4288   3800             *  CARRY: UNCERTAIN.       *
4289   3800             *                          *
4290   3800             *  NBUF1 THROUGH NBUF8     *
4291   3800             *    CONTAIN 5-BIT NIBLS   *
4292   3800             *    OF FORM 000ABCDE.     *
4293   3800             *                          *
4294   3800             *  TEMPS T0, T1, T2 USED.  *
4295   3800             *                          *
4296   3800             ****************************
4297   3800             	ORG	$3800
4298   3800             * OBJ $B800
4299   3800 A2 32       PRENIBL	LDX	#$32		;INDEX FOR (51) 5-BYTE PASSES.
4300   3802 A0 00       	LDY	#$0		;USER BUF INDEX.
4301   3804 B1 3E       PNIB1	LDA	(BUF),Y		;FIRST OF 5 USER BYTES.
4302   3806 85 26       	STA	T0		;(ONLY 3 LSB'S USED)
4303   3808 4A          	LSRA
4304   3809 4A          	LSRA			;5 MSB'S TO LOW BITS.
4305   380A 4A          	LSRA
4306   380B 9D 00 3B    	STA	NBUF1,X		;FIRST OF 8 5-BIT NIBLS.
4307   380E C8          	INY
4308   380F B1 3E       	LDA	(BUF),Y		;SECOND OF 5 USER BYTES.
4309   3811 85 27       	STA	T1		;ONLY 3 LSB'S USED)
4310   3813 4A          	LSRA
4311   3814 4A          	LSRA			;5 MSB'S TO LOW BITS.
4312   3815 4A          	LSRA
4313   3816 9D 33 3B    	STA	NBUF2,X		;SECOND OF 8 5-BIT NIBLS.
4314   3819 C8          	INY
4315   381A B1 3E       	LDA	(BUF),Y		;THIRD OF 5 USER BYTES.
4316   381C 85 2A       	STA	T2		;(ONLY 3 LSB'S USED)
4317   381E 4A          	LSRA
4318   381F 4A          	LSRA			;5 MSB'S TO LOW BITS.
4319   3820 4A          	LSRA
4320   3821 9D 66 3B    	STA	NBUF3,X		;THIRD OF 8 5-BIT NIBLS.
4321   3824 C8          	INY
4322   3825 B1 3E       	LDA	(BUF),Y		;FOURTH OF 5 USER BYTES.
4323   3827 4A          	LSRA
4324   3828 26 2A       	ROL	T2		;LSB INTO T2.
4325   382A 4A          	LSRA
4326   382B 26 27       	ROL	T1		;NEXT LSB INTO T1.
4327   382D 4A          	LSRA
4328   382E 26 26       	ROL	T0		;NEXT LSB INTO T0.
4329   3830 9D 99 3B    	STA	NBUF4,X		;FOURTH OF 8 5-BIT NIBLS.
4330   3833 C8          	INY
4331   3834 B1 3E       	LDA	(BUF),Y		;FIFTH OF 5 USER BYTES.
4332   3836 4A          	LSRA
4333   3837 26 2A       	ROL	T2		;LSB INTO T2.
4334   3839 4A          	LSRA
4335   383A 26 27       	ROL	T1		;NEXT LSB INTO T1.
4336   383C 4A          	LSRA
4337   383D 9D CC 3B    	STA	NBUF5,X		;FIFTH OF 8 5-BIT NIBLS.
4338   3840 A5 26       	LDA	T0
4339   3842 2A          	ROLA			;NEXT LSB.
4340   3843 29 1F       	AND	#$1F		;TRUNCATE TO 5 BITS.
4341   3845 9D 00 3C    	STA	NBUF6,X		;SIXTH OF 8 5-BIT NIBLS.
4342   3848 A5 27       	LDA	T1
4343   384A 29 1F       	AND	#$1F		;TRUNCATE TO 5 BITS.
4344   384C 9D 33 3C    	STA	NBUF7,X		;SEVENTH OF 8 5-BIT NIBLS.
4345   384F A5 2A       	LDA	T2
4346   3851 29 1F       	AND	#$1F		;TRUNCATE TO 5 BITS.
4347   3853 9D 66 3C    	STA	NBUF8,X		;EIGHTH OF 8 5-BIT NIBLS.
4348   3856 C8          	INY
4349   3857 CA          	DEX			;NEXT OF (51) 5-BYTE PASSES.
4350   3858 10 AA       	BPL	PNIB1
4351   385A B1 3E       	LDA 	(BUF),Y
4352   385C AA          	TAX
4353   385D 29 07       	AND 	#$7		;3 LSB'S OF LAST
4354   385F 8D 99 3C    	STA	NBUF8+$33	;  USER BYTE.
4355   3862 8A          	TXA
4356   3863 4A          	LSRA
4357   3864 4A          	LSRA
4358   3865 4A          	LSRA			;5 MSB'S OF LAST
4359   3866 8D FF 3B    	STA	NBUF5+$33	;  USER BYTE.
4360   3869 60          	RTS

Page    101    APPLE DOS 3.1

4361   386A             	EJECT
4362   386A             ************************
4363   386A             *                      *
4364   386A             *      WRITE SUBR      *
4365   386A             *                      *
4366   386A             ************************
4367   386A             *                      *
4368   386A             *   WRITES DATA FROM   *
4369   386A             *    NBUF1 TO NBUF8    *
4370   386A             *   CONVERTING 5-BIT   *
4371   386A             *    TO 7-BIT NIBLS    *
4372   386A             *   VIA 'NIBL' TABLE.  :
4373   386A             *                      *
4374   386A             *  FIRST, NBUF6 TO     *
4375   386A             *   NBUF8, HIGH TO LOW *
4376   386A             *  THEN, NBUF1 TO      *
4377   386A             *   NBUF5, LOW TO HIGH *
4378   386A             *                      *
4379   386A             *  ---- ON ENTRY ----  *
4380   386A             *                      *
4381   386A             *   X-REG: SLOTNUM     *
4382   386A             *        TIMES $10.    *
4383   386A             *                      *
4384   386A             *   NBUF1 TO NBUF8     *
4385   386A             *    HOLD NIBLS FROM   *
4386   386A             *    PRENIBL SUBR.     *
4387   386A             *    (000ABCDE)        *
4388   386A             *                      *
4389   386A             *  ---- ON EXIT -----  *
4390   386A             *                      *
4391   386A             *  CARRY SET IF ERROR. *
4392   386A             *   (W PROT VIOLATION) *
4393   386A             *                      *
4394   386A             *  IF NO ERROR:        *
4395   386A             *                      *
4396   386A             *    A-REG: UNCERTAIN. *
4397   386A             *    X-REG: UNCHANGED. *
4398   386A             *    Y-REG: HOLDS $00. *
4399   386A             *    CARRY CLEAR.      *
4400   386A             *                      *
4401   386A             *    SLOTABS, SLOTZ,   *
4402   386A             *     AND WTEMP USED.  *
4403   386A             *                      *
4404   386A             *  ---- ASSUMES ----   *
4405   386A             *                      *
4406   386A             *  1 USEC CYCLE TIME   *
4407   386A             *                      *
4408   386A             ************************
4409   386A 38          WRITE	SEC			;ANTICIPATE WPROT ERR.
4410   386B BD 8D C0    	LDA	Q6H,X
4411   386E BD 8E C0    	LDA	Q7L,X		;SENSE WPROT FLAG.
4412   3871 30 7C       	BMI	WEXIT		; IF HIGH, THEN ERR.
4413   3873 86 27       	STX	SLOTZ		;FOR ZERO PAGE ACCESS.
4414   3875 8E 78 06    	STX	SLOTABS		;FOR NON-ZERO PAGE.
4415   3878 AD 00 3C    	LDA	NBUF6
4416   387B 85 26       	STA	WTEMP		;FOR ZERO-PAGE ACCESS.
4417   387D A9 FF       	LDA	#$FF		;SYNC DATA.
4418   387F 9D 8F C0    	STA	Q7H,X		;(5)  WRITE 1ST NIBL.
4419   3882 1D 8C C0    	ORA	Q6L,X		;(4)
4420   3885 48          	PHA			;(3)
4421   3886 68          	PLA			;(4)  CRITICAL TIMING!
4422   3887 EA          	NOP			;(2)
4423   3888 A0 0A       	LDY	#$A		;(2)  FOR 11 NIBLS.
4424   388A 05 26       WSYNC	ORA	WTEMP		;(3)  FOR TIMING.
4425   388C 20 F4 38    	JSR	WNIBL7		;(13,9,6)  WRITE SYNC.
4426   388F 88          	DEY			;(2)
4427   3890 D0 F8       	BNE	WSYNC		;(2*)  MUST NOT CROSS PAGE!
4428   3892 A9 D5       	LDA	#$D5		;(2)  1ST DATA MARK.
4429   3894 20 F3 38    	JSR	WNIBL9		;(15,9,6)
4430   3897 A9 AA       	LDA	#$AA		;(2)  2ND DATA MARK.
4431   3899 20 F3 38    	JSR	WNIBL9		;(15,9,6)
4432   389C A9 AD       	LDA	#$AD		;(2)  3RD DATA MARK.
4433   389E 20 F3 38    	JSR	WNIBL9		;(15,9,6)
4434   38A1 98          	TYA			;(2)  CLEAR CHKSUM.
4435   38A2 A0 9A       	LDY	#$9A		;(2)  NBUF6-8 INDEX.
4436   38A4 D0 03       	BNE	WDATA1		;(3)  ALWAYS.  NO PAGE CROSS!!
4437   38A6 B9 00 3C    WDATA0	LDA	NBUF6,Y		;(4)  PRIOR 5-BIT NIBL.
4438   38A9 59 FF 3B    WDATA1	EOR	NBUF6-1,Y	;(5)  XOR WITH CURRENT.
4439   38AC             *   (NBUF6 MUST BE ON PAGE BOUNDARY FOR TIMING!!)
4440   38AC AA          	TAX			;(2)  INDEX TO 7-BIT NIBL.
4441   38AD BD 9A 3C    	LDA	NIBL,X		;(4)  MUST NOT CROSS PAGE!
4442   38B0 A6 27       	LDX	SLOTZ		;(3)  CRITICAL TIMING!
4443   38B2 9D 8D C0    	STA	Q6H,X		;(5)  WRITE NIBL.
4444   38B5 BD 8C C0    	LDA	Q6L,X		;(4)
4445   38B8 88          	DEY			;(2)  NEXT NIBL.
4446   38B9 D0 EB       	BNE	WDATA0		;(2*)  MUST NOT CROSS PAGE!
4447   38BB A5 26       	LDA	WTEMP		;(3)  PRIOR NIBL FROM BUF6.
4448   38BD EA          	NOP			;(2)  CRITICAL TIMING.
4449   38BE 59 00 3B    WDATA2	EOR	NBUF1,Y		;(4)  XOR NBUF1 NIBL.
4450   38C1 AA          	TAX			;(2)  INDEX TO 7-BIT NIBL.
4451   38C2 BD 9A 3C    	LDA	NIBL,X		;(4)
4452   38C5 AE 78 06    	LDX	SLOTABS		;(4)  TIMING CRITICAL.
4453   38C8 9D 8D C0    	STA	Q6H,X		;(5)  WRITE NIBL.
4454   38CB BD 8C C0    	LDA	Q6L,X		;(4)
4455   38CE B9 00 3B    	LDA	NBUF1,Y		;(4)  PRIOR 5-BIT NIBL.
4456   38D1 C8          	INY			;(2)  NEXT NBUF1 NIBL.
4457   38D2 D0 EA       	BNE	WDATA2		;(2*)  MUST NOT CROSS PAGE!
4458   38D4 AA          	TAX			;(2)  LAST NIBL AS CHKSUM.
4459   38D5 BD 9A 3C    	LDA	NIBL,X		;(4)  INDEX TO 7-BIT NIBL.
4460   38D8 A6 27       	LDX	SLOTZ		;(3)
4461   38DA 20 F6 38    	JSR	WNIBL		;(6,9,6)  WRITE CHKSUM.
4462   38DD A9 DE       	LDA	#$DE		;(2)  DM4, BIT SLIP MARK.
4463   38DF 20 F3 38    	JSR	WNIBL9		;(15,9,6)    WRITE IT.
4464   38E2 A9 AA       	LDA	#$AA		;(2)  DM5, BIT SLIP MARK.
4465   38E4 20 F3 38    	JSR	WNIBL9		;(15,9,6)    WRITE IT.
4466   38E7 A9 EB       	LDA	#$EB		;(2)  DM6, BIT SLIP MARK.
4467   38E9 20 F3 38    	JSR	WNIBL9		;(15,9,6)    WRITE IT.
4468   38EC BD 8E C0    	LDA	Q7L,X		; OUT OF WRITE MODE.
4469   38EF BD 8C C0    WEXIT	LDA	Q6L,X		;  TO READ MODE.
4470   38F2 60          	RTS			; RETURN FROM WRITE.
4471   38F3             *****************************
4472   38F3             *                           *
4473   38F3             *   7-BIT NIBL WRITE SUBRS  *
4474   38F3             *                           *
4475   38F3             *   A-REG OR'D PRIOR EXIT   *
4476   38F3             *       CARRY CLEARED       *
4477   38F3             *                           *
4478   38F3             *****************************
4479   38F3 18          WNIBL9	CLC			;(2)  9 CYCLES, THEN WRITE.
4480   38F4 48          WNIBL7	PHA			;(3)  7 CYCLES, THEN WRITE.
4481   38F5 68          	PLA			;(4)
4482   38F6 9D 8D C0    WNIBL	STA	Q6H,X		;(5)  NIBL WRITE SUB.
4483   38F9 1D 8C C0    	ORA	Q6L,X		;(4)  CLOBBERS ACC, NOT CARRY.
4484   38FC 60          	RTS

Page    102    APPLE DOS 3.1

4485   38FD             	EJECT
4486   38FD             **************************
4487   38FD             *                        *
4488   38FD             *     READ SUBROUTINE    *
4489   38FD             *                        *
4490   38FD             **************************
4491   38FD             *                        *
4492   38FD             *    READS 5-BIT NIBLS   *
4493   38FD             *     (ABCDE000) INTO    *
4494   38FD             *   NBUF1 THROUGH NBUF8  *
4495   38FD             *    CONVERTING 7-BIT    *
4496   38FD             *     NIBLS TO 5-BIT     *
4497   38FD             *    VIA 'DNIBL' TABLE   *
4498   38FD             *                        *
4499   38FD             *  FIRST READS NBUF6 TO  *
4500   38FD             *    NBUF8 HIGH TO LOW,  *
4501   38FD             *  THEN READS NBUF1 TO   *
4502   38FD             *    NBUF5 LOW TO HIGH   *
4503   38FD             *                        *
4504   38FD             *   ---- ON ENTRY ----   *
4505   38FD             *                        *
4506   38FD             *  X-REG: SLOTNUM        *
4507   38FD             *         TIMES $10.     *
4508   38FD             *                        *
4509   38FD             *  READ MODE (Q6L, Q7L)  *
4510   38FD             *                        *
4511   38FD             *   ---- ON EXIT -----   *
4512   38FD             *                        *
4513   38FD             *  CARRY SET IF ERROR.   *
4514   38FD             *                        *
4515   38FD             *  IF NO ERROR:          *
4516   38FD             *     A-REG: HOLDS $AA   *
4517   38FD             *     X-REG: UNCHANGED.  *
4518   38FD             *     Y-REG: HOLDS $00   *
4519   38FD             *     CARRY CLEAR.       *
4520   38FD             *                        *
4521   38FD             *     NBUF1 TO NBUF8     *
4522   38FD             *       HOLD 5-BIT       *
4523   38FD             *       NIBLS ABCDE000.  *
4524   38FD             *                        *
4525   38FD             *     USES TEMP 'IDX'.   *
4526   38FD             *                        *
4527   38FD             *   ---- CAUTION -----   *
4528   38FD             *                        *
4529   38FD             *        OBSERVE         *
4530   38FD             *    'NO PAGE CROSS'     *
4531   38FD             *      WARNINGS ON       *
4532   38FD             *    SOME BRANCHES!!     *
4533   38FD             *                        *
4534   38FD             *   ---- ASSUMES ----    *
4535   38FD             *                        *
4536   38FD             *   1 USEC CYCLE TIME    *
4537   38FD             *                        *
4538   38FD             **************************
4539   38FD A0 20       READ	LDY	#$20		;'MUST FIND' COUNT.
4540   38FF 88          RSYNC	DEY			;IF CAN'T FIND MARKS
4541   3900 F0 61       	BEQ	RDERR		;THEN EXIT WITH CARRY SET.
4542   3902 BD 8C C0    RDD1	LDA	Q6L,X		;READ NIBL.
4543   3905 10 FB       	BPL	RDD1		;*** NO PAGE CROSS! ***
4544   3907 49 D5       RSYNC1	EOR	#$D5		;DATA MARK 1?
4545   3909 D0 F4       	BNE	RSYNC		;  LOOP IF NOT.
4546   390B EA          	NOP			;DELAY BETWEEN NIBLS.
4547   390C BD 8C C0    RDD2	LDA	Q6L,X
4548   390F 10 FB       	BPL	RDD2		;*** NO PAGE CROSS! ***
4549   3911 C9 AA       	CMP	#$AA		;DATA MARK 2?
4550   3913 D0 F2       	BNE	RSYNC1		;  (IF NOT, IS IT DM1?)
4551   3915 A0 9A       	LDY	#$9A		;INIT NBUF6 INDEX.
4552   3917             *              (ADDED NIBL DELAY)
4553   3917 BD 8C C0    RDD3	LDA	Q6L,X
4554   391A 10 FB       	BPL	RDD3		;*** NO PAGE CROSS! ***
4555   391C C9 AD       	CMP	#$AD		;DATA MARK 3?
4556   391E D0 E7       	BNE	RSYNC1		;  (IF NOT, IS IT DM1?)
4557   3920             *         (CARRY SET IF DM3!)
4558   3920 A9 00       	LDA	#$00		;INIT CHECKSUM.
4559   3922 88          RDATA1	DEY
4560   3923 84 26       	STY	IDX
4561   3925 BC 8C C0    RDD4	LDY	Q6L,X
4562   3928 10 FB       	BPL	RDD4		;*** NO PAGE CROSS! ***
4563   392A 59 00 3A    	EOR	DNIBL,Y		;XOR 5-BIT NIBL.
4564   392D A4 26       	LDY	IDX
4565   392F 99 00 3C    	STA	NBUF6,Y		;STORE IN NBUF6 PAGE.
4566   3932 D0 EE       	BNE	RDATA1		;TAKEN IF Y-REG NONZERO.
4567   3934 84 26       RDATA2	STY	IDX
4568   3936 BC 8C C0    RDD5	LDY	Q6L,X
4569   3939 10 FB       	BPL	RDD5		;*** NO PAGE CROSS! ***
4570   393B 59 00 3A    	EOR	DNIBL,Y		;XOR 5-BIT NIBL.
4571   393E A4 26       	LDY	IDX
4572   3940 99 00 3B    	STA	NBUF1,Y		;STORE IN NBUF1 PAGE.
4573   3943 C8          	INY	
4574   3944 D0 EE       	BNE	RDATA2
4575   3946 BC 8C C0    RDD6	LDY	Q6L,X		;READ 7-BIT CSUM NIBL.
4576   3949 10 FB       	BPL	RDD6		;*** NO PAGE CROSS! ***
4577   394B D9 00 3A    	CMP	DNIBL,Y		;IF LAST NBUF1 NIBL NOT
4578   394E D0 13       	BNE	RDERR		;EQUAL CHKSUM NIBL THEN ERR.
4579   3950 BD 8C C0    RDD7	LDA	Q6L,X
4580   3953 10 FB       	BPL	RDD7		;*** NO PAGE CROSS! ***
4581   3955 C9 DE       	CMP	#$DE		;FIRST BIT SLIP MARK?
4582   3957 D0 0A       	BNE	RDERR		;  (ERR IF NOT)
4583   3959 EA          	NOP			;DELAY BETWEEN NIBLS.
4584   395A BD 8C C0    RDD8	LDA	Q6L,X
4585   395D 10 FB       	BPL	RDD8		;*** NO PAGE CROSS! ***
4586   395F C9 AA       	CMP	#$AA		;SECOND BIT SLIP MARK?
4587   3961 F0 5C       	BEQ	RDEXIT		;  (DONE IF IT IS)
4588   3963 38          RDERR	SEC			;INDICATE 'ERROR EXIT'.
4589   3964 60          	RTS			;RETURN FROM READ OR READADR.

Page    103    APPLE DOS 3.1

4590   3965             	EJECT
4591   3965             ****************************
4592   3965             *                          *
4593   3965             *    READ ADDRESS FIELD    *
4594   3965             *                          *
4595   3965             *        SUBROUTINE        *
4596   3965             *                          *
4597   3965             ****************************
4598   3965             *                          *
4599   3965             *    READS VOLUME, TRACK   *
4600   3965             *        AND SECTOR        *
4601   3965             *                          *
4602   3965             *   ---- ON ENTRY ----     *
4603   3965             *                          *
4604   3965             *  XREG: SLOTNUM TIMES $10 *
4605   3965             *                          *
4606   3965             *  READ MODE (Q6L, Q7L)    *
4607   3965             *                          *
4608   3965             *   ---- ON EXIT -----     *
4609   3965             *                          *
4610   3965             *  CARRY SET IF ERROR.     *
4611   3965             *                          *
4612   3965             *  IF NO ERROR:            *
4613   3965             *    A-REG: HOLDS $AA.     *
4614   3965             *    Y-REG: HOLDS $00.     *
4615   3965             *    X-REG: UNCHANGED.     *
4616   3965             *    CARRY CLEAR.          *
4617   3965             *                          *
4618   3965             *    CSSTV HOLDS CHKSUM,   *
4619   3965             *      SECTOR, TRACK, AND  *
4620   3965             *      VOLUME READ.        *
4621   3965             *                          *
4622   3965             *    USES TEMPS COUNT,     *
4623   3965             *      LAST, CSUM, AND     *
4624   3965             *      4 BYTES AT CSSTV.   *
4625   3965             *                          *
4626   3965             *    ---- EXPECTS ----     *
4627   3965             *                          *
4628   3965             *  NORMAL DENSITY NIBLS    *
4629   3965             *   (4-BIT), ODD BITS,     *
4630   3965             *   THEN EVEN.             *
4631   3965             *                          *
4632   3965             *    ---- CAUTION ----     *
4633   3965             *                          *
4634   3965             *         OBSERVE          *
4635   3965             *    'NO PAGE CROSS'       *
4636   3965             *      WARNINGS ON         *
4637   3965             *    SOME BRANCHES!!       *
4638   3965             *                          *
4639   3965             *    ---- ASSUMES ----     *
4640   3965             *                          *
4641   3965             *    1 USEC CYCLE TIME     *
4642   3965             *                          *
4643   3965             ****************************
4644   3965 A0 F8       RDADR	LDY	#$F8
4645   3967 84 26       	STY	COUNT		;'MUST FIND' COUNT.
4646   3969 C8          RDASYN	INY
4647   396A D0 04       	BNE	RDA1		;LOW ORDER OF COUNT.
4648   396C E6 26       	INC	COUNT		;(2K NIBLS TO FIND
4649   396E F0 F3       	BEQ	RDERR		;  ADR MARK, ELSE ERR)
4650   3970 BD 8C C0    RDA1	LDA	Q6L,X		;READ NIBL.
4651   3973 10 FB       	BPL	RDA1		;*** NO PAGE CROSS! ***
4652   3975 C9 D5       RDASN1	CMP	#$D5		;ADR MARK 1?
4653   3977 D0 F0       	BNE	RDASYN		;  (LOOP IF NOT)
4654   3979 EA          	NOP			;ADDED NIBL DELAY.
4655   397A BD 8C C0    RDA2	LDA	Q6L,X
4656   397D 10 FB       	BPL	RDA2		;*** NO PAGE CROSS! ***
4657   397F C9 AA       	CMP	#$AA		;ADR MARK 2?
4658   3981 D0 F2       	BNE	RDASN1		;  (IF NOT, IS IT AM1?)
4659   3983 A0 03       	LDY	#$3		;INDEX FOR 4-BYTE READ.
4660   3985             *            (ADDED NIBL DELAY)
4661   3985 BD 8C C0    RDA3	LDA	Q6L,X
4662   3988 10 FB       	BPL	RDA3		;*** NO PAGE CROSS! ***
4663   398A C9 B5       	CMP	#$B5		;ADR MARK 3?
4664   398C D0 E7       	BNE	RDASN1		;  (IF NOT, IS IT AM1?)
4665   398E             *        (LEAVES CARRY SET!)
4666   398E A9 00       	LDA	#$0		;INIT CHECKSUM.
4667   3990 85 27       RDAFLD	STA	CSUM
4668   3992 BD 8C C0    RDA4	LDA	Q6L,X		;READ 'ODD BIT' NIBL.
4669   3995 10 FB       	BPL	RDA4 		;*** NO PAGE CROSS! ***
4670   3997 2A          	ROLA			;ALIGN ODD BITS, '1' INTO LSB.
4671   3998 85 26       	STA	LAST		;  (SAVE THEM)
4672   399A BD 8C C0    RDA5	LDA	Q6L,X		;READ 'EVEN BIT' NIBL.
4673   399D 10 FB       	BPL	RDA5		;*** NO PAGE CROSS! ***
4674   399F 25 26       	AND	LAST		;MERGE ODD AND EVEN BITS.
4675   39A1 99 2C 00    	STA	CSSTV,Y		;STORE DATA BYTE.
4676   39A4 45 27       	EOR	CSUM		;XOR CHECKSUM.
4677   39A6 88          	DEY	
4678   39A7 10 E7       	BPL	RDAFLD		;LOOP ON 4 DATA BYTES.
4679   39A9 A8          	TAY			;IF FINAL CHECKSUM
4680   39AA D0 B7       	BNE	RDERR		;  NONZERO, THEN ERROR.
4681   39AC BD 8C C0    RDA6	LDA	Q6L,X		;FIRST BIT-SLIP NIBL.
4682   39AF 10 FB       	BPL	RDA6		;*** NO PAGE CROSS! ***
4683   39B1 C9 DE       	CMP	#$DE
4684   39B3 D0 AE       	BNE	RDERR		;ERROR IF NONMATCH.
4685   39B5 EA          	NOP			;DELAY BETWEEN NIBLS.
4686   39B6 BD 8C C0    RDA7	LDA	Q6L,X		;SECOND BIT-SLIP NIBL.
4687   39B9 10 FB       	BPL	RDA7		;*** NO PAGE CROSS! ***
4688   39BB C9 AA       	CMP	#$AA
4689   39BD D0 A4       	BNE	RDERR		;ERROR IF NONMATCH.
4690   39BF 18          RDEXIT	CLC			;CLEAR CARRY ON
4691   39C0 60          	RTS			;NORMAL READ EXITS.

Page    104    APPLE DOS 3.1

4692   39C1             	EJECT
4693   39C1             ***************************
4694   39C1             *                         *
4695   39C1             *    POSTNIBLIZE SUBR     *
4696   39C1             *                         *
4697   39C1             ***************************
4698   39C1             *                         *
4699   39C1             *  CONVERTS 5-BIT NIBLS   *
4700   39C1             *  OF FORM ABCDE000 IN    *
4701   39C1             *  NBUF1 THROUGH NBUF8    *
4702   39C1             *  INTO 256 BYTES OF      *
4703   39C1             *  USER DATA IN BUF.      *
4704   39C1             *                         *
4705   39C1             *   ---- ON ENTRY ----    *
4706   39C1             *                         *
4707   39C1             *  X-REG: HOLDS SLOTNUM   *
4708   39C1             *            TIMES $10.   *
4709   39C1             *                         *
4710   39C1             *  BUF IS 2-BYTE POINTER  *
4711   39C1             *    TO 256 BYTES OF USER *
4712   39C1             *    DATA TO BE CONVERTED *
4713   39C1             *    TO 5-BIT NIBLS IN    *
4714   39C1             *    NBUF1 THROUGH NBUF8  *
4715   39C1             *    PRIOR TO WRITE.      *
4716   39C1             *                         *
4717   39C1             *   ---- ON EXIT -----    *
4718   39C1             *                         *
4719   39C1             *  A-REG: UNCERTAIN.      *
4720   39C1             *  Y-REG: HOLDS $FF.      *
4721   39C1             *  X-REG: HOLDS $FF.      *
4722   39C1             *  CARRY: UNCERTAIN.      *
4723   39C1             *                         *
4724   39C1             *  5-BIT NIBLS OF FORM    *
4725   39C1             *    000ABCDE IN 410      *
4726   39C1             *    BYTES FROM NBUF1     *
4727   39C1             *    TO NBUF8.            *
4728   39C1             *                         *
4729   39C1             ***************************
4730   39C1 A2 32       POSTNIB	LDX	#$32		;INDEX FOR 51 PASSES.
4731   39C3 A0 00       	LDY	#$0		;INDEX TO USER BUF.
4732   39C5 BD 00 3C    POSTNB1 LDA	NBUF6,X
4733   39C8 4A          	LSRA
4734   39C9 4A          	LSRA
4735   39CA 4A          	LSRA
4736   39CB 85 27       	STA	T1
4737   39CD 4A          	LSRA
4738   39CE 85 26       	STA	T0
4739   39D0 4A          	LSRA
4740   39D1 1D 00 3B    	ORA	NBUF1,X
4741   39D4 91 3E       	STA	(BUF),Y		;FIRST OF 5 USER BYTES.
4742   39D6 C8          	INY
4743   39D7 BD 33 3C    	LDA	NBUF7,X
4744   39DA 4A          	LSRA
4745   39DB 4A          	LSRA
4746   39DC 4A          	LSRA
4747   39DD 4A          	LSRA
4748   39DE 26 27       	ROL	T1
4749   39E0 4A          	LSRA
4750   39E1 26 26       	ROL	T0
4751   39E3 1D 33 3B    	ORA	NBUF2,X
4752   39E6 91 3E       	STA	(BUF),Y		;SECOND OF 5 USER BYTES.
4753   39E8 C8          	INY	
4754   39E9 BD 66 3C    	LDA	NBUF8,X
4755   39EC 4A          	LSRA
4756   39ED 4A          	LSRA
4757   39EE 4A          	LSRA
4758   39EF 4A          	LSRA
4759   39F0 26 27       	ROL	T1
4760   39F2 4A          	LSRA
4761   39F3 26 26       	ROL	T0
4762   39F5 1D 66 3B    	ORA	NBUF3,X
4763   39F8 91 3E       	STA	(BUF),Y		;THIRD OF 5 USER BYTES.
4764   39FA C8          	INY	
4765   39FB A5 26       	LDA	T0
4766   39FD 29 07       	AND	#$7
4767   39FF 1D 99 3B    	ORA	NBUF4,X
4768   3A02 91 3E       	STA	(BUF),Y		;FOURTH OF 5 USER BYTES.
4769   3A04 C8          	INY	
4770   3A05 A5 27       	LDA	T1
4771   3A07 29 07       	AND	#$7
4772   3A09 1D CC 3B    	ORA	NBUF5,X
4773   3A0C 91 3E       	STA	(BUF),Y		;FIFTH OF 5 USER BYTES.
4774   3A0E C8          	INY	
4775   3A0F CA          	DEX			;NEXT OF 51 PASSES.
4776   3A10 10 B3       	BPL	POSTNB1		;HANDLE LAST USER
4777   3A12 AD 99 3C    	LDA	NBUF8+$33	;  BYTE DIFFERENTLY.
4778   3A15 4A          	LSRA
4779   3A16 4A          	LSRA
4780   3A17 4A          	LSRA
4781   3A18 0D FF 3B    	ORA	NBUF5+$33
4782   3A1B 91 3E       	STA	(BUF),Y
4783   3A1D 60          	RTS

Page    105    APPLE DOS 3.1

4784   3A1E             	EJECT
4785   3A1E             **************************
4786   3A1E             *                        *
4787   3A1E             *  FAST SEEK SUBROUTINE  *
4788   3A1E             *                        *
4789   3A1E             **************************
4790   3A1E             *                        *
4791   3A1E             *   ---- ON ENTRY ----   *
4792   3A1E             *                        *
4793   3A1E             *  X-REG HOLDS SLOTNUM   *
4794   3A1E             *         TIMES $10.     *
4795   3A1E             *                        *
4796   3A1E             *  A-REG HOLDS DESIRED   *
4797   3A1E             *         HALFTRACK.     *
4798   3A1E             *         (SINGLE PHASE) *
4799   3A1E             *                        *
4800   3A1E             *  CURTRK HOLDS CURRENT  *
4801   3A1E             *          HALFTRACK.    *
4802   3A1E             *                        *
4803   3A1E             *   ---- ON EXIT -----   *
4804   3A1E             *                        *
4805   3A1E             *  A-REG UNCERTAIN.      *
4806   3A1E             *  Y-REG UNCERTAIN.      *
4807   3A1E             *  X-REG UNDISTURBED.    *
4808   3A1E             *                        *
4809   3A1E             *  CURTRK AND TRKN HOLD  *
4810   3A1E             *      FINAL HALFTRACK.  *
4811   3A1E             *                        *
4812   3A1E             *  PRIOR HOLDS PRIOR     *
4813   3A1E             *    HALFTRACK IF SEEK   *
4814   3A1E             *    WAS REQUIRED.       *
4815   3A1E             *                        *
4816   3A1E             *  MONTIMEL AND MONTIMEH *
4817   3A1E             *    ARE INCREMENTED BY  *
4818   3A1E             *    THE NUMBER OF       *
4819   3A1E             *    100 USEC QUANTUMS   *
4820   3A1E             *    REQUIRED BY SEEK    *
4821   3A1E             *    FOR MOTOR ON TIME   *
4822   3A1E             *    OVERLAP.            *
4823   3A1E             *                        *
4824   3A1E             * --- VARIABLES USED --- *
4825   3A1E             *                        *
4826   3A1E             *  CURTRK, TRKN, COUNT,  *
4827   3A1E             *    PRIOR, SLOTTEMP     *
4828   3A1E             *    MONTIMEL, MONTIMEH  *
4829   3A1E             *                        *
4830   3A1E             **************************
4831   3A1E 85 2A       SEEK	STA	TRKN		;TARGET TRACK.
4832   3A20 CD 78 04    	CMP	CURTRK		;ON DESIRED TRACK?
4833   3A23 F0 59       	BEQ	SEEKXIT		;  YES, HIT IT AND RETURN.
4834   3A25 86 2B       	STX	SLOTTEMP	;SAVE X-REG.
4835   3A27 A9 00       	LDA	#$0
4836   3A29 85 26       	STA	TRKCNT		;HALFTRACK COUNT.
4837   3A2B AD 78 04    SEEK2	LDA	CURTRK		;SAVE CURTRK FOR
4838   3A2E 85 27       	STA	PRIOR		;  DELAYED TURNOFF.
4839   3A30 38          	SEC	
4840   3A31 E5 2A       	SBC	TRKN		;DELTA-TRACKS.
4841   3A33 F0 42       	BEQ	SEEKEND		;DONE, FINISH SEEK.
4842   3A35 B0 07       	BCS	OUT		;(MOVE OUT, NOT IN)
4843   3A37 49 FF       	EOR	#$FF		;CALC TRKS TO GO.
4844   3A39 EE 78 04    	INC	CURTRK		;INCR CURRENT TRACK (IN).
4845   3A3C 90 05       	BCC	MINTST		;(ALWAYS TAKEN)
4846   3A3E 69 FE       OUT	ADC	#$FE		;CALC TRKS TO GO.
4847   3A40 CE 78 04    	DEC	CURTRK		;DECR CURRENT TRACK (OUT).
4848   3A43 C5 26       MINTST	CMP	TRKCNT
4849   3A45 90 02       	BCC	MAXTST		;  AND 'TRKS MOVED'.
4850   3A47 A5 26       	LDA	TRKCNT
4851   3A49 C9 0C       MAXTST	CMP	#$C
4852   3A4B 90 02       	BCC	STEP		;IF > $B, USE $B.
4853   3A4D A9 0B       	LDA	#$B
4854   3A4F A8          STEP	TAY			;ACCELLERATION INDEX.
4855   3A50 AD 78 04    	LDA	CURTRK
4856   3A53 29 03       	AND	#$3		;INDEX TO 'CURRENT
4857   3A55 0A          	ASLA			;   PHASE' OF 4-PHASE
4858   3A56 05 2B       	ORA	SLOTTEMP	;  STEPPER.
4859   3A58 AA          	TAX	
4860   3A59 BD 81 C0    	LDA	PHASEON,X	;HIT NEXT PHASE
4861   3A5C B9 90 3A    	LDA	ONTABLE,Y	;  FOR 'ONTIME'.
4862   3A5F 20 7F 3A    	JSR	MSWAIT		;(100 USEC INTERVALS)
4863   3A62 A5 27       	LDA	PRIOR
4864   3A64 29 03       	AND	#$3		;INDEX TO 'PRIOR PHASE'
4865   3A66 0A          	ASLA			;    OF 4-PHASE STEPPER.
4866   3A67 05 2B       	ORA	SLOTTEMP
4867   3A69 AA          	TAX	
4868   3A6A BD 80 C0    	LDA	PHASEOFF,X	;PRIOR PHASE OFF,
4869   3A6D B9 9C 3A    	LDA	OFFTABLE,Y	;  THEN WAIT 'OFFTIME'.
4870   3A70 20 7F 3A    	JSR	MSWAIT		;(100 USEC INTERVALS)
4871   3A73 E6 26       	INC	TRKCNT		;'TRACKS MOVED' COUNT.
4872   3A75 D0 B4       	BNE	SEEK2		;(ALWAYS TAKEN)
4873   3A77 A9 FF       SEEKEND	LDA	#$FF		;DELAY 9.5 MSEC FOR
4874   3A79 20 7F 3A    	JSR	MSWAIT		;   SETTLING TIME.
4875   3A7C A6 2B       	LDX	SLOTTEMP	;RESTORE X-REG.
4876   3A7E 60          SEEKXIT	RTS			;RETURN.

Page    106    APPLE DOS 3.1

4877   3A7F             	EJECT
4878   3A7F             **************************
4879   3A7F             *                        *
4880   3A7F             *   MSWAIT SUBROUTINE    *
4881   3A7F             *                        *
4882   3A7F             **************************
4883   3A7F             *                        *
4884   3A7F             *  DELAYS A SPECIFIED    *
4885   3A7F             *   NUMBER OF 100 USEC   *
4886   3A7F             *   INTERVALS FOR MOTOR  *
4887   3A7F             *   ON TIMING.           *
4888   3A7F             *                        *
4889   3A7F             *   ---- ON ENTRY ----   *
4890   3A7F             *                        *
4891   3A7F             *  A-REG: HOLDS NUMBER   *
4892   3A7F             *        OF 100 USEC     *
4893   3A7F             *        INTERVALS TO    *
4894   3A7F             *        DELAY.          *
4895   3A7F             *                        *
4896   3A7F             *   ---- ON EXIT -----   *
4897   3A7F             *                        *
4898   3A7F             *  A-REG: HOLDS $00.     *
4899   3A7F             *  X-REG: HOLDS $00.     *
4900   3A7F             *  Y-REG: UNCHANGED.     *
4901   3A7F             *  CARRY: SET.           *
4902   3A7F             *                        *
4903   3A7F             *  MONTIMEL, MONTIMEH    *
4904   3A7F             *   ARE INCREMENTED ONCE *
4905   3A7F             *   PER 100 USEC INTERVAL*
4906   3A7F             *   FOR MOTON ON TIMING. *
4907   3A7F             *                        *
4908   3A7F             *   ---- ASSUMES ----    *
4909   3A7F             *                        *
4910   3A7F             *   1 USEC CYCLE TIME    *
4911   3A7F             *                        *
4912   3A7F             **************************
4913   3A7F A2 11       MSWAIT	LDX	#$11
4914   3A81 CA          MSW1	DEX			;DELAY 86 USEC.
4915   3A82 D0 FD       	BNE	MSW1
4916   3A84 E6 46       	INC	MONTIMEL
4917   3A86 D0 02       	BNE	MSW2		;DOUBLE-BYTE
4918   3A88 E6 47       	INC	MONTIMEH	;  INCREMENT.
4919   3A8A 38          MSW2	SEC
4920   3A8B E9 01       	SBC	#$1		;DONE 'N' INTERVALS?
4921   3A8D D0 F0       	BNE	MSWAIT		;(A-REG COUNTS)
4922   3A8F 60          	RTS

Page    107    APPLE DOS 3.1

4923   3A90             	EJECT
4924   3A90             **************************
4925   3A90             *                        *
4926   3A90             *  PHASE ON-, OFF-TIME   *
4927   3A90             *   TABLES IN 100-USEC   *
4928   3A90             *   INTERVALS. (SEEK)    *
4929   3A90             *                        *
4930   3A90             **************************
4931   3A90 01 30 28    ONTABLE	DB	$01,$30,$28
4932   3A93 24 20 1E    	DB	$24,$20,$1E
4933   3A96 1D 1C 1C    	DB	$1D,$1C,$1C
4934   3A99 1C 1C 1C    	DB	$1C,$1C,$1C
4935   3A9C 70 2C 26    OFFTABLE DB	$70,$2C,$26
4936   3A9F 22 1F 1E    	DB	$22,$1F,$1E
4937   3AA2 1D 1C 1C    	DB	$1D,$1C,$1C
4938   3AA5 1C 1C 1C    	DB	$1C,$1C,$1C

Page    108    APPLE DOS 3.1

4939   3AA8             	EJECT
4940   3AA8             **************************
4941   3AA8             *                        *
4942   3AA8             *     7-BIT TO 5-BIT     *
4943   3AA8             *    'DENIBLIZE' TABL    *
4944   3AA8             *                        *
4945   3AA8             *      VALID CODES       *
4946   3AA8             *    $AB TO $FF ONLY.    *
4947   3AA8             *    ($DA NOT VALID)     *
4948   3AA8             *                        *
4949   3AA8             *   ---- CAUTION ----    *
4950   3AA8             *                        *
4951   3AA8             * INSURE THAT FOLLOWING  *
4952   3AA8             *     'RE-ORG' IS OK.    *
4953   3AA8             *                        *
4954   3AA8             **************************
4955   3AAB             	ORG	$3AAB
4956   3AAB             * OBJ $BAAB
4957   3AAB 00 01 08    	DB	$00,$01,$08
4958   3AAE 10 18 02    	DB	$10,$18,$02
4959   3AB1 03 04 05    	DB	$03,$04,$05
4960   3AB4 06 20 28    	DB	$06,$20,$28
4961   3AB7 30 07 09    	DB	$30,$07,$09
4962   3ABA 38 40 0A    	DB	$38,$40,$0A
4963   3ABD 48 50 58    	DB	$48,$50,$58
4964   3AC0 0B 0C 0D    	DB	$0B,$0C,$0D
4965   3AC3 0E 0F 11    	DB	$0E,$0F,$11
4966   3AC6 12 13 14    	DB	$12,$13,$14
4967   3AC9 15 16 17    	DB	$15,$16,$17
4968   3ACC 19 1A 1B    	DB	$19,$1A,$1B
4969   3ACF 1C 1D 1E    	DB	$1C,$1D,$1E
4970   3AD2 21 22 23    	DB	$21,$22,$23
4971   3AD5 24 60 68    	DB	$24,$60,$68
4972   3AD8 25 26 70    	DB	$25,$26,$70
4973   3ADB 78 27 80    	DB	$78,$27,$80
4974   3ADE 88 90 29    	DB	$88,$90,$29
4975   3AE1 2A 2B 2C    	DB	$2A,$2B,$2C
4976   3AE4 2D 2E 2F    	DB	$2D,$2E,$2F
4977   3AE7 31 32 33    	DB	$31,$32,$33
4978   3AEA 98 A0 34    	DB	$98,$A0,$34
4979   3AED A8 B0 B8    	DB	$A8,$B0,$B8
4980   3AF0 35 36 37    	DB	$35,$36,$37
4981   3AF3 39 3A C0    	DB	$39,$3A,$C0
4982   3AF6 C8 D0 3B    	DB	$C8,$D0,$3B
4983   3AF9 3C D8 E0    	DB	$3C,$D8,$E0
4984   3AFC 3E E8 F0    	DB	$3E,$E8,$F0
4985   3AFF F8          	DB	$F8

Page    109    APPLE DOS 3.1

4986   3B00             	EJECT
4987   3B00             **************************
4988   3B00             *                        *
4989   3B00             *     5-BIT TO 7-BIT     *
4990   3B00             *     NIBL CONVERSION    *
4991   3B00             *          TABLE         *
4992   3B00             *                        *
4993   3B00             **************************
4994   3B00             *                        *
4995   3B00             *     CODES $AA, $D5     *
4996   3B00             *        NOT USED        *
4997   3B00             *                        *
4998   3B00             **************************
4999   3C9A             	ORG	$3C9A
5000   3C9A             * OBJ $BC9A
5001   3C9A AB AD AE    NIBL	DB	$AB,$AD,$AE
5002   3C9D AF B5 B6    	DB	$AF,$B5,$B6
5003   3CA0 B7 BA BB    	DB	$B7,$BA,$BB
5004   3CA3 BD BE BF    	DB	$BD,$BE,$BF
5005   3CA6 D6 D7 DA    	DB	$D6,$D7,$DA
5006   3CA9 DB DD DE    	DB	$0DB,$DD,$DE
5007   3CAC DF EA EB    	DB	$DF,$EA,$EB
5008   3CAF ED EE EF    	DB	$ED,$EE,$EF
5009   3CB2 F5 F6 F7    	DB	$F5,$F6,$F7
5010   3CB5 FA FB FD    	DB	$FA,$FB,$FD
5011   3CB8 FE FF       	DB	$FE,$FF
5012   3CBA 1C 1C 1C    	DB	$1C,$1C,$1C
5013   3CBD             *
5014   3CBD 00 00 00    	DB	$00,$00,$00
5015   3CC0 A4 2D B9 D0 	DB	$A4,$2D,$B9,$D0,$3C,$A0,$05,$4C
5015   3CC4 3C A0 05 4C 
5016   3CC8 0A 3E 00 00 	DB	$0A,$3E,$00,$00,$00,$00,$00,$00
5016   3CCC 00 00 00 00 
5017   3CD0 00 05 0A 02 	DB	$00,$05,$0A,$02,$07,$0C,$04,$09
5017   3CD4 07 0C 04 09 
5018   3CD8 01 06 0B 03 	DB	$01,$06,$0B,$03,$08,$00,$00,$00
5018   3CDC 08 00 00 00 
5019   3CE0 00 00 00 00 	DB	$00,$00,$00,$00,$00,$00,$00,$00
5019   3CE4 00 00 00 00 
5020   3CE8 00 00 00 00 	DB	$00,$00,$00,$00,$00,$00,$00,$00
5020   3CEC 00 00 00 00 
5021   3CF0 00 00 00 00 	DB	$00,$00,$00,$00,$00,$00,$00,$00
5021   3CF4 00 00 00 00 
5022   3CF8 00 00 00 00 	DB	$00,$00,$00,$00,$00,$00,$00,$00
5022   3CFC 00 00 00 00 
5023   3D00             **************************
5024   3D00             *                        *
5025   3D00             *    RWTS ENTRY POINT    *
5026   3D00             *                        *
5027   3D00             **************************
5028   3D00             VOLFND	EQU	$2F
5029   3D00             TRKFND	EQU	$2E
5030   3D00             SECFND	EQU	$2D
5031   3D00             DRIVNO	EQU	$35
5032   3D00             DEVCTBL	EQU	$3C
5033   3D00             FMTTRKC	EQU	$41
5034   3D00             IOBPL	EQU	$48
5035   3D00             FMTMASK	EQU	$4A
5036   3D00             FMTSEC	EQU	$4B
5037   3D00             RETRYCNT EQU	$578
5038   3D00             SLOT	EQU	$5F8
5039   3D00             SETWRT	EQU	$C08F
5040   3D00             SETRD	EQU	$C08E
5041   3D00             WRTDAT	EQU	$C08D
5042   3D00             RDDATA	EQU	$C08C
5043   3D00             DRVSL2	EQU	$C08B
5044   3D00             DRVSL1	EQU	$C08A
5045   3D00             DRVON	EQU	$C089
5046   3D00             DRVOFF	EQU	$C088
5047   3D00             PHASE1OFF EQU	$C082
5048   3D00             PHASE2OFF EQU	$C084
5049   3D00             PHASE3OFF EQU	$C086
5050   3D00             	ORG	DISKIO
5051   3D00             * OBJ $BD00
5052   3D00             RWTS
5053   3D00 84 48       	STY	IOBPL		;SAVE IOB ADDRESS
5054   3D02 85 49       	STA	IOBPL+1
5055   3D04 A0 01       	LDY	#$1		;GET NEW SLOT #
5056   3D06 B1 48       	LDA	(IOBPL),Y
5057   3D08 AA          	TAX			;SAVE SLOT # TO X
5058   3D09 8C F8 04    	STY	$4F8		;SET SEEK CNT=1
5059   3D0C A0 0F       	LDY	#$F		;SEE IF SLOT HAS CHANGED
5060   3D0E D1 48       	CMP	(IOBPL),Y
5061   3D10 F0 1B       	BEQ	L3D2D		;BR IF SAME SLOT
5062   3D12 8A          	TXA			;SAVE NEW SLOT #
5063   3D13 48          	PHA
5064   3D14 B1 48       	LDA	(IOBPL),Y	;GET OLD SLOT #
5065   3D16 AA          	TAX
5066   3D17 68          	PLA			
5067   3D18 48          	PHA			;NEW SLOT # BACK TO STACK
5068   3D19 91 48       	STA	(IOBPL),Y	;SET NEW SLOT NUMBER
5069   3D1B BD 8E C0    	LDA	SETRD,X		;SET READ MODE
5070   3D1E             L3D1E
5071   3D1E A0 08       	LDY	#$8		;DELAY UNTIL DATA IS STABLE
5072   3D20 BD 8C C0    	LDA	RDDATA,X
5073   3D23             L3D23
5074   3D23 DD 8C C0    	CMP	RDDATA,X
5075   3D26 D0 F6       	BNE	L3D1E		;BR IF DRIVE STILL SPINNING
5076   3D28 88          	DEY
5077   3D29 D0 F8       	BNE	L3D23		;LONG ENOUGH? BR UNTIL OLD DRIVE OFF
5078   3D2B 68          	PLA			;GET NEW SLOT #
5079   3D2C AA          	TAX
5080   3D2D             L3D2D
5081   3D2D BD 8E C0    	LDA	SETRD,X		;INSURE IN READ MODE
5082   3D30 BD 8C C0    	LDA	RDDATA,X	;GET THE DATA
5083   3D33 BD 8C C0    	LDA	RDDATA,X
5084   3D36 48          	PHA			;DELAY FOR DISK DATA TO CHANGE
5085   3D37 68          	PLA
5086   3D38 8E F8 05    	STX	SLOT		;SET SLOT
5087   3D3B DD 8C C0    	CMP	RDDATA,X	;CHECK RUNNING
5088   3D3E 08          	PHP			;SAVE CHECK RESULTS TO STACK
5089   3D3F BD 89 C0    	LDA	DRVON,X		;TURN DRIVE ON
5090   3D42 A0 06       	LDY	#$6		;MOVE IBDCTP & IBBUFP PTRS TO PAGE 0
5091   3D44             L3D44
5092   3D44 B1 48       	LDA	(IOBPL),Y
5093   3D46 99 36 00    	STA	$0036,Y		;PTRS DESTINATION ON PG 0
5094   3D49 C8          	INY
5095   3D4A C0 0A       	CPY	#$A		;ALL PTRS MOVED?
5096   3D4C D0 F6       	BNE	L3D44		;MOVE MORE IF NOT
5097   3D4E A0 02       	LDY	#2		;GET DRIVE #
5098   3D50 B1 48       	LDA	(IOBPL),Y
5099   3D52 A0 10       	LDY	#$10		;SAME DRIVE USED BEFORE?
5100   3D54 D1 48       	CMP	(IOBPL),Y
5101   3D56 F0 06       	BEQ	L3D5E		;BR IS SO
5102   3D58 91 48       	STA	(IOBPL),Y	;ELSE SET CURR DRV #
5103   3D5A 28          	PLP			;RESTORE CHECK RUNNING STATUS
5104   3D5B A0 00       	LDY	#$0		;SET Z FLAG
5105   3D5D 08          	PHP
5106   3D5E             L3D5E
5107   3D5E 6A          	RORA			;BY GOING INTO CARRY
5108   3D5F BD 8A C0    	LDA	DRVSL1,X	;SELECT DRIVE 1
5109   3D62 B0 03       	BCS	L3D67		;CARRY STILL SET - DRIVE 1 IT IS
5110   3D64 BD 8B C0    	LDA	DRVSL2,X	;ELSE SELECT DRIVE 2
5111   3D67             L3D67
5112   3D67 66 35       	ROR	DRIVNO		;SAVE SELECTED DRV TO PG 0
5113   3D69 A0 02       	LDY	#$2		;GET MOT ON TIME LO FROM DEVCTBL
5114   3D6B B1 3C       	LDA	(DEVCTBL),Y
5115   3D6D 85 46       	STA	MONTIMEL	;SAVE LO
5116   3D6F C8          	INY
5117   3D70 B1 3C       	LDA	(DEVCTBL),Y	;GET MOT ON TIME HI FROM DEVCTBL
5118   3D72 85 47       	STA	MONTIMEH	;SAVE HI
5119   3D74 C8          	INY			;Y=4, SET TO IOB TRK
5120   3D75 B1 48       	LDA	(IOBPL),Y	;GET DESIRED TRACK
5121   3D77 20 3B 3E    	JSR	MYSEEK		;GO SEEK
5122   3D7A 28          	PLP			;WAS MOTOR ON?
5123   3D7B D0 0D       	BNE	L3D8A		;SKIP DELAY AND TRY TRACK IF SO
5124   3D7D             L3D7D
5125   3D7D A0 12       	LDY	#$12		;DELAY 100 USEC PER COUNT
5126   3D7F             L3D7F
5127   3D7F 88          	DEY
5128   3D80 D0 FD       	BNE	L3D7F
5129   3D82 E6 46       	INC	MONTIMEL
5130   3D84 D0 F7       	BNE	L3D7D
5131   3D86 E6 47       	INC	MONTIMEH
5132   3D88 D0 F3       	BNE	L3D7D		;COUNT UP TO $0000
5133   3D8A             *
5134   3D8A             * DISK IS UP TO SPEED
5135   3D8A             * IF NOT FORMAT, LOCATE CORRECT SECTOR
5136   3D8A             *
5137   3D8A             L3D8A
5138   3D8A A0 0C       	LDY	#$C
5139   3D8C B1 48       	LDA	(IOBPL),Y	;GET COMMAND CODE #
5140   3D8E F0 55       	BEQ	L3DE5		;BR IF NULL COMMAND
5141   3D90 C9 04       	CMP	#$4		;FORMAT?
5142   3D92 F0 53       	BEQ	L3DE7		;BR IF SO
5143   3D94 6A          	RORA			;SET CARRY=1 FOR READ, 0 FOR WRITE
5144   3D95 08          	PHP			;AND SAVE THAT
5145   3D96 B0 03       	BCS	L3D9B		;BR IF READ
5146   3D98 20 00 38    	JSR	PRENIBL		;MUST PRENIBBLIZE FOR WRITE
5147   3D9B             L3D9B
5148   3D9B A0 30       	LDY	#$30		;48 RETRIES
5149   3D9D 8C 78 05    	STY	RETRYCNT	;SAVE RETRY COUNT
5150   3DA0             L3DA0
5151   3DA0 AE F8 05    	LDX	SLOT		;GET SLOT # INTO X
5152   3DA3 20 65 39    	JSR	RDADR		;READ NEXT ADDRESS FIELD
5153   3DA6 90 1F       	BCC	L3DC7		;BR IF GOOD READ
5154   3DA8             L3DA8
5155   3DA8 CE 78 05    	DEC	RETRYCNT	;DEC RETRY COUNT
5156   3DAB 10 F3       	BPL	L3DA0		;IF HAVEN'T TRIED ENOUGH, TRY AGAIN
5157   3DAD AD 78 04    	LDA	$478		;GET TRACK WE WANT
5158   3DB0 48          	PHA			;SAVE IT
5159   3DB1 A9 60       	LDA	#$60		;RECALIBRATE TO TRK 96
5160   3DB3 20 82 3E    	JSR	L3E82
5161   3DB6 CE F8 04    	DEC	$4F8		;ONCE TOO MANY?
5162   3DB9 D0 23       	BNE	L3DDE		;TRIED TO RECAL TOO MANY
5163   3DBB A9 00       	LDA	#$0		;MOVE TO TRK 0
5164   3DBD 20 3B 3E    	JSR	MYSEEK
5165   3DC0 68          	PLA
5166   3DC1             L3DC1
5167   3DC1 20 3B 3E    	JSR	MYSEEK		;GO TO CORRECT TRACK
5168   3DC4 4C 9B 3D    	JMP	L3D9B		;LOOP BACK, TRY AGAIN ON THIS TRK
5169   3DC7             L3DC7
5170   3DC7 A4 2E       	LDY	TRKFND		;ON THE RIGHT TRACK?
5171   3DC9 CC 78 04    	CPY	$478
5172   3DCC F0 22       	BEQ	L3DF0		;BR IF SO
5173   3DCE AD 78 04    	LDA	$478		;SAVE DESTINATION TRK
5174   3DD1 48          	PHA
5175   3DD2 98          	TYA
5176   3DD3 20 82 3E    	JSR	L3E82
5177   3DD6 68          	PLA
5178   3DD7 CE 78 05    	DEC	RETRYCNT	;SHOULD WE RESEEK?
5179   3DDA 10 E5       	BPL	L3DC1		;YES - RESEEK
5180   3DDC 30 CA       	BMI	L3DA8		;NO - RECALIBRATE
5181   3DDE             L3DDE
5182   3DDE 68          	PLA			;REMOVE CURTRK
5183   3DDF A9 40       	LDA	#$40		;BAD DRIVE ERROR
5184   3DE1             L3DE1
5185   3DE1 28          	PLP
5186   3DE2 4C 29 3E    	JMP	L3E29		;GO HANDLE ERROR
5187   3DE5             L3DE5
5188   3DE5 F0 40       	BEQ	L3E27		;ALL DONE
5189   3DE7             L3DE7
5190   3DE7 A0 03       	LDY	#$3		;GET VOLUME #
5191   3DE9 B1 48       	LDA	(IOBPL),Y
5192   3DEB 85 2F       	STA	VOLFND		;SAVE TO PG 0
5193   3DED 4C 9C 3E    	JMP	DSKFORM		;GO FORMAT
5194   3DF0             L3DF0
5195   3DF0 A0 03       	LDY	#$3		;IS THE RIGHT DISK IN?
5196   3DF2 B1 48       	LDA	(IOBPL),Y	;GET DESIRED VOLUME
5197   3DF4 48          	PHA			;SAVE VOLUME #
5198   3DF5 A5 2F       	LDA	VOLFND		;GET ACTUAL VOLUME
5199   3DF7 A0 0E       	LDY	#$E		;INDICATE VOLUME FOUND
5200   3DF9 91 48       	STA	(IOBPL),Y
5201   3DFB 68          	PLA			;GET DESIRED VOLUME BACK
5202   3DFC F0 08       	BEQ	L3E06		;DESIRED VOLUME MATCHES ALL
5203   3DFE C5 2F       	CMP	VOLFND
5204   3E00 F0 04       	BEQ	L3E06		;YES...IT WAS CORRECT
5205   3E02 A9 20       	LDA	#$20		;SOMEONE SWITCHED DISKS!
5206   3E04 D0 DB       	BNE	L3DE1		;ALWAYS
5207   3E06             L3E06
5208   3E06 A0 05       	LDY	#$5		;TO ALLOW FOR INTERLEAVE
5209   3E08 A5 2D       	LDA	SECFND		;GET REQUESTED LOGICAL SECTOR
5210   3E0A             L3E0A
5211   3E0A D1 48       	CMP	(IOBPL),Y
5212   3E0C F0 09       	BEQ	L3E17		;FOUND OUR DESIRED SECTOR
5213   3E0E CE 78 05    	DEC	RETRYCNT	;ADJUST RETRY COUNT
5214   3E11 10 8D       	BPL	L3DA0
5215   3E13 A9 80       	LDA	#$80
5216   3E15 D0 CA       	BNE	L3DE1		;NO, KEEP TRYING
5217   3E17             *
5218   3E17             * SECTOR FOUND
5219   3E17             *
5220   3E17             L3E17
5221   3E17 28          	PLP			;GOT OUR SECTOR
5222   3E18 90 18       	BCC	L3E32		;CARRY WAS SET FOR WRITE OPERATION
5223   3E1A 20 FD 38    	JSR	READ		;GO READ
5224   3E1D 08          	PHP			;SAVE STATUS OF READ OPERATION
5225   3E1E B0 88       	BCS	L3DA8		;CARRY SET IF BAD READ
5226   3E20 28          	PLP			;ADJUST STACK
5227   3E21 20 C1 39    	JSR	POSTNIB		;DECODE INTO REAL DATA
5228   3E24 AE F8 05    	LDX	SLOT		;GET SLOT # INTO X
5229   3E27             L3E27
5230   3E27 18          	CLC			;INDICATE NO ERROR
5231   3E28 24          	DB	$24		;SKIP NEXT SEC TO MAINTAIN NO ERROR
5232   3E29             L3E29				;   DO USELESS BIT INSTR INSTEAD
5233   3E29 38          	SEC			;INDICATE AN ERROR
5234   3E2A A0 0D       	LDY	#$D		;SET ERROR #
5235   3E2C 91 48       	STA	(IOBPL),Y
5236   3E2E BD 88 C0    	LDA	DRVOFF,X	;TURN DRV MOTOR OFF
5237   3E31 60          	RTS
5238   3E32             L3E32
5239   3E32 20 6A 38    	JSR	WRITE		;WRITE NIBBLES NOW
5240   3E35 90 F0       	BCC	L3E27		;BR IF NO ERRORS
5241   3E37 A9 10       	LDA	#$10		;DISK IS WRITE PROTECTED
5242   3E39 B0 EE       	BCS	L3E29		;ALWAYS!
5243   3E3B             **************************
5244   3E3B             *                        *
5245   3E3B             *      SEEK ROUTINE      *
5246   3E3B             *                        *
5247   3E3B             *   SEEKS TRACK 'N' IN   *
5248   3E3B             *       SLOT #X/16       *
5249   3E3B             * IF DRIVNO IS NEGATIVE, *
5250   3E3B             *       ON DRIVE 1       *
5251   3E3B             * IF DRIVNO IS POSITIVE, *
5252   3E3B             *       ON DRIVE 2       *
5253   3E3B             *                        *
5254   3E3B             **************************
5255   3E3B             MYSEEK
5256   3E3B 48          	PHA			;PRESERVE ACC
5257   3E3C A0 01       	LDY	#$1		;TWO PHASE DISK?
5258   3E3E B1 3C       	LDA	(DEVCTBL),Y
5259   3E40 6A          	RORA			;GET # OF PHASES INTO CARRY
5260   3E41 68          	PLA
5261   3E42 90 08       	BCC	L3E4C		;BR IF 1 PHASE PER TRK
5262   3E44 0A          	ASLA
5263   3E45 20 4C 3E    	JSR	L3E4C
5264   3E48 4E 78 04    	LSR	$478		;DIVIDE BACK DOWN
5265   3E4B 60          	RTS
5266   3E4C             *
5267   3E4C             L3E4C
5268   3E4C 85 2E       	STA	TRKFND		;SAVE DEST TRACK (*2)
5269   3E4E BD 80 C0    	LDA	PHASEOFF,X
5270   3E51 BD 82 C0    	LDA	PHASE1OFF,X
5271   3E54 BD 84 C0    	LDA	PHASE2OFF,X
5272   3E57 BD 86 C0    	LDA	PHASE3OFF,X
5273   3E5A 20 7B 3E    	JSR	L3E7B
5274   3E5D B9 78 04    	LDA	$478,Y
5275   3E60 24 35       	BIT	DRIVNO		;IF MINUS, ON DRV 0
5276   3E62 30 03       	BMI	L3E67
5277   3E64 B9 F8 04    	LDA	$4F8,Y		;ELSE GET DRV 1 TRACK
5278   3E67             L3E67
5279   3E67 8D 78 04    	STA	$478		;CURRENT TRACK
5280   3E6A A5 2E       	LDA	TRKFND		;DESTINATION TRACK
5281   3E6C 24 35       	BIT	DRIVNO		;UPDATE SLOT DEPENDENT 
5282   3E6E 30 05       	BMI	L3E75		;  LOCATIONS WITH TRACK
5283   3E70 99 F8 04    	STA	$4F8,Y		;  INFORMATION
5284   3E73 10 03       	BPL	L3E78		;ALWAYS!
5285   3E75 99 78 04    L3E75	STA	$478,Y
5286   3E78 4C 1E 3A    L3E78	JMP	SEEK		;GO SEEK
5287   3E7B             L3E7B
5288   3E7B 8A          	TXA			;SET Y=SLOT #
5289   3E7C 4A          	LSRA
5290   3E7D 4A          	LSRA
5291   3E7E 4A          	LSRA
5292   3E7F 4A          	LSRA
5293   3E80 A8          	TAY
5294   3E81 60          	RTS
5295   3E82             *
5296   3E82             * SET SLOT DEPENDENT TRACK LOCATION
5297   3E82             *
5298   3E82             L3E82
5299   3E82 48          	PHA			;SAVE DEST TRACK
5300   3E83 A0 02       	LDY	#$2
5301   3E85 B1 48       	LDA	(IOBPL),Y
5302   3E87 6A          	RORA			;GET DRIVE # INTO CARRY
5303   3E88 66 35       	ROR	DRIVNO		;INTO (DRIVENO)
5304   3E8A 20 7B 3E    	JSR	L3E7B		;SETUP Y REG
5305   3E8D 68          	PLA
5306   3E8E 0A          	ASLA			;ASSUME TRACK IS HELD *2
5307   3E8F 24 35       	BIT	DRIVNO
5308   3E91 30 05       	BMI	L3E98		;IF ON DRIVE 1(1), DRIVNO MINUS
5309   3E93 99 F8 04    	STA	$4F8,Y		;SAVE DRV 2 TRACK
5310   3E96 10 03       	BPL	L3E9B		;ALWAYS
5311   3E98             L3E98
5312   3E98 99 78 04    	STA	$478,Y		;ELSE SAVE DRV 1 TRACK
5313   3E9B             L3E9B
5314   3E9B 60          	RTS
5315   3E9C             **************************
5316   3E9C             *                        *
5317   3E9C             *    FORMAT ROUTINE      *
5318   3E9C             *                        *
5319   3E9C             **************************
5320   3E9C             DSKFORM
5321   3E9C A9 80       	LDA	#$80		;FAKE DRV 0 TRACK
5322   3E9E 8D 78 04    	STA	$478
5323   3EA1 A9 00       	LDA	#$0		;SET TRACK TO 0
5324   3EA3 85 41       	STA	FMTTRKC		;SAVE FORMAT TRACK COUNTER
5325   3EA5 20 1E 3A    	JSR	SEEK		;GO THERE
5326   3EA8 A9 AA       	LDA	#$AA		;MASK FOR ODD-EVEN ENCODING
5327   3EAA 85 4A       	STA	FMTMASK		;SAVE TO PG 0
5328   3EAC A0 50       	LDY	#$50		;ATTEMPTS COUNT
5329   3EAE             L3EAE
5330   3EAE 84 47       	STY	MONTIMEH	;SAVE # OF ATTEMPTS
5331   3EB0 A9 27       	LDA	#$27		;39 SELF-SYNC NIBBLES
5332   3EB2 85 4B       	STA	FMTSEC		;SAVE COUNT
5333   3EB4 BD 8D C0    	LDA	WRTDAT,X	;TURN OFF WRITE
5334   3EB7 BD 8E C0    	LDA	SETRD,X
5335   3EBA             *
5336   3EBA             * WRITE GAP
5337   3EBA             *
5338   3EBA A9 FF       	LDA	#$FF		;GET SYNC BYTE
5339   3EBC 9D 8F C0    	STA	SETWRT,X	;WRITE IT
5340   3EBF DD 8C C0    	CMP	RDDATA,X	;READ IT BACK
5341   3EC2 24 00       	BIT	$0000
5342   3EC4             L3EC4
5343   3EC4 88          	DEY			;ADJUST WRITE ATTEMPTS
5344   3EC5 F0 0F       	BEQ	L3ED6		;BR IF GOOD WRITE
5345   3EC7 48          	PHA			;ELSE DELAY
5346   3EC8 68          	PLA
5347   3EC9 EA          	NOP
5348   3ECA             L3ECA
5349   3ECA 48          	PHA			;DELAY SOME MORE
5350   3ECB 68          	PLA
5351   3ECC EA          	NOP
5352   3ECD EA          	NOP
5353   3ECE 9D 8D C0    	STA	WRTDAT,X	;WRITE AGAIN
5354   3ED1 DD 8C C0    	CMP	RDDATA,X	;READ IT BACK
5355   3ED4 B0 EE       	BCS	L3EC4		;BR IF STILL NOT GOOD
5356   3ED6             L3ED6
5357   3ED6 C6 4B       	DEC	FMTSEC		;GOOD WRITE, SO DEC SYNC COUNT
5358   3ED8 D0 F0       	BNE	L3ECA		;WRITE NEXT
5359   3EDA A4 47       	LDY	MONTIMEH
5360   3EDC EA          	NOP
5361   3EDD EA          	NOP
5362   3EDE D0 06       	BNE	L3EE6		;BR IF MOTOR TIME GOOD
5363   3EE0             L3EE0
5364   3EE0 48          	PHA			;DELAYS
5365   3EE1 68          	PLA
5366   3EE2 48          	PHA
5367   3EE3 68          	PLA
5368   3EE4 C1 00       	CMP	($0000,X)
5369   3EE6             L3EE6
5370   3EE6 EA          	NOP			;DELAY
5371   3EE7             *
5372   3EE7             * WRITE SECTOR ROUTINE
5373   3EE7             *
5374   3EE7             L3EE7
5375   3EE7 9D 8D C0    	STA	WRTDAT,X
5376   3EEA DD 8C C0    	CMP	RDDATA,X
5377   3EED 88          	DEY
5378   3EEE D0 F0       	BNE	L3EE0
5379   3EF0             *
5380   3EF0             * WRITE ADDR FIELD PROLOGUE
5381   3EF0             *
5382   3EF0 A9 D5       	LDA	#$D5		;ADDR MARK 1
5383   3EF2 20 CA 3F    	JSR	WBYTE1
5384   3EF5 A9 AA       	LDA	#$AA		;ADDR MARK 2
5385   3EF7 20 CB 3F    	JSR	WBYTE
5386   3EFA A9 B5       	LDA	#$B5		;ADDR MARK 3
5387   3EFC 20 CB 3F    	JSR	WBYTE
5388   3EFF A5 2F       	LDA	VOLFND		;WRITE ODD-EVEN ENCODED VOLUME
5389   3F01 20 BB 3F    	JSR	EOWBYTE
5390   3F04 A5 41       	LDA	FMTTRKC		;WRITE ODD-EVEN ENCODED TRACK
5391   3F06 20 BB 3F    	JSR	EOWBYTE
5392   3F09 A5 4B       	LDA	FMTSEC		;WRITE ODD-EVEN ENCODED SECTOR
5393   3F0B 20 BB 3F    	JSR	EOWBYTE
5394   3F0E A5 2F       	LDA	VOLFND		;CALC CHECKSUM BY EOR'ING VOLUME,
5395   3F10 45 41       	EOR	FMTTRKC		;  TRACK, AND SECTOR
5396   3F12 45 4B       	EOR	FMTSEC
5397   3F14 48          	PHA
5398   3F15 4A          	LSRA
5399   3F16 05 4A       	ORA	FMTMASK		;WITH $AA
5400   3F18 9D 8D C0    	STA	WRTDAT,X	;WRITE CHECKSUM ODD BITS
5401   3F1B DD 8C C0    	CMP	RDDATA,X
5402   3F1E 68          	PLA
5403   3F1F 09 AA       	ORA	#$AA
5404   3F21 20 CA 3F    	JSR	WBYTE1		;WRITE CHECKSUM EVEN BITS
5405   3F24             *
5406   3F24             * WRITE ADDR FIELD EPILOGUE
5407   3F24             *
5408   3F24 A9 DE       	LDA	#$DE		;BIT-SLIP 1
5409   3F26 20 CB 3F    	JSR	WBYTE
5410   3F29 A9 AA       	LDA	#$AA		;BIT-SLIP 2
5411   3F2B 20 CB 3F    	JSR	WBYTE
5412   3F2E A9 EB       	LDA	#$EB		;BIT-SLIP 3
5413   3F30 20 CB 3F    	JSR	WBYTE
5414   3F33 A9 FF       	LDA	#$FF		;WRITE SYNC BYTE
5415   3F35 20 CB 3F    	JSR	WBYTE
5416   3F38             *
5417   3F38             * WRITE DATA FIELD
5418   3F38             *
5419   3F38 A0 02       	LDY	#$2		;WRITE IN TWO PASSES....
5420   3F3A 84 46       	STY	MONTIMEL
5421   3F3C A0 AD       	LDY	#$AD		;...OF 173 BYTES EACH PASS (346 BYTES)
5422   3F3E D0 06       	BNE	L3F46
5423   3F40             L3F40
5424   3F40 88          	DEY			;ADJUST # BYTES WRITTEN
5425   3F41 F0 0D       	BEQ	L3F50
5426   3F43 48          	PHA			;GET $FF DATA FIELD BYTE BACK
5427   3F44 68          	PLA			;RE-SAVE IT
5428   3F45 EA          	NOP			;DELAY SOME
5429   3F46             L3F46
5430   3F46 48          	PHA			;GET DATA BYE BACK
5431   3F47 68          	PLA			;RESAVE
5432   3F48 9D 8D C0    	STA	WRTDAT,X	;WRITE IT
5433   3F4B DD 8C C0    	CMP	RDDATA,X
5434   3F4E B0 F0       	BCS	L3F40		;WRITE SOME MORE
5435   3F50             L3F50
5436   3F50 C6 46       	DEC	MONTIMEL	;TWO PASSES COMPLETE?
5437   3F52 D0 F2       	BNE	L3F46		;DO ANOTHER PASS IF NOT
5438   3F54 A4 47       	LDY	MONTIMEH
5439   3F56 18          	CLC			;FOR ADC WITHOUT CARRY
5440   3F57 24 00       	BIT	$0000
5441   3F59 9D 8D C0    	STA	WRTDAT,X
5442   3F5C BD 8C C0    	LDA	RDDATA,X
5443   3F5F A5 4B       	LDA	FMTSEC		;GET SECTOR
5444   3F61 69 0A       	ADC	#$A		;3 SECTOR INTERLEAVE
5445   3F63 85 4B       	STA	FMTSEC		;RESAVE SECTOR
5446   3F65 E9 0C       	SBC	#$C		;13 SECTORS DONE?
5447   3F67 F0 0A       	BEQ	L3F73		;BR IF SO
5448   3F69 B0 01       	BCS	L3F6C		;MORE SECTORS TO WRITE
5449   3F6B 2C          	DB	$2C		;SKIP NEXT STA OF SECTOR, DO USELESS BIT INSTEAD
5450   3F6C             L3F6C
5451   3F6C 85 4B       	STA	FMTSEC
5452   3F6E A9 FF       	LDA	#$FF		;SYNC BYTE
5453   3F70 4C E7 3E    	JMP	L3EE7		;GO WRITE ANOTHER SECTOR
5454   3F73             L3F73
5455   3F73 48          	PHA			;GET DATA BYTE BACK
5456   3F74 68          	PLA			;AND RESAVE
5457   3F75 A4 47       	LDY	MONTIMEH
5458   3F77 BD 8D C0    	LDA	WRTDAT,X
5459   3F7A BD 8E C0    	LDA	SETRD,X		;TURN OFF WRITE MODE
5460   3F7D 30 34       	BMI	L3FB3
5461   3F7F 88          	DEY
5462   3F80             L3F80
5463   3F80 48          	PHA			;DELAYS
5464   3F81 68          	PLA
5465   3F82 EA          	NOP
5466   3F83 EA          	NOP
5467   3F84 24 00       	BIT	$0000
5468   3F86 48          	PHA
5469   3F87 68          	PLA
5470   3F88 88          	DEY
5471   3F89 D0 F5       	BNE	L3F80
5472   3F8B 20 65 39    	JSR	RDADR		;VERIFY SECTOR ADDRESS
5473   3F8E B0 04       	BCS	L3F94		;BR IF READ ADDRESS ERROR
5474   3F90 A5 2D       	LDA	SECFND
5475   3F92 F0 0A       	BEQ	L3F9E
5476   3F94             L3F94
5477   3F94 A4 47       	LDY	MONTIMEH	;GET TRACK FMT ATTEMPTS
5478   3F96 88          	DEY			;DEC ATTEMPTS MADE
5479   3F97 C0 10       	CPY	#$10		;DID WE TRY ENOUGH?
5480   3F99 90 18       	BCC	L3FB3		;BR IF ERROR ... WE TRIED ENOUGH
5481   3F9B 4C AE 3E    	JMP	L3EAE		;ELSE TRY AGAIN
5482   3F9E             L3F9E
5483   3F9E E6 41       	INC	FMTTRKC		;INC TRACK PTR
5484   3FA0 A5 41       	LDA	FMTTRKC		;GET NEXT TRACK
5485   3FA2 C9 23       	CMP	#$23		;DID WE DO ALL 35 TRACKS?
5486   3FA4 B0 12       	BCS	L3FB8		;BR IS SO
5487   3FA6 0A          	ASLA			;ELSE GO TO NEXT TRACK
5488   3FA7 20 1E 3A    	JSR	SEEK
5489   3FAA A4 47       	LDY	MONTIMEH	;ADJUST # OF ATTEMPTS
5490   3FAC C8          	INY
5491   3FAD C8          	INY
5492   3FAE 84 47       	STY	MONTIMEH
5493   3FB0 4C AE 3E    	JMP	L3EAE		;GO FORMAT NEXT TRACK
5494   3FB3             L3FB3
5495   3FB3 A9 40       	LDA	#$40		;ERROR
5496   3FB5 4C 29 3E    	JMP	L3E29
5497   3FB8             L3FB8
5498   3FB8 4C 27 3E    	JMP	L3E27		;ALL WENT WELL
5499   3FBB             *
5500   3FBB             * WRITE ODD BITS, THEN EVEN BITS OF A BYTE
5501   3FBB             *
5502   3FBB             EOWBYTE
5503   3FBB 48          	PHA			;SAVE IT
5504   3FBC 4A          	LSRA			;ODD BITS FIRST
5505   3FBD 05 4A       	ORA	FMTMASK		;WITH $AA
5506   3FBF 9D 8D C0    	STA	WRTDAT,X	;WRITE IT
5507   3FC2 DD 8C C0    	CMP	RDDATA,X
5508   3FC5 68          	PLA			;RESTORE BYTE
5509   3FC6 C1 00       	CMP	($0000,X)
5510   3FC8 09 AA       	ORA	#$AA		;GET EVEN BITS
5511   3FCA             **************************
5512   3FCA             *                        *
5513   3FCA             *  WRITE A BYTE TO DISK  *
5514   3FCA             *                        *
5515   3FCA             **************************
5516   3FCA             WBYTE1
5517   3FCA EA          	NOP
5518   3FCB             WBYTE
5519   3FCB 48          	PHA			;SAVE BYTE TO STACK
5520   3FCC 68          	PLA			;GET IT BACK
5521   3FCD EA          	NOP			;DELAY
5522   3FCE 9D 8D C0    	STA	WRTDAT,X	;WRITE IT
5523   3FD1 DD 8C C0    	CMP	RDDATA,X
5524   3FD4 60          	RTS
5525   3FD5             **************************
5526   3FD5             *                        *
5527   3FD5             *   FIX FOR A BUG WITH   * 
5528   3FD5             *      APPLESOFT II      *
5529   3FD5             *  READ/WRITE STATEMENTS *
5530   3FD5             *    (LINES GT 255 ARE   *
5531   3FD5             *        IGNORED!)       *
5532   3FD5             *                        *
5533   3FD5             **************************
5534   3FD5             ASRWPAT
5535   3FD5 E8          	INX			;BUMP HIGH BYTE OF LINE #
5536   3FD6 F0 01       	BEQ	ASRWP1		;BR IF HIGH AS WE CAN GO
5537   3FD8 60          	RTS			;ELSE LINE # GT 255, SO RETURN
5538   3FD9 4C DD 25    ASRWP1	JMP	ICFDB		;NOT RUN MODE - CLOSE FILE
5539   3FDC             *
5540   3FFF             	ORG	AEC2
5541   3FFF 00          	DB	0
5542   4000             	END

       Number of errors = 0
