Modem_1_ddev_read:
	moveq	#$00,d1				; clear high bits of d1
	lea	Modem_1_IOREC.l,a2		; a2 -> IOREC of port
	move	$0004(a2),d2			; d2 = Rx_size_ix
	move	$0008(a2),d1			; d1 = Rx_tail_ix
	sub	$0006(a2),d1			; d1 -= Rx_head_ix
	bcc.s	.L006AE				; if tail>head, keep positive d1
	add	d2,d1				; else d1 += Rx_size_ix
.L006AE:
	cmp.l	d0,d1				; available < wanted ?
	bcc.s	.L006B4				; else use wanted count
	move.l	d1,d0				; d0 = available byte count
.L006B4:
	move.l	d0,-(a7)			; push count
	beq.s	.L006E0				; exit if count==0
	subq.l	#2,d0				; d0 = dbra value for count-1
	bcs.s	.L006D6				; if count == 1, skip loop
	movea.l	(a2),a0				; a0 = Rx_buffer_p
	move	$0006(a2),d1			; d1 = Rx_head_ix
.L006C2:
	addq	#1,d1				; d1 += 1
	cmp	d2,d1				; d1 >= Rx_size_ix ?
	bcs.s	.done_index_wrap
	moveq	#$00,d1				; d1 = zero index
.done_index_wrap:
	move.b	$00(a0,d1.l),(a1)+		; transfer byte to arg buffer
	dbf	d0,.L006C2			; loop for all but last char
	move	d1,$0006(a2)			; Rx_head_ix = d1
.L006D6:
	move.l	a1,-(a7)			; push -> arg buffer pos
	bsr.w	Modem_1_Bconin			; use Bconin for last char
	movea.l	(a7)+,a1			; pull a1 -> arg buffer pos
	move.b	d0,(a1)				; store last char
.L006E0:
	move.l	(a7)+,d0			; pull d0 = count
	rts					; return to caller

Modem_1_ddev_write:
	moveq	#$00,d1				; clear high bits of d1
	lea	Modem_1_IOREC.l,a2		; a2 -> IOREC of port
	move	$0012(a2),d2			; d2 = Tx_io_size_ix
	move	$0014(a2),d1			; d1 = Tx_io_head_ix
	sub	$0016(a2),d1			; d1 -= Tx_io_tail_ix
	bhi.s	.L006FC				; if head>tail, keep positive d1
	add	d2,d1				; d1 += Tx_io_size_ix
.L006FC:
	subq.l	#2,d1				; d1 = safe_room
	bpl.s	.L00702				; if positive, all is well
	moveq	#$00,d1				; else force d1 = 0
.L00702:
	cmp.l	d0,d1				; safe_room < wanted ?
	bcc.s	.L00708				; else use wanted count
	move.l	d1,d0				; d0 = safe_room count
.L00708:
	move.l	d0,-(a7)			; push count
	beq.s	.L00736				; exit if count == 0
	subq.l	#2,d0				; d0 = dbra value for count-1
	bcs.s	.L0072C				; if count==1, skip loop
	movea.l	$000E(a2),a0			; a0 = Tx_io_buffer_p
	move	$0016(a2),d1			; d1 = Tx_io_tail_ix
.L00718:
	addq	#1,d1				; d1 += 1
	cmp	d2,d1				; d1 >= Tx_io_size_ix ?
	bcs.s	.L00720
	moveq	#$00,d1				; d1 = zero index
.L00720:
	move.b	(a1)+,$00(a0,d1.l)		; transfer byte from arg buffer
	dbf	d0,.L00718			; loop for all but last char
	move	d1,$0016(a2)			; Tx_io_tail_ix = d1
.L0072C:
	move.b	(a1),d0				; d0 = last char
	move.l	d0,-(a7)			; push last char as arg
	bsr.w	Modem_1_Bconout			; use Bconout for last char
	addq.l	#4,a7				; clean stack
.L00736:
	move.l	(a7)+,d0			; pull d0 = count
	rts					; return to caller
