;----------------------------------------------------------------------
;                            Master.s
;
;              This Makes the Master.com too run on the mux
;            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;----------------------------------------------------------------------
;
;
;          Source Code is Copyright 1995
;	 Kenny Aimes and Stephen J. Carden
;
;
;First pass dissembly done by Ken Aimes
;Second and third pass cleanup By Stephen J. Carden
;
;-----------------------------------------------------------------------
; Notes: o This source code MAY NOT be placed for download on any BBS's!
;        o "mea" is a macro that loads the address of the first field
;          into the pointer specified by the second field.
;-----------------------------------------------------------------------
; Assembler:  MADMAC (tm) ST Cross Assembler (Atari Corp)
;             XASM   st and IBM VERSIONS
;-----------------------------------------------------------------------
;=====================================================================

com_file_name:		.macro
;			dc.b   13,"filename.ext",$9b
			dc.b   12,"Master.com  ",$9b
			.endm

;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; File revision history. Version Number in hex
;
file_ver:		equ   $34
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the Month in dec for the first time this revision 
;was compiled
;
c_month:		equ   10
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the day in dec for the first time this revision 
;was compiled
c_day:			equ   5
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; the year in dec for the first time this revision 
;was compiled
c_year:			equ   2012
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Type of compiler used in program
;
; 0 = unknown Compiler
; 1 = xasm
; 2 = mac_65
; 3 = basic
; 4 = compiled basic xl
; 5 = C65
; 6 = Action
;
; We can add more as time goes on!
;
;
;
xasm:			equ	1
mac_65:			equ	2 
basic:			equ	3
basicxl:		equ	4
c65:			equ	5
action:			equ	6

file_compiler:		equ	xasm
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; is this relocatable code ?
; anyother value other than 1 or 2 would be unknown
r..yes:			equ	1
r..no:			equ	2
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Gotta define if it can be relocated
l_relocatable:		equ	r..no
;
;
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Gotta define if it can be relocated
r..crl:			equ	$7d
r..crlf:		equ	$9b
r..space:		equ	$20

l_frstscreenbyte:	equ	r..space
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; The language the output file is in. 
;
;
; 0	=	Undifined
; 1	=	English
; 2	=	German
;
r..language:		equ	1
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


;----------------------------
;
;     Zero Page Equates
;----------------------------
;
cb:             equ     $cb
cd:             equ     $cd

;        System Equates
;----------------------------
;
lnflg:          equ    $00
casini:         equ    $02
ramlo:          equ    $04
tramsz:         equ    $06
boot.:          equ    $09
dosvec:         equ    $0a
pokmsk:         equ    $10
brkkey:         equ    $11
rtclok:         equ    $12
bufadr:         equ    $15
status:         equ    $30
chksum:         equ    $31
bufrlo:         equ    $32
bfenlo:         equ    $34
critic:         equ    $42
zdrva:          equ    $45
zchain:         equ    $4a
atract:         equ    $4d
drkmsk:         equ    $4e
lmargn:         equ    $52
colcrs:         equ    $55
dindex:         equ    $57
oldrow:         equ    $5a
oldadr:         equ    $5e
palnts:         equ    $62
vtimr1:         equ    $0210
cdtmv1:         equ    $0218
cdtma1:         equ    $0226
sdlstl:         equ    $0230

lpenv:          equ    $0235
cdevic:         equ    $023a
ccomnd:         equ    $023b
caux1:          equ    $023c

pdvmsk:         equ    $0247
shpdvs:         equ    $0248
pptmpx:         equ    $024d
dretry:         equ    $02bd
color1:         equ    $02c5
color2:         equ    $02c6
color4:         equ    $02c8
ch:             equ    $02fc
ddevic:         equ    $0300
dunit:          equ    $0301
dcomnd:         equ    $0302
dstats:         equ    $0303
dbuflo:         equ    $0304

dtimlo:         equ    $0306
dbytlo:         equ    $0308

daux1:          equ    $030a

timer1:         equ    $030c
temp1:          equ    $0312
temp2:          equ    $0313
temp3:          equ    $0315
savio:          equ    $0316
stackp:         equ    $0318
tstat:          equ    $0319

iccom:          equ    $0342
icbal:          equ    $0344
icbll:          equ    $0348
icax1:          equ    $034a

serin:          equ    $d20d
irqst:          equ    $d20e
skstat:         equ    $d20f
audf3:          equ    $d204
audf4:          equ    $d206
audc4:          equ    $d207
audctl:         equ    $d208
skres:          equ    $d20a
serout:         equ    $d20d
irqen:          equ    $d20e
skctl:          equ    $d20f
porta:          equ    $d300
portb:          equ    $d301
pactl:          equ    $d302
pbctl:          equ    $d303
nmien:          equ    $d40e
consol:         equ    $d01f
ciov:           equ    $e456
siov:           equ    $e459
setvbv:         equ    $e45c
;----------------------------
;
; External reference Equates
;----------------------------

PBIbank:           equ    $d1ff  ; pbi control line
;
;Cart stuff for the mux
;  
d570:           equ    $d570
d571:           equ    $d571
d572:           equ    $d572
d573:           equ    $d573
d57b:           equ    $d57b
d57c:           equ    $d57c
d57d:           equ    $d57d
d57e:           equ    $d57e


;
;
d805:           equ    $d805
;
;
		.include globals


                .org  $2fbb
;========================================= 
;       Beginning and initialization 
;========================================= 
;
;
START_IT:
		LDA COMTAB  ; calc address of SIO 
		SEC 
		SBC # low lsio
		STA XSIO+1
		LDA COMTAB+1
		SBC # high lsio
		STA XSIO+2
		lda	#$6c
		sta	xsio
		JMP top

XSIO:		jMP siov

;
;$2fd5
;  Stuff added so I can use any os I wish.
c73a:		lda	dbuflo		;$304
		sta	bufadr		; $15
        	lda	dbuflo+1	;$305
		sta	bufadr+1	; $16
		rts

c9af:		dex
		bpl	c9bb
		lda	#$00
		sta	shpdvs
		sta	PBIbank
		rts

c9bb:		lda	pdvmsk
		and	ca21,x
		beq	c9af
		sta	shpdvs
		sta	PBIbank
		rts

ca21:		dc.b	$80,$40,$20,$10,$08,$04,$02,$01


;
;
;
line1:		dc.b	<internal>, <+128>," The Multiplexer! V3.4 Stephen J. Carden"
line2:		dc.b	<internal>, <+128>," Active:"
l3033:		dc.b	<internal>, <+128>,"c  Drive:"
l303c:		dc.b	<internal>, <+128>,"1  Slave:"
l3045:		dc.b	<internal>, <+128>,"1  Pipe:"
l304d:		dc.b	<internal>, <+128>,"00 "
L3050:		dc.b	<internal>, <+128>,"   "
line3:		dc.b	<internal>, <+128>,"Loc"
L3056:		dc.b	<internal>, <+128>,"k 1:  2:  3:  4:  5:  6:  7:  8:  9: "
line4:		dc.b	<internal>, <+128>,"Errors:"
l3082:		dc.b   	<internal>, <+128>,"                      Count:"
l309e:		dc.b	<internal>, <+128>,"0000 "
;
dlist:		dc.b	$70,$70,$70,$70,$70,$70,$70,$70,$42
		dc.w	line1
		dc.b	$70,2,$50,2,$50,2,$41
		dc.w	dlist
;
;
;
data:		ds.b	256


variables:
		dc.b	$22
l31b8:		dc.b	0,0,0,0,0,0,0,0
		dc.b	0,0,0,0,0,0,0,0
l31c8:		dc.b	0,0,0,0,0,0,0,0
		dc.b	0,0,0,0,0,0,0,0
l31d8:		dc.b	0
l31d9:		dc.b	0
l31da:		dc.b	0
l31db:		dc.b	0
l31dc:		dc.b	0
l31dd:		dc.b	0,0
l31df:		dc.b	0
l31e0:		dc.b	1
l31e1:		dc.b	0
l31e2:		dc.b	0
l31e3:		dc.b	0
l31e4:		dc.b	0
l31e5:		dc.b	0
l31e6:		dc.b	0,0,0,0,0,0,0,0
		dc.b	0,0,0,0,0,0,0
l31f5:		dc.b	0
l31f6:		dc.b	0,0,0,0,0,0,0,0
		dc.b	0,0,0,0,0,0
l3204:		dc.b	0
l3205:		dc.b	0
		dc.b	0,0,0,0,0,0,0,0
;

init_pia:
		lda	#$ff
		sta	d57c
		lda	#0
		sta	d57b
		lda	#$7f
		sta	d57e
		lda	#$38
		sta	d572
		sta	d570
		lda	#$38
		sta	pactl
		lda	#$30
		sta	porta
		ldx	#$3c
		stx	pactl
		ldx	#$20
		stx	porta
		sta	porta
		lda	#$20
		sta	d570
		jmp	set_input
;
;
;
print:		stx	cb
		sty	cb+1
		ldy	#0
pr1:		lda	(cb),y
		sta	line4+7,y
		iny
		cpy	#$16
		bne	pr1
		inc	l31d8
		bne	l325c
		inc	l31d9
l325c:		lda	l31d9
		jsr	l441e
		sta	line4+35
		lda	l31d9
		jsr	l4422
		sta	line4+36
		lda	l31d8
		jsr	l441e
		sta	line4+37
		lda	l31d8
		jsr	l4422
		sta	line4+38
		rts
;
set_input:	lda	#0
		sta	d573
		lda	d570
		ora	#8
		sta	d570
		rts
;
set_output:	lda	#$ff
		sta	d573
		lda	d570
		and	#$f7
		sta	d570
		rts
;
time_out:	dc.b	<internal>, <+128>," Timeout in #"
l32aa:		dc.b	0
		dc.b	<internal>, <+128>," Sl.#"
sl_timeout:	dc.b	0,$80,$80
;
;
;
put_byte:	sta	d571
l32b6:		bit	d57d
		bpl	l32b6
		rts
;
bb_mio_off:	cli
		cld
		lda	#0
		sta	PBIbank
		lda	error_num
		and	#$0f
		ora	#$90
		sta	l32aa
		lda	l31dd
		ora	#$90
		sta	sl_timeout
		lda	l31dd
		ora	#$30
		sta	slave_num
		bit	l3ded
		bvc	set_print
		ldx	# low error
		ldy	# high error
		jsr	l43bf
set_print:	ldx	# low time_out
		ldy	# high time_out
		jsr	print
		jmp	l349f
;
error:		dc.b	"Error from routine #"
error_num:	dc.b	$30,", Slave #"
slave_num:	dc.b	$31,$2e,$9b,$00
;
;
handshake_out:	lda	#$ff
		sta	d57c
		lda	#$82
		sta	d57e
		lda	#$f9
		sta	d57c
		rts
;
get_byte:	bit	d570
		bpl	get_byte
		lda	d571
		rts
;
get_command:
		jsr	set_input
		lda	#$33
		sta	error_num
		lda	#$f8
		sta	d57c
		ldx	#$55
		stx	chksum
		ldx	#0
get_command1:	bit	d570
		bpl	get_command1
		lda	d571
		sta	ddevic,x
		clc
		adc	chksum
		sta	chksum
		inx
		cpx	#$0d
		bcc	get_command1
		jsr	get_byte
		cmp	chksum
		bne	set_checksum
		rts
;
set_checksum:	ldx	# low checksum
		ldy	# high checksum
		jsr	print
		lda	l31dd
		ora	#$30
		sta	l33ae
		bit	l3ded
		bvc	l3379
		ldx	# low checksum1
		ldy	# high checksum1
		jsr	l43bf
l3379:		jmp	l349f
;
checksum:	dc.b	<internal>, <+128>," Checksum Mismatch    "
checksum1:	dc.b	"Checksum mismatch on slave #"
l33ae:		dc.b	$30,$2e,$9b,$00
;
get_data:	jsr	set_input
		lda	#$34
		sta	error_num
		lda	#$f8
		sta	d57c
		ldx	#$55
		stx	chksum
		ldx	#0
get_data1:	bit	d570
		bpl	get_data1
		lda	d571
		sta	data,x
		clc
		adc	chksum
		sta	chksum
		inx
		cpx	dbytlo
		bne	get_data1
		jsr	get_byte
		cmp	chksum
		bne	l33e3
		rts
;
l33e3:		jmp	set_checksum
;
put_data:	jsr	set_output
		jsr	handshake_out
		ldx	#$55
		stx	chksum
		ldx	#0
		lda	#$31
		sta	error_num
put_data1:	lda	data,x
		sta	d571
		clc
		adc	chksum
		sta	chksum
put_data2:	bit	d57d
		bpl	put_data2
		inx
		cpx	dbytlo
		bne	put_data1
		jsr	put_byte
		jmp	set_input
;
sendsns:	jsr	set_output
		jsr	handshake_out
		lda	#$32
		sta	error_num
		lda	l31da
		jsr	put_byte
		lda	l31db
		jsr	put_byte
		lda	l31da
		clc
		adc	l31db
		eor	#$80
		jsr	put_byte
		jmp	set_input
;
setup:		lda	#0
		sta	atract
		jsr	set_timers
		lda	#$c0
		sta	nmien
		lda	#$80
		sta	line2+9
		lda	#0
		sta	d570
		jsr	set_output
		lda	#$ff
		sta	d57c
		lda	#0
		sta	d571
		ldy	#$0a
l345e:		dey
		bpl	l345e
		lda	#$20
		sta	d570
		rts
;
set_timers:	lda	# low bb_mio_off
		sta	cdtma1
		lda	# high bb_mio_off
		sta	cdtma1+1
		lda	#0
		sta	cdtmv1
		sta	cdtmv1+1
		rts
;
l347a:		ldx	#$ff
		txs
		jsr	setup
		inc	line2+8
		ldx	l31e0
		lda	l3ace,x
		sta	d571
		lda	rtclok+2
		adc	#7
		tay
l3491:		bit	d570
		bvs	l349c
		cpy	rtclok+2
		bne	l3491
		beq	l349f
l349c:		jmp	l3546
;
l349f:		ldx	#$ff
		txs
		inx
		stx	l31e1
		jsr	setup
l34a9:		ldx	l31e0
		inx
		cpx	#8
		bcc	l34bb
		bit	porta
		bmi	l34b9
		jsr	l437d
l34b9:		ldx	#0
l34bb:		stx	l31e0
		lda	l3ace,x
		ldx	#$32
		sta	d571
l34c6:		bit	d570
		bvs	l3546
		dex
		bne	l34c6
		ldx	#0
		stx	d571
l34d3:		bit	d570
		bvs	l3546
		inx
		cpx	#$1e
		bcc	l34d3
		inc	line2+8
		lda	ch
		cmp	#$ff
		beq	l34a9
		ldy	#$ff
		sty	ch
		cmp	#$21
		bne	l34f6
		jsr	l3cc6
		jmp	l34a9
;
l34f6:		cmp	#$2a
		beq	l3505
		cmp	#$0a
		beq	l3508
		cmp	#$3a
		beq	l350b
		jmp	l34a9
;
l3505:		lda	#$40	;'heart'
		dc.b	$2c
l3508:		lda	#$80	;' '+128
		dc.b	$2c
l350b:		lda	#$20	;'@'
		eor	l3ded
		sta	l3ded
		jsr	l3519
		jmp	l3543
;
l3519:		bit	l3ded
		bvs	l3521
		lda	#$80	;' '+128
		dc.b	$2c
l3521:		lda	#$e5	;'e'+128
		sta	line2+37
		bit	l3ded
		bmi	l352e
		lda	#$80	;' '+128
		dc.b	$2c
l352e:		lda	#$f0	;'p'+128
		sta	line2+38
		lda	l3ded
		and	#$20
		bne	l353d
		lda	#$80	;' '+128
		dc.b	$2c
l353d:		lda	#$e4	;'d'+128
		sta	line2+39
		rts
;
l3543:		jmp	l34a9
;
l3546:		ldx	l31e0
		inx
		stx	l31dd
		txa
		ora	#$90
		bit	d570
		bvc	l3543
		sta	line2+26
		jsr	set_timers
		lda	#4
		sta	cdtmv1
		lda	d570
		and	#$cf
		sta	d570
		lda	#$8a	;'*'+128
		sta	line2+9
		jsr	get_command
		lda	# low data
		sta	dbuflo
		lda	# high data
		sta	dbuflo+1
		lda	ddevic
		cmp	#$91
		bne	l3584
		jmp	l36c1
;
l3584:		cmp	#$92
		bne	l358b
		jmp	l39e7
;
l358b:		ldy	#$20
		lda	ddevic
		clc
		adc	dunit
		clc
		adc	#$ff
		ldx	l36b6
l359a:		cmp	l36b6,x
		beq	l35b6
		dex
		bne	l359a
l35a2:		lda	dstats
		sta	l31da
		lda	dunit
		ora	#$40
		sta	l31db
		jsr	sendsns
		jmp	l349f
;
l35b6:		tax
		lda	l31dd
		sec
		sbc	#1
		asl
		asl
		asl
		asl
		tay
		cpx	#$40
		bne	l35d6
		lda	mastab,y
		bmi	l35d3
		and	#$0f
		sta	dunit
		jmp	l361d
;
l35d3:		jmp	l35a2
;
l35d6:		stx	l31df
		tya
		clc
		adc	l31df
		sec
		sbc	#$30
		tay
		lda	mastab,y
		bpl	l3615
		and	#$0f
		ora	#$30
		sec
		sbc	ddevic
		clc
		adc	#1
		sta	dunit
		lda	mastab,y
		and	#$40
		beq	l35d3
		lda	dcomnd
		cmp	#$50	;Write without verify
		beq	l3612
		cmp	#$57	;write
		beq	l3612
		cmp	#$21	;format
		beq	l3612
		cmp	#$22	;format enhanced density
		beq	l3612
		jmp	l35a2
;
l3612:		lda	mastab,y
l3615:		sta	dunit
		lda	#$31	;drive id
		sta	ddevic
l361d:		lda	ddevic
		cmp	#$40	;printer id
		beq	l362c
		lda	dunit	; id byte
		and	#$0f	; change $01 to '1'
		ora	#$90	;'0'inverse
		dc.b	$2c
l362c:		lda	#$b0	;'P'inverse
		sta	line2+17
		lda	dstats
		sta	l31dc
		jsr	l3cb8
		lda	dstats
		bpl	l3642
		jsr	get_data
l3642:		bit	dunit
		bvc	l3666
		lda	dcomnd
		cmp	#$57
		beq	l365a
		cmp	#$50
		beq	l365a
		cmp	#$21
		beq	l365a
		cmp	#$22
		bne	l365e
l365a:		ldy	#$90
		bne	l3679
l365e:		lda	dunit
		and	#$0f
		sta	dunit
l3666:		jsr	set_timers
		lda	ddevic
		cmp	#$40
		beq	l3676
		jsr	l3ef2
		jmp	l3679
;
l3676:		jsr	xsio
l3679:		sty	l31da
		jsr	set_timers
		lda	#4
		sta	cdtmv1
		bit	l31dc
		bvc	l368c
		jsr	put_data
l368c:		jsr	sendsns
		lda	l3ded
		and	#$20
		beq	l36a6
		lda	ddevic
		clc
		adc	dunit
		sbc	#$32
		cmp	#$0a
		bcs	l36a6
		jsr	l4593
l36a6:		lda	l31e1
		cmp	#$14
		bcs	l36b3
		inc	l31e1
		jmp	l347a
;
l36b3:		jmp	l349f
;
;==============================================
;10 BYTES FOLLOW-LOOKMAX(FIRST BYTE) & LOOKTABLE
l36b6:		dc.b	$0a,$31,$32,$33,$34,$35,$36
		dc.b	$37,$38,$39,$40
;
l36c1:		lda	dstats
		sta	l31dc
		lda	dcomnd
		cmp	#$52
		beq	l3727
		cmp	#$53
		beq	l36e6
		cmp	#$57
		beq	l3752
		lda	#$8b
		sta	l31da
		lda	#$40
		sta	l31db
		jsr	sendsns
		jmp	l349f
;
l36e6:		jsr	l3cb8
		lda	daux1+1
		bne	l36fe
		lda	daux1
		cmp	#8
		bcs	l36fe
		jsr	l386d
		lda	data
		sta	data+1
l36fe:		lda	#0
		sta	data+2
		sta	data+3
		lda	daux1
		clc
		adc	#$14
		sta	data
		cmp	#$1c
		bcc	l371d
		jsr	l3785
		ldy	#0
		lda	(cb),y
		sta	data+1
l371d:		ldy	#1
		lda	#$fe
		sta	l31e1
		jmp	l3679
;
l3727:		jsr	l3cb8
		lda	daux1+1
		bne	l373f
		lda	daux1
		cmp	#8
		bcs	l373f
		jsr	l386d
		jsr	l390b
		jmp	l374f
;
l373f:		jsr	l3785
		ldy	#0
l3744:		lda	(cb),y
		sta	data,y
		iny
		cpy	dbytlo
		bne	l3744
l374f:		jmp	l371d
;
l3752:		jsr	l3cb8
		jsr	get_data
		lda	daux1+1
		bne	l376a
		lda	daux1
		cmp	#8
		bcs	l376a
		jsr	l392d
		jmp	l377a
;
l376a:		jsr	l3785
		ldy	#0
l376f:		lda	data,y
		sta	(cb),y
		iny
		cpy	dbytlo
		bne	l376f
l377a:		lda	#1
l377c:		sta	l31da
		jsr	sendsns
		jmp	l349f
;
l3785:		lda	#0
		sta	cb
		lda	daux1+1
		bne	l37b8
		lda	daux1
		bmi	l37c7
		lsr
		sta	cb+1
		ror	cb
		clc
		lda	# low pipe_end
		adc	cb
		sta	cb
		lda	# high pipe_end
		adc	cb+1
		sta	cb+1
l37a5:		lda	daux1
		jsr	l441e
		sta	line2+34
		lda	daux1
		jsr	l4422
		sta	line2+35
		rts
;
l37b8:		lda	# low mastab
		ldx	# high mastab
l37bc:		sta	cb
		stx	cb+1
		rts
;
l37c1:		lda	# low variables
		ldx	# high variables
		bne	l37bc
l37c7:		cmp	#128		;$80
		beq	l37c1
		lda	# low l386a
		ldx	# high l386a
		jsr	l37bc
		lda	daux1
		cmp	#129				;$81
		bne	l37dc
		jmp	l44a0
;
l37dc:		cmp	#$82
		bne	l37e3
		jmp	l44bf
;
l37e3:		cmp	#$83
		bne	l37ea
		jmp	l3cc6
;
l37ea:		cmp	#$8d
		bcc	l381d
		cmp	#$96
		bcs	l381e
		sec
		sbc	#$8c
		sta	dunit
		lda	l31dd
		asl
		asl
		asl
		asl
		adc	dunit
		tax
		lda	l3d5c,x
		bmi	l381d
		and	#$0f
		tay
		lda	l31b8,y
		cmp	l31dd
		bne	l381d
		lda	l31c8,y
		cmp	#1
		bne	l381d
		jmp	l3b92
;
l381d:		rts
;
l381e:		cmp	#$97
		bcc	l381d
		cmp	#$a0
		bcs	l381d
		sec
		sbc	#$96
		sta	dunit
		lda	l31dd
		asl
		asl
		asl
		asl
		adc	dunit
		tax
		lda	l3d5c,x
		bmi	l381d
		and	#$0f
		tay
		lda	l31b8,y
		beq	l384f
		cmp	l31dd
		beq	l384f
		lda	#$c9
		sta	dstats
		rts
;
l384f:		lda	l31c8,y
		ora	#1
		sta	l31c8,y
		lda	l31dd
		sta	l31b8,y
		tya
		asl
		asl
		tax
		lda	l31dd
		ora	#$90
		sta	line3+3,x
		rts
;
l386a:		dc.b	$01,$9b
		dc.b	$00
l386d:		jsr	l37a5
		lda	daux1
		asl
		tax
		lda	l31e5,x
		cmp	l31f5,x
		bne	l389c
		lda	l31e6,x
		cmp	l31f6,x
		bne	l389c
l3885:		lda	daux1
		asl
		tax
		lda	#0
		sta	data
		sta	l31e5,x
		sta	l31e6,x
		sta	l31f5,x
		sta	l31f6,x
		rts
;
l389c:		lda	l31f5,x
		clc
		adc	pipe20,x
		sta	cb
		lda	l31f6,x
		adc	pipe20+1,x
		sta	cb+1
		lda	l31f6,x
		cmp	#3
		bne	l38bf
		lda	l31f5,x
		bpl	l38bf
		eor	#$ff
		clc
		adc	#1
		dc.b	$2c
l38bf:		lda	#$ff
		sta	l31e2
		ldy	#0
		ldx	#0
l38c8:		lda	(cb),y
		sta	data+1,x
		iny
		inx
		bmi	l3885
		cpy	l31e2
		beq	l38e0
l38d6:		cmp	#$9b
		bne	l38c8
		stx	data
		jmp	l38fb
;
l38e0:		pha
		lda	#$ff
		sta	l31e2
		lda	daux1
		asl
		tay
		lda	pipe20,y
		sta	cb
		lda	pipe20+1,y
		sta	cb+1
		ldy	#0
		pla
		jmp	l38d6
;
l38fb:		lda	daux1
		asl
		tax
		tya
		clc
		adc	cb
		sta	cb
		bcc	l390a
		inc	cb+1
l390a:		rts
;
l390b:		sec
		lda	cb
		sbc	pipe20,x
		sta	l31f5,x
		lda	cb+1
		sbc	pipe20+1,x
		sta	l31f6,x
		rts
;
pipe20:		dc.w	program_end
pipe21:		dc.w	program_end+1024
pipe22:		dc.w	program_end+2048
pipe23:		dc.w	program_end+3072
pipe24:		dc.w	program_end+4096
pipe25:		dc.w	program_end+5120
pipe26:		dc.w	program_end+6144
pipe27:		dc.w	program_end+7168
;

;
l392d:		jsr	l37a5
		lda	daux1
		asl
		tax
		lda	l31e5,x
		sta	l31e3
		clc
		adc	pipe20,x
		sta	cd
		lda	l31e6,x
		sta	l31e4
		adc	pipe20+1,x
		sta	cd+1
		ldy	#0
		lda	data
		bne	l3956
		jmp	l3885
;
l3956:		inc	l31e3
		bne	l397d
		inc	l31e4
		lda	l31e4
		cmp	#4
		bcc	l397d
		lda	#0
		sta	l31e4
		sty	data
		sec
		lda	pipe20,x
		sbc	data
		sta	cd
		lda	pipe20+1,x
		sbc	#0
		sta	cd+1
l397d:		lda	l31e3
		cmp	l31f5,x
		bne	l39c9
		lda	l31e4
		cmp	l31f6,x
		bne	l39c9
		clc
		lda	l31f5,x
		adc	pipe20,x
		sta	cb
		lda	l31f6,x
		adc	pipe20+1,x
		sta	cb+1
		ldy	#$ff
l39a0:		iny
		inc	l31f5,x
		bne	l39c0
		inc	l31f6,x
		lda	l31f6,x
		cmp	#4
		bcc	l39c0
		lda	#0
		tay
		sta	l31f6,x
		lda	pipe20,x
		sta	cb
		lda	pipe20+1,x
		sta	cb+1
l39c0:		lda	(cb),y
		cmp	#$9b
		bne	l39a0
		jmp	l392d
;
l39c9:		lda	data+1,y
		sta	(cd),y
		cmp	#$9b
		beq	l39da
		iny
		bpl	l3956
		lda	#$89
		jmp	l377c
;
l39da:		lda	l31e3
		sta	l31e5,x
		lda	l31e4
		sta	l31e6,x
		rts
;
l39e7:		jsr	l3cb8
		lda	#1
		sta	dstats
		lda	l31dd
		asl
		asl
		asl
		asl
		clc
		adc	dunit
		tay
		lda	l3d5c,y
		bmi	l3a2a
		and	#$0f
		tay
		asl
		asl
		tax
		lda	dcomnd
		cmp	#$43
		beq	l3a21
		cmp	#$58
		beq	l3a1e
		cmp	#$52
		beq	l3a1b
		cmp	#$4f
		beq	l3a56
		bne	l3a24
l3a1b:		jmp	l3c79
;
l3a1e:		jmp	l3bda
;
l3a21:		jsr	l3b28
l3a24:		jsr	l3cb8
		jmp	l349f
;
l3a2a:		jmp	l3ac8
;
slave_open:	dc.b	"Slave "
l3a33:		dc.b	$78
		dc.b	" OPENed IOCB "
l3a41:		dc.b	$78
		dc.b	" for $"
l3a48:		dc.b	$78
		dc.b	" on drive "
l3a53:		dc.b	$78,$9b,$00
;
;
;
;
l3a56:		bit	l3ded
		bpl	l3aab
		jsr	l3a61
		jmp	l3aab
;
l3a61:		txa
		pha
		tya
		pha
		lda	daux1
		pha
		lda	daux1+1
		pha
		lda	l31dd
		ora	#$30
		sta	l3a33
		lda	daux1
		jsr	l442c
		sta	l3a48
		lda	dunit
		ora	#$30
		sta	l3a53
		lda	daux1+1
		lsr
		lsr
		lsr
		lsr
		ora	#$30
		sta	l3a41
		ldx	# low slave_open
		ldy	# high slave_open
		jsr	l43bf
		pla
		sta	daux1+1
		pla
		sta	daux1
		pla
		tay
		pla
		tax
		lda	#4
		sta	cdtmv1
		rts
;
l3aab:		ldx	l31dd
		lda	#0
		sta	l3204,x
		lda	daux1
		and	#$0f
		cmp	#$0c
		bne	l3ac4
		lda	l3dec
		beq	l3ac8
		jmp	l3ad6
;
l3ac4:		and	#8
		bne	l3ad6
l3ac8:		jsr	l3cb8
		jmp	l349f
;
l3ace:
		dc.b	$01,$02,$04,$08
		dc.b	$10,$20,$40,$80
;
l3ad6:		lda	l31b8,y
		beq	l3ae0
		cmp	l31dd
		bne	l3b06
l3ae0:		lda	daux1+1
		lsr
		lsr
		lsr
		lsr
		tax
		lda	l3ace,x
		ora	l31c8,y
		sta	l31c8,y
		lda	l31dd
l3af4:		sta	l31b8,y
		tya
		asl
		asl
		tax
		lda	l31dd
		ora	#$90
		sta	line3+3,x
		jmp	l3ac8
;
l3b06:		lda	#$c9
		sta	dstats
		jsr	l3cb8
		jmp	l349f
;
slave_close:	dc.b	"Slave "
l3b17:		dc.b	$78
		dc.b	" CLOSEd IOCB "
l3b25:		dc.b	$78,$9b,$00
;
;
l3b28:		ldx	l31dd
		lda	l3204,x
		php
		lda	#0
		sta	l3204,x
		plp
		bne	l3b3f
		bit	l3ded
		bpl	l3b67
		jsr	l3b42
l3b3f:		jmp	l3b67
;
l3b42:		tya
		pha
		lda	l31dd
		ora	#$30
		sta	l3b17
		lda	daux1+1
		lsr
		lsr
		lsr
		lsr
		ora	#$30
		sta	l3b25
		ldx	# low slave_close
		ldy	# high slave_close
		jsr	l43bf
		lda	#4
		sta	cdtmv1
		pla
		tay
		rts
;
l3b67:		ldy	#1
l3b69:		lda	l31b8,y
		beq	l3ba5
		cmp	l31dd
		bne	l3ba5
		lda	daux1+1
		lsr
		lsr
		lsr
		lsr
		tax
		lda	l3ace,x
		and	l31c8,y
		beq	l3ba5
		lda	l3ace,x
		eor	#$ff
		and	l31c8,y
		sta	l31c8,y
		cmp	#0
		bne	l3baa
l3b92:		lda	#0
		sta	l31b8,y
		sta	l31c8,y
		tya
		asl
		asl
		tax
		lda	#$80
		sta	line3+3,x
		bne	l3baa
l3ba5:		iny
		cpy	#$0a
		bcc	l3b69
l3baa:		rts
;
;
xio_on_iocb:
		dc.b	"Slave "
l3bb1:		dc.b	$78
		dc.b	" Doing XIO $"
l3bbe:		dc.b	$78
l3bbf:		dc.b	$78
		dc.b	" using IOCB "
l3bcc:		dc.b	$78
		dc.b	" on drive "
l3bd7:		dc.b	$78,$9b,$00
;
;
l3bda:		bit	l3ded
		bpl	l3c35
		txa
		pha
		tya
		pha
		lda	daux1
		pha
		lda	daux1+1
		pha
		lda	l31dd
		ora	#$30
		sta	l3bb1
		lda	daux1+1
		lsr
		lsr
		lsr
		lsr
		ora	#$30
		sta	l3bcc
		lda	dunit
		ora	#$30
		sta	l3bd7
		lda	daux1
		lsr
		lsr
		lsr
		lsr
		jsr	l442c
		sta	l3bbe
		lda	daux1
		jsr	l442c
		sta	l3bbf
		ldx	# low xio_on_iocb
		ldy	# high xio_on_iocb
		jsr	l43bf
		pla
		sta	daux1+1
		pla
		sta	daux1
		pla
		tay
		pla
		tax
		lda	#4
		sta	cdtmv1
l3c35:		stx	l31df
		ldx	l31dd
		lda	#0
		sta	l3204,x
		lda	daux1
		ldx	xiomax
l3c46:		cmp	xiomax,x
		beq	l3c64
		dex
		bne	l3c46
		ldx	l31dd
		sta	l3204,x
		lda	#2
		sta	l31da
		lda	#0
		sta	l31db
		jsr	sendsns
		jmp	l349f
;
l3c64:		ldx	l31df
		jmp	l3ad6
;
slave_reset:
		dc.b	"Slave "
;
l3c70:		dc.b	$78
		dc.b	" RESET"
		dc.b	$9b,$00
l3c79:		bit	l3ded
		bpl	l3c8d
		lda	l31dd
		ora	#$30
		sta	l3c70
		ldx	# low slave_reset
		ldy	# high slave_reset
		jsr	l43bf
l3c8d:		ldy	#1
l3c8f:		lda	l31b8,y
		cmp	l31dd
		bne	l3ca8
		lda	#0
		sta	l31b8,y
		sta	l31c8,y
		tya
		asl
		asl
		tax
		lda	#$80
		sta	line3+3,x
l3ca8:		iny
		cpy	#$0a
		bcc	l3c8f
		lda	#0
		ldx	l31dd
		sta	l3204,x
		jmp	l3ac8
;
l3cb8:		lda	dstats
		sta	l31da
		lda	#0
		sta	l31db
		jmp	sendsns
;
l3cc6:		ldy	#1
l3cc8:		lda	#0
		sta	l31d8
		sta	l31d9
		sta	l31b8,y
		sta	l31c8,y
		sta	l3205,y
		tya
		asl
		asl
		tax
		lda	#$80
		sta	line3+3,x
		iny
		cpy	#$0a
		bcc	l3cc8
		ldy	#$20
l3ce9:		lda	l3cf8,y
		sta	line4+7,y
		dey
		bpl	l3ce9
		lda	#$c0
		sta 	nmien
		rts
;
l3cf8:		dc.b	<internal>, <+128>,"                      Count:0000 "
;;
;
top:		lda	#dlist&255
		sta	sdlstl
		lda	#dlist/256
		sta	sdlstl+1
		lda	#0
		sta	color4
		lda	#$92
		sta	color2
		lda	#$ca
		sta	color1
		lda	portb
		ora	#2
		sta	portb
		lda	# low pipe_end	; need to fix this
		sta	cb
		lda	# high pipe_end
		sta	cb+1
		ldx	#$40
		lda	#0
		tay
l3d47:		sta	(cb),y
		iny
		bne	l3d47
		inc	cb+1
		dex
		bne	l3d47
		lda	#0
		sta	l31e0
		jsr	init_pia
		jsr	l44a0
l3d5c:		jmp	l349f
;
;
;
xiomax:		dc.b	$0c,$20,$21,$22
		dc.b	$23,$24,$29,$2a
		dc.b	$2b,$2d,$2e,$fd
		dc.b	$fe
;MASTER TABLE
mastab:
		dc.b	1,1,2,3,4,5,6,7,8,$89,0,0,0,0,0,0 ;SLAVE #1
		dc.b	1,1,2,3,4,5,6,7,8,$89,0,0,0,0,0,0 ;SLAVE #2
		dc.b	1,1,2,3,4,5,6,7,8,$89,0,0,0,0,0,0 ;SLAVE #3
		dc.b	1,1,2,3,4,5,6,7,8,$89,0,0,0,0,0,0 ;SLAVE #4
		dc.b	1,1,2,3,4,5,6,7,8,$89,0,0,0,0,0,0 ;SLAVE #5
		dc.b	1,1,2,3,4,5,6,7,8,$89,0,0,0,0,0,0 ;SLAVE #6
		dc.b	1,1,2,3,4,5,6,7,8,$89,0,0,0,0,0,0 ;SLAVE #7
		dc.b	1,1,2,3,4,5,6,7,8,$89,0,0,0,0,0,0 ;SLAVE #8
;
;
;
l3dec:		dc.b	$00
l3ded:		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
l3e6d:		dc.b	$00,$00,$00,$00
		dc.b	$00,$00,$00,$00
		dc.b	$00,$00
l3e77:		dc.b	$00
l3e78:		dc.b	$00
l3e79:		dc.b	$00
l3e7a:		dc.b	$00
l3e7b:		dc.b	$00
l3e7c:		dc.b	$00
;
table1:
		dc.b	$28,$01,$00,$12
		dc.b	$00,$00,$00,$80
		dc.b	$ff,$00,$00,$00
		dc.b	$04,$08,$0c,$10
		dc.b	$01,$05,$09,$0d
		dc.b	$11,$02,$06,$0a
		dc.b	$0e,$12,$03,$07,$0b,$0f
;
;
table2:
		dc.b	$28,$01,$00,$12
		dc.b	$00,$04,$01,$00
		dc.b	$ff,$00,$00,$00
		dc.b	$01,$0a,$08,$11
		dc.b	$06,$0f,$04,$0d
		dc.b	$02,$0b,$09,$12
		dc.b	$07,$10,$05,$0e,$03,$0c
;
;
table3:
		dc.b	$28,$01,$00,$1a
		dc.b	$00,$04,$00,$80
		dc.b	$ff,$00,$00,$00
		dc.b	$04,$08,$0c,$10
		dc.b	$14,$18,$01,$05
		dc.b	$09,$0d,$11,$15
		dc.b	$19,$02,$06,$0a,$0e,$12
;
;
;
;
table5:
		dc.b	$16,$1a,$03,$07
		dc.b	$0b,$0f,$13
l3ede:		dc.b	$17


l3edf:		lda	# high l3eef
		pha
		lda	# low l3eef
		pha
		php
		pha
		lda	#$3c
		sta	pbctl
		jmp	(lpenv+1)
;
l3eef		dec	brkkey
		rts
;
l3ef2:		lda	#1
		sta	critic
		lda	dunit
		pha
		lda	pdvmsk
		beq	l3f19
		ldx	#8
l3f01:		jsr	c9af
		beq	l3f19
		txa
		pha
		jsr	d805
		pla
		tax
		bcc	l3f01
		lda	#0
		sta	shpdvs
		sta	PBIbank
		beq	l3f1c
l3f19:		jsr	l3f29
l3f1c:		pla
		sta	dunit
		lda	#0
		sta	critic
		sty	dstats
		tya
		rts
;
l3f29:		ldy	#$a8
		sty	l3e7b
		lda	#0
		sta	temp3
		clc
		lda	ddevic
		adc	dunit
		sec
		sbc	#$32
		cmp	#9
		bcc	l3f48
l3f41:		lda	#$28
		ldx	#$0d
		jmp	l40e4
;
l3f48:		tax
		sta	l3e77
		lda	#8
		sta	consol
		lda	consol
		cmp	#1
		bne	l3f5f
		lda	#40
		sta	l3e6d,x
		bne	l3f81
l3f5f:		cmp	#2
		beq	l3f89
l3f63:		lda	l3e6d,x
		bpl	l3f81
		lda	dcomnd
		cmp	#$50
		beq	l3f77
		cmp	#$57
		beq	l3f77
		cmp	#$52
		bne	l3f41
l3f77:		lda	#$20
		sta	temp3
		lda	#$10
		jmp	l3fc0
;
l3f81:		cmp	#$28
		beq	l3f95
		cmp	#0
		bne	l3f9c
l3f89:		jsr	l42f5
		ldx	l3e77
		ldy	l3e7b
		jmp	l3f63
;
l3f95:		lda	#$28
		ldx	#$0e
		jmp	l3ff5
;
l3f9c:		cmp	#$0f
		bne	l3fe6
		lda	#$80
		sta	temp3
		lda	dcomnd
		and	#$7f
		cmp	#$23
		bcs	l3fbe
		lda	consol
		and	#2
		beq	l3fcf
		lda	skstat
		and	#8
		beq	l3fcf
		bne	l3fd2
l3fbe:		lda	#$0f
l3fc0:		ldx	#$0e
		jsr	l40e4
		cpy	#$8a
		beq	l3ffe
		cpy	#$8b
		beq	l3ffe
		tya
		rts
;
l3fcf:		lda	#0
		dc.b	$2c
l3fd2:		lda	#$80
		sta	temp3
		lda	dcomnd
		and	#$7f
		sta	dcomnd
		lda	#$28
		ldx	#$0d
		jmp	l40e4
;
l3fe6:		lda	dcomnd
		cmp	#$21
		beq	l4008
		cmp	#$22
		beq	l4008
l3ff1:		lda	#$0a
		ldx	#$18
l3ff5:		jsr	l40e4
		cpy	#$8a
		beq	l3ffe
		tya
		rts
;
l3ffe:		ldx	l3e77
		lda	#0
		sta	l3e6d,x
		tya
		rts
;
l4008:		lda	consol
		and	#2
		beq	l3ff1
		lda	skstat
		and	#8
		beq	l3ff1
		jsr	c73a
		lda	dbytlo
		sta	l3e79
		lda	dbytlo+1
		sta	l3e7a
		lda	dcomnd
		sta	l3e78
		cmp	#$22
		beq	l4063
		lda	#2
		sta	dbuflo+1
		sta	dtimlo
		lda	#$60
		sta	dbuflo
		lda	#0
		sta	dbytlo+1
		lda	#$0c
		sta	dbytlo
		lda	#$40
		sta	dstats
		lda	#$4e
		sta	dcomnd
		jsr	l3ff1
		bpl	l4058
		jmp	l4069
;
l4058:		lda	pptmpx+26
		bne	l4069
		ldx	# low table2
		ldy	# high table3
		bne	l406d
l4063:		ldx	# low table3
		ldy	# high table2
		bne	l406d
l4069:		ldx	# low table1
		ldy	# high table1
l406d:		stx	dbuflo
		sty	dbuflo+1
		lda	#$66
		sta	dcomnd
		lda	#$80
		sta	dstats
		sta	dbytlo
		sta	dtimlo
		asl
		sta	dbytlo+1
		ldy	#$a8
		jsr	l3ff1
		lda	l3e78
		sta	dcomnd
		lda	bufadr
		sta	dbuflo
		lda	bufadr+1
		sta	dbuflo+1
		lda	l3e79
		sta	dbytlo
		lda	l3e7a
		sta	dbytlo+1
		cpy	#$8b
		beq	l40cf
		cpy	#1
		beq	l40d9
		ldy	#0
l40b2:		tya
		lsr
		adc	#1
		sta	(bufadr),y
		iny
		lda	#0
		sta	(bufadr),y
		iny
		cpy	#$7e
		bcc	l40b2
		lda	#$ff
		sta	(bufadr),y
		iny
		sta	(bufadr),y
		ldy	#$90
		sty	status
		tya
		rts
;
l40cf:		ldy	#$a8
		lda	#$40
		sta	dstats
		jmp	l3ff1
;
l40d9:		ldy	#0
		lda	#$ff
		sta	(bufadr),y
		iny
		sta	(bufadr),y
		tya
		rts
;
l40e4:		stx	tstat
		sty	temp1
		sta	temp2
		tsx
		stx	stackp
		sei
		lda	#1
		sta	dretry
l40f7:		lda	tstat
		sta	l3e7c
l40fd:		lda	temp2
		cmp	#$0a
		beq	l4106
		lda	#$28
l4106:		sta	audf3
		lda	#0
		sta	audf4
		sta	status
		lda	ddevic
		clc
		adc	dunit
		adc	#$ff
		sta	cdevic
		lda	dcomnd
		ora	temp3
		sta	ccomnd
		lda	daux1
		sta	caux1
		lda	daux1+1
		sta	caux1+1
		lda	# low cdevic	;$3a
		sta	bufrlo
		lda	# high cdevic	;2
		sta	bufrlo+1
		asl
		sta	bfenlo
		lda	#0
		sta	bfenlo+1
		sta	savio
		lda	#$34
		sta	pbctl
		jsr	l41ce
		lda	#1
		sta	savio
		lda	dbuflo
		sta	bufrlo
		lda	dbuflo+1
		sta	bufrlo+1
		lda	dbytlo
		sta	bfenlo
		lda	dbytlo+1
		sta	bfenlo+1
		lda	temp2
		sta	audf3
		lda	dstats
		bpl	l4172
		jsr	l41ce
l4172:		jsr	l4239
		bit	dstats
		bvc	l41a5
		ldy	#0
		sty	chksum
l417e:		jsr	l427e
		sta	(bufrlo),y
		clc
		adc	chksum
		adc	#0
		sta	chksum
		inc	bufrlo
		bne	l4190
		inc	bufrlo+1
l4190:		lda	bfenlo
		bne	l4196
		dec	bfenlo+1
l4196:		dec	bfenlo
		bne	l417e
		lda	bfenlo+1
		bne 	l417e
		jsr	l427e
		cmp	chksum
		bne	l421e
l41a5:		lda	#$a0
		sta	audc4
		lda	pokmsk
		sta	irqen
		jsr	l426b
		ldy	status
		beq	l41c8
		cpy	#$80
		bne	l41c0
		jsr	l3edf
		jmp	l41c9
;
l41c0:		dec	dretry
		bmi	l41c9
		jmp	l40f7
;
l41c8:		iny
l41c9:		cli
		sty	status
		tya
		rts
;
l41ce:		ldx	#0
l41d0:		dex
		bne	l41d0
		jsr	l42d9
		ldy	#0
		lda	(bufrlo),y
		sta	chksum
		sta	serout
l41df:		inc	bufrlo
		bne	l41e5
		inc	bufrlo+1
l41e5:		lda	bfenlo
		bne	l41eb
		dec	bfenlo+1
l41eb:		dec	bfenlo
		beq	l41fe
l41ef:		lda	(bufrlo),y
		jsr	l42c0
		clc
		adc	chksum
		adc	#0
		sta	chksum
		jmp	l41df
;
l41fe:		lda	bfenlo+1
		bne	l41ef
		lda	chksum
		jsr	l42c0
l4207:		lda	irqst
		and	#8
		bne	l4207
		jsr	l42dc
		ldy	#2
		jsr	l426d
		lda	#$c0
		sta	irqen
		jmp	l424a
;
l421e:		lda	#143				;$8f
		dc.b	$2c 				; hummm  maybe a coding error
l4221:		lda	#138				; maybe bit l8aa9
l4223:		sta	status
		ldx	stackp
		txs
		lda	savio
		bne	l4236
		dec	l3e7c
		beq	l4236
		jmp	l40fd
;
l4236:		jmp	l41a5
;
l4239:		lda	dtimlo
		ror
		ror
		tay
		and	#high l3fc0	;$3f
		tax
		tya
		ror
		and	#low l3fc0	;$c0
		tay
		jsr	l426f
l424a:		jsr	l42dc
		lda	#$3c
		sta	pbctl
		jsr	l427e
		cmp	#$41
		beq	l426b
		cmp	#$43
		beq	l426a
		cmp	#$45
		beq	l4266
		lda	#$8b
		jmp	l4223
;
l4266:		lda	#$90
		sta	status
l426a:		rts
;
l426b:		ldy	#0
l426d:		ldx	#0
l426f:		lda	#low l4221	;$21
		sta	cdtma1
		lda	#high l4221	;$42
		sta	cdtma1+1
		lda	#1
		jmp	setvbv
;
l427e:		lda	#$20
		bit	irqst
		bpl	l42a1
		bne	l427e
		lda	#$df
		sta	irqen
		lda	#$f8
		sta	irqen
		lda	skstat
		sta	skres
		bpl	l42bb
		and	#$20
		beq	l42b8
		lda	serin
		rts
;
l42a1:		lda	#$5f
		sta	irqen
		lda	#$f8
		sta	irqen
		lda	#0
		sta	dretry
		lda	#1
		sta	savio
		lda	#$80
		dc.b	$2c
l42b8:		lda	#$8e
		dc.b	$2c
l42bb:		lda	#$8c
		jmp	l4223
;
l42c0:		pha
l42c1:		lda	irqst
		bpl	l42a1
		and	#$10
		bne	l42c1
		lda	#$ef
		sta	irqen
		lda	#$f8
		sta	irqen
		pla
		sta	serout
		rts
;
l42d9:		lda	#$23
		dc.b	$2c
l42dc:		lda	#$13
		sta	skctl
		sta	skres
		lda	#$28
		sta	audctl
		lda	temp1
		sta	audc4
		lda	#$f8
		sta	irqen
		rts
;
l42f5:		ldy	#9
l42f7:		lda	dcomnd,y
		pha
		dey
		bpl	l42f7
		lda	#'?'	;$3f
		sta	dcomnd
		lda	#low cdevic	
		sta	dbuflo
		ldy	#high cdevic	
		sty	dbuflo+1
		dey
		sty	dtimlo
		sty	dbytlo
		dey
		sty	dbytlo+1
		sty	daux1+1
		lda	#$20
		sta	daux1
		asl
		sta	dstats
		lda	#$28
		ldx	#6
		ldy	#$a0
		jsr	l40e4
		php
		lda	#$48
		sta	dcomnd
		lda	#0
		sta	dstats
		lda	#$28
		ldx	#2
		ldy	#$a0
		jsr	l40e4
		plp
		bpl	l4363
		cpy	#0
		bpl	l4366
		lda	#$d3
		sta	dcomnd
		ldx	#4
		stx	dbytlo
		lda	#$40
		sta	dstats
		ldy	#$a0
		lda	#$0f
		jsr	l40e4
		bpl	l4369
		lda	#$28
		dc.b	$2c
l4363:		lda	#$0a
		dc.b	$2c
l4366:		lda	#$80
		dc.b	$2c
l4369:		lda	#$0f
		ldx	l3e77
		sta	l3e6d,x
		ldy	#0
l4373:		pla
		sta	dcomnd,y
		iny
		cpy	#$0a
		bcc	l4373
		rts
;
l437d:		lda	porta
		asl
		asl
		asl
		asl
		sta	l43ba
		lda	#$10
		sta	porta
		lda	porta
		and	#$0f
		ora	l43ba
		sta	l43ba
		ldx	#9
l4399:		lda	l43b0,x
		sta	ddevic,x
		dex
		bpl	l4399
		jsr	xsio
		lda	#$20
		ldx	#$30
		sta	porta
		stx	porta
		rts
;
l43b0:		dc.b	$40,$01,$57,$80,$ba,$43,$00,$00,$01,$00


;PRINTER BYTES!---------------
l43ba:		dc.b	$00
printer_id:	dc.b	$50,$31,$3a,$9b


l43bf:		stx	cb
		sty	cb+1
		jsr	set_timers
		ldx	#$70
		lda	#$0c
		sta	iccom,x
		jsr	ciov
		lda	#3
		sta	iccom,x
		lda	#8
		sta	icax1,x
		lda	#0
		sta	icax1+1,x
		lda	#low printer_id
		sta	icbal,x
		lda	#high printer_id
		sta	icbal+1,x
		jsr	ciov
l43ec:		ldy	#0
		lda	(cb),y
		beq	l43fd
		jsr	l440a
		inc	cb
		bne	l43ec
		inc	cb+1
		bne	l43ec
l43fd:		ldx	#$70
		lda	#$0c
		sta	iccom,x
		jsr	ciov
		jmp	set_timers
;
l440a:		tay
		ldx	#$70
		lda	#$0b
		sta	iccom,x
		lda	#0
		sta	icbll,x
		sta	icbll+1,x
		tya
		jmp	ciov
;
l441e:		lsr
		lsr
		lsr
		lsr
l4422:		jsr	l442c
		adc	#$60
		rts
;
l4428:		lsr
		lsr
		lsr
		lsr
l442c:		and	#$0f
		clc
		adc	#$30
		cmp	#$3a
		bcc	l4437
		adc	#6
l4437:		rts
;
l4438:		jsr	set_timers
		ldx	#$10
		lda	#$0c
		sta	iccom,x
		jsr	ciov
		lda	#3
		sta	iccom,x
		lda	#low mux_cfg
		sta	icbal,x
		lda	#high mux_cfg
		sta	icbal+1,x
		lda	#0
		sta	icax1+1,x
		rts
;
mux_cfg:	dc.b	"D1:MUX.CFG",$9B,"---blank space---",$9B
;
;
l4477:		ldx	#$10
		sta	iccom,x
		lda	#0
		sta	icbll,x
		lda	#1
		sta	icbll+1,x
		lda	#low mastab
		sta	icbal,x
		lda	#high mastab
		sta	icbal+1,x
		jsr	ciov
		tya
		pha
		lda	#$0c
		sta	iccom,x
		jsr	ciov
		pla
		tay
		rts
;
l44a0:		lda	dbytlo
		pha
		jsr	l4438
		lda	#4
		sta	icax1,x
		jsr	ciov
		lda	#7
		jsr	l4477
		jsr	l3519
		pla
		sta	dbytlo
		sty	dstats
		rts
;
l44bf:		lda	dbytlo
		pha
		jsr	l4438
		lda	#$0c
		sta	icax1,x
		jsr	ciov
		bpl	l44db
		jsr	l4438
		lda	#8
		sta	icax1,x
		jsr	ciov
l44db:		lda	#$0b
		jsr	l4477
		pla
		sta	dbytlo
		sty	dstats
		rts
;
read_sector:	dc.b	"Slave "
;
l44ee:		dc.b	$78
		dc.b	" Read sector $"
;
;
l44fd:		dc.b	$78
l44fe:		dc.b	$78
l44ff:		dc.b	$78
l4500:		dc.b	$78
l4501:		dc.b	$78," from drive "
l450e:		dc.b	$78
		dc.b	", Status=$"
l4519:		dc.b	$78
l451a:		dc.b	$78,$9b,$00
;
;
wrote_sector:
		dc.b	"Slave "
l4523:		dc.b	$78
;
		dc.b	" WROTE sector $"
;
;
;
;
;
;
l4533:		dc.b	$78
l4534:		dc.b	$78
l4535:		dc.b	$78
l4536:		dc.b	$78
l4537:		dc.b	$78
		dc.b	" to drive "
;
l4542:		dc.b	$78
		dc.b	", Status=$"
;
l454d:		dc.b	$78
l454e:		dc.b	$78,$9b,$00
;
;
status_req:
		dc.b	"Slave "
;
l4557:		dc.b	$78
		dc.b	" Status request on drive "
;
;
;
;
;
l4571:		dc.b	$78
		dc.b	", Status bytes: $"
;
;
;
l4583:		dc.b	$78
l4584:		dc.b	$78,$20,$24
l4587:		dc.b	$78
l4588:		dc.b	$78,$20,$24
l458b:		dc.b	$78
l458c:		dc.b	$78,$20,$24
l458f:		dc.b	$78
l4590:		dc.b	$78,$9b,$00

l4593:		ldx	#$0c
l4595:		lda	ddevic,x
		pha
		dex
		bpl	l4595
		lda	ddevic
		clc
		adc	dunit
		adc	#$ff
		tax
		lda	l31dd
		ora	#$30
		tay
		lda	dcomnd
		cmp	#$52
		beq	l45ce
		cmp	#$50
		beq	l461d
		cmp	#$57
		beq	l461d
		cmp	#$53
		beq	l45cb
l45bf:		ldx	#0
l45c1:		pla
		sta	ddevic,x
		inx
		cpx	#$0d
		bcc	l45c1
		rts
;
l45cb:		jmp	l466c
;
l45ce:		stx	l450e
		sty	l44ee
		lda	timer1
		jsr	l442c
		sta	l44fd
		lda	daux1+1
		jsr	l4428
		sta	l44fe
		lda	daux1+1
		jsr	l442c
		sta	l44ff
		lda	daux1
		jsr	l4428
		sta	l4500
		lda	daux1
		jsr	l442c
		sta	l4501
		lda	dstats
		jsr	l4428
		sta	l4519
		lda	dstats
		jsr	l442c
		sta	l451a
		ldx	#low read_sector
		ldy	#high read_sector
		jsr	l43bf
		jmp	l45bf
;
l461d:		stx	l4542
		sty	l4523
		lda	timer1
		jsr	l442c
		sta	l4533
		lda	daux1+1
		jsr	l4428
		sta	l4534
		lda	daux1+1
		jsr	l442c
		sta	l4535
		lda	daux1
		jsr	l4428
		sta	l4536
		lda	daux1
		jsr	l442c
		sta	l4537
		lda	dstats
		jsr	l4428
		sta	l454d
		lda	dstats
		jsr	l442c
		sta	l454e
		ldx	#low wrote_sector
		ldy	#high wrote_sector
		jsr	l43bf
		jmp	l45bf
;
l466c:		stx	l4571
		sty	l4557
		lda	data
		jsr	l4428
		sta	l4583
		lda	data
		jsr	l442c
		sta	l4584
		lda	data+1
		jsr	l4428
		sta	l4587
		lda	data+1
		jsr	l442c
		sta	l4588
		lda	data+2
		jsr	l4428
		sta	l458b
		lda	data+2
		jsr	l442c
		sta	l458c
		lda	data+3
		jsr	l4428
		sta	l458f
		lda	data+3
		jsr	l442c
		sta	l4590
		ldx	#low status_req
		ldy	#high status_req
		jsr	l43bf
		jmp	l45bf
;
program_end:	ds.b	0		; this is the same as "label = *" in mac/65
		ds.b	8192
pipe_end:	ds.b	0		;     equ   program_end+8192

		.org	$74c4

pipe_28:	ds.b	128
pipe_29:	ds.b	128

pipe_30:	ds.b	128
pipe_31:	ds.b	128
pipe_32:	ds.b	128
pipe_33:	ds.b	128
pipe_34:	ds.b	128
pipe_35:	ds.b	128
pipe_36:	ds.b	128
pipe_37:	ds.b	128
pipe_38:	ds.b	128
pipe_39:	ds.b	128

pipe_40:	ds.b	128
pipe_41:	ds.b	128
pipe_42:	ds.b	128
pipe_43:	ds.b	128
pipe_44:	ds.b	128
pipe_45:	ds.b	128
pipe_46:	ds.b	128
pipe_47:	ds.b	128
pipe_48:	ds.b	128
pipe_49:	ds.b	128

pipe_50:	ds.b	128
pipe_51:	ds.b	128
pipe_52:	ds.b	128
pipe_53:	ds.b	128
pipe_54:	ds.b	128
pipe_55:	ds.b	128
pipe_56:	ds.b	128
pipe_57:	ds.b	128
pipe_58:	ds.b	128
pipe_59:	ds.b	128

pipe_60:	ds.b	128
pipe_61:	ds.b	128
pipe_62:	ds.b	128
pipe_63:	ds.b	128
pipe_64:	ds.b	128
pipe_65:	ds.b	128
pipe_66:	ds.b	128
pipe_67:	ds.b	128
pipe_68:	ds.b	128
pipe_69:	ds.b	128

pipe_70:	ds.b	128
pipe_71:	ds.b	128
pipe_72:	ds.b	128
pipe_73:	ds.b	128
pipe_74:	ds.b	128
pipe_75:	ds.b	128
pipe_76:	ds.b	128
pipe_77:	ds.b	128
pipe_78:	ds.b	128
pipe_79:	ds.b	128

pipe_80:	ds.b	128
pipe_81:	ds.b	128
pipe_82:	ds.b	128
pipe_83:	ds.b	128
pipe_84:	ds.b	128
pipe_85:	ds.b	128
pipe_86:	ds.b	128
pipe_87:	ds.b	128
pipe_88:	ds.b	128
pipe_89:	ds.b	128

pipe_90:	ds.b	128
pipe_91:	ds.b	128
pipe_92:	ds.b	128
pipe_93:	ds.b	128
pipe_94:	ds.b	128
pipe_95:	ds.b	128
pipe_96:	ds.b	128
pipe_97:	ds.b	128
pipe_98:	ds.b	128
pipe_99:	ds.b	128

pipe_100:	ds.b	128
pipe_101:	ds.b	128
pipe_102:	ds.b	128
pipe_103:	ds.b	128
pipe_104:	ds.b	128
pipe_105:	ds.b	128
pipe_106:	ds.b	128
pipe_107:	ds.b	128
pipe_108:	ds.b	128
pipe_109:	ds.b	128

pipe_110:	ds.b	128
pipe_111:	ds.b	128
pipe_112:	ds.b	128
pipe_113:	ds.b	128
pipe_114:	ds.b	128
pipe_115:	ds.b	128
pipe_116:	ds.b	128
pipe_117:	ds.b	128
pipe_118:	ds.b	128
pipe_119:	ds.b	128


pipe_120:	ds.b	128
pipe_121:	ds.b	128
pipe_122:	ds.b	128
pipe_123:	ds.b	128
pipe_124:	ds.b	128
pipe_125:	ds.b	128
pipe_126:	ds.b	128
pipe_127:	ds.b	128
pipe_128:	ds.b	128
pipe_129:	ds.b	128


pipe_130:	ds.b	128
pipe_131:	ds.b	128
pipe_132:	ds.b	128
pipe_133:	ds.b	128
pipe_134:	ds.b	128
pipe_135:	ds.b	128
pipe_136:	ds.b	128
pipe_137:	ds.b	128
pipe_138:	ds.b	128
pipe_139:	ds.b	128


pipe_140:	ds.b	128
pipe_141:	ds.b	128
pipe_142:	ds.b	128
pipe_143:	ds.b	128
pipe_144:	ds.b	128
pipe_145:	ds.b	128
pipe_146:	ds.b	128
pipe_147:	ds.b	128

user_pipe_end:	ds.b	0
win_end:	ds.b	0
;
;
;